|
12304
|
260
|
29
|
2026-04-14T11:00:28.291288+00:00
|
/Users/lukas/.screenpipe/data/data/2026-04-14/1776 /Users/lukas/.screenpipe/data/data/2026-04-14/1776164428291_m1.jpg...
|
PhpStorm
|
faVsco.js – AutomatedReportsService.php
|
1
|
NULL
|
monitor_1
|
NULL
|
NULL
|
NULL
|
NULL
|
Project: faVsco.js, menu
#11894 on JY-18909-automa Project: faVsco.js, menu
#11894 on JY-18909-automated-reports-ask-jiminny, menu
Start Listening for PHP Debug Connections
AutomatedReportsCommandTest
Run 'AutomatedReportsCommandTest'
Debug 'AutomatedReportsCommandTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Execute
Explain Plan
Browse Query History
View Parameters
Open Query Execution Settings…
In-Editor Results
Tx: Auto
Cancel Running Statements
Playground
jiminny
Sync Changes
Hide This Notification
Code changed:
Hide
16
13
13
Previous Highlighted Error
Next Highlighted Error
SELECT * FROM teams WHERE id = 1;
select * from crm_layouts where crm_configuration_id = 39;
SELECT * FROM crm_layout_entities WHERE crm_layout_id = 283;
SELECT * FROM crm_fields WHERE id = 2234;
SELECT * FROM crm_field_values WHERE crm_field_id = 2234;
select * from crm_profiles where user_id = 143;
select * from record_types where crm_configuration_id = 39; # 0121K000001MHElQAO,0121K000001MHEqQAO
select * from business_processes where crm_configuration_id = 39;
# 01941000000H669AAC, 01941000000H66JAAS
select * from record_type_field_values
where record_type_id IN (24);
select * from crm_field_values where id IN (2730);
select * from crm_configurations where id = 39;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 1
and sa.provider = 'salesforce'; #1035
select * from users where team_id = 1; # 222 group 3
SELECT * FROM activities WHERE user_id = 222 order by id desc;
select * from sidekick_settings where team_id = 1;
select * from teams where id = 1;
select * from team_features where team_id = 1;
select * from activities where crm_configuration_id = 2
and provider = 'ms-teams' and id = 608765;
SELECT * FROM activities WHERE crm_configuration_id = 2 and crm_provider_id = '59523413338';
select * from sidekick_settings where team_id = 2;
SELECT * FROM activities WHERE id = 608660;
select * from activity_summary_logs where activity_id = 608660;
select * from ai_prompts where transcription_id = 11214;
# [PASSWORD_DOTS]
SELECT * FROM activities WHERE uuid_to_bin('ed78a437-2804-450e-ab2f-56ab1c641346') = uuid;
# id: 608818, crm: 59628809737
SELECT * FROM activities WHERE uuid_to_bin('36b06e55-afdd-4782-8dee-c624cd0af191') = uuid;
# id: 608821, crm: 59632069252
SELECT ce.start_time, ce.end_time, a.id, a.uuid, crm_provider_id, calendar_event_id, title,
playbook_category_id, user_id, lead_id, contact_id, account_id, opportunity_id,
scheduled_start_time, scheduled_end_time, actual_start_time, actual_end_time, a.created_at
FROM activities a
join calendar_events ce on a.calendar_event_id = ce.id
WHERE a.id IN (608818, 608821);
select * from users where team_id = 1;
select * from team_settings where team_id = 1;
select * from crm_profiles where crm_configuration_id = 39 order by user_id;
select * from team_features where team_id = 1;
select * from users where team_id = 2;
SELECT * FROM activities WHERE uuid_to_bin('ec7647e9-5225-458b-b475-f31aa2769204') = uuid; # 612639
# Preslava N. Ivanova, grou id 3
SELECT * FROM opportunities WHERE uuid_to_bin('a2928fe5-aec5-46cb-85d9-7654c89e46a6') = uuid;
select * from activities where opportunity_id = 344 and actual_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00';
select
a.id,
a.type,
a.scheduled_start_time,
a.actual_start_time,
a.created_at,
a.opportunity_id,
a.status
FROM activities a
WHERE opportunity_id = 344
and status IN ('completed', 'received', 'delivered')
and (
(a.actual_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00')
OR (a.created_at between '2024-10-11 00:00:00' and '2024-10-12 00:00:00')
OR (a.scheduled_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00'))
;
SELECT * FROM users WHERE id = 222;
SELECT * FROM crm_profiles WHERE user_id = 222;
select * from crm_layouts where crm_configuration_id = 39;
SELECT * FROM crm_layout_entities WHERE crm_layout_id = 281;
select * from group_deal_risk_types;
select * from opportunities where team_id = 1;
SELECT * FROM opportunities WHERE id = 315;
SELECT * FROM crm_field_data WHERE object_id = 315;
select * from crm_field_data where object_id = 260;
select * from generic_ai_prompts where subject_id = 315;
select * from teams; # 36, 21, 121, [EMAIL]
SELECT * FROM social_accounts WHERE sociable_id = 121 and provider = 'bullhorn';
# [PASSWORD_DOTS]
select * from teams where id = 1;
select * from crm_configurations where id = 39;
select * from users where team_id = 1;
select u.email, cp.* from users u
join crm_profiles cp on u.id = cp.user_id
where u.team_id = 1;
# 1 - 00541000004281rAAA
# 204 - 0052g000003freeAAA
# 429 - 0052g000003qGOiAAM
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 1
and sa.provider = 'salesforce';
select * from activities where type = 'softphone'
and created_at > '2024-12-11 15:24:36' order by id desc;
select * from activity_providers where team_id = 1;
select * from activity_provider_users where activity_provider_id = 328;
select * from opportunities where crm_configuration_id = 39
AND account_id = 178 AND is_closed = false
order by created_at DESC;
select * from contacts where id = 3952;
select * from accounts where id = 178;
# [PASSWORD_DOTS]
select * from teams where id = 36;
select * from crm_configurations where id = 21;
select * from users where team_id = 36;
select u.email, cp.* from users u
join crm_profiles cp on u.id = cp.user_id
where u.team_id = 36;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 36
and sa.provider = 'bullhorn';
select * from social_accounts where id = 348;
UPDATE social_accounts SET
provider_user_token = '21442_6802599_91:41179a58-21e7-4d7c-ad58-56bb666b2f65',
provider_refresh_token = '21442_6802599_91:01c6b335-3f2a-42e4-85ff-8a08fa65fceb',
expires = 1733998131,
state = 'connected'
WHERE id = 348;
# [PASSWORD_DOTS]
select * from teams where id = 31;
select * from crm_configurations where id = 18;
select * from users where team_id = 31; # 257
select u.email, cp.* from users u
join crm_profiles cp on u.id = cp.user_id
where u.team_id = 31;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 31
and sa.provider = 'close';
select * from contacts where crm_configuration_id = 18;
# [PASSWORD_DOTS] NEPTUNE [PASSWORD_DOTS]
select * from teams;
select * from users where id IN (1030, 1035, 1052);
select * from crm_configurations;
select * from users where team_id = 65; # 257
select * from team_settings where team_id = 65; # 257
select * from invitations where team_id = 65; # 257
select * from users where email = '[EMAIL]'; # 257
select u.email, cp.* from users u
join crm_profiles cp on u.id = cp.user_id
where u.team_id = 65;
select * from crm_configurations where id = 53;
select * from accounts where crm_configuration_id = 53 order by id desc;
select * from leads where crm_configuration_id = 53 order by id desc;
select * from contacts where crm_configuration_id = 53 order by id desc;
select * from opportunities where crm_configuration_id = 53 order by id desc;
select * from crm_profiles where crm_configuration_id = 53 order by id desc;
select * from crm_fields where crm_configuration_id = 53 order by id desc;
select * from crm_field_values where crm_field_id = 3341 order by id desc;
select * from crm_layouts where crm_configuration_id = 53 order by id desc;
select * from stages where crm_configuration_id = 53 order by id desc;
select * from crm_profiles where crm_configuration_id = 13;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 65
and sa.provider = 'integration-app';
select * from contacts where crm_configuration_id = 13;
select * from social_accounts where sociable_id = 283;
SELECT * FROM opportunities WHERE crm_provider_id = '006O400000E9bzeIAB';
select * from activity_providers where team_id = 65;
SELECT * FROM activities WHERE crm_configuration_id IN (51, 52, 53);
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 65
;
# [PASSWORD_DOTS] STAGING [PASSWORD_DOTS]
SELECT * FROM teams;
SELECT * FROM teams WHERE id = 88;
SELECT * FROM teams WHERE id = 89;
select * from team_settings where team_id = 89;
SELECT * FROM users WHERE team_id = 89;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 89;
select * from users;
SELECT * FROM social_accounts WHERE sociable_id = 1761;
SELECT * FROM crm_configurations WHERE id = 70;
select * from accounts where crm_configuration_id = 70 order by id desc;
select * from leads where crm_configuration_id = 70 order by id desc;
select * from contacts where crm_configuration_id = 70 order by id desc;
select * from opportunities where crm_configuration_id = 70 order by id desc;
select * from crm_profiles where crm_configuration_id = 70 order by id desc;
select * from crm_fields where crm_configuration_id = 70 order by id desc;
select * from crm_field_values where crm_field_id = 3536 order by id desc;
select * from crm_layouts where crm_configuration_id = 70 order by id desc;
select * from stages where crm_configuration_id = 70 order by id desc;
select * from business_processes where crm_configuration_id = 70 order by id desc;
select * from business_process_stages where business_process_id = 34;
select * from contacts where id = 10468;
select * from crm_layouts where crm_configuration_id = 70;
SELECT * FROM crm_layout_entities WHERE crm_layout_id = 388;
SELECT * FROM crm_fields WHERE id IN (3533,3534,3535);
select * from activities where crm_configuration_id = 70
and (account_id IS NOT NULL or lead_id IS NOT NULL or contact_id IS NOT NULL or opportunity_id IS NOT NULL) order by id desc;
SELECT * FROM activities WHERE uuid_to_bin('2e10b60f-8a61-41c5-a3d4-28835353dc65') = uuid;
SELECT * FROM activities where crm_configuration_id = 69 ;
SELECT * FROM users WHERE email LIKE '%[EMAIL]%';
SELECT * FROM activities WHERE uuid_to_bin('5a150c93-40fc-42ec-b3bd-c1d328e09f6e') = uuid;
SELECT * FROM opportunities WHERE id = 385;
select * from participants p
join activities a on p.activity_id = a.id
where a.crm_configuration_id = 70
and (p.lead_id IS NOT NULL or p.contact_id IS NOT NULL);
SELECT * FROM participants WHERE id = 1013638;
select * from teams where id = 90;
select * from users where team_id = 90;
select * from social_accounts where social_accounts.sociable_id IN (1960,1760);
SELECT * FROM crm_profiles WHERE crm_configuration_id = 71;
select * from invitations where team_id = 90;
select * from crm_configurations where id = 71;
select * from accounts where crm_configuration_id = 71 order by id desc;
select * from leads where crm_configuration_id = 71 order by id desc;
select * from contacts where crm_configuration_id = 71 order by id desc;
select * from opportunities where crm_configuration_id = 71 order by id desc;
select * from crm_profiles where crm_configuration_id = 71 order by id desc;
select * from crm_fields where crm_configuration_id = 71 order by id desc;
select * from crm_field_values where crm_field_id = 3341 order by id desc;
select * from crm_layouts where crm_configuration_id = 71 order by id desc;
select * from stages where crm_configuration_id = 71 order by id desc;
select * from users order by secondary_email desc;
select u.id, u.email, u.status, sa.id, sa.provider_user_id from social_accounts sa
join users u on sa.sociable_id = u.id
where sa.provider = 'google' and u.email LIKE 'aneliya%';
select * from failed_jobs order by id desc;
select * from users where email = '[EMAIL]' or secondary_email = '[EMAIL]';
select * from teams;
SELECT * FROM crm_profiles WHERE crm_configuration_id = 39;
SELECT * FROM crm_fields WHERE crm_configuration_id = 39 and object_type = 'task';
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 1
and sa.provider = 'salesforce';
# [PASSWORD_DOTS]
SELECT * FROM activities WHERE uuid_to_bin('c38b3895-fd0f-4b1f-9fb2-c170dba137c6') = uuid;
SELECT * FROM crm_configurations WHERE id = 70;
select * from teams where id = 1;
select * from groups where team_id = 1;
select * from users where team_id = 1;
select o.id, o.name,o.close_date, u.id, u.name, u.group_id, r.id, r.display_name, g.name, g.scope from opportunities o
join users u on o.user_id = u.id
join groups g on u.group_id = g.id
join role_user ru on u.id = ru.user_id
join roles r on ru.role_id = r.id
where o.crm_configuration_id = 39 and close_date > '2024-01-01 00:00:00';
select * from role_user where user_id = 143;
select * from roles;
select * from role_user;
select * from groups where id = 9;
select * from scope_groups where group_id = 9;
# [PASSWORD_DOTS]
select * from teams where id = 36;
select * from crm_configurations;
SELECT * FROM social_accounts WHERE sociable_id = 121;
https://crmsandbox.zoho.com/crm/jiminnyw4/tab/Leads/4776201000005049105
https://crmsandbox.zoho.com/crm/
https://crm.zoho.com/crm/org3469620/tab/Leads/230045000229559080
https://crm.zoho.com/crm/
org3469620
SELECT * FROM activities WHERE uuid_to_bin('03382d20-c8bc-48e7-a3d4-90b52fa5ceab') = uuid;
select * from users where email LIKE "%mobile_automation_%";
select * from social_accounts where sociable_id IN (2228);
select * from crm_profiles where user_id IN (2222,2223,2226,2227);
select * from teams order by id desc;
SELECT * FROM users WHERE id = 2229;
SELECT * FROM crm_profiles WHERE user_id = 2229;
select * from opportunities where crm_configuration_id = 88;
select * from crm_fields where crm_configuration_id = 88;
select * from crm_profiles where crm_configuration_id = 88;
SELECT * FROM teams WHERE id = 1;
SELECT * FROM users WHERE id = 143;
SELECT * FROM users WHERE uuid_to_bin('fde193d3-06a2-4e1a-8895-62b94039215d') = uuid;
SELECT * FROM teams WHERE uuid_to_bin('73385071-a756-42ae-9c73-8b53f2309467') = uuid;
https://app.staging.jiminny.com/ondemand?
min_duration=1
&
only_recorded=1
&
user_id%5B%5D=641f1acb-16b8-42d1-8726-df52979dad0e
&
sequence_number=2
select * from users where team_id = 1 and email like '%stoyan%'
select * from coaching_feedbacks;
select * from teams;
SELECT * FROM users WHERE team_id = 36;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 19
and sa.provider = 'pipedrive';
select * from users where id = 143;
SELECT * FROM users WHERE uuid_to_bin('73180eeb-33de-4065-977d-ccbe0e6c94fc') = uuid;
SELECT * FROM teams WHERE uuid_to_bin('73180eeb-33de-4065-977d-ccbe0e6c94fc') = uuid;
SELECT * FROM activity_shares WHERE uuid_to_bin('73180eeb-33de-4065-977d-ccbe0e6c94fc') = uuid;
select * from users where team_id = 2;
select * from activities where crm_configuration_id = 39
and activities.scheduled_start_time BETWEEN '2025-04-09 00:00:00' AND '2025-04-09 23:59:59'
AND user_id = 143
order by id desc;
# [PASSWORD_DOTS]
select * from teams where id = 142; # 2312, 126
select * from team_settings;
select * from users where team_id = 142; # 21642
SELECT * FROM social_accounts WHERE sociable_id = 21642;
SELECT * FROM crm_profiles cp join users u ON u.id = cp.user_id WHERE team_id = 142;
select * from crm_profiles where id IN (93);
select * from invitations;
select * from team_features where team_id = 1;
SELECT * FROM crm_configurations WHERE id = 126;
select * from accounts where crm_configuration_id = 126 order by id desc;
select * from leads where crm_configuration_id = 126 order by id desc;
select * from contacts where crm_configuration_id = 126 order by id desc;
select * from opportunities where crm_configuration_id = 126 order by id desc;
select * from crm_profiles where crm_configuration_id = 126 order by id desc;
select * from crm_fields where crm_configuration_id = 126 # 11060
# and type IN ('picklist', 'status')
# and object_type = 'task'
order by id desc;
# 5731,5732,5733
select DISTINCT crm_field_id from crm_field_values where crm_field_id IN (11151,12239,12215,12185,12175,12165,12144,12137,12127,12109,12107,12105,12103,12092,12037,12005,12003,11987,11969,11958,11951,11942,11931,11924,11921,11917,11915,11901,11893,11883,11872,11870,11868,11866,11839,11833,11821,11793,11780,11777,11769,11757,11737,11735,11656,11645,11638,11629,11618,11611,11602,11591,11584,11581,11558,11544,11543,11534,11532,11529,11527,11503,11497,11493,11488,11470,11468,11457,11455,11397,11387,11372,11363,11348,11323,11318,11309,11301,11300,11292,11290,11286,11284,11256,11252,11242,11237,11233,11219,11176,11160) order by id desc;
select * from crm_layouts where crm_configuration_id = 126 order by id desc;
SELECT * FROM crm_layout_entities WHERE crm_layout_id in (300,299,298);
select * from stages where crm_configuration_id = 126 order by id desc;
select * from business_processes where crm_configuration_id = 126 order by id desc;
select * from business_process_stages where business_process_id IN (76,75,74,73);
select * from playbooks where team_id = 142;
select * from playbook_layouts where playbook_id IN (108);
SELECT * FROM playbook_categories WHERE playbook_id IN (108);
select * from teams where id = 130;
SELECT * FROM social_accounts WHERE sociable_id = 2291;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 2
and sa.provider = 'hubspot';
SELECT * FROM activities
WHERE crm_configuration_id = 110;
select * from teams;
select * from crm_configurations;
SELECT * FROM activities WHERE id = 628773;
SELECT * FROM crm_profiles WHERE user_id = 1460;
SELECT * FROM social_accounts WHERE sociable_id = 2291;
select * from teams;
select ru.*, pr.*, p.* from users u join role_user ru on ru.user_id = u.id
join permission_role pr on pr.role_id = ru.role_id
join permissions p on p.id = pr.permission_id
where team_id = 495 and p.name IN ('dial');
select * from teams where id = 145;
select * from crm_configurations where id = 129;
select * from social_accounts where sociable_id = 2317;
SELECT * FROM activities WHERE uuid_to_bin('8dbab184-a333-4268-ad57-fb41f8d53a9a') = uuid;
select * from teams where id = 1;
SELECT * FROM crm_layouts WHERE crm_configuration_id = 39;
SELECT * FROM crm_layout_entities WHERE crm_layout_id = 280;
SELECT * FROM crm_layout_entities WHERE id = 5507;
SELECT * FROM crm_fields WHERE crm_configuration_id = 39 and object_type IN ('event');
select * from teams;
select * from activities where crm_configuration_id = 14;
SELECT * FROM social_accounts where provider = 'copper';
select * from activities where id = 628467;
select * from participants where activity_id = 628467;
SELECT * FROM contacts WHERE id = 3969;
SELECT * FROM accounts WHERE id = 177;
SELECT * FROM activities WHERE uuid_to_bin('4eb54c77-cfa3-2bd4-84a7-9ed46a21c988') = uuid;
# [PASSWORD_DOTS] BH
select * from teams where id = 36;
SELECT * FROM crm_configurations WHERE id = 21;
select * from activities where crm_configuration_id = 21 and id = 607901;
select * from activities where crm_configuration_id = 21;
select * roles;
select * from permissions;
select * from permission_role where permission_id = 226;
select * from migrations order by id desc;
# mercury
# neptune
# earth
select * from teams;
select * from teams where id = 19;
select * from teams where id = 27;
select * from users where team_id = 27;
SELECT * FROM crm_configurations WHERE id = 42;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 19
and sa.provider = 'pipedrive';
select * from activities where id = 631461;
SELECT * FROM crm_field_values WHERE crm_field_id = 180;
select * from teams where id = 2;
SELECT * FROM social_accounts WHERE sociable_id = 89;
SELECT * FROM activities WHERE uuid_to_bin('ba0c029a-bc14-4e17-8603-64174acebcbb') = uuid; # 634273
select * from activity_summary_logs where activity_id = 634273;
select * from sidekick_settings where team_id = 2;
select * from teams; # 2, 2
SELECT * FROM crm_configurations WHERE team_id = 2; # 2
select * from team_features where team_id = 2;
select * from features;
SELECT * FROM opportunities WHERE crm_configuration_id = 2 and crm_provider_id = '51317301383';
SELECT * FROM opportunities WHERE crm_configuration_id = 2 order by id desc;
select * from automated_reports order by id desc;
select * from automated_report_results order by id desc;
select * from users where team_id = 1 and id IN (7160, 3248);
select * from migrations order by id desc;
SELECT
CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,
u.email,
sa.*,
t.owner_id FROM social_accounts sa
JOIN users u on u.id = sa.sociable_id
JOIN teams t on t.id = u.team_id
WHERE u.team_id = 1 and sa.provider = 'salesforce';
select * from teams where id = 1;
select * from groups g JOIN playbooks p on g.playbook_id = p.id where g.team_id = 1;
select * from groups where id = 565;
select * from playbooks where team_id = 1;
select * from playbooks where id = 175;
select * from playbook_categories where playbook_id = 175;
select * from users where team_id = 1;
select * from users where id = 7160;
select * from crm_profiles where user_id = 7160;
select * from features;
select
*
# id, uuid, type, provider, playbook_category_id, user_id, lead_id, contact_id, account_id, opportunity_id, stage_id,
# crm_configuration_id, crm_provider_id, transcription_id, status
from activities where crm_configuration_id = 1 and type = 'conference'
# and crm_provider_id IS NOT NULL
and provider != 'uploader' and actual_start_time IS NOT NULL
ORDER by id desc;
select * from activities where id = 54747783; # 00UO400000pCzojMAC
select p.id, p.activity_type, pc.id, pc.name
FROM playbooks p
join playbook_categories pc on p.id = pc.playbook_id
where p.team_id = 1 and p.activity_type = 'event';
SELECT * FROM crm_fields WHERE crm_configuration_id = 1 and object_type = 'event';
SELECT * FROM crm_field_values WHERE crm_field_id = 4;
select * from crm_layouts cl join playbook_layouts pl on cl.id = pl.layout_id
where crm_configuration_id = 1 and pl.playbook_id = 175;
select * from teams;
SELECT r.* FROM automated_reports r
join teams t on r.team_id = t.id
WHERE r.frequency = 'daily'
and r.status = 1
AND t.status = 'active'
AND (r.expires_at >= now() OR r.expires_at IS NULL);
select * from automated_report_results where report_id IN (18, 33);
select * from activity_searches where id = 10932;
select * from activity_search_filters where activity_search_id = 10932;
select * from automated_reports;
select * from automated_report_results where report_id IN (34, 35);...
|
[{"role":"AXButton","text" [{"role":"AXButton","text":"Project: faVsco.js, menu","depth":5,"help_text":"~/jiminny/app","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"#11894 on JY-18909-automated-reports-ask-jiminny, menu","depth":5,"help_text":"Pull request #11894 exists for current branch JY-18909-automated-reports-ask-jiminny","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Start Listening for PHP Debug Connections","depth":5,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"AutomatedReportsCommandTest","depth":6,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Run 'AutomatedReportsCommandTest'","depth":6,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Debug 'AutomatedReportsCommandTest'","depth":6,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"More Actions","depth":6,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JetBrains AI","depth":5,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Search Everywhere","depth":5,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"IDE and Project Settings","depth":5,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Execute","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Explain Plan","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Browse Query History","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"View Parameters","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Open Query Execution Settings…","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"In-Editor Results","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Tx: Auto","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Cancel Running Statements","depth":4,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Playground","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"jiminny","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.088194445,"height":0.027777778},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"16","depth":4,"role_description":"text"},{"role":"AXStaticText","text":"13","depth":4,"role_description":"text"},{"role":"AXStaticText","text":"13","depth":4,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"SELECT * FROM teams WHERE id = 1;\n\nselect * from crm_layouts where crm_configuration_id = 39;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 283;\nSELECT * FROM crm_fields WHERE id = 2234;\nSELECT * FROM crm_field_values WHERE crm_field_id = 2234;\n\nselect * from crm_profiles where user_id = 143;\n\nselect * from record_types where crm_configuration_id = 39; # 0121K000001MHElQAO,0121K000001MHEqQAO\nselect * from business_processes where crm_configuration_id = 39;\n# 01941000000H669AAC, 01941000000H66JAAS\n\nselect * from record_type_field_values\n where record_type_id IN (24);\n\nselect * from crm_field_values where id IN (2730);\n\nselect * from crm_configurations where id = 39;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 1\nand sa.provider = 'salesforce'; #1035\n\n\nselect * from users where team_id = 1; # 222 group 3\nSELECT * FROM activities WHERE user_id = 222 order by id desc;\nselect * from sidekick_settings where team_id = 1;\nselect * from teams where id = 1;\nselect * from team_features where team_id = 1;\n\nselect * from activities where crm_configuration_id = 2\nand provider = 'ms-teams' and id = 608765;\n\nSELECT * FROM activities WHERE crm_configuration_id = 2 and crm_provider_id = '59523413338';\n\nselect * from sidekick_settings where team_id = 2;\n\nSELECT * FROM activities WHERE id = 608660;\nselect * from activity_summary_logs where activity_id = 608660;\nselect * from ai_prompts where transcription_id = 11214;\n\n# ********************************************************************************************************\nSELECT * FROM activities WHERE uuid_to_bin('ed78a437-2804-450e-ab2f-56ab1c641346') = uuid;\n# id: 608818, crm: 59628809737\nSELECT * FROM activities WHERE uuid_to_bin('36b06e55-afdd-4782-8dee-c624cd0af191') = uuid;\n# id: 608821, crm: 59632069252\nSELECT ce.start_time, ce.end_time, a.id, a.uuid, crm_provider_id, calendar_event_id, title,\nplaybook_category_id, user_id, lead_id, contact_id, account_id, opportunity_id,\nscheduled_start_time, scheduled_end_time, actual_start_time, actual_end_time, a.created_at\nFROM activities a\njoin calendar_events ce on a.calendar_event_id = ce.id\nWHERE a.id IN (608818, 608821);\n\nselect * from users where team_id = 1;\nselect * from team_settings where team_id = 1;\nselect * from crm_profiles where crm_configuration_id = 39 order by user_id;\n\nselect * from team_features where team_id = 1;\n\nselect * from users where team_id = 2;\n\nSELECT * FROM activities WHERE uuid_to_bin('ec7647e9-5225-458b-b475-f31aa2769204') = uuid; # 612639\n# Preslava N. Ivanova, grou id 3\n\nSELECT * FROM opportunities WHERE uuid_to_bin('a2928fe5-aec5-46cb-85d9-7654c89e46a6') = uuid;\n\nselect * from activities where opportunity_id = 344 and actual_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00';\n\nselect\n a.id,\n a.type,\n a.scheduled_start_time,\n a.actual_start_time,\n a.created_at,\n a.opportunity_id,\n a.status\nFROM activities a\nWHERE opportunity_id = 344\nand status IN ('completed', 'received', 'delivered')\nand (\n (a.actual_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00')\nOR (a.created_at between '2024-10-11 00:00:00' and '2024-10-12 00:00:00')\nOR (a.scheduled_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00'))\n;\n\nSELECT * FROM users WHERE id = 222;\n\nSELECT * FROM crm_profiles WHERE user_id = 222;\nselect * from crm_layouts where crm_configuration_id = 39;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 281;\n\nselect * from group_deal_risk_types;\n\nselect * from opportunities where team_id = 1;\n\nSELECT * FROM opportunities WHERE id = 315;\nSELECT * FROM crm_field_data WHERE object_id = 315;\nselect * from crm_field_data where object_id = 260;\n\nselect * from generic_ai_prompts where subject_id = 315;\n\nselect * from teams; # 36, 21, 121, james.graham@bullhorn.jiminny.com\nSELECT * FROM social_accounts WHERE sociable_id = 121 and provider = 'bullhorn';\n\n# ************************************************************************************\nselect * from teams where id = 1;\nselect * from crm_configurations where id = 39;\nselect * from users where team_id = 1;\nselect u.email, cp.* from users u\njoin crm_profiles cp on u.id = cp.user_id\nwhere u.team_id = 1;\n# 1 - 00541000004281rAAA\n# 204 - 0052g000003freeAAA\n# 429 - 0052g000003qGOiAAM\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 1\nand sa.provider = 'salesforce';\n\nselect * from activities where type = 'softphone'\nand created_at > '2024-12-11 15:24:36' order by id desc;\n\nselect * from activity_providers where team_id = 1;\nselect * from activity_provider_users where activity_provider_id = 328;\n\nselect * from opportunities where crm_configuration_id = 39\nAND account_id = 178 AND is_closed = false\norder by created_at DESC;\n\nselect * from contacts where id = 3952;\nselect * from accounts where id = 178;\n\n# ************************************************************************************\nselect * from teams where id = 36;\nselect * from crm_configurations where id = 21;\nselect * from users where team_id = 36;\nselect u.email, cp.* from users u\njoin crm_profiles cp on u.id = cp.user_id\nwhere u.team_id = 36;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 36\nand sa.provider = 'bullhorn';\n\nselect * from social_accounts where id = 348;\nUPDATE social_accounts SET\nprovider_user_token = '21442_6802599_91:41179a58-21e7-4d7c-ad58-56bb666b2f65',\nprovider_refresh_token = '21442_6802599_91:01c6b335-3f2a-42e4-85ff-8a08fa65fceb',\nexpires = 1733998131,\nstate = 'connected'\nWHERE id = 348;\n\n# ************************************************************************************\nselect * from teams where id = 31;\nselect * from crm_configurations where id = 18;\n\nselect * from users where team_id = 31; # 257\nselect u.email, cp.* from users u\njoin crm_profiles cp on u.id = cp.user_id\nwhere u.team_id = 31;\n\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 31\nand sa.provider = 'close';\n\nselect * from contacts where crm_configuration_id = 18;\n\n# ********************** NEPTUNE **************************************************************\nselect * from teams;\nselect * from users where id IN (1030, 1035, 1052);\nselect * from crm_configurations;\n\nselect * from users where team_id = 65; # 257\nselect * from team_settings where team_id = 65; # 257\nselect * from invitations where team_id = 65; # 257\nselect * from users where email = 'integration-account@jiminny.com'; # 257\nselect u.email, cp.* from users u\njoin crm_profiles cp on u.id = cp.user_id\nwhere u.team_id = 65;\n\nselect * from crm_configurations where id = 53;\nselect * from accounts where crm_configuration_id = 53 order by id desc;\nselect * from leads where crm_configuration_id = 53 order by id desc;\nselect * from contacts where crm_configuration_id = 53 order by id desc;\nselect * from opportunities where crm_configuration_id = 53 order by id desc;\nselect * from crm_profiles where crm_configuration_id = 53 order by id desc;\nselect * from crm_fields where crm_configuration_id = 53 order by id desc;\nselect * from crm_field_values where crm_field_id = 3341 order by id desc;\nselect * from crm_layouts where crm_configuration_id = 53 order by id desc;\nselect * from stages where crm_configuration_id = 53 order by id desc;\n\n\nselect * from crm_profiles where crm_configuration_id = 13;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 65\nand sa.provider = 'integration-app';\n\nselect * from contacts where crm_configuration_id = 13;\n\nselect * from social_accounts where sociable_id = 283;\n\nSELECT * FROM opportunities WHERE crm_provider_id = '006O400000E9bzeIAB';\n\nselect * from activity_providers where team_id = 65;\nSELECT * FROM activities WHERE crm_configuration_id IN (51, 52, 53);\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 65\n;\n\n# ***************************** STAGING ********************************************\nSELECT * FROM teams;\nSELECT * FROM teams WHERE id = 88;\nSELECT * FROM teams WHERE id = 89;\nselect * from team_settings where team_id = 89;\nSELECT * FROM users WHERE team_id = 89;\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 89;\n\nselect * from users;\nSELECT * FROM social_accounts WHERE sociable_id = 1761;\nSELECT * FROM crm_configurations WHERE id = 70;\nselect * from accounts where crm_configuration_id = 70 order by id desc;\nselect * from leads where crm_configuration_id = 70 order by id desc;\nselect * from contacts where crm_configuration_id = 70 order by id desc;\nselect * from opportunities where crm_configuration_id = 70 order by id desc;\nselect * from crm_profiles where crm_configuration_id = 70 order by id desc;\nselect * from crm_fields where crm_configuration_id = 70 order by id desc;\nselect * from crm_field_values where crm_field_id = 3536 order by id desc;\nselect * from crm_layouts where crm_configuration_id = 70 order by id desc;\nselect * from stages where crm_configuration_id = 70 order by id desc;\nselect * from business_processes where crm_configuration_id = 70 order by id desc;\nselect * from business_process_stages where business_process_id = 34;\n\nselect * from contacts where id = 10468;\n\nselect * from crm_layouts where crm_configuration_id = 70;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 388;\nSELECT * FROM crm_fields WHERE id IN (3533,3534,3535);\n\nselect * from activities where crm_configuration_id = 70\nand (account_id IS NOT NULL or lead_id IS NOT NULL or contact_id IS NOT NULL or opportunity_id IS NOT NULL) order by id desc;\n\nSELECT * FROM activities WHERE uuid_to_bin('2e10b60f-8a61-41c5-a3d4-28835353dc65') = uuid;\nSELECT * FROM activities where crm_configuration_id = 69 ;\n\nSELECT * FROM users WHERE email LIKE '%jiminny_web_sa2@jiminny.com%';\nSELECT * FROM activities WHERE uuid_to_bin('5a150c93-40fc-42ec-b3bd-c1d328e09f6e') = uuid;\nSELECT * FROM opportunities WHERE id = 385;\n\nselect * from participants p\njoin activities a on p.activity_id = a.id\nwhere a.crm_configuration_id = 70\nand (p.lead_id IS NOT NULL or p.contact_id IS NOT NULL);\nSELECT * FROM participants WHERE id = 1013638;\n\nselect * from teams where id = 90;\nselect * from users where team_id = 90;\nselect * from social_accounts where social_accounts.sociable_id IN (1960,1760);\nSELECT * FROM crm_profiles WHERE crm_configuration_id = 71;\nselect * from invitations where team_id = 90;\n\nselect * from crm_configurations where id = 71;\nselect * from accounts where crm_configuration_id = 71 order by id desc;\nselect * from leads where crm_configuration_id = 71 order by id desc;\nselect * from contacts where crm_configuration_id = 71 order by id desc;\nselect * from opportunities where crm_configuration_id = 71 order by id desc;\nselect * from crm_profiles where crm_configuration_id = 71 order by id desc;\nselect * from crm_fields where crm_configuration_id = 71 order by id desc;\nselect * from crm_field_values where crm_field_id = 3341 order by id desc;\nselect * from crm_layouts where crm_configuration_id = 71 order by id desc;\nselect * from stages where crm_configuration_id = 71 order by id desc;\n\nselect * from users order by secondary_email desc;\nselect u.id, u.email, u.status, sa.id, sa.provider_user_id from social_accounts sa\n join users u on sa.sociable_id = u.id\nwhere sa.provider = 'google' and u.email LIKE 'aneliya%';\n\nselect * from failed_jobs order by id desc;\n\nselect * from users where email = 'ben.allwright@learningpeople.co.uk' or secondary_email = 'ben.allwright@learningpeople.co.uk';\n\nselect * from teams;\nSELECT * FROM crm_profiles WHERE crm_configuration_id = 39;\nSELECT * FROM crm_fields WHERE crm_configuration_id = 39 and object_type = 'task';\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 1\nand sa.provider = 'salesforce';\n\n# ************************************************************************************\nSELECT * FROM activities WHERE uuid_to_bin('c38b3895-fd0f-4b1f-9fb2-c170dba137c6') = uuid;\nSELECT * FROM crm_configurations WHERE id = 70;\n\nselect * from teams where id = 1;\nselect * from groups where team_id = 1;\nselect * from users where team_id = 1;\n\nselect o.id, o.name,o.close_date, u.id, u.name, u.group_id, r.id, r.display_name, g.name, g.scope from opportunities o\njoin users u on o.user_id = u.id\njoin groups g on u.group_id = g.id\njoin role_user ru on u.id = ru.user_id\njoin roles r on ru.role_id = r.id\nwhere o.crm_configuration_id = 39 and close_date > '2024-01-01 00:00:00';\n\nselect * from role_user where user_id = 143;\nselect * from roles;\n\nselect * from role_user;\nselect * from groups where id = 9;\nselect * from scope_groups where group_id = 9;\n\n# ************************************************************************************\nselect * from teams where id = 36;\nselect * from crm_configurations;\nSELECT * FROM social_accounts WHERE sociable_id = 121;\n\nhttps://crmsandbox.zoho.com/crm/jiminnyw4/tab/Leads/4776201000005049105\nhttps://crmsandbox.zoho.com/crm/\n\nhttps://crm.zoho.com/crm/org3469620/tab/Leads/230045000229559080\n https://crm.zoho.com/crm/\n org3469620\n\nSELECT * FROM activities WHERE uuid_to_bin('03382d20-c8bc-48e7-a3d4-90b52fa5ceab') = uuid;\n\nselect * from users where email LIKE \"%mobile_automation_%\";\nselect * from social_accounts where sociable_id IN (2228);\nselect * from crm_profiles where user_id IN (2222,2223,2226,2227);\n\nselect * from teams order by id desc;\nSELECT * FROM users WHERE id = 2229;\nSELECT * FROM crm_profiles WHERE user_id = 2229;\nselect * from opportunities where crm_configuration_id = 88;\nselect * from crm_fields where crm_configuration_id = 88;\nselect * from crm_profiles where crm_configuration_id = 88;\n\nSELECT * FROM teams WHERE id = 1;\n\nSELECT * FROM users WHERE id = 143;\nSELECT * FROM users WHERE uuid_to_bin('fde193d3-06a2-4e1a-8895-62b94039215d') = uuid;\nSELECT * FROM teams WHERE uuid_to_bin('73385071-a756-42ae-9c73-8b53f2309467') = uuid;\n\nhttps://app.staging.jiminny.com/ondemand?\n min_duration=1\n &\n only_recorded=1\n &\n user_id%5B%5D=641f1acb-16b8-42d1-8726-df52979dad0e\n &\n sequence_number=2\n\n select * from users where team_id = 1 and email like '%stoyan%'\n\nselect * from coaching_feedbacks;\n\nselect * from teams;\nSELECT * FROM users WHERE team_id = 36;\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 19\nand sa.provider = 'pipedrive';\n\nselect * from users where id = 143;\n\nSELECT * FROM users WHERE uuid_to_bin('73180eeb-33de-4065-977d-ccbe0e6c94fc') = uuid;\nSELECT * FROM teams WHERE uuid_to_bin('73180eeb-33de-4065-977d-ccbe0e6c94fc') = uuid;\nSELECT * FROM activity_shares WHERE uuid_to_bin('73180eeb-33de-4065-977d-ccbe0e6c94fc') = uuid;\n\nselect * from users where team_id = 2;\nselect * from activities where crm_configuration_id = 39\nand activities.scheduled_start_time BETWEEN '2025-04-09 00:00:00' AND '2025-04-09 23:59:59'\nAND user_id = 143\norder by id desc;\n\n# ************************************************************************************\nselect * from teams where id = 142; # 2312, 126\nselect * from team_settings;\nselect * from users where team_id = 142; # 21642\nSELECT * FROM social_accounts WHERE sociable_id = 21642;\nSELECT * FROM crm_profiles cp join users u ON u.id = cp.user_id WHERE team_id = 142;\nselect * from crm_profiles where id IN (93);\nselect * from invitations;\nselect * from team_features where team_id = 1;\n\nSELECT * FROM crm_configurations WHERE id = 126;\nselect * from accounts where crm_configuration_id = 126 order by id desc;\nselect * from leads where crm_configuration_id = 126 order by id desc;\nselect * from contacts where crm_configuration_id = 126 order by id desc;\nselect * from opportunities where crm_configuration_id = 126 order by id desc;\nselect * from crm_profiles where crm_configuration_id = 126 order by id desc;\nselect * from crm_fields where crm_configuration_id = 126 # 11060\n# and type IN ('picklist', 'status')\n# and object_type = 'task'\norder by id desc;\n# 5731,5732,5733\nselect DISTINCT crm_field_id from crm_field_values where crm_field_id IN (11151,12239,12215,12185,12175,12165,12144,12137,12127,12109,12107,12105,12103,12092,12037,12005,12003,11987,11969,11958,11951,11942,11931,11924,11921,11917,11915,11901,11893,11883,11872,11870,11868,11866,11839,11833,11821,11793,11780,11777,11769,11757,11737,11735,11656,11645,11638,11629,11618,11611,11602,11591,11584,11581,11558,11544,11543,11534,11532,11529,11527,11503,11497,11493,11488,11470,11468,11457,11455,11397,11387,11372,11363,11348,11323,11318,11309,11301,11300,11292,11290,11286,11284,11256,11252,11242,11237,11233,11219,11176,11160) order by id desc;\nselect * from crm_layouts where crm_configuration_id = 126 order by id desc;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id in (300,299,298);\nselect * from stages where crm_configuration_id = 126 order by id desc;\nselect * from business_processes where crm_configuration_id = 126 order by id desc;\nselect * from business_process_stages where business_process_id IN (76,75,74,73);\nselect * from playbooks where team_id = 142;\nselect * from playbook_layouts where playbook_id IN (108);\nSELECT * FROM playbook_categories WHERE playbook_id IN (108);\n\nselect * from teams where id = 130;\nSELECT * FROM social_accounts WHERE sociable_id = 2291;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 2\nand sa.provider = 'hubspot';\n\nSELECT * FROM activities\n WHERE crm_configuration_id = 110;\n\nselect * from teams;\nselect * from crm_configurations;\n\nSELECT * FROM activities WHERE id = 628773;\nSELECT * FROM crm_profiles WHERE user_id = 1460;\nSELECT * FROM social_accounts WHERE sociable_id = 2291;\n\nselect * from teams;\nselect ru.*, pr.*, p.* from users u join role_user ru on ru.user_id = u.id\njoin permission_role pr on pr.role_id = ru.role_id\n join permissions p on p.id = pr.permission_id\nwhere team_id = 495 and p.name IN ('dial');\n\nselect * from teams where id = 145;\nselect * from crm_configurations where id = 129;\nselect * from social_accounts where sociable_id = 2317;\nSELECT * FROM activities WHERE uuid_to_bin('8dbab184-a333-4268-ad57-fb41f8d53a9a') = uuid;\n\nselect * from teams where id = 1;\nSELECT * FROM crm_layouts WHERE crm_configuration_id = 39;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 280;\nSELECT * FROM crm_layout_entities WHERE id = 5507;\nSELECT * FROM crm_fields WHERE crm_configuration_id = 39 and object_type IN ('event');\n\nselect * from teams;\nselect * from activities where crm_configuration_id = 14;\n\nSELECT * FROM social_accounts where provider = 'copper';\n\nselect * from activities where id = 628467;\nselect * from participants where activity_id = 628467;\n\nSELECT * FROM contacts WHERE id = 3969;\nSELECT * FROM accounts WHERE id = 177;\n\nSELECT * FROM activities WHERE uuid_to_bin('4eb54c77-cfa3-2bd4-84a7-9ed46a21c988') = uuid;\n\n# ********************* BH\nselect * from teams where id = 36;\nSELECT * FROM crm_configurations WHERE id = 21;\nselect * from activities where crm_configuration_id = 21 and id = 607901;\nselect * from activities where crm_configuration_id = 21;\n\nselect * roles;\nselect * from permissions;\nselect * from permission_role where permission_id = 226;\n\nselect * from migrations order by id desc;\n\n# mercury\n# neptune\n# earth\n\nselect * from teams;\nselect * from teams where id = 19;\nselect * from teams where id = 27;\nselect * from users where team_id = 27;\nSELECT * FROM crm_configurations WHERE id = 42;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 19\nand sa.provider = 'pipedrive';\n\nselect * from activities where id = 631461;\nSELECT * FROM crm_field_values WHERE crm_field_id = 180;\n\nselect * from teams where id = 2;\nSELECT * FROM social_accounts WHERE sociable_id = 89;\n\nSELECT * FROM activities WHERE uuid_to_bin('ba0c029a-bc14-4e17-8603-64174acebcbb') = uuid; # 634273\nselect * from activity_summary_logs where activity_id = 634273;\n\nselect * from sidekick_settings where team_id = 2;\n\nselect * from teams; # 2, 2\nSELECT * FROM crm_configurations WHERE team_id = 2; # 2\nselect * from team_features where team_id = 2;\nselect * from features;\nSELECT * FROM opportunities WHERE crm_configuration_id = 2 and crm_provider_id = '51317301383';\nSELECT * FROM opportunities WHERE crm_configuration_id = 2 order by id desc;\n\nselect * from automated_reports order by id desc;\nselect * from automated_report_results order by id desc;\nselect * from users where team_id = 1 and id IN (7160, 3248);\nselect * from migrations order by id desc;\n\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 1 and sa.provider = 'salesforce';\n\nselect * from teams where id = 1;\nselect * from groups g JOIN playbooks p on g.playbook_id = p.id where g.team_id = 1;\nselect * from groups where id = 565;\nselect * from playbooks where team_id = 1;\nselect * from playbooks where id = 175;\nselect * from playbook_categories where playbook_id = 175;\nselect * from users where team_id = 1;\nselect * from users where id = 7160;\nselect * from crm_profiles where user_id = 7160;\nselect * from features;\nselect\n *\n# id, uuid, type, provider, playbook_category_id, user_id, lead_id, contact_id, account_id, opportunity_id, stage_id,\n# crm_configuration_id, crm_provider_id, transcription_id, status\nfrom activities where crm_configuration_id = 1 and type = 'conference'\n# and crm_provider_id IS NOT NULL\nand provider != 'uploader' and actual_start_time IS NOT NULL\nORDER by id desc;\nselect * from activities where id = 54747783; # 00UO400000pCzojMAC\n\nselect p.id, p.activity_type, pc.id, pc.name\nFROM playbooks p\njoin playbook_categories pc on p.id = pc.playbook_id\nwhere p.team_id = 1 and p.activity_type = 'event';\n\nSELECT * FROM crm_fields WHERE crm_configuration_id = 1 and object_type = 'event';\nSELECT * FROM crm_field_values WHERE crm_field_id = 4;\n\nselect * from crm_layouts cl join playbook_layouts pl on cl.id = pl.layout_id\nwhere crm_configuration_id = 1 and pl.playbook_id = 175;\n\nselect * from teams;\nSELECT r.* FROM automated_reports r\njoin teams t on r.team_id = t.id\nWHERE r.frequency = 'daily'\n and r.status = 1\nAND t.status = 'active'\nAND (r.expires_at >= now() OR r.expires_at IS NULL);\n\nselect * from automated_report_results where report_id IN (18, 33);\n\nselect * from activity_searches where id = 10932;\nselect * from activity_search_filters where activity_search_id = 10932;\nselect * from automated_reports;\nselect * from automated_report_results where report_id IN (34, 35);","depth":4,"value":"SELECT * FROM teams WHERE id = 1;\n\nselect * from crm_layouts where crm_configuration_id = 39;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 283;\nSELECT * FROM crm_fields WHERE id = 2234;\nSELECT * FROM crm_field_values WHERE crm_field_id = 2234;\n\nselect * from crm_profiles where user_id = 143;\n\nselect * from record_types where crm_configuration_id = 39; # 0121K000001MHElQAO,0121K000001MHEqQAO\nselect * from business_processes where crm_configuration_id = 39;\n# 01941000000H669AAC, 01941000000H66JAAS\n\nselect * from record_type_field_values\n where record_type_id IN (24);\n\nselect * from crm_field_values where id IN (2730);\n\nselect * from crm_configurations where id = 39;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 1\nand sa.provider = 'salesforce'; #1035\n\n\nselect * from users where team_id = 1; # 222 group 3\nSELECT * FROM activities WHERE user_id = 222 order by id desc;\nselect * from sidekick_settings where team_id = 1;\nselect * from teams where id = 1;\nselect * from team_features where team_id = 1;\n\nselect * from activities where crm_configuration_id = 2\nand provider = 'ms-teams' and id = 608765;\n\nSELECT * FROM activities WHERE crm_configuration_id = 2 and crm_provider_id = '59523413338';\n\nselect * from sidekick_settings where team_id = 2;\n\nSELECT * FROM activities WHERE id = 608660;\nselect * from activity_summary_logs where activity_id = 608660;\nselect * from ai_prompts where transcription_id = 11214;\n\n# ********************************************************************************************************\nSELECT * FROM activities WHERE uuid_to_bin('ed78a437-2804-450e-ab2f-56ab1c641346') = uuid;\n# id: 608818, crm: 59628809737\nSELECT * FROM activities WHERE uuid_to_bin('36b06e55-afdd-4782-8dee-c624cd0af191') = uuid;\n# id: 608821, crm: 59632069252\nSELECT ce.start_time, ce.end_time, a.id, a.uuid, crm_provider_id, calendar_event_id, title,\nplaybook_category_id, user_id, lead_id, contact_id, account_id, opportunity_id,\nscheduled_start_time, scheduled_end_time, actual_start_time, actual_end_time, a.created_at\nFROM activities a\njoin calendar_events ce on a.calendar_event_id = ce.id\nWHERE a.id IN (608818, 608821);\n\nselect * from users where team_id = 1;\nselect * from team_settings where team_id = 1;\nselect * from crm_profiles where crm_configuration_id = 39 order by user_id;\n\nselect * from team_features where team_id = 1;\n\nselect * from users where team_id = 2;\n\nSELECT * FROM activities WHERE uuid_to_bin('ec7647e9-5225-458b-b475-f31aa2769204') = uuid; # 612639\n# Preslava N. Ivanova, grou id 3\n\nSELECT * FROM opportunities WHERE uuid_to_bin('a2928fe5-aec5-46cb-85d9-7654c89e46a6') = uuid;\n\nselect * from activities where opportunity_id = 344 and actual_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00';\n\nselect\n a.id,\n a.type,\n a.scheduled_start_time,\n a.actual_start_time,\n a.created_at,\n a.opportunity_id,\n a.status\nFROM activities a\nWHERE opportunity_id = 344\nand status IN ('completed', 'received', 'delivered')\nand (\n (a.actual_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00')\nOR (a.created_at between '2024-10-11 00:00:00' and '2024-10-12 00:00:00')\nOR (a.scheduled_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00'))\n;\n\nSELECT * FROM users WHERE id = 222;\n\nSELECT * FROM crm_profiles WHERE user_id = 222;\nselect * from crm_layouts where crm_configuration_id = 39;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 281;\n\nselect * from group_deal_risk_types;\n\nselect * from opportunities where team_id = 1;\n\nSELECT * FROM opportunities WHERE id = 315;\nSELECT * FROM crm_field_data WHERE object_id = 315;\nselect * from crm_field_data where object_id = 260;\n\nselect * from generic_ai_prompts where subject_id = 315;\n\nselect * from teams; # 36, 21, 121, james.graham@bullhorn.jiminny.com\nSELECT * FROM social_accounts WHERE sociable_id = 121 and provider = 'bullhorn';\n\n# ************************************************************************************\nselect * from teams where id = 1;\nselect * from crm_configurations where id = 39;\nselect * from users where team_id = 1;\nselect u.email, cp.* from users u\njoin crm_profiles cp on u.id = cp.user_id\nwhere u.team_id = 1;\n# 1 - 00541000004281rAAA\n# 204 - 0052g000003freeAAA\n# 429 - 0052g000003qGOiAAM\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 1\nand sa.provider = 'salesforce';\n\nselect * from activities where type = 'softphone'\nand created_at > '2024-12-11 15:24:36' order by id desc;\n\nselect * from activity_providers where team_id = 1;\nselect * from activity_provider_users where activity_provider_id = 328;\n\nselect * from opportunities where crm_configuration_id = 39\nAND account_id = 178 AND is_closed = false\norder by created_at DESC;\n\nselect * from contacts where id = 3952;\nselect * from accounts where id = 178;\n\n# ************************************************************************************\nselect * from teams where id = 36;\nselect * from crm_configurations where id = 21;\nselect * from users where team_id = 36;\nselect u.email, cp.* from users u\njoin crm_profiles cp on u.id = cp.user_id\nwhere u.team_id = 36;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 36\nand sa.provider = 'bullhorn';\n\nselect * from social_accounts where id = 348;\nUPDATE social_accounts SET\nprovider_user_token = '21442_6802599_91:41179a58-21e7-4d7c-ad58-56bb666b2f65',\nprovider_refresh_token = '21442_6802599_91:01c6b335-3f2a-42e4-85ff-8a08fa65fceb',\nexpires = 1733998131,\nstate = 'connected'\nWHERE id = 348;\n\n# ************************************************************************************\nselect * from teams where id = 31;\nselect * from crm_configurations where id = 18;\n\nselect * from users where team_id = 31; # 257\nselect u.email, cp.* from users u\njoin crm_profiles cp on u.id = cp.user_id\nwhere u.team_id = 31;\n\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 31\nand sa.provider = 'close';\n\nselect * from contacts where crm_configuration_id = 18;\n\n# ********************** NEPTUNE **************************************************************\nselect * from teams;\nselect * from users where id IN (1030, 1035, 1052);\nselect * from crm_configurations;\n\nselect * from users where team_id = 65; # 257\nselect * from team_settings where team_id = 65; # 257\nselect * from invitations where team_id = 65; # 257\nselect * from users where email = 'integration-account@jiminny.com'; # 257\nselect u.email, cp.* from users u\njoin crm_profiles cp on u.id = cp.user_id\nwhere u.team_id = 65;\n\nselect * from crm_configurations where id = 53;\nselect * from accounts where crm_configuration_id = 53 order by id desc;\nselect * from leads where crm_configuration_id = 53 order by id desc;\nselect * from contacts where crm_configuration_id = 53 order by id desc;\nselect * from opportunities where crm_configuration_id = 53 order by id desc;\nselect * from crm_profiles where crm_configuration_id = 53 order by id desc;\nselect * from crm_fields where crm_configuration_id = 53 order by id desc;\nselect * from crm_field_values where crm_field_id = 3341 order by id desc;\nselect * from crm_layouts where crm_configuration_id = 53 order by id desc;\nselect * from stages where crm_configuration_id = 53 order by id desc;\n\n\nselect * from crm_profiles where crm_configuration_id = 13;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 65\nand sa.provider = 'integration-app';\n\nselect * from contacts where crm_configuration_id = 13;\n\nselect * from social_accounts where sociable_id = 283;\n\nSELECT * FROM opportunities WHERE crm_provider_id = '006O400000E9bzeIAB';\n\nselect * from activity_providers where team_id = 65;\nSELECT * FROM activities WHERE crm_configuration_id IN (51, 52, 53);\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 65\n;\n\n# ***************************** STAGING ********************************************\nSELECT * FROM teams;\nSELECT * FROM teams WHERE id = 88;\nSELECT * FROM teams WHERE id = 89;\nselect * from team_settings where team_id = 89;\nSELECT * FROM users WHERE team_id = 89;\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 89;\n\nselect * from users;\nSELECT * FROM social_accounts WHERE sociable_id = 1761;\nSELECT * FROM crm_configurations WHERE id = 70;\nselect * from accounts where crm_configuration_id = 70 order by id desc;\nselect * from leads where crm_configuration_id = 70 order by id desc;\nselect * from contacts where crm_configuration_id = 70 order by id desc;\nselect * from opportunities where crm_configuration_id = 70 order by id desc;\nselect * from crm_profiles where crm_configuration_id = 70 order by id desc;\nselect * from crm_fields where crm_configuration_id = 70 order by id desc;\nselect * from crm_field_values where crm_field_id = 3536 order by id desc;\nselect * from crm_layouts where crm_configuration_id = 70 order by id desc;\nselect * from stages where crm_configuration_id = 70 order by id desc;\nselect * from business_processes where crm_configuration_id = 70 order by id desc;\nselect * from business_process_stages where business_process_id = 34;\n\nselect * from contacts where id = 10468;\n\nselect * from crm_layouts where crm_configuration_id = 70;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 388;\nSELECT * FROM crm_fields WHERE id IN (3533,3534,3535);\n\nselect * from activities where crm_configuration_id = 70\nand (account_id IS NOT NULL or lead_id IS NOT NULL or contact_id IS NOT NULL or opportunity_id IS NOT NULL) order by id desc;\n\nSELECT * FROM activities WHERE uuid_to_bin('2e10b60f-8a61-41c5-a3d4-28835353dc65') = uuid;\nSELECT * FROM activities where crm_configuration_id = 69 ;\n\nSELECT * FROM users WHERE email LIKE '%jiminny_web_sa2@jiminny.com%';\nSELECT * FROM activities WHERE uuid_to_bin('5a150c93-40fc-42ec-b3bd-c1d328e09f6e') = uuid;\nSELECT * FROM opportunities WHERE id = 385;\n\nselect * from participants p\njoin activities a on p.activity_id = a.id\nwhere a.crm_configuration_id = 70\nand (p.lead_id IS NOT NULL or p.contact_id IS NOT NULL);\nSELECT * FROM participants WHERE id = 1013638;\n\nselect * from teams where id = 90;\nselect * from users where team_id = 90;\nselect * from social_accounts where social_accounts.sociable_id IN (1960,1760);\nSELECT * FROM crm_profiles WHERE crm_configuration_id = 71;\nselect * from invitations where team_id = 90;\n\nselect * from crm_configurations where id = 71;\nselect * from accounts where crm_configuration_id = 71 order by id desc;\nselect * from leads where crm_configuration_id = 71 order by id desc;\nselect * from contacts where crm_configuration_id = 71 order by id desc;\nselect * from opportunities where crm_configuration_id = 71 order by id desc;\nselect * from crm_profiles where crm_configuration_id = 71 order by id desc;\nselect * from crm_fields where crm_configuration_id = 71 order by id desc;\nselect * from crm_field_values where crm_field_id = 3341 order by id desc;\nselect * from crm_layouts where crm_configuration_id = 71 order by id desc;\nselect * from stages where crm_configuration_id = 71 order by id desc;\n\nselect * from users order by secondary_email desc;\nselect u.id, u.email, u.status, sa.id, sa.provider_user_id from social_accounts sa\n join users u on sa.sociable_id = u.id\nwhere sa.provider = 'google' and u.email LIKE 'aneliya%';\n\nselect * from failed_jobs order by id desc;\n\nselect * from users where email = 'ben.allwright@learningpeople.co.uk' or secondary_email = 'ben.allwright@learningpeople.co.uk';\n\nselect * from teams;\nSELECT * FROM crm_profiles WHERE crm_configuration_id = 39;\nSELECT * FROM crm_fields WHERE crm_configuration_id = 39 and object_type = 'task';\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 1\nand sa.provider = 'salesforce';\n\n# ************************************************************************************\nSELECT * FROM activities WHERE uuid_to_bin('c38b3895-fd0f-4b1f-9fb2-c170dba137c6') = uuid;\nSELECT * FROM crm_configurations WHERE id = 70;\n\nselect * from teams where id = 1;\nselect * from groups where team_id = 1;\nselect * from users where team_id = 1;\n\nselect o.id, o.name,o.close_date, u.id, u.name, u.group_id, r.id, r.display_name, g.name, g.scope from opportunities o\njoin users u on o.user_id = u.id\njoin groups g on u.group_id = g.id\njoin role_user ru on u.id = ru.user_id\njoin roles r on ru.role_id = r.id\nwhere o.crm_configuration_id = 39 and close_date > '2024-01-01 00:00:00';\n\nselect * from role_user where user_id = 143;\nselect * from roles;\n\nselect * from role_user;\nselect * from groups where id = 9;\nselect * from scope_groups where group_id = 9;\n\n# ************************************************************************************\nselect * from teams where id = 36;\nselect * from crm_configurations;\nSELECT * FROM social_accounts WHERE sociable_id = 121;\n\nhttps://crmsandbox.zoho.com/crm/jiminnyw4/tab/Leads/4776201000005049105\nhttps://crmsandbox.zoho.com/crm/\n\nhttps://crm.zoho.com/crm/org3469620/tab/Leads/230045000229559080\n https://crm.zoho.com/crm/\n org3469620\n\nSELECT * FROM activities WHERE uuid_to_bin('03382d20-c8bc-48e7-a3d4-90b52fa5ceab') = uuid;\n\nselect * from users where email LIKE \"%mobile_automation_%\";\nselect * from social_accounts where sociable_id IN (2228);\nselect * from crm_profiles where user_id IN (2222,2223,2226,2227);\n\nselect * from teams order by id desc;\nSELECT * FROM users WHERE id = 2229;\nSELECT * FROM crm_profiles WHERE user_id = 2229;\nselect * from opportunities where crm_configuration_id = 88;\nselect * from crm_fields where crm_configuration_id = 88;\nselect * from crm_profiles where crm_configuration_id = 88;\n\nSELECT * FROM teams WHERE id = 1;\n\nSELECT * FROM users WHERE id = 143;\nSELECT * FROM users WHERE uuid_to_bin('fde193d3-06a2-4e1a-8895-62b94039215d') = uuid;\nSELECT * FROM teams WHERE uuid_to_bin('73385071-a756-42ae-9c73-8b53f2309467') = uuid;\n\nhttps://app.staging.jiminny.com/ondemand?\n min_duration=1\n &\n only_recorded=1\n &\n user_id%5B%5D=641f1acb-16b8-42d1-8726-df52979dad0e\n &\n sequence_number=2\n\n select * from users where team_id = 1 and email like '%stoyan%'\n\nselect * from coaching_feedbacks;\n\nselect * from teams;\nSELECT * FROM users WHERE team_id = 36;\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 19\nand sa.provider = 'pipedrive';\n\nselect * from users where id = 143;\n\nSELECT * FROM users WHERE uuid_to_bin('73180eeb-33de-4065-977d-ccbe0e6c94fc') = uuid;\nSELECT * FROM teams WHERE uuid_to_bin('73180eeb-33de-4065-977d-ccbe0e6c94fc') = uuid;\nSELECT * FROM activity_shares WHERE uuid_to_bin('73180eeb-33de-4065-977d-ccbe0e6c94fc') = uuid;\n\nselect * from users where team_id = 2;\nselect * from activities where crm_configuration_id = 39\nand activities.scheduled_start_time BETWEEN '2025-04-09 00:00:00' AND '2025-04-09 23:59:59'\nAND user_id = 143\norder by id desc;\n\n# ************************************************************************************\nselect * from teams where id = 142; # 2312, 126\nselect * from team_settings;\nselect * from users where team_id = 142; # 21642\nSELECT * FROM social_accounts WHERE sociable_id = 21642;\nSELECT * FROM crm_profiles cp join users u ON u.id = cp.user_id WHERE team_id = 142;\nselect * from crm_profiles where id IN (93);\nselect * from invitations;\nselect * from team_features where team_id = 1;\n\nSELECT * FROM crm_configurations WHERE id = 126;\nselect * from accounts where crm_configuration_id = 126 order by id desc;\nselect * from leads where crm_configuration_id = 126 order by id desc;\nselect * from contacts where crm_configuration_id = 126 order by id desc;\nselect * from opportunities where crm_configuration_id = 126 order by id desc;\nselect * from crm_profiles where crm_configuration_id = 126 order by id desc;\nselect * from crm_fields where crm_configuration_id = 126 # 11060\n# and type IN ('picklist', 'status')\n# and object_type = 'task'\norder by id desc;\n# 5731,5732,5733\nselect DISTINCT crm_field_id from crm_field_values where crm_field_id IN (11151,12239,12215,12185,12175,12165,12144,12137,12127,12109,12107,12105,12103,12092,12037,12005,12003,11987,11969,11958,11951,11942,11931,11924,11921,11917,11915,11901,11893,11883,11872,11870,11868,11866,11839,11833,11821,11793,11780,11777,11769,11757,11737,11735,11656,11645,11638,11629,11618,11611,11602,11591,11584,11581,11558,11544,11543,11534,11532,11529,11527,11503,11497,11493,11488,11470,11468,11457,11455,11397,11387,11372,11363,11348,11323,11318,11309,11301,11300,11292,11290,11286,11284,11256,11252,11242,11237,11233,11219,11176,11160) order by id desc;\nselect * from crm_layouts where crm_configuration_id = 126 order by id desc;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id in (300,299,298);\nselect * from stages where crm_configuration_id = 126 order by id desc;\nselect * from business_processes where crm_configuration_id = 126 order by id desc;\nselect * from business_process_stages where business_process_id IN (76,75,74,73);\nselect * from playbooks where team_id = 142;\nselect * from playbook_layouts where playbook_id IN (108);\nSELECT * FROM playbook_categories WHERE playbook_id IN (108);\n\nselect * from teams where id = 130;\nSELECT * FROM social_accounts WHERE sociable_id = 2291;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 2\nand sa.provider = 'hubspot';\n\nSELECT * FROM activities\n WHERE crm_configuration_id = 110;\n\nselect * from teams;\nselect * from crm_configurations;\n\nSELECT * FROM activities WHERE id = 628773;\nSELECT * FROM crm_profiles WHERE user_id = 1460;\nSELECT * FROM social_accounts WHERE sociable_id = 2291;\n\nselect * from teams;\nselect ru.*, pr.*, p.* from users u join role_user ru on ru.user_id = u.id\njoin permission_role pr on pr.role_id = ru.role_id\n join permissions p on p.id = pr.permission_id\nwhere team_id = 495 and p.name IN ('dial');\n\nselect * from teams where id = 145;\nselect * from crm_configurations where id = 129;\nselect * from social_accounts where sociable_id = 2317;\nSELECT * FROM activities WHERE uuid_to_bin('8dbab184-a333-4268-ad57-fb41f8d53a9a') = uuid;\n\nselect * from teams where id = 1;\nSELECT * FROM crm_layouts WHERE crm_configuration_id = 39;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 280;\nSELECT * FROM crm_layout_entities WHERE id = 5507;\nSELECT * FROM crm_fields WHERE crm_configuration_id = 39 and object_type IN ('event');\n\nselect * from teams;\nselect * from activities where crm_configuration_id = 14;\n\nSELECT * FROM social_accounts where provider = 'copper';\n\nselect * from activities where id = 628467;\nselect * from participants where activity_id = 628467;\n\nSELECT * FROM contacts WHERE id = 3969;\nSELECT * FROM accounts WHERE id = 177;\n\nSELECT * FROM activities WHERE uuid_to_bin('4eb54c77-cfa3-2bd4-84a7-9ed46a21c988') = uuid;\n\n# ********************* BH\nselect * from teams where id = 36;\nSELECT * FROM crm_configurations WHERE id = 21;\nselect * from activities where crm_configuration_id = 21 and id = 607901;\nselect * from activities where crm_configuration_id = 21;\n\nselect * roles;\nselect * from permissions;\nselect * from permission_role where permission_id = 226;\n\nselect * from migrations order by id desc;\n\n# mercury\n# neptune\n# earth\n\nselect * from teams;\nselect * from teams where id = 19;\nselect * from teams where id = 27;\nselect * from users where team_id = 27;\nSELECT * FROM crm_configurations WHERE id = 42;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 19\nand sa.provider = 'pipedrive';\n\nselect * from activities where id = 631461;\nSELECT * FROM crm_field_values WHERE crm_field_id = 180;\n\nselect * from teams where id = 2;\nSELECT * FROM social_accounts WHERE sociable_id = 89;\n\nSELECT * FROM activities WHERE uuid_to_bin('ba0c029a-bc14-4e17-8603-64174acebcbb') = uuid; # 634273\nselect * from activity_summary_logs where activity_id = 634273;\n\nselect * from sidekick_settings where team_id = 2;\n\nselect * from teams; # 2, 2\nSELECT * FROM crm_configurations WHERE team_id = 2; # 2\nselect * from team_features where team_id = 2;\nselect * from features;\nSELECT * FROM opportunities WHERE crm_configuration_id = 2 and crm_provider_id = '51317301383';\nSELECT * FROM opportunities WHERE crm_configuration_id = 2 order by id desc;\n\nselect * from automated_reports order by id desc;\nselect * from automated_report_results order by id desc;\nselect * from users where team_id = 1 and id IN (7160, 3248);\nselect * from migrations order by id desc;\n\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 1 and sa.provider = 'salesforce';\n\nselect * from teams where id = 1;\nselect * from groups g JOIN playbooks p on g.playbook_id = p.id where g.team_id = 1;\nselect * from groups where id = 565;\nselect * from playbooks where team_id = 1;\nselect * from playbooks where id = 175;\nselect * from playbook_categories where playbook_id = 175;\nselect * from users where team_id = 1;\nselect * from users where id = 7160;\nselect * from crm_profiles where user_id = 7160;\nselect * from features;\nselect\n *\n# id, uuid, type, provider, playbook_category_id, user_id, lead_id, contact_id, account_id, opportunity_id, stage_id,\n# crm_configuration_id, crm_provider_id, transcription_id, status\nfrom activities where crm_configuration_id = 1 and type = 'conference'\n# and crm_provider_id IS NOT NULL\nand provider != 'uploader' and actual_start_time IS NOT NULL\nORDER by id desc;\nselect * from activities where id = 54747783; # 00UO400000pCzojMAC\n\nselect p.id, p.activity_type, pc.id, pc.name\nFROM playbooks p\njoin playbook_categories pc on p.id = pc.playbook_id\nwhere p.team_id = 1 and p.activity_type = 'event';\n\nSELECT * FROM crm_fields WHERE crm_configuration_id = 1 and object_type = 'event';\nSELECT * FROM crm_field_values WHERE crm_field_id = 4;\n\nselect * from crm_layouts cl join playbook_layouts pl on cl.id = pl.layout_id\nwhere crm_configuration_id = 1 and pl.playbook_id = 175;\n\nselect * from teams;\nSELECT r.* FROM automated_reports r\njoin teams t on r.team_id = t.id\nWHERE r.frequency = 'daily'\n and r.status = 1\nAND t.status = 'active'\nAND (r.expires_at >= now() OR r.expires_at IS NULL);\n\nselect * from automated_report_results where report_id IN (18, 33);\n\nselect * from activity_searches where id = 10932;\nselect * from activity_search_filters where activity_search_id = 10932;\nselect * from automated_reports;\nselect * from automated_report_results where report_id IN (34, 35);","role_description":"text entry area","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false}]...
|
3567222476067194268
|
6686649022737200205
|
idle
|
accessibility
|
NULL
|
Project: faVsco.js, menu
#11894 on JY-18909-automa Project: faVsco.js, menu
#11894 on JY-18909-automated-reports-ask-jiminny, menu
Start Listening for PHP Debug Connections
AutomatedReportsCommandTest
Run 'AutomatedReportsCommandTest'
Debug 'AutomatedReportsCommandTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Execute
Explain Plan
Browse Query History
View Parameters
Open Query Execution Settings…
In-Editor Results
Tx: Auto
Cancel Running Statements
Playground
jiminny
Sync Changes
Hide This Notification
Code changed:
Hide
16
13
13
Previous Highlighted Error
Next Highlighted Error
SELECT * FROM teams WHERE id = 1;
select * from crm_layouts where crm_configuration_id = 39;
SELECT * FROM crm_layout_entities WHERE crm_layout_id = 283;
SELECT * FROM crm_fields WHERE id = 2234;
SELECT * FROM crm_field_values WHERE crm_field_id = 2234;
select * from crm_profiles where user_id = 143;
select * from record_types where crm_configuration_id = 39; # 0121K000001MHElQAO,0121K000001MHEqQAO
select * from business_processes where crm_configuration_id = 39;
# 01941000000H669AAC, 01941000000H66JAAS
select * from record_type_field_values
where record_type_id IN (24);
select * from crm_field_values where id IN (2730);
select * from crm_configurations where id = 39;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 1
and sa.provider = 'salesforce'; #1035
select * from users where team_id = 1; # 222 group 3
SELECT * FROM activities WHERE user_id = 222 order by id desc;
select * from sidekick_settings where team_id = 1;
select * from teams where id = 1;
select * from team_features where team_id = 1;
select * from activities where crm_configuration_id = 2
and provider = 'ms-teams' and id = 608765;
SELECT * FROM activities WHERE crm_configuration_id = 2 and crm_provider_id = '59523413338';
select * from sidekick_settings where team_id = 2;
SELECT * FROM activities WHERE id = 608660;
select * from activity_summary_logs where activity_id = 608660;
select * from ai_prompts where transcription_id = 11214;
# [PASSWORD_DOTS]
SELECT * FROM activities WHERE uuid_to_bin('ed78a437-2804-450e-ab2f-56ab1c641346') = uuid;
# id: 608818, crm: 59628809737
SELECT * FROM activities WHERE uuid_to_bin('36b06e55-afdd-4782-8dee-c624cd0af191') = uuid;
# id: 608821, crm: 59632069252
SELECT ce.start_time, ce.end_time, a.id, a.uuid, crm_provider_id, calendar_event_id, title,
playbook_category_id, user_id, lead_id, contact_id, account_id, opportunity_id,
scheduled_start_time, scheduled_end_time, actual_start_time, actual_end_time, a.created_at
FROM activities a
join calendar_events ce on a.calendar_event_id = ce.id
WHERE a.id IN (608818, 608821);
select * from users where team_id = 1;
select * from team_settings where team_id = 1;
select * from crm_profiles where crm_configuration_id = 39 order by user_id;
select * from team_features where team_id = 1;
select * from users where team_id = 2;
SELECT * FROM activities WHERE uuid_to_bin('ec7647e9-5225-458b-b475-f31aa2769204') = uuid; # 612639
# Preslava N. Ivanova, grou id 3
SELECT * FROM opportunities WHERE uuid_to_bin('a2928fe5-aec5-46cb-85d9-7654c89e46a6') = uuid;
select * from activities where opportunity_id = 344 and actual_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00';
select
a.id,
a.type,
a.scheduled_start_time,
a.actual_start_time,
a.created_at,
a.opportunity_id,
a.status
FROM activities a
WHERE opportunity_id = 344
and status IN ('completed', 'received', 'delivered')
and (
(a.actual_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00')
OR (a.created_at between '2024-10-11 00:00:00' and '2024-10-12 00:00:00')
OR (a.scheduled_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00'))
;
SELECT * FROM users WHERE id = 222;
SELECT * FROM crm_profiles WHERE user_id = 222;
select * from crm_layouts where crm_configuration_id = 39;
SELECT * FROM crm_layout_entities WHERE crm_layout_id = 281;
select * from group_deal_risk_types;
select * from opportunities where team_id = 1;
SELECT * FROM opportunities WHERE id = 315;
SELECT * FROM crm_field_data WHERE object_id = 315;
select * from crm_field_data where object_id = 260;
select * from generic_ai_prompts where subject_id = 315;
select * from teams; # 36, 21, 121, [EMAIL]
SELECT * FROM social_accounts WHERE sociable_id = 121 and provider = 'bullhorn';
# [PASSWORD_DOTS]
select * from teams where id = 1;
select * from crm_configurations where id = 39;
select * from users where team_id = 1;
select u.email, cp.* from users u
join crm_profiles cp on u.id = cp.user_id
where u.team_id = 1;
# 1 - 00541000004281rAAA
# 204 - 0052g000003freeAAA
# 429 - 0052g000003qGOiAAM
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 1
and sa.provider = 'salesforce';
select * from activities where type = 'softphone'
and created_at > '2024-12-11 15:24:36' order by id desc;
select * from activity_providers where team_id = 1;
select * from activity_provider_users where activity_provider_id = 328;
select * from opportunities where crm_configuration_id = 39
AND account_id = 178 AND is_closed = false
order by created_at DESC;
select * from contacts where id = 3952;
select * from accounts where id = 178;
# [PASSWORD_DOTS]
select * from teams where id = 36;
select * from crm_configurations where id = 21;
select * from users where team_id = 36;
select u.email, cp.* from users u
join crm_profiles cp on u.id = cp.user_id
where u.team_id = 36;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 36
and sa.provider = 'bullhorn';
select * from social_accounts where id = 348;
UPDATE social_accounts SET
provider_user_token = '21442_6802599_91:41179a58-21e7-4d7c-ad58-56bb666b2f65',
provider_refresh_token = '21442_6802599_91:01c6b335-3f2a-42e4-85ff-8a08fa65fceb',
expires = 1733998131,
state = 'connected'
WHERE id = 348;
# [PASSWORD_DOTS]
select * from teams where id = 31;
select * from crm_configurations where id = 18;
select * from users where team_id = 31; # 257
select u.email, cp.* from users u
join crm_profiles cp on u.id = cp.user_id
where u.team_id = 31;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 31
and sa.provider = 'close';
select * from contacts where crm_configuration_id = 18;
# [PASSWORD_DOTS] NEPTUNE [PASSWORD_DOTS]
select * from teams;
select * from users where id IN (1030, 1035, 1052);
select * from crm_configurations;
select * from users where team_id = 65; # 257
select * from team_settings where team_id = 65; # 257
select * from invitations where team_id = 65; # 257
select * from users where email = '[EMAIL]'; # 257
select u.email, cp.* from users u
join crm_profiles cp on u.id = cp.user_id
where u.team_id = 65;
select * from crm_configurations where id = 53;
select * from accounts where crm_configuration_id = 53 order by id desc;
select * from leads where crm_configuration_id = 53 order by id desc;
select * from contacts where crm_configuration_id = 53 order by id desc;
select * from opportunities where crm_configuration_id = 53 order by id desc;
select * from crm_profiles where crm_configuration_id = 53 order by id desc;
select * from crm_fields where crm_configuration_id = 53 order by id desc;
select * from crm_field_values where crm_field_id = 3341 order by id desc;
select * from crm_layouts where crm_configuration_id = 53 order by id desc;
select * from stages where crm_configuration_id = 53 order by id desc;
select * from crm_profiles where crm_configuration_id = 13;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 65
and sa.provider = 'integration-app';
select * from contacts where crm_configuration_id = 13;
select * from social_accounts where sociable_id = 283;
SELECT * FROM opportunities WHERE crm_provider_id = '006O400000E9bzeIAB';
select * from activity_providers where team_id = 65;
SELECT * FROM activities WHERE crm_configuration_id IN (51, 52, 53);
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 65
;
# [PASSWORD_DOTS] STAGING [PASSWORD_DOTS]
SELECT * FROM teams;
SELECT * FROM teams WHERE id = 88;
SELECT * FROM teams WHERE id = 89;
select * from team_settings where team_id = 89;
SELECT * FROM users WHERE team_id = 89;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 89;
select * from users;
SELECT * FROM social_accounts WHERE sociable_id = 1761;
SELECT * FROM crm_configurations WHERE id = 70;
select * from accounts where crm_configuration_id = 70 order by id desc;
select * from leads where crm_configuration_id = 70 order by id desc;
select * from contacts where crm_configuration_id = 70 order by id desc;
select * from opportunities where crm_configuration_id = 70 order by id desc;
select * from crm_profiles where crm_configuration_id = 70 order by id desc;
select * from crm_fields where crm_configuration_id = 70 order by id desc;
select * from crm_field_values where crm_field_id = 3536 order by id desc;
select * from crm_layouts where crm_configuration_id = 70 order by id desc;
select * from stages where crm_configuration_id = 70 order by id desc;
select * from business_processes where crm_configuration_id = 70 order by id desc;
select * from business_process_stages where business_process_id = 34;
select * from contacts where id = 10468;
select * from crm_layouts where crm_configuration_id = 70;
SELECT * FROM crm_layout_entities WHERE crm_layout_id = 388;
SELECT * FROM crm_fields WHERE id IN (3533,3534,3535);
select * from activities where crm_configuration_id = 70
and (account_id IS NOT NULL or lead_id IS NOT NULL or contact_id IS NOT NULL or opportunity_id IS NOT NULL) order by id desc;
SELECT * FROM activities WHERE uuid_to_bin('2e10b60f-8a61-41c5-a3d4-28835353dc65') = uuid;
SELECT * FROM activities where crm_configuration_id = 69 ;
SELECT * FROM users WHERE email LIKE '%[EMAIL]%';
SELECT * FROM activities WHERE uuid_to_bin('5a150c93-40fc-42ec-b3bd-c1d328e09f6e') = uuid;
SELECT * FROM opportunities WHERE id = 385;
select * from participants p
join activities a on p.activity_id = a.id
where a.crm_configuration_id = 70
and (p.lead_id IS NOT NULL or p.contact_id IS NOT NULL);
SELECT * FROM participants WHERE id = 1013638;
select * from teams where id = 90;
select * from users where team_id = 90;
select * from social_accounts where social_accounts.sociable_id IN (1960,1760);
SELECT * FROM crm_profiles WHERE crm_configuration_id = 71;
select * from invitations where team_id = 90;
select * from crm_configurations where id = 71;
select * from accounts where crm_configuration_id = 71 order by id desc;
select * from leads where crm_configuration_id = 71 order by id desc;
select * from contacts where crm_configuration_id = 71 order by id desc;
select * from opportunities where crm_configuration_id = 71 order by id desc;
select * from crm_profiles where crm_configuration_id = 71 order by id desc;
select * from crm_fields where crm_configuration_id = 71 order by id desc;
select * from crm_field_values where crm_field_id = 3341 order by id desc;
select * from crm_layouts where crm_configuration_id = 71 order by id desc;
select * from stages where crm_configuration_id = 71 order by id desc;
select * from users order by secondary_email desc;
select u.id, u.email, u.status, sa.id, sa.provider_user_id from social_accounts sa
join users u on sa.sociable_id = u.id
where sa.provider = 'google' and u.email LIKE 'aneliya%';
select * from failed_jobs order by id desc;
select * from users where email = '[EMAIL]' or secondary_email = '[EMAIL]';
select * from teams;
SELECT * FROM crm_profiles WHERE crm_configuration_id = 39;
SELECT * FROM crm_fields WHERE crm_configuration_id = 39 and object_type = 'task';
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 1
and sa.provider = 'salesforce';
# [PASSWORD_DOTS]
SELECT * FROM activities WHERE uuid_to_bin('c38b3895-fd0f-4b1f-9fb2-c170dba137c6') = uuid;
SELECT * FROM crm_configurations WHERE id = 70;
select * from teams where id = 1;
select * from groups where team_id = 1;
select * from users where team_id = 1;
select o.id, o.name,o.close_date, u.id, u.name, u.group_id, r.id, r.display_name, g.name, g.scope from opportunities o
join users u on o.user_id = u.id
join groups g on u.group_id = g.id
join role_user ru on u.id = ru.user_id
join roles r on ru.role_id = r.id
where o.crm_configuration_id = 39 and close_date > '2024-01-01 00:00:00';
select * from role_user where user_id = 143;
select * from roles;
select * from role_user;
select * from groups where id = 9;
select * from scope_groups where group_id = 9;
# [PASSWORD_DOTS]
select * from teams where id = 36;
select * from crm_configurations;
SELECT * FROM social_accounts WHERE sociable_id = 121;
https://crmsandbox.zoho.com/crm/jiminnyw4/tab/Leads/4776201000005049105
https://crmsandbox.zoho.com/crm/
https://crm.zoho.com/crm/org3469620/tab/Leads/230045000229559080
https://crm.zoho.com/crm/
org3469620
SELECT * FROM activities WHERE uuid_to_bin('03382d20-c8bc-48e7-a3d4-90b52fa5ceab') = uuid;
select * from users where email LIKE "%mobile_automation_%";
select * from social_accounts where sociable_id IN (2228);
select * from crm_profiles where user_id IN (2222,2223,2226,2227);
select * from teams order by id desc;
SELECT * FROM users WHERE id = 2229;
SELECT * FROM crm_profiles WHERE user_id = 2229;
select * from opportunities where crm_configuration_id = 88;
select * from crm_fields where crm_configuration_id = 88;
select * from crm_profiles where crm_configuration_id = 88;
SELECT * FROM teams WHERE id = 1;
SELECT * FROM users WHERE id = 143;
SELECT * FROM users WHERE uuid_to_bin('fde193d3-06a2-4e1a-8895-62b94039215d') = uuid;
SELECT * FROM teams WHERE uuid_to_bin('73385071-a756-42ae-9c73-8b53f2309467') = uuid;
https://app.staging.jiminny.com/ondemand?
min_duration=1
&
only_recorded=1
&
user_id%5B%5D=641f1acb-16b8-42d1-8726-df52979dad0e
&
sequence_number=2
select * from users where team_id = 1 and email like '%stoyan%'
select * from coaching_feedbacks;
select * from teams;
SELECT * FROM users WHERE team_id = 36;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 19
and sa.provider = 'pipedrive';
select * from users where id = 143;
SELECT * FROM users WHERE uuid_to_bin('73180eeb-33de-4065-977d-ccbe0e6c94fc') = uuid;
SELECT * FROM teams WHERE uuid_to_bin('73180eeb-33de-4065-977d-ccbe0e6c94fc') = uuid;
SELECT * FROM activity_shares WHERE uuid_to_bin('73180eeb-33de-4065-977d-ccbe0e6c94fc') = uuid;
select * from users where team_id = 2;
select * from activities where crm_configuration_id = 39
and activities.scheduled_start_time BETWEEN '2025-04-09 00:00:00' AND '2025-04-09 23:59:59'
AND user_id = 143
order by id desc;
# [PASSWORD_DOTS]
select * from teams where id = 142; # 2312, 126
select * from team_settings;
select * from users where team_id = 142; # 21642
SELECT * FROM social_accounts WHERE sociable_id = 21642;
SELECT * FROM crm_profiles cp join users u ON u.id = cp.user_id WHERE team_id = 142;
select * from crm_profiles where id IN (93);
select * from invitations;
select * from team_features where team_id = 1;
SELECT * FROM crm_configurations WHERE id = 126;
select * from accounts where crm_configuration_id = 126 order by id desc;
select * from leads where crm_configuration_id = 126 order by id desc;
select * from contacts where crm_configuration_id = 126 order by id desc;
select * from opportunities where crm_configuration_id = 126 order by id desc;
select * from crm_profiles where crm_configuration_id = 126 order by id desc;
select * from crm_fields where crm_configuration_id = 126 # 11060
# and type IN ('picklist', 'status')
# and object_type = 'task'
order by id desc;
# 5731,5732,5733
select DISTINCT crm_field_id from crm_field_values where crm_field_id IN (11151,12239,12215,12185,12175,12165,12144,12137,12127,12109,12107,12105,12103,12092,12037,12005,12003,11987,11969,11958,11951,11942,11931,11924,11921,11917,11915,11901,11893,11883,11872,11870,11868,11866,11839,11833,11821,11793,11780,11777,11769,11757,11737,11735,11656,11645,11638,11629,11618,11611,11602,11591,11584,11581,11558,11544,11543,11534,11532,11529,11527,11503,11497,11493,11488,11470,11468,11457,11455,11397,11387,11372,11363,11348,11323,11318,11309,11301,11300,11292,11290,11286,11284,11256,11252,11242,11237,11233,11219,11176,11160) order by id desc;
select * from crm_layouts where crm_configuration_id = 126 order by id desc;
SELECT * FROM crm_layout_entities WHERE crm_layout_id in (300,299,298);
select * from stages where crm_configuration_id = 126 order by id desc;
select * from business_processes where crm_configuration_id = 126 order by id desc;
select * from business_process_stages where business_process_id IN (76,75,74,73);
select * from playbooks where team_id = 142;
select * from playbook_layouts where playbook_id IN (108);
SELECT * FROM playbook_categories WHERE playbook_id IN (108);
select * from teams where id = 130;
SELECT * FROM social_accounts WHERE sociable_id = 2291;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 2
and sa.provider = 'hubspot';
SELECT * FROM activities
WHERE crm_configuration_id = 110;
select * from teams;
select * from crm_configurations;
SELECT * FROM activities WHERE id = 628773;
SELECT * FROM crm_profiles WHERE user_id = 1460;
SELECT * FROM social_accounts WHERE sociable_id = 2291;
select * from teams;
select ru.*, pr.*, p.* from users u join role_user ru on ru.user_id = u.id
join permission_role pr on pr.role_id = ru.role_id
join permissions p on p.id = pr.permission_id
where team_id = 495 and p.name IN ('dial');
select * from teams where id = 145;
select * from crm_configurations where id = 129;
select * from social_accounts where sociable_id = 2317;
SELECT * FROM activities WHERE uuid_to_bin('8dbab184-a333-4268-ad57-fb41f8d53a9a') = uuid;
select * from teams where id = 1;
SELECT * FROM crm_layouts WHERE crm_configuration_id = 39;
SELECT * FROM crm_layout_entities WHERE crm_layout_id = 280;
SELECT * FROM crm_layout_entities WHERE id = 5507;
SELECT * FROM crm_fields WHERE crm_configuration_id = 39 and object_type IN ('event');
select * from teams;
select * from activities where crm_configuration_id = 14;
SELECT * FROM social_accounts where provider = 'copper';
select * from activities where id = 628467;
select * from participants where activity_id = 628467;
SELECT * FROM contacts WHERE id = 3969;
SELECT * FROM accounts WHERE id = 177;
SELECT * FROM activities WHERE uuid_to_bin('4eb54c77-cfa3-2bd4-84a7-9ed46a21c988') = uuid;
# [PASSWORD_DOTS] BH
select * from teams where id = 36;
SELECT * FROM crm_configurations WHERE id = 21;
select * from activities where crm_configuration_id = 21 and id = 607901;
select * from activities where crm_configuration_id = 21;
select * roles;
select * from permissions;
select * from permission_role where permission_id = 226;
select * from migrations order by id desc;
# mercury
# neptune
# earth
select * from teams;
select * from teams where id = 19;
select * from teams where id = 27;
select * from users where team_id = 27;
SELECT * FROM crm_configurations WHERE id = 42;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 19
and sa.provider = 'pipedrive';
select * from activities where id = 631461;
SELECT * FROM crm_field_values WHERE crm_field_id = 180;
select * from teams where id = 2;
SELECT * FROM social_accounts WHERE sociable_id = 89;
SELECT * FROM activities WHERE uuid_to_bin('ba0c029a-bc14-4e17-8603-64174acebcbb') = uuid; # 634273
select * from activity_summary_logs where activity_id = 634273;
select * from sidekick_settings where team_id = 2;
select * from teams; # 2, 2
SELECT * FROM crm_configurations WHERE team_id = 2; # 2
select * from team_features where team_id = 2;
select * from features;
SELECT * FROM opportunities WHERE crm_configuration_id = 2 and crm_provider_id = '51317301383';
SELECT * FROM opportunities WHERE crm_configuration_id = 2 order by id desc;
select * from automated_reports order by id desc;
select * from automated_report_results order by id desc;
select * from users where team_id = 1 and id IN (7160, 3248);
select * from migrations order by id desc;
SELECT
CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,
u.email,
sa.*,
t.owner_id FROM social_accounts sa
JOIN users u on u.id = sa.sociable_id
JOIN teams t on t.id = u.team_id
WHERE u.team_id = 1 and sa.provider = 'salesforce';
select * from teams where id = 1;
select * from groups g JOIN playbooks p on g.playbook_id = p.id where g.team_id = 1;
select * from groups where id = 565;
select * from playbooks where team_id = 1;
select * from playbooks where id = 175;
select * from playbook_categories where playbook_id = 175;
select * from users where team_id = 1;
select * from users where id = 7160;
select * from crm_profiles where user_id = 7160;
select * from features;
select
*
# id, uuid, type, provider, playbook_category_id, user_id, lead_id, contact_id, account_id, opportunity_id, stage_id,
# crm_configuration_id, crm_provider_id, transcription_id, status
from activities where crm_configuration_id = 1 and type = 'conference'
# and crm_provider_id IS NOT NULL
and provider != 'uploader' and actual_start_time IS NOT NULL
ORDER by id desc;
select * from activities where id = 54747783; # 00UO400000pCzojMAC
select p.id, p.activity_type, pc.id, pc.name
FROM playbooks p
join playbook_categories pc on p.id = pc.playbook_id
where p.team_id = 1 and p.activity_type = 'event';
SELECT * FROM crm_fields WHERE crm_configuration_id = 1 and object_type = 'event';
SELECT * FROM crm_field_values WHERE crm_field_id = 4;
select * from crm_layouts cl join playbook_layouts pl on cl.id = pl.layout_id
where crm_configuration_id = 1 and pl.playbook_id = 175;
select * from teams;
SELECT r.* FROM automated_reports r
join teams t on r.team_id = t.id
WHERE r.frequency = 'daily'
and r.status = 1
AND t.status = 'active'
AND (r.expires_at >= now() OR r.expires_at IS NULL);
select * from automated_report_results where report_id IN (18, 33);
select * from activity_searches where id = 10932;
select * from activity_search_filters where activity_search_id = 10932;
select * from automated_reports;
select * from automated_report_results where report_id IN (34, 35);...
|
NULL
|
|
12306
|
260
|
30
|
2026-04-14T11:00:58.568293+00:00
|
/Users/lukas/.screenpipe/data/data/2026-04-14/1776 /Users/lukas/.screenpipe/data/data/2026-04-14/1776164458568_m1.jpg...
|
PhpStorm
|
faVsco.js – AutomatedReportsService.php
|
1
|
NULL
|
monitor_1
|
NULL
|
NULL
|
NULL
|
NULL
|
Project: faVsco.js, menu
#11894 on JY-18909-automa Project: faVsco.js, menu
#11894 on JY-18909-automated-reports-ask-jiminny, menu
Start Listening for PHP Debug Connections
AutomatedReportsCommandTest
Run 'AutomatedReportsCommandTest'
Debug 'AutomatedReportsCommandTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Execute
Explain Plan
Browse Query History
View Parameters
Open Query Execution Settings…
In-Editor Results
Tx: Auto
Cancel Running Statements
Playground
jiminny
Sync Changes
Hide This Notification
Code changed:
Hide
16
13
13
Previous Highlighted Error
Next Highlighted Error
SELECT * FROM teams WHERE id = 1;
select * from crm_layouts where crm_configuration_id = 39;
SELECT * FROM crm_layout_entities WHERE crm_layout_id = 283;
SELECT * FROM crm_fields WHERE id = 2234;
SELECT * FROM crm_field_values WHERE crm_field_id = 2234;
select * from crm_profiles where user_id = 143;
select * from record_types where crm_configuration_id = 39; # 0121K000001MHElQAO,0121K000001MHEqQAO
select * from business_processes where crm_configuration_id = 39;
# 01941000000H669AAC, 01941000000H66JAAS
select * from record_type_field_values
where record_type_id IN (24);
select * from crm_field_values where id IN (2730);
select * from crm_configurations where id = 39;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 1
and sa.provider = 'salesforce'; #1035
select * from users where team_id = 1; # 222 group 3
SELECT * FROM activities WHERE user_id = 222 order by id desc;
select * from sidekick_settings where team_id = 1;
select * from teams where id = 1;
select * from team_features where team_id = 1;
select * from activities where crm_configuration_id = 2
and provider = 'ms-teams' and id = 608765;
SELECT * FROM activities WHERE crm_configuration_id = 2 and crm_provider_id = '59523413338';
select * from sidekick_settings where team_id = 2;
SELECT * FROM activities WHERE id = 608660;
select * from activity_summary_logs where activity_id = 608660;
select * from ai_prompts where transcription_id = 11214;
# [PASSWORD_DOTS]
SELECT * FROM activities WHERE uuid_to_bin('ed78a437-2804-450e-ab2f-56ab1c641346') = uuid;
# id: 608818, crm: 59628809737
SELECT * FROM activities WHERE uuid_to_bin('36b06e55-afdd-4782-8dee-c624cd0af191') = uuid;
# id: 608821, crm: 59632069252
SELECT ce.start_time, ce.end_time, a.id, a.uuid, crm_provider_id, calendar_event_id, title,
playbook_category_id, user_id, lead_id, contact_id, account_id, opportunity_id,
scheduled_start_time, scheduled_end_time, actual_start_time, actual_end_time, a.created_at
FROM activities a
join calendar_events ce on a.calendar_event_id = ce.id
WHERE a.id IN (608818, 608821);
select * from users where team_id = 1;
select * from team_settings where team_id = 1;
select * from crm_profiles where crm_configuration_id = 39 order by user_id;
select * from team_features where team_id = 1;
select * from users where team_id = 2;
SELECT * FROM activities WHERE uuid_to_bin('ec7647e9-5225-458b-b475-f31aa2769204') = uuid; # 612639
# Preslava N. Ivanova, grou id 3
SELECT * FROM opportunities WHERE uuid_to_bin('a2928fe5-aec5-46cb-85d9-7654c89e46a6') = uuid;
select * from activities where opportunity_id = 344 and actual_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00';
select
a.id,
a.type,
a.scheduled_start_time,
a.actual_start_time,
a.created_at,
a.opportunity_id,
a.status
FROM activities a
WHERE opportunity_id = 344
and status IN ('completed', 'received', 'delivered')
and (
(a.actual_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00')
OR (a.created_at between '2024-10-11 00:00:00' and '2024-10-12 00:00:00')
OR (a.scheduled_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00'))
;
SELECT * FROM users WHERE id = 222;
SELECT * FROM crm_profiles WHERE user_id = 222;
select * from crm_layouts where crm_configuration_id = 39;
SELECT * FROM crm_layout_entities WHERE crm_layout_id = 281;
select * from group_deal_risk_types;
select * from opportunities where team_id = 1;
SELECT * FROM opportunities WHERE id = 315;
SELECT * FROM crm_field_data WHERE object_id = 315;
select * from crm_field_data where object_id = 260;
select * from generic_ai_prompts where subject_id = 315;
select * from teams; # 36, 21, 121, [EMAIL]
SELECT * FROM social_accounts WHERE sociable_id = 121 and provider = 'bullhorn';
# [PASSWORD_DOTS]
select * from teams where id = 1;
select * from crm_configurations where id = 39;
select * from users where team_id = 1;
select u.email, cp.* from users u
join crm_profiles cp on u.id = cp.user_id
where u.team_id = 1;
# 1 - 00541000004281rAAA
# 204 - 0052g000003freeAAA
# 429 - 0052g000003qGOiAAM
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 1
and sa.provider = 'salesforce';
select * from activities where type = 'softphone'
and created_at > '2024-12-11 15:24:36' order by id desc;
select * from activity_providers where team_id = 1;
select * from activity_provider_users where activity_provider_id = 328;
select * from opportunities where crm_configuration_id = 39
AND account_id = 178 AND is_closed = false
order by created_at DESC;
select * from contacts where id = 3952;
select * from accounts where id = 178;
# [PASSWORD_DOTS]
select * from teams where id = 36;
select * from crm_configurations where id = 21;
select * from users where team_id = 36;
select u.email, cp.* from users u
join crm_profiles cp on u.id = cp.user_id
where u.team_id = 36;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 36
and sa.provider = 'bullhorn';
select * from social_accounts where id = 348;
UPDATE social_accounts SET
provider_user_token = '21442_6802599_91:41179a58-21e7-4d7c-ad58-56bb666b2f65',
provider_refresh_token = '21442_6802599_91:01c6b335-3f2a-42e4-85ff-8a08fa65fceb',
expires = 1733998131,
state = 'connected'
WHERE id = 348;
# [PASSWORD_DOTS]
select * from teams where id = 31;
select * from crm_configurations where id = 18;
select * from users where team_id = 31; # 257
select u.email, cp.* from users u
join crm_profiles cp on u.id = cp.user_id
where u.team_id = 31;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 31
and sa.provider = 'close';
select * from contacts where crm_configuration_id = 18;
# [PASSWORD_DOTS] NEPTUNE [PASSWORD_DOTS]
select * from teams;
select * from users where id IN (1030, 1035, 1052);
select * from crm_configurations;
select * from users where team_id = 65; # 257
select * from team_settings where team_id = 65; # 257
select * from invitations where team_id = 65; # 257
select * from users where email = '[EMAIL]'; # 257
select u.email, cp.* from users u
join crm_profiles cp on u.id = cp.user_id
where u.team_id = 65;
select * from crm_configurations where id = 53;
select * from accounts where crm_configuration_id = 53 order by id desc;
select * from leads where crm_configuration_id = 53 order by id desc;
select * from contacts where crm_configuration_id = 53 order by id desc;
select * from opportunities where crm_configuration_id = 53 order by id desc;
select * from crm_profiles where crm_configuration_id = 53 order by id desc;
select * from crm_fields where crm_configuration_id = 53 order by id desc;
select * from crm_field_values where crm_field_id = 3341 order by id desc;
select * from crm_layouts where crm_configuration_id = 53 order by id desc;
select * from stages where crm_configuration_id = 53 order by id desc;
select * from crm_profiles where crm_configuration_id = 13;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 65
and sa.provider = 'integration-app';
select * from contacts where crm_configuration_id = 13;
select * from social_accounts where sociable_id = 283;
SELECT * FROM opportunities WHERE crm_provider_id = '006O400000E9bzeIAB';
select * from activity_providers where team_id = 65;
SELECT * FROM activities WHERE crm_configuration_id IN (51, 52, 53);
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 65
;
# [PASSWORD_DOTS] STAGING [PASSWORD_DOTS]
SELECT * FROM teams;
SELECT * FROM teams WHERE id = 88;
SELECT * FROM teams WHERE id = 89;
select * from team_settings where team_id = 89;
SELECT * FROM users WHERE team_id = 89;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 89;
select * from users;
SELECT * FROM social_accounts WHERE sociable_id = 1761;
SELECT * FROM crm_configurations WHERE id = 70;
select * from accounts where crm_configuration_id = 70 order by id desc;
select * from leads where crm_configuration_id = 70 order by id desc;
select * from contacts where crm_configuration_id = 70 order by id desc;
select * from opportunities where crm_configuration_id = 70 order by id desc;
select * from crm_profiles where crm_configuration_id = 70 order by id desc;
select * from crm_fields where crm_configuration_id = 70 order by id desc;
select * from crm_field_values where crm_field_id = 3536 order by id desc;
select * from crm_layouts where crm_configuration_id = 70 order by id desc;
select * from stages where crm_configuration_id = 70 order by id desc;
select * from business_processes where crm_configuration_id = 70 order by id desc;
select * from business_process_stages where business_process_id = 34;
select * from contacts where id = 10468;
select * from crm_layouts where crm_configuration_id = 70;
SELECT * FROM crm_layout_entities WHERE crm_layout_id = 388;
SELECT * FROM crm_fields WHERE id IN (3533,3534,3535);
select * from activities where crm_configuration_id = 70
and (account_id IS NOT NULL or lead_id IS NOT NULL or contact_id IS NOT NULL or opportunity_id IS NOT NULL) order by id desc;
SELECT * FROM activities WHERE uuid_to_bin('2e10b60f-8a61-41c5-a3d4-28835353dc65') = uuid;
SELECT * FROM activities where crm_configuration_id = 69 ;
SELECT * FROM users WHERE email LIKE '%[EMAIL]%';
SELECT * FROM activities WHERE uuid_to_bin('5a150c93-40fc-42ec-b3bd-c1d328e09f6e') = uuid;
SELECT * FROM opportunities WHERE id = 385;
select * from participants p
join activities a on p.activity_id = a.id
where a.crm_configuration_id = 70
and (p.lead_id IS NOT NULL or p.contact_id IS NOT NULL);
SELECT * FROM participants WHERE id = 1013638;
select * from teams where id = 90;
select * from users where team_id = 90;
select * from social_accounts where social_accounts.sociable_id IN (1960,1760);
SELECT * FROM crm_profiles WHERE crm_configuration_id = 71;
select * from invitations where team_id = 90;
select * from crm_configurations where id = 71;
select * from accounts where crm_configuration_id = 71 order by id desc;
select * from leads where crm_configuration_id = 71 order by id desc;
select * from contacts where crm_configuration_id = 71 order by id desc;
select * from opportunities where crm_configuration_id = 71 order by id desc;
select * from crm_profiles where crm_configuration_id = 71 order by id desc;
select * from crm_fields where crm_configuration_id = 71 order by id desc;
select * from crm_field_values where crm_field_id = 3341 order by id desc;
select * from crm_layouts where crm_configuration_id = 71 order by id desc;
select * from stages where crm_configuration_id = 71 order by id desc;
select * from users order by secondary_email desc;
select u.id, u.email, u.status, sa.id, sa.provider_user_id from social_accounts sa
join users u on sa.sociable_id = u.id
where sa.provider = 'google' and u.email LIKE 'aneliya%';
select * from failed_jobs order by id desc;
select * from users where email = '[EMAIL]' or secondary_email = '[EMAIL]';
select * from teams;
SELECT * FROM crm_profiles WHERE crm_configuration_id = 39;
SELECT * FROM crm_fields WHERE crm_configuration_id = 39 and object_type = 'task';
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 1
and sa.provider = 'salesforce';
# [PASSWORD_DOTS]
SELECT * FROM activities WHERE uuid_to_bin('c38b3895-fd0f-4b1f-9fb2-c170dba137c6') = uuid;
SELECT * FROM crm_configurations WHERE id = 70;
select * from teams where id = 1;
select * from groups where team_id = 1;
select * from users where team_id = 1;
select o.id, o.name,o.close_date, u.id, u.name, u.group_id, r.id, r.display_name, g.name, g.scope from opportunities o
join users u on o.user_id = u.id
join groups g on u.group_id = g.id
join role_user ru on u.id = ru.user_id
join roles r on ru.role_id = r.id
where o.crm_configuration_id = 39 and close_date > '2024-01-01 00:00:00';
select * from role_user where user_id = 143;
select * from roles;
select * from role_user;
select * from groups where id = 9;
select * from scope_groups where group_id = 9;
# [PASSWORD_DOTS]
select * from teams where id = 36;
select * from crm_configurations;
SELECT * FROM social_accounts WHERE sociable_id = 121;
[URL_WITH_CREDENTIALS] this will add filter, however if we need to control feature by FF we need conditional logic
public const array TYPES = [
['id' => 'exec_summary', 'name' => 'Exec Summary'],
['id' => 'coaching_profiles', 'name' => 'Coaching Profiles'],
['id' => 'product_feedback', 'name' => 'Product Feedback'],
['id' => self::TYPE_LOSS_ANALYSIS, 'name' => 'Loss Analysis'],
// ['id' => 'questions', 'name' => 'Questions'],
// ['id' => 'statistical_quant', 'name' => 'Statistical Quantitative'],
];
public const array ALL_TYPES = [
...self::TYPES,
['id' => self::TYPE_ASK_JIMINNY, 'name' => 'Ask Jiminny'],
];
public const string FREQUENCY_DAILY = 'daily';
public const string FREQUENCY_WEEKLY = 'weekly';
public const string FREQUENCY_MONTHLY = 'monthly';
public const string FREQUENCY_QUARTERLY = 'quarterly';
public const string FREQUENCY_ONE_OFF = 'one_off';
/**
* Frequencies for standard (non-Ask Jiminny) reports.
*/
public const array FREQUENCIES = [
['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],
['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],
['id' => self::FREQUENCY_QUARTERLY, 'name' => 'Quarterly'],
['id' => self::FREQUENCY_ONE_OFF, 'name' => 'One-off'],
];
/**
* Frequencies for Ask Jiminny reports.
*/
public const array ASK_JIMINNY_FREQUENCIES = [
['id' => self::FREQUENCY_DAILY, 'name' => 'Daily'],
['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],
['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],
];
public const string MEDIA_TYPE_PDF = 'pdf';
public const string MEDIA_TYPE_PODCAST = 'podcast';
public const array MEDIA_TYPES = [self::MEDIA_TYPE_PDF, self::MEDIA_TYPE_PODCAST];
public const array MEDIA_TYPE_OBJECT_PDF = ['id' => self::MEDIA_TYPE_PDF, 'name' => 'PDF'];
public const array MEDIA_TYPE_OBJECT_PODCAST = ['id' => self::MEDIA_TYPE_PODCAST, 'name' => 'Podcast'];
public const array MEDIA_TYPE_OBJECTS = [self::MEDIA_TYPE_OBJECT_PDF, self::MEDIA_TYPE_OBJECT_PODCAST];
public const array CALL_TYPE_CONFERENCE = ['id' => 'conference', 'name' => 'Conference'];
public const array CALL_TYPE_DIALER = ['id' => 'dialer', 'name' => 'Dialer'];
public const int SENT_REPORT_AT_HOURS = 5;
public const string PDF_KEY = 'pdf';
public const string AUDIO_KEY = 'audio';
private const array ALL_FREQUENCIES = [
['id' => self::FREQUENCY_DAILY, 'name' => 'Daily'],
['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],
['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],
['id' => self::FREQUENCY_QUARTERLY, 'name' => 'Quarterly'],
['id' => self::FREQUENCY_ONE_OFF, 'name' => 'One-off'],
];
private const string S3_DIR = 'reports';
private const array FILE_EXTENSIONS_VARIANTS = ['html', 'MD', 'pdf'];
private const array FILE_PODCAST_EXTENSIONS_VARIANTS = ['json', 'mp3', 'ssml'];
public function __construct(
private readonly TeamRepository $teamRepository,
private readonly GroupRepository $groupRepository,
private readonly UserRepository $userRepository,
private readonly StageRepository $stageRepository,
private readonly DealStagesService $dealStagesService,
private readonly RecipientsService $recipientsService,
private readonly AutomatedReportsRepository $automatedReportsRepository,
private readonly Webhook $webhookService,
private readonly BusDispatcher $dispatcher,
private readonly ActivityTypeService $activityTypeService,
private readonly PlaybookCategoryRepository $playbookCategoryRepository,
private readonly AskAnythingPromptService $askAnythingPromptService,
private readonly SearchRepository $activitySearchRepository,
private readonly AskAnythingRepository $askAnythingRepository,
) {
}
public static function getTypes(): array
{
$types = self::TYPES;
return array_map(static function ($type) {
return $type['id'];
}, $types);
}
public static function getCallTypes(): array
{
return array_map(static function ($callType) {
return $callType['id'];
}, [self::CALL_TYPE_CONFERENCE, self::CALL_TYPE_DIALER]);
}
public static function getFrequencies(): array
{
return array_map(static function ($frequency) {
return $frequency['id'];
}, self::FREQUENCIES);
}
// front-facing structure
public function getReportEnabledFieldData(bool $value = false): array
{
return [
'id' => 'report_enabled',
'label' => '',
'inputType' => InputTypeEnum::TOGGLE,
'value' => $value,
];
}
// Organizations = Teams
public function getOrganizationFieldData(?string $value = null, bool $shortVersion = false): array
{
$options = $this->getTeams();
if ($shortVersion) {
return [
'id' => 'organization',
'label' => 'Organization',
'options' => $options,
];
}
return [
'id' => 'organization',
'label' => 'Organization',
'inputType' => InputTypeEnum::DROPDOWN,
'required' => true,
'placeholder' => 'Select',
'options' => $options,
'value' => $value,
'dependencies' => [
'teams',
'deal_stage_at_call',
'current_deal_stage',
'recipients',
ActivityTypeService::PLAYBOOK_CATEGORIES_KEY,
],
'dependsOn' => [],
];
}
// Teams = Groups
public function getTeamFieldData(array $options = [], array $value = [], bool $shortVersion = false): array
{
if ($shortVersion) {
return [
'id' => 'teams',
'label' => 'Team',
'options' => $options,
];
}
return [
'id' => 'teams',
'label' => 'Team',
'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,
'required' => false,
'placeholder' => 'Select',
'options' => $options,
'value' => $value, // value should be an array of objects {id, name}
'dependencies' => [ActivityTypeService::PLAYBOOK_CATEGORIES_KEY],
'dependsOn' => [],
];
}
public function getReportTypeFieldData(?string $value = null, bool $shortVersion = false, ?Team $team = null): array
{
$types = [];
if ($team instanceof Team) {
if ($team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {
$types = self::TYPES;
}
if ($team->hasFeature(FeatureEnum::ASK_JIMINNY_REPORTS)) {
$types[] = ['id' => self::TYPE_ASK_JIMINNY, 'name' => 'Ask Jiminny'];
}
} else {
$types = self::TYPES;
}
if ($shortVersion) {
return [
'id' => 'report_type',
'label' => 'Report Type',
'options' => $types,
];
}
return [
'id' => 'report_type',
'label' => 'Report Type',
'inputType' => InputTypeEnum::DROPDOWN,
'required' => true,
'placeholder' => 'Select',
'options' => $types,
'value' => $value,
'dependencies' => [],
'dependsOn' => [],
];
}
public function getFrequencyFieldData(?string $value = null): array
{
return [
'id' => 'frequency',
'label' => 'Frequency',
'inputType' => InputTypeEnum::DROPDOWN,
'required' => true,
'placeholder' => 'Select',
'options' => self::FREQUENCIES,
'value' => $value,
'dependencies' => ['period'],
'dependsOn' => [],
];
}
public function getPeriodFieldData(?string $valueStartDate = null, ?string $valueEndDate = null): array
{
return [
'id' => 'period',
'label' => 'Select one-off period',
'inputType' => InputTypeEnum::DATE_RANGE,
'required' => true,
'placeholder' => 'Select',
'value' => ['startDate' => $valueStartDate, 'endDate' => $valueEndDate],
'queryParams' => [
'startDate' => 'start_date_period',
'endDate' => 'end_date_period',
],
'dependencies' => [],
'dependsOn' => ['frequency'],
];
}
public function getActivityTypesFieldData(?Team $team = null, array $value = [], array $teamsFilter = []): array
{
return $this->activityTypeService->getActivityTypeFieldData(team: $team, value: $value, groupIds: $teamsFilter);
}
public function getDealStageAtCallFieldData(?Team $team = null, array $value = []): array
{
return $this->dealStagesService->getDealStageAtCallFieldData(team: $team, value: $value);
}
public function getCurrentDealStageFieldData(?Team $team = null, array $value = []): array
{
return $this->dealStagesService->getCurrentDealStageFieldData(team: $team, value: $value);
}
public function getDealValueFieldData(?int $valueMin = null, ?int $valueMax = null): array
{
return [
'id' => 'deal_value',
'label' => 'Deal Value',
'inputType' => InputTypeEnum::INTEGER_RANGE,
'required' => false,
'value' => ['min' => $valueMin, 'max' => $valueMax],
'queryParams' => [
'min' => 'min_deal_value',
'max' => 'max_deal_value',
],
'dependencies' => [],
'dependsOn' => [],
];
}
public function getCallTypeFieldData(bool $conferenceOn = false, bool $dialerOn = false): array
{
$value = [];
$conferenceOn && $value[] = self::CALL_TYPE_CONFERENCE;
$dialerOn && $value[] = self::CALL_TYPE_DIALER;
return [
'id' => 'call_type',
'label' => 'Call Type',
'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,
'required' => true,
'options' => [
self::CALL_TYPE_CONFERENCE,
self::CALL_TYPE_DIALER,
],
'value' => $value,
'dependencies' => [],
'dependsOn' => [],
];
}
public function getMediaTypeFieldData(?AutomatedReport $report = null): array
{
$value = [];
if ($report) {
$value = $this->transformMediaTypes($report);
}
return [
'id' => 'media_types',
'label' => 'Export as',
'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,
'required' => true,
'options' => self::MEDIA_TYPE_OBJECTS,
'value' => $value,
'dependencies' => [],
'dependsOn' => [],
];
}
public function getCallDurationFieldData(?int $valueMin = null, ?int $valueMax = null): array
{
return [
'id' => 'call_duration',
'label' => 'Call Duration',
'inputType' => InputTypeEnum::INTEGER_RANGE,
'required' => false,
'value' => ['min' => $valueMin, 'max' => $valueMax],
'queryParams' => [
'min' => 'min_call_duration',
'max' => 'max_call_duration',
],
'dependencies' => [],
'dependsOn' => [],
];
}
public function getRecipientsFieldData(?Team $team = null, array $value = []): array
{
return $this->recipientsService->getRecipientsFieldData(team: $team, value: $value);
}
public function getJiminnyRecipientsFieldData(array $value = []): array
{
return $this->recipientsService->getJiminnyRecipientsFieldData($value);
}
public function getAdditionalPromptInputFieldData(?string $value = null): array
{
return [
'id' => 'additional_prompt_input',
'label' => 'Special requirements',
'inputType' => InputTypeEnum::TEXTAREA,
'required' => false,
'placeholder' => 'What should be the focus of the report?',
'value' => $value,
'dependencies' => [],
'dependsOn' => [],
];
}
public function getCustomReportNameFieldData(?string $value = null): array
{
return [
'id' => 'custom_name',
'label' => 'Custom report name',
'inputType' => InputTypeEnum::TEXT,
'required' => false,
'placeholder' => 'Enter custom name',
'value' => $value,
'dependencies' => [],
'dependsOn' => [],
];
}
// data providers
public function getTeams(): array
{
$teams = $this->teamRepository->getTeamsForKiosk(status: Team::STATUS_ACTIVE);
$teamData = [];
foreach ($teams as $team) {
if (! $team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {
continue;
}
$teamData[] = $this->transformTeam($team);
}
return $teamData;
}
public function getTeamGroups(string $teamUuid): array
{
$data = [];
$team = $this->getTeam($teamUuid);
if ($team !== null) {
$groups = $team->groups()->get();
foreach ($groups as $group) {
$data[] = [
'id' => $group->getUuid(),
'name' => $group->getName(),
];
}
}
return $data;
}
public function getTeamsGroupsOptions(array $filterTeamUuids = []): array
{
$data = [];
$teams = $this->getTeams();
foreach ($teams as $team) {
if (! empty($filterTeamUuids) && ! in_array($team['id'], $filterTeamUuids, true)) {
continue;
}
$data[] = [
'label' => $team['name'],
'groups' => $this->getTeamGroups($team['id']),
];
}
return $data;
}
public function getTeam(string $teamUuid): ?Team
{
return $this->teamRepository->idOrUuid($teamUuid);
}
public function getTeamById(int $teamId): ?Team
{
return $this->teamRepository->find($teamId);
}
public function getGroupsUuids(AutomatedReport $report): array
{
$uuids = [];
$reportGroups = $report->getGroups();
foreach ($reportGroups as $groupId) {
if ($group = $this->groupRepository->find($groupId)) {
$uuids[] = $group->getUuid();
}
}
return $uuids;
}
public function getPlaybookCategoriesUuids(AutomatedReport $report): array
{
$uuids = [];
$playbookCategories = $report->getPlaybookCategories();
foreach ($playbookCategories as $id) {
if ($category = $this->playbookCategoryRepository->find($id)) {
$uuids[] = $category->getUuid();
}
}
return $uuids;
}
public function getDealAtCallStagesUuids(AutomatedReport $report): array
{
$uuids = [];
$reportStages = $report->getDealAtCallStages();
foreach ($reportStages as $id) {
if ($stage = $this->stageRepository->find($id)) {
$uuids[] = $stage->getUuid();
}
}
return $uuids;
}
public function getCurrentDealStagesUuids(AutomatedReport $report): array
{
$uuids = [];
$reportStages = $report->getCurrentDealStages();
foreach ($reportStages as $id) {
if ($stage = $this->stageRepository->find($id)) {
$uuids[] = $stage->getUuid();
}
}
return $uuids;
}
public function getUsersUuids(AutomatedReport $report): array
{
return $this->extractUserUuids($report->getRecipients());
}
public function getJiminnyUsersUuids(AutomatedReport $report): array
{
return $this->extractUserUuids($report->getJiminnyRecipients());
}
/**
* @param array<string, mixed> $recipients
*/
private function extractUserUuids(array $recipients): array
{
$userIds = $recipients['users'] ?? [];
return collect($userIds)
->map(fn ($id) => $this->userRepository->find((int) $id))
->filter()
->map(fn (UserContract $user) => $user->getUuid())
->values()
->all();
}
// get mail data
public function getRecipientUsers(AutomatedReport $report): array
{
return $this->buildRecipientUsers($report->getRecipients());
}
private function getJiminnyRecipientUsers(AutomatedReport $report): array
{
return $this->buildRecipientUsers($report->getJiminnyRecipients());
}
/**
* @param array<string, mixed> $recipients
*/
private function buildRecipientUsers(array $recipients): array
{
$userIds = $recipients['users'] ?? [];
return collect($userIds)
->map(fn ($id) => $this->userRepository->find((int) $id))
->filter()
->map(fn (UserContract $user) => [
'email' => $user->getEmailAddress(),
'name' => $user->getName(),
'timezone' => $user->getTimezone()->getName(),
])
->values()
->all();
}
public function getValidRecipientUsers(AutomatedReport $report, bool $includeJiminny = false): array
{
if ($report->isAskJiminnyReport()) {
$recipients = $this->resolveAskJiminnyRecipients($report);
} else {
$recipients = $this->getRecipientUsers($report);
if ($includeJiminny) {
$recipients = array_merge($recipients, $this->getJiminnyRecipientUsers($report));
}
}
$emails = [];
return array_values(array_filter(
$recipients,
static function ($recipient) use (&$emails) {
if (empty($recipient['email']) || in_array($recipient['email'], $emails, true)) {
return false;
}
$emails[] = $recipient['email'];
return true;
}
));
}
private function resolveAskJiminnyRecipients(AutomatedReport $report): array
{
$recipients = [];
$creator = $report->getCreator();
if ($creator !== null) {
$recipients[] = [
'email' => $creator->getEmailAddress(),
'name' => $creator->getName(),
'timezone' => $creator->getTimezone()->getName(),
];
}
return array_merge(
$recipients,
$this->buildRecipientUsers($report->getRecipients()),
$this->getGroupRecipientUsers($report),
);
}
private function getGroupRecipientUsers(AutomatedReport $report): array
{
$users = [];
foreach ($report->getGroups() as $groupId) {
$group = $this->groupRepository->find($groupId);
if ($group === null) {
continue;
}
foreach ($group->getMembers() as $member) {
$users[] = [
'email' => $member->getEmailAddress(),
'name' => $member->getName(),
'timezone' => $member->getTimezone()->getName(),
];
}
}
return $users;
}
public function getReportTypeName(AutomatedReportResult $report): string
{
$type = $report->getReport()->getType();
$getType = $this->transformReportType($type);
return $getType['name'];
}
public function getReportPeriodName(AutomatedReportResult $report): string
{
$from = $report->getFromDate();
$to = $report->getToDate();
$frequency = $report->getReport()->getFrequency();
if ($from === null || $to === null) {
if (! $report->getReport()->isAskJiminnyReport()) {
$invalidPeriod = $from === null ? 'from' : 'to';
throw new ApplicationException('Report period is invalid: ' . $invalidPeriod);
}
$period = $this->calculateFromAndToDatePeriod($frequency);
$from = $period['fromDate'];
$to = $period['toDate'];
}
return $this->formatReportPeriodName($frequency, $from, $to);
}
private function formatReportPeriodName(string $frequency, Carbon $from, Carbon $to): string
{
$fromYear = $from->format('Y');
$toYear = $to->format('Y');
$differentYears = $fromYear !== $toYear;
switch ($frequency) {
case self::FREQUENCY_DAILY:
return $from->format('j M Y');
case self::FREQUENCY_QUARTERLY:
// 'Jan-Mar 2025' or 'Nov 2024-Jan 2025' if years differ
$startMonth = $from->format('M');
$endMonth = $to->copy()->subMonth();
$endMonthName = $endMonth->format('M');
$endMonthYear = $endMonth->format('Y');
if ($differentYears) {
return "{$startMonth} {$fromYear} - {$endMonthName} {$endMonthYear}";
}
return "{$startMonth} - {$endMonthName} {$toYear}";
case self::FREQUENCY_MONTHLY:
// 'May 2025' - monthly reports are always within the same year
return $from->format('M Y');
case self::FREQUENCY_WEEKLY:
// '4 - 8 Aug 2025', '27 Oct - 3 Nov 2025', or '28 Dec 2024 - 3 Jan 2025' if years differ
$startDay = $from->format('j');
$endDay = $to->format('j');
$startMonth = $from->format('M');
$endMonth = $to->format('M');
if ($differentYears) {
return "{$startDay} {$startMonth} {$fromYear} - {$endDay} {$endMonth} {$toYear}";
}
if ($startMonth !== $endMonth) {
return "{$startDay} {$startMonth} - {$endDay} {$endMonth} {$toYear}";
}
return "{$startDay} - {$endDay} {$endMonth} {$toYear}";
case self::FREQUENCY_ONE_OFF:
// '2 May-31 May 2025' or '15 Dec 2024-15 Jan 2025' if years differ
$startDay = $from->format('j');
$startMonth = $from->format('M');
$endDay = $to->format('j');
$endMonth = $to->format('M');
// If same month and year, use a format like '2-31 May 2025'
if ($startMonth === $endMonth && ! $differentYears) {
return "{$startDay} - {$endDay} {$startMonth} {$toYear}";
}
// If different years, include both years
if ($differentYears) {
return "{$startDay} {$startMonth} {$fromYear} - {$endDay} {$endMonth} {$toYear}";
}
// Same year but different months
return "{$startDay} {$startMonth} - {$endDay} {$endMonth} {$toYear}";
default:
// Default format for unknown frequencies
return $from->format('j M Y') . ' - ' . $to->format('j M Y');
}
}
public function getReportTeamsName(AutomatedReportResult $report): string
{
$groups = $report->getGroups();
if (empty($groups)) {
return 'All';
}
// Get group names from repository
$groupNames = [];
foreach ($groups as $groupId) {
$group = $this->groupRepository->find($groupId);
if ($group) {
$groupNames[] = $group->getName();
}
}
if (count($groupNames) === 1) {
// Single team format
$teamsName = $groupNames[0];
} else {
// Multiple teams format
$teamsName = implode(', ', $groupNames);
}
return $teamsName;
}
public function getReportFileName(AutomatedReportResult $report): string
...
|
[{"role":"AXButton","text" [{"role":"AXButton","text":"Project: faVsco.js, menu","depth":5,"help_text":"~/jiminny/app","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"#11894 on JY-18909-automated-reports-ask-jiminny, menu","depth":5,"help_text":"Pull request #11894 exists for current branch JY-18909-automated-reports-ask-jiminny","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Start Listening for PHP Debug Connections","depth":5,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"AutomatedReportsCommandTest","depth":6,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Run 'AutomatedReportsCommandTest'","depth":6,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Debug 'AutomatedReportsCommandTest'","depth":6,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"More Actions","depth":6,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JetBrains AI","depth":5,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Search Everywhere","depth":5,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"IDE and Project Settings","depth":5,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Execute","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Explain Plan","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Browse Query History","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"View Parameters","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Open Query Execution Settings…","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"In-Editor Results","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Tx: Auto","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Cancel Running Statements","depth":4,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Playground","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"jiminny","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.088194445,"height":0.027777778},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"16","depth":4,"role_description":"text"},{"role":"AXStaticText","text":"13","depth":4,"role_description":"text"},{"role":"AXStaticText","text":"13","depth":4,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"SELECT * FROM teams WHERE id = 1;\n\nselect * from crm_layouts where crm_configuration_id = 39;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 283;\nSELECT * FROM crm_fields WHERE id = 2234;\nSELECT * FROM crm_field_values WHERE crm_field_id = 2234;\n\nselect * from crm_profiles where user_id = 143;\n\nselect * from record_types where crm_configuration_id = 39; # 0121K000001MHElQAO,0121K000001MHEqQAO\nselect * from business_processes where crm_configuration_id = 39;\n# 01941000000H669AAC, 01941000000H66JAAS\n\nselect * from record_type_field_values\n where record_type_id IN (24);\n\nselect * from crm_field_values where id IN (2730);\n\nselect * from crm_configurations where id = 39;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 1\nand sa.provider = 'salesforce'; #1035\n\n\nselect * from users where team_id = 1; # 222 group 3\nSELECT * FROM activities WHERE user_id = 222 order by id desc;\nselect * from sidekick_settings where team_id = 1;\nselect * from teams where id = 1;\nselect * from team_features where team_id = 1;\n\nselect * from activities where crm_configuration_id = 2\nand provider = 'ms-teams' and id = 608765;\n\nSELECT * FROM activities WHERE crm_configuration_id = 2 and crm_provider_id = '59523413338';\n\nselect * from sidekick_settings where team_id = 2;\n\nSELECT * FROM activities WHERE id = 608660;\nselect * from activity_summary_logs where activity_id = 608660;\nselect * from ai_prompts where transcription_id = 11214;\n\n# ********************************************************************************************************\nSELECT * FROM activities WHERE uuid_to_bin('ed78a437-2804-450e-ab2f-56ab1c641346') = uuid;\n# id: 608818, crm: 59628809737\nSELECT * FROM activities WHERE uuid_to_bin('36b06e55-afdd-4782-8dee-c624cd0af191') = uuid;\n# id: 608821, crm: 59632069252\nSELECT ce.start_time, ce.end_time, a.id, a.uuid, crm_provider_id, calendar_event_id, title,\nplaybook_category_id, user_id, lead_id, contact_id, account_id, opportunity_id,\nscheduled_start_time, scheduled_end_time, actual_start_time, actual_end_time, a.created_at\nFROM activities a\njoin calendar_events ce on a.calendar_event_id = ce.id\nWHERE a.id IN (608818, 608821);\n\nselect * from users where team_id = 1;\nselect * from team_settings where team_id = 1;\nselect * from crm_profiles where crm_configuration_id = 39 order by user_id;\n\nselect * from team_features where team_id = 1;\n\nselect * from users where team_id = 2;\n\nSELECT * FROM activities WHERE uuid_to_bin('ec7647e9-5225-458b-b475-f31aa2769204') = uuid; # 612639\n# Preslava N. Ivanova, grou id 3\n\nSELECT * FROM opportunities WHERE uuid_to_bin('a2928fe5-aec5-46cb-85d9-7654c89e46a6') = uuid;\n\nselect * from activities where opportunity_id = 344 and actual_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00';\n\nselect\n a.id,\n a.type,\n a.scheduled_start_time,\n a.actual_start_time,\n a.created_at,\n a.opportunity_id,\n a.status\nFROM activities a\nWHERE opportunity_id = 344\nand status IN ('completed', 'received', 'delivered')\nand (\n (a.actual_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00')\nOR (a.created_at between '2024-10-11 00:00:00' and '2024-10-12 00:00:00')\nOR (a.scheduled_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00'))\n;\n\nSELECT * FROM users WHERE id = 222;\n\nSELECT * FROM crm_profiles WHERE user_id = 222;\nselect * from crm_layouts where crm_configuration_id = 39;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 281;\n\nselect * from group_deal_risk_types;\n\nselect * from opportunities where team_id = 1;\n\nSELECT * FROM opportunities WHERE id = 315;\nSELECT * FROM crm_field_data WHERE object_id = 315;\nselect * from crm_field_data where object_id = 260;\n\nselect * from generic_ai_prompts where subject_id = 315;\n\nselect * from teams; # 36, 21, 121, james.graham@bullhorn.jiminny.com\nSELECT * FROM social_accounts WHERE sociable_id = 121 and provider = 'bullhorn';\n\n# ************************************************************************************\nselect * from teams where id = 1;\nselect * from crm_configurations where id = 39;\nselect * from users where team_id = 1;\nselect u.email, cp.* from users u\njoin crm_profiles cp on u.id = cp.user_id\nwhere u.team_id = 1;\n# 1 - 00541000004281rAAA\n# 204 - 0052g000003freeAAA\n# 429 - 0052g000003qGOiAAM\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 1\nand sa.provider = 'salesforce';\n\nselect * from activities where type = 'softphone'\nand created_at > '2024-12-11 15:24:36' order by id desc;\n\nselect * from activity_providers where team_id = 1;\nselect * from activity_provider_users where activity_provider_id = 328;\n\nselect * from opportunities where crm_configuration_id = 39\nAND account_id = 178 AND is_closed = false\norder by created_at DESC;\n\nselect * from contacts where id = 3952;\nselect * from accounts where id = 178;\n\n# ************************************************************************************\nselect * from teams where id = 36;\nselect * from crm_configurations where id = 21;\nselect * from users where team_id = 36;\nselect u.email, cp.* from users u\njoin crm_profiles cp on u.id = cp.user_id\nwhere u.team_id = 36;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 36\nand sa.provider = 'bullhorn';\n\nselect * from social_accounts where id = 348;\nUPDATE social_accounts SET\nprovider_user_token = '21442_6802599_91:41179a58-21e7-4d7c-ad58-56bb666b2f65',\nprovider_refresh_token = '21442_6802599_91:01c6b335-3f2a-42e4-85ff-8a08fa65fceb',\nexpires = 1733998131,\nstate = 'connected'\nWHERE id = 348;\n\n# ************************************************************************************\nselect * from teams where id = 31;\nselect * from crm_configurations where id = 18;\n\nselect * from users where team_id = 31; # 257\nselect u.email, cp.* from users u\njoin crm_profiles cp on u.id = cp.user_id\nwhere u.team_id = 31;\n\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 31\nand sa.provider = 'close';\n\nselect * from contacts where crm_configuration_id = 18;\n\n# ********************** NEPTUNE **************************************************************\nselect * from teams;\nselect * from users where id IN (1030, 1035, 1052);\nselect * from crm_configurations;\n\nselect * from users where team_id = 65; # 257\nselect * from team_settings where team_id = 65; # 257\nselect * from invitations where team_id = 65; # 257\nselect * from users where email = 'integration-account@jiminny.com'; # 257\nselect u.email, cp.* from users u\njoin crm_profiles cp on u.id = cp.user_id\nwhere u.team_id = 65;\n\nselect * from crm_configurations where id = 53;\nselect * from accounts where crm_configuration_id = 53 order by id desc;\nselect * from leads where crm_configuration_id = 53 order by id desc;\nselect * from contacts where crm_configuration_id = 53 order by id desc;\nselect * from opportunities where crm_configuration_id = 53 order by id desc;\nselect * from crm_profiles where crm_configuration_id = 53 order by id desc;\nselect * from crm_fields where crm_configuration_id = 53 order by id desc;\nselect * from crm_field_values where crm_field_id = 3341 order by id desc;\nselect * from crm_layouts where crm_configuration_id = 53 order by id desc;\nselect * from stages where crm_configuration_id = 53 order by id desc;\n\n\nselect * from crm_profiles where crm_configuration_id = 13;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 65\nand sa.provider = 'integration-app';\n\nselect * from contacts where crm_configuration_id = 13;\n\nselect * from social_accounts where sociable_id = 283;\n\nSELECT * FROM opportunities WHERE crm_provider_id = '006O400000E9bzeIAB';\n\nselect * from activity_providers where team_id = 65;\nSELECT * FROM activities WHERE crm_configuration_id IN (51, 52, 53);\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 65\n;\n\n# ***************************** STAGING ********************************************\nSELECT * FROM teams;\nSELECT * FROM teams WHERE id = 88;\nSELECT * FROM teams WHERE id = 89;\nselect * from team_settings where team_id = 89;\nSELECT * FROM users WHERE team_id = 89;\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 89;\n\nselect * from users;\nSELECT * FROM social_accounts WHERE sociable_id = 1761;\nSELECT * FROM crm_configurations WHERE id = 70;\nselect * from accounts where crm_configuration_id = 70 order by id desc;\nselect * from leads where crm_configuration_id = 70 order by id desc;\nselect * from contacts where crm_configuration_id = 70 order by id desc;\nselect * from opportunities where crm_configuration_id = 70 order by id desc;\nselect * from crm_profiles where crm_configuration_id = 70 order by id desc;\nselect * from crm_fields where crm_configuration_id = 70 order by id desc;\nselect * from crm_field_values where crm_field_id = 3536 order by id desc;\nselect * from crm_layouts where crm_configuration_id = 70 order by id desc;\nselect * from stages where crm_configuration_id = 70 order by id desc;\nselect * from business_processes where crm_configuration_id = 70 order by id desc;\nselect * from business_process_stages where business_process_id = 34;\n\nselect * from contacts where id = 10468;\n\nselect * from crm_layouts where crm_configuration_id = 70;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 388;\nSELECT * FROM crm_fields WHERE id IN (3533,3534,3535);\n\nselect * from activities where crm_configuration_id = 70\nand (account_id IS NOT NULL or lead_id IS NOT NULL or contact_id IS NOT NULL or opportunity_id IS NOT NULL) order by id desc;\n\nSELECT * FROM activities WHERE uuid_to_bin('2e10b60f-8a61-41c5-a3d4-28835353dc65') = uuid;\nSELECT * FROM activities where crm_configuration_id = 69 ;\n\nSELECT * FROM users WHERE email LIKE '%jiminny_web_sa2@jiminny.com%';\nSELECT * FROM activities WHERE uuid_to_bin('5a150c93-40fc-42ec-b3bd-c1d328e09f6e') = uuid;\nSELECT * FROM opportunities WHERE id = 385;\n\nselect * from participants p\njoin activities a on p.activity_id = a.id\nwhere a.crm_configuration_id = 70\nand (p.lead_id IS NOT NULL or p.contact_id IS NOT NULL);\nSELECT * FROM participants WHERE id = 1013638;\n\nselect * from teams where id = 90;\nselect * from users where team_id = 90;\nselect * from social_accounts where social_accounts.sociable_id IN (1960,1760);\nSELECT * FROM crm_profiles WHERE crm_configuration_id = 71;\nselect * from invitations where team_id = 90;\n\nselect * from crm_configurations where id = 71;\nselect * from accounts where crm_configuration_id = 71 order by id desc;\nselect * from leads where crm_configuration_id = 71 order by id desc;\nselect * from contacts where crm_configuration_id = 71 order by id desc;\nselect * from opportunities where crm_configuration_id = 71 order by id desc;\nselect * from crm_profiles where crm_configuration_id = 71 order by id desc;\nselect * from crm_fields where crm_configuration_id = 71 order by id desc;\nselect * from crm_field_values where crm_field_id = 3341 order by id desc;\nselect * from crm_layouts where crm_configuration_id = 71 order by id desc;\nselect * from stages where crm_configuration_id = 71 order by id desc;\n\nselect * from users order by secondary_email desc;\nselect u.id, u.email, u.status, sa.id, sa.provider_user_id from social_accounts sa\n join users u on sa.sociable_id = u.id\nwhere sa.provider = 'google' and u.email LIKE 'aneliya%';\n\nselect * from failed_jobs order by id desc;\n\nselect * from users where email = 'ben.allwright@learningpeople.co.uk' or secondary_email = 'ben.allwright@learningpeople.co.uk';\n\nselect * from teams;\nSELECT * FROM crm_profiles WHERE crm_configuration_id = 39;\nSELECT * FROM crm_fields WHERE crm_configuration_id = 39 and object_type = 'task';\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 1\nand sa.provider = 'salesforce';\n\n# ************************************************************************************\nSELECT * FROM activities WHERE uuid_to_bin('c38b3895-fd0f-4b1f-9fb2-c170dba137c6') = uuid;\nSELECT * FROM crm_configurations WHERE id = 70;\n\nselect * from teams where id = 1;\nselect * from groups where team_id = 1;\nselect * from users where team_id = 1;\n\nselect o.id, o.name,o.close_date, u.id, u.name, u.group_id, r.id, r.display_name, g.name, g.scope from opportunities o\njoin users u on o.user_id = u.id\njoin groups g on u.group_id = g.id\njoin role_user ru on u.id = ru.user_id\njoin roles r on ru.role_id = r.id\nwhere o.crm_configuration_id = 39 and close_date > '2024-01-01 00:00:00';\n\nselect * from role_user where user_id = 143;\nselect * from roles;\n\nselect * from role_user;\nselect * from groups where id = 9;\nselect * from scope_groups where group_id = 9;\n\n# ************************************************************************************\nselect * from teams where id = 36;\nselect * from crm_configurations;\nSELECT * FROM social_accounts WHERE sociable_id = 121;\n\nhttps://crmsandbox.zoho.com/crm/jiminnyw4/tab/Leads/4776201000005049105\nhttps://crmsandbox.zoho.com/crm/\n\nhttps://crm.zoho.com/crm/org3469620/tab/Leads/230045000229559080\n https://crm.zoho.com/crm/\n org3469620\n\nSELECT * FROM activities WHERE uuid_to_bin('03382d20-c8bc-48e7-a3d4-90b52fa5ceab') = uuid;\n\nselect * from users where email LIKE \"%mobile_automation_%\";\nselect * from social_accounts where sociable_id IN (2228);\nselect * from crm_profiles where user_id IN (2222,2223,2226,2227);\n\nselect * from teams order by id desc;\nSELECT * FROM users WHERE id = 2229;\nSELECT * FROM crm_profiles WHERE user_id = 2229;\nselect * from opportunities where crm_configuration_id = 88;\nselect * from crm_fields where crm_configuration_id = 88;\nselect * from crm_profiles where crm_configuration_id = 88;\n\nSELECT * FROM teams WHERE id = 1;\n\nSELECT * FROM users WHERE id = 143;\nSELECT * FROM users WHERE uuid_to_bin('fde193d3-06a2-4e1a-8895-62b94039215d') = uuid;\nSELECT * FROM teams WHERE uuid_to_bin('73385071-a756-42ae-9c73-8b53f2309467') = uuid;\n\nhttps://app.staging.jiminny.com/ondemand?\n min_duration=1\n &\n only_recorded=1\n &\n user_id%5B%5D=641f1acb-16b8-42d1-8726-df52979dad0e\n &\n sequence_number=2\n\n select * from users where team_id = 1 and email like '%stoyan%'\n\nselect * from coaching_feedbacks;\n\nselect * from teams;\nSELECT * FROM users WHERE team_id = 36;\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 19\nand sa.provider = 'pipedrive';\n\nselect * from users where id = 143;\n\nSELECT * FROM users WHERE uuid_to_bin('73180eeb-33de-4065-977d-ccbe0e6c94fc') = uuid;\nSELECT * FROM teams WHERE uuid_to_bin('73180eeb-33de-4065-977d-ccbe0e6c94fc') = uuid;\nSELECT * FROM activity_shares WHERE uuid_to_bin('73180eeb-33de-4065-977d-ccbe0e6c94fc') = uuid;\n\nselect * from users where team_id = 2;\nselect * from activities where crm_configuration_id = 39\nand activities.scheduled_start_time BETWEEN '2025-04-09 00:00:00' AND '2025-04-09 23:59:59'\nAND user_id = 143\norder by id desc;\n\n# ************************************************************************************\nselect * from teams where id = 142; # 2312, 126\nselect * from team_settings;\nselect * from users where team_id = 142; # 21642\nSELECT * FROM social_accounts WHERE sociable_id = 21642;\nSELECT * FROM crm_profiles cp join users u ON u.id = cp.user_id WHERE team_id = 142;\nselect * from crm_profiles where id IN (93);\nselect * from invitations;\nselect * from team_features where team_id = 1;\n\nSELECT * FROM crm_configurations WHERE id = 126;\nselect * from accounts where crm_configuration_id = 126 order by id desc;\nselect * from leads where crm_configuration_id = 126 order by id desc;\nselect * from contacts where crm_configuration_id = 126 order by id desc;\nselect * from opportunities where crm_configuration_id = 126 order by id desc;\nselect * from crm_profiles where crm_configuration_id = 126 order by id desc;\nselect * from crm_fields where crm_configuration_id = 126 # 11060\n# and type IN ('picklist', 'status')\n# and object_type = 'task'\norder by id desc;\n# 5731,5732,5733\nselect DISTINCT crm_field_id from crm_field_values where crm_field_id IN (11151,12239,12215,12185,12175,12165,12144,12137,12127,12109,12107,12105,12103,12092,12037,12005,12003,11987,11969,11958,11951,11942,11931,11924,11921,11917,11915,11901,11893,11883,11872,11870,11868,11866,11839,11833,11821,11793,11780,11777,11769,11757,11737,11735,11656,11645,11638,11629,11618,11611,11602,11591,11584,11581,11558,11544,11543,11534,11532,11529,11527,11503,11497,11493,11488,11470,11468,11457,11455,11397,11387,11372,11363,11348,11323,11318,11309,11301,11300,11292,11290,11286,11284,11256,11252,11242,11237,11233,11219,11176,11160) order by id desc;\nselect * from crm_layouts where crm_configuration_id = 126 order by id desc;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id in (300,299,298);\nselect * from stages where crm_configuration_id = 126 order by id desc;\nselect * from business_processes where crm_configuration_id = 126 order by id desc;\nselect * from business_process_stages where business_process_id IN (76,75,74,73);\nselect * from playbooks where team_id = 142;\nselect * from playbook_layouts where playbook_id IN (108);\nSELECT * FROM playbook_categories WHERE playbook_id IN (108);\n\nselect * from teams where id = 130;\nSELECT * FROM social_accounts WHERE sociable_id = 2291;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 2\nand sa.provider = 'hubspot';\n\nSELECT * FROM activities\n WHERE crm_configuration_id = 110;\n\nselect * from teams;\nselect * from crm_configurations;\n\nSELECT * FROM activities WHERE id = 628773;\nSELECT * FROM crm_profiles WHERE user_id = 1460;\nSELECT * FROM social_accounts WHERE sociable_id = 2291;\n\nselect * from teams;\nselect ru.*, pr.*, p.* from users u join role_user ru on ru.user_id = u.id\njoin permission_role pr on pr.role_id = ru.role_id\n join permissions p on p.id = pr.permission_id\nwhere team_id = 495 and p.name IN ('dial');\n\nselect * from teams where id = 145;\nselect * from crm_configurations where id = 129;\nselect * from social_accounts where sociable_id = 2317;\nSELECT * FROM activities WHERE uuid_to_bin('8dbab184-a333-4268-ad57-fb41f8d53a9a') = uuid;\n\nselect * from teams where id = 1;\nSELECT * FROM crm_layouts WHERE crm_configuration_id = 39;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 280;\nSELECT * FROM crm_layout_entities WHERE id = 5507;\nSELECT * FROM crm_fields WHERE crm_configuration_id = 39 and object_type IN ('event');\n\nselect * from teams;\nselect * from activities where crm_configuration_id = 14;\n\nSELECT * FROM social_accounts where provider = 'copper';\n\nselect * from activities where id = 628467;\nselect * from participants where activity_id = 628467;\n\nSELECT * FROM contacts WHERE id = 3969;\nSELECT * FROM accounts WHERE id = 177;\n\nSELECT * FROM activities WHERE uuid_to_bin('4eb54c77-cfa3-2bd4-84a7-9ed46a21c988') = uuid;\n\n# ********************* BH\nselect * from teams where id = 36;\nSELECT * FROM crm_configurations WHERE id = 21;\nselect * from activities where crm_configuration_id = 21 and id = 607901;\nselect * from activities where crm_configuration_id = 21;\n\nselect * roles;\nselect * from permissions;\nselect * from permission_role where permission_id = 226;\n\nselect * from migrations order by id desc;\n\n# mercury\n# neptune\n# earth\n\nselect * from teams;\nselect * from teams where id = 19;\nselect * from teams where id = 27;\nselect * from users where team_id = 27;\nSELECT * FROM crm_configurations WHERE id = 42;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 19\nand sa.provider = 'pipedrive';\n\nselect * from activities where id = 631461;\nSELECT * FROM crm_field_values WHERE crm_field_id = 180;\n\nselect * from teams where id = 2;\nSELECT * FROM social_accounts WHERE sociable_id = 89;\n\nSELECT * FROM activities WHERE uuid_to_bin('ba0c029a-bc14-4e17-8603-64174acebcbb') = uuid; # 634273\nselect * from activity_summary_logs where activity_id = 634273;\n\nselect * from sidekick_settings where team_id = 2;\n\nselect * from teams; # 2, 2\nSELECT * FROM crm_configurations WHERE team_id = 2; # 2\nselect * from team_features where team_id = 2;\nselect * from features;\nSELECT * FROM opportunities WHERE crm_configuration_id = 2 and crm_provider_id = '51317301383';\nSELECT * FROM opportunities WHERE crm_configuration_id = 2 order by id desc;\n\nselect * from automated_reports order by id desc;\nselect * from automated_report_results order by id desc;\nselect * from users where team_id = 1 and id IN (7160, 3248);\nselect * from migrations order by id desc;\n\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 1 and sa.provider = 'salesforce';\n\nselect * from teams where id = 1;\nselect * from groups g JOIN playbooks p on g.playbook_id = p.id where g.team_id = 1;\nselect * from groups where id = 565;\nselect * from playbooks where team_id = 1;\nselect * from playbooks where id = 175;\nselect * from playbook_categories where playbook_id = 175;\nselect * from users where team_id = 1;\nselect * from users where id = 7160;\nselect * from crm_profiles where user_id = 7160;\nselect * from features;\nselect\n *\n# id, uuid, type, provider, playbook_category_id, user_id, lead_id, contact_id, account_id, opportunity_id, stage_id,\n# crm_configuration_id, crm_provider_id, transcription_id, status\nfrom activities where crm_configuration_id = 1 and type = 'conference'\n# and crm_provider_id IS NOT NULL\nand provider != 'uploader' and actual_start_time IS NOT NULL\nORDER by id desc;\nselect * from activities where id = 54747783; # 00UO400000pCzojMAC\n\nselect p.id, p.activity_type, pc.id, pc.name\nFROM playbooks p\njoin playbook_categories pc on p.id = pc.playbook_id\nwhere p.team_id = 1 and p.activity_type = 'event';\n\nSELECT * FROM crm_fields WHERE crm_configuration_id = 1 and object_type = 'event';\nSELECT * FROM crm_field_values WHERE crm_field_id = 4;\n\nselect * from crm_layouts cl join playbook_layouts pl on cl.id = pl.layout_id\nwhere crm_configuration_id = 1 and pl.playbook_id = 175;\n\nselect * from teams;\nSELECT r.* FROM automated_reports r\njoin teams t on r.team_id = t.id\nWHERE r.frequency = 'daily'\n and r.status = 1\nAND t.status = 'active'\nAND (r.expires_at >= now() OR r.expires_at IS NULL);\n\nselect * from automated_report_results where report_id IN (18, 33);\n\nselect * from activity_searches where id = 10932;\nselect * from activity_search_filters where activity_search_id = 10932;\nselect * from automated_reports;\nselect * from automated_report_results where report_id IN (34, 35);","depth":4,"value":"SELECT * FROM teams WHERE id = 1;\n\nselect * from crm_layouts where crm_configuration_id = 39;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 283;\nSELECT * FROM crm_fields WHERE id = 2234;\nSELECT * FROM crm_field_values WHERE crm_field_id = 2234;\n\nselect * from crm_profiles where user_id = 143;\n\nselect * from record_types where crm_configuration_id = 39; # 0121K000001MHElQAO,0121K000001MHEqQAO\nselect * from business_processes where crm_configuration_id = 39;\n# 01941000000H669AAC, 01941000000H66JAAS\n\nselect * from record_type_field_values\n where record_type_id IN (24);\n\nselect * from crm_field_values where id IN (2730);\n\nselect * from crm_configurations where id = 39;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 1\nand sa.provider = 'salesforce'; #1035\n\n\nselect * from users where team_id = 1; # 222 group 3\nSELECT * FROM activities WHERE user_id = 222 order by id desc;\nselect * from sidekick_settings where team_id = 1;\nselect * from teams where id = 1;\nselect * from team_features where team_id = 1;\n\nselect * from activities where crm_configuration_id = 2\nand provider = 'ms-teams' and id = 608765;\n\nSELECT * FROM activities WHERE crm_configuration_id = 2 and crm_provider_id = '59523413338';\n\nselect * from sidekick_settings where team_id = 2;\n\nSELECT * FROM activities WHERE id = 608660;\nselect * from activity_summary_logs where activity_id = 608660;\nselect * from ai_prompts where transcription_id = 11214;\n\n# ********************************************************************************************************\nSELECT * FROM activities WHERE uuid_to_bin('ed78a437-2804-450e-ab2f-56ab1c641346') = uuid;\n# id: 608818, crm: 59628809737\nSELECT * FROM activities WHERE uuid_to_bin('36b06e55-afdd-4782-8dee-c624cd0af191') = uuid;\n# id: 608821, crm: 59632069252\nSELECT ce.start_time, ce.end_time, a.id, a.uuid, crm_provider_id, calendar_event_id, title,\nplaybook_category_id, user_id, lead_id, contact_id, account_id, opportunity_id,\nscheduled_start_time, scheduled_end_time, actual_start_time, actual_end_time, a.created_at\nFROM activities a\njoin calendar_events ce on a.calendar_event_id = ce.id\nWHERE a.id IN (608818, 608821);\n\nselect * from users where team_id = 1;\nselect * from team_settings where team_id = 1;\nselect * from crm_profiles where crm_configuration_id = 39 order by user_id;\n\nselect * from team_features where team_id = 1;\n\nselect * from users where team_id = 2;\n\nSELECT * FROM activities WHERE uuid_to_bin('ec7647e9-5225-458b-b475-f31aa2769204') = uuid; # 612639\n# Preslava N. Ivanova, grou id 3\n\nSELECT * FROM opportunities WHERE uuid_to_bin('a2928fe5-aec5-46cb-85d9-7654c89e46a6') = uuid;\n\nselect * from activities where opportunity_id = 344 and actual_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00';\n\nselect\n a.id,\n a.type,\n a.scheduled_start_time,\n a.actual_start_time,\n a.created_at,\n a.opportunity_id,\n a.status\nFROM activities a\nWHERE opportunity_id = 344\nand status IN ('completed', 'received', 'delivered')\nand (\n (a.actual_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00')\nOR (a.created_at between '2024-10-11 00:00:00' and '2024-10-12 00:00:00')\nOR (a.scheduled_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00'))\n;\n\nSELECT * FROM users WHERE id = 222;\n\nSELECT * FROM crm_profiles WHERE user_id = 222;\nselect * from crm_layouts where crm_configuration_id = 39;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 281;\n\nselect * from group_deal_risk_types;\n\nselect * from opportunities where team_id = 1;\n\nSELECT * FROM opportunities WHERE id = 315;\nSELECT * FROM crm_field_data WHERE object_id = 315;\nselect * from crm_field_data where object_id = 260;\n\nselect * from generic_ai_prompts where subject_id = 315;\n\nselect * from teams; # 36, 21, 121, james.graham@bullhorn.jiminny.com\nSELECT * FROM social_accounts WHERE sociable_id = 121 and provider = 'bullhorn';\n\n# ************************************************************************************\nselect * from teams where id = 1;\nselect * from crm_configurations where id = 39;\nselect * from users where team_id = 1;\nselect u.email, cp.* from users u\njoin crm_profiles cp on u.id = cp.user_id\nwhere u.team_id = 1;\n# 1 - 00541000004281rAAA\n# 204 - 0052g000003freeAAA\n# 429 - 0052g000003qGOiAAM\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 1\nand sa.provider = 'salesforce';\n\nselect * from activities where type = 'softphone'\nand created_at > '2024-12-11 15:24:36' order by id desc;\n\nselect * from activity_providers where team_id = 1;\nselect * from activity_provider_users where activity_provider_id = 328;\n\nselect * from opportunities where crm_configuration_id = 39\nAND account_id = 178 AND is_closed = false\norder by created_at DESC;\n\nselect * from contacts where id = 3952;\nselect * from accounts where id = 178;\n\n# ************************************************************************************\nselect * from teams where id = 36;\nselect * from crm_configurations where id = 21;\nselect * from users where team_id = 36;\nselect u.email, cp.* from users u\njoin crm_profiles cp on u.id = cp.user_id\nwhere u.team_id = 36;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 36\nand sa.provider = 'bullhorn';\n\nselect * from social_accounts where id = 348;\nUPDATE social_accounts SET\nprovider_user_token = '21442_6802599_91:41179a58-21e7-4d7c-ad58-56bb666b2f65',\nprovider_refresh_token = '21442_6802599_91:01c6b335-3f2a-42e4-85ff-8a08fa65fceb',\nexpires = 1733998131,\nstate = 'connected'\nWHERE id = 348;\n\n# ************************************************************************************\nselect * from teams where id = 31;\nselect * from crm_configurations where id = 18;\n\nselect * from users where team_id = 31; # 257\nselect u.email, cp.* from users u\njoin crm_profiles cp on u.id = cp.user_id\nwhere u.team_id = 31;\n\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 31\nand sa.provider = 'close';\n\nselect * from contacts where crm_configuration_id = 18;\n\n# ********************** NEPTUNE **************************************************************\nselect * from teams;\nselect * from users where id IN (1030, 1035, 1052);\nselect * from crm_configurations;\n\nselect * from users where team_id = 65; # 257\nselect * from team_settings where team_id = 65; # 257\nselect * from invitations where team_id = 65; # 257\nselect * from users where email = 'integration-account@jiminny.com'; # 257\nselect u.email, cp.* from users u\njoin crm_profiles cp on u.id = cp.user_id\nwhere u.team_id = 65;\n\nselect * from crm_configurations where id = 53;\nselect * from accounts where crm_configuration_id = 53 order by id desc;\nselect * from leads where crm_configuration_id = 53 order by id desc;\nselect * from contacts where crm_configuration_id = 53 order by id desc;\nselect * from opportunities where crm_configuration_id = 53 order by id desc;\nselect * from crm_profiles where crm_configuration_id = 53 order by id desc;\nselect * from crm_fields where crm_configuration_id = 53 order by id desc;\nselect * from crm_field_values where crm_field_id = 3341 order by id desc;\nselect * from crm_layouts where crm_configuration_id = 53 order by id desc;\nselect * from stages where crm_configuration_id = 53 order by id desc;\n\n\nselect * from crm_profiles where crm_configuration_id = 13;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 65\nand sa.provider = 'integration-app';\n\nselect * from contacts where crm_configuration_id = 13;\n\nselect * from social_accounts where sociable_id = 283;\n\nSELECT * FROM opportunities WHERE crm_provider_id = '006O400000E9bzeIAB';\n\nselect * from activity_providers where team_id = 65;\nSELECT * FROM activities WHERE crm_configuration_id IN (51, 52, 53);\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 65\n;\n\n# ***************************** STAGING ********************************************\nSELECT * FROM teams;\nSELECT * FROM teams WHERE id = 88;\nSELECT * FROM teams WHERE id = 89;\nselect * from team_settings where team_id = 89;\nSELECT * FROM users WHERE team_id = 89;\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 89;\n\nselect * from users;\nSELECT * FROM social_accounts WHERE sociable_id = 1761;\nSELECT * FROM crm_configurations WHERE id = 70;\nselect * from accounts where crm_configuration_id = 70 order by id desc;\nselect * from leads where crm_configuration_id = 70 order by id desc;\nselect * from contacts where crm_configuration_id = 70 order by id desc;\nselect * from opportunities where crm_configuration_id = 70 order by id desc;\nselect * from crm_profiles where crm_configuration_id = 70 order by id desc;\nselect * from crm_fields where crm_configuration_id = 70 order by id desc;\nselect * from crm_field_values where crm_field_id = 3536 order by id desc;\nselect * from crm_layouts where crm_configuration_id = 70 order by id desc;\nselect * from stages where crm_configuration_id = 70 order by id desc;\nselect * from business_processes where crm_configuration_id = 70 order by id desc;\nselect * from business_process_stages where business_process_id = 34;\n\nselect * from contacts where id = 10468;\n\nselect * from crm_layouts where crm_configuration_id = 70;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 388;\nSELECT * FROM crm_fields WHERE id IN (3533,3534,3535);\n\nselect * from activities where crm_configuration_id = 70\nand (account_id IS NOT NULL or lead_id IS NOT NULL or contact_id IS NOT NULL or opportunity_id IS NOT NULL) order by id desc;\n\nSELECT * FROM activities WHERE uuid_to_bin('2e10b60f-8a61-41c5-a3d4-28835353dc65') = uuid;\nSELECT * FROM activities where crm_configuration_id = 69 ;\n\nSELECT * FROM users WHERE email LIKE '%jiminny_web_sa2@jiminny.com%';\nSELECT * FROM activities WHERE uuid_to_bin('5a150c93-40fc-42ec-b3bd-c1d328e09f6e') = uuid;\nSELECT * FROM opportunities WHERE id = 385;\n\nselect * from participants p\njoin activities a on p.activity_id = a.id\nwhere a.crm_configuration_id = 70\nand (p.lead_id IS NOT NULL or p.contact_id IS NOT NULL);\nSELECT * FROM participants WHERE id = 1013638;\n\nselect * from teams where id = 90;\nselect * from users where team_id = 90;\nselect * from social_accounts where social_accounts.sociable_id IN (1960,1760);\nSELECT * FROM crm_profiles WHERE crm_configuration_id = 71;\nselect * from invitations where team_id = 90;\n\nselect * from crm_configurations where id = 71;\nselect * from accounts where crm_configuration_id = 71 order by id desc;\nselect * from leads where crm_configuration_id = 71 order by id desc;\nselect * from contacts where crm_configuration_id = 71 order by id desc;\nselect * from opportunities where crm_configuration_id = 71 order by id desc;\nselect * from crm_profiles where crm_configuration_id = 71 order by id desc;\nselect * from crm_fields where crm_configuration_id = 71 order by id desc;\nselect * from crm_field_values where crm_field_id = 3341 order by id desc;\nselect * from crm_layouts where crm_configuration_id = 71 order by id desc;\nselect * from stages where crm_configuration_id = 71 order by id desc;\n\nselect * from users order by secondary_email desc;\nselect u.id, u.email, u.status, sa.id, sa.provider_user_id from social_accounts sa\n join users u on sa.sociable_id = u.id\nwhere sa.provider = 'google' and u.email LIKE 'aneliya%';\n\nselect * from failed_jobs order by id desc;\n\nselect * from users where email = 'ben.allwright@learningpeople.co.uk' or secondary_email = 'ben.allwright@learningpeople.co.uk';\n\nselect * from teams;\nSELECT * FROM crm_profiles WHERE crm_configuration_id = 39;\nSELECT * FROM crm_fields WHERE crm_configuration_id = 39 and object_type = 'task';\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 1\nand sa.provider = 'salesforce';\n\n# ************************************************************************************\nSELECT * FROM activities WHERE uuid_to_bin('c38b3895-fd0f-4b1f-9fb2-c170dba137c6') = uuid;\nSELECT * FROM crm_configurations WHERE id = 70;\n\nselect * from teams where id = 1;\nselect * from groups where team_id = 1;\nselect * from users where team_id = 1;\n\nselect o.id, o.name,o.close_date, u.id, u.name, u.group_id, r.id, r.display_name, g.name, g.scope from opportunities o\njoin users u on o.user_id = u.id\njoin groups g on u.group_id = g.id\njoin role_user ru on u.id = ru.user_id\njoin roles r on ru.role_id = r.id\nwhere o.crm_configuration_id = 39 and close_date > '2024-01-01 00:00:00';\n\nselect * from role_user where user_id = 143;\nselect * from roles;\n\nselect * from role_user;\nselect * from groups where id = 9;\nselect * from scope_groups where group_id = 9;\n\n# ************************************************************************************\nselect * from teams where id = 36;\nselect * from crm_configurations;\nSELECT * FROM social_accounts WHERE sociable_id = 121;\n\nhttps://crmsandbox.zoho.com/crm/jiminnyw4/tab/Leads/4776201000005049105\nhttps://crmsandbox.zoho.com/crm/\n\nhttps://crm.zoho.com/crm/org3469620/tab/Leads/230045000229559080\n https://crm.zoho.com/crm/\n org3469620\n\nSELECT * FROM activities WHERE uuid_to_bin('03382d20-c8bc-48e7-a3d4-90b52fa5ceab') = uuid;\n\nselect * from users where email LIKE \"%mobile_automation_%\";\nselect * from social_accounts where sociable_id IN (2228);\nselect * from crm_profiles where user_id IN (2222,2223,2226,2227);\n\nselect * from teams order by id desc;\nSELECT * FROM users WHERE id = 2229;\nSELECT * FROM crm_profiles WHERE user_id = 2229;\nselect * from opportunities where crm_configuration_id = 88;\nselect * from crm_fields where crm_configuration_id = 88;\nselect * from crm_profiles where crm_configuration_id = 88;\n\nSELECT * FROM teams WHERE id = 1;\n\nSELECT * FROM users WHERE id = 143;\nSELECT * FROM users WHERE uuid_to_bin('fde193d3-06a2-4e1a-8895-62b94039215d') = uuid;\nSELECT * FROM teams WHERE uuid_to_bin('73385071-a756-42ae-9c73-8b53f2309467') = uuid;\n\nhttps://app.staging.jiminny.com/ondemand?\n min_duration=1\n &\n only_recorded=1\n &\n user_id%5B%5D=641f1acb-16b8-42d1-8726-df52979dad0e\n &\n sequence_number=2\n\n select * from users where team_id = 1 and email like '%stoyan%'\n\nselect * from coaching_feedbacks;\n\nselect * from teams;\nSELECT * FROM users WHERE team_id = 36;\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 19\nand sa.provider = 'pipedrive';\n\nselect * from users where id = 143;\n\nSELECT * FROM users WHERE uuid_to_bin('73180eeb-33de-4065-977d-ccbe0e6c94fc') = uuid;\nSELECT * FROM teams WHERE uuid_to_bin('73180eeb-33de-4065-977d-ccbe0e6c94fc') = uuid;\nSELECT * FROM activity_shares WHERE uuid_to_bin('73180eeb-33de-4065-977d-ccbe0e6c94fc') = uuid;\n\nselect * from users where team_id = 2;\nselect * from activities where crm_configuration_id = 39\nand activities.scheduled_start_time BETWEEN '2025-04-09 00:00:00' AND '2025-04-09 23:59:59'\nAND user_id = 143\norder by id desc;\n\n# ************************************************************************************\nselect * from teams where id = 142; # 2312, 126\nselect * from team_settings;\nselect * from users where team_id = 142; # 21642\nSELECT * FROM social_accounts WHERE sociable_id = 21642;\nSELECT * FROM crm_profiles cp join users u ON u.id = cp.user_id WHERE team_id = 142;\nselect * from crm_profiles where id IN (93);\nselect * from invitations;\nselect * from team_features where team_id = 1;\n\nSELECT * FROM crm_configurations WHERE id = 126;\nselect * from accounts where crm_configuration_id = 126 order by id desc;\nselect * from leads where crm_configuration_id = 126 order by id desc;\nselect * from contacts where crm_configuration_id = 126 order by id desc;\nselect * from opportunities where crm_configuration_id = 126 order by id desc;\nselect * from crm_profiles where crm_configuration_id = 126 order by id desc;\nselect * from crm_fields where crm_configuration_id = 126 # 11060\n# and type IN ('picklist', 'status')\n# and object_type = 'task'\norder by id desc;\n# 5731,5732,5733\nselect DISTINCT crm_field_id from crm_field_values where crm_field_id IN (11151,12239,12215,12185,12175,12165,12144,12137,12127,12109,12107,12105,12103,12092,12037,12005,12003,11987,11969,11958,11951,11942,11931,11924,11921,11917,11915,11901,11893,11883,11872,11870,11868,11866,11839,11833,11821,11793,11780,11777,11769,11757,11737,11735,11656,11645,11638,11629,11618,11611,11602,11591,11584,11581,11558,11544,11543,11534,11532,11529,11527,11503,11497,11493,11488,11470,11468,11457,11455,11397,11387,11372,11363,11348,11323,11318,11309,11301,11300,11292,11290,11286,11284,11256,11252,11242,11237,11233,11219,11176,11160) order by id desc;\nselect * from crm_layouts where crm_configuration_id = 126 order by id desc;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id in (300,299,298);\nselect * from stages where crm_configuration_id = 126 order by id desc;\nselect * from business_processes where crm_configuration_id = 126 order by id desc;\nselect * from business_process_stages where business_process_id IN (76,75,74,73);\nselect * from playbooks where team_id = 142;\nselect * from playbook_layouts where playbook_id IN (108);\nSELECT * FROM playbook_categories WHERE playbook_id IN (108);\n\nselect * from teams where id = 130;\nSELECT * FROM social_accounts WHERE sociable_id = 2291;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 2\nand sa.provider = 'hubspot';\n\nSELECT * FROM activities\n WHERE crm_configuration_id = 110;\n\nselect * from teams;\nselect * from crm_configurations;\n\nSELECT * FROM activities WHERE id = 628773;\nSELECT * FROM crm_profiles WHERE user_id = 1460;\nSELECT * FROM social_accounts WHERE sociable_id = 2291;\n\nselect * from teams;\nselect ru.*, pr.*, p.* from users u join role_user ru on ru.user_id = u.id\njoin permission_role pr on pr.role_id = ru.role_id\n join permissions p on p.id = pr.permission_id\nwhere team_id = 495 and p.name IN ('dial');\n\nselect * from teams where id = 145;\nselect * from crm_configurations where id = 129;\nselect * from social_accounts where sociable_id = 2317;\nSELECT * FROM activities WHERE uuid_to_bin('8dbab184-a333-4268-ad57-fb41f8d53a9a') = uuid;\n\nselect * from teams where id = 1;\nSELECT * FROM crm_layouts WHERE crm_configuration_id = 39;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 280;\nSELECT * FROM crm_layout_entities WHERE id = 5507;\nSELECT * FROM crm_fields WHERE crm_configuration_id = 39 and object_type IN ('event');\n\nselect * from teams;\nselect * from activities where crm_configuration_id = 14;\n\nSELECT * FROM social_accounts where provider = 'copper';\n\nselect * from activities where id = 628467;\nselect * from participants where activity_id = 628467;\n\nSELECT * FROM contacts WHERE id = 3969;\nSELECT * FROM accounts WHERE id = 177;\n\nSELECT * FROM activities WHERE uuid_to_bin('4eb54c77-cfa3-2bd4-84a7-9ed46a21c988') = uuid;\n\n# ********************* BH\nselect * from teams where id = 36;\nSELECT * FROM crm_configurations WHERE id = 21;\nselect * from activities where crm_configuration_id = 21 and id = 607901;\nselect * from activities where crm_configuration_id = 21;\n\nselect * roles;\nselect * from permissions;\nselect * from permission_role where permission_id = 226;\n\nselect * from migrations order by id desc;\n\n# mercury\n# neptune\n# earth\n\nselect * from teams;\nselect * from teams where id = 19;\nselect * from teams where id = 27;\nselect * from users where team_id = 27;\nSELECT * FROM crm_configurations WHERE id = 42;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 19\nand sa.provider = 'pipedrive';\n\nselect * from activities where id = 631461;\nSELECT * FROM crm_field_values WHERE crm_field_id = 180;\n\nselect * from teams where id = 2;\nSELECT * FROM social_accounts WHERE sociable_id = 89;\n\nSELECT * FROM activities WHERE uuid_to_bin('ba0c029a-bc14-4e17-8603-64174acebcbb') = uuid; # 634273\nselect * from activity_summary_logs where activity_id = 634273;\n\nselect * from sidekick_settings where team_id = 2;\n\nselect * from teams; # 2, 2\nSELECT * FROM crm_configurations WHERE team_id = 2; # 2\nselect * from team_features where team_id = 2;\nselect * from features;\nSELECT * FROM opportunities WHERE crm_configuration_id = 2 and crm_provider_id = '51317301383';\nSELECT * FROM opportunities WHERE crm_configuration_id = 2 order by id desc;\n\nselect * from automated_reports order by id desc;\nselect * from automated_report_results order by id desc;\nselect * from users where team_id = 1 and id IN (7160, 3248);\nselect * from migrations order by id desc;\n\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 1 and sa.provider = 'salesforce';\n\nselect * from teams where id = 1;\nselect * from groups g JOIN playbooks p on g.playbook_id = p.id where g.team_id = 1;\nselect * from groups where id = 565;\nselect * from playbooks where team_id = 1;\nselect * from playbooks where id = 175;\nselect * from playbook_categories where playbook_id = 175;\nselect * from users where team_id = 1;\nselect * from users where id = 7160;\nselect * from crm_profiles where user_id = 7160;\nselect * from features;\nselect\n *\n# id, uuid, type, provider, playbook_category_id, user_id, lead_id, contact_id, account_id, opportunity_id, stage_id,\n# crm_configuration_id, crm_provider_id, transcription_id, status\nfrom activities where crm_configuration_id = 1 and type = 'conference'\n# and crm_provider_id IS NOT NULL\nand provider != 'uploader' and actual_start_time IS NOT NULL\nORDER by id desc;\nselect * from activities where id = 54747783; # 00UO400000pCzojMAC\n\nselect p.id, p.activity_type, pc.id, pc.name\nFROM playbooks p\njoin playbook_categories pc on p.id = pc.playbook_id\nwhere p.team_id = 1 and p.activity_type = 'event';\n\nSELECT * FROM crm_fields WHERE crm_configuration_id = 1 and object_type = 'event';\nSELECT * FROM crm_field_values WHERE crm_field_id = 4;\n\nselect * from crm_layouts cl join playbook_layouts pl on cl.id = pl.layout_id\nwhere crm_configuration_id = 1 and pl.playbook_id = 175;\n\nselect * from teams;\nSELECT r.* FROM automated_reports r\njoin teams t on r.team_id = t.id\nWHERE r.frequency = 'daily'\n and r.status = 1\nAND t.status = 'active'\nAND (r.expires_at >= now() OR r.expires_at IS NULL);\n\nselect * from automated_report_results where report_id IN (18, 33);\n\nselect * from activity_searches where id = 10932;\nselect * from activity_search_filters where activity_search_id = 10932;\nselect * from automated_reports;\nselect * from automated_report_results where report_id IN (34, 35);","role_description":"text entry area","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.088194445,"height":0.027777778},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"102","depth":4,"role_description":"text"},{"role":"AXStaticText","text":"3","depth":4,"role_description":"text"},{"role":"AXStaticText","text":"34","depth":4,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Services\\Kiosk\\AutomatedReports;\n\nuse Carbon\\CarbonImmutable;\nuse Carbon\\CarbonInterface;\nuse Carbon\\Exceptions\\InvalidFormatException;\nuse DateTime;\nuse DateTimeInterface;\nuse DateTimeZone;\nuse Illuminate\\Contracts\\Bus\\Dispatcher as BusDispatcher;\nuse Illuminate\\Database\\Eloquent\\Builder;\nuse Illuminate\\Support\\Carbon;\nuse Illuminate\\Support\\Collection;\nuse Illuminate\\Support\\Facades\\Log;\nuse Illuminate\\Support\\Facades\\Storage;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinition\\InputTypeEnum;\nuse Jiminny\\Component\\AskAnything\\AskAnythingPromptService;\nuse Jiminny\\Component\\AskAnything\\Dtos\\AskAnythingPromptDto;\nuse Jiminny\\Component\\UrlGenerator\\Webhook;\nuse Jiminny\\Contracts\\Repositories\\PlaybookCategoryRepository;\nuse Jiminny\\Contracts\\Repositories\\TeamRepository;\nuse Jiminny\\Contracts\\Repositories\\UserRepository;\nuse Jiminny\\Exceptions\\ApplicationException;\nuse Jiminny\\Exceptions\\InvalidArgumentException;\nuse Jiminny\\Exceptions\\ModelNotFoundException;\nuse Jiminny\\Jobs\\AutomatedReports\\RequestGenerateReportJob;\nuse Jiminny\\Models\\Activity\\Search;\nuse Jiminny\\Models\\AskAnything\\AskAnythingPrompt;\nuse Jiminny\\Models\\AskAnything\\AskAnythingPromptTarget;\nuse Jiminny\\Models\\AutomatedReport;\nuse Jiminny\\Models\\AutomatedReportResult;\nuse Jiminny\\Models\\Contracts\\UserContract;\nuse Jiminny\\Models\\Feature\\FeatureEnum;\nuse Jiminny\\Models\\Team;\nuse Jiminny\\Models\\User;\nuse Jiminny\\Repositories\\AskAnythingRepository;\nuse Jiminny\\Repositories\\AutomatedReportsRepository;\nuse Jiminny\\Repositories\\GroupRepository;\nuse Jiminny\\Repositories\\SearchRepository;\nuse Jiminny\\Repositories\\StageRepository;\nuse Throwable;\n\nclass AutomatedReportsService\n{\n public const string TYPE_LOSS_ANALYSIS = 'loss_analysis';\n public const string TYPE_ASK_JIMINNY = 'ask_jiminny';\n\n /**\n * Standard report types (used by kiosk for existing automated reports).\n */\n // @TODO this will add filter, however if we need to control feature by FF we need conditional logic\n public const array TYPES = [\n ['id' => 'exec_summary', 'name' => 'Exec Summary'],\n ['id' => 'coaching_profiles', 'name' => 'Coaching Profiles'],\n ['id' => 'product_feedback', 'name' => 'Product Feedback'],\n ['id' => self::TYPE_LOSS_ANALYSIS, 'name' => 'Loss Analysis'],\n// ['id' => 'questions', 'name' => 'Questions'],\n// ['id' => 'statistical_quant', 'name' => 'Statistical Quantitative'],\n ];\n\n public const array ALL_TYPES = [\n ...self::TYPES,\n ['id' => self::TYPE_ASK_JIMINNY, 'name' => 'Ask Jiminny'],\n ];\n\n public const string FREQUENCY_DAILY = 'daily';\n public const string FREQUENCY_WEEKLY = 'weekly';\n public const string FREQUENCY_MONTHLY = 'monthly';\n public const string FREQUENCY_QUARTERLY = 'quarterly';\n public const string FREQUENCY_ONE_OFF = 'one_off';\n\n /**\n * Frequencies for standard (non-Ask Jiminny) reports.\n */\n public const array FREQUENCIES = [\n ['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],\n ['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],\n ['id' => self::FREQUENCY_QUARTERLY, 'name' => 'Quarterly'],\n ['id' => self::FREQUENCY_ONE_OFF, 'name' => 'One-off'],\n ];\n\n /**\n * Frequencies for Ask Jiminny reports.\n */\n public const array ASK_JIMINNY_FREQUENCIES = [\n ['id' => self::FREQUENCY_DAILY, 'name' => 'Daily'],\n ['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],\n ['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],\n ];\n\n public const string MEDIA_TYPE_PDF = 'pdf';\n public const string MEDIA_TYPE_PODCAST = 'podcast';\n public const array MEDIA_TYPES = [self::MEDIA_TYPE_PDF, self::MEDIA_TYPE_PODCAST];\n public const array MEDIA_TYPE_OBJECT_PDF = ['id' => self::MEDIA_TYPE_PDF, 'name' => 'PDF'];\n public const array MEDIA_TYPE_OBJECT_PODCAST = ['id' => self::MEDIA_TYPE_PODCAST, 'name' => 'Podcast'];\n public const array MEDIA_TYPE_OBJECTS = [self::MEDIA_TYPE_OBJECT_PDF, self::MEDIA_TYPE_OBJECT_PODCAST];\n\n public const array CALL_TYPE_CONFERENCE = ['id' => 'conference', 'name' => 'Conference'];\n public const array CALL_TYPE_DIALER = ['id' => 'dialer', 'name' => 'Dialer'];\n public const int SENT_REPORT_AT_HOURS = 5;\n public const string PDF_KEY = 'pdf';\n public const string AUDIO_KEY = 'audio';\n\n private const array ALL_FREQUENCIES = [\n ['id' => self::FREQUENCY_DAILY, 'name' => 'Daily'],\n ['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],\n ['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],\n ['id' => self::FREQUENCY_QUARTERLY, 'name' => 'Quarterly'],\n ['id' => self::FREQUENCY_ONE_OFF, 'name' => 'One-off'],\n ];\n private const string S3_DIR = 'reports';\n private const array FILE_EXTENSIONS_VARIANTS = ['html', 'MD', 'pdf'];\n private const array FILE_PODCAST_EXTENSIONS_VARIANTS = ['json', 'mp3', 'ssml'];\n\n public function __construct(\n private readonly TeamRepository $teamRepository,\n private readonly GroupRepository $groupRepository,\n private readonly UserRepository $userRepository,\n private readonly StageRepository $stageRepository,\n private readonly DealStagesService $dealStagesService,\n private readonly RecipientsService $recipientsService,\n private readonly AutomatedReportsRepository $automatedReportsRepository,\n private readonly Webhook $webhookService,\n private readonly BusDispatcher $dispatcher,\n private readonly ActivityTypeService $activityTypeService,\n private readonly PlaybookCategoryRepository $playbookCategoryRepository,\n private readonly AskAnythingPromptService $askAnythingPromptService,\n private readonly SearchRepository $activitySearchRepository,\n private readonly AskAnythingRepository $askAnythingRepository,\n ) {\n }\n\n public static function getTypes(): array\n {\n $types = self::TYPES;\n\n return array_map(static function ($type) {\n return $type['id'];\n }, $types);\n }\n\n public static function getCallTypes(): array\n {\n return array_map(static function ($callType) {\n return $callType['id'];\n }, [self::CALL_TYPE_CONFERENCE, self::CALL_TYPE_DIALER]);\n }\n\n public static function getFrequencies(): array\n {\n return array_map(static function ($frequency) {\n return $frequency['id'];\n }, self::FREQUENCIES);\n }\n\n // front-facing structure\n public function getReportEnabledFieldData(bool $value = false): array\n {\n return [\n 'id' => 'report_enabled',\n 'label' => '',\n 'inputType' => InputTypeEnum::TOGGLE,\n 'value' => $value,\n ];\n }\n\n // Organizations = Teams\n public function getOrganizationFieldData(?string $value = null, bool $shortVersion = false): array\n {\n $options = $this->getTeams();\n\n if ($shortVersion) {\n return [\n 'id' => 'organization',\n 'label' => 'Organization',\n 'options' => $options,\n ];\n }\n\n return [\n 'id' => 'organization',\n 'label' => 'Organization',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => $options,\n 'value' => $value,\n 'dependencies' => [\n 'teams',\n 'deal_stage_at_call',\n 'current_deal_stage',\n 'recipients',\n ActivityTypeService::PLAYBOOK_CATEGORIES_KEY,\n ],\n 'dependsOn' => [],\n ];\n }\n\n // Teams = Groups\n public function getTeamFieldData(array $options = [], array $value = [], bool $shortVersion = false): array\n {\n if ($shortVersion) {\n return [\n 'id' => 'teams',\n 'label' => 'Team',\n 'options' => $options,\n ];\n }\n\n return [\n 'id' => 'teams',\n 'label' => 'Team',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'required' => false,\n 'placeholder' => 'Select',\n 'options' => $options,\n 'value' => $value, // value should be an array of objects {id, name}\n 'dependencies' => [ActivityTypeService::PLAYBOOK_CATEGORIES_KEY],\n 'dependsOn' => [],\n ];\n }\n\n public function getReportTypeFieldData(?string $value = null, bool $shortVersion = false, ?Team $team = null): array\n {\n $types = [];\n if ($team instanceof Team) {\n if ($team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {\n $types = self::TYPES;\n }\n if ($team->hasFeature(FeatureEnum::ASK_JIMINNY_REPORTS)) {\n $types[] = ['id' => self::TYPE_ASK_JIMINNY, 'name' => 'Ask Jiminny'];\n }\n } else {\n $types = self::TYPES;\n }\n\n if ($shortVersion) {\n return [\n 'id' => 'report_type',\n 'label' => 'Report Type',\n 'options' => $types,\n ];\n }\n\n return [\n 'id' => 'report_type',\n 'label' => 'Report Type',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => $types,\n 'value' => $value,\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getFrequencyFieldData(?string $value = null): array\n {\n return [\n 'id' => 'frequency',\n 'label' => 'Frequency',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => self::FREQUENCIES,\n 'value' => $value,\n 'dependencies' => ['period'],\n 'dependsOn' => [],\n ];\n }\n\n public function getPeriodFieldData(?string $valueStartDate = null, ?string $valueEndDate = null): array\n {\n return [\n 'id' => 'period',\n 'label' => 'Select one-off period',\n 'inputType' => InputTypeEnum::DATE_RANGE,\n 'required' => true,\n 'placeholder' => 'Select',\n 'value' => ['startDate' => $valueStartDate, 'endDate' => $valueEndDate],\n 'queryParams' => [\n 'startDate' => 'start_date_period',\n 'endDate' => 'end_date_period',\n ],\n 'dependencies' => [],\n 'dependsOn' => ['frequency'],\n ];\n }\n\n public function getActivityTypesFieldData(?Team $team = null, array $value = [], array $teamsFilter = []): array\n {\n return $this->activityTypeService->getActivityTypeFieldData(team: $team, value: $value, groupIds: $teamsFilter);\n }\n\n public function getDealStageAtCallFieldData(?Team $team = null, array $value = []): array\n {\n return $this->dealStagesService->getDealStageAtCallFieldData(team: $team, value: $value);\n }\n\n public function getCurrentDealStageFieldData(?Team $team = null, array $value = []): array\n {\n return $this->dealStagesService->getCurrentDealStageFieldData(team: $team, value: $value);\n }\n\n public function getDealValueFieldData(?int $valueMin = null, ?int $valueMax = null): array\n {\n return [\n 'id' => 'deal_value',\n 'label' => 'Deal Value',\n 'inputType' => InputTypeEnum::INTEGER_RANGE,\n 'required' => false,\n 'value' => ['min' => $valueMin, 'max' => $valueMax],\n 'queryParams' => [\n 'min' => 'min_deal_value',\n 'max' => 'max_deal_value',\n ],\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getCallTypeFieldData(bool $conferenceOn = false, bool $dialerOn = false): array\n {\n $value = [];\n $conferenceOn && $value[] = self::CALL_TYPE_CONFERENCE;\n $dialerOn && $value[] = self::CALL_TYPE_DIALER;\n\n return [\n 'id' => 'call_type',\n 'label' => 'Call Type',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'required' => true,\n 'options' => [\n self::CALL_TYPE_CONFERENCE,\n self::CALL_TYPE_DIALER,\n ],\n 'value' => $value,\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getMediaTypeFieldData(?AutomatedReport $report = null): array\n {\n $value = [];\n\n if ($report) {\n $value = $this->transformMediaTypes($report);\n }\n\n return [\n 'id' => 'media_types',\n 'label' => 'Export as',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'required' => true,\n 'options' => self::MEDIA_TYPE_OBJECTS,\n 'value' => $value,\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getCallDurationFieldData(?int $valueMin = null, ?int $valueMax = null): array\n {\n return [\n 'id' => 'call_duration',\n 'label' => 'Call Duration',\n 'inputType' => InputTypeEnum::INTEGER_RANGE,\n 'required' => false,\n 'value' => ['min' => $valueMin, 'max' => $valueMax],\n 'queryParams' => [\n 'min' => 'min_call_duration',\n 'max' => 'max_call_duration',\n ],\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getRecipientsFieldData(?Team $team = null, array $value = []): array\n {\n return $this->recipientsService->getRecipientsFieldData(team: $team, value: $value);\n }\n\n public function getJiminnyRecipientsFieldData(array $value = []): array\n {\n return $this->recipientsService->getJiminnyRecipientsFieldData($value);\n }\n\n public function getAdditionalPromptInputFieldData(?string $value = null): array\n {\n return [\n 'id' => 'additional_prompt_input',\n 'label' => 'Special requirements',\n 'inputType' => InputTypeEnum::TEXTAREA,\n 'required' => false,\n 'placeholder' => 'What should be the focus of the report?',\n 'value' => $value,\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getCustomReportNameFieldData(?string $value = null): array\n {\n return [\n 'id' => 'custom_name',\n 'label' => 'Custom report name',\n 'inputType' => InputTypeEnum::TEXT,\n 'required' => false,\n 'placeholder' => 'Enter custom name',\n 'value' => $value,\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n // data providers\n public function getTeams(): array\n {\n $teams = $this->teamRepository->getTeamsForKiosk(status: Team::STATUS_ACTIVE);\n\n $teamData = [];\n foreach ($teams as $team) {\n if (! $team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {\n continue;\n }\n\n $teamData[] = $this->transformTeam($team);\n }\n\n return $teamData;\n }\n\n public function getTeamGroups(string $teamUuid): array\n {\n $data = [];\n $team = $this->getTeam($teamUuid);\n\n if ($team !== null) {\n $groups = $team->groups()->get();\n\n foreach ($groups as $group) {\n $data[] = [\n 'id' => $group->getUuid(),\n 'name' => $group->getName(),\n ];\n }\n }\n\n return $data;\n }\n\n public function getTeamsGroupsOptions(array $filterTeamUuids = []): array\n {\n $data = [];\n $teams = $this->getTeams();\n\n foreach ($teams as $team) {\n if (! empty($filterTeamUuids) && ! in_array($team['id'], $filterTeamUuids, true)) {\n continue;\n }\n\n $data[] = [\n 'label' => $team['name'],\n 'groups' => $this->getTeamGroups($team['id']),\n ];\n }\n\n return $data;\n }\n\n public function getTeam(string $teamUuid): ?Team\n {\n return $this->teamRepository->idOrUuid($teamUuid);\n }\n\n public function getTeamById(int $teamId): ?Team\n {\n return $this->teamRepository->find($teamId);\n }\n\n public function getGroupsUuids(AutomatedReport $report): array\n {\n $uuids = [];\n $reportGroups = $report->getGroups();\n foreach ($reportGroups as $groupId) {\n if ($group = $this->groupRepository->find($groupId)) {\n $uuids[] = $group->getUuid();\n }\n }\n\n return $uuids;\n }\n\n public function getPlaybookCategoriesUuids(AutomatedReport $report): array\n {\n $uuids = [];\n $playbookCategories = $report->getPlaybookCategories();\n foreach ($playbookCategories as $id) {\n if ($category = $this->playbookCategoryRepository->find($id)) {\n $uuids[] = $category->getUuid();\n }\n }\n\n return $uuids;\n }\n\n public function getDealAtCallStagesUuids(AutomatedReport $report): array\n {\n $uuids = [];\n $reportStages = $report->getDealAtCallStages();\n foreach ($reportStages as $id) {\n if ($stage = $this->stageRepository->find($id)) {\n $uuids[] = $stage->getUuid();\n }\n }\n\n return $uuids;\n }\n\n public function getCurrentDealStagesUuids(AutomatedReport $report): array\n {\n $uuids = [];\n $reportStages = $report->getCurrentDealStages();\n foreach ($reportStages as $id) {\n if ($stage = $this->stageRepository->find($id)) {\n $uuids[] = $stage->getUuid();\n }\n }\n\n return $uuids;\n }\n\n public function getUsersUuids(AutomatedReport $report): array\n {\n return $this->extractUserUuids($report->getRecipients());\n }\n\n public function getJiminnyUsersUuids(AutomatedReport $report): array\n {\n return $this->extractUserUuids($report->getJiminnyRecipients());\n }\n\n /**\n * @param array<string, mixed> $recipients\n */\n private function extractUserUuids(array $recipients): array\n {\n $userIds = $recipients['users'] ?? [];\n\n return collect($userIds)\n ->map(fn ($id) => $this->userRepository->find((int) $id))\n ->filter()\n ->map(fn (UserContract $user) => $user->getUuid())\n ->values()\n ->all();\n }\n\n // get mail data\n public function getRecipientUsers(AutomatedReport $report): array\n {\n return $this->buildRecipientUsers($report->getRecipients());\n }\n\n private function getJiminnyRecipientUsers(AutomatedReport $report): array\n {\n return $this->buildRecipientUsers($report->getJiminnyRecipients());\n }\n\n /**\n * @param array<string, mixed> $recipients\n */\n private function buildRecipientUsers(array $recipients): array\n {\n $userIds = $recipients['users'] ?? [];\n\n return collect($userIds)\n ->map(fn ($id) => $this->userRepository->find((int) $id))\n ->filter()\n ->map(fn (UserContract $user) => [\n 'email' => $user->getEmailAddress(),\n 'name' => $user->getName(),\n 'timezone' => $user->getTimezone()->getName(),\n ])\n ->values()\n ->all();\n }\n\n public function getValidRecipientUsers(AutomatedReport $report, bool $includeJiminny = false): array\n {\n if ($report->isAskJiminnyReport()) {\n $recipients = $this->resolveAskJiminnyRecipients($report);\n } else {\n $recipients = $this->getRecipientUsers($report);\n if ($includeJiminny) {\n $recipients = array_merge($recipients, $this->getJiminnyRecipientUsers($report));\n }\n }\n\n $emails = [];\n\n return array_values(array_filter(\n $recipients,\n static function ($recipient) use (&$emails) {\n if (empty($recipient['email']) || in_array($recipient['email'], $emails, true)) {\n return false;\n }\n $emails[] = $recipient['email'];\n\n return true;\n }\n ));\n }\n\n private function resolveAskJiminnyRecipients(AutomatedReport $report): array\n {\n $recipients = [];\n\n $creator = $report->getCreator();\n if ($creator !== null) {\n $recipients[] = [\n 'email' => $creator->getEmailAddress(),\n 'name' => $creator->getName(),\n 'timezone' => $creator->getTimezone()->getName(),\n ];\n }\n\n return array_merge(\n $recipients,\n $this->buildRecipientUsers($report->getRecipients()),\n $this->getGroupRecipientUsers($report),\n );\n }\n\n private function getGroupRecipientUsers(AutomatedReport $report): array\n {\n $users = [];\n foreach ($report->getGroups() as $groupId) {\n $group = $this->groupRepository->find($groupId);\n if ($group === null) {\n continue;\n }\n foreach ($group->getMembers() as $member) {\n $users[] = [\n 'email' => $member->getEmailAddress(),\n 'name' => $member->getName(),\n 'timezone' => $member->getTimezone()->getName(),\n ];\n }\n }\n\n return $users;\n }\n\n public function getReportTypeName(AutomatedReportResult $report): string\n {\n $type = $report->getReport()->getType();\n\n $getType = $this->transformReportType($type);\n\n return $getType['name'];\n }\n\n public function getReportPeriodName(AutomatedReportResult $report): string\n {\n $from = $report->getFromDate();\n $to = $report->getToDate();\n $frequency = $report->getReport()->getFrequency();\n\n if ($from === null || $to === null) {\n if (! $report->getReport()->isAskJiminnyReport()) {\n $invalidPeriod = $from === null ? 'from' : 'to';\n\n throw new ApplicationException('Report period is invalid: ' . $invalidPeriod);\n }\n\n $period = $this->calculateFromAndToDatePeriod($frequency);\n $from = $period['fromDate'];\n $to = $period['toDate'];\n }\n\n return $this->formatReportPeriodName($frequency, $from, $to);\n }\n\n private function formatReportPeriodName(string $frequency, Carbon $from, Carbon $to): string\n {\n $fromYear = $from->format('Y');\n $toYear = $to->format('Y');\n $differentYears = $fromYear !== $toYear;\n\n switch ($frequency) {\n case self::FREQUENCY_DAILY:\n return $from->format('j M Y');\n\n case self::FREQUENCY_QUARTERLY:\n // 'Jan-Mar 2025' or 'Nov 2024-Jan 2025' if years differ\n $startMonth = $from->format('M');\n $endMonth = $to->copy()->subMonth();\n $endMonthName = $endMonth->format('M');\n $endMonthYear = $endMonth->format('Y');\n\n if ($differentYears) {\n return \"{$startMonth} {$fromYear} - {$endMonthName} {$endMonthYear}\";\n }\n\n return \"{$startMonth} - {$endMonthName} {$toYear}\";\n\n case self::FREQUENCY_MONTHLY:\n // 'May 2025' - monthly reports are always within the same year\n return $from->format('M Y');\n\n case self::FREQUENCY_WEEKLY:\n // '4 - 8 Aug 2025', '27 Oct - 3 Nov 2025', or '28 Dec 2024 - 3 Jan 2025' if years differ\n $startDay = $from->format('j');\n $endDay = $to->format('j');\n $startMonth = $from->format('M');\n $endMonth = $to->format('M');\n\n if ($differentYears) {\n return \"{$startDay} {$startMonth} {$fromYear} - {$endDay} {$endMonth} {$toYear}\";\n }\n\n if ($startMonth !== $endMonth) {\n return \"{$startDay} {$startMonth} - {$endDay} {$endMonth} {$toYear}\";\n }\n\n return \"{$startDay} - {$endDay} {$endMonth} {$toYear}\";\n\n case self::FREQUENCY_ONE_OFF:\n // '2 May-31 May 2025' or '15 Dec 2024-15 Jan 2025' if years differ\n $startDay = $from->format('j');\n $startMonth = $from->format('M');\n $endDay = $to->format('j');\n $endMonth = $to->format('M');\n\n // If same month and year, use a format like '2-31 May 2025'\n if ($startMonth === $endMonth && ! $differentYears) {\n return \"{$startDay} - {$endDay} {$startMonth} {$toYear}\";\n }\n\n // If different years, include both years\n if ($differentYears) {\n return \"{$startDay} {$startMonth} {$fromYear} - {$endDay} {$endMonth} {$toYear}\";\n }\n\n // Same year but different months\n return \"{$startDay} {$startMonth} - {$endDay} {$endMonth} {$toYear}\";\n\n default:\n // Default format for unknown frequencies\n return $from->format('j M Y') . ' - ' . $to->format('j M Y');\n }\n }\n\n public function getReportTeamsName(AutomatedReportResult $report): string\n {\n $groups = $report->getGroups();\n\n if (empty($groups)) {\n return 'All';\n }\n\n // Get group names from repository\n $groupNames = [];\n foreach ($groups as $groupId) {\n $group = $this->groupRepository->find($groupId);\n if ($group) {\n $groupNames[] = $group->getName();\n }\n }\n\n if (count($groupNames) === 1) {\n // Single team format\n $teamsName = $groupNames[0];\n } else {\n // Multiple teams format\n $teamsName = implode(', ', $groupNames);\n }\n\n return $teamsName;\n }\n\n public function getReportFileName(AutomatedReportResult $report): string\n {\n $customName = $report->getReport()->getCustomName();\n $periodName = $this->getReportPeriodName($report);\n $filenameSuffix = $this->getFilenameSuffix($report);\n\n if ($customName) {\n if ($filenameSuffix) {\n $customName .= \" {$filenameSuffix}\";\n }\n\n return $this->sanitizeFileName(\"{$customName} - {$periodName}\");\n }\n\n $baseName = $this->getReportTypeName($report);\n\n if ($filenameSuffix) {\n $baseName .= \" {$filenameSuffix}\";\n }\n\n return $this->sanitizeFileName(\"{$baseName} - {$periodName} - {$this->getReportTeamsName($report)}\");\n }\n\n public function getReportFileNameWithExtension(AutomatedReportResult $result): string\n {\n $extension = $this->getMediaTypeMetadata($result)['extension'];\n\n return $this->getReportFileName($result) . '.' . $extension;\n }\n\n public function sanitizeFileName(string $fileName): string\n {\n return str_replace(['/', '\\\\'], '-', $fileName);\n }\n\n public function isUserRecipientOfReport(User $user, AutomatedReport $report): bool\n {\n $recipients = array_map('intval', $report->getRecipients()['users'] ?? []);\n\n return in_array($user->getId(), $recipients);\n }\n\n public function transformReportResults(Collection $automatedReportResults): array\n {\n $data = [];\n foreach ($automatedReportResults as $automatedReportResult) {\n /** @var AutomatedReportResult $automatedReportResult */\n\n $report = $automatedReportResult->getReport();\n\n $createdBy = $report->getCreator();\n $creator = [\n 'id' => $createdBy?->getUuid(),\n 'name' => $createdBy?->getName(),\n 'email' => $createdBy?->getEmailAddress(),\n 'photoUrl' => $createdBy?->getPhotoUrl(),\n ];\n\n $data[] = [\n 'id' => $automatedReportResult->getUuid(),\n 'name' => $automatedReportResult->getName(),\n 'frequency' => $this->transformFrequency($report->getFrequency()),\n 'recipients' => [\n ...array_values($this->transformGroups(team: $report->getTeam(), groupsIds: $report->getGroups())),\n ...array_values($this->transformRecipients($report->getRecipients())),\n ],\n 'report_type' => $this->transformReportType($report->getType()),\n 'media_type' => $automatedReportResult->getMediaType(),\n 'downloadUrl' => $this->generateReportResultDownloadUrl($automatedReportResult),\n 'viewUrl' => $this->generateReportResultViewUrl($automatedReportResult),\n 'generated_at' => $automatedReportResult->getGeneratedAt()?->toIso8601String(),\n 'creator' => $creator,\n ];\n }\n\n return $data;\n }\n\n public function hasCallTypeConference(AutomatedReport $report): bool\n {\n return in_array(self::CALL_TYPE_CONFERENCE['id'], $report->getCallTypes(), true);\n }\n\n public function hasCallTypeDialer(AutomatedReport $report): bool\n {\n return in_array(self::CALL_TYPE_DIALER['id'], $report->getCallTypes(), true);\n }\n\n // transformers\n private function transformTeam(Team $team): array\n {\n if (! $team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {\n return [];\n }\n\n return [\n 'id' => $team->getUuid(),\n 'name' => $team->getName(),\n ];\n }\n\n private function transformReportFullView(AutomatedReport $report): array\n {\n $base = $this->transformReportBase($report);\n\n return $report->getType() === self::TYPE_ASK_JIMINNY\n ? $base + $this->transformAskJiminnyFields($report)\n : $base + $this->transformStandardReportFields($report);\n }\n\n private function transformReportBase(AutomatedReport $report): array\n {\n return [\n 'id' => $report->getUuid(),\n 'organization' => $this->transformOrganization(team: $report->getTeam()),\n 'report_type' => $this->transformReportType($report->getType()),\n 'frequency' => $this->transformFrequency($report->getFrequency()),\n ];\n }\n\n private function transformStandardReportFields(AutomatedReport $report): array\n {\n $team = $report->getTeam();\n\n return [\n 'report_enabled' => $report->getStatus(),\n 'start_date_period' => $report->getFrom()?->format('Y-m-d H:i:s'),\n 'end_date_period' => $report->getTo()?->format('Y-m-d H:i:s'),\n 'deal_value_min' => $report->getDealValueMin(),\n 'deal_value_max' => $report->getDealValueMax(),\n 'call_types' => $this->transformCallType($report->getCallTypes()),\n 'media_types' => $this->transformMediaTypes($report),\n 'call_duration_min' => $this->transformDurationToMinutes($report->getCallDurationMin()),\n 'call_duration_max' => $this->transformDurationToMinutes($report->getCallDurationMax()),\n 'teams' => $this->transformGroups(team: $team, groupsIds: $report->getGroups()),\n 'deal_at_call_stages' => $this->transformStages(team: $team, stagesIds: $report->getDealAtCallStages()),\n 'current_deal_stages' => $this->transformStages(team: $team, stagesIds: $report->getCurrentDealStages()),\n 'recipients' => $this->transformRecipients($report->getRecipients()),\n 'created_by' => $this->transformCreator($report->getCreator()),\n 'additional_prompt_input' => $report->getAdditionalPromptInput(),\n 'custom_name' => $report->getCustomName(),\n 'created_at' => $report->getCreatedAt()->format('Y-m-d H:i:s'),\n 'updated_at' => $report->getUpdatedAt()->format('Y-m-d H:i:s'),\n 'deleted_at' => $report->getDeletedAt()?->format('Y-m-d H:i:s'),\n ];\n }\n\n private function transformAskJiminnyFields(AutomatedReport $report): array\n {\n $team = $report->getTeam();\n $creatorId = $report->getAttribute('created_by');\n $explicitUserIds = array_values(array_filter(\n $report->getRecipients()['users'] ?? [],\n static fn ($id) => $id !== $creatorId\n ));\n\n return [\n 'report_name' => $report->getCustomName(),\n 'enabled' => $report->getStatus(),\n 'share_teams' => $this->transformGroups(team: $team, groupsIds: $report->getGroups()),\n 'share_users' => $this->transformRecipients(['users' => $explicitUserIds]),\n 'saved_search' => $this->transformSafeSearch($report->getSavedSearch()),\n 'ask_jiminny_prompt' => $this->transformAskJiminnyPrompt($report->getAskAnythingPrompt()),\n 'expires_on' => $report->getExpiresAt()?->format('Y-m-d'),\n ];\n }\n\n private function transformOrganization(?Team $team): array\n {\n return [\n 'id' => $team?->getUuid(),\n 'name' => $team?->getName(),\n ];\n }\n\n private function transformReportType(string $type): array\n {\n foreach (self::ALL_TYPES as $typeItem) {\n if ($typeItem['id'] === $type) {\n return $typeItem;\n }\n }\n\n return [];\n }\n\n private function transformCallType(array $types): array\n {\n $result = [];\n $callTypes = [self::CALL_TYPE_CONFERENCE, self::CALL_TYPE_DIALER];\n\n foreach ($types as $type) {\n foreach ($callTypes as $callTypeItem) {\n if ($callTypeItem['id'] === $type) {\n $result[] = $callTypeItem;\n\n break;\n }\n }\n }\n\n return $result;\n }\n\n private function transformMediaTypes(AutomatedReport $report): array\n {\n $values = [];\n\n foreach ($report->getMediaTypes() as $mediaType) {\n if (! in_array($mediaType, self::MEDIA_TYPES, true)) {\n continue;\n }\n\n $values[] = match ($mediaType) {\n self::MEDIA_TYPE_PDF => self::MEDIA_TYPE_OBJECT_PDF,\n self::MEDIA_TYPE_PODCAST => self::MEDIA_TYPE_OBJECT_PODCAST,\n };\n }\n\n return $values;\n }\n\n private function transformFrequency(string $frequency): array\n {\n foreach (self::ALL_FREQUENCIES as $frequencyItem) {\n if ($frequencyItem['id'] === $frequency) {\n return $frequencyItem;\n }\n }\n\n return [];\n }\n\n public function transformDurationToMinutes(?int $duration): ?int\n {\n if (! $duration) {\n return null;\n }\n\n return (int) ($duration / 60);\n }\n\n private function transformGroups(?Team $team, array $groupsIds): array\n {\n if (empty($groupsIds) || ! $team) {\n return [];\n }\n\n $data = [];\n foreach ($groupsIds as $groupId) {\n $group = $team->groups()->where('id', $groupId)->first();\n\n if ($group) {\n $data[] = [\n 'id' => $group->getUuid(),\n 'name' => $group->getName(),\n 'photoUrl' => $group->getPhotoUrl(),\n ];\n }\n }\n\n return $data;\n }\n\n private function transformStages(?Team $team, array $stagesIds): array\n {\n if (empty($stagesIds) || ! $team) {\n return [];\n }\n\n $data = [];\n foreach ($stagesIds as $stageId) {\n $stage = $team->stages()->where('id', $stageId)->first();\n\n if ($stage) {\n $data[] = [\n 'id' => $stage->getUuid(),\n 'name' => $stage->getName(),\n ];\n }\n }\n\n return $data;\n }\n\n private function transformRecipients(array $recipients): array\n {\n $users = [];\n foreach ($recipients['users'] ?? [] as $userId) {\n $users[] = $this->transformUser($userId);\n }\n\n return $users;\n }\n\n private function transformCreator(?User $user): ?array\n {\n if ($user === null) {\n return null;\n }\n\n return $this->transformUser($user->getId());\n }\n\n private function transformAskJiminnyPrompt(?AskAnythingPrompt $prompt): ?array\n {\n if ($prompt === null) {\n return null;\n }\n\n return [\n 'id' => $prompt->getUuid(),\n 'name' => $prompt->getTitle(),\n ];\n }\n\n private function transformSafeSearch(?Search $search): ?array\n {\n if ($search === null) {\n return null;\n }\n\n return [\n 'id' => $search->getUuid(),\n 'name' => $search->getName(),\n ];\n }\n\n private function transformUser(int $userId): array\n {\n /* @var ?User $user */\n $user = $this->userRepository->find($userId);\n\n return [\n 'id' => $user?->getUuid(),\n 'name' => $user?->getName(),\n 'email' => $user?->getEmailAddress(),\n 'photoUrl' => $user?->getPhotoUrl(),\n ];\n }\n\n public function create(array $data): array\n {\n $validatedData = $this->validateAndTransformData($data);\n $validatedData['created_by'] = auth()->id();\n\n $automatedReport = $this->automatedReportsRepository->create($validatedData);\n\n $this->generateOneOffReport($automatedReport);\n\n return $this->transformReportFullView($automatedReport);\n }\n\n public function update(string $uuid, array $data): array\n {\n $validatedData = $this->validateAndTransformData($data);\n $report = $this->automatedReportsRepository->findByUuid($uuid);\n\n if (! $report) {\n throw new InvalidArgumentException('Report not found');\n }\n\n $oldCustomName = $report->getCustomName();\n\n $automatedReport = $this->automatedReportsRepository->update($report, $validatedData);\n\n if ($oldCustomName !== $automatedReport->getCustomName()) {\n $this->updateResultNames($automatedReport);\n }\n\n $this->generateOneOffReport($automatedReport);\n\n return $this->transformReportFullView($automatedReport);\n }\n\n /**\n * Create an Ask Jiminny report.\n */\n public function createAskJiminnyReport(array $data, User $creator): array\n {\n $validatedData = $this->validateAskJiminnyReportData($data, $creator);\n $validatedData['created_by'] = $creator->getId();\n\n $automatedReport = $this->automatedReportsRepository->create($validatedData);\n\n return $this->transformReportFullView($automatedReport);\n }\n\n /**\n * Update an Ask Jiminny report.\n */\n public function updateAskJiminnyReport(AutomatedReport $report, array $data, User $user): array\n {\n if (! $report->isAskJiminnyReport()) {\n throw new InvalidArgumentException('Report is not an Ask Jiminny report');\n }\n\n $validatedData = $this->validateAskJiminnyReportData($data, $user);\n\n $oldCustomName = $report->getCustomName();\n\n $automatedReport = $this->automatedReportsRepository->update($report, $validatedData);\n\n if ($oldCustomName !== $automatedReport->getCustomName()) {\n $this->updateResultNames($automatedReport);\n }\n\n return $this->transformReportFullView($automatedReport);\n }\n\n public function updateAskJiminnyReportStatus(AutomatedReport $report, bool $status): array\n {\n $this->automatedReportsRepository->update($report, ['status' => $status]);\n\n return $this->transformReportFullView($report->fresh());\n }\n\n /**\n * Validate and transform data for Ask Jiminny reports.\n */\n private function validateAskJiminnyReportData(array $data, User $user): array\n {\n // Validate name\n $name = trim($data['report_name'] ?? '');\n if (empty($name)) {\n throw new InvalidArgumentException('Report name is required');\n }\n if (mb_strlen($name) > 50) {\n throw new InvalidArgumentException('Report name must be 50 characters or less');\n }\n\n // Validate frequency (only daily, weekly, monthly for Ask Jiminny)\n $frequency = $data['frequency'] ?? null;\n $askJiminnyFrequencies = [self::FREQUENCY_DAILY, self::FREQUENCY_WEEKLY, self::FREQUENCY_MONTHLY];\n if (! in_array($frequency, $askJiminnyFrequencies, true)) {\n throw new InvalidArgumentException('Frequency must be daily, weekly, or monthly');\n }\n\n // Validate expiration date\n $expiresAt = $data['expires_on'] ?? null;\n if (empty($expiresAt)) {\n throw new InvalidArgumentException('Expiration date is required');\n }\n\n try {\n $expiresAtDate = Carbon::parse($expiresAt);\n } catch (InvalidFormatException $e) {\n throw new InvalidArgumentException('Expiration date format is invalid');\n }\n $maxExpiration = Carbon::now()->addYear();\n if ($expiresAtDate->gt($maxExpiration)) {\n throw new InvalidArgumentException('Expiration date cannot be more than 1 year from now');\n }\n if ($expiresAtDate->isPast()) {\n throw new InvalidArgumentException('Expiration date cannot be in the past');\n }\n\n // Validate saved search\n $activitySearchId = $data['saved_search'] ?? null;\n if (empty($activitySearchId)) {\n throw new InvalidArgumentException('Saved search is required');\n }\n $savedSearch = $this->activitySearchRepository->findByUuidAndUser($activitySearchId, $user);\n if (! $savedSearch) {\n throw new InvalidArgumentException('Saved search not found or does not belong to you');\n }\n\n // Validate saved prompt\n $askAnythingPromptId = $data['ask_jiminny_prompt'] ?? null;\n if (empty($askAnythingPromptId)) {\n throw new InvalidArgumentException('Ask Jiminny prompt is required');\n }\n $prompt = $this->askAnythingRepository->getPromptByUuid($askAnythingPromptId);\n if (! $prompt) {\n throw new InvalidArgumentException('Ask Jiminny prompt not found');\n }\n\n // Validate status\n $status = $data['enabled'] ?? false;\n\n $recipientUserIds = [$user->getId()];\n\n if (! empty($data['share_users'])) {\n $sharedUserIds = $this->validateAndGetUserIdsByTeam(\n $user->team,\n (array) $data['share_users']\n );\n $recipientUserIds = array_merge($recipientUserIds, $sharedUserIds);\n }\n\n $sharedGroupIds = [];\n if (! empty($data['share_teams'])) {\n $sharedGroupIds = $this->validateAndGetGroupIds($user->team, (array) $data['share_teams']);\n }\n\n $recipientUserIds = array_values(array_unique($recipientUserIds));\n\n return [\n 'team_id' => $user->getTeamId(),\n 'type' => self::TYPE_ASK_JIMINNY,\n 'status' => (bool) $status,\n 'frequency' => $frequency,\n 'custom_name' => $name,\n 'activity_search_id' => $savedSearch->getId(),\n 'ask_anything_prompt_id' => $prompt->getId(),\n 'expires_at' => $expiresAtDate->toDateString(),\n 'media_types' => [self::MEDIA_TYPE_PDF],\n 'call_types' => [],\n 'recipients' => ['users' => $recipientUserIds],\n 'groups' => $sharedGroupIds,\n ];\n }\n\n public static function getAskJiminnyFrequencies(): array\n {\n return array_map(static function ($frequency) {\n return $frequency['id'];\n }, self::ASK_JIMINNY_FREQUENCIES);\n }\n\n public function getAskJiminnyReportFilters(User $user): array\n {\n $savedSearches = $this->activitySearchRepository->findByUserOrderedByName($user)\n ->map(fn (Search $search) => [\n 'id' => $search->getUuid(),\n 'name' => $search->getName(),\n ])\n ->values()->all();\n\n $prompts = collect(\n $this->askAnythingPromptService->get($user, AskAnythingPromptTarget::on_demand)\n )->map(fn (AskAnythingPromptDto $prompt) => [\n 'id' => $prompt->id,\n 'name' => $prompt->title,\n ])->values()->all();\n\n return [\n [\n 'id' => 'prompt',\n 'label' => 'Prompt',\n 'options' => $prompts,\n ],\n [\n 'id' => 'saved_search',\n 'label' => 'Saved Search',\n 'options' => $savedSearches,\n ],\n ];\n }\n\n public function getAskJiminnyReportFormData(User $user, ?AutomatedReport $report = null): array\n {\n $team = $user->getTeam();\n $userTimezone = $user->getTimezone();\n\n $savedSearches = $this->activitySearchRepository->findByUserOrderedByName($user)\n ->map(fn (Search $search) => [\n 'id' => $search->getUuid(),\n 'name' => $search->getName(),\n ])\n ->values()->all();\n\n $prompts = collect(\n $this->askAnythingPromptService->get($user, AskAnythingPromptTarget::on_demand)\n )->map(fn (AskAnythingPromptDto $prompt) => [\n 'id' => $prompt->id,\n 'name' => $prompt->title,\n ])->values()->all();\n\n $teamGroups = $this->groupRepository->getAllByTeam($team)->map(fn ($group) => [\n 'id' => $group->getUuid(),\n 'name' => $group->getName(),\n ])->values()->all();\n\n $shareUsers = $this->recipientsService->getRecipientsFieldData(team: $team)['options'] ?? [];\n\n $sharedTeamsValue = [];\n $sharedUsersValue = [];\n if ($report) {\n $sharedTeamsValue = $this->transformGroups($team, $report->getGroups());\n\n $recipientUserIds = $report->getRecipients()['users'] ?? [];\n $creatorId = $report->getAttribute('created_by');\n $sharedUserIds = array_values(array_filter(\n $recipientUserIds,\n static fn ($id) => $id !== $creatorId\n ));\n $sharedUsersValue = collect($sharedUserIds)\n ->map(fn ($id) => $this->userRepository->find((int) $id))\n ->filter()\n ->map(fn (User $u) => [\n 'id' => $u->getUuid(),\n 'name' => $u->getName(),\n ])\n ->values()\n ->all();\n }\n\n return [\n 'fields' => [\n [\n 'id' => 'enabled',\n 'inputType' => InputTypeEnum::TOGGLE,\n 'label' => '',\n 'value' => $report?->getStatus() ?? false,\n ],\n [\n 'id' => 'report_name',\n 'inputType' => InputTypeEnum::TEXT,\n 'label' => 'Name',\n 'placeholder' => 'Enter name',\n 'required' => true,\n 'validation' => ['maxLength' => 50],\n 'value' => $report?->getCustomName() ?? '',\n ],\n [\n 'id' => 'frequency',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'label' => 'Frequency',\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => self::ASK_JIMINNY_FREQUENCIES,\n 'value' => $report ? $this->transformFrequency($report->getFrequency()) : null,\n ],\n [\n 'id' => 'expires_on',\n 'inputType' => InputTypeEnum::DATE,\n 'label' => 'Expires on',\n 'required' => true,\n 'placeholder' => 'Select',\n 'validation' => [\n 'minDate' => now($userTimezone)->toDateString(),\n 'maxDate' => now($userTimezone)->addYear()->toDateString(),\n ],\n 'value' => $report?->getExpiresAt()?->toDateString(),\n ],\n [\n 'id' => 'share_teams',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'label' => 'Team',\n 'required' => false,\n 'placeholder' => 'Select',\n 'options' => $teamGroups,\n 'value' => $sharedTeamsValue,\n ],\n [\n 'id' => 'share_users',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'label' => 'Team member',\n 'required' => false,\n 'placeholder' => 'Select',\n 'groupLabelKey' => 'label',\n 'groupValuesKey' => 'users',\n 'optionLabelKey' => 'name',\n 'optionValueKey' => 'id',\n 'options' => $shareUsers,\n 'value' => $sharedUsersValue,\n ],\n [\n 'id' => 'saved_search',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'label' => 'Saved search',\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => $savedSearches,\n 'value' => $report && $report->getSavedSearch() ? [\n 'id' => $report->getSavedSearch()->getUuid(),\n 'name' => $report->getSavedSearch()->getName(),\n ] : null,\n ],\n [\n 'id' => 'ask_jiminny_prompt',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'label' => 'Ask Jiminny prompt',\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => $prompts,\n 'value' => $report && $report->getAskAnythingPrompt() ? [\n 'id' => $report->getAskAnythingPrompt()->getUuid(),\n 'name' => $report->getAskAnythingPrompt()->getTitle(),\n ] : null,\n ],\n ],\n ];\n }\n\n private function updateResultNames(AutomatedReport $automatedReport): void\n {\n $results = $this->automatedReportsRepository->getResultsByReport($automatedReport);\n\n foreach ($results as $result) {\n $result->update(['name' => $this->getReportFileName($result)]);\n }\n }\n\n public function updateStatus(string $uuid, array $data): array\n {\n $automatedReport = $this->automatedReportsRepository->findByUuid($uuid);\n\n if (! $automatedReport) {\n throw new ModelNotFoundException('Report not found');\n }\n\n $status = $this->validateReportStatus($data['report_enabled'] ?? null);\n $automatedReport->update([\n 'status' => $status,\n ]);\n\n $this->generateOneOffReport($automatedReport);\n\n return $this->transformReportFullView($automatedReport);\n }\n\n private function generateOneOffReport(AutomatedReport $automatedReport): void\n {\n // the scheduler handles all the other frequency types\n if ($automatedReport->getStatus() === false || $automatedReport->getFrequency() !== self::FREQUENCY_ONE_OFF) {\n return;\n }\n\n $this->dispatcher->dispatch(new RequestGenerateReportJob($automatedReport->getUuid()));\n }\n\n public function getReport(string $uuid): AutomatedReport\n {\n $automatedReport = $this->automatedReportsRepository->findByUuid($uuid);\n\n if (! $automatedReport) {\n throw new ModelNotFoundException('Report not found');\n }\n\n return $automatedReport;\n }\n\n public function get(string $uuid): array\n {\n $automatedReport = $this->getReport($uuid);\n\n return $this->transformReportFullView($automatedReport);\n }\n\n public function list(string $sortColumn = 'created_at', string $sortDirection = 'desc'): array\n {\n $results = [];\n $collection = $this->automatedReportsRepository->getAllStandardReports($sortColumn, $sortDirection);\n\n /** @var AutomatedReport $report */\n foreach ($collection as $report) {\n $results[] = $this->transformReportFullView($report);\n }\n\n return ['data' => $results];\n }\n\n public function listAskJiminnyReports(\n User $user,\n string $sortColumn = 'created_at',\n string $sortDirection = 'desc'\n ): array {\n $results = [];\n $collection = $this->automatedReportsRepository->getAskJiminnyReportsByUser($user, $sortColumn, $sortDirection);\n\n /** @var AutomatedReport $report */\n foreach ($collection as $report) {\n $results[] = $this->transformReportFullView($report);\n }\n\n return ['data' => $results];\n }\n\n public function delete(string $uuid): void\n {\n $automatedReport = $this->automatedReportsRepository->findByUuid($uuid);\n\n if (! $automatedReport) {\n throw new ModelNotFoundException('Report not found');\n }\n\n $automatedReport->delete();\n }\n\n public function createReportResult(AutomatedReport $automatedReport, array $data = []): AutomatedReportResult\n {\n return $this->automatedReportsRepository->createResult(\n array_merge(\n [\n 'report_id' => $automatedReport->getId(),\n 'status' => AutomatedReportResult::STATUS_DEFAULT,\n ],\n $data\n )\n );\n }\n\n public function getReportResult(string $resultUuid): AutomatedReportResult\n {\n $report = $this->automatedReportsRepository->findResultByUuid($resultUuid);\n\n if (! $report) {\n throw new ModelNotFoundException('Report Result not found');\n }\n\n return $report;\n }\n\n public function findChildResult(AutomatedReportResult $result, string $type): ?AutomatedReportResult\n {\n return $this->automatedReportsRepository->findChildResult($result, $type);\n }\n\n // prophet API calls\n /**\n * @throws ApplicationException\n */\n public function getGenerateReportPayload(AutomatedReport $automatedReport, string $reportResultUuid): array\n {\n $period = $this->calculateFromAndToDate($automatedReport);\n $fromDate = $period['fromDate'];\n $toDate = $period['toDate'];\n\n return [\n 'team_id' => $automatedReport->getTeamId(),\n 'request_id' => $reportResultUuid,\n 'report_type' => $automatedReport->getType(),\n 'media_types' => $automatedReport->getMediaTypes(),\n 'from_date' => $fromDate->startOfDay()->format(DateTimeInterface::RFC3339),\n 'to_date' => $toDate->endOfDay()->format(DateTimeInterface::RFC3339),\n 'group_ids' => $automatedReport->getGroups(),\n 'call_deal_stage' => $automatedReport->getDealAtCallStages(),\n 'current_deal_stage' => $automatedReport->getCurrentDealStages(),\n 'deal_min_value' => $automatedReport->getDealValueMin(),\n 'deal_max_value' => $automatedReport->getDealValueMax(),\n 'call_types' => $automatedReport->getCallTypes(),\n 'call_duration_min_seconds' => $automatedReport->getCallDurationMin(),\n 'call_duration_max_seconds' => $automatedReport->getCallDurationMax(),\n 'special_requirements' => $automatedReport->getAdditionalPromptInput(),\n 'callback_url' => $this->getCallbackUrl(),\n 'report_period' => $this->formatReportPeriodName(\n $automatedReport->getFrequency(),\n $fromDate,\n $toDate,\n ),\n 'playbook_categories' => $automatedReport->getPlaybookCategories(),\n 'custom_name' => $automatedReport->getCustomName(),\n ];\n }\n\n // $inputPayload - FE payload structure\n public function getActivitiesCountPayload(array $inputPayload): array\n {\n // Use validateAndTransformData to validate and normalize input\n $validatedData = $this->validateAndTransformData($inputPayload);\n $period = $this->calculateFromAndToDatePeriod(\n $validatedData['frequency'],\n Carbon::parse($validatedData['from']),\n Carbon::parse($validatedData['to']),\n );\n $fromDate = $period['fromDate'];\n $toDate = $period['toDate'];\n\n // Create payload similar to getGenerateReportPayload\n return [\n 'team_id' => $validatedData['team_id'],\n 'group_ids' => $validatedData['groups'] ?? [],\n 'report_type' => $validatedData['type'],\n 'from_date' => $fromDate->format(DateTimeInterface::RFC3339),\n 'to_date' => $toDate->format(DateTimeInterface::RFC3339),\n 'call_deal_stage' => $validatedData['deal_at_call_stages'] ?? [],\n 'current_deal_stage' => $validatedData['current_deal_stages'] ?? [],\n 'deal_min_value' => $validatedData['deal_value_min'] ?? null,\n 'deal_max_value' => $validatedData['deal_value_max'] ?? null,\n 'call_types' => $validatedData['call_types'],\n 'call_duration_min_seconds' => $validatedData['call_duration_min'] ?? null,\n 'call_duration_max_seconds' => $validatedData['call_duration_max'] ?? null,\n 'special_requirements' => $validatedData['additional_prompt_input'] ?? null,\n 'playbook_categories' => $validatedData['playbook_categories'] ?? [],\n 'request_id' => null,\n 'callback_url' => null,\n ];\n }\n\n public function shouldSendReport(array $users, ?CarbonInterface $generatedAt = null): bool\n {\n if (empty($users)) {\n return false;\n }\n\n $earliestTz = collect($users)\n ->mapWithKeys(function (array $user) {\n $tz = new DateTimeZone($user['timezone']);\n $nowUtc = new DateTime('now', new DateTimeZone('UTC'));\n $offset = $tz->getOffset($nowUtc);\n\n return [$user['timezone'] => $offset];\n })\n ->sortDesc()\n ->keys()\n ->first();\n\n $now = Carbon::now($earliestTz);\n $isScheduledTime = (int) $now->format('H') === self::SENT_REPORT_AT_HOURS;\n\n if ($isScheduledTime) {\n return true;\n }\n\n return $this->hasPassedScheduledTime($generatedAt, $earliestTz);\n }\n\n public function hasPassedScheduledTime(?CarbonInterface $generatedAt, string $timezone): bool\n {\n if ($generatedAt === null) {\n return false;\n }\n\n $now = Carbon::now($timezone);\n $scheduledTime = $now->copy()->setTime(self::SENT_REPORT_AT_HOURS, 0, 0);\n\n if ($now->hour < self::SENT_REPORT_AT_HOURS) {\n $scheduledTime = $scheduledTime->subDay();\n }\n\n $scheduledTimeUtc = $scheduledTime->copy()->utc();\n $generatedAtUtc = $generatedAt->copy()->utc();\n $nowUtc = $now->copy()->utc();\n\n return $generatedAtUtc->lt($scheduledTimeUtc) && $nowUtc->gt($scheduledTimeUtc);\n }\n\n public function calculateFromAndToDatePeriod(\n string $frequency,\n ?Carbon $fromDate = null,\n ?Carbon $toDate = null\n ): array {\n if ($frequency === self::FREQUENCY_ONE_OFF) {\n return [\n 'fromDate' => $fromDate,\n 'toDate' => $toDate,\n ];\n }\n\n $now = Carbon::now();\n\n return match ($frequency) {\n self::FREQUENCY_DAILY => [\n 'fromDate' => $now->copy()->subDay()->startOfDay(),\n 'toDate' => $now->copy()->subDay()->endOfDay(),\n ],\n self::FREQUENCY_WEEKLY => [\n 'fromDate' => $now->copy()->subWeeks(1)->startOfDay(),\n 'toDate' => $now->copy()->subDay()->endOfDay(),\n ],\n self::FREQUENCY_MONTHLY => [\n 'fromDate' => $now->copy()->subMonths(1)->startOfDay(),\n 'toDate' => $now->copy()->subDay()->endOfDay(),\n ],\n self::FREQUENCY_QUARTERLY => [\n 'fromDate' => $now->copy()->subMonths(3)->startOfDay(),\n 'toDate' => $now->copy()->subDay()->endOfDay(),\n ],\n default => throw new InvalidArgumentException(\"Unsupported frequency: {$frequency}\"),\n };\n }\n\n private function calculateFromAndToDate(AutomatedReport $automatedReport): array\n {\n return $this->calculateFromAndToDatePeriod(\n $automatedReport->getFrequency(),\n $automatedReport->getFrom(),\n $automatedReport->getTo()\n );\n }\n\n public function getAskJiminnyGenerateReportPayload(\n AutomatedReport $automatedReport,\n AutomatedReportResult $reportResult,\n array $activityIds,\n ): array {\n return [\n 'user_question' => $automatedReport->getAskAnythingPrompt()?->getContent(),\n 'call_ids' => array_map('strval', $activityIds),\n 'team_id' => $automatedReport->getTeamId(),\n 'request_id' => $reportResult->getUuid(),\n 'callback_url' => $this->getCallbackUrl(),\n 'report_period' => $this->getReportPeriodName($reportResult),\n 'report_name' => $automatedReport->getCustomName(),\n ];\n }\n\n private function getCallbackUrl(): string\n {\n return $this->webhookService->route('jiminny.webhook.reports.ready');\n }\n\n /**\n * Validate and transform payload data for automated reports\n *\n * @param array $data\n *\n * @throws InvalidArgumentException\n *\n * @return array\n */\n private function validateAndTransformData(array $data): array\n {\n // Validate organization (team) and check feature\n $team = $this->validateOrganization($data['organization'] ?? null);\n\n $status = $this->validateReportStatus($data['report_enabled'] ?? null);\n $type = $this->validateReportType($data['report_type'] ?? null);\n $frequency = $this->validateFrequency($data['frequency'] ?? null);\n $additionalPromptInput = $this->validateAdditionalPromptInput(\n $data['additional_prompt_input'] ?? null\n );\n $customReportName = $this->validateCustomReportName($data['custom_name'] ?? null);\n\n // Prepare data for the database\n $reportData = [\n 'team_id' => $team->getId(),\n 'type' => $type,\n 'status' => $status,\n 'frequency' => $frequency,\n 'additional_prompt_input' => $additionalPromptInput,\n 'custom_name' => $customReportName,\n ];\n\n // Validate deal values\n $reportData = $this->validateDealValues($data, $reportData);\n\n // Validate date range\n $reportData = $this->validateDateRange($data, $reportData, $frequency);\n\n // Validate call durations\n $reportData = $this->validateCallDurations($data, $reportData);\n\n // Validate call types\n $reportData = $this->validateCallTypes($data, $reportData);\n\n // Validate media types\n $reportData = $this->validateMediaTypes($data, $reportData);\n\n // Validate groups\n if (isset($data['teams'])) {\n $reportData['groups'] = $this->validateAndGetGroupIds($team, $data['teams']);\n }\n\n // Validate deal stages\n $reportData = $this->validateDealStages($data, $reportData, $team, $type);\n\n // Validate playbook categories\n $reportData = $this->validatePlaybookCategories($data, $reportData, $team);\n\n // Validate recipients\n $reportData['recipients'] = [\n 'users' => $this->validateAndGetUserIdsByTeam($team, $data['recipients'] ?? []),\n ];\n\n if (isset($data['jiminny_recipients'])) {\n // Validate Jiminny recipients\n $reportData['jiminny_recipients'] = [\n 'users' => $this->validateAndGetJiminnyUserIds((array) $data['jiminny_recipients']),\n ];\n }\n\n return $reportData;\n }\n\n private function validateDealValues(array $data, array $reportData): array\n {\n if (isset($data['min_deal_value'])) {\n $reportData['deal_value_min'] = (int) $data['min_deal_value'];\n\n if ($reportData['deal_value_min'] > 4294967295 || $reportData['deal_value_min'] < 0) {\n throw new InvalidArgumentException('Min deal value should be between 0 and 4294967295');\n }\n }\n\n if (isset($data['max_deal_value'])) {\n $reportData['deal_value_max'] = (int) $data['max_deal_value'];\n\n if ($reportData['deal_value_max'] > 4294967295 || $reportData['deal_value_max'] < 0) {\n throw new InvalidArgumentException('Max deal value should be between 0 and 4294967295');\n }\n }\n\n if (isset($data['min_deal_value'], $data['max_deal_value'])\n && $data['min_deal_value'] > $data['max_deal_value']\n ) {\n throw new InvalidArgumentException('Min deal value cannot be greater than max deal value');\n }\n\n return $reportData;\n }\n\n private function validateDateRange(array $data, array $reportData, string $frequency): array\n {\n // Set date range only for one_off frequency\n if ($frequency === 'one_off') {\n if (isset($data['start_date_period'])) {\n $reportData['from'] = $this->parseDate($data['start_date_period']);\n }\n\n if (isset($data['end_date_period'])) {\n $reportData['to'] = $this->parseDate($data['end_date_period']);\n }\n\n if (empty($reportData['from']) || empty($reportData['to'])) {\n throw new InvalidArgumentException(\n 'Start date and end date are required for one_off frequency'\n );\n }\n } else {\n $reportData['from'] = null;\n $reportData['to'] = null;\n }\n\n return $reportData;\n }\n\n private function validateCallDurations(array $data, array $reportData): array\n {\n // Convert call durations from minutes to seconds\n if (isset($data['min_call_duration'])) {\n $reportData['call_duration_min'] = (int) $data['min_call_duration'] * 60;\n\n if ($reportData['call_duration_min'] > 4294967295 || $reportData['call_duration_min'] < 0) {\n throw new InvalidArgumentException('Min call duration should be between 0 and 4294967295');\n }\n }\n\n if (isset($data['max_call_duration'])) {\n $reportData['call_duration_max'] = (int) $data['max_call_duration'] * 60;\n\n if ($reportData['call_duration_max'] > 4294967295 || $reportData['call_duration_max'] < 0) {\n throw new InvalidArgumentException('Max call duration should be between 0 and 4294967295');\n }\n }\n\n return $reportData;\n }\n\n private function validateCallTypes(array $data, array $reportData): array\n {\n // Set call types\n $reportData['call_types'] = $data['call_type'] ?? [];\n if (empty($reportData['call_types'])) {\n $reportData['call_types'] = self::getCallTypes();\n }\n\n foreach ($reportData['call_types'] as $callType) {\n if (! in_array($callType, self::getCallTypes(), true)) {\n throw new InvalidArgumentException(sprintf('Call type %s is invalid', $callType));\n }\n }\n\n return $reportData;\n }\n\n private function validateMediaTypes(array $data, array $reportData): array\n {\n // Set media types from input data\n $reportData['media_types'] = $data['media_types'] ?? [];\n\n if (empty($reportData['media_types'])) {\n throw new InvalidArgumentException('Media types are required');\n }\n\n foreach ($reportData['media_types'] as $mediaType) {\n if (! in_array($mediaType, self::MEDIA_TYPES, true)) {\n throw new InvalidArgumentException(sprintf('Media type %s is invalid', $mediaType));\n }\n }\n\n return $reportData;\n }\n\n private function validateDealStages(array $data, array $reportData, Team $team, string $reportType): array\n {\n // Validate and set deal stages\n if (isset($data['deal_stage_at_call'])) {\n $reportData['deal_at_call_stages'] =\n $this->validateAndGetDealStageIds($team, $data['deal_stage_at_call'], 'Deal stage at call');\n }\n\n if (isset($data['current_deal_stage'])) {\n $reportData['current_deal_stages'] =\n $this->validateAndGetDealStageIds($team, $data['current_deal_stage'], 'Current deal stage');\n }\n\n // Ensure current_deal_stage is not provided for loss_analysis report type\n if ($reportType === self::TYPE_LOSS_ANALYSIS && ! empty($data['current_deal_stage'])) {\n throw new InvalidArgumentException('Current deal stage is not applicable for Loss Analysis reports');\n }\n\n return $reportData;\n }\n\n // transform uuid to id\n private function validatePlaybookCategories(array $data, array $reportData, Team $team): array\n {\n $key = 'playbook_categories';\n\n if (isset($data[$key])) {\n $payloadIds = $data[$key];\n $ids = [];\n\n foreach ($payloadIds as $uuid) {\n $uuid = (string) $uuid;\n\n try {\n $playbookCategory = $this->playbookCategoryRepository->findByUuid($uuid);\n } catch (Throwable $throwable) {\n Log::error(__METHOD__ . ' ' . $throwable->getMessage());\n\n throw new InvalidArgumentException(sprintf('Playbook category %s not found', $uuid));\n }\n\n if (! $playbookCategory) {\n throw new InvalidArgumentException(sprintf('Playbook category %s not found', $uuid));\n }\n\n if (! $playbookCategory->hasPlaybook()) {\n throw new InvalidArgumentException(sprintf('Playbook category %s has no playbook', $uuid));\n }\n\n if ($playbookCategory->getPlaybook()->getTeamId() !== $team->getId()) {\n throw new InvalidArgumentException(\n sprintf('Playbook category %s not found for team %s', $uuid, $team->getUuid())\n );\n }\n\n $ids[] = $playbookCategory->getId();\n }\n\n $reportData[$key] = $ids;\n }\n\n return $reportData;\n }\n\n private function validateReportStatus($status): bool\n {\n if (! in_array($status, [true, false], true)) {\n throw new InvalidArgumentException('Report status is invalid');\n }\n\n return $status;\n }\n\n private function validateReportType($type): string\n {\n if (! in_array($type, self::getTypes(), true)) {\n throw new InvalidArgumentException(sprintf('Report type is invalid: %s', $type));\n }\n\n return $type;\n }\n\n private function validateFrequency($frequency): string\n {\n if (! in_array($frequency, self::getFrequencies(), true)) {\n throw new InvalidArgumentException('Frequency is invalid');\n }\n\n return $frequency;\n }\n\n private function validateAdditionalPromptInput(?string $additionalPromptInput): ?string\n {\n if ($additionalPromptInput && strlen($additionalPromptInput) > 5000) {\n throw new InvalidArgumentException('Additional Prompt Input should be less than 5000 characters');\n }\n\n return $additionalPromptInput;\n }\n\n private function validateCustomReportName(?string $customReportName): ?string\n {\n if ($customReportName === null || $customReportName === '') {\n return null;\n }\n\n if (strlen($customReportName) > 70) {\n throw new InvalidArgumentException('Custom report name should be less than 70 characters');\n }\n\n return $customReportName;\n }\n\n private function validateOrganization(?string $organizationUuid): Team\n {\n if (! $organizationUuid) {\n throw new InvalidArgumentException('Organization is required');\n }\n\n $team = $this->teamRepository->idOrUuid($organizationUuid);\n\n if (! $team) {\n throw new InvalidArgumentException('Organization not found');\n }\n\n if (! $team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {\n throw new InvalidArgumentException('Organization does not have the Automated Reports feature');\n }\n\n return $team;\n }\n\n private function validateAndGetGroupIds(Team $team, array $teamUuids): array\n {\n $groupIds = [];\n\n foreach ($teamUuids as $uuid) {\n $group = $this->groupRepository->findByUuid($uuid);\n\n if ($group === null || $group->getTeamId() !== $team->getId()) {\n throw new InvalidArgumentException(\n sprintf('Group %s not found for team %s', $uuid, $team->getUuid())\n );\n }\n\n $groupIds[] = $group->getId();\n\n }\n\n return $groupIds;\n }\n\n private function validateAndGetDealStageIds(Team $team, array $stageUuids, string $propertyLabel): array\n {\n $stageIds = [];\n\n foreach ($stageUuids as $uuid) {\n $stage = $this->stageRepository->findByUuid($uuid);\n\n if ($stage === null || $stage->getTeamId() !== $team->getId()) {\n throw new InvalidArgumentException(\n sprintf('Stage %s not found for team %s for %s', $uuid, $team->getUuid(), $propertyLabel)\n );\n }\n\n $stageIds[] = $stage->getId();\n }\n\n return $stageIds;\n }\n\n private function validateAndGetUserIds(array $userUuids, callable $teamCheck): array\n {\n if (empty($userUuids)) {\n return [];\n }\n\n $userIds = [];\n\n foreach ($userUuids as $uuid) {\n $user = $this->userRepository->findByUuid($uuid);\n\n if (! $user || ! $user->isStatusActive()) {\n throw new InvalidArgumentException(\n sprintf('User %s not found or is not active', $uuid)\n );\n }\n\n if (! $teamCheck($user)) {\n throw new InvalidArgumentException(\n sprintf('User %s does not belong to the allowed team(s)', $uuid)\n );\n }\n\n $userIds[] = $user->getId();\n }\n\n return $userIds;\n }\n\n private function validateAndGetUserIdsByTeam(Team $team, array $userUuids): array\n {\n return $this->validateAndGetUserIds($userUuids, fn ($user) => $user->getTeamId() === $team->getId());\n }\n\n private function validateAndGetJiminnyUserIds(array $userUuids): array\n {\n $allowedTeamIds = config('kiosk.teamIds', []);\n\n return $this->validateAndGetUserIds($userUuids, fn ($user) => in_array($user->getTeamId(), $allowedTeamIds, true));\n }\n\n private function parseDate(string $dateString): string\n {\n return date('Y-m-d H:i:s', strtotime($dateString));\n }\n\n private function generateReportResultViewUrl(AutomatedReportResult $result): string\n {\n $mediaResource = $this->getReportMediaRouteResource($result);\n\n return route('ai-reports.' . $mediaResource . '.view', ['uuid' => $result->getUuid()]);\n }\n\n private function generateReportResultDownloadUrl(AutomatedReportResult $result): string\n {\n $mediaResource = $this->getReportMediaRouteResource($result);\n\n return route('ai-reports.' . $mediaResource . '.download', ['uuid' => $result->getUuid()]);\n }\n\n private function getReportMediaRouteResource(AutomatedReportResult $result): string\n {\n if ($result->getMediaType() === self::MEDIA_TYPE_PDF) {\n return self::PDF_KEY;\n } elseif ($result->getMediaType() === self::MEDIA_TYPE_PODCAST) {\n return self::AUDIO_KEY;\n }\n\n throw new \\InvalidArgumentException('Unknown media type.');\n }\n\n public function getMediaPath(AutomatedReportResult $result): ?string\n {\n $url = match ($result->getMediaType()) {\n self::MEDIA_TYPE_PDF => $result->getPdfUrl(),\n self::MEDIA_TYPE_PODCAST => $result->getPodcastAudioUrl(),\n default => null,\n };\n\n if ($url === null) {\n return null;\n }\n\n $path = parse_url(trim($url, '\"\\''), PHP_URL_PATH);\n\n return $path ?: null;\n }\n\n public function getFilenameSuffix(AutomatedReportResult $result): ?string\n {\n return match ($result->getMediaType()) {\n self::MEDIA_TYPE_PODCAST => 'Podcast',\n default => null,\n };\n }\n\n public function getMailSubjectSuffix(AutomatedReportResult $result): string\n {\n return match ($result->getMediaType()) {\n self::MEDIA_TYPE_PDF => 'report',\n self::MEDIA_TYPE_PODCAST => 'podcast',\n default => '',\n };\n }\n\n public function getMediaTypeMetadata(AutomatedReportResult $result): array\n {\n return match ($result->getMediaType()) {\n self::MEDIA_TYPE_PODCAST => ['extension' => 'mp3', 'mime' => 'audio/mpeg'],\n self::MEDIA_TYPE_PDF => ['extension' => 'pdf', 'mime' => 'application/pdf'],\n default => ['extension' => null, 'mime' => null],\n };\n }\n\n public function deleteS3Files(AutomatedReportResult $result): void\n {\n $teamUuid = $result->getReport()->getTeam()->getUuid();\n $reportUuid = $result->getUuid();\n\n // delete all files for a report uuid no mather of pdf, podcast, or both\n // in case of both - the podcast files are linked to the pdf (parent) uuid\n // pdf and podcast date times should be close\n $path = sprintf('%s/%s/%s', $teamUuid, self::S3_DIR, $reportUuid);\n\n foreach (self::FILE_EXTENSIONS_VARIANTS as $extension) {\n $file = $path . '.' . $extension;\n\n if (Storage::exists($file)) {\n Storage::delete($file);\n Log::info('[Reports] Deleted S3 file', [\n 'path' => $file,\n ]);\n }\n }\n\n foreach (self::FILE_PODCAST_EXTENSIONS_VARIANTS as $extension) {\n $file = $path . '_podcast.' . $extension;\n\n if (Storage::exists($file)) {\n Storage::delete($file);\n Log::info('[Reports] Deleted Podcast S3 file', [\n 'path' => $file,\n ]);\n }\n }\n }\n\n /**\n *\n * @param int|null $teamId Optional team ID to filter results\n *\n * @return Collection<int, int> Collection of team IDs\n */\n public function getTeamIdsWithReportsResults(?int $teamId = null): Collection\n {\n return $this->automatedReportsRepository->getTeamIdsWithReportsResults($teamId);\n }\n\n /**\n * Core delete logic for report results using a query\n *\n * @param Builder $query\n * @param array $logContext\n *\n * @return int\n */\n private function deleteReportResultsByQuery(Builder $query, array $logContext = []): int\n {\n $deletedCount = 0;\n\n if ($query->exists()) {\n Log::info(\n 'Run delete report results',\n array_merge(\n $logContext,\n [\n 'service' => 'AutomatedReportsService',\n ]\n )\n );\n\n $query->chunkById(50, function ($results) use (&$deletedCount, $logContext) {\n foreach ($results as $result) {\n $this->deleteReportResult($result);\n $deletedCount++;\n\n Log::info(\n 'Deleted a report result',\n array_merge(\n $logContext,\n [\n 'result_id' => $result->getId(),\n 'report_id' => $result->getReportId(),\n ]\n )\n );\n }\n });\n }\n\n return $deletedCount;\n }\n\n /**\n * Delete report results for a team by retention period\n *\n * @param Team $team\n * @param CarbonImmutable $retentionDate\n *\n * @return int Number of deleted report results\n */\n public function deleteReportsResultsInRetentionPeriod(Team $team, CarbonImmutable $retentionDate): int\n {\n $reportIds = $this->automatedReportsRepository->getReportIdsByTeam($team);\n\n if ($reportIds->isEmpty()) {\n return 0;\n }\n\n $query = $this->automatedReportsRepository\n ->getReportResultsQueryForRetention($team, $retentionDate);\n\n return $this->deleteReportResultsByQuery($query, [\n 'team_id' => $team->getId(),\n 'retention_date' => $retentionDate->toDateTimeString(),\n ]);\n }\n\n /**\n * Delete ALL report results for a specific automated report\n *\n * @param string $uuid\n *\n * @return int\n */\n public function deleteReportResults(string $uuid): int\n {\n $report = $this->getReport($uuid);\n\n $query = $this->automatedReportsRepository->getResultsByReportQuery($report);\n\n return $this->deleteReportResultsByQuery($query, [\n 'report_uuid' => $uuid,\n 'report_id' => $report->getId(),\n ]);\n }\n\n public function deleteReportResult(AutomatedReportResult $result): void\n {\n $this->deleteS3Files($result);\n\n $result->delete();\n }\n\n /**\n * Get all reports for a specific team\n *\n * @param Team $team\n *\n * @return \\Illuminate\\Database\\Eloquent\\Collection\n */\n public function getTeamReports(Team $team): \\Illuminate\\Database\\Eloquent\\Collection\n {\n return $this->automatedReportsRepository->getReportsByTeam($team);\n }\n\n /**\n * Get all report results for a specific report\n *\n * @param AutomatedReport $report\n *\n * @return \\Illuminate\\Database\\Eloquent\\Collection\n */\n public function getReportResults(AutomatedReport $report): \\Illuminate\\Database\\Eloquent\\Collection\n {\n return $this->automatedReportsRepository->getResultsByReport($report);\n }\n\n public function deleteAllReportResults(AutomatedReport $report): void\n {\n $results = $this->getReportResults($report);\n\n /** @var AutomatedReportResult $result */\n foreach ($results as $result) {\n Log::info('Deleting result', [\n 'report' => $report->getId(),\n 'result' => $result->getId(),\n ]);\n\n $this->deleteReportResult($result);\n }\n }\n\n public function deleteAllData(Team $team): void\n {\n Log::info('Deleting automated report and results for team', [\n 'team' => $team->getId(),\n ]);\n\n $reports = $this->getTeamReports($team);\n\n /** @var AutomatedReport $report */\n foreach ($reports as $report) {\n Log::info('Deleting report', [\n 'team' => $team->getId(),\n 'report' => $report->getId(),\n ]);\n\n $this->deleteAllReportResults($report);\n\n $report->delete();\n }\n }\n}","depth":4,"value":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Services\\Kiosk\\AutomatedReports;\n\nuse Carbon\\CarbonImmutable;\nuse Carbon\\CarbonInterface;\nuse Carbon\\Exceptions\\InvalidFormatException;\nuse DateTime;\nuse DateTimeInterface;\nuse DateTimeZone;\nuse Illuminate\\Contracts\\Bus\\Dispatcher as BusDispatcher;\nuse Illuminate\\Database\\Eloquent\\Builder;\nuse Illuminate\\Support\\Carbon;\nuse Illuminate\\Support\\Collection;\nuse Illuminate\\Support\\Facades\\Log;\nuse Illuminate\\Support\\Facades\\Storage;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinition\\InputTypeEnum;\nuse Jiminny\\Component\\AskAnything\\AskAnythingPromptService;\nuse Jiminny\\Component\\AskAnything\\Dtos\\AskAnythingPromptDto;\nuse Jiminny\\Component\\UrlGenerator\\Webhook;\nuse Jiminny\\Contracts\\Repositories\\PlaybookCategoryRepository;\nuse Jiminny\\Contracts\\Repositories\\TeamRepository;\nuse Jiminny\\Contracts\\Repositories\\UserRepository;\nuse Jiminny\\Exceptions\\ApplicationException;\nuse Jiminny\\Exceptions\\InvalidArgumentException;\nuse Jiminny\\Exceptions\\ModelNotFoundException;\nuse Jiminny\\Jobs\\AutomatedReports\\RequestGenerateReportJob;\nuse Jiminny\\Models\\Activity\\Search;\nuse Jiminny\\Models\\AskAnything\\AskAnythingPrompt;\nuse Jiminny\\Models\\AskAnything\\AskAnythingPromptTarget;\nuse Jiminny\\Models\\AutomatedReport;\nuse Jiminny\\Models\\AutomatedReportResult;\nuse Jiminny\\Models\\Contracts\\UserContract;\nuse Jiminny\\Models\\Feature\\FeatureEnum;\nuse Jiminny\\Models\\Team;\nuse Jiminny\\Models\\User;\nuse Jiminny\\Repositories\\AskAnythingRepository;\nuse Jiminny\\Repositories\\AutomatedReportsRepository;\nuse Jiminny\\Repositories\\GroupRepository;\nuse Jiminny\\Repositories\\SearchRepository;\nuse Jiminny\\Repositories\\StageRepository;\nuse Throwable;\n\nclass AutomatedReportsService\n{\n public const string TYPE_LOSS_ANALYSIS = 'loss_analysis';\n public const string TYPE_ASK_JIMINNY = 'ask_jiminny';\n\n /**\n * Standard report types (used by kiosk for existing automated reports).\n */\n // @TODO this will add filter, however if we need to control feature by FF we need conditional logic\n public const array TYPES = [\n ['id' => 'exec_summary', 'name' => 'Exec Summary'],\n ['id' => 'coaching_profiles', 'name' => 'Coaching Profiles'],\n ['id' => 'product_feedback', 'name' => 'Product Feedback'],\n ['id' => self::TYPE_LOSS_ANALYSIS, 'name' => 'Loss Analysis'],\n// ['id' => 'questions', 'name' => 'Questions'],\n// ['id' => 'statistical_quant', 'name' => 'Statistical Quantitative'],\n ];\n\n public const array ALL_TYPES = [\n ...self::TYPES,\n ['id' => self::TYPE_ASK_JIMINNY, 'name' => 'Ask Jiminny'],\n ];\n\n public const string FREQUENCY_DAILY = 'daily';\n public const string FREQUENCY_WEEKLY = 'weekly';\n public const string FREQUENCY_MONTHLY = 'monthly';\n public const string FREQUENCY_QUARTERLY = 'quarterly';\n public const string FREQUENCY_ONE_OFF = 'one_off';\n\n /**\n * Frequencies for standard (non-Ask Jiminny) reports.\n */\n public const array FREQUENCIES = [\n ['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],\n ['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],\n ['id' => self::FREQUENCY_QUARTERLY, 'name' => 'Quarterly'],\n ['id' => self::FREQUENCY_ONE_OFF, 'name' => 'One-off'],\n ];\n\n /**\n * Frequencies for Ask Jiminny reports.\n */\n public const array ASK_JIMINNY_FREQUENCIES = [\n ['id' => self::FREQUENCY_DAILY, 'name' => 'Daily'],\n ['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],\n ['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],\n ];\n\n public const string MEDIA_TYPE_PDF = 'pdf';\n public const string MEDIA_TYPE_PODCAST = 'podcast';\n public const array MEDIA_TYPES = [self::MEDIA_TYPE_PDF, self::MEDIA_TYPE_PODCAST];\n public const array MEDIA_TYPE_OBJECT_PDF = ['id' => self::MEDIA_TYPE_PDF, 'name' => 'PDF'];\n public const array MEDIA_TYPE_OBJECT_PODCAST = ['id' => self::MEDIA_TYPE_PODCAST, 'name' => 'Podcast'];\n public const array MEDIA_TYPE_OBJECTS = [self::MEDIA_TYPE_OBJECT_PDF, self::MEDIA_TYPE_OBJECT_PODCAST];\n\n public const array CALL_TYPE_CONFERENCE = ['id' => 'conference', 'name' => 'Conference'];\n public const array CALL_TYPE_DIALER = ['id' => 'dialer', 'name' => 'Dialer'];\n public const int SENT_REPORT_AT_HOURS = 5;\n public const string PDF_KEY = 'pdf';\n public const string AUDIO_KEY = 'audio';\n\n private const array ALL_FREQUENCIES = [\n ['id' => self::FREQUENCY_DAILY, 'name' => 'Daily'],\n ['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],\n ['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],\n ['id' => self::FREQUENCY_QUARTERLY, 'name' => 'Quarterly'],\n ['id' => self::FREQUENCY_ONE_OFF, 'name' => 'One-off'],\n ];\n private const string S3_DIR = 'reports';\n private const array FILE_EXTENSIONS_VARIANTS = ['html', 'MD', 'pdf'];\n private const array FILE_PODCAST_EXTENSIONS_VARIANTS = ['json', 'mp3', 'ssml'];\n\n public function __construct(\n private readonly TeamRepository $teamRepository,\n private readonly GroupRepository $groupRepository,\n private readonly UserRepository $userRepository,\n private readonly StageRepository $stageRepository,\n private readonly DealStagesService $dealStagesService,\n private readonly RecipientsService $recipientsService,\n private readonly AutomatedReportsRepository $automatedReportsRepository,\n private readonly Webhook $webhookService,\n private readonly BusDispatcher $dispatcher,\n private readonly ActivityTypeService $activityTypeService,\n private readonly PlaybookCategoryRepository $playbookCategoryRepository,\n private readonly AskAnythingPromptService $askAnythingPromptService,\n private readonly SearchRepository $activitySearchRepository,\n private readonly AskAnythingRepository $askAnythingRepository,\n ) {\n }\n\n public static function getTypes(): array\n {\n $types = self::TYPES;\n\n return array_map(static function ($type) {\n return $type['id'];\n }, $types);\n }\n\n public static function getCallTypes(): array\n {\n return array_map(static function ($callType) {\n return $callType['id'];\n }, [self::CALL_TYPE_CONFERENCE, self::CALL_TYPE_DIALER]);\n }\n\n public static function getFrequencies(): array\n {\n return array_map(static function ($frequency) {\n return $frequency['id'];\n }, self::FREQUENCIES);\n }\n\n // front-facing structure\n public function getReportEnabledFieldData(bool $value = false): array\n {\n return [\n 'id' => 'report_enabled',\n 'label' => '',\n 'inputType' => InputTypeEnum::TOGGLE,\n 'value' => $value,\n ];\n }\n\n // Organizations = Teams\n public function getOrganizationFieldData(?string $value = null, bool $shortVersion = false): array\n {\n $options = $this->getTeams();\n\n if ($shortVersion) {\n return [\n 'id' => 'organization',\n 'label' => 'Organization',\n 'options' => $options,\n ];\n }\n\n return [\n 'id' => 'organization',\n 'label' => 'Organization',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => $options,\n 'value' => $value,\n 'dependencies' => [\n 'teams',\n 'deal_stage_at_call',\n 'current_deal_stage',\n 'recipients',\n ActivityTypeService::PLAYBOOK_CATEGORIES_KEY,\n ],\n 'dependsOn' => [],\n ];\n }\n\n // Teams = Groups\n public function getTeamFieldData(array $options = [], array $value = [], bool $shortVersion = false): array\n {\n if ($shortVersion) {\n return [\n 'id' => 'teams',\n 'label' => 'Team',\n 'options' => $options,\n ];\n }\n\n return [\n 'id' => 'teams',\n 'label' => 'Team',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'required' => false,\n 'placeholder' => 'Select',\n 'options' => $options,\n 'value' => $value, // value should be an array of objects {id, name}\n 'dependencies' => [ActivityTypeService::PLAYBOOK_CATEGORIES_KEY],\n 'dependsOn' => [],\n ];\n }\n\n public function getReportTypeFieldData(?string $value = null, bool $shortVersion = false, ?Team $team = null): array\n {\n $types = [];\n if ($team instanceof Team) {\n if ($team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {\n $types = self::TYPES;\n }\n if ($team->hasFeature(FeatureEnum::ASK_JIMINNY_REPORTS)) {\n $types[] = ['id' => self::TYPE_ASK_JIMINNY, 'name' => 'Ask Jiminny'];\n }\n } else {\n $types = self::TYPES;\n }\n\n if ($shortVersion) {\n return [\n 'id' => 'report_type',\n 'label' => 'Report Type',\n 'options' => $types,\n ];\n }\n\n return [\n 'id' => 'report_type',\n 'label' => 'Report Type',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => $types,\n 'value' => $value,\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getFrequencyFieldData(?string $value = null): array\n {\n return [\n 'id' => 'frequency',\n 'label' => 'Frequency',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => self::FREQUENCIES,\n 'value' => $value,\n 'dependencies' => ['period'],\n 'dependsOn' => [],\n ];\n }\n\n public function getPeriodFieldData(?string $valueStartDate = null, ?string $valueEndDate = null): array\n {\n return [\n 'id' => 'period',\n 'label' => 'Select one-off period',\n 'inputType' => InputTypeEnum::DATE_RANGE,\n 'required' => true,\n 'placeholder' => 'Select',\n 'value' => ['startDate' => $valueStartDate, 'endDate' => $valueEndDate],\n 'queryParams' => [\n 'startDate' => 'start_date_period',\n 'endDate' => 'end_date_period',\n ],\n 'dependencies' => [],\n 'dependsOn' => ['frequency'],\n ];\n }\n\n public function getActivityTypesFieldData(?Team $team = null, array $value = [], array $teamsFilter = []): array\n {\n return $this->activityTypeService->getActivityTypeFieldData(team: $team, value: $value, groupIds: $teamsFilter);\n }\n\n public function getDealStageAtCallFieldData(?Team $team = null, array $value = []): array\n {\n return $this->dealStagesService->getDealStageAtCallFieldData(team: $team, value: $value);\n }\n\n public function getCurrentDealStageFieldData(?Team $team = null, array $value = []): array\n {\n return $this->dealStagesService->getCurrentDealStageFieldData(team: $team, value: $value);\n }\n\n public function getDealValueFieldData(?int $valueMin = null, ?int $valueMax = null): array\n {\n return [\n 'id' => 'deal_value',\n 'label' => 'Deal Value',\n 'inputType' => InputTypeEnum::INTEGER_RANGE,\n 'required' => false,\n 'value' => ['min' => $valueMin, 'max' => $valueMax],\n 'queryParams' => [\n 'min' => 'min_deal_value',\n 'max' => 'max_deal_value',\n ],\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getCallTypeFieldData(bool $conferenceOn = false, bool $dialerOn = false): array\n {\n $value = [];\n $conferenceOn && $value[] = self::CALL_TYPE_CONFERENCE;\n $dialerOn && $value[] = self::CALL_TYPE_DIALER;\n\n return [\n 'id' => 'call_type',\n 'label' => 'Call Type',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'required' => true,\n 'options' => [\n self::CALL_TYPE_CONFERENCE,\n self::CALL_TYPE_DIALER,\n ],\n 'value' => $value,\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getMediaTypeFieldData(?AutomatedReport $report = null): array\n {\n $value = [];\n\n if ($report) {\n $value = $this->transformMediaTypes($report);\n }\n\n return [\n 'id' => 'media_types',\n 'label' => 'Export as',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'required' => true,\n 'options' => self::MEDIA_TYPE_OBJECTS,\n 'value' => $value,\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getCallDurationFieldData(?int $valueMin = null, ?int $valueMax = null): array\n {\n return [\n 'id' => 'call_duration',\n 'label' => 'Call Duration',\n 'inputType' => InputTypeEnum::INTEGER_RANGE,\n 'required' => false,\n 'value' => ['min' => $valueMin, 'max' => $valueMax],\n 'queryParams' => [\n 'min' => 'min_call_duration',\n 'max' => 'max_call_duration',\n ],\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getRecipientsFieldData(?Team $team = null, array $value = []): array\n {\n return $this->recipientsService->getRecipientsFieldData(team: $team, value: $value);\n }\n\n public function getJiminnyRecipientsFieldData(array $value = []): array\n {\n return $this->recipientsService->getJiminnyRecipientsFieldData($value);\n }\n\n public function getAdditionalPromptInputFieldData(?string $value = null): array\n {\n return [\n 'id' => 'additional_prompt_input',\n 'label' => 'Special requirements',\n 'inputType' => InputTypeEnum::TEXTAREA,\n 'required' => false,\n 'placeholder' => 'What should be the focus of the report?',\n 'value' => $value,\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getCustomReportNameFieldData(?string $value = null): array\n {\n return [\n 'id' => 'custom_name',\n 'label' => 'Custom report name',\n 'inputType' => InputTypeEnum::TEXT,\n 'required' => false,\n 'placeholder' => 'Enter custom name',\n 'value' => $value,\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n // data providers\n public function getTeams(): array\n {\n $teams = $this->teamRepository->getTeamsForKiosk(status: Team::STATUS_ACTIVE);\n\n $teamData = [];\n foreach ($teams as $team) {\n if (! $team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {\n continue;\n }\n\n $teamData[] = $this->transformTeam($team);\n }\n\n return $teamData;\n }\n\n public function getTeamGroups(string $teamUuid): array\n {\n $data = [];\n $team = $this->getTeam($teamUuid);\n\n if ($team !== null) {\n $groups = $team->groups()->get();\n\n foreach ($groups as $group) {\n $data[] = [\n 'id' => $group->getUuid(),\n 'name' => $group->getName(),\n ];\n }\n }\n\n return $data;\n }\n\n public function getTeamsGroupsOptions(array $filterTeamUuids = []): array\n {\n $data = [];\n $teams = $this->getTeams();\n\n foreach ($teams as $team) {\n if (! empty($filterTeamUuids) && ! in_array($team['id'], $filterTeamUuids, true)) {\n continue;\n }\n\n $data[] = [\n 'label' => $team['name'],\n 'groups' => $this->getTeamGroups($team['id']),\n ];\n }\n\n return $data;\n }\n\n public function getTeam(string $teamUuid): ?Team\n {\n return $this->teamRepository->idOrUuid($teamUuid);\n }\n\n public function getTeamById(int $teamId): ?Team\n {\n return $this->teamRepository->find($teamId);\n }\n\n public function getGroupsUuids(AutomatedReport $report): array\n {\n $uuids = [];\n $reportGroups = $report->getGroups();\n foreach ($reportGroups as $groupId) {\n if ($group = $this->groupRepository->find($groupId)) {\n $uuids[] = $group->getUuid();\n }\n }\n\n return $uuids;\n }\n\n public function getPlaybookCategoriesUuids(AutomatedReport $report): array\n {\n $uuids = [];\n $playbookCategories = $report->getPlaybookCategories();\n foreach ($playbookCategories as $id) {\n if ($category = $this->playbookCategoryRepository->find($id)) {\n $uuids[] = $category->getUuid();\n }\n }\n\n return $uuids;\n }\n\n public function getDealAtCallStagesUuids(AutomatedReport $report): array\n {\n $uuids = [];\n $reportStages = $report->getDealAtCallStages();\n foreach ($reportStages as $id) {\n if ($stage = $this->stageRepository->find($id)) {\n $uuids[] = $stage->getUuid();\n }\n }\n\n return $uuids;\n }\n\n public function getCurrentDealStagesUuids(AutomatedReport $report): array\n {\n $uuids = [];\n $reportStages = $report->getCurrentDealStages();\n foreach ($reportStages as $id) {\n if ($stage = $this->stageRepository->find($id)) {\n $uuids[] = $stage->getUuid();\n }\n }\n\n return $uuids;\n }\n\n public function getUsersUuids(AutomatedReport $report): array\n {\n return $this->extractUserUuids($report->getRecipients());\n }\n\n public function getJiminnyUsersUuids(AutomatedReport $report): array\n {\n return $this->extractUserUuids($report->getJiminnyRecipients());\n }\n\n /**\n * @param array<string, mixed> $recipients\n */\n private function extractUserUuids(array $recipients): array\n {\n $userIds = $recipients['users'] ?? [];\n\n return collect($userIds)\n ->map(fn ($id) => $this->userRepository->find((int) $id))\n ->filter()\n ->map(fn (UserContract $user) => $user->getUuid())\n ->values()\n ->all();\n }\n\n // get mail data\n public function getRecipientUsers(AutomatedReport $report): array\n {\n return $this->buildRecipientUsers($report->getRecipients());\n }\n\n private function getJiminnyRecipientUsers(AutomatedReport $report): array\n {\n return $this->buildRecipientUsers($report->getJiminnyRecipients());\n }\n\n /**\n * @param array<string, mixed> $recipients\n */\n private function buildRecipientUsers(array $recipients): array\n {\n $userIds = $recipients['users'] ?? [];\n\n return collect($userIds)\n ->map(fn ($id) => $this->userRepository->find((int) $id))\n ->filter()\n ->map(fn (UserContract $user) => [\n 'email' => $user->getEmailAddress(),\n 'name' => $user->getName(),\n 'timezone' => $user->getTimezone()->getName(),\n ])\n ->values()\n ->all();\n }\n\n public function getValidRecipientUsers(AutomatedReport $report, bool $includeJiminny = false): array\n {\n if ($report->isAskJiminnyReport()) {\n $recipients = $this->resolveAskJiminnyRecipients($report);\n } else {\n $recipients = $this->getRecipientUsers($report);\n if ($includeJiminny) {\n $recipients = array_merge($recipients, $this->getJiminnyRecipientUsers($report));\n }\n }\n\n $emails = [];\n\n return array_values(array_filter(\n $recipients,\n static function ($recipient) use (&$emails) {\n if (empty($recipient['email']) || in_array($recipient['email'], $emails, true)) {\n return false;\n }\n $emails[] = $recipient['email'];\n\n return true;\n }\n ));\n }\n\n private function resolveAskJiminnyRecipients(AutomatedReport $report): array\n {\n $recipients = [];\n\n $creator = $report->getCreator();\n if ($creator !== null) {\n $recipients[] = [\n 'email' => $creator->getEmailAddress(),\n 'name' => $creator->getName(),\n 'timezone' => $creator->getTimezone()->getName(),\n ];\n }\n\n return array_merge(\n $recipients,\n $this->buildRecipientUsers($report->getRecipients()),\n $this->getGroupRecipientUsers($report),\n );\n }\n\n private function getGroupRecipientUsers(AutomatedReport $report): array\n {\n $users = [];\n foreach ($report->getGroups() as $groupId) {\n $group = $this->groupRepository->find($groupId);\n if ($group === null) {\n continue;\n }\n foreach ($group->getMembers() as $member) {\n $users[] = [\n 'email' => $member->getEmailAddress(),\n 'name' => $member->getName(),\n 'timezone' => $member->getTimezone()->getName(),\n ];\n }\n }\n\n return $users;\n }\n\n public function getReportTypeName(AutomatedReportResult $report): string\n {\n $type = $report->getReport()->getType();\n\n $getType = $this->transformReportType($type);\n\n return $getType['name'];\n }\n\n public function getReportPeriodName(AutomatedReportResult $report): string\n {\n $from = $report->getFromDate();\n $to = $report->getToDate();\n $frequency = $report->getReport()->getFrequency();\n\n if ($from === null || $to === null) {\n if (! $report->getReport()->isAskJiminnyReport()) {\n $invalidPeriod = $from === null ? 'from' : 'to';\n\n throw new ApplicationException('Report period is invalid: ' . $invalidPeriod);\n }\n\n $period = $this->calculateFromAndToDatePeriod($frequency);\n $from = $period['fromDate'];\n $to = $period['toDate'];\n }\n\n return $this->formatReportPeriodName($frequency, $from, $to);\n }\n\n private function formatReportPeriodName(string $frequency, Carbon $from, Carbon $to): string\n {\n $fromYear = $from->format('Y');\n $toYear = $to->format('Y');\n $differentYears = $fromYear !== $toYear;\n\n switch ($frequency) {\n case self::FREQUENCY_DAILY:\n return $from->format('j M Y');\n\n case self::FREQUENCY_QUARTERLY:\n // 'Jan-Mar 2025' or 'Nov 2024-Jan 2025' if years differ\n $startMonth = $from->format('M');\n $endMonth = $to->copy()->subMonth();\n $endMonthName = $endMonth->format('M');\n $endMonthYear = $endMonth->format('Y');\n\n if ($differentYears) {\n return \"{$startMonth} {$fromYear} - {$endMonthName} {$endMonthYear}\";\n }\n\n return \"{$startMonth} - {$endMonthName} {$toYear}\";\n\n case self::FREQUENCY_MONTHLY:\n // 'May 2025' - monthly reports are always within the same year\n return $from->format('M Y');\n\n case self::FREQUENCY_WEEKLY:\n // '4 - 8 Aug 2025', '27 Oct - 3 Nov 2025', or '28 Dec 2024 - 3 Jan 2025' if years differ\n $startDay = $from->format('j');\n $endDay = $to->format('j');\n $startMonth = $from->format('M');\n $endMonth = $to->format('M');\n\n if ($differentYears) {\n return \"{$startDay} {$startMonth} {$fromYear} - {$endDay} {$endMonth} {$toYear}\";\n }\n\n if ($startMonth !== $endMonth) {\n return \"{$startDay} {$startMonth} - {$endDay} {$endMonth} {$toYear}\";\n }\n\n return \"{$startDay} - {$endDay} {$endMonth} {$toYear}\";\n\n case self::FREQUENCY_ONE_OFF:\n // '2 May-31 May 2025' or '15 Dec 2024-15 Jan 2025' if years differ\n $startDay = $from->format('j');\n $startMonth = $from->format('M');\n $endDay = $to->format('j');\n $endMonth = $to->format('M');\n\n // If same month and year, use a format like '2-31 May 2025'\n if ($startMonth === $endMonth && ! $differentYears) {\n return \"{$startDay} - {$endDay} {$startMonth} {$toYear}\";\n }\n\n // If different years, include both years\n if ($differentYears) {\n return \"{$startDay} {$startMonth} {$fromYear} - {$endDay} {$endMonth} {$toYear}\";\n }\n\n // Same year but different months\n return \"{$startDay} {$startMonth} - {$endDay} {$endMonth} {$toYear}\";\n\n default:\n // Default format for unknown frequencies\n return $from->format('j M Y') . ' - ' . $to->format('j M Y');\n }\n }\n\n public function getReportTeamsName(AutomatedReportResult $report): string\n {\n $groups = $report->getGroups();\n\n if (empty($groups)) {\n return 'All';\n }\n\n // Get group names from repository\n $groupNames = [];\n foreach ($groups as $groupId) {\n $group = $this->groupRepository->find($groupId);\n if ($group) {\n $groupNames[] = $group->getName();\n }\n }\n\n if (count($groupNames) === 1) {\n // Single team format\n $teamsName = $groupNames[0];\n } else {\n // Multiple teams format\n $teamsName = implode(', ', $groupNames);\n }\n\n return $teamsName;\n }\n\n public function getReportFileName(AutomatedReportResult $report): string\n {\n $customName = $report->getReport()->getCustomName();\n $periodName = $this->getReportPeriodName($report);\n $filenameSuffix = $this->getFilenameSuffix($report);\n\n if ($customName) {\n if ($filenameSuffix) {\n $customName .= \" {$filenameSuffix}\";\n }\n\n return $this->sanitizeFileName(\"{$customName} - {$periodName}\");\n }\n\n $baseName = $this->getReportTypeName($report);\n\n if ($filenameSuffix) {\n $baseName .= \" {$filenameSuffix}\";\n }\n\n return $this->sanitizeFileName(\"{$baseName} - {$periodName} - {$this->getReportTeamsName($report)}\");\n }\n\n public function getReportFileNameWithExtension(AutomatedReportResult $result): string\n {\n $extension = $this->getMediaTypeMetadata($result)['extension'];\n\n return $this->getReportFileName($result) . '.' . $extension;\n }\n\n public function sanitizeFileName(string $fileName): string\n {\n return str_replace(['/', '\\\\'], '-', $fileName);\n }\n\n public function isUserRecipientOfReport(User $user, AutomatedReport $report): bool\n {\n $recipients = array_map('intval', $report->getRecipients()['users'] ?? []);\n\n return in_array($user->getId(), $recipients);\n }\n\n public function transformReportResults(Collection $automatedReportResults): array\n {\n $data = [];\n foreach ($automatedReportResults as $automatedReportResult) {\n /** @var AutomatedReportResult $automatedReportResult */\n\n $report = $automatedReportResult->getReport();\n\n $createdBy = $report->getCreator();\n $creator = [\n 'id' => $createdBy?->getUuid(),\n 'name' => $createdBy?->getName(),\n 'email' => $createdBy?->getEmailAddress(),\n 'photoUrl' => $createdBy?->getPhotoUrl(),\n ];\n\n $data[] = [\n 'id' => $automatedReportResult->getUuid(),\n 'name' => $automatedReportResult->getName(),\n 'frequency' => $this->transformFrequency($report->getFrequency()),\n 'recipients' => [\n ...array_values($this->transformGroups(team: $report->getTeam(), groupsIds: $report->getGroups())),\n ...array_values($this->transformRecipients($report->getRecipients())),\n ],\n 'report_type' => $this->transformReportType($report->getType()),\n 'media_type' => $automatedReportResult->getMediaType(),\n 'downloadUrl' => $this->generateReportResultDownloadUrl($automatedReportResult),\n 'viewUrl' => $this->generateReportResultViewUrl($automatedReportResult),\n 'generated_at' => $automatedReportResult->getGeneratedAt()?->toIso8601String(),\n 'creator' => $creator,\n ];\n }\n\n return $data;\n }\n\n public function hasCallTypeConference(AutomatedReport $report): bool\n {\n return in_array(self::CALL_TYPE_CONFERENCE['id'], $report->getCallTypes(), true);\n }\n\n public function hasCallTypeDialer(AutomatedReport $report): bool\n {\n return in_array(self::CALL_TYPE_DIALER['id'], $report->getCallTypes(), true);\n }\n\n // transformers\n private function transformTeam(Team $team): array\n {\n if (! $team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {\n return [];\n }\n\n return [\n 'id' => $team->getUuid(),\n 'name' => $team->getName(),\n ];\n }\n\n private function transformReportFullView(AutomatedReport $report): array\n {\n $base = $this->transformReportBase($report);\n\n return $report->getType() === self::TYPE_ASK_JIMINNY\n ? $base + $this->transformAskJiminnyFields($report)\n : $base + $this->transformStandardReportFields($report);\n }\n\n private function transformReportBase(AutomatedReport $report): array\n {\n return [\n 'id' => $report->getUuid(),\n 'organization' => $this->transformOrganization(team: $report->getTeam()),\n 'report_type' => $this->transformReportType($report->getType()),\n 'frequency' => $this->transformFrequency($report->getFrequency()),\n ];\n }\n\n private function transformStandardReportFields(AutomatedReport $report): array\n {\n $team = $report->getTeam();\n\n return [\n 'report_enabled' => $report->getStatus(),\n 'start_date_period' => $report->getFrom()?->format('Y-m-d H:i:s'),\n 'end_date_period' => $report->getTo()?->format('Y-m-d H:i:s'),\n 'deal_value_min' => $report->getDealValueMin(),\n 'deal_value_max' => $report->getDealValueMax(),\n 'call_types' => $this->transformCallType($report->getCallTypes()),\n 'media_types' => $this->transformMediaTypes($report),\n 'call_duration_min' => $this->transformDurationToMinutes($report->getCallDurationMin()),\n 'call_duration_max' => $this->transformDurationToMinutes($report->getCallDurationMax()),\n 'teams' => $this->transformGroups(team: $team, groupsIds: $report->getGroups()),\n 'deal_at_call_stages' => $this->transformStages(team: $team, stagesIds: $report->getDealAtCallStages()),\n 'current_deal_stages' => $this->transformStages(team: $team, stagesIds: $report->getCurrentDealStages()),\n 'recipients' => $this->transformRecipients($report->getRecipients()),\n 'created_by' => $this->transformCreator($report->getCreator()),\n 'additional_prompt_input' => $report->getAdditionalPromptInput(),\n 'custom_name' => $report->getCustomName(),\n 'created_at' => $report->getCreatedAt()->format('Y-m-d H:i:s'),\n 'updated_at' => $report->getUpdatedAt()->format('Y-m-d H:i:s'),\n 'deleted_at' => $report->getDeletedAt()?->format('Y-m-d H:i:s'),\n ];\n }\n\n private function transformAskJiminnyFields(AutomatedReport $report): array\n {\n $team = $report->getTeam();\n $creatorId = $report->getAttribute('created_by');\n $explicitUserIds = array_values(array_filter(\n $report->getRecipients()['users'] ?? [],\n static fn ($id) => $id !== $creatorId\n ));\n\n return [\n 'report_name' => $report->getCustomName(),\n 'enabled' => $report->getStatus(),\n 'share_teams' => $this->transformGroups(team: $team, groupsIds: $report->getGroups()),\n 'share_users' => $this->transformRecipients(['users' => $explicitUserIds]),\n 'saved_search' => $this->transformSafeSearch($report->getSavedSearch()),\n 'ask_jiminny_prompt' => $this->transformAskJiminnyPrompt($report->getAskAnythingPrompt()),\n 'expires_on' => $report->getExpiresAt()?->format('Y-m-d'),\n ];\n }\n\n private function transformOrganization(?Team $team): array\n {\n return [\n 'id' => $team?->getUuid(),\n 'name' => $team?->getName(),\n ];\n }\n\n private function transformReportType(string $type): array\n {\n foreach (self::ALL_TYPES as $typeItem) {\n if ($typeItem['id'] === $type) {\n return $typeItem;\n }\n }\n\n return [];\n }\n\n private function transformCallType(array $types): array\n {\n $result = [];\n $callTypes = [self::CALL_TYPE_CONFERENCE, self::CALL_TYPE_DIALER];\n\n foreach ($types as $type) {\n foreach ($callTypes as $callTypeItem) {\n if ($callTypeItem['id'] === $type) {\n $result[] = $callTypeItem;\n\n break;\n }\n }\n }\n\n return $result;\n }\n\n private function transformMediaTypes(AutomatedReport $report): array\n {\n $values = [];\n\n foreach ($report->getMediaTypes() as $mediaType) {\n if (! in_array($mediaType, self::MEDIA_TYPES, true)) {\n continue;\n }\n\n $values[] = match ($mediaType) {\n self::MEDIA_TYPE_PDF => self::MEDIA_TYPE_OBJECT_PDF,\n self::MEDIA_TYPE_PODCAST => self::MEDIA_TYPE_OBJECT_PODCAST,\n };\n }\n\n return $values;\n }\n\n private function transformFrequency(string $frequency): array\n {\n foreach (self::ALL_FREQUENCIES as $frequencyItem) {\n if ($frequencyItem['id'] === $frequency) {\n return $frequencyItem;\n }\n }\n\n return [];\n }\n\n public function transformDurationToMinutes(?int $duration): ?int\n {\n if (! $duration) {\n return null;\n }\n\n return (int) ($duration / 60);\n }\n\n private function transformGroups(?Team $team, array $groupsIds): array\n {\n if (empty($groupsIds) || ! $team) {\n return [];\n }\n\n $data = [];\n foreach ($groupsIds as $groupId) {\n $group = $team->groups()->where('id', $groupId)->first();\n\n if ($group) {\n $data[] = [\n 'id' => $group->getUuid(),\n 'name' => $group->getName(),\n 'photoUrl' => $group->getPhotoUrl(),\n ];\n }\n }\n\n return $data;\n }\n\n private function transformStages(?Team $team, array $stagesIds): array\n {\n if (empty($stagesIds) || ! $team) {\n return [];\n }\n\n $data = [];\n foreach ($stagesIds as $stageId) {\n $stage = $team->stages()->where('id', $stageId)->first();\n\n if ($stage) {\n $data[] = [\n 'id' => $stage->getUuid(),\n 'name' => $stage->getName(),\n ];\n }\n }\n\n return $data;\n }\n\n private function transformRecipients(array $recipients): array\n {\n $users = [];\n foreach ($recipients['users'] ?? [] as $userId) {\n $users[] = $this->transformUser($userId);\n }\n\n return $users;\n }\n\n private function transformCreator(?User $user): ?array\n {\n if ($user === null) {\n return null;\n }\n\n return $this->transformUser($user->getId());\n }\n\n private function transformAskJiminnyPrompt(?AskAnythingPrompt $prompt): ?array\n {\n if ($prompt === null) {\n return null;\n }\n\n return [\n 'id' => $prompt->getUuid(),\n 'name' => $prompt->getTitle(),\n ];\n }\n\n private function transformSafeSearch(?Search $search): ?array\n {\n if ($search === null) {\n return null;\n }\n\n return [\n 'id' => $search->getUuid(),\n 'name' => $search->getName(),\n ];\n }\n\n private function transformUser(int $userId): array\n {\n /* @var ?User $user */\n $user = $this->userRepository->find($userId);\n\n return [\n 'id' => $user?->getUuid(),\n 'name' => $user?->getName(),\n 'email' => $user?->getEmailAddress(),\n 'photoUrl' => $user?->getPhotoUrl(),\n ];\n }\n\n public function create(array $data): array\n {\n $validatedData = $this->validateAndTransformData($data);\n $validatedData['created_by'] = auth()->id();\n\n $automatedReport = $this->automatedReportsRepository->create($validatedData);\n\n $this->generateOneOffReport($automatedReport);\n\n return $this->transformReportFullView($automatedReport);\n }\n\n public function update(string $uuid, array $data): array\n {\n $validatedData = $this->validateAndTransformData($data);\n $report = $this->automatedReportsRepository->findByUuid($uuid);\n\n if (! $report) {\n throw new InvalidArgumentException('Report not found');\n }\n\n $oldCustomName = $report->getCustomName();\n\n $automatedReport = $this->automatedReportsRepository->update($report, $validatedData);\n\n if ($oldCustomName !== $automatedReport->getCustomName()) {\n $this->updateResultNames($automatedReport);\n }\n\n $this->generateOneOffReport($automatedReport);\n\n return $this->transformReportFullView($automatedReport);\n }\n\n /**\n * Create an Ask Jiminny report.\n */\n public function createAskJiminnyReport(array $data, User $creator): array\n {\n $validatedData = $this->validateAskJiminnyReportData($data, $creator);\n $validatedData['created_by'] = $creator->getId();\n\n $automatedReport = $this->automatedReportsRepository->create($validatedData);\n\n return $this->transformReportFullView($automatedReport);\n }\n\n /**\n * Update an Ask Jiminny report.\n */\n public function updateAskJiminnyReport(AutomatedReport $report, array $data, User $user): array\n {\n if (! $report->isAskJiminnyReport()) {\n throw new InvalidArgumentException('Report is not an Ask Jiminny report');\n }\n\n $validatedData = $this->validateAskJiminnyReportData($data, $user);\n\n $oldCustomName = $report->getCustomName();\n\n $automatedReport = $this->automatedReportsRepository->update($report, $validatedData);\n\n if ($oldCustomName !== $automatedReport->getCustomName()) {\n $this->updateResultNames($automatedReport);\n }\n\n return $this->transformReportFullView($automatedReport);\n }\n\n public function updateAskJiminnyReportStatus(AutomatedReport $report, bool $status): array\n {\n $this->automatedReportsRepository->update($report, ['status' => $status]);\n\n return $this->transformReportFullView($report->fresh());\n }\n\n /**\n * Validate and transform data for Ask Jiminny reports.\n */\n private function validateAskJiminnyReportData(array $data, User $user): array\n {\n // Validate name\n $name = trim($data['report_name'] ?? '');\n if (empty($name)) {\n throw new InvalidArgumentException('Report name is required');\n }\n if (mb_strlen($name) > 50) {\n throw new InvalidArgumentException('Report name must be 50 characters or less');\n }\n\n // Validate frequency (only daily, weekly, monthly for Ask Jiminny)\n $frequency = $data['frequency'] ?? null;\n $askJiminnyFrequencies = [self::FREQUENCY_DAILY, self::FREQUENCY_WEEKLY, self::FREQUENCY_MONTHLY];\n if (! in_array($frequency, $askJiminnyFrequencies, true)) {\n throw new InvalidArgumentException('Frequency must be daily, weekly, or monthly');\n }\n\n // Validate expiration date\n $expiresAt = $data['expires_on'] ?? null;\n if (empty($expiresAt)) {\n throw new InvalidArgumentException('Expiration date is required');\n }\n\n try {\n $expiresAtDate = Carbon::parse($expiresAt);\n } catch (InvalidFormatException $e) {\n throw new InvalidArgumentException('Expiration date format is invalid');\n }\n $maxExpiration = Carbon::now()->addYear();\n if ($expiresAtDate->gt($maxExpiration)) {\n throw new InvalidArgumentException('Expiration date cannot be more than 1 year from now');\n }\n if ($expiresAtDate->isPast()) {\n throw new InvalidArgumentException('Expiration date cannot be in the past');\n }\n\n // Validate saved search\n $activitySearchId = $data['saved_search'] ?? null;\n if (empty($activitySearchId)) {\n throw new InvalidArgumentException('Saved search is required');\n }\n $savedSearch = $this->activitySearchRepository->findByUuidAndUser($activitySearchId, $user);\n if (! $savedSearch) {\n throw new InvalidArgumentException('Saved search not found or does not belong to you');\n }\n\n // Validate saved prompt\n $askAnythingPromptId = $data['ask_jiminny_prompt'] ?? null;\n if (empty($askAnythingPromptId)) {\n throw new InvalidArgumentException('Ask Jiminny prompt is required');\n }\n $prompt = $this->askAnythingRepository->getPromptByUuid($askAnythingPromptId);\n if (! $prompt) {\n throw new InvalidArgumentException('Ask Jiminny prompt not found');\n }\n\n // Validate status\n $status = $data['enabled'] ?? false;\n\n $recipientUserIds = [$user->getId()];\n\n if (! empty($data['share_users'])) {\n $sharedUserIds = $this->validateAndGetUserIdsByTeam(\n $user->team,\n (array) $data['share_users']\n );\n $recipientUserIds = array_merge($recipientUserIds, $sharedUserIds);\n }\n\n $sharedGroupIds = [];\n if (! empty($data['share_teams'])) {\n $sharedGroupIds = $this->validateAndGetGroupIds($user->team, (array) $data['share_teams']);\n }\n\n $recipientUserIds = array_values(array_unique($recipientUserIds));\n\n return [\n 'team_id' => $user->getTeamId(),\n 'type' => self::TYPE_ASK_JIMINNY,\n 'status' => (bool) $status,\n 'frequency' => $frequency,\n 'custom_name' => $name,\n 'activity_search_id' => $savedSearch->getId(),\n 'ask_anything_prompt_id' => $prompt->getId(),\n 'expires_at' => $expiresAtDate->toDateString(),\n 'media_types' => [self::MEDIA_TYPE_PDF],\n 'call_types' => [],\n 'recipients' => ['users' => $recipientUserIds],\n 'groups' => $sharedGroupIds,\n ];\n }\n\n public static function getAskJiminnyFrequencies(): array\n {\n return array_map(static function ($frequency) {\n return $frequency['id'];\n }, self::ASK_JIMINNY_FREQUENCIES);\n }\n\n public function getAskJiminnyReportFilters(User $user): array\n {\n $savedSearches = $this->activitySearchRepository->findByUserOrderedByName($user)\n ->map(fn (Search $search) => [\n 'id' => $search->getUuid(),\n 'name' => $search->getName(),\n ])\n ->values()->all();\n\n $prompts = collect(\n $this->askAnythingPromptService->get($user, AskAnythingPromptTarget::on_demand)\n )->map(fn (AskAnythingPromptDto $prompt) => [\n 'id' => $prompt->id,\n 'name' => $prompt->title,\n ])->values()->all();\n\n return [\n [\n 'id' => 'prompt',\n 'label' => 'Prompt',\n 'options' => $prompts,\n ],\n [\n 'id' => 'saved_search',\n 'label' => 'Saved Search',\n 'options' => $savedSearches,\n ],\n ];\n }\n\n public function getAskJiminnyReportFormData(User $user, ?AutomatedReport $report = null): array\n {\n $team = $user->getTeam();\n $userTimezone = $user->getTimezone();\n\n $savedSearches = $this->activitySearchRepository->findByUserOrderedByName($user)\n ->map(fn (Search $search) => [\n 'id' => $search->getUuid(),\n 'name' => $search->getName(),\n ])\n ->values()->all();\n\n $prompts = collect(\n $this->askAnythingPromptService->get($user, AskAnythingPromptTarget::on_demand)\n )->map(fn (AskAnythingPromptDto $prompt) => [\n 'id' => $prompt->id,\n 'name' => $prompt->title,\n ])->values()->all();\n\n $teamGroups = $this->groupRepository->getAllByTeam($team)->map(fn ($group) => [\n 'id' => $group->getUuid(),\n 'name' => $group->getName(),\n ])->values()->all();\n\n $shareUsers = $this->recipientsService->getRecipientsFieldData(team: $team)['options'] ?? [];\n\n $sharedTeamsValue = [];\n $sharedUsersValue = [];\n if ($report) {\n $sharedTeamsValue = $this->transformGroups($team, $report->getGroups());\n\n $recipientUserIds = $report->getRecipients()['users'] ?? [];\n $creatorId = $report->getAttribute('created_by');\n $sharedUserIds = array_values(array_filter(\n $recipientUserIds,\n static fn ($id) => $id !== $creatorId\n ));\n $sharedUsersValue = collect($sharedUserIds)\n ->map(fn ($id) => $this->userRepository->find((int) $id))\n ->filter()\n ->map(fn (User $u) => [\n 'id' => $u->getUuid(),\n 'name' => $u->getName(),\n ])\n ->values()\n ->all();\n }\n\n return [\n 'fields' => [\n [\n 'id' => 'enabled',\n 'inputType' => InputTypeEnum::TOGGLE,\n 'label' => '',\n 'value' => $report?->getStatus() ?? false,\n ],\n [\n 'id' => 'report_name',\n 'inputType' => InputTypeEnum::TEXT,\n 'label' => 'Name',\n 'placeholder' => 'Enter name',\n 'required' => true,\n 'validation' => ['maxLength' => 50],\n 'value' => $report?->getCustomName() ?? '',\n ],\n [\n 'id' => 'frequency',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'label' => 'Frequency',\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => self::ASK_JIMINNY_FREQUENCIES,\n 'value' => $report ? $this->transformFrequency($report->getFrequency()) : null,\n ],\n [\n 'id' => 'expires_on',\n 'inputType' => InputTypeEnum::DATE,\n 'label' => 'Expires on',\n 'required' => true,\n 'placeholder' => 'Select',\n 'validation' => [\n 'minDate' => now($userTimezone)->toDateString(),\n 'maxDate' => now($userTimezone)->addYear()->toDateString(),\n ],\n 'value' => $report?->getExpiresAt()?->toDateString(),\n ],\n [\n 'id' => 'share_teams',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'label' => 'Team',\n 'required' => false,\n 'placeholder' => 'Select',\n 'options' => $teamGroups,\n 'value' => $sharedTeamsValue,\n ],\n [\n 'id' => 'share_users',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'label' => 'Team member',\n 'required' => false,\n 'placeholder' => 'Select',\n 'groupLabelKey' => 'label',\n 'groupValuesKey' => 'users',\n 'optionLabelKey' => 'name',\n 'optionValueKey' => 'id',\n 'options' => $shareUsers,\n 'value' => $sharedUsersValue,\n ],\n [\n 'id' => 'saved_search',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'label' => 'Saved search',\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => $savedSearches,\n 'value' => $report && $report->getSavedSearch() ? [\n 'id' => $report->getSavedSearch()->getUuid(),\n 'name' => $report->getSavedSearch()->getName(),\n ] : null,\n ],\n [\n 'id' => 'ask_jiminny_prompt',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'label' => 'Ask Jiminny prompt',\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => $prompts,\n 'value' => $report && $report->getAskAnythingPrompt() ? [\n 'id' => $report->getAskAnythingPrompt()->getUuid(),\n 'name' => $report->getAskAnythingPrompt()->getTitle(),\n ] : null,\n ],\n ],\n ];\n }\n\n private function updateResultNames(AutomatedReport $automatedReport): void\n {\n $results = $this->automatedReportsRepository->getResultsByReport($automatedReport);\n\n foreach ($results as $result) {\n $result->update(['name' => $this->getReportFileName($result)]);\n }\n }\n\n public function updateStatus(string $uuid, array $data): array\n {\n $automatedReport = $this->automatedReportsRepository->findByUuid($uuid);\n\n if (! $automatedReport) {\n throw new ModelNotFoundException('Report not found');\n }\n\n $status = $this->validateReportStatus($data['report_enabled'] ?? null);\n $automatedReport->update([\n 'status' => $status,\n ]);\n\n $this->generateOneOffReport($automatedReport);\n\n return $this->transformReportFullView($automatedReport);\n }\n\n private function generateOneOffReport(AutomatedReport $automatedReport): void\n {\n // the scheduler handles all the other frequency types\n if ($automatedReport->getStatus() === false || $automatedReport->getFrequency() !== self::FREQUENCY_ONE_OFF) {\n return;\n }\n\n $this->dispatcher->dispatch(new RequestGenerateReportJob($automatedReport->getUuid()));\n }\n\n public function getReport(string $uuid): AutomatedReport\n {\n $automatedReport = $this->automatedReportsRepository->findByUuid($uuid);\n\n if (! $automatedReport) {\n throw new ModelNotFoundException('Report not found');\n }\n\n return $automatedReport;\n }\n\n public function get(string $uuid): array\n {\n $automatedReport = $this->getReport($uuid);\n\n return $this->transformReportFullView($automatedReport);\n }\n\n public function list(string $sortColumn = 'created_at', string $sortDirection = 'desc'): array\n {\n $results = [];\n $collection = $this->automatedReportsRepository->getAllStandardReports($sortColumn, $sortDirection);\n\n /** @var AutomatedReport $report */\n foreach ($collection as $report) {\n $results[] = $this->transformReportFullView($report);\n }\n\n return ['data' => $results];\n }\n\n public function listAskJiminnyReports(\n User $user,\n string $sortColumn = 'created_at',\n string $sortDirection = 'desc'\n ): array {\n $results = [];\n $collection = $this->automatedReportsRepository->getAskJiminnyReportsByUser($user, $sortColumn, $sortDirection);\n\n /** @var AutomatedReport $report */\n foreach ($collection as $report) {\n $results[] = $this->transformReportFullView($report);\n }\n\n return ['data' => $results];\n }\n\n public function delete(string $uuid): void\n {\n $automatedReport = $this->automatedReportsRepository->findByUuid($uuid);\n\n if (! $automatedReport) {\n throw new ModelNotFoundException('Report not found');\n }\n\n $automatedReport->delete();\n }\n\n public function createReportResult(AutomatedReport $automatedReport, array $data = []): AutomatedReportResult\n {\n return $this->automatedReportsRepository->createResult(\n array_merge(\n [\n 'report_id' => $automatedReport->getId(),\n 'status' => AutomatedReportResult::STATUS_DEFAULT,\n ],\n $data\n )\n );\n }\n\n public function getReportResult(string $resultUuid): AutomatedReportResult\n {\n $report = $this->automatedReportsRepository->findResultByUuid($resultUuid);\n\n if (! $report) {\n throw new ModelNotFoundException('Report Result not found');\n }\n\n return $report;\n }\n\n public function findChildResult(AutomatedReportResult $result, string $type): ?AutomatedReportResult\n {\n return $this->automatedReportsRepository->findChildResult($result, $type);\n }\n\n // prophet API calls\n /**\n * @throws ApplicationException\n */\n public function getGenerateReportPayload(AutomatedReport $automatedReport, string $reportResultUuid): array\n {\n $period = $this->calculateFromAndToDate($automatedReport);\n $fromDate = $period['fromDate'];\n $toDate = $period['toDate'];\n\n return [\n 'team_id' => $automatedReport->getTeamId(),\n 'request_id' => $reportResultUuid,\n 'report_type' => $automatedReport->getType(),\n 'media_types' => $automatedReport->getMediaTypes(),\n 'from_date' => $fromDate->startOfDay()->format(DateTimeInterface::RFC3339),\n 'to_date' => $toDate->endOfDay()->format(DateTimeInterface::RFC3339),\n 'group_ids' => $automatedReport->getGroups(),\n 'call_deal_stage' => $automatedReport->getDealAtCallStages(),\n 'current_deal_stage' => $automatedReport->getCurrentDealStages(),\n 'deal_min_value' => $automatedReport->getDealValueMin(),\n 'deal_max_value' => $automatedReport->getDealValueMax(),\n 'call_types' => $automatedReport->getCallTypes(),\n 'call_duration_min_seconds' => $automatedReport->getCallDurationMin(),\n 'call_duration_max_seconds' => $automatedReport->getCallDurationMax(),\n 'special_requirements' => $automatedReport->getAdditionalPromptInput(),\n 'callback_url' => $this->getCallbackUrl(),\n 'report_period' => $this->formatReportPeriodName(\n $automatedReport->getFrequency(),\n $fromDate,\n $toDate,\n ),\n 'playbook_categories' => $automatedReport->getPlaybookCategories(),\n 'custom_name' => $automatedReport->getCustomName(),\n ];\n }\n\n // $inputPayload - FE payload structure\n public function getActivitiesCountPayload(array $inputPayload): array\n {\n // Use validateAndTransformData to validate and normalize input\n $validatedData = $this->validateAndTransformData($inputPayload);\n $period = $this->calculateFromAndToDatePeriod(\n $validatedData['frequency'],\n Carbon::parse($validatedData['from']),\n Carbon::parse($validatedData['to']),\n );\n $fromDate = $period['fromDate'];\n $toDate = $period['toDate'];\n\n // Create payload similar to getGenerateReportPayload\n return [\n 'team_id' => $validatedData['team_id'],\n 'group_ids' => $validatedData['groups'] ?? [],\n 'report_type' => $validatedData['type'],\n 'from_date' => $fromDate->format(DateTimeInterface::RFC3339),\n 'to_date' => $toDate->format(DateTimeInterface::RFC3339),\n 'call_deal_stage' => $validatedData['deal_at_call_stages'] ?? [],\n 'current_deal_stage' => $validatedData['current_deal_stages'] ?? [],\n 'deal_min_value' => $validatedData['deal_value_min'] ?? null,\n 'deal_max_value' => $validatedData['deal_value_max'] ?? null,\n 'call_types' => $validatedData['call_types'],\n 'call_duration_min_seconds' => $validatedData['call_duration_min'] ?? null,\n 'call_duration_max_seconds' => $validatedData['call_duration_max'] ?? null,\n 'special_requirements' => $validatedData['additional_prompt_input'] ?? null,\n 'playbook_categories' => $validatedData['playbook_categories'] ?? [],\n 'request_id' => null,\n 'callback_url' => null,\n ];\n }\n\n public function shouldSendReport(array $users, ?CarbonInterface $generatedAt = null): bool\n {\n if (empty($users)) {\n return false;\n }\n\n $earliestTz = collect($users)\n ->mapWithKeys(function (array $user) {\n $tz = new DateTimeZone($user['timezone']);\n $nowUtc = new DateTime('now', new DateTimeZone('UTC'));\n $offset = $tz->getOffset($nowUtc);\n\n return [$user['timezone'] => $offset];\n })\n ->sortDesc()\n ->keys()\n ->first();\n\n $now = Carbon::now($earliestTz);\n $isScheduledTime = (int) $now->format('H') === self::SENT_REPORT_AT_HOURS;\n\n if ($isScheduledTime) {\n return true;\n }\n\n return $this->hasPassedScheduledTime($generatedAt, $earliestTz);\n }\n\n public function hasPassedScheduledTime(?CarbonInterface $generatedAt, string $timezone): bool\n {\n if ($generatedAt === null) {\n return false;\n }\n\n $now = Carbon::now($timezone);\n $scheduledTime = $now->copy()->setTime(self::SENT_REPORT_AT_HOURS, 0, 0);\n\n if ($now->hour < self::SENT_REPORT_AT_HOURS) {\n $scheduledTime = $scheduledTime->subDay();\n }\n\n $scheduledTimeUtc = $scheduledTime->copy()->utc();\n $generatedAtUtc = $generatedAt->copy()->utc();\n $nowUtc = $now->copy()->utc();\n\n return $generatedAtUtc->lt($scheduledTimeUtc) && $nowUtc->gt($scheduledTimeUtc);\n }\n\n public function calculateFromAndToDatePeriod(\n string $frequency,\n ?Carbon $fromDate = null,\n ?Carbon $toDate = null\n ): array {\n if ($frequency === self::FREQUENCY_ONE_OFF) {\n return [\n 'fromDate' => $fromDate,\n 'toDate' => $toDate,\n ];\n }\n\n $now = Carbon::now();\n\n return match ($frequency) {\n self::FREQUENCY_DAILY => [\n 'fromDate' => $now->copy()->subDay()->startOfDay(),\n 'toDate' => $now->copy()->subDay()->endOfDay(),\n ],\n self::FREQUENCY_WEEKLY => [\n 'fromDate' => $now->copy()->subWeeks(1)->startOfDay(),\n 'toDate' => $now->copy()->subDay()->endOfDay(),\n ],\n self::FREQUENCY_MONTHLY => [\n 'fromDate' => $now->copy()->subMonths(1)->startOfDay(),\n 'toDate' => $now->copy()->subDay()->endOfDay(),\n ],\n self::FREQUENCY_QUARTERLY => [\n 'fromDate' => $now->copy()->subMonths(3)->startOfDay(),\n 'toDate' => $now->copy()->subDay()->endOfDay(),\n ],\n default => throw new InvalidArgumentException(\"Unsupported frequency: {$frequency}\"),\n };\n }\n\n private function calculateFromAndToDate(AutomatedReport $automatedReport): array\n {\n return $this->calculateFromAndToDatePeriod(\n $automatedReport->getFrequency(),\n $automatedReport->getFrom(),\n $automatedReport->getTo()\n );\n }\n\n public function getAskJiminnyGenerateReportPayload(\n AutomatedReport $automatedReport,\n AutomatedReportResult $reportResult,\n array $activityIds,\n ): array {\n return [\n 'user_question' => $automatedReport->getAskAnythingPrompt()?->getContent(),\n 'call_ids' => array_map('strval', $activityIds),\n 'team_id' => $automatedReport->getTeamId(),\n 'request_id' => $reportResult->getUuid(),\n 'callback_url' => $this->getCallbackUrl(),\n 'report_period' => $this->getReportPeriodName($reportResult),\n 'report_name' => $automatedReport->getCustomName(),\n ];\n }\n\n private function getCallbackUrl(): string\n {\n return $this->webhookService->route('jiminny.webhook.reports.ready');\n }\n\n /**\n * Validate and transform payload data for automated reports\n *\n * @param array $data\n *\n * @throws InvalidArgumentException\n *\n * @return array\n */\n private function validateAndTransformData(array $data): array\n {\n // Validate organization (team) and check feature\n $team = $this->validateOrganization($data['organization'] ?? null);\n\n $status = $this->validateReportStatus($data['report_enabled'] ?? null);\n $type = $this->validateReportType($data['report_type'] ?? null);\n $frequency = $this->validateFrequency($data['frequency'] ?? null);\n $additionalPromptInput = $this->validateAdditionalPromptInput(\n $data['additional_prompt_input'] ?? null\n );\n $customReportName = $this->validateCustomReportName($data['custom_name'] ?? null);\n\n // Prepare data for the database\n $reportData = [\n 'team_id' => $team->getId(),\n 'type' => $type,\n 'status' => $status,\n 'frequency' => $frequency,\n 'additional_prompt_input' => $additionalPromptInput,\n 'custom_name' => $customReportName,\n ];\n\n // Validate deal values\n $reportData = $this->validateDealValues($data, $reportData);\n\n // Validate date range\n $reportData = $this->validateDateRange($data, $reportData, $frequency);\n\n // Validate call durations\n $reportData = $this->validateCallDurations($data, $reportData);\n\n // Validate call types\n $reportData = $this->validateCallTypes($data, $reportData);\n\n // Validate media types\n $reportData = $this->validateMediaTypes($data, $reportData);\n\n // Validate groups\n if (isset($data['teams'])) {\n $reportData['groups'] = $this->validateAndGetGroupIds($team, $data['teams']);\n }\n\n // Validate deal stages\n $reportData = $this->validateDealStages($data, $reportData, $team, $type);\n\n // Validate playbook categories\n $reportData = $this->validatePlaybookCategories($data, $reportData, $team);\n\n // Validate recipients\n $reportData['recipients'] = [\n 'users' => $this->validateAndGetUserIdsByTeam($team, $data['recipients'] ?? []),\n ];\n\n if (isset($data['jiminny_recipients'])) {\n // Validate Jiminny recipients\n $reportData['jiminny_recipients'] = [\n 'users' => $this->validateAndGetJiminnyUserIds((array) $data['jiminny_recipients']),\n ];\n }\n\n return $reportData;\n }\n\n private function validateDealValues(array $data, array $reportData): array\n {\n if (isset($data['min_deal_value'])) {\n $reportData['deal_value_min'] = (int) $data['min_deal_value'];\n\n if ($reportData['deal_value_min'] > 4294967295 || $reportData['deal_value_min'] < 0) {\n throw new InvalidArgumentException('Min deal value should be between 0 and 4294967295');\n }\n }\n\n if (isset($data['max_deal_value'])) {\n $reportData['deal_value_max'] = (int) $data['max_deal_value'];\n\n if ($reportData['deal_value_max'] > 4294967295 || $reportData['deal_value_max'] < 0) {\n throw new InvalidArgumentException('Max deal value should be between 0 and 4294967295');\n }\n }\n\n if (isset($data['min_deal_value'], $data['max_deal_value'])\n && $data['min_deal_value'] > $data['max_deal_value']\n ) {\n throw new InvalidArgumentException('Min deal value cannot be greater than max deal value');\n }\n\n return $reportData;\n }\n\n private function validateDateRange(array $data, array $reportData, string $frequency): array\n {\n // Set date range only for one_off frequency\n if ($frequency === 'one_off') {\n if (isset($data['start_date_period'])) {\n $reportData['from'] = $this->parseDate($data['start_date_period']);\n }\n\n if (isset($data['end_date_period'])) {\n $reportData['to'] = $this->parseDate($data['end_date_period']);\n }\n\n if (empty($reportData['from']) || empty($reportData['to'])) {\n throw new InvalidArgumentException(\n 'Start date and end date are required for one_off frequency'\n );\n }\n } else {\n $reportData['from'] = null;\n $reportData['to'] = null;\n }\n\n return $reportData;\n }\n\n private function validateCallDurations(array $data, array $reportData): array\n {\n // Convert call durations from minutes to seconds\n if (isset($data['min_call_duration'])) {\n $reportData['call_duration_min'] = (int) $data['min_call_duration'] * 60;\n\n if ($reportData['call_duration_min'] > 4294967295 || $reportData['call_duration_min'] < 0) {\n throw new InvalidArgumentException('Min call duration should be between 0 and 4294967295');\n }\n }\n\n if (isset($data['max_call_duration'])) {\n $reportData['call_duration_max'] = (int) $data['max_call_duration'] * 60;\n\n if ($reportData['call_duration_max'] > 4294967295 || $reportData['call_duration_max'] < 0) {\n throw new InvalidArgumentException('Max call duration should be between 0 and 4294967295');\n }\n }\n\n return $reportData;\n }\n\n private function validateCallTypes(array $data, array $reportData): array\n {\n // Set call types\n $reportData['call_types'] = $data['call_type'] ?? [];\n if (empty($reportData['call_types'])) {\n $reportData['call_types'] = self::getCallTypes();\n }\n\n foreach ($reportData['call_types'] as $callType) {\n if (! in_array($callType, self::getCallTypes(), true)) {\n throw new InvalidArgumentException(sprintf('Call type %s is invalid', $callType));\n }\n }\n\n return $reportData;\n }\n\n private function validateMediaTypes(array $data, array $reportData): array\n {\n // Set media types from input data\n $reportData['media_types'] = $data['media_types'] ?? [];\n\n if (empty($reportData['media_types'])) {\n throw new InvalidArgumentException('Media types are required');\n }\n\n foreach ($reportData['media_types'] as $mediaType) {\n if (! in_array($mediaType, self::MEDIA_TYPES, true)) {\n throw new InvalidArgumentException(sprintf('Media type %s is invalid', $mediaType));\n }\n }\n\n return $reportData;\n }\n\n private function validateDealStages(array $data, array $reportData, Team $team, string $reportType): array\n {\n // Validate and set deal stages\n if (isset($data['deal_stage_at_call'])) {\n $reportData['deal_at_call_stages'] =\n $this->validateAndGetDealStageIds($team, $data['deal_stage_at_call'], 'Deal stage at call');\n }\n\n if (isset($data['current_deal_stage'])) {\n $reportData['current_deal_stages'] =\n $this->validateAndGetDealStageIds($team, $data['current_deal_stage'], 'Current deal stage');\n }\n\n // Ensure current_deal_stage is not provided for loss_analysis report type\n if ($reportType === self::TYPE_LOSS_ANALYSIS && ! empty($data['current_deal_stage'])) {\n throw new InvalidArgumentException('Current deal stage is not applicable for Loss Analysis reports');\n }\n\n return $reportData;\n }\n\n // transform uuid to id\n private function validatePlaybookCategories(array $data, array $reportData, Team $team): array\n {\n $key = 'playbook_categories';\n\n if (isset($data[$key])) {\n $payloadIds = $data[$key];\n $ids = [];\n\n foreach ($payloadIds as $uuid) {\n $uuid = (string) $uuid;\n\n try {\n $playbookCategory = $this->playbookCategoryRepository->findByUuid($uuid);\n } catch (Throwable $throwable) {\n Log::error(__METHOD__ . ' ' . $throwable->getMessage());\n\n throw new InvalidArgumentException(sprintf('Playbook category %s not found', $uuid));\n }\n\n if (! $playbookCategory) {\n throw new InvalidArgumentException(sprintf('Playbook category %s not found', $uuid));\n }\n\n if (! $playbookCategory->hasPlaybook()) {\n throw new InvalidArgumentException(sprintf('Playbook category %s has no playbook', $uuid));\n }\n\n if ($playbookCategory->getPlaybook()->getTeamId() !== $team->getId()) {\n throw new InvalidArgumentException(\n sprintf('Playbook category %s not found for team %s', $uuid, $team->getUuid())\n );\n }\n\n $ids[] = $playbookCategory->getId();\n }\n\n $reportData[$key] = $ids;\n }\n\n return $reportData;\n }\n\n private function validateReportStatus($status): bool\n {\n if (! in_array($status, [true, false], true)) {\n throw new InvalidArgumentException('Report status is invalid');\n }\n\n return $status;\n }\n\n private function validateReportType($type): string\n {\n if (! in_array($type, self::getTypes(), true)) {\n throw new InvalidArgumentException(sprintf('Report type is invalid: %s', $type));\n }\n\n return $type;\n }\n\n private function validateFrequency($frequency): string\n {\n if (! in_array($frequency, self::getFrequencies(), true)) {\n throw new InvalidArgumentException('Frequency is invalid');\n }\n\n return $frequency;\n }\n\n private function validateAdditionalPromptInput(?string $additionalPromptInput): ?string\n {\n if ($additionalPromptInput && strlen($additionalPromptInput) > 5000) {\n throw new InvalidArgumentException('Additional Prompt Input should be less than 5000 characters');\n }\n\n return $additionalPromptInput;\n }\n\n private function validateCustomReportName(?string $customReportName): ?string\n {\n if ($customReportName === null || $customReportName === '') {\n return null;\n }\n\n if (strlen($customReportName) > 70) {\n throw new InvalidArgumentException('Custom report name should be less than 70 characters');\n }\n\n return $customReportName;\n }\n\n private function validateOrganization(?string $organizationUuid): Team\n {\n if (! $organizationUuid) {\n throw new InvalidArgumentException('Organization is required');\n }\n\n $team = $this->teamRepository->idOrUuid($organizationUuid);\n\n if (! $team) {\n throw new InvalidArgumentException('Organization not found');\n }\n\n if (! $team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {\n throw new InvalidArgumentException('Organization does not have the Automated Reports feature');\n }\n\n return $team;\n }\n\n private function validateAndGetGroupIds(Team $team, array $teamUuids): array\n {\n $groupIds = [];\n\n foreach ($teamUuids as $uuid) {\n $group = $this->groupRepository->findByUuid($uuid);\n\n if ($group === null || $group->getTeamId() !== $team->getId()) {\n throw new InvalidArgumentException(\n sprintf('Group %s not found for team %s', $uuid, $team->getUuid())\n );\n }\n\n $groupIds[] = $group->getId();\n\n }\n\n return $groupIds;\n }\n\n private function validateAndGetDealStageIds(Team $team, array $stageUuids, string $propertyLabel): array\n {\n $stageIds = [];\n\n foreach ($stageUuids as $uuid) {\n $stage = $this->stageRepository->findByUuid($uuid);\n\n if ($stage === null || $stage->getTeamId() !== $team->getId()) {\n throw new InvalidArgumentException(\n sprintf('Stage %s not found for team %s for %s', $uuid, $team->getUuid(), $propertyLabel)\n );\n }\n\n $stageIds[] = $stage->getId();\n }\n\n return $stageIds;\n }\n\n private function validateAndGetUserIds(array $userUuids, callable $teamCheck): array\n {\n if (empty($userUuids)) {\n return [];\n }\n\n $userIds = [];\n\n foreach ($userUuids as $uuid) {\n $user = $this->userRepository->findByUuid($uuid);\n\n if (! $user || ! $user->isStatusActive()) {\n throw new InvalidArgumentException(\n sprintf('User %s not found or is not active', $uuid)\n );\n }\n\n if (! $teamCheck($user)) {\n throw new InvalidArgumentException(\n sprintf('User %s does not belong to the allowed team(s)', $uuid)\n );\n }\n\n $userIds[] = $user->getId();\n }\n\n return $userIds;\n }\n\n private function validateAndGetUserIdsByTeam(Team $team, array $userUuids): array\n {\n return $this->validateAndGetUserIds($userUuids, fn ($user) => $user->getTeamId() === $team->getId());\n }\n\n private function validateAndGetJiminnyUserIds(array $userUuids): array\n {\n $allowedTeamIds = config('kiosk.teamIds', []);\n\n return $this->validateAndGetUserIds($userUuids, fn ($user) => in_array($user->getTeamId(), $allowedTeamIds, true));\n }\n\n private function parseDate(string $dateString): string\n {\n return date('Y-m-d H:i:s', strtotime($dateString));\n }\n\n private function generateReportResultViewUrl(AutomatedReportResult $result): string\n {\n $mediaResource = $this->getReportMediaRouteResource($result);\n\n return route('ai-reports.' . $mediaResource . '.view', ['uuid' => $result->getUuid()]);\n }\n\n private function generateReportResultDownloadUrl(AutomatedReportResult $result): string\n {\n $mediaResource = $this->getReportMediaRouteResource($result);\n\n return route('ai-reports.' . $mediaResource . '.download', ['uuid' => $result->getUuid()]);\n }\n\n private function getReportMediaRouteResource(AutomatedReportResult $result): string\n {\n if ($result->getMediaType() === self::MEDIA_TYPE_PDF) {\n return self::PDF_KEY;\n } elseif ($result->getMediaType() === self::MEDIA_TYPE_PODCAST) {\n return self::AUDIO_KEY;\n }\n\n throw new \\InvalidArgumentException('Unknown media type.');\n }\n\n public function getMediaPath(AutomatedReportResult $result): ?string\n {\n $url = match ($result->getMediaType()) {\n self::MEDIA_TYPE_PDF => $result->getPdfUrl(),\n self::MEDIA_TYPE_PODCAST => $result->getPodcastAudioUrl(),\n default => null,\n };\n\n if ($url === null) {\n return null;\n }\n\n $path = parse_url(trim($url, '\"\\''), PHP_URL_PATH);\n\n return $path ?: null;\n }\n\n public function getFilenameSuffix(AutomatedReportResult $result): ?string\n {\n return match ($result->getMediaType()) {\n self::MEDIA_TYPE_PODCAST => 'Podcast',\n default => null,\n };\n }\n\n public function getMailSubjectSuffix(AutomatedReportResult $result): string\n {\n return match ($result->getMediaType()) {\n self::MEDIA_TYPE_PDF => 'report',\n self::MEDIA_TYPE_PODCAST => 'podcast',\n default => '',\n };\n }\n\n public function getMediaTypeMetadata(AutomatedReportResult $result): array\n {\n return match ($result->getMediaType()) {\n self::MEDIA_TYPE_PODCAST => ['extension' => 'mp3', 'mime' => 'audio/mpeg'],\n self::MEDIA_TYPE_PDF => ['extension' => 'pdf', 'mime' => 'application/pdf'],\n default => ['extension' => null, 'mime' => null],\n };\n }\n\n public function deleteS3Files(AutomatedReportResult $result): void\n {\n $teamUuid = $result->getReport()->getTeam()->getUuid();\n $reportUuid = $result->getUuid();\n\n // delete all files for a report uuid no mather of pdf, podcast, or both\n // in case of both - the podcast files are linked to the pdf (parent) uuid\n // pdf and podcast date times should be close\n $path = sprintf('%s/%s/%s', $teamUuid, self::S3_DIR, $reportUuid);\n\n foreach (self::FILE_EXTENSIONS_VARIANTS as $extension) {\n $file = $path . '.' . $extension;\n\n if (Storage::exists($file)) {\n Storage::delete($file);\n Log::info('[Reports] Deleted S3 file', [\n 'path' => $file,\n ]);\n }\n }\n\n foreach (self::FILE_PODCAST_EXTENSIONS_VARIANTS as $extension) {\n $file = $path . '_podcast.' . $extension;\n\n if (Storage::exists($file)) {\n Storage::delete($file);\n Log::info('[Reports] Deleted Podcast S3 file', [\n 'path' => $file,\n ]);\n }\n }\n }\n\n /**\n *\n * @param int|null $teamId Optional team ID to filter results\n *\n * @return Collection<int, int> Collection of team IDs\n */\n public function getTeamIdsWithReportsResults(?int $teamId = null): Collection\n {\n return $this->automatedReportsRepository->getTeamIdsWithReportsResults($teamId);\n }\n\n /**\n * Core delete logic for report results using a query\n *\n * @param Builder $query\n * @param array $logContext\n *\n * @return int\n */\n private function deleteReportResultsByQuery(Builder $query, array $logContext = []): int\n {\n $deletedCount = 0;\n\n if ($query->exists()) {\n Log::info(\n 'Run delete report results',\n array_merge(\n $logContext,\n [\n 'service' => 'AutomatedReportsService',\n ]\n )\n );\n\n $query->chunkById(50, function ($results) use (&$deletedCount, $logContext) {\n foreach ($results as $result) {\n $this->deleteReportResult($result);\n $deletedCount++;\n\n Log::info(\n 'Deleted a report result',\n array_merge(\n $logContext,\n [\n 'result_id' => $result->getId(),\n 'report_id' => $result->getReportId(),\n ]\n )\n );\n }\n });\n }\n\n return $deletedCount;\n }\n\n /**\n * Delete report results for a team by retention period\n *\n * @param Team $team\n * @param CarbonImmutable $retentionDate\n *\n * @return int Number of deleted report results\n */\n public function deleteReportsResultsInRetentionPeriod(Team $team, CarbonImmutable $retentionDate): int\n {\n $reportIds = $this->automatedReportsRepository->getReportIdsByTeam($team);\n\n if ($reportIds->isEmpty()) {\n return 0;\n }\n\n $query = $this->automatedReportsRepository\n ->getReportResultsQueryForRetention($team, $retentionDate);\n\n return $this->deleteReportResultsByQuery($query, [\n 'team_id' => $team->getId(),\n 'retention_date' => $retentionDate->toDateTimeString(),\n ]);\n }\n\n /**\n * Delete ALL report results for a specific automated report\n *\n * @param string $uuid\n *\n * @return int\n */\n public function deleteReportResults(string $uuid): int\n {\n $report = $this->getReport($uuid);\n\n $query = $this->automatedReportsRepository->getResultsByReportQuery($report);\n\n return $this->deleteReportResultsByQuery($query, [\n 'report_uuid' => $uuid,\n 'report_id' => $report->getId(),\n ]);\n }\n\n public function deleteReportResult(AutomatedReportResult $result): void\n {\n $this->deleteS3Files($result);\n\n $result->delete();\n }\n\n /**\n * Get all reports for a specific team\n *\n * @param Team $team\n *\n * @return \\Illuminate\\Database\\Eloquent\\Collection\n */\n public function getTeamReports(Team $team): \\Illuminate\\Database\\Eloquent\\Collection\n {\n return $this->automatedReportsRepository->getReportsByTeam($team);\n }\n\n /**\n * Get all report results for a specific report\n *\n * @param AutomatedReport $report\n *\n * @return \\Illuminate\\Database\\Eloquent\\Collection\n */\n public function getReportResults(AutomatedReport $report): \\Illuminate\\Database\\Eloquent\\Collection\n {\n return $this->automatedReportsRepository->getResultsByReport($report);\n }\n\n public function deleteAllReportResults(AutomatedReport $report): void\n {\n $results = $this->getReportResults($report);\n\n /** @var AutomatedReportResult $result */\n foreach ($results as $result) {\n Log::info('Deleting result', [\n 'report' => $report->getId(),\n 'result' => $result->getId(),\n ]);\n\n $this->deleteReportResult($result);\n }\n }\n\n public function deleteAllData(Team $team): void\n {\n Log::info('Deleting automated report and results for team', [\n 'team' => $team->getId(),\n ]);\n\n $reports = $this->getTeamReports($team);\n\n /** @var AutomatedReport $report */\n foreach ($reports as $report) {\n Log::info('Deleting report', [\n 'team' => $team->getId(),\n 'report' => $report->getId(),\n ]);\n\n $this->deleteAllReportResults($report);\n\n $report->delete();\n }\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":true,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"Project","depth":3,"role_description":"text"},{"role":"AXButton","text":"Project","depth":3,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"New File or Directory…","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Expand Selected","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Collapse All","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Options","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false}]...
|
3397592283435315795
|
6686367547760219213
|
idle
|
accessibility
|
NULL
|
Project: faVsco.js, menu
#11894 on JY-18909-automa Project: faVsco.js, menu
#11894 on JY-18909-automated-reports-ask-jiminny, menu
Start Listening for PHP Debug Connections
AutomatedReportsCommandTest
Run 'AutomatedReportsCommandTest'
Debug 'AutomatedReportsCommandTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Execute
Explain Plan
Browse Query History
View Parameters
Open Query Execution Settings…
In-Editor Results
Tx: Auto
Cancel Running Statements
Playground
jiminny
Sync Changes
Hide This Notification
Code changed:
Hide
16
13
13
Previous Highlighted Error
Next Highlighted Error
SELECT * FROM teams WHERE id = 1;
select * from crm_layouts where crm_configuration_id = 39;
SELECT * FROM crm_layout_entities WHERE crm_layout_id = 283;
SELECT * FROM crm_fields WHERE id = 2234;
SELECT * FROM crm_field_values WHERE crm_field_id = 2234;
select * from crm_profiles where user_id = 143;
select * from record_types where crm_configuration_id = 39; # 0121K000001MHElQAO,0121K000001MHEqQAO
select * from business_processes where crm_configuration_id = 39;
# 01941000000H669AAC, 01941000000H66JAAS
select * from record_type_field_values
where record_type_id IN (24);
select * from crm_field_values where id IN (2730);
select * from crm_configurations where id = 39;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 1
and sa.provider = 'salesforce'; #1035
select * from users where team_id = 1; # 222 group 3
SELECT * FROM activities WHERE user_id = 222 order by id desc;
select * from sidekick_settings where team_id = 1;
select * from teams where id = 1;
select * from team_features where team_id = 1;
select * from activities where crm_configuration_id = 2
and provider = 'ms-teams' and id = 608765;
SELECT * FROM activities WHERE crm_configuration_id = 2 and crm_provider_id = '59523413338';
select * from sidekick_settings where team_id = 2;
SELECT * FROM activities WHERE id = 608660;
select * from activity_summary_logs where activity_id = 608660;
select * from ai_prompts where transcription_id = 11214;
# [PASSWORD_DOTS]
SELECT * FROM activities WHERE uuid_to_bin('ed78a437-2804-450e-ab2f-56ab1c641346') = uuid;
# id: 608818, crm: 59628809737
SELECT * FROM activities WHERE uuid_to_bin('36b06e55-afdd-4782-8dee-c624cd0af191') = uuid;
# id: 608821, crm: 59632069252
SELECT ce.start_time, ce.end_time, a.id, a.uuid, crm_provider_id, calendar_event_id, title,
playbook_category_id, user_id, lead_id, contact_id, account_id, opportunity_id,
scheduled_start_time, scheduled_end_time, actual_start_time, actual_end_time, a.created_at
FROM activities a
join calendar_events ce on a.calendar_event_id = ce.id
WHERE a.id IN (608818, 608821);
select * from users where team_id = 1;
select * from team_settings where team_id = 1;
select * from crm_profiles where crm_configuration_id = 39 order by user_id;
select * from team_features where team_id = 1;
select * from users where team_id = 2;
SELECT * FROM activities WHERE uuid_to_bin('ec7647e9-5225-458b-b475-f31aa2769204') = uuid; # 612639
# Preslava N. Ivanova, grou id 3
SELECT * FROM opportunities WHERE uuid_to_bin('a2928fe5-aec5-46cb-85d9-7654c89e46a6') = uuid;
select * from activities where opportunity_id = 344 and actual_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00';
select
a.id,
a.type,
a.scheduled_start_time,
a.actual_start_time,
a.created_at,
a.opportunity_id,
a.status
FROM activities a
WHERE opportunity_id = 344
and status IN ('completed', 'received', 'delivered')
and (
(a.actual_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00')
OR (a.created_at between '2024-10-11 00:00:00' and '2024-10-12 00:00:00')
OR (a.scheduled_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00'))
;
SELECT * FROM users WHERE id = 222;
SELECT * FROM crm_profiles WHERE user_id = 222;
select * from crm_layouts where crm_configuration_id = 39;
SELECT * FROM crm_layout_entities WHERE crm_layout_id = 281;
select * from group_deal_risk_types;
select * from opportunities where team_id = 1;
SELECT * FROM opportunities WHERE id = 315;
SELECT * FROM crm_field_data WHERE object_id = 315;
select * from crm_field_data where object_id = 260;
select * from generic_ai_prompts where subject_id = 315;
select * from teams; # 36, 21, 121, [EMAIL]
SELECT * FROM social_accounts WHERE sociable_id = 121 and provider = 'bullhorn';
# [PASSWORD_DOTS]
select * from teams where id = 1;
select * from crm_configurations where id = 39;
select * from users where team_id = 1;
select u.email, cp.* from users u
join crm_profiles cp on u.id = cp.user_id
where u.team_id = 1;
# 1 - 00541000004281rAAA
# 204 - 0052g000003freeAAA
# 429 - 0052g000003qGOiAAM
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 1
and sa.provider = 'salesforce';
select * from activities where type = 'softphone'
and created_at > '2024-12-11 15:24:36' order by id desc;
select * from activity_providers where team_id = 1;
select * from activity_provider_users where activity_provider_id = 328;
select * from opportunities where crm_configuration_id = 39
AND account_id = 178 AND is_closed = false
order by created_at DESC;
select * from contacts where id = 3952;
select * from accounts where id = 178;
# [PASSWORD_DOTS]
select * from teams where id = 36;
select * from crm_configurations where id = 21;
select * from users where team_id = 36;
select u.email, cp.* from users u
join crm_profiles cp on u.id = cp.user_id
where u.team_id = 36;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 36
and sa.provider = 'bullhorn';
select * from social_accounts where id = 348;
UPDATE social_accounts SET
provider_user_token = '21442_6802599_91:41179a58-21e7-4d7c-ad58-56bb666b2f65',
provider_refresh_token = '21442_6802599_91:01c6b335-3f2a-42e4-85ff-8a08fa65fceb',
expires = 1733998131,
state = 'connected'
WHERE id = 348;
# [PASSWORD_DOTS]
select * from teams where id = 31;
select * from crm_configurations where id = 18;
select * from users where team_id = 31; # 257
select u.email, cp.* from users u
join crm_profiles cp on u.id = cp.user_id
where u.team_id = 31;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 31
and sa.provider = 'close';
select * from contacts where crm_configuration_id = 18;
# [PASSWORD_DOTS] NEPTUNE [PASSWORD_DOTS]
select * from teams;
select * from users where id IN (1030, 1035, 1052);
select * from crm_configurations;
select * from users where team_id = 65; # 257
select * from team_settings where team_id = 65; # 257
select * from invitations where team_id = 65; # 257
select * from users where email = '[EMAIL]'; # 257
select u.email, cp.* from users u
join crm_profiles cp on u.id = cp.user_id
where u.team_id = 65;
select * from crm_configurations where id = 53;
select * from accounts where crm_configuration_id = 53 order by id desc;
select * from leads where crm_configuration_id = 53 order by id desc;
select * from contacts where crm_configuration_id = 53 order by id desc;
select * from opportunities where crm_configuration_id = 53 order by id desc;
select * from crm_profiles where crm_configuration_id = 53 order by id desc;
select * from crm_fields where crm_configuration_id = 53 order by id desc;
select * from crm_field_values where crm_field_id = 3341 order by id desc;
select * from crm_layouts where crm_configuration_id = 53 order by id desc;
select * from stages where crm_configuration_id = 53 order by id desc;
select * from crm_profiles where crm_configuration_id = 13;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 65
and sa.provider = 'integration-app';
select * from contacts where crm_configuration_id = 13;
select * from social_accounts where sociable_id = 283;
SELECT * FROM opportunities WHERE crm_provider_id = '006O400000E9bzeIAB';
select * from activity_providers where team_id = 65;
SELECT * FROM activities WHERE crm_configuration_id IN (51, 52, 53);
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 65
;
# [PASSWORD_DOTS] STAGING [PASSWORD_DOTS]
SELECT * FROM teams;
SELECT * FROM teams WHERE id = 88;
SELECT * FROM teams WHERE id = 89;
select * from team_settings where team_id = 89;
SELECT * FROM users WHERE team_id = 89;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 89;
select * from users;
SELECT * FROM social_accounts WHERE sociable_id = 1761;
SELECT * FROM crm_configurations WHERE id = 70;
select * from accounts where crm_configuration_id = 70 order by id desc;
select * from leads where crm_configuration_id = 70 order by id desc;
select * from contacts where crm_configuration_id = 70 order by id desc;
select * from opportunities where crm_configuration_id = 70 order by id desc;
select * from crm_profiles where crm_configuration_id = 70 order by id desc;
select * from crm_fields where crm_configuration_id = 70 order by id desc;
select * from crm_field_values where crm_field_id = 3536 order by id desc;
select * from crm_layouts where crm_configuration_id = 70 order by id desc;
select * from stages where crm_configuration_id = 70 order by id desc;
select * from business_processes where crm_configuration_id = 70 order by id desc;
select * from business_process_stages where business_process_id = 34;
select * from contacts where id = 10468;
select * from crm_layouts where crm_configuration_id = 70;
SELECT * FROM crm_layout_entities WHERE crm_layout_id = 388;
SELECT * FROM crm_fields WHERE id IN (3533,3534,3535);
select * from activities where crm_configuration_id = 70
and (account_id IS NOT NULL or lead_id IS NOT NULL or contact_id IS NOT NULL or opportunity_id IS NOT NULL) order by id desc;
SELECT * FROM activities WHERE uuid_to_bin('2e10b60f-8a61-41c5-a3d4-28835353dc65') = uuid;
SELECT * FROM activities where crm_configuration_id = 69 ;
SELECT * FROM users WHERE email LIKE '%[EMAIL]%';
SELECT * FROM activities WHERE uuid_to_bin('5a150c93-40fc-42ec-b3bd-c1d328e09f6e') = uuid;
SELECT * FROM opportunities WHERE id = 385;
select * from participants p
join activities a on p.activity_id = a.id
where a.crm_configuration_id = 70
and (p.lead_id IS NOT NULL or p.contact_id IS NOT NULL);
SELECT * FROM participants WHERE id = 1013638;
select * from teams where id = 90;
select * from users where team_id = 90;
select * from social_accounts where social_accounts.sociable_id IN (1960,1760);
SELECT * FROM crm_profiles WHERE crm_configuration_id = 71;
select * from invitations where team_id = 90;
select * from crm_configurations where id = 71;
select * from accounts where crm_configuration_id = 71 order by id desc;
select * from leads where crm_configuration_id = 71 order by id desc;
select * from contacts where crm_configuration_id = 71 order by id desc;
select * from opportunities where crm_configuration_id = 71 order by id desc;
select * from crm_profiles where crm_configuration_id = 71 order by id desc;
select * from crm_fields where crm_configuration_id = 71 order by id desc;
select * from crm_field_values where crm_field_id = 3341 order by id desc;
select * from crm_layouts where crm_configuration_id = 71 order by id desc;
select * from stages where crm_configuration_id = 71 order by id desc;
select * from users order by secondary_email desc;
select u.id, u.email, u.status, sa.id, sa.provider_user_id from social_accounts sa
join users u on sa.sociable_id = u.id
where sa.provider = 'google' and u.email LIKE 'aneliya%';
select * from failed_jobs order by id desc;
select * from users where email = '[EMAIL]' or secondary_email = '[EMAIL]';
select * from teams;
SELECT * FROM crm_profiles WHERE crm_configuration_id = 39;
SELECT * FROM crm_fields WHERE crm_configuration_id = 39 and object_type = 'task';
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 1
and sa.provider = 'salesforce';
# [PASSWORD_DOTS]
SELECT * FROM activities WHERE uuid_to_bin('c38b3895-fd0f-4b1f-9fb2-c170dba137c6') = uuid;
SELECT * FROM crm_configurations WHERE id = 70;
select * from teams where id = 1;
select * from groups where team_id = 1;
select * from users where team_id = 1;
select o.id, o.name,o.close_date, u.id, u.name, u.group_id, r.id, r.display_name, g.name, g.scope from opportunities o
join users u on o.user_id = u.id
join groups g on u.group_id = g.id
join role_user ru on u.id = ru.user_id
join roles r on ru.role_id = r.id
where o.crm_configuration_id = 39 and close_date > '2024-01-01 00:00:00';
select * from role_user where user_id = 143;
select * from roles;
select * from role_user;
select * from groups where id = 9;
select * from scope_groups where group_id = 9;
# [PASSWORD_DOTS]
select * from teams where id = 36;
select * from crm_configurations;
SELECT * FROM social_accounts WHERE sociable_id = 121;
[URL_WITH_CREDENTIALS] this will add filter, however if we need to control feature by FF we need conditional logic
public const array TYPES = [
['id' => 'exec_summary', 'name' => 'Exec Summary'],
['id' => 'coaching_profiles', 'name' => 'Coaching Profiles'],
['id' => 'product_feedback', 'name' => 'Product Feedback'],
['id' => self::TYPE_LOSS_ANALYSIS, 'name' => 'Loss Analysis'],
// ['id' => 'questions', 'name' => 'Questions'],
// ['id' => 'statistical_quant', 'name' => 'Statistical Quantitative'],
];
public const array ALL_TYPES = [
...self::TYPES,
['id' => self::TYPE_ASK_JIMINNY, 'name' => 'Ask Jiminny'],
];
public const string FREQUENCY_DAILY = 'daily';
public const string FREQUENCY_WEEKLY = 'weekly';
public const string FREQUENCY_MONTHLY = 'monthly';
public const string FREQUENCY_QUARTERLY = 'quarterly';
public const string FREQUENCY_ONE_OFF = 'one_off';
/**
* Frequencies for standard (non-Ask Jiminny) reports.
*/
public const array FREQUENCIES = [
['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],
['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],
['id' => self::FREQUENCY_QUARTERLY, 'name' => 'Quarterly'],
['id' => self::FREQUENCY_ONE_OFF, 'name' => 'One-off'],
];
/**
* Frequencies for Ask Jiminny reports.
*/
public const array ASK_JIMINNY_FREQUENCIES = [
['id' => self::FREQUENCY_DAILY, 'name' => 'Daily'],
['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],
['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],
];
public const string MEDIA_TYPE_PDF = 'pdf';
public const string MEDIA_TYPE_PODCAST = 'podcast';
public const array MEDIA_TYPES = [self::MEDIA_TYPE_PDF, self::MEDIA_TYPE_PODCAST];
public const array MEDIA_TYPE_OBJECT_PDF = ['id' => self::MEDIA_TYPE_PDF, 'name' => 'PDF'];
public const array MEDIA_TYPE_OBJECT_PODCAST = ['id' => self::MEDIA_TYPE_PODCAST, 'name' => 'Podcast'];
public const array MEDIA_TYPE_OBJECTS = [self::MEDIA_TYPE_OBJECT_PDF, self::MEDIA_TYPE_OBJECT_PODCAST];
public const array CALL_TYPE_CONFERENCE = ['id' => 'conference', 'name' => 'Conference'];
public const array CALL_TYPE_DIALER = ['id' => 'dialer', 'name' => 'Dialer'];
public const int SENT_REPORT_AT_HOURS = 5;
public const string PDF_KEY = 'pdf';
public const string AUDIO_KEY = 'audio';
private const array ALL_FREQUENCIES = [
['id' => self::FREQUENCY_DAILY, 'name' => 'Daily'],
['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],
['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],
['id' => self::FREQUENCY_QUARTERLY, 'name' => 'Quarterly'],
['id' => self::FREQUENCY_ONE_OFF, 'name' => 'One-off'],
];
private const string S3_DIR = 'reports';
private const array FILE_EXTENSIONS_VARIANTS = ['html', 'MD', 'pdf'];
private const array FILE_PODCAST_EXTENSIONS_VARIANTS = ['json', 'mp3', 'ssml'];
public function __construct(
private readonly TeamRepository $teamRepository,
private readonly GroupRepository $groupRepository,
private readonly UserRepository $userRepository,
private readonly StageRepository $stageRepository,
private readonly DealStagesService $dealStagesService,
private readonly RecipientsService $recipientsService,
private readonly AutomatedReportsRepository $automatedReportsRepository,
private readonly Webhook $webhookService,
private readonly BusDispatcher $dispatcher,
private readonly ActivityTypeService $activityTypeService,
private readonly PlaybookCategoryRepository $playbookCategoryRepository,
private readonly AskAnythingPromptService $askAnythingPromptService,
private readonly SearchRepository $activitySearchRepository,
private readonly AskAnythingRepository $askAnythingRepository,
) {
}
public static function getTypes(): array
{
$types = self::TYPES;
return array_map(static function ($type) {
return $type['id'];
}, $types);
}
public static function getCallTypes(): array
{
return array_map(static function ($callType) {
return $callType['id'];
}, [self::CALL_TYPE_CONFERENCE, self::CALL_TYPE_DIALER]);
}
public static function getFrequencies(): array
{
return array_map(static function ($frequency) {
return $frequency['id'];
}, self::FREQUENCIES);
}
// front-facing structure
public function getReportEnabledFieldData(bool $value = false): array
{
return [
'id' => 'report_enabled',
'label' => '',
'inputType' => InputTypeEnum::TOGGLE,
'value' => $value,
];
}
// Organizations = Teams
public function getOrganizationFieldData(?string $value = null, bool $shortVersion = false): array
{
$options = $this->getTeams();
if ($shortVersion) {
return [
'id' => 'organization',
'label' => 'Organization',
'options' => $options,
];
}
return [
'id' => 'organization',
'label' => 'Organization',
'inputType' => InputTypeEnum::DROPDOWN,
'required' => true,
'placeholder' => 'Select',
'options' => $options,
'value' => $value,
'dependencies' => [
'teams',
'deal_stage_at_call',
'current_deal_stage',
'recipients',
ActivityTypeService::PLAYBOOK_CATEGORIES_KEY,
],
'dependsOn' => [],
];
}
// Teams = Groups
public function getTeamFieldData(array $options = [], array $value = [], bool $shortVersion = false): array
{
if ($shortVersion) {
return [
'id' => 'teams',
'label' => 'Team',
'options' => $options,
];
}
return [
'id' => 'teams',
'label' => 'Team',
'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,
'required' => false,
'placeholder' => 'Select',
'options' => $options,
'value' => $value, // value should be an array of objects {id, name}
'dependencies' => [ActivityTypeService::PLAYBOOK_CATEGORIES_KEY],
'dependsOn' => [],
];
}
public function getReportTypeFieldData(?string $value = null, bool $shortVersion = false, ?Team $team = null): array
{
$types = [];
if ($team instanceof Team) {
if ($team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {
$types = self::TYPES;
}
if ($team->hasFeature(FeatureEnum::ASK_JIMINNY_REPORTS)) {
$types[] = ['id' => self::TYPE_ASK_JIMINNY, 'name' => 'Ask Jiminny'];
}
} else {
$types = self::TYPES;
}
if ($shortVersion) {
return [
'id' => 'report_type',
'label' => 'Report Type',
'options' => $types,
];
}
return [
'id' => 'report_type',
'label' => 'Report Type',
'inputType' => InputTypeEnum::DROPDOWN,
'required' => true,
'placeholder' => 'Select',
'options' => $types,
'value' => $value,
'dependencies' => [],
'dependsOn' => [],
];
}
public function getFrequencyFieldData(?string $value = null): array
{
return [
'id' => 'frequency',
'label' => 'Frequency',
'inputType' => InputTypeEnum::DROPDOWN,
'required' => true,
'placeholder' => 'Select',
'options' => self::FREQUENCIES,
'value' => $value,
'dependencies' => ['period'],
'dependsOn' => [],
];
}
public function getPeriodFieldData(?string $valueStartDate = null, ?string $valueEndDate = null): array
{
return [
'id' => 'period',
'label' => 'Select one-off period',
'inputType' => InputTypeEnum::DATE_RANGE,
'required' => true,
'placeholder' => 'Select',
'value' => ['startDate' => $valueStartDate, 'endDate' => $valueEndDate],
'queryParams' => [
'startDate' => 'start_date_period',
'endDate' => 'end_date_period',
],
'dependencies' => [],
'dependsOn' => ['frequency'],
];
}
public function getActivityTypesFieldData(?Team $team = null, array $value = [], array $teamsFilter = []): array
{
return $this->activityTypeService->getActivityTypeFieldData(team: $team, value: $value, groupIds: $teamsFilter);
}
public function getDealStageAtCallFieldData(?Team $team = null, array $value = []): array
{
return $this->dealStagesService->getDealStageAtCallFieldData(team: $team, value: $value);
}
public function getCurrentDealStageFieldData(?Team $team = null, array $value = []): array
{
return $this->dealStagesService->getCurrentDealStageFieldData(team: $team, value: $value);
}
public function getDealValueFieldData(?int $valueMin = null, ?int $valueMax = null): array
{
return [
'id' => 'deal_value',
'label' => 'Deal Value',
'inputType' => InputTypeEnum::INTEGER_RANGE,
'required' => false,
'value' => ['min' => $valueMin, 'max' => $valueMax],
'queryParams' => [
'min' => 'min_deal_value',
'max' => 'max_deal_value',
],
'dependencies' => [],
'dependsOn' => [],
];
}
public function getCallTypeFieldData(bool $conferenceOn = false, bool $dialerOn = false): array
{
$value = [];
$conferenceOn && $value[] = self::CALL_TYPE_CONFERENCE;
$dialerOn && $value[] = self::CALL_TYPE_DIALER;
return [
'id' => 'call_type',
'label' => 'Call Type',
'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,
'required' => true,
'options' => [
self::CALL_TYPE_CONFERENCE,
self::CALL_TYPE_DIALER,
],
'value' => $value,
'dependencies' => [],
'dependsOn' => [],
];
}
public function getMediaTypeFieldData(?AutomatedReport $report = null): array
{
$value = [];
if ($report) {
$value = $this->transformMediaTypes($report);
}
return [
'id' => 'media_types',
'label' => 'Export as',
'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,
'required' => true,
'options' => self::MEDIA_TYPE_OBJECTS,
'value' => $value,
'dependencies' => [],
'dependsOn' => [],
];
}
public function getCallDurationFieldData(?int $valueMin = null, ?int $valueMax = null): array
{
return [
'id' => 'call_duration',
'label' => 'Call Duration',
'inputType' => InputTypeEnum::INTEGER_RANGE,
'required' => false,
'value' => ['min' => $valueMin, 'max' => $valueMax],
'queryParams' => [
'min' => 'min_call_duration',
'max' => 'max_call_duration',
],
'dependencies' => [],
'dependsOn' => [],
];
}
public function getRecipientsFieldData(?Team $team = null, array $value = []): array
{
return $this->recipientsService->getRecipientsFieldData(team: $team, value: $value);
}
public function getJiminnyRecipientsFieldData(array $value = []): array
{
return $this->recipientsService->getJiminnyRecipientsFieldData($value);
}
public function getAdditionalPromptInputFieldData(?string $value = null): array
{
return [
'id' => 'additional_prompt_input',
'label' => 'Special requirements',
'inputType' => InputTypeEnum::TEXTAREA,
'required' => false,
'placeholder' => 'What should be the focus of the report?',
'value' => $value,
'dependencies' => [],
'dependsOn' => [],
];
}
public function getCustomReportNameFieldData(?string $value = null): array
{
return [
'id' => 'custom_name',
'label' => 'Custom report name',
'inputType' => InputTypeEnum::TEXT,
'required' => false,
'placeholder' => 'Enter custom name',
'value' => $value,
'dependencies' => [],
'dependsOn' => [],
];
}
// data providers
public function getTeams(): array
{
$teams = $this->teamRepository->getTeamsForKiosk(status: Team::STATUS_ACTIVE);
$teamData = [];
foreach ($teams as $team) {
if (! $team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {
continue;
}
$teamData[] = $this->transformTeam($team);
}
return $teamData;
}
public function getTeamGroups(string $teamUuid): array
{
$data = [];
$team = $this->getTeam($teamUuid);
if ($team !== null) {
$groups = $team->groups()->get();
foreach ($groups as $group) {
$data[] = [
'id' => $group->getUuid(),
'name' => $group->getName(),
];
}
}
return $data;
}
public function getTeamsGroupsOptions(array $filterTeamUuids = []): array
{
$data = [];
$teams = $this->getTeams();
foreach ($teams as $team) {
if (! empty($filterTeamUuids) && ! in_array($team['id'], $filterTeamUuids, true)) {
continue;
}
$data[] = [
'label' => $team['name'],
'groups' => $this->getTeamGroups($team['id']),
];
}
return $data;
}
public function getTeam(string $teamUuid): ?Team
{
return $this->teamRepository->idOrUuid($teamUuid);
}
public function getTeamById(int $teamId): ?Team
{
return $this->teamRepository->find($teamId);
}
public function getGroupsUuids(AutomatedReport $report): array
{
$uuids = [];
$reportGroups = $report->getGroups();
foreach ($reportGroups as $groupId) {
if ($group = $this->groupRepository->find($groupId)) {
$uuids[] = $group->getUuid();
}
}
return $uuids;
}
public function getPlaybookCategoriesUuids(AutomatedReport $report): array
{
$uuids = [];
$playbookCategories = $report->getPlaybookCategories();
foreach ($playbookCategories as $id) {
if ($category = $this->playbookCategoryRepository->find($id)) {
$uuids[] = $category->getUuid();
}
}
return $uuids;
}
public function getDealAtCallStagesUuids(AutomatedReport $report): array
{
$uuids = [];
$reportStages = $report->getDealAtCallStages();
foreach ($reportStages as $id) {
if ($stage = $this->stageRepository->find($id)) {
$uuids[] = $stage->getUuid();
}
}
return $uuids;
}
public function getCurrentDealStagesUuids(AutomatedReport $report): array
{
$uuids = [];
$reportStages = $report->getCurrentDealStages();
foreach ($reportStages as $id) {
if ($stage = $this->stageRepository->find($id)) {
$uuids[] = $stage->getUuid();
}
}
return $uuids;
}
public function getUsersUuids(AutomatedReport $report): array
{
return $this->extractUserUuids($report->getRecipients());
}
public function getJiminnyUsersUuids(AutomatedReport $report): array
{
return $this->extractUserUuids($report->getJiminnyRecipients());
}
/**
* @param array<string, mixed> $recipients
*/
private function extractUserUuids(array $recipients): array
{
$userIds = $recipients['users'] ?? [];
return collect($userIds)
->map(fn ($id) => $this->userRepository->find((int) $id))
->filter()
->map(fn (UserContract $user) => $user->getUuid())
->values()
->all();
}
// get mail data
public function getRecipientUsers(AutomatedReport $report): array
{
return $this->buildRecipientUsers($report->getRecipients());
}
private function getJiminnyRecipientUsers(AutomatedReport $report): array
{
return $this->buildRecipientUsers($report->getJiminnyRecipients());
}
/**
* @param array<string, mixed> $recipients
*/
private function buildRecipientUsers(array $recipients): array
{
$userIds = $recipients['users'] ?? [];
return collect($userIds)
->map(fn ($id) => $this->userRepository->find((int) $id))
->filter()
->map(fn (UserContract $user) => [
'email' => $user->getEmailAddress(),
'name' => $user->getName(),
'timezone' => $user->getTimezone()->getName(),
])
->values()
->all();
}
public function getValidRecipientUsers(AutomatedReport $report, bool $includeJiminny = false): array
{
if ($report->isAskJiminnyReport()) {
$recipients = $this->resolveAskJiminnyRecipients($report);
} else {
$recipients = $this->getRecipientUsers($report);
if ($includeJiminny) {
$recipients = array_merge($recipients, $this->getJiminnyRecipientUsers($report));
}
}
$emails = [];
return array_values(array_filter(
$recipients,
static function ($recipient) use (&$emails) {
if (empty($recipient['email']) || in_array($recipient['email'], $emails, true)) {
return false;
}
$emails[] = $recipient['email'];
return true;
}
));
}
private function resolveAskJiminnyRecipients(AutomatedReport $report): array
{
$recipients = [];
$creator = $report->getCreator();
if ($creator !== null) {
$recipients[] = [
'email' => $creator->getEmailAddress(),
'name' => $creator->getName(),
'timezone' => $creator->getTimezone()->getName(),
];
}
return array_merge(
$recipients,
$this->buildRecipientUsers($report->getRecipients()),
$this->getGroupRecipientUsers($report),
);
}
private function getGroupRecipientUsers(AutomatedReport $report): array
{
$users = [];
foreach ($report->getGroups() as $groupId) {
$group = $this->groupRepository->find($groupId);
if ($group === null) {
continue;
}
foreach ($group->getMembers() as $member) {
$users[] = [
'email' => $member->getEmailAddress(),
'name' => $member->getName(),
'timezone' => $member->getTimezone()->getName(),
];
}
}
return $users;
}
public function getReportTypeName(AutomatedReportResult $report): string
{
$type = $report->getReport()->getType();
$getType = $this->transformReportType($type);
return $getType['name'];
}
public function getReportPeriodName(AutomatedReportResult $report): string
{
$from = $report->getFromDate();
$to = $report->getToDate();
$frequency = $report->getReport()->getFrequency();
if ($from === null || $to === null) {
if (! $report->getReport()->isAskJiminnyReport()) {
$invalidPeriod = $from === null ? 'from' : 'to';
throw new ApplicationException('Report period is invalid: ' . $invalidPeriod);
}
$period = $this->calculateFromAndToDatePeriod($frequency);
$from = $period['fromDate'];
$to = $period['toDate'];
}
return $this->formatReportPeriodName($frequency, $from, $to);
}
private function formatReportPeriodName(string $frequency, Carbon $from, Carbon $to): string
{
$fromYear = $from->format('Y');
$toYear = $to->format('Y');
$differentYears = $fromYear !== $toYear;
switch ($frequency) {
case self::FREQUENCY_DAILY:
return $from->format('j M Y');
case self::FREQUENCY_QUARTERLY:
// 'Jan-Mar 2025' or 'Nov 2024-Jan 2025' if years differ
$startMonth = $from->format('M');
$endMonth = $to->copy()->subMonth();
$endMonthName = $endMonth->format('M');
$endMonthYear = $endMonth->format('Y');
if ($differentYears) {
return "{$startMonth} {$fromYear} - {$endMonthName} {$endMonthYear}";
}
return "{$startMonth} - {$endMonthName} {$toYear}";
case self::FREQUENCY_MONTHLY:
// 'May 2025' - monthly reports are always within the same year
return $from->format('M Y');
case self::FREQUENCY_WEEKLY:
// '4 - 8 Aug 2025', '27 Oct - 3 Nov 2025', or '28 Dec 2024 - 3 Jan 2025' if years differ
$startDay = $from->format('j');
$endDay = $to->format('j');
$startMonth = $from->format('M');
$endMonth = $to->format('M');
if ($differentYears) {
return "{$startDay} {$startMonth} {$fromYear} - {$endDay} {$endMonth} {$toYear}";
}
if ($startMonth !== $endMonth) {
return "{$startDay} {$startMonth} - {$endDay} {$endMonth} {$toYear}";
}
return "{$startDay} - {$endDay} {$endMonth} {$toYear}";
case self::FREQUENCY_ONE_OFF:
// '2 May-31 May 2025' or '15 Dec 2024-15 Jan 2025' if years differ
$startDay = $from->format('j');
$startMonth = $from->format('M');
$endDay = $to->format('j');
$endMonth = $to->format('M');
// If same month and year, use a format like '2-31 May 2025'
if ($startMonth === $endMonth && ! $differentYears) {
return "{$startDay} - {$endDay} {$startMonth} {$toYear}";
}
// If different years, include both years
if ($differentYears) {
return "{$startDay} {$startMonth} {$fromYear} - {$endDay} {$endMonth} {$toYear}";
}
// Same year but different months
return "{$startDay} {$startMonth} - {$endDay} {$endMonth} {$toYear}";
default:
// Default format for unknown frequencies
return $from->format('j M Y') . ' - ' . $to->format('j M Y');
}
}
public function getReportTeamsName(AutomatedReportResult $report): string
{
$groups = $report->getGroups();
if (empty($groups)) {
return 'All';
}
// Get group names from repository
$groupNames = [];
foreach ($groups as $groupId) {
$group = $this->groupRepository->find($groupId);
if ($group) {
$groupNames[] = $group->getName();
}
}
if (count($groupNames) === 1) {
// Single team format
$teamsName = $groupNames[0];
} else {
// Multiple teams format
$teamsName = implode(', ', $groupNames);
}
return $teamsName;
}
public function getReportFileName(AutomatedReportResult $report): string
...
|
12304
|
|
12308
|
260
|
31
|
2026-04-14T11:01:28.831912+00:00
|
/Users/lukas/.screenpipe/data/data/2026-04-14/1776 /Users/lukas/.screenpipe/data/data/2026-04-14/1776164488831_m1.jpg...
|
PhpStorm
|
faVsco.js – AutomatedReportsService.php
|
1
|
NULL
|
monitor_1
|
NULL
|
NULL
|
NULL
|
NULL
|
Project: faVsco.js, menu
#11894 on JY-18909-automa Project: faVsco.js, menu
#11894 on JY-18909-automated-reports-ask-jiminny, menu
Start Listening for PHP Debug Connections
AutomatedReportsCommandTest
Run 'AutomatedReportsCommandTest'
Debug 'AutomatedReportsCommandTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Execute
Explain Plan
Browse Query History
View Parameters
Open Query Execution Settings…
In-Editor Results
Tx: Auto
Cancel Running Statements
Playground
jiminny
Sync Changes
Hide This Notification
Code changed:
Hide
16
13
13
Previous Highlighted Error
Next Highlighted Error
SELECT * FROM teams WHERE id = 1;
select * from crm_layouts where crm_configuration_id = 39;
SELECT * FROM crm_layout_entities WHERE crm_layout_id = 283;
SELECT * FROM crm_fields WHERE id = 2234;
SELECT * FROM crm_field_values WHERE crm_field_id = 2234;
select * from crm_profiles where user_id = 143;
select * from record_types where crm_configuration_id = 39; # 0121K000001MHElQAO,0121K000001MHEqQAO
select * from business_processes where crm_configuration_id = 39;
# 01941000000H669AAC, 01941000000H66JAAS
select * from record_type_field_values
where record_type_id IN (24);
select * from crm_field_values where id IN (2730);
select * from crm_configurations where id = 39;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 1
and sa.provider = 'salesforce'; #1035
select * from users where team_id = 1; # 222 group 3
SELECT * FROM activities WHERE user_id = 222 order by id desc;
select * from sidekick_settings where team_id = 1;
select * from teams where id = 1;
select * from team_features where team_id = 1;
select * from activities where crm_configuration_id = 2
and provider = 'ms-teams' and id = 608765;
SELECT * FROM activities WHERE crm_configuration_id = 2 and crm_provider_id = '59523413338';
select * from sidekick_settings where team_id = 2;
SELECT * FROM activities WHERE id = 608660;
select * from activity_summary_logs where activity_id = 608660;
select * from ai_prompts where transcription_id = 11214;
# [PASSWORD_DOTS]
SELECT * FROM activities WHERE uuid_to_bin('ed78a437-2804-450e-ab2f-56ab1c641346') = uuid;
# id: 608818, crm: 59628809737
SELECT * FROM activities WHERE uuid_to_bin('36b06e55-afdd-4782-8dee-c624cd0af191') = uuid;
# id: 608821, crm: 59632069252
SELECT ce.start_time, ce.end_time, a.id, a.uuid, crm_provider_id, calendar_event_id, title,
playbook_category_id, user_id, lead_id, contact_id, account_id, opportunity_id,
scheduled_start_time, scheduled_end_time, actual_start_time, actual_end_time, a.created_at
FROM activities a
join calendar_events ce on a.calendar_event_id = ce.id
WHERE a.id IN (608818, 608821);
select * from users where team_id = 1;
select * from team_settings where team_id = 1;
select * from crm_profiles where crm_configuration_id = 39 order by user_id;
select * from team_features where team_id = 1;
select * from users where team_id = 2;
SELECT * FROM activities WHERE uuid_to_bin('ec7647e9-5225-458b-b475-f31aa2769204') = uuid; # 612639
# Preslava N. Ivanova, grou id 3
SELECT * FROM opportunities WHERE uuid_to_bin('a2928fe5-aec5-46cb-85d9-7654c89e46a6') = uuid;
select * from activities where opportunity_id = 344 and actual_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00';
select
a.id,
a.type,
a.scheduled_start_time,
a.actual_start_time,
a.created_at,
a.opportunity_id,
a.status
FROM activities a
WHERE opportunity_id = 344
and status IN ('completed', 'received', 'delivered')
and (
(a.actual_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00')
OR (a.created_at between '2024-10-11 00:00:00' and '2024-10-12 00:00:00')
OR (a.scheduled_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00'))
;
SELECT * FROM users WHERE id = 222;
SELECT * FROM crm_profiles WHERE user_id = 222;
select * from crm_layouts where crm_configuration_id = 39;
SELECT * FROM crm_layout_entities WHERE crm_layout_id = 281;
select * from group_deal_risk_types;
select * from opportunities where team_id = 1;
SELECT * FROM opportunities WHERE id = 315;
SELECT * FROM crm_field_data WHERE object_id = 315;
select * from crm_field_data where object_id = 260;
select * from generic_ai_prompts where subject_id = 315;
select * from teams; # 36, 21, 121, [EMAIL]
SELECT * FROM social_accounts WHERE sociable_id = 121 and provider = 'bullhorn';
# [PASSWORD_DOTS]
select * from teams where id = 1;
select * from crm_configurations where id = 39;
select * from users where team_id = 1;
select u.email, cp.* from users u
join crm_profiles cp on u.id = cp.user_id
where u.team_id = 1;
# 1 - 00541000004281rAAA
# 204 - 0052g000003freeAAA
# 429 - 0052g000003qGOiAAM
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 1
and sa.provider = 'salesforce';
select * from activities where type = 'softphone'
and created_at > '2024-12-11 15:24:36' order by id desc;
select * from activity_providers where team_id = 1;
select * from activity_provider_users where activity_provider_id = 328;
select * from opportunities where crm_configuration_id = 39
AND account_id = 178 AND is_closed = false
order by created_at DESC;
select * from contacts where id = 3952;
select * from accounts where id = 178;
# [PASSWORD_DOTS]
select * from teams where id = 36;
select * from crm_configurations where id = 21;
select * from users where team_id = 36;
select u.email, cp.* from users u
join crm_profiles cp on u.id = cp.user_id
where u.team_id = 36;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 36
and sa.provider = 'bullhorn';
select * from social_accounts where id = 348;
UPDATE social_accounts SET
provider_user_token = '21442_6802599_91:41179a58-21e7-4d7c-ad58-56bb666b2f65',
provider_refresh_token = '21442_6802599_91:01c6b335-3f2a-42e4-85ff-8a08fa65fceb',
expires = 1733998131,
state = 'connected'
WHERE id = 348;
# [PASSWORD_DOTS]
select * from teams where id = 31;
select * from crm_configurations where id = 18;
select * from users where team_id = 31; # 257
select u.email, cp.* from users u
join crm_profiles cp on u.id = cp.user_id
where u.team_id = 31;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 31
and sa.provider = 'close';
select * from contacts where crm_configuration_id = 18;
# [PASSWORD_DOTS] NEPTUNE [PASSWORD_DOTS]
select * from teams;
select * from users where id IN (1030, 1035, 1052);
select * from crm_configurations;
select * from users where team_id = 65; # 257
select * from team_settings where team_id = 65; # 257
select * from invitations where team_id = 65; # 257
select * from users where email = '[EMAIL]'; # 257
select u.email, cp.* from users u
join crm_profiles cp on u.id = cp.user_id
where u.team_id = 65;
select * from crm_configurations where id = 53;
select * from accounts where crm_configuration_id = 53 order by id desc;
select * from leads where crm_configuration_id = 53 order by id desc;
select * from contacts where crm_configuration_id = 53 order by id desc;
select * from opportunities where crm_configuration_id = 53 order by id desc;
select * from crm_profiles where crm_configuration_id = 53 order by id desc;
select * from crm_fields where crm_configuration_id = 53 order by id desc;
select * from crm_field_values where crm_field_id = 3341 order by id desc;
select * from crm_layouts where crm_configuration_id = 53 order by id desc;
select * from stages where crm_configuration_id = 53 order by id desc;
select * from crm_profiles where crm_configuration_id = 13;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 65
and sa.provider = 'integration-app';
select * from contacts where crm_configuration_id = 13;
select * from social_accounts where sociable_id = 283;
SELECT * FROM opportunities WHERE crm_provider_id = '006O400000E9bzeIAB';
select * from activity_providers where team_id = 65;
SELECT * FROM activities WHERE crm_configuration_id IN (51, 52, 53);
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 65
;
# [PASSWORD_DOTS] STAGING [PASSWORD_DOTS]
SELECT * FROM teams;
SELECT * FROM teams WHERE id = 88;
SELECT * FROM teams WHERE id = 89;
select * from team_settings where team_id = 89;
SELECT * FROM users WHERE team_id = 89;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 89;
select * from users;
SELECT * FROM social_accounts WHERE sociable_id = 1761;
SELECT * FROM crm_configurations WHERE id = 70;
select * from accounts where crm_configuration_id = 70 order by id desc;
select * from leads where crm_configuration_id = 70 order by id desc;
select * from contacts where crm_configuration_id = 70 order by id desc;
select * from opportunities where crm_configuration_id = 70 order by id desc;
select * from crm_profiles where crm_configuration_id = 70 order by id desc;
select * from crm_fields where crm_configuration_id = 70 order by id desc;
select * from crm_field_values where crm_field_id = 3536 order by id desc;
select * from crm_layouts where crm_configuration_id = 70 order by id desc;
select * from stages where crm_configuration_id = 70 order by id desc;
select * from business_processes where crm_configuration_id = 70 order by id desc;
select * from business_process_stages where business_process_id = 34;
select * from contacts where id = 10468;
select * from crm_layouts where crm_configuration_id = 70;
SELECT * FROM crm_layout_entities WHERE crm_layout_id = 388;
SELECT * FROM crm_fields WHERE id IN (3533,3534,3535);
select * from activities where crm_configuration_id = 70
and (account_id IS NOT NULL or lead_id IS NOT NULL or contact_id IS NOT NULL or opportunity_id IS NOT NULL) order by id desc;
SELECT * FROM activities WHERE uuid_to_bin('2e10b60f-8a61-41c5-a3d4-28835353dc65') = uuid;
SELECT * FROM activities where crm_configuration_id = 69 ;
SELECT * FROM users WHERE email LIKE '%[EMAIL]%';
SELECT * FROM activities WHERE uuid_to_bin('5a150c93-40fc-42ec-b3bd-c1d328e09f6e') = uuid;
SELECT * FROM opportunities WHERE id = 385;
select * from participants p
join activities a on p.activity_id = a.id
where a.crm_configuration_id = 70
and (p.lead_id IS NOT NULL or p.contact_id IS NOT NULL);
SELECT * FROM participants WHERE id = 1013638;
select * from teams where id = 90;
select * from users where team_id = 90;
select * from social_accounts where social_accounts.sociable_id IN (1960,1760);
SELECT * FROM crm_profiles WHERE crm_configuration_id = 71;
select * from invitations where team_id = 90;
select * from crm_configurations where id = 71;
select * from accounts where crm_configuration_id = 71 order by id desc;
select * from leads where crm_configuration_id = 71 order by id desc;
select * from contacts where crm_configuration_id = 71 order by id desc;
select * from opportunities where crm_configuration_id = 71 order by id desc;
select * from crm_profiles where crm_configuration_id = 71 order by id desc;
select * from crm_fields where crm_configuration_id = 71 order by id desc;
select * from crm_field_values where crm_field_id = 3341 order by id desc;
select * from crm_layouts where crm_configuration_id = 71 order by id desc;
select * from stages where crm_configuration_id = 71 order by id desc;
select * from users order by secondary_email desc;
select u.id, u.email, u.status, sa.id, sa.provider_user_id from social_accounts sa
join users u on sa.sociable_id = u.id
where sa.provider = 'google' and u.email LIKE 'aneliya%';
select * from failed_jobs order by id desc;
select * from users where email = '[EMAIL]' or secondary_email = '[EMAIL]';
select * from teams;
SELECT * FROM crm_profiles WHERE crm_configuration_id = 39;
SELECT * FROM crm_fields WHERE crm_configuration_id = 39 and object_type = 'task';
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 1
and sa.provider = 'salesforce';
# [PASSWORD_DOTS]
SELECT * FROM activities WHERE uuid_to_bin('c38b3895-fd0f-4b1f-9fb2-c170dba137c6') = uuid;
SELECT * FROM crm_configurations WHERE id = 70;
select * from teams where id = 1;
select * from groups where team_id = 1;
select * from users where team_id = 1;
select o.id, o.name,o.close_date, u.id, u.name, u.group_id, r.id, r.display_name, g.name, g.scope from opportunities o
join users u on o.user_id = u.id
join groups g on u.group_id = g.id
join role_user ru on u.id = ru.user_id
join roles r on ru.role_id = r.id
where o.crm_configuration_id = 39 and close_date > '2024-01-01 00:00:00';
select * from role_user where user_id = 143;
select * from roles;
select * from role_user;
select * from groups where id = 9;
select * from scope_groups where group_id = 9;
# [PASSWORD_DOTS]
select * from teams where id = 36;
select * from crm_configurations;
SELECT * FROM social_accounts WHERE sociable_id = 121;
[URL_WITH_CREDENTIALS] this will add filter, however if we need to control feature by FF we need conditional logic
public const array TYPES = [
['id' => 'exec_summary', 'name' => 'Exec Summary'],
['id' => 'coaching_profiles', 'name' => 'Coaching Profiles'],
['id' => 'product_feedback', 'name' => 'Product Feedback'],
['id' => self::TYPE_LOSS_ANALYSIS, 'name' => 'Loss Analysis'],
// ['id' => 'questions', 'name' => 'Questions'],
// ['id' => 'statistical_quant', 'name' => 'Statistical Quantitative'],
];
public const array ALL_TYPES = [
...self::TYPES,
['id' => self::TYPE_ASK_JIMINNY, 'name' => 'Ask Jiminny'],
];
public const string FREQUENCY_DAILY = 'daily';
public const string FREQUENCY_WEEKLY = 'weekly';
public const string FREQUENCY_MONTHLY = 'monthly';
public const string FREQUENCY_QUARTERLY = 'quarterly';
public const string FREQUENCY_ONE_OFF = 'one_off';
/**
* Frequencies for standard (non-Ask Jiminny) reports.
*/
public const array FREQUENCIES = [
['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],
['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],
['id' => self::FREQUENCY_QUARTERLY, 'name' => 'Quarterly'],
['id' => self::FREQUENCY_ONE_OFF, 'name' => 'One-off'],
];
/**
* Frequencies for Ask Jiminny reports.
*/
public const array ASK_JIMINNY_FREQUENCIES = [
['id' => self::FREQUENCY_DAILY, 'name' => 'Daily'],
['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],
['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],
];
public const string MEDIA_TYPE_PDF = 'pdf';
public const string MEDIA_TYPE_PODCAST = 'podcast';
public const array MEDIA_TYPES = [self::MEDIA_TYPE_PDF, self::MEDIA_TYPE_PODCAST];
public const array MEDIA_TYPE_OBJECT_PDF = ['id' => self::MEDIA_TYPE_PDF, 'name' => 'PDF'];
public const array MEDIA_TYPE_OBJECT_PODCAST = ['id' => self::MEDIA_TYPE_PODCAST, 'name' => 'Podcast'];
public const array MEDIA_TYPE_OBJECTS = [self::MEDIA_TYPE_OBJECT_PDF, self::MEDIA_TYPE_OBJECT_PODCAST];
public const array CALL_TYPE_CONFERENCE = ['id' => 'conference', 'name' => 'Conference'];
public const array CALL_TYPE_DIALER = ['id' => 'dialer', 'name' => 'Dialer'];
public const int SENT_REPORT_AT_HOURS = 5;
public const string PDF_KEY = 'pdf';
public const string AUDIO_KEY = 'audio';
private const array ALL_FREQUENCIES = [
['id' => self::FREQUENCY_DAILY, 'name' => 'Daily'],
['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],
['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],
['id' => self::FREQUENCY_QUARTERLY, 'name' => 'Quarterly'],
['id' => self::FREQUENCY_ONE_OFF, 'name' => 'One-off'],
];
private const string S3_DIR = 'reports';
private const array FILE_EXTENSIONS_VARIANTS = ['html', 'MD', 'pdf'];
private const array FILE_PODCAST_EXTENSIONS_VARIANTS = ['json', 'mp3', 'ssml'];
public function __construct(
private readonly TeamRepository $teamRepository,
private readonly GroupRepository $groupRepository,
private readonly UserRepository $userRepository,
private readonly StageRepository $stageRepository,
private readonly DealStagesService $dealStagesService,
private readonly RecipientsService $recipientsService,
private readonly AutomatedReportsRepository $automatedReportsRepository,
private readonly Webhook $webhookService,
private readonly BusDispatcher $dispatcher,
private readonly ActivityTypeService $activityTypeService,
private readonly PlaybookCategoryRepository $playbookCategoryRepository,
private readonly AskAnythingPromptService $askAnythingPromptService,
private readonly SearchRepository $activitySearchRepository,
private readonly AskAnythingRepository $askAnythingRepository,
) {
}
public static function getTypes(): array
{
$types = self::TYPES;
return array_map(static function ($type) {
return $type['id'];
}, $types);
}
public static function getCallTypes(): array
{
return array_map(static function ($callType) {
return $callType['id'];
}, [self::CALL_TYPE_CONFERENCE, self::CALL_TYPE_DIALER]);
}
public static function getFrequencies(): array
{
return array_map(static function ($frequency) {
return $frequency['id'];
}, self::FREQUENCIES);
}
// front-facing structure
public function getReportEnabledFieldData(bool $value = false): array
{
return [
'id' => 'report_enabled',
'label' => '',
'inputType' => InputTypeEnum::TOGGLE,
'value' => $value,
];
}
// Organizations = Teams
public function getOrganizationFieldData(?string $value = null, bool $shortVersion = false): array
{
$options = $this->getTeams();
if ($shortVersion) {
return [
'id' => 'organization',
'label' => 'Organization',
'options' => $options,
];
}
return [
'id' => 'organization',
'label' => 'Organization',
'inputType' => InputTypeEnum::DROPDOWN,
'required' => true,
'placeholder' => 'Select',
'options' => $options,
'value' => $value,
'dependencies' => [
'teams',
'deal_stage_at_call',
'current_deal_stage',
'recipients',
ActivityTypeService::PLAYBOOK_CATEGORIES_KEY,
],
'dependsOn' => [],
];
}
// Teams = Groups
public function getTeamFieldData(array $options = [], array $value = [], bool $shortVersion = false): array
{
if ($shortVersion) {
return [
'id' => 'teams',
'label' => 'Team',
'options' => $options,
];
}
return [
'id' => 'teams',
'label' => 'Team',
'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,
'required' => false,
'placeholder' => 'Select',
'options' => $options,
'value' => $value, // value should be an array of objects {id, name}
'dependencies' => [ActivityTypeService::PLAYBOOK_CATEGORIES_KEY],
'dependsOn' => [],
];
}
public function getReportTypeFieldData(?string $value = null, bool $shortVersion = false, ?Team $team = null): array
{
$types = [];
if ($team instanceof Team) {
if ($team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {
$types = self::TYPES;
}
if ($team->hasFeature(FeatureEnum::ASK_JIMINNY_REPORTS)) {
$types[] = ['id' => self::TYPE_ASK_JIMINNY, 'name' => 'Ask Jiminny'];
}
} else {
$types = self::TYPES;
}
if ($shortVersion) {
return [
'id' => 'report_type',
'label' => 'Report Type',
'options' => $types,
];
}
return [
'id' => 'report_type',
'label' => 'Report Type',
'inputType' => InputTypeEnum::DROPDOWN,
'required' => true,
'placeholder' => 'Select',
'options' => $types,
'value' => $value,
'dependencies' => [],
'dependsOn' => [],
];
}
public function getFrequencyFieldData(?string $value = null): array
{
return [
'id' => 'frequency',
'label' => 'Frequency',
'inputType' => InputTypeEnum::DROPDOWN,
'required' => true,
'placeholder' => 'Select',
'options' => self::FREQUENCIES,
'value' => $value,
'dependencies' => ['period'],
'dependsOn' => [],
];
}
public function getPeriodFieldData(?string $valueStartDate = null, ?string $valueEndDate = null): array
{
return [
'id' => 'period',
'label' => 'Select one-off period',
'inputType' => InputTypeEnum::DATE_RANGE,
'required' => true,
'placeholder' => 'Select',
'value' => ['startDate' => $valueStartDate, 'endDate' => $valueEndDate],
'queryParams' => [
'startDate' => 'start_date_period',
'endDate' => 'end_date_period',
],
'dependencies' => [],
'dependsOn' => ['frequency'],
];
}
public function getActivityTypesFieldData(?Team $team = null, array $value = [], array $teamsFilter = []): array
{
return $this->activityTypeService->getActivityTypeFieldData(team: $team, value: $value, groupIds: $teamsFilter);
}
public function getDealStageAtCallFieldData(?Team $team = null, array $value = []): array
{
return $this->dealStagesService->getDealStageAtCallFieldData(team: $team, value: $value);
}
public function getCurrentDealStageFieldData(?Team $team = null, array $value = []): array
{
return $this->dealStagesService->getCurrentDealStageFieldData(team: $team, value: $value);
}
public function getDealValueFieldData(?int $valueMin = null, ?int $valueMax = null): array
{
return [
'id' => 'deal_value',
'label' => 'Deal Value',
'inputType' => InputTypeEnum::INTEGER_RANGE,
'required' => false,
'value' => ['min' => $valueMin, 'max' => $valueMax],
'queryParams' => [
'min' => 'min_deal_value',
'max' => 'max_deal_value',
],
'dependencies' => [],
'dependsOn' => [],
];
}
public function getCallTypeFieldData(bool $conferenceOn = false, bool $dialerOn = false): array
{
$value = [];
$conferenceOn && $value[] = self::CALL_TYPE_CONFERENCE;
$dialerOn && $value[] = self::CALL_TYPE_DIALER;
return [
'id' => 'call_type',
'label' => 'Call Type',
'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,
'required' => true,
'options' => [
self::CALL_TYPE_CONFERENCE,
self::CALL_TYPE_DIALER,
],
'value' => $value,
'dependencies' => [],
'dependsOn' => [],
];
}
public function getMediaTypeFieldData(?AutomatedReport $report = null): array
{
$value = [];
if ($report) {
$value = $this->transformMediaTypes($report);
}
return [
'id' => 'media_types',
'label' => 'Export as',
'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,
'required' => true,
'options' => self::MEDIA_TYPE_OBJECTS,
'value' => $value,
'dependencies' => [],
'dependsOn' => [],
];
}
public function getCallDurationFieldData(?int $valueMin = null, ?int $valueMax = null): array
{
return [
'id' => 'call_duration',
'label' => 'Call Duration',
'inputType' => InputTypeEnum::INTEGER_RANGE,
'required' => false,
'value' => ['min' => $valueMin, 'max' => $valueMax],
'queryParams' => [
'min' => 'min_call_duration',
'max' => 'max_call_duration',
],
'dependencies' => [],
'dependsOn' => [],
];
}
public function getRecipientsFieldData(?Team $team = null, array $value = []): array
{
return $this->recipientsService->getRecipientsFieldData(team: $team, value: $value);
}
public function getJiminnyRecipientsFieldData(array $value = []): array
{
return $this->recipientsService->getJiminnyRecipientsFieldData($value);
}
public function getAdditionalPromptInputFieldData(?string $value = null): array
{
return [
'id' => 'additional_prompt_input',
'label' => 'Special requirements',
'inputType' => InputTypeEnum::TEXTAREA,
'required' => false,
'placeholder' => 'What should be the focus of the report?',
'value' => $value,
'dependencies' => [],
'dependsOn' => [],
];
}
public function getCustomReportNameFieldData(?string $value = null): array
{
return [
'id' => 'custom_name',
'label' => 'Custom report name',
'inputType' => InputTypeEnum::TEXT,
'required' => false,
'placeholder' => 'Enter custom name',
'value' => $value,
'dependencies' => [],
'dependsOn' => [],
];
}
// data providers
public function getTeams(): array
{
$teams = $this->teamRepository->getTeamsForKiosk(status: Team::STATUS_ACTIVE);
$teamData = [];
foreach ($teams as $team) {
if (! $team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {
continue;
}
$teamData[] = $this->transformTeam($team);
}
return $teamData;
}
public function getTeamGroups(string $teamUuid): array
{
$data = [];
$team = $this->getTeam($teamUuid);
if ($team !== null) {
$groups = $team->groups()->get();
foreach ($groups as $group) {
$data[] = [
'id' => $group->getUuid(),
'name' => $group->getName(),
];
}
}
return $data;
}
public function getTeamsGroupsOptions(array $filterTeamUuids = []): array
{
$data = [];
$teams = $this->getTeams();
foreach ($teams as $team) {
if (! empty($filterTeamUuids) && ! in_array($team['id'], $filterTeamUuids, true)) {
continue;
}
$data[] = [
'label' => $team['name'],
'groups' => $this->getTeamGroups($team['id']),
];
}
return $data;
}
public function getTeam(string $teamUuid): ?Team
{
return $this->teamRepository->idOrUuid($teamUuid);
}
public function getTeamById(int $teamId): ?Team
{
return $this->teamRepository->find($teamId);
}
public function getGroupsUuids(AutomatedReport $report): array
{
$uuids = [];
$reportGroups = $report->getGroups();
foreach ($reportGroups as $groupId) {
if ($group = $this->groupRepository->find($groupId)) {
$uuids[] = $group->getUuid();
}
}
return $uuids;
}
public function getPlaybookCategoriesUuids(AutomatedReport $report): array
{
$uuids = [];
$playbookCategories = $report->getPlaybookCategories();
foreach ($playbookCategories as $id) {
if ($category = $this->playbookCategoryRepository->find($id)) {
$uuids[] = $category->getUuid();
}
}
return $uuids;
}
public function getDealAtCallStagesUuids(AutomatedReport $report): array
{
$uuids = [];
$reportStages = $report->getDealAtCallStages();
foreach ($reportStages as $id) {
if ($stage = $this->stageRepository->find($id)) {
$uuids[] = $stage->getUuid();
}
}
return $uuids;
}
public function getCurrentDealStagesUuids(AutomatedReport $report): array
{
$uuids = [];
$reportStages = $report->getCurrentDealStages();
foreach ($reportStages as $id) {
if ($stage = $this->stageRepository->find($id)) {
$uuids[] = $stage->getUuid();
}
}
return $uuids;
}
public function getUsersUuids(AutomatedReport $report): array
{
return $this->extractUserUuids($report->getRecipients());
}
public function getJiminnyUsersUuids(AutomatedReport $report): array
{
return $this->extractUserUuids($report->getJiminnyRecipients());
}
/**
* @param array<string, mixed> $recipients
*/
private function extractUserUuids(array $recipients): array
{
$userIds = $recipients['users'] ?? [];
return collect($userIds)
->map(fn ($id) => $this->userRepository->find((int) $id))
->filter()
->map(fn (UserContract $user) => $user->getUuid())
->values()
->all();
}
// get mail data
public function getRecipientUsers(AutomatedReport $report): array
{
return $this->buildRecipientUsers($report->getRecipients());
}
private function getJiminnyRecipientUsers(AutomatedReport $report): array
{
return $this->buildRecipientUsers($report->getJiminnyRecipients());
}
/**
* @param array<string, mixed> $recipients
*/
private function buildRecipientUsers(array $recipients): array
{
$userIds = $recipients['users'] ?? [];
return collect($userIds)
->map(fn ($id) => $this->userRepository->find((int) $id))
->filter()
->map(fn (UserContract $user) => [
'email' => $user->getEmailAddress(),
'name' => $user->getName(),
'timezone' => $user->getTimezone()->getName(),
])
->values()
->all();
}
public function getValidRecipientUsers(AutomatedReport $report, bool $includeJiminny = false): array
{
if ($report->isAskJiminnyReport()) {
$recipients = $this->resolveAskJiminnyRecipients($report);
} else {
$recipients = $this->getRecipientUsers($report);
if ($includeJiminny) {
$recipients = array_merge($recipients, $this->getJiminnyRecipientUsers($report));
}
}
$emails = [];
return array_values(array_filter(
$recipients,
static function ($recipient) use (&$emails) {
if (empty($recipient['email']) || in_array($recipient['email'], $emails, true)) {
return false;
}
$emails[] = $recipient['email'];
return true;
}
));
}
private function resolveAskJiminnyRecipients(AutomatedReport $report): array
{
$recipients = [];
$creator = $report->getCreator();
if ($creator !== null) {
$recipients[] = [
'email' => $creator->getEmailAddress(),
'name' => $creator->getName(),
'timezone' => $creator->getTimezone()->getName(),
];
}
return array_merge(
$recipients,
$this->buildRecipientUsers($report->getRecipients()),
$this->getGroupRecipientUsers($report),
);
}
private function getGroupRecipientUsers(AutomatedReport $report): array
{
$users = [];
foreach ($report->getGroups() as $groupId) {
$group = $this->groupRepository->find($groupId);
if ($group === null) {
continue;
}
foreach ($group->getMembers() as $member) {
$users[] = [
'email' => $member->getEmailAddress(),
'name' => $member->getName(),
'timezone' => $member->getTimezone()->getName(),
];
}
}
return $users;
}
public function getReportTypeName(AutomatedReportResult $report): string
{
$type = $report->getReport()->getType();
$getType = $this->transformReportType($type);
return $getType['name'];
}
public function getReportPeriodName(AutomatedReportResult $report): string
{
$from = $report->getFromDate();
$to = $report->getToDate();
$frequency = $report->getReport()->getFrequency();
if ($from === null || $to === null) {
if (! $report->getReport()->isAskJiminnyReport()) {
$invalidPeriod = $from === null ? 'from' : 'to';
throw new ApplicationException('Report period is invalid: ' . $invalidPeriod);
}
$period = $this->calculateFromAndToDatePeriod($frequency);
$from = $period['fromDate'];
$to = $period['toDate'];
}
return $this->formatReportPeriodName($frequency, $from, $to);
}
private function formatReportPeriodName(string $frequency, Carbon $from, Carbon $to): string
{
$fromYear = $from->format('Y');
$toYear = $to->format('Y');
$differentYears = $fromYear !== $toYear;
switch ($frequency) {
case self::FREQUENCY_DAILY:
return $from->format('j M Y');
case self::FREQUENCY_QUARTERLY:
// 'Jan-Mar 2025' or 'Nov 2024-Jan 2025' if years differ
$startMonth = $from->format('M');
$endMonth = $to->copy()->subMonth();
$endMonthName = $endMonth->format('M');
$endMonthYear = $endMonth->format('Y');
if ($differentYears) {
return "{$startMonth} {$fromYear} - {$endMonthName} {$endMonthYear}";
}
return "{$startMonth} - {$endMonthName} {$toYear}";
case self::FREQUENCY_MONTHLY:
// 'May 2025' - monthly reports are always within the same year
return $from->format('M Y');
case self::FREQUENCY_WEEKLY:
// '4 - 8 Aug 2025', '27 Oct - 3 Nov 2025', or '28 Dec 2024 - 3 Jan 2025' if years differ
$startDay = $from->format('j');
$endDay = $to->format('j');
$startMonth = $from->format('M');
$endMonth = $to->format('M');
if ($differentYears) {
return "{$startDay} {$startMonth} {$fromYear} - {$endDay} {$endMonth} {$toYear}";
}
if ($startMonth !== $endMonth) {
return "{$startDay} {$startMonth} - {$endDay} {$endMonth} {$toYear}";
}
return "{$startDay} - {$endDay} {$endMonth} {$toYear}";
case self::FREQUENCY_ONE_OFF:
// '2 May-31 May 2025' or '15 Dec 2024-15 Jan 2025' if years differ
$startDay = $from->format('j');
$startMonth = $from->format('M');
$endDay = $to->format('j');
$endMonth = $to->format('M');
// If same month and year, use a format like '2-31 May 2025'
if ($startMonth === $endMonth && ! $differentYears) {
return "{$startDay} - {$endDay} {$startMonth} {$toYear}";
}
// If different years, include both years
if ($differentYears) {
return "{$startDay} {$startMonth} {$fromYear} - {$endDay} {$endMonth} {$toYear}";
}
// Same year but different months
return "{$startDay} {$startMonth} - {$endDay} {$endMonth} {$toYear}";
default:
// Default format for unknown frequencies
return $from->format('j M Y') . ' - ' . $to->format('j M Y');
}
}
public function getReportTeamsName(AutomatedReportResult $report): string
{
$groups = $report->getGroups();
if (empty($groups)) {
return 'All';
}
// Get group names from repository
$groupNames = [];
foreach ($groups as $groupId) {
$group = $this->groupRepository->find($groupId);
if ($group) {
$groupNames[] = $group->getName();
}
}
if (count($groupNames) === 1) {
// Single team format
$teamsName = $groupNames[0];
} else {
// Multiple teams format
$teamsName = implode(', ', $groupNames);
}
return $teamsName;
}
public function getReportFileName(AutomatedReportResult $report): string
...
|
[{"role":"AXButton","text" [{"role":"AXButton","text":"Project: faVsco.js, menu","depth":5,"help_text":"~/jiminny/app","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"#11894 on JY-18909-automated-reports-ask-jiminny, menu","depth":5,"help_text":"Pull request #11894 exists for current branch JY-18909-automated-reports-ask-jiminny","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Start Listening for PHP Debug Connections","depth":5,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"AutomatedReportsCommandTest","depth":6,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Run 'AutomatedReportsCommandTest'","depth":6,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Debug 'AutomatedReportsCommandTest'","depth":6,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"More Actions","depth":6,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JetBrains AI","depth":5,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Search Everywhere","depth":5,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"IDE and Project Settings","depth":5,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Execute","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Explain Plan","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Browse Query History","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"View Parameters","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Open Query Execution Settings…","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"In-Editor Results","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Tx: Auto","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Cancel Running Statements","depth":4,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Playground","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"jiminny","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.088194445,"height":0.027777778},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"16","depth":4,"role_description":"text"},{"role":"AXStaticText","text":"13","depth":4,"role_description":"text"},{"role":"AXStaticText","text":"13","depth":4,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"SELECT * FROM teams WHERE id = 1;\n\nselect * from crm_layouts where crm_configuration_id = 39;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 283;\nSELECT * FROM crm_fields WHERE id = 2234;\nSELECT * FROM crm_field_values WHERE crm_field_id = 2234;\n\nselect * from crm_profiles where user_id = 143;\n\nselect * from record_types where crm_configuration_id = 39; # 0121K000001MHElQAO,0121K000001MHEqQAO\nselect * from business_processes where crm_configuration_id = 39;\n# 01941000000H669AAC, 01941000000H66JAAS\n\nselect * from record_type_field_values\n where record_type_id IN (24);\n\nselect * from crm_field_values where id IN (2730);\n\nselect * from crm_configurations where id = 39;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 1\nand sa.provider = 'salesforce'; #1035\n\n\nselect * from users where team_id = 1; # 222 group 3\nSELECT * FROM activities WHERE user_id = 222 order by id desc;\nselect * from sidekick_settings where team_id = 1;\nselect * from teams where id = 1;\nselect * from team_features where team_id = 1;\n\nselect * from activities where crm_configuration_id = 2\nand provider = 'ms-teams' and id = 608765;\n\nSELECT * FROM activities WHERE crm_configuration_id = 2 and crm_provider_id = '59523413338';\n\nselect * from sidekick_settings where team_id = 2;\n\nSELECT * FROM activities WHERE id = 608660;\nselect * from activity_summary_logs where activity_id = 608660;\nselect * from ai_prompts where transcription_id = 11214;\n\n# ********************************************************************************************************\nSELECT * FROM activities WHERE uuid_to_bin('ed78a437-2804-450e-ab2f-56ab1c641346') = uuid;\n# id: 608818, crm: 59628809737\nSELECT * FROM activities WHERE uuid_to_bin('36b06e55-afdd-4782-8dee-c624cd0af191') = uuid;\n# id: 608821, crm: 59632069252\nSELECT ce.start_time, ce.end_time, a.id, a.uuid, crm_provider_id, calendar_event_id, title,\nplaybook_category_id, user_id, lead_id, contact_id, account_id, opportunity_id,\nscheduled_start_time, scheduled_end_time, actual_start_time, actual_end_time, a.created_at\nFROM activities a\njoin calendar_events ce on a.calendar_event_id = ce.id\nWHERE a.id IN (608818, 608821);\n\nselect * from users where team_id = 1;\nselect * from team_settings where team_id = 1;\nselect * from crm_profiles where crm_configuration_id = 39 order by user_id;\n\nselect * from team_features where team_id = 1;\n\nselect * from users where team_id = 2;\n\nSELECT * FROM activities WHERE uuid_to_bin('ec7647e9-5225-458b-b475-f31aa2769204') = uuid; # 612639\n# Preslava N. Ivanova, grou id 3\n\nSELECT * FROM opportunities WHERE uuid_to_bin('a2928fe5-aec5-46cb-85d9-7654c89e46a6') = uuid;\n\nselect * from activities where opportunity_id = 344 and actual_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00';\n\nselect\n a.id,\n a.type,\n a.scheduled_start_time,\n a.actual_start_time,\n a.created_at,\n a.opportunity_id,\n a.status\nFROM activities a\nWHERE opportunity_id = 344\nand status IN ('completed', 'received', 'delivered')\nand (\n (a.actual_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00')\nOR (a.created_at between '2024-10-11 00:00:00' and '2024-10-12 00:00:00')\nOR (a.scheduled_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00'))\n;\n\nSELECT * FROM users WHERE id = 222;\n\nSELECT * FROM crm_profiles WHERE user_id = 222;\nselect * from crm_layouts where crm_configuration_id = 39;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 281;\n\nselect * from group_deal_risk_types;\n\nselect * from opportunities where team_id = 1;\n\nSELECT * FROM opportunities WHERE id = 315;\nSELECT * FROM crm_field_data WHERE object_id = 315;\nselect * from crm_field_data where object_id = 260;\n\nselect * from generic_ai_prompts where subject_id = 315;\n\nselect * from teams; # 36, 21, 121, james.graham@bullhorn.jiminny.com\nSELECT * FROM social_accounts WHERE sociable_id = 121 and provider = 'bullhorn';\n\n# ************************************************************************************\nselect * from teams where id = 1;\nselect * from crm_configurations where id = 39;\nselect * from users where team_id = 1;\nselect u.email, cp.* from users u\njoin crm_profiles cp on u.id = cp.user_id\nwhere u.team_id = 1;\n# 1 - 00541000004281rAAA\n# 204 - 0052g000003freeAAA\n# 429 - 0052g000003qGOiAAM\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 1\nand sa.provider = 'salesforce';\n\nselect * from activities where type = 'softphone'\nand created_at > '2024-12-11 15:24:36' order by id desc;\n\nselect * from activity_providers where team_id = 1;\nselect * from activity_provider_users where activity_provider_id = 328;\n\nselect * from opportunities where crm_configuration_id = 39\nAND account_id = 178 AND is_closed = false\norder by created_at DESC;\n\nselect * from contacts where id = 3952;\nselect * from accounts where id = 178;\n\n# ************************************************************************************\nselect * from teams where id = 36;\nselect * from crm_configurations where id = 21;\nselect * from users where team_id = 36;\nselect u.email, cp.* from users u\njoin crm_profiles cp on u.id = cp.user_id\nwhere u.team_id = 36;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 36\nand sa.provider = 'bullhorn';\n\nselect * from social_accounts where id = 348;\nUPDATE social_accounts SET\nprovider_user_token = '21442_6802599_91:41179a58-21e7-4d7c-ad58-56bb666b2f65',\nprovider_refresh_token = '21442_6802599_91:01c6b335-3f2a-42e4-85ff-8a08fa65fceb',\nexpires = 1733998131,\nstate = 'connected'\nWHERE id = 348;\n\n# ************************************************************************************\nselect * from teams where id = 31;\nselect * from crm_configurations where id = 18;\n\nselect * from users where team_id = 31; # 257\nselect u.email, cp.* from users u\njoin crm_profiles cp on u.id = cp.user_id\nwhere u.team_id = 31;\n\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 31\nand sa.provider = 'close';\n\nselect * from contacts where crm_configuration_id = 18;\n\n# ********************** NEPTUNE **************************************************************\nselect * from teams;\nselect * from users where id IN (1030, 1035, 1052);\nselect * from crm_configurations;\n\nselect * from users where team_id = 65; # 257\nselect * from team_settings where team_id = 65; # 257\nselect * from invitations where team_id = 65; # 257\nselect * from users where email = 'integration-account@jiminny.com'; # 257\nselect u.email, cp.* from users u\njoin crm_profiles cp on u.id = cp.user_id\nwhere u.team_id = 65;\n\nselect * from crm_configurations where id = 53;\nselect * from accounts where crm_configuration_id = 53 order by id desc;\nselect * from leads where crm_configuration_id = 53 order by id desc;\nselect * from contacts where crm_configuration_id = 53 order by id desc;\nselect * from opportunities where crm_configuration_id = 53 order by id desc;\nselect * from crm_profiles where crm_configuration_id = 53 order by id desc;\nselect * from crm_fields where crm_configuration_id = 53 order by id desc;\nselect * from crm_field_values where crm_field_id = 3341 order by id desc;\nselect * from crm_layouts where crm_configuration_id = 53 order by id desc;\nselect * from stages where crm_configuration_id = 53 order by id desc;\n\n\nselect * from crm_profiles where crm_configuration_id = 13;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 65\nand sa.provider = 'integration-app';\n\nselect * from contacts where crm_configuration_id = 13;\n\nselect * from social_accounts where sociable_id = 283;\n\nSELECT * FROM opportunities WHERE crm_provider_id = '006O400000E9bzeIAB';\n\nselect * from activity_providers where team_id = 65;\nSELECT * FROM activities WHERE crm_configuration_id IN (51, 52, 53);\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 65\n;\n\n# ***************************** STAGING ********************************************\nSELECT * FROM teams;\nSELECT * FROM teams WHERE id = 88;\nSELECT * FROM teams WHERE id = 89;\nselect * from team_settings where team_id = 89;\nSELECT * FROM users WHERE team_id = 89;\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 89;\n\nselect * from users;\nSELECT * FROM social_accounts WHERE sociable_id = 1761;\nSELECT * FROM crm_configurations WHERE id = 70;\nselect * from accounts where crm_configuration_id = 70 order by id desc;\nselect * from leads where crm_configuration_id = 70 order by id desc;\nselect * from contacts where crm_configuration_id = 70 order by id desc;\nselect * from opportunities where crm_configuration_id = 70 order by id desc;\nselect * from crm_profiles where crm_configuration_id = 70 order by id desc;\nselect * from crm_fields where crm_configuration_id = 70 order by id desc;\nselect * from crm_field_values where crm_field_id = 3536 order by id desc;\nselect * from crm_layouts where crm_configuration_id = 70 order by id desc;\nselect * from stages where crm_configuration_id = 70 order by id desc;\nselect * from business_processes where crm_configuration_id = 70 order by id desc;\nselect * from business_process_stages where business_process_id = 34;\n\nselect * from contacts where id = 10468;\n\nselect * from crm_layouts where crm_configuration_id = 70;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 388;\nSELECT * FROM crm_fields WHERE id IN (3533,3534,3535);\n\nselect * from activities where crm_configuration_id = 70\nand (account_id IS NOT NULL or lead_id IS NOT NULL or contact_id IS NOT NULL or opportunity_id IS NOT NULL) order by id desc;\n\nSELECT * FROM activities WHERE uuid_to_bin('2e10b60f-8a61-41c5-a3d4-28835353dc65') = uuid;\nSELECT * FROM activities where crm_configuration_id = 69 ;\n\nSELECT * FROM users WHERE email LIKE '%jiminny_web_sa2@jiminny.com%';\nSELECT * FROM activities WHERE uuid_to_bin('5a150c93-40fc-42ec-b3bd-c1d328e09f6e') = uuid;\nSELECT * FROM opportunities WHERE id = 385;\n\nselect * from participants p\njoin activities a on p.activity_id = a.id\nwhere a.crm_configuration_id = 70\nand (p.lead_id IS NOT NULL or p.contact_id IS NOT NULL);\nSELECT * FROM participants WHERE id = 1013638;\n\nselect * from teams where id = 90;\nselect * from users where team_id = 90;\nselect * from social_accounts where social_accounts.sociable_id IN (1960,1760);\nSELECT * FROM crm_profiles WHERE crm_configuration_id = 71;\nselect * from invitations where team_id = 90;\n\nselect * from crm_configurations where id = 71;\nselect * from accounts where crm_configuration_id = 71 order by id desc;\nselect * from leads where crm_configuration_id = 71 order by id desc;\nselect * from contacts where crm_configuration_id = 71 order by id desc;\nselect * from opportunities where crm_configuration_id = 71 order by id desc;\nselect * from crm_profiles where crm_configuration_id = 71 order by id desc;\nselect * from crm_fields where crm_configuration_id = 71 order by id desc;\nselect * from crm_field_values where crm_field_id = 3341 order by id desc;\nselect * from crm_layouts where crm_configuration_id = 71 order by id desc;\nselect * from stages where crm_configuration_id = 71 order by id desc;\n\nselect * from users order by secondary_email desc;\nselect u.id, u.email, u.status, sa.id, sa.provider_user_id from social_accounts sa\n join users u on sa.sociable_id = u.id\nwhere sa.provider = 'google' and u.email LIKE 'aneliya%';\n\nselect * from failed_jobs order by id desc;\n\nselect * from users where email = 'ben.allwright@learningpeople.co.uk' or secondary_email = 'ben.allwright@learningpeople.co.uk';\n\nselect * from teams;\nSELECT * FROM crm_profiles WHERE crm_configuration_id = 39;\nSELECT * FROM crm_fields WHERE crm_configuration_id = 39 and object_type = 'task';\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 1\nand sa.provider = 'salesforce';\n\n# ************************************************************************************\nSELECT * FROM activities WHERE uuid_to_bin('c38b3895-fd0f-4b1f-9fb2-c170dba137c6') = uuid;\nSELECT * FROM crm_configurations WHERE id = 70;\n\nselect * from teams where id = 1;\nselect * from groups where team_id = 1;\nselect * from users where team_id = 1;\n\nselect o.id, o.name,o.close_date, u.id, u.name, u.group_id, r.id, r.display_name, g.name, g.scope from opportunities o\njoin users u on o.user_id = u.id\njoin groups g on u.group_id = g.id\njoin role_user ru on u.id = ru.user_id\njoin roles r on ru.role_id = r.id\nwhere o.crm_configuration_id = 39 and close_date > '2024-01-01 00:00:00';\n\nselect * from role_user where user_id = 143;\nselect * from roles;\n\nselect * from role_user;\nselect * from groups where id = 9;\nselect * from scope_groups where group_id = 9;\n\n# ************************************************************************************\nselect * from teams where id = 36;\nselect * from crm_configurations;\nSELECT * FROM social_accounts WHERE sociable_id = 121;\n\nhttps://crmsandbox.zoho.com/crm/jiminnyw4/tab/Leads/4776201000005049105\nhttps://crmsandbox.zoho.com/crm/\n\nhttps://crm.zoho.com/crm/org3469620/tab/Leads/230045000229559080\n https://crm.zoho.com/crm/\n org3469620\n\nSELECT * FROM activities WHERE uuid_to_bin('03382d20-c8bc-48e7-a3d4-90b52fa5ceab') = uuid;\n\nselect * from users where email LIKE \"%mobile_automation_%\";\nselect * from social_accounts where sociable_id IN (2228);\nselect * from crm_profiles where user_id IN (2222,2223,2226,2227);\n\nselect * from teams order by id desc;\nSELECT * FROM users WHERE id = 2229;\nSELECT * FROM crm_profiles WHERE user_id = 2229;\nselect * from opportunities where crm_configuration_id = 88;\nselect * from crm_fields where crm_configuration_id = 88;\nselect * from crm_profiles where crm_configuration_id = 88;\n\nSELECT * FROM teams WHERE id = 1;\n\nSELECT * FROM users WHERE id = 143;\nSELECT * FROM users WHERE uuid_to_bin('fde193d3-06a2-4e1a-8895-62b94039215d') = uuid;\nSELECT * FROM teams WHERE uuid_to_bin('73385071-a756-42ae-9c73-8b53f2309467') = uuid;\n\nhttps://app.staging.jiminny.com/ondemand?\n min_duration=1\n &\n only_recorded=1\n &\n user_id%5B%5D=641f1acb-16b8-42d1-8726-df52979dad0e\n &\n sequence_number=2\n\n select * from users where team_id = 1 and email like '%stoyan%'\n\nselect * from coaching_feedbacks;\n\nselect * from teams;\nSELECT * FROM users WHERE team_id = 36;\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 19\nand sa.provider = 'pipedrive';\n\nselect * from users where id = 143;\n\nSELECT * FROM users WHERE uuid_to_bin('73180eeb-33de-4065-977d-ccbe0e6c94fc') = uuid;\nSELECT * FROM teams WHERE uuid_to_bin('73180eeb-33de-4065-977d-ccbe0e6c94fc') = uuid;\nSELECT * FROM activity_shares WHERE uuid_to_bin('73180eeb-33de-4065-977d-ccbe0e6c94fc') = uuid;\n\nselect * from users where team_id = 2;\nselect * from activities where crm_configuration_id = 39\nand activities.scheduled_start_time BETWEEN '2025-04-09 00:00:00' AND '2025-04-09 23:59:59'\nAND user_id = 143\norder by id desc;\n\n# ************************************************************************************\nselect * from teams where id = 142; # 2312, 126\nselect * from team_settings;\nselect * from users where team_id = 142; # 21642\nSELECT * FROM social_accounts WHERE sociable_id = 21642;\nSELECT * FROM crm_profiles cp join users u ON u.id = cp.user_id WHERE team_id = 142;\nselect * from crm_profiles where id IN (93);\nselect * from invitations;\nselect * from team_features where team_id = 1;\n\nSELECT * FROM crm_configurations WHERE id = 126;\nselect * from accounts where crm_configuration_id = 126 order by id desc;\nselect * from leads where crm_configuration_id = 126 order by id desc;\nselect * from contacts where crm_configuration_id = 126 order by id desc;\nselect * from opportunities where crm_configuration_id = 126 order by id desc;\nselect * from crm_profiles where crm_configuration_id = 126 order by id desc;\nselect * from crm_fields where crm_configuration_id = 126 # 11060\n# and type IN ('picklist', 'status')\n# and object_type = 'task'\norder by id desc;\n# 5731,5732,5733\nselect DISTINCT crm_field_id from crm_field_values where crm_field_id IN (11151,12239,12215,12185,12175,12165,12144,12137,12127,12109,12107,12105,12103,12092,12037,12005,12003,11987,11969,11958,11951,11942,11931,11924,11921,11917,11915,11901,11893,11883,11872,11870,11868,11866,11839,11833,11821,11793,11780,11777,11769,11757,11737,11735,11656,11645,11638,11629,11618,11611,11602,11591,11584,11581,11558,11544,11543,11534,11532,11529,11527,11503,11497,11493,11488,11470,11468,11457,11455,11397,11387,11372,11363,11348,11323,11318,11309,11301,11300,11292,11290,11286,11284,11256,11252,11242,11237,11233,11219,11176,11160) order by id desc;\nselect * from crm_layouts where crm_configuration_id = 126 order by id desc;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id in (300,299,298);\nselect * from stages where crm_configuration_id = 126 order by id desc;\nselect * from business_processes where crm_configuration_id = 126 order by id desc;\nselect * from business_process_stages where business_process_id IN (76,75,74,73);\nselect * from playbooks where team_id = 142;\nselect * from playbook_layouts where playbook_id IN (108);\nSELECT * FROM playbook_categories WHERE playbook_id IN (108);\n\nselect * from teams where id = 130;\nSELECT * FROM social_accounts WHERE sociable_id = 2291;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 2\nand sa.provider = 'hubspot';\n\nSELECT * FROM activities\n WHERE crm_configuration_id = 110;\n\nselect * from teams;\nselect * from crm_configurations;\n\nSELECT * FROM activities WHERE id = 628773;\nSELECT * FROM crm_profiles WHERE user_id = 1460;\nSELECT * FROM social_accounts WHERE sociable_id = 2291;\n\nselect * from teams;\nselect ru.*, pr.*, p.* from users u join role_user ru on ru.user_id = u.id\njoin permission_role pr on pr.role_id = ru.role_id\n join permissions p on p.id = pr.permission_id\nwhere team_id = 495 and p.name IN ('dial');\n\nselect * from teams where id = 145;\nselect * from crm_configurations where id = 129;\nselect * from social_accounts where sociable_id = 2317;\nSELECT * FROM activities WHERE uuid_to_bin('8dbab184-a333-4268-ad57-fb41f8d53a9a') = uuid;\n\nselect * from teams where id = 1;\nSELECT * FROM crm_layouts WHERE crm_configuration_id = 39;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 280;\nSELECT * FROM crm_layout_entities WHERE id = 5507;\nSELECT * FROM crm_fields WHERE crm_configuration_id = 39 and object_type IN ('event');\n\nselect * from teams;\nselect * from activities where crm_configuration_id = 14;\n\nSELECT * FROM social_accounts where provider = 'copper';\n\nselect * from activities where id = 628467;\nselect * from participants where activity_id = 628467;\n\nSELECT * FROM contacts WHERE id = 3969;\nSELECT * FROM accounts WHERE id = 177;\n\nSELECT * FROM activities WHERE uuid_to_bin('4eb54c77-cfa3-2bd4-84a7-9ed46a21c988') = uuid;\n\n# ********************* BH\nselect * from teams where id = 36;\nSELECT * FROM crm_configurations WHERE id = 21;\nselect * from activities where crm_configuration_id = 21 and id = 607901;\nselect * from activities where crm_configuration_id = 21;\n\nselect * roles;\nselect * from permissions;\nselect * from permission_role where permission_id = 226;\n\nselect * from migrations order by id desc;\n\n# mercury\n# neptune\n# earth\n\nselect * from teams;\nselect * from teams where id = 19;\nselect * from teams where id = 27;\nselect * from users where team_id = 27;\nSELECT * FROM crm_configurations WHERE id = 42;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 19\nand sa.provider = 'pipedrive';\n\nselect * from activities where id = 631461;\nSELECT * FROM crm_field_values WHERE crm_field_id = 180;\n\nselect * from teams where id = 2;\nSELECT * FROM social_accounts WHERE sociable_id = 89;\n\nSELECT * FROM activities WHERE uuid_to_bin('ba0c029a-bc14-4e17-8603-64174acebcbb') = uuid; # 634273\nselect * from activity_summary_logs where activity_id = 634273;\n\nselect * from sidekick_settings where team_id = 2;\n\nselect * from teams; # 2, 2\nSELECT * FROM crm_configurations WHERE team_id = 2; # 2\nselect * from team_features where team_id = 2;\nselect * from features;\nSELECT * FROM opportunities WHERE crm_configuration_id = 2 and crm_provider_id = '51317301383';\nSELECT * FROM opportunities WHERE crm_configuration_id = 2 order by id desc;\n\nselect * from automated_reports order by id desc;\nselect * from automated_report_results order by id desc;\nselect * from users where team_id = 1 and id IN (7160, 3248);\nselect * from migrations order by id desc;\n\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 1 and sa.provider = 'salesforce';\n\nselect * from teams where id = 1;\nselect * from groups g JOIN playbooks p on g.playbook_id = p.id where g.team_id = 1;\nselect * from groups where id = 565;\nselect * from playbooks where team_id = 1;\nselect * from playbooks where id = 175;\nselect * from playbook_categories where playbook_id = 175;\nselect * from users where team_id = 1;\nselect * from users where id = 7160;\nselect * from crm_profiles where user_id = 7160;\nselect * from features;\nselect\n *\n# id, uuid, type, provider, playbook_category_id, user_id, lead_id, contact_id, account_id, opportunity_id, stage_id,\n# crm_configuration_id, crm_provider_id, transcription_id, status\nfrom activities where crm_configuration_id = 1 and type = 'conference'\n# and crm_provider_id IS NOT NULL\nand provider != 'uploader' and actual_start_time IS NOT NULL\nORDER by id desc;\nselect * from activities where id = 54747783; # 00UO400000pCzojMAC\n\nselect p.id, p.activity_type, pc.id, pc.name\nFROM playbooks p\njoin playbook_categories pc on p.id = pc.playbook_id\nwhere p.team_id = 1 and p.activity_type = 'event';\n\nSELECT * FROM crm_fields WHERE crm_configuration_id = 1 and object_type = 'event';\nSELECT * FROM crm_field_values WHERE crm_field_id = 4;\n\nselect * from crm_layouts cl join playbook_layouts pl on cl.id = pl.layout_id\nwhere crm_configuration_id = 1 and pl.playbook_id = 175;\n\nselect * from teams;\nSELECT r.* FROM automated_reports r\njoin teams t on r.team_id = t.id\nWHERE r.frequency = 'daily'\n and r.status = 1\nAND t.status = 'active'\nAND (r.expires_at >= now() OR r.expires_at IS NULL);\n\nselect * from automated_report_results where report_id IN (18, 33);\n\nselect * from activity_searches where id = 10932;\nselect * from activity_search_filters where activity_search_id = 10932;\nselect * from automated_reports;\nselect * from automated_report_results where report_id IN (34, 35);","depth":4,"value":"SELECT * FROM teams WHERE id = 1;\n\nselect * from crm_layouts where crm_configuration_id = 39;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 283;\nSELECT * FROM crm_fields WHERE id = 2234;\nSELECT * FROM crm_field_values WHERE crm_field_id = 2234;\n\nselect * from crm_profiles where user_id = 143;\n\nselect * from record_types where crm_configuration_id = 39; # 0121K000001MHElQAO,0121K000001MHEqQAO\nselect * from business_processes where crm_configuration_id = 39;\n# 01941000000H669AAC, 01941000000H66JAAS\n\nselect * from record_type_field_values\n where record_type_id IN (24);\n\nselect * from crm_field_values where id IN (2730);\n\nselect * from crm_configurations where id = 39;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 1\nand sa.provider = 'salesforce'; #1035\n\n\nselect * from users where team_id = 1; # 222 group 3\nSELECT * FROM activities WHERE user_id = 222 order by id desc;\nselect * from sidekick_settings where team_id = 1;\nselect * from teams where id = 1;\nselect * from team_features where team_id = 1;\n\nselect * from activities where crm_configuration_id = 2\nand provider = 'ms-teams' and id = 608765;\n\nSELECT * FROM activities WHERE crm_configuration_id = 2 and crm_provider_id = '59523413338';\n\nselect * from sidekick_settings where team_id = 2;\n\nSELECT * FROM activities WHERE id = 608660;\nselect * from activity_summary_logs where activity_id = 608660;\nselect * from ai_prompts where transcription_id = 11214;\n\n# ********************************************************************************************************\nSELECT * FROM activities WHERE uuid_to_bin('ed78a437-2804-450e-ab2f-56ab1c641346') = uuid;\n# id: 608818, crm: 59628809737\nSELECT * FROM activities WHERE uuid_to_bin('36b06e55-afdd-4782-8dee-c624cd0af191') = uuid;\n# id: 608821, crm: 59632069252\nSELECT ce.start_time, ce.end_time, a.id, a.uuid, crm_provider_id, calendar_event_id, title,\nplaybook_category_id, user_id, lead_id, contact_id, account_id, opportunity_id,\nscheduled_start_time, scheduled_end_time, actual_start_time, actual_end_time, a.created_at\nFROM activities a\njoin calendar_events ce on a.calendar_event_id = ce.id\nWHERE a.id IN (608818, 608821);\n\nselect * from users where team_id = 1;\nselect * from team_settings where team_id = 1;\nselect * from crm_profiles where crm_configuration_id = 39 order by user_id;\n\nselect * from team_features where team_id = 1;\n\nselect * from users where team_id = 2;\n\nSELECT * FROM activities WHERE uuid_to_bin('ec7647e9-5225-458b-b475-f31aa2769204') = uuid; # 612639\n# Preslava N. Ivanova, grou id 3\n\nSELECT * FROM opportunities WHERE uuid_to_bin('a2928fe5-aec5-46cb-85d9-7654c89e46a6') = uuid;\n\nselect * from activities where opportunity_id = 344 and actual_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00';\n\nselect\n a.id,\n a.type,\n a.scheduled_start_time,\n a.actual_start_time,\n a.created_at,\n a.opportunity_id,\n a.status\nFROM activities a\nWHERE opportunity_id = 344\nand status IN ('completed', 'received', 'delivered')\nand (\n (a.actual_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00')\nOR (a.created_at between '2024-10-11 00:00:00' and '2024-10-12 00:00:00')\nOR (a.scheduled_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00'))\n;\n\nSELECT * FROM users WHERE id = 222;\n\nSELECT * FROM crm_profiles WHERE user_id = 222;\nselect * from crm_layouts where crm_configuration_id = 39;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 281;\n\nselect * from group_deal_risk_types;\n\nselect * from opportunities where team_id = 1;\n\nSELECT * FROM opportunities WHERE id = 315;\nSELECT * FROM crm_field_data WHERE object_id = 315;\nselect * from crm_field_data where object_id = 260;\n\nselect * from generic_ai_prompts where subject_id = 315;\n\nselect * from teams; # 36, 21, 121, james.graham@bullhorn.jiminny.com\nSELECT * FROM social_accounts WHERE sociable_id = 121 and provider = 'bullhorn';\n\n# ************************************************************************************\nselect * from teams where id = 1;\nselect * from crm_configurations where id = 39;\nselect * from users where team_id = 1;\nselect u.email, cp.* from users u\njoin crm_profiles cp on u.id = cp.user_id\nwhere u.team_id = 1;\n# 1 - 00541000004281rAAA\n# 204 - 0052g000003freeAAA\n# 429 - 0052g000003qGOiAAM\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 1\nand sa.provider = 'salesforce';\n\nselect * from activities where type = 'softphone'\nand created_at > '2024-12-11 15:24:36' order by id desc;\n\nselect * from activity_providers where team_id = 1;\nselect * from activity_provider_users where activity_provider_id = 328;\n\nselect * from opportunities where crm_configuration_id = 39\nAND account_id = 178 AND is_closed = false\norder by created_at DESC;\n\nselect * from contacts where id = 3952;\nselect * from accounts where id = 178;\n\n# ************************************************************************************\nselect * from teams where id = 36;\nselect * from crm_configurations where id = 21;\nselect * from users where team_id = 36;\nselect u.email, cp.* from users u\njoin crm_profiles cp on u.id = cp.user_id\nwhere u.team_id = 36;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 36\nand sa.provider = 'bullhorn';\n\nselect * from social_accounts where id = 348;\nUPDATE social_accounts SET\nprovider_user_token = '21442_6802599_91:41179a58-21e7-4d7c-ad58-56bb666b2f65',\nprovider_refresh_token = '21442_6802599_91:01c6b335-3f2a-42e4-85ff-8a08fa65fceb',\nexpires = 1733998131,\nstate = 'connected'\nWHERE id = 348;\n\n# ************************************************************************************\nselect * from teams where id = 31;\nselect * from crm_configurations where id = 18;\n\nselect * from users where team_id = 31; # 257\nselect u.email, cp.* from users u\njoin crm_profiles cp on u.id = cp.user_id\nwhere u.team_id = 31;\n\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 31\nand sa.provider = 'close';\n\nselect * from contacts where crm_configuration_id = 18;\n\n# ********************** NEPTUNE **************************************************************\nselect * from teams;\nselect * from users where id IN (1030, 1035, 1052);\nselect * from crm_configurations;\n\nselect * from users where team_id = 65; # 257\nselect * from team_settings where team_id = 65; # 257\nselect * from invitations where team_id = 65; # 257\nselect * from users where email = 'integration-account@jiminny.com'; # 257\nselect u.email, cp.* from users u\njoin crm_profiles cp on u.id = cp.user_id\nwhere u.team_id = 65;\n\nselect * from crm_configurations where id = 53;\nselect * from accounts where crm_configuration_id = 53 order by id desc;\nselect * from leads where crm_configuration_id = 53 order by id desc;\nselect * from contacts where crm_configuration_id = 53 order by id desc;\nselect * from opportunities where crm_configuration_id = 53 order by id desc;\nselect * from crm_profiles where crm_configuration_id = 53 order by id desc;\nselect * from crm_fields where crm_configuration_id = 53 order by id desc;\nselect * from crm_field_values where crm_field_id = 3341 order by id desc;\nselect * from crm_layouts where crm_configuration_id = 53 order by id desc;\nselect * from stages where crm_configuration_id = 53 order by id desc;\n\n\nselect * from crm_profiles where crm_configuration_id = 13;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 65\nand sa.provider = 'integration-app';\n\nselect * from contacts where crm_configuration_id = 13;\n\nselect * from social_accounts where sociable_id = 283;\n\nSELECT * FROM opportunities WHERE crm_provider_id = '006O400000E9bzeIAB';\n\nselect * from activity_providers where team_id = 65;\nSELECT * FROM activities WHERE crm_configuration_id IN (51, 52, 53);\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 65\n;\n\n# ***************************** STAGING ********************************************\nSELECT * FROM teams;\nSELECT * FROM teams WHERE id = 88;\nSELECT * FROM teams WHERE id = 89;\nselect * from team_settings where team_id = 89;\nSELECT * FROM users WHERE team_id = 89;\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 89;\n\nselect * from users;\nSELECT * FROM social_accounts WHERE sociable_id = 1761;\nSELECT * FROM crm_configurations WHERE id = 70;\nselect * from accounts where crm_configuration_id = 70 order by id desc;\nselect * from leads where crm_configuration_id = 70 order by id desc;\nselect * from contacts where crm_configuration_id = 70 order by id desc;\nselect * from opportunities where crm_configuration_id = 70 order by id desc;\nselect * from crm_profiles where crm_configuration_id = 70 order by id desc;\nselect * from crm_fields where crm_configuration_id = 70 order by id desc;\nselect * from crm_field_values where crm_field_id = 3536 order by id desc;\nselect * from crm_layouts where crm_configuration_id = 70 order by id desc;\nselect * from stages where crm_configuration_id = 70 order by id desc;\nselect * from business_processes where crm_configuration_id = 70 order by id desc;\nselect * from business_process_stages where business_process_id = 34;\n\nselect * from contacts where id = 10468;\n\nselect * from crm_layouts where crm_configuration_id = 70;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 388;\nSELECT * FROM crm_fields WHERE id IN (3533,3534,3535);\n\nselect * from activities where crm_configuration_id = 70\nand (account_id IS NOT NULL or lead_id IS NOT NULL or contact_id IS NOT NULL or opportunity_id IS NOT NULL) order by id desc;\n\nSELECT * FROM activities WHERE uuid_to_bin('2e10b60f-8a61-41c5-a3d4-28835353dc65') = uuid;\nSELECT * FROM activities where crm_configuration_id = 69 ;\n\nSELECT * FROM users WHERE email LIKE '%jiminny_web_sa2@jiminny.com%';\nSELECT * FROM activities WHERE uuid_to_bin('5a150c93-40fc-42ec-b3bd-c1d328e09f6e') = uuid;\nSELECT * FROM opportunities WHERE id = 385;\n\nselect * from participants p\njoin activities a on p.activity_id = a.id\nwhere a.crm_configuration_id = 70\nand (p.lead_id IS NOT NULL or p.contact_id IS NOT NULL);\nSELECT * FROM participants WHERE id = 1013638;\n\nselect * from teams where id = 90;\nselect * from users where team_id = 90;\nselect * from social_accounts where social_accounts.sociable_id IN (1960,1760);\nSELECT * FROM crm_profiles WHERE crm_configuration_id = 71;\nselect * from invitations where team_id = 90;\n\nselect * from crm_configurations where id = 71;\nselect * from accounts where crm_configuration_id = 71 order by id desc;\nselect * from leads where crm_configuration_id = 71 order by id desc;\nselect * from contacts where crm_configuration_id = 71 order by id desc;\nselect * from opportunities where crm_configuration_id = 71 order by id desc;\nselect * from crm_profiles where crm_configuration_id = 71 order by id desc;\nselect * from crm_fields where crm_configuration_id = 71 order by id desc;\nselect * from crm_field_values where crm_field_id = 3341 order by id desc;\nselect * from crm_layouts where crm_configuration_id = 71 order by id desc;\nselect * from stages where crm_configuration_id = 71 order by id desc;\n\nselect * from users order by secondary_email desc;\nselect u.id, u.email, u.status, sa.id, sa.provider_user_id from social_accounts sa\n join users u on sa.sociable_id = u.id\nwhere sa.provider = 'google' and u.email LIKE 'aneliya%';\n\nselect * from failed_jobs order by id desc;\n\nselect * from users where email = 'ben.allwright@learningpeople.co.uk' or secondary_email = 'ben.allwright@learningpeople.co.uk';\n\nselect * from teams;\nSELECT * FROM crm_profiles WHERE crm_configuration_id = 39;\nSELECT * FROM crm_fields WHERE crm_configuration_id = 39 and object_type = 'task';\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 1\nand sa.provider = 'salesforce';\n\n# ************************************************************************************\nSELECT * FROM activities WHERE uuid_to_bin('c38b3895-fd0f-4b1f-9fb2-c170dba137c6') = uuid;\nSELECT * FROM crm_configurations WHERE id = 70;\n\nselect * from teams where id = 1;\nselect * from groups where team_id = 1;\nselect * from users where team_id = 1;\n\nselect o.id, o.name,o.close_date, u.id, u.name, u.group_id, r.id, r.display_name, g.name, g.scope from opportunities o\njoin users u on o.user_id = u.id\njoin groups g on u.group_id = g.id\njoin role_user ru on u.id = ru.user_id\njoin roles r on ru.role_id = r.id\nwhere o.crm_configuration_id = 39 and close_date > '2024-01-01 00:00:00';\n\nselect * from role_user where user_id = 143;\nselect * from roles;\n\nselect * from role_user;\nselect * from groups where id = 9;\nselect * from scope_groups where group_id = 9;\n\n# ************************************************************************************\nselect * from teams where id = 36;\nselect * from crm_configurations;\nSELECT * FROM social_accounts WHERE sociable_id = 121;\n\nhttps://crmsandbox.zoho.com/crm/jiminnyw4/tab/Leads/4776201000005049105\nhttps://crmsandbox.zoho.com/crm/\n\nhttps://crm.zoho.com/crm/org3469620/tab/Leads/230045000229559080\n https://crm.zoho.com/crm/\n org3469620\n\nSELECT * FROM activities WHERE uuid_to_bin('03382d20-c8bc-48e7-a3d4-90b52fa5ceab') = uuid;\n\nselect * from users where email LIKE \"%mobile_automation_%\";\nselect * from social_accounts where sociable_id IN (2228);\nselect * from crm_profiles where user_id IN (2222,2223,2226,2227);\n\nselect * from teams order by id desc;\nSELECT * FROM users WHERE id = 2229;\nSELECT * FROM crm_profiles WHERE user_id = 2229;\nselect * from opportunities where crm_configuration_id = 88;\nselect * from crm_fields where crm_configuration_id = 88;\nselect * from crm_profiles where crm_configuration_id = 88;\n\nSELECT * FROM teams WHERE id = 1;\n\nSELECT * FROM users WHERE id = 143;\nSELECT * FROM users WHERE uuid_to_bin('fde193d3-06a2-4e1a-8895-62b94039215d') = uuid;\nSELECT * FROM teams WHERE uuid_to_bin('73385071-a756-42ae-9c73-8b53f2309467') = uuid;\n\nhttps://app.staging.jiminny.com/ondemand?\n min_duration=1\n &\n only_recorded=1\n &\n user_id%5B%5D=641f1acb-16b8-42d1-8726-df52979dad0e\n &\n sequence_number=2\n\n select * from users where team_id = 1 and email like '%stoyan%'\n\nselect * from coaching_feedbacks;\n\nselect * from teams;\nSELECT * FROM users WHERE team_id = 36;\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 19\nand sa.provider = 'pipedrive';\n\nselect * from users where id = 143;\n\nSELECT * FROM users WHERE uuid_to_bin('73180eeb-33de-4065-977d-ccbe0e6c94fc') = uuid;\nSELECT * FROM teams WHERE uuid_to_bin('73180eeb-33de-4065-977d-ccbe0e6c94fc') = uuid;\nSELECT * FROM activity_shares WHERE uuid_to_bin('73180eeb-33de-4065-977d-ccbe0e6c94fc') = uuid;\n\nselect * from users where team_id = 2;\nselect * from activities where crm_configuration_id = 39\nand activities.scheduled_start_time BETWEEN '2025-04-09 00:00:00' AND '2025-04-09 23:59:59'\nAND user_id = 143\norder by id desc;\n\n# ************************************************************************************\nselect * from teams where id = 142; # 2312, 126\nselect * from team_settings;\nselect * from users where team_id = 142; # 21642\nSELECT * FROM social_accounts WHERE sociable_id = 21642;\nSELECT * FROM crm_profiles cp join users u ON u.id = cp.user_id WHERE team_id = 142;\nselect * from crm_profiles where id IN (93);\nselect * from invitations;\nselect * from team_features where team_id = 1;\n\nSELECT * FROM crm_configurations WHERE id = 126;\nselect * from accounts where crm_configuration_id = 126 order by id desc;\nselect * from leads where crm_configuration_id = 126 order by id desc;\nselect * from contacts where crm_configuration_id = 126 order by id desc;\nselect * from opportunities where crm_configuration_id = 126 order by id desc;\nselect * from crm_profiles where crm_configuration_id = 126 order by id desc;\nselect * from crm_fields where crm_configuration_id = 126 # 11060\n# and type IN ('picklist', 'status')\n# and object_type = 'task'\norder by id desc;\n# 5731,5732,5733\nselect DISTINCT crm_field_id from crm_field_values where crm_field_id IN (11151,12239,12215,12185,12175,12165,12144,12137,12127,12109,12107,12105,12103,12092,12037,12005,12003,11987,11969,11958,11951,11942,11931,11924,11921,11917,11915,11901,11893,11883,11872,11870,11868,11866,11839,11833,11821,11793,11780,11777,11769,11757,11737,11735,11656,11645,11638,11629,11618,11611,11602,11591,11584,11581,11558,11544,11543,11534,11532,11529,11527,11503,11497,11493,11488,11470,11468,11457,11455,11397,11387,11372,11363,11348,11323,11318,11309,11301,11300,11292,11290,11286,11284,11256,11252,11242,11237,11233,11219,11176,11160) order by id desc;\nselect * from crm_layouts where crm_configuration_id = 126 order by id desc;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id in (300,299,298);\nselect * from stages where crm_configuration_id = 126 order by id desc;\nselect * from business_processes where crm_configuration_id = 126 order by id desc;\nselect * from business_process_stages where business_process_id IN (76,75,74,73);\nselect * from playbooks where team_id = 142;\nselect * from playbook_layouts where playbook_id IN (108);\nSELECT * FROM playbook_categories WHERE playbook_id IN (108);\n\nselect * from teams where id = 130;\nSELECT * FROM social_accounts WHERE sociable_id = 2291;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 2\nand sa.provider = 'hubspot';\n\nSELECT * FROM activities\n WHERE crm_configuration_id = 110;\n\nselect * from teams;\nselect * from crm_configurations;\n\nSELECT * FROM activities WHERE id = 628773;\nSELECT * FROM crm_profiles WHERE user_id = 1460;\nSELECT * FROM social_accounts WHERE sociable_id = 2291;\n\nselect * from teams;\nselect ru.*, pr.*, p.* from users u join role_user ru on ru.user_id = u.id\njoin permission_role pr on pr.role_id = ru.role_id\n join permissions p on p.id = pr.permission_id\nwhere team_id = 495 and p.name IN ('dial');\n\nselect * from teams where id = 145;\nselect * from crm_configurations where id = 129;\nselect * from social_accounts where sociable_id = 2317;\nSELECT * FROM activities WHERE uuid_to_bin('8dbab184-a333-4268-ad57-fb41f8d53a9a') = uuid;\n\nselect * from teams where id = 1;\nSELECT * FROM crm_layouts WHERE crm_configuration_id = 39;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 280;\nSELECT * FROM crm_layout_entities WHERE id = 5507;\nSELECT * FROM crm_fields WHERE crm_configuration_id = 39 and object_type IN ('event');\n\nselect * from teams;\nselect * from activities where crm_configuration_id = 14;\n\nSELECT * FROM social_accounts where provider = 'copper';\n\nselect * from activities where id = 628467;\nselect * from participants where activity_id = 628467;\n\nSELECT * FROM contacts WHERE id = 3969;\nSELECT * FROM accounts WHERE id = 177;\n\nSELECT * FROM activities WHERE uuid_to_bin('4eb54c77-cfa3-2bd4-84a7-9ed46a21c988') = uuid;\n\n# ********************* BH\nselect * from teams where id = 36;\nSELECT * FROM crm_configurations WHERE id = 21;\nselect * from activities where crm_configuration_id = 21 and id = 607901;\nselect * from activities where crm_configuration_id = 21;\n\nselect * roles;\nselect * from permissions;\nselect * from permission_role where permission_id = 226;\n\nselect * from migrations order by id desc;\n\n# mercury\n# neptune\n# earth\n\nselect * from teams;\nselect * from teams where id = 19;\nselect * from teams where id = 27;\nselect * from users where team_id = 27;\nSELECT * FROM crm_configurations WHERE id = 42;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 19\nand sa.provider = 'pipedrive';\n\nselect * from activities where id = 631461;\nSELECT * FROM crm_field_values WHERE crm_field_id = 180;\n\nselect * from teams where id = 2;\nSELECT * FROM social_accounts WHERE sociable_id = 89;\n\nSELECT * FROM activities WHERE uuid_to_bin('ba0c029a-bc14-4e17-8603-64174acebcbb') = uuid; # 634273\nselect * from activity_summary_logs where activity_id = 634273;\n\nselect * from sidekick_settings where team_id = 2;\n\nselect * from teams; # 2, 2\nSELECT * FROM crm_configurations WHERE team_id = 2; # 2\nselect * from team_features where team_id = 2;\nselect * from features;\nSELECT * FROM opportunities WHERE crm_configuration_id = 2 and crm_provider_id = '51317301383';\nSELECT * FROM opportunities WHERE crm_configuration_id = 2 order by id desc;\n\nselect * from automated_reports order by id desc;\nselect * from automated_report_results order by id desc;\nselect * from users where team_id = 1 and id IN (7160, 3248);\nselect * from migrations order by id desc;\n\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 1 and sa.provider = 'salesforce';\n\nselect * from teams where id = 1;\nselect * from groups g JOIN playbooks p on g.playbook_id = p.id where g.team_id = 1;\nselect * from groups where id = 565;\nselect * from playbooks where team_id = 1;\nselect * from playbooks where id = 175;\nselect * from playbook_categories where playbook_id = 175;\nselect * from users where team_id = 1;\nselect * from users where id = 7160;\nselect * from crm_profiles where user_id = 7160;\nselect * from features;\nselect\n *\n# id, uuid, type, provider, playbook_category_id, user_id, lead_id, contact_id, account_id, opportunity_id, stage_id,\n# crm_configuration_id, crm_provider_id, transcription_id, status\nfrom activities where crm_configuration_id = 1 and type = 'conference'\n# and crm_provider_id IS NOT NULL\nand provider != 'uploader' and actual_start_time IS NOT NULL\nORDER by id desc;\nselect * from activities where id = 54747783; # 00UO400000pCzojMAC\n\nselect p.id, p.activity_type, pc.id, pc.name\nFROM playbooks p\njoin playbook_categories pc on p.id = pc.playbook_id\nwhere p.team_id = 1 and p.activity_type = 'event';\n\nSELECT * FROM crm_fields WHERE crm_configuration_id = 1 and object_type = 'event';\nSELECT * FROM crm_field_values WHERE crm_field_id = 4;\n\nselect * from crm_layouts cl join playbook_layouts pl on cl.id = pl.layout_id\nwhere crm_configuration_id = 1 and pl.playbook_id = 175;\n\nselect * from teams;\nSELECT r.* FROM automated_reports r\njoin teams t on r.team_id = t.id\nWHERE r.frequency = 'daily'\n and r.status = 1\nAND t.status = 'active'\nAND (r.expires_at >= now() OR r.expires_at IS NULL);\n\nselect * from automated_report_results where report_id IN (18, 33);\n\nselect * from activity_searches where id = 10932;\nselect * from activity_search_filters where activity_search_id = 10932;\nselect * from automated_reports;\nselect * from automated_report_results where report_id IN (34, 35);","role_description":"text entry area","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.088194445,"height":0.027777778},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"102","depth":4,"role_description":"text"},{"role":"AXStaticText","text":"3","depth":4,"role_description":"text"},{"role":"AXStaticText","text":"34","depth":4,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Services\\Kiosk\\AutomatedReports;\n\nuse Carbon\\CarbonImmutable;\nuse Carbon\\CarbonInterface;\nuse Carbon\\Exceptions\\InvalidFormatException;\nuse DateTime;\nuse DateTimeInterface;\nuse DateTimeZone;\nuse Illuminate\\Contracts\\Bus\\Dispatcher as BusDispatcher;\nuse Illuminate\\Database\\Eloquent\\Builder;\nuse Illuminate\\Support\\Carbon;\nuse Illuminate\\Support\\Collection;\nuse Illuminate\\Support\\Facades\\Log;\nuse Illuminate\\Support\\Facades\\Storage;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinition\\InputTypeEnum;\nuse Jiminny\\Component\\AskAnything\\AskAnythingPromptService;\nuse Jiminny\\Component\\AskAnything\\Dtos\\AskAnythingPromptDto;\nuse Jiminny\\Component\\UrlGenerator\\Webhook;\nuse Jiminny\\Contracts\\Repositories\\PlaybookCategoryRepository;\nuse Jiminny\\Contracts\\Repositories\\TeamRepository;\nuse Jiminny\\Contracts\\Repositories\\UserRepository;\nuse Jiminny\\Exceptions\\ApplicationException;\nuse Jiminny\\Exceptions\\InvalidArgumentException;\nuse Jiminny\\Exceptions\\ModelNotFoundException;\nuse Jiminny\\Jobs\\AutomatedReports\\RequestGenerateReportJob;\nuse Jiminny\\Models\\Activity\\Search;\nuse Jiminny\\Models\\AskAnything\\AskAnythingPrompt;\nuse Jiminny\\Models\\AskAnything\\AskAnythingPromptTarget;\nuse Jiminny\\Models\\AutomatedReport;\nuse Jiminny\\Models\\AutomatedReportResult;\nuse Jiminny\\Models\\Contracts\\UserContract;\nuse Jiminny\\Models\\Feature\\FeatureEnum;\nuse Jiminny\\Models\\Team;\nuse Jiminny\\Models\\User;\nuse Jiminny\\Repositories\\AskAnythingRepository;\nuse Jiminny\\Repositories\\AutomatedReportsRepository;\nuse Jiminny\\Repositories\\GroupRepository;\nuse Jiminny\\Repositories\\SearchRepository;\nuse Jiminny\\Repositories\\StageRepository;\nuse Throwable;\n\nclass AutomatedReportsService\n{\n public const string TYPE_LOSS_ANALYSIS = 'loss_analysis';\n public const string TYPE_ASK_JIMINNY = 'ask_jiminny';\n\n /**\n * Standard report types (used by kiosk for existing automated reports).\n */\n // @TODO this will add filter, however if we need to control feature by FF we need conditional logic\n public const array TYPES = [\n ['id' => 'exec_summary', 'name' => 'Exec Summary'],\n ['id' => 'coaching_profiles', 'name' => 'Coaching Profiles'],\n ['id' => 'product_feedback', 'name' => 'Product Feedback'],\n ['id' => self::TYPE_LOSS_ANALYSIS, 'name' => 'Loss Analysis'],\n// ['id' => 'questions', 'name' => 'Questions'],\n// ['id' => 'statistical_quant', 'name' => 'Statistical Quantitative'],\n ];\n\n public const array ALL_TYPES = [\n ...self::TYPES,\n ['id' => self::TYPE_ASK_JIMINNY, 'name' => 'Ask Jiminny'],\n ];\n\n public const string FREQUENCY_DAILY = 'daily';\n public const string FREQUENCY_WEEKLY = 'weekly';\n public const string FREQUENCY_MONTHLY = 'monthly';\n public const string FREQUENCY_QUARTERLY = 'quarterly';\n public const string FREQUENCY_ONE_OFF = 'one_off';\n\n /**\n * Frequencies for standard (non-Ask Jiminny) reports.\n */\n public const array FREQUENCIES = [\n ['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],\n ['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],\n ['id' => self::FREQUENCY_QUARTERLY, 'name' => 'Quarterly'],\n ['id' => self::FREQUENCY_ONE_OFF, 'name' => 'One-off'],\n ];\n\n /**\n * Frequencies for Ask Jiminny reports.\n */\n public const array ASK_JIMINNY_FREQUENCIES = [\n ['id' => self::FREQUENCY_DAILY, 'name' => 'Daily'],\n ['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],\n ['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],\n ];\n\n public const string MEDIA_TYPE_PDF = 'pdf';\n public const string MEDIA_TYPE_PODCAST = 'podcast';\n public const array MEDIA_TYPES = [self::MEDIA_TYPE_PDF, self::MEDIA_TYPE_PODCAST];\n public const array MEDIA_TYPE_OBJECT_PDF = ['id' => self::MEDIA_TYPE_PDF, 'name' => 'PDF'];\n public const array MEDIA_TYPE_OBJECT_PODCAST = ['id' => self::MEDIA_TYPE_PODCAST, 'name' => 'Podcast'];\n public const array MEDIA_TYPE_OBJECTS = [self::MEDIA_TYPE_OBJECT_PDF, self::MEDIA_TYPE_OBJECT_PODCAST];\n\n public const array CALL_TYPE_CONFERENCE = ['id' => 'conference', 'name' => 'Conference'];\n public const array CALL_TYPE_DIALER = ['id' => 'dialer', 'name' => 'Dialer'];\n public const int SENT_REPORT_AT_HOURS = 5;\n public const string PDF_KEY = 'pdf';\n public const string AUDIO_KEY = 'audio';\n\n private const array ALL_FREQUENCIES = [\n ['id' => self::FREQUENCY_DAILY, 'name' => 'Daily'],\n ['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],\n ['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],\n ['id' => self::FREQUENCY_QUARTERLY, 'name' => 'Quarterly'],\n ['id' => self::FREQUENCY_ONE_OFF, 'name' => 'One-off'],\n ];\n private const string S3_DIR = 'reports';\n private const array FILE_EXTENSIONS_VARIANTS = ['html', 'MD', 'pdf'];\n private const array FILE_PODCAST_EXTENSIONS_VARIANTS = ['json', 'mp3', 'ssml'];\n\n public function __construct(\n private readonly TeamRepository $teamRepository,\n private readonly GroupRepository $groupRepository,\n private readonly UserRepository $userRepository,\n private readonly StageRepository $stageRepository,\n private readonly DealStagesService $dealStagesService,\n private readonly RecipientsService $recipientsService,\n private readonly AutomatedReportsRepository $automatedReportsRepository,\n private readonly Webhook $webhookService,\n private readonly BusDispatcher $dispatcher,\n private readonly ActivityTypeService $activityTypeService,\n private readonly PlaybookCategoryRepository $playbookCategoryRepository,\n private readonly AskAnythingPromptService $askAnythingPromptService,\n private readonly SearchRepository $activitySearchRepository,\n private readonly AskAnythingRepository $askAnythingRepository,\n ) {\n }\n\n public static function getTypes(): array\n {\n $types = self::TYPES;\n\n return array_map(static function ($type) {\n return $type['id'];\n }, $types);\n }\n\n public static function getCallTypes(): array\n {\n return array_map(static function ($callType) {\n return $callType['id'];\n }, [self::CALL_TYPE_CONFERENCE, self::CALL_TYPE_DIALER]);\n }\n\n public static function getFrequencies(): array\n {\n return array_map(static function ($frequency) {\n return $frequency['id'];\n }, self::FREQUENCIES);\n }\n\n // front-facing structure\n public function getReportEnabledFieldData(bool $value = false): array\n {\n return [\n 'id' => 'report_enabled',\n 'label' => '',\n 'inputType' => InputTypeEnum::TOGGLE,\n 'value' => $value,\n ];\n }\n\n // Organizations = Teams\n public function getOrganizationFieldData(?string $value = null, bool $shortVersion = false): array\n {\n $options = $this->getTeams();\n\n if ($shortVersion) {\n return [\n 'id' => 'organization',\n 'label' => 'Organization',\n 'options' => $options,\n ];\n }\n\n return [\n 'id' => 'organization',\n 'label' => 'Organization',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => $options,\n 'value' => $value,\n 'dependencies' => [\n 'teams',\n 'deal_stage_at_call',\n 'current_deal_stage',\n 'recipients',\n ActivityTypeService::PLAYBOOK_CATEGORIES_KEY,\n ],\n 'dependsOn' => [],\n ];\n }\n\n // Teams = Groups\n public function getTeamFieldData(array $options = [], array $value = [], bool $shortVersion = false): array\n {\n if ($shortVersion) {\n return [\n 'id' => 'teams',\n 'label' => 'Team',\n 'options' => $options,\n ];\n }\n\n return [\n 'id' => 'teams',\n 'label' => 'Team',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'required' => false,\n 'placeholder' => 'Select',\n 'options' => $options,\n 'value' => $value, // value should be an array of objects {id, name}\n 'dependencies' => [ActivityTypeService::PLAYBOOK_CATEGORIES_KEY],\n 'dependsOn' => [],\n ];\n }\n\n public function getReportTypeFieldData(?string $value = null, bool $shortVersion = false, ?Team $team = null): array\n {\n $types = [];\n if ($team instanceof Team) {\n if ($team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {\n $types = self::TYPES;\n }\n if ($team->hasFeature(FeatureEnum::ASK_JIMINNY_REPORTS)) {\n $types[] = ['id' => self::TYPE_ASK_JIMINNY, 'name' => 'Ask Jiminny'];\n }\n } else {\n $types = self::TYPES;\n }\n\n if ($shortVersion) {\n return [\n 'id' => 'report_type',\n 'label' => 'Report Type',\n 'options' => $types,\n ];\n }\n\n return [\n 'id' => 'report_type',\n 'label' => 'Report Type',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => $types,\n 'value' => $value,\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getFrequencyFieldData(?string $value = null): array\n {\n return [\n 'id' => 'frequency',\n 'label' => 'Frequency',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => self::FREQUENCIES,\n 'value' => $value,\n 'dependencies' => ['period'],\n 'dependsOn' => [],\n ];\n }\n\n public function getPeriodFieldData(?string $valueStartDate = null, ?string $valueEndDate = null): array\n {\n return [\n 'id' => 'period',\n 'label' => 'Select one-off period',\n 'inputType' => InputTypeEnum::DATE_RANGE,\n 'required' => true,\n 'placeholder' => 'Select',\n 'value' => ['startDate' => $valueStartDate, 'endDate' => $valueEndDate],\n 'queryParams' => [\n 'startDate' => 'start_date_period',\n 'endDate' => 'end_date_period',\n ],\n 'dependencies' => [],\n 'dependsOn' => ['frequency'],\n ];\n }\n\n public function getActivityTypesFieldData(?Team $team = null, array $value = [], array $teamsFilter = []): array\n {\n return $this->activityTypeService->getActivityTypeFieldData(team: $team, value: $value, groupIds: $teamsFilter);\n }\n\n public function getDealStageAtCallFieldData(?Team $team = null, array $value = []): array\n {\n return $this->dealStagesService->getDealStageAtCallFieldData(team: $team, value: $value);\n }\n\n public function getCurrentDealStageFieldData(?Team $team = null, array $value = []): array\n {\n return $this->dealStagesService->getCurrentDealStageFieldData(team: $team, value: $value);\n }\n\n public function getDealValueFieldData(?int $valueMin = null, ?int $valueMax = null): array\n {\n return [\n 'id' => 'deal_value',\n 'label' => 'Deal Value',\n 'inputType' => InputTypeEnum::INTEGER_RANGE,\n 'required' => false,\n 'value' => ['min' => $valueMin, 'max' => $valueMax],\n 'queryParams' => [\n 'min' => 'min_deal_value',\n 'max' => 'max_deal_value',\n ],\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getCallTypeFieldData(bool $conferenceOn = false, bool $dialerOn = false): array\n {\n $value = [];\n $conferenceOn && $value[] = self::CALL_TYPE_CONFERENCE;\n $dialerOn && $value[] = self::CALL_TYPE_DIALER;\n\n return [\n 'id' => 'call_type',\n 'label' => 'Call Type',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'required' => true,\n 'options' => [\n self::CALL_TYPE_CONFERENCE,\n self::CALL_TYPE_DIALER,\n ],\n 'value' => $value,\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getMediaTypeFieldData(?AutomatedReport $report = null): array\n {\n $value = [];\n\n if ($report) {\n $value = $this->transformMediaTypes($report);\n }\n\n return [\n 'id' => 'media_types',\n 'label' => 'Export as',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'required' => true,\n 'options' => self::MEDIA_TYPE_OBJECTS,\n 'value' => $value,\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getCallDurationFieldData(?int $valueMin = null, ?int $valueMax = null): array\n {\n return [\n 'id' => 'call_duration',\n 'label' => 'Call Duration',\n 'inputType' => InputTypeEnum::INTEGER_RANGE,\n 'required' => false,\n 'value' => ['min' => $valueMin, 'max' => $valueMax],\n 'queryParams' => [\n 'min' => 'min_call_duration',\n 'max' => 'max_call_duration',\n ],\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getRecipientsFieldData(?Team $team = null, array $value = []): array\n {\n return $this->recipientsService->getRecipientsFieldData(team: $team, value: $value);\n }\n\n public function getJiminnyRecipientsFieldData(array $value = []): array\n {\n return $this->recipientsService->getJiminnyRecipientsFieldData($value);\n }\n\n public function getAdditionalPromptInputFieldData(?string $value = null): array\n {\n return [\n 'id' => 'additional_prompt_input',\n 'label' => 'Special requirements',\n 'inputType' => InputTypeEnum::TEXTAREA,\n 'required' => false,\n 'placeholder' => 'What should be the focus of the report?',\n 'value' => $value,\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getCustomReportNameFieldData(?string $value = null): array\n {\n return [\n 'id' => 'custom_name',\n 'label' => 'Custom report name',\n 'inputType' => InputTypeEnum::TEXT,\n 'required' => false,\n 'placeholder' => 'Enter custom name',\n 'value' => $value,\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n // data providers\n public function getTeams(): array\n {\n $teams = $this->teamRepository->getTeamsForKiosk(status: Team::STATUS_ACTIVE);\n\n $teamData = [];\n foreach ($teams as $team) {\n if (! $team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {\n continue;\n }\n\n $teamData[] = $this->transformTeam($team);\n }\n\n return $teamData;\n }\n\n public function getTeamGroups(string $teamUuid): array\n {\n $data = [];\n $team = $this->getTeam($teamUuid);\n\n if ($team !== null) {\n $groups = $team->groups()->get();\n\n foreach ($groups as $group) {\n $data[] = [\n 'id' => $group->getUuid(),\n 'name' => $group->getName(),\n ];\n }\n }\n\n return $data;\n }\n\n public function getTeamsGroupsOptions(array $filterTeamUuids = []): array\n {\n $data = [];\n $teams = $this->getTeams();\n\n foreach ($teams as $team) {\n if (! empty($filterTeamUuids) && ! in_array($team['id'], $filterTeamUuids, true)) {\n continue;\n }\n\n $data[] = [\n 'label' => $team['name'],\n 'groups' => $this->getTeamGroups($team['id']),\n ];\n }\n\n return $data;\n }\n\n public function getTeam(string $teamUuid): ?Team\n {\n return $this->teamRepository->idOrUuid($teamUuid);\n }\n\n public function getTeamById(int $teamId): ?Team\n {\n return $this->teamRepository->find($teamId);\n }\n\n public function getGroupsUuids(AutomatedReport $report): array\n {\n $uuids = [];\n $reportGroups = $report->getGroups();\n foreach ($reportGroups as $groupId) {\n if ($group = $this->groupRepository->find($groupId)) {\n $uuids[] = $group->getUuid();\n }\n }\n\n return $uuids;\n }\n\n public function getPlaybookCategoriesUuids(AutomatedReport $report): array\n {\n $uuids = [];\n $playbookCategories = $report->getPlaybookCategories();\n foreach ($playbookCategories as $id) {\n if ($category = $this->playbookCategoryRepository->find($id)) {\n $uuids[] = $category->getUuid();\n }\n }\n\n return $uuids;\n }\n\n public function getDealAtCallStagesUuids(AutomatedReport $report): array\n {\n $uuids = [];\n $reportStages = $report->getDealAtCallStages();\n foreach ($reportStages as $id) {\n if ($stage = $this->stageRepository->find($id)) {\n $uuids[] = $stage->getUuid();\n }\n }\n\n return $uuids;\n }\n\n public function getCurrentDealStagesUuids(AutomatedReport $report): array\n {\n $uuids = [];\n $reportStages = $report->getCurrentDealStages();\n foreach ($reportStages as $id) {\n if ($stage = $this->stageRepository->find($id)) {\n $uuids[] = $stage->getUuid();\n }\n }\n\n return $uuids;\n }\n\n public function getUsersUuids(AutomatedReport $report): array\n {\n return $this->extractUserUuids($report->getRecipients());\n }\n\n public function getJiminnyUsersUuids(AutomatedReport $report): array\n {\n return $this->extractUserUuids($report->getJiminnyRecipients());\n }\n\n /**\n * @param array<string, mixed> $recipients\n */\n private function extractUserUuids(array $recipients): array\n {\n $userIds = $recipients['users'] ?? [];\n\n return collect($userIds)\n ->map(fn ($id) => $this->userRepository->find((int) $id))\n ->filter()\n ->map(fn (UserContract $user) => $user->getUuid())\n ->values()\n ->all();\n }\n\n // get mail data\n public function getRecipientUsers(AutomatedReport $report): array\n {\n return $this->buildRecipientUsers($report->getRecipients());\n }\n\n private function getJiminnyRecipientUsers(AutomatedReport $report): array\n {\n return $this->buildRecipientUsers($report->getJiminnyRecipients());\n }\n\n /**\n * @param array<string, mixed> $recipients\n */\n private function buildRecipientUsers(array $recipients): array\n {\n $userIds = $recipients['users'] ?? [];\n\n return collect($userIds)\n ->map(fn ($id) => $this->userRepository->find((int) $id))\n ->filter()\n ->map(fn (UserContract $user) => [\n 'email' => $user->getEmailAddress(),\n 'name' => $user->getName(),\n 'timezone' => $user->getTimezone()->getName(),\n ])\n ->values()\n ->all();\n }\n\n public function getValidRecipientUsers(AutomatedReport $report, bool $includeJiminny = false): array\n {\n if ($report->isAskJiminnyReport()) {\n $recipients = $this->resolveAskJiminnyRecipients($report);\n } else {\n $recipients = $this->getRecipientUsers($report);\n if ($includeJiminny) {\n $recipients = array_merge($recipients, $this->getJiminnyRecipientUsers($report));\n }\n }\n\n $emails = [];\n\n return array_values(array_filter(\n $recipients,\n static function ($recipient) use (&$emails) {\n if (empty($recipient['email']) || in_array($recipient['email'], $emails, true)) {\n return false;\n }\n $emails[] = $recipient['email'];\n\n return true;\n }\n ));\n }\n\n private function resolveAskJiminnyRecipients(AutomatedReport $report): array\n {\n $recipients = [];\n\n $creator = $report->getCreator();\n if ($creator !== null) {\n $recipients[] = [\n 'email' => $creator->getEmailAddress(),\n 'name' => $creator->getName(),\n 'timezone' => $creator->getTimezone()->getName(),\n ];\n }\n\n return array_merge(\n $recipients,\n $this->buildRecipientUsers($report->getRecipients()),\n $this->getGroupRecipientUsers($report),\n );\n }\n\n private function getGroupRecipientUsers(AutomatedReport $report): array\n {\n $users = [];\n foreach ($report->getGroups() as $groupId) {\n $group = $this->groupRepository->find($groupId);\n if ($group === null) {\n continue;\n }\n foreach ($group->getMembers() as $member) {\n $users[] = [\n 'email' => $member->getEmailAddress(),\n 'name' => $member->getName(),\n 'timezone' => $member->getTimezone()->getName(),\n ];\n }\n }\n\n return $users;\n }\n\n public function getReportTypeName(AutomatedReportResult $report): string\n {\n $type = $report->getReport()->getType();\n\n $getType = $this->transformReportType($type);\n\n return $getType['name'];\n }\n\n public function getReportPeriodName(AutomatedReportResult $report): string\n {\n $from = $report->getFromDate();\n $to = $report->getToDate();\n $frequency = $report->getReport()->getFrequency();\n\n if ($from === null || $to === null) {\n if (! $report->getReport()->isAskJiminnyReport()) {\n $invalidPeriod = $from === null ? 'from' : 'to';\n\n throw new ApplicationException('Report period is invalid: ' . $invalidPeriod);\n }\n\n $period = $this->calculateFromAndToDatePeriod($frequency);\n $from = $period['fromDate'];\n $to = $period['toDate'];\n }\n\n return $this->formatReportPeriodName($frequency, $from, $to);\n }\n\n private function formatReportPeriodName(string $frequency, Carbon $from, Carbon $to): string\n {\n $fromYear = $from->format('Y');\n $toYear = $to->format('Y');\n $differentYears = $fromYear !== $toYear;\n\n switch ($frequency) {\n case self::FREQUENCY_DAILY:\n return $from->format('j M Y');\n\n case self::FREQUENCY_QUARTERLY:\n // 'Jan-Mar 2025' or 'Nov 2024-Jan 2025' if years differ\n $startMonth = $from->format('M');\n $endMonth = $to->copy()->subMonth();\n $endMonthName = $endMonth->format('M');\n $endMonthYear = $endMonth->format('Y');\n\n if ($differentYears) {\n return \"{$startMonth} {$fromYear} - {$endMonthName} {$endMonthYear}\";\n }\n\n return \"{$startMonth} - {$endMonthName} {$toYear}\";\n\n case self::FREQUENCY_MONTHLY:\n // 'May 2025' - monthly reports are always within the same year\n return $from->format('M Y');\n\n case self::FREQUENCY_WEEKLY:\n // '4 - 8 Aug 2025', '27 Oct - 3 Nov 2025', or '28 Dec 2024 - 3 Jan 2025' if years differ\n $startDay = $from->format('j');\n $endDay = $to->format('j');\n $startMonth = $from->format('M');\n $endMonth = $to->format('M');\n\n if ($differentYears) {\n return \"{$startDay} {$startMonth} {$fromYear} - {$endDay} {$endMonth} {$toYear}\";\n }\n\n if ($startMonth !== $endMonth) {\n return \"{$startDay} {$startMonth} - {$endDay} {$endMonth} {$toYear}\";\n }\n\n return \"{$startDay} - {$endDay} {$endMonth} {$toYear}\";\n\n case self::FREQUENCY_ONE_OFF:\n // '2 May-31 May 2025' or '15 Dec 2024-15 Jan 2025' if years differ\n $startDay = $from->format('j');\n $startMonth = $from->format('M');\n $endDay = $to->format('j');\n $endMonth = $to->format('M');\n\n // If same month and year, use a format like '2-31 May 2025'\n if ($startMonth === $endMonth && ! $differentYears) {\n return \"{$startDay} - {$endDay} {$startMonth} {$toYear}\";\n }\n\n // If different years, include both years\n if ($differentYears) {\n return \"{$startDay} {$startMonth} {$fromYear} - {$endDay} {$endMonth} {$toYear}\";\n }\n\n // Same year but different months\n return \"{$startDay} {$startMonth} - {$endDay} {$endMonth} {$toYear}\";\n\n default:\n // Default format for unknown frequencies\n return $from->format('j M Y') . ' - ' . $to->format('j M Y');\n }\n }\n\n public function getReportTeamsName(AutomatedReportResult $report): string\n {\n $groups = $report->getGroups();\n\n if (empty($groups)) {\n return 'All';\n }\n\n // Get group names from repository\n $groupNames = [];\n foreach ($groups as $groupId) {\n $group = $this->groupRepository->find($groupId);\n if ($group) {\n $groupNames[] = $group->getName();\n }\n }\n\n if (count($groupNames) === 1) {\n // Single team format\n $teamsName = $groupNames[0];\n } else {\n // Multiple teams format\n $teamsName = implode(', ', $groupNames);\n }\n\n return $teamsName;\n }\n\n public function getReportFileName(AutomatedReportResult $report): string\n {\n $customName = $report->getReport()->getCustomName();\n $periodName = $this->getReportPeriodName($report);\n $filenameSuffix = $this->getFilenameSuffix($report);\n\n if ($customName) {\n if ($filenameSuffix) {\n $customName .= \" {$filenameSuffix}\";\n }\n\n return $this->sanitizeFileName(\"{$customName} - {$periodName}\");\n }\n\n $baseName = $this->getReportTypeName($report);\n\n if ($filenameSuffix) {\n $baseName .= \" {$filenameSuffix}\";\n }\n\n return $this->sanitizeFileName(\"{$baseName} - {$periodName} - {$this->getReportTeamsName($report)}\");\n }\n\n public function getReportFileNameWithExtension(AutomatedReportResult $result): string\n {\n $extension = $this->getMediaTypeMetadata($result)['extension'];\n\n return $this->getReportFileName($result) . '.' . $extension;\n }\n\n public function sanitizeFileName(string $fileName): string\n {\n return str_replace(['/', '\\\\'], '-', $fileName);\n }\n\n public function isUserRecipientOfReport(User $user, AutomatedReport $report): bool\n {\n $recipients = array_map('intval', $report->getRecipients()['users'] ?? []);\n\n return in_array($user->getId(), $recipients);\n }\n\n public function transformReportResults(Collection $automatedReportResults): array\n {\n $data = [];\n foreach ($automatedReportResults as $automatedReportResult) {\n /** @var AutomatedReportResult $automatedReportResult */\n\n $report = $automatedReportResult->getReport();\n\n $createdBy = $report->getCreator();\n $creator = [\n 'id' => $createdBy?->getUuid(),\n 'name' => $createdBy?->getName(),\n 'email' => $createdBy?->getEmailAddress(),\n 'photoUrl' => $createdBy?->getPhotoUrl(),\n ];\n\n $data[] = [\n 'id' => $automatedReportResult->getUuid(),\n 'name' => $automatedReportResult->getName(),\n 'frequency' => $this->transformFrequency($report->getFrequency()),\n 'recipients' => [\n ...array_values($this->transformGroups(team: $report->getTeam(), groupsIds: $report->getGroups())),\n ...array_values($this->transformRecipients($report->getRecipients())),\n ],\n 'report_type' => $this->transformReportType($report->getType()),\n 'media_type' => $automatedReportResult->getMediaType(),\n 'downloadUrl' => $this->generateReportResultDownloadUrl($automatedReportResult),\n 'viewUrl' => $this->generateReportResultViewUrl($automatedReportResult),\n 'generated_at' => $automatedReportResult->getGeneratedAt()?->toIso8601String(),\n 'creator' => $creator,\n ];\n }\n\n return $data;\n }\n\n public function hasCallTypeConference(AutomatedReport $report): bool\n {\n return in_array(self::CALL_TYPE_CONFERENCE['id'], $report->getCallTypes(), true);\n }\n\n public function hasCallTypeDialer(AutomatedReport $report): bool\n {\n return in_array(self::CALL_TYPE_DIALER['id'], $report->getCallTypes(), true);\n }\n\n // transformers\n private function transformTeam(Team $team): array\n {\n if (! $team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {\n return [];\n }\n\n return [\n 'id' => $team->getUuid(),\n 'name' => $team->getName(),\n ];\n }\n\n private function transformReportFullView(AutomatedReport $report): array\n {\n $base = $this->transformReportBase($report);\n\n return $report->getType() === self::TYPE_ASK_JIMINNY\n ? $base + $this->transformAskJiminnyFields($report)\n : $base + $this->transformStandardReportFields($report);\n }\n\n private function transformReportBase(AutomatedReport $report): array\n {\n return [\n 'id' => $report->getUuid(),\n 'organization' => $this->transformOrganization(team: $report->getTeam()),\n 'report_type' => $this->transformReportType($report->getType()),\n 'frequency' => $this->transformFrequency($report->getFrequency()),\n ];\n }\n\n private function transformStandardReportFields(AutomatedReport $report): array\n {\n $team = $report->getTeam();\n\n return [\n 'report_enabled' => $report->getStatus(),\n 'start_date_period' => $report->getFrom()?->format('Y-m-d H:i:s'),\n 'end_date_period' => $report->getTo()?->format('Y-m-d H:i:s'),\n 'deal_value_min' => $report->getDealValueMin(),\n 'deal_value_max' => $report->getDealValueMax(),\n 'call_types' => $this->transformCallType($report->getCallTypes()),\n 'media_types' => $this->transformMediaTypes($report),\n 'call_duration_min' => $this->transformDurationToMinutes($report->getCallDurationMin()),\n 'call_duration_max' => $this->transformDurationToMinutes($report->getCallDurationMax()),\n 'teams' => $this->transformGroups(team: $team, groupsIds: $report->getGroups()),\n 'deal_at_call_stages' => $this->transformStages(team: $team, stagesIds: $report->getDealAtCallStages()),\n 'current_deal_stages' => $this->transformStages(team: $team, stagesIds: $report->getCurrentDealStages()),\n 'recipients' => $this->transformRecipients($report->getRecipients()),\n 'created_by' => $this->transformCreator($report->getCreator()),\n 'additional_prompt_input' => $report->getAdditionalPromptInput(),\n 'custom_name' => $report->getCustomName(),\n 'created_at' => $report->getCreatedAt()->format('Y-m-d H:i:s'),\n 'updated_at' => $report->getUpdatedAt()->format('Y-m-d H:i:s'),\n 'deleted_at' => $report->getDeletedAt()?->format('Y-m-d H:i:s'),\n ];\n }\n\n private function transformAskJiminnyFields(AutomatedReport $report): array\n {\n $team = $report->getTeam();\n $creatorId = $report->getAttribute('created_by');\n $explicitUserIds = array_values(array_filter(\n $report->getRecipients()['users'] ?? [],\n static fn ($id) => $id !== $creatorId\n ));\n\n return [\n 'report_name' => $report->getCustomName(),\n 'enabled' => $report->getStatus(),\n 'share_teams' => $this->transformGroups(team: $team, groupsIds: $report->getGroups()),\n 'share_users' => $this->transformRecipients(['users' => $explicitUserIds]),\n 'saved_search' => $this->transformSafeSearch($report->getSavedSearch()),\n 'ask_jiminny_prompt' => $this->transformAskJiminnyPrompt($report->getAskAnythingPrompt()),\n 'expires_on' => $report->getExpiresAt()?->format('Y-m-d'),\n ];\n }\n\n private function transformOrganization(?Team $team): array\n {\n return [\n 'id' => $team?->getUuid(),\n 'name' => $team?->getName(),\n ];\n }\n\n private function transformReportType(string $type): array\n {\n foreach (self::ALL_TYPES as $typeItem) {\n if ($typeItem['id'] === $type) {\n return $typeItem;\n }\n }\n\n return [];\n }\n\n private function transformCallType(array $types): array\n {\n $result = [];\n $callTypes = [self::CALL_TYPE_CONFERENCE, self::CALL_TYPE_DIALER];\n\n foreach ($types as $type) {\n foreach ($callTypes as $callTypeItem) {\n if ($callTypeItem['id'] === $type) {\n $result[] = $callTypeItem;\n\n break;\n }\n }\n }\n\n return $result;\n }\n\n private function transformMediaTypes(AutomatedReport $report): array\n {\n $values = [];\n\n foreach ($report->getMediaTypes() as $mediaType) {\n if (! in_array($mediaType, self::MEDIA_TYPES, true)) {\n continue;\n }\n\n $values[] = match ($mediaType) {\n self::MEDIA_TYPE_PDF => self::MEDIA_TYPE_OBJECT_PDF,\n self::MEDIA_TYPE_PODCAST => self::MEDIA_TYPE_OBJECT_PODCAST,\n };\n }\n\n return $values;\n }\n\n private function transformFrequency(string $frequency): array\n {\n foreach (self::ALL_FREQUENCIES as $frequencyItem) {\n if ($frequencyItem['id'] === $frequency) {\n return $frequencyItem;\n }\n }\n\n return [];\n }\n\n public function transformDurationToMinutes(?int $duration): ?int\n {\n if (! $duration) {\n return null;\n }\n\n return (int) ($duration / 60);\n }\n\n private function transformGroups(?Team $team, array $groupsIds): array\n {\n if (empty($groupsIds) || ! $team) {\n return [];\n }\n\n $data = [];\n foreach ($groupsIds as $groupId) {\n $group = $team->groups()->where('id', $groupId)->first();\n\n if ($group) {\n $data[] = [\n 'id' => $group->getUuid(),\n 'name' => $group->getName(),\n 'photoUrl' => $group->getPhotoUrl(),\n ];\n }\n }\n\n return $data;\n }\n\n private function transformStages(?Team $team, array $stagesIds): array\n {\n if (empty($stagesIds) || ! $team) {\n return [];\n }\n\n $data = [];\n foreach ($stagesIds as $stageId) {\n $stage = $team->stages()->where('id', $stageId)->first();\n\n if ($stage) {\n $data[] = [\n 'id' => $stage->getUuid(),\n 'name' => $stage->getName(),\n ];\n }\n }\n\n return $data;\n }\n\n private function transformRecipients(array $recipients): array\n {\n $users = [];\n foreach ($recipients['users'] ?? [] as $userId) {\n $users[] = $this->transformUser($userId);\n }\n\n return $users;\n }\n\n private function transformCreator(?User $user): ?array\n {\n if ($user === null) {\n return null;\n }\n\n return $this->transformUser($user->getId());\n }\n\n private function transformAskJiminnyPrompt(?AskAnythingPrompt $prompt): ?array\n {\n if ($prompt === null) {\n return null;\n }\n\n return [\n 'id' => $prompt->getUuid(),\n 'name' => $prompt->getTitle(),\n ];\n }\n\n private function transformSafeSearch(?Search $search): ?array\n {\n if ($search === null) {\n return null;\n }\n\n return [\n 'id' => $search->getUuid(),\n 'name' => $search->getName(),\n ];\n }\n\n private function transformUser(int $userId): array\n {\n /* @var ?User $user */\n $user = $this->userRepository->find($userId);\n\n return [\n 'id' => $user?->getUuid(),\n 'name' => $user?->getName(),\n 'email' => $user?->getEmailAddress(),\n 'photoUrl' => $user?->getPhotoUrl(),\n ];\n }\n\n public function create(array $data): array\n {\n $validatedData = $this->validateAndTransformData($data);\n $validatedData['created_by'] = auth()->id();\n\n $automatedReport = $this->automatedReportsRepository->create($validatedData);\n\n $this->generateOneOffReport($automatedReport);\n\n return $this->transformReportFullView($automatedReport);\n }\n\n public function update(string $uuid, array $data): array\n {\n $validatedData = $this->validateAndTransformData($data);\n $report = $this->automatedReportsRepository->findByUuid($uuid);\n\n if (! $report) {\n throw new InvalidArgumentException('Report not found');\n }\n\n $oldCustomName = $report->getCustomName();\n\n $automatedReport = $this->automatedReportsRepository->update($report, $validatedData);\n\n if ($oldCustomName !== $automatedReport->getCustomName()) {\n $this->updateResultNames($automatedReport);\n }\n\n $this->generateOneOffReport($automatedReport);\n\n return $this->transformReportFullView($automatedReport);\n }\n\n /**\n * Create an Ask Jiminny report.\n */\n public function createAskJiminnyReport(array $data, User $creator): array\n {\n $validatedData = $this->validateAskJiminnyReportData($data, $creator);\n $validatedData['created_by'] = $creator->getId();\n\n $automatedReport = $this->automatedReportsRepository->create($validatedData);\n\n return $this->transformReportFullView($automatedReport);\n }\n\n /**\n * Update an Ask Jiminny report.\n */\n public function updateAskJiminnyReport(AutomatedReport $report, array $data, User $user): array\n {\n if (! $report->isAskJiminnyReport()) {\n throw new InvalidArgumentException('Report is not an Ask Jiminny report');\n }\n\n $validatedData = $this->validateAskJiminnyReportData($data, $user);\n\n $oldCustomName = $report->getCustomName();\n\n $automatedReport = $this->automatedReportsRepository->update($report, $validatedData);\n\n if ($oldCustomName !== $automatedReport->getCustomName()) {\n $this->updateResultNames($automatedReport);\n }\n\n return $this->transformReportFullView($automatedReport);\n }\n\n public function updateAskJiminnyReportStatus(AutomatedReport $report, bool $status): array\n {\n $this->automatedReportsRepository->update($report, ['status' => $status]);\n\n return $this->transformReportFullView($report->fresh());\n }\n\n /**\n * Validate and transform data for Ask Jiminny reports.\n */\n private function validateAskJiminnyReportData(array $data, User $user): array\n {\n // Validate name\n $name = trim($data['report_name'] ?? '');\n if (empty($name)) {\n throw new InvalidArgumentException('Report name is required');\n }\n if (mb_strlen($name) > 50) {\n throw new InvalidArgumentException('Report name must be 50 characters or less');\n }\n\n // Validate frequency (only daily, weekly, monthly for Ask Jiminny)\n $frequency = $data['frequency'] ?? null;\n $askJiminnyFrequencies = [self::FREQUENCY_DAILY, self::FREQUENCY_WEEKLY, self::FREQUENCY_MONTHLY];\n if (! in_array($frequency, $askJiminnyFrequencies, true)) {\n throw new InvalidArgumentException('Frequency must be daily, weekly, or monthly');\n }\n\n // Validate expiration date\n $expiresAt = $data['expires_on'] ?? null;\n if (empty($expiresAt)) {\n throw new InvalidArgumentException('Expiration date is required');\n }\n\n try {\n $expiresAtDate = Carbon::parse($expiresAt);\n } catch (InvalidFormatException $e) {\n throw new InvalidArgumentException('Expiration date format is invalid');\n }\n $maxExpiration = Carbon::now()->addYear();\n if ($expiresAtDate->gt($maxExpiration)) {\n throw new InvalidArgumentException('Expiration date cannot be more than 1 year from now');\n }\n if ($expiresAtDate->isPast()) {\n throw new InvalidArgumentException('Expiration date cannot be in the past');\n }\n\n // Validate saved search\n $activitySearchId = $data['saved_search'] ?? null;\n if (empty($activitySearchId)) {\n throw new InvalidArgumentException('Saved search is required');\n }\n $savedSearch = $this->activitySearchRepository->findByUuidAndUser($activitySearchId, $user);\n if (! $savedSearch) {\n throw new InvalidArgumentException('Saved search not found or does not belong to you');\n }\n\n // Validate saved prompt\n $askAnythingPromptId = $data['ask_jiminny_prompt'] ?? null;\n if (empty($askAnythingPromptId)) {\n throw new InvalidArgumentException('Ask Jiminny prompt is required');\n }\n $prompt = $this->askAnythingRepository->getPromptByUuid($askAnythingPromptId);\n if (! $prompt) {\n throw new InvalidArgumentException('Ask Jiminny prompt not found');\n }\n\n // Validate status\n $status = $data['enabled'] ?? false;\n\n $recipientUserIds = [$user->getId()];\n\n if (! empty($data['share_users'])) {\n $sharedUserIds = $this->validateAndGetUserIdsByTeam(\n $user->team,\n (array) $data['share_users']\n );\n $recipientUserIds = array_merge($recipientUserIds, $sharedUserIds);\n }\n\n $sharedGroupIds = [];\n if (! empty($data['share_teams'])) {\n $sharedGroupIds = $this->validateAndGetGroupIds($user->team, (array) $data['share_teams']);\n }\n\n $recipientUserIds = array_values(array_unique($recipientUserIds));\n\n return [\n 'team_id' => $user->getTeamId(),\n 'type' => self::TYPE_ASK_JIMINNY,\n 'status' => (bool) $status,\n 'frequency' => $frequency,\n 'custom_name' => $name,\n 'activity_search_id' => $savedSearch->getId(),\n 'ask_anything_prompt_id' => $prompt->getId(),\n 'expires_at' => $expiresAtDate->toDateString(),\n 'media_types' => [self::MEDIA_TYPE_PDF],\n 'call_types' => [],\n 'recipients' => ['users' => $recipientUserIds],\n 'groups' => $sharedGroupIds,\n ];\n }\n\n public static function getAskJiminnyFrequencies(): array\n {\n return array_map(static function ($frequency) {\n return $frequency['id'];\n }, self::ASK_JIMINNY_FREQUENCIES);\n }\n\n public function getAskJiminnyReportFilters(User $user): array\n {\n $savedSearches = $this->activitySearchRepository->findByUserOrderedByName($user)\n ->map(fn (Search $search) => [\n 'id' => $search->getUuid(),\n 'name' => $search->getName(),\n ])\n ->values()->all();\n\n $prompts = collect(\n $this->askAnythingPromptService->get($user, AskAnythingPromptTarget::on_demand)\n )->map(fn (AskAnythingPromptDto $prompt) => [\n 'id' => $prompt->id,\n 'name' => $prompt->title,\n ])->values()->all();\n\n return [\n [\n 'id' => 'prompt',\n 'label' => 'Prompt',\n 'options' => $prompts,\n ],\n [\n 'id' => 'saved_search',\n 'label' => 'Saved Search',\n 'options' => $savedSearches,\n ],\n ];\n }\n\n public function getAskJiminnyReportFormData(User $user, ?AutomatedReport $report = null): array\n {\n $team = $user->getTeam();\n $userTimezone = $user->getTimezone();\n\n $savedSearches = $this->activitySearchRepository->findByUserOrderedByName($user)\n ->map(fn (Search $search) => [\n 'id' => $search->getUuid(),\n 'name' => $search->getName(),\n ])\n ->values()->all();\n\n $prompts = collect(\n $this->askAnythingPromptService->get($user, AskAnythingPromptTarget::on_demand)\n )->map(fn (AskAnythingPromptDto $prompt) => [\n 'id' => $prompt->id,\n 'name' => $prompt->title,\n ])->values()->all();\n\n $teamGroups = $this->groupRepository->getAllByTeam($team)->map(fn ($group) => [\n 'id' => $group->getUuid(),\n 'name' => $group->getName(),\n ])->values()->all();\n\n $shareUsers = $this->recipientsService->getRecipientsFieldData(team: $team)['options'] ?? [];\n\n $sharedTeamsValue = [];\n $sharedUsersValue = [];\n if ($report) {\n $sharedTeamsValue = $this->transformGroups($team, $report->getGroups());\n\n $recipientUserIds = $report->getRecipients()['users'] ?? [];\n $creatorId = $report->getAttribute('created_by');\n $sharedUserIds = array_values(array_filter(\n $recipientUserIds,\n static fn ($id) => $id !== $creatorId\n ));\n $sharedUsersValue = collect($sharedUserIds)\n ->map(fn ($id) => $this->userRepository->find((int) $id))\n ->filter()\n ->map(fn (User $u) => [\n 'id' => $u->getUuid(),\n 'name' => $u->getName(),\n ])\n ->values()\n ->all();\n }\n\n return [\n 'fields' => [\n [\n 'id' => 'enabled',\n 'inputType' => InputTypeEnum::TOGGLE,\n 'label' => '',\n 'value' => $report?->getStatus() ?? false,\n ],\n [\n 'id' => 'report_name',\n 'inputType' => InputTypeEnum::TEXT,\n 'label' => 'Name',\n 'placeholder' => 'Enter name',\n 'required' => true,\n 'validation' => ['maxLength' => 50],\n 'value' => $report?->getCustomName() ?? '',\n ],\n [\n 'id' => 'frequency',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'label' => 'Frequency',\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => self::ASK_JIMINNY_FREQUENCIES,\n 'value' => $report ? $this->transformFrequency($report->getFrequency()) : null,\n ],\n [\n 'id' => 'expires_on',\n 'inputType' => InputTypeEnum::DATE,\n 'label' => 'Expires on',\n 'required' => true,\n 'placeholder' => 'Select',\n 'validation' => [\n 'minDate' => now($userTimezone)->toDateString(),\n 'maxDate' => now($userTimezone)->addYear()->toDateString(),\n ],\n 'value' => $report?->getExpiresAt()?->toDateString(),\n ],\n [\n 'id' => 'share_teams',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'label' => 'Team',\n 'required' => false,\n 'placeholder' => 'Select',\n 'options' => $teamGroups,\n 'value' => $sharedTeamsValue,\n ],\n [\n 'id' => 'share_users',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'label' => 'Team member',\n 'required' => false,\n 'placeholder' => 'Select',\n 'groupLabelKey' => 'label',\n 'groupValuesKey' => 'users',\n 'optionLabelKey' => 'name',\n 'optionValueKey' => 'id',\n 'options' => $shareUsers,\n 'value' => $sharedUsersValue,\n ],\n [\n 'id' => 'saved_search',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'label' => 'Saved search',\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => $savedSearches,\n 'value' => $report && $report->getSavedSearch() ? [\n 'id' => $report->getSavedSearch()->getUuid(),\n 'name' => $report->getSavedSearch()->getName(),\n ] : null,\n ],\n [\n 'id' => 'ask_jiminny_prompt',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'label' => 'Ask Jiminny prompt',\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => $prompts,\n 'value' => $report && $report->getAskAnythingPrompt() ? [\n 'id' => $report->getAskAnythingPrompt()->getUuid(),\n 'name' => $report->getAskAnythingPrompt()->getTitle(),\n ] : null,\n ],\n ],\n ];\n }\n\n private function updateResultNames(AutomatedReport $automatedReport): void\n {\n $results = $this->automatedReportsRepository->getResultsByReport($automatedReport);\n\n foreach ($results as $result) {\n $result->update(['name' => $this->getReportFileName($result)]);\n }\n }\n\n public function updateStatus(string $uuid, array $data): array\n {\n $automatedReport = $this->automatedReportsRepository->findByUuid($uuid);\n\n if (! $automatedReport) {\n throw new ModelNotFoundException('Report not found');\n }\n\n $status = $this->validateReportStatus($data['report_enabled'] ?? null);\n $automatedReport->update([\n 'status' => $status,\n ]);\n\n $this->generateOneOffReport($automatedReport);\n\n return $this->transformReportFullView($automatedReport);\n }\n\n private function generateOneOffReport(AutomatedReport $automatedReport): void\n {\n // the scheduler handles all the other frequency types\n if ($automatedReport->getStatus() === false || $automatedReport->getFrequency() !== self::FREQUENCY_ONE_OFF) {\n return;\n }\n\n $this->dispatcher->dispatch(new RequestGenerateReportJob($automatedReport->getUuid()));\n }\n\n public function getReport(string $uuid): AutomatedReport\n {\n $automatedReport = $this->automatedReportsRepository->findByUuid($uuid);\n\n if (! $automatedReport) {\n throw new ModelNotFoundException('Report not found');\n }\n\n return $automatedReport;\n }\n\n public function get(string $uuid): array\n {\n $automatedReport = $this->getReport($uuid);\n\n return $this->transformReportFullView($automatedReport);\n }\n\n public function list(string $sortColumn = 'created_at', string $sortDirection = 'desc'): array\n {\n $results = [];\n $collection = $this->automatedReportsRepository->getAllStandardReports($sortColumn, $sortDirection);\n\n /** @var AutomatedReport $report */\n foreach ($collection as $report) {\n $results[] = $this->transformReportFullView($report);\n }\n\n return ['data' => $results];\n }\n\n public function listAskJiminnyReports(\n User $user,\n string $sortColumn = 'created_at',\n string $sortDirection = 'desc'\n ): array {\n $results = [];\n $collection = $this->automatedReportsRepository->getAskJiminnyReportsByUser($user, $sortColumn, $sortDirection);\n\n /** @var AutomatedReport $report */\n foreach ($collection as $report) {\n $results[] = $this->transformReportFullView($report);\n }\n\n return ['data' => $results];\n }\n\n public function delete(string $uuid): void\n {\n $automatedReport = $this->automatedReportsRepository->findByUuid($uuid);\n\n if (! $automatedReport) {\n throw new ModelNotFoundException('Report not found');\n }\n\n $automatedReport->delete();\n }\n\n public function createReportResult(AutomatedReport $automatedReport, array $data = []): AutomatedReportResult\n {\n return $this->automatedReportsRepository->createResult(\n array_merge(\n [\n 'report_id' => $automatedReport->getId(),\n 'status' => AutomatedReportResult::STATUS_DEFAULT,\n ],\n $data\n )\n );\n }\n\n public function getReportResult(string $resultUuid): AutomatedReportResult\n {\n $report = $this->automatedReportsRepository->findResultByUuid($resultUuid);\n\n if (! $report) {\n throw new ModelNotFoundException('Report Result not found');\n }\n\n return $report;\n }\n\n public function findChildResult(AutomatedReportResult $result, string $type): ?AutomatedReportResult\n {\n return $this->automatedReportsRepository->findChildResult($result, $type);\n }\n\n // prophet API calls\n /**\n * @throws ApplicationException\n */\n public function getGenerateReportPayload(AutomatedReport $automatedReport, string $reportResultUuid): array\n {\n $period = $this->calculateFromAndToDate($automatedReport);\n $fromDate = $period['fromDate'];\n $toDate = $period['toDate'];\n\n return [\n 'team_id' => $automatedReport->getTeamId(),\n 'request_id' => $reportResultUuid,\n 'report_type' => $automatedReport->getType(),\n 'media_types' => $automatedReport->getMediaTypes(),\n 'from_date' => $fromDate->startOfDay()->format(DateTimeInterface::RFC3339),\n 'to_date' => $toDate->endOfDay()->format(DateTimeInterface::RFC3339),\n 'group_ids' => $automatedReport->getGroups(),\n 'call_deal_stage' => $automatedReport->getDealAtCallStages(),\n 'current_deal_stage' => $automatedReport->getCurrentDealStages(),\n 'deal_min_value' => $automatedReport->getDealValueMin(),\n 'deal_max_value' => $automatedReport->getDealValueMax(),\n 'call_types' => $automatedReport->getCallTypes(),\n 'call_duration_min_seconds' => $automatedReport->getCallDurationMin(),\n 'call_duration_max_seconds' => $automatedReport->getCallDurationMax(),\n 'special_requirements' => $automatedReport->getAdditionalPromptInput(),\n 'callback_url' => $this->getCallbackUrl(),\n 'report_period' => $this->formatReportPeriodName(\n $automatedReport->getFrequency(),\n $fromDate,\n $toDate,\n ),\n 'playbook_categories' => $automatedReport->getPlaybookCategories(),\n 'custom_name' => $automatedReport->getCustomName(),\n ];\n }\n\n // $inputPayload - FE payload structure\n public function getActivitiesCountPayload(array $inputPayload): array\n {\n // Use validateAndTransformData to validate and normalize input\n $validatedData = $this->validateAndTransformData($inputPayload);\n $period = $this->calculateFromAndToDatePeriod(\n $validatedData['frequency'],\n Carbon::parse($validatedData['from']),\n Carbon::parse($validatedData['to']),\n );\n $fromDate = $period['fromDate'];\n $toDate = $period['toDate'];\n\n // Create payload similar to getGenerateReportPayload\n return [\n 'team_id' => $validatedData['team_id'],\n 'group_ids' => $validatedData['groups'] ?? [],\n 'report_type' => $validatedData['type'],\n 'from_date' => $fromDate->format(DateTimeInterface::RFC3339),\n 'to_date' => $toDate->format(DateTimeInterface::RFC3339),\n 'call_deal_stage' => $validatedData['deal_at_call_stages'] ?? [],\n 'current_deal_stage' => $validatedData['current_deal_stages'] ?? [],\n 'deal_min_value' => $validatedData['deal_value_min'] ?? null,\n 'deal_max_value' => $validatedData['deal_value_max'] ?? null,\n 'call_types' => $validatedData['call_types'],\n 'call_duration_min_seconds' => $validatedData['call_duration_min'] ?? null,\n 'call_duration_max_seconds' => $validatedData['call_duration_max'] ?? null,\n 'special_requirements' => $validatedData['additional_prompt_input'] ?? null,\n 'playbook_categories' => $validatedData['playbook_categories'] ?? [],\n 'request_id' => null,\n 'callback_url' => null,\n ];\n }\n\n public function shouldSendReport(array $users, ?CarbonInterface $generatedAt = null): bool\n {\n if (empty($users)) {\n return false;\n }\n\n $earliestTz = collect($users)\n ->mapWithKeys(function (array $user) {\n $tz = new DateTimeZone($user['timezone']);\n $nowUtc = new DateTime('now', new DateTimeZone('UTC'));\n $offset = $tz->getOffset($nowUtc);\n\n return [$user['timezone'] => $offset];\n })\n ->sortDesc()\n ->keys()\n ->first();\n\n $now = Carbon::now($earliestTz);\n $isScheduledTime = (int) $now->format('H') === self::SENT_REPORT_AT_HOURS;\n\n if ($isScheduledTime) {\n return true;\n }\n\n return $this->hasPassedScheduledTime($generatedAt, $earliestTz);\n }\n\n public function hasPassedScheduledTime(?CarbonInterface $generatedAt, string $timezone): bool\n {\n if ($generatedAt === null) {\n return false;\n }\n\n $now = Carbon::now($timezone);\n $scheduledTime = $now->copy()->setTime(self::SENT_REPORT_AT_HOURS, 0, 0);\n\n if ($now->hour < self::SENT_REPORT_AT_HOURS) {\n $scheduledTime = $scheduledTime->subDay();\n }\n\n $scheduledTimeUtc = $scheduledTime->copy()->utc();\n $generatedAtUtc = $generatedAt->copy()->utc();\n $nowUtc = $now->copy()->utc();\n\n return $generatedAtUtc->lt($scheduledTimeUtc) && $nowUtc->gt($scheduledTimeUtc);\n }\n\n public function calculateFromAndToDatePeriod(\n string $frequency,\n ?Carbon $fromDate = null,\n ?Carbon $toDate = null\n ): array {\n if ($frequency === self::FREQUENCY_ONE_OFF) {\n return [\n 'fromDate' => $fromDate,\n 'toDate' => $toDate,\n ];\n }\n\n $now = Carbon::now();\n\n return match ($frequency) {\n self::FREQUENCY_DAILY => [\n 'fromDate' => $now->copy()->subDay()->startOfDay(),\n 'toDate' => $now->copy()->subDay()->endOfDay(),\n ],\n self::FREQUENCY_WEEKLY => [\n 'fromDate' => $now->copy()->subWeeks(1)->startOfDay(),\n 'toDate' => $now->copy()->subDay()->endOfDay(),\n ],\n self::FREQUENCY_MONTHLY => [\n 'fromDate' => $now->copy()->subMonths(1)->startOfDay(),\n 'toDate' => $now->copy()->subDay()->endOfDay(),\n ],\n self::FREQUENCY_QUARTERLY => [\n 'fromDate' => $now->copy()->subMonths(3)->startOfDay(),\n 'toDate' => $now->copy()->subDay()->endOfDay(),\n ],\n default => throw new InvalidArgumentException(\"Unsupported frequency: {$frequency}\"),\n };\n }\n\n private function calculateFromAndToDate(AutomatedReport $automatedReport): array\n {\n return $this->calculateFromAndToDatePeriod(\n $automatedReport->getFrequency(),\n $automatedReport->getFrom(),\n $automatedReport->getTo()\n );\n }\n\n public function getAskJiminnyGenerateReportPayload(\n AutomatedReport $automatedReport,\n AutomatedReportResult $reportResult,\n array $activityIds,\n ): array {\n return [\n 'user_question' => $automatedReport->getAskAnythingPrompt()?->getContent(),\n 'call_ids' => array_map('strval', $activityIds),\n 'team_id' => $automatedReport->getTeamId(),\n 'request_id' => $reportResult->getUuid(),\n 'callback_url' => $this->getCallbackUrl(),\n 'report_period' => $this->getReportPeriodName($reportResult),\n 'report_name' => $automatedReport->getCustomName(),\n ];\n }\n\n private function getCallbackUrl(): string\n {\n return $this->webhookService->route('jiminny.webhook.reports.ready');\n }\n\n /**\n * Validate and transform payload data for automated reports\n *\n * @param array $data\n *\n * @throws InvalidArgumentException\n *\n * @return array\n */\n private function validateAndTransformData(array $data): array\n {\n // Validate organization (team) and check feature\n $team = $this->validateOrganization($data['organization'] ?? null);\n\n $status = $this->validateReportStatus($data['report_enabled'] ?? null);\n $type = $this->validateReportType($data['report_type'] ?? null);\n $frequency = $this->validateFrequency($data['frequency'] ?? null);\n $additionalPromptInput = $this->validateAdditionalPromptInput(\n $data['additional_prompt_input'] ?? null\n );\n $customReportName = $this->validateCustomReportName($data['custom_name'] ?? null);\n\n // Prepare data for the database\n $reportData = [\n 'team_id' => $team->getId(),\n 'type' => $type,\n 'status' => $status,\n 'frequency' => $frequency,\n 'additional_prompt_input' => $additionalPromptInput,\n 'custom_name' => $customReportName,\n ];\n\n // Validate deal values\n $reportData = $this->validateDealValues($data, $reportData);\n\n // Validate date range\n $reportData = $this->validateDateRange($data, $reportData, $frequency);\n\n // Validate call durations\n $reportData = $this->validateCallDurations($data, $reportData);\n\n // Validate call types\n $reportData = $this->validateCallTypes($data, $reportData);\n\n // Validate media types\n $reportData = $this->validateMediaTypes($data, $reportData);\n\n // Validate groups\n if (isset($data['teams'])) {\n $reportData['groups'] = $this->validateAndGetGroupIds($team, $data['teams']);\n }\n\n // Validate deal stages\n $reportData = $this->validateDealStages($data, $reportData, $team, $type);\n\n // Validate playbook categories\n $reportData = $this->validatePlaybookCategories($data, $reportData, $team);\n\n // Validate recipients\n $reportData['recipients'] = [\n 'users' => $this->validateAndGetUserIdsByTeam($team, $data['recipients'] ?? []),\n ];\n\n if (isset($data['jiminny_recipients'])) {\n // Validate Jiminny recipients\n $reportData['jiminny_recipients'] = [\n 'users' => $this->validateAndGetJiminnyUserIds((array) $data['jiminny_recipients']),\n ];\n }\n\n return $reportData;\n }\n\n private function validateDealValues(array $data, array $reportData): array\n {\n if (isset($data['min_deal_value'])) {\n $reportData['deal_value_min'] = (int) $data['min_deal_value'];\n\n if ($reportData['deal_value_min'] > 4294967295 || $reportData['deal_value_min'] < 0) {\n throw new InvalidArgumentException('Min deal value should be between 0 and 4294967295');\n }\n }\n\n if (isset($data['max_deal_value'])) {\n $reportData['deal_value_max'] = (int) $data['max_deal_value'];\n\n if ($reportData['deal_value_max'] > 4294967295 || $reportData['deal_value_max'] < 0) {\n throw new InvalidArgumentException('Max deal value should be between 0 and 4294967295');\n }\n }\n\n if (isset($data['min_deal_value'], $data['max_deal_value'])\n && $data['min_deal_value'] > $data['max_deal_value']\n ) {\n throw new InvalidArgumentException('Min deal value cannot be greater than max deal value');\n }\n\n return $reportData;\n }\n\n private function validateDateRange(array $data, array $reportData, string $frequency): array\n {\n // Set date range only for one_off frequency\n if ($frequency === 'one_off') {\n if (isset($data['start_date_period'])) {\n $reportData['from'] = $this->parseDate($data['start_date_period']);\n }\n\n if (isset($data['end_date_period'])) {\n $reportData['to'] = $this->parseDate($data['end_date_period']);\n }\n\n if (empty($reportData['from']) || empty($reportData['to'])) {\n throw new InvalidArgumentException(\n 'Start date and end date are required for one_off frequency'\n );\n }\n } else {\n $reportData['from'] = null;\n $reportData['to'] = null;\n }\n\n return $reportData;\n }\n\n private function validateCallDurations(array $data, array $reportData): array\n {\n // Convert call durations from minutes to seconds\n if (isset($data['min_call_duration'])) {\n $reportData['call_duration_min'] = (int) $data['min_call_duration'] * 60;\n\n if ($reportData['call_duration_min'] > 4294967295 || $reportData['call_duration_min'] < 0) {\n throw new InvalidArgumentException('Min call duration should be between 0 and 4294967295');\n }\n }\n\n if (isset($data['max_call_duration'])) {\n $reportData['call_duration_max'] = (int) $data['max_call_duration'] * 60;\n\n if ($reportData['call_duration_max'] > 4294967295 || $reportData['call_duration_max'] < 0) {\n throw new InvalidArgumentException('Max call duration should be between 0 and 4294967295');\n }\n }\n\n return $reportData;\n }\n\n private function validateCallTypes(array $data, array $reportData): array\n {\n // Set call types\n $reportData['call_types'] = $data['call_type'] ?? [];\n if (empty($reportData['call_types'])) {\n $reportData['call_types'] = self::getCallTypes();\n }\n\n foreach ($reportData['call_types'] as $callType) {\n if (! in_array($callType, self::getCallTypes(), true)) {\n throw new InvalidArgumentException(sprintf('Call type %s is invalid', $callType));\n }\n }\n\n return $reportData;\n }\n\n private function validateMediaTypes(array $data, array $reportData): array\n {\n // Set media types from input data\n $reportData['media_types'] = $data['media_types'] ?? [];\n\n if (empty($reportData['media_types'])) {\n throw new InvalidArgumentException('Media types are required');\n }\n\n foreach ($reportData['media_types'] as $mediaType) {\n if (! in_array($mediaType, self::MEDIA_TYPES, true)) {\n throw new InvalidArgumentException(sprintf('Media type %s is invalid', $mediaType));\n }\n }\n\n return $reportData;\n }\n\n private function validateDealStages(array $data, array $reportData, Team $team, string $reportType): array\n {\n // Validate and set deal stages\n if (isset($data['deal_stage_at_call'])) {\n $reportData['deal_at_call_stages'] =\n $this->validateAndGetDealStageIds($team, $data['deal_stage_at_call'], 'Deal stage at call');\n }\n\n if (isset($data['current_deal_stage'])) {\n $reportData['current_deal_stages'] =\n $this->validateAndGetDealStageIds($team, $data['current_deal_stage'], 'Current deal stage');\n }\n\n // Ensure current_deal_stage is not provided for loss_analysis report type\n if ($reportType === self::TYPE_LOSS_ANALYSIS && ! empty($data['current_deal_stage'])) {\n throw new InvalidArgumentException('Current deal stage is not applicable for Loss Analysis reports');\n }\n\n return $reportData;\n }\n\n // transform uuid to id\n private function validatePlaybookCategories(array $data, array $reportData, Team $team): array\n {\n $key = 'playbook_categories';\n\n if (isset($data[$key])) {\n $payloadIds = $data[$key];\n $ids = [];\n\n foreach ($payloadIds as $uuid) {\n $uuid = (string) $uuid;\n\n try {\n $playbookCategory = $this->playbookCategoryRepository->findByUuid($uuid);\n } catch (Throwable $throwable) {\n Log::error(__METHOD__ . ' ' . $throwable->getMessage());\n\n throw new InvalidArgumentException(sprintf('Playbook category %s not found', $uuid));\n }\n\n if (! $playbookCategory) {\n throw new InvalidArgumentException(sprintf('Playbook category %s not found', $uuid));\n }\n\n if (! $playbookCategory->hasPlaybook()) {\n throw new InvalidArgumentException(sprintf('Playbook category %s has no playbook', $uuid));\n }\n\n if ($playbookCategory->getPlaybook()->getTeamId() !== $team->getId()) {\n throw new InvalidArgumentException(\n sprintf('Playbook category %s not found for team %s', $uuid, $team->getUuid())\n );\n }\n\n $ids[] = $playbookCategory->getId();\n }\n\n $reportData[$key] = $ids;\n }\n\n return $reportData;\n }\n\n private function validateReportStatus($status): bool\n {\n if (! in_array($status, [true, false], true)) {\n throw new InvalidArgumentException('Report status is invalid');\n }\n\n return $status;\n }\n\n private function validateReportType($type): string\n {\n if (! in_array($type, self::getTypes(), true)) {\n throw new InvalidArgumentException(sprintf('Report type is invalid: %s', $type));\n }\n\n return $type;\n }\n\n private function validateFrequency($frequency): string\n {\n if (! in_array($frequency, self::getFrequencies(), true)) {\n throw new InvalidArgumentException('Frequency is invalid');\n }\n\n return $frequency;\n }\n\n private function validateAdditionalPromptInput(?string $additionalPromptInput): ?string\n {\n if ($additionalPromptInput && strlen($additionalPromptInput) > 5000) {\n throw new InvalidArgumentException('Additional Prompt Input should be less than 5000 characters');\n }\n\n return $additionalPromptInput;\n }\n\n private function validateCustomReportName(?string $customReportName): ?string\n {\n if ($customReportName === null || $customReportName === '') {\n return null;\n }\n\n if (strlen($customReportName) > 70) {\n throw new InvalidArgumentException('Custom report name should be less than 70 characters');\n }\n\n return $customReportName;\n }\n\n private function validateOrganization(?string $organizationUuid): Team\n {\n if (! $organizationUuid) {\n throw new InvalidArgumentException('Organization is required');\n }\n\n $team = $this->teamRepository->idOrUuid($organizationUuid);\n\n if (! $team) {\n throw new InvalidArgumentException('Organization not found');\n }\n\n if (! $team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {\n throw new InvalidArgumentException('Organization does not have the Automated Reports feature');\n }\n\n return $team;\n }\n\n private function validateAndGetGroupIds(Team $team, array $teamUuids): array\n {\n $groupIds = [];\n\n foreach ($teamUuids as $uuid) {\n $group = $this->groupRepository->findByUuid($uuid);\n\n if ($group === null || $group->getTeamId() !== $team->getId()) {\n throw new InvalidArgumentException(\n sprintf('Group %s not found for team %s', $uuid, $team->getUuid())\n );\n }\n\n $groupIds[] = $group->getId();\n\n }\n\n return $groupIds;\n }\n\n private function validateAndGetDealStageIds(Team $team, array $stageUuids, string $propertyLabel): array\n {\n $stageIds = [];\n\n foreach ($stageUuids as $uuid) {\n $stage = $this->stageRepository->findByUuid($uuid);\n\n if ($stage === null || $stage->getTeamId() !== $team->getId()) {\n throw new InvalidArgumentException(\n sprintf('Stage %s not found for team %s for %s', $uuid, $team->getUuid(), $propertyLabel)\n );\n }\n\n $stageIds[] = $stage->getId();\n }\n\n return $stageIds;\n }\n\n private function validateAndGetUserIds(array $userUuids, callable $teamCheck): array\n {\n if (empty($userUuids)) {\n return [];\n }\n\n $userIds = [];\n\n foreach ($userUuids as $uuid) {\n $user = $this->userRepository->findByUuid($uuid);\n\n if (! $user || ! $user->isStatusActive()) {\n throw new InvalidArgumentException(\n sprintf('User %s not found or is not active', $uuid)\n );\n }\n\n if (! $teamCheck($user)) {\n throw new InvalidArgumentException(\n sprintf('User %s does not belong to the allowed team(s)', $uuid)\n );\n }\n\n $userIds[] = $user->getId();\n }\n\n return $userIds;\n }\n\n private function validateAndGetUserIdsByTeam(Team $team, array $userUuids): array\n {\n return $this->validateAndGetUserIds($userUuids, fn ($user) => $user->getTeamId() === $team->getId());\n }\n\n private function validateAndGetJiminnyUserIds(array $userUuids): array\n {\n $allowedTeamIds = config('kiosk.teamIds', []);\n\n return $this->validateAndGetUserIds($userUuids, fn ($user) => in_array($user->getTeamId(), $allowedTeamIds, true));\n }\n\n private function parseDate(string $dateString): string\n {\n return date('Y-m-d H:i:s', strtotime($dateString));\n }\n\n private function generateReportResultViewUrl(AutomatedReportResult $result): string\n {\n $mediaResource = $this->getReportMediaRouteResource($result);\n\n return route('ai-reports.' . $mediaResource . '.view', ['uuid' => $result->getUuid()]);\n }\n\n private function generateReportResultDownloadUrl(AutomatedReportResult $result): string\n {\n $mediaResource = $this->getReportMediaRouteResource($result);\n\n return route('ai-reports.' . $mediaResource . '.download', ['uuid' => $result->getUuid()]);\n }\n\n private function getReportMediaRouteResource(AutomatedReportResult $result): string\n {\n if ($result->getMediaType() === self::MEDIA_TYPE_PDF) {\n return self::PDF_KEY;\n } elseif ($result->getMediaType() === self::MEDIA_TYPE_PODCAST) {\n return self::AUDIO_KEY;\n }\n\n throw new \\InvalidArgumentException('Unknown media type.');\n }\n\n public function getMediaPath(AutomatedReportResult $result): ?string\n {\n $url = match ($result->getMediaType()) {\n self::MEDIA_TYPE_PDF => $result->getPdfUrl(),\n self::MEDIA_TYPE_PODCAST => $result->getPodcastAudioUrl(),\n default => null,\n };\n\n if ($url === null) {\n return null;\n }\n\n $path = parse_url(trim($url, '\"\\''), PHP_URL_PATH);\n\n return $path ?: null;\n }\n\n public function getFilenameSuffix(AutomatedReportResult $result): ?string\n {\n return match ($result->getMediaType()) {\n self::MEDIA_TYPE_PODCAST => 'Podcast',\n default => null,\n };\n }\n\n public function getMailSubjectSuffix(AutomatedReportResult $result): string\n {\n return match ($result->getMediaType()) {\n self::MEDIA_TYPE_PDF => 'report',\n self::MEDIA_TYPE_PODCAST => 'podcast',\n default => '',\n };\n }\n\n public function getMediaTypeMetadata(AutomatedReportResult $result): array\n {\n return match ($result->getMediaType()) {\n self::MEDIA_TYPE_PODCAST => ['extension' => 'mp3', 'mime' => 'audio/mpeg'],\n self::MEDIA_TYPE_PDF => ['extension' => 'pdf', 'mime' => 'application/pdf'],\n default => ['extension' => null, 'mime' => null],\n };\n }\n\n public function deleteS3Files(AutomatedReportResult $result): void\n {\n $teamUuid = $result->getReport()->getTeam()->getUuid();\n $reportUuid = $result->getUuid();\n\n // delete all files for a report uuid no mather of pdf, podcast, or both\n // in case of both - the podcast files are linked to the pdf (parent) uuid\n // pdf and podcast date times should be close\n $path = sprintf('%s/%s/%s', $teamUuid, self::S3_DIR, $reportUuid);\n\n foreach (self::FILE_EXTENSIONS_VARIANTS as $extension) {\n $file = $path . '.' . $extension;\n\n if (Storage::exists($file)) {\n Storage::delete($file);\n Log::info('[Reports] Deleted S3 file', [\n 'path' => $file,\n ]);\n }\n }\n\n foreach (self::FILE_PODCAST_EXTENSIONS_VARIANTS as $extension) {\n $file = $path . '_podcast.' . $extension;\n\n if (Storage::exists($file)) {\n Storage::delete($file);\n Log::info('[Reports] Deleted Podcast S3 file', [\n 'path' => $file,\n ]);\n }\n }\n }\n\n /**\n *\n * @param int|null $teamId Optional team ID to filter results\n *\n * @return Collection<int, int> Collection of team IDs\n */\n public function getTeamIdsWithReportsResults(?int $teamId = null): Collection\n {\n return $this->automatedReportsRepository->getTeamIdsWithReportsResults($teamId);\n }\n\n /**\n * Core delete logic for report results using a query\n *\n * @param Builder $query\n * @param array $logContext\n *\n * @return int\n */\n private function deleteReportResultsByQuery(Builder $query, array $logContext = []): int\n {\n $deletedCount = 0;\n\n if ($query->exists()) {\n Log::info(\n 'Run delete report results',\n array_merge(\n $logContext,\n [\n 'service' => 'AutomatedReportsService',\n ]\n )\n );\n\n $query->chunkById(50, function ($results) use (&$deletedCount, $logContext) {\n foreach ($results as $result) {\n $this->deleteReportResult($result);\n $deletedCount++;\n\n Log::info(\n 'Deleted a report result',\n array_merge(\n $logContext,\n [\n 'result_id' => $result->getId(),\n 'report_id' => $result->getReportId(),\n ]\n )\n );\n }\n });\n }\n\n return $deletedCount;\n }\n\n /**\n * Delete report results for a team by retention period\n *\n * @param Team $team\n * @param CarbonImmutable $retentionDate\n *\n * @return int Number of deleted report results\n */\n public function deleteReportsResultsInRetentionPeriod(Team $team, CarbonImmutable $retentionDate): int\n {\n $reportIds = $this->automatedReportsRepository->getReportIdsByTeam($team);\n\n if ($reportIds->isEmpty()) {\n return 0;\n }\n\n $query = $this->automatedReportsRepository\n ->getReportResultsQueryForRetention($team, $retentionDate);\n\n return $this->deleteReportResultsByQuery($query, [\n 'team_id' => $team->getId(),\n 'retention_date' => $retentionDate->toDateTimeString(),\n ]);\n }\n\n /**\n * Delete ALL report results for a specific automated report\n *\n * @param string $uuid\n *\n * @return int\n */\n public function deleteReportResults(string $uuid): int\n {\n $report = $this->getReport($uuid);\n\n $query = $this->automatedReportsRepository->getResultsByReportQuery($report);\n\n return $this->deleteReportResultsByQuery($query, [\n 'report_uuid' => $uuid,\n 'report_id' => $report->getId(),\n ]);\n }\n\n public function deleteReportResult(AutomatedReportResult $result): void\n {\n $this->deleteS3Files($result);\n\n $result->delete();\n }\n\n /**\n * Get all reports for a specific team\n *\n * @param Team $team\n *\n * @return \\Illuminate\\Database\\Eloquent\\Collection\n */\n public function getTeamReports(Team $team): \\Illuminate\\Database\\Eloquent\\Collection\n {\n return $this->automatedReportsRepository->getReportsByTeam($team);\n }\n\n /**\n * Get all report results for a specific report\n *\n * @param AutomatedReport $report\n *\n * @return \\Illuminate\\Database\\Eloquent\\Collection\n */\n public function getReportResults(AutomatedReport $report): \\Illuminate\\Database\\Eloquent\\Collection\n {\n return $this->automatedReportsRepository->getResultsByReport($report);\n }\n\n public function deleteAllReportResults(AutomatedReport $report): void\n {\n $results = $this->getReportResults($report);\n\n /** @var AutomatedReportResult $result */\n foreach ($results as $result) {\n Log::info('Deleting result', [\n 'report' => $report->getId(),\n 'result' => $result->getId(),\n ]);\n\n $this->deleteReportResult($result);\n }\n }\n\n public function deleteAllData(Team $team): void\n {\n Log::info('Deleting automated report and results for team', [\n 'team' => $team->getId(),\n ]);\n\n $reports = $this->getTeamReports($team);\n\n /** @var AutomatedReport $report */\n foreach ($reports as $report) {\n Log::info('Deleting report', [\n 'team' => $team->getId(),\n 'report' => $report->getId(),\n ]);\n\n $this->deleteAllReportResults($report);\n\n $report->delete();\n }\n }\n}","depth":4,"value":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Services\\Kiosk\\AutomatedReports;\n\nuse Carbon\\CarbonImmutable;\nuse Carbon\\CarbonInterface;\nuse Carbon\\Exceptions\\InvalidFormatException;\nuse DateTime;\nuse DateTimeInterface;\nuse DateTimeZone;\nuse Illuminate\\Contracts\\Bus\\Dispatcher as BusDispatcher;\nuse Illuminate\\Database\\Eloquent\\Builder;\nuse Illuminate\\Support\\Carbon;\nuse Illuminate\\Support\\Collection;\nuse Illuminate\\Support\\Facades\\Log;\nuse Illuminate\\Support\\Facades\\Storage;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinition\\InputTypeEnum;\nuse Jiminny\\Component\\AskAnything\\AskAnythingPromptService;\nuse Jiminny\\Component\\AskAnything\\Dtos\\AskAnythingPromptDto;\nuse Jiminny\\Component\\UrlGenerator\\Webhook;\nuse Jiminny\\Contracts\\Repositories\\PlaybookCategoryRepository;\nuse Jiminny\\Contracts\\Repositories\\TeamRepository;\nuse Jiminny\\Contracts\\Repositories\\UserRepository;\nuse Jiminny\\Exceptions\\ApplicationException;\nuse Jiminny\\Exceptions\\InvalidArgumentException;\nuse Jiminny\\Exceptions\\ModelNotFoundException;\nuse Jiminny\\Jobs\\AutomatedReports\\RequestGenerateReportJob;\nuse Jiminny\\Models\\Activity\\Search;\nuse Jiminny\\Models\\AskAnything\\AskAnythingPrompt;\nuse Jiminny\\Models\\AskAnything\\AskAnythingPromptTarget;\nuse Jiminny\\Models\\AutomatedReport;\nuse Jiminny\\Models\\AutomatedReportResult;\nuse Jiminny\\Models\\Contracts\\UserContract;\nuse Jiminny\\Models\\Feature\\FeatureEnum;\nuse Jiminny\\Models\\Team;\nuse Jiminny\\Models\\User;\nuse Jiminny\\Repositories\\AskAnythingRepository;\nuse Jiminny\\Repositories\\AutomatedReportsRepository;\nuse Jiminny\\Repositories\\GroupRepository;\nuse Jiminny\\Repositories\\SearchRepository;\nuse Jiminny\\Repositories\\StageRepository;\nuse Throwable;\n\nclass AutomatedReportsService\n{\n public const string TYPE_LOSS_ANALYSIS = 'loss_analysis';\n public const string TYPE_ASK_JIMINNY = 'ask_jiminny';\n\n /**\n * Standard report types (used by kiosk for existing automated reports).\n */\n // @TODO this will add filter, however if we need to control feature by FF we need conditional logic\n public const array TYPES = [\n ['id' => 'exec_summary', 'name' => 'Exec Summary'],\n ['id' => 'coaching_profiles', 'name' => 'Coaching Profiles'],\n ['id' => 'product_feedback', 'name' => 'Product Feedback'],\n ['id' => self::TYPE_LOSS_ANALYSIS, 'name' => 'Loss Analysis'],\n// ['id' => 'questions', 'name' => 'Questions'],\n// ['id' => 'statistical_quant', 'name' => 'Statistical Quantitative'],\n ];\n\n public const array ALL_TYPES = [\n ...self::TYPES,\n ['id' => self::TYPE_ASK_JIMINNY, 'name' => 'Ask Jiminny'],\n ];\n\n public const string FREQUENCY_DAILY = 'daily';\n public const string FREQUENCY_WEEKLY = 'weekly';\n public const string FREQUENCY_MONTHLY = 'monthly';\n public const string FREQUENCY_QUARTERLY = 'quarterly';\n public const string FREQUENCY_ONE_OFF = 'one_off';\n\n /**\n * Frequencies for standard (non-Ask Jiminny) reports.\n */\n public const array FREQUENCIES = [\n ['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],\n ['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],\n ['id' => self::FREQUENCY_QUARTERLY, 'name' => 'Quarterly'],\n ['id' => self::FREQUENCY_ONE_OFF, 'name' => 'One-off'],\n ];\n\n /**\n * Frequencies for Ask Jiminny reports.\n */\n public const array ASK_JIMINNY_FREQUENCIES = [\n ['id' => self::FREQUENCY_DAILY, 'name' => 'Daily'],\n ['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],\n ['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],\n ];\n\n public const string MEDIA_TYPE_PDF = 'pdf';\n public const string MEDIA_TYPE_PODCAST = 'podcast';\n public const array MEDIA_TYPES = [self::MEDIA_TYPE_PDF, self::MEDIA_TYPE_PODCAST];\n public const array MEDIA_TYPE_OBJECT_PDF = ['id' => self::MEDIA_TYPE_PDF, 'name' => 'PDF'];\n public const array MEDIA_TYPE_OBJECT_PODCAST = ['id' => self::MEDIA_TYPE_PODCAST, 'name' => 'Podcast'];\n public const array MEDIA_TYPE_OBJECTS = [self::MEDIA_TYPE_OBJECT_PDF, self::MEDIA_TYPE_OBJECT_PODCAST];\n\n public const array CALL_TYPE_CONFERENCE = ['id' => 'conference', 'name' => 'Conference'];\n public const array CALL_TYPE_DIALER = ['id' => 'dialer', 'name' => 'Dialer'];\n public const int SENT_REPORT_AT_HOURS = 5;\n public const string PDF_KEY = 'pdf';\n public const string AUDIO_KEY = 'audio';\n\n private const array ALL_FREQUENCIES = [\n ['id' => self::FREQUENCY_DAILY, 'name' => 'Daily'],\n ['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],\n ['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],\n ['id' => self::FREQUENCY_QUARTERLY, 'name' => 'Quarterly'],\n ['id' => self::FREQUENCY_ONE_OFF, 'name' => 'One-off'],\n ];\n private const string S3_DIR = 'reports';\n private const array FILE_EXTENSIONS_VARIANTS = ['html', 'MD', 'pdf'];\n private const array FILE_PODCAST_EXTENSIONS_VARIANTS = ['json', 'mp3', 'ssml'];\n\n public function __construct(\n private readonly TeamRepository $teamRepository,\n private readonly GroupRepository $groupRepository,\n private readonly UserRepository $userRepository,\n private readonly StageRepository $stageRepository,\n private readonly DealStagesService $dealStagesService,\n private readonly RecipientsService $recipientsService,\n private readonly AutomatedReportsRepository $automatedReportsRepository,\n private readonly Webhook $webhookService,\n private readonly BusDispatcher $dispatcher,\n private readonly ActivityTypeService $activityTypeService,\n private readonly PlaybookCategoryRepository $playbookCategoryRepository,\n private readonly AskAnythingPromptService $askAnythingPromptService,\n private readonly SearchRepository $activitySearchRepository,\n private readonly AskAnythingRepository $askAnythingRepository,\n ) {\n }\n\n public static function getTypes(): array\n {\n $types = self::TYPES;\n\n return array_map(static function ($type) {\n return $type['id'];\n }, $types);\n }\n\n public static function getCallTypes(): array\n {\n return array_map(static function ($callType) {\n return $callType['id'];\n }, [self::CALL_TYPE_CONFERENCE, self::CALL_TYPE_DIALER]);\n }\n\n public static function getFrequencies(): array\n {\n return array_map(static function ($frequency) {\n return $frequency['id'];\n }, self::FREQUENCIES);\n }\n\n // front-facing structure\n public function getReportEnabledFieldData(bool $value = false): array\n {\n return [\n 'id' => 'report_enabled',\n 'label' => '',\n 'inputType' => InputTypeEnum::TOGGLE,\n 'value' => $value,\n ];\n }\n\n // Organizations = Teams\n public function getOrganizationFieldData(?string $value = null, bool $shortVersion = false): array\n {\n $options = $this->getTeams();\n\n if ($shortVersion) {\n return [\n 'id' => 'organization',\n 'label' => 'Organization',\n 'options' => $options,\n ];\n }\n\n return [\n 'id' => 'organization',\n 'label' => 'Organization',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => $options,\n 'value' => $value,\n 'dependencies' => [\n 'teams',\n 'deal_stage_at_call',\n 'current_deal_stage',\n 'recipients',\n ActivityTypeService::PLAYBOOK_CATEGORIES_KEY,\n ],\n 'dependsOn' => [],\n ];\n }\n\n // Teams = Groups\n public function getTeamFieldData(array $options = [], array $value = [], bool $shortVersion = false): array\n {\n if ($shortVersion) {\n return [\n 'id' => 'teams',\n 'label' => 'Team',\n 'options' => $options,\n ];\n }\n\n return [\n 'id' => 'teams',\n 'label' => 'Team',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'required' => false,\n 'placeholder' => 'Select',\n 'options' => $options,\n 'value' => $value, // value should be an array of objects {id, name}\n 'dependencies' => [ActivityTypeService::PLAYBOOK_CATEGORIES_KEY],\n 'dependsOn' => [],\n ];\n }\n\n public function getReportTypeFieldData(?string $value = null, bool $shortVersion = false, ?Team $team = null): array\n {\n $types = [];\n if ($team instanceof Team) {\n if ($team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {\n $types = self::TYPES;\n }\n if ($team->hasFeature(FeatureEnum::ASK_JIMINNY_REPORTS)) {\n $types[] = ['id' => self::TYPE_ASK_JIMINNY, 'name' => 'Ask Jiminny'];\n }\n } else {\n $types = self::TYPES;\n }\n\n if ($shortVersion) {\n return [\n 'id' => 'report_type',\n 'label' => 'Report Type',\n 'options' => $types,\n ];\n }\n\n return [\n 'id' => 'report_type',\n 'label' => 'Report Type',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => $types,\n 'value' => $value,\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getFrequencyFieldData(?string $value = null): array\n {\n return [\n 'id' => 'frequency',\n 'label' => 'Frequency',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => self::FREQUENCIES,\n 'value' => $value,\n 'dependencies' => ['period'],\n 'dependsOn' => [],\n ];\n }\n\n public function getPeriodFieldData(?string $valueStartDate = null, ?string $valueEndDate = null): array\n {\n return [\n 'id' => 'period',\n 'label' => 'Select one-off period',\n 'inputType' => InputTypeEnum::DATE_RANGE,\n 'required' => true,\n 'placeholder' => 'Select',\n 'value' => ['startDate' => $valueStartDate, 'endDate' => $valueEndDate],\n 'queryParams' => [\n 'startDate' => 'start_date_period',\n 'endDate' => 'end_date_period',\n ],\n 'dependencies' => [],\n 'dependsOn' => ['frequency'],\n ];\n }\n\n public function getActivityTypesFieldData(?Team $team = null, array $value = [], array $teamsFilter = []): array\n {\n return $this->activityTypeService->getActivityTypeFieldData(team: $team, value: $value, groupIds: $teamsFilter);\n }\n\n public function getDealStageAtCallFieldData(?Team $team = null, array $value = []): array\n {\n return $this->dealStagesService->getDealStageAtCallFieldData(team: $team, value: $value);\n }\n\n public function getCurrentDealStageFieldData(?Team $team = null, array $value = []): array\n {\n return $this->dealStagesService->getCurrentDealStageFieldData(team: $team, value: $value);\n }\n\n public function getDealValueFieldData(?int $valueMin = null, ?int $valueMax = null): array\n {\n return [\n 'id' => 'deal_value',\n 'label' => 'Deal Value',\n 'inputType' => InputTypeEnum::INTEGER_RANGE,\n 'required' => false,\n 'value' => ['min' => $valueMin, 'max' => $valueMax],\n 'queryParams' => [\n 'min' => 'min_deal_value',\n 'max' => 'max_deal_value',\n ],\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getCallTypeFieldData(bool $conferenceOn = false, bool $dialerOn = false): array\n {\n $value = [];\n $conferenceOn && $value[] = self::CALL_TYPE_CONFERENCE;\n $dialerOn && $value[] = self::CALL_TYPE_DIALER;\n\n return [\n 'id' => 'call_type',\n 'label' => 'Call Type',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'required' => true,\n 'options' => [\n self::CALL_TYPE_CONFERENCE,\n self::CALL_TYPE_DIALER,\n ],\n 'value' => $value,\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getMediaTypeFieldData(?AutomatedReport $report = null): array\n {\n $value = [];\n\n if ($report) {\n $value = $this->transformMediaTypes($report);\n }\n\n return [\n 'id' => 'media_types',\n 'label' => 'Export as',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'required' => true,\n 'options' => self::MEDIA_TYPE_OBJECTS,\n 'value' => $value,\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getCallDurationFieldData(?int $valueMin = null, ?int $valueMax = null): array\n {\n return [\n 'id' => 'call_duration',\n 'label' => 'Call Duration',\n 'inputType' => InputTypeEnum::INTEGER_RANGE,\n 'required' => false,\n 'value' => ['min' => $valueMin, 'max' => $valueMax],\n 'queryParams' => [\n 'min' => 'min_call_duration',\n 'max' => 'max_call_duration',\n ],\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getRecipientsFieldData(?Team $team = null, array $value = []): array\n {\n return $this->recipientsService->getRecipientsFieldData(team: $team, value: $value);\n }\n\n public function getJiminnyRecipientsFieldData(array $value = []): array\n {\n return $this->recipientsService->getJiminnyRecipientsFieldData($value);\n }\n\n public function getAdditionalPromptInputFieldData(?string $value = null): array\n {\n return [\n 'id' => 'additional_prompt_input',\n 'label' => 'Special requirements',\n 'inputType' => InputTypeEnum::TEXTAREA,\n 'required' => false,\n 'placeholder' => 'What should be the focus of the report?',\n 'value' => $value,\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getCustomReportNameFieldData(?string $value = null): array\n {\n return [\n 'id' => 'custom_name',\n 'label' => 'Custom report name',\n 'inputType' => InputTypeEnum::TEXT,\n 'required' => false,\n 'placeholder' => 'Enter custom name',\n 'value' => $value,\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n // data providers\n public function getTeams(): array\n {\n $teams = $this->teamRepository->getTeamsForKiosk(status: Team::STATUS_ACTIVE);\n\n $teamData = [];\n foreach ($teams as $team) {\n if (! $team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {\n continue;\n }\n\n $teamData[] = $this->transformTeam($team);\n }\n\n return $teamData;\n }\n\n public function getTeamGroups(string $teamUuid): array\n {\n $data = [];\n $team = $this->getTeam($teamUuid);\n\n if ($team !== null) {\n $groups = $team->groups()->get();\n\n foreach ($groups as $group) {\n $data[] = [\n 'id' => $group->getUuid(),\n 'name' => $group->getName(),\n ];\n }\n }\n\n return $data;\n }\n\n public function getTeamsGroupsOptions(array $filterTeamUuids = []): array\n {\n $data = [];\n $teams = $this->getTeams();\n\n foreach ($teams as $team) {\n if (! empty($filterTeamUuids) && ! in_array($team['id'], $filterTeamUuids, true)) {\n continue;\n }\n\n $data[] = [\n 'label' => $team['name'],\n 'groups' => $this->getTeamGroups($team['id']),\n ];\n }\n\n return $data;\n }\n\n public function getTeam(string $teamUuid): ?Team\n {\n return $this->teamRepository->idOrUuid($teamUuid);\n }\n\n public function getTeamById(int $teamId): ?Team\n {\n return $this->teamRepository->find($teamId);\n }\n\n public function getGroupsUuids(AutomatedReport $report): array\n {\n $uuids = [];\n $reportGroups = $report->getGroups();\n foreach ($reportGroups as $groupId) {\n if ($group = $this->groupRepository->find($groupId)) {\n $uuids[] = $group->getUuid();\n }\n }\n\n return $uuids;\n }\n\n public function getPlaybookCategoriesUuids(AutomatedReport $report): array\n {\n $uuids = [];\n $playbookCategories = $report->getPlaybookCategories();\n foreach ($playbookCategories as $id) {\n if ($category = $this->playbookCategoryRepository->find($id)) {\n $uuids[] = $category->getUuid();\n }\n }\n\n return $uuids;\n }\n\n public function getDealAtCallStagesUuids(AutomatedReport $report): array\n {\n $uuids = [];\n $reportStages = $report->getDealAtCallStages();\n foreach ($reportStages as $id) {\n if ($stage = $this->stageRepository->find($id)) {\n $uuids[] = $stage->getUuid();\n }\n }\n\n return $uuids;\n }\n\n public function getCurrentDealStagesUuids(AutomatedReport $report): array\n {\n $uuids = [];\n $reportStages = $report->getCurrentDealStages();\n foreach ($reportStages as $id) {\n if ($stage = $this->stageRepository->find($id)) {\n $uuids[] = $stage->getUuid();\n }\n }\n\n return $uuids;\n }\n\n public function getUsersUuids(AutomatedReport $report): array\n {\n return $this->extractUserUuids($report->getRecipients());\n }\n\n public function getJiminnyUsersUuids(AutomatedReport $report): array\n {\n return $this->extractUserUuids($report->getJiminnyRecipients());\n }\n\n /**\n * @param array<string, mixed> $recipients\n */\n private function extractUserUuids(array $recipients): array\n {\n $userIds = $recipients['users'] ?? [];\n\n return collect($userIds)\n ->map(fn ($id) => $this->userRepository->find((int) $id))\n ->filter()\n ->map(fn (UserContract $user) => $user->getUuid())\n ->values()\n ->all();\n }\n\n // get mail data\n public function getRecipientUsers(AutomatedReport $report): array\n {\n return $this->buildRecipientUsers($report->getRecipients());\n }\n\n private function getJiminnyRecipientUsers(AutomatedReport $report): array\n {\n return $this->buildRecipientUsers($report->getJiminnyRecipients());\n }\n\n /**\n * @param array<string, mixed> $recipients\n */\n private function buildRecipientUsers(array $recipients): array\n {\n $userIds = $recipients['users'] ?? [];\n\n return collect($userIds)\n ->map(fn ($id) => $this->userRepository->find((int) $id))\n ->filter()\n ->map(fn (UserContract $user) => [\n 'email' => $user->getEmailAddress(),\n 'name' => $user->getName(),\n 'timezone' => $user->getTimezone()->getName(),\n ])\n ->values()\n ->all();\n }\n\n public function getValidRecipientUsers(AutomatedReport $report, bool $includeJiminny = false): array\n {\n if ($report->isAskJiminnyReport()) {\n $recipients = $this->resolveAskJiminnyRecipients($report);\n } else {\n $recipients = $this->getRecipientUsers($report);\n if ($includeJiminny) {\n $recipients = array_merge($recipients, $this->getJiminnyRecipientUsers($report));\n }\n }\n\n $emails = [];\n\n return array_values(array_filter(\n $recipients,\n static function ($recipient) use (&$emails) {\n if (empty($recipient['email']) || in_array($recipient['email'], $emails, true)) {\n return false;\n }\n $emails[] = $recipient['email'];\n\n return true;\n }\n ));\n }\n\n private function resolveAskJiminnyRecipients(AutomatedReport $report): array\n {\n $recipients = [];\n\n $creator = $report->getCreator();\n if ($creator !== null) {\n $recipients[] = [\n 'email' => $creator->getEmailAddress(),\n 'name' => $creator->getName(),\n 'timezone' => $creator->getTimezone()->getName(),\n ];\n }\n\n return array_merge(\n $recipients,\n $this->buildRecipientUsers($report->getRecipients()),\n $this->getGroupRecipientUsers($report),\n );\n }\n\n private function getGroupRecipientUsers(AutomatedReport $report): array\n {\n $users = [];\n foreach ($report->getGroups() as $groupId) {\n $group = $this->groupRepository->find($groupId);\n if ($group === null) {\n continue;\n }\n foreach ($group->getMembers() as $member) {\n $users[] = [\n 'email' => $member->getEmailAddress(),\n 'name' => $member->getName(),\n 'timezone' => $member->getTimezone()->getName(),\n ];\n }\n }\n\n return $users;\n }\n\n public function getReportTypeName(AutomatedReportResult $report): string\n {\n $type = $report->getReport()->getType();\n\n $getType = $this->transformReportType($type);\n\n return $getType['name'];\n }\n\n public function getReportPeriodName(AutomatedReportResult $report): string\n {\n $from = $report->getFromDate();\n $to = $report->getToDate();\n $frequency = $report->getReport()->getFrequency();\n\n if ($from === null || $to === null) {\n if (! $report->getReport()->isAskJiminnyReport()) {\n $invalidPeriod = $from === null ? 'from' : 'to';\n\n throw new ApplicationException('Report period is invalid: ' . $invalidPeriod);\n }\n\n $period = $this->calculateFromAndToDatePeriod($frequency);\n $from = $period['fromDate'];\n $to = $period['toDate'];\n }\n\n return $this->formatReportPeriodName($frequency, $from, $to);\n }\n\n private function formatReportPeriodName(string $frequency, Carbon $from, Carbon $to): string\n {\n $fromYear = $from->format('Y');\n $toYear = $to->format('Y');\n $differentYears = $fromYear !== $toYear;\n\n switch ($frequency) {\n case self::FREQUENCY_DAILY:\n return $from->format('j M Y');\n\n case self::FREQUENCY_QUARTERLY:\n // 'Jan-Mar 2025' or 'Nov 2024-Jan 2025' if years differ\n $startMonth = $from->format('M');\n $endMonth = $to->copy()->subMonth();\n $endMonthName = $endMonth->format('M');\n $endMonthYear = $endMonth->format('Y');\n\n if ($differentYears) {\n return \"{$startMonth} {$fromYear} - {$endMonthName} {$endMonthYear}\";\n }\n\n return \"{$startMonth} - {$endMonthName} {$toYear}\";\n\n case self::FREQUENCY_MONTHLY:\n // 'May 2025' - monthly reports are always within the same year\n return $from->format('M Y');\n\n case self::FREQUENCY_WEEKLY:\n // '4 - 8 Aug 2025', '27 Oct - 3 Nov 2025', or '28 Dec 2024 - 3 Jan 2025' if years differ\n $startDay = $from->format('j');\n $endDay = $to->format('j');\n $startMonth = $from->format('M');\n $endMonth = $to->format('M');\n\n if ($differentYears) {\n return \"{$startDay} {$startMonth} {$fromYear} - {$endDay} {$endMonth} {$toYear}\";\n }\n\n if ($startMonth !== $endMonth) {\n return \"{$startDay} {$startMonth} - {$endDay} {$endMonth} {$toYear}\";\n }\n\n return \"{$startDay} - {$endDay} {$endMonth} {$toYear}\";\n\n case self::FREQUENCY_ONE_OFF:\n // '2 May-31 May 2025' or '15 Dec 2024-15 Jan 2025' if years differ\n $startDay = $from->format('j');\n $startMonth = $from->format('M');\n $endDay = $to->format('j');\n $endMonth = $to->format('M');\n\n // If same month and year, use a format like '2-31 May 2025'\n if ($startMonth === $endMonth && ! $differentYears) {\n return \"{$startDay} - {$endDay} {$startMonth} {$toYear}\";\n }\n\n // If different years, include both years\n if ($differentYears) {\n return \"{$startDay} {$startMonth} {$fromYear} - {$endDay} {$endMonth} {$toYear}\";\n }\n\n // Same year but different months\n return \"{$startDay} {$startMonth} - {$endDay} {$endMonth} {$toYear}\";\n\n default:\n // Default format for unknown frequencies\n return $from->format('j M Y') . ' - ' . $to->format('j M Y');\n }\n }\n\n public function getReportTeamsName(AutomatedReportResult $report): string\n {\n $groups = $report->getGroups();\n\n if (empty($groups)) {\n return 'All';\n }\n\n // Get group names from repository\n $groupNames = [];\n foreach ($groups as $groupId) {\n $group = $this->groupRepository->find($groupId);\n if ($group) {\n $groupNames[] = $group->getName();\n }\n }\n\n if (count($groupNames) === 1) {\n // Single team format\n $teamsName = $groupNames[0];\n } else {\n // Multiple teams format\n $teamsName = implode(', ', $groupNames);\n }\n\n return $teamsName;\n }\n\n public function getReportFileName(AutomatedReportResult $report): string\n {\n $customName = $report->getReport()->getCustomName();\n $periodName = $this->getReportPeriodName($report);\n $filenameSuffix = $this->getFilenameSuffix($report);\n\n if ($customName) {\n if ($filenameSuffix) {\n $customName .= \" {$filenameSuffix}\";\n }\n\n return $this->sanitizeFileName(\"{$customName} - {$periodName}\");\n }\n\n $baseName = $this->getReportTypeName($report);\n\n if ($filenameSuffix) {\n $baseName .= \" {$filenameSuffix}\";\n }\n\n return $this->sanitizeFileName(\"{$baseName} - {$periodName} - {$this->getReportTeamsName($report)}\");\n }\n\n public function getReportFileNameWithExtension(AutomatedReportResult $result): string\n {\n $extension = $this->getMediaTypeMetadata($result)['extension'];\n\n return $this->getReportFileName($result) . '.' . $extension;\n }\n\n public function sanitizeFileName(string $fileName): string\n {\n return str_replace(['/', '\\\\'], '-', $fileName);\n }\n\n public function isUserRecipientOfReport(User $user, AutomatedReport $report): bool\n {\n $recipients = array_map('intval', $report->getRecipients()['users'] ?? []);\n\n return in_array($user->getId(), $recipients);\n }\n\n public function transformReportResults(Collection $automatedReportResults): array\n {\n $data = [];\n foreach ($automatedReportResults as $automatedReportResult) {\n /** @var AutomatedReportResult $automatedReportResult */\n\n $report = $automatedReportResult->getReport();\n\n $createdBy = $report->getCreator();\n $creator = [\n 'id' => $createdBy?->getUuid(),\n 'name' => $createdBy?->getName(),\n 'email' => $createdBy?->getEmailAddress(),\n 'photoUrl' => $createdBy?->getPhotoUrl(),\n ];\n\n $data[] = [\n 'id' => $automatedReportResult->getUuid(),\n 'name' => $automatedReportResult->getName(),\n 'frequency' => $this->transformFrequency($report->getFrequency()),\n 'recipients' => [\n ...array_values($this->transformGroups(team: $report->getTeam(), groupsIds: $report->getGroups())),\n ...array_values($this->transformRecipients($report->getRecipients())),\n ],\n 'report_type' => $this->transformReportType($report->getType()),\n 'media_type' => $automatedReportResult->getMediaType(),\n 'downloadUrl' => $this->generateReportResultDownloadUrl($automatedReportResult),\n 'viewUrl' => $this->generateReportResultViewUrl($automatedReportResult),\n 'generated_at' => $automatedReportResult->getGeneratedAt()?->toIso8601String(),\n 'creator' => $creator,\n ];\n }\n\n return $data;\n }\n\n public function hasCallTypeConference(AutomatedReport $report): bool\n {\n return in_array(self::CALL_TYPE_CONFERENCE['id'], $report->getCallTypes(), true);\n }\n\n public function hasCallTypeDialer(AutomatedReport $report): bool\n {\n return in_array(self::CALL_TYPE_DIALER['id'], $report->getCallTypes(), true);\n }\n\n // transformers\n private function transformTeam(Team $team): array\n {\n if (! $team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {\n return [];\n }\n\n return [\n 'id' => $team->getUuid(),\n 'name' => $team->getName(),\n ];\n }\n\n private function transformReportFullView(AutomatedReport $report): array\n {\n $base = $this->transformReportBase($report);\n\n return $report->getType() === self::TYPE_ASK_JIMINNY\n ? $base + $this->transformAskJiminnyFields($report)\n : $base + $this->transformStandardReportFields($report);\n }\n\n private function transformReportBase(AutomatedReport $report): array\n {\n return [\n 'id' => $report->getUuid(),\n 'organization' => $this->transformOrganization(team: $report->getTeam()),\n 'report_type' => $this->transformReportType($report->getType()),\n 'frequency' => $this->transformFrequency($report->getFrequency()),\n ];\n }\n\n private function transformStandardReportFields(AutomatedReport $report): array\n {\n $team = $report->getTeam();\n\n return [\n 'report_enabled' => $report->getStatus(),\n 'start_date_period' => $report->getFrom()?->format('Y-m-d H:i:s'),\n 'end_date_period' => $report->getTo()?->format('Y-m-d H:i:s'),\n 'deal_value_min' => $report->getDealValueMin(),\n 'deal_value_max' => $report->getDealValueMax(),\n 'call_types' => $this->transformCallType($report->getCallTypes()),\n 'media_types' => $this->transformMediaTypes($report),\n 'call_duration_min' => $this->transformDurationToMinutes($report->getCallDurationMin()),\n 'call_duration_max' => $this->transformDurationToMinutes($report->getCallDurationMax()),\n 'teams' => $this->transformGroups(team: $team, groupsIds: $report->getGroups()),\n 'deal_at_call_stages' => $this->transformStages(team: $team, stagesIds: $report->getDealAtCallStages()),\n 'current_deal_stages' => $this->transformStages(team: $team, stagesIds: $report->getCurrentDealStages()),\n 'recipients' => $this->transformRecipients($report->getRecipients()),\n 'created_by' => $this->transformCreator($report->getCreator()),\n 'additional_prompt_input' => $report->getAdditionalPromptInput(),\n 'custom_name' => $report->getCustomName(),\n 'created_at' => $report->getCreatedAt()->format('Y-m-d H:i:s'),\n 'updated_at' => $report->getUpdatedAt()->format('Y-m-d H:i:s'),\n 'deleted_at' => $report->getDeletedAt()?->format('Y-m-d H:i:s'),\n ];\n }\n\n private function transformAskJiminnyFields(AutomatedReport $report): array\n {\n $team = $report->getTeam();\n $creatorId = $report->getAttribute('created_by');\n $explicitUserIds = array_values(array_filter(\n $report->getRecipients()['users'] ?? [],\n static fn ($id) => $id !== $creatorId\n ));\n\n return [\n 'report_name' => $report->getCustomName(),\n 'enabled' => $report->getStatus(),\n 'share_teams' => $this->transformGroups(team: $team, groupsIds: $report->getGroups()),\n 'share_users' => $this->transformRecipients(['users' => $explicitUserIds]),\n 'saved_search' => $this->transformSafeSearch($report->getSavedSearch()),\n 'ask_jiminny_prompt' => $this->transformAskJiminnyPrompt($report->getAskAnythingPrompt()),\n 'expires_on' => $report->getExpiresAt()?->format('Y-m-d'),\n ];\n }\n\n private function transformOrganization(?Team $team): array\n {\n return [\n 'id' => $team?->getUuid(),\n 'name' => $team?->getName(),\n ];\n }\n\n private function transformReportType(string $type): array\n {\n foreach (self::ALL_TYPES as $typeItem) {\n if ($typeItem['id'] === $type) {\n return $typeItem;\n }\n }\n\n return [];\n }\n\n private function transformCallType(array $types): array\n {\n $result = [];\n $callTypes = [self::CALL_TYPE_CONFERENCE, self::CALL_TYPE_DIALER];\n\n foreach ($types as $type) {\n foreach ($callTypes as $callTypeItem) {\n if ($callTypeItem['id'] === $type) {\n $result[] = $callTypeItem;\n\n break;\n }\n }\n }\n\n return $result;\n }\n\n private function transformMediaTypes(AutomatedReport $report): array\n {\n $values = [];\n\n foreach ($report->getMediaTypes() as $mediaType) {\n if (! in_array($mediaType, self::MEDIA_TYPES, true)) {\n continue;\n }\n\n $values[] = match ($mediaType) {\n self::MEDIA_TYPE_PDF => self::MEDIA_TYPE_OBJECT_PDF,\n self::MEDIA_TYPE_PODCAST => self::MEDIA_TYPE_OBJECT_PODCAST,\n };\n }\n\n return $values;\n }\n\n private function transformFrequency(string $frequency): array\n {\n foreach (self::ALL_FREQUENCIES as $frequencyItem) {\n if ($frequencyItem['id'] === $frequency) {\n return $frequencyItem;\n }\n }\n\n return [];\n }\n\n public function transformDurationToMinutes(?int $duration): ?int\n {\n if (! $duration) {\n return null;\n }\n\n return (int) ($duration / 60);\n }\n\n private function transformGroups(?Team $team, array $groupsIds): array\n {\n if (empty($groupsIds) || ! $team) {\n return [];\n }\n\n $data = [];\n foreach ($groupsIds as $groupId) {\n $group = $team->groups()->where('id', $groupId)->first();\n\n if ($group) {\n $data[] = [\n 'id' => $group->getUuid(),\n 'name' => $group->getName(),\n 'photoUrl' => $group->getPhotoUrl(),\n ];\n }\n }\n\n return $data;\n }\n\n private function transformStages(?Team $team, array $stagesIds): array\n {\n if (empty($stagesIds) || ! $team) {\n return [];\n }\n\n $data = [];\n foreach ($stagesIds as $stageId) {\n $stage = $team->stages()->where('id', $stageId)->first();\n\n if ($stage) {\n $data[] = [\n 'id' => $stage->getUuid(),\n 'name' => $stage->getName(),\n ];\n }\n }\n\n return $data;\n }\n\n private function transformRecipients(array $recipients): array\n {\n $users = [];\n foreach ($recipients['users'] ?? [] as $userId) {\n $users[] = $this->transformUser($userId);\n }\n\n return $users;\n }\n\n private function transformCreator(?User $user): ?array\n {\n if ($user === null) {\n return null;\n }\n\n return $this->transformUser($user->getId());\n }\n\n private function transformAskJiminnyPrompt(?AskAnythingPrompt $prompt): ?array\n {\n if ($prompt === null) {\n return null;\n }\n\n return [\n 'id' => $prompt->getUuid(),\n 'name' => $prompt->getTitle(),\n ];\n }\n\n private function transformSafeSearch(?Search $search): ?array\n {\n if ($search === null) {\n return null;\n }\n\n return [\n 'id' => $search->getUuid(),\n 'name' => $search->getName(),\n ];\n }\n\n private function transformUser(int $userId): array\n {\n /* @var ?User $user */\n $user = $this->userRepository->find($userId);\n\n return [\n 'id' => $user?->getUuid(),\n 'name' => $user?->getName(),\n 'email' => $user?->getEmailAddress(),\n 'photoUrl' => $user?->getPhotoUrl(),\n ];\n }\n\n public function create(array $data): array\n {\n $validatedData = $this->validateAndTransformData($data);\n $validatedData['created_by'] = auth()->id();\n\n $automatedReport = $this->automatedReportsRepository->create($validatedData);\n\n $this->generateOneOffReport($automatedReport);\n\n return $this->transformReportFullView($automatedReport);\n }\n\n public function update(string $uuid, array $data): array\n {\n $validatedData = $this->validateAndTransformData($data);\n $report = $this->automatedReportsRepository->findByUuid($uuid);\n\n if (! $report) {\n throw new InvalidArgumentException('Report not found');\n }\n\n $oldCustomName = $report->getCustomName();\n\n $automatedReport = $this->automatedReportsRepository->update($report, $validatedData);\n\n if ($oldCustomName !== $automatedReport->getCustomName()) {\n $this->updateResultNames($automatedReport);\n }\n\n $this->generateOneOffReport($automatedReport);\n\n return $this->transformReportFullView($automatedReport);\n }\n\n /**\n * Create an Ask Jiminny report.\n */\n public function createAskJiminnyReport(array $data, User $creator): array\n {\n $validatedData = $this->validateAskJiminnyReportData($data, $creator);\n $validatedData['created_by'] = $creator->getId();\n\n $automatedReport = $this->automatedReportsRepository->create($validatedData);\n\n return $this->transformReportFullView($automatedReport);\n }\n\n /**\n * Update an Ask Jiminny report.\n */\n public function updateAskJiminnyReport(AutomatedReport $report, array $data, User $user): array\n {\n if (! $report->isAskJiminnyReport()) {\n throw new InvalidArgumentException('Report is not an Ask Jiminny report');\n }\n\n $validatedData = $this->validateAskJiminnyReportData($data, $user);\n\n $oldCustomName = $report->getCustomName();\n\n $automatedReport = $this->automatedReportsRepository->update($report, $validatedData);\n\n if ($oldCustomName !== $automatedReport->getCustomName()) {\n $this->updateResultNames($automatedReport);\n }\n\n return $this->transformReportFullView($automatedReport);\n }\n\n public function updateAskJiminnyReportStatus(AutomatedReport $report, bool $status): array\n {\n $this->automatedReportsRepository->update($report, ['status' => $status]);\n\n return $this->transformReportFullView($report->fresh());\n }\n\n /**\n * Validate and transform data for Ask Jiminny reports.\n */\n private function validateAskJiminnyReportData(array $data, User $user): array\n {\n // Validate name\n $name = trim($data['report_name'] ?? '');\n if (empty($name)) {\n throw new InvalidArgumentException('Report name is required');\n }\n if (mb_strlen($name) > 50) {\n throw new InvalidArgumentException('Report name must be 50 characters or less');\n }\n\n // Validate frequency (only daily, weekly, monthly for Ask Jiminny)\n $frequency = $data['frequency'] ?? null;\n $askJiminnyFrequencies = [self::FREQUENCY_DAILY, self::FREQUENCY_WEEKLY, self::FREQUENCY_MONTHLY];\n if (! in_array($frequency, $askJiminnyFrequencies, true)) {\n throw new InvalidArgumentException('Frequency must be daily, weekly, or monthly');\n }\n\n // Validate expiration date\n $expiresAt = $data['expires_on'] ?? null;\n if (empty($expiresAt)) {\n throw new InvalidArgumentException('Expiration date is required');\n }\n\n try {\n $expiresAtDate = Carbon::parse($expiresAt);\n } catch (InvalidFormatException $e) {\n throw new InvalidArgumentException('Expiration date format is invalid');\n }\n $maxExpiration = Carbon::now()->addYear();\n if ($expiresAtDate->gt($maxExpiration)) {\n throw new InvalidArgumentException('Expiration date cannot be more than 1 year from now');\n }\n if ($expiresAtDate->isPast()) {\n throw new InvalidArgumentException('Expiration date cannot be in the past');\n }\n\n // Validate saved search\n $activitySearchId = $data['saved_search'] ?? null;\n if (empty($activitySearchId)) {\n throw new InvalidArgumentException('Saved search is required');\n }\n $savedSearch = $this->activitySearchRepository->findByUuidAndUser($activitySearchId, $user);\n if (! $savedSearch) {\n throw new InvalidArgumentException('Saved search not found or does not belong to you');\n }\n\n // Validate saved prompt\n $askAnythingPromptId = $data['ask_jiminny_prompt'] ?? null;\n if (empty($askAnythingPromptId)) {\n throw new InvalidArgumentException('Ask Jiminny prompt is required');\n }\n $prompt = $this->askAnythingRepository->getPromptByUuid($askAnythingPromptId);\n if (! $prompt) {\n throw new InvalidArgumentException('Ask Jiminny prompt not found');\n }\n\n // Validate status\n $status = $data['enabled'] ?? false;\n\n $recipientUserIds = [$user->getId()];\n\n if (! empty($data['share_users'])) {\n $sharedUserIds = $this->validateAndGetUserIdsByTeam(\n $user->team,\n (array) $data['share_users']\n );\n $recipientUserIds = array_merge($recipientUserIds, $sharedUserIds);\n }\n\n $sharedGroupIds = [];\n if (! empty($data['share_teams'])) {\n $sharedGroupIds = $this->validateAndGetGroupIds($user->team, (array) $data['share_teams']);\n }\n\n $recipientUserIds = array_values(array_unique($recipientUserIds));\n\n return [\n 'team_id' => $user->getTeamId(),\n 'type' => self::TYPE_ASK_JIMINNY,\n 'status' => (bool) $status,\n 'frequency' => $frequency,\n 'custom_name' => $name,\n 'activity_search_id' => $savedSearch->getId(),\n 'ask_anything_prompt_id' => $prompt->getId(),\n 'expires_at' => $expiresAtDate->toDateString(),\n 'media_types' => [self::MEDIA_TYPE_PDF],\n 'call_types' => [],\n 'recipients' => ['users' => $recipientUserIds],\n 'groups' => $sharedGroupIds,\n ];\n }\n\n public static function getAskJiminnyFrequencies(): array\n {\n return array_map(static function ($frequency) {\n return $frequency['id'];\n }, self::ASK_JIMINNY_FREQUENCIES);\n }\n\n public function getAskJiminnyReportFilters(User $user): array\n {\n $savedSearches = $this->activitySearchRepository->findByUserOrderedByName($user)\n ->map(fn (Search $search) => [\n 'id' => $search->getUuid(),\n 'name' => $search->getName(),\n ])\n ->values()->all();\n\n $prompts = collect(\n $this->askAnythingPromptService->get($user, AskAnythingPromptTarget::on_demand)\n )->map(fn (AskAnythingPromptDto $prompt) => [\n 'id' => $prompt->id,\n 'name' => $prompt->title,\n ])->values()->all();\n\n return [\n [\n 'id' => 'prompt',\n 'label' => 'Prompt',\n 'options' => $prompts,\n ],\n [\n 'id' => 'saved_search',\n 'label' => 'Saved Search',\n 'options' => $savedSearches,\n ],\n ];\n }\n\n public function getAskJiminnyReportFormData(User $user, ?AutomatedReport $report = null): array\n {\n $team = $user->getTeam();\n $userTimezone = $user->getTimezone();\n\n $savedSearches = $this->activitySearchRepository->findByUserOrderedByName($user)\n ->map(fn (Search $search) => [\n 'id' => $search->getUuid(),\n 'name' => $search->getName(),\n ])\n ->values()->all();\n\n $prompts = collect(\n $this->askAnythingPromptService->get($user, AskAnythingPromptTarget::on_demand)\n )->map(fn (AskAnythingPromptDto $prompt) => [\n 'id' => $prompt->id,\n 'name' => $prompt->title,\n ])->values()->all();\n\n $teamGroups = $this->groupRepository->getAllByTeam($team)->map(fn ($group) => [\n 'id' => $group->getUuid(),\n 'name' => $group->getName(),\n ])->values()->all();\n\n $shareUsers = $this->recipientsService->getRecipientsFieldData(team: $team)['options'] ?? [];\n\n $sharedTeamsValue = [];\n $sharedUsersValue = [];\n if ($report) {\n $sharedTeamsValue = $this->transformGroups($team, $report->getGroups());\n\n $recipientUserIds = $report->getRecipients()['users'] ?? [];\n $creatorId = $report->getAttribute('created_by');\n $sharedUserIds = array_values(array_filter(\n $recipientUserIds,\n static fn ($id) => $id !== $creatorId\n ));\n $sharedUsersValue = collect($sharedUserIds)\n ->map(fn ($id) => $this->userRepository->find((int) $id))\n ->filter()\n ->map(fn (User $u) => [\n 'id' => $u->getUuid(),\n 'name' => $u->getName(),\n ])\n ->values()\n ->all();\n }\n\n return [\n 'fields' => [\n [\n 'id' => 'enabled',\n 'inputType' => InputTypeEnum::TOGGLE,\n 'label' => '',\n 'value' => $report?->getStatus() ?? false,\n ],\n [\n 'id' => 'report_name',\n 'inputType' => InputTypeEnum::TEXT,\n 'label' => 'Name',\n 'placeholder' => 'Enter name',\n 'required' => true,\n 'validation' => ['maxLength' => 50],\n 'value' => $report?->getCustomName() ?? '',\n ],\n [\n 'id' => 'frequency',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'label' => 'Frequency',\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => self::ASK_JIMINNY_FREQUENCIES,\n 'value' => $report ? $this->transformFrequency($report->getFrequency()) : null,\n ],\n [\n 'id' => 'expires_on',\n 'inputType' => InputTypeEnum::DATE,\n 'label' => 'Expires on',\n 'required' => true,\n 'placeholder' => 'Select',\n 'validation' => [\n 'minDate' => now($userTimezone)->toDateString(),\n 'maxDate' => now($userTimezone)->addYear()->toDateString(),\n ],\n 'value' => $report?->getExpiresAt()?->toDateString(),\n ],\n [\n 'id' => 'share_teams',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'label' => 'Team',\n 'required' => false,\n 'placeholder' => 'Select',\n 'options' => $teamGroups,\n 'value' => $sharedTeamsValue,\n ],\n [\n 'id' => 'share_users',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'label' => 'Team member',\n 'required' => false,\n 'placeholder' => 'Select',\n 'groupLabelKey' => 'label',\n 'groupValuesKey' => 'users',\n 'optionLabelKey' => 'name',\n 'optionValueKey' => 'id',\n 'options' => $shareUsers,\n 'value' => $sharedUsersValue,\n ],\n [\n 'id' => 'saved_search',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'label' => 'Saved search',\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => $savedSearches,\n 'value' => $report && $report->getSavedSearch() ? [\n 'id' => $report->getSavedSearch()->getUuid(),\n 'name' => $report->getSavedSearch()->getName(),\n ] : null,\n ],\n [\n 'id' => 'ask_jiminny_prompt',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'label' => 'Ask Jiminny prompt',\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => $prompts,\n 'value' => $report && $report->getAskAnythingPrompt() ? [\n 'id' => $report->getAskAnythingPrompt()->getUuid(),\n 'name' => $report->getAskAnythingPrompt()->getTitle(),\n ] : null,\n ],\n ],\n ];\n }\n\n private function updateResultNames(AutomatedReport $automatedReport): void\n {\n $results = $this->automatedReportsRepository->getResultsByReport($automatedReport);\n\n foreach ($results as $result) {\n $result->update(['name' => $this->getReportFileName($result)]);\n }\n }\n\n public function updateStatus(string $uuid, array $data): array\n {\n $automatedReport = $this->automatedReportsRepository->findByUuid($uuid);\n\n if (! $automatedReport) {\n throw new ModelNotFoundException('Report not found');\n }\n\n $status = $this->validateReportStatus($data['report_enabled'] ?? null);\n $automatedReport->update([\n 'status' => $status,\n ]);\n\n $this->generateOneOffReport($automatedReport);\n\n return $this->transformReportFullView($automatedReport);\n }\n\n private function generateOneOffReport(AutomatedReport $automatedReport): void\n {\n // the scheduler handles all the other frequency types\n if ($automatedReport->getStatus() === false || $automatedReport->getFrequency() !== self::FREQUENCY_ONE_OFF) {\n return;\n }\n\n $this->dispatcher->dispatch(new RequestGenerateReportJob($automatedReport->getUuid()));\n }\n\n public function getReport(string $uuid): AutomatedReport\n {\n $automatedReport = $this->automatedReportsRepository->findByUuid($uuid);\n\n if (! $automatedReport) {\n throw new ModelNotFoundException('Report not found');\n }\n\n return $automatedReport;\n }\n\n public function get(string $uuid): array\n {\n $automatedReport = $this->getReport($uuid);\n\n return $this->transformReportFullView($automatedReport);\n }\n\n public function list(string $sortColumn = 'created_at', string $sortDirection = 'desc'): array\n {\n $results = [];\n $collection = $this->automatedReportsRepository->getAllStandardReports($sortColumn, $sortDirection);\n\n /** @var AutomatedReport $report */\n foreach ($collection as $report) {\n $results[] = $this->transformReportFullView($report);\n }\n\n return ['data' => $results];\n }\n\n public function listAskJiminnyReports(\n User $user,\n string $sortColumn = 'created_at',\n string $sortDirection = 'desc'\n ): array {\n $results = [];\n $collection = $this->automatedReportsRepository->getAskJiminnyReportsByUser($user, $sortColumn, $sortDirection);\n\n /** @var AutomatedReport $report */\n foreach ($collection as $report) {\n $results[] = $this->transformReportFullView($report);\n }\n\n return ['data' => $results];\n }\n\n public function delete(string $uuid): void\n {\n $automatedReport = $this->automatedReportsRepository->findByUuid($uuid);\n\n if (! $automatedReport) {\n throw new ModelNotFoundException('Report not found');\n }\n\n $automatedReport->delete();\n }\n\n public function createReportResult(AutomatedReport $automatedReport, array $data = []): AutomatedReportResult\n {\n return $this->automatedReportsRepository->createResult(\n array_merge(\n [\n 'report_id' => $automatedReport->getId(),\n 'status' => AutomatedReportResult::STATUS_DEFAULT,\n ],\n $data\n )\n );\n }\n\n public function getReportResult(string $resultUuid): AutomatedReportResult\n {\n $report = $this->automatedReportsRepository->findResultByUuid($resultUuid);\n\n if (! $report) {\n throw new ModelNotFoundException('Report Result not found');\n }\n\n return $report;\n }\n\n public function findChildResult(AutomatedReportResult $result, string $type): ?AutomatedReportResult\n {\n return $this->automatedReportsRepository->findChildResult($result, $type);\n }\n\n // prophet API calls\n /**\n * @throws ApplicationException\n */\n public function getGenerateReportPayload(AutomatedReport $automatedReport, string $reportResultUuid): array\n {\n $period = $this->calculateFromAndToDate($automatedReport);\n $fromDate = $period['fromDate'];\n $toDate = $period['toDate'];\n\n return [\n 'team_id' => $automatedReport->getTeamId(),\n 'request_id' => $reportResultUuid,\n 'report_type' => $automatedReport->getType(),\n 'media_types' => $automatedReport->getMediaTypes(),\n 'from_date' => $fromDate->startOfDay()->format(DateTimeInterface::RFC3339),\n 'to_date' => $toDate->endOfDay()->format(DateTimeInterface::RFC3339),\n 'group_ids' => $automatedReport->getGroups(),\n 'call_deal_stage' => $automatedReport->getDealAtCallStages(),\n 'current_deal_stage' => $automatedReport->getCurrentDealStages(),\n 'deal_min_value' => $automatedReport->getDealValueMin(),\n 'deal_max_value' => $automatedReport->getDealValueMax(),\n 'call_types' => $automatedReport->getCallTypes(),\n 'call_duration_min_seconds' => $automatedReport->getCallDurationMin(),\n 'call_duration_max_seconds' => $automatedReport->getCallDurationMax(),\n 'special_requirements' => $automatedReport->getAdditionalPromptInput(),\n 'callback_url' => $this->getCallbackUrl(),\n 'report_period' => $this->formatReportPeriodName(\n $automatedReport->getFrequency(),\n $fromDate,\n $toDate,\n ),\n 'playbook_categories' => $automatedReport->getPlaybookCategories(),\n 'custom_name' => $automatedReport->getCustomName(),\n ];\n }\n\n // $inputPayload - FE payload structure\n public function getActivitiesCountPayload(array $inputPayload): array\n {\n // Use validateAndTransformData to validate and normalize input\n $validatedData = $this->validateAndTransformData($inputPayload);\n $period = $this->calculateFromAndToDatePeriod(\n $validatedData['frequency'],\n Carbon::parse($validatedData['from']),\n Carbon::parse($validatedData['to']),\n );\n $fromDate = $period['fromDate'];\n $toDate = $period['toDate'];\n\n // Create payload similar to getGenerateReportPayload\n return [\n 'team_id' => $validatedData['team_id'],\n 'group_ids' => $validatedData['groups'] ?? [],\n 'report_type' => $validatedData['type'],\n 'from_date' => $fromDate->format(DateTimeInterface::RFC3339),\n 'to_date' => $toDate->format(DateTimeInterface::RFC3339),\n 'call_deal_stage' => $validatedData['deal_at_call_stages'] ?? [],\n 'current_deal_stage' => $validatedData['current_deal_stages'] ?? [],\n 'deal_min_value' => $validatedData['deal_value_min'] ?? null,\n 'deal_max_value' => $validatedData['deal_value_max'] ?? null,\n 'call_types' => $validatedData['call_types'],\n 'call_duration_min_seconds' => $validatedData['call_duration_min'] ?? null,\n 'call_duration_max_seconds' => $validatedData['call_duration_max'] ?? null,\n 'special_requirements' => $validatedData['additional_prompt_input'] ?? null,\n 'playbook_categories' => $validatedData['playbook_categories'] ?? [],\n 'request_id' => null,\n 'callback_url' => null,\n ];\n }\n\n public function shouldSendReport(array $users, ?CarbonInterface $generatedAt = null): bool\n {\n if (empty($users)) {\n return false;\n }\n\n $earliestTz = collect($users)\n ->mapWithKeys(function (array $user) {\n $tz = new DateTimeZone($user['timezone']);\n $nowUtc = new DateTime('now', new DateTimeZone('UTC'));\n $offset = $tz->getOffset($nowUtc);\n\n return [$user['timezone'] => $offset];\n })\n ->sortDesc()\n ->keys()\n ->first();\n\n $now = Carbon::now($earliestTz);\n $isScheduledTime = (int) $now->format('H') === self::SENT_REPORT_AT_HOURS;\n\n if ($isScheduledTime) {\n return true;\n }\n\n return $this->hasPassedScheduledTime($generatedAt, $earliestTz);\n }\n\n public function hasPassedScheduledTime(?CarbonInterface $generatedAt, string $timezone): bool\n {\n if ($generatedAt === null) {\n return false;\n }\n\n $now = Carbon::now($timezone);\n $scheduledTime = $now->copy()->setTime(self::SENT_REPORT_AT_HOURS, 0, 0);\n\n if ($now->hour < self::SENT_REPORT_AT_HOURS) {\n $scheduledTime = $scheduledTime->subDay();\n }\n\n $scheduledTimeUtc = $scheduledTime->copy()->utc();\n $generatedAtUtc = $generatedAt->copy()->utc();\n $nowUtc = $now->copy()->utc();\n\n return $generatedAtUtc->lt($scheduledTimeUtc) && $nowUtc->gt($scheduledTimeUtc);\n }\n\n public function calculateFromAndToDatePeriod(\n string $frequency,\n ?Carbon $fromDate = null,\n ?Carbon $toDate = null\n ): array {\n if ($frequency === self::FREQUENCY_ONE_OFF) {\n return [\n 'fromDate' => $fromDate,\n 'toDate' => $toDate,\n ];\n }\n\n $now = Carbon::now();\n\n return match ($frequency) {\n self::FREQUENCY_DAILY => [\n 'fromDate' => $now->copy()->subDay()->startOfDay(),\n 'toDate' => $now->copy()->subDay()->endOfDay(),\n ],\n self::FREQUENCY_WEEKLY => [\n 'fromDate' => $now->copy()->subWeeks(1)->startOfDay(),\n 'toDate' => $now->copy()->subDay()->endOfDay(),\n ],\n self::FREQUENCY_MONTHLY => [\n 'fromDate' => $now->copy()->subMonths(1)->startOfDay(),\n 'toDate' => $now->copy()->subDay()->endOfDay(),\n ],\n self::FREQUENCY_QUARTERLY => [\n 'fromDate' => $now->copy()->subMonths(3)->startOfDay(),\n 'toDate' => $now->copy()->subDay()->endOfDay(),\n ],\n default => throw new InvalidArgumentException(\"Unsupported frequency: {$frequency}\"),\n };\n }\n\n private function calculateFromAndToDate(AutomatedReport $automatedReport): array\n {\n return $this->calculateFromAndToDatePeriod(\n $automatedReport->getFrequency(),\n $automatedReport->getFrom(),\n $automatedReport->getTo()\n );\n }\n\n public function getAskJiminnyGenerateReportPayload(\n AutomatedReport $automatedReport,\n AutomatedReportResult $reportResult,\n array $activityIds,\n ): array {\n return [\n 'user_question' => $automatedReport->getAskAnythingPrompt()?->getContent(),\n 'call_ids' => array_map('strval', $activityIds),\n 'team_id' => $automatedReport->getTeamId(),\n 'request_id' => $reportResult->getUuid(),\n 'callback_url' => $this->getCallbackUrl(),\n 'report_period' => $this->getReportPeriodName($reportResult),\n 'report_name' => $automatedReport->getCustomName(),\n ];\n }\n\n private function getCallbackUrl(): string\n {\n return $this->webhookService->route('jiminny.webhook.reports.ready');\n }\n\n /**\n * Validate and transform payload data for automated reports\n *\n * @param array $data\n *\n * @throws InvalidArgumentException\n *\n * @return array\n */\n private function validateAndTransformData(array $data): array\n {\n // Validate organization (team) and check feature\n $team = $this->validateOrganization($data['organization'] ?? null);\n\n $status = $this->validateReportStatus($data['report_enabled'] ?? null);\n $type = $this->validateReportType($data['report_type'] ?? null);\n $frequency = $this->validateFrequency($data['frequency'] ?? null);\n $additionalPromptInput = $this->validateAdditionalPromptInput(\n $data['additional_prompt_input'] ?? null\n );\n $customReportName = $this->validateCustomReportName($data['custom_name'] ?? null);\n\n // Prepare data for the database\n $reportData = [\n 'team_id' => $team->getId(),\n 'type' => $type,\n 'status' => $status,\n 'frequency' => $frequency,\n 'additional_prompt_input' => $additionalPromptInput,\n 'custom_name' => $customReportName,\n ];\n\n // Validate deal values\n $reportData = $this->validateDealValues($data, $reportData);\n\n // Validate date range\n $reportData = $this->validateDateRange($data, $reportData, $frequency);\n\n // Validate call durations\n $reportData = $this->validateCallDurations($data, $reportData);\n\n // Validate call types\n $reportData = $this->validateCallTypes($data, $reportData);\n\n // Validate media types\n $reportData = $this->validateMediaTypes($data, $reportData);\n\n // Validate groups\n if (isset($data['teams'])) {\n $reportData['groups'] = $this->validateAndGetGroupIds($team, $data['teams']);\n }\n\n // Validate deal stages\n $reportData = $this->validateDealStages($data, $reportData, $team, $type);\n\n // Validate playbook categories\n $reportData = $this->validatePlaybookCategories($data, $reportData, $team);\n\n // Validate recipients\n $reportData['recipients'] = [\n 'users' => $this->validateAndGetUserIdsByTeam($team, $data['recipients'] ?? []),\n ];\n\n if (isset($data['jiminny_recipients'])) {\n // Validate Jiminny recipients\n $reportData['jiminny_recipients'] = [\n 'users' => $this->validateAndGetJiminnyUserIds((array) $data['jiminny_recipients']),\n ];\n }\n\n return $reportData;\n }\n\n private function validateDealValues(array $data, array $reportData): array\n {\n if (isset($data['min_deal_value'])) {\n $reportData['deal_value_min'] = (int) $data['min_deal_value'];\n\n if ($reportData['deal_value_min'] > 4294967295 || $reportData['deal_value_min'] < 0) {\n throw new InvalidArgumentException('Min deal value should be between 0 and 4294967295');\n }\n }\n\n if (isset($data['max_deal_value'])) {\n $reportData['deal_value_max'] = (int) $data['max_deal_value'];\n\n if ($reportData['deal_value_max'] > 4294967295 || $reportData['deal_value_max'] < 0) {\n throw new InvalidArgumentException('Max deal value should be between 0 and 4294967295');\n }\n }\n\n if (isset($data['min_deal_value'], $data['max_deal_value'])\n && $data['min_deal_value'] > $data['max_deal_value']\n ) {\n throw new InvalidArgumentException('Min deal value cannot be greater than max deal value');\n }\n\n return $reportData;\n }\n\n private function validateDateRange(array $data, array $reportData, string $frequency): array\n {\n // Set date range only for one_off frequency\n if ($frequency === 'one_off') {\n if (isset($data['start_date_period'])) {\n $reportData['from'] = $this->parseDate($data['start_date_period']);\n }\n\n if (isset($data['end_date_period'])) {\n $reportData['to'] = $this->parseDate($data['end_date_period']);\n }\n\n if (empty($reportData['from']) || empty($reportData['to'])) {\n throw new InvalidArgumentException(\n 'Start date and end date are required for one_off frequency'\n );\n }\n } else {\n $reportData['from'] = null;\n $reportData['to'] = null;\n }\n\n return $reportData;\n }\n\n private function validateCallDurations(array $data, array $reportData): array\n {\n // Convert call durations from minutes to seconds\n if (isset($data['min_call_duration'])) {\n $reportData['call_duration_min'] = (int) $data['min_call_duration'] * 60;\n\n if ($reportData['call_duration_min'] > 4294967295 || $reportData['call_duration_min'] < 0) {\n throw new InvalidArgumentException('Min call duration should be between 0 and 4294967295');\n }\n }\n\n if (isset($data['max_call_duration'])) {\n $reportData['call_duration_max'] = (int) $data['max_call_duration'] * 60;\n\n if ($reportData['call_duration_max'] > 4294967295 || $reportData['call_duration_max'] < 0) {\n throw new InvalidArgumentException('Max call duration should be between 0 and 4294967295');\n }\n }\n\n return $reportData;\n }\n\n private function validateCallTypes(array $data, array $reportData): array\n {\n // Set call types\n $reportData['call_types'] = $data['call_type'] ?? [];\n if (empty($reportData['call_types'])) {\n $reportData['call_types'] = self::getCallTypes();\n }\n\n foreach ($reportData['call_types'] as $callType) {\n if (! in_array($callType, self::getCallTypes(), true)) {\n throw new InvalidArgumentException(sprintf('Call type %s is invalid', $callType));\n }\n }\n\n return $reportData;\n }\n\n private function validateMediaTypes(array $data, array $reportData): array\n {\n // Set media types from input data\n $reportData['media_types'] = $data['media_types'] ?? [];\n\n if (empty($reportData['media_types'])) {\n throw new InvalidArgumentException('Media types are required');\n }\n\n foreach ($reportData['media_types'] as $mediaType) {\n if (! in_array($mediaType, self::MEDIA_TYPES, true)) {\n throw new InvalidArgumentException(sprintf('Media type %s is invalid', $mediaType));\n }\n }\n\n return $reportData;\n }\n\n private function validateDealStages(array $data, array $reportData, Team $team, string $reportType): array\n {\n // Validate and set deal stages\n if (isset($data['deal_stage_at_call'])) {\n $reportData['deal_at_call_stages'] =\n $this->validateAndGetDealStageIds($team, $data['deal_stage_at_call'], 'Deal stage at call');\n }\n\n if (isset($data['current_deal_stage'])) {\n $reportData['current_deal_stages'] =\n $this->validateAndGetDealStageIds($team, $data['current_deal_stage'], 'Current deal stage');\n }\n\n // Ensure current_deal_stage is not provided for loss_analysis report type\n if ($reportType === self::TYPE_LOSS_ANALYSIS && ! empty($data['current_deal_stage'])) {\n throw new InvalidArgumentException('Current deal stage is not applicable for Loss Analysis reports');\n }\n\n return $reportData;\n }\n\n // transform uuid to id\n private function validatePlaybookCategories(array $data, array $reportData, Team $team): array\n {\n $key = 'playbook_categories';\n\n if (isset($data[$key])) {\n $payloadIds = $data[$key];\n $ids = [];\n\n foreach ($payloadIds as $uuid) {\n $uuid = (string) $uuid;\n\n try {\n $playbookCategory = $this->playbookCategoryRepository->findByUuid($uuid);\n } catch (Throwable $throwable) {\n Log::error(__METHOD__ . ' ' . $throwable->getMessage());\n\n throw new InvalidArgumentException(sprintf('Playbook category %s not found', $uuid));\n }\n\n if (! $playbookCategory) {\n throw new InvalidArgumentException(sprintf('Playbook category %s not found', $uuid));\n }\n\n if (! $playbookCategory->hasPlaybook()) {\n throw new InvalidArgumentException(sprintf('Playbook category %s has no playbook', $uuid));\n }\n\n if ($playbookCategory->getPlaybook()->getTeamId() !== $team->getId()) {\n throw new InvalidArgumentException(\n sprintf('Playbook category %s not found for team %s', $uuid, $team->getUuid())\n );\n }\n\n $ids[] = $playbookCategory->getId();\n }\n\n $reportData[$key] = $ids;\n }\n\n return $reportData;\n }\n\n private function validateReportStatus($status): bool\n {\n if (! in_array($status, [true, false], true)) {\n throw new InvalidArgumentException('Report status is invalid');\n }\n\n return $status;\n }\n\n private function validateReportType($type): string\n {\n if (! in_array($type, self::getTypes(), true)) {\n throw new InvalidArgumentException(sprintf('Report type is invalid: %s', $type));\n }\n\n return $type;\n }\n\n private function validateFrequency($frequency): string\n {\n if (! in_array($frequency, self::getFrequencies(), true)) {\n throw new InvalidArgumentException('Frequency is invalid');\n }\n\n return $frequency;\n }\n\n private function validateAdditionalPromptInput(?string $additionalPromptInput): ?string\n {\n if ($additionalPromptInput && strlen($additionalPromptInput) > 5000) {\n throw new InvalidArgumentException('Additional Prompt Input should be less than 5000 characters');\n }\n\n return $additionalPromptInput;\n }\n\n private function validateCustomReportName(?string $customReportName): ?string\n {\n if ($customReportName === null || $customReportName === '') {\n return null;\n }\n\n if (strlen($customReportName) > 70) {\n throw new InvalidArgumentException('Custom report name should be less than 70 characters');\n }\n\n return $customReportName;\n }\n\n private function validateOrganization(?string $organizationUuid): Team\n {\n if (! $organizationUuid) {\n throw new InvalidArgumentException('Organization is required');\n }\n\n $team = $this->teamRepository->idOrUuid($organizationUuid);\n\n if (! $team) {\n throw new InvalidArgumentException('Organization not found');\n }\n\n if (! $team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {\n throw new InvalidArgumentException('Organization does not have the Automated Reports feature');\n }\n\n return $team;\n }\n\n private function validateAndGetGroupIds(Team $team, array $teamUuids): array\n {\n $groupIds = [];\n\n foreach ($teamUuids as $uuid) {\n $group = $this->groupRepository->findByUuid($uuid);\n\n if ($group === null || $group->getTeamId() !== $team->getId()) {\n throw new InvalidArgumentException(\n sprintf('Group %s not found for team %s', $uuid, $team->getUuid())\n );\n }\n\n $groupIds[] = $group->getId();\n\n }\n\n return $groupIds;\n }\n\n private function validateAndGetDealStageIds(Team $team, array $stageUuids, string $propertyLabel): array\n {\n $stageIds = [];\n\n foreach ($stageUuids as $uuid) {\n $stage = $this->stageRepository->findByUuid($uuid);\n\n if ($stage === null || $stage->getTeamId() !== $team->getId()) {\n throw new InvalidArgumentException(\n sprintf('Stage %s not found for team %s for %s', $uuid, $team->getUuid(), $propertyLabel)\n );\n }\n\n $stageIds[] = $stage->getId();\n }\n\n return $stageIds;\n }\n\n private function validateAndGetUserIds(array $userUuids, callable $teamCheck): array\n {\n if (empty($userUuids)) {\n return [];\n }\n\n $userIds = [];\n\n foreach ($userUuids as $uuid) {\n $user = $this->userRepository->findByUuid($uuid);\n\n if (! $user || ! $user->isStatusActive()) {\n throw new InvalidArgumentException(\n sprintf('User %s not found or is not active', $uuid)\n );\n }\n\n if (! $teamCheck($user)) {\n throw new InvalidArgumentException(\n sprintf('User %s does not belong to the allowed team(s)', $uuid)\n );\n }\n\n $userIds[] = $user->getId();\n }\n\n return $userIds;\n }\n\n private function validateAndGetUserIdsByTeam(Team $team, array $userUuids): array\n {\n return $this->validateAndGetUserIds($userUuids, fn ($user) => $user->getTeamId() === $team->getId());\n }\n\n private function validateAndGetJiminnyUserIds(array $userUuids): array\n {\n $allowedTeamIds = config('kiosk.teamIds', []);\n\n return $this->validateAndGetUserIds($userUuids, fn ($user) => in_array($user->getTeamId(), $allowedTeamIds, true));\n }\n\n private function parseDate(string $dateString): string\n {\n return date('Y-m-d H:i:s', strtotime($dateString));\n }\n\n private function generateReportResultViewUrl(AutomatedReportResult $result): string\n {\n $mediaResource = $this->getReportMediaRouteResource($result);\n\n return route('ai-reports.' . $mediaResource . '.view', ['uuid' => $result->getUuid()]);\n }\n\n private function generateReportResultDownloadUrl(AutomatedReportResult $result): string\n {\n $mediaResource = $this->getReportMediaRouteResource($result);\n\n return route('ai-reports.' . $mediaResource . '.download', ['uuid' => $result->getUuid()]);\n }\n\n private function getReportMediaRouteResource(AutomatedReportResult $result): string\n {\n if ($result->getMediaType() === self::MEDIA_TYPE_PDF) {\n return self::PDF_KEY;\n } elseif ($result->getMediaType() === self::MEDIA_TYPE_PODCAST) {\n return self::AUDIO_KEY;\n }\n\n throw new \\InvalidArgumentException('Unknown media type.');\n }\n\n public function getMediaPath(AutomatedReportResult $result): ?string\n {\n $url = match ($result->getMediaType()) {\n self::MEDIA_TYPE_PDF => $result->getPdfUrl(),\n self::MEDIA_TYPE_PODCAST => $result->getPodcastAudioUrl(),\n default => null,\n };\n\n if ($url === null) {\n return null;\n }\n\n $path = parse_url(trim($url, '\"\\''), PHP_URL_PATH);\n\n return $path ?: null;\n }\n\n public function getFilenameSuffix(AutomatedReportResult $result): ?string\n {\n return match ($result->getMediaType()) {\n self::MEDIA_TYPE_PODCAST => 'Podcast',\n default => null,\n };\n }\n\n public function getMailSubjectSuffix(AutomatedReportResult $result): string\n {\n return match ($result->getMediaType()) {\n self::MEDIA_TYPE_PDF => 'report',\n self::MEDIA_TYPE_PODCAST => 'podcast',\n default => '',\n };\n }\n\n public function getMediaTypeMetadata(AutomatedReportResult $result): array\n {\n return match ($result->getMediaType()) {\n self::MEDIA_TYPE_PODCAST => ['extension' => 'mp3', 'mime' => 'audio/mpeg'],\n self::MEDIA_TYPE_PDF => ['extension' => 'pdf', 'mime' => 'application/pdf'],\n default => ['extension' => null, 'mime' => null],\n };\n }\n\n public function deleteS3Files(AutomatedReportResult $result): void\n {\n $teamUuid = $result->getReport()->getTeam()->getUuid();\n $reportUuid = $result->getUuid();\n\n // delete all files for a report uuid no mather of pdf, podcast, or both\n // in case of both - the podcast files are linked to the pdf (parent) uuid\n // pdf and podcast date times should be close\n $path = sprintf('%s/%s/%s', $teamUuid, self::S3_DIR, $reportUuid);\n\n foreach (self::FILE_EXTENSIONS_VARIANTS as $extension) {\n $file = $path . '.' . $extension;\n\n if (Storage::exists($file)) {\n Storage::delete($file);\n Log::info('[Reports] Deleted S3 file', [\n 'path' => $file,\n ]);\n }\n }\n\n foreach (self::FILE_PODCAST_EXTENSIONS_VARIANTS as $extension) {\n $file = $path . '_podcast.' . $extension;\n\n if (Storage::exists($file)) {\n Storage::delete($file);\n Log::info('[Reports] Deleted Podcast S3 file', [\n 'path' => $file,\n ]);\n }\n }\n }\n\n /**\n *\n * @param int|null $teamId Optional team ID to filter results\n *\n * @return Collection<int, int> Collection of team IDs\n */\n public function getTeamIdsWithReportsResults(?int $teamId = null): Collection\n {\n return $this->automatedReportsRepository->getTeamIdsWithReportsResults($teamId);\n }\n\n /**\n * Core delete logic for report results using a query\n *\n * @param Builder $query\n * @param array $logContext\n *\n * @return int\n */\n private function deleteReportResultsByQuery(Builder $query, array $logContext = []): int\n {\n $deletedCount = 0;\n\n if ($query->exists()) {\n Log::info(\n 'Run delete report results',\n array_merge(\n $logContext,\n [\n 'service' => 'AutomatedReportsService',\n ]\n )\n );\n\n $query->chunkById(50, function ($results) use (&$deletedCount, $logContext) {\n foreach ($results as $result) {\n $this->deleteReportResult($result);\n $deletedCount++;\n\n Log::info(\n 'Deleted a report result',\n array_merge(\n $logContext,\n [\n 'result_id' => $result->getId(),\n 'report_id' => $result->getReportId(),\n ]\n )\n );\n }\n });\n }\n\n return $deletedCount;\n }\n\n /**\n * Delete report results for a team by retention period\n *\n * @param Team $team\n * @param CarbonImmutable $retentionDate\n *\n * @return int Number of deleted report results\n */\n public function deleteReportsResultsInRetentionPeriod(Team $team, CarbonImmutable $retentionDate): int\n {\n $reportIds = $this->automatedReportsRepository->getReportIdsByTeam($team);\n\n if ($reportIds->isEmpty()) {\n return 0;\n }\n\n $query = $this->automatedReportsRepository\n ->getReportResultsQueryForRetention($team, $retentionDate);\n\n return $this->deleteReportResultsByQuery($query, [\n 'team_id' => $team->getId(),\n 'retention_date' => $retentionDate->toDateTimeString(),\n ]);\n }\n\n /**\n * Delete ALL report results for a specific automated report\n *\n * @param string $uuid\n *\n * @return int\n */\n public function deleteReportResults(string $uuid): int\n {\n $report = $this->getReport($uuid);\n\n $query = $this->automatedReportsRepository->getResultsByReportQuery($report);\n\n return $this->deleteReportResultsByQuery($query, [\n 'report_uuid' => $uuid,\n 'report_id' => $report->getId(),\n ]);\n }\n\n public function deleteReportResult(AutomatedReportResult $result): void\n {\n $this->deleteS3Files($result);\n\n $result->delete();\n }\n\n /**\n * Get all reports for a specific team\n *\n * @param Team $team\n *\n * @return \\Illuminate\\Database\\Eloquent\\Collection\n */\n public function getTeamReports(Team $team): \\Illuminate\\Database\\Eloquent\\Collection\n {\n return $this->automatedReportsRepository->getReportsByTeam($team);\n }\n\n /**\n * Get all report results for a specific report\n *\n * @param AutomatedReport $report\n *\n * @return \\Illuminate\\Database\\Eloquent\\Collection\n */\n public function getReportResults(AutomatedReport $report): \\Illuminate\\Database\\Eloquent\\Collection\n {\n return $this->automatedReportsRepository->getResultsByReport($report);\n }\n\n public function deleteAllReportResults(AutomatedReport $report): void\n {\n $results = $this->getReportResults($report);\n\n /** @var AutomatedReportResult $result */\n foreach ($results as $result) {\n Log::info('Deleting result', [\n 'report' => $report->getId(),\n 'result' => $result->getId(),\n ]);\n\n $this->deleteReportResult($result);\n }\n }\n\n public function deleteAllData(Team $team): void\n {\n Log::info('Deleting automated report and results for team', [\n 'team' => $team->getId(),\n ]);\n\n $reports = $this->getTeamReports($team);\n\n /** @var AutomatedReport $report */\n foreach ($reports as $report) {\n Log::info('Deleting report', [\n 'team' => $team->getId(),\n 'report' => $report->getId(),\n ]);\n\n $this->deleteAllReportResults($report);\n\n $report->delete();\n }\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":true,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"Project","depth":3,"role_description":"text"},{"role":"AXButton","text":"Project","depth":3,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"New File or Directory…","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Expand Selected","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Collapse All","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Options","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false}]...
|
3397592283435315795
|
6686367547760219213
|
idle
|
accessibility
|
NULL
|
Project: faVsco.js, menu
#11894 on JY-18909-automa Project: faVsco.js, menu
#11894 on JY-18909-automated-reports-ask-jiminny, menu
Start Listening for PHP Debug Connections
AutomatedReportsCommandTest
Run 'AutomatedReportsCommandTest'
Debug 'AutomatedReportsCommandTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Execute
Explain Plan
Browse Query History
View Parameters
Open Query Execution Settings…
In-Editor Results
Tx: Auto
Cancel Running Statements
Playground
jiminny
Sync Changes
Hide This Notification
Code changed:
Hide
16
13
13
Previous Highlighted Error
Next Highlighted Error
SELECT * FROM teams WHERE id = 1;
select * from crm_layouts where crm_configuration_id = 39;
SELECT * FROM crm_layout_entities WHERE crm_layout_id = 283;
SELECT * FROM crm_fields WHERE id = 2234;
SELECT * FROM crm_field_values WHERE crm_field_id = 2234;
select * from crm_profiles where user_id = 143;
select * from record_types where crm_configuration_id = 39; # 0121K000001MHElQAO,0121K000001MHEqQAO
select * from business_processes where crm_configuration_id = 39;
# 01941000000H669AAC, 01941000000H66JAAS
select * from record_type_field_values
where record_type_id IN (24);
select * from crm_field_values where id IN (2730);
select * from crm_configurations where id = 39;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 1
and sa.provider = 'salesforce'; #1035
select * from users where team_id = 1; # 222 group 3
SELECT * FROM activities WHERE user_id = 222 order by id desc;
select * from sidekick_settings where team_id = 1;
select * from teams where id = 1;
select * from team_features where team_id = 1;
select * from activities where crm_configuration_id = 2
and provider = 'ms-teams' and id = 608765;
SELECT * FROM activities WHERE crm_configuration_id = 2 and crm_provider_id = '59523413338';
select * from sidekick_settings where team_id = 2;
SELECT * FROM activities WHERE id = 608660;
select * from activity_summary_logs where activity_id = 608660;
select * from ai_prompts where transcription_id = 11214;
# [PASSWORD_DOTS]
SELECT * FROM activities WHERE uuid_to_bin('ed78a437-2804-450e-ab2f-56ab1c641346') = uuid;
# id: 608818, crm: 59628809737
SELECT * FROM activities WHERE uuid_to_bin('36b06e55-afdd-4782-8dee-c624cd0af191') = uuid;
# id: 608821, crm: 59632069252
SELECT ce.start_time, ce.end_time, a.id, a.uuid, crm_provider_id, calendar_event_id, title,
playbook_category_id, user_id, lead_id, contact_id, account_id, opportunity_id,
scheduled_start_time, scheduled_end_time, actual_start_time, actual_end_time, a.created_at
FROM activities a
join calendar_events ce on a.calendar_event_id = ce.id
WHERE a.id IN (608818, 608821);
select * from users where team_id = 1;
select * from team_settings where team_id = 1;
select * from crm_profiles where crm_configuration_id = 39 order by user_id;
select * from team_features where team_id = 1;
select * from users where team_id = 2;
SELECT * FROM activities WHERE uuid_to_bin('ec7647e9-5225-458b-b475-f31aa2769204') = uuid; # 612639
# Preslava N. Ivanova, grou id 3
SELECT * FROM opportunities WHERE uuid_to_bin('a2928fe5-aec5-46cb-85d9-7654c89e46a6') = uuid;
select * from activities where opportunity_id = 344 and actual_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00';
select
a.id,
a.type,
a.scheduled_start_time,
a.actual_start_time,
a.created_at,
a.opportunity_id,
a.status
FROM activities a
WHERE opportunity_id = 344
and status IN ('completed', 'received', 'delivered')
and (
(a.actual_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00')
OR (a.created_at between '2024-10-11 00:00:00' and '2024-10-12 00:00:00')
OR (a.scheduled_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00'))
;
SELECT * FROM users WHERE id = 222;
SELECT * FROM crm_profiles WHERE user_id = 222;
select * from crm_layouts where crm_configuration_id = 39;
SELECT * FROM crm_layout_entities WHERE crm_layout_id = 281;
select * from group_deal_risk_types;
select * from opportunities where team_id = 1;
SELECT * FROM opportunities WHERE id = 315;
SELECT * FROM crm_field_data WHERE object_id = 315;
select * from crm_field_data where object_id = 260;
select * from generic_ai_prompts where subject_id = 315;
select * from teams; # 36, 21, 121, [EMAIL]
SELECT * FROM social_accounts WHERE sociable_id = 121 and provider = 'bullhorn';
# [PASSWORD_DOTS]
select * from teams where id = 1;
select * from crm_configurations where id = 39;
select * from users where team_id = 1;
select u.email, cp.* from users u
join crm_profiles cp on u.id = cp.user_id
where u.team_id = 1;
# 1 - 00541000004281rAAA
# 204 - 0052g000003freeAAA
# 429 - 0052g000003qGOiAAM
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 1
and sa.provider = 'salesforce';
select * from activities where type = 'softphone'
and created_at > '2024-12-11 15:24:36' order by id desc;
select * from activity_providers where team_id = 1;
select * from activity_provider_users where activity_provider_id = 328;
select * from opportunities where crm_configuration_id = 39
AND account_id = 178 AND is_closed = false
order by created_at DESC;
select * from contacts where id = 3952;
select * from accounts where id = 178;
# [PASSWORD_DOTS]
select * from teams where id = 36;
select * from crm_configurations where id = 21;
select * from users where team_id = 36;
select u.email, cp.* from users u
join crm_profiles cp on u.id = cp.user_id
where u.team_id = 36;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 36
and sa.provider = 'bullhorn';
select * from social_accounts where id = 348;
UPDATE social_accounts SET
provider_user_token = '21442_6802599_91:41179a58-21e7-4d7c-ad58-56bb666b2f65',
provider_refresh_token = '21442_6802599_91:01c6b335-3f2a-42e4-85ff-8a08fa65fceb',
expires = 1733998131,
state = 'connected'
WHERE id = 348;
# [PASSWORD_DOTS]
select * from teams where id = 31;
select * from crm_configurations where id = 18;
select * from users where team_id = 31; # 257
select u.email, cp.* from users u
join crm_profiles cp on u.id = cp.user_id
where u.team_id = 31;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 31
and sa.provider = 'close';
select * from contacts where crm_configuration_id = 18;
# [PASSWORD_DOTS] NEPTUNE [PASSWORD_DOTS]
select * from teams;
select * from users where id IN (1030, 1035, 1052);
select * from crm_configurations;
select * from users where team_id = 65; # 257
select * from team_settings where team_id = 65; # 257
select * from invitations where team_id = 65; # 257
select * from users where email = '[EMAIL]'; # 257
select u.email, cp.* from users u
join crm_profiles cp on u.id = cp.user_id
where u.team_id = 65;
select * from crm_configurations where id = 53;
select * from accounts where crm_configuration_id = 53 order by id desc;
select * from leads where crm_configuration_id = 53 order by id desc;
select * from contacts where crm_configuration_id = 53 order by id desc;
select * from opportunities where crm_configuration_id = 53 order by id desc;
select * from crm_profiles where crm_configuration_id = 53 order by id desc;
select * from crm_fields where crm_configuration_id = 53 order by id desc;
select * from crm_field_values where crm_field_id = 3341 order by id desc;
select * from crm_layouts where crm_configuration_id = 53 order by id desc;
select * from stages where crm_configuration_id = 53 order by id desc;
select * from crm_profiles where crm_configuration_id = 13;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 65
and sa.provider = 'integration-app';
select * from contacts where crm_configuration_id = 13;
select * from social_accounts where sociable_id = 283;
SELECT * FROM opportunities WHERE crm_provider_id = '006O400000E9bzeIAB';
select * from activity_providers where team_id = 65;
SELECT * FROM activities WHERE crm_configuration_id IN (51, 52, 53);
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 65
;
# [PASSWORD_DOTS] STAGING [PASSWORD_DOTS]
SELECT * FROM teams;
SELECT * FROM teams WHERE id = 88;
SELECT * FROM teams WHERE id = 89;
select * from team_settings where team_id = 89;
SELECT * FROM users WHERE team_id = 89;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 89;
select * from users;
SELECT * FROM social_accounts WHERE sociable_id = 1761;
SELECT * FROM crm_configurations WHERE id = 70;
select * from accounts where crm_configuration_id = 70 order by id desc;
select * from leads where crm_configuration_id = 70 order by id desc;
select * from contacts where crm_configuration_id = 70 order by id desc;
select * from opportunities where crm_configuration_id = 70 order by id desc;
select * from crm_profiles where crm_configuration_id = 70 order by id desc;
select * from crm_fields where crm_configuration_id = 70 order by id desc;
select * from crm_field_values where crm_field_id = 3536 order by id desc;
select * from crm_layouts where crm_configuration_id = 70 order by id desc;
select * from stages where crm_configuration_id = 70 order by id desc;
select * from business_processes where crm_configuration_id = 70 order by id desc;
select * from business_process_stages where business_process_id = 34;
select * from contacts where id = 10468;
select * from crm_layouts where crm_configuration_id = 70;
SELECT * FROM crm_layout_entities WHERE crm_layout_id = 388;
SELECT * FROM crm_fields WHERE id IN (3533,3534,3535);
select * from activities where crm_configuration_id = 70
and (account_id IS NOT NULL or lead_id IS NOT NULL or contact_id IS NOT NULL or opportunity_id IS NOT NULL) order by id desc;
SELECT * FROM activities WHERE uuid_to_bin('2e10b60f-8a61-41c5-a3d4-28835353dc65') = uuid;
SELECT * FROM activities where crm_configuration_id = 69 ;
SELECT * FROM users WHERE email LIKE '%[EMAIL]%';
SELECT * FROM activities WHERE uuid_to_bin('5a150c93-40fc-42ec-b3bd-c1d328e09f6e') = uuid;
SELECT * FROM opportunities WHERE id = 385;
select * from participants p
join activities a on p.activity_id = a.id
where a.crm_configuration_id = 70
and (p.lead_id IS NOT NULL or p.contact_id IS NOT NULL);
SELECT * FROM participants WHERE id = 1013638;
select * from teams where id = 90;
select * from users where team_id = 90;
select * from social_accounts where social_accounts.sociable_id IN (1960,1760);
SELECT * FROM crm_profiles WHERE crm_configuration_id = 71;
select * from invitations where team_id = 90;
select * from crm_configurations where id = 71;
select * from accounts where crm_configuration_id = 71 order by id desc;
select * from leads where crm_configuration_id = 71 order by id desc;
select * from contacts where crm_configuration_id = 71 order by id desc;
select * from opportunities where crm_configuration_id = 71 order by id desc;
select * from crm_profiles where crm_configuration_id = 71 order by id desc;
select * from crm_fields where crm_configuration_id = 71 order by id desc;
select * from crm_field_values where crm_field_id = 3341 order by id desc;
select * from crm_layouts where crm_configuration_id = 71 order by id desc;
select * from stages where crm_configuration_id = 71 order by id desc;
select * from users order by secondary_email desc;
select u.id, u.email, u.status, sa.id, sa.provider_user_id from social_accounts sa
join users u on sa.sociable_id = u.id
where sa.provider = 'google' and u.email LIKE 'aneliya%';
select * from failed_jobs order by id desc;
select * from users where email = '[EMAIL]' or secondary_email = '[EMAIL]';
select * from teams;
SELECT * FROM crm_profiles WHERE crm_configuration_id = 39;
SELECT * FROM crm_fields WHERE crm_configuration_id = 39 and object_type = 'task';
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 1
and sa.provider = 'salesforce';
# [PASSWORD_DOTS]
SELECT * FROM activities WHERE uuid_to_bin('c38b3895-fd0f-4b1f-9fb2-c170dba137c6') = uuid;
SELECT * FROM crm_configurations WHERE id = 70;
select * from teams where id = 1;
select * from groups where team_id = 1;
select * from users where team_id = 1;
select o.id, o.name,o.close_date, u.id, u.name, u.group_id, r.id, r.display_name, g.name, g.scope from opportunities o
join users u on o.user_id = u.id
join groups g on u.group_id = g.id
join role_user ru on u.id = ru.user_id
join roles r on ru.role_id = r.id
where o.crm_configuration_id = 39 and close_date > '2024-01-01 00:00:00';
select * from role_user where user_id = 143;
select * from roles;
select * from role_user;
select * from groups where id = 9;
select * from scope_groups where group_id = 9;
# [PASSWORD_DOTS]
select * from teams where id = 36;
select * from crm_configurations;
SELECT * FROM social_accounts WHERE sociable_id = 121;
[URL_WITH_CREDENTIALS] this will add filter, however if we need to control feature by FF we need conditional logic
public const array TYPES = [
['id' => 'exec_summary', 'name' => 'Exec Summary'],
['id' => 'coaching_profiles', 'name' => 'Coaching Profiles'],
['id' => 'product_feedback', 'name' => 'Product Feedback'],
['id' => self::TYPE_LOSS_ANALYSIS, 'name' => 'Loss Analysis'],
// ['id' => 'questions', 'name' => 'Questions'],
// ['id' => 'statistical_quant', 'name' => 'Statistical Quantitative'],
];
public const array ALL_TYPES = [
...self::TYPES,
['id' => self::TYPE_ASK_JIMINNY, 'name' => 'Ask Jiminny'],
];
public const string FREQUENCY_DAILY = 'daily';
public const string FREQUENCY_WEEKLY = 'weekly';
public const string FREQUENCY_MONTHLY = 'monthly';
public const string FREQUENCY_QUARTERLY = 'quarterly';
public const string FREQUENCY_ONE_OFF = 'one_off';
/**
* Frequencies for standard (non-Ask Jiminny) reports.
*/
public const array FREQUENCIES = [
['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],
['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],
['id' => self::FREQUENCY_QUARTERLY, 'name' => 'Quarterly'],
['id' => self::FREQUENCY_ONE_OFF, 'name' => 'One-off'],
];
/**
* Frequencies for Ask Jiminny reports.
*/
public const array ASK_JIMINNY_FREQUENCIES = [
['id' => self::FREQUENCY_DAILY, 'name' => 'Daily'],
['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],
['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],
];
public const string MEDIA_TYPE_PDF = 'pdf';
public const string MEDIA_TYPE_PODCAST = 'podcast';
public const array MEDIA_TYPES = [self::MEDIA_TYPE_PDF, self::MEDIA_TYPE_PODCAST];
public const array MEDIA_TYPE_OBJECT_PDF = ['id' => self::MEDIA_TYPE_PDF, 'name' => 'PDF'];
public const array MEDIA_TYPE_OBJECT_PODCAST = ['id' => self::MEDIA_TYPE_PODCAST, 'name' => 'Podcast'];
public const array MEDIA_TYPE_OBJECTS = [self::MEDIA_TYPE_OBJECT_PDF, self::MEDIA_TYPE_OBJECT_PODCAST];
public const array CALL_TYPE_CONFERENCE = ['id' => 'conference', 'name' => 'Conference'];
public const array CALL_TYPE_DIALER = ['id' => 'dialer', 'name' => 'Dialer'];
public const int SENT_REPORT_AT_HOURS = 5;
public const string PDF_KEY = 'pdf';
public const string AUDIO_KEY = 'audio';
private const array ALL_FREQUENCIES = [
['id' => self::FREQUENCY_DAILY, 'name' => 'Daily'],
['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],
['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],
['id' => self::FREQUENCY_QUARTERLY, 'name' => 'Quarterly'],
['id' => self::FREQUENCY_ONE_OFF, 'name' => 'One-off'],
];
private const string S3_DIR = 'reports';
private const array FILE_EXTENSIONS_VARIANTS = ['html', 'MD', 'pdf'];
private const array FILE_PODCAST_EXTENSIONS_VARIANTS = ['json', 'mp3', 'ssml'];
public function __construct(
private readonly TeamRepository $teamRepository,
private readonly GroupRepository $groupRepository,
private readonly UserRepository $userRepository,
private readonly StageRepository $stageRepository,
private readonly DealStagesService $dealStagesService,
private readonly RecipientsService $recipientsService,
private readonly AutomatedReportsRepository $automatedReportsRepository,
private readonly Webhook $webhookService,
private readonly BusDispatcher $dispatcher,
private readonly ActivityTypeService $activityTypeService,
private readonly PlaybookCategoryRepository $playbookCategoryRepository,
private readonly AskAnythingPromptService $askAnythingPromptService,
private readonly SearchRepository $activitySearchRepository,
private readonly AskAnythingRepository $askAnythingRepository,
) {
}
public static function getTypes(): array
{
$types = self::TYPES;
return array_map(static function ($type) {
return $type['id'];
}, $types);
}
public static function getCallTypes(): array
{
return array_map(static function ($callType) {
return $callType['id'];
}, [self::CALL_TYPE_CONFERENCE, self::CALL_TYPE_DIALER]);
}
public static function getFrequencies(): array
{
return array_map(static function ($frequency) {
return $frequency['id'];
}, self::FREQUENCIES);
}
// front-facing structure
public function getReportEnabledFieldData(bool $value = false): array
{
return [
'id' => 'report_enabled',
'label' => '',
'inputType' => InputTypeEnum::TOGGLE,
'value' => $value,
];
}
// Organizations = Teams
public function getOrganizationFieldData(?string $value = null, bool $shortVersion = false): array
{
$options = $this->getTeams();
if ($shortVersion) {
return [
'id' => 'organization',
'label' => 'Organization',
'options' => $options,
];
}
return [
'id' => 'organization',
'label' => 'Organization',
'inputType' => InputTypeEnum::DROPDOWN,
'required' => true,
'placeholder' => 'Select',
'options' => $options,
'value' => $value,
'dependencies' => [
'teams',
'deal_stage_at_call',
'current_deal_stage',
'recipients',
ActivityTypeService::PLAYBOOK_CATEGORIES_KEY,
],
'dependsOn' => [],
];
}
// Teams = Groups
public function getTeamFieldData(array $options = [], array $value = [], bool $shortVersion = false): array
{
if ($shortVersion) {
return [
'id' => 'teams',
'label' => 'Team',
'options' => $options,
];
}
return [
'id' => 'teams',
'label' => 'Team',
'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,
'required' => false,
'placeholder' => 'Select',
'options' => $options,
'value' => $value, // value should be an array of objects {id, name}
'dependencies' => [ActivityTypeService::PLAYBOOK_CATEGORIES_KEY],
'dependsOn' => [],
];
}
public function getReportTypeFieldData(?string $value = null, bool $shortVersion = false, ?Team $team = null): array
{
$types = [];
if ($team instanceof Team) {
if ($team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {
$types = self::TYPES;
}
if ($team->hasFeature(FeatureEnum::ASK_JIMINNY_REPORTS)) {
$types[] = ['id' => self::TYPE_ASK_JIMINNY, 'name' => 'Ask Jiminny'];
}
} else {
$types = self::TYPES;
}
if ($shortVersion) {
return [
'id' => 'report_type',
'label' => 'Report Type',
'options' => $types,
];
}
return [
'id' => 'report_type',
'label' => 'Report Type',
'inputType' => InputTypeEnum::DROPDOWN,
'required' => true,
'placeholder' => 'Select',
'options' => $types,
'value' => $value,
'dependencies' => [],
'dependsOn' => [],
];
}
public function getFrequencyFieldData(?string $value = null): array
{
return [
'id' => 'frequency',
'label' => 'Frequency',
'inputType' => InputTypeEnum::DROPDOWN,
'required' => true,
'placeholder' => 'Select',
'options' => self::FREQUENCIES,
'value' => $value,
'dependencies' => ['period'],
'dependsOn' => [],
];
}
public function getPeriodFieldData(?string $valueStartDate = null, ?string $valueEndDate = null): array
{
return [
'id' => 'period',
'label' => 'Select one-off period',
'inputType' => InputTypeEnum::DATE_RANGE,
'required' => true,
'placeholder' => 'Select',
'value' => ['startDate' => $valueStartDate, 'endDate' => $valueEndDate],
'queryParams' => [
'startDate' => 'start_date_period',
'endDate' => 'end_date_period',
],
'dependencies' => [],
'dependsOn' => ['frequency'],
];
}
public function getActivityTypesFieldData(?Team $team = null, array $value = [], array $teamsFilter = []): array
{
return $this->activityTypeService->getActivityTypeFieldData(team: $team, value: $value, groupIds: $teamsFilter);
}
public function getDealStageAtCallFieldData(?Team $team = null, array $value = []): array
{
return $this->dealStagesService->getDealStageAtCallFieldData(team: $team, value: $value);
}
public function getCurrentDealStageFieldData(?Team $team = null, array $value = []): array
{
return $this->dealStagesService->getCurrentDealStageFieldData(team: $team, value: $value);
}
public function getDealValueFieldData(?int $valueMin = null, ?int $valueMax = null): array
{
return [
'id' => 'deal_value',
'label' => 'Deal Value',
'inputType' => InputTypeEnum::INTEGER_RANGE,
'required' => false,
'value' => ['min' => $valueMin, 'max' => $valueMax],
'queryParams' => [
'min' => 'min_deal_value',
'max' => 'max_deal_value',
],
'dependencies' => [],
'dependsOn' => [],
];
}
public function getCallTypeFieldData(bool $conferenceOn = false, bool $dialerOn = false): array
{
$value = [];
$conferenceOn && $value[] = self::CALL_TYPE_CONFERENCE;
$dialerOn && $value[] = self::CALL_TYPE_DIALER;
return [
'id' => 'call_type',
'label' => 'Call Type',
'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,
'required' => true,
'options' => [
self::CALL_TYPE_CONFERENCE,
self::CALL_TYPE_DIALER,
],
'value' => $value,
'dependencies' => [],
'dependsOn' => [],
];
}
public function getMediaTypeFieldData(?AutomatedReport $report = null): array
{
$value = [];
if ($report) {
$value = $this->transformMediaTypes($report);
}
return [
'id' => 'media_types',
'label' => 'Export as',
'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,
'required' => true,
'options' => self::MEDIA_TYPE_OBJECTS,
'value' => $value,
'dependencies' => [],
'dependsOn' => [],
];
}
public function getCallDurationFieldData(?int $valueMin = null, ?int $valueMax = null): array
{
return [
'id' => 'call_duration',
'label' => 'Call Duration',
'inputType' => InputTypeEnum::INTEGER_RANGE,
'required' => false,
'value' => ['min' => $valueMin, 'max' => $valueMax],
'queryParams' => [
'min' => 'min_call_duration',
'max' => 'max_call_duration',
],
'dependencies' => [],
'dependsOn' => [],
];
}
public function getRecipientsFieldData(?Team $team = null, array $value = []): array
{
return $this->recipientsService->getRecipientsFieldData(team: $team, value: $value);
}
public function getJiminnyRecipientsFieldData(array $value = []): array
{
return $this->recipientsService->getJiminnyRecipientsFieldData($value);
}
public function getAdditionalPromptInputFieldData(?string $value = null): array
{
return [
'id' => 'additional_prompt_input',
'label' => 'Special requirements',
'inputType' => InputTypeEnum::TEXTAREA,
'required' => false,
'placeholder' => 'What should be the focus of the report?',
'value' => $value,
'dependencies' => [],
'dependsOn' => [],
];
}
public function getCustomReportNameFieldData(?string $value = null): array
{
return [
'id' => 'custom_name',
'label' => 'Custom report name',
'inputType' => InputTypeEnum::TEXT,
'required' => false,
'placeholder' => 'Enter custom name',
'value' => $value,
'dependencies' => [],
'dependsOn' => [],
];
}
// data providers
public function getTeams(): array
{
$teams = $this->teamRepository->getTeamsForKiosk(status: Team::STATUS_ACTIVE);
$teamData = [];
foreach ($teams as $team) {
if (! $team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {
continue;
}
$teamData[] = $this->transformTeam($team);
}
return $teamData;
}
public function getTeamGroups(string $teamUuid): array
{
$data = [];
$team = $this->getTeam($teamUuid);
if ($team !== null) {
$groups = $team->groups()->get();
foreach ($groups as $group) {
$data[] = [
'id' => $group->getUuid(),
'name' => $group->getName(),
];
}
}
return $data;
}
public function getTeamsGroupsOptions(array $filterTeamUuids = []): array
{
$data = [];
$teams = $this->getTeams();
foreach ($teams as $team) {
if (! empty($filterTeamUuids) && ! in_array($team['id'], $filterTeamUuids, true)) {
continue;
}
$data[] = [
'label' => $team['name'],
'groups' => $this->getTeamGroups($team['id']),
];
}
return $data;
}
public function getTeam(string $teamUuid): ?Team
{
return $this->teamRepository->idOrUuid($teamUuid);
}
public function getTeamById(int $teamId): ?Team
{
return $this->teamRepository->find($teamId);
}
public function getGroupsUuids(AutomatedReport $report): array
{
$uuids = [];
$reportGroups = $report->getGroups();
foreach ($reportGroups as $groupId) {
if ($group = $this->groupRepository->find($groupId)) {
$uuids[] = $group->getUuid();
}
}
return $uuids;
}
public function getPlaybookCategoriesUuids(AutomatedReport $report): array
{
$uuids = [];
$playbookCategories = $report->getPlaybookCategories();
foreach ($playbookCategories as $id) {
if ($category = $this->playbookCategoryRepository->find($id)) {
$uuids[] = $category->getUuid();
}
}
return $uuids;
}
public function getDealAtCallStagesUuids(AutomatedReport $report): array
{
$uuids = [];
$reportStages = $report->getDealAtCallStages();
foreach ($reportStages as $id) {
if ($stage = $this->stageRepository->find($id)) {
$uuids[] = $stage->getUuid();
}
}
return $uuids;
}
public function getCurrentDealStagesUuids(AutomatedReport $report): array
{
$uuids = [];
$reportStages = $report->getCurrentDealStages();
foreach ($reportStages as $id) {
if ($stage = $this->stageRepository->find($id)) {
$uuids[] = $stage->getUuid();
}
}
return $uuids;
}
public function getUsersUuids(AutomatedReport $report): array
{
return $this->extractUserUuids($report->getRecipients());
}
public function getJiminnyUsersUuids(AutomatedReport $report): array
{
return $this->extractUserUuids($report->getJiminnyRecipients());
}
/**
* @param array<string, mixed> $recipients
*/
private function extractUserUuids(array $recipients): array
{
$userIds = $recipients['users'] ?? [];
return collect($userIds)
->map(fn ($id) => $this->userRepository->find((int) $id))
->filter()
->map(fn (UserContract $user) => $user->getUuid())
->values()
->all();
}
// get mail data
public function getRecipientUsers(AutomatedReport $report): array
{
return $this->buildRecipientUsers($report->getRecipients());
}
private function getJiminnyRecipientUsers(AutomatedReport $report): array
{
return $this->buildRecipientUsers($report->getJiminnyRecipients());
}
/**
* @param array<string, mixed> $recipients
*/
private function buildRecipientUsers(array $recipients): array
{
$userIds = $recipients['users'] ?? [];
return collect($userIds)
->map(fn ($id) => $this->userRepository->find((int) $id))
->filter()
->map(fn (UserContract $user) => [
'email' => $user->getEmailAddress(),
'name' => $user->getName(),
'timezone' => $user->getTimezone()->getName(),
])
->values()
->all();
}
public function getValidRecipientUsers(AutomatedReport $report, bool $includeJiminny = false): array
{
if ($report->isAskJiminnyReport()) {
$recipients = $this->resolveAskJiminnyRecipients($report);
} else {
$recipients = $this->getRecipientUsers($report);
if ($includeJiminny) {
$recipients = array_merge($recipients, $this->getJiminnyRecipientUsers($report));
}
}
$emails = [];
return array_values(array_filter(
$recipients,
static function ($recipient) use (&$emails) {
if (empty($recipient['email']) || in_array($recipient['email'], $emails, true)) {
return false;
}
$emails[] = $recipient['email'];
return true;
}
));
}
private function resolveAskJiminnyRecipients(AutomatedReport $report): array
{
$recipients = [];
$creator = $report->getCreator();
if ($creator !== null) {
$recipients[] = [
'email' => $creator->getEmailAddress(),
'name' => $creator->getName(),
'timezone' => $creator->getTimezone()->getName(),
];
}
return array_merge(
$recipients,
$this->buildRecipientUsers($report->getRecipients()),
$this->getGroupRecipientUsers($report),
);
}
private function getGroupRecipientUsers(AutomatedReport $report): array
{
$users = [];
foreach ($report->getGroups() as $groupId) {
$group = $this->groupRepository->find($groupId);
if ($group === null) {
continue;
}
foreach ($group->getMembers() as $member) {
$users[] = [
'email' => $member->getEmailAddress(),
'name' => $member->getName(),
'timezone' => $member->getTimezone()->getName(),
];
}
}
return $users;
}
public function getReportTypeName(AutomatedReportResult $report): string
{
$type = $report->getReport()->getType();
$getType = $this->transformReportType($type);
return $getType['name'];
}
public function getReportPeriodName(AutomatedReportResult $report): string
{
$from = $report->getFromDate();
$to = $report->getToDate();
$frequency = $report->getReport()->getFrequency();
if ($from === null || $to === null) {
if (! $report->getReport()->isAskJiminnyReport()) {
$invalidPeriod = $from === null ? 'from' : 'to';
throw new ApplicationException('Report period is invalid: ' . $invalidPeriod);
}
$period = $this->calculateFromAndToDatePeriod($frequency);
$from = $period['fromDate'];
$to = $period['toDate'];
}
return $this->formatReportPeriodName($frequency, $from, $to);
}
private function formatReportPeriodName(string $frequency, Carbon $from, Carbon $to): string
{
$fromYear = $from->format('Y');
$toYear = $to->format('Y');
$differentYears = $fromYear !== $toYear;
switch ($frequency) {
case self::FREQUENCY_DAILY:
return $from->format('j M Y');
case self::FREQUENCY_QUARTERLY:
// 'Jan-Mar 2025' or 'Nov 2024-Jan 2025' if years differ
$startMonth = $from->format('M');
$endMonth = $to->copy()->subMonth();
$endMonthName = $endMonth->format('M');
$endMonthYear = $endMonth->format('Y');
if ($differentYears) {
return "{$startMonth} {$fromYear} - {$endMonthName} {$endMonthYear}";
}
return "{$startMonth} - {$endMonthName} {$toYear}";
case self::FREQUENCY_MONTHLY:
// 'May 2025' - monthly reports are always within the same year
return $from->format('M Y');
case self::FREQUENCY_WEEKLY:
// '4 - 8 Aug 2025', '27 Oct - 3 Nov 2025', or '28 Dec 2024 - 3 Jan 2025' if years differ
$startDay = $from->format('j');
$endDay = $to->format('j');
$startMonth = $from->format('M');
$endMonth = $to->format('M');
if ($differentYears) {
return "{$startDay} {$startMonth} {$fromYear} - {$endDay} {$endMonth} {$toYear}";
}
if ($startMonth !== $endMonth) {
return "{$startDay} {$startMonth} - {$endDay} {$endMonth} {$toYear}";
}
return "{$startDay} - {$endDay} {$endMonth} {$toYear}";
case self::FREQUENCY_ONE_OFF:
// '2 May-31 May 2025' or '15 Dec 2024-15 Jan 2025' if years differ
$startDay = $from->format('j');
$startMonth = $from->format('M');
$endDay = $to->format('j');
$endMonth = $to->format('M');
// If same month and year, use a format like '2-31 May 2025'
if ($startMonth === $endMonth && ! $differentYears) {
return "{$startDay} - {$endDay} {$startMonth} {$toYear}";
}
// If different years, include both years
if ($differentYears) {
return "{$startDay} {$startMonth} {$fromYear} - {$endDay} {$endMonth} {$toYear}";
}
// Same year but different months
return "{$startDay} {$startMonth} - {$endDay} {$endMonth} {$toYear}";
default:
// Default format for unknown frequencies
return $from->format('j M Y') . ' - ' . $to->format('j M Y');
}
}
public function getReportTeamsName(AutomatedReportResult $report): string
{
$groups = $report->getGroups();
if (empty($groups)) {
return 'All';
}
// Get group names from repository
$groupNames = [];
foreach ($groups as $groupId) {
$group = $this->groupRepository->find($groupId);
if ($group) {
$groupNames[] = $group->getName();
}
}
if (count($groupNames) === 1) {
// Single team format
$teamsName = $groupNames[0];
} else {
// Multiple teams format
$teamsName = implode(', ', $groupNames);
}
return $teamsName;
}
public function getReportFileName(AutomatedReportResult $report): string
...
|
NULL
|
|
12310
|
260
|
32
|
2026-04-14T11:01:59.100538+00:00
|
/Users/lukas/.screenpipe/data/data/2026-04-14/1776 /Users/lukas/.screenpipe/data/data/2026-04-14/1776164519100_m1.jpg...
|
PhpStorm
|
faVsco.js – AutomatedReportsService.php
|
1
|
NULL
|
monitor_1
|
NULL
|
NULL
|
NULL
|
NULL
|
Project: faVsco.js, menu
#11894 on JY-18909-automa Project: faVsco.js, menu
#11894 on JY-18909-automated-reports-ask-jiminny, menu
Start Listening for PHP Debug Connections
AutomatedReportsCommandTest
Run 'AutomatedReportsCommandTest'
Debug 'AutomatedReportsCommandTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Execute
Explain Plan
Browse Query History
View Parameters
Open Query Execution Settings…
In-Editor Results
Tx: Auto
Cancel Running Statements
Playground
jiminny
Sync Changes
Hide This Notification
Code changed:
Hide
16
13
13
Previous Highlighted Error
Next Highlighted Error
SELECT * FROM teams WHERE id = 1;
select * from crm_layouts where crm_configuration_id = 39;
SELECT * FROM crm_layout_entities WHERE crm_layout_id = 283;
SELECT * FROM crm_fields WHERE id = 2234;
SELECT * FROM crm_field_values WHERE crm_field_id = 2234;
select * from crm_profiles where user_id = 143;
select * from record_types where crm_configuration_id = 39; # 0121K000001MHElQAO,0121K000001MHEqQAO
select * from business_processes where crm_configuration_id = 39;
# 01941000000H669AAC, 01941000000H66JAAS
select * from record_type_field_values
where record_type_id IN (24);
select * from crm_field_values where id IN (2730);
select * from crm_configurations where id = 39;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 1
and sa.provider = 'salesforce'; #1035
select * from users where team_id = 1; # 222 group 3
SELECT * FROM activities WHERE user_id = 222 order by id desc;
select * from sidekick_settings where team_id = 1;
select * from teams where id = 1;
select * from team_features where team_id = 1;
select * from activities where crm_configuration_id = 2
and provider = 'ms-teams' and id = 608765;
SELECT * FROM activities WHERE crm_configuration_id = 2 and crm_provider_id = '59523413338';
select * from sidekick_settings where team_id = 2;
SELECT * FROM activities WHERE id = 608660;
select * from activity_summary_logs where activity_id = 608660;
select * from ai_prompts where transcription_id = 11214;
# [PASSWORD_DOTS]
SELECT * FROM activities WHERE uuid_to_bin('ed78a437-2804-450e-ab2f-56ab1c641346') = uuid;
# id: 608818, crm: 59628809737
SELECT * FROM activities WHERE uuid_to_bin('36b06e55-afdd-4782-8dee-c624cd0af191') = uuid;
# id: 608821, crm: 59632069252
SELECT ce.start_time, ce.end_time, a.id, a.uuid, crm_provider_id, calendar_event_id, title,
playbook_category_id, user_id, lead_id, contact_id, account_id, opportunity_id,
scheduled_start_time, scheduled_end_time, actual_start_time, actual_end_time, a.created_at
FROM activities a
join calendar_events ce on a.calendar_event_id = ce.id
WHERE a.id IN (608818, 608821);
select * from users where team_id = 1;
select * from team_settings where team_id = 1;
select * from crm_profiles where crm_configuration_id = 39 order by user_id;
select * from team_features where team_id = 1;
select * from users where team_id = 2;
SELECT * FROM activities WHERE uuid_to_bin('ec7647e9-5225-458b-b475-f31aa2769204') = uuid; # 612639
# Preslava N. Ivanova, grou id 3
SELECT * FROM opportunities WHERE uuid_to_bin('a2928fe5-aec5-46cb-85d9-7654c89e46a6') = uuid;
select * from activities where opportunity_id = 344 and actual_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00';
select
a.id,
a.type,
a.scheduled_start_time,
a.actual_start_time,
a.created_at,
a.opportunity_id,
a.status
FROM activities a
WHERE opportunity_id = 344
and status IN ('completed', 'received', 'delivered')
and (
(a.actual_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00')
OR (a.created_at between '2024-10-11 00:00:00' and '2024-10-12 00:00:00')
OR (a.scheduled_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00'))
;
SELECT * FROM users WHERE id = 222;
SELECT * FROM crm_profiles WHERE user_id = 222;
select * from crm_layouts where crm_configuration_id = 39;
SELECT * FROM crm_layout_entities WHERE crm_layout_id = 281;
select * from group_deal_risk_types;
select * from opportunities where team_id = 1;
SELECT * FROM opportunities WHERE id = 315;
SELECT * FROM crm_field_data WHERE object_id = 315;
select * from crm_field_data where object_id = 260;
select * from generic_ai_prompts where subject_id = 315;
select * from teams; # 36, 21, 121, [EMAIL]
SELECT * FROM social_accounts WHERE sociable_id = 121 and provider = 'bullhorn';
# [PASSWORD_DOTS]
select * from teams where id = 1;
select * from crm_configurations where id = 39;
select * from users where team_id = 1;
select u.email, cp.* from users u
join crm_profiles cp on u.id = cp.user_id
where u.team_id = 1;
# 1 - 00541000004281rAAA
# 204 - 0052g000003freeAAA
# 429 - 0052g000003qGOiAAM
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 1
and sa.provider = 'salesforce';
select * from activities where type = 'softphone'
and created_at > '2024-12-11 15:24:36' order by id desc;
select * from activity_providers where team_id = 1;
select * from activity_provider_users where activity_provider_id = 328;
select * from opportunities where crm_configuration_id = 39
AND account_id = 178 AND is_closed = false
order by created_at DESC;
select * from contacts where id = 3952;
select * from accounts where id = 178;
# [PASSWORD_DOTS]
select * from teams where id = 36;
select * from crm_configurations where id = 21;
select * from users where team_id = 36;
select u.email, cp.* from users u
join crm_profiles cp on u.id = cp.user_id
where u.team_id = 36;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 36
and sa.provider = 'bullhorn';
select * from social_accounts where id = 348;
UPDATE social_accounts SET
provider_user_token = '21442_6802599_91:41179a58-21e7-4d7c-ad58-56bb666b2f65',
provider_refresh_token = '21442_6802599_91:01c6b335-3f2a-42e4-85ff-8a08fa65fceb',
expires = 1733998131,
state = 'connected'
WHERE id = 348;
# [PASSWORD_DOTS]
select * from teams where id = 31;
select * from crm_configurations where id = 18;
select * from users where team_id = 31; # 257
select u.email, cp.* from users u
join crm_profiles cp on u.id = cp.user_id
where u.team_id = 31;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 31
and sa.provider = 'close';
select * from contacts where crm_configuration_id = 18;
# [PASSWORD_DOTS] NEPTUNE [PASSWORD_DOTS]
select * from teams;
select * from users where id IN (1030, 1035, 1052);
select * from crm_configurations;
select * from users where team_id = 65; # 257
select * from team_settings where team_id = 65; # 257
select * from invitations where team_id = 65; # 257
select * from users where email = '[EMAIL]'; # 257
select u.email, cp.* from users u
join crm_profiles cp on u.id = cp.user_id
where u.team_id = 65;
select * from crm_configurations where id = 53;
select * from accounts where crm_configuration_id = 53 order by id desc;
select * from leads where crm_configuration_id = 53 order by id desc;
select * from contacts where crm_configuration_id = 53 order by id desc;
select * from opportunities where crm_configuration_id = 53 order by id desc;
select * from crm_profiles where crm_configuration_id = 53 order by id desc;
select * from crm_fields where crm_configuration_id = 53 order by id desc;
select * from crm_field_values where crm_field_id = 3341 order by id desc;
select * from crm_layouts where crm_configuration_id = 53 order by id desc;
select * from stages where crm_configuration_id = 53 order by id desc;
select * from crm_profiles where crm_configuration_id = 13;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 65
and sa.provider = 'integration-app';
select * from contacts where crm_configuration_id = 13;
select * from social_accounts where sociable_id = 283;
SELECT * FROM opportunities WHERE crm_provider_id = '006O400000E9bzeIAB';
select * from activity_providers where team_id = 65;
SELECT * FROM activities WHERE crm_configuration_id IN (51, 52, 53);
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 65
;
# [PASSWORD_DOTS] STAGING [PASSWORD_DOTS]
SELECT * FROM teams;
SELECT * FROM teams WHERE id = 88;
SELECT * FROM teams WHERE id = 89;
select * from team_settings where team_id = 89;
SELECT * FROM users WHERE team_id = 89;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 89;
select * from users;
SELECT * FROM social_accounts WHERE sociable_id = 1761;
SELECT * FROM crm_configurations WHERE id = 70;
select * from accounts where crm_configuration_id = 70 order by id desc;
select * from leads where crm_configuration_id = 70 order by id desc;
select * from contacts where crm_configuration_id = 70 order by id desc;
select * from opportunities where crm_configuration_id = 70 order by id desc;
select * from crm_profiles where crm_configuration_id = 70 order by id desc;
select * from crm_fields where crm_configuration_id = 70 order by id desc;
select * from crm_field_values where crm_field_id = 3536 order by id desc;
select * from crm_layouts where crm_configuration_id = 70 order by id desc;
select * from stages where crm_configuration_id = 70 order by id desc;
select * from business_processes where crm_configuration_id = 70 order by id desc;
select * from business_process_stages where business_process_id = 34;
select * from contacts where id = 10468;
select * from crm_layouts where crm_configuration_id = 70;
SELECT * FROM crm_layout_entities WHERE crm_layout_id = 388;
SELECT * FROM crm_fields WHERE id IN (3533,3534,3535);
select * from activities where crm_configuration_id = 70
and (account_id IS NOT NULL or lead_id IS NOT NULL or contact_id IS NOT NULL or opportunity_id IS NOT NULL) order by id desc;
SELECT * FROM activities WHERE uuid_to_bin('2e10b60f-8a61-41c5-a3d4-28835353dc65') = uuid;
SELECT * FROM activities where crm_configuration_id = 69 ;
SELECT * FROM users WHERE email LIKE '%[EMAIL]%';
SELECT * FROM activities WHERE uuid_to_bin('5a150c93-40fc-42ec-b3bd-c1d328e09f6e') = uuid;
SELECT * FROM opportunities WHERE id = 385;
select * from participants p
join activities a on p.activity_id = a.id
where a.crm_configuration_id = 70
and (p.lead_id IS NOT NULL or p.contact_id IS NOT NULL);
SELECT * FROM participants WHERE id = 1013638;
select * from teams where id = 90;
select * from users where team_id = 90;
select * from social_accounts where social_accounts.sociable_id IN (1960,1760);
SELECT * FROM crm_profiles WHERE crm_configuration_id = 71;
select * from invitations where team_id = 90;
select * from crm_configurations where id = 71;
select * from accounts where crm_configuration_id = 71 order by id desc;
select * from leads where crm_configuration_id = 71 order by id desc;
select * from contacts where crm_configuration_id = 71 order by id desc;
select * from opportunities where crm_configuration_id = 71 order by id desc;
select * from crm_profiles where crm_configuration_id = 71 order by id desc;
select * from crm_fields where crm_configuration_id = 71 order by id desc;
select * from crm_field_values where crm_field_id = 3341 order by id desc;
select * from crm_layouts where crm_configuration_id = 71 order by id desc;
select * from stages where crm_configuration_id = 71 order by id desc;
select * from users order by secondary_email desc;
select u.id, u.email, u.status, sa.id, sa.provider_user_id from social_accounts sa
join users u on sa.sociable_id = u.id
where sa.provider = 'google' and u.email LIKE 'aneliya%';
select * from failed_jobs order by id desc;
select * from users where email = '[EMAIL]' or secondary_email = '[EMAIL]';
select * from teams;
SELECT * FROM crm_profiles WHERE crm_configuration_id = 39;
SELECT * FROM crm_fields WHERE crm_configuration_id = 39 and object_type = 'task';
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 1
and sa.provider = 'salesforce';
# [PASSWORD_DOTS]
SELECT * FROM activities WHERE uuid_to_bin('c38b3895-fd0f-4b1f-9fb2-c170dba137c6') = uuid;
SELECT * FROM crm_configurations WHERE id = 70;
select * from teams where id = 1;
select * from groups where team_id = 1;
select * from users where team_id = 1;
select o.id, o.name,o.close_date, u.id, u.name, u.group_id, r.id, r.display_name, g.name, g.scope from opportunities o
join users u on o.user_id = u.id
join groups g on u.group_id = g.id
join role_user ru on u.id = ru.user_id
join roles r on ru.role_id = r.id
where o.crm_configuration_id = 39 and close_date > '2024-01-01 00:00:00';
select * from role_user where user_id = 143;
select * from roles;
select * from role_user;
select * from groups where id = 9;
select * from scope_groups where group_id = 9;
# [PASSWORD_DOTS]
select * from teams where id = 36;
select * from crm_configurations;
SELECT * FROM social_accounts WHERE sociable_id = 121;
[URL_WITH_CREDENTIALS] this will add filter, however if we need to control feature by FF we need conditional logic
public const array TYPES = [
['id' => 'exec_summary', 'name' => 'Exec Summary'],
['id' => 'coaching_profiles', 'name' => 'Coaching Profiles'],
['id' => 'product_feedback', 'name' => 'Product Feedback'],
['id' => self::TYPE_LOSS_ANALYSIS, 'name' => 'Loss Analysis'],
// ['id' => 'questions', 'name' => 'Questions'],
// ['id' => 'statistical_quant', 'name' => 'Statistical Quantitative'],
];
public const array ALL_TYPES = [
...self::TYPES,
['id' => self::TYPE_ASK_JIMINNY, 'name' => 'Ask Jiminny'],
];
public const string FREQUENCY_DAILY = 'daily';
public const string FREQUENCY_WEEKLY = 'weekly';
public const string FREQUENCY_MONTHLY = 'monthly';
public const string FREQUENCY_QUARTERLY = 'quarterly';
public const string FREQUENCY_ONE_OFF = 'one_off';
/**
* Frequencies for standard (non-Ask Jiminny) reports.
*/
public const array FREQUENCIES = [
['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],
['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],
['id' => self::FREQUENCY_QUARTERLY, 'name' => 'Quarterly'],
['id' => self::FREQUENCY_ONE_OFF, 'name' => 'One-off'],
];
/**
* Frequencies for Ask Jiminny reports.
*/
public const array ASK_JIMINNY_FREQUENCIES = [
['id' => self::FREQUENCY_DAILY, 'name' => 'Daily'],
['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],
['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],
];
public const string MEDIA_TYPE_PDF = 'pdf';
public const string MEDIA_TYPE_PODCAST = 'podcast';
public const array MEDIA_TYPES = [self::MEDIA_TYPE_PDF, self::MEDIA_TYPE_PODCAST];
public const array MEDIA_TYPE_OBJECT_PDF = ['id' => self::MEDIA_TYPE_PDF, 'name' => 'PDF'];
public const array MEDIA_TYPE_OBJECT_PODCAST = ['id' => self::MEDIA_TYPE_PODCAST, 'name' => 'Podcast'];
public const array MEDIA_TYPE_OBJECTS = [self::MEDIA_TYPE_OBJECT_PDF, self::MEDIA_TYPE_OBJECT_PODCAST];
public const array CALL_TYPE_CONFERENCE = ['id' => 'conference', 'name' => 'Conference'];
public const array CALL_TYPE_DIALER = ['id' => 'dialer', 'name' => 'Dialer'];
public const int SENT_REPORT_AT_HOURS = 5;
public const string PDF_KEY = 'pdf';
public const string AUDIO_KEY = 'audio';
private const array ALL_FREQUENCIES = [
['id' => self::FREQUENCY_DAILY, 'name' => 'Daily'],
['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],
['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],
['id' => self::FREQUENCY_QUARTERLY, 'name' => 'Quarterly'],
['id' => self::FREQUENCY_ONE_OFF, 'name' => 'One-off'],
];
private const string S3_DIR = 'reports';
private const array FILE_EXTENSIONS_VARIANTS = ['html', 'MD', 'pdf'];
private const array FILE_PODCAST_EXTENSIONS_VARIANTS = ['json', 'mp3', 'ssml'];
public function __construct(
private readonly TeamRepository $teamRepository,
private readonly GroupRepository $groupRepository,
private readonly UserRepository $userRepository,
private readonly StageRepository $stageRepository,
private readonly DealStagesService $dealStagesService,
private readonly RecipientsService $recipientsService,
private readonly AutomatedReportsRepository $automatedReportsRepository,
private readonly Webhook $webhookService,
private readonly BusDispatcher $dispatcher,
private readonly ActivityTypeService $activityTypeService,
private readonly PlaybookCategoryRepository $playbookCategoryRepository,
private readonly AskAnythingPromptService $askAnythingPromptService,
private readonly SearchRepository $activitySearchRepository,
private readonly AskAnythingRepository $askAnythingRepository,
) {
}
public static function getTypes(): array
{
$types = self::TYPES;
return array_map(static function ($type) {
return $type['id'];
}, $types);
}
public static function getCallTypes(): array
{
return array_map(static function ($callType) {
return $callType['id'];
}, [self::CALL_TYPE_CONFERENCE, self::CALL_TYPE_DIALER]);
}
public static function getFrequencies(): array
{
return array_map(static function ($frequency) {
return $frequency['id'];
}, self::FREQUENCIES);
}
// front-facing structure
public function getReportEnabledFieldData(bool $value = false): array
{
return [
'id' => 'report_enabled',
'label' => '',
'inputType' => InputTypeEnum::TOGGLE,
'value' => $value,
];
}
// Organizations = Teams
public function getOrganizationFieldData(?string $value = null, bool $shortVersion = false): array
{
$options = $this->getTeams();
if ($shortVersion) {
return [
'id' => 'organization',
'label' => 'Organization',
'options' => $options,
];
}
return [
'id' => 'organization',
'label' => 'Organization',
'inputType' => InputTypeEnum::DROPDOWN,
'required' => true,
'placeholder' => 'Select',
'options' => $options,
'value' => $value,
'dependencies' => [
'teams',
'deal_stage_at_call',
'current_deal_stage',
'recipients',
ActivityTypeService::PLAYBOOK_CATEGORIES_KEY,
],
'dependsOn' => [],
];
}
// Teams = Groups
public function getTeamFieldData(array $options = [], array $value = [], bool $shortVersion = false): array
{
if ($shortVersion) {
return [
'id' => 'teams',
'label' => 'Team',
'options' => $options,
];
}
return [
'id' => 'teams',
'label' => 'Team',
'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,
'required' => false,
'placeholder' => 'Select',
'options' => $options,
'value' => $value, // value should be an array of objects {id, name}
'dependencies' => [ActivityTypeService::PLAYBOOK_CATEGORIES_KEY],
'dependsOn' => [],
];
}
public function getReportTypeFieldData(?string $value = null, bool $shortVersion = false, ?Team $team = null): array
{
$types = [];
if ($team instanceof Team) {
if ($team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {
$types = self::TYPES;
}
if ($team->hasFeature(FeatureEnum::ASK_JIMINNY_REPORTS)) {
$types[] = ['id' => self::TYPE_ASK_JIMINNY, 'name' => 'Ask Jiminny'];
}
} else {
$types = self::TYPES;
}
if ($shortVersion) {
return [
'id' => 'report_type',
'label' => 'Report Type',
'options' => $types,
];
}
return [
'id' => 'report_type',
'label' => 'Report Type',
'inputType' => InputTypeEnum::DROPDOWN,
'required' => true,
'placeholder' => 'Select',
'options' => $types,
'value' => $value,
'dependencies' => [],
'dependsOn' => [],
];
}
public function getFrequencyFieldData(?string $value = null): array
{
return [
'id' => 'frequency',
'label' => 'Frequency',
'inputType' => InputTypeEnum::DROPDOWN,
'required' => true,
'placeholder' => 'Select',
'options' => self::FREQUENCIES,
'value' => $value,
'dependencies' => ['period'],
'dependsOn' => [],
];
}
public function getPeriodFieldData(?string $valueStartDate = null, ?string $valueEndDate = null): array
{
return [
'id' => 'period',
'label' => 'Select one-off period',
'inputType' => InputTypeEnum::DATE_RANGE,
'required' => true,
'placeholder' => 'Select',
'value' => ['startDate' => $valueStartDate, 'endDate' => $valueEndDate],
'queryParams' => [
'startDate' => 'start_date_period',
'endDate' => 'end_date_period',
],
'dependencies' => [],
'dependsOn' => ['frequency'],
];
}
public function getActivityTypesFieldData(?Team $team = null, array $value = [], array $teamsFilter = []): array
{
return $this->activityTypeService->getActivityTypeFieldData(team: $team, value: $value, groupIds: $teamsFilter);
}
public function getDealStageAtCallFieldData(?Team $team = null, array $value = []): array
{
return $this->dealStagesService->getDealStageAtCallFieldData(team: $team, value: $value);
}
public function getCurrentDealStageFieldData(?Team $team = null, array $value = []): array
{
return $this->dealStagesService->getCurrentDealStageFieldData(team: $team, value: $value);
}
public function getDealValueFieldData(?int $valueMin = null, ?int $valueMax = null): array
{
return [
'id' => 'deal_value',
'label' => 'Deal Value',
'inputType' => InputTypeEnum::INTEGER_RANGE,
'required' => false,
'value' => ['min' => $valueMin, 'max' => $valueMax],
'queryParams' => [
'min' => 'min_deal_value',
'max' => 'max_deal_value',
],
'dependencies' => [],
'dependsOn' => [],
];
}
public function getCallTypeFieldData(bool $conferenceOn = false, bool $dialerOn = false): array
{
$value = [];
$conferenceOn && $value[] = self::CALL_TYPE_CONFERENCE;
$dialerOn && $value[] = self::CALL_TYPE_DIALER;
return [
'id' => 'call_type',
'label' => 'Call Type',
'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,
'required' => true,
'options' => [
self::CALL_TYPE_CONFERENCE,
self::CALL_TYPE_DIALER,
],
'value' => $value,
'dependencies' => [],
'dependsOn' => [],
];
}
public function getMediaTypeFieldData(?AutomatedReport $report = null): array
{
$value = [];
if ($report) {
$value = $this->transformMediaTypes($report);
}
return [
'id' => 'media_types',
'label' => 'Export as',
'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,
'required' => true,
'options' => self::MEDIA_TYPE_OBJECTS,
'value' => $value,
'dependencies' => [],
'dependsOn' => [],
];
}
public function getCallDurationFieldData(?int $valueMin = null, ?int $valueMax = null): array
{
return [
'id' => 'call_duration',
'label' => 'Call Duration',
'inputType' => InputTypeEnum::INTEGER_RANGE,
'required' => false,
'value' => ['min' => $valueMin, 'max' => $valueMax],
'queryParams' => [
'min' => 'min_call_duration',
'max' => 'max_call_duration',
],
'dependencies' => [],
'dependsOn' => [],
];
}
public function getRecipientsFieldData(?Team $team = null, array $value = []): array
{
return $this->recipientsService->getRecipientsFieldData(team: $team, value: $value);
}
public function getJiminnyRecipientsFieldData(array $value = []): array
{
return $this->recipientsService->getJiminnyRecipientsFieldData($value);
}
public function getAdditionalPromptInputFieldData(?string $value = null): array
{
return [
'id' => 'additional_prompt_input',
'label' => 'Special requirements',
'inputType' => InputTypeEnum::TEXTAREA,
'required' => false,
'placeholder' => 'What should be the focus of the report?',
'value' => $value,
'dependencies' => [],
'dependsOn' => [],
];
}
public function getCustomReportNameFieldData(?string $value = null): array
{
return [
'id' => 'custom_name',
'label' => 'Custom report name',
'inputType' => InputTypeEnum::TEXT,
'required' => false,
'placeholder' => 'Enter custom name',
'value' => $value,
'dependencies' => [],
'dependsOn' => [],
];
}
// data providers
public function getTeams(): array
{
$teams = $this->teamRepository->getTeamsForKiosk(status: Team::STATUS_ACTIVE);
$teamData = [];
foreach ($teams as $team) {
if (! $team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {
continue;
}
$teamData[] = $this->transformTeam($team);
}
return $teamData;
}
public function getTeamGroups(string $teamUuid): array
{
$data = [];
$team = $this->getTeam($teamUuid);
if ($team !== null) {
$groups = $team->groups()->get();
foreach ($groups as $group) {
$data[] = [
'id' => $group->getUuid(),
'name' => $group->getName(),
];
}
}
return $data;
}
public function getTeamsGroupsOptions(array $filterTeamUuids = []): array
{
$data = [];
$teams = $this->getTeams();
foreach ($teams as $team) {
if (! empty($filterTeamUuids) && ! in_array($team['id'], $filterTeamUuids, true)) {
continue;
}
$data[] = [
'label' => $team['name'],
'groups' => $this->getTeamGroups($team['id']),
];
}
return $data;
}
public function getTeam(string $teamUuid): ?Team
{
return $this->teamRepository->idOrUuid($teamUuid);
}
public function getTeamById(int $teamId): ?Team
{
return $this->teamRepository->find($teamId);
}
public function getGroupsUuids(AutomatedReport $report): array
{
$uuids = [];
$reportGroups = $report->getGroups();
foreach ($reportGroups as $groupId) {
if ($group = $this->groupRepository->find($groupId)) {
$uuids[] = $group->getUuid();
}
}
return $uuids;
}
public function getPlaybookCategoriesUuids(AutomatedReport $report): array
{
$uuids = [];
$playbookCategories = $report->getPlaybookCategories();
foreach ($playbookCategories as $id) {
if ($category = $this->playbookCategoryRepository->find($id)) {
$uuids[] = $category->getUuid();
}
}
return $uuids;
}
public function getDealAtCallStagesUuids(AutomatedReport $report): array
{
$uuids = [];
$reportStages = $report->getDealAtCallStages();
foreach ($reportStages as $id) {
if ($stage = $this->stageRepository->find($id)) {
$uuids[] = $stage->getUuid();
}
}
return $uuids;
}
public function getCurrentDealStagesUuids(AutomatedReport $report): array
{
$uuids = [];
$reportStages = $report->getCurrentDealStages();
foreach ($reportStages as $id) {
if ($stage = $this->stageRepository->find($id)) {
$uuids[] = $stage->getUuid();
}
}
return $uuids;
}
public function getUsersUuids(AutomatedReport $report): array
{
return $this->extractUserUuids($report->getRecipients());
}
public function getJiminnyUsersUuids(AutomatedReport $report): array
{
return $this->extractUserUuids($report->getJiminnyRecipients());
}
/**
* @param array<string, mixed> $recipients
*/
private function extractUserUuids(array $recipients): array
{
$userIds = $recipients['users'] ?? [];
return collect($userIds)
->map(fn ($id) => $this->userRepository->find((int) $id))
->filter()
->map(fn (UserContract $user) => $user->getUuid())
->values()
->all();
}
// get mail data
public function getRecipientUsers(AutomatedReport $report): array
{
return $this->buildRecipientUsers($report->getRecipients());
}
private function getJiminnyRecipientUsers(AutomatedReport $report): array
{
return $this->buildRecipientUsers($report->getJiminnyRecipients());
}
/**
* @param array<string, mixed> $recipients
*/
private function buildRecipientUsers(array $recipients): array
{
$userIds = $recipients['users'] ?? [];
return collect($userIds)
->map(fn ($id) => $this->userRepository->find((int) $id))
->filter()
->map(fn (UserContract $user) => [
'email' => $user->getEmailAddress(),
'name' => $user->getName(),
'timezone' => $user->getTimezone()->getName(),
])
->values()
->all();
}
public function getValidRecipientUsers(AutomatedReport $report, bool $includeJiminny = false): array
{
if ($report->isAskJiminnyReport()) {
$recipients = $this->resolveAskJiminnyRecipients($report);
} else {
$recipients = $this->getRecipientUsers($report);
if ($includeJiminny) {
$recipients = array_merge($recipients, $this->getJiminnyRecipientUsers($report));
}
}
$emails = [];
return array_values(array_filter(
$recipients,
static function ($recipient) use (&$emails) {
if (empty($recipient['email']) || in_array($recipient['email'], $emails, true)) {
return false;
}
$emails[] = $recipient['email'];
return true;
}
));
}
private function resolveAskJiminnyRecipients(AutomatedReport $report): array
{
$recipients = [];
$creator = $report->getCreator();
if ($creator !== null) {
$recipients[] = [
'email' => $creator->getEmailAddress(),
'name' => $creator->getName(),
'timezone' => $creator->getTimezone()->getName(),
];
}
return array_merge(
$recipients,
$this->buildRecipientUsers($report->getRecipients()),
$this->getGroupRecipientUsers($report),
);
}
private function getGroupRecipientUsers(AutomatedReport $report): array
{
$users = [];
foreach ($report->getGroups() as $groupId) {
$group = $this->groupRepository->find($groupId);
if ($group === null) {
continue;
}
foreach ($group->getMembers() as $member) {
$users[] = [
'email' => $member->getEmailAddress(),
'name' => $member->getName(),
'timezone' => $member->getTimezone()->getName(),
];
}
}
return $users;
}
public function getReportTypeName(AutomatedReportResult $report): string
{
$type = $report->getReport()->getType();
$getType = $this->transformReportType($type);
return $getType['name'];
}
public function getReportPeriodName(AutomatedReportResult $report): string
{
$from = $report->getFromDate();
$to = $report->getToDate();
$frequency = $report->getReport()->getFrequency();
if ($from === null || $to === null) {
if (! $report->getReport()->isAskJiminnyReport()) {
$invalidPeriod = $from === null ? 'from' : 'to';
throw new ApplicationException('Report period is invalid: ' . $invalidPeriod);
}
$period = $this->calculateFromAndToDatePeriod($frequency);
$from = $period['fromDate'];
$to = $period['toDate'];
}
return $this->formatReportPeriodName($frequency, $from, $to);
}
private function formatReportPeriodName(string $frequency, Carbon $from, Carbon $to): string
{
$fromYear = $from->format('Y');
$toYear = $to->format('Y');
$differentYears = $fromYear !== $toYear;
switch ($frequency) {
case self::FREQUENCY_DAILY:
return $from->format('j M Y');
case self::FREQUENCY_QUARTERLY:
// 'Jan-Mar 2025' or 'Nov 2024-Jan 2025' if years differ
$startMonth = $from->format('M');
$endMonth = $to->copy()->subMonth();
$endMonthName = $endMonth->format('M');
$endMonthYear = $endMonth->format('Y');
if ($differentYears) {
return "{$startMonth} {$fromYear} - {$endMonthName} {$endMonthYear}";
}
return "{$startMonth} - {$endMonthName} {$toYear}";
case self::FREQUENCY_MONTHLY:
// 'May 2025' - monthly reports are always within the same year
return $from->format('M Y');
case self::FREQUENCY_WEEKLY:
// '4 - 8 Aug 2025', '27 Oct - 3 Nov 2025', or '28 Dec 2024 - 3 Jan 2025' if years differ
$startDay = $from->format('j');
$endDay = $to->format('j');
$startMonth = $from->format('M');
$endMonth = $to->format('M');
if ($differentYears) {
return "{$startDay} {$startMonth} {$fromYear} - {$endDay} {$endMonth} {$toYear}";
}
if ($startMonth !== $endMonth) {
return "{$startDay} {$startMonth} - {$endDay} {$endMonth} {$toYear}";
}
return "{$startDay} - {$endDay} {$endMonth} {$toYear}";
case self::FREQUENCY_ONE_OFF:
// '2 May-31 May 2025' or '15 Dec 2024-15 Jan 2025' if years differ
$startDay = $from->format('j');
$startMonth = $from->format('M');
$endDay = $to->format('j');
$endMonth = $to->format('M');
// If same month and year, use a format like '2-31 May 2025'
if ($startMonth === $endMonth && ! $differentYears) {
return "{$startDay} - {$endDay} {$startMonth} {$toYear}";
}
// If different years, include both years
if ($differentYears) {
return "{$startDay} {$startMonth} {$fromYear} - {$endDay} {$endMonth} {$toYear}";
}
// Same year but different months
return "{$startDay} {$startMonth} - {$endDay} {$endMonth} {$toYear}";
default:
// Default format for unknown frequencies
return $from->format('j M Y') . ' - ' . $to->format('j M Y');
}
}
public function getReportTeamsName(AutomatedReportResult $report): string
{
$groups = $report->getGroups();
if (empty($groups)) {
return 'All';
}
// Get group names from repository
$groupNames = [];
foreach ($groups as $groupId) {
$group = $this->groupRepository->find($groupId);
if ($group) {
$groupNames[] = $group->getName();
}
}
if (count($groupNames) === 1) {
// Single team format
$teamsName = $groupNames[0];
} else {
// Multiple teams format
$teamsName = implode(', ', $groupNames);
}
return $teamsName;
}
public function getReportFileName(AutomatedReportResult $report): string
...
|
[{"role":"AXButton","text" [{"role":"AXButton","text":"Project: faVsco.js, menu","depth":5,"help_text":"~/jiminny/app","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"#11894 on JY-18909-automated-reports-ask-jiminny, menu","depth":5,"help_text":"Pull request #11894 exists for current branch JY-18909-automated-reports-ask-jiminny","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Start Listening for PHP Debug Connections","depth":5,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"AutomatedReportsCommandTest","depth":6,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Run 'AutomatedReportsCommandTest'","depth":6,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Debug 'AutomatedReportsCommandTest'","depth":6,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"More Actions","depth":6,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JetBrains AI","depth":5,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Search Everywhere","depth":5,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"IDE and Project Settings","depth":5,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Execute","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Explain Plan","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Browse Query History","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"View Parameters","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Open Query Execution Settings…","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"In-Editor Results","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Tx: Auto","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Cancel Running Statements","depth":4,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Playground","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"jiminny","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.088194445,"height":0.027777778},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"16","depth":4,"role_description":"text"},{"role":"AXStaticText","text":"13","depth":4,"role_description":"text"},{"role":"AXStaticText","text":"13","depth":4,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"SELECT * FROM teams WHERE id = 1;\n\nselect * from crm_layouts where crm_configuration_id = 39;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 283;\nSELECT * FROM crm_fields WHERE id = 2234;\nSELECT * FROM crm_field_values WHERE crm_field_id = 2234;\n\nselect * from crm_profiles where user_id = 143;\n\nselect * from record_types where crm_configuration_id = 39; # 0121K000001MHElQAO,0121K000001MHEqQAO\nselect * from business_processes where crm_configuration_id = 39;\n# 01941000000H669AAC, 01941000000H66JAAS\n\nselect * from record_type_field_values\n where record_type_id IN (24);\n\nselect * from crm_field_values where id IN (2730);\n\nselect * from crm_configurations where id = 39;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 1\nand sa.provider = 'salesforce'; #1035\n\n\nselect * from users where team_id = 1; # 222 group 3\nSELECT * FROM activities WHERE user_id = 222 order by id desc;\nselect * from sidekick_settings where team_id = 1;\nselect * from teams where id = 1;\nselect * from team_features where team_id = 1;\n\nselect * from activities where crm_configuration_id = 2\nand provider = 'ms-teams' and id = 608765;\n\nSELECT * FROM activities WHERE crm_configuration_id = 2 and crm_provider_id = '59523413338';\n\nselect * from sidekick_settings where team_id = 2;\n\nSELECT * FROM activities WHERE id = 608660;\nselect * from activity_summary_logs where activity_id = 608660;\nselect * from ai_prompts where transcription_id = 11214;\n\n# ********************************************************************************************************\nSELECT * FROM activities WHERE uuid_to_bin('ed78a437-2804-450e-ab2f-56ab1c641346') = uuid;\n# id: 608818, crm: 59628809737\nSELECT * FROM activities WHERE uuid_to_bin('36b06e55-afdd-4782-8dee-c624cd0af191') = uuid;\n# id: 608821, crm: 59632069252\nSELECT ce.start_time, ce.end_time, a.id, a.uuid, crm_provider_id, calendar_event_id, title,\nplaybook_category_id, user_id, lead_id, contact_id, account_id, opportunity_id,\nscheduled_start_time, scheduled_end_time, actual_start_time, actual_end_time, a.created_at\nFROM activities a\njoin calendar_events ce on a.calendar_event_id = ce.id\nWHERE a.id IN (608818, 608821);\n\nselect * from users where team_id = 1;\nselect * from team_settings where team_id = 1;\nselect * from crm_profiles where crm_configuration_id = 39 order by user_id;\n\nselect * from team_features where team_id = 1;\n\nselect * from users where team_id = 2;\n\nSELECT * FROM activities WHERE uuid_to_bin('ec7647e9-5225-458b-b475-f31aa2769204') = uuid; # 612639\n# Preslava N. Ivanova, grou id 3\n\nSELECT * FROM opportunities WHERE uuid_to_bin('a2928fe5-aec5-46cb-85d9-7654c89e46a6') = uuid;\n\nselect * from activities where opportunity_id = 344 and actual_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00';\n\nselect\n a.id,\n a.type,\n a.scheduled_start_time,\n a.actual_start_time,\n a.created_at,\n a.opportunity_id,\n a.status\nFROM activities a\nWHERE opportunity_id = 344\nand status IN ('completed', 'received', 'delivered')\nand (\n (a.actual_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00')\nOR (a.created_at between '2024-10-11 00:00:00' and '2024-10-12 00:00:00')\nOR (a.scheduled_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00'))\n;\n\nSELECT * FROM users WHERE id = 222;\n\nSELECT * FROM crm_profiles WHERE user_id = 222;\nselect * from crm_layouts where crm_configuration_id = 39;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 281;\n\nselect * from group_deal_risk_types;\n\nselect * from opportunities where team_id = 1;\n\nSELECT * FROM opportunities WHERE id = 315;\nSELECT * FROM crm_field_data WHERE object_id = 315;\nselect * from crm_field_data where object_id = 260;\n\nselect * from generic_ai_prompts where subject_id = 315;\n\nselect * from teams; # 36, 21, 121, james.graham@bullhorn.jiminny.com\nSELECT * FROM social_accounts WHERE sociable_id = 121 and provider = 'bullhorn';\n\n# ************************************************************************************\nselect * from teams where id = 1;\nselect * from crm_configurations where id = 39;\nselect * from users where team_id = 1;\nselect u.email, cp.* from users u\njoin crm_profiles cp on u.id = cp.user_id\nwhere u.team_id = 1;\n# 1 - 00541000004281rAAA\n# 204 - 0052g000003freeAAA\n# 429 - 0052g000003qGOiAAM\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 1\nand sa.provider = 'salesforce';\n\nselect * from activities where type = 'softphone'\nand created_at > '2024-12-11 15:24:36' order by id desc;\n\nselect * from activity_providers where team_id = 1;\nselect * from activity_provider_users where activity_provider_id = 328;\n\nselect * from opportunities where crm_configuration_id = 39\nAND account_id = 178 AND is_closed = false\norder by created_at DESC;\n\nselect * from contacts where id = 3952;\nselect * from accounts where id = 178;\n\n# ************************************************************************************\nselect * from teams where id = 36;\nselect * from crm_configurations where id = 21;\nselect * from users where team_id = 36;\nselect u.email, cp.* from users u\njoin crm_profiles cp on u.id = cp.user_id\nwhere u.team_id = 36;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 36\nand sa.provider = 'bullhorn';\n\nselect * from social_accounts where id = 348;\nUPDATE social_accounts SET\nprovider_user_token = '21442_6802599_91:41179a58-21e7-4d7c-ad58-56bb666b2f65',\nprovider_refresh_token = '21442_6802599_91:01c6b335-3f2a-42e4-85ff-8a08fa65fceb',\nexpires = 1733998131,\nstate = 'connected'\nWHERE id = 348;\n\n# ************************************************************************************\nselect * from teams where id = 31;\nselect * from crm_configurations where id = 18;\n\nselect * from users where team_id = 31; # 257\nselect u.email, cp.* from users u\njoin crm_profiles cp on u.id = cp.user_id\nwhere u.team_id = 31;\n\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 31\nand sa.provider = 'close';\n\nselect * from contacts where crm_configuration_id = 18;\n\n# ********************** NEPTUNE **************************************************************\nselect * from teams;\nselect * from users where id IN (1030, 1035, 1052);\nselect * from crm_configurations;\n\nselect * from users where team_id = 65; # 257\nselect * from team_settings where team_id = 65; # 257\nselect * from invitations where team_id = 65; # 257\nselect * from users where email = 'integration-account@jiminny.com'; # 257\nselect u.email, cp.* from users u\njoin crm_profiles cp on u.id = cp.user_id\nwhere u.team_id = 65;\n\nselect * from crm_configurations where id = 53;\nselect * from accounts where crm_configuration_id = 53 order by id desc;\nselect * from leads where crm_configuration_id = 53 order by id desc;\nselect * from contacts where crm_configuration_id = 53 order by id desc;\nselect * from opportunities where crm_configuration_id = 53 order by id desc;\nselect * from crm_profiles where crm_configuration_id = 53 order by id desc;\nselect * from crm_fields where crm_configuration_id = 53 order by id desc;\nselect * from crm_field_values where crm_field_id = 3341 order by id desc;\nselect * from crm_layouts where crm_configuration_id = 53 order by id desc;\nselect * from stages where crm_configuration_id = 53 order by id desc;\n\n\nselect * from crm_profiles where crm_configuration_id = 13;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 65\nand sa.provider = 'integration-app';\n\nselect * from contacts where crm_configuration_id = 13;\n\nselect * from social_accounts where sociable_id = 283;\n\nSELECT * FROM opportunities WHERE crm_provider_id = '006O400000E9bzeIAB';\n\nselect * from activity_providers where team_id = 65;\nSELECT * FROM activities WHERE crm_configuration_id IN (51, 52, 53);\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 65\n;\n\n# ***************************** STAGING ********************************************\nSELECT * FROM teams;\nSELECT * FROM teams WHERE id = 88;\nSELECT * FROM teams WHERE id = 89;\nselect * from team_settings where team_id = 89;\nSELECT * FROM users WHERE team_id = 89;\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 89;\n\nselect * from users;\nSELECT * FROM social_accounts WHERE sociable_id = 1761;\nSELECT * FROM crm_configurations WHERE id = 70;\nselect * from accounts where crm_configuration_id = 70 order by id desc;\nselect * from leads where crm_configuration_id = 70 order by id desc;\nselect * from contacts where crm_configuration_id = 70 order by id desc;\nselect * from opportunities where crm_configuration_id = 70 order by id desc;\nselect * from crm_profiles where crm_configuration_id = 70 order by id desc;\nselect * from crm_fields where crm_configuration_id = 70 order by id desc;\nselect * from crm_field_values where crm_field_id = 3536 order by id desc;\nselect * from crm_layouts where crm_configuration_id = 70 order by id desc;\nselect * from stages where crm_configuration_id = 70 order by id desc;\nselect * from business_processes where crm_configuration_id = 70 order by id desc;\nselect * from business_process_stages where business_process_id = 34;\n\nselect * from contacts where id = 10468;\n\nselect * from crm_layouts where crm_configuration_id = 70;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 388;\nSELECT * FROM crm_fields WHERE id IN (3533,3534,3535);\n\nselect * from activities where crm_configuration_id = 70\nand (account_id IS NOT NULL or lead_id IS NOT NULL or contact_id IS NOT NULL or opportunity_id IS NOT NULL) order by id desc;\n\nSELECT * FROM activities WHERE uuid_to_bin('2e10b60f-8a61-41c5-a3d4-28835353dc65') = uuid;\nSELECT * FROM activities where crm_configuration_id = 69 ;\n\nSELECT * FROM users WHERE email LIKE '%jiminny_web_sa2@jiminny.com%';\nSELECT * FROM activities WHERE uuid_to_bin('5a150c93-40fc-42ec-b3bd-c1d328e09f6e') = uuid;\nSELECT * FROM opportunities WHERE id = 385;\n\nselect * from participants p\njoin activities a on p.activity_id = a.id\nwhere a.crm_configuration_id = 70\nand (p.lead_id IS NOT NULL or p.contact_id IS NOT NULL);\nSELECT * FROM participants WHERE id = 1013638;\n\nselect * from teams where id = 90;\nselect * from users where team_id = 90;\nselect * from social_accounts where social_accounts.sociable_id IN (1960,1760);\nSELECT * FROM crm_profiles WHERE crm_configuration_id = 71;\nselect * from invitations where team_id = 90;\n\nselect * from crm_configurations where id = 71;\nselect * from accounts where crm_configuration_id = 71 order by id desc;\nselect * from leads where crm_configuration_id = 71 order by id desc;\nselect * from contacts where crm_configuration_id = 71 order by id desc;\nselect * from opportunities where crm_configuration_id = 71 order by id desc;\nselect * from crm_profiles where crm_configuration_id = 71 order by id desc;\nselect * from crm_fields where crm_configuration_id = 71 order by id desc;\nselect * from crm_field_values where crm_field_id = 3341 order by id desc;\nselect * from crm_layouts where crm_configuration_id = 71 order by id desc;\nselect * from stages where crm_configuration_id = 71 order by id desc;\n\nselect * from users order by secondary_email desc;\nselect u.id, u.email, u.status, sa.id, sa.provider_user_id from social_accounts sa\n join users u on sa.sociable_id = u.id\nwhere sa.provider = 'google' and u.email LIKE 'aneliya%';\n\nselect * from failed_jobs order by id desc;\n\nselect * from users where email = 'ben.allwright@learningpeople.co.uk' or secondary_email = 'ben.allwright@learningpeople.co.uk';\n\nselect * from teams;\nSELECT * FROM crm_profiles WHERE crm_configuration_id = 39;\nSELECT * FROM crm_fields WHERE crm_configuration_id = 39 and object_type = 'task';\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 1\nand sa.provider = 'salesforce';\n\n# ************************************************************************************\nSELECT * FROM activities WHERE uuid_to_bin('c38b3895-fd0f-4b1f-9fb2-c170dba137c6') = uuid;\nSELECT * FROM crm_configurations WHERE id = 70;\n\nselect * from teams where id = 1;\nselect * from groups where team_id = 1;\nselect * from users where team_id = 1;\n\nselect o.id, o.name,o.close_date, u.id, u.name, u.group_id, r.id, r.display_name, g.name, g.scope from opportunities o\njoin users u on o.user_id = u.id\njoin groups g on u.group_id = g.id\njoin role_user ru on u.id = ru.user_id\njoin roles r on ru.role_id = r.id\nwhere o.crm_configuration_id = 39 and close_date > '2024-01-01 00:00:00';\n\nselect * from role_user where user_id = 143;\nselect * from roles;\n\nselect * from role_user;\nselect * from groups where id = 9;\nselect * from scope_groups where group_id = 9;\n\n# ************************************************************************************\nselect * from teams where id = 36;\nselect * from crm_configurations;\nSELECT * FROM social_accounts WHERE sociable_id = 121;\n\nhttps://crmsandbox.zoho.com/crm/jiminnyw4/tab/Leads/4776201000005049105\nhttps://crmsandbox.zoho.com/crm/\n\nhttps://crm.zoho.com/crm/org3469620/tab/Leads/230045000229559080\n https://crm.zoho.com/crm/\n org3469620\n\nSELECT * FROM activities WHERE uuid_to_bin('03382d20-c8bc-48e7-a3d4-90b52fa5ceab') = uuid;\n\nselect * from users where email LIKE \"%mobile_automation_%\";\nselect * from social_accounts where sociable_id IN (2228);\nselect * from crm_profiles where user_id IN (2222,2223,2226,2227);\n\nselect * from teams order by id desc;\nSELECT * FROM users WHERE id = 2229;\nSELECT * FROM crm_profiles WHERE user_id = 2229;\nselect * from opportunities where crm_configuration_id = 88;\nselect * from crm_fields where crm_configuration_id = 88;\nselect * from crm_profiles where crm_configuration_id = 88;\n\nSELECT * FROM teams WHERE id = 1;\n\nSELECT * FROM users WHERE id = 143;\nSELECT * FROM users WHERE uuid_to_bin('fde193d3-06a2-4e1a-8895-62b94039215d') = uuid;\nSELECT * FROM teams WHERE uuid_to_bin('73385071-a756-42ae-9c73-8b53f2309467') = uuid;\n\nhttps://app.staging.jiminny.com/ondemand?\n min_duration=1\n &\n only_recorded=1\n &\n user_id%5B%5D=641f1acb-16b8-42d1-8726-df52979dad0e\n &\n sequence_number=2\n\n select * from users where team_id = 1 and email like '%stoyan%'\n\nselect * from coaching_feedbacks;\n\nselect * from teams;\nSELECT * FROM users WHERE team_id = 36;\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 19\nand sa.provider = 'pipedrive';\n\nselect * from users where id = 143;\n\nSELECT * FROM users WHERE uuid_to_bin('73180eeb-33de-4065-977d-ccbe0e6c94fc') = uuid;\nSELECT * FROM teams WHERE uuid_to_bin('73180eeb-33de-4065-977d-ccbe0e6c94fc') = uuid;\nSELECT * FROM activity_shares WHERE uuid_to_bin('73180eeb-33de-4065-977d-ccbe0e6c94fc') = uuid;\n\nselect * from users where team_id = 2;\nselect * from activities where crm_configuration_id = 39\nand activities.scheduled_start_time BETWEEN '2025-04-09 00:00:00' AND '2025-04-09 23:59:59'\nAND user_id = 143\norder by id desc;\n\n# ************************************************************************************\nselect * from teams where id = 142; # 2312, 126\nselect * from team_settings;\nselect * from users where team_id = 142; # 21642\nSELECT * FROM social_accounts WHERE sociable_id = 21642;\nSELECT * FROM crm_profiles cp join users u ON u.id = cp.user_id WHERE team_id = 142;\nselect * from crm_profiles where id IN (93);\nselect * from invitations;\nselect * from team_features where team_id = 1;\n\nSELECT * FROM crm_configurations WHERE id = 126;\nselect * from accounts where crm_configuration_id = 126 order by id desc;\nselect * from leads where crm_configuration_id = 126 order by id desc;\nselect * from contacts where crm_configuration_id = 126 order by id desc;\nselect * from opportunities where crm_configuration_id = 126 order by id desc;\nselect * from crm_profiles where crm_configuration_id = 126 order by id desc;\nselect * from crm_fields where crm_configuration_id = 126 # 11060\n# and type IN ('picklist', 'status')\n# and object_type = 'task'\norder by id desc;\n# 5731,5732,5733\nselect DISTINCT crm_field_id from crm_field_values where crm_field_id IN (11151,12239,12215,12185,12175,12165,12144,12137,12127,12109,12107,12105,12103,12092,12037,12005,12003,11987,11969,11958,11951,11942,11931,11924,11921,11917,11915,11901,11893,11883,11872,11870,11868,11866,11839,11833,11821,11793,11780,11777,11769,11757,11737,11735,11656,11645,11638,11629,11618,11611,11602,11591,11584,11581,11558,11544,11543,11534,11532,11529,11527,11503,11497,11493,11488,11470,11468,11457,11455,11397,11387,11372,11363,11348,11323,11318,11309,11301,11300,11292,11290,11286,11284,11256,11252,11242,11237,11233,11219,11176,11160) order by id desc;\nselect * from crm_layouts where crm_configuration_id = 126 order by id desc;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id in (300,299,298);\nselect * from stages where crm_configuration_id = 126 order by id desc;\nselect * from business_processes where crm_configuration_id = 126 order by id desc;\nselect * from business_process_stages where business_process_id IN (76,75,74,73);\nselect * from playbooks where team_id = 142;\nselect * from playbook_layouts where playbook_id IN (108);\nSELECT * FROM playbook_categories WHERE playbook_id IN (108);\n\nselect * from teams where id = 130;\nSELECT * FROM social_accounts WHERE sociable_id = 2291;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 2\nand sa.provider = 'hubspot';\n\nSELECT * FROM activities\n WHERE crm_configuration_id = 110;\n\nselect * from teams;\nselect * from crm_configurations;\n\nSELECT * FROM activities WHERE id = 628773;\nSELECT * FROM crm_profiles WHERE user_id = 1460;\nSELECT * FROM social_accounts WHERE sociable_id = 2291;\n\nselect * from teams;\nselect ru.*, pr.*, p.* from users u join role_user ru on ru.user_id = u.id\njoin permission_role pr on pr.role_id = ru.role_id\n join permissions p on p.id = pr.permission_id\nwhere team_id = 495 and p.name IN ('dial');\n\nselect * from teams where id = 145;\nselect * from crm_configurations where id = 129;\nselect * from social_accounts where sociable_id = 2317;\nSELECT * FROM activities WHERE uuid_to_bin('8dbab184-a333-4268-ad57-fb41f8d53a9a') = uuid;\n\nselect * from teams where id = 1;\nSELECT * FROM crm_layouts WHERE crm_configuration_id = 39;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 280;\nSELECT * FROM crm_layout_entities WHERE id = 5507;\nSELECT * FROM crm_fields WHERE crm_configuration_id = 39 and object_type IN ('event');\n\nselect * from teams;\nselect * from activities where crm_configuration_id = 14;\n\nSELECT * FROM social_accounts where provider = 'copper';\n\nselect * from activities where id = 628467;\nselect * from participants where activity_id = 628467;\n\nSELECT * FROM contacts WHERE id = 3969;\nSELECT * FROM accounts WHERE id = 177;\n\nSELECT * FROM activities WHERE uuid_to_bin('4eb54c77-cfa3-2bd4-84a7-9ed46a21c988') = uuid;\n\n# ********************* BH\nselect * from teams where id = 36;\nSELECT * FROM crm_configurations WHERE id = 21;\nselect * from activities where crm_configuration_id = 21 and id = 607901;\nselect * from activities where crm_configuration_id = 21;\n\nselect * roles;\nselect * from permissions;\nselect * from permission_role where permission_id = 226;\n\nselect * from migrations order by id desc;\n\n# mercury\n# neptune\n# earth\n\nselect * from teams;\nselect * from teams where id = 19;\nselect * from teams where id = 27;\nselect * from users where team_id = 27;\nSELECT * FROM crm_configurations WHERE id = 42;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 19\nand sa.provider = 'pipedrive';\n\nselect * from activities where id = 631461;\nSELECT * FROM crm_field_values WHERE crm_field_id = 180;\n\nselect * from teams where id = 2;\nSELECT * FROM social_accounts WHERE sociable_id = 89;\n\nSELECT * FROM activities WHERE uuid_to_bin('ba0c029a-bc14-4e17-8603-64174acebcbb') = uuid; # 634273\nselect * from activity_summary_logs where activity_id = 634273;\n\nselect * from sidekick_settings where team_id = 2;\n\nselect * from teams; # 2, 2\nSELECT * FROM crm_configurations WHERE team_id = 2; # 2\nselect * from team_features where team_id = 2;\nselect * from features;\nSELECT * FROM opportunities WHERE crm_configuration_id = 2 and crm_provider_id = '51317301383';\nSELECT * FROM opportunities WHERE crm_configuration_id = 2 order by id desc;\n\nselect * from automated_reports order by id desc;\nselect * from automated_report_results order by id desc;\nselect * from users where team_id = 1 and id IN (7160, 3248);\nselect * from migrations order by id desc;\n\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 1 and sa.provider = 'salesforce';\n\nselect * from teams where id = 1;\nselect * from groups g JOIN playbooks p on g.playbook_id = p.id where g.team_id = 1;\nselect * from groups where id = 565;\nselect * from playbooks where team_id = 1;\nselect * from playbooks where id = 175;\nselect * from playbook_categories where playbook_id = 175;\nselect * from users where team_id = 1;\nselect * from users where id = 7160;\nselect * from crm_profiles where user_id = 7160;\nselect * from features;\nselect\n *\n# id, uuid, type, provider, playbook_category_id, user_id, lead_id, contact_id, account_id, opportunity_id, stage_id,\n# crm_configuration_id, crm_provider_id, transcription_id, status\nfrom activities where crm_configuration_id = 1 and type = 'conference'\n# and crm_provider_id IS NOT NULL\nand provider != 'uploader' and actual_start_time IS NOT NULL\nORDER by id desc;\nselect * from activities where id = 54747783; # 00UO400000pCzojMAC\n\nselect p.id, p.activity_type, pc.id, pc.name\nFROM playbooks p\njoin playbook_categories pc on p.id = pc.playbook_id\nwhere p.team_id = 1 and p.activity_type = 'event';\n\nSELECT * FROM crm_fields WHERE crm_configuration_id = 1 and object_type = 'event';\nSELECT * FROM crm_field_values WHERE crm_field_id = 4;\n\nselect * from crm_layouts cl join playbook_layouts pl on cl.id = pl.layout_id\nwhere crm_configuration_id = 1 and pl.playbook_id = 175;\n\nselect * from teams;\nSELECT r.* FROM automated_reports r\njoin teams t on r.team_id = t.id\nWHERE r.frequency = 'daily'\n and r.status = 1\nAND t.status = 'active'\nAND (r.expires_at >= now() OR r.expires_at IS NULL);\n\nselect * from automated_report_results where report_id IN (18, 33);\n\nselect * from activity_searches where id = 10932;\nselect * from activity_search_filters where activity_search_id = 10932;\nselect * from automated_reports;\nselect * from automated_report_results where report_id IN (34, 35);","depth":4,"value":"SELECT * FROM teams WHERE id = 1;\n\nselect * from crm_layouts where crm_configuration_id = 39;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 283;\nSELECT * FROM crm_fields WHERE id = 2234;\nSELECT * FROM crm_field_values WHERE crm_field_id = 2234;\n\nselect * from crm_profiles where user_id = 143;\n\nselect * from record_types where crm_configuration_id = 39; # 0121K000001MHElQAO,0121K000001MHEqQAO\nselect * from business_processes where crm_configuration_id = 39;\n# 01941000000H669AAC, 01941000000H66JAAS\n\nselect * from record_type_field_values\n where record_type_id IN (24);\n\nselect * from crm_field_values where id IN (2730);\n\nselect * from crm_configurations where id = 39;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 1\nand sa.provider = 'salesforce'; #1035\n\n\nselect * from users where team_id = 1; # 222 group 3\nSELECT * FROM activities WHERE user_id = 222 order by id desc;\nselect * from sidekick_settings where team_id = 1;\nselect * from teams where id = 1;\nselect * from team_features where team_id = 1;\n\nselect * from activities where crm_configuration_id = 2\nand provider = 'ms-teams' and id = 608765;\n\nSELECT * FROM activities WHERE crm_configuration_id = 2 and crm_provider_id = '59523413338';\n\nselect * from sidekick_settings where team_id = 2;\n\nSELECT * FROM activities WHERE id = 608660;\nselect * from activity_summary_logs where activity_id = 608660;\nselect * from ai_prompts where transcription_id = 11214;\n\n# ********************************************************************************************************\nSELECT * FROM activities WHERE uuid_to_bin('ed78a437-2804-450e-ab2f-56ab1c641346') = uuid;\n# id: 608818, crm: 59628809737\nSELECT * FROM activities WHERE uuid_to_bin('36b06e55-afdd-4782-8dee-c624cd0af191') = uuid;\n# id: 608821, crm: 59632069252\nSELECT ce.start_time, ce.end_time, a.id, a.uuid, crm_provider_id, calendar_event_id, title,\nplaybook_category_id, user_id, lead_id, contact_id, account_id, opportunity_id,\nscheduled_start_time, scheduled_end_time, actual_start_time, actual_end_time, a.created_at\nFROM activities a\njoin calendar_events ce on a.calendar_event_id = ce.id\nWHERE a.id IN (608818, 608821);\n\nselect * from users where team_id = 1;\nselect * from team_settings where team_id = 1;\nselect * from crm_profiles where crm_configuration_id = 39 order by user_id;\n\nselect * from team_features where team_id = 1;\n\nselect * from users where team_id = 2;\n\nSELECT * FROM activities WHERE uuid_to_bin('ec7647e9-5225-458b-b475-f31aa2769204') = uuid; # 612639\n# Preslava N. Ivanova, grou id 3\n\nSELECT * FROM opportunities WHERE uuid_to_bin('a2928fe5-aec5-46cb-85d9-7654c89e46a6') = uuid;\n\nselect * from activities where opportunity_id = 344 and actual_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00';\n\nselect\n a.id,\n a.type,\n a.scheduled_start_time,\n a.actual_start_time,\n a.created_at,\n a.opportunity_id,\n a.status\nFROM activities a\nWHERE opportunity_id = 344\nand status IN ('completed', 'received', 'delivered')\nand (\n (a.actual_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00')\nOR (a.created_at between '2024-10-11 00:00:00' and '2024-10-12 00:00:00')\nOR (a.scheduled_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00'))\n;\n\nSELECT * FROM users WHERE id = 222;\n\nSELECT * FROM crm_profiles WHERE user_id = 222;\nselect * from crm_layouts where crm_configuration_id = 39;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 281;\n\nselect * from group_deal_risk_types;\n\nselect * from opportunities where team_id = 1;\n\nSELECT * FROM opportunities WHERE id = 315;\nSELECT * FROM crm_field_data WHERE object_id = 315;\nselect * from crm_field_data where object_id = 260;\n\nselect * from generic_ai_prompts where subject_id = 315;\n\nselect * from teams; # 36, 21, 121, james.graham@bullhorn.jiminny.com\nSELECT * FROM social_accounts WHERE sociable_id = 121 and provider = 'bullhorn';\n\n# ************************************************************************************\nselect * from teams where id = 1;\nselect * from crm_configurations where id = 39;\nselect * from users where team_id = 1;\nselect u.email, cp.* from users u\njoin crm_profiles cp on u.id = cp.user_id\nwhere u.team_id = 1;\n# 1 - 00541000004281rAAA\n# 204 - 0052g000003freeAAA\n# 429 - 0052g000003qGOiAAM\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 1\nand sa.provider = 'salesforce';\n\nselect * from activities where type = 'softphone'\nand created_at > '2024-12-11 15:24:36' order by id desc;\n\nselect * from activity_providers where team_id = 1;\nselect * from activity_provider_users where activity_provider_id = 328;\n\nselect * from opportunities where crm_configuration_id = 39\nAND account_id = 178 AND is_closed = false\norder by created_at DESC;\n\nselect * from contacts where id = 3952;\nselect * from accounts where id = 178;\n\n# ************************************************************************************\nselect * from teams where id = 36;\nselect * from crm_configurations where id = 21;\nselect * from users where team_id = 36;\nselect u.email, cp.* from users u\njoin crm_profiles cp on u.id = cp.user_id\nwhere u.team_id = 36;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 36\nand sa.provider = 'bullhorn';\n\nselect * from social_accounts where id = 348;\nUPDATE social_accounts SET\nprovider_user_token = '21442_6802599_91:41179a58-21e7-4d7c-ad58-56bb666b2f65',\nprovider_refresh_token = '21442_6802599_91:01c6b335-3f2a-42e4-85ff-8a08fa65fceb',\nexpires = 1733998131,\nstate = 'connected'\nWHERE id = 348;\n\n# ************************************************************************************\nselect * from teams where id = 31;\nselect * from crm_configurations where id = 18;\n\nselect * from users where team_id = 31; # 257\nselect u.email, cp.* from users u\njoin crm_profiles cp on u.id = cp.user_id\nwhere u.team_id = 31;\n\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 31\nand sa.provider = 'close';\n\nselect * from contacts where crm_configuration_id = 18;\n\n# ********************** NEPTUNE **************************************************************\nselect * from teams;\nselect * from users where id IN (1030, 1035, 1052);\nselect * from crm_configurations;\n\nselect * from users where team_id = 65; # 257\nselect * from team_settings where team_id = 65; # 257\nselect * from invitations where team_id = 65; # 257\nselect * from users where email = 'integration-account@jiminny.com'; # 257\nselect u.email, cp.* from users u\njoin crm_profiles cp on u.id = cp.user_id\nwhere u.team_id = 65;\n\nselect * from crm_configurations where id = 53;\nselect * from accounts where crm_configuration_id = 53 order by id desc;\nselect * from leads where crm_configuration_id = 53 order by id desc;\nselect * from contacts where crm_configuration_id = 53 order by id desc;\nselect * from opportunities where crm_configuration_id = 53 order by id desc;\nselect * from crm_profiles where crm_configuration_id = 53 order by id desc;\nselect * from crm_fields where crm_configuration_id = 53 order by id desc;\nselect * from crm_field_values where crm_field_id = 3341 order by id desc;\nselect * from crm_layouts where crm_configuration_id = 53 order by id desc;\nselect * from stages where crm_configuration_id = 53 order by id desc;\n\n\nselect * from crm_profiles where crm_configuration_id = 13;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 65\nand sa.provider = 'integration-app';\n\nselect * from contacts where crm_configuration_id = 13;\n\nselect * from social_accounts where sociable_id = 283;\n\nSELECT * FROM opportunities WHERE crm_provider_id = '006O400000E9bzeIAB';\n\nselect * from activity_providers where team_id = 65;\nSELECT * FROM activities WHERE crm_configuration_id IN (51, 52, 53);\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 65\n;\n\n# ***************************** STAGING ********************************************\nSELECT * FROM teams;\nSELECT * FROM teams WHERE id = 88;\nSELECT * FROM teams WHERE id = 89;\nselect * from team_settings where team_id = 89;\nSELECT * FROM users WHERE team_id = 89;\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 89;\n\nselect * from users;\nSELECT * FROM social_accounts WHERE sociable_id = 1761;\nSELECT * FROM crm_configurations WHERE id = 70;\nselect * from accounts where crm_configuration_id = 70 order by id desc;\nselect * from leads where crm_configuration_id = 70 order by id desc;\nselect * from contacts where crm_configuration_id = 70 order by id desc;\nselect * from opportunities where crm_configuration_id = 70 order by id desc;\nselect * from crm_profiles where crm_configuration_id = 70 order by id desc;\nselect * from crm_fields where crm_configuration_id = 70 order by id desc;\nselect * from crm_field_values where crm_field_id = 3536 order by id desc;\nselect * from crm_layouts where crm_configuration_id = 70 order by id desc;\nselect * from stages where crm_configuration_id = 70 order by id desc;\nselect * from business_processes where crm_configuration_id = 70 order by id desc;\nselect * from business_process_stages where business_process_id = 34;\n\nselect * from contacts where id = 10468;\n\nselect * from crm_layouts where crm_configuration_id = 70;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 388;\nSELECT * FROM crm_fields WHERE id IN (3533,3534,3535);\n\nselect * from activities where crm_configuration_id = 70\nand (account_id IS NOT NULL or lead_id IS NOT NULL or contact_id IS NOT NULL or opportunity_id IS NOT NULL) order by id desc;\n\nSELECT * FROM activities WHERE uuid_to_bin('2e10b60f-8a61-41c5-a3d4-28835353dc65') = uuid;\nSELECT * FROM activities where crm_configuration_id = 69 ;\n\nSELECT * FROM users WHERE email LIKE '%jiminny_web_sa2@jiminny.com%';\nSELECT * FROM activities WHERE uuid_to_bin('5a150c93-40fc-42ec-b3bd-c1d328e09f6e') = uuid;\nSELECT * FROM opportunities WHERE id = 385;\n\nselect * from participants p\njoin activities a on p.activity_id = a.id\nwhere a.crm_configuration_id = 70\nand (p.lead_id IS NOT NULL or p.contact_id IS NOT NULL);\nSELECT * FROM participants WHERE id = 1013638;\n\nselect * from teams where id = 90;\nselect * from users where team_id = 90;\nselect * from social_accounts where social_accounts.sociable_id IN (1960,1760);\nSELECT * FROM crm_profiles WHERE crm_configuration_id = 71;\nselect * from invitations where team_id = 90;\n\nselect * from crm_configurations where id = 71;\nselect * from accounts where crm_configuration_id = 71 order by id desc;\nselect * from leads where crm_configuration_id = 71 order by id desc;\nselect * from contacts where crm_configuration_id = 71 order by id desc;\nselect * from opportunities where crm_configuration_id = 71 order by id desc;\nselect * from crm_profiles where crm_configuration_id = 71 order by id desc;\nselect * from crm_fields where crm_configuration_id = 71 order by id desc;\nselect * from crm_field_values where crm_field_id = 3341 order by id desc;\nselect * from crm_layouts where crm_configuration_id = 71 order by id desc;\nselect * from stages where crm_configuration_id = 71 order by id desc;\n\nselect * from users order by secondary_email desc;\nselect u.id, u.email, u.status, sa.id, sa.provider_user_id from social_accounts sa\n join users u on sa.sociable_id = u.id\nwhere sa.provider = 'google' and u.email LIKE 'aneliya%';\n\nselect * from failed_jobs order by id desc;\n\nselect * from users where email = 'ben.allwright@learningpeople.co.uk' or secondary_email = 'ben.allwright@learningpeople.co.uk';\n\nselect * from teams;\nSELECT * FROM crm_profiles WHERE crm_configuration_id = 39;\nSELECT * FROM crm_fields WHERE crm_configuration_id = 39 and object_type = 'task';\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 1\nand sa.provider = 'salesforce';\n\n# ************************************************************************************\nSELECT * FROM activities WHERE uuid_to_bin('c38b3895-fd0f-4b1f-9fb2-c170dba137c6') = uuid;\nSELECT * FROM crm_configurations WHERE id = 70;\n\nselect * from teams where id = 1;\nselect * from groups where team_id = 1;\nselect * from users where team_id = 1;\n\nselect o.id, o.name,o.close_date, u.id, u.name, u.group_id, r.id, r.display_name, g.name, g.scope from opportunities o\njoin users u on o.user_id = u.id\njoin groups g on u.group_id = g.id\njoin role_user ru on u.id = ru.user_id\njoin roles r on ru.role_id = r.id\nwhere o.crm_configuration_id = 39 and close_date > '2024-01-01 00:00:00';\n\nselect * from role_user where user_id = 143;\nselect * from roles;\n\nselect * from role_user;\nselect * from groups where id = 9;\nselect * from scope_groups where group_id = 9;\n\n# ************************************************************************************\nselect * from teams where id = 36;\nselect * from crm_configurations;\nSELECT * FROM social_accounts WHERE sociable_id = 121;\n\nhttps://crmsandbox.zoho.com/crm/jiminnyw4/tab/Leads/4776201000005049105\nhttps://crmsandbox.zoho.com/crm/\n\nhttps://crm.zoho.com/crm/org3469620/tab/Leads/230045000229559080\n https://crm.zoho.com/crm/\n org3469620\n\nSELECT * FROM activities WHERE uuid_to_bin('03382d20-c8bc-48e7-a3d4-90b52fa5ceab') = uuid;\n\nselect * from users where email LIKE \"%mobile_automation_%\";\nselect * from social_accounts where sociable_id IN (2228);\nselect * from crm_profiles where user_id IN (2222,2223,2226,2227);\n\nselect * from teams order by id desc;\nSELECT * FROM users WHERE id = 2229;\nSELECT * FROM crm_profiles WHERE user_id = 2229;\nselect * from opportunities where crm_configuration_id = 88;\nselect * from crm_fields where crm_configuration_id = 88;\nselect * from crm_profiles where crm_configuration_id = 88;\n\nSELECT * FROM teams WHERE id = 1;\n\nSELECT * FROM users WHERE id = 143;\nSELECT * FROM users WHERE uuid_to_bin('fde193d3-06a2-4e1a-8895-62b94039215d') = uuid;\nSELECT * FROM teams WHERE uuid_to_bin('73385071-a756-42ae-9c73-8b53f2309467') = uuid;\n\nhttps://app.staging.jiminny.com/ondemand?\n min_duration=1\n &\n only_recorded=1\n &\n user_id%5B%5D=641f1acb-16b8-42d1-8726-df52979dad0e\n &\n sequence_number=2\n\n select * from users where team_id = 1 and email like '%stoyan%'\n\nselect * from coaching_feedbacks;\n\nselect * from teams;\nSELECT * FROM users WHERE team_id = 36;\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 19\nand sa.provider = 'pipedrive';\n\nselect * from users where id = 143;\n\nSELECT * FROM users WHERE uuid_to_bin('73180eeb-33de-4065-977d-ccbe0e6c94fc') = uuid;\nSELECT * FROM teams WHERE uuid_to_bin('73180eeb-33de-4065-977d-ccbe0e6c94fc') = uuid;\nSELECT * FROM activity_shares WHERE uuid_to_bin('73180eeb-33de-4065-977d-ccbe0e6c94fc') = uuid;\n\nselect * from users where team_id = 2;\nselect * from activities where crm_configuration_id = 39\nand activities.scheduled_start_time BETWEEN '2025-04-09 00:00:00' AND '2025-04-09 23:59:59'\nAND user_id = 143\norder by id desc;\n\n# ************************************************************************************\nselect * from teams where id = 142; # 2312, 126\nselect * from team_settings;\nselect * from users where team_id = 142; # 21642\nSELECT * FROM social_accounts WHERE sociable_id = 21642;\nSELECT * FROM crm_profiles cp join users u ON u.id = cp.user_id WHERE team_id = 142;\nselect * from crm_profiles where id IN (93);\nselect * from invitations;\nselect * from team_features where team_id = 1;\n\nSELECT * FROM crm_configurations WHERE id = 126;\nselect * from accounts where crm_configuration_id = 126 order by id desc;\nselect * from leads where crm_configuration_id = 126 order by id desc;\nselect * from contacts where crm_configuration_id = 126 order by id desc;\nselect * from opportunities where crm_configuration_id = 126 order by id desc;\nselect * from crm_profiles where crm_configuration_id = 126 order by id desc;\nselect * from crm_fields where crm_configuration_id = 126 # 11060\n# and type IN ('picklist', 'status')\n# and object_type = 'task'\norder by id desc;\n# 5731,5732,5733\nselect DISTINCT crm_field_id from crm_field_values where crm_field_id IN (11151,12239,12215,12185,12175,12165,12144,12137,12127,12109,12107,12105,12103,12092,12037,12005,12003,11987,11969,11958,11951,11942,11931,11924,11921,11917,11915,11901,11893,11883,11872,11870,11868,11866,11839,11833,11821,11793,11780,11777,11769,11757,11737,11735,11656,11645,11638,11629,11618,11611,11602,11591,11584,11581,11558,11544,11543,11534,11532,11529,11527,11503,11497,11493,11488,11470,11468,11457,11455,11397,11387,11372,11363,11348,11323,11318,11309,11301,11300,11292,11290,11286,11284,11256,11252,11242,11237,11233,11219,11176,11160) order by id desc;\nselect * from crm_layouts where crm_configuration_id = 126 order by id desc;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id in (300,299,298);\nselect * from stages where crm_configuration_id = 126 order by id desc;\nselect * from business_processes where crm_configuration_id = 126 order by id desc;\nselect * from business_process_stages where business_process_id IN (76,75,74,73);\nselect * from playbooks where team_id = 142;\nselect * from playbook_layouts where playbook_id IN (108);\nSELECT * FROM playbook_categories WHERE playbook_id IN (108);\n\nselect * from teams where id = 130;\nSELECT * FROM social_accounts WHERE sociable_id = 2291;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 2\nand sa.provider = 'hubspot';\n\nSELECT * FROM activities\n WHERE crm_configuration_id = 110;\n\nselect * from teams;\nselect * from crm_configurations;\n\nSELECT * FROM activities WHERE id = 628773;\nSELECT * FROM crm_profiles WHERE user_id = 1460;\nSELECT * FROM social_accounts WHERE sociable_id = 2291;\n\nselect * from teams;\nselect ru.*, pr.*, p.* from users u join role_user ru on ru.user_id = u.id\njoin permission_role pr on pr.role_id = ru.role_id\n join permissions p on p.id = pr.permission_id\nwhere team_id = 495 and p.name IN ('dial');\n\nselect * from teams where id = 145;\nselect * from crm_configurations where id = 129;\nselect * from social_accounts where sociable_id = 2317;\nSELECT * FROM activities WHERE uuid_to_bin('8dbab184-a333-4268-ad57-fb41f8d53a9a') = uuid;\n\nselect * from teams where id = 1;\nSELECT * FROM crm_layouts WHERE crm_configuration_id = 39;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 280;\nSELECT * FROM crm_layout_entities WHERE id = 5507;\nSELECT * FROM crm_fields WHERE crm_configuration_id = 39 and object_type IN ('event');\n\nselect * from teams;\nselect * from activities where crm_configuration_id = 14;\n\nSELECT * FROM social_accounts where provider = 'copper';\n\nselect * from activities where id = 628467;\nselect * from participants where activity_id = 628467;\n\nSELECT * FROM contacts WHERE id = 3969;\nSELECT * FROM accounts WHERE id = 177;\n\nSELECT * FROM activities WHERE uuid_to_bin('4eb54c77-cfa3-2bd4-84a7-9ed46a21c988') = uuid;\n\n# ********************* BH\nselect * from teams where id = 36;\nSELECT * FROM crm_configurations WHERE id = 21;\nselect * from activities where crm_configuration_id = 21 and id = 607901;\nselect * from activities where crm_configuration_id = 21;\n\nselect * roles;\nselect * from permissions;\nselect * from permission_role where permission_id = 226;\n\nselect * from migrations order by id desc;\n\n# mercury\n# neptune\n# earth\n\nselect * from teams;\nselect * from teams where id = 19;\nselect * from teams where id = 27;\nselect * from users where team_id = 27;\nSELECT * FROM crm_configurations WHERE id = 42;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 19\nand sa.provider = 'pipedrive';\n\nselect * from activities where id = 631461;\nSELECT * FROM crm_field_values WHERE crm_field_id = 180;\n\nselect * from teams where id = 2;\nSELECT * FROM social_accounts WHERE sociable_id = 89;\n\nSELECT * FROM activities WHERE uuid_to_bin('ba0c029a-bc14-4e17-8603-64174acebcbb') = uuid; # 634273\nselect * from activity_summary_logs where activity_id = 634273;\n\nselect * from sidekick_settings where team_id = 2;\n\nselect * from teams; # 2, 2\nSELECT * FROM crm_configurations WHERE team_id = 2; # 2\nselect * from team_features where team_id = 2;\nselect * from features;\nSELECT * FROM opportunities WHERE crm_configuration_id = 2 and crm_provider_id = '51317301383';\nSELECT * FROM opportunities WHERE crm_configuration_id = 2 order by id desc;\n\nselect * from automated_reports order by id desc;\nselect * from automated_report_results order by id desc;\nselect * from users where team_id = 1 and id IN (7160, 3248);\nselect * from migrations order by id desc;\n\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 1 and sa.provider = 'salesforce';\n\nselect * from teams where id = 1;\nselect * from groups g JOIN playbooks p on g.playbook_id = p.id where g.team_id = 1;\nselect * from groups where id = 565;\nselect * from playbooks where team_id = 1;\nselect * from playbooks where id = 175;\nselect * from playbook_categories where playbook_id = 175;\nselect * from users where team_id = 1;\nselect * from users where id = 7160;\nselect * from crm_profiles where user_id = 7160;\nselect * from features;\nselect\n *\n# id, uuid, type, provider, playbook_category_id, user_id, lead_id, contact_id, account_id, opportunity_id, stage_id,\n# crm_configuration_id, crm_provider_id, transcription_id, status\nfrom activities where crm_configuration_id = 1 and type = 'conference'\n# and crm_provider_id IS NOT NULL\nand provider != 'uploader' and actual_start_time IS NOT NULL\nORDER by id desc;\nselect * from activities where id = 54747783; # 00UO400000pCzojMAC\n\nselect p.id, p.activity_type, pc.id, pc.name\nFROM playbooks p\njoin playbook_categories pc on p.id = pc.playbook_id\nwhere p.team_id = 1 and p.activity_type = 'event';\n\nSELECT * FROM crm_fields WHERE crm_configuration_id = 1 and object_type = 'event';\nSELECT * FROM crm_field_values WHERE crm_field_id = 4;\n\nselect * from crm_layouts cl join playbook_layouts pl on cl.id = pl.layout_id\nwhere crm_configuration_id = 1 and pl.playbook_id = 175;\n\nselect * from teams;\nSELECT r.* FROM automated_reports r\njoin teams t on r.team_id = t.id\nWHERE r.frequency = 'daily'\n and r.status = 1\nAND t.status = 'active'\nAND (r.expires_at >= now() OR r.expires_at IS NULL);\n\nselect * from automated_report_results where report_id IN (18, 33);\n\nselect * from activity_searches where id = 10932;\nselect * from activity_search_filters where activity_search_id = 10932;\nselect * from automated_reports;\nselect * from automated_report_results where report_id IN (34, 35);","role_description":"text entry area","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.088194445,"height":0.027777778},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"102","depth":4,"role_description":"text"},{"role":"AXStaticText","text":"3","depth":4,"role_description":"text"},{"role":"AXStaticText","text":"34","depth":4,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Services\\Kiosk\\AutomatedReports;\n\nuse Carbon\\CarbonImmutable;\nuse Carbon\\CarbonInterface;\nuse Carbon\\Exceptions\\InvalidFormatException;\nuse DateTime;\nuse DateTimeInterface;\nuse DateTimeZone;\nuse Illuminate\\Contracts\\Bus\\Dispatcher as BusDispatcher;\nuse Illuminate\\Database\\Eloquent\\Builder;\nuse Illuminate\\Support\\Carbon;\nuse Illuminate\\Support\\Collection;\nuse Illuminate\\Support\\Facades\\Log;\nuse Illuminate\\Support\\Facades\\Storage;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinition\\InputTypeEnum;\nuse Jiminny\\Component\\AskAnything\\AskAnythingPromptService;\nuse Jiminny\\Component\\AskAnything\\Dtos\\AskAnythingPromptDto;\nuse Jiminny\\Component\\UrlGenerator\\Webhook;\nuse Jiminny\\Contracts\\Repositories\\PlaybookCategoryRepository;\nuse Jiminny\\Contracts\\Repositories\\TeamRepository;\nuse Jiminny\\Contracts\\Repositories\\UserRepository;\nuse Jiminny\\Exceptions\\ApplicationException;\nuse Jiminny\\Exceptions\\InvalidArgumentException;\nuse Jiminny\\Exceptions\\ModelNotFoundException;\nuse Jiminny\\Jobs\\AutomatedReports\\RequestGenerateReportJob;\nuse Jiminny\\Models\\Activity\\Search;\nuse Jiminny\\Models\\AskAnything\\AskAnythingPrompt;\nuse Jiminny\\Models\\AskAnything\\AskAnythingPromptTarget;\nuse Jiminny\\Models\\AutomatedReport;\nuse Jiminny\\Models\\AutomatedReportResult;\nuse Jiminny\\Models\\Contracts\\UserContract;\nuse Jiminny\\Models\\Feature\\FeatureEnum;\nuse Jiminny\\Models\\Team;\nuse Jiminny\\Models\\User;\nuse Jiminny\\Repositories\\AskAnythingRepository;\nuse Jiminny\\Repositories\\AutomatedReportsRepository;\nuse Jiminny\\Repositories\\GroupRepository;\nuse Jiminny\\Repositories\\SearchRepository;\nuse Jiminny\\Repositories\\StageRepository;\nuse Throwable;\n\nclass AutomatedReportsService\n{\n public const string TYPE_LOSS_ANALYSIS = 'loss_analysis';\n public const string TYPE_ASK_JIMINNY = 'ask_jiminny';\n\n /**\n * Standard report types (used by kiosk for existing automated reports).\n */\n // @TODO this will add filter, however if we need to control feature by FF we need conditional logic\n public const array TYPES = [\n ['id' => 'exec_summary', 'name' => 'Exec Summary'],\n ['id' => 'coaching_profiles', 'name' => 'Coaching Profiles'],\n ['id' => 'product_feedback', 'name' => 'Product Feedback'],\n ['id' => self::TYPE_LOSS_ANALYSIS, 'name' => 'Loss Analysis'],\n// ['id' => 'questions', 'name' => 'Questions'],\n// ['id' => 'statistical_quant', 'name' => 'Statistical Quantitative'],\n ];\n\n public const array ALL_TYPES = [\n ...self::TYPES,\n ['id' => self::TYPE_ASK_JIMINNY, 'name' => 'Ask Jiminny'],\n ];\n\n public const string FREQUENCY_DAILY = 'daily';\n public const string FREQUENCY_WEEKLY = 'weekly';\n public const string FREQUENCY_MONTHLY = 'monthly';\n public const string FREQUENCY_QUARTERLY = 'quarterly';\n public const string FREQUENCY_ONE_OFF = 'one_off';\n\n /**\n * Frequencies for standard (non-Ask Jiminny) reports.\n */\n public const array FREQUENCIES = [\n ['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],\n ['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],\n ['id' => self::FREQUENCY_QUARTERLY, 'name' => 'Quarterly'],\n ['id' => self::FREQUENCY_ONE_OFF, 'name' => 'One-off'],\n ];\n\n /**\n * Frequencies for Ask Jiminny reports.\n */\n public const array ASK_JIMINNY_FREQUENCIES = [\n ['id' => self::FREQUENCY_DAILY, 'name' => 'Daily'],\n ['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],\n ['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],\n ];\n\n public const string MEDIA_TYPE_PDF = 'pdf';\n public const string MEDIA_TYPE_PODCAST = 'podcast';\n public const array MEDIA_TYPES = [self::MEDIA_TYPE_PDF, self::MEDIA_TYPE_PODCAST];\n public const array MEDIA_TYPE_OBJECT_PDF = ['id' => self::MEDIA_TYPE_PDF, 'name' => 'PDF'];\n public const array MEDIA_TYPE_OBJECT_PODCAST = ['id' => self::MEDIA_TYPE_PODCAST, 'name' => 'Podcast'];\n public const array MEDIA_TYPE_OBJECTS = [self::MEDIA_TYPE_OBJECT_PDF, self::MEDIA_TYPE_OBJECT_PODCAST];\n\n public const array CALL_TYPE_CONFERENCE = ['id' => 'conference', 'name' => 'Conference'];\n public const array CALL_TYPE_DIALER = ['id' => 'dialer', 'name' => 'Dialer'];\n public const int SENT_REPORT_AT_HOURS = 5;\n public const string PDF_KEY = 'pdf';\n public const string AUDIO_KEY = 'audio';\n\n private const array ALL_FREQUENCIES = [\n ['id' => self::FREQUENCY_DAILY, 'name' => 'Daily'],\n ['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],\n ['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],\n ['id' => self::FREQUENCY_QUARTERLY, 'name' => 'Quarterly'],\n ['id' => self::FREQUENCY_ONE_OFF, 'name' => 'One-off'],\n ];\n private const string S3_DIR = 'reports';\n private const array FILE_EXTENSIONS_VARIANTS = ['html', 'MD', 'pdf'];\n private const array FILE_PODCAST_EXTENSIONS_VARIANTS = ['json', 'mp3', 'ssml'];\n\n public function __construct(\n private readonly TeamRepository $teamRepository,\n private readonly GroupRepository $groupRepository,\n private readonly UserRepository $userRepository,\n private readonly StageRepository $stageRepository,\n private readonly DealStagesService $dealStagesService,\n private readonly RecipientsService $recipientsService,\n private readonly AutomatedReportsRepository $automatedReportsRepository,\n private readonly Webhook $webhookService,\n private readonly BusDispatcher $dispatcher,\n private readonly ActivityTypeService $activityTypeService,\n private readonly PlaybookCategoryRepository $playbookCategoryRepository,\n private readonly AskAnythingPromptService $askAnythingPromptService,\n private readonly SearchRepository $activitySearchRepository,\n private readonly AskAnythingRepository $askAnythingRepository,\n ) {\n }\n\n public static function getTypes(): array\n {\n $types = self::TYPES;\n\n return array_map(static function ($type) {\n return $type['id'];\n }, $types);\n }\n\n public static function getCallTypes(): array\n {\n return array_map(static function ($callType) {\n return $callType['id'];\n }, [self::CALL_TYPE_CONFERENCE, self::CALL_TYPE_DIALER]);\n }\n\n public static function getFrequencies(): array\n {\n return array_map(static function ($frequency) {\n return $frequency['id'];\n }, self::FREQUENCIES);\n }\n\n // front-facing structure\n public function getReportEnabledFieldData(bool $value = false): array\n {\n return [\n 'id' => 'report_enabled',\n 'label' => '',\n 'inputType' => InputTypeEnum::TOGGLE,\n 'value' => $value,\n ];\n }\n\n // Organizations = Teams\n public function getOrganizationFieldData(?string $value = null, bool $shortVersion = false): array\n {\n $options = $this->getTeams();\n\n if ($shortVersion) {\n return [\n 'id' => 'organization',\n 'label' => 'Organization',\n 'options' => $options,\n ];\n }\n\n return [\n 'id' => 'organization',\n 'label' => 'Organization',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => $options,\n 'value' => $value,\n 'dependencies' => [\n 'teams',\n 'deal_stage_at_call',\n 'current_deal_stage',\n 'recipients',\n ActivityTypeService::PLAYBOOK_CATEGORIES_KEY,\n ],\n 'dependsOn' => [],\n ];\n }\n\n // Teams = Groups\n public function getTeamFieldData(array $options = [], array $value = [], bool $shortVersion = false): array\n {\n if ($shortVersion) {\n return [\n 'id' => 'teams',\n 'label' => 'Team',\n 'options' => $options,\n ];\n }\n\n return [\n 'id' => 'teams',\n 'label' => 'Team',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'required' => false,\n 'placeholder' => 'Select',\n 'options' => $options,\n 'value' => $value, // value should be an array of objects {id, name}\n 'dependencies' => [ActivityTypeService::PLAYBOOK_CATEGORIES_KEY],\n 'dependsOn' => [],\n ];\n }\n\n public function getReportTypeFieldData(?string $value = null, bool $shortVersion = false, ?Team $team = null): array\n {\n $types = [];\n if ($team instanceof Team) {\n if ($team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {\n $types = self::TYPES;\n }\n if ($team->hasFeature(FeatureEnum::ASK_JIMINNY_REPORTS)) {\n $types[] = ['id' => self::TYPE_ASK_JIMINNY, 'name' => 'Ask Jiminny'];\n }\n } else {\n $types = self::TYPES;\n }\n\n if ($shortVersion) {\n return [\n 'id' => 'report_type',\n 'label' => 'Report Type',\n 'options' => $types,\n ];\n }\n\n return [\n 'id' => 'report_type',\n 'label' => 'Report Type',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => $types,\n 'value' => $value,\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getFrequencyFieldData(?string $value = null): array\n {\n return [\n 'id' => 'frequency',\n 'label' => 'Frequency',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => self::FREQUENCIES,\n 'value' => $value,\n 'dependencies' => ['period'],\n 'dependsOn' => [],\n ];\n }\n\n public function getPeriodFieldData(?string $valueStartDate = null, ?string $valueEndDate = null): array\n {\n return [\n 'id' => 'period',\n 'label' => 'Select one-off period',\n 'inputType' => InputTypeEnum::DATE_RANGE,\n 'required' => true,\n 'placeholder' => 'Select',\n 'value' => ['startDate' => $valueStartDate, 'endDate' => $valueEndDate],\n 'queryParams' => [\n 'startDate' => 'start_date_period',\n 'endDate' => 'end_date_period',\n ],\n 'dependencies' => [],\n 'dependsOn' => ['frequency'],\n ];\n }\n\n public function getActivityTypesFieldData(?Team $team = null, array $value = [], array $teamsFilter = []): array\n {\n return $this->activityTypeService->getActivityTypeFieldData(team: $team, value: $value, groupIds: $teamsFilter);\n }\n\n public function getDealStageAtCallFieldData(?Team $team = null, array $value = []): array\n {\n return $this->dealStagesService->getDealStageAtCallFieldData(team: $team, value: $value);\n }\n\n public function getCurrentDealStageFieldData(?Team $team = null, array $value = []): array\n {\n return $this->dealStagesService->getCurrentDealStageFieldData(team: $team, value: $value);\n }\n\n public function getDealValueFieldData(?int $valueMin = null, ?int $valueMax = null): array\n {\n return [\n 'id' => 'deal_value',\n 'label' => 'Deal Value',\n 'inputType' => InputTypeEnum::INTEGER_RANGE,\n 'required' => false,\n 'value' => ['min' => $valueMin, 'max' => $valueMax],\n 'queryParams' => [\n 'min' => 'min_deal_value',\n 'max' => 'max_deal_value',\n ],\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getCallTypeFieldData(bool $conferenceOn = false, bool $dialerOn = false): array\n {\n $value = [];\n $conferenceOn && $value[] = self::CALL_TYPE_CONFERENCE;\n $dialerOn && $value[] = self::CALL_TYPE_DIALER;\n\n return [\n 'id' => 'call_type',\n 'label' => 'Call Type',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'required' => true,\n 'options' => [\n self::CALL_TYPE_CONFERENCE,\n self::CALL_TYPE_DIALER,\n ],\n 'value' => $value,\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getMediaTypeFieldData(?AutomatedReport $report = null): array\n {\n $value = [];\n\n if ($report) {\n $value = $this->transformMediaTypes($report);\n }\n\n return [\n 'id' => 'media_types',\n 'label' => 'Export as',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'required' => true,\n 'options' => self::MEDIA_TYPE_OBJECTS,\n 'value' => $value,\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getCallDurationFieldData(?int $valueMin = null, ?int $valueMax = null): array\n {\n return [\n 'id' => 'call_duration',\n 'label' => 'Call Duration',\n 'inputType' => InputTypeEnum::INTEGER_RANGE,\n 'required' => false,\n 'value' => ['min' => $valueMin, 'max' => $valueMax],\n 'queryParams' => [\n 'min' => 'min_call_duration',\n 'max' => 'max_call_duration',\n ],\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getRecipientsFieldData(?Team $team = null, array $value = []): array\n {\n return $this->recipientsService->getRecipientsFieldData(team: $team, value: $value);\n }\n\n public function getJiminnyRecipientsFieldData(array $value = []): array\n {\n return $this->recipientsService->getJiminnyRecipientsFieldData($value);\n }\n\n public function getAdditionalPromptInputFieldData(?string $value = null): array\n {\n return [\n 'id' => 'additional_prompt_input',\n 'label' => 'Special requirements',\n 'inputType' => InputTypeEnum::TEXTAREA,\n 'required' => false,\n 'placeholder' => 'What should be the focus of the report?',\n 'value' => $value,\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getCustomReportNameFieldData(?string $value = null): array\n {\n return [\n 'id' => 'custom_name',\n 'label' => 'Custom report name',\n 'inputType' => InputTypeEnum::TEXT,\n 'required' => false,\n 'placeholder' => 'Enter custom name',\n 'value' => $value,\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n // data providers\n public function getTeams(): array\n {\n $teams = $this->teamRepository->getTeamsForKiosk(status: Team::STATUS_ACTIVE);\n\n $teamData = [];\n foreach ($teams as $team) {\n if (! $team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {\n continue;\n }\n\n $teamData[] = $this->transformTeam($team);\n }\n\n return $teamData;\n }\n\n public function getTeamGroups(string $teamUuid): array\n {\n $data = [];\n $team = $this->getTeam($teamUuid);\n\n if ($team !== null) {\n $groups = $team->groups()->get();\n\n foreach ($groups as $group) {\n $data[] = [\n 'id' => $group->getUuid(),\n 'name' => $group->getName(),\n ];\n }\n }\n\n return $data;\n }\n\n public function getTeamsGroupsOptions(array $filterTeamUuids = []): array\n {\n $data = [];\n $teams = $this->getTeams();\n\n foreach ($teams as $team) {\n if (! empty($filterTeamUuids) && ! in_array($team['id'], $filterTeamUuids, true)) {\n continue;\n }\n\n $data[] = [\n 'label' => $team['name'],\n 'groups' => $this->getTeamGroups($team['id']),\n ];\n }\n\n return $data;\n }\n\n public function getTeam(string $teamUuid): ?Team\n {\n return $this->teamRepository->idOrUuid($teamUuid);\n }\n\n public function getTeamById(int $teamId): ?Team\n {\n return $this->teamRepository->find($teamId);\n }\n\n public function getGroupsUuids(AutomatedReport $report): array\n {\n $uuids = [];\n $reportGroups = $report->getGroups();\n foreach ($reportGroups as $groupId) {\n if ($group = $this->groupRepository->find($groupId)) {\n $uuids[] = $group->getUuid();\n }\n }\n\n return $uuids;\n }\n\n public function getPlaybookCategoriesUuids(AutomatedReport $report): array\n {\n $uuids = [];\n $playbookCategories = $report->getPlaybookCategories();\n foreach ($playbookCategories as $id) {\n if ($category = $this->playbookCategoryRepository->find($id)) {\n $uuids[] = $category->getUuid();\n }\n }\n\n return $uuids;\n }\n\n public function getDealAtCallStagesUuids(AutomatedReport $report): array\n {\n $uuids = [];\n $reportStages = $report->getDealAtCallStages();\n foreach ($reportStages as $id) {\n if ($stage = $this->stageRepository->find($id)) {\n $uuids[] = $stage->getUuid();\n }\n }\n\n return $uuids;\n }\n\n public function getCurrentDealStagesUuids(AutomatedReport $report): array\n {\n $uuids = [];\n $reportStages = $report->getCurrentDealStages();\n foreach ($reportStages as $id) {\n if ($stage = $this->stageRepository->find($id)) {\n $uuids[] = $stage->getUuid();\n }\n }\n\n return $uuids;\n }\n\n public function getUsersUuids(AutomatedReport $report): array\n {\n return $this->extractUserUuids($report->getRecipients());\n }\n\n public function getJiminnyUsersUuids(AutomatedReport $report): array\n {\n return $this->extractUserUuids($report->getJiminnyRecipients());\n }\n\n /**\n * @param array<string, mixed> $recipients\n */\n private function extractUserUuids(array $recipients): array\n {\n $userIds = $recipients['users'] ?? [];\n\n return collect($userIds)\n ->map(fn ($id) => $this->userRepository->find((int) $id))\n ->filter()\n ->map(fn (UserContract $user) => $user->getUuid())\n ->values()\n ->all();\n }\n\n // get mail data\n public function getRecipientUsers(AutomatedReport $report): array\n {\n return $this->buildRecipientUsers($report->getRecipients());\n }\n\n private function getJiminnyRecipientUsers(AutomatedReport $report): array\n {\n return $this->buildRecipientUsers($report->getJiminnyRecipients());\n }\n\n /**\n * @param array<string, mixed> $recipients\n */\n private function buildRecipientUsers(array $recipients): array\n {\n $userIds = $recipients['users'] ?? [];\n\n return collect($userIds)\n ->map(fn ($id) => $this->userRepository->find((int) $id))\n ->filter()\n ->map(fn (UserContract $user) => [\n 'email' => $user->getEmailAddress(),\n 'name' => $user->getName(),\n 'timezone' => $user->getTimezone()->getName(),\n ])\n ->values()\n ->all();\n }\n\n public function getValidRecipientUsers(AutomatedReport $report, bool $includeJiminny = false): array\n {\n if ($report->isAskJiminnyReport()) {\n $recipients = $this->resolveAskJiminnyRecipients($report);\n } else {\n $recipients = $this->getRecipientUsers($report);\n if ($includeJiminny) {\n $recipients = array_merge($recipients, $this->getJiminnyRecipientUsers($report));\n }\n }\n\n $emails = [];\n\n return array_values(array_filter(\n $recipients,\n static function ($recipient) use (&$emails) {\n if (empty($recipient['email']) || in_array($recipient['email'], $emails, true)) {\n return false;\n }\n $emails[] = $recipient['email'];\n\n return true;\n }\n ));\n }\n\n private function resolveAskJiminnyRecipients(AutomatedReport $report): array\n {\n $recipients = [];\n\n $creator = $report->getCreator();\n if ($creator !== null) {\n $recipients[] = [\n 'email' => $creator->getEmailAddress(),\n 'name' => $creator->getName(),\n 'timezone' => $creator->getTimezone()->getName(),\n ];\n }\n\n return array_merge(\n $recipients,\n $this->buildRecipientUsers($report->getRecipients()),\n $this->getGroupRecipientUsers($report),\n );\n }\n\n private function getGroupRecipientUsers(AutomatedReport $report): array\n {\n $users = [];\n foreach ($report->getGroups() as $groupId) {\n $group = $this->groupRepository->find($groupId);\n if ($group === null) {\n continue;\n }\n foreach ($group->getMembers() as $member) {\n $users[] = [\n 'email' => $member->getEmailAddress(),\n 'name' => $member->getName(),\n 'timezone' => $member->getTimezone()->getName(),\n ];\n }\n }\n\n return $users;\n }\n\n public function getReportTypeName(AutomatedReportResult $report): string\n {\n $type = $report->getReport()->getType();\n\n $getType = $this->transformReportType($type);\n\n return $getType['name'];\n }\n\n public function getReportPeriodName(AutomatedReportResult $report): string\n {\n $from = $report->getFromDate();\n $to = $report->getToDate();\n $frequency = $report->getReport()->getFrequency();\n\n if ($from === null || $to === null) {\n if (! $report->getReport()->isAskJiminnyReport()) {\n $invalidPeriod = $from === null ? 'from' : 'to';\n\n throw new ApplicationException('Report period is invalid: ' . $invalidPeriod);\n }\n\n $period = $this->calculateFromAndToDatePeriod($frequency);\n $from = $period['fromDate'];\n $to = $period['toDate'];\n }\n\n return $this->formatReportPeriodName($frequency, $from, $to);\n }\n\n private function formatReportPeriodName(string $frequency, Carbon $from, Carbon $to): string\n {\n $fromYear = $from->format('Y');\n $toYear = $to->format('Y');\n $differentYears = $fromYear !== $toYear;\n\n switch ($frequency) {\n case self::FREQUENCY_DAILY:\n return $from->format('j M Y');\n\n case self::FREQUENCY_QUARTERLY:\n // 'Jan-Mar 2025' or 'Nov 2024-Jan 2025' if years differ\n $startMonth = $from->format('M');\n $endMonth = $to->copy()->subMonth();\n $endMonthName = $endMonth->format('M');\n $endMonthYear = $endMonth->format('Y');\n\n if ($differentYears) {\n return \"{$startMonth} {$fromYear} - {$endMonthName} {$endMonthYear}\";\n }\n\n return \"{$startMonth} - {$endMonthName} {$toYear}\";\n\n case self::FREQUENCY_MONTHLY:\n // 'May 2025' - monthly reports are always within the same year\n return $from->format('M Y');\n\n case self::FREQUENCY_WEEKLY:\n // '4 - 8 Aug 2025', '27 Oct - 3 Nov 2025', or '28 Dec 2024 - 3 Jan 2025' if years differ\n $startDay = $from->format('j');\n $endDay = $to->format('j');\n $startMonth = $from->format('M');\n $endMonth = $to->format('M');\n\n if ($differentYears) {\n return \"{$startDay} {$startMonth} {$fromYear} - {$endDay} {$endMonth} {$toYear}\";\n }\n\n if ($startMonth !== $endMonth) {\n return \"{$startDay} {$startMonth} - {$endDay} {$endMonth} {$toYear}\";\n }\n\n return \"{$startDay} - {$endDay} {$endMonth} {$toYear}\";\n\n case self::FREQUENCY_ONE_OFF:\n // '2 May-31 May 2025' or '15 Dec 2024-15 Jan 2025' if years differ\n $startDay = $from->format('j');\n $startMonth = $from->format('M');\n $endDay = $to->format('j');\n $endMonth = $to->format('M');\n\n // If same month and year, use a format like '2-31 May 2025'\n if ($startMonth === $endMonth && ! $differentYears) {\n return \"{$startDay} - {$endDay} {$startMonth} {$toYear}\";\n }\n\n // If different years, include both years\n if ($differentYears) {\n return \"{$startDay} {$startMonth} {$fromYear} - {$endDay} {$endMonth} {$toYear}\";\n }\n\n // Same year but different months\n return \"{$startDay} {$startMonth} - {$endDay} {$endMonth} {$toYear}\";\n\n default:\n // Default format for unknown frequencies\n return $from->format('j M Y') . ' - ' . $to->format('j M Y');\n }\n }\n\n public function getReportTeamsName(AutomatedReportResult $report): string\n {\n $groups = $report->getGroups();\n\n if (empty($groups)) {\n return 'All';\n }\n\n // Get group names from repository\n $groupNames = [];\n foreach ($groups as $groupId) {\n $group = $this->groupRepository->find($groupId);\n if ($group) {\n $groupNames[] = $group->getName();\n }\n }\n\n if (count($groupNames) === 1) {\n // Single team format\n $teamsName = $groupNames[0];\n } else {\n // Multiple teams format\n $teamsName = implode(', ', $groupNames);\n }\n\n return $teamsName;\n }\n\n public function getReportFileName(AutomatedReportResult $report): string\n {\n $customName = $report->getReport()->getCustomName();\n $periodName = $this->getReportPeriodName($report);\n $filenameSuffix = $this->getFilenameSuffix($report);\n\n if ($customName) {\n if ($filenameSuffix) {\n $customName .= \" {$filenameSuffix}\";\n }\n\n return $this->sanitizeFileName(\"{$customName} - {$periodName}\");\n }\n\n $baseName = $this->getReportTypeName($report);\n\n if ($filenameSuffix) {\n $baseName .= \" {$filenameSuffix}\";\n }\n\n return $this->sanitizeFileName(\"{$baseName} - {$periodName} - {$this->getReportTeamsName($report)}\");\n }\n\n public function getReportFileNameWithExtension(AutomatedReportResult $result): string\n {\n $extension = $this->getMediaTypeMetadata($result)['extension'];\n\n return $this->getReportFileName($result) . '.' . $extension;\n }\n\n public function sanitizeFileName(string $fileName): string\n {\n return str_replace(['/', '\\\\'], '-', $fileName);\n }\n\n public function isUserRecipientOfReport(User $user, AutomatedReport $report): bool\n {\n $recipients = array_map('intval', $report->getRecipients()['users'] ?? []);\n\n return in_array($user->getId(), $recipients);\n }\n\n public function transformReportResults(Collection $automatedReportResults): array\n {\n $data = [];\n foreach ($automatedReportResults as $automatedReportResult) {\n /** @var AutomatedReportResult $automatedReportResult */\n\n $report = $automatedReportResult->getReport();\n\n $createdBy = $report->getCreator();\n $creator = [\n 'id' => $createdBy?->getUuid(),\n 'name' => $createdBy?->getName(),\n 'email' => $createdBy?->getEmailAddress(),\n 'photoUrl' => $createdBy?->getPhotoUrl(),\n ];\n\n $data[] = [\n 'id' => $automatedReportResult->getUuid(),\n 'name' => $automatedReportResult->getName(),\n 'frequency' => $this->transformFrequency($report->getFrequency()),\n 'recipients' => [\n ...array_values($this->transformGroups(team: $report->getTeam(), groupsIds: $report->getGroups())),\n ...array_values($this->transformRecipients($report->getRecipients())),\n ],\n 'report_type' => $this->transformReportType($report->getType()),\n 'media_type' => $automatedReportResult->getMediaType(),\n 'downloadUrl' => $this->generateReportResultDownloadUrl($automatedReportResult),\n 'viewUrl' => $this->generateReportResultViewUrl($automatedReportResult),\n 'generated_at' => $automatedReportResult->getGeneratedAt()?->toIso8601String(),\n 'creator' => $creator,\n ];\n }\n\n return $data;\n }\n\n public function hasCallTypeConference(AutomatedReport $report): bool\n {\n return in_array(self::CALL_TYPE_CONFERENCE['id'], $report->getCallTypes(), true);\n }\n\n public function hasCallTypeDialer(AutomatedReport $report): bool\n {\n return in_array(self::CALL_TYPE_DIALER['id'], $report->getCallTypes(), true);\n }\n\n // transformers\n private function transformTeam(Team $team): array\n {\n if (! $team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {\n return [];\n }\n\n return [\n 'id' => $team->getUuid(),\n 'name' => $team->getName(),\n ];\n }\n\n private function transformReportFullView(AutomatedReport $report): array\n {\n $base = $this->transformReportBase($report);\n\n return $report->getType() === self::TYPE_ASK_JIMINNY\n ? $base + $this->transformAskJiminnyFields($report)\n : $base + $this->transformStandardReportFields($report);\n }\n\n private function transformReportBase(AutomatedReport $report): array\n {\n return [\n 'id' => $report->getUuid(),\n 'organization' => $this->transformOrganization(team: $report->getTeam()),\n 'report_type' => $this->transformReportType($report->getType()),\n 'frequency' => $this->transformFrequency($report->getFrequency()),\n ];\n }\n\n private function transformStandardReportFields(AutomatedReport $report): array\n {\n $team = $report->getTeam();\n\n return [\n 'report_enabled' => $report->getStatus(),\n 'start_date_period' => $report->getFrom()?->format('Y-m-d H:i:s'),\n 'end_date_period' => $report->getTo()?->format('Y-m-d H:i:s'),\n 'deal_value_min' => $report->getDealValueMin(),\n 'deal_value_max' => $report->getDealValueMax(),\n 'call_types' => $this->transformCallType($report->getCallTypes()),\n 'media_types' => $this->transformMediaTypes($report),\n 'call_duration_min' => $this->transformDurationToMinutes($report->getCallDurationMin()),\n 'call_duration_max' => $this->transformDurationToMinutes($report->getCallDurationMax()),\n 'teams' => $this->transformGroups(team: $team, groupsIds: $report->getGroups()),\n 'deal_at_call_stages' => $this->transformStages(team: $team, stagesIds: $report->getDealAtCallStages()),\n 'current_deal_stages' => $this->transformStages(team: $team, stagesIds: $report->getCurrentDealStages()),\n 'recipients' => $this->transformRecipients($report->getRecipients()),\n 'created_by' => $this->transformCreator($report->getCreator()),\n 'additional_prompt_input' => $report->getAdditionalPromptInput(),\n 'custom_name' => $report->getCustomName(),\n 'created_at' => $report->getCreatedAt()->format('Y-m-d H:i:s'),\n 'updated_at' => $report->getUpdatedAt()->format('Y-m-d H:i:s'),\n 'deleted_at' => $report->getDeletedAt()?->format('Y-m-d H:i:s'),\n ];\n }\n\n private function transformAskJiminnyFields(AutomatedReport $report): array\n {\n $team = $report->getTeam();\n $creatorId = $report->getAttribute('created_by');\n $explicitUserIds = array_values(array_filter(\n $report->getRecipients()['users'] ?? [],\n static fn ($id) => $id !== $creatorId\n ));\n\n return [\n 'report_name' => $report->getCustomName(),\n 'enabled' => $report->getStatus(),\n 'share_teams' => $this->transformGroups(team: $team, groupsIds: $report->getGroups()),\n 'share_users' => $this->transformRecipients(['users' => $explicitUserIds]),\n 'saved_search' => $this->transformSafeSearch($report->getSavedSearch()),\n 'ask_jiminny_prompt' => $this->transformAskJiminnyPrompt($report->getAskAnythingPrompt()),\n 'expires_on' => $report->getExpiresAt()?->format('Y-m-d'),\n ];\n }\n\n private function transformOrganization(?Team $team): array\n {\n return [\n 'id' => $team?->getUuid(),\n 'name' => $team?->getName(),\n ];\n }\n\n private function transformReportType(string $type): array\n {\n foreach (self::ALL_TYPES as $typeItem) {\n if ($typeItem['id'] === $type) {\n return $typeItem;\n }\n }\n\n return [];\n }\n\n private function transformCallType(array $types): array\n {\n $result = [];\n $callTypes = [self::CALL_TYPE_CONFERENCE, self::CALL_TYPE_DIALER];\n\n foreach ($types as $type) {\n foreach ($callTypes as $callTypeItem) {\n if ($callTypeItem['id'] === $type) {\n $result[] = $callTypeItem;\n\n break;\n }\n }\n }\n\n return $result;\n }\n\n private function transformMediaTypes(AutomatedReport $report): array\n {\n $values = [];\n\n foreach ($report->getMediaTypes() as $mediaType) {\n if (! in_array($mediaType, self::MEDIA_TYPES, true)) {\n continue;\n }\n\n $values[] = match ($mediaType) {\n self::MEDIA_TYPE_PDF => self::MEDIA_TYPE_OBJECT_PDF,\n self::MEDIA_TYPE_PODCAST => self::MEDIA_TYPE_OBJECT_PODCAST,\n };\n }\n\n return $values;\n }\n\n private function transformFrequency(string $frequency): array\n {\n foreach (self::ALL_FREQUENCIES as $frequencyItem) {\n if ($frequencyItem['id'] === $frequency) {\n return $frequencyItem;\n }\n }\n\n return [];\n }\n\n public function transformDurationToMinutes(?int $duration): ?int\n {\n if (! $duration) {\n return null;\n }\n\n return (int) ($duration / 60);\n }\n\n private function transformGroups(?Team $team, array $groupsIds): array\n {\n if (empty($groupsIds) || ! $team) {\n return [];\n }\n\n $data = [];\n foreach ($groupsIds as $groupId) {\n $group = $team->groups()->where('id', $groupId)->first();\n\n if ($group) {\n $data[] = [\n 'id' => $group->getUuid(),\n 'name' => $group->getName(),\n 'photoUrl' => $group->getPhotoUrl(),\n ];\n }\n }\n\n return $data;\n }\n\n private function transformStages(?Team $team, array $stagesIds): array\n {\n if (empty($stagesIds) || ! $team) {\n return [];\n }\n\n $data = [];\n foreach ($stagesIds as $stageId) {\n $stage = $team->stages()->where('id', $stageId)->first();\n\n if ($stage) {\n $data[] = [\n 'id' => $stage->getUuid(),\n 'name' => $stage->getName(),\n ];\n }\n }\n\n return $data;\n }\n\n private function transformRecipients(array $recipients): array\n {\n $users = [];\n foreach ($recipients['users'] ?? [] as $userId) {\n $users[] = $this->transformUser($userId);\n }\n\n return $users;\n }\n\n private function transformCreator(?User $user): ?array\n {\n if ($user === null) {\n return null;\n }\n\n return $this->transformUser($user->getId());\n }\n\n private function transformAskJiminnyPrompt(?AskAnythingPrompt $prompt): ?array\n {\n if ($prompt === null) {\n return null;\n }\n\n return [\n 'id' => $prompt->getUuid(),\n 'name' => $prompt->getTitle(),\n ];\n }\n\n private function transformSafeSearch(?Search $search): ?array\n {\n if ($search === null) {\n return null;\n }\n\n return [\n 'id' => $search->getUuid(),\n 'name' => $search->getName(),\n ];\n }\n\n private function transformUser(int $userId): array\n {\n /* @var ?User $user */\n $user = $this->userRepository->find($userId);\n\n return [\n 'id' => $user?->getUuid(),\n 'name' => $user?->getName(),\n 'email' => $user?->getEmailAddress(),\n 'photoUrl' => $user?->getPhotoUrl(),\n ];\n }\n\n public function create(array $data): array\n {\n $validatedData = $this->validateAndTransformData($data);\n $validatedData['created_by'] = auth()->id();\n\n $automatedReport = $this->automatedReportsRepository->create($validatedData);\n\n $this->generateOneOffReport($automatedReport);\n\n return $this->transformReportFullView($automatedReport);\n }\n\n public function update(string $uuid, array $data): array\n {\n $validatedData = $this->validateAndTransformData($data);\n $report = $this->automatedReportsRepository->findByUuid($uuid);\n\n if (! $report) {\n throw new InvalidArgumentException('Report not found');\n }\n\n $oldCustomName = $report->getCustomName();\n\n $automatedReport = $this->automatedReportsRepository->update($report, $validatedData);\n\n if ($oldCustomName !== $automatedReport->getCustomName()) {\n $this->updateResultNames($automatedReport);\n }\n\n $this->generateOneOffReport($automatedReport);\n\n return $this->transformReportFullView($automatedReport);\n }\n\n /**\n * Create an Ask Jiminny report.\n */\n public function createAskJiminnyReport(array $data, User $creator): array\n {\n $validatedData = $this->validateAskJiminnyReportData($data, $creator);\n $validatedData['created_by'] = $creator->getId();\n\n $automatedReport = $this->automatedReportsRepository->create($validatedData);\n\n return $this->transformReportFullView($automatedReport);\n }\n\n /**\n * Update an Ask Jiminny report.\n */\n public function updateAskJiminnyReport(AutomatedReport $report, array $data, User $user): array\n {\n if (! $report->isAskJiminnyReport()) {\n throw new InvalidArgumentException('Report is not an Ask Jiminny report');\n }\n\n $validatedData = $this->validateAskJiminnyReportData($data, $user);\n\n $oldCustomName = $report->getCustomName();\n\n $automatedReport = $this->automatedReportsRepository->update($report, $validatedData);\n\n if ($oldCustomName !== $automatedReport->getCustomName()) {\n $this->updateResultNames($automatedReport);\n }\n\n return $this->transformReportFullView($automatedReport);\n }\n\n public function updateAskJiminnyReportStatus(AutomatedReport $report, bool $status): array\n {\n $this->automatedReportsRepository->update($report, ['status' => $status]);\n\n return $this->transformReportFullView($report->fresh());\n }\n\n /**\n * Validate and transform data for Ask Jiminny reports.\n */\n private function validateAskJiminnyReportData(array $data, User $user): array\n {\n // Validate name\n $name = trim($data['report_name'] ?? '');\n if (empty($name)) {\n throw new InvalidArgumentException('Report name is required');\n }\n if (mb_strlen($name) > 50) {\n throw new InvalidArgumentException('Report name must be 50 characters or less');\n }\n\n // Validate frequency (only daily, weekly, monthly for Ask Jiminny)\n $frequency = $data['frequency'] ?? null;\n $askJiminnyFrequencies = [self::FREQUENCY_DAILY, self::FREQUENCY_WEEKLY, self::FREQUENCY_MONTHLY];\n if (! in_array($frequency, $askJiminnyFrequencies, true)) {\n throw new InvalidArgumentException('Frequency must be daily, weekly, or monthly');\n }\n\n // Validate expiration date\n $expiresAt = $data['expires_on'] ?? null;\n if (empty($expiresAt)) {\n throw new InvalidArgumentException('Expiration date is required');\n }\n\n try {\n $expiresAtDate = Carbon::parse($expiresAt);\n } catch (InvalidFormatException $e) {\n throw new InvalidArgumentException('Expiration date format is invalid');\n }\n $maxExpiration = Carbon::now()->addYear();\n if ($expiresAtDate->gt($maxExpiration)) {\n throw new InvalidArgumentException('Expiration date cannot be more than 1 year from now');\n }\n if ($expiresAtDate->isPast()) {\n throw new InvalidArgumentException('Expiration date cannot be in the past');\n }\n\n // Validate saved search\n $activitySearchId = $data['saved_search'] ?? null;\n if (empty($activitySearchId)) {\n throw new InvalidArgumentException('Saved search is required');\n }\n $savedSearch = $this->activitySearchRepository->findByUuidAndUser($activitySearchId, $user);\n if (! $savedSearch) {\n throw new InvalidArgumentException('Saved search not found or does not belong to you');\n }\n\n // Validate saved prompt\n $askAnythingPromptId = $data['ask_jiminny_prompt'] ?? null;\n if (empty($askAnythingPromptId)) {\n throw new InvalidArgumentException('Ask Jiminny prompt is required');\n }\n $prompt = $this->askAnythingRepository->getPromptByUuid($askAnythingPromptId);\n if (! $prompt) {\n throw new InvalidArgumentException('Ask Jiminny prompt not found');\n }\n\n // Validate status\n $status = $data['enabled'] ?? false;\n\n $recipientUserIds = [$user->getId()];\n\n if (! empty($data['share_users'])) {\n $sharedUserIds = $this->validateAndGetUserIdsByTeam(\n $user->team,\n (array) $data['share_users']\n );\n $recipientUserIds = array_merge($recipientUserIds, $sharedUserIds);\n }\n\n $sharedGroupIds = [];\n if (! empty($data['share_teams'])) {\n $sharedGroupIds = $this->validateAndGetGroupIds($user->team, (array) $data['share_teams']);\n }\n\n $recipientUserIds = array_values(array_unique($recipientUserIds));\n\n return [\n 'team_id' => $user->getTeamId(),\n 'type' => self::TYPE_ASK_JIMINNY,\n 'status' => (bool) $status,\n 'frequency' => $frequency,\n 'custom_name' => $name,\n 'activity_search_id' => $savedSearch->getId(),\n 'ask_anything_prompt_id' => $prompt->getId(),\n 'expires_at' => $expiresAtDate->toDateString(),\n 'media_types' => [self::MEDIA_TYPE_PDF],\n 'call_types' => [],\n 'recipients' => ['users' => $recipientUserIds],\n 'groups' => $sharedGroupIds,\n ];\n }\n\n public static function getAskJiminnyFrequencies(): array\n {\n return array_map(static function ($frequency) {\n return $frequency['id'];\n }, self::ASK_JIMINNY_FREQUENCIES);\n }\n\n public function getAskJiminnyReportFilters(User $user): array\n {\n $savedSearches = $this->activitySearchRepository->findByUserOrderedByName($user)\n ->map(fn (Search $search) => [\n 'id' => $search->getUuid(),\n 'name' => $search->getName(),\n ])\n ->values()->all();\n\n $prompts = collect(\n $this->askAnythingPromptService->get($user, AskAnythingPromptTarget::on_demand)\n )->map(fn (AskAnythingPromptDto $prompt) => [\n 'id' => $prompt->id,\n 'name' => $prompt->title,\n ])->values()->all();\n\n return [\n [\n 'id' => 'prompt',\n 'label' => 'Prompt',\n 'options' => $prompts,\n ],\n [\n 'id' => 'saved_search',\n 'label' => 'Saved Search',\n 'options' => $savedSearches,\n ],\n ];\n }\n\n public function getAskJiminnyReportFormData(User $user, ?AutomatedReport $report = null): array\n {\n $team = $user->getTeam();\n $userTimezone = $user->getTimezone();\n\n $savedSearches = $this->activitySearchRepository->findByUserOrderedByName($user)\n ->map(fn (Search $search) => [\n 'id' => $search->getUuid(),\n 'name' => $search->getName(),\n ])\n ->values()->all();\n\n $prompts = collect(\n $this->askAnythingPromptService->get($user, AskAnythingPromptTarget::on_demand)\n )->map(fn (AskAnythingPromptDto $prompt) => [\n 'id' => $prompt->id,\n 'name' => $prompt->title,\n ])->values()->all();\n\n $teamGroups = $this->groupRepository->getAllByTeam($team)->map(fn ($group) => [\n 'id' => $group->getUuid(),\n 'name' => $group->getName(),\n ])->values()->all();\n\n $shareUsers = $this->recipientsService->getRecipientsFieldData(team: $team)['options'] ?? [];\n\n $sharedTeamsValue = [];\n $sharedUsersValue = [];\n if ($report) {\n $sharedTeamsValue = $this->transformGroups($team, $report->getGroups());\n\n $recipientUserIds = $report->getRecipients()['users'] ?? [];\n $creatorId = $report->getAttribute('created_by');\n $sharedUserIds = array_values(array_filter(\n $recipientUserIds,\n static fn ($id) => $id !== $creatorId\n ));\n $sharedUsersValue = collect($sharedUserIds)\n ->map(fn ($id) => $this->userRepository->find((int) $id))\n ->filter()\n ->map(fn (User $u) => [\n 'id' => $u->getUuid(),\n 'name' => $u->getName(),\n ])\n ->values()\n ->all();\n }\n\n return [\n 'fields' => [\n [\n 'id' => 'enabled',\n 'inputType' => InputTypeEnum::TOGGLE,\n 'label' => '',\n 'value' => $report?->getStatus() ?? false,\n ],\n [\n 'id' => 'report_name',\n 'inputType' => InputTypeEnum::TEXT,\n 'label' => 'Name',\n 'placeholder' => 'Enter name',\n 'required' => true,\n 'validation' => ['maxLength' => 50],\n 'value' => $report?->getCustomName() ?? '',\n ],\n [\n 'id' => 'frequency',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'label' => 'Frequency',\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => self::ASK_JIMINNY_FREQUENCIES,\n 'value' => $report ? $this->transformFrequency($report->getFrequency()) : null,\n ],\n [\n 'id' => 'expires_on',\n 'inputType' => InputTypeEnum::DATE,\n 'label' => 'Expires on',\n 'required' => true,\n 'placeholder' => 'Select',\n 'validation' => [\n 'minDate' => now($userTimezone)->toDateString(),\n 'maxDate' => now($userTimezone)->addYear()->toDateString(),\n ],\n 'value' => $report?->getExpiresAt()?->toDateString(),\n ],\n [\n 'id' => 'share_teams',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'label' => 'Team',\n 'required' => false,\n 'placeholder' => 'Select',\n 'options' => $teamGroups,\n 'value' => $sharedTeamsValue,\n ],\n [\n 'id' => 'share_users',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'label' => 'Team member',\n 'required' => false,\n 'placeholder' => 'Select',\n 'groupLabelKey' => 'label',\n 'groupValuesKey' => 'users',\n 'optionLabelKey' => 'name',\n 'optionValueKey' => 'id',\n 'options' => $shareUsers,\n 'value' => $sharedUsersValue,\n ],\n [\n 'id' => 'saved_search',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'label' => 'Saved search',\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => $savedSearches,\n 'value' => $report && $report->getSavedSearch() ? [\n 'id' => $report->getSavedSearch()->getUuid(),\n 'name' => $report->getSavedSearch()->getName(),\n ] : null,\n ],\n [\n 'id' => 'ask_jiminny_prompt',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'label' => 'Ask Jiminny prompt',\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => $prompts,\n 'value' => $report && $report->getAskAnythingPrompt() ? [\n 'id' => $report->getAskAnythingPrompt()->getUuid(),\n 'name' => $report->getAskAnythingPrompt()->getTitle(),\n ] : null,\n ],\n ],\n ];\n }\n\n private function updateResultNames(AutomatedReport $automatedReport): void\n {\n $results = $this->automatedReportsRepository->getResultsByReport($automatedReport);\n\n foreach ($results as $result) {\n $result->update(['name' => $this->getReportFileName($result)]);\n }\n }\n\n public function updateStatus(string $uuid, array $data): array\n {\n $automatedReport = $this->automatedReportsRepository->findByUuid($uuid);\n\n if (! $automatedReport) {\n throw new ModelNotFoundException('Report not found');\n }\n\n $status = $this->validateReportStatus($data['report_enabled'] ?? null);\n $automatedReport->update([\n 'status' => $status,\n ]);\n\n $this->generateOneOffReport($automatedReport);\n\n return $this->transformReportFullView($automatedReport);\n }\n\n private function generateOneOffReport(AutomatedReport $automatedReport): void\n {\n // the scheduler handles all the other frequency types\n if ($automatedReport->getStatus() === false || $automatedReport->getFrequency() !== self::FREQUENCY_ONE_OFF) {\n return;\n }\n\n $this->dispatcher->dispatch(new RequestGenerateReportJob($automatedReport->getUuid()));\n }\n\n public function getReport(string $uuid): AutomatedReport\n {\n $automatedReport = $this->automatedReportsRepository->findByUuid($uuid);\n\n if (! $automatedReport) {\n throw new ModelNotFoundException('Report not found');\n }\n\n return $automatedReport;\n }\n\n public function get(string $uuid): array\n {\n $automatedReport = $this->getReport($uuid);\n\n return $this->transformReportFullView($automatedReport);\n }\n\n public function list(string $sortColumn = 'created_at', string $sortDirection = 'desc'): array\n {\n $results = [];\n $collection = $this->automatedReportsRepository->getAllStandardReports($sortColumn, $sortDirection);\n\n /** @var AutomatedReport $report */\n foreach ($collection as $report) {\n $results[] = $this->transformReportFullView($report);\n }\n\n return ['data' => $results];\n }\n\n public function listAskJiminnyReports(\n User $user,\n string $sortColumn = 'created_at',\n string $sortDirection = 'desc'\n ): array {\n $results = [];\n $collection = $this->automatedReportsRepository->getAskJiminnyReportsByUser($user, $sortColumn, $sortDirection);\n\n /** @var AutomatedReport $report */\n foreach ($collection as $report) {\n $results[] = $this->transformReportFullView($report);\n }\n\n return ['data' => $results];\n }\n\n public function delete(string $uuid): void\n {\n $automatedReport = $this->automatedReportsRepository->findByUuid($uuid);\n\n if (! $automatedReport) {\n throw new ModelNotFoundException('Report not found');\n }\n\n $automatedReport->delete();\n }\n\n public function createReportResult(AutomatedReport $automatedReport, array $data = []): AutomatedReportResult\n {\n return $this->automatedReportsRepository->createResult(\n array_merge(\n [\n 'report_id' => $automatedReport->getId(),\n 'status' => AutomatedReportResult::STATUS_DEFAULT,\n ],\n $data\n )\n );\n }\n\n public function getReportResult(string $resultUuid): AutomatedReportResult\n {\n $report = $this->automatedReportsRepository->findResultByUuid($resultUuid);\n\n if (! $report) {\n throw new ModelNotFoundException('Report Result not found');\n }\n\n return $report;\n }\n\n public function findChildResult(AutomatedReportResult $result, string $type): ?AutomatedReportResult\n {\n return $this->automatedReportsRepository->findChildResult($result, $type);\n }\n\n // prophet API calls\n /**\n * @throws ApplicationException\n */\n public function getGenerateReportPayload(AutomatedReport $automatedReport, string $reportResultUuid): array\n {\n $period = $this->calculateFromAndToDate($automatedReport);\n $fromDate = $period['fromDate'];\n $toDate = $period['toDate'];\n\n return [\n 'team_id' => $automatedReport->getTeamId(),\n 'request_id' => $reportResultUuid,\n 'report_type' => $automatedReport->getType(),\n 'media_types' => $automatedReport->getMediaTypes(),\n 'from_date' => $fromDate->startOfDay()->format(DateTimeInterface::RFC3339),\n 'to_date' => $toDate->endOfDay()->format(DateTimeInterface::RFC3339),\n 'group_ids' => $automatedReport->getGroups(),\n 'call_deal_stage' => $automatedReport->getDealAtCallStages(),\n 'current_deal_stage' => $automatedReport->getCurrentDealStages(),\n 'deal_min_value' => $automatedReport->getDealValueMin(),\n 'deal_max_value' => $automatedReport->getDealValueMax(),\n 'call_types' => $automatedReport->getCallTypes(),\n 'call_duration_min_seconds' => $automatedReport->getCallDurationMin(),\n 'call_duration_max_seconds' => $automatedReport->getCallDurationMax(),\n 'special_requirements' => $automatedReport->getAdditionalPromptInput(),\n 'callback_url' => $this->getCallbackUrl(),\n 'report_period' => $this->formatReportPeriodName(\n $automatedReport->getFrequency(),\n $fromDate,\n $toDate,\n ),\n 'playbook_categories' => $automatedReport->getPlaybookCategories(),\n 'custom_name' => $automatedReport->getCustomName(),\n ];\n }\n\n // $inputPayload - FE payload structure\n public function getActivitiesCountPayload(array $inputPayload): array\n {\n // Use validateAndTransformData to validate and normalize input\n $validatedData = $this->validateAndTransformData($inputPayload);\n $period = $this->calculateFromAndToDatePeriod(\n $validatedData['frequency'],\n Carbon::parse($validatedData['from']),\n Carbon::parse($validatedData['to']),\n );\n $fromDate = $period['fromDate'];\n $toDate = $period['toDate'];\n\n // Create payload similar to getGenerateReportPayload\n return [\n 'team_id' => $validatedData['team_id'],\n 'group_ids' => $validatedData['groups'] ?? [],\n 'report_type' => $validatedData['type'],\n 'from_date' => $fromDate->format(DateTimeInterface::RFC3339),\n 'to_date' => $toDate->format(DateTimeInterface::RFC3339),\n 'call_deal_stage' => $validatedData['deal_at_call_stages'] ?? [],\n 'current_deal_stage' => $validatedData['current_deal_stages'] ?? [],\n 'deal_min_value' => $validatedData['deal_value_min'] ?? null,\n 'deal_max_value' => $validatedData['deal_value_max'] ?? null,\n 'call_types' => $validatedData['call_types'],\n 'call_duration_min_seconds' => $validatedData['call_duration_min'] ?? null,\n 'call_duration_max_seconds' => $validatedData['call_duration_max'] ?? null,\n 'special_requirements' => $validatedData['additional_prompt_input'] ?? null,\n 'playbook_categories' => $validatedData['playbook_categories'] ?? [],\n 'request_id' => null,\n 'callback_url' => null,\n ];\n }\n\n public function shouldSendReport(array $users, ?CarbonInterface $generatedAt = null): bool\n {\n if (empty($users)) {\n return false;\n }\n\n $earliestTz = collect($users)\n ->mapWithKeys(function (array $user) {\n $tz = new DateTimeZone($user['timezone']);\n $nowUtc = new DateTime('now', new DateTimeZone('UTC'));\n $offset = $tz->getOffset($nowUtc);\n\n return [$user['timezone'] => $offset];\n })\n ->sortDesc()\n ->keys()\n ->first();\n\n $now = Carbon::now($earliestTz);\n $isScheduledTime = (int) $now->format('H') === self::SENT_REPORT_AT_HOURS;\n\n if ($isScheduledTime) {\n return true;\n }\n\n return $this->hasPassedScheduledTime($generatedAt, $earliestTz);\n }\n\n public function hasPassedScheduledTime(?CarbonInterface $generatedAt, string $timezone): bool\n {\n if ($generatedAt === null) {\n return false;\n }\n\n $now = Carbon::now($timezone);\n $scheduledTime = $now->copy()->setTime(self::SENT_REPORT_AT_HOURS, 0, 0);\n\n if ($now->hour < self::SENT_REPORT_AT_HOURS) {\n $scheduledTime = $scheduledTime->subDay();\n }\n\n $scheduledTimeUtc = $scheduledTime->copy()->utc();\n $generatedAtUtc = $generatedAt->copy()->utc();\n $nowUtc = $now->copy()->utc();\n\n return $generatedAtUtc->lt($scheduledTimeUtc) && $nowUtc->gt($scheduledTimeUtc);\n }\n\n public function calculateFromAndToDatePeriod(\n string $frequency,\n ?Carbon $fromDate = null,\n ?Carbon $toDate = null\n ): array {\n if ($frequency === self::FREQUENCY_ONE_OFF) {\n return [\n 'fromDate' => $fromDate,\n 'toDate' => $toDate,\n ];\n }\n\n $now = Carbon::now();\n\n return match ($frequency) {\n self::FREQUENCY_DAILY => [\n 'fromDate' => $now->copy()->subDay()->startOfDay(),\n 'toDate' => $now->copy()->subDay()->endOfDay(),\n ],\n self::FREQUENCY_WEEKLY => [\n 'fromDate' => $now->copy()->subWeeks(1)->startOfDay(),\n 'toDate' => $now->copy()->subDay()->endOfDay(),\n ],\n self::FREQUENCY_MONTHLY => [\n 'fromDate' => $now->copy()->subMonths(1)->startOfDay(),\n 'toDate' => $now->copy()->subDay()->endOfDay(),\n ],\n self::FREQUENCY_QUARTERLY => [\n 'fromDate' => $now->copy()->subMonths(3)->startOfDay(),\n 'toDate' => $now->copy()->subDay()->endOfDay(),\n ],\n default => throw new InvalidArgumentException(\"Unsupported frequency: {$frequency}\"),\n };\n }\n\n private function calculateFromAndToDate(AutomatedReport $automatedReport): array\n {\n return $this->calculateFromAndToDatePeriod(\n $automatedReport->getFrequency(),\n $automatedReport->getFrom(),\n $automatedReport->getTo()\n );\n }\n\n public function getAskJiminnyGenerateReportPayload(\n AutomatedReport $automatedReport,\n AutomatedReportResult $reportResult,\n array $activityIds,\n ): array {\n return [\n 'user_question' => $automatedReport->getAskAnythingPrompt()?->getContent(),\n 'call_ids' => array_map('strval', $activityIds),\n 'team_id' => $automatedReport->getTeamId(),\n 'request_id' => $reportResult->getUuid(),\n 'callback_url' => $this->getCallbackUrl(),\n 'report_period' => $this->getReportPeriodName($reportResult),\n 'report_name' => $automatedReport->getCustomName(),\n ];\n }\n\n private function getCallbackUrl(): string\n {\n return $this->webhookService->route('jiminny.webhook.reports.ready');\n }\n\n /**\n * Validate and transform payload data for automated reports\n *\n * @param array $data\n *\n * @throws InvalidArgumentException\n *\n * @return array\n */\n private function validateAndTransformData(array $data): array\n {\n // Validate organization (team) and check feature\n $team = $this->validateOrganization($data['organization'] ?? null);\n\n $status = $this->validateReportStatus($data['report_enabled'] ?? null);\n $type = $this->validateReportType($data['report_type'] ?? null);\n $frequency = $this->validateFrequency($data['frequency'] ?? null);\n $additionalPromptInput = $this->validateAdditionalPromptInput(\n $data['additional_prompt_input'] ?? null\n );\n $customReportName = $this->validateCustomReportName($data['custom_name'] ?? null);\n\n // Prepare data for the database\n $reportData = [\n 'team_id' => $team->getId(),\n 'type' => $type,\n 'status' => $status,\n 'frequency' => $frequency,\n 'additional_prompt_input' => $additionalPromptInput,\n 'custom_name' => $customReportName,\n ];\n\n // Validate deal values\n $reportData = $this->validateDealValues($data, $reportData);\n\n // Validate date range\n $reportData = $this->validateDateRange($data, $reportData, $frequency);\n\n // Validate call durations\n $reportData = $this->validateCallDurations($data, $reportData);\n\n // Validate call types\n $reportData = $this->validateCallTypes($data, $reportData);\n\n // Validate media types\n $reportData = $this->validateMediaTypes($data, $reportData);\n\n // Validate groups\n if (isset($data['teams'])) {\n $reportData['groups'] = $this->validateAndGetGroupIds($team, $data['teams']);\n }\n\n // Validate deal stages\n $reportData = $this->validateDealStages($data, $reportData, $team, $type);\n\n // Validate playbook categories\n $reportData = $this->validatePlaybookCategories($data, $reportData, $team);\n\n // Validate recipients\n $reportData['recipients'] = [\n 'users' => $this->validateAndGetUserIdsByTeam($team, $data['recipients'] ?? []),\n ];\n\n if (isset($data['jiminny_recipients'])) {\n // Validate Jiminny recipients\n $reportData['jiminny_recipients'] = [\n 'users' => $this->validateAndGetJiminnyUserIds((array) $data['jiminny_recipients']),\n ];\n }\n\n return $reportData;\n }\n\n private function validateDealValues(array $data, array $reportData): array\n {\n if (isset($data['min_deal_value'])) {\n $reportData['deal_value_min'] = (int) $data['min_deal_value'];\n\n if ($reportData['deal_value_min'] > 4294967295 || $reportData['deal_value_min'] < 0) {\n throw new InvalidArgumentException('Min deal value should be between 0 and 4294967295');\n }\n }\n\n if (isset($data['max_deal_value'])) {\n $reportData['deal_value_max'] = (int) $data['max_deal_value'];\n\n if ($reportData['deal_value_max'] > 4294967295 || $reportData['deal_value_max'] < 0) {\n throw new InvalidArgumentException('Max deal value should be between 0 and 4294967295');\n }\n }\n\n if (isset($data['min_deal_value'], $data['max_deal_value'])\n && $data['min_deal_value'] > $data['max_deal_value']\n ) {\n throw new InvalidArgumentException('Min deal value cannot be greater than max deal value');\n }\n\n return $reportData;\n }\n\n private function validateDateRange(array $data, array $reportData, string $frequency): array\n {\n // Set date range only for one_off frequency\n if ($frequency === 'one_off') {\n if (isset($data['start_date_period'])) {\n $reportData['from'] = $this->parseDate($data['start_date_period']);\n }\n\n if (isset($data['end_date_period'])) {\n $reportData['to'] = $this->parseDate($data['end_date_period']);\n }\n\n if (empty($reportData['from']) || empty($reportData['to'])) {\n throw new InvalidArgumentException(\n 'Start date and end date are required for one_off frequency'\n );\n }\n } else {\n $reportData['from'] = null;\n $reportData['to'] = null;\n }\n\n return $reportData;\n }\n\n private function validateCallDurations(array $data, array $reportData): array\n {\n // Convert call durations from minutes to seconds\n if (isset($data['min_call_duration'])) {\n $reportData['call_duration_min'] = (int) $data['min_call_duration'] * 60;\n\n if ($reportData['call_duration_min'] > 4294967295 || $reportData['call_duration_min'] < 0) {\n throw new InvalidArgumentException('Min call duration should be between 0 and 4294967295');\n }\n }\n\n if (isset($data['max_call_duration'])) {\n $reportData['call_duration_max'] = (int) $data['max_call_duration'] * 60;\n\n if ($reportData['call_duration_max'] > 4294967295 || $reportData['call_duration_max'] < 0) {\n throw new InvalidArgumentException('Max call duration should be between 0 and 4294967295');\n }\n }\n\n return $reportData;\n }\n\n private function validateCallTypes(array $data, array $reportData): array\n {\n // Set call types\n $reportData['call_types'] = $data['call_type'] ?? [];\n if (empty($reportData['call_types'])) {\n $reportData['call_types'] = self::getCallTypes();\n }\n\n foreach ($reportData['call_types'] as $callType) {\n if (! in_array($callType, self::getCallTypes(), true)) {\n throw new InvalidArgumentException(sprintf('Call type %s is invalid', $callType));\n }\n }\n\n return $reportData;\n }\n\n private function validateMediaTypes(array $data, array $reportData): array\n {\n // Set media types from input data\n $reportData['media_types'] = $data['media_types'] ?? [];\n\n if (empty($reportData['media_types'])) {\n throw new InvalidArgumentException('Media types are required');\n }\n\n foreach ($reportData['media_types'] as $mediaType) {\n if (! in_array($mediaType, self::MEDIA_TYPES, true)) {\n throw new InvalidArgumentException(sprintf('Media type %s is invalid', $mediaType));\n }\n }\n\n return $reportData;\n }\n\n private function validateDealStages(array $data, array $reportData, Team $team, string $reportType): array\n {\n // Validate and set deal stages\n if (isset($data['deal_stage_at_call'])) {\n $reportData['deal_at_call_stages'] =\n $this->validateAndGetDealStageIds($team, $data['deal_stage_at_call'], 'Deal stage at call');\n }\n\n if (isset($data['current_deal_stage'])) {\n $reportData['current_deal_stages'] =\n $this->validateAndGetDealStageIds($team, $data['current_deal_stage'], 'Current deal stage');\n }\n\n // Ensure current_deal_stage is not provided for loss_analysis report type\n if ($reportType === self::TYPE_LOSS_ANALYSIS && ! empty($data['current_deal_stage'])) {\n throw new InvalidArgumentException('Current deal stage is not applicable for Loss Analysis reports');\n }\n\n return $reportData;\n }\n\n // transform uuid to id\n private function validatePlaybookCategories(array $data, array $reportData, Team $team): array\n {\n $key = 'playbook_categories';\n\n if (isset($data[$key])) {\n $payloadIds = $data[$key];\n $ids = [];\n\n foreach ($payloadIds as $uuid) {\n $uuid = (string) $uuid;\n\n try {\n $playbookCategory = $this->playbookCategoryRepository->findByUuid($uuid);\n } catch (Throwable $throwable) {\n Log::error(__METHOD__ . ' ' . $throwable->getMessage());\n\n throw new InvalidArgumentException(sprintf('Playbook category %s not found', $uuid));\n }\n\n if (! $playbookCategory) {\n throw new InvalidArgumentException(sprintf('Playbook category %s not found', $uuid));\n }\n\n if (! $playbookCategory->hasPlaybook()) {\n throw new InvalidArgumentException(sprintf('Playbook category %s has no playbook', $uuid));\n }\n\n if ($playbookCategory->getPlaybook()->getTeamId() !== $team->getId()) {\n throw new InvalidArgumentException(\n sprintf('Playbook category %s not found for team %s', $uuid, $team->getUuid())\n );\n }\n\n $ids[] = $playbookCategory->getId();\n }\n\n $reportData[$key] = $ids;\n }\n\n return $reportData;\n }\n\n private function validateReportStatus($status): bool\n {\n if (! in_array($status, [true, false], true)) {\n throw new InvalidArgumentException('Report status is invalid');\n }\n\n return $status;\n }\n\n private function validateReportType($type): string\n {\n if (! in_array($type, self::getTypes(), true)) {\n throw new InvalidArgumentException(sprintf('Report type is invalid: %s', $type));\n }\n\n return $type;\n }\n\n private function validateFrequency($frequency): string\n {\n if (! in_array($frequency, self::getFrequencies(), true)) {\n throw new InvalidArgumentException('Frequency is invalid');\n }\n\n return $frequency;\n }\n\n private function validateAdditionalPromptInput(?string $additionalPromptInput): ?string\n {\n if ($additionalPromptInput && strlen($additionalPromptInput) > 5000) {\n throw new InvalidArgumentException('Additional Prompt Input should be less than 5000 characters');\n }\n\n return $additionalPromptInput;\n }\n\n private function validateCustomReportName(?string $customReportName): ?string\n {\n if ($customReportName === null || $customReportName === '') {\n return null;\n }\n\n if (strlen($customReportName) > 70) {\n throw new InvalidArgumentException('Custom report name should be less than 70 characters');\n }\n\n return $customReportName;\n }\n\n private function validateOrganization(?string $organizationUuid): Team\n {\n if (! $organizationUuid) {\n throw new InvalidArgumentException('Organization is required');\n }\n\n $team = $this->teamRepository->idOrUuid($organizationUuid);\n\n if (! $team) {\n throw new InvalidArgumentException('Organization not found');\n }\n\n if (! $team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {\n throw new InvalidArgumentException('Organization does not have the Automated Reports feature');\n }\n\n return $team;\n }\n\n private function validateAndGetGroupIds(Team $team, array $teamUuids): array\n {\n $groupIds = [];\n\n foreach ($teamUuids as $uuid) {\n $group = $this->groupRepository->findByUuid($uuid);\n\n if ($group === null || $group->getTeamId() !== $team->getId()) {\n throw new InvalidArgumentException(\n sprintf('Group %s not found for team %s', $uuid, $team->getUuid())\n );\n }\n\n $groupIds[] = $group->getId();\n\n }\n\n return $groupIds;\n }\n\n private function validateAndGetDealStageIds(Team $team, array $stageUuids, string $propertyLabel): array\n {\n $stageIds = [];\n\n foreach ($stageUuids as $uuid) {\n $stage = $this->stageRepository->findByUuid($uuid);\n\n if ($stage === null || $stage->getTeamId() !== $team->getId()) {\n throw new InvalidArgumentException(\n sprintf('Stage %s not found for team %s for %s', $uuid, $team->getUuid(), $propertyLabel)\n );\n }\n\n $stageIds[] = $stage->getId();\n }\n\n return $stageIds;\n }\n\n private function validateAndGetUserIds(array $userUuids, callable $teamCheck): array\n {\n if (empty($userUuids)) {\n return [];\n }\n\n $userIds = [];\n\n foreach ($userUuids as $uuid) {\n $user = $this->userRepository->findByUuid($uuid);\n\n if (! $user || ! $user->isStatusActive()) {\n throw new InvalidArgumentException(\n sprintf('User %s not found or is not active', $uuid)\n );\n }\n\n if (! $teamCheck($user)) {\n throw new InvalidArgumentException(\n sprintf('User %s does not belong to the allowed team(s)', $uuid)\n );\n }\n\n $userIds[] = $user->getId();\n }\n\n return $userIds;\n }\n\n private function validateAndGetUserIdsByTeam(Team $team, array $userUuids): array\n {\n return $this->validateAndGetUserIds($userUuids, fn ($user) => $user->getTeamId() === $team->getId());\n }\n\n private function validateAndGetJiminnyUserIds(array $userUuids): array\n {\n $allowedTeamIds = config('kiosk.teamIds', []);\n\n return $this->validateAndGetUserIds($userUuids, fn ($user) => in_array($user->getTeamId(), $allowedTeamIds, true));\n }\n\n private function parseDate(string $dateString): string\n {\n return date('Y-m-d H:i:s', strtotime($dateString));\n }\n\n private function generateReportResultViewUrl(AutomatedReportResult $result): string\n {\n $mediaResource = $this->getReportMediaRouteResource($result);\n\n return route('ai-reports.' . $mediaResource . '.view', ['uuid' => $result->getUuid()]);\n }\n\n private function generateReportResultDownloadUrl(AutomatedReportResult $result): string\n {\n $mediaResource = $this->getReportMediaRouteResource($result);\n\n return route('ai-reports.' . $mediaResource . '.download', ['uuid' => $result->getUuid()]);\n }\n\n private function getReportMediaRouteResource(AutomatedReportResult $result): string\n {\n if ($result->getMediaType() === self::MEDIA_TYPE_PDF) {\n return self::PDF_KEY;\n } elseif ($result->getMediaType() === self::MEDIA_TYPE_PODCAST) {\n return self::AUDIO_KEY;\n }\n\n throw new \\InvalidArgumentException('Unknown media type.');\n }\n\n public function getMediaPath(AutomatedReportResult $result): ?string\n {\n $url = match ($result->getMediaType()) {\n self::MEDIA_TYPE_PDF => $result->getPdfUrl(),\n self::MEDIA_TYPE_PODCAST => $result->getPodcastAudioUrl(),\n default => null,\n };\n\n if ($url === null) {\n return null;\n }\n\n $path = parse_url(trim($url, '\"\\''), PHP_URL_PATH);\n\n return $path ?: null;\n }\n\n public function getFilenameSuffix(AutomatedReportResult $result): ?string\n {\n return match ($result->getMediaType()) {\n self::MEDIA_TYPE_PODCAST => 'Podcast',\n default => null,\n };\n }\n\n public function getMailSubjectSuffix(AutomatedReportResult $result): string\n {\n return match ($result->getMediaType()) {\n self::MEDIA_TYPE_PDF => 'report',\n self::MEDIA_TYPE_PODCAST => 'podcast',\n default => '',\n };\n }\n\n public function getMediaTypeMetadata(AutomatedReportResult $result): array\n {\n return match ($result->getMediaType()) {\n self::MEDIA_TYPE_PODCAST => ['extension' => 'mp3', 'mime' => 'audio/mpeg'],\n self::MEDIA_TYPE_PDF => ['extension' => 'pdf', 'mime' => 'application/pdf'],\n default => ['extension' => null, 'mime' => null],\n };\n }\n\n public function deleteS3Files(AutomatedReportResult $result): void\n {\n $teamUuid = $result->getReport()->getTeam()->getUuid();\n $reportUuid = $result->getUuid();\n\n // delete all files for a report uuid no mather of pdf, podcast, or both\n // in case of both - the podcast files are linked to the pdf (parent) uuid\n // pdf and podcast date times should be close\n $path = sprintf('%s/%s/%s', $teamUuid, self::S3_DIR, $reportUuid);\n\n foreach (self::FILE_EXTENSIONS_VARIANTS as $extension) {\n $file = $path . '.' . $extension;\n\n if (Storage::exists($file)) {\n Storage::delete($file);\n Log::info('[Reports] Deleted S3 file', [\n 'path' => $file,\n ]);\n }\n }\n\n foreach (self::FILE_PODCAST_EXTENSIONS_VARIANTS as $extension) {\n $file = $path . '_podcast.' . $extension;\n\n if (Storage::exists($file)) {\n Storage::delete($file);\n Log::info('[Reports] Deleted Podcast S3 file', [\n 'path' => $file,\n ]);\n }\n }\n }\n\n /**\n *\n * @param int|null $teamId Optional team ID to filter results\n *\n * @return Collection<int, int> Collection of team IDs\n */\n public function getTeamIdsWithReportsResults(?int $teamId = null): Collection\n {\n return $this->automatedReportsRepository->getTeamIdsWithReportsResults($teamId);\n }\n\n /**\n * Core delete logic for report results using a query\n *\n * @param Builder $query\n * @param array $logContext\n *\n * @return int\n */\n private function deleteReportResultsByQuery(Builder $query, array $logContext = []): int\n {\n $deletedCount = 0;\n\n if ($query->exists()) {\n Log::info(\n 'Run delete report results',\n array_merge(\n $logContext,\n [\n 'service' => 'AutomatedReportsService',\n ]\n )\n );\n\n $query->chunkById(50, function ($results) use (&$deletedCount, $logContext) {\n foreach ($results as $result) {\n $this->deleteReportResult($result);\n $deletedCount++;\n\n Log::info(\n 'Deleted a report result',\n array_merge(\n $logContext,\n [\n 'result_id' => $result->getId(),\n 'report_id' => $result->getReportId(),\n ]\n )\n );\n }\n });\n }\n\n return $deletedCount;\n }\n\n /**\n * Delete report results for a team by retention period\n *\n * @param Team $team\n * @param CarbonImmutable $retentionDate\n *\n * @return int Number of deleted report results\n */\n public function deleteReportsResultsInRetentionPeriod(Team $team, CarbonImmutable $retentionDate): int\n {\n $reportIds = $this->automatedReportsRepository->getReportIdsByTeam($team);\n\n if ($reportIds->isEmpty()) {\n return 0;\n }\n\n $query = $this->automatedReportsRepository\n ->getReportResultsQueryForRetention($team, $retentionDate);\n\n return $this->deleteReportResultsByQuery($query, [\n 'team_id' => $team->getId(),\n 'retention_date' => $retentionDate->toDateTimeString(),\n ]);\n }\n\n /**\n * Delete ALL report results for a specific automated report\n *\n * @param string $uuid\n *\n * @return int\n */\n public function deleteReportResults(string $uuid): int\n {\n $report = $this->getReport($uuid);\n\n $query = $this->automatedReportsRepository->getResultsByReportQuery($report);\n\n return $this->deleteReportResultsByQuery($query, [\n 'report_uuid' => $uuid,\n 'report_id' => $report->getId(),\n ]);\n }\n\n public function deleteReportResult(AutomatedReportResult $result): void\n {\n $this->deleteS3Files($result);\n\n $result->delete();\n }\n\n /**\n * Get all reports for a specific team\n *\n * @param Team $team\n *\n * @return \\Illuminate\\Database\\Eloquent\\Collection\n */\n public function getTeamReports(Team $team): \\Illuminate\\Database\\Eloquent\\Collection\n {\n return $this->automatedReportsRepository->getReportsByTeam($team);\n }\n\n /**\n * Get all report results for a specific report\n *\n * @param AutomatedReport $report\n *\n * @return \\Illuminate\\Database\\Eloquent\\Collection\n */\n public function getReportResults(AutomatedReport $report): \\Illuminate\\Database\\Eloquent\\Collection\n {\n return $this->automatedReportsRepository->getResultsByReport($report);\n }\n\n public function deleteAllReportResults(AutomatedReport $report): void\n {\n $results = $this->getReportResults($report);\n\n /** @var AutomatedReportResult $result */\n foreach ($results as $result) {\n Log::info('Deleting result', [\n 'report' => $report->getId(),\n 'result' => $result->getId(),\n ]);\n\n $this->deleteReportResult($result);\n }\n }\n\n public function deleteAllData(Team $team): void\n {\n Log::info('Deleting automated report and results for team', [\n 'team' => $team->getId(),\n ]);\n\n $reports = $this->getTeamReports($team);\n\n /** @var AutomatedReport $report */\n foreach ($reports as $report) {\n Log::info('Deleting report', [\n 'team' => $team->getId(),\n 'report' => $report->getId(),\n ]);\n\n $this->deleteAllReportResults($report);\n\n $report->delete();\n }\n }\n}","depth":4,"value":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Services\\Kiosk\\AutomatedReports;\n\nuse Carbon\\CarbonImmutable;\nuse Carbon\\CarbonInterface;\nuse Carbon\\Exceptions\\InvalidFormatException;\nuse DateTime;\nuse DateTimeInterface;\nuse DateTimeZone;\nuse Illuminate\\Contracts\\Bus\\Dispatcher as BusDispatcher;\nuse Illuminate\\Database\\Eloquent\\Builder;\nuse Illuminate\\Support\\Carbon;\nuse Illuminate\\Support\\Collection;\nuse Illuminate\\Support\\Facades\\Log;\nuse Illuminate\\Support\\Facades\\Storage;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinition\\InputTypeEnum;\nuse Jiminny\\Component\\AskAnything\\AskAnythingPromptService;\nuse Jiminny\\Component\\AskAnything\\Dtos\\AskAnythingPromptDto;\nuse Jiminny\\Component\\UrlGenerator\\Webhook;\nuse Jiminny\\Contracts\\Repositories\\PlaybookCategoryRepository;\nuse Jiminny\\Contracts\\Repositories\\TeamRepository;\nuse Jiminny\\Contracts\\Repositories\\UserRepository;\nuse Jiminny\\Exceptions\\ApplicationException;\nuse Jiminny\\Exceptions\\InvalidArgumentException;\nuse Jiminny\\Exceptions\\ModelNotFoundException;\nuse Jiminny\\Jobs\\AutomatedReports\\RequestGenerateReportJob;\nuse Jiminny\\Models\\Activity\\Search;\nuse Jiminny\\Models\\AskAnything\\AskAnythingPrompt;\nuse Jiminny\\Models\\AskAnything\\AskAnythingPromptTarget;\nuse Jiminny\\Models\\AutomatedReport;\nuse Jiminny\\Models\\AutomatedReportResult;\nuse Jiminny\\Models\\Contracts\\UserContract;\nuse Jiminny\\Models\\Feature\\FeatureEnum;\nuse Jiminny\\Models\\Team;\nuse Jiminny\\Models\\User;\nuse Jiminny\\Repositories\\AskAnythingRepository;\nuse Jiminny\\Repositories\\AutomatedReportsRepository;\nuse Jiminny\\Repositories\\GroupRepository;\nuse Jiminny\\Repositories\\SearchRepository;\nuse Jiminny\\Repositories\\StageRepository;\nuse Throwable;\n\nclass AutomatedReportsService\n{\n public const string TYPE_LOSS_ANALYSIS = 'loss_analysis';\n public const string TYPE_ASK_JIMINNY = 'ask_jiminny';\n\n /**\n * Standard report types (used by kiosk for existing automated reports).\n */\n // @TODO this will add filter, however if we need to control feature by FF we need conditional logic\n public const array TYPES = [\n ['id' => 'exec_summary', 'name' => 'Exec Summary'],\n ['id' => 'coaching_profiles', 'name' => 'Coaching Profiles'],\n ['id' => 'product_feedback', 'name' => 'Product Feedback'],\n ['id' => self::TYPE_LOSS_ANALYSIS, 'name' => 'Loss Analysis'],\n// ['id' => 'questions', 'name' => 'Questions'],\n// ['id' => 'statistical_quant', 'name' => 'Statistical Quantitative'],\n ];\n\n public const array ALL_TYPES = [\n ...self::TYPES,\n ['id' => self::TYPE_ASK_JIMINNY, 'name' => 'Ask Jiminny'],\n ];\n\n public const string FREQUENCY_DAILY = 'daily';\n public const string FREQUENCY_WEEKLY = 'weekly';\n public const string FREQUENCY_MONTHLY = 'monthly';\n public const string FREQUENCY_QUARTERLY = 'quarterly';\n public const string FREQUENCY_ONE_OFF = 'one_off';\n\n /**\n * Frequencies for standard (non-Ask Jiminny) reports.\n */\n public const array FREQUENCIES = [\n ['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],\n ['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],\n ['id' => self::FREQUENCY_QUARTERLY, 'name' => 'Quarterly'],\n ['id' => self::FREQUENCY_ONE_OFF, 'name' => 'One-off'],\n ];\n\n /**\n * Frequencies for Ask Jiminny reports.\n */\n public const array ASK_JIMINNY_FREQUENCIES = [\n ['id' => self::FREQUENCY_DAILY, 'name' => 'Daily'],\n ['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],\n ['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],\n ];\n\n public const string MEDIA_TYPE_PDF = 'pdf';\n public const string MEDIA_TYPE_PODCAST = 'podcast';\n public const array MEDIA_TYPES = [self::MEDIA_TYPE_PDF, self::MEDIA_TYPE_PODCAST];\n public const array MEDIA_TYPE_OBJECT_PDF = ['id' => self::MEDIA_TYPE_PDF, 'name' => 'PDF'];\n public const array MEDIA_TYPE_OBJECT_PODCAST = ['id' => self::MEDIA_TYPE_PODCAST, 'name' => 'Podcast'];\n public const array MEDIA_TYPE_OBJECTS = [self::MEDIA_TYPE_OBJECT_PDF, self::MEDIA_TYPE_OBJECT_PODCAST];\n\n public const array CALL_TYPE_CONFERENCE = ['id' => 'conference', 'name' => 'Conference'];\n public const array CALL_TYPE_DIALER = ['id' => 'dialer', 'name' => 'Dialer'];\n public const int SENT_REPORT_AT_HOURS = 5;\n public const string PDF_KEY = 'pdf';\n public const string AUDIO_KEY = 'audio';\n\n private const array ALL_FREQUENCIES = [\n ['id' => self::FREQUENCY_DAILY, 'name' => 'Daily'],\n ['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],\n ['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],\n ['id' => self::FREQUENCY_QUARTERLY, 'name' => 'Quarterly'],\n ['id' => self::FREQUENCY_ONE_OFF, 'name' => 'One-off'],\n ];\n private const string S3_DIR = 'reports';\n private const array FILE_EXTENSIONS_VARIANTS = ['html', 'MD', 'pdf'];\n private const array FILE_PODCAST_EXTENSIONS_VARIANTS = ['json', 'mp3', 'ssml'];\n\n public function __construct(\n private readonly TeamRepository $teamRepository,\n private readonly GroupRepository $groupRepository,\n private readonly UserRepository $userRepository,\n private readonly StageRepository $stageRepository,\n private readonly DealStagesService $dealStagesService,\n private readonly RecipientsService $recipientsService,\n private readonly AutomatedReportsRepository $automatedReportsRepository,\n private readonly Webhook $webhookService,\n private readonly BusDispatcher $dispatcher,\n private readonly ActivityTypeService $activityTypeService,\n private readonly PlaybookCategoryRepository $playbookCategoryRepository,\n private readonly AskAnythingPromptService $askAnythingPromptService,\n private readonly SearchRepository $activitySearchRepository,\n private readonly AskAnythingRepository $askAnythingRepository,\n ) {\n }\n\n public static function getTypes(): array\n {\n $types = self::TYPES;\n\n return array_map(static function ($type) {\n return $type['id'];\n }, $types);\n }\n\n public static function getCallTypes(): array\n {\n return array_map(static function ($callType) {\n return $callType['id'];\n }, [self::CALL_TYPE_CONFERENCE, self::CALL_TYPE_DIALER]);\n }\n\n public static function getFrequencies(): array\n {\n return array_map(static function ($frequency) {\n return $frequency['id'];\n }, self::FREQUENCIES);\n }\n\n // front-facing structure\n public function getReportEnabledFieldData(bool $value = false): array\n {\n return [\n 'id' => 'report_enabled',\n 'label' => '',\n 'inputType' => InputTypeEnum::TOGGLE,\n 'value' => $value,\n ];\n }\n\n // Organizations = Teams\n public function getOrganizationFieldData(?string $value = null, bool $shortVersion = false): array\n {\n $options = $this->getTeams();\n\n if ($shortVersion) {\n return [\n 'id' => 'organization',\n 'label' => 'Organization',\n 'options' => $options,\n ];\n }\n\n return [\n 'id' => 'organization',\n 'label' => 'Organization',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => $options,\n 'value' => $value,\n 'dependencies' => [\n 'teams',\n 'deal_stage_at_call',\n 'current_deal_stage',\n 'recipients',\n ActivityTypeService::PLAYBOOK_CATEGORIES_KEY,\n ],\n 'dependsOn' => [],\n ];\n }\n\n // Teams = Groups\n public function getTeamFieldData(array $options = [], array $value = [], bool $shortVersion = false): array\n {\n if ($shortVersion) {\n return [\n 'id' => 'teams',\n 'label' => 'Team',\n 'options' => $options,\n ];\n }\n\n return [\n 'id' => 'teams',\n 'label' => 'Team',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'required' => false,\n 'placeholder' => 'Select',\n 'options' => $options,\n 'value' => $value, // value should be an array of objects {id, name}\n 'dependencies' => [ActivityTypeService::PLAYBOOK_CATEGORIES_KEY],\n 'dependsOn' => [],\n ];\n }\n\n public function getReportTypeFieldData(?string $value = null, bool $shortVersion = false, ?Team $team = null): array\n {\n $types = [];\n if ($team instanceof Team) {\n if ($team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {\n $types = self::TYPES;\n }\n if ($team->hasFeature(FeatureEnum::ASK_JIMINNY_REPORTS)) {\n $types[] = ['id' => self::TYPE_ASK_JIMINNY, 'name' => 'Ask Jiminny'];\n }\n } else {\n $types = self::TYPES;\n }\n\n if ($shortVersion) {\n return [\n 'id' => 'report_type',\n 'label' => 'Report Type',\n 'options' => $types,\n ];\n }\n\n return [\n 'id' => 'report_type',\n 'label' => 'Report Type',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => $types,\n 'value' => $value,\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getFrequencyFieldData(?string $value = null): array\n {\n return [\n 'id' => 'frequency',\n 'label' => 'Frequency',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => self::FREQUENCIES,\n 'value' => $value,\n 'dependencies' => ['period'],\n 'dependsOn' => [],\n ];\n }\n\n public function getPeriodFieldData(?string $valueStartDate = null, ?string $valueEndDate = null): array\n {\n return [\n 'id' => 'period',\n 'label' => 'Select one-off period',\n 'inputType' => InputTypeEnum::DATE_RANGE,\n 'required' => true,\n 'placeholder' => 'Select',\n 'value' => ['startDate' => $valueStartDate, 'endDate' => $valueEndDate],\n 'queryParams' => [\n 'startDate' => 'start_date_period',\n 'endDate' => 'end_date_period',\n ],\n 'dependencies' => [],\n 'dependsOn' => ['frequency'],\n ];\n }\n\n public function getActivityTypesFieldData(?Team $team = null, array $value = [], array $teamsFilter = []): array\n {\n return $this->activityTypeService->getActivityTypeFieldData(team: $team, value: $value, groupIds: $teamsFilter);\n }\n\n public function getDealStageAtCallFieldData(?Team $team = null, array $value = []): array\n {\n return $this->dealStagesService->getDealStageAtCallFieldData(team: $team, value: $value);\n }\n\n public function getCurrentDealStageFieldData(?Team $team = null, array $value = []): array\n {\n return $this->dealStagesService->getCurrentDealStageFieldData(team: $team, value: $value);\n }\n\n public function getDealValueFieldData(?int $valueMin = null, ?int $valueMax = null): array\n {\n return [\n 'id' => 'deal_value',\n 'label' => 'Deal Value',\n 'inputType' => InputTypeEnum::INTEGER_RANGE,\n 'required' => false,\n 'value' => ['min' => $valueMin, 'max' => $valueMax],\n 'queryParams' => [\n 'min' => 'min_deal_value',\n 'max' => 'max_deal_value',\n ],\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getCallTypeFieldData(bool $conferenceOn = false, bool $dialerOn = false): array\n {\n $value = [];\n $conferenceOn && $value[] = self::CALL_TYPE_CONFERENCE;\n $dialerOn && $value[] = self::CALL_TYPE_DIALER;\n\n return [\n 'id' => 'call_type',\n 'label' => 'Call Type',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'required' => true,\n 'options' => [\n self::CALL_TYPE_CONFERENCE,\n self::CALL_TYPE_DIALER,\n ],\n 'value' => $value,\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getMediaTypeFieldData(?AutomatedReport $report = null): array\n {\n $value = [];\n\n if ($report) {\n $value = $this->transformMediaTypes($report);\n }\n\n return [\n 'id' => 'media_types',\n 'label' => 'Export as',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'required' => true,\n 'options' => self::MEDIA_TYPE_OBJECTS,\n 'value' => $value,\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getCallDurationFieldData(?int $valueMin = null, ?int $valueMax = null): array\n {\n return [\n 'id' => 'call_duration',\n 'label' => 'Call Duration',\n 'inputType' => InputTypeEnum::INTEGER_RANGE,\n 'required' => false,\n 'value' => ['min' => $valueMin, 'max' => $valueMax],\n 'queryParams' => [\n 'min' => 'min_call_duration',\n 'max' => 'max_call_duration',\n ],\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getRecipientsFieldData(?Team $team = null, array $value = []): array\n {\n return $this->recipientsService->getRecipientsFieldData(team: $team, value: $value);\n }\n\n public function getJiminnyRecipientsFieldData(array $value = []): array\n {\n return $this->recipientsService->getJiminnyRecipientsFieldData($value);\n }\n\n public function getAdditionalPromptInputFieldData(?string $value = null): array\n {\n return [\n 'id' => 'additional_prompt_input',\n 'label' => 'Special requirements',\n 'inputType' => InputTypeEnum::TEXTAREA,\n 'required' => false,\n 'placeholder' => 'What should be the focus of the report?',\n 'value' => $value,\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getCustomReportNameFieldData(?string $value = null): array\n {\n return [\n 'id' => 'custom_name',\n 'label' => 'Custom report name',\n 'inputType' => InputTypeEnum::TEXT,\n 'required' => false,\n 'placeholder' => 'Enter custom name',\n 'value' => $value,\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n // data providers\n public function getTeams(): array\n {\n $teams = $this->teamRepository->getTeamsForKiosk(status: Team::STATUS_ACTIVE);\n\n $teamData = [];\n foreach ($teams as $team) {\n if (! $team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {\n continue;\n }\n\n $teamData[] = $this->transformTeam($team);\n }\n\n return $teamData;\n }\n\n public function getTeamGroups(string $teamUuid): array\n {\n $data = [];\n $team = $this->getTeam($teamUuid);\n\n if ($team !== null) {\n $groups = $team->groups()->get();\n\n foreach ($groups as $group) {\n $data[] = [\n 'id' => $group->getUuid(),\n 'name' => $group->getName(),\n ];\n }\n }\n\n return $data;\n }\n\n public function getTeamsGroupsOptions(array $filterTeamUuids = []): array\n {\n $data = [];\n $teams = $this->getTeams();\n\n foreach ($teams as $team) {\n if (! empty($filterTeamUuids) && ! in_array($team['id'], $filterTeamUuids, true)) {\n continue;\n }\n\n $data[] = [\n 'label' => $team['name'],\n 'groups' => $this->getTeamGroups($team['id']),\n ];\n }\n\n return $data;\n }\n\n public function getTeam(string $teamUuid): ?Team\n {\n return $this->teamRepository->idOrUuid($teamUuid);\n }\n\n public function getTeamById(int $teamId): ?Team\n {\n return $this->teamRepository->find($teamId);\n }\n\n public function getGroupsUuids(AutomatedReport $report): array\n {\n $uuids = [];\n $reportGroups = $report->getGroups();\n foreach ($reportGroups as $groupId) {\n if ($group = $this->groupRepository->find($groupId)) {\n $uuids[] = $group->getUuid();\n }\n }\n\n return $uuids;\n }\n\n public function getPlaybookCategoriesUuids(AutomatedReport $report): array\n {\n $uuids = [];\n $playbookCategories = $report->getPlaybookCategories();\n foreach ($playbookCategories as $id) {\n if ($category = $this->playbookCategoryRepository->find($id)) {\n $uuids[] = $category->getUuid();\n }\n }\n\n return $uuids;\n }\n\n public function getDealAtCallStagesUuids(AutomatedReport $report): array\n {\n $uuids = [];\n $reportStages = $report->getDealAtCallStages();\n foreach ($reportStages as $id) {\n if ($stage = $this->stageRepository->find($id)) {\n $uuids[] = $stage->getUuid();\n }\n }\n\n return $uuids;\n }\n\n public function getCurrentDealStagesUuids(AutomatedReport $report): array\n {\n $uuids = [];\n $reportStages = $report->getCurrentDealStages();\n foreach ($reportStages as $id) {\n if ($stage = $this->stageRepository->find($id)) {\n $uuids[] = $stage->getUuid();\n }\n }\n\n return $uuids;\n }\n\n public function getUsersUuids(AutomatedReport $report): array\n {\n return $this->extractUserUuids($report->getRecipients());\n }\n\n public function getJiminnyUsersUuids(AutomatedReport $report): array\n {\n return $this->extractUserUuids($report->getJiminnyRecipients());\n }\n\n /**\n * @param array<string, mixed> $recipients\n */\n private function extractUserUuids(array $recipients): array\n {\n $userIds = $recipients['users'] ?? [];\n\n return collect($userIds)\n ->map(fn ($id) => $this->userRepository->find((int) $id))\n ->filter()\n ->map(fn (UserContract $user) => $user->getUuid())\n ->values()\n ->all();\n }\n\n // get mail data\n public function getRecipientUsers(AutomatedReport $report): array\n {\n return $this->buildRecipientUsers($report->getRecipients());\n }\n\n private function getJiminnyRecipientUsers(AutomatedReport $report): array\n {\n return $this->buildRecipientUsers($report->getJiminnyRecipients());\n }\n\n /**\n * @param array<string, mixed> $recipients\n */\n private function buildRecipientUsers(array $recipients): array\n {\n $userIds = $recipients['users'] ?? [];\n\n return collect($userIds)\n ->map(fn ($id) => $this->userRepository->find((int) $id))\n ->filter()\n ->map(fn (UserContract $user) => [\n 'email' => $user->getEmailAddress(),\n 'name' => $user->getName(),\n 'timezone' => $user->getTimezone()->getName(),\n ])\n ->values()\n ->all();\n }\n\n public function getValidRecipientUsers(AutomatedReport $report, bool $includeJiminny = false): array\n {\n if ($report->isAskJiminnyReport()) {\n $recipients = $this->resolveAskJiminnyRecipients($report);\n } else {\n $recipients = $this->getRecipientUsers($report);\n if ($includeJiminny) {\n $recipients = array_merge($recipients, $this->getJiminnyRecipientUsers($report));\n }\n }\n\n $emails = [];\n\n return array_values(array_filter(\n $recipients,\n static function ($recipient) use (&$emails) {\n if (empty($recipient['email']) || in_array($recipient['email'], $emails, true)) {\n return false;\n }\n $emails[] = $recipient['email'];\n\n return true;\n }\n ));\n }\n\n private function resolveAskJiminnyRecipients(AutomatedReport $report): array\n {\n $recipients = [];\n\n $creator = $report->getCreator();\n if ($creator !== null) {\n $recipients[] = [\n 'email' => $creator->getEmailAddress(),\n 'name' => $creator->getName(),\n 'timezone' => $creator->getTimezone()->getName(),\n ];\n }\n\n return array_merge(\n $recipients,\n $this->buildRecipientUsers($report->getRecipients()),\n $this->getGroupRecipientUsers($report),\n );\n }\n\n private function getGroupRecipientUsers(AutomatedReport $report): array\n {\n $users = [];\n foreach ($report->getGroups() as $groupId) {\n $group = $this->groupRepository->find($groupId);\n if ($group === null) {\n continue;\n }\n foreach ($group->getMembers() as $member) {\n $users[] = [\n 'email' => $member->getEmailAddress(),\n 'name' => $member->getName(),\n 'timezone' => $member->getTimezone()->getName(),\n ];\n }\n }\n\n return $users;\n }\n\n public function getReportTypeName(AutomatedReportResult $report): string\n {\n $type = $report->getReport()->getType();\n\n $getType = $this->transformReportType($type);\n\n return $getType['name'];\n }\n\n public function getReportPeriodName(AutomatedReportResult $report): string\n {\n $from = $report->getFromDate();\n $to = $report->getToDate();\n $frequency = $report->getReport()->getFrequency();\n\n if ($from === null || $to === null) {\n if (! $report->getReport()->isAskJiminnyReport()) {\n $invalidPeriod = $from === null ? 'from' : 'to';\n\n throw new ApplicationException('Report period is invalid: ' . $invalidPeriod);\n }\n\n $period = $this->calculateFromAndToDatePeriod($frequency);\n $from = $period['fromDate'];\n $to = $period['toDate'];\n }\n\n return $this->formatReportPeriodName($frequency, $from, $to);\n }\n\n private function formatReportPeriodName(string $frequency, Carbon $from, Carbon $to): string\n {\n $fromYear = $from->format('Y');\n $toYear = $to->format('Y');\n $differentYears = $fromYear !== $toYear;\n\n switch ($frequency) {\n case self::FREQUENCY_DAILY:\n return $from->format('j M Y');\n\n case self::FREQUENCY_QUARTERLY:\n // 'Jan-Mar 2025' or 'Nov 2024-Jan 2025' if years differ\n $startMonth = $from->format('M');\n $endMonth = $to->copy()->subMonth();\n $endMonthName = $endMonth->format('M');\n $endMonthYear = $endMonth->format('Y');\n\n if ($differentYears) {\n return \"{$startMonth} {$fromYear} - {$endMonthName} {$endMonthYear}\";\n }\n\n return \"{$startMonth} - {$endMonthName} {$toYear}\";\n\n case self::FREQUENCY_MONTHLY:\n // 'May 2025' - monthly reports are always within the same year\n return $from->format('M Y');\n\n case self::FREQUENCY_WEEKLY:\n // '4 - 8 Aug 2025', '27 Oct - 3 Nov 2025', or '28 Dec 2024 - 3 Jan 2025' if years differ\n $startDay = $from->format('j');\n $endDay = $to->format('j');\n $startMonth = $from->format('M');\n $endMonth = $to->format('M');\n\n if ($differentYears) {\n return \"{$startDay} {$startMonth} {$fromYear} - {$endDay} {$endMonth} {$toYear}\";\n }\n\n if ($startMonth !== $endMonth) {\n return \"{$startDay} {$startMonth} - {$endDay} {$endMonth} {$toYear}\";\n }\n\n return \"{$startDay} - {$endDay} {$endMonth} {$toYear}\";\n\n case self::FREQUENCY_ONE_OFF:\n // '2 May-31 May 2025' or '15 Dec 2024-15 Jan 2025' if years differ\n $startDay = $from->format('j');\n $startMonth = $from->format('M');\n $endDay = $to->format('j');\n $endMonth = $to->format('M');\n\n // If same month and year, use a format like '2-31 May 2025'\n if ($startMonth === $endMonth && ! $differentYears) {\n return \"{$startDay} - {$endDay} {$startMonth} {$toYear}\";\n }\n\n // If different years, include both years\n if ($differentYears) {\n return \"{$startDay} {$startMonth} {$fromYear} - {$endDay} {$endMonth} {$toYear}\";\n }\n\n // Same year but different months\n return \"{$startDay} {$startMonth} - {$endDay} {$endMonth} {$toYear}\";\n\n default:\n // Default format for unknown frequencies\n return $from->format('j M Y') . ' - ' . $to->format('j M Y');\n }\n }\n\n public function getReportTeamsName(AutomatedReportResult $report): string\n {\n $groups = $report->getGroups();\n\n if (empty($groups)) {\n return 'All';\n }\n\n // Get group names from repository\n $groupNames = [];\n foreach ($groups as $groupId) {\n $group = $this->groupRepository->find($groupId);\n if ($group) {\n $groupNames[] = $group->getName();\n }\n }\n\n if (count($groupNames) === 1) {\n // Single team format\n $teamsName = $groupNames[0];\n } else {\n // Multiple teams format\n $teamsName = implode(', ', $groupNames);\n }\n\n return $teamsName;\n }\n\n public function getReportFileName(AutomatedReportResult $report): string\n {\n $customName = $report->getReport()->getCustomName();\n $periodName = $this->getReportPeriodName($report);\n $filenameSuffix = $this->getFilenameSuffix($report);\n\n if ($customName) {\n if ($filenameSuffix) {\n $customName .= \" {$filenameSuffix}\";\n }\n\n return $this->sanitizeFileName(\"{$customName} - {$periodName}\");\n }\n\n $baseName = $this->getReportTypeName($report);\n\n if ($filenameSuffix) {\n $baseName .= \" {$filenameSuffix}\";\n }\n\n return $this->sanitizeFileName(\"{$baseName} - {$periodName} - {$this->getReportTeamsName($report)}\");\n }\n\n public function getReportFileNameWithExtension(AutomatedReportResult $result): string\n {\n $extension = $this->getMediaTypeMetadata($result)['extension'];\n\n return $this->getReportFileName($result) . '.' . $extension;\n }\n\n public function sanitizeFileName(string $fileName): string\n {\n return str_replace(['/', '\\\\'], '-', $fileName);\n }\n\n public function isUserRecipientOfReport(User $user, AutomatedReport $report): bool\n {\n $recipients = array_map('intval', $report->getRecipients()['users'] ?? []);\n\n return in_array($user->getId(), $recipients);\n }\n\n public function transformReportResults(Collection $automatedReportResults): array\n {\n $data = [];\n foreach ($automatedReportResults as $automatedReportResult) {\n /** @var AutomatedReportResult $automatedReportResult */\n\n $report = $automatedReportResult->getReport();\n\n $createdBy = $report->getCreator();\n $creator = [\n 'id' => $createdBy?->getUuid(),\n 'name' => $createdBy?->getName(),\n 'email' => $createdBy?->getEmailAddress(),\n 'photoUrl' => $createdBy?->getPhotoUrl(),\n ];\n\n $data[] = [\n 'id' => $automatedReportResult->getUuid(),\n 'name' => $automatedReportResult->getName(),\n 'frequency' => $this->transformFrequency($report->getFrequency()),\n 'recipients' => [\n ...array_values($this->transformGroups(team: $report->getTeam(), groupsIds: $report->getGroups())),\n ...array_values($this->transformRecipients($report->getRecipients())),\n ],\n 'report_type' => $this->transformReportType($report->getType()),\n 'media_type' => $automatedReportResult->getMediaType(),\n 'downloadUrl' => $this->generateReportResultDownloadUrl($automatedReportResult),\n 'viewUrl' => $this->generateReportResultViewUrl($automatedReportResult),\n 'generated_at' => $automatedReportResult->getGeneratedAt()?->toIso8601String(),\n 'creator' => $creator,\n ];\n }\n\n return $data;\n }\n\n public function hasCallTypeConference(AutomatedReport $report): bool\n {\n return in_array(self::CALL_TYPE_CONFERENCE['id'], $report->getCallTypes(), true);\n }\n\n public function hasCallTypeDialer(AutomatedReport $report): bool\n {\n return in_array(self::CALL_TYPE_DIALER['id'], $report->getCallTypes(), true);\n }\n\n // transformers\n private function transformTeam(Team $team): array\n {\n if (! $team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {\n return [];\n }\n\n return [\n 'id' => $team->getUuid(),\n 'name' => $team->getName(),\n ];\n }\n\n private function transformReportFullView(AutomatedReport $report): array\n {\n $base = $this->transformReportBase($report);\n\n return $report->getType() === self::TYPE_ASK_JIMINNY\n ? $base + $this->transformAskJiminnyFields($report)\n : $base + $this->transformStandardReportFields($report);\n }\n\n private function transformReportBase(AutomatedReport $report): array\n {\n return [\n 'id' => $report->getUuid(),\n 'organization' => $this->transformOrganization(team: $report->getTeam()),\n 'report_type' => $this->transformReportType($report->getType()),\n 'frequency' => $this->transformFrequency($report->getFrequency()),\n ];\n }\n\n private function transformStandardReportFields(AutomatedReport $report): array\n {\n $team = $report->getTeam();\n\n return [\n 'report_enabled' => $report->getStatus(),\n 'start_date_period' => $report->getFrom()?->format('Y-m-d H:i:s'),\n 'end_date_period' => $report->getTo()?->format('Y-m-d H:i:s'),\n 'deal_value_min' => $report->getDealValueMin(),\n 'deal_value_max' => $report->getDealValueMax(),\n 'call_types' => $this->transformCallType($report->getCallTypes()),\n 'media_types' => $this->transformMediaTypes($report),\n 'call_duration_min' => $this->transformDurationToMinutes($report->getCallDurationMin()),\n 'call_duration_max' => $this->transformDurationToMinutes($report->getCallDurationMax()),\n 'teams' => $this->transformGroups(team: $team, groupsIds: $report->getGroups()),\n 'deal_at_call_stages' => $this->transformStages(team: $team, stagesIds: $report->getDealAtCallStages()),\n 'current_deal_stages' => $this->transformStages(team: $team, stagesIds: $report->getCurrentDealStages()),\n 'recipients' => $this->transformRecipients($report->getRecipients()),\n 'created_by' => $this->transformCreator($report->getCreator()),\n 'additional_prompt_input' => $report->getAdditionalPromptInput(),\n 'custom_name' => $report->getCustomName(),\n 'created_at' => $report->getCreatedAt()->format('Y-m-d H:i:s'),\n 'updated_at' => $report->getUpdatedAt()->format('Y-m-d H:i:s'),\n 'deleted_at' => $report->getDeletedAt()?->format('Y-m-d H:i:s'),\n ];\n }\n\n private function transformAskJiminnyFields(AutomatedReport $report): array\n {\n $team = $report->getTeam();\n $creatorId = $report->getAttribute('created_by');\n $explicitUserIds = array_values(array_filter(\n $report->getRecipients()['users'] ?? [],\n static fn ($id) => $id !== $creatorId\n ));\n\n return [\n 'report_name' => $report->getCustomName(),\n 'enabled' => $report->getStatus(),\n 'share_teams' => $this->transformGroups(team: $team, groupsIds: $report->getGroups()),\n 'share_users' => $this->transformRecipients(['users' => $explicitUserIds]),\n 'saved_search' => $this->transformSafeSearch($report->getSavedSearch()),\n 'ask_jiminny_prompt' => $this->transformAskJiminnyPrompt($report->getAskAnythingPrompt()),\n 'expires_on' => $report->getExpiresAt()?->format('Y-m-d'),\n ];\n }\n\n private function transformOrganization(?Team $team): array\n {\n return [\n 'id' => $team?->getUuid(),\n 'name' => $team?->getName(),\n ];\n }\n\n private function transformReportType(string $type): array\n {\n foreach (self::ALL_TYPES as $typeItem) {\n if ($typeItem['id'] === $type) {\n return $typeItem;\n }\n }\n\n return [];\n }\n\n private function transformCallType(array $types): array\n {\n $result = [];\n $callTypes = [self::CALL_TYPE_CONFERENCE, self::CALL_TYPE_DIALER];\n\n foreach ($types as $type) {\n foreach ($callTypes as $callTypeItem) {\n if ($callTypeItem['id'] === $type) {\n $result[] = $callTypeItem;\n\n break;\n }\n }\n }\n\n return $result;\n }\n\n private function transformMediaTypes(AutomatedReport $report): array\n {\n $values = [];\n\n foreach ($report->getMediaTypes() as $mediaType) {\n if (! in_array($mediaType, self::MEDIA_TYPES, true)) {\n continue;\n }\n\n $values[] = match ($mediaType) {\n self::MEDIA_TYPE_PDF => self::MEDIA_TYPE_OBJECT_PDF,\n self::MEDIA_TYPE_PODCAST => self::MEDIA_TYPE_OBJECT_PODCAST,\n };\n }\n\n return $values;\n }\n\n private function transformFrequency(string $frequency): array\n {\n foreach (self::ALL_FREQUENCIES as $frequencyItem) {\n if ($frequencyItem['id'] === $frequency) {\n return $frequencyItem;\n }\n }\n\n return [];\n }\n\n public function transformDurationToMinutes(?int $duration): ?int\n {\n if (! $duration) {\n return null;\n }\n\n return (int) ($duration / 60);\n }\n\n private function transformGroups(?Team $team, array $groupsIds): array\n {\n if (empty($groupsIds) || ! $team) {\n return [];\n }\n\n $data = [];\n foreach ($groupsIds as $groupId) {\n $group = $team->groups()->where('id', $groupId)->first();\n\n if ($group) {\n $data[] = [\n 'id' => $group->getUuid(),\n 'name' => $group->getName(),\n 'photoUrl' => $group->getPhotoUrl(),\n ];\n }\n }\n\n return $data;\n }\n\n private function transformStages(?Team $team, array $stagesIds): array\n {\n if (empty($stagesIds) || ! $team) {\n return [];\n }\n\n $data = [];\n foreach ($stagesIds as $stageId) {\n $stage = $team->stages()->where('id', $stageId)->first();\n\n if ($stage) {\n $data[] = [\n 'id' => $stage->getUuid(),\n 'name' => $stage->getName(),\n ];\n }\n }\n\n return $data;\n }\n\n private function transformRecipients(array $recipients): array\n {\n $users = [];\n foreach ($recipients['users'] ?? [] as $userId) {\n $users[] = $this->transformUser($userId);\n }\n\n return $users;\n }\n\n private function transformCreator(?User $user): ?array\n {\n if ($user === null) {\n return null;\n }\n\n return $this->transformUser($user->getId());\n }\n\n private function transformAskJiminnyPrompt(?AskAnythingPrompt $prompt): ?array\n {\n if ($prompt === null) {\n return null;\n }\n\n return [\n 'id' => $prompt->getUuid(),\n 'name' => $prompt->getTitle(),\n ];\n }\n\n private function transformSafeSearch(?Search $search): ?array\n {\n if ($search === null) {\n return null;\n }\n\n return [\n 'id' => $search->getUuid(),\n 'name' => $search->getName(),\n ];\n }\n\n private function transformUser(int $userId): array\n {\n /* @var ?User $user */\n $user = $this->userRepository->find($userId);\n\n return [\n 'id' => $user?->getUuid(),\n 'name' => $user?->getName(),\n 'email' => $user?->getEmailAddress(),\n 'photoUrl' => $user?->getPhotoUrl(),\n ];\n }\n\n public function create(array $data): array\n {\n $validatedData = $this->validateAndTransformData($data);\n $validatedData['created_by'] = auth()->id();\n\n $automatedReport = $this->automatedReportsRepository->create($validatedData);\n\n $this->generateOneOffReport($automatedReport);\n\n return $this->transformReportFullView($automatedReport);\n }\n\n public function update(string $uuid, array $data): array\n {\n $validatedData = $this->validateAndTransformData($data);\n $report = $this->automatedReportsRepository->findByUuid($uuid);\n\n if (! $report) {\n throw new InvalidArgumentException('Report not found');\n }\n\n $oldCustomName = $report->getCustomName();\n\n $automatedReport = $this->automatedReportsRepository->update($report, $validatedData);\n\n if ($oldCustomName !== $automatedReport->getCustomName()) {\n $this->updateResultNames($automatedReport);\n }\n\n $this->generateOneOffReport($automatedReport);\n\n return $this->transformReportFullView($automatedReport);\n }\n\n /**\n * Create an Ask Jiminny report.\n */\n public function createAskJiminnyReport(array $data, User $creator): array\n {\n $validatedData = $this->validateAskJiminnyReportData($data, $creator);\n $validatedData['created_by'] = $creator->getId();\n\n $automatedReport = $this->automatedReportsRepository->create($validatedData);\n\n return $this->transformReportFullView($automatedReport);\n }\n\n /**\n * Update an Ask Jiminny report.\n */\n public function updateAskJiminnyReport(AutomatedReport $report, array $data, User $user): array\n {\n if (! $report->isAskJiminnyReport()) {\n throw new InvalidArgumentException('Report is not an Ask Jiminny report');\n }\n\n $validatedData = $this->validateAskJiminnyReportData($data, $user);\n\n $oldCustomName = $report->getCustomName();\n\n $automatedReport = $this->automatedReportsRepository->update($report, $validatedData);\n\n if ($oldCustomName !== $automatedReport->getCustomName()) {\n $this->updateResultNames($automatedReport);\n }\n\n return $this->transformReportFullView($automatedReport);\n }\n\n public function updateAskJiminnyReportStatus(AutomatedReport $report, bool $status): array\n {\n $this->automatedReportsRepository->update($report, ['status' => $status]);\n\n return $this->transformReportFullView($report->fresh());\n }\n\n /**\n * Validate and transform data for Ask Jiminny reports.\n */\n private function validateAskJiminnyReportData(array $data, User $user): array\n {\n // Validate name\n $name = trim($data['report_name'] ?? '');\n if (empty($name)) {\n throw new InvalidArgumentException('Report name is required');\n }\n if (mb_strlen($name) > 50) {\n throw new InvalidArgumentException('Report name must be 50 characters or less');\n }\n\n // Validate frequency (only daily, weekly, monthly for Ask Jiminny)\n $frequency = $data['frequency'] ?? null;\n $askJiminnyFrequencies = [self::FREQUENCY_DAILY, self::FREQUENCY_WEEKLY, self::FREQUENCY_MONTHLY];\n if (! in_array($frequency, $askJiminnyFrequencies, true)) {\n throw new InvalidArgumentException('Frequency must be daily, weekly, or monthly');\n }\n\n // Validate expiration date\n $expiresAt = $data['expires_on'] ?? null;\n if (empty($expiresAt)) {\n throw new InvalidArgumentException('Expiration date is required');\n }\n\n try {\n $expiresAtDate = Carbon::parse($expiresAt);\n } catch (InvalidFormatException $e) {\n throw new InvalidArgumentException('Expiration date format is invalid');\n }\n $maxExpiration = Carbon::now()->addYear();\n if ($expiresAtDate->gt($maxExpiration)) {\n throw new InvalidArgumentException('Expiration date cannot be more than 1 year from now');\n }\n if ($expiresAtDate->isPast()) {\n throw new InvalidArgumentException('Expiration date cannot be in the past');\n }\n\n // Validate saved search\n $activitySearchId = $data['saved_search'] ?? null;\n if (empty($activitySearchId)) {\n throw new InvalidArgumentException('Saved search is required');\n }\n $savedSearch = $this->activitySearchRepository->findByUuidAndUser($activitySearchId, $user);\n if (! $savedSearch) {\n throw new InvalidArgumentException('Saved search not found or does not belong to you');\n }\n\n // Validate saved prompt\n $askAnythingPromptId = $data['ask_jiminny_prompt'] ?? null;\n if (empty($askAnythingPromptId)) {\n throw new InvalidArgumentException('Ask Jiminny prompt is required');\n }\n $prompt = $this->askAnythingRepository->getPromptByUuid($askAnythingPromptId);\n if (! $prompt) {\n throw new InvalidArgumentException('Ask Jiminny prompt not found');\n }\n\n // Validate status\n $status = $data['enabled'] ?? false;\n\n $recipientUserIds = [$user->getId()];\n\n if (! empty($data['share_users'])) {\n $sharedUserIds = $this->validateAndGetUserIdsByTeam(\n $user->team,\n (array) $data['share_users']\n );\n $recipientUserIds = array_merge($recipientUserIds, $sharedUserIds);\n }\n\n $sharedGroupIds = [];\n if (! empty($data['share_teams'])) {\n $sharedGroupIds = $this->validateAndGetGroupIds($user->team, (array) $data['share_teams']);\n }\n\n $recipientUserIds = array_values(array_unique($recipientUserIds));\n\n return [\n 'team_id' => $user->getTeamId(),\n 'type' => self::TYPE_ASK_JIMINNY,\n 'status' => (bool) $status,\n 'frequency' => $frequency,\n 'custom_name' => $name,\n 'activity_search_id' => $savedSearch->getId(),\n 'ask_anything_prompt_id' => $prompt->getId(),\n 'expires_at' => $expiresAtDate->toDateString(),\n 'media_types' => [self::MEDIA_TYPE_PDF],\n 'call_types' => [],\n 'recipients' => ['users' => $recipientUserIds],\n 'groups' => $sharedGroupIds,\n ];\n }\n\n public static function getAskJiminnyFrequencies(): array\n {\n return array_map(static function ($frequency) {\n return $frequency['id'];\n }, self::ASK_JIMINNY_FREQUENCIES);\n }\n\n public function getAskJiminnyReportFilters(User $user): array\n {\n $savedSearches = $this->activitySearchRepository->findByUserOrderedByName($user)\n ->map(fn (Search $search) => [\n 'id' => $search->getUuid(),\n 'name' => $search->getName(),\n ])\n ->values()->all();\n\n $prompts = collect(\n $this->askAnythingPromptService->get($user, AskAnythingPromptTarget::on_demand)\n )->map(fn (AskAnythingPromptDto $prompt) => [\n 'id' => $prompt->id,\n 'name' => $prompt->title,\n ])->values()->all();\n\n return [\n [\n 'id' => 'prompt',\n 'label' => 'Prompt',\n 'options' => $prompts,\n ],\n [\n 'id' => 'saved_search',\n 'label' => 'Saved Search',\n 'options' => $savedSearches,\n ],\n ];\n }\n\n public function getAskJiminnyReportFormData(User $user, ?AutomatedReport $report = null): array\n {\n $team = $user->getTeam();\n $userTimezone = $user->getTimezone();\n\n $savedSearches = $this->activitySearchRepository->findByUserOrderedByName($user)\n ->map(fn (Search $search) => [\n 'id' => $search->getUuid(),\n 'name' => $search->getName(),\n ])\n ->values()->all();\n\n $prompts = collect(\n $this->askAnythingPromptService->get($user, AskAnythingPromptTarget::on_demand)\n )->map(fn (AskAnythingPromptDto $prompt) => [\n 'id' => $prompt->id,\n 'name' => $prompt->title,\n ])->values()->all();\n\n $teamGroups = $this->groupRepository->getAllByTeam($team)->map(fn ($group) => [\n 'id' => $group->getUuid(),\n 'name' => $group->getName(),\n ])->values()->all();\n\n $shareUsers = $this->recipientsService->getRecipientsFieldData(team: $team)['options'] ?? [];\n\n $sharedTeamsValue = [];\n $sharedUsersValue = [];\n if ($report) {\n $sharedTeamsValue = $this->transformGroups($team, $report->getGroups());\n\n $recipientUserIds = $report->getRecipients()['users'] ?? [];\n $creatorId = $report->getAttribute('created_by');\n $sharedUserIds = array_values(array_filter(\n $recipientUserIds,\n static fn ($id) => $id !== $creatorId\n ));\n $sharedUsersValue = collect($sharedUserIds)\n ->map(fn ($id) => $this->userRepository->find((int) $id))\n ->filter()\n ->map(fn (User $u) => [\n 'id' => $u->getUuid(),\n 'name' => $u->getName(),\n ])\n ->values()\n ->all();\n }\n\n return [\n 'fields' => [\n [\n 'id' => 'enabled',\n 'inputType' => InputTypeEnum::TOGGLE,\n 'label' => '',\n 'value' => $report?->getStatus() ?? false,\n ],\n [\n 'id' => 'report_name',\n 'inputType' => InputTypeEnum::TEXT,\n 'label' => 'Name',\n 'placeholder' => 'Enter name',\n 'required' => true,\n 'validation' => ['maxLength' => 50],\n 'value' => $report?->getCustomName() ?? '',\n ],\n [\n 'id' => 'frequency',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'label' => 'Frequency',\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => self::ASK_JIMINNY_FREQUENCIES,\n 'value' => $report ? $this->transformFrequency($report->getFrequency()) : null,\n ],\n [\n 'id' => 'expires_on',\n 'inputType' => InputTypeEnum::DATE,\n 'label' => 'Expires on',\n 'required' => true,\n 'placeholder' => 'Select',\n 'validation' => [\n 'minDate' => now($userTimezone)->toDateString(),\n 'maxDate' => now($userTimezone)->addYear()->toDateString(),\n ],\n 'value' => $report?->getExpiresAt()?->toDateString(),\n ],\n [\n 'id' => 'share_teams',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'label' => 'Team',\n 'required' => false,\n 'placeholder' => 'Select',\n 'options' => $teamGroups,\n 'value' => $sharedTeamsValue,\n ],\n [\n 'id' => 'share_users',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'label' => 'Team member',\n 'required' => false,\n 'placeholder' => 'Select',\n 'groupLabelKey' => 'label',\n 'groupValuesKey' => 'users',\n 'optionLabelKey' => 'name',\n 'optionValueKey' => 'id',\n 'options' => $shareUsers,\n 'value' => $sharedUsersValue,\n ],\n [\n 'id' => 'saved_search',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'label' => 'Saved search',\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => $savedSearches,\n 'value' => $report && $report->getSavedSearch() ? [\n 'id' => $report->getSavedSearch()->getUuid(),\n 'name' => $report->getSavedSearch()->getName(),\n ] : null,\n ],\n [\n 'id' => 'ask_jiminny_prompt',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'label' => 'Ask Jiminny prompt',\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => $prompts,\n 'value' => $report && $report->getAskAnythingPrompt() ? [\n 'id' => $report->getAskAnythingPrompt()->getUuid(),\n 'name' => $report->getAskAnythingPrompt()->getTitle(),\n ] : null,\n ],\n ],\n ];\n }\n\n private function updateResultNames(AutomatedReport $automatedReport): void\n {\n $results = $this->automatedReportsRepository->getResultsByReport($automatedReport);\n\n foreach ($results as $result) {\n $result->update(['name' => $this->getReportFileName($result)]);\n }\n }\n\n public function updateStatus(string $uuid, array $data): array\n {\n $automatedReport = $this->automatedReportsRepository->findByUuid($uuid);\n\n if (! $automatedReport) {\n throw new ModelNotFoundException('Report not found');\n }\n\n $status = $this->validateReportStatus($data['report_enabled'] ?? null);\n $automatedReport->update([\n 'status' => $status,\n ]);\n\n $this->generateOneOffReport($automatedReport);\n\n return $this->transformReportFullView($automatedReport);\n }\n\n private function generateOneOffReport(AutomatedReport $automatedReport): void\n {\n // the scheduler handles all the other frequency types\n if ($automatedReport->getStatus() === false || $automatedReport->getFrequency() !== self::FREQUENCY_ONE_OFF) {\n return;\n }\n\n $this->dispatcher->dispatch(new RequestGenerateReportJob($automatedReport->getUuid()));\n }\n\n public function getReport(string $uuid): AutomatedReport\n {\n $automatedReport = $this->automatedReportsRepository->findByUuid($uuid);\n\n if (! $automatedReport) {\n throw new ModelNotFoundException('Report not found');\n }\n\n return $automatedReport;\n }\n\n public function get(string $uuid): array\n {\n $automatedReport = $this->getReport($uuid);\n\n return $this->transformReportFullView($automatedReport);\n }\n\n public function list(string $sortColumn = 'created_at', string $sortDirection = 'desc'): array\n {\n $results = [];\n $collection = $this->automatedReportsRepository->getAllStandardReports($sortColumn, $sortDirection);\n\n /** @var AutomatedReport $report */\n foreach ($collection as $report) {\n $results[] = $this->transformReportFullView($report);\n }\n\n return ['data' => $results];\n }\n\n public function listAskJiminnyReports(\n User $user,\n string $sortColumn = 'created_at',\n string $sortDirection = 'desc'\n ): array {\n $results = [];\n $collection = $this->automatedReportsRepository->getAskJiminnyReportsByUser($user, $sortColumn, $sortDirection);\n\n /** @var AutomatedReport $report */\n foreach ($collection as $report) {\n $results[] = $this->transformReportFullView($report);\n }\n\n return ['data' => $results];\n }\n\n public function delete(string $uuid): void\n {\n $automatedReport = $this->automatedReportsRepository->findByUuid($uuid);\n\n if (! $automatedReport) {\n throw new ModelNotFoundException('Report not found');\n }\n\n $automatedReport->delete();\n }\n\n public function createReportResult(AutomatedReport $automatedReport, array $data = []): AutomatedReportResult\n {\n return $this->automatedReportsRepository->createResult(\n array_merge(\n [\n 'report_id' => $automatedReport->getId(),\n 'status' => AutomatedReportResult::STATUS_DEFAULT,\n ],\n $data\n )\n );\n }\n\n public function getReportResult(string $resultUuid): AutomatedReportResult\n {\n $report = $this->automatedReportsRepository->findResultByUuid($resultUuid);\n\n if (! $report) {\n throw new ModelNotFoundException('Report Result not found');\n }\n\n return $report;\n }\n\n public function findChildResult(AutomatedReportResult $result, string $type): ?AutomatedReportResult\n {\n return $this->automatedReportsRepository->findChildResult($result, $type);\n }\n\n // prophet API calls\n /**\n * @throws ApplicationException\n */\n public function getGenerateReportPayload(AutomatedReport $automatedReport, string $reportResultUuid): array\n {\n $period = $this->calculateFromAndToDate($automatedReport);\n $fromDate = $period['fromDate'];\n $toDate = $period['toDate'];\n\n return [\n 'team_id' => $automatedReport->getTeamId(),\n 'request_id' => $reportResultUuid,\n 'report_type' => $automatedReport->getType(),\n 'media_types' => $automatedReport->getMediaTypes(),\n 'from_date' => $fromDate->startOfDay()->format(DateTimeInterface::RFC3339),\n 'to_date' => $toDate->endOfDay()->format(DateTimeInterface::RFC3339),\n 'group_ids' => $automatedReport->getGroups(),\n 'call_deal_stage' => $automatedReport->getDealAtCallStages(),\n 'current_deal_stage' => $automatedReport->getCurrentDealStages(),\n 'deal_min_value' => $automatedReport->getDealValueMin(),\n 'deal_max_value' => $automatedReport->getDealValueMax(),\n 'call_types' => $automatedReport->getCallTypes(),\n 'call_duration_min_seconds' => $automatedReport->getCallDurationMin(),\n 'call_duration_max_seconds' => $automatedReport->getCallDurationMax(),\n 'special_requirements' => $automatedReport->getAdditionalPromptInput(),\n 'callback_url' => $this->getCallbackUrl(),\n 'report_period' => $this->formatReportPeriodName(\n $automatedReport->getFrequency(),\n $fromDate,\n $toDate,\n ),\n 'playbook_categories' => $automatedReport->getPlaybookCategories(),\n 'custom_name' => $automatedReport->getCustomName(),\n ];\n }\n\n // $inputPayload - FE payload structure\n public function getActivitiesCountPayload(array $inputPayload): array\n {\n // Use validateAndTransformData to validate and normalize input\n $validatedData = $this->validateAndTransformData($inputPayload);\n $period = $this->calculateFromAndToDatePeriod(\n $validatedData['frequency'],\n Carbon::parse($validatedData['from']),\n Carbon::parse($validatedData['to']),\n );\n $fromDate = $period['fromDate'];\n $toDate = $period['toDate'];\n\n // Create payload similar to getGenerateReportPayload\n return [\n 'team_id' => $validatedData['team_id'],\n 'group_ids' => $validatedData['groups'] ?? [],\n 'report_type' => $validatedData['type'],\n 'from_date' => $fromDate->format(DateTimeInterface::RFC3339),\n 'to_date' => $toDate->format(DateTimeInterface::RFC3339),\n 'call_deal_stage' => $validatedData['deal_at_call_stages'] ?? [],\n 'current_deal_stage' => $validatedData['current_deal_stages'] ?? [],\n 'deal_min_value' => $validatedData['deal_value_min'] ?? null,\n 'deal_max_value' => $validatedData['deal_value_max'] ?? null,\n 'call_types' => $validatedData['call_types'],\n 'call_duration_min_seconds' => $validatedData['call_duration_min'] ?? null,\n 'call_duration_max_seconds' => $validatedData['call_duration_max'] ?? null,\n 'special_requirements' => $validatedData['additional_prompt_input'] ?? null,\n 'playbook_categories' => $validatedData['playbook_categories'] ?? [],\n 'request_id' => null,\n 'callback_url' => null,\n ];\n }\n\n public function shouldSendReport(array $users, ?CarbonInterface $generatedAt = null): bool\n {\n if (empty($users)) {\n return false;\n }\n\n $earliestTz = collect($users)\n ->mapWithKeys(function (array $user) {\n $tz = new DateTimeZone($user['timezone']);\n $nowUtc = new DateTime('now', new DateTimeZone('UTC'));\n $offset = $tz->getOffset($nowUtc);\n\n return [$user['timezone'] => $offset];\n })\n ->sortDesc()\n ->keys()\n ->first();\n\n $now = Carbon::now($earliestTz);\n $isScheduledTime = (int) $now->format('H') === self::SENT_REPORT_AT_HOURS;\n\n if ($isScheduledTime) {\n return true;\n }\n\n return $this->hasPassedScheduledTime($generatedAt, $earliestTz);\n }\n\n public function hasPassedScheduledTime(?CarbonInterface $generatedAt, string $timezone): bool\n {\n if ($generatedAt === null) {\n return false;\n }\n\n $now = Carbon::now($timezone);\n $scheduledTime = $now->copy()->setTime(self::SENT_REPORT_AT_HOURS, 0, 0);\n\n if ($now->hour < self::SENT_REPORT_AT_HOURS) {\n $scheduledTime = $scheduledTime->subDay();\n }\n\n $scheduledTimeUtc = $scheduledTime->copy()->utc();\n $generatedAtUtc = $generatedAt->copy()->utc();\n $nowUtc = $now->copy()->utc();\n\n return $generatedAtUtc->lt($scheduledTimeUtc) && $nowUtc->gt($scheduledTimeUtc);\n }\n\n public function calculateFromAndToDatePeriod(\n string $frequency,\n ?Carbon $fromDate = null,\n ?Carbon $toDate = null\n ): array {\n if ($frequency === self::FREQUENCY_ONE_OFF) {\n return [\n 'fromDate' => $fromDate,\n 'toDate' => $toDate,\n ];\n }\n\n $now = Carbon::now();\n\n return match ($frequency) {\n self::FREQUENCY_DAILY => [\n 'fromDate' => $now->copy()->subDay()->startOfDay(),\n 'toDate' => $now->copy()->subDay()->endOfDay(),\n ],\n self::FREQUENCY_WEEKLY => [\n 'fromDate' => $now->copy()->subWeeks(1)->startOfDay(),\n 'toDate' => $now->copy()->subDay()->endOfDay(),\n ],\n self::FREQUENCY_MONTHLY => [\n 'fromDate' => $now->copy()->subMonths(1)->startOfDay(),\n 'toDate' => $now->copy()->subDay()->endOfDay(),\n ],\n self::FREQUENCY_QUARTERLY => [\n 'fromDate' => $now->copy()->subMonths(3)->startOfDay(),\n 'toDate' => $now->copy()->subDay()->endOfDay(),\n ],\n default => throw new InvalidArgumentException(\"Unsupported frequency: {$frequency}\"),\n };\n }\n\n private function calculateFromAndToDate(AutomatedReport $automatedReport): array\n {\n return $this->calculateFromAndToDatePeriod(\n $automatedReport->getFrequency(),\n $automatedReport->getFrom(),\n $automatedReport->getTo()\n );\n }\n\n public function getAskJiminnyGenerateReportPayload(\n AutomatedReport $automatedReport,\n AutomatedReportResult $reportResult,\n array $activityIds,\n ): array {\n return [\n 'user_question' => $automatedReport->getAskAnythingPrompt()?->getContent(),\n 'call_ids' => array_map('strval', $activityIds),\n 'team_id' => $automatedReport->getTeamId(),\n 'request_id' => $reportResult->getUuid(),\n 'callback_url' => $this->getCallbackUrl(),\n 'report_period' => $this->getReportPeriodName($reportResult),\n 'report_name' => $automatedReport->getCustomName(),\n ];\n }\n\n private function getCallbackUrl(): string\n {\n return $this->webhookService->route('jiminny.webhook.reports.ready');\n }\n\n /**\n * Validate and transform payload data for automated reports\n *\n * @param array $data\n *\n * @throws InvalidArgumentException\n *\n * @return array\n */\n private function validateAndTransformData(array $data): array\n {\n // Validate organization (team) and check feature\n $team = $this->validateOrganization($data['organization'] ?? null);\n\n $status = $this->validateReportStatus($data['report_enabled'] ?? null);\n $type = $this->validateReportType($data['report_type'] ?? null);\n $frequency = $this->validateFrequency($data['frequency'] ?? null);\n $additionalPromptInput = $this->validateAdditionalPromptInput(\n $data['additional_prompt_input'] ?? null\n );\n $customReportName = $this->validateCustomReportName($data['custom_name'] ?? null);\n\n // Prepare data for the database\n $reportData = [\n 'team_id' => $team->getId(),\n 'type' => $type,\n 'status' => $status,\n 'frequency' => $frequency,\n 'additional_prompt_input' => $additionalPromptInput,\n 'custom_name' => $customReportName,\n ];\n\n // Validate deal values\n $reportData = $this->validateDealValues($data, $reportData);\n\n // Validate date range\n $reportData = $this->validateDateRange($data, $reportData, $frequency);\n\n // Validate call durations\n $reportData = $this->validateCallDurations($data, $reportData);\n\n // Validate call types\n $reportData = $this->validateCallTypes($data, $reportData);\n\n // Validate media types\n $reportData = $this->validateMediaTypes($data, $reportData);\n\n // Validate groups\n if (isset($data['teams'])) {\n $reportData['groups'] = $this->validateAndGetGroupIds($team, $data['teams']);\n }\n\n // Validate deal stages\n $reportData = $this->validateDealStages($data, $reportData, $team, $type);\n\n // Validate playbook categories\n $reportData = $this->validatePlaybookCategories($data, $reportData, $team);\n\n // Validate recipients\n $reportData['recipients'] = [\n 'users' => $this->validateAndGetUserIdsByTeam($team, $data['recipients'] ?? []),\n ];\n\n if (isset($data['jiminny_recipients'])) {\n // Validate Jiminny recipients\n $reportData['jiminny_recipients'] = [\n 'users' => $this->validateAndGetJiminnyUserIds((array) $data['jiminny_recipients']),\n ];\n }\n\n return $reportData;\n }\n\n private function validateDealValues(array $data, array $reportData): array\n {\n if (isset($data['min_deal_value'])) {\n $reportData['deal_value_min'] = (int) $data['min_deal_value'];\n\n if ($reportData['deal_value_min'] > 4294967295 || $reportData['deal_value_min'] < 0) {\n throw new InvalidArgumentException('Min deal value should be between 0 and 4294967295');\n }\n }\n\n if (isset($data['max_deal_value'])) {\n $reportData['deal_value_max'] = (int) $data['max_deal_value'];\n\n if ($reportData['deal_value_max'] > 4294967295 || $reportData['deal_value_max'] < 0) {\n throw new InvalidArgumentException('Max deal value should be between 0 and 4294967295');\n }\n }\n\n if (isset($data['min_deal_value'], $data['max_deal_value'])\n && $data['min_deal_value'] > $data['max_deal_value']\n ) {\n throw new InvalidArgumentException('Min deal value cannot be greater than max deal value');\n }\n\n return $reportData;\n }\n\n private function validateDateRange(array $data, array $reportData, string $frequency): array\n {\n // Set date range only for one_off frequency\n if ($frequency === 'one_off') {\n if (isset($data['start_date_period'])) {\n $reportData['from'] = $this->parseDate($data['start_date_period']);\n }\n\n if (isset($data['end_date_period'])) {\n $reportData['to'] = $this->parseDate($data['end_date_period']);\n }\n\n if (empty($reportData['from']) || empty($reportData['to'])) {\n throw new InvalidArgumentException(\n 'Start date and end date are required for one_off frequency'\n );\n }\n } else {\n $reportData['from'] = null;\n $reportData['to'] = null;\n }\n\n return $reportData;\n }\n\n private function validateCallDurations(array $data, array $reportData): array\n {\n // Convert call durations from minutes to seconds\n if (isset($data['min_call_duration'])) {\n $reportData['call_duration_min'] = (int) $data['min_call_duration'] * 60;\n\n if ($reportData['call_duration_min'] > 4294967295 || $reportData['call_duration_min'] < 0) {\n throw new InvalidArgumentException('Min call duration should be between 0 and 4294967295');\n }\n }\n\n if (isset($data['max_call_duration'])) {\n $reportData['call_duration_max'] = (int) $data['max_call_duration'] * 60;\n\n if ($reportData['call_duration_max'] > 4294967295 || $reportData['call_duration_max'] < 0) {\n throw new InvalidArgumentException('Max call duration should be between 0 and 4294967295');\n }\n }\n\n return $reportData;\n }\n\n private function validateCallTypes(array $data, array $reportData): array\n {\n // Set call types\n $reportData['call_types'] = $data['call_type'] ?? [];\n if (empty($reportData['call_types'])) {\n $reportData['call_types'] = self::getCallTypes();\n }\n\n foreach ($reportData['call_types'] as $callType) {\n if (! in_array($callType, self::getCallTypes(), true)) {\n throw new InvalidArgumentException(sprintf('Call type %s is invalid', $callType));\n }\n }\n\n return $reportData;\n }\n\n private function validateMediaTypes(array $data, array $reportData): array\n {\n // Set media types from input data\n $reportData['media_types'] = $data['media_types'] ?? [];\n\n if (empty($reportData['media_types'])) {\n throw new InvalidArgumentException('Media types are required');\n }\n\n foreach ($reportData['media_types'] as $mediaType) {\n if (! in_array($mediaType, self::MEDIA_TYPES, true)) {\n throw new InvalidArgumentException(sprintf('Media type %s is invalid', $mediaType));\n }\n }\n\n return $reportData;\n }\n\n private function validateDealStages(array $data, array $reportData, Team $team, string $reportType): array\n {\n // Validate and set deal stages\n if (isset($data['deal_stage_at_call'])) {\n $reportData['deal_at_call_stages'] =\n $this->validateAndGetDealStageIds($team, $data['deal_stage_at_call'], 'Deal stage at call');\n }\n\n if (isset($data['current_deal_stage'])) {\n $reportData['current_deal_stages'] =\n $this->validateAndGetDealStageIds($team, $data['current_deal_stage'], 'Current deal stage');\n }\n\n // Ensure current_deal_stage is not provided for loss_analysis report type\n if ($reportType === self::TYPE_LOSS_ANALYSIS && ! empty($data['current_deal_stage'])) {\n throw new InvalidArgumentException('Current deal stage is not applicable for Loss Analysis reports');\n }\n\n return $reportData;\n }\n\n // transform uuid to id\n private function validatePlaybookCategories(array $data, array $reportData, Team $team): array\n {\n $key = 'playbook_categories';\n\n if (isset($data[$key])) {\n $payloadIds = $data[$key];\n $ids = [];\n\n foreach ($payloadIds as $uuid) {\n $uuid = (string) $uuid;\n\n try {\n $playbookCategory = $this->playbookCategoryRepository->findByUuid($uuid);\n } catch (Throwable $throwable) {\n Log::error(__METHOD__ . ' ' . $throwable->getMessage());\n\n throw new InvalidArgumentException(sprintf('Playbook category %s not found', $uuid));\n }\n\n if (! $playbookCategory) {\n throw new InvalidArgumentException(sprintf('Playbook category %s not found', $uuid));\n }\n\n if (! $playbookCategory->hasPlaybook()) {\n throw new InvalidArgumentException(sprintf('Playbook category %s has no playbook', $uuid));\n }\n\n if ($playbookCategory->getPlaybook()->getTeamId() !== $team->getId()) {\n throw new InvalidArgumentException(\n sprintf('Playbook category %s not found for team %s', $uuid, $team->getUuid())\n );\n }\n\n $ids[] = $playbookCategory->getId();\n }\n\n $reportData[$key] = $ids;\n }\n\n return $reportData;\n }\n\n private function validateReportStatus($status): bool\n {\n if (! in_array($status, [true, false], true)) {\n throw new InvalidArgumentException('Report status is invalid');\n }\n\n return $status;\n }\n\n private function validateReportType($type): string\n {\n if (! in_array($type, self::getTypes(), true)) {\n throw new InvalidArgumentException(sprintf('Report type is invalid: %s', $type));\n }\n\n return $type;\n }\n\n private function validateFrequency($frequency): string\n {\n if (! in_array($frequency, self::getFrequencies(), true)) {\n throw new InvalidArgumentException('Frequency is invalid');\n }\n\n return $frequency;\n }\n\n private function validateAdditionalPromptInput(?string $additionalPromptInput): ?string\n {\n if ($additionalPromptInput && strlen($additionalPromptInput) > 5000) {\n throw new InvalidArgumentException('Additional Prompt Input should be less than 5000 characters');\n }\n\n return $additionalPromptInput;\n }\n\n private function validateCustomReportName(?string $customReportName): ?string\n {\n if ($customReportName === null || $customReportName === '') {\n return null;\n }\n\n if (strlen($customReportName) > 70) {\n throw new InvalidArgumentException('Custom report name should be less than 70 characters');\n }\n\n return $customReportName;\n }\n\n private function validateOrganization(?string $organizationUuid): Team\n {\n if (! $organizationUuid) {\n throw new InvalidArgumentException('Organization is required');\n }\n\n $team = $this->teamRepository->idOrUuid($organizationUuid);\n\n if (! $team) {\n throw new InvalidArgumentException('Organization not found');\n }\n\n if (! $team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {\n throw new InvalidArgumentException('Organization does not have the Automated Reports feature');\n }\n\n return $team;\n }\n\n private function validateAndGetGroupIds(Team $team, array $teamUuids): array\n {\n $groupIds = [];\n\n foreach ($teamUuids as $uuid) {\n $group = $this->groupRepository->findByUuid($uuid);\n\n if ($group === null || $group->getTeamId() !== $team->getId()) {\n throw new InvalidArgumentException(\n sprintf('Group %s not found for team %s', $uuid, $team->getUuid())\n );\n }\n\n $groupIds[] = $group->getId();\n\n }\n\n return $groupIds;\n }\n\n private function validateAndGetDealStageIds(Team $team, array $stageUuids, string $propertyLabel): array\n {\n $stageIds = [];\n\n foreach ($stageUuids as $uuid) {\n $stage = $this->stageRepository->findByUuid($uuid);\n\n if ($stage === null || $stage->getTeamId() !== $team->getId()) {\n throw new InvalidArgumentException(\n sprintf('Stage %s not found for team %s for %s', $uuid, $team->getUuid(), $propertyLabel)\n );\n }\n\n $stageIds[] = $stage->getId();\n }\n\n return $stageIds;\n }\n\n private function validateAndGetUserIds(array $userUuids, callable $teamCheck): array\n {\n if (empty($userUuids)) {\n return [];\n }\n\n $userIds = [];\n\n foreach ($userUuids as $uuid) {\n $user = $this->userRepository->findByUuid($uuid);\n\n if (! $user || ! $user->isStatusActive()) {\n throw new InvalidArgumentException(\n sprintf('User %s not found or is not active', $uuid)\n );\n }\n\n if (! $teamCheck($user)) {\n throw new InvalidArgumentException(\n sprintf('User %s does not belong to the allowed team(s)', $uuid)\n );\n }\n\n $userIds[] = $user->getId();\n }\n\n return $userIds;\n }\n\n private function validateAndGetUserIdsByTeam(Team $team, array $userUuids): array\n {\n return $this->validateAndGetUserIds($userUuids, fn ($user) => $user->getTeamId() === $team->getId());\n }\n\n private function validateAndGetJiminnyUserIds(array $userUuids): array\n {\n $allowedTeamIds = config('kiosk.teamIds', []);\n\n return $this->validateAndGetUserIds($userUuids, fn ($user) => in_array($user->getTeamId(), $allowedTeamIds, true));\n }\n\n private function parseDate(string $dateString): string\n {\n return date('Y-m-d H:i:s', strtotime($dateString));\n }\n\n private function generateReportResultViewUrl(AutomatedReportResult $result): string\n {\n $mediaResource = $this->getReportMediaRouteResource($result);\n\n return route('ai-reports.' . $mediaResource . '.view', ['uuid' => $result->getUuid()]);\n }\n\n private function generateReportResultDownloadUrl(AutomatedReportResult $result): string\n {\n $mediaResource = $this->getReportMediaRouteResource($result);\n\n return route('ai-reports.' . $mediaResource . '.download', ['uuid' => $result->getUuid()]);\n }\n\n private function getReportMediaRouteResource(AutomatedReportResult $result): string\n {\n if ($result->getMediaType() === self::MEDIA_TYPE_PDF) {\n return self::PDF_KEY;\n } elseif ($result->getMediaType() === self::MEDIA_TYPE_PODCAST) {\n return self::AUDIO_KEY;\n }\n\n throw new \\InvalidArgumentException('Unknown media type.');\n }\n\n public function getMediaPath(AutomatedReportResult $result): ?string\n {\n $url = match ($result->getMediaType()) {\n self::MEDIA_TYPE_PDF => $result->getPdfUrl(),\n self::MEDIA_TYPE_PODCAST => $result->getPodcastAudioUrl(),\n default => null,\n };\n\n if ($url === null) {\n return null;\n }\n\n $path = parse_url(trim($url, '\"\\''), PHP_URL_PATH);\n\n return $path ?: null;\n }\n\n public function getFilenameSuffix(AutomatedReportResult $result): ?string\n {\n return match ($result->getMediaType()) {\n self::MEDIA_TYPE_PODCAST => 'Podcast',\n default => null,\n };\n }\n\n public function getMailSubjectSuffix(AutomatedReportResult $result): string\n {\n return match ($result->getMediaType()) {\n self::MEDIA_TYPE_PDF => 'report',\n self::MEDIA_TYPE_PODCAST => 'podcast',\n default => '',\n };\n }\n\n public function getMediaTypeMetadata(AutomatedReportResult $result): array\n {\n return match ($result->getMediaType()) {\n self::MEDIA_TYPE_PODCAST => ['extension' => 'mp3', 'mime' => 'audio/mpeg'],\n self::MEDIA_TYPE_PDF => ['extension' => 'pdf', 'mime' => 'application/pdf'],\n default => ['extension' => null, 'mime' => null],\n };\n }\n\n public function deleteS3Files(AutomatedReportResult $result): void\n {\n $teamUuid = $result->getReport()->getTeam()->getUuid();\n $reportUuid = $result->getUuid();\n\n // delete all files for a report uuid no mather of pdf, podcast, or both\n // in case of both - the podcast files are linked to the pdf (parent) uuid\n // pdf and podcast date times should be close\n $path = sprintf('%s/%s/%s', $teamUuid, self::S3_DIR, $reportUuid);\n\n foreach (self::FILE_EXTENSIONS_VARIANTS as $extension) {\n $file = $path . '.' . $extension;\n\n if (Storage::exists($file)) {\n Storage::delete($file);\n Log::info('[Reports] Deleted S3 file', [\n 'path' => $file,\n ]);\n }\n }\n\n foreach (self::FILE_PODCAST_EXTENSIONS_VARIANTS as $extension) {\n $file = $path . '_podcast.' . $extension;\n\n if (Storage::exists($file)) {\n Storage::delete($file);\n Log::info('[Reports] Deleted Podcast S3 file', [\n 'path' => $file,\n ]);\n }\n }\n }\n\n /**\n *\n * @param int|null $teamId Optional team ID to filter results\n *\n * @return Collection<int, int> Collection of team IDs\n */\n public function getTeamIdsWithReportsResults(?int $teamId = null): Collection\n {\n return $this->automatedReportsRepository->getTeamIdsWithReportsResults($teamId);\n }\n\n /**\n * Core delete logic for report results using a query\n *\n * @param Builder $query\n * @param array $logContext\n *\n * @return int\n */\n private function deleteReportResultsByQuery(Builder $query, array $logContext = []): int\n {\n $deletedCount = 0;\n\n if ($query->exists()) {\n Log::info(\n 'Run delete report results',\n array_merge(\n $logContext,\n [\n 'service' => 'AutomatedReportsService',\n ]\n )\n );\n\n $query->chunkById(50, function ($results) use (&$deletedCount, $logContext) {\n foreach ($results as $result) {\n $this->deleteReportResult($result);\n $deletedCount++;\n\n Log::info(\n 'Deleted a report result',\n array_merge(\n $logContext,\n [\n 'result_id' => $result->getId(),\n 'report_id' => $result->getReportId(),\n ]\n )\n );\n }\n });\n }\n\n return $deletedCount;\n }\n\n /**\n * Delete report results for a team by retention period\n *\n * @param Team $team\n * @param CarbonImmutable $retentionDate\n *\n * @return int Number of deleted report results\n */\n public function deleteReportsResultsInRetentionPeriod(Team $team, CarbonImmutable $retentionDate): int\n {\n $reportIds = $this->automatedReportsRepository->getReportIdsByTeam($team);\n\n if ($reportIds->isEmpty()) {\n return 0;\n }\n\n $query = $this->automatedReportsRepository\n ->getReportResultsQueryForRetention($team, $retentionDate);\n\n return $this->deleteReportResultsByQuery($query, [\n 'team_id' => $team->getId(),\n 'retention_date' => $retentionDate->toDateTimeString(),\n ]);\n }\n\n /**\n * Delete ALL report results for a specific automated report\n *\n * @param string $uuid\n *\n * @return int\n */\n public function deleteReportResults(string $uuid): int\n {\n $report = $this->getReport($uuid);\n\n $query = $this->automatedReportsRepository->getResultsByReportQuery($report);\n\n return $this->deleteReportResultsByQuery($query, [\n 'report_uuid' => $uuid,\n 'report_id' => $report->getId(),\n ]);\n }\n\n public function deleteReportResult(AutomatedReportResult $result): void\n {\n $this->deleteS3Files($result);\n\n $result->delete();\n }\n\n /**\n * Get all reports for a specific team\n *\n * @param Team $team\n *\n * @return \\Illuminate\\Database\\Eloquent\\Collection\n */\n public function getTeamReports(Team $team): \\Illuminate\\Database\\Eloquent\\Collection\n {\n return $this->automatedReportsRepository->getReportsByTeam($team);\n }\n\n /**\n * Get all report results for a specific report\n *\n * @param AutomatedReport $report\n *\n * @return \\Illuminate\\Database\\Eloquent\\Collection\n */\n public function getReportResults(AutomatedReport $report): \\Illuminate\\Database\\Eloquent\\Collection\n {\n return $this->automatedReportsRepository->getResultsByReport($report);\n }\n\n public function deleteAllReportResults(AutomatedReport $report): void\n {\n $results = $this->getReportResults($report);\n\n /** @var AutomatedReportResult $result */\n foreach ($results as $result) {\n Log::info('Deleting result', [\n 'report' => $report->getId(),\n 'result' => $result->getId(),\n ]);\n\n $this->deleteReportResult($result);\n }\n }\n\n public function deleteAllData(Team $team): void\n {\n Log::info('Deleting automated report and results for team', [\n 'team' => $team->getId(),\n ]);\n\n $reports = $this->getTeamReports($team);\n\n /** @var AutomatedReport $report */\n foreach ($reports as $report) {\n Log::info('Deleting report', [\n 'team' => $team->getId(),\n 'report' => $report->getId(),\n ]);\n\n $this->deleteAllReportResults($report);\n\n $report->delete();\n }\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":true,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"Project","depth":3,"role_description":"text"},{"role":"AXButton","text":"Project","depth":3,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"New File or Directory…","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Expand Selected","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Collapse All","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Options","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false}]...
|
3397592283435315795
|
6686367547760219213
|
idle
|
accessibility
|
NULL
|
Project: faVsco.js, menu
#11894 on JY-18909-automa Project: faVsco.js, menu
#11894 on JY-18909-automated-reports-ask-jiminny, menu
Start Listening for PHP Debug Connections
AutomatedReportsCommandTest
Run 'AutomatedReportsCommandTest'
Debug 'AutomatedReportsCommandTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Execute
Explain Plan
Browse Query History
View Parameters
Open Query Execution Settings…
In-Editor Results
Tx: Auto
Cancel Running Statements
Playground
jiminny
Sync Changes
Hide This Notification
Code changed:
Hide
16
13
13
Previous Highlighted Error
Next Highlighted Error
SELECT * FROM teams WHERE id = 1;
select * from crm_layouts where crm_configuration_id = 39;
SELECT * FROM crm_layout_entities WHERE crm_layout_id = 283;
SELECT * FROM crm_fields WHERE id = 2234;
SELECT * FROM crm_field_values WHERE crm_field_id = 2234;
select * from crm_profiles where user_id = 143;
select * from record_types where crm_configuration_id = 39; # 0121K000001MHElQAO,0121K000001MHEqQAO
select * from business_processes where crm_configuration_id = 39;
# 01941000000H669AAC, 01941000000H66JAAS
select * from record_type_field_values
where record_type_id IN (24);
select * from crm_field_values where id IN (2730);
select * from crm_configurations where id = 39;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 1
and sa.provider = 'salesforce'; #1035
select * from users where team_id = 1; # 222 group 3
SELECT * FROM activities WHERE user_id = 222 order by id desc;
select * from sidekick_settings where team_id = 1;
select * from teams where id = 1;
select * from team_features where team_id = 1;
select * from activities where crm_configuration_id = 2
and provider = 'ms-teams' and id = 608765;
SELECT * FROM activities WHERE crm_configuration_id = 2 and crm_provider_id = '59523413338';
select * from sidekick_settings where team_id = 2;
SELECT * FROM activities WHERE id = 608660;
select * from activity_summary_logs where activity_id = 608660;
select * from ai_prompts where transcription_id = 11214;
# [PASSWORD_DOTS]
SELECT * FROM activities WHERE uuid_to_bin('ed78a437-2804-450e-ab2f-56ab1c641346') = uuid;
# id: 608818, crm: 59628809737
SELECT * FROM activities WHERE uuid_to_bin('36b06e55-afdd-4782-8dee-c624cd0af191') = uuid;
# id: 608821, crm: 59632069252
SELECT ce.start_time, ce.end_time, a.id, a.uuid, crm_provider_id, calendar_event_id, title,
playbook_category_id, user_id, lead_id, contact_id, account_id, opportunity_id,
scheduled_start_time, scheduled_end_time, actual_start_time, actual_end_time, a.created_at
FROM activities a
join calendar_events ce on a.calendar_event_id = ce.id
WHERE a.id IN (608818, 608821);
select * from users where team_id = 1;
select * from team_settings where team_id = 1;
select * from crm_profiles where crm_configuration_id = 39 order by user_id;
select * from team_features where team_id = 1;
select * from users where team_id = 2;
SELECT * FROM activities WHERE uuid_to_bin('ec7647e9-5225-458b-b475-f31aa2769204') = uuid; # 612639
# Preslava N. Ivanova, grou id 3
SELECT * FROM opportunities WHERE uuid_to_bin('a2928fe5-aec5-46cb-85d9-7654c89e46a6') = uuid;
select * from activities where opportunity_id = 344 and actual_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00';
select
a.id,
a.type,
a.scheduled_start_time,
a.actual_start_time,
a.created_at,
a.opportunity_id,
a.status
FROM activities a
WHERE opportunity_id = 344
and status IN ('completed', 'received', 'delivered')
and (
(a.actual_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00')
OR (a.created_at between '2024-10-11 00:00:00' and '2024-10-12 00:00:00')
OR (a.scheduled_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00'))
;
SELECT * FROM users WHERE id = 222;
SELECT * FROM crm_profiles WHERE user_id = 222;
select * from crm_layouts where crm_configuration_id = 39;
SELECT * FROM crm_layout_entities WHERE crm_layout_id = 281;
select * from group_deal_risk_types;
select * from opportunities where team_id = 1;
SELECT * FROM opportunities WHERE id = 315;
SELECT * FROM crm_field_data WHERE object_id = 315;
select * from crm_field_data where object_id = 260;
select * from generic_ai_prompts where subject_id = 315;
select * from teams; # 36, 21, 121, [EMAIL]
SELECT * FROM social_accounts WHERE sociable_id = 121 and provider = 'bullhorn';
# [PASSWORD_DOTS]
select * from teams where id = 1;
select * from crm_configurations where id = 39;
select * from users where team_id = 1;
select u.email, cp.* from users u
join crm_profiles cp on u.id = cp.user_id
where u.team_id = 1;
# 1 - 00541000004281rAAA
# 204 - 0052g000003freeAAA
# 429 - 0052g000003qGOiAAM
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 1
and sa.provider = 'salesforce';
select * from activities where type = 'softphone'
and created_at > '2024-12-11 15:24:36' order by id desc;
select * from activity_providers where team_id = 1;
select * from activity_provider_users where activity_provider_id = 328;
select * from opportunities where crm_configuration_id = 39
AND account_id = 178 AND is_closed = false
order by created_at DESC;
select * from contacts where id = 3952;
select * from accounts where id = 178;
# [PASSWORD_DOTS]
select * from teams where id = 36;
select * from crm_configurations where id = 21;
select * from users where team_id = 36;
select u.email, cp.* from users u
join crm_profiles cp on u.id = cp.user_id
where u.team_id = 36;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 36
and sa.provider = 'bullhorn';
select * from social_accounts where id = 348;
UPDATE social_accounts SET
provider_user_token = '21442_6802599_91:41179a58-21e7-4d7c-ad58-56bb666b2f65',
provider_refresh_token = '21442_6802599_91:01c6b335-3f2a-42e4-85ff-8a08fa65fceb',
expires = 1733998131,
state = 'connected'
WHERE id = 348;
# [PASSWORD_DOTS]
select * from teams where id = 31;
select * from crm_configurations where id = 18;
select * from users where team_id = 31; # 257
select u.email, cp.* from users u
join crm_profiles cp on u.id = cp.user_id
where u.team_id = 31;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 31
and sa.provider = 'close';
select * from contacts where crm_configuration_id = 18;
# [PASSWORD_DOTS] NEPTUNE [PASSWORD_DOTS]
select * from teams;
select * from users where id IN (1030, 1035, 1052);
select * from crm_configurations;
select * from users where team_id = 65; # 257
select * from team_settings where team_id = 65; # 257
select * from invitations where team_id = 65; # 257
select * from users where email = '[EMAIL]'; # 257
select u.email, cp.* from users u
join crm_profiles cp on u.id = cp.user_id
where u.team_id = 65;
select * from crm_configurations where id = 53;
select * from accounts where crm_configuration_id = 53 order by id desc;
select * from leads where crm_configuration_id = 53 order by id desc;
select * from contacts where crm_configuration_id = 53 order by id desc;
select * from opportunities where crm_configuration_id = 53 order by id desc;
select * from crm_profiles where crm_configuration_id = 53 order by id desc;
select * from crm_fields where crm_configuration_id = 53 order by id desc;
select * from crm_field_values where crm_field_id = 3341 order by id desc;
select * from crm_layouts where crm_configuration_id = 53 order by id desc;
select * from stages where crm_configuration_id = 53 order by id desc;
select * from crm_profiles where crm_configuration_id = 13;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 65
and sa.provider = 'integration-app';
select * from contacts where crm_configuration_id = 13;
select * from social_accounts where sociable_id = 283;
SELECT * FROM opportunities WHERE crm_provider_id = '006O400000E9bzeIAB';
select * from activity_providers where team_id = 65;
SELECT * FROM activities WHERE crm_configuration_id IN (51, 52, 53);
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 65
;
# [PASSWORD_DOTS] STAGING [PASSWORD_DOTS]
SELECT * FROM teams;
SELECT * FROM teams WHERE id = 88;
SELECT * FROM teams WHERE id = 89;
select * from team_settings where team_id = 89;
SELECT * FROM users WHERE team_id = 89;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 89;
select * from users;
SELECT * FROM social_accounts WHERE sociable_id = 1761;
SELECT * FROM crm_configurations WHERE id = 70;
select * from accounts where crm_configuration_id = 70 order by id desc;
select * from leads where crm_configuration_id = 70 order by id desc;
select * from contacts where crm_configuration_id = 70 order by id desc;
select * from opportunities where crm_configuration_id = 70 order by id desc;
select * from crm_profiles where crm_configuration_id = 70 order by id desc;
select * from crm_fields where crm_configuration_id = 70 order by id desc;
select * from crm_field_values where crm_field_id = 3536 order by id desc;
select * from crm_layouts where crm_configuration_id = 70 order by id desc;
select * from stages where crm_configuration_id = 70 order by id desc;
select * from business_processes where crm_configuration_id = 70 order by id desc;
select * from business_process_stages where business_process_id = 34;
select * from contacts where id = 10468;
select * from crm_layouts where crm_configuration_id = 70;
SELECT * FROM crm_layout_entities WHERE crm_layout_id = 388;
SELECT * FROM crm_fields WHERE id IN (3533,3534,3535);
select * from activities where crm_configuration_id = 70
and (account_id IS NOT NULL or lead_id IS NOT NULL or contact_id IS NOT NULL or opportunity_id IS NOT NULL) order by id desc;
SELECT * FROM activities WHERE uuid_to_bin('2e10b60f-8a61-41c5-a3d4-28835353dc65') = uuid;
SELECT * FROM activities where crm_configuration_id = 69 ;
SELECT * FROM users WHERE email LIKE '%[EMAIL]%';
SELECT * FROM activities WHERE uuid_to_bin('5a150c93-40fc-42ec-b3bd-c1d328e09f6e') = uuid;
SELECT * FROM opportunities WHERE id = 385;
select * from participants p
join activities a on p.activity_id = a.id
where a.crm_configuration_id = 70
and (p.lead_id IS NOT NULL or p.contact_id IS NOT NULL);
SELECT * FROM participants WHERE id = 1013638;
select * from teams where id = 90;
select * from users where team_id = 90;
select * from social_accounts where social_accounts.sociable_id IN (1960,1760);
SELECT * FROM crm_profiles WHERE crm_configuration_id = 71;
select * from invitations where team_id = 90;
select * from crm_configurations where id = 71;
select * from accounts where crm_configuration_id = 71 order by id desc;
select * from leads where crm_configuration_id = 71 order by id desc;
select * from contacts where crm_configuration_id = 71 order by id desc;
select * from opportunities where crm_configuration_id = 71 order by id desc;
select * from crm_profiles where crm_configuration_id = 71 order by id desc;
select * from crm_fields where crm_configuration_id = 71 order by id desc;
select * from crm_field_values where crm_field_id = 3341 order by id desc;
select * from crm_layouts where crm_configuration_id = 71 order by id desc;
select * from stages where crm_configuration_id = 71 order by id desc;
select * from users order by secondary_email desc;
select u.id, u.email, u.status, sa.id, sa.provider_user_id from social_accounts sa
join users u on sa.sociable_id = u.id
where sa.provider = 'google' and u.email LIKE 'aneliya%';
select * from failed_jobs order by id desc;
select * from users where email = '[EMAIL]' or secondary_email = '[EMAIL]';
select * from teams;
SELECT * FROM crm_profiles WHERE crm_configuration_id = 39;
SELECT * FROM crm_fields WHERE crm_configuration_id = 39 and object_type = 'task';
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 1
and sa.provider = 'salesforce';
# [PASSWORD_DOTS]
SELECT * FROM activities WHERE uuid_to_bin('c38b3895-fd0f-4b1f-9fb2-c170dba137c6') = uuid;
SELECT * FROM crm_configurations WHERE id = 70;
select * from teams where id = 1;
select * from groups where team_id = 1;
select * from users where team_id = 1;
select o.id, o.name,o.close_date, u.id, u.name, u.group_id, r.id, r.display_name, g.name, g.scope from opportunities o
join users u on o.user_id = u.id
join groups g on u.group_id = g.id
join role_user ru on u.id = ru.user_id
join roles r on ru.role_id = r.id
where o.crm_configuration_id = 39 and close_date > '2024-01-01 00:00:00';
select * from role_user where user_id = 143;
select * from roles;
select * from role_user;
select * from groups where id = 9;
select * from scope_groups where group_id = 9;
# [PASSWORD_DOTS]
select * from teams where id = 36;
select * from crm_configurations;
SELECT * FROM social_accounts WHERE sociable_id = 121;
[URL_WITH_CREDENTIALS] this will add filter, however if we need to control feature by FF we need conditional logic
public const array TYPES = [
['id' => 'exec_summary', 'name' => 'Exec Summary'],
['id' => 'coaching_profiles', 'name' => 'Coaching Profiles'],
['id' => 'product_feedback', 'name' => 'Product Feedback'],
['id' => self::TYPE_LOSS_ANALYSIS, 'name' => 'Loss Analysis'],
// ['id' => 'questions', 'name' => 'Questions'],
// ['id' => 'statistical_quant', 'name' => 'Statistical Quantitative'],
];
public const array ALL_TYPES = [
...self::TYPES,
['id' => self::TYPE_ASK_JIMINNY, 'name' => 'Ask Jiminny'],
];
public const string FREQUENCY_DAILY = 'daily';
public const string FREQUENCY_WEEKLY = 'weekly';
public const string FREQUENCY_MONTHLY = 'monthly';
public const string FREQUENCY_QUARTERLY = 'quarterly';
public const string FREQUENCY_ONE_OFF = 'one_off';
/**
* Frequencies for standard (non-Ask Jiminny) reports.
*/
public const array FREQUENCIES = [
['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],
['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],
['id' => self::FREQUENCY_QUARTERLY, 'name' => 'Quarterly'],
['id' => self::FREQUENCY_ONE_OFF, 'name' => 'One-off'],
];
/**
* Frequencies for Ask Jiminny reports.
*/
public const array ASK_JIMINNY_FREQUENCIES = [
['id' => self::FREQUENCY_DAILY, 'name' => 'Daily'],
['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],
['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],
];
public const string MEDIA_TYPE_PDF = 'pdf';
public const string MEDIA_TYPE_PODCAST = 'podcast';
public const array MEDIA_TYPES = [self::MEDIA_TYPE_PDF, self::MEDIA_TYPE_PODCAST];
public const array MEDIA_TYPE_OBJECT_PDF = ['id' => self::MEDIA_TYPE_PDF, 'name' => 'PDF'];
public const array MEDIA_TYPE_OBJECT_PODCAST = ['id' => self::MEDIA_TYPE_PODCAST, 'name' => 'Podcast'];
public const array MEDIA_TYPE_OBJECTS = [self::MEDIA_TYPE_OBJECT_PDF, self::MEDIA_TYPE_OBJECT_PODCAST];
public const array CALL_TYPE_CONFERENCE = ['id' => 'conference', 'name' => 'Conference'];
public const array CALL_TYPE_DIALER = ['id' => 'dialer', 'name' => 'Dialer'];
public const int SENT_REPORT_AT_HOURS = 5;
public const string PDF_KEY = 'pdf';
public const string AUDIO_KEY = 'audio';
private const array ALL_FREQUENCIES = [
['id' => self::FREQUENCY_DAILY, 'name' => 'Daily'],
['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],
['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],
['id' => self::FREQUENCY_QUARTERLY, 'name' => 'Quarterly'],
['id' => self::FREQUENCY_ONE_OFF, 'name' => 'One-off'],
];
private const string S3_DIR = 'reports';
private const array FILE_EXTENSIONS_VARIANTS = ['html', 'MD', 'pdf'];
private const array FILE_PODCAST_EXTENSIONS_VARIANTS = ['json', 'mp3', 'ssml'];
public function __construct(
private readonly TeamRepository $teamRepository,
private readonly GroupRepository $groupRepository,
private readonly UserRepository $userRepository,
private readonly StageRepository $stageRepository,
private readonly DealStagesService $dealStagesService,
private readonly RecipientsService $recipientsService,
private readonly AutomatedReportsRepository $automatedReportsRepository,
private readonly Webhook $webhookService,
private readonly BusDispatcher $dispatcher,
private readonly ActivityTypeService $activityTypeService,
private readonly PlaybookCategoryRepository $playbookCategoryRepository,
private readonly AskAnythingPromptService $askAnythingPromptService,
private readonly SearchRepository $activitySearchRepository,
private readonly AskAnythingRepository $askAnythingRepository,
) {
}
public static function getTypes(): array
{
$types = self::TYPES;
return array_map(static function ($type) {
return $type['id'];
}, $types);
}
public static function getCallTypes(): array
{
return array_map(static function ($callType) {
return $callType['id'];
}, [self::CALL_TYPE_CONFERENCE, self::CALL_TYPE_DIALER]);
}
public static function getFrequencies(): array
{
return array_map(static function ($frequency) {
return $frequency['id'];
}, self::FREQUENCIES);
}
// front-facing structure
public function getReportEnabledFieldData(bool $value = false): array
{
return [
'id' => 'report_enabled',
'label' => '',
'inputType' => InputTypeEnum::TOGGLE,
'value' => $value,
];
}
// Organizations = Teams
public function getOrganizationFieldData(?string $value = null, bool $shortVersion = false): array
{
$options = $this->getTeams();
if ($shortVersion) {
return [
'id' => 'organization',
'label' => 'Organization',
'options' => $options,
];
}
return [
'id' => 'organization',
'label' => 'Organization',
'inputType' => InputTypeEnum::DROPDOWN,
'required' => true,
'placeholder' => 'Select',
'options' => $options,
'value' => $value,
'dependencies' => [
'teams',
'deal_stage_at_call',
'current_deal_stage',
'recipients',
ActivityTypeService::PLAYBOOK_CATEGORIES_KEY,
],
'dependsOn' => [],
];
}
// Teams = Groups
public function getTeamFieldData(array $options = [], array $value = [], bool $shortVersion = false): array
{
if ($shortVersion) {
return [
'id' => 'teams',
'label' => 'Team',
'options' => $options,
];
}
return [
'id' => 'teams',
'label' => 'Team',
'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,
'required' => false,
'placeholder' => 'Select',
'options' => $options,
'value' => $value, // value should be an array of objects {id, name}
'dependencies' => [ActivityTypeService::PLAYBOOK_CATEGORIES_KEY],
'dependsOn' => [],
];
}
public function getReportTypeFieldData(?string $value = null, bool $shortVersion = false, ?Team $team = null): array
{
$types = [];
if ($team instanceof Team) {
if ($team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {
$types = self::TYPES;
}
if ($team->hasFeature(FeatureEnum::ASK_JIMINNY_REPORTS)) {
$types[] = ['id' => self::TYPE_ASK_JIMINNY, 'name' => 'Ask Jiminny'];
}
} else {
$types = self::TYPES;
}
if ($shortVersion) {
return [
'id' => 'report_type',
'label' => 'Report Type',
'options' => $types,
];
}
return [
'id' => 'report_type',
'label' => 'Report Type',
'inputType' => InputTypeEnum::DROPDOWN,
'required' => true,
'placeholder' => 'Select',
'options' => $types,
'value' => $value,
'dependencies' => [],
'dependsOn' => [],
];
}
public function getFrequencyFieldData(?string $value = null): array
{
return [
'id' => 'frequency',
'label' => 'Frequency',
'inputType' => InputTypeEnum::DROPDOWN,
'required' => true,
'placeholder' => 'Select',
'options' => self::FREQUENCIES,
'value' => $value,
'dependencies' => ['period'],
'dependsOn' => [],
];
}
public function getPeriodFieldData(?string $valueStartDate = null, ?string $valueEndDate = null): array
{
return [
'id' => 'period',
'label' => 'Select one-off period',
'inputType' => InputTypeEnum::DATE_RANGE,
'required' => true,
'placeholder' => 'Select',
'value' => ['startDate' => $valueStartDate, 'endDate' => $valueEndDate],
'queryParams' => [
'startDate' => 'start_date_period',
'endDate' => 'end_date_period',
],
'dependencies' => [],
'dependsOn' => ['frequency'],
];
}
public function getActivityTypesFieldData(?Team $team = null, array $value = [], array $teamsFilter = []): array
{
return $this->activityTypeService->getActivityTypeFieldData(team: $team, value: $value, groupIds: $teamsFilter);
}
public function getDealStageAtCallFieldData(?Team $team = null, array $value = []): array
{
return $this->dealStagesService->getDealStageAtCallFieldData(team: $team, value: $value);
}
public function getCurrentDealStageFieldData(?Team $team = null, array $value = []): array
{
return $this->dealStagesService->getCurrentDealStageFieldData(team: $team, value: $value);
}
public function getDealValueFieldData(?int $valueMin = null, ?int $valueMax = null): array
{
return [
'id' => 'deal_value',
'label' => 'Deal Value',
'inputType' => InputTypeEnum::INTEGER_RANGE,
'required' => false,
'value' => ['min' => $valueMin, 'max' => $valueMax],
'queryParams' => [
'min' => 'min_deal_value',
'max' => 'max_deal_value',
],
'dependencies' => [],
'dependsOn' => [],
];
}
public function getCallTypeFieldData(bool $conferenceOn = false, bool $dialerOn = false): array
{
$value = [];
$conferenceOn && $value[] = self::CALL_TYPE_CONFERENCE;
$dialerOn && $value[] = self::CALL_TYPE_DIALER;
return [
'id' => 'call_type',
'label' => 'Call Type',
'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,
'required' => true,
'options' => [
self::CALL_TYPE_CONFERENCE,
self::CALL_TYPE_DIALER,
],
'value' => $value,
'dependencies' => [],
'dependsOn' => [],
];
}
public function getMediaTypeFieldData(?AutomatedReport $report = null): array
{
$value = [];
if ($report) {
$value = $this->transformMediaTypes($report);
}
return [
'id' => 'media_types',
'label' => 'Export as',
'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,
'required' => true,
'options' => self::MEDIA_TYPE_OBJECTS,
'value' => $value,
'dependencies' => [],
'dependsOn' => [],
];
}
public function getCallDurationFieldData(?int $valueMin = null, ?int $valueMax = null): array
{
return [
'id' => 'call_duration',
'label' => 'Call Duration',
'inputType' => InputTypeEnum::INTEGER_RANGE,
'required' => false,
'value' => ['min' => $valueMin, 'max' => $valueMax],
'queryParams' => [
'min' => 'min_call_duration',
'max' => 'max_call_duration',
],
'dependencies' => [],
'dependsOn' => [],
];
}
public function getRecipientsFieldData(?Team $team = null, array $value = []): array
{
return $this->recipientsService->getRecipientsFieldData(team: $team, value: $value);
}
public function getJiminnyRecipientsFieldData(array $value = []): array
{
return $this->recipientsService->getJiminnyRecipientsFieldData($value);
}
public function getAdditionalPromptInputFieldData(?string $value = null): array
{
return [
'id' => 'additional_prompt_input',
'label' => 'Special requirements',
'inputType' => InputTypeEnum::TEXTAREA,
'required' => false,
'placeholder' => 'What should be the focus of the report?',
'value' => $value,
'dependencies' => [],
'dependsOn' => [],
];
}
public function getCustomReportNameFieldData(?string $value = null): array
{
return [
'id' => 'custom_name',
'label' => 'Custom report name',
'inputType' => InputTypeEnum::TEXT,
'required' => false,
'placeholder' => 'Enter custom name',
'value' => $value,
'dependencies' => [],
'dependsOn' => [],
];
}
// data providers
public function getTeams(): array
{
$teams = $this->teamRepository->getTeamsForKiosk(status: Team::STATUS_ACTIVE);
$teamData = [];
foreach ($teams as $team) {
if (! $team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {
continue;
}
$teamData[] = $this->transformTeam($team);
}
return $teamData;
}
public function getTeamGroups(string $teamUuid): array
{
$data = [];
$team = $this->getTeam($teamUuid);
if ($team !== null) {
$groups = $team->groups()->get();
foreach ($groups as $group) {
$data[] = [
'id' => $group->getUuid(),
'name' => $group->getName(),
];
}
}
return $data;
}
public function getTeamsGroupsOptions(array $filterTeamUuids = []): array
{
$data = [];
$teams = $this->getTeams();
foreach ($teams as $team) {
if (! empty($filterTeamUuids) && ! in_array($team['id'], $filterTeamUuids, true)) {
continue;
}
$data[] = [
'label' => $team['name'],
'groups' => $this->getTeamGroups($team['id']),
];
}
return $data;
}
public function getTeam(string $teamUuid): ?Team
{
return $this->teamRepository->idOrUuid($teamUuid);
}
public function getTeamById(int $teamId): ?Team
{
return $this->teamRepository->find($teamId);
}
public function getGroupsUuids(AutomatedReport $report): array
{
$uuids = [];
$reportGroups = $report->getGroups();
foreach ($reportGroups as $groupId) {
if ($group = $this->groupRepository->find($groupId)) {
$uuids[] = $group->getUuid();
}
}
return $uuids;
}
public function getPlaybookCategoriesUuids(AutomatedReport $report): array
{
$uuids = [];
$playbookCategories = $report->getPlaybookCategories();
foreach ($playbookCategories as $id) {
if ($category = $this->playbookCategoryRepository->find($id)) {
$uuids[] = $category->getUuid();
}
}
return $uuids;
}
public function getDealAtCallStagesUuids(AutomatedReport $report): array
{
$uuids = [];
$reportStages = $report->getDealAtCallStages();
foreach ($reportStages as $id) {
if ($stage = $this->stageRepository->find($id)) {
$uuids[] = $stage->getUuid();
}
}
return $uuids;
}
public function getCurrentDealStagesUuids(AutomatedReport $report): array
{
$uuids = [];
$reportStages = $report->getCurrentDealStages();
foreach ($reportStages as $id) {
if ($stage = $this->stageRepository->find($id)) {
$uuids[] = $stage->getUuid();
}
}
return $uuids;
}
public function getUsersUuids(AutomatedReport $report): array
{
return $this->extractUserUuids($report->getRecipients());
}
public function getJiminnyUsersUuids(AutomatedReport $report): array
{
return $this->extractUserUuids($report->getJiminnyRecipients());
}
/**
* @param array<string, mixed> $recipients
*/
private function extractUserUuids(array $recipients): array
{
$userIds = $recipients['users'] ?? [];
return collect($userIds)
->map(fn ($id) => $this->userRepository->find((int) $id))
->filter()
->map(fn (UserContract $user) => $user->getUuid())
->values()
->all();
}
// get mail data
public function getRecipientUsers(AutomatedReport $report): array
{
return $this->buildRecipientUsers($report->getRecipients());
}
private function getJiminnyRecipientUsers(AutomatedReport $report): array
{
return $this->buildRecipientUsers($report->getJiminnyRecipients());
}
/**
* @param array<string, mixed> $recipients
*/
private function buildRecipientUsers(array $recipients): array
{
$userIds = $recipients['users'] ?? [];
return collect($userIds)
->map(fn ($id) => $this->userRepository->find((int) $id))
->filter()
->map(fn (UserContract $user) => [
'email' => $user->getEmailAddress(),
'name' => $user->getName(),
'timezone' => $user->getTimezone()->getName(),
])
->values()
->all();
}
public function getValidRecipientUsers(AutomatedReport $report, bool $includeJiminny = false): array
{
if ($report->isAskJiminnyReport()) {
$recipients = $this->resolveAskJiminnyRecipients($report);
} else {
$recipients = $this->getRecipientUsers($report);
if ($includeJiminny) {
$recipients = array_merge($recipients, $this->getJiminnyRecipientUsers($report));
}
}
$emails = [];
return array_values(array_filter(
$recipients,
static function ($recipient) use (&$emails) {
if (empty($recipient['email']) || in_array($recipient['email'], $emails, true)) {
return false;
}
$emails[] = $recipient['email'];
return true;
}
));
}
private function resolveAskJiminnyRecipients(AutomatedReport $report): array
{
$recipients = [];
$creator = $report->getCreator();
if ($creator !== null) {
$recipients[] = [
'email' => $creator->getEmailAddress(),
'name' => $creator->getName(),
'timezone' => $creator->getTimezone()->getName(),
];
}
return array_merge(
$recipients,
$this->buildRecipientUsers($report->getRecipients()),
$this->getGroupRecipientUsers($report),
);
}
private function getGroupRecipientUsers(AutomatedReport $report): array
{
$users = [];
foreach ($report->getGroups() as $groupId) {
$group = $this->groupRepository->find($groupId);
if ($group === null) {
continue;
}
foreach ($group->getMembers() as $member) {
$users[] = [
'email' => $member->getEmailAddress(),
'name' => $member->getName(),
'timezone' => $member->getTimezone()->getName(),
];
}
}
return $users;
}
public function getReportTypeName(AutomatedReportResult $report): string
{
$type = $report->getReport()->getType();
$getType = $this->transformReportType($type);
return $getType['name'];
}
public function getReportPeriodName(AutomatedReportResult $report): string
{
$from = $report->getFromDate();
$to = $report->getToDate();
$frequency = $report->getReport()->getFrequency();
if ($from === null || $to === null) {
if (! $report->getReport()->isAskJiminnyReport()) {
$invalidPeriod = $from === null ? 'from' : 'to';
throw new ApplicationException('Report period is invalid: ' . $invalidPeriod);
}
$period = $this->calculateFromAndToDatePeriod($frequency);
$from = $period['fromDate'];
$to = $period['toDate'];
}
return $this->formatReportPeriodName($frequency, $from, $to);
}
private function formatReportPeriodName(string $frequency, Carbon $from, Carbon $to): string
{
$fromYear = $from->format('Y');
$toYear = $to->format('Y');
$differentYears = $fromYear !== $toYear;
switch ($frequency) {
case self::FREQUENCY_DAILY:
return $from->format('j M Y');
case self::FREQUENCY_QUARTERLY:
// 'Jan-Mar 2025' or 'Nov 2024-Jan 2025' if years differ
$startMonth = $from->format('M');
$endMonth = $to->copy()->subMonth();
$endMonthName = $endMonth->format('M');
$endMonthYear = $endMonth->format('Y');
if ($differentYears) {
return "{$startMonth} {$fromYear} - {$endMonthName} {$endMonthYear}";
}
return "{$startMonth} - {$endMonthName} {$toYear}";
case self::FREQUENCY_MONTHLY:
// 'May 2025' - monthly reports are always within the same year
return $from->format('M Y');
case self::FREQUENCY_WEEKLY:
// '4 - 8 Aug 2025', '27 Oct - 3 Nov 2025', or '28 Dec 2024 - 3 Jan 2025' if years differ
$startDay = $from->format('j');
$endDay = $to->format('j');
$startMonth = $from->format('M');
$endMonth = $to->format('M');
if ($differentYears) {
return "{$startDay} {$startMonth} {$fromYear} - {$endDay} {$endMonth} {$toYear}";
}
if ($startMonth !== $endMonth) {
return "{$startDay} {$startMonth} - {$endDay} {$endMonth} {$toYear}";
}
return "{$startDay} - {$endDay} {$endMonth} {$toYear}";
case self::FREQUENCY_ONE_OFF:
// '2 May-31 May 2025' or '15 Dec 2024-15 Jan 2025' if years differ
$startDay = $from->format('j');
$startMonth = $from->format('M');
$endDay = $to->format('j');
$endMonth = $to->format('M');
// If same month and year, use a format like '2-31 May 2025'
if ($startMonth === $endMonth && ! $differentYears) {
return "{$startDay} - {$endDay} {$startMonth} {$toYear}";
}
// If different years, include both years
if ($differentYears) {
return "{$startDay} {$startMonth} {$fromYear} - {$endDay} {$endMonth} {$toYear}";
}
// Same year but different months
return "{$startDay} {$startMonth} - {$endDay} {$endMonth} {$toYear}";
default:
// Default format for unknown frequencies
return $from->format('j M Y') . ' - ' . $to->format('j M Y');
}
}
public function getReportTeamsName(AutomatedReportResult $report): string
{
$groups = $report->getGroups();
if (empty($groups)) {
return 'All';
}
// Get group names from repository
$groupNames = [];
foreach ($groups as $groupId) {
$group = $this->groupRepository->find($groupId);
if ($group) {
$groupNames[] = $group->getName();
}
}
if (count($groupNames) === 1) {
// Single team format
$teamsName = $groupNames[0];
} else {
// Multiple teams format
$teamsName = implode(', ', $groupNames);
}
return $teamsName;
}
public function getReportFileName(AutomatedReportResult $report): string
...
|
12308
|
|
12311
|
260
|
33
|
2026-04-14T11:02:29.330582+00:00
|
/Users/lukas/.screenpipe/data/data/2026-04-14/1776 /Users/lukas/.screenpipe/data/data/2026-04-14/1776164549330_m1.jpg...
|
PhpStorm
|
faVsco.js – AutomatedReportsService.php
|
1
|
NULL
|
monitor_1
|
NULL
|
NULL
|
NULL
|
NULL
|
Project: faVsco.js, menu
#11894 on JY-18909-automa Project: faVsco.js, menu
#11894 on JY-18909-automated-reports-ask-jiminny, menu
Start Listening for PHP Debug Connections
AutomatedReportsCommandTest
Run 'AutomatedReportsCommandTest'
Debug 'AutomatedReportsCommandTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Execute
Explain Plan
Browse Query History
View Parameters
Open Query Execution Settings…
In-Editor Results
Tx: Auto
Cancel Running Statements
Playground
jiminny
Sync Changes
Hide This Notification
Code changed:
Hide
16
13
13
Previous Highlighted Error
Next Highlighted Error
SELECT * FROM teams WHERE id = 1;
select * from crm_layouts where crm_configuration_id = 39;
SELECT * FROM crm_layout_entities WHERE crm_layout_id = 283;
SELECT * FROM crm_fields WHERE id = 2234;
SELECT * FROM crm_field_values WHERE crm_field_id = 2234;
select * from crm_profiles where user_id = 143;
select * from record_types where crm_configuration_id = 39; # 0121K000001MHElQAO,0121K000001MHEqQAO
select * from business_processes where crm_configuration_id = 39;
# 01941000000H669AAC, 01941000000H66JAAS
select * from record_type_field_values
where record_type_id IN (24);
select * from crm_field_values where id IN (2730);
select * from crm_configurations where id = 39;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 1
and sa.provider = 'salesforce'; #1035
select * from users where team_id = 1; # 222 group 3
SELECT * FROM activities WHERE user_id = 222 order by id desc;
select * from sidekick_settings where team_id = 1;
select * from teams where id = 1;
select * from team_features where team_id = 1;
select * from activities where crm_configuration_id = 2
and provider = 'ms-teams' and id = 608765;
SELECT * FROM activities WHERE crm_configuration_id = 2 and crm_provider_id = '59523413338';
select * from sidekick_settings where team_id = 2;
SELECT * FROM activities WHERE id = 608660;
select * from activity_summary_logs where activity_id = 608660;
select * from ai_prompts where transcription_id = 11214;
# [PASSWORD_DOTS]
SELECT * FROM activities WHERE uuid_to_bin('ed78a437-2804-450e-ab2f-56ab1c641346') = uuid;
# id: 608818, crm: 59628809737
SELECT * FROM activities WHERE uuid_to_bin('36b06e55-afdd-4782-8dee-c624cd0af191') = uuid;
# id: 608821, crm: 59632069252
SELECT ce.start_time, ce.end_time, a.id, a.uuid, crm_provider_id, calendar_event_id, title,
playbook_category_id, user_id, lead_id, contact_id, account_id, opportunity_id,
scheduled_start_time, scheduled_end_time, actual_start_time, actual_end_time, a.created_at
FROM activities a
join calendar_events ce on a.calendar_event_id = ce.id
WHERE a.id IN (608818, 608821);
select * from users where team_id = 1;
select * from team_settings where team_id = 1;
select * from crm_profiles where crm_configuration_id = 39 order by user_id;
select * from team_features where team_id = 1;
select * from users where team_id = 2;
SELECT * FROM activities WHERE uuid_to_bin('ec7647e9-5225-458b-b475-f31aa2769204') = uuid; # 612639
# Preslava N. Ivanova, grou id 3
SELECT * FROM opportunities WHERE uuid_to_bin('a2928fe5-aec5-46cb-85d9-7654c89e46a6') = uuid;
select * from activities where opportunity_id = 344 and actual_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00';
select
a.id,
a.type,
a.scheduled_start_time,
a.actual_start_time,
a.created_at,
a.opportunity_id,
a.status
FROM activities a
WHERE opportunity_id = 344
and status IN ('completed', 'received', 'delivered')
and (
(a.actual_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00')
OR (a.created_at between '2024-10-11 00:00:00' and '2024-10-12 00:00:00')
OR (a.scheduled_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00'))
;
SELECT * FROM users WHERE id = 222;
SELECT * FROM crm_profiles WHERE user_id = 222;
select * from crm_layouts where crm_configuration_id = 39;
SELECT * FROM crm_layout_entities WHERE crm_layout_id = 281;
select * from group_deal_risk_types;
select * from opportunities where team_id = 1;
SELECT * FROM opportunities WHERE id = 315;
SELECT * FROM crm_field_data WHERE object_id = 315;
select * from crm_field_data where object_id = 260;
select * from generic_ai_prompts where subject_id = 315;
select * from teams; # 36, 21, 121, [EMAIL]
SELECT * FROM social_accounts WHERE sociable_id = 121 and provider = 'bullhorn';
# [PASSWORD_DOTS]
select * from teams where id = 1;
select * from crm_configurations where id = 39;
select * from users where team_id = 1;
select u.email, cp.* from users u
join crm_profiles cp on u.id = cp.user_id
where u.team_id = 1;
# 1 - 00541000004281rAAA
# 204 - 0052g000003freeAAA
# 429 - 0052g000003qGOiAAM
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 1
and sa.provider = 'salesforce';
select * from activities where type = 'softphone'
and created_at > '2024-12-11 15:24:36' order by id desc;
select * from activity_providers where team_id = 1;
select * from activity_provider_users where activity_provider_id = 328;
select * from opportunities where crm_configuration_id = 39
AND account_id = 178 AND is_closed = false
order by created_at DESC;
select * from contacts where id = 3952;
select * from accounts where id = 178;
# [PASSWORD_DOTS]
select * from teams where id = 36;
select * from crm_configurations where id = 21;
select * from users where team_id = 36;
select u.email, cp.* from users u
join crm_profiles cp on u.id = cp.user_id
where u.team_id = 36;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 36
and sa.provider = 'bullhorn';
select * from social_accounts where id = 348;
UPDATE social_accounts SET
provider_user_token = '21442_6802599_91:41179a58-21e7-4d7c-ad58-56bb666b2f65',
provider_refresh_token = '21442_6802599_91:01c6b335-3f2a-42e4-85ff-8a08fa65fceb',
expires = 1733998131,
state = 'connected'
WHERE id = 348;
# [PASSWORD_DOTS]
select * from teams where id = 31;
select * from crm_configurations where id = 18;
select * from users where team_id = 31; # 257
select u.email, cp.* from users u
join crm_profiles cp on u.id = cp.user_id
where u.team_id = 31;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 31
and sa.provider = 'close';
select * from contacts where crm_configuration_id = 18;
# [PASSWORD_DOTS] NEPTUNE [PASSWORD_DOTS]
select * from teams;
select * from users where id IN (1030, 1035, 1052);
select * from crm_configurations;
select * from users where team_id = 65; # 257
select * from team_settings where team_id = 65; # 257
select * from invitations where team_id = 65; # 257
select * from users where email = '[EMAIL]'; # 257
select u.email, cp.* from users u
join crm_profiles cp on u.id = cp.user_id
where u.team_id = 65;
select * from crm_configurations where id = 53;
select * from accounts where crm_configuration_id = 53 order by id desc;
select * from leads where crm_configuration_id = 53 order by id desc;
select * from contacts where crm_configuration_id = 53 order by id desc;
select * from opportunities where crm_configuration_id = 53 order by id desc;
select * from crm_profiles where crm_configuration_id = 53 order by id desc;
select * from crm_fields where crm_configuration_id = 53 order by id desc;
select * from crm_field_values where crm_field_id = 3341 order by id desc;
select * from crm_layouts where crm_configuration_id = 53 order by id desc;
select * from stages where crm_configuration_id = 53 order by id desc;
select * from crm_profiles where crm_configuration_id = 13;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 65
and sa.provider = 'integration-app';
select * from contacts where crm_configuration_id = 13;
select * from social_accounts where sociable_id = 283;
SELECT * FROM opportunities WHERE crm_provider_id = '006O400000E9bzeIAB';
select * from activity_providers where team_id = 65;
SELECT * FROM activities WHERE crm_configuration_id IN (51, 52, 53);
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 65
;
# [PASSWORD_DOTS] STAGING [PASSWORD_DOTS]
SELECT * FROM teams;
SELECT * FROM teams WHERE id = 88;
SELECT * FROM teams WHERE id = 89;
select * from team_settings where team_id = 89;
SELECT * FROM users WHERE team_id = 89;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 89;
select * from users;
SELECT * FROM social_accounts WHERE sociable_id = 1761;
SELECT * FROM crm_configurations WHERE id = 70;
select * from accounts where crm_configuration_id = 70 order by id desc;
select * from leads where crm_configuration_id = 70 order by id desc;
select * from contacts where crm_configuration_id = 70 order by id desc;
select * from opportunities where crm_configuration_id = 70 order by id desc;
select * from crm_profiles where crm_configuration_id = 70 order by id desc;
select * from crm_fields where crm_configuration_id = 70 order by id desc;
select * from crm_field_values where crm_field_id = 3536 order by id desc;
select * from crm_layouts where crm_configuration_id = 70 order by id desc;
select * from stages where crm_configuration_id = 70 order by id desc;
select * from business_processes where crm_configuration_id = 70 order by id desc;
select * from business_process_stages where business_process_id = 34;
select * from contacts where id = 10468;
select * from crm_layouts where crm_configuration_id = 70;
SELECT * FROM crm_layout_entities WHERE crm_layout_id = 388;
SELECT * FROM crm_fields WHERE id IN (3533,3534,3535);
select * from activities where crm_configuration_id = 70
and (account_id IS NOT NULL or lead_id IS NOT NULL or contact_id IS NOT NULL or opportunity_id IS NOT NULL) order by id desc;
SELECT * FROM activities WHERE uuid_to_bin('2e10b60f-8a61-41c5-a3d4-28835353dc65') = uuid;
SELECT * FROM activities where crm_configuration_id = 69 ;
SELECT * FROM users WHERE email LIKE '%[EMAIL]%';
SELECT * FROM activities WHERE uuid_to_bin('5a150c93-40fc-42ec-b3bd-c1d328e09f6e') = uuid;
SELECT * FROM opportunities WHERE id = 385;
select * from participants p
join activities a on p.activity_id = a.id
where a.crm_configuration_id = 70
and (p.lead_id IS NOT NULL or p.contact_id IS NOT NULL);
SELECT * FROM participants WHERE id = 1013638;
select * from teams where id = 90;
select * from users where team_id = 90;
select * from social_accounts where social_accounts.sociable_id IN (1960,1760);
SELECT * FROM crm_profiles WHERE crm_configuration_id = 71;
select * from invitations where team_id = 90;
select * from crm_configurations where id = 71;
select * from accounts where crm_configuration_id = 71 order by id desc;
select * from leads where crm_configuration_id = 71 order by id desc;
select * from contacts where crm_configuration_id = 71 order by id desc;
select * from opportunities where crm_configuration_id = 71 order by id desc;
select * from crm_profiles where crm_configuration_id = 71 order by id desc;
select * from crm_fields where crm_configuration_id = 71 order by id desc;
select * from crm_field_values where crm_field_id = 3341 order by id desc;
select * from crm_layouts where crm_configuration_id = 71 order by id desc;
select * from stages where crm_configuration_id = 71 order by id desc;
select * from users order by secondary_email desc;
select u.id, u.email, u.status, sa.id, sa.provider_user_id from social_accounts sa
join users u on sa.sociable_id = u.id
where sa.provider = 'google' and u.email LIKE 'aneliya%';
select * from failed_jobs order by id desc;
select * from users where email = '[EMAIL]' or secondary_email = '[EMAIL]';
select * from teams;
SELECT * FROM crm_profiles WHERE crm_configuration_id = 39;
SELECT * FROM crm_fields WHERE crm_configuration_id = 39 and object_type = 'task';
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 1
and sa.provider = 'salesforce';
# [PASSWORD_DOTS]
SELECT * FROM activities WHERE uuid_to_bin('c38b3895-fd0f-4b1f-9fb2-c170dba137c6') = uuid;
SELECT * FROM crm_configurations WHERE id = 70;
select * from teams where id = 1;
select * from groups where team_id = 1;
select * from users where team_id = 1;
select o.id, o.name,o.close_date, u.id, u.name, u.group_id, r.id, r.display_name, g.name, g.scope from opportunities o
join users u on o.user_id = u.id
join groups g on u.group_id = g.id
join role_user ru on u.id = ru.user_id
join roles r on ru.role_id = r.id
where o.crm_configuration_id = 39 and close_date > '2024-01-01 00:00:00';
select * from role_user where user_id = 143;
select * from roles;
select * from role_user;
select * from groups where id = 9;
select * from scope_groups where group_id = 9;
# [PASSWORD_DOTS]
select * from teams where id = 36;
select * from crm_configurations;
SELECT * FROM social_accounts WHERE sociable_id = 121;
[URL_WITH_CREDENTIALS] this will add filter, however if we need to control feature by FF we need conditional logic
public const array TYPES = [
['id' => 'exec_summary', 'name' => 'Exec Summary'],
['id' => 'coaching_profiles', 'name' => 'Coaching Profiles'],
['id' => 'product_feedback', 'name' => 'Product Feedback'],
['id' => self::TYPE_LOSS_ANALYSIS, 'name' => 'Loss Analysis'],
// ['id' => 'questions', 'name' => 'Questions'],
// ['id' => 'statistical_quant', 'name' => 'Statistical Quantitative'],
];
public const array ALL_TYPES = [
...self::TYPES,
['id' => self::TYPE_ASK_JIMINNY, 'name' => 'Ask Jiminny'],
];
public const string FREQUENCY_DAILY = 'daily';
public const string FREQUENCY_WEEKLY = 'weekly';
public const string FREQUENCY_MONTHLY = 'monthly';
public const string FREQUENCY_QUARTERLY = 'quarterly';
public const string FREQUENCY_ONE_OFF = 'one_off';
/**
* Frequencies for standard (non-Ask Jiminny) reports.
*/
public const array FREQUENCIES = [
['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],
['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],
['id' => self::FREQUENCY_QUARTERLY, 'name' => 'Quarterly'],
['id' => self::FREQUENCY_ONE_OFF, 'name' => 'One-off'],
];
/**
* Frequencies for Ask Jiminny reports.
*/
public const array ASK_JIMINNY_FREQUENCIES = [
['id' => self::FREQUENCY_DAILY, 'name' => 'Daily'],
['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],
['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],
];
public const string MEDIA_TYPE_PDF = 'pdf';
public const string MEDIA_TYPE_PODCAST = 'podcast';
public const array MEDIA_TYPES = [self::MEDIA_TYPE_PDF, self::MEDIA_TYPE_PODCAST];
public const array MEDIA_TYPE_OBJECT_PDF = ['id' => self::MEDIA_TYPE_PDF, 'name' => 'PDF'];
public const array MEDIA_TYPE_OBJECT_PODCAST = ['id' => self::MEDIA_TYPE_PODCAST, 'name' => 'Podcast'];
public const array MEDIA_TYPE_OBJECTS = [self::MEDIA_TYPE_OBJECT_PDF, self::MEDIA_TYPE_OBJECT_PODCAST];
public const array CALL_TYPE_CONFERENCE = ['id' => 'conference', 'name' => 'Conference'];
public const array CALL_TYPE_DIALER = ['id' => 'dialer', 'name' => 'Dialer'];
public const int SENT_REPORT_AT_HOURS = 5;
public const string PDF_KEY = 'pdf';
public const string AUDIO_KEY = 'audio';
private const array ALL_FREQUENCIES = [
['id' => self::FREQUENCY_DAILY, 'name' => 'Daily'],
['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],
['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],
['id' => self::FREQUENCY_QUARTERLY, 'name' => 'Quarterly'],
['id' => self::FREQUENCY_ONE_OFF, 'name' => 'One-off'],
];
private const string S3_DIR = 'reports';
private const array FILE_EXTENSIONS_VARIANTS = ['html', 'MD', 'pdf'];
private const array FILE_PODCAST_EXTENSIONS_VARIANTS = ['json', 'mp3', 'ssml'];
public function __construct(
private readonly TeamRepository $teamRepository,
private readonly GroupRepository $groupRepository,
private readonly UserRepository $userRepository,
private readonly StageRepository $stageRepository,
private readonly DealStagesService $dealStagesService,
private readonly RecipientsService $recipientsService,
private readonly AutomatedReportsRepository $automatedReportsRepository,
private readonly Webhook $webhookService,
private readonly BusDispatcher $dispatcher,
private readonly ActivityTypeService $activityTypeService,
private readonly PlaybookCategoryRepository $playbookCategoryRepository,
private readonly AskAnythingPromptService $askAnythingPromptService,
private readonly SearchRepository $activitySearchRepository,
private readonly AskAnythingRepository $askAnythingRepository,
) {
}
public static function getTypes(): array
{
$types = self::TYPES;
return array_map(static function ($type) {
return $type['id'];
}, $types);
}
public static function getCallTypes(): array
{
return array_map(static function ($callType) {
return $callType['id'];
}, [self::CALL_TYPE_CONFERENCE, self::CALL_TYPE_DIALER]);
}
public static function getFrequencies(): array
{
return array_map(static function ($frequency) {
return $frequency['id'];
}, self::FREQUENCIES);
}
// front-facing structure
public function getReportEnabledFieldData(bool $value = false): array
{
return [
'id' => 'report_enabled',
'label' => '',
'inputType' => InputTypeEnum::TOGGLE,
'value' => $value,
];
}
// Organizations = Teams
public function getOrganizationFieldData(?string $value = null, bool $shortVersion = false): array
{
$options = $this->getTeams();
if ($shortVersion) {
return [
'id' => 'organization',
'label' => 'Organization',
'options' => $options,
];
}
return [
'id' => 'organization',
'label' => 'Organization',
'inputType' => InputTypeEnum::DROPDOWN,
'required' => true,
'placeholder' => 'Select',
'options' => $options,
'value' => $value,
'dependencies' => [
'teams',
'deal_stage_at_call',
'current_deal_stage',
'recipients',
ActivityTypeService::PLAYBOOK_CATEGORIES_KEY,
],
'dependsOn' => [],
];
}
// Teams = Groups
public function getTeamFieldData(array $options = [], array $value = [], bool $shortVersion = false): array
{
if ($shortVersion) {
return [
'id' => 'teams',
'label' => 'Team',
'options' => $options,
];
}
return [
'id' => 'teams',
'label' => 'Team',
'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,
'required' => false,
'placeholder' => 'Select',
'options' => $options,
'value' => $value, // value should be an array of objects {id, name}
'dependencies' => [ActivityTypeService::PLAYBOOK_CATEGORIES_KEY],
'dependsOn' => [],
];
}
public function getReportTypeFieldData(?string $value = null, bool $shortVersion = false, ?Team $team = null): array
{
$types = [];
if ($team instanceof Team) {
if ($team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {
$types = self::TYPES;
}
if ($team->hasFeature(FeatureEnum::ASK_JIMINNY_REPORTS)) {
$types[] = ['id' => self::TYPE_ASK_JIMINNY, 'name' => 'Ask Jiminny'];
}
} else {
$types = self::TYPES;
}
if ($shortVersion) {
return [
'id' => 'report_type',
'label' => 'Report Type',
'options' => $types,
];
}
return [
'id' => 'report_type',
'label' => 'Report Type',
'inputType' => InputTypeEnum::DROPDOWN,
'required' => true,
'placeholder' => 'Select',
'options' => $types,
'value' => $value,
'dependencies' => [],
'dependsOn' => [],
];
}
public function getFrequencyFieldData(?string $value = null): array
{
return [
'id' => 'frequency',
'label' => 'Frequency',
'inputType' => InputTypeEnum::DROPDOWN,
'required' => true,
'placeholder' => 'Select',
'options' => self::FREQUENCIES,
'value' => $value,
'dependencies' => ['period'],
'dependsOn' => [],
];
}
public function getPeriodFieldData(?string $valueStartDate = null, ?string $valueEndDate = null): array
{
return [
'id' => 'period',
'label' => 'Select one-off period',
'inputType' => InputTypeEnum::DATE_RANGE,
'required' => true,
'placeholder' => 'Select',
'value' => ['startDate' => $valueStartDate, 'endDate' => $valueEndDate],
'queryParams' => [
'startDate' => 'start_date_period',
'endDate' => 'end_date_period',
],
'dependencies' => [],
'dependsOn' => ['frequency'],
];
}
public function getActivityTypesFieldData(?Team $team = null, array $value = [], array $teamsFilter = []): array
{
return $this->activityTypeService->getActivityTypeFieldData(team: $team, value: $value, groupIds: $teamsFilter);
}
public function getDealStageAtCallFieldData(?Team $team = null, array $value = []): array
{
return $this->dealStagesService->getDealStageAtCallFieldData(team: $team, value: $value);
}
public function getCurrentDealStageFieldData(?Team $team = null, array $value = []): array
{
return $this->dealStagesService->getCurrentDealStageFieldData(team: $team, value: $value);
}
public function getDealValueFieldData(?int $valueMin = null, ?int $valueMax = null): array
{
return [
'id' => 'deal_value',
'label' => 'Deal Value',
'inputType' => InputTypeEnum::INTEGER_RANGE,
'required' => false,
'value' => ['min' => $valueMin, 'max' => $valueMax],
'queryParams' => [
'min' => 'min_deal_value',
'max' => 'max_deal_value',
],
'dependencies' => [],
'dependsOn' => [],
];
}
public function getCallTypeFieldData(bool $conferenceOn = false, bool $dialerOn = false): array
{
$value = [];
$conferenceOn && $value[] = self::CALL_TYPE_CONFERENCE;
$dialerOn && $value[] = self::CALL_TYPE_DIALER;
return [
'id' => 'call_type',
'label' => 'Call Type',
'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,
'required' => true,
'options' => [
self::CALL_TYPE_CONFERENCE,
self::CALL_TYPE_DIALER,
],
'value' => $value,
'dependencies' => [],
'dependsOn' => [],
];
}
public function getMediaTypeFieldData(?AutomatedReport $report = null): array
{
$value = [];
if ($report) {
$value = $this->transformMediaTypes($report);
}
return [
'id' => 'media_types',
'label' => 'Export as',
'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,
'required' => true,
'options' => self::MEDIA_TYPE_OBJECTS,
'value' => $value,
'dependencies' => [],
'dependsOn' => [],
];
}
public function getCallDurationFieldData(?int $valueMin = null, ?int $valueMax = null): array
{
return [
'id' => 'call_duration',
'label' => 'Call Duration',
'inputType' => InputTypeEnum::INTEGER_RANGE,
'required' => false,
'value' => ['min' => $valueMin, 'max' => $valueMax],
'queryParams' => [
'min' => 'min_call_duration',
'max' => 'max_call_duration',
],
'dependencies' => [],
'dependsOn' => [],
];
}
public function getRecipientsFieldData(?Team $team = null, array $value = []): array
{
return $this->recipientsService->getRecipientsFieldData(team: $team, value: $value);
}
public function getJiminnyRecipientsFieldData(array $value = []): array
{
return $this->recipientsService->getJiminnyRecipientsFieldData($value);
}
public function getAdditionalPromptInputFieldData(?string $value = null): array
{
return [
'id' => 'additional_prompt_input',
'label' => 'Special requirements',
'inputType' => InputTypeEnum::TEXTAREA,
'required' => false,
'placeholder' => 'What should be the focus of the report?',
'value' => $value,
'dependencies' => [],
'dependsOn' => [],
];
}
public function getCustomReportNameFieldData(?string $value = null): array
{
return [
'id' => 'custom_name',
'label' => 'Custom report name',
'inputType' => InputTypeEnum::TEXT,
'required' => false,
'placeholder' => 'Enter custom name',
'value' => $value,
'dependencies' => [],
'dependsOn' => [],
];
}
// data providers
public function getTeams(): array
{
$teams = $this->teamRepository->getTeamsForKiosk(status: Team::STATUS_ACTIVE);
$teamData = [];
foreach ($teams as $team) {
if (! $team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {
continue;
}
$teamData[] = $this->transformTeam($team);
}
return $teamData;
}
public function getTeamGroups(string $teamUuid): array
{
$data = [];
$team = $this->getTeam($teamUuid);
if ($team !== null) {
$groups = $team->groups()->get();
foreach ($groups as $group) {
$data[] = [
'id' => $group->getUuid(),
'name' => $group->getName(),
];
}
}
return $data;
}
public function getTeamsGroupsOptions(array $filterTeamUuids = []): array
{
$data = [];
$teams = $this->getTeams();
foreach ($teams as $team) {
if (! empty($filterTeamUuids) && ! in_array($team['id'], $filterTeamUuids, true)) {
continue;
}
$data[] = [
'label' => $team['name'],
'groups' => $this->getTeamGroups($team['id']),
];
}
return $data;
}
public function getTeam(string $teamUuid): ?Team
{
return $this->teamRepository->idOrUuid($teamUuid);
}
public function getTeamById(int $teamId): ?Team
{
return $this->teamRepository->find($teamId);
}
public function getGroupsUuids(AutomatedReport $report): array
{
$uuids = [];
$reportGroups = $report->getGroups();
foreach ($reportGroups as $groupId) {
if ($group = $this->groupRepository->find($groupId)) {
$uuids[] = $group->getUuid();
}
}
return $uuids;
}
public function getPlaybookCategoriesUuids(AutomatedReport $report): array
{
$uuids = [];
$playbookCategories = $report->getPlaybookCategories();
foreach ($playbookCategories as $id) {
if ($category = $this->playbookCategoryRepository->find($id)) {
$uuids[] = $category->getUuid();
}
}
return $uuids;
}
public function getDealAtCallStagesUuids(AutomatedReport $report): array
{
$uuids = [];
$reportStages = $report->getDealAtCallStages();
foreach ($reportStages as $id) {
if ($stage = $this->stageRepository->find($id)) {
$uuids[] = $stage->getUuid();
}
}
return $uuids;
}
public function getCurrentDealStagesUuids(AutomatedReport $report): array
{
$uuids = [];
$reportStages = $report->getCurrentDealStages();
foreach ($reportStages as $id) {
if ($stage = $this->stageRepository->find($id)) {
$uuids[] = $stage->getUuid();
}
}
return $uuids;
}
public function getUsersUuids(AutomatedReport $report): array
{
return $this->extractUserUuids($report->getRecipients());
}
public function getJiminnyUsersUuids(AutomatedReport $report): array
{
return $this->extractUserUuids($report->getJiminnyRecipients());
}
/**
* @param array<string, mixed> $recipients
*/
private function extractUserUuids(array $recipients): array
{
$userIds = $recipients['users'] ?? [];
return collect($userIds)
->map(fn ($id) => $this->userRepository->find((int) $id))
->filter()
->map(fn (UserContract $user) => $user->getUuid())
->values()
->all();
}
// get mail data
public function getRecipientUsers(AutomatedReport $report): array
{
return $this->buildRecipientUsers($report->getRecipients());
}
private function getJiminnyRecipientUsers(AutomatedReport $report): array
{
return $this->buildRecipientUsers($report->getJiminnyRecipients());
}
/**
* @param array<string, mixed> $recipients
*/
private function buildRecipientUsers(array $recipients): array
{
$userIds = $recipients['users'] ?? [];
return collect($userIds)
->map(fn ($id) => $this->userRepository->find((int) $id))
->filter()
->map(fn (UserContract $user) => [
'email' => $user->getEmailAddress(),
'name' => $user->getName(),
'timezone' => $user->getTimezone()->getName(),
])
->values()
->all();
}
public function getValidRecipientUsers(AutomatedReport $report, bool $includeJiminny = false): array
{
if ($report->isAskJiminnyReport()) {
$recipients = $this->resolveAskJiminnyRecipients($report);
} else {
$recipients = $this->getRecipientUsers($report);
if ($includeJiminny) {
$recipients = array_merge($recipients, $this->getJiminnyRecipientUsers($report));
}
}
$emails = [];
return array_values(array_filter(
$recipients,
static function ($recipient) use (&$emails) {
if (empty($recipient['email']) || in_array($recipient['email'], $emails, true)) {
return false;
}
$emails[] = $recipient['email'];
return true;
}
));
}
private function resolveAskJiminnyRecipients(AutomatedReport $report): array
{
$recipients = [];
$creator = $report->getCreator();
if ($creator !== null) {
$recipients[] = [
'email' => $creator->getEmailAddress(),
'name' => $creator->getName(),
'timezone' => $creator->getTimezone()->getName(),
];
}
return array_merge(
$recipients,
$this->buildRecipientUsers($report->getRecipients()),
$this->getGroupRecipientUsers($report),
);
}
private function getGroupRecipientUsers(AutomatedReport $report): array
{
$users = [];
foreach ($report->getGroups() as $groupId) {
$group = $this->groupRepository->find($groupId);
if ($group === null) {
continue;
}
foreach ($group->getMembers() as $member) {
$users[] = [
'email' => $member->getEmailAddress(),
'name' => $member->getName(),
'timezone' => $member->getTimezone()->getName(),
];
}
}
return $users;
}
public function getReportTypeName(AutomatedReportResult $report): string
{
$type = $report->getReport()->getType();
$getType = $this->transformReportType($type);
return $getType['name'];
}
public function getReportPeriodName(AutomatedReportResult $report): string
{
$from = $report->getFromDate();
$to = $report->getToDate();
$frequency = $report->getReport()->getFrequency();
if ($from === null || $to === null) {
if (! $report->getReport()->isAskJiminnyReport()) {
$invalidPeriod = $from === null ? 'from' : 'to';
throw new ApplicationException('Report period is invalid: ' . $invalidPeriod);
}
$period = $this->calculateFromAndToDatePeriod($frequency);
$from = $period['fromDate'];
$to = $period['toDate'];
}
return $this->formatReportPeriodName($frequency, $from, $to);
}
private function formatReportPeriodName(string $frequency, Carbon $from, Carbon $to): string
{
$fromYear = $from->format('Y');
$toYear = $to->format('Y');
$differentYears = $fromYear !== $toYear;
switch ($frequency) {
case self::FREQUENCY_DAILY:
return $from->format('j M Y');
case self::FREQUENCY_QUARTERLY:
// 'Jan-Mar 2025' or 'Nov 2024-Jan 2025' if years differ
$startMonth = $from->format('M');
$endMonth = $to->copy()->subMonth();
$endMonthName = $endMonth->format('M');
$endMonthYear = $endMonth->format('Y');
if ($differentYears) {
return "{$startMonth} {$fromYear} - {$endMonthName} {$endMonthYear}";
}
return "{$startMonth} - {$endMonthName} {$toYear}";
case self::FREQUENCY_MONTHLY:
// 'May 2025' - monthly reports are always within the same year
return $from->format('M Y');
case self::FREQUENCY_WEEKLY:
// '4 - 8 Aug 2025', '27 Oct - 3 Nov 2025', or '28 Dec 2024 - 3 Jan 2025' if years differ
$startDay = $from->format('j');
$endDay = $to->format('j');
$startMonth = $from->format('M');
$endMonth = $to->format('M');
if ($differentYears) {
return "{$startDay} {$startMonth} {$fromYear} - {$endDay} {$endMonth} {$toYear}";
}
if ($startMonth !== $endMonth) {
return "{$startDay} {$startMonth} - {$endDay} {$endMonth} {$toYear}";
}
return "{$startDay} - {$endDay} {$endMonth} {$toYear}";
case self::FREQUENCY_ONE_OFF:
// '2 May-31 May 2025' or '15 Dec 2024-15 Jan 2025' if years differ
$startDay = $from->format('j');
$startMonth = $from->format('M');
$endDay = $to->format('j');
$endMonth = $to->format('M');
// If same month and year, use a format like '2-31 May 2025'
if ($startMonth === $endMonth && ! $differentYears) {
return "{$startDay} - {$endDay} {$startMonth} {$toYear}";
}
// If different years, include both years
if ($differentYears) {
return "{$startDay} {$startMonth} {$fromYear} - {$endDay} {$endMonth} {$toYear}";
}
// Same year but different months
return "{$startDay} {$startMonth} - {$endDay} {$endMonth} {$toYear}";
default:
// Default format for unknown frequencies
return $from->format('j M Y') . ' - ' . $to->format('j M Y');
}
}
public function getReportTeamsName(AutomatedReportResult $report): string
{
$groups = $report->getGroups();
if (empty($groups)) {
return 'All';
}
// Get group names from repository
$groupNames = [];
foreach ($groups as $groupId) {
$group = $this->groupRepository->find($groupId);
if ($group) {
$groupNames[] = $group->getName();
}
}
if (count($groupNames) === 1) {
// Single team format
$teamsName = $groupNames[0];
} else {
// Multiple teams format
$teamsName = implode(', ', $groupNames);
}
return $teamsName;
}
public function getReportFileName(AutomatedReportResult $report): string
...
|
[{"role":"AXButton","text" [{"role":"AXButton","text":"Project: faVsco.js, menu","depth":5,"help_text":"~/jiminny/app","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"#11894 on JY-18909-automated-reports-ask-jiminny, menu","depth":5,"help_text":"Pull request #11894 exists for current branch JY-18909-automated-reports-ask-jiminny","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Start Listening for PHP Debug Connections","depth":5,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"AutomatedReportsCommandTest","depth":6,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Run 'AutomatedReportsCommandTest'","depth":6,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Debug 'AutomatedReportsCommandTest'","depth":6,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"More Actions","depth":6,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JetBrains AI","depth":5,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Search Everywhere","depth":5,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"IDE and Project Settings","depth":5,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Execute","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Explain Plan","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Browse Query History","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"View Parameters","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Open Query Execution Settings…","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"In-Editor Results","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Tx: Auto","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Cancel Running Statements","depth":4,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Playground","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"jiminny","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.088194445,"height":0.027777778},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"16","depth":4,"role_description":"text"},{"role":"AXStaticText","text":"13","depth":4,"role_description":"text"},{"role":"AXStaticText","text":"13","depth":4,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"SELECT * FROM teams WHERE id = 1;\n\nselect * from crm_layouts where crm_configuration_id = 39;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 283;\nSELECT * FROM crm_fields WHERE id = 2234;\nSELECT * FROM crm_field_values WHERE crm_field_id = 2234;\n\nselect * from crm_profiles where user_id = 143;\n\nselect * from record_types where crm_configuration_id = 39; # 0121K000001MHElQAO,0121K000001MHEqQAO\nselect * from business_processes where crm_configuration_id = 39;\n# 01941000000H669AAC, 01941000000H66JAAS\n\nselect * from record_type_field_values\n where record_type_id IN (24);\n\nselect * from crm_field_values where id IN (2730);\n\nselect * from crm_configurations where id = 39;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 1\nand sa.provider = 'salesforce'; #1035\n\n\nselect * from users where team_id = 1; # 222 group 3\nSELECT * FROM activities WHERE user_id = 222 order by id desc;\nselect * from sidekick_settings where team_id = 1;\nselect * from teams where id = 1;\nselect * from team_features where team_id = 1;\n\nselect * from activities where crm_configuration_id = 2\nand provider = 'ms-teams' and id = 608765;\n\nSELECT * FROM activities WHERE crm_configuration_id = 2 and crm_provider_id = '59523413338';\n\nselect * from sidekick_settings where team_id = 2;\n\nSELECT * FROM activities WHERE id = 608660;\nselect * from activity_summary_logs where activity_id = 608660;\nselect * from ai_prompts where transcription_id = 11214;\n\n# ********************************************************************************************************\nSELECT * FROM activities WHERE uuid_to_bin('ed78a437-2804-450e-ab2f-56ab1c641346') = uuid;\n# id: 608818, crm: 59628809737\nSELECT * FROM activities WHERE uuid_to_bin('36b06e55-afdd-4782-8dee-c624cd0af191') = uuid;\n# id: 608821, crm: 59632069252\nSELECT ce.start_time, ce.end_time, a.id, a.uuid, crm_provider_id, calendar_event_id, title,\nplaybook_category_id, user_id, lead_id, contact_id, account_id, opportunity_id,\nscheduled_start_time, scheduled_end_time, actual_start_time, actual_end_time, a.created_at\nFROM activities a\njoin calendar_events ce on a.calendar_event_id = ce.id\nWHERE a.id IN (608818, 608821);\n\nselect * from users where team_id = 1;\nselect * from team_settings where team_id = 1;\nselect * from crm_profiles where crm_configuration_id = 39 order by user_id;\n\nselect * from team_features where team_id = 1;\n\nselect * from users where team_id = 2;\n\nSELECT * FROM activities WHERE uuid_to_bin('ec7647e9-5225-458b-b475-f31aa2769204') = uuid; # 612639\n# Preslava N. Ivanova, grou id 3\n\nSELECT * FROM opportunities WHERE uuid_to_bin('a2928fe5-aec5-46cb-85d9-7654c89e46a6') = uuid;\n\nselect * from activities where opportunity_id = 344 and actual_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00';\n\nselect\n a.id,\n a.type,\n a.scheduled_start_time,\n a.actual_start_time,\n a.created_at,\n a.opportunity_id,\n a.status\nFROM activities a\nWHERE opportunity_id = 344\nand status IN ('completed', 'received', 'delivered')\nand (\n (a.actual_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00')\nOR (a.created_at between '2024-10-11 00:00:00' and '2024-10-12 00:00:00')\nOR (a.scheduled_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00'))\n;\n\nSELECT * FROM users WHERE id = 222;\n\nSELECT * FROM crm_profiles WHERE user_id = 222;\nselect * from crm_layouts where crm_configuration_id = 39;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 281;\n\nselect * from group_deal_risk_types;\n\nselect * from opportunities where team_id = 1;\n\nSELECT * FROM opportunities WHERE id = 315;\nSELECT * FROM crm_field_data WHERE object_id = 315;\nselect * from crm_field_data where object_id = 260;\n\nselect * from generic_ai_prompts where subject_id = 315;\n\nselect * from teams; # 36, 21, 121, james.graham@bullhorn.jiminny.com\nSELECT * FROM social_accounts WHERE sociable_id = 121 and provider = 'bullhorn';\n\n# ************************************************************************************\nselect * from teams where id = 1;\nselect * from crm_configurations where id = 39;\nselect * from users where team_id = 1;\nselect u.email, cp.* from users u\njoin crm_profiles cp on u.id = cp.user_id\nwhere u.team_id = 1;\n# 1 - 00541000004281rAAA\n# 204 - 0052g000003freeAAA\n# 429 - 0052g000003qGOiAAM\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 1\nand sa.provider = 'salesforce';\n\nselect * from activities where type = 'softphone'\nand created_at > '2024-12-11 15:24:36' order by id desc;\n\nselect * from activity_providers where team_id = 1;\nselect * from activity_provider_users where activity_provider_id = 328;\n\nselect * from opportunities where crm_configuration_id = 39\nAND account_id = 178 AND is_closed = false\norder by created_at DESC;\n\nselect * from contacts where id = 3952;\nselect * from accounts where id = 178;\n\n# ************************************************************************************\nselect * from teams where id = 36;\nselect * from crm_configurations where id = 21;\nselect * from users where team_id = 36;\nselect u.email, cp.* from users u\njoin crm_profiles cp on u.id = cp.user_id\nwhere u.team_id = 36;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 36\nand sa.provider = 'bullhorn';\n\nselect * from social_accounts where id = 348;\nUPDATE social_accounts SET\nprovider_user_token = '21442_6802599_91:41179a58-21e7-4d7c-ad58-56bb666b2f65',\nprovider_refresh_token = '21442_6802599_91:01c6b335-3f2a-42e4-85ff-8a08fa65fceb',\nexpires = 1733998131,\nstate = 'connected'\nWHERE id = 348;\n\n# ************************************************************************************\nselect * from teams where id = 31;\nselect * from crm_configurations where id = 18;\n\nselect * from users where team_id = 31; # 257\nselect u.email, cp.* from users u\njoin crm_profiles cp on u.id = cp.user_id\nwhere u.team_id = 31;\n\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 31\nand sa.provider = 'close';\n\nselect * from contacts where crm_configuration_id = 18;\n\n# ********************** NEPTUNE **************************************************************\nselect * from teams;\nselect * from users where id IN (1030, 1035, 1052);\nselect * from crm_configurations;\n\nselect * from users where team_id = 65; # 257\nselect * from team_settings where team_id = 65; # 257\nselect * from invitations where team_id = 65; # 257\nselect * from users where email = 'integration-account@jiminny.com'; # 257\nselect u.email, cp.* from users u\njoin crm_profiles cp on u.id = cp.user_id\nwhere u.team_id = 65;\n\nselect * from crm_configurations where id = 53;\nselect * from accounts where crm_configuration_id = 53 order by id desc;\nselect * from leads where crm_configuration_id = 53 order by id desc;\nselect * from contacts where crm_configuration_id = 53 order by id desc;\nselect * from opportunities where crm_configuration_id = 53 order by id desc;\nselect * from crm_profiles where crm_configuration_id = 53 order by id desc;\nselect * from crm_fields where crm_configuration_id = 53 order by id desc;\nselect * from crm_field_values where crm_field_id = 3341 order by id desc;\nselect * from crm_layouts where crm_configuration_id = 53 order by id desc;\nselect * from stages where crm_configuration_id = 53 order by id desc;\n\n\nselect * from crm_profiles where crm_configuration_id = 13;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 65\nand sa.provider = 'integration-app';\n\nselect * from contacts where crm_configuration_id = 13;\n\nselect * from social_accounts where sociable_id = 283;\n\nSELECT * FROM opportunities WHERE crm_provider_id = '006O400000E9bzeIAB';\n\nselect * from activity_providers where team_id = 65;\nSELECT * FROM activities WHERE crm_configuration_id IN (51, 52, 53);\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 65\n;\n\n# ***************************** STAGING ********************************************\nSELECT * FROM teams;\nSELECT * FROM teams WHERE id = 88;\nSELECT * FROM teams WHERE id = 89;\nselect * from team_settings where team_id = 89;\nSELECT * FROM users WHERE team_id = 89;\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 89;\n\nselect * from users;\nSELECT * FROM social_accounts WHERE sociable_id = 1761;\nSELECT * FROM crm_configurations WHERE id = 70;\nselect * from accounts where crm_configuration_id = 70 order by id desc;\nselect * from leads where crm_configuration_id = 70 order by id desc;\nselect * from contacts where crm_configuration_id = 70 order by id desc;\nselect * from opportunities where crm_configuration_id = 70 order by id desc;\nselect * from crm_profiles where crm_configuration_id = 70 order by id desc;\nselect * from crm_fields where crm_configuration_id = 70 order by id desc;\nselect * from crm_field_values where crm_field_id = 3536 order by id desc;\nselect * from crm_layouts where crm_configuration_id = 70 order by id desc;\nselect * from stages where crm_configuration_id = 70 order by id desc;\nselect * from business_processes where crm_configuration_id = 70 order by id desc;\nselect * from business_process_stages where business_process_id = 34;\n\nselect * from contacts where id = 10468;\n\nselect * from crm_layouts where crm_configuration_id = 70;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 388;\nSELECT * FROM crm_fields WHERE id IN (3533,3534,3535);\n\nselect * from activities where crm_configuration_id = 70\nand (account_id IS NOT NULL or lead_id IS NOT NULL or contact_id IS NOT NULL or opportunity_id IS NOT NULL) order by id desc;\n\nSELECT * FROM activities WHERE uuid_to_bin('2e10b60f-8a61-41c5-a3d4-28835353dc65') = uuid;\nSELECT * FROM activities where crm_configuration_id = 69 ;\n\nSELECT * FROM users WHERE email LIKE '%jiminny_web_sa2@jiminny.com%';\nSELECT * FROM activities WHERE uuid_to_bin('5a150c93-40fc-42ec-b3bd-c1d328e09f6e') = uuid;\nSELECT * FROM opportunities WHERE id = 385;\n\nselect * from participants p\njoin activities a on p.activity_id = a.id\nwhere a.crm_configuration_id = 70\nand (p.lead_id IS NOT NULL or p.contact_id IS NOT NULL);\nSELECT * FROM participants WHERE id = 1013638;\n\nselect * from teams where id = 90;\nselect * from users where team_id = 90;\nselect * from social_accounts where social_accounts.sociable_id IN (1960,1760);\nSELECT * FROM crm_profiles WHERE crm_configuration_id = 71;\nselect * from invitations where team_id = 90;\n\nselect * from crm_configurations where id = 71;\nselect * from accounts where crm_configuration_id = 71 order by id desc;\nselect * from leads where crm_configuration_id = 71 order by id desc;\nselect * from contacts where crm_configuration_id = 71 order by id desc;\nselect * from opportunities where crm_configuration_id = 71 order by id desc;\nselect * from crm_profiles where crm_configuration_id = 71 order by id desc;\nselect * from crm_fields where crm_configuration_id = 71 order by id desc;\nselect * from crm_field_values where crm_field_id = 3341 order by id desc;\nselect * from crm_layouts where crm_configuration_id = 71 order by id desc;\nselect * from stages where crm_configuration_id = 71 order by id desc;\n\nselect * from users order by secondary_email desc;\nselect u.id, u.email, u.status, sa.id, sa.provider_user_id from social_accounts sa\n join users u on sa.sociable_id = u.id\nwhere sa.provider = 'google' and u.email LIKE 'aneliya%';\n\nselect * from failed_jobs order by id desc;\n\nselect * from users where email = 'ben.allwright@learningpeople.co.uk' or secondary_email = 'ben.allwright@learningpeople.co.uk';\n\nselect * from teams;\nSELECT * FROM crm_profiles WHERE crm_configuration_id = 39;\nSELECT * FROM crm_fields WHERE crm_configuration_id = 39 and object_type = 'task';\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 1\nand sa.provider = 'salesforce';\n\n# ************************************************************************************\nSELECT * FROM activities WHERE uuid_to_bin('c38b3895-fd0f-4b1f-9fb2-c170dba137c6') = uuid;\nSELECT * FROM crm_configurations WHERE id = 70;\n\nselect * from teams where id = 1;\nselect * from groups where team_id = 1;\nselect * from users where team_id = 1;\n\nselect o.id, o.name,o.close_date, u.id, u.name, u.group_id, r.id, r.display_name, g.name, g.scope from opportunities o\njoin users u on o.user_id = u.id\njoin groups g on u.group_id = g.id\njoin role_user ru on u.id = ru.user_id\njoin roles r on ru.role_id = r.id\nwhere o.crm_configuration_id = 39 and close_date > '2024-01-01 00:00:00';\n\nselect * from role_user where user_id = 143;\nselect * from roles;\n\nselect * from role_user;\nselect * from groups where id = 9;\nselect * from scope_groups where group_id = 9;\n\n# ************************************************************************************\nselect * from teams where id = 36;\nselect * from crm_configurations;\nSELECT * FROM social_accounts WHERE sociable_id = 121;\n\nhttps://crmsandbox.zoho.com/crm/jiminnyw4/tab/Leads/4776201000005049105\nhttps://crmsandbox.zoho.com/crm/\n\nhttps://crm.zoho.com/crm/org3469620/tab/Leads/230045000229559080\n https://crm.zoho.com/crm/\n org3469620\n\nSELECT * FROM activities WHERE uuid_to_bin('03382d20-c8bc-48e7-a3d4-90b52fa5ceab') = uuid;\n\nselect * from users where email LIKE \"%mobile_automation_%\";\nselect * from social_accounts where sociable_id IN (2228);\nselect * from crm_profiles where user_id IN (2222,2223,2226,2227);\n\nselect * from teams order by id desc;\nSELECT * FROM users WHERE id = 2229;\nSELECT * FROM crm_profiles WHERE user_id = 2229;\nselect * from opportunities where crm_configuration_id = 88;\nselect * from crm_fields where crm_configuration_id = 88;\nselect * from crm_profiles where crm_configuration_id = 88;\n\nSELECT * FROM teams WHERE id = 1;\n\nSELECT * FROM users WHERE id = 143;\nSELECT * FROM users WHERE uuid_to_bin('fde193d3-06a2-4e1a-8895-62b94039215d') = uuid;\nSELECT * FROM teams WHERE uuid_to_bin('73385071-a756-42ae-9c73-8b53f2309467') = uuid;\n\nhttps://app.staging.jiminny.com/ondemand?\n min_duration=1\n &\n only_recorded=1\n &\n user_id%5B%5D=641f1acb-16b8-42d1-8726-df52979dad0e\n &\n sequence_number=2\n\n select * from users where team_id = 1 and email like '%stoyan%'\n\nselect * from coaching_feedbacks;\n\nselect * from teams;\nSELECT * FROM users WHERE team_id = 36;\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 19\nand sa.provider = 'pipedrive';\n\nselect * from users where id = 143;\n\nSELECT * FROM users WHERE uuid_to_bin('73180eeb-33de-4065-977d-ccbe0e6c94fc') = uuid;\nSELECT * FROM teams WHERE uuid_to_bin('73180eeb-33de-4065-977d-ccbe0e6c94fc') = uuid;\nSELECT * FROM activity_shares WHERE uuid_to_bin('73180eeb-33de-4065-977d-ccbe0e6c94fc') = uuid;\n\nselect * from users where team_id = 2;\nselect * from activities where crm_configuration_id = 39\nand activities.scheduled_start_time BETWEEN '2025-04-09 00:00:00' AND '2025-04-09 23:59:59'\nAND user_id = 143\norder by id desc;\n\n# ************************************************************************************\nselect * from teams where id = 142; # 2312, 126\nselect * from team_settings;\nselect * from users where team_id = 142; # 21642\nSELECT * FROM social_accounts WHERE sociable_id = 21642;\nSELECT * FROM crm_profiles cp join users u ON u.id = cp.user_id WHERE team_id = 142;\nselect * from crm_profiles where id IN (93);\nselect * from invitations;\nselect * from team_features where team_id = 1;\n\nSELECT * FROM crm_configurations WHERE id = 126;\nselect * from accounts where crm_configuration_id = 126 order by id desc;\nselect * from leads where crm_configuration_id = 126 order by id desc;\nselect * from contacts where crm_configuration_id = 126 order by id desc;\nselect * from opportunities where crm_configuration_id = 126 order by id desc;\nselect * from crm_profiles where crm_configuration_id = 126 order by id desc;\nselect * from crm_fields where crm_configuration_id = 126 # 11060\n# and type IN ('picklist', 'status')\n# and object_type = 'task'\norder by id desc;\n# 5731,5732,5733\nselect DISTINCT crm_field_id from crm_field_values where crm_field_id IN (11151,12239,12215,12185,12175,12165,12144,12137,12127,12109,12107,12105,12103,12092,12037,12005,12003,11987,11969,11958,11951,11942,11931,11924,11921,11917,11915,11901,11893,11883,11872,11870,11868,11866,11839,11833,11821,11793,11780,11777,11769,11757,11737,11735,11656,11645,11638,11629,11618,11611,11602,11591,11584,11581,11558,11544,11543,11534,11532,11529,11527,11503,11497,11493,11488,11470,11468,11457,11455,11397,11387,11372,11363,11348,11323,11318,11309,11301,11300,11292,11290,11286,11284,11256,11252,11242,11237,11233,11219,11176,11160) order by id desc;\nselect * from crm_layouts where crm_configuration_id = 126 order by id desc;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id in (300,299,298);\nselect * from stages where crm_configuration_id = 126 order by id desc;\nselect * from business_processes where crm_configuration_id = 126 order by id desc;\nselect * from business_process_stages where business_process_id IN (76,75,74,73);\nselect * from playbooks where team_id = 142;\nselect * from playbook_layouts where playbook_id IN (108);\nSELECT * FROM playbook_categories WHERE playbook_id IN (108);\n\nselect * from teams where id = 130;\nSELECT * FROM social_accounts WHERE sociable_id = 2291;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 2\nand sa.provider = 'hubspot';\n\nSELECT * FROM activities\n WHERE crm_configuration_id = 110;\n\nselect * from teams;\nselect * from crm_configurations;\n\nSELECT * FROM activities WHERE id = 628773;\nSELECT * FROM crm_profiles WHERE user_id = 1460;\nSELECT * FROM social_accounts WHERE sociable_id = 2291;\n\nselect * from teams;\nselect ru.*, pr.*, p.* from users u join role_user ru on ru.user_id = u.id\njoin permission_role pr on pr.role_id = ru.role_id\n join permissions p on p.id = pr.permission_id\nwhere team_id = 495 and p.name IN ('dial');\n\nselect * from teams where id = 145;\nselect * from crm_configurations where id = 129;\nselect * from social_accounts where sociable_id = 2317;\nSELECT * FROM activities WHERE uuid_to_bin('8dbab184-a333-4268-ad57-fb41f8d53a9a') = uuid;\n\nselect * from teams where id = 1;\nSELECT * FROM crm_layouts WHERE crm_configuration_id = 39;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 280;\nSELECT * FROM crm_layout_entities WHERE id = 5507;\nSELECT * FROM crm_fields WHERE crm_configuration_id = 39 and object_type IN ('event');\n\nselect * from teams;\nselect * from activities where crm_configuration_id = 14;\n\nSELECT * FROM social_accounts where provider = 'copper';\n\nselect * from activities where id = 628467;\nselect * from participants where activity_id = 628467;\n\nSELECT * FROM contacts WHERE id = 3969;\nSELECT * FROM accounts WHERE id = 177;\n\nSELECT * FROM activities WHERE uuid_to_bin('4eb54c77-cfa3-2bd4-84a7-9ed46a21c988') = uuid;\n\n# ********************* BH\nselect * from teams where id = 36;\nSELECT * FROM crm_configurations WHERE id = 21;\nselect * from activities where crm_configuration_id = 21 and id = 607901;\nselect * from activities where crm_configuration_id = 21;\n\nselect * roles;\nselect * from permissions;\nselect * from permission_role where permission_id = 226;\n\nselect * from migrations order by id desc;\n\n# mercury\n# neptune\n# earth\n\nselect * from teams;\nselect * from teams where id = 19;\nselect * from teams where id = 27;\nselect * from users where team_id = 27;\nSELECT * FROM crm_configurations WHERE id = 42;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 19\nand sa.provider = 'pipedrive';\n\nselect * from activities where id = 631461;\nSELECT * FROM crm_field_values WHERE crm_field_id = 180;\n\nselect * from teams where id = 2;\nSELECT * FROM social_accounts WHERE sociable_id = 89;\n\nSELECT * FROM activities WHERE uuid_to_bin('ba0c029a-bc14-4e17-8603-64174acebcbb') = uuid; # 634273\nselect * from activity_summary_logs where activity_id = 634273;\n\nselect * from sidekick_settings where team_id = 2;\n\nselect * from teams; # 2, 2\nSELECT * FROM crm_configurations WHERE team_id = 2; # 2\nselect * from team_features where team_id = 2;\nselect * from features;\nSELECT * FROM opportunities WHERE crm_configuration_id = 2 and crm_provider_id = '51317301383';\nSELECT * FROM opportunities WHERE crm_configuration_id = 2 order by id desc;\n\nselect * from automated_reports order by id desc;\nselect * from automated_report_results order by id desc;\nselect * from users where team_id = 1 and id IN (7160, 3248);\nselect * from migrations order by id desc;\n\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 1 and sa.provider = 'salesforce';\n\nselect * from teams where id = 1;\nselect * from groups g JOIN playbooks p on g.playbook_id = p.id where g.team_id = 1;\nselect * from groups where id = 565;\nselect * from playbooks where team_id = 1;\nselect * from playbooks where id = 175;\nselect * from playbook_categories where playbook_id = 175;\nselect * from users where team_id = 1;\nselect * from users where id = 7160;\nselect * from crm_profiles where user_id = 7160;\nselect * from features;\nselect\n *\n# id, uuid, type, provider, playbook_category_id, user_id, lead_id, contact_id, account_id, opportunity_id, stage_id,\n# crm_configuration_id, crm_provider_id, transcription_id, status\nfrom activities where crm_configuration_id = 1 and type = 'conference'\n# and crm_provider_id IS NOT NULL\nand provider != 'uploader' and actual_start_time IS NOT NULL\nORDER by id desc;\nselect * from activities where id = 54747783; # 00UO400000pCzojMAC\n\nselect p.id, p.activity_type, pc.id, pc.name\nFROM playbooks p\njoin playbook_categories pc on p.id = pc.playbook_id\nwhere p.team_id = 1 and p.activity_type = 'event';\n\nSELECT * FROM crm_fields WHERE crm_configuration_id = 1 and object_type = 'event';\nSELECT * FROM crm_field_values WHERE crm_field_id = 4;\n\nselect * from crm_layouts cl join playbook_layouts pl on cl.id = pl.layout_id\nwhere crm_configuration_id = 1 and pl.playbook_id = 175;\n\nselect * from teams;\nSELECT r.* FROM automated_reports r\njoin teams t on r.team_id = t.id\nWHERE r.frequency = 'daily'\n and r.status = 1\nAND t.status = 'active'\nAND (r.expires_at >= now() OR r.expires_at IS NULL);\n\nselect * from automated_report_results where report_id IN (18, 33);\n\nselect * from activity_searches where id = 10932;\nselect * from activity_search_filters where activity_search_id = 10932;\nselect * from automated_reports;\nselect * from automated_report_results where report_id IN (34, 35);","depth":4,"value":"SELECT * FROM teams WHERE id = 1;\n\nselect * from crm_layouts where crm_configuration_id = 39;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 283;\nSELECT * FROM crm_fields WHERE id = 2234;\nSELECT * FROM crm_field_values WHERE crm_field_id = 2234;\n\nselect * from crm_profiles where user_id = 143;\n\nselect * from record_types where crm_configuration_id = 39; # 0121K000001MHElQAO,0121K000001MHEqQAO\nselect * from business_processes where crm_configuration_id = 39;\n# 01941000000H669AAC, 01941000000H66JAAS\n\nselect * from record_type_field_values\n where record_type_id IN (24);\n\nselect * from crm_field_values where id IN (2730);\n\nselect * from crm_configurations where id = 39;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 1\nand sa.provider = 'salesforce'; #1035\n\n\nselect * from users where team_id = 1; # 222 group 3\nSELECT * FROM activities WHERE user_id = 222 order by id desc;\nselect * from sidekick_settings where team_id = 1;\nselect * from teams where id = 1;\nselect * from team_features where team_id = 1;\n\nselect * from activities where crm_configuration_id = 2\nand provider = 'ms-teams' and id = 608765;\n\nSELECT * FROM activities WHERE crm_configuration_id = 2 and crm_provider_id = '59523413338';\n\nselect * from sidekick_settings where team_id = 2;\n\nSELECT * FROM activities WHERE id = 608660;\nselect * from activity_summary_logs where activity_id = 608660;\nselect * from ai_prompts where transcription_id = 11214;\n\n# ********************************************************************************************************\nSELECT * FROM activities WHERE uuid_to_bin('ed78a437-2804-450e-ab2f-56ab1c641346') = uuid;\n# id: 608818, crm: 59628809737\nSELECT * FROM activities WHERE uuid_to_bin('36b06e55-afdd-4782-8dee-c624cd0af191') = uuid;\n# id: 608821, crm: 59632069252\nSELECT ce.start_time, ce.end_time, a.id, a.uuid, crm_provider_id, calendar_event_id, title,\nplaybook_category_id, user_id, lead_id, contact_id, account_id, opportunity_id,\nscheduled_start_time, scheduled_end_time, actual_start_time, actual_end_time, a.created_at\nFROM activities a\njoin calendar_events ce on a.calendar_event_id = ce.id\nWHERE a.id IN (608818, 608821);\n\nselect * from users where team_id = 1;\nselect * from team_settings where team_id = 1;\nselect * from crm_profiles where crm_configuration_id = 39 order by user_id;\n\nselect * from team_features where team_id = 1;\n\nselect * from users where team_id = 2;\n\nSELECT * FROM activities WHERE uuid_to_bin('ec7647e9-5225-458b-b475-f31aa2769204') = uuid; # 612639\n# Preslava N. Ivanova, grou id 3\n\nSELECT * FROM opportunities WHERE uuid_to_bin('a2928fe5-aec5-46cb-85d9-7654c89e46a6') = uuid;\n\nselect * from activities where opportunity_id = 344 and actual_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00';\n\nselect\n a.id,\n a.type,\n a.scheduled_start_time,\n a.actual_start_time,\n a.created_at,\n a.opportunity_id,\n a.status\nFROM activities a\nWHERE opportunity_id = 344\nand status IN ('completed', 'received', 'delivered')\nand (\n (a.actual_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00')\nOR (a.created_at between '2024-10-11 00:00:00' and '2024-10-12 00:00:00')\nOR (a.scheduled_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00'))\n;\n\nSELECT * FROM users WHERE id = 222;\n\nSELECT * FROM crm_profiles WHERE user_id = 222;\nselect * from crm_layouts where crm_configuration_id = 39;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 281;\n\nselect * from group_deal_risk_types;\n\nselect * from opportunities where team_id = 1;\n\nSELECT * FROM opportunities WHERE id = 315;\nSELECT * FROM crm_field_data WHERE object_id = 315;\nselect * from crm_field_data where object_id = 260;\n\nselect * from generic_ai_prompts where subject_id = 315;\n\nselect * from teams; # 36, 21, 121, james.graham@bullhorn.jiminny.com\nSELECT * FROM social_accounts WHERE sociable_id = 121 and provider = 'bullhorn';\n\n# ************************************************************************************\nselect * from teams where id = 1;\nselect * from crm_configurations where id = 39;\nselect * from users where team_id = 1;\nselect u.email, cp.* from users u\njoin crm_profiles cp on u.id = cp.user_id\nwhere u.team_id = 1;\n# 1 - 00541000004281rAAA\n# 204 - 0052g000003freeAAA\n# 429 - 0052g000003qGOiAAM\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 1\nand sa.provider = 'salesforce';\n\nselect * from activities where type = 'softphone'\nand created_at > '2024-12-11 15:24:36' order by id desc;\n\nselect * from activity_providers where team_id = 1;\nselect * from activity_provider_users where activity_provider_id = 328;\n\nselect * from opportunities where crm_configuration_id = 39\nAND account_id = 178 AND is_closed = false\norder by created_at DESC;\n\nselect * from contacts where id = 3952;\nselect * from accounts where id = 178;\n\n# ************************************************************************************\nselect * from teams where id = 36;\nselect * from crm_configurations where id = 21;\nselect * from users where team_id = 36;\nselect u.email, cp.* from users u\njoin crm_profiles cp on u.id = cp.user_id\nwhere u.team_id = 36;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 36\nand sa.provider = 'bullhorn';\n\nselect * from social_accounts where id = 348;\nUPDATE social_accounts SET\nprovider_user_token = '21442_6802599_91:41179a58-21e7-4d7c-ad58-56bb666b2f65',\nprovider_refresh_token = '21442_6802599_91:01c6b335-3f2a-42e4-85ff-8a08fa65fceb',\nexpires = 1733998131,\nstate = 'connected'\nWHERE id = 348;\n\n# ************************************************************************************\nselect * from teams where id = 31;\nselect * from crm_configurations where id = 18;\n\nselect * from users where team_id = 31; # 257\nselect u.email, cp.* from users u\njoin crm_profiles cp on u.id = cp.user_id\nwhere u.team_id = 31;\n\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 31\nand sa.provider = 'close';\n\nselect * from contacts where crm_configuration_id = 18;\n\n# ********************** NEPTUNE **************************************************************\nselect * from teams;\nselect * from users where id IN (1030, 1035, 1052);\nselect * from crm_configurations;\n\nselect * from users where team_id = 65; # 257\nselect * from team_settings where team_id = 65; # 257\nselect * from invitations where team_id = 65; # 257\nselect * from users where email = 'integration-account@jiminny.com'; # 257\nselect u.email, cp.* from users u\njoin crm_profiles cp on u.id = cp.user_id\nwhere u.team_id = 65;\n\nselect * from crm_configurations where id = 53;\nselect * from accounts where crm_configuration_id = 53 order by id desc;\nselect * from leads where crm_configuration_id = 53 order by id desc;\nselect * from contacts where crm_configuration_id = 53 order by id desc;\nselect * from opportunities where crm_configuration_id = 53 order by id desc;\nselect * from crm_profiles where crm_configuration_id = 53 order by id desc;\nselect * from crm_fields where crm_configuration_id = 53 order by id desc;\nselect * from crm_field_values where crm_field_id = 3341 order by id desc;\nselect * from crm_layouts where crm_configuration_id = 53 order by id desc;\nselect * from stages where crm_configuration_id = 53 order by id desc;\n\n\nselect * from crm_profiles where crm_configuration_id = 13;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 65\nand sa.provider = 'integration-app';\n\nselect * from contacts where crm_configuration_id = 13;\n\nselect * from social_accounts where sociable_id = 283;\n\nSELECT * FROM opportunities WHERE crm_provider_id = '006O400000E9bzeIAB';\n\nselect * from activity_providers where team_id = 65;\nSELECT * FROM activities WHERE crm_configuration_id IN (51, 52, 53);\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 65\n;\n\n# ***************************** STAGING ********************************************\nSELECT * FROM teams;\nSELECT * FROM teams WHERE id = 88;\nSELECT * FROM teams WHERE id = 89;\nselect * from team_settings where team_id = 89;\nSELECT * FROM users WHERE team_id = 89;\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 89;\n\nselect * from users;\nSELECT * FROM social_accounts WHERE sociable_id = 1761;\nSELECT * FROM crm_configurations WHERE id = 70;\nselect * from accounts where crm_configuration_id = 70 order by id desc;\nselect * from leads where crm_configuration_id = 70 order by id desc;\nselect * from contacts where crm_configuration_id = 70 order by id desc;\nselect * from opportunities where crm_configuration_id = 70 order by id desc;\nselect * from crm_profiles where crm_configuration_id = 70 order by id desc;\nselect * from crm_fields where crm_configuration_id = 70 order by id desc;\nselect * from crm_field_values where crm_field_id = 3536 order by id desc;\nselect * from crm_layouts where crm_configuration_id = 70 order by id desc;\nselect * from stages where crm_configuration_id = 70 order by id desc;\nselect * from business_processes where crm_configuration_id = 70 order by id desc;\nselect * from business_process_stages where business_process_id = 34;\n\nselect * from contacts where id = 10468;\n\nselect * from crm_layouts where crm_configuration_id = 70;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 388;\nSELECT * FROM crm_fields WHERE id IN (3533,3534,3535);\n\nselect * from activities where crm_configuration_id = 70\nand (account_id IS NOT NULL or lead_id IS NOT NULL or contact_id IS NOT NULL or opportunity_id IS NOT NULL) order by id desc;\n\nSELECT * FROM activities WHERE uuid_to_bin('2e10b60f-8a61-41c5-a3d4-28835353dc65') = uuid;\nSELECT * FROM activities where crm_configuration_id = 69 ;\n\nSELECT * FROM users WHERE email LIKE '%jiminny_web_sa2@jiminny.com%';\nSELECT * FROM activities WHERE uuid_to_bin('5a150c93-40fc-42ec-b3bd-c1d328e09f6e') = uuid;\nSELECT * FROM opportunities WHERE id = 385;\n\nselect * from participants p\njoin activities a on p.activity_id = a.id\nwhere a.crm_configuration_id = 70\nand (p.lead_id IS NOT NULL or p.contact_id IS NOT NULL);\nSELECT * FROM participants WHERE id = 1013638;\n\nselect * from teams where id = 90;\nselect * from users where team_id = 90;\nselect * from social_accounts where social_accounts.sociable_id IN (1960,1760);\nSELECT * FROM crm_profiles WHERE crm_configuration_id = 71;\nselect * from invitations where team_id = 90;\n\nselect * from crm_configurations where id = 71;\nselect * from accounts where crm_configuration_id = 71 order by id desc;\nselect * from leads where crm_configuration_id = 71 order by id desc;\nselect * from contacts where crm_configuration_id = 71 order by id desc;\nselect * from opportunities where crm_configuration_id = 71 order by id desc;\nselect * from crm_profiles where crm_configuration_id = 71 order by id desc;\nselect * from crm_fields where crm_configuration_id = 71 order by id desc;\nselect * from crm_field_values where crm_field_id = 3341 order by id desc;\nselect * from crm_layouts where crm_configuration_id = 71 order by id desc;\nselect * from stages where crm_configuration_id = 71 order by id desc;\n\nselect * from users order by secondary_email desc;\nselect u.id, u.email, u.status, sa.id, sa.provider_user_id from social_accounts sa\n join users u on sa.sociable_id = u.id\nwhere sa.provider = 'google' and u.email LIKE 'aneliya%';\n\nselect * from failed_jobs order by id desc;\n\nselect * from users where email = 'ben.allwright@learningpeople.co.uk' or secondary_email = 'ben.allwright@learningpeople.co.uk';\n\nselect * from teams;\nSELECT * FROM crm_profiles WHERE crm_configuration_id = 39;\nSELECT * FROM crm_fields WHERE crm_configuration_id = 39 and object_type = 'task';\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 1\nand sa.provider = 'salesforce';\n\n# ************************************************************************************\nSELECT * FROM activities WHERE uuid_to_bin('c38b3895-fd0f-4b1f-9fb2-c170dba137c6') = uuid;\nSELECT * FROM crm_configurations WHERE id = 70;\n\nselect * from teams where id = 1;\nselect * from groups where team_id = 1;\nselect * from users where team_id = 1;\n\nselect o.id, o.name,o.close_date, u.id, u.name, u.group_id, r.id, r.display_name, g.name, g.scope from opportunities o\njoin users u on o.user_id = u.id\njoin groups g on u.group_id = g.id\njoin role_user ru on u.id = ru.user_id\njoin roles r on ru.role_id = r.id\nwhere o.crm_configuration_id = 39 and close_date > '2024-01-01 00:00:00';\n\nselect * from role_user where user_id = 143;\nselect * from roles;\n\nselect * from role_user;\nselect * from groups where id = 9;\nselect * from scope_groups where group_id = 9;\n\n# ************************************************************************************\nselect * from teams where id = 36;\nselect * from crm_configurations;\nSELECT * FROM social_accounts WHERE sociable_id = 121;\n\nhttps://crmsandbox.zoho.com/crm/jiminnyw4/tab/Leads/4776201000005049105\nhttps://crmsandbox.zoho.com/crm/\n\nhttps://crm.zoho.com/crm/org3469620/tab/Leads/230045000229559080\n https://crm.zoho.com/crm/\n org3469620\n\nSELECT * FROM activities WHERE uuid_to_bin('03382d20-c8bc-48e7-a3d4-90b52fa5ceab') = uuid;\n\nselect * from users where email LIKE \"%mobile_automation_%\";\nselect * from social_accounts where sociable_id IN (2228);\nselect * from crm_profiles where user_id IN (2222,2223,2226,2227);\n\nselect * from teams order by id desc;\nSELECT * FROM users WHERE id = 2229;\nSELECT * FROM crm_profiles WHERE user_id = 2229;\nselect * from opportunities where crm_configuration_id = 88;\nselect * from crm_fields where crm_configuration_id = 88;\nselect * from crm_profiles where crm_configuration_id = 88;\n\nSELECT * FROM teams WHERE id = 1;\n\nSELECT * FROM users WHERE id = 143;\nSELECT * FROM users WHERE uuid_to_bin('fde193d3-06a2-4e1a-8895-62b94039215d') = uuid;\nSELECT * FROM teams WHERE uuid_to_bin('73385071-a756-42ae-9c73-8b53f2309467') = uuid;\n\nhttps://app.staging.jiminny.com/ondemand?\n min_duration=1\n &\n only_recorded=1\n &\n user_id%5B%5D=641f1acb-16b8-42d1-8726-df52979dad0e\n &\n sequence_number=2\n\n select * from users where team_id = 1 and email like '%stoyan%'\n\nselect * from coaching_feedbacks;\n\nselect * from teams;\nSELECT * FROM users WHERE team_id = 36;\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 19\nand sa.provider = 'pipedrive';\n\nselect * from users where id = 143;\n\nSELECT * FROM users WHERE uuid_to_bin('73180eeb-33de-4065-977d-ccbe0e6c94fc') = uuid;\nSELECT * FROM teams WHERE uuid_to_bin('73180eeb-33de-4065-977d-ccbe0e6c94fc') = uuid;\nSELECT * FROM activity_shares WHERE uuid_to_bin('73180eeb-33de-4065-977d-ccbe0e6c94fc') = uuid;\n\nselect * from users where team_id = 2;\nselect * from activities where crm_configuration_id = 39\nand activities.scheduled_start_time BETWEEN '2025-04-09 00:00:00' AND '2025-04-09 23:59:59'\nAND user_id = 143\norder by id desc;\n\n# ************************************************************************************\nselect * from teams where id = 142; # 2312, 126\nselect * from team_settings;\nselect * from users where team_id = 142; # 21642\nSELECT * FROM social_accounts WHERE sociable_id = 21642;\nSELECT * FROM crm_profiles cp join users u ON u.id = cp.user_id WHERE team_id = 142;\nselect * from crm_profiles where id IN (93);\nselect * from invitations;\nselect * from team_features where team_id = 1;\n\nSELECT * FROM crm_configurations WHERE id = 126;\nselect * from accounts where crm_configuration_id = 126 order by id desc;\nselect * from leads where crm_configuration_id = 126 order by id desc;\nselect * from contacts where crm_configuration_id = 126 order by id desc;\nselect * from opportunities where crm_configuration_id = 126 order by id desc;\nselect * from crm_profiles where crm_configuration_id = 126 order by id desc;\nselect * from crm_fields where crm_configuration_id = 126 # 11060\n# and type IN ('picklist', 'status')\n# and object_type = 'task'\norder by id desc;\n# 5731,5732,5733\nselect DISTINCT crm_field_id from crm_field_values where crm_field_id IN (11151,12239,12215,12185,12175,12165,12144,12137,12127,12109,12107,12105,12103,12092,12037,12005,12003,11987,11969,11958,11951,11942,11931,11924,11921,11917,11915,11901,11893,11883,11872,11870,11868,11866,11839,11833,11821,11793,11780,11777,11769,11757,11737,11735,11656,11645,11638,11629,11618,11611,11602,11591,11584,11581,11558,11544,11543,11534,11532,11529,11527,11503,11497,11493,11488,11470,11468,11457,11455,11397,11387,11372,11363,11348,11323,11318,11309,11301,11300,11292,11290,11286,11284,11256,11252,11242,11237,11233,11219,11176,11160) order by id desc;\nselect * from crm_layouts where crm_configuration_id = 126 order by id desc;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id in (300,299,298);\nselect * from stages where crm_configuration_id = 126 order by id desc;\nselect * from business_processes where crm_configuration_id = 126 order by id desc;\nselect * from business_process_stages where business_process_id IN (76,75,74,73);\nselect * from playbooks where team_id = 142;\nselect * from playbook_layouts where playbook_id IN (108);\nSELECT * FROM playbook_categories WHERE playbook_id IN (108);\n\nselect * from teams where id = 130;\nSELECT * FROM social_accounts WHERE sociable_id = 2291;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 2\nand sa.provider = 'hubspot';\n\nSELECT * FROM activities\n WHERE crm_configuration_id = 110;\n\nselect * from teams;\nselect * from crm_configurations;\n\nSELECT * FROM activities WHERE id = 628773;\nSELECT * FROM crm_profiles WHERE user_id = 1460;\nSELECT * FROM social_accounts WHERE sociable_id = 2291;\n\nselect * from teams;\nselect ru.*, pr.*, p.* from users u join role_user ru on ru.user_id = u.id\njoin permission_role pr on pr.role_id = ru.role_id\n join permissions p on p.id = pr.permission_id\nwhere team_id = 495 and p.name IN ('dial');\n\nselect * from teams where id = 145;\nselect * from crm_configurations where id = 129;\nselect * from social_accounts where sociable_id = 2317;\nSELECT * FROM activities WHERE uuid_to_bin('8dbab184-a333-4268-ad57-fb41f8d53a9a') = uuid;\n\nselect * from teams where id = 1;\nSELECT * FROM crm_layouts WHERE crm_configuration_id = 39;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 280;\nSELECT * FROM crm_layout_entities WHERE id = 5507;\nSELECT * FROM crm_fields WHERE crm_configuration_id = 39 and object_type IN ('event');\n\nselect * from teams;\nselect * from activities where crm_configuration_id = 14;\n\nSELECT * FROM social_accounts where provider = 'copper';\n\nselect * from activities where id = 628467;\nselect * from participants where activity_id = 628467;\n\nSELECT * FROM contacts WHERE id = 3969;\nSELECT * FROM accounts WHERE id = 177;\n\nSELECT * FROM activities WHERE uuid_to_bin('4eb54c77-cfa3-2bd4-84a7-9ed46a21c988') = uuid;\n\n# ********************* BH\nselect * from teams where id = 36;\nSELECT * FROM crm_configurations WHERE id = 21;\nselect * from activities where crm_configuration_id = 21 and id = 607901;\nselect * from activities where crm_configuration_id = 21;\n\nselect * roles;\nselect * from permissions;\nselect * from permission_role where permission_id = 226;\n\nselect * from migrations order by id desc;\n\n# mercury\n# neptune\n# earth\n\nselect * from teams;\nselect * from teams where id = 19;\nselect * from teams where id = 27;\nselect * from users where team_id = 27;\nSELECT * FROM crm_configurations WHERE id = 42;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 19\nand sa.provider = 'pipedrive';\n\nselect * from activities where id = 631461;\nSELECT * FROM crm_field_values WHERE crm_field_id = 180;\n\nselect * from teams where id = 2;\nSELECT * FROM social_accounts WHERE sociable_id = 89;\n\nSELECT * FROM activities WHERE uuid_to_bin('ba0c029a-bc14-4e17-8603-64174acebcbb') = uuid; # 634273\nselect * from activity_summary_logs where activity_id = 634273;\n\nselect * from sidekick_settings where team_id = 2;\n\nselect * from teams; # 2, 2\nSELECT * FROM crm_configurations WHERE team_id = 2; # 2\nselect * from team_features where team_id = 2;\nselect * from features;\nSELECT * FROM opportunities WHERE crm_configuration_id = 2 and crm_provider_id = '51317301383';\nSELECT * FROM opportunities WHERE crm_configuration_id = 2 order by id desc;\n\nselect * from automated_reports order by id desc;\nselect * from automated_report_results order by id desc;\nselect * from users where team_id = 1 and id IN (7160, 3248);\nselect * from migrations order by id desc;\n\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 1 and sa.provider = 'salesforce';\n\nselect * from teams where id = 1;\nselect * from groups g JOIN playbooks p on g.playbook_id = p.id where g.team_id = 1;\nselect * from groups where id = 565;\nselect * from playbooks where team_id = 1;\nselect * from playbooks where id = 175;\nselect * from playbook_categories where playbook_id = 175;\nselect * from users where team_id = 1;\nselect * from users where id = 7160;\nselect * from crm_profiles where user_id = 7160;\nselect * from features;\nselect\n *\n# id, uuid, type, provider, playbook_category_id, user_id, lead_id, contact_id, account_id, opportunity_id, stage_id,\n# crm_configuration_id, crm_provider_id, transcription_id, status\nfrom activities where crm_configuration_id = 1 and type = 'conference'\n# and crm_provider_id IS NOT NULL\nand provider != 'uploader' and actual_start_time IS NOT NULL\nORDER by id desc;\nselect * from activities where id = 54747783; # 00UO400000pCzojMAC\n\nselect p.id, p.activity_type, pc.id, pc.name\nFROM playbooks p\njoin playbook_categories pc on p.id = pc.playbook_id\nwhere p.team_id = 1 and p.activity_type = 'event';\n\nSELECT * FROM crm_fields WHERE crm_configuration_id = 1 and object_type = 'event';\nSELECT * FROM crm_field_values WHERE crm_field_id = 4;\n\nselect * from crm_layouts cl join playbook_layouts pl on cl.id = pl.layout_id\nwhere crm_configuration_id = 1 and pl.playbook_id = 175;\n\nselect * from teams;\nSELECT r.* FROM automated_reports r\njoin teams t on r.team_id = t.id\nWHERE r.frequency = 'daily'\n and r.status = 1\nAND t.status = 'active'\nAND (r.expires_at >= now() OR r.expires_at IS NULL);\n\nselect * from automated_report_results where report_id IN (18, 33);\n\nselect * from activity_searches where id = 10932;\nselect * from activity_search_filters where activity_search_id = 10932;\nselect * from automated_reports;\nselect * from automated_report_results where report_id IN (34, 35);","role_description":"text entry area","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.088194445,"height":0.027777778},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"102","depth":4,"role_description":"text"},{"role":"AXStaticText","text":"3","depth":4,"role_description":"text"},{"role":"AXStaticText","text":"34","depth":4,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Services\\Kiosk\\AutomatedReports;\n\nuse Carbon\\CarbonImmutable;\nuse Carbon\\CarbonInterface;\nuse Carbon\\Exceptions\\InvalidFormatException;\nuse DateTime;\nuse DateTimeInterface;\nuse DateTimeZone;\nuse Illuminate\\Contracts\\Bus\\Dispatcher as BusDispatcher;\nuse Illuminate\\Database\\Eloquent\\Builder;\nuse Illuminate\\Support\\Carbon;\nuse Illuminate\\Support\\Collection;\nuse Illuminate\\Support\\Facades\\Log;\nuse Illuminate\\Support\\Facades\\Storage;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinition\\InputTypeEnum;\nuse Jiminny\\Component\\AskAnything\\AskAnythingPromptService;\nuse Jiminny\\Component\\AskAnything\\Dtos\\AskAnythingPromptDto;\nuse Jiminny\\Component\\UrlGenerator\\Webhook;\nuse Jiminny\\Contracts\\Repositories\\PlaybookCategoryRepository;\nuse Jiminny\\Contracts\\Repositories\\TeamRepository;\nuse Jiminny\\Contracts\\Repositories\\UserRepository;\nuse Jiminny\\Exceptions\\ApplicationException;\nuse Jiminny\\Exceptions\\InvalidArgumentException;\nuse Jiminny\\Exceptions\\ModelNotFoundException;\nuse Jiminny\\Jobs\\AutomatedReports\\RequestGenerateReportJob;\nuse Jiminny\\Models\\Activity\\Search;\nuse Jiminny\\Models\\AskAnything\\AskAnythingPrompt;\nuse Jiminny\\Models\\AskAnything\\AskAnythingPromptTarget;\nuse Jiminny\\Models\\AutomatedReport;\nuse Jiminny\\Models\\AutomatedReportResult;\nuse Jiminny\\Models\\Contracts\\UserContract;\nuse Jiminny\\Models\\Feature\\FeatureEnum;\nuse Jiminny\\Models\\Team;\nuse Jiminny\\Models\\User;\nuse Jiminny\\Repositories\\AskAnythingRepository;\nuse Jiminny\\Repositories\\AutomatedReportsRepository;\nuse Jiminny\\Repositories\\GroupRepository;\nuse Jiminny\\Repositories\\SearchRepository;\nuse Jiminny\\Repositories\\StageRepository;\nuse Throwable;\n\nclass AutomatedReportsService\n{\n public const string TYPE_LOSS_ANALYSIS = 'loss_analysis';\n public const string TYPE_ASK_JIMINNY = 'ask_jiminny';\n\n /**\n * Standard report types (used by kiosk for existing automated reports).\n */\n // @TODO this will add filter, however if we need to control feature by FF we need conditional logic\n public const array TYPES = [\n ['id' => 'exec_summary', 'name' => 'Exec Summary'],\n ['id' => 'coaching_profiles', 'name' => 'Coaching Profiles'],\n ['id' => 'product_feedback', 'name' => 'Product Feedback'],\n ['id' => self::TYPE_LOSS_ANALYSIS, 'name' => 'Loss Analysis'],\n// ['id' => 'questions', 'name' => 'Questions'],\n// ['id' => 'statistical_quant', 'name' => 'Statistical Quantitative'],\n ];\n\n public const array ALL_TYPES = [\n ...self::TYPES,\n ['id' => self::TYPE_ASK_JIMINNY, 'name' => 'Ask Jiminny'],\n ];\n\n public const string FREQUENCY_DAILY = 'daily';\n public const string FREQUENCY_WEEKLY = 'weekly';\n public const string FREQUENCY_MONTHLY = 'monthly';\n public const string FREQUENCY_QUARTERLY = 'quarterly';\n public const string FREQUENCY_ONE_OFF = 'one_off';\n\n /**\n * Frequencies for standard (non-Ask Jiminny) reports.\n */\n public const array FREQUENCIES = [\n ['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],\n ['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],\n ['id' => self::FREQUENCY_QUARTERLY, 'name' => 'Quarterly'],\n ['id' => self::FREQUENCY_ONE_OFF, 'name' => 'One-off'],\n ];\n\n /**\n * Frequencies for Ask Jiminny reports.\n */\n public const array ASK_JIMINNY_FREQUENCIES = [\n ['id' => self::FREQUENCY_DAILY, 'name' => 'Daily'],\n ['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],\n ['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],\n ];\n\n public const string MEDIA_TYPE_PDF = 'pdf';\n public const string MEDIA_TYPE_PODCAST = 'podcast';\n public const array MEDIA_TYPES = [self::MEDIA_TYPE_PDF, self::MEDIA_TYPE_PODCAST];\n public const array MEDIA_TYPE_OBJECT_PDF = ['id' => self::MEDIA_TYPE_PDF, 'name' => 'PDF'];\n public const array MEDIA_TYPE_OBJECT_PODCAST = ['id' => self::MEDIA_TYPE_PODCAST, 'name' => 'Podcast'];\n public const array MEDIA_TYPE_OBJECTS = [self::MEDIA_TYPE_OBJECT_PDF, self::MEDIA_TYPE_OBJECT_PODCAST];\n\n public const array CALL_TYPE_CONFERENCE = ['id' => 'conference', 'name' => 'Conference'];\n public const array CALL_TYPE_DIALER = ['id' => 'dialer', 'name' => 'Dialer'];\n public const int SENT_REPORT_AT_HOURS = 5;\n public const string PDF_KEY = 'pdf';\n public const string AUDIO_KEY = 'audio';\n\n private const array ALL_FREQUENCIES = [\n ['id' => self::FREQUENCY_DAILY, 'name' => 'Daily'],\n ['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],\n ['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],\n ['id' => self::FREQUENCY_QUARTERLY, 'name' => 'Quarterly'],\n ['id' => self::FREQUENCY_ONE_OFF, 'name' => 'One-off'],\n ];\n private const string S3_DIR = 'reports';\n private const array FILE_EXTENSIONS_VARIANTS = ['html', 'MD', 'pdf'];\n private const array FILE_PODCAST_EXTENSIONS_VARIANTS = ['json', 'mp3', 'ssml'];\n\n public function __construct(\n private readonly TeamRepository $teamRepository,\n private readonly GroupRepository $groupRepository,\n private readonly UserRepository $userRepository,\n private readonly StageRepository $stageRepository,\n private readonly DealStagesService $dealStagesService,\n private readonly RecipientsService $recipientsService,\n private readonly AutomatedReportsRepository $automatedReportsRepository,\n private readonly Webhook $webhookService,\n private readonly BusDispatcher $dispatcher,\n private readonly ActivityTypeService $activityTypeService,\n private readonly PlaybookCategoryRepository $playbookCategoryRepository,\n private readonly AskAnythingPromptService $askAnythingPromptService,\n private readonly SearchRepository $activitySearchRepository,\n private readonly AskAnythingRepository $askAnythingRepository,\n ) {\n }\n\n public static function getTypes(): array\n {\n $types = self::TYPES;\n\n return array_map(static function ($type) {\n return $type['id'];\n }, $types);\n }\n\n public static function getCallTypes(): array\n {\n return array_map(static function ($callType) {\n return $callType['id'];\n }, [self::CALL_TYPE_CONFERENCE, self::CALL_TYPE_DIALER]);\n }\n\n public static function getFrequencies(): array\n {\n return array_map(static function ($frequency) {\n return $frequency['id'];\n }, self::FREQUENCIES);\n }\n\n // front-facing structure\n public function getReportEnabledFieldData(bool $value = false): array\n {\n return [\n 'id' => 'report_enabled',\n 'label' => '',\n 'inputType' => InputTypeEnum::TOGGLE,\n 'value' => $value,\n ];\n }\n\n // Organizations = Teams\n public function getOrganizationFieldData(?string $value = null, bool $shortVersion = false): array\n {\n $options = $this->getTeams();\n\n if ($shortVersion) {\n return [\n 'id' => 'organization',\n 'label' => 'Organization',\n 'options' => $options,\n ];\n }\n\n return [\n 'id' => 'organization',\n 'label' => 'Organization',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => $options,\n 'value' => $value,\n 'dependencies' => [\n 'teams',\n 'deal_stage_at_call',\n 'current_deal_stage',\n 'recipients',\n ActivityTypeService::PLAYBOOK_CATEGORIES_KEY,\n ],\n 'dependsOn' => [],\n ];\n }\n\n // Teams = Groups\n public function getTeamFieldData(array $options = [], array $value = [], bool $shortVersion = false): array\n {\n if ($shortVersion) {\n return [\n 'id' => 'teams',\n 'label' => 'Team',\n 'options' => $options,\n ];\n }\n\n return [\n 'id' => 'teams',\n 'label' => 'Team',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'required' => false,\n 'placeholder' => 'Select',\n 'options' => $options,\n 'value' => $value, // value should be an array of objects {id, name}\n 'dependencies' => [ActivityTypeService::PLAYBOOK_CATEGORIES_KEY],\n 'dependsOn' => [],\n ];\n }\n\n public function getReportTypeFieldData(?string $value = null, bool $shortVersion = false, ?Team $team = null): array\n {\n $types = [];\n if ($team instanceof Team) {\n if ($team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {\n $types = self::TYPES;\n }\n if ($team->hasFeature(FeatureEnum::ASK_JIMINNY_REPORTS)) {\n $types[] = ['id' => self::TYPE_ASK_JIMINNY, 'name' => 'Ask Jiminny'];\n }\n } else {\n $types = self::TYPES;\n }\n\n if ($shortVersion) {\n return [\n 'id' => 'report_type',\n 'label' => 'Report Type',\n 'options' => $types,\n ];\n }\n\n return [\n 'id' => 'report_type',\n 'label' => 'Report Type',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => $types,\n 'value' => $value,\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getFrequencyFieldData(?string $value = null): array\n {\n return [\n 'id' => 'frequency',\n 'label' => 'Frequency',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => self::FREQUENCIES,\n 'value' => $value,\n 'dependencies' => ['period'],\n 'dependsOn' => [],\n ];\n }\n\n public function getPeriodFieldData(?string $valueStartDate = null, ?string $valueEndDate = null): array\n {\n return [\n 'id' => 'period',\n 'label' => 'Select one-off period',\n 'inputType' => InputTypeEnum::DATE_RANGE,\n 'required' => true,\n 'placeholder' => 'Select',\n 'value' => ['startDate' => $valueStartDate, 'endDate' => $valueEndDate],\n 'queryParams' => [\n 'startDate' => 'start_date_period',\n 'endDate' => 'end_date_period',\n ],\n 'dependencies' => [],\n 'dependsOn' => ['frequency'],\n ];\n }\n\n public function getActivityTypesFieldData(?Team $team = null, array $value = [], array $teamsFilter = []): array\n {\n return $this->activityTypeService->getActivityTypeFieldData(team: $team, value: $value, groupIds: $teamsFilter);\n }\n\n public function getDealStageAtCallFieldData(?Team $team = null, array $value = []): array\n {\n return $this->dealStagesService->getDealStageAtCallFieldData(team: $team, value: $value);\n }\n\n public function getCurrentDealStageFieldData(?Team $team = null, array $value = []): array\n {\n return $this->dealStagesService->getCurrentDealStageFieldData(team: $team, value: $value);\n }\n\n public function getDealValueFieldData(?int $valueMin = null, ?int $valueMax = null): array\n {\n return [\n 'id' => 'deal_value',\n 'label' => 'Deal Value',\n 'inputType' => InputTypeEnum::INTEGER_RANGE,\n 'required' => false,\n 'value' => ['min' => $valueMin, 'max' => $valueMax],\n 'queryParams' => [\n 'min' => 'min_deal_value',\n 'max' => 'max_deal_value',\n ],\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getCallTypeFieldData(bool $conferenceOn = false, bool $dialerOn = false): array\n {\n $value = [];\n $conferenceOn && $value[] = self::CALL_TYPE_CONFERENCE;\n $dialerOn && $value[] = self::CALL_TYPE_DIALER;\n\n return [\n 'id' => 'call_type',\n 'label' => 'Call Type',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'required' => true,\n 'options' => [\n self::CALL_TYPE_CONFERENCE,\n self::CALL_TYPE_DIALER,\n ],\n 'value' => $value,\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getMediaTypeFieldData(?AutomatedReport $report = null): array\n {\n $value = [];\n\n if ($report) {\n $value = $this->transformMediaTypes($report);\n }\n\n return [\n 'id' => 'media_types',\n 'label' => 'Export as',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'required' => true,\n 'options' => self::MEDIA_TYPE_OBJECTS,\n 'value' => $value,\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getCallDurationFieldData(?int $valueMin = null, ?int $valueMax = null): array\n {\n return [\n 'id' => 'call_duration',\n 'label' => 'Call Duration',\n 'inputType' => InputTypeEnum::INTEGER_RANGE,\n 'required' => false,\n 'value' => ['min' => $valueMin, 'max' => $valueMax],\n 'queryParams' => [\n 'min' => 'min_call_duration',\n 'max' => 'max_call_duration',\n ],\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getRecipientsFieldData(?Team $team = null, array $value = []): array\n {\n return $this->recipientsService->getRecipientsFieldData(team: $team, value: $value);\n }\n\n public function getJiminnyRecipientsFieldData(array $value = []): array\n {\n return $this->recipientsService->getJiminnyRecipientsFieldData($value);\n }\n\n public function getAdditionalPromptInputFieldData(?string $value = null): array\n {\n return [\n 'id' => 'additional_prompt_input',\n 'label' => 'Special requirements',\n 'inputType' => InputTypeEnum::TEXTAREA,\n 'required' => false,\n 'placeholder' => 'What should be the focus of the report?',\n 'value' => $value,\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getCustomReportNameFieldData(?string $value = null): array\n {\n return [\n 'id' => 'custom_name',\n 'label' => 'Custom report name',\n 'inputType' => InputTypeEnum::TEXT,\n 'required' => false,\n 'placeholder' => 'Enter custom name',\n 'value' => $value,\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n // data providers\n public function getTeams(): array\n {\n $teams = $this->teamRepository->getTeamsForKiosk(status: Team::STATUS_ACTIVE);\n\n $teamData = [];\n foreach ($teams as $team) {\n if (! $team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {\n continue;\n }\n\n $teamData[] = $this->transformTeam($team);\n }\n\n return $teamData;\n }\n\n public function getTeamGroups(string $teamUuid): array\n {\n $data = [];\n $team = $this->getTeam($teamUuid);\n\n if ($team !== null) {\n $groups = $team->groups()->get();\n\n foreach ($groups as $group) {\n $data[] = [\n 'id' => $group->getUuid(),\n 'name' => $group->getName(),\n ];\n }\n }\n\n return $data;\n }\n\n public function getTeamsGroupsOptions(array $filterTeamUuids = []): array\n {\n $data = [];\n $teams = $this->getTeams();\n\n foreach ($teams as $team) {\n if (! empty($filterTeamUuids) && ! in_array($team['id'], $filterTeamUuids, true)) {\n continue;\n }\n\n $data[] = [\n 'label' => $team['name'],\n 'groups' => $this->getTeamGroups($team['id']),\n ];\n }\n\n return $data;\n }\n\n public function getTeam(string $teamUuid): ?Team\n {\n return $this->teamRepository->idOrUuid($teamUuid);\n }\n\n public function getTeamById(int $teamId): ?Team\n {\n return $this->teamRepository->find($teamId);\n }\n\n public function getGroupsUuids(AutomatedReport $report): array\n {\n $uuids = [];\n $reportGroups = $report->getGroups();\n foreach ($reportGroups as $groupId) {\n if ($group = $this->groupRepository->find($groupId)) {\n $uuids[] = $group->getUuid();\n }\n }\n\n return $uuids;\n }\n\n public function getPlaybookCategoriesUuids(AutomatedReport $report): array\n {\n $uuids = [];\n $playbookCategories = $report->getPlaybookCategories();\n foreach ($playbookCategories as $id) {\n if ($category = $this->playbookCategoryRepository->find($id)) {\n $uuids[] = $category->getUuid();\n }\n }\n\n return $uuids;\n }\n\n public function getDealAtCallStagesUuids(AutomatedReport $report): array\n {\n $uuids = [];\n $reportStages = $report->getDealAtCallStages();\n foreach ($reportStages as $id) {\n if ($stage = $this->stageRepository->find($id)) {\n $uuids[] = $stage->getUuid();\n }\n }\n\n return $uuids;\n }\n\n public function getCurrentDealStagesUuids(AutomatedReport $report): array\n {\n $uuids = [];\n $reportStages = $report->getCurrentDealStages();\n foreach ($reportStages as $id) {\n if ($stage = $this->stageRepository->find($id)) {\n $uuids[] = $stage->getUuid();\n }\n }\n\n return $uuids;\n }\n\n public function getUsersUuids(AutomatedReport $report): array\n {\n return $this->extractUserUuids($report->getRecipients());\n }\n\n public function getJiminnyUsersUuids(AutomatedReport $report): array\n {\n return $this->extractUserUuids($report->getJiminnyRecipients());\n }\n\n /**\n * @param array<string, mixed> $recipients\n */\n private function extractUserUuids(array $recipients): array\n {\n $userIds = $recipients['users'] ?? [];\n\n return collect($userIds)\n ->map(fn ($id) => $this->userRepository->find((int) $id))\n ->filter()\n ->map(fn (UserContract $user) => $user->getUuid())\n ->values()\n ->all();\n }\n\n // get mail data\n public function getRecipientUsers(AutomatedReport $report): array\n {\n return $this->buildRecipientUsers($report->getRecipients());\n }\n\n private function getJiminnyRecipientUsers(AutomatedReport $report): array\n {\n return $this->buildRecipientUsers($report->getJiminnyRecipients());\n }\n\n /**\n * @param array<string, mixed> $recipients\n */\n private function buildRecipientUsers(array $recipients): array\n {\n $userIds = $recipients['users'] ?? [];\n\n return collect($userIds)\n ->map(fn ($id) => $this->userRepository->find((int) $id))\n ->filter()\n ->map(fn (UserContract $user) => [\n 'email' => $user->getEmailAddress(),\n 'name' => $user->getName(),\n 'timezone' => $user->getTimezone()->getName(),\n ])\n ->values()\n ->all();\n }\n\n public function getValidRecipientUsers(AutomatedReport $report, bool $includeJiminny = false): array\n {\n if ($report->isAskJiminnyReport()) {\n $recipients = $this->resolveAskJiminnyRecipients($report);\n } else {\n $recipients = $this->getRecipientUsers($report);\n if ($includeJiminny) {\n $recipients = array_merge($recipients, $this->getJiminnyRecipientUsers($report));\n }\n }\n\n $emails = [];\n\n return array_values(array_filter(\n $recipients,\n static function ($recipient) use (&$emails) {\n if (empty($recipient['email']) || in_array($recipient['email'], $emails, true)) {\n return false;\n }\n $emails[] = $recipient['email'];\n\n return true;\n }\n ));\n }\n\n private function resolveAskJiminnyRecipients(AutomatedReport $report): array\n {\n $recipients = [];\n\n $creator = $report->getCreator();\n if ($creator !== null) {\n $recipients[] = [\n 'email' => $creator->getEmailAddress(),\n 'name' => $creator->getName(),\n 'timezone' => $creator->getTimezone()->getName(),\n ];\n }\n\n return array_merge(\n $recipients,\n $this->buildRecipientUsers($report->getRecipients()),\n $this->getGroupRecipientUsers($report),\n );\n }\n\n private function getGroupRecipientUsers(AutomatedReport $report): array\n {\n $users = [];\n foreach ($report->getGroups() as $groupId) {\n $group = $this->groupRepository->find($groupId);\n if ($group === null) {\n continue;\n }\n foreach ($group->getMembers() as $member) {\n $users[] = [\n 'email' => $member->getEmailAddress(),\n 'name' => $member->getName(),\n 'timezone' => $member->getTimezone()->getName(),\n ];\n }\n }\n\n return $users;\n }\n\n public function getReportTypeName(AutomatedReportResult $report): string\n {\n $type = $report->getReport()->getType();\n\n $getType = $this->transformReportType($type);\n\n return $getType['name'];\n }\n\n public function getReportPeriodName(AutomatedReportResult $report): string\n {\n $from = $report->getFromDate();\n $to = $report->getToDate();\n $frequency = $report->getReport()->getFrequency();\n\n if ($from === null || $to === null) {\n if (! $report->getReport()->isAskJiminnyReport()) {\n $invalidPeriod = $from === null ? 'from' : 'to';\n\n throw new ApplicationException('Report period is invalid: ' . $invalidPeriod);\n }\n\n $period = $this->calculateFromAndToDatePeriod($frequency);\n $from = $period['fromDate'];\n $to = $period['toDate'];\n }\n\n return $this->formatReportPeriodName($frequency, $from, $to);\n }\n\n private function formatReportPeriodName(string $frequency, Carbon $from, Carbon $to): string\n {\n $fromYear = $from->format('Y');\n $toYear = $to->format('Y');\n $differentYears = $fromYear !== $toYear;\n\n switch ($frequency) {\n case self::FREQUENCY_DAILY:\n return $from->format('j M Y');\n\n case self::FREQUENCY_QUARTERLY:\n // 'Jan-Mar 2025' or 'Nov 2024-Jan 2025' if years differ\n $startMonth = $from->format('M');\n $endMonth = $to->copy()->subMonth();\n $endMonthName = $endMonth->format('M');\n $endMonthYear = $endMonth->format('Y');\n\n if ($differentYears) {\n return \"{$startMonth} {$fromYear} - {$endMonthName} {$endMonthYear}\";\n }\n\n return \"{$startMonth} - {$endMonthName} {$toYear}\";\n\n case self::FREQUENCY_MONTHLY:\n // 'May 2025' - monthly reports are always within the same year\n return $from->format('M Y');\n\n case self::FREQUENCY_WEEKLY:\n // '4 - 8 Aug 2025', '27 Oct - 3 Nov 2025', or '28 Dec 2024 - 3 Jan 2025' if years differ\n $startDay = $from->format('j');\n $endDay = $to->format('j');\n $startMonth = $from->format('M');\n $endMonth = $to->format('M');\n\n if ($differentYears) {\n return \"{$startDay} {$startMonth} {$fromYear} - {$endDay} {$endMonth} {$toYear}\";\n }\n\n if ($startMonth !== $endMonth) {\n return \"{$startDay} {$startMonth} - {$endDay} {$endMonth} {$toYear}\";\n }\n\n return \"{$startDay} - {$endDay} {$endMonth} {$toYear}\";\n\n case self::FREQUENCY_ONE_OFF:\n // '2 May-31 May 2025' or '15 Dec 2024-15 Jan 2025' if years differ\n $startDay = $from->format('j');\n $startMonth = $from->format('M');\n $endDay = $to->format('j');\n $endMonth = $to->format('M');\n\n // If same month and year, use a format like '2-31 May 2025'\n if ($startMonth === $endMonth && ! $differentYears) {\n return \"{$startDay} - {$endDay} {$startMonth} {$toYear}\";\n }\n\n // If different years, include both years\n if ($differentYears) {\n return \"{$startDay} {$startMonth} {$fromYear} - {$endDay} {$endMonth} {$toYear}\";\n }\n\n // Same year but different months\n return \"{$startDay} {$startMonth} - {$endDay} {$endMonth} {$toYear}\";\n\n default:\n // Default format for unknown frequencies\n return $from->format('j M Y') . ' - ' . $to->format('j M Y');\n }\n }\n\n public function getReportTeamsName(AutomatedReportResult $report): string\n {\n $groups = $report->getGroups();\n\n if (empty($groups)) {\n return 'All';\n }\n\n // Get group names from repository\n $groupNames = [];\n foreach ($groups as $groupId) {\n $group = $this->groupRepository->find($groupId);\n if ($group) {\n $groupNames[] = $group->getName();\n }\n }\n\n if (count($groupNames) === 1) {\n // Single team format\n $teamsName = $groupNames[0];\n } else {\n // Multiple teams format\n $teamsName = implode(', ', $groupNames);\n }\n\n return $teamsName;\n }\n\n public function getReportFileName(AutomatedReportResult $report): string\n {\n $customName = $report->getReport()->getCustomName();\n $periodName = $this->getReportPeriodName($report);\n $filenameSuffix = $this->getFilenameSuffix($report);\n\n if ($customName) {\n if ($filenameSuffix) {\n $customName .= \" {$filenameSuffix}\";\n }\n\n return $this->sanitizeFileName(\"{$customName} - {$periodName}\");\n }\n\n $baseName = $this->getReportTypeName($report);\n\n if ($filenameSuffix) {\n $baseName .= \" {$filenameSuffix}\";\n }\n\n return $this->sanitizeFileName(\"{$baseName} - {$periodName} - {$this->getReportTeamsName($report)}\");\n }\n\n public function getReportFileNameWithExtension(AutomatedReportResult $result): string\n {\n $extension = $this->getMediaTypeMetadata($result)['extension'];\n\n return $this->getReportFileName($result) . '.' . $extension;\n }\n\n public function sanitizeFileName(string $fileName): string\n {\n return str_replace(['/', '\\\\'], '-', $fileName);\n }\n\n public function isUserRecipientOfReport(User $user, AutomatedReport $report): bool\n {\n $recipients = array_map('intval', $report->getRecipients()['users'] ?? []);\n\n return in_array($user->getId(), $recipients);\n }\n\n public function transformReportResults(Collection $automatedReportResults): array\n {\n $data = [];\n foreach ($automatedReportResults as $automatedReportResult) {\n /** @var AutomatedReportResult $automatedReportResult */\n\n $report = $automatedReportResult->getReport();\n\n $createdBy = $report->getCreator();\n $creator = [\n 'id' => $createdBy?->getUuid(),\n 'name' => $createdBy?->getName(),\n 'email' => $createdBy?->getEmailAddress(),\n 'photoUrl' => $createdBy?->getPhotoUrl(),\n ];\n\n $data[] = [\n 'id' => $automatedReportResult->getUuid(),\n 'name' => $automatedReportResult->getName(),\n 'frequency' => $this->transformFrequency($report->getFrequency()),\n 'recipients' => [\n ...array_values($this->transformGroups(team: $report->getTeam(), groupsIds: $report->getGroups())),\n ...array_values($this->transformRecipients($report->getRecipients())),\n ],\n 'report_type' => $this->transformReportType($report->getType()),\n 'media_type' => $automatedReportResult->getMediaType(),\n 'downloadUrl' => $this->generateReportResultDownloadUrl($automatedReportResult),\n 'viewUrl' => $this->generateReportResultViewUrl($automatedReportResult),\n 'generated_at' => $automatedReportResult->getGeneratedAt()?->toIso8601String(),\n 'creator' => $creator,\n ];\n }\n\n return $data;\n }\n\n public function hasCallTypeConference(AutomatedReport $report): bool\n {\n return in_array(self::CALL_TYPE_CONFERENCE['id'], $report->getCallTypes(), true);\n }\n\n public function hasCallTypeDialer(AutomatedReport $report): bool\n {\n return in_array(self::CALL_TYPE_DIALER['id'], $report->getCallTypes(), true);\n }\n\n // transformers\n private function transformTeam(Team $team): array\n {\n if (! $team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {\n return [];\n }\n\n return [\n 'id' => $team->getUuid(),\n 'name' => $team->getName(),\n ];\n }\n\n private function transformReportFullView(AutomatedReport $report): array\n {\n $base = $this->transformReportBase($report);\n\n return $report->getType() === self::TYPE_ASK_JIMINNY\n ? $base + $this->transformAskJiminnyFields($report)\n : $base + $this->transformStandardReportFields($report);\n }\n\n private function transformReportBase(AutomatedReport $report): array\n {\n return [\n 'id' => $report->getUuid(),\n 'organization' => $this->transformOrganization(team: $report->getTeam()),\n 'report_type' => $this->transformReportType($report->getType()),\n 'frequency' => $this->transformFrequency($report->getFrequency()),\n ];\n }\n\n private function transformStandardReportFields(AutomatedReport $report): array\n {\n $team = $report->getTeam();\n\n return [\n 'report_enabled' => $report->getStatus(),\n 'start_date_period' => $report->getFrom()?->format('Y-m-d H:i:s'),\n 'end_date_period' => $report->getTo()?->format('Y-m-d H:i:s'),\n 'deal_value_min' => $report->getDealValueMin(),\n 'deal_value_max' => $report->getDealValueMax(),\n 'call_types' => $this->transformCallType($report->getCallTypes()),\n 'media_types' => $this->transformMediaTypes($report),\n 'call_duration_min' => $this->transformDurationToMinutes($report->getCallDurationMin()),\n 'call_duration_max' => $this->transformDurationToMinutes($report->getCallDurationMax()),\n 'teams' => $this->transformGroups(team: $team, groupsIds: $report->getGroups()),\n 'deal_at_call_stages' => $this->transformStages(team: $team, stagesIds: $report->getDealAtCallStages()),\n 'current_deal_stages' => $this->transformStages(team: $team, stagesIds: $report->getCurrentDealStages()),\n 'recipients' => $this->transformRecipients($report->getRecipients()),\n 'created_by' => $this->transformCreator($report->getCreator()),\n 'additional_prompt_input' => $report->getAdditionalPromptInput(),\n 'custom_name' => $report->getCustomName(),\n 'created_at' => $report->getCreatedAt()->format('Y-m-d H:i:s'),\n 'updated_at' => $report->getUpdatedAt()->format('Y-m-d H:i:s'),\n 'deleted_at' => $report->getDeletedAt()?->format('Y-m-d H:i:s'),\n ];\n }\n\n private function transformAskJiminnyFields(AutomatedReport $report): array\n {\n $team = $report->getTeam();\n $creatorId = $report->getAttribute('created_by');\n $explicitUserIds = array_values(array_filter(\n $report->getRecipients()['users'] ?? [],\n static fn ($id) => $id !== $creatorId\n ));\n\n return [\n 'report_name' => $report->getCustomName(),\n 'enabled' => $report->getStatus(),\n 'share_teams' => $this->transformGroups(team: $team, groupsIds: $report->getGroups()),\n 'share_users' => $this->transformRecipients(['users' => $explicitUserIds]),\n 'saved_search' => $this->transformSafeSearch($report->getSavedSearch()),\n 'ask_jiminny_prompt' => $this->transformAskJiminnyPrompt($report->getAskAnythingPrompt()),\n 'expires_on' => $report->getExpiresAt()?->format('Y-m-d'),\n ];\n }\n\n private function transformOrganization(?Team $team): array\n {\n return [\n 'id' => $team?->getUuid(),\n 'name' => $team?->getName(),\n ];\n }\n\n private function transformReportType(string $type): array\n {\n foreach (self::ALL_TYPES as $typeItem) {\n if ($typeItem['id'] === $type) {\n return $typeItem;\n }\n }\n\n return [];\n }\n\n private function transformCallType(array $types): array\n {\n $result = [];\n $callTypes = [self::CALL_TYPE_CONFERENCE, self::CALL_TYPE_DIALER];\n\n foreach ($types as $type) {\n foreach ($callTypes as $callTypeItem) {\n if ($callTypeItem['id'] === $type) {\n $result[] = $callTypeItem;\n\n break;\n }\n }\n }\n\n return $result;\n }\n\n private function transformMediaTypes(AutomatedReport $report): array\n {\n $values = [];\n\n foreach ($report->getMediaTypes() as $mediaType) {\n if (! in_array($mediaType, self::MEDIA_TYPES, true)) {\n continue;\n }\n\n $values[] = match ($mediaType) {\n self::MEDIA_TYPE_PDF => self::MEDIA_TYPE_OBJECT_PDF,\n self::MEDIA_TYPE_PODCAST => self::MEDIA_TYPE_OBJECT_PODCAST,\n };\n }\n\n return $values;\n }\n\n private function transformFrequency(string $frequency): array\n {\n foreach (self::ALL_FREQUENCIES as $frequencyItem) {\n if ($frequencyItem['id'] === $frequency) {\n return $frequencyItem;\n }\n }\n\n return [];\n }\n\n public function transformDurationToMinutes(?int $duration): ?int\n {\n if (! $duration) {\n return null;\n }\n\n return (int) ($duration / 60);\n }\n\n private function transformGroups(?Team $team, array $groupsIds): array\n {\n if (empty($groupsIds) || ! $team) {\n return [];\n }\n\n $data = [];\n foreach ($groupsIds as $groupId) {\n $group = $team->groups()->where('id', $groupId)->first();\n\n if ($group) {\n $data[] = [\n 'id' => $group->getUuid(),\n 'name' => $group->getName(),\n 'photoUrl' => $group->getPhotoUrl(),\n ];\n }\n }\n\n return $data;\n }\n\n private function transformStages(?Team $team, array $stagesIds): array\n {\n if (empty($stagesIds) || ! $team) {\n return [];\n }\n\n $data = [];\n foreach ($stagesIds as $stageId) {\n $stage = $team->stages()->where('id', $stageId)->first();\n\n if ($stage) {\n $data[] = [\n 'id' => $stage->getUuid(),\n 'name' => $stage->getName(),\n ];\n }\n }\n\n return $data;\n }\n\n private function transformRecipients(array $recipients): array\n {\n $users = [];\n foreach ($recipients['users'] ?? [] as $userId) {\n $users[] = $this->transformUser($userId);\n }\n\n return $users;\n }\n\n private function transformCreator(?User $user): ?array\n {\n if ($user === null) {\n return null;\n }\n\n return $this->transformUser($user->getId());\n }\n\n private function transformAskJiminnyPrompt(?AskAnythingPrompt $prompt): ?array\n {\n if ($prompt === null) {\n return null;\n }\n\n return [\n 'id' => $prompt->getUuid(),\n 'name' => $prompt->getTitle(),\n ];\n }\n\n private function transformSafeSearch(?Search $search): ?array\n {\n if ($search === null) {\n return null;\n }\n\n return [\n 'id' => $search->getUuid(),\n 'name' => $search->getName(),\n ];\n }\n\n private function transformUser(int $userId): array\n {\n /* @var ?User $user */\n $user = $this->userRepository->find($userId);\n\n return [\n 'id' => $user?->getUuid(),\n 'name' => $user?->getName(),\n 'email' => $user?->getEmailAddress(),\n 'photoUrl' => $user?->getPhotoUrl(),\n ];\n }\n\n public function create(array $data): array\n {\n $validatedData = $this->validateAndTransformData($data);\n $validatedData['created_by'] = auth()->id();\n\n $automatedReport = $this->automatedReportsRepository->create($validatedData);\n\n $this->generateOneOffReport($automatedReport);\n\n return $this->transformReportFullView($automatedReport);\n }\n\n public function update(string $uuid, array $data): array\n {\n $validatedData = $this->validateAndTransformData($data);\n $report = $this->automatedReportsRepository->findByUuid($uuid);\n\n if (! $report) {\n throw new InvalidArgumentException('Report not found');\n }\n\n $oldCustomName = $report->getCustomName();\n\n $automatedReport = $this->automatedReportsRepository->update($report, $validatedData);\n\n if ($oldCustomName !== $automatedReport->getCustomName()) {\n $this->updateResultNames($automatedReport);\n }\n\n $this->generateOneOffReport($automatedReport);\n\n return $this->transformReportFullView($automatedReport);\n }\n\n /**\n * Create an Ask Jiminny report.\n */\n public function createAskJiminnyReport(array $data, User $creator): array\n {\n $validatedData = $this->validateAskJiminnyReportData($data, $creator);\n $validatedData['created_by'] = $creator->getId();\n\n $automatedReport = $this->automatedReportsRepository->create($validatedData);\n\n return $this->transformReportFullView($automatedReport);\n }\n\n /**\n * Update an Ask Jiminny report.\n */\n public function updateAskJiminnyReport(AutomatedReport $report, array $data, User $user): array\n {\n if (! $report->isAskJiminnyReport()) {\n throw new InvalidArgumentException('Report is not an Ask Jiminny report');\n }\n\n $validatedData = $this->validateAskJiminnyReportData($data, $user);\n\n $oldCustomName = $report->getCustomName();\n\n $automatedReport = $this->automatedReportsRepository->update($report, $validatedData);\n\n if ($oldCustomName !== $automatedReport->getCustomName()) {\n $this->updateResultNames($automatedReport);\n }\n\n return $this->transformReportFullView($automatedReport);\n }\n\n public function updateAskJiminnyReportStatus(AutomatedReport $report, bool $status): array\n {\n $this->automatedReportsRepository->update($report, ['status' => $status]);\n\n return $this->transformReportFullView($report->fresh());\n }\n\n /**\n * Validate and transform data for Ask Jiminny reports.\n */\n private function validateAskJiminnyReportData(array $data, User $user): array\n {\n // Validate name\n $name = trim($data['report_name'] ?? '');\n if (empty($name)) {\n throw new InvalidArgumentException('Report name is required');\n }\n if (mb_strlen($name) > 50) {\n throw new InvalidArgumentException('Report name must be 50 characters or less');\n }\n\n // Validate frequency (only daily, weekly, monthly for Ask Jiminny)\n $frequency = $data['frequency'] ?? null;\n $askJiminnyFrequencies = [self::FREQUENCY_DAILY, self::FREQUENCY_WEEKLY, self::FREQUENCY_MONTHLY];\n if (! in_array($frequency, $askJiminnyFrequencies, true)) {\n throw new InvalidArgumentException('Frequency must be daily, weekly, or monthly');\n }\n\n // Validate expiration date\n $expiresAt = $data['expires_on'] ?? null;\n if (empty($expiresAt)) {\n throw new InvalidArgumentException('Expiration date is required');\n }\n\n try {\n $expiresAtDate = Carbon::parse($expiresAt);\n } catch (InvalidFormatException $e) {\n throw new InvalidArgumentException('Expiration date format is invalid');\n }\n $maxExpiration = Carbon::now()->addYear();\n if ($expiresAtDate->gt($maxExpiration)) {\n throw new InvalidArgumentException('Expiration date cannot be more than 1 year from now');\n }\n if ($expiresAtDate->isPast()) {\n throw new InvalidArgumentException('Expiration date cannot be in the past');\n }\n\n // Validate saved search\n $activitySearchId = $data['saved_search'] ?? null;\n if (empty($activitySearchId)) {\n throw new InvalidArgumentException('Saved search is required');\n }\n $savedSearch = $this->activitySearchRepository->findByUuidAndUser($activitySearchId, $user);\n if (! $savedSearch) {\n throw new InvalidArgumentException('Saved search not found or does not belong to you');\n }\n\n // Validate saved prompt\n $askAnythingPromptId = $data['ask_jiminny_prompt'] ?? null;\n if (empty($askAnythingPromptId)) {\n throw new InvalidArgumentException('Ask Jiminny prompt is required');\n }\n $prompt = $this->askAnythingRepository->getPromptByUuid($askAnythingPromptId);\n if (! $prompt) {\n throw new InvalidArgumentException('Ask Jiminny prompt not found');\n }\n\n // Validate status\n $status = $data['enabled'] ?? false;\n\n $recipientUserIds = [$user->getId()];\n\n if (! empty($data['share_users'])) {\n $sharedUserIds = $this->validateAndGetUserIdsByTeam(\n $user->team,\n (array) $data['share_users']\n );\n $recipientUserIds = array_merge($recipientUserIds, $sharedUserIds);\n }\n\n $sharedGroupIds = [];\n if (! empty($data['share_teams'])) {\n $sharedGroupIds = $this->validateAndGetGroupIds($user->team, (array) $data['share_teams']);\n }\n\n $recipientUserIds = array_values(array_unique($recipientUserIds));\n\n return [\n 'team_id' => $user->getTeamId(),\n 'type' => self::TYPE_ASK_JIMINNY,\n 'status' => (bool) $status,\n 'frequency' => $frequency,\n 'custom_name' => $name,\n 'activity_search_id' => $savedSearch->getId(),\n 'ask_anything_prompt_id' => $prompt->getId(),\n 'expires_at' => $expiresAtDate->toDateString(),\n 'media_types' => [self::MEDIA_TYPE_PDF],\n 'call_types' => [],\n 'recipients' => ['users' => $recipientUserIds],\n 'groups' => $sharedGroupIds,\n ];\n }\n\n public static function getAskJiminnyFrequencies(): array\n {\n return array_map(static function ($frequency) {\n return $frequency['id'];\n }, self::ASK_JIMINNY_FREQUENCIES);\n }\n\n public function getAskJiminnyReportFilters(User $user): array\n {\n $savedSearches = $this->activitySearchRepository->findByUserOrderedByName($user)\n ->map(fn (Search $search) => [\n 'id' => $search->getUuid(),\n 'name' => $search->getName(),\n ])\n ->values()->all();\n\n $prompts = collect(\n $this->askAnythingPromptService->get($user, AskAnythingPromptTarget::on_demand)\n )->map(fn (AskAnythingPromptDto $prompt) => [\n 'id' => $prompt->id,\n 'name' => $prompt->title,\n ])->values()->all();\n\n return [\n [\n 'id' => 'prompt',\n 'label' => 'Prompt',\n 'options' => $prompts,\n ],\n [\n 'id' => 'saved_search',\n 'label' => 'Saved Search',\n 'options' => $savedSearches,\n ],\n ];\n }\n\n public function getAskJiminnyReportFormData(User $user, ?AutomatedReport $report = null): array\n {\n $team = $user->getTeam();\n $userTimezone = $user->getTimezone();\n\n $savedSearches = $this->activitySearchRepository->findByUserOrderedByName($user)\n ->map(fn (Search $search) => [\n 'id' => $search->getUuid(),\n 'name' => $search->getName(),\n ])\n ->values()->all();\n\n $prompts = collect(\n $this->askAnythingPromptService->get($user, AskAnythingPromptTarget::on_demand)\n )->map(fn (AskAnythingPromptDto $prompt) => [\n 'id' => $prompt->id,\n 'name' => $prompt->title,\n ])->values()->all();\n\n $teamGroups = $this->groupRepository->getAllByTeam($team)->map(fn ($group) => [\n 'id' => $group->getUuid(),\n 'name' => $group->getName(),\n ])->values()->all();\n\n $shareUsers = $this->recipientsService->getRecipientsFieldData(team: $team)['options'] ?? [];\n\n $sharedTeamsValue = [];\n $sharedUsersValue = [];\n if ($report) {\n $sharedTeamsValue = $this->transformGroups($team, $report->getGroups());\n\n $recipientUserIds = $report->getRecipients()['users'] ?? [];\n $creatorId = $report->getAttribute('created_by');\n $sharedUserIds = array_values(array_filter(\n $recipientUserIds,\n static fn ($id) => $id !== $creatorId\n ));\n $sharedUsersValue = collect($sharedUserIds)\n ->map(fn ($id) => $this->userRepository->find((int) $id))\n ->filter()\n ->map(fn (User $u) => [\n 'id' => $u->getUuid(),\n 'name' => $u->getName(),\n ])\n ->values()\n ->all();\n }\n\n return [\n 'fields' => [\n [\n 'id' => 'enabled',\n 'inputType' => InputTypeEnum::TOGGLE,\n 'label' => '',\n 'value' => $report?->getStatus() ?? false,\n ],\n [\n 'id' => 'report_name',\n 'inputType' => InputTypeEnum::TEXT,\n 'label' => 'Name',\n 'placeholder' => 'Enter name',\n 'required' => true,\n 'validation' => ['maxLength' => 50],\n 'value' => $report?->getCustomName() ?? '',\n ],\n [\n 'id' => 'frequency',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'label' => 'Frequency',\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => self::ASK_JIMINNY_FREQUENCIES,\n 'value' => $report ? $this->transformFrequency($report->getFrequency()) : null,\n ],\n [\n 'id' => 'expires_on',\n 'inputType' => InputTypeEnum::DATE,\n 'label' => 'Expires on',\n 'required' => true,\n 'placeholder' => 'Select',\n 'validation' => [\n 'minDate' => now($userTimezone)->toDateString(),\n 'maxDate' => now($userTimezone)->addYear()->toDateString(),\n ],\n 'value' => $report?->getExpiresAt()?->toDateString(),\n ],\n [\n 'id' => 'share_teams',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'label' => 'Team',\n 'required' => false,\n 'placeholder' => 'Select',\n 'options' => $teamGroups,\n 'value' => $sharedTeamsValue,\n ],\n [\n 'id' => 'share_users',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'label' => 'Team member',\n 'required' => false,\n 'placeholder' => 'Select',\n 'groupLabelKey' => 'label',\n 'groupValuesKey' => 'users',\n 'optionLabelKey' => 'name',\n 'optionValueKey' => 'id',\n 'options' => $shareUsers,\n 'value' => $sharedUsersValue,\n ],\n [\n 'id' => 'saved_search',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'label' => 'Saved search',\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => $savedSearches,\n 'value' => $report && $report->getSavedSearch() ? [\n 'id' => $report->getSavedSearch()->getUuid(),\n 'name' => $report->getSavedSearch()->getName(),\n ] : null,\n ],\n [\n 'id' => 'ask_jiminny_prompt',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'label' => 'Ask Jiminny prompt',\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => $prompts,\n 'value' => $report && $report->getAskAnythingPrompt() ? [\n 'id' => $report->getAskAnythingPrompt()->getUuid(),\n 'name' => $report->getAskAnythingPrompt()->getTitle(),\n ] : null,\n ],\n ],\n ];\n }\n\n private function updateResultNames(AutomatedReport $automatedReport): void\n {\n $results = $this->automatedReportsRepository->getResultsByReport($automatedReport);\n\n foreach ($results as $result) {\n $result->update(['name' => $this->getReportFileName($result)]);\n }\n }\n\n public function updateStatus(string $uuid, array $data): array\n {\n $automatedReport = $this->automatedReportsRepository->findByUuid($uuid);\n\n if (! $automatedReport) {\n throw new ModelNotFoundException('Report not found');\n }\n\n $status = $this->validateReportStatus($data['report_enabled'] ?? null);\n $automatedReport->update([\n 'status' => $status,\n ]);\n\n $this->generateOneOffReport($automatedReport);\n\n return $this->transformReportFullView($automatedReport);\n }\n\n private function generateOneOffReport(AutomatedReport $automatedReport): void\n {\n // the scheduler handles all the other frequency types\n if ($automatedReport->getStatus() === false || $automatedReport->getFrequency() !== self::FREQUENCY_ONE_OFF) {\n return;\n }\n\n $this->dispatcher->dispatch(new RequestGenerateReportJob($automatedReport->getUuid()));\n }\n\n public function getReport(string $uuid): AutomatedReport\n {\n $automatedReport = $this->automatedReportsRepository->findByUuid($uuid);\n\n if (! $automatedReport) {\n throw new ModelNotFoundException('Report not found');\n }\n\n return $automatedReport;\n }\n\n public function get(string $uuid): array\n {\n $automatedReport = $this->getReport($uuid);\n\n return $this->transformReportFullView($automatedReport);\n }\n\n public function list(string $sortColumn = 'created_at', string $sortDirection = 'desc'): array\n {\n $results = [];\n $collection = $this->automatedReportsRepository->getAllStandardReports($sortColumn, $sortDirection);\n\n /** @var AutomatedReport $report */\n foreach ($collection as $report) {\n $results[] = $this->transformReportFullView($report);\n }\n\n return ['data' => $results];\n }\n\n public function listAskJiminnyReports(\n User $user,\n string $sortColumn = 'created_at',\n string $sortDirection = 'desc'\n ): array {\n $results = [];\n $collection = $this->automatedReportsRepository->getAskJiminnyReportsByUser($user, $sortColumn, $sortDirection);\n\n /** @var AutomatedReport $report */\n foreach ($collection as $report) {\n $results[] = $this->transformReportFullView($report);\n }\n\n return ['data' => $results];\n }\n\n public function delete(string $uuid): void\n {\n $automatedReport = $this->automatedReportsRepository->findByUuid($uuid);\n\n if (! $automatedReport) {\n throw new ModelNotFoundException('Report not found');\n }\n\n $automatedReport->delete();\n }\n\n public function createReportResult(AutomatedReport $automatedReport, array $data = []): AutomatedReportResult\n {\n return $this->automatedReportsRepository->createResult(\n array_merge(\n [\n 'report_id' => $automatedReport->getId(),\n 'status' => AutomatedReportResult::STATUS_DEFAULT,\n ],\n $data\n )\n );\n }\n\n public function getReportResult(string $resultUuid): AutomatedReportResult\n {\n $report = $this->automatedReportsRepository->findResultByUuid($resultUuid);\n\n if (! $report) {\n throw new ModelNotFoundException('Report Result not found');\n }\n\n return $report;\n }\n\n public function findChildResult(AutomatedReportResult $result, string $type): ?AutomatedReportResult\n {\n return $this->automatedReportsRepository->findChildResult($result, $type);\n }\n\n // prophet API calls\n /**\n * @throws ApplicationException\n */\n public function getGenerateReportPayload(AutomatedReport $automatedReport, string $reportResultUuid): array\n {\n $period = $this->calculateFromAndToDate($automatedReport);\n $fromDate = $period['fromDate'];\n $toDate = $period['toDate'];\n\n return [\n 'team_id' => $automatedReport->getTeamId(),\n 'request_id' => $reportResultUuid,\n 'report_type' => $automatedReport->getType(),\n 'media_types' => $automatedReport->getMediaTypes(),\n 'from_date' => $fromDate->startOfDay()->format(DateTimeInterface::RFC3339),\n 'to_date' => $toDate->endOfDay()->format(DateTimeInterface::RFC3339),\n 'group_ids' => $automatedReport->getGroups(),\n 'call_deal_stage' => $automatedReport->getDealAtCallStages(),\n 'current_deal_stage' => $automatedReport->getCurrentDealStages(),\n 'deal_min_value' => $automatedReport->getDealValueMin(),\n 'deal_max_value' => $automatedReport->getDealValueMax(),\n 'call_types' => $automatedReport->getCallTypes(),\n 'call_duration_min_seconds' => $automatedReport->getCallDurationMin(),\n 'call_duration_max_seconds' => $automatedReport->getCallDurationMax(),\n 'special_requirements' => $automatedReport->getAdditionalPromptInput(),\n 'callback_url' => $this->getCallbackUrl(),\n 'report_period' => $this->formatReportPeriodName(\n $automatedReport->getFrequency(),\n $fromDate,\n $toDate,\n ),\n 'playbook_categories' => $automatedReport->getPlaybookCategories(),\n 'custom_name' => $automatedReport->getCustomName(),\n ];\n }\n\n // $inputPayload - FE payload structure\n public function getActivitiesCountPayload(array $inputPayload): array\n {\n // Use validateAndTransformData to validate and normalize input\n $validatedData = $this->validateAndTransformData($inputPayload);\n $period = $this->calculateFromAndToDatePeriod(\n $validatedData['frequency'],\n Carbon::parse($validatedData['from']),\n Carbon::parse($validatedData['to']),\n );\n $fromDate = $period['fromDate'];\n $toDate = $period['toDate'];\n\n // Create payload similar to getGenerateReportPayload\n return [\n 'team_id' => $validatedData['team_id'],\n 'group_ids' => $validatedData['groups'] ?? [],\n 'report_type' => $validatedData['type'],\n 'from_date' => $fromDate->format(DateTimeInterface::RFC3339),\n 'to_date' => $toDate->format(DateTimeInterface::RFC3339),\n 'call_deal_stage' => $validatedData['deal_at_call_stages'] ?? [],\n 'current_deal_stage' => $validatedData['current_deal_stages'] ?? [],\n 'deal_min_value' => $validatedData['deal_value_min'] ?? null,\n 'deal_max_value' => $validatedData['deal_value_max'] ?? null,\n 'call_types' => $validatedData['call_types'],\n 'call_duration_min_seconds' => $validatedData['call_duration_min'] ?? null,\n 'call_duration_max_seconds' => $validatedData['call_duration_max'] ?? null,\n 'special_requirements' => $validatedData['additional_prompt_input'] ?? null,\n 'playbook_categories' => $validatedData['playbook_categories'] ?? [],\n 'request_id' => null,\n 'callback_url' => null,\n ];\n }\n\n public function shouldSendReport(array $users, ?CarbonInterface $generatedAt = null): bool\n {\n if (empty($users)) {\n return false;\n }\n\n $earliestTz = collect($users)\n ->mapWithKeys(function (array $user) {\n $tz = new DateTimeZone($user['timezone']);\n $nowUtc = new DateTime('now', new DateTimeZone('UTC'));\n $offset = $tz->getOffset($nowUtc);\n\n return [$user['timezone'] => $offset];\n })\n ->sortDesc()\n ->keys()\n ->first();\n\n $now = Carbon::now($earliestTz);\n $isScheduledTime = (int) $now->format('H') === self::SENT_REPORT_AT_HOURS;\n\n if ($isScheduledTime) {\n return true;\n }\n\n return $this->hasPassedScheduledTime($generatedAt, $earliestTz);\n }\n\n public function hasPassedScheduledTime(?CarbonInterface $generatedAt, string $timezone): bool\n {\n if ($generatedAt === null) {\n return false;\n }\n\n $now = Carbon::now($timezone);\n $scheduledTime = $now->copy()->setTime(self::SENT_REPORT_AT_HOURS, 0, 0);\n\n if ($now->hour < self::SENT_REPORT_AT_HOURS) {\n $scheduledTime = $scheduledTime->subDay();\n }\n\n $scheduledTimeUtc = $scheduledTime->copy()->utc();\n $generatedAtUtc = $generatedAt->copy()->utc();\n $nowUtc = $now->copy()->utc();\n\n return $generatedAtUtc->lt($scheduledTimeUtc) && $nowUtc->gt($scheduledTimeUtc);\n }\n\n public function calculateFromAndToDatePeriod(\n string $frequency,\n ?Carbon $fromDate = null,\n ?Carbon $toDate = null\n ): array {\n if ($frequency === self::FREQUENCY_ONE_OFF) {\n return [\n 'fromDate' => $fromDate,\n 'toDate' => $toDate,\n ];\n }\n\n $now = Carbon::now();\n\n return match ($frequency) {\n self::FREQUENCY_DAILY => [\n 'fromDate' => $now->copy()->subDay()->startOfDay(),\n 'toDate' => $now->copy()->subDay()->endOfDay(),\n ],\n self::FREQUENCY_WEEKLY => [\n 'fromDate' => $now->copy()->subWeeks(1)->startOfDay(),\n 'toDate' => $now->copy()->subDay()->endOfDay(),\n ],\n self::FREQUENCY_MONTHLY => [\n 'fromDate' => $now->copy()->subMonths(1)->startOfDay(),\n 'toDate' => $now->copy()->subDay()->endOfDay(),\n ],\n self::FREQUENCY_QUARTERLY => [\n 'fromDate' => $now->copy()->subMonths(3)->startOfDay(),\n 'toDate' => $now->copy()->subDay()->endOfDay(),\n ],\n default => throw new InvalidArgumentException(\"Unsupported frequency: {$frequency}\"),\n };\n }\n\n private function calculateFromAndToDate(AutomatedReport $automatedReport): array\n {\n return $this->calculateFromAndToDatePeriod(\n $automatedReport->getFrequency(),\n $automatedReport->getFrom(),\n $automatedReport->getTo()\n );\n }\n\n public function getAskJiminnyGenerateReportPayload(\n AutomatedReport $automatedReport,\n AutomatedReportResult $reportResult,\n array $activityIds,\n ): array {\n return [\n 'user_question' => $automatedReport->getAskAnythingPrompt()?->getContent(),\n 'call_ids' => array_map('strval', $activityIds),\n 'team_id' => $automatedReport->getTeamId(),\n 'request_id' => $reportResult->getUuid(),\n 'callback_url' => $this->getCallbackUrl(),\n 'report_period' => $this->getReportPeriodName($reportResult),\n 'report_name' => $automatedReport->getCustomName(),\n ];\n }\n\n private function getCallbackUrl(): string\n {\n return $this->webhookService->route('jiminny.webhook.reports.ready');\n }\n\n /**\n * Validate and transform payload data for automated reports\n *\n * @param array $data\n *\n * @throws InvalidArgumentException\n *\n * @return array\n */\n private function validateAndTransformData(array $data): array\n {\n // Validate organization (team) and check feature\n $team = $this->validateOrganization($data['organization'] ?? null);\n\n $status = $this->validateReportStatus($data['report_enabled'] ?? null);\n $type = $this->validateReportType($data['report_type'] ?? null);\n $frequency = $this->validateFrequency($data['frequency'] ?? null);\n $additionalPromptInput = $this->validateAdditionalPromptInput(\n $data['additional_prompt_input'] ?? null\n );\n $customReportName = $this->validateCustomReportName($data['custom_name'] ?? null);\n\n // Prepare data for the database\n $reportData = [\n 'team_id' => $team->getId(),\n 'type' => $type,\n 'status' => $status,\n 'frequency' => $frequency,\n 'additional_prompt_input' => $additionalPromptInput,\n 'custom_name' => $customReportName,\n ];\n\n // Validate deal values\n $reportData = $this->validateDealValues($data, $reportData);\n\n // Validate date range\n $reportData = $this->validateDateRange($data, $reportData, $frequency);\n\n // Validate call durations\n $reportData = $this->validateCallDurations($data, $reportData);\n\n // Validate call types\n $reportData = $this->validateCallTypes($data, $reportData);\n\n // Validate media types\n $reportData = $this->validateMediaTypes($data, $reportData);\n\n // Validate groups\n if (isset($data['teams'])) {\n $reportData['groups'] = $this->validateAndGetGroupIds($team, $data['teams']);\n }\n\n // Validate deal stages\n $reportData = $this->validateDealStages($data, $reportData, $team, $type);\n\n // Validate playbook categories\n $reportData = $this->validatePlaybookCategories($data, $reportData, $team);\n\n // Validate recipients\n $reportData['recipients'] = [\n 'users' => $this->validateAndGetUserIdsByTeam($team, $data['recipients'] ?? []),\n ];\n\n if (isset($data['jiminny_recipients'])) {\n // Validate Jiminny recipients\n $reportData['jiminny_recipients'] = [\n 'users' => $this->validateAndGetJiminnyUserIds((array) $data['jiminny_recipients']),\n ];\n }\n\n return $reportData;\n }\n\n private function validateDealValues(array $data, array $reportData): array\n {\n if (isset($data['min_deal_value'])) {\n $reportData['deal_value_min'] = (int) $data['min_deal_value'];\n\n if ($reportData['deal_value_min'] > 4294967295 || $reportData['deal_value_min'] < 0) {\n throw new InvalidArgumentException('Min deal value should be between 0 and 4294967295');\n }\n }\n\n if (isset($data['max_deal_value'])) {\n $reportData['deal_value_max'] = (int) $data['max_deal_value'];\n\n if ($reportData['deal_value_max'] > 4294967295 || $reportData['deal_value_max'] < 0) {\n throw new InvalidArgumentException('Max deal value should be between 0 and 4294967295');\n }\n }\n\n if (isset($data['min_deal_value'], $data['max_deal_value'])\n && $data['min_deal_value'] > $data['max_deal_value']\n ) {\n throw new InvalidArgumentException('Min deal value cannot be greater than max deal value');\n }\n\n return $reportData;\n }\n\n private function validateDateRange(array $data, array $reportData, string $frequency): array\n {\n // Set date range only for one_off frequency\n if ($frequency === 'one_off') {\n if (isset($data['start_date_period'])) {\n $reportData['from'] = $this->parseDate($data['start_date_period']);\n }\n\n if (isset($data['end_date_period'])) {\n $reportData['to'] = $this->parseDate($data['end_date_period']);\n }\n\n if (empty($reportData['from']) || empty($reportData['to'])) {\n throw new InvalidArgumentException(\n 'Start date and end date are required for one_off frequency'\n );\n }\n } else {\n $reportData['from'] = null;\n $reportData['to'] = null;\n }\n\n return $reportData;\n }\n\n private function validateCallDurations(array $data, array $reportData): array\n {\n // Convert call durations from minutes to seconds\n if (isset($data['min_call_duration'])) {\n $reportData['call_duration_min'] = (int) $data['min_call_duration'] * 60;\n\n if ($reportData['call_duration_min'] > 4294967295 || $reportData['call_duration_min'] < 0) {\n throw new InvalidArgumentException('Min call duration should be between 0 and 4294967295');\n }\n }\n\n if (isset($data['max_call_duration'])) {\n $reportData['call_duration_max'] = (int) $data['max_call_duration'] * 60;\n\n if ($reportData['call_duration_max'] > 4294967295 || $reportData['call_duration_max'] < 0) {\n throw new InvalidArgumentException('Max call duration should be between 0 and 4294967295');\n }\n }\n\n return $reportData;\n }\n\n private function validateCallTypes(array $data, array $reportData): array\n {\n // Set call types\n $reportData['call_types'] = $data['call_type'] ?? [];\n if (empty($reportData['call_types'])) {\n $reportData['call_types'] = self::getCallTypes();\n }\n\n foreach ($reportData['call_types'] as $callType) {\n if (! in_array($callType, self::getCallTypes(), true)) {\n throw new InvalidArgumentException(sprintf('Call type %s is invalid', $callType));\n }\n }\n\n return $reportData;\n }\n\n private function validateMediaTypes(array $data, array $reportData): array\n {\n // Set media types from input data\n $reportData['media_types'] = $data['media_types'] ?? [];\n\n if (empty($reportData['media_types'])) {\n throw new InvalidArgumentException('Media types are required');\n }\n\n foreach ($reportData['media_types'] as $mediaType) {\n if (! in_array($mediaType, self::MEDIA_TYPES, true)) {\n throw new InvalidArgumentException(sprintf('Media type %s is invalid', $mediaType));\n }\n }\n\n return $reportData;\n }\n\n private function validateDealStages(array $data, array $reportData, Team $team, string $reportType): array\n {\n // Validate and set deal stages\n if (isset($data['deal_stage_at_call'])) {\n $reportData['deal_at_call_stages'] =\n $this->validateAndGetDealStageIds($team, $data['deal_stage_at_call'], 'Deal stage at call');\n }\n\n if (isset($data['current_deal_stage'])) {\n $reportData['current_deal_stages'] =\n $this->validateAndGetDealStageIds($team, $data['current_deal_stage'], 'Current deal stage');\n }\n\n // Ensure current_deal_stage is not provided for loss_analysis report type\n if ($reportType === self::TYPE_LOSS_ANALYSIS && ! empty($data['current_deal_stage'])) {\n throw new InvalidArgumentException('Current deal stage is not applicable for Loss Analysis reports');\n }\n\n return $reportData;\n }\n\n // transform uuid to id\n private function validatePlaybookCategories(array $data, array $reportData, Team $team): array\n {\n $key = 'playbook_categories';\n\n if (isset($data[$key])) {\n $payloadIds = $data[$key];\n $ids = [];\n\n foreach ($payloadIds as $uuid) {\n $uuid = (string) $uuid;\n\n try {\n $playbookCategory = $this->playbookCategoryRepository->findByUuid($uuid);\n } catch (Throwable $throwable) {\n Log::error(__METHOD__ . ' ' . $throwable->getMessage());\n\n throw new InvalidArgumentException(sprintf('Playbook category %s not found', $uuid));\n }\n\n if (! $playbookCategory) {\n throw new InvalidArgumentException(sprintf('Playbook category %s not found', $uuid));\n }\n\n if (! $playbookCategory->hasPlaybook()) {\n throw new InvalidArgumentException(sprintf('Playbook category %s has no playbook', $uuid));\n }\n\n if ($playbookCategory->getPlaybook()->getTeamId() !== $team->getId()) {\n throw new InvalidArgumentException(\n sprintf('Playbook category %s not found for team %s', $uuid, $team->getUuid())\n );\n }\n\n $ids[] = $playbookCategory->getId();\n }\n\n $reportData[$key] = $ids;\n }\n\n return $reportData;\n }\n\n private function validateReportStatus($status): bool\n {\n if (! in_array($status, [true, false], true)) {\n throw new InvalidArgumentException('Report status is invalid');\n }\n\n return $status;\n }\n\n private function validateReportType($type): string\n {\n if (! in_array($type, self::getTypes(), true)) {\n throw new InvalidArgumentException(sprintf('Report type is invalid: %s', $type));\n }\n\n return $type;\n }\n\n private function validateFrequency($frequency): string\n {\n if (! in_array($frequency, self::getFrequencies(), true)) {\n throw new InvalidArgumentException('Frequency is invalid');\n }\n\n return $frequency;\n }\n\n private function validateAdditionalPromptInput(?string $additionalPromptInput): ?string\n {\n if ($additionalPromptInput && strlen($additionalPromptInput) > 5000) {\n throw new InvalidArgumentException('Additional Prompt Input should be less than 5000 characters');\n }\n\n return $additionalPromptInput;\n }\n\n private function validateCustomReportName(?string $customReportName): ?string\n {\n if ($customReportName === null || $customReportName === '') {\n return null;\n }\n\n if (strlen($customReportName) > 70) {\n throw new InvalidArgumentException('Custom report name should be less than 70 characters');\n }\n\n return $customReportName;\n }\n\n private function validateOrganization(?string $organizationUuid): Team\n {\n if (! $organizationUuid) {\n throw new InvalidArgumentException('Organization is required');\n }\n\n $team = $this->teamRepository->idOrUuid($organizationUuid);\n\n if (! $team) {\n throw new InvalidArgumentException('Organization not found');\n }\n\n if (! $team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {\n throw new InvalidArgumentException('Organization does not have the Automated Reports feature');\n }\n\n return $team;\n }\n\n private function validateAndGetGroupIds(Team $team, array $teamUuids): array\n {\n $groupIds = [];\n\n foreach ($teamUuids as $uuid) {\n $group = $this->groupRepository->findByUuid($uuid);\n\n if ($group === null || $group->getTeamId() !== $team->getId()) {\n throw new InvalidArgumentException(\n sprintf('Group %s not found for team %s', $uuid, $team->getUuid())\n );\n }\n\n $groupIds[] = $group->getId();\n\n }\n\n return $groupIds;\n }\n\n private function validateAndGetDealStageIds(Team $team, array $stageUuids, string $propertyLabel): array\n {\n $stageIds = [];\n\n foreach ($stageUuids as $uuid) {\n $stage = $this->stageRepository->findByUuid($uuid);\n\n if ($stage === null || $stage->getTeamId() !== $team->getId()) {\n throw new InvalidArgumentException(\n sprintf('Stage %s not found for team %s for %s', $uuid, $team->getUuid(), $propertyLabel)\n );\n }\n\n $stageIds[] = $stage->getId();\n }\n\n return $stageIds;\n }\n\n private function validateAndGetUserIds(array $userUuids, callable $teamCheck): array\n {\n if (empty($userUuids)) {\n return [];\n }\n\n $userIds = [];\n\n foreach ($userUuids as $uuid) {\n $user = $this->userRepository->findByUuid($uuid);\n\n if (! $user || ! $user->isStatusActive()) {\n throw new InvalidArgumentException(\n sprintf('User %s not found or is not active', $uuid)\n );\n }\n\n if (! $teamCheck($user)) {\n throw new InvalidArgumentException(\n sprintf('User %s does not belong to the allowed team(s)', $uuid)\n );\n }\n\n $userIds[] = $user->getId();\n }\n\n return $userIds;\n }\n\n private function validateAndGetUserIdsByTeam(Team $team, array $userUuids): array\n {\n return $this->validateAndGetUserIds($userUuids, fn ($user) => $user->getTeamId() === $team->getId());\n }\n\n private function validateAndGetJiminnyUserIds(array $userUuids): array\n {\n $allowedTeamIds = config('kiosk.teamIds', []);\n\n return $this->validateAndGetUserIds($userUuids, fn ($user) => in_array($user->getTeamId(), $allowedTeamIds, true));\n }\n\n private function parseDate(string $dateString): string\n {\n return date('Y-m-d H:i:s', strtotime($dateString));\n }\n\n private function generateReportResultViewUrl(AutomatedReportResult $result): string\n {\n $mediaResource = $this->getReportMediaRouteResource($result);\n\n return route('ai-reports.' . $mediaResource . '.view', ['uuid' => $result->getUuid()]);\n }\n\n private function generateReportResultDownloadUrl(AutomatedReportResult $result): string\n {\n $mediaResource = $this->getReportMediaRouteResource($result);\n\n return route('ai-reports.' . $mediaResource . '.download', ['uuid' => $result->getUuid()]);\n }\n\n private function getReportMediaRouteResource(AutomatedReportResult $result): string\n {\n if ($result->getMediaType() === self::MEDIA_TYPE_PDF) {\n return self::PDF_KEY;\n } elseif ($result->getMediaType() === self::MEDIA_TYPE_PODCAST) {\n return self::AUDIO_KEY;\n }\n\n throw new \\InvalidArgumentException('Unknown media type.');\n }\n\n public function getMediaPath(AutomatedReportResult $result): ?string\n {\n $url = match ($result->getMediaType()) {\n self::MEDIA_TYPE_PDF => $result->getPdfUrl(),\n self::MEDIA_TYPE_PODCAST => $result->getPodcastAudioUrl(),\n default => null,\n };\n\n if ($url === null) {\n return null;\n }\n\n $path = parse_url(trim($url, '\"\\''), PHP_URL_PATH);\n\n return $path ?: null;\n }\n\n public function getFilenameSuffix(AutomatedReportResult $result): ?string\n {\n return match ($result->getMediaType()) {\n self::MEDIA_TYPE_PODCAST => 'Podcast',\n default => null,\n };\n }\n\n public function getMailSubjectSuffix(AutomatedReportResult $result): string\n {\n return match ($result->getMediaType()) {\n self::MEDIA_TYPE_PDF => 'report',\n self::MEDIA_TYPE_PODCAST => 'podcast',\n default => '',\n };\n }\n\n public function getMediaTypeMetadata(AutomatedReportResult $result): array\n {\n return match ($result->getMediaType()) {\n self::MEDIA_TYPE_PODCAST => ['extension' => 'mp3', 'mime' => 'audio/mpeg'],\n self::MEDIA_TYPE_PDF => ['extension' => 'pdf', 'mime' => 'application/pdf'],\n default => ['extension' => null, 'mime' => null],\n };\n }\n\n public function deleteS3Files(AutomatedReportResult $result): void\n {\n $teamUuid = $result->getReport()->getTeam()->getUuid();\n $reportUuid = $result->getUuid();\n\n // delete all files for a report uuid no mather of pdf, podcast, or both\n // in case of both - the podcast files are linked to the pdf (parent) uuid\n // pdf and podcast date times should be close\n $path = sprintf('%s/%s/%s', $teamUuid, self::S3_DIR, $reportUuid);\n\n foreach (self::FILE_EXTENSIONS_VARIANTS as $extension) {\n $file = $path . '.' . $extension;\n\n if (Storage::exists($file)) {\n Storage::delete($file);\n Log::info('[Reports] Deleted S3 file', [\n 'path' => $file,\n ]);\n }\n }\n\n foreach (self::FILE_PODCAST_EXTENSIONS_VARIANTS as $extension) {\n $file = $path . '_podcast.' . $extension;\n\n if (Storage::exists($file)) {\n Storage::delete($file);\n Log::info('[Reports] Deleted Podcast S3 file', [\n 'path' => $file,\n ]);\n }\n }\n }\n\n /**\n *\n * @param int|null $teamId Optional team ID to filter results\n *\n * @return Collection<int, int> Collection of team IDs\n */\n public function getTeamIdsWithReportsResults(?int $teamId = null): Collection\n {\n return $this->automatedReportsRepository->getTeamIdsWithReportsResults($teamId);\n }\n\n /**\n * Core delete logic for report results using a query\n *\n * @param Builder $query\n * @param array $logContext\n *\n * @return int\n */\n private function deleteReportResultsByQuery(Builder $query, array $logContext = []): int\n {\n $deletedCount = 0;\n\n if ($query->exists()) {\n Log::info(\n 'Run delete report results',\n array_merge(\n $logContext,\n [\n 'service' => 'AutomatedReportsService',\n ]\n )\n );\n\n $query->chunkById(50, function ($results) use (&$deletedCount, $logContext) {\n foreach ($results as $result) {\n $this->deleteReportResult($result);\n $deletedCount++;\n\n Log::info(\n 'Deleted a report result',\n array_merge(\n $logContext,\n [\n 'result_id' => $result->getId(),\n 'report_id' => $result->getReportId(),\n ]\n )\n );\n }\n });\n }\n\n return $deletedCount;\n }\n\n /**\n * Delete report results for a team by retention period\n *\n * @param Team $team\n * @param CarbonImmutable $retentionDate\n *\n * @return int Number of deleted report results\n */\n public function deleteReportsResultsInRetentionPeriod(Team $team, CarbonImmutable $retentionDate): int\n {\n $reportIds = $this->automatedReportsRepository->getReportIdsByTeam($team);\n\n if ($reportIds->isEmpty()) {\n return 0;\n }\n\n $query = $this->automatedReportsRepository\n ->getReportResultsQueryForRetention($team, $retentionDate);\n\n return $this->deleteReportResultsByQuery($query, [\n 'team_id' => $team->getId(),\n 'retention_date' => $retentionDate->toDateTimeString(),\n ]);\n }\n\n /**\n * Delete ALL report results for a specific automated report\n *\n * @param string $uuid\n *\n * @return int\n */\n public function deleteReportResults(string $uuid): int\n {\n $report = $this->getReport($uuid);\n\n $query = $this->automatedReportsRepository->getResultsByReportQuery($report);\n\n return $this->deleteReportResultsByQuery($query, [\n 'report_uuid' => $uuid,\n 'report_id' => $report->getId(),\n ]);\n }\n\n public function deleteReportResult(AutomatedReportResult $result): void\n {\n $this->deleteS3Files($result);\n\n $result->delete();\n }\n\n /**\n * Get all reports for a specific team\n *\n * @param Team $team\n *\n * @return \\Illuminate\\Database\\Eloquent\\Collection\n */\n public function getTeamReports(Team $team): \\Illuminate\\Database\\Eloquent\\Collection\n {\n return $this->automatedReportsRepository->getReportsByTeam($team);\n }\n\n /**\n * Get all report results for a specific report\n *\n * @param AutomatedReport $report\n *\n * @return \\Illuminate\\Database\\Eloquent\\Collection\n */\n public function getReportResults(AutomatedReport $report): \\Illuminate\\Database\\Eloquent\\Collection\n {\n return $this->automatedReportsRepository->getResultsByReport($report);\n }\n\n public function deleteAllReportResults(AutomatedReport $report): void\n {\n $results = $this->getReportResults($report);\n\n /** @var AutomatedReportResult $result */\n foreach ($results as $result) {\n Log::info('Deleting result', [\n 'report' => $report->getId(),\n 'result' => $result->getId(),\n ]);\n\n $this->deleteReportResult($result);\n }\n }\n\n public function deleteAllData(Team $team): void\n {\n Log::info('Deleting automated report and results for team', [\n 'team' => $team->getId(),\n ]);\n\n $reports = $this->getTeamReports($team);\n\n /** @var AutomatedReport $report */\n foreach ($reports as $report) {\n Log::info('Deleting report', [\n 'team' => $team->getId(),\n 'report' => $report->getId(),\n ]);\n\n $this->deleteAllReportResults($report);\n\n $report->delete();\n }\n }\n}","depth":4,"value":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Services\\Kiosk\\AutomatedReports;\n\nuse Carbon\\CarbonImmutable;\nuse Carbon\\CarbonInterface;\nuse Carbon\\Exceptions\\InvalidFormatException;\nuse DateTime;\nuse DateTimeInterface;\nuse DateTimeZone;\nuse Illuminate\\Contracts\\Bus\\Dispatcher as BusDispatcher;\nuse Illuminate\\Database\\Eloquent\\Builder;\nuse Illuminate\\Support\\Carbon;\nuse Illuminate\\Support\\Collection;\nuse Illuminate\\Support\\Facades\\Log;\nuse Illuminate\\Support\\Facades\\Storage;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinition\\InputTypeEnum;\nuse Jiminny\\Component\\AskAnything\\AskAnythingPromptService;\nuse Jiminny\\Component\\AskAnything\\Dtos\\AskAnythingPromptDto;\nuse Jiminny\\Component\\UrlGenerator\\Webhook;\nuse Jiminny\\Contracts\\Repositories\\PlaybookCategoryRepository;\nuse Jiminny\\Contracts\\Repositories\\TeamRepository;\nuse Jiminny\\Contracts\\Repositories\\UserRepository;\nuse Jiminny\\Exceptions\\ApplicationException;\nuse Jiminny\\Exceptions\\InvalidArgumentException;\nuse Jiminny\\Exceptions\\ModelNotFoundException;\nuse Jiminny\\Jobs\\AutomatedReports\\RequestGenerateReportJob;\nuse Jiminny\\Models\\Activity\\Search;\nuse Jiminny\\Models\\AskAnything\\AskAnythingPrompt;\nuse Jiminny\\Models\\AskAnything\\AskAnythingPromptTarget;\nuse Jiminny\\Models\\AutomatedReport;\nuse Jiminny\\Models\\AutomatedReportResult;\nuse Jiminny\\Models\\Contracts\\UserContract;\nuse Jiminny\\Models\\Feature\\FeatureEnum;\nuse Jiminny\\Models\\Team;\nuse Jiminny\\Models\\User;\nuse Jiminny\\Repositories\\AskAnythingRepository;\nuse Jiminny\\Repositories\\AutomatedReportsRepository;\nuse Jiminny\\Repositories\\GroupRepository;\nuse Jiminny\\Repositories\\SearchRepository;\nuse Jiminny\\Repositories\\StageRepository;\nuse Throwable;\n\nclass AutomatedReportsService\n{\n public const string TYPE_LOSS_ANALYSIS = 'loss_analysis';\n public const string TYPE_ASK_JIMINNY = 'ask_jiminny';\n\n /**\n * Standard report types (used by kiosk for existing automated reports).\n */\n // @TODO this will add filter, however if we need to control feature by FF we need conditional logic\n public const array TYPES = [\n ['id' => 'exec_summary', 'name' => 'Exec Summary'],\n ['id' => 'coaching_profiles', 'name' => 'Coaching Profiles'],\n ['id' => 'product_feedback', 'name' => 'Product Feedback'],\n ['id' => self::TYPE_LOSS_ANALYSIS, 'name' => 'Loss Analysis'],\n// ['id' => 'questions', 'name' => 'Questions'],\n// ['id' => 'statistical_quant', 'name' => 'Statistical Quantitative'],\n ];\n\n public const array ALL_TYPES = [\n ...self::TYPES,\n ['id' => self::TYPE_ASK_JIMINNY, 'name' => 'Ask Jiminny'],\n ];\n\n public const string FREQUENCY_DAILY = 'daily';\n public const string FREQUENCY_WEEKLY = 'weekly';\n public const string FREQUENCY_MONTHLY = 'monthly';\n public const string FREQUENCY_QUARTERLY = 'quarterly';\n public const string FREQUENCY_ONE_OFF = 'one_off';\n\n /**\n * Frequencies for standard (non-Ask Jiminny) reports.\n */\n public const array FREQUENCIES = [\n ['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],\n ['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],\n ['id' => self::FREQUENCY_QUARTERLY, 'name' => 'Quarterly'],\n ['id' => self::FREQUENCY_ONE_OFF, 'name' => 'One-off'],\n ];\n\n /**\n * Frequencies for Ask Jiminny reports.\n */\n public const array ASK_JIMINNY_FREQUENCIES = [\n ['id' => self::FREQUENCY_DAILY, 'name' => 'Daily'],\n ['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],\n ['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],\n ];\n\n public const string MEDIA_TYPE_PDF = 'pdf';\n public const string MEDIA_TYPE_PODCAST = 'podcast';\n public const array MEDIA_TYPES = [self::MEDIA_TYPE_PDF, self::MEDIA_TYPE_PODCAST];\n public const array MEDIA_TYPE_OBJECT_PDF = ['id' => self::MEDIA_TYPE_PDF, 'name' => 'PDF'];\n public const array MEDIA_TYPE_OBJECT_PODCAST = ['id' => self::MEDIA_TYPE_PODCAST, 'name' => 'Podcast'];\n public const array MEDIA_TYPE_OBJECTS = [self::MEDIA_TYPE_OBJECT_PDF, self::MEDIA_TYPE_OBJECT_PODCAST];\n\n public const array CALL_TYPE_CONFERENCE = ['id' => 'conference', 'name' => 'Conference'];\n public const array CALL_TYPE_DIALER = ['id' => 'dialer', 'name' => 'Dialer'];\n public const int SENT_REPORT_AT_HOURS = 5;\n public const string PDF_KEY = 'pdf';\n public const string AUDIO_KEY = 'audio';\n\n private const array ALL_FREQUENCIES = [\n ['id' => self::FREQUENCY_DAILY, 'name' => 'Daily'],\n ['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],\n ['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],\n ['id' => self::FREQUENCY_QUARTERLY, 'name' => 'Quarterly'],\n ['id' => self::FREQUENCY_ONE_OFF, 'name' => 'One-off'],\n ];\n private const string S3_DIR = 'reports';\n private const array FILE_EXTENSIONS_VARIANTS = ['html', 'MD', 'pdf'];\n private const array FILE_PODCAST_EXTENSIONS_VARIANTS = ['json', 'mp3', 'ssml'];\n\n public function __construct(\n private readonly TeamRepository $teamRepository,\n private readonly GroupRepository $groupRepository,\n private readonly UserRepository $userRepository,\n private readonly StageRepository $stageRepository,\n private readonly DealStagesService $dealStagesService,\n private readonly RecipientsService $recipientsService,\n private readonly AutomatedReportsRepository $automatedReportsRepository,\n private readonly Webhook $webhookService,\n private readonly BusDispatcher $dispatcher,\n private readonly ActivityTypeService $activityTypeService,\n private readonly PlaybookCategoryRepository $playbookCategoryRepository,\n private readonly AskAnythingPromptService $askAnythingPromptService,\n private readonly SearchRepository $activitySearchRepository,\n private readonly AskAnythingRepository $askAnythingRepository,\n ) {\n }\n\n public static function getTypes(): array\n {\n $types = self::TYPES;\n\n return array_map(static function ($type) {\n return $type['id'];\n }, $types);\n }\n\n public static function getCallTypes(): array\n {\n return array_map(static function ($callType) {\n return $callType['id'];\n }, [self::CALL_TYPE_CONFERENCE, self::CALL_TYPE_DIALER]);\n }\n\n public static function getFrequencies(): array\n {\n return array_map(static function ($frequency) {\n return $frequency['id'];\n }, self::FREQUENCIES);\n }\n\n // front-facing structure\n public function getReportEnabledFieldData(bool $value = false): array\n {\n return [\n 'id' => 'report_enabled',\n 'label' => '',\n 'inputType' => InputTypeEnum::TOGGLE,\n 'value' => $value,\n ];\n }\n\n // Organizations = Teams\n public function getOrganizationFieldData(?string $value = null, bool $shortVersion = false): array\n {\n $options = $this->getTeams();\n\n if ($shortVersion) {\n return [\n 'id' => 'organization',\n 'label' => 'Organization',\n 'options' => $options,\n ];\n }\n\n return [\n 'id' => 'organization',\n 'label' => 'Organization',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => $options,\n 'value' => $value,\n 'dependencies' => [\n 'teams',\n 'deal_stage_at_call',\n 'current_deal_stage',\n 'recipients',\n ActivityTypeService::PLAYBOOK_CATEGORIES_KEY,\n ],\n 'dependsOn' => [],\n ];\n }\n\n // Teams = Groups\n public function getTeamFieldData(array $options = [], array $value = [], bool $shortVersion = false): array\n {\n if ($shortVersion) {\n return [\n 'id' => 'teams',\n 'label' => 'Team',\n 'options' => $options,\n ];\n }\n\n return [\n 'id' => 'teams',\n 'label' => 'Team',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'required' => false,\n 'placeholder' => 'Select',\n 'options' => $options,\n 'value' => $value, // value should be an array of objects {id, name}\n 'dependencies' => [ActivityTypeService::PLAYBOOK_CATEGORIES_KEY],\n 'dependsOn' => [],\n ];\n }\n\n public function getReportTypeFieldData(?string $value = null, bool $shortVersion = false, ?Team $team = null): array\n {\n $types = [];\n if ($team instanceof Team) {\n if ($team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {\n $types = self::TYPES;\n }\n if ($team->hasFeature(FeatureEnum::ASK_JIMINNY_REPORTS)) {\n $types[] = ['id' => self::TYPE_ASK_JIMINNY, 'name' => 'Ask Jiminny'];\n }\n } else {\n $types = self::TYPES;\n }\n\n if ($shortVersion) {\n return [\n 'id' => 'report_type',\n 'label' => 'Report Type',\n 'options' => $types,\n ];\n }\n\n return [\n 'id' => 'report_type',\n 'label' => 'Report Type',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => $types,\n 'value' => $value,\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getFrequencyFieldData(?string $value = null): array\n {\n return [\n 'id' => 'frequency',\n 'label' => 'Frequency',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => self::FREQUENCIES,\n 'value' => $value,\n 'dependencies' => ['period'],\n 'dependsOn' => [],\n ];\n }\n\n public function getPeriodFieldData(?string $valueStartDate = null, ?string $valueEndDate = null): array\n {\n return [\n 'id' => 'period',\n 'label' => 'Select one-off period',\n 'inputType' => InputTypeEnum::DATE_RANGE,\n 'required' => true,\n 'placeholder' => 'Select',\n 'value' => ['startDate' => $valueStartDate, 'endDate' => $valueEndDate],\n 'queryParams' => [\n 'startDate' => 'start_date_period',\n 'endDate' => 'end_date_period',\n ],\n 'dependencies' => [],\n 'dependsOn' => ['frequency'],\n ];\n }\n\n public function getActivityTypesFieldData(?Team $team = null, array $value = [], array $teamsFilter = []): array\n {\n return $this->activityTypeService->getActivityTypeFieldData(team: $team, value: $value, groupIds: $teamsFilter);\n }\n\n public function getDealStageAtCallFieldData(?Team $team = null, array $value = []): array\n {\n return $this->dealStagesService->getDealStageAtCallFieldData(team: $team, value: $value);\n }\n\n public function getCurrentDealStageFieldData(?Team $team = null, array $value = []): array\n {\n return $this->dealStagesService->getCurrentDealStageFieldData(team: $team, value: $value);\n }\n\n public function getDealValueFieldData(?int $valueMin = null, ?int $valueMax = null): array\n {\n return [\n 'id' => 'deal_value',\n 'label' => 'Deal Value',\n 'inputType' => InputTypeEnum::INTEGER_RANGE,\n 'required' => false,\n 'value' => ['min' => $valueMin, 'max' => $valueMax],\n 'queryParams' => [\n 'min' => 'min_deal_value',\n 'max' => 'max_deal_value',\n ],\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getCallTypeFieldData(bool $conferenceOn = false, bool $dialerOn = false): array\n {\n $value = [];\n $conferenceOn && $value[] = self::CALL_TYPE_CONFERENCE;\n $dialerOn && $value[] = self::CALL_TYPE_DIALER;\n\n return [\n 'id' => 'call_type',\n 'label' => 'Call Type',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'required' => true,\n 'options' => [\n self::CALL_TYPE_CONFERENCE,\n self::CALL_TYPE_DIALER,\n ],\n 'value' => $value,\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getMediaTypeFieldData(?AutomatedReport $report = null): array\n {\n $value = [];\n\n if ($report) {\n $value = $this->transformMediaTypes($report);\n }\n\n return [\n 'id' => 'media_types',\n 'label' => 'Export as',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'required' => true,\n 'options' => self::MEDIA_TYPE_OBJECTS,\n 'value' => $value,\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getCallDurationFieldData(?int $valueMin = null, ?int $valueMax = null): array\n {\n return [\n 'id' => 'call_duration',\n 'label' => 'Call Duration',\n 'inputType' => InputTypeEnum::INTEGER_RANGE,\n 'required' => false,\n 'value' => ['min' => $valueMin, 'max' => $valueMax],\n 'queryParams' => [\n 'min' => 'min_call_duration',\n 'max' => 'max_call_duration',\n ],\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getRecipientsFieldData(?Team $team = null, array $value = []): array\n {\n return $this->recipientsService->getRecipientsFieldData(team: $team, value: $value);\n }\n\n public function getJiminnyRecipientsFieldData(array $value = []): array\n {\n return $this->recipientsService->getJiminnyRecipientsFieldData($value);\n }\n\n public function getAdditionalPromptInputFieldData(?string $value = null): array\n {\n return [\n 'id' => 'additional_prompt_input',\n 'label' => 'Special requirements',\n 'inputType' => InputTypeEnum::TEXTAREA,\n 'required' => false,\n 'placeholder' => 'What should be the focus of the report?',\n 'value' => $value,\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getCustomReportNameFieldData(?string $value = null): array\n {\n return [\n 'id' => 'custom_name',\n 'label' => 'Custom report name',\n 'inputType' => InputTypeEnum::TEXT,\n 'required' => false,\n 'placeholder' => 'Enter custom name',\n 'value' => $value,\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n // data providers\n public function getTeams(): array\n {\n $teams = $this->teamRepository->getTeamsForKiosk(status: Team::STATUS_ACTIVE);\n\n $teamData = [];\n foreach ($teams as $team) {\n if (! $team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {\n continue;\n }\n\n $teamData[] = $this->transformTeam($team);\n }\n\n return $teamData;\n }\n\n public function getTeamGroups(string $teamUuid): array\n {\n $data = [];\n $team = $this->getTeam($teamUuid);\n\n if ($team !== null) {\n $groups = $team->groups()->get();\n\n foreach ($groups as $group) {\n $data[] = [\n 'id' => $group->getUuid(),\n 'name' => $group->getName(),\n ];\n }\n }\n\n return $data;\n }\n\n public function getTeamsGroupsOptions(array $filterTeamUuids = []): array\n {\n $data = [];\n $teams = $this->getTeams();\n\n foreach ($teams as $team) {\n if (! empty($filterTeamUuids) && ! in_array($team['id'], $filterTeamUuids, true)) {\n continue;\n }\n\n $data[] = [\n 'label' => $team['name'],\n 'groups' => $this->getTeamGroups($team['id']),\n ];\n }\n\n return $data;\n }\n\n public function getTeam(string $teamUuid): ?Team\n {\n return $this->teamRepository->idOrUuid($teamUuid);\n }\n\n public function getTeamById(int $teamId): ?Team\n {\n return $this->teamRepository->find($teamId);\n }\n\n public function getGroupsUuids(AutomatedReport $report): array\n {\n $uuids = [];\n $reportGroups = $report->getGroups();\n foreach ($reportGroups as $groupId) {\n if ($group = $this->groupRepository->find($groupId)) {\n $uuids[] = $group->getUuid();\n }\n }\n\n return $uuids;\n }\n\n public function getPlaybookCategoriesUuids(AutomatedReport $report): array\n {\n $uuids = [];\n $playbookCategories = $report->getPlaybookCategories();\n foreach ($playbookCategories as $id) {\n if ($category = $this->playbookCategoryRepository->find($id)) {\n $uuids[] = $category->getUuid();\n }\n }\n\n return $uuids;\n }\n\n public function getDealAtCallStagesUuids(AutomatedReport $report): array\n {\n $uuids = [];\n $reportStages = $report->getDealAtCallStages();\n foreach ($reportStages as $id) {\n if ($stage = $this->stageRepository->find($id)) {\n $uuids[] = $stage->getUuid();\n }\n }\n\n return $uuids;\n }\n\n public function getCurrentDealStagesUuids(AutomatedReport $report): array\n {\n $uuids = [];\n $reportStages = $report->getCurrentDealStages();\n foreach ($reportStages as $id) {\n if ($stage = $this->stageRepository->find($id)) {\n $uuids[] = $stage->getUuid();\n }\n }\n\n return $uuids;\n }\n\n public function getUsersUuids(AutomatedReport $report): array\n {\n return $this->extractUserUuids($report->getRecipients());\n }\n\n public function getJiminnyUsersUuids(AutomatedReport $report): array\n {\n return $this->extractUserUuids($report->getJiminnyRecipients());\n }\n\n /**\n * @param array<string, mixed> $recipients\n */\n private function extractUserUuids(array $recipients): array\n {\n $userIds = $recipients['users'] ?? [];\n\n return collect($userIds)\n ->map(fn ($id) => $this->userRepository->find((int) $id))\n ->filter()\n ->map(fn (UserContract $user) => $user->getUuid())\n ->values()\n ->all();\n }\n\n // get mail data\n public function getRecipientUsers(AutomatedReport $report): array\n {\n return $this->buildRecipientUsers($report->getRecipients());\n }\n\n private function getJiminnyRecipientUsers(AutomatedReport $report): array\n {\n return $this->buildRecipientUsers($report->getJiminnyRecipients());\n }\n\n /**\n * @param array<string, mixed> $recipients\n */\n private function buildRecipientUsers(array $recipients): array\n {\n $userIds = $recipients['users'] ?? [];\n\n return collect($userIds)\n ->map(fn ($id) => $this->userRepository->find((int) $id))\n ->filter()\n ->map(fn (UserContract $user) => [\n 'email' => $user->getEmailAddress(),\n 'name' => $user->getName(),\n 'timezone' => $user->getTimezone()->getName(),\n ])\n ->values()\n ->all();\n }\n\n public function getValidRecipientUsers(AutomatedReport $report, bool $includeJiminny = false): array\n {\n if ($report->isAskJiminnyReport()) {\n $recipients = $this->resolveAskJiminnyRecipients($report);\n } else {\n $recipients = $this->getRecipientUsers($report);\n if ($includeJiminny) {\n $recipients = array_merge($recipients, $this->getJiminnyRecipientUsers($report));\n }\n }\n\n $emails = [];\n\n return array_values(array_filter(\n $recipients,\n static function ($recipient) use (&$emails) {\n if (empty($recipient['email']) || in_array($recipient['email'], $emails, true)) {\n return false;\n }\n $emails[] = $recipient['email'];\n\n return true;\n }\n ));\n }\n\n private function resolveAskJiminnyRecipients(AutomatedReport $report): array\n {\n $recipients = [];\n\n $creator = $report->getCreator();\n if ($creator !== null) {\n $recipients[] = [\n 'email' => $creator->getEmailAddress(),\n 'name' => $creator->getName(),\n 'timezone' => $creator->getTimezone()->getName(),\n ];\n }\n\n return array_merge(\n $recipients,\n $this->buildRecipientUsers($report->getRecipients()),\n $this->getGroupRecipientUsers($report),\n );\n }\n\n private function getGroupRecipientUsers(AutomatedReport $report): array\n {\n $users = [];\n foreach ($report->getGroups() as $groupId) {\n $group = $this->groupRepository->find($groupId);\n if ($group === null) {\n continue;\n }\n foreach ($group->getMembers() as $member) {\n $users[] = [\n 'email' => $member->getEmailAddress(),\n 'name' => $member->getName(),\n 'timezone' => $member->getTimezone()->getName(),\n ];\n }\n }\n\n return $users;\n }\n\n public function getReportTypeName(AutomatedReportResult $report): string\n {\n $type = $report->getReport()->getType();\n\n $getType = $this->transformReportType($type);\n\n return $getType['name'];\n }\n\n public function getReportPeriodName(AutomatedReportResult $report): string\n {\n $from = $report->getFromDate();\n $to = $report->getToDate();\n $frequency = $report->getReport()->getFrequency();\n\n if ($from === null || $to === null) {\n if (! $report->getReport()->isAskJiminnyReport()) {\n $invalidPeriod = $from === null ? 'from' : 'to';\n\n throw new ApplicationException('Report period is invalid: ' . $invalidPeriod);\n }\n\n $period = $this->calculateFromAndToDatePeriod($frequency);\n $from = $period['fromDate'];\n $to = $period['toDate'];\n }\n\n return $this->formatReportPeriodName($frequency, $from, $to);\n }\n\n private function formatReportPeriodName(string $frequency, Carbon $from, Carbon $to): string\n {\n $fromYear = $from->format('Y');\n $toYear = $to->format('Y');\n $differentYears = $fromYear !== $toYear;\n\n switch ($frequency) {\n case self::FREQUENCY_DAILY:\n return $from->format('j M Y');\n\n case self::FREQUENCY_QUARTERLY:\n // 'Jan-Mar 2025' or 'Nov 2024-Jan 2025' if years differ\n $startMonth = $from->format('M');\n $endMonth = $to->copy()->subMonth();\n $endMonthName = $endMonth->format('M');\n $endMonthYear = $endMonth->format('Y');\n\n if ($differentYears) {\n return \"{$startMonth} {$fromYear} - {$endMonthName} {$endMonthYear}\";\n }\n\n return \"{$startMonth} - {$endMonthName} {$toYear}\";\n\n case self::FREQUENCY_MONTHLY:\n // 'May 2025' - monthly reports are always within the same year\n return $from->format('M Y');\n\n case self::FREQUENCY_WEEKLY:\n // '4 - 8 Aug 2025', '27 Oct - 3 Nov 2025', or '28 Dec 2024 - 3 Jan 2025' if years differ\n $startDay = $from->format('j');\n $endDay = $to->format('j');\n $startMonth = $from->format('M');\n $endMonth = $to->format('M');\n\n if ($differentYears) {\n return \"{$startDay} {$startMonth} {$fromYear} - {$endDay} {$endMonth} {$toYear}\";\n }\n\n if ($startMonth !== $endMonth) {\n return \"{$startDay} {$startMonth} - {$endDay} {$endMonth} {$toYear}\";\n }\n\n return \"{$startDay} - {$endDay} {$endMonth} {$toYear}\";\n\n case self::FREQUENCY_ONE_OFF:\n // '2 May-31 May 2025' or '15 Dec 2024-15 Jan 2025' if years differ\n $startDay = $from->format('j');\n $startMonth = $from->format('M');\n $endDay = $to->format('j');\n $endMonth = $to->format('M');\n\n // If same month and year, use a format like '2-31 May 2025'\n if ($startMonth === $endMonth && ! $differentYears) {\n return \"{$startDay} - {$endDay} {$startMonth} {$toYear}\";\n }\n\n // If different years, include both years\n if ($differentYears) {\n return \"{$startDay} {$startMonth} {$fromYear} - {$endDay} {$endMonth} {$toYear}\";\n }\n\n // Same year but different months\n return \"{$startDay} {$startMonth} - {$endDay} {$endMonth} {$toYear}\";\n\n default:\n // Default format for unknown frequencies\n return $from->format('j M Y') . ' - ' . $to->format('j M Y');\n }\n }\n\n public function getReportTeamsName(AutomatedReportResult $report): string\n {\n $groups = $report->getGroups();\n\n if (empty($groups)) {\n return 'All';\n }\n\n // Get group names from repository\n $groupNames = [];\n foreach ($groups as $groupId) {\n $group = $this->groupRepository->find($groupId);\n if ($group) {\n $groupNames[] = $group->getName();\n }\n }\n\n if (count($groupNames) === 1) {\n // Single team format\n $teamsName = $groupNames[0];\n } else {\n // Multiple teams format\n $teamsName = implode(', ', $groupNames);\n }\n\n return $teamsName;\n }\n\n public function getReportFileName(AutomatedReportResult $report): string\n {\n $customName = $report->getReport()->getCustomName();\n $periodName = $this->getReportPeriodName($report);\n $filenameSuffix = $this->getFilenameSuffix($report);\n\n if ($customName) {\n if ($filenameSuffix) {\n $customName .= \" {$filenameSuffix}\";\n }\n\n return $this->sanitizeFileName(\"{$customName} - {$periodName}\");\n }\n\n $baseName = $this->getReportTypeName($report);\n\n if ($filenameSuffix) {\n $baseName .= \" {$filenameSuffix}\";\n }\n\n return $this->sanitizeFileName(\"{$baseName} - {$periodName} - {$this->getReportTeamsName($report)}\");\n }\n\n public function getReportFileNameWithExtension(AutomatedReportResult $result): string\n {\n $extension = $this->getMediaTypeMetadata($result)['extension'];\n\n return $this->getReportFileName($result) . '.' . $extension;\n }\n\n public function sanitizeFileName(string $fileName): string\n {\n return str_replace(['/', '\\\\'], '-', $fileName);\n }\n\n public function isUserRecipientOfReport(User $user, AutomatedReport $report): bool\n {\n $recipients = array_map('intval', $report->getRecipients()['users'] ?? []);\n\n return in_array($user->getId(), $recipients);\n }\n\n public function transformReportResults(Collection $automatedReportResults): array\n {\n $data = [];\n foreach ($automatedReportResults as $automatedReportResult) {\n /** @var AutomatedReportResult $automatedReportResult */\n\n $report = $automatedReportResult->getReport();\n\n $createdBy = $report->getCreator();\n $creator = [\n 'id' => $createdBy?->getUuid(),\n 'name' => $createdBy?->getName(),\n 'email' => $createdBy?->getEmailAddress(),\n 'photoUrl' => $createdBy?->getPhotoUrl(),\n ];\n\n $data[] = [\n 'id' => $automatedReportResult->getUuid(),\n 'name' => $automatedReportResult->getName(),\n 'frequency' => $this->transformFrequency($report->getFrequency()),\n 'recipients' => [\n ...array_values($this->transformGroups(team: $report->getTeam(), groupsIds: $report->getGroups())),\n ...array_values($this->transformRecipients($report->getRecipients())),\n ],\n 'report_type' => $this->transformReportType($report->getType()),\n 'media_type' => $automatedReportResult->getMediaType(),\n 'downloadUrl' => $this->generateReportResultDownloadUrl($automatedReportResult),\n 'viewUrl' => $this->generateReportResultViewUrl($automatedReportResult),\n 'generated_at' => $automatedReportResult->getGeneratedAt()?->toIso8601String(),\n 'creator' => $creator,\n ];\n }\n\n return $data;\n }\n\n public function hasCallTypeConference(AutomatedReport $report): bool\n {\n return in_array(self::CALL_TYPE_CONFERENCE['id'], $report->getCallTypes(), true);\n }\n\n public function hasCallTypeDialer(AutomatedReport $report): bool\n {\n return in_array(self::CALL_TYPE_DIALER['id'], $report->getCallTypes(), true);\n }\n\n // transformers\n private function transformTeam(Team $team): array\n {\n if (! $team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {\n return [];\n }\n\n return [\n 'id' => $team->getUuid(),\n 'name' => $team->getName(),\n ];\n }\n\n private function transformReportFullView(AutomatedReport $report): array\n {\n $base = $this->transformReportBase($report);\n\n return $report->getType() === self::TYPE_ASK_JIMINNY\n ? $base + $this->transformAskJiminnyFields($report)\n : $base + $this->transformStandardReportFields($report);\n }\n\n private function transformReportBase(AutomatedReport $report): array\n {\n return [\n 'id' => $report->getUuid(),\n 'organization' => $this->transformOrganization(team: $report->getTeam()),\n 'report_type' => $this->transformReportType($report->getType()),\n 'frequency' => $this->transformFrequency($report->getFrequency()),\n ];\n }\n\n private function transformStandardReportFields(AutomatedReport $report): array\n {\n $team = $report->getTeam();\n\n return [\n 'report_enabled' => $report->getStatus(),\n 'start_date_period' => $report->getFrom()?->format('Y-m-d H:i:s'),\n 'end_date_period' => $report->getTo()?->format('Y-m-d H:i:s'),\n 'deal_value_min' => $report->getDealValueMin(),\n 'deal_value_max' => $report->getDealValueMax(),\n 'call_types' => $this->transformCallType($report->getCallTypes()),\n 'media_types' => $this->transformMediaTypes($report),\n 'call_duration_min' => $this->transformDurationToMinutes($report->getCallDurationMin()),\n 'call_duration_max' => $this->transformDurationToMinutes($report->getCallDurationMax()),\n 'teams' => $this->transformGroups(team: $team, groupsIds: $report->getGroups()),\n 'deal_at_call_stages' => $this->transformStages(team: $team, stagesIds: $report->getDealAtCallStages()),\n 'current_deal_stages' => $this->transformStages(team: $team, stagesIds: $report->getCurrentDealStages()),\n 'recipients' => $this->transformRecipients($report->getRecipients()),\n 'created_by' => $this->transformCreator($report->getCreator()),\n 'additional_prompt_input' => $report->getAdditionalPromptInput(),\n 'custom_name' => $report->getCustomName(),\n 'created_at' => $report->getCreatedAt()->format('Y-m-d H:i:s'),\n 'updated_at' => $report->getUpdatedAt()->format('Y-m-d H:i:s'),\n 'deleted_at' => $report->getDeletedAt()?->format('Y-m-d H:i:s'),\n ];\n }\n\n private function transformAskJiminnyFields(AutomatedReport $report): array\n {\n $team = $report->getTeam();\n $creatorId = $report->getAttribute('created_by');\n $explicitUserIds = array_values(array_filter(\n $report->getRecipients()['users'] ?? [],\n static fn ($id) => $id !== $creatorId\n ));\n\n return [\n 'report_name' => $report->getCustomName(),\n 'enabled' => $report->getStatus(),\n 'share_teams' => $this->transformGroups(team: $team, groupsIds: $report->getGroups()),\n 'share_users' => $this->transformRecipients(['users' => $explicitUserIds]),\n 'saved_search' => $this->transformSafeSearch($report->getSavedSearch()),\n 'ask_jiminny_prompt' => $this->transformAskJiminnyPrompt($report->getAskAnythingPrompt()),\n 'expires_on' => $report->getExpiresAt()?->format('Y-m-d'),\n ];\n }\n\n private function transformOrganization(?Team $team): array\n {\n return [\n 'id' => $team?->getUuid(),\n 'name' => $team?->getName(),\n ];\n }\n\n private function transformReportType(string $type): array\n {\n foreach (self::ALL_TYPES as $typeItem) {\n if ($typeItem['id'] === $type) {\n return $typeItem;\n }\n }\n\n return [];\n }\n\n private function transformCallType(array $types): array\n {\n $result = [];\n $callTypes = [self::CALL_TYPE_CONFERENCE, self::CALL_TYPE_DIALER];\n\n foreach ($types as $type) {\n foreach ($callTypes as $callTypeItem) {\n if ($callTypeItem['id'] === $type) {\n $result[] = $callTypeItem;\n\n break;\n }\n }\n }\n\n return $result;\n }\n\n private function transformMediaTypes(AutomatedReport $report): array\n {\n $values = [];\n\n foreach ($report->getMediaTypes() as $mediaType) {\n if (! in_array($mediaType, self::MEDIA_TYPES, true)) {\n continue;\n }\n\n $values[] = match ($mediaType) {\n self::MEDIA_TYPE_PDF => self::MEDIA_TYPE_OBJECT_PDF,\n self::MEDIA_TYPE_PODCAST => self::MEDIA_TYPE_OBJECT_PODCAST,\n };\n }\n\n return $values;\n }\n\n private function transformFrequency(string $frequency): array\n {\n foreach (self::ALL_FREQUENCIES as $frequencyItem) {\n if ($frequencyItem['id'] === $frequency) {\n return $frequencyItem;\n }\n }\n\n return [];\n }\n\n public function transformDurationToMinutes(?int $duration): ?int\n {\n if (! $duration) {\n return null;\n }\n\n return (int) ($duration / 60);\n }\n\n private function transformGroups(?Team $team, array $groupsIds): array\n {\n if (empty($groupsIds) || ! $team) {\n return [];\n }\n\n $data = [];\n foreach ($groupsIds as $groupId) {\n $group = $team->groups()->where('id', $groupId)->first();\n\n if ($group) {\n $data[] = [\n 'id' => $group->getUuid(),\n 'name' => $group->getName(),\n 'photoUrl' => $group->getPhotoUrl(),\n ];\n }\n }\n\n return $data;\n }\n\n private function transformStages(?Team $team, array $stagesIds): array\n {\n if (empty($stagesIds) || ! $team) {\n return [];\n }\n\n $data = [];\n foreach ($stagesIds as $stageId) {\n $stage = $team->stages()->where('id', $stageId)->first();\n\n if ($stage) {\n $data[] = [\n 'id' => $stage->getUuid(),\n 'name' => $stage->getName(),\n ];\n }\n }\n\n return $data;\n }\n\n private function transformRecipients(array $recipients): array\n {\n $users = [];\n foreach ($recipients['users'] ?? [] as $userId) {\n $users[] = $this->transformUser($userId);\n }\n\n return $users;\n }\n\n private function transformCreator(?User $user): ?array\n {\n if ($user === null) {\n return null;\n }\n\n return $this->transformUser($user->getId());\n }\n\n private function transformAskJiminnyPrompt(?AskAnythingPrompt $prompt): ?array\n {\n if ($prompt === null) {\n return null;\n }\n\n return [\n 'id' => $prompt->getUuid(),\n 'name' => $prompt->getTitle(),\n ];\n }\n\n private function transformSafeSearch(?Search $search): ?array\n {\n if ($search === null) {\n return null;\n }\n\n return [\n 'id' => $search->getUuid(),\n 'name' => $search->getName(),\n ];\n }\n\n private function transformUser(int $userId): array\n {\n /* @var ?User $user */\n $user = $this->userRepository->find($userId);\n\n return [\n 'id' => $user?->getUuid(),\n 'name' => $user?->getName(),\n 'email' => $user?->getEmailAddress(),\n 'photoUrl' => $user?->getPhotoUrl(),\n ];\n }\n\n public function create(array $data): array\n {\n $validatedData = $this->validateAndTransformData($data);\n $validatedData['created_by'] = auth()->id();\n\n $automatedReport = $this->automatedReportsRepository->create($validatedData);\n\n $this->generateOneOffReport($automatedReport);\n\n return $this->transformReportFullView($automatedReport);\n }\n\n public function update(string $uuid, array $data): array\n {\n $validatedData = $this->validateAndTransformData($data);\n $report = $this->automatedReportsRepository->findByUuid($uuid);\n\n if (! $report) {\n throw new InvalidArgumentException('Report not found');\n }\n\n $oldCustomName = $report->getCustomName();\n\n $automatedReport = $this->automatedReportsRepository->update($report, $validatedData);\n\n if ($oldCustomName !== $automatedReport->getCustomName()) {\n $this->updateResultNames($automatedReport);\n }\n\n $this->generateOneOffReport($automatedReport);\n\n return $this->transformReportFullView($automatedReport);\n }\n\n /**\n * Create an Ask Jiminny report.\n */\n public function createAskJiminnyReport(array $data, User $creator): array\n {\n $validatedData = $this->validateAskJiminnyReportData($data, $creator);\n $validatedData['created_by'] = $creator->getId();\n\n $automatedReport = $this->automatedReportsRepository->create($validatedData);\n\n return $this->transformReportFullView($automatedReport);\n }\n\n /**\n * Update an Ask Jiminny report.\n */\n public function updateAskJiminnyReport(AutomatedReport $report, array $data, User $user): array\n {\n if (! $report->isAskJiminnyReport()) {\n throw new InvalidArgumentException('Report is not an Ask Jiminny report');\n }\n\n $validatedData = $this->validateAskJiminnyReportData($data, $user);\n\n $oldCustomName = $report->getCustomName();\n\n $automatedReport = $this->automatedReportsRepository->update($report, $validatedData);\n\n if ($oldCustomName !== $automatedReport->getCustomName()) {\n $this->updateResultNames($automatedReport);\n }\n\n return $this->transformReportFullView($automatedReport);\n }\n\n public function updateAskJiminnyReportStatus(AutomatedReport $report, bool $status): array\n {\n $this->automatedReportsRepository->update($report, ['status' => $status]);\n\n return $this->transformReportFullView($report->fresh());\n }\n\n /**\n * Validate and transform data for Ask Jiminny reports.\n */\n private function validateAskJiminnyReportData(array $data, User $user): array\n {\n // Validate name\n $name = trim($data['report_name'] ?? '');\n if (empty($name)) {\n throw new InvalidArgumentException('Report name is required');\n }\n if (mb_strlen($name) > 50) {\n throw new InvalidArgumentException('Report name must be 50 characters or less');\n }\n\n // Validate frequency (only daily, weekly, monthly for Ask Jiminny)\n $frequency = $data['frequency'] ?? null;\n $askJiminnyFrequencies = [self::FREQUENCY_DAILY, self::FREQUENCY_WEEKLY, self::FREQUENCY_MONTHLY];\n if (! in_array($frequency, $askJiminnyFrequencies, true)) {\n throw new InvalidArgumentException('Frequency must be daily, weekly, or monthly');\n }\n\n // Validate expiration date\n $expiresAt = $data['expires_on'] ?? null;\n if (empty($expiresAt)) {\n throw new InvalidArgumentException('Expiration date is required');\n }\n\n try {\n $expiresAtDate = Carbon::parse($expiresAt);\n } catch (InvalidFormatException $e) {\n throw new InvalidArgumentException('Expiration date format is invalid');\n }\n $maxExpiration = Carbon::now()->addYear();\n if ($expiresAtDate->gt($maxExpiration)) {\n throw new InvalidArgumentException('Expiration date cannot be more than 1 year from now');\n }\n if ($expiresAtDate->isPast()) {\n throw new InvalidArgumentException('Expiration date cannot be in the past');\n }\n\n // Validate saved search\n $activitySearchId = $data['saved_search'] ?? null;\n if (empty($activitySearchId)) {\n throw new InvalidArgumentException('Saved search is required');\n }\n $savedSearch = $this->activitySearchRepository->findByUuidAndUser($activitySearchId, $user);\n if (! $savedSearch) {\n throw new InvalidArgumentException('Saved search not found or does not belong to you');\n }\n\n // Validate saved prompt\n $askAnythingPromptId = $data['ask_jiminny_prompt'] ?? null;\n if (empty($askAnythingPromptId)) {\n throw new InvalidArgumentException('Ask Jiminny prompt is required');\n }\n $prompt = $this->askAnythingRepository->getPromptByUuid($askAnythingPromptId);\n if (! $prompt) {\n throw new InvalidArgumentException('Ask Jiminny prompt not found');\n }\n\n // Validate status\n $status = $data['enabled'] ?? false;\n\n $recipientUserIds = [$user->getId()];\n\n if (! empty($data['share_users'])) {\n $sharedUserIds = $this->validateAndGetUserIdsByTeam(\n $user->team,\n (array) $data['share_users']\n );\n $recipientUserIds = array_merge($recipientUserIds, $sharedUserIds);\n }\n\n $sharedGroupIds = [];\n if (! empty($data['share_teams'])) {\n $sharedGroupIds = $this->validateAndGetGroupIds($user->team, (array) $data['share_teams']);\n }\n\n $recipientUserIds = array_values(array_unique($recipientUserIds));\n\n return [\n 'team_id' => $user->getTeamId(),\n 'type' => self::TYPE_ASK_JIMINNY,\n 'status' => (bool) $status,\n 'frequency' => $frequency,\n 'custom_name' => $name,\n 'activity_search_id' => $savedSearch->getId(),\n 'ask_anything_prompt_id' => $prompt->getId(),\n 'expires_at' => $expiresAtDate->toDateString(),\n 'media_types' => [self::MEDIA_TYPE_PDF],\n 'call_types' => [],\n 'recipients' => ['users' => $recipientUserIds],\n 'groups' => $sharedGroupIds,\n ];\n }\n\n public static function getAskJiminnyFrequencies(): array\n {\n return array_map(static function ($frequency) {\n return $frequency['id'];\n }, self::ASK_JIMINNY_FREQUENCIES);\n }\n\n public function getAskJiminnyReportFilters(User $user): array\n {\n $savedSearches = $this->activitySearchRepository->findByUserOrderedByName($user)\n ->map(fn (Search $search) => [\n 'id' => $search->getUuid(),\n 'name' => $search->getName(),\n ])\n ->values()->all();\n\n $prompts = collect(\n $this->askAnythingPromptService->get($user, AskAnythingPromptTarget::on_demand)\n )->map(fn (AskAnythingPromptDto $prompt) => [\n 'id' => $prompt->id,\n 'name' => $prompt->title,\n ])->values()->all();\n\n return [\n [\n 'id' => 'prompt',\n 'label' => 'Prompt',\n 'options' => $prompts,\n ],\n [\n 'id' => 'saved_search',\n 'label' => 'Saved Search',\n 'options' => $savedSearches,\n ],\n ];\n }\n\n public function getAskJiminnyReportFormData(User $user, ?AutomatedReport $report = null): array\n {\n $team = $user->getTeam();\n $userTimezone = $user->getTimezone();\n\n $savedSearches = $this->activitySearchRepository->findByUserOrderedByName($user)\n ->map(fn (Search $search) => [\n 'id' => $search->getUuid(),\n 'name' => $search->getName(),\n ])\n ->values()->all();\n\n $prompts = collect(\n $this->askAnythingPromptService->get($user, AskAnythingPromptTarget::on_demand)\n )->map(fn (AskAnythingPromptDto $prompt) => [\n 'id' => $prompt->id,\n 'name' => $prompt->title,\n ])->values()->all();\n\n $teamGroups = $this->groupRepository->getAllByTeam($team)->map(fn ($group) => [\n 'id' => $group->getUuid(),\n 'name' => $group->getName(),\n ])->values()->all();\n\n $shareUsers = $this->recipientsService->getRecipientsFieldData(team: $team)['options'] ?? [];\n\n $sharedTeamsValue = [];\n $sharedUsersValue = [];\n if ($report) {\n $sharedTeamsValue = $this->transformGroups($team, $report->getGroups());\n\n $recipientUserIds = $report->getRecipients()['users'] ?? [];\n $creatorId = $report->getAttribute('created_by');\n $sharedUserIds = array_values(array_filter(\n $recipientUserIds,\n static fn ($id) => $id !== $creatorId\n ));\n $sharedUsersValue = collect($sharedUserIds)\n ->map(fn ($id) => $this->userRepository->find((int) $id))\n ->filter()\n ->map(fn (User $u) => [\n 'id' => $u->getUuid(),\n 'name' => $u->getName(),\n ])\n ->values()\n ->all();\n }\n\n return [\n 'fields' => [\n [\n 'id' => 'enabled',\n 'inputType' => InputTypeEnum::TOGGLE,\n 'label' => '',\n 'value' => $report?->getStatus() ?? false,\n ],\n [\n 'id' => 'report_name',\n 'inputType' => InputTypeEnum::TEXT,\n 'label' => 'Name',\n 'placeholder' => 'Enter name',\n 'required' => true,\n 'validation' => ['maxLength' => 50],\n 'value' => $report?->getCustomName() ?? '',\n ],\n [\n 'id' => 'frequency',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'label' => 'Frequency',\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => self::ASK_JIMINNY_FREQUENCIES,\n 'value' => $report ? $this->transformFrequency($report->getFrequency()) : null,\n ],\n [\n 'id' => 'expires_on',\n 'inputType' => InputTypeEnum::DATE,\n 'label' => 'Expires on',\n 'required' => true,\n 'placeholder' => 'Select',\n 'validation' => [\n 'minDate' => now($userTimezone)->toDateString(),\n 'maxDate' => now($userTimezone)->addYear()->toDateString(),\n ],\n 'value' => $report?->getExpiresAt()?->toDateString(),\n ],\n [\n 'id' => 'share_teams',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'label' => 'Team',\n 'required' => false,\n 'placeholder' => 'Select',\n 'options' => $teamGroups,\n 'value' => $sharedTeamsValue,\n ],\n [\n 'id' => 'share_users',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'label' => 'Team member',\n 'required' => false,\n 'placeholder' => 'Select',\n 'groupLabelKey' => 'label',\n 'groupValuesKey' => 'users',\n 'optionLabelKey' => 'name',\n 'optionValueKey' => 'id',\n 'options' => $shareUsers,\n 'value' => $sharedUsersValue,\n ],\n [\n 'id' => 'saved_search',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'label' => 'Saved search',\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => $savedSearches,\n 'value' => $report && $report->getSavedSearch() ? [\n 'id' => $report->getSavedSearch()->getUuid(),\n 'name' => $report->getSavedSearch()->getName(),\n ] : null,\n ],\n [\n 'id' => 'ask_jiminny_prompt',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'label' => 'Ask Jiminny prompt',\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => $prompts,\n 'value' => $report && $report->getAskAnythingPrompt() ? [\n 'id' => $report->getAskAnythingPrompt()->getUuid(),\n 'name' => $report->getAskAnythingPrompt()->getTitle(),\n ] : null,\n ],\n ],\n ];\n }\n\n private function updateResultNames(AutomatedReport $automatedReport): void\n {\n $results = $this->automatedReportsRepository->getResultsByReport($automatedReport);\n\n foreach ($results as $result) {\n $result->update(['name' => $this->getReportFileName($result)]);\n }\n }\n\n public function updateStatus(string $uuid, array $data): array\n {\n $automatedReport = $this->automatedReportsRepository->findByUuid($uuid);\n\n if (! $automatedReport) {\n throw new ModelNotFoundException('Report not found');\n }\n\n $status = $this->validateReportStatus($data['report_enabled'] ?? null);\n $automatedReport->update([\n 'status' => $status,\n ]);\n\n $this->generateOneOffReport($automatedReport);\n\n return $this->transformReportFullView($automatedReport);\n }\n\n private function generateOneOffReport(AutomatedReport $automatedReport): void\n {\n // the scheduler handles all the other frequency types\n if ($automatedReport->getStatus() === false || $automatedReport->getFrequency() !== self::FREQUENCY_ONE_OFF) {\n return;\n }\n\n $this->dispatcher->dispatch(new RequestGenerateReportJob($automatedReport->getUuid()));\n }\n\n public function getReport(string $uuid): AutomatedReport\n {\n $automatedReport = $this->automatedReportsRepository->findByUuid($uuid);\n\n if (! $automatedReport) {\n throw new ModelNotFoundException('Report not found');\n }\n\n return $automatedReport;\n }\n\n public function get(string $uuid): array\n {\n $automatedReport = $this->getReport($uuid);\n\n return $this->transformReportFullView($automatedReport);\n }\n\n public function list(string $sortColumn = 'created_at', string $sortDirection = 'desc'): array\n {\n $results = [];\n $collection = $this->automatedReportsRepository->getAllStandardReports($sortColumn, $sortDirection);\n\n /** @var AutomatedReport $report */\n foreach ($collection as $report) {\n $results[] = $this->transformReportFullView($report);\n }\n\n return ['data' => $results];\n }\n\n public function listAskJiminnyReports(\n User $user,\n string $sortColumn = 'created_at',\n string $sortDirection = 'desc'\n ): array {\n $results = [];\n $collection = $this->automatedReportsRepository->getAskJiminnyReportsByUser($user, $sortColumn, $sortDirection);\n\n /** @var AutomatedReport $report */\n foreach ($collection as $report) {\n $results[] = $this->transformReportFullView($report);\n }\n\n return ['data' => $results];\n }\n\n public function delete(string $uuid): void\n {\n $automatedReport = $this->automatedReportsRepository->findByUuid($uuid);\n\n if (! $automatedReport) {\n throw new ModelNotFoundException('Report not found');\n }\n\n $automatedReport->delete();\n }\n\n public function createReportResult(AutomatedReport $automatedReport, array $data = []): AutomatedReportResult\n {\n return $this->automatedReportsRepository->createResult(\n array_merge(\n [\n 'report_id' => $automatedReport->getId(),\n 'status' => AutomatedReportResult::STATUS_DEFAULT,\n ],\n $data\n )\n );\n }\n\n public function getReportResult(string $resultUuid): AutomatedReportResult\n {\n $report = $this->automatedReportsRepository->findResultByUuid($resultUuid);\n\n if (! $report) {\n throw new ModelNotFoundException('Report Result not found');\n }\n\n return $report;\n }\n\n public function findChildResult(AutomatedReportResult $result, string $type): ?AutomatedReportResult\n {\n return $this->automatedReportsRepository->findChildResult($result, $type);\n }\n\n // prophet API calls\n /**\n * @throws ApplicationException\n */\n public function getGenerateReportPayload(AutomatedReport $automatedReport, string $reportResultUuid): array\n {\n $period = $this->calculateFromAndToDate($automatedReport);\n $fromDate = $period['fromDate'];\n $toDate = $period['toDate'];\n\n return [\n 'team_id' => $automatedReport->getTeamId(),\n 'request_id' => $reportResultUuid,\n 'report_type' => $automatedReport->getType(),\n 'media_types' => $automatedReport->getMediaTypes(),\n 'from_date' => $fromDate->startOfDay()->format(DateTimeInterface::RFC3339),\n 'to_date' => $toDate->endOfDay()->format(DateTimeInterface::RFC3339),\n 'group_ids' => $automatedReport->getGroups(),\n 'call_deal_stage' => $automatedReport->getDealAtCallStages(),\n 'current_deal_stage' => $automatedReport->getCurrentDealStages(),\n 'deal_min_value' => $automatedReport->getDealValueMin(),\n 'deal_max_value' => $automatedReport->getDealValueMax(),\n 'call_types' => $automatedReport->getCallTypes(),\n 'call_duration_min_seconds' => $automatedReport->getCallDurationMin(),\n 'call_duration_max_seconds' => $automatedReport->getCallDurationMax(),\n 'special_requirements' => $automatedReport->getAdditionalPromptInput(),\n 'callback_url' => $this->getCallbackUrl(),\n 'report_period' => $this->formatReportPeriodName(\n $automatedReport->getFrequency(),\n $fromDate,\n $toDate,\n ),\n 'playbook_categories' => $automatedReport->getPlaybookCategories(),\n 'custom_name' => $automatedReport->getCustomName(),\n ];\n }\n\n // $inputPayload - FE payload structure\n public function getActivitiesCountPayload(array $inputPayload): array\n {\n // Use validateAndTransformData to validate and normalize input\n $validatedData = $this->validateAndTransformData($inputPayload);\n $period = $this->calculateFromAndToDatePeriod(\n $validatedData['frequency'],\n Carbon::parse($validatedData['from']),\n Carbon::parse($validatedData['to']),\n );\n $fromDate = $period['fromDate'];\n $toDate = $period['toDate'];\n\n // Create payload similar to getGenerateReportPayload\n return [\n 'team_id' => $validatedData['team_id'],\n 'group_ids' => $validatedData['groups'] ?? [],\n 'report_type' => $validatedData['type'],\n 'from_date' => $fromDate->format(DateTimeInterface::RFC3339),\n 'to_date' => $toDate->format(DateTimeInterface::RFC3339),\n 'call_deal_stage' => $validatedData['deal_at_call_stages'] ?? [],\n 'current_deal_stage' => $validatedData['current_deal_stages'] ?? [],\n 'deal_min_value' => $validatedData['deal_value_min'] ?? null,\n 'deal_max_value' => $validatedData['deal_value_max'] ?? null,\n 'call_types' => $validatedData['call_types'],\n 'call_duration_min_seconds' => $validatedData['call_duration_min'] ?? null,\n 'call_duration_max_seconds' => $validatedData['call_duration_max'] ?? null,\n 'special_requirements' => $validatedData['additional_prompt_input'] ?? null,\n 'playbook_categories' => $validatedData['playbook_categories'] ?? [],\n 'request_id' => null,\n 'callback_url' => null,\n ];\n }\n\n public function shouldSendReport(array $users, ?CarbonInterface $generatedAt = null): bool\n {\n if (empty($users)) {\n return false;\n }\n\n $earliestTz = collect($users)\n ->mapWithKeys(function (array $user) {\n $tz = new DateTimeZone($user['timezone']);\n $nowUtc = new DateTime('now', new DateTimeZone('UTC'));\n $offset = $tz->getOffset($nowUtc);\n\n return [$user['timezone'] => $offset];\n })\n ->sortDesc()\n ->keys()\n ->first();\n\n $now = Carbon::now($earliestTz);\n $isScheduledTime = (int) $now->format('H') === self::SENT_REPORT_AT_HOURS;\n\n if ($isScheduledTime) {\n return true;\n }\n\n return $this->hasPassedScheduledTime($generatedAt, $earliestTz);\n }\n\n public function hasPassedScheduledTime(?CarbonInterface $generatedAt, string $timezone): bool\n {\n if ($generatedAt === null) {\n return false;\n }\n\n $now = Carbon::now($timezone);\n $scheduledTime = $now->copy()->setTime(self::SENT_REPORT_AT_HOURS, 0, 0);\n\n if ($now->hour < self::SENT_REPORT_AT_HOURS) {\n $scheduledTime = $scheduledTime->subDay();\n }\n\n $scheduledTimeUtc = $scheduledTime->copy()->utc();\n $generatedAtUtc = $generatedAt->copy()->utc();\n $nowUtc = $now->copy()->utc();\n\n return $generatedAtUtc->lt($scheduledTimeUtc) && $nowUtc->gt($scheduledTimeUtc);\n }\n\n public function calculateFromAndToDatePeriod(\n string $frequency,\n ?Carbon $fromDate = null,\n ?Carbon $toDate = null\n ): array {\n if ($frequency === self::FREQUENCY_ONE_OFF) {\n return [\n 'fromDate' => $fromDate,\n 'toDate' => $toDate,\n ];\n }\n\n $now = Carbon::now();\n\n return match ($frequency) {\n self::FREQUENCY_DAILY => [\n 'fromDate' => $now->copy()->subDay()->startOfDay(),\n 'toDate' => $now->copy()->subDay()->endOfDay(),\n ],\n self::FREQUENCY_WEEKLY => [\n 'fromDate' => $now->copy()->subWeeks(1)->startOfDay(),\n 'toDate' => $now->copy()->subDay()->endOfDay(),\n ],\n self::FREQUENCY_MONTHLY => [\n 'fromDate' => $now->copy()->subMonths(1)->startOfDay(),\n 'toDate' => $now->copy()->subDay()->endOfDay(),\n ],\n self::FREQUENCY_QUARTERLY => [\n 'fromDate' => $now->copy()->subMonths(3)->startOfDay(),\n 'toDate' => $now->copy()->subDay()->endOfDay(),\n ],\n default => throw new InvalidArgumentException(\"Unsupported frequency: {$frequency}\"),\n };\n }\n\n private function calculateFromAndToDate(AutomatedReport $automatedReport): array\n {\n return $this->calculateFromAndToDatePeriod(\n $automatedReport->getFrequency(),\n $automatedReport->getFrom(),\n $automatedReport->getTo()\n );\n }\n\n public function getAskJiminnyGenerateReportPayload(\n AutomatedReport $automatedReport,\n AutomatedReportResult $reportResult,\n array $activityIds,\n ): array {\n return [\n 'user_question' => $automatedReport->getAskAnythingPrompt()?->getContent(),\n 'call_ids' => array_map('strval', $activityIds),\n 'team_id' => $automatedReport->getTeamId(),\n 'request_id' => $reportResult->getUuid(),\n 'callback_url' => $this->getCallbackUrl(),\n 'report_period' => $this->getReportPeriodName($reportResult),\n 'report_name' => $automatedReport->getCustomName(),\n ];\n }\n\n private function getCallbackUrl(): string\n {\n return $this->webhookService->route('jiminny.webhook.reports.ready');\n }\n\n /**\n * Validate and transform payload data for automated reports\n *\n * @param array $data\n *\n * @throws InvalidArgumentException\n *\n * @return array\n */\n private function validateAndTransformData(array $data): array\n {\n // Validate organization (team) and check feature\n $team = $this->validateOrganization($data['organization'] ?? null);\n\n $status = $this->validateReportStatus($data['report_enabled'] ?? null);\n $type = $this->validateReportType($data['report_type'] ?? null);\n $frequency = $this->validateFrequency($data['frequency'] ?? null);\n $additionalPromptInput = $this->validateAdditionalPromptInput(\n $data['additional_prompt_input'] ?? null\n );\n $customReportName = $this->validateCustomReportName($data['custom_name'] ?? null);\n\n // Prepare data for the database\n $reportData = [\n 'team_id' => $team->getId(),\n 'type' => $type,\n 'status' => $status,\n 'frequency' => $frequency,\n 'additional_prompt_input' => $additionalPromptInput,\n 'custom_name' => $customReportName,\n ];\n\n // Validate deal values\n $reportData = $this->validateDealValues($data, $reportData);\n\n // Validate date range\n $reportData = $this->validateDateRange($data, $reportData, $frequency);\n\n // Validate call durations\n $reportData = $this->validateCallDurations($data, $reportData);\n\n // Validate call types\n $reportData = $this->validateCallTypes($data, $reportData);\n\n // Validate media types\n $reportData = $this->validateMediaTypes($data, $reportData);\n\n // Validate groups\n if (isset($data['teams'])) {\n $reportData['groups'] = $this->validateAndGetGroupIds($team, $data['teams']);\n }\n\n // Validate deal stages\n $reportData = $this->validateDealStages($data, $reportData, $team, $type);\n\n // Validate playbook categories\n $reportData = $this->validatePlaybookCategories($data, $reportData, $team);\n\n // Validate recipients\n $reportData['recipients'] = [\n 'users' => $this->validateAndGetUserIdsByTeam($team, $data['recipients'] ?? []),\n ];\n\n if (isset($data['jiminny_recipients'])) {\n // Validate Jiminny recipients\n $reportData['jiminny_recipients'] = [\n 'users' => $this->validateAndGetJiminnyUserIds((array) $data['jiminny_recipients']),\n ];\n }\n\n return $reportData;\n }\n\n private function validateDealValues(array $data, array $reportData): array\n {\n if (isset($data['min_deal_value'])) {\n $reportData['deal_value_min'] = (int) $data['min_deal_value'];\n\n if ($reportData['deal_value_min'] > 4294967295 || $reportData['deal_value_min'] < 0) {\n throw new InvalidArgumentException('Min deal value should be between 0 and 4294967295');\n }\n }\n\n if (isset($data['max_deal_value'])) {\n $reportData['deal_value_max'] = (int) $data['max_deal_value'];\n\n if ($reportData['deal_value_max'] > 4294967295 || $reportData['deal_value_max'] < 0) {\n throw new InvalidArgumentException('Max deal value should be between 0 and 4294967295');\n }\n }\n\n if (isset($data['min_deal_value'], $data['max_deal_value'])\n && $data['min_deal_value'] > $data['max_deal_value']\n ) {\n throw new InvalidArgumentException('Min deal value cannot be greater than max deal value');\n }\n\n return $reportData;\n }\n\n private function validateDateRange(array $data, array $reportData, string $frequency): array\n {\n // Set date range only for one_off frequency\n if ($frequency === 'one_off') {\n if (isset($data['start_date_period'])) {\n $reportData['from'] = $this->parseDate($data['start_date_period']);\n }\n\n if (isset($data['end_date_period'])) {\n $reportData['to'] = $this->parseDate($data['end_date_period']);\n }\n\n if (empty($reportData['from']) || empty($reportData['to'])) {\n throw new InvalidArgumentException(\n 'Start date and end date are required for one_off frequency'\n );\n }\n } else {\n $reportData['from'] = null;\n $reportData['to'] = null;\n }\n\n return $reportData;\n }\n\n private function validateCallDurations(array $data, array $reportData): array\n {\n // Convert call durations from minutes to seconds\n if (isset($data['min_call_duration'])) {\n $reportData['call_duration_min'] = (int) $data['min_call_duration'] * 60;\n\n if ($reportData['call_duration_min'] > 4294967295 || $reportData['call_duration_min'] < 0) {\n throw new InvalidArgumentException('Min call duration should be between 0 and 4294967295');\n }\n }\n\n if (isset($data['max_call_duration'])) {\n $reportData['call_duration_max'] = (int) $data['max_call_duration'] * 60;\n\n if ($reportData['call_duration_max'] > 4294967295 || $reportData['call_duration_max'] < 0) {\n throw new InvalidArgumentException('Max call duration should be between 0 and 4294967295');\n }\n }\n\n return $reportData;\n }\n\n private function validateCallTypes(array $data, array $reportData): array\n {\n // Set call types\n $reportData['call_types'] = $data['call_type'] ?? [];\n if (empty($reportData['call_types'])) {\n $reportData['call_types'] = self::getCallTypes();\n }\n\n foreach ($reportData['call_types'] as $callType) {\n if (! in_array($callType, self::getCallTypes(), true)) {\n throw new InvalidArgumentException(sprintf('Call type %s is invalid', $callType));\n }\n }\n\n return $reportData;\n }\n\n private function validateMediaTypes(array $data, array $reportData): array\n {\n // Set media types from input data\n $reportData['media_types'] = $data['media_types'] ?? [];\n\n if (empty($reportData['media_types'])) {\n throw new InvalidArgumentException('Media types are required');\n }\n\n foreach ($reportData['media_types'] as $mediaType) {\n if (! in_array($mediaType, self::MEDIA_TYPES, true)) {\n throw new InvalidArgumentException(sprintf('Media type %s is invalid', $mediaType));\n }\n }\n\n return $reportData;\n }\n\n private function validateDealStages(array $data, array $reportData, Team $team, string $reportType): array\n {\n // Validate and set deal stages\n if (isset($data['deal_stage_at_call'])) {\n $reportData['deal_at_call_stages'] =\n $this->validateAndGetDealStageIds($team, $data['deal_stage_at_call'], 'Deal stage at call');\n }\n\n if (isset($data['current_deal_stage'])) {\n $reportData['current_deal_stages'] =\n $this->validateAndGetDealStageIds($team, $data['current_deal_stage'], 'Current deal stage');\n }\n\n // Ensure current_deal_stage is not provided for loss_analysis report type\n if ($reportType === self::TYPE_LOSS_ANALYSIS && ! empty($data['current_deal_stage'])) {\n throw new InvalidArgumentException('Current deal stage is not applicable for Loss Analysis reports');\n }\n\n return $reportData;\n }\n\n // transform uuid to id\n private function validatePlaybookCategories(array $data, array $reportData, Team $team): array\n {\n $key = 'playbook_categories';\n\n if (isset($data[$key])) {\n $payloadIds = $data[$key];\n $ids = [];\n\n foreach ($payloadIds as $uuid) {\n $uuid = (string) $uuid;\n\n try {\n $playbookCategory = $this->playbookCategoryRepository->findByUuid($uuid);\n } catch (Throwable $throwable) {\n Log::error(__METHOD__ . ' ' . $throwable->getMessage());\n\n throw new InvalidArgumentException(sprintf('Playbook category %s not found', $uuid));\n }\n\n if (! $playbookCategory) {\n throw new InvalidArgumentException(sprintf('Playbook category %s not found', $uuid));\n }\n\n if (! $playbookCategory->hasPlaybook()) {\n throw new InvalidArgumentException(sprintf('Playbook category %s has no playbook', $uuid));\n }\n\n if ($playbookCategory->getPlaybook()->getTeamId() !== $team->getId()) {\n throw new InvalidArgumentException(\n sprintf('Playbook category %s not found for team %s', $uuid, $team->getUuid())\n );\n }\n\n $ids[] = $playbookCategory->getId();\n }\n\n $reportData[$key] = $ids;\n }\n\n return $reportData;\n }\n\n private function validateReportStatus($status): bool\n {\n if (! in_array($status, [true, false], true)) {\n throw new InvalidArgumentException('Report status is invalid');\n }\n\n return $status;\n }\n\n private function validateReportType($type): string\n {\n if (! in_array($type, self::getTypes(), true)) {\n throw new InvalidArgumentException(sprintf('Report type is invalid: %s', $type));\n }\n\n return $type;\n }\n\n private function validateFrequency($frequency): string\n {\n if (! in_array($frequency, self::getFrequencies(), true)) {\n throw new InvalidArgumentException('Frequency is invalid');\n }\n\n return $frequency;\n }\n\n private function validateAdditionalPromptInput(?string $additionalPromptInput): ?string\n {\n if ($additionalPromptInput && strlen($additionalPromptInput) > 5000) {\n throw new InvalidArgumentException('Additional Prompt Input should be less than 5000 characters');\n }\n\n return $additionalPromptInput;\n }\n\n private function validateCustomReportName(?string $customReportName): ?string\n {\n if ($customReportName === null || $customReportName === '') {\n return null;\n }\n\n if (strlen($customReportName) > 70) {\n throw new InvalidArgumentException('Custom report name should be less than 70 characters');\n }\n\n return $customReportName;\n }\n\n private function validateOrganization(?string $organizationUuid): Team\n {\n if (! $organizationUuid) {\n throw new InvalidArgumentException('Organization is required');\n }\n\n $team = $this->teamRepository->idOrUuid($organizationUuid);\n\n if (! $team) {\n throw new InvalidArgumentException('Organization not found');\n }\n\n if (! $team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {\n throw new InvalidArgumentException('Organization does not have the Automated Reports feature');\n }\n\n return $team;\n }\n\n private function validateAndGetGroupIds(Team $team, array $teamUuids): array\n {\n $groupIds = [];\n\n foreach ($teamUuids as $uuid) {\n $group = $this->groupRepository->findByUuid($uuid);\n\n if ($group === null || $group->getTeamId() !== $team->getId()) {\n throw new InvalidArgumentException(\n sprintf('Group %s not found for team %s', $uuid, $team->getUuid())\n );\n }\n\n $groupIds[] = $group->getId();\n\n }\n\n return $groupIds;\n }\n\n private function validateAndGetDealStageIds(Team $team, array $stageUuids, string $propertyLabel): array\n {\n $stageIds = [];\n\n foreach ($stageUuids as $uuid) {\n $stage = $this->stageRepository->findByUuid($uuid);\n\n if ($stage === null || $stage->getTeamId() !== $team->getId()) {\n throw new InvalidArgumentException(\n sprintf('Stage %s not found for team %s for %s', $uuid, $team->getUuid(), $propertyLabel)\n );\n }\n\n $stageIds[] = $stage->getId();\n }\n\n return $stageIds;\n }\n\n private function validateAndGetUserIds(array $userUuids, callable $teamCheck): array\n {\n if (empty($userUuids)) {\n return [];\n }\n\n $userIds = [];\n\n foreach ($userUuids as $uuid) {\n $user = $this->userRepository->findByUuid($uuid);\n\n if (! $user || ! $user->isStatusActive()) {\n throw new InvalidArgumentException(\n sprintf('User %s not found or is not active', $uuid)\n );\n }\n\n if (! $teamCheck($user)) {\n throw new InvalidArgumentException(\n sprintf('User %s does not belong to the allowed team(s)', $uuid)\n );\n }\n\n $userIds[] = $user->getId();\n }\n\n return $userIds;\n }\n\n private function validateAndGetUserIdsByTeam(Team $team, array $userUuids): array\n {\n return $this->validateAndGetUserIds($userUuids, fn ($user) => $user->getTeamId() === $team->getId());\n }\n\n private function validateAndGetJiminnyUserIds(array $userUuids): array\n {\n $allowedTeamIds = config('kiosk.teamIds', []);\n\n return $this->validateAndGetUserIds($userUuids, fn ($user) => in_array($user->getTeamId(), $allowedTeamIds, true));\n }\n\n private function parseDate(string $dateString): string\n {\n return date('Y-m-d H:i:s', strtotime($dateString));\n }\n\n private function generateReportResultViewUrl(AutomatedReportResult $result): string\n {\n $mediaResource = $this->getReportMediaRouteResource($result);\n\n return route('ai-reports.' . $mediaResource . '.view', ['uuid' => $result->getUuid()]);\n }\n\n private function generateReportResultDownloadUrl(AutomatedReportResult $result): string\n {\n $mediaResource = $this->getReportMediaRouteResource($result);\n\n return route('ai-reports.' . $mediaResource . '.download', ['uuid' => $result->getUuid()]);\n }\n\n private function getReportMediaRouteResource(AutomatedReportResult $result): string\n {\n if ($result->getMediaType() === self::MEDIA_TYPE_PDF) {\n return self::PDF_KEY;\n } elseif ($result->getMediaType() === self::MEDIA_TYPE_PODCAST) {\n return self::AUDIO_KEY;\n }\n\n throw new \\InvalidArgumentException('Unknown media type.');\n }\n\n public function getMediaPath(AutomatedReportResult $result): ?string\n {\n $url = match ($result->getMediaType()) {\n self::MEDIA_TYPE_PDF => $result->getPdfUrl(),\n self::MEDIA_TYPE_PODCAST => $result->getPodcastAudioUrl(),\n default => null,\n };\n\n if ($url === null) {\n return null;\n }\n\n $path = parse_url(trim($url, '\"\\''), PHP_URL_PATH);\n\n return $path ?: null;\n }\n\n public function getFilenameSuffix(AutomatedReportResult $result): ?string\n {\n return match ($result->getMediaType()) {\n self::MEDIA_TYPE_PODCAST => 'Podcast',\n default => null,\n };\n }\n\n public function getMailSubjectSuffix(AutomatedReportResult $result): string\n {\n return match ($result->getMediaType()) {\n self::MEDIA_TYPE_PDF => 'report',\n self::MEDIA_TYPE_PODCAST => 'podcast',\n default => '',\n };\n }\n\n public function getMediaTypeMetadata(AutomatedReportResult $result): array\n {\n return match ($result->getMediaType()) {\n self::MEDIA_TYPE_PODCAST => ['extension' => 'mp3', 'mime' => 'audio/mpeg'],\n self::MEDIA_TYPE_PDF => ['extension' => 'pdf', 'mime' => 'application/pdf'],\n default => ['extension' => null, 'mime' => null],\n };\n }\n\n public function deleteS3Files(AutomatedReportResult $result): void\n {\n $teamUuid = $result->getReport()->getTeam()->getUuid();\n $reportUuid = $result->getUuid();\n\n // delete all files for a report uuid no mather of pdf, podcast, or both\n // in case of both - the podcast files are linked to the pdf (parent) uuid\n // pdf and podcast date times should be close\n $path = sprintf('%s/%s/%s', $teamUuid, self::S3_DIR, $reportUuid);\n\n foreach (self::FILE_EXTENSIONS_VARIANTS as $extension) {\n $file = $path . '.' . $extension;\n\n if (Storage::exists($file)) {\n Storage::delete($file);\n Log::info('[Reports] Deleted S3 file', [\n 'path' => $file,\n ]);\n }\n }\n\n foreach (self::FILE_PODCAST_EXTENSIONS_VARIANTS as $extension) {\n $file = $path . '_podcast.' . $extension;\n\n if (Storage::exists($file)) {\n Storage::delete($file);\n Log::info('[Reports] Deleted Podcast S3 file', [\n 'path' => $file,\n ]);\n }\n }\n }\n\n /**\n *\n * @param int|null $teamId Optional team ID to filter results\n *\n * @return Collection<int, int> Collection of team IDs\n */\n public function getTeamIdsWithReportsResults(?int $teamId = null): Collection\n {\n return $this->automatedReportsRepository->getTeamIdsWithReportsResults($teamId);\n }\n\n /**\n * Core delete logic for report results using a query\n *\n * @param Builder $query\n * @param array $logContext\n *\n * @return int\n */\n private function deleteReportResultsByQuery(Builder $query, array $logContext = []): int\n {\n $deletedCount = 0;\n\n if ($query->exists()) {\n Log::info(\n 'Run delete report results',\n array_merge(\n $logContext,\n [\n 'service' => 'AutomatedReportsService',\n ]\n )\n );\n\n $query->chunkById(50, function ($results) use (&$deletedCount, $logContext) {\n foreach ($results as $result) {\n $this->deleteReportResult($result);\n $deletedCount++;\n\n Log::info(\n 'Deleted a report result',\n array_merge(\n $logContext,\n [\n 'result_id' => $result->getId(),\n 'report_id' => $result->getReportId(),\n ]\n )\n );\n }\n });\n }\n\n return $deletedCount;\n }\n\n /**\n * Delete report results for a team by retention period\n *\n * @param Team $team\n * @param CarbonImmutable $retentionDate\n *\n * @return int Number of deleted report results\n */\n public function deleteReportsResultsInRetentionPeriod(Team $team, CarbonImmutable $retentionDate): int\n {\n $reportIds = $this->automatedReportsRepository->getReportIdsByTeam($team);\n\n if ($reportIds->isEmpty()) {\n return 0;\n }\n\n $query = $this->automatedReportsRepository\n ->getReportResultsQueryForRetention($team, $retentionDate);\n\n return $this->deleteReportResultsByQuery($query, [\n 'team_id' => $team->getId(),\n 'retention_date' => $retentionDate->toDateTimeString(),\n ]);\n }\n\n /**\n * Delete ALL report results for a specific automated report\n *\n * @param string $uuid\n *\n * @return int\n */\n public function deleteReportResults(string $uuid): int\n {\n $report = $this->getReport($uuid);\n\n $query = $this->automatedReportsRepository->getResultsByReportQuery($report);\n\n return $this->deleteReportResultsByQuery($query, [\n 'report_uuid' => $uuid,\n 'report_id' => $report->getId(),\n ]);\n }\n\n public function deleteReportResult(AutomatedReportResult $result): void\n {\n $this->deleteS3Files($result);\n\n $result->delete();\n }\n\n /**\n * Get all reports for a specific team\n *\n * @param Team $team\n *\n * @return \\Illuminate\\Database\\Eloquent\\Collection\n */\n public function getTeamReports(Team $team): \\Illuminate\\Database\\Eloquent\\Collection\n {\n return $this->automatedReportsRepository->getReportsByTeam($team);\n }\n\n /**\n * Get all report results for a specific report\n *\n * @param AutomatedReport $report\n *\n * @return \\Illuminate\\Database\\Eloquent\\Collection\n */\n public function getReportResults(AutomatedReport $report): \\Illuminate\\Database\\Eloquent\\Collection\n {\n return $this->automatedReportsRepository->getResultsByReport($report);\n }\n\n public function deleteAllReportResults(AutomatedReport $report): void\n {\n $results = $this->getReportResults($report);\n\n /** @var AutomatedReportResult $result */\n foreach ($results as $result) {\n Log::info('Deleting result', [\n 'report' => $report->getId(),\n 'result' => $result->getId(),\n ]);\n\n $this->deleteReportResult($result);\n }\n }\n\n public function deleteAllData(Team $team): void\n {\n Log::info('Deleting automated report and results for team', [\n 'team' => $team->getId(),\n ]);\n\n $reports = $this->getTeamReports($team);\n\n /** @var AutomatedReport $report */\n foreach ($reports as $report) {\n Log::info('Deleting report', [\n 'team' => $team->getId(),\n 'report' => $report->getId(),\n ]);\n\n $this->deleteAllReportResults($report);\n\n $report->delete();\n }\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":true,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"Project","depth":3,"role_description":"text"},{"role":"AXButton","text":"Project","depth":3,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"New File or Directory…","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Expand Selected","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Collapse All","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Options","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false}]...
|
3397592283435315795
|
6686367547760219213
|
idle
|
accessibility
|
NULL
|
Project: faVsco.js, menu
#11894 on JY-18909-automa Project: faVsco.js, menu
#11894 on JY-18909-automated-reports-ask-jiminny, menu
Start Listening for PHP Debug Connections
AutomatedReportsCommandTest
Run 'AutomatedReportsCommandTest'
Debug 'AutomatedReportsCommandTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Execute
Explain Plan
Browse Query History
View Parameters
Open Query Execution Settings…
In-Editor Results
Tx: Auto
Cancel Running Statements
Playground
jiminny
Sync Changes
Hide This Notification
Code changed:
Hide
16
13
13
Previous Highlighted Error
Next Highlighted Error
SELECT * FROM teams WHERE id = 1;
select * from crm_layouts where crm_configuration_id = 39;
SELECT * FROM crm_layout_entities WHERE crm_layout_id = 283;
SELECT * FROM crm_fields WHERE id = 2234;
SELECT * FROM crm_field_values WHERE crm_field_id = 2234;
select * from crm_profiles where user_id = 143;
select * from record_types where crm_configuration_id = 39; # 0121K000001MHElQAO,0121K000001MHEqQAO
select * from business_processes where crm_configuration_id = 39;
# 01941000000H669AAC, 01941000000H66JAAS
select * from record_type_field_values
where record_type_id IN (24);
select * from crm_field_values where id IN (2730);
select * from crm_configurations where id = 39;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 1
and sa.provider = 'salesforce'; #1035
select * from users where team_id = 1; # 222 group 3
SELECT * FROM activities WHERE user_id = 222 order by id desc;
select * from sidekick_settings where team_id = 1;
select * from teams where id = 1;
select * from team_features where team_id = 1;
select * from activities where crm_configuration_id = 2
and provider = 'ms-teams' and id = 608765;
SELECT * FROM activities WHERE crm_configuration_id = 2 and crm_provider_id = '59523413338';
select * from sidekick_settings where team_id = 2;
SELECT * FROM activities WHERE id = 608660;
select * from activity_summary_logs where activity_id = 608660;
select * from ai_prompts where transcription_id = 11214;
# [PASSWORD_DOTS]
SELECT * FROM activities WHERE uuid_to_bin('ed78a437-2804-450e-ab2f-56ab1c641346') = uuid;
# id: 608818, crm: 59628809737
SELECT * FROM activities WHERE uuid_to_bin('36b06e55-afdd-4782-8dee-c624cd0af191') = uuid;
# id: 608821, crm: 59632069252
SELECT ce.start_time, ce.end_time, a.id, a.uuid, crm_provider_id, calendar_event_id, title,
playbook_category_id, user_id, lead_id, contact_id, account_id, opportunity_id,
scheduled_start_time, scheduled_end_time, actual_start_time, actual_end_time, a.created_at
FROM activities a
join calendar_events ce on a.calendar_event_id = ce.id
WHERE a.id IN (608818, 608821);
select * from users where team_id = 1;
select * from team_settings where team_id = 1;
select * from crm_profiles where crm_configuration_id = 39 order by user_id;
select * from team_features where team_id = 1;
select * from users where team_id = 2;
SELECT * FROM activities WHERE uuid_to_bin('ec7647e9-5225-458b-b475-f31aa2769204') = uuid; # 612639
# Preslava N. Ivanova, grou id 3
SELECT * FROM opportunities WHERE uuid_to_bin('a2928fe5-aec5-46cb-85d9-7654c89e46a6') = uuid;
select * from activities where opportunity_id = 344 and actual_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00';
select
a.id,
a.type,
a.scheduled_start_time,
a.actual_start_time,
a.created_at,
a.opportunity_id,
a.status
FROM activities a
WHERE opportunity_id = 344
and status IN ('completed', 'received', 'delivered')
and (
(a.actual_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00')
OR (a.created_at between '2024-10-11 00:00:00' and '2024-10-12 00:00:00')
OR (a.scheduled_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00'))
;
SELECT * FROM users WHERE id = 222;
SELECT * FROM crm_profiles WHERE user_id = 222;
select * from crm_layouts where crm_configuration_id = 39;
SELECT * FROM crm_layout_entities WHERE crm_layout_id = 281;
select * from group_deal_risk_types;
select * from opportunities where team_id = 1;
SELECT * FROM opportunities WHERE id = 315;
SELECT * FROM crm_field_data WHERE object_id = 315;
select * from crm_field_data where object_id = 260;
select * from generic_ai_prompts where subject_id = 315;
select * from teams; # 36, 21, 121, [EMAIL]
SELECT * FROM social_accounts WHERE sociable_id = 121 and provider = 'bullhorn';
# [PASSWORD_DOTS]
select * from teams where id = 1;
select * from crm_configurations where id = 39;
select * from users where team_id = 1;
select u.email, cp.* from users u
join crm_profiles cp on u.id = cp.user_id
where u.team_id = 1;
# 1 - 00541000004281rAAA
# 204 - 0052g000003freeAAA
# 429 - 0052g000003qGOiAAM
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 1
and sa.provider = 'salesforce';
select * from activities where type = 'softphone'
and created_at > '2024-12-11 15:24:36' order by id desc;
select * from activity_providers where team_id = 1;
select * from activity_provider_users where activity_provider_id = 328;
select * from opportunities where crm_configuration_id = 39
AND account_id = 178 AND is_closed = false
order by created_at DESC;
select * from contacts where id = 3952;
select * from accounts where id = 178;
# [PASSWORD_DOTS]
select * from teams where id = 36;
select * from crm_configurations where id = 21;
select * from users where team_id = 36;
select u.email, cp.* from users u
join crm_profiles cp on u.id = cp.user_id
where u.team_id = 36;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 36
and sa.provider = 'bullhorn';
select * from social_accounts where id = 348;
UPDATE social_accounts SET
provider_user_token = '21442_6802599_91:41179a58-21e7-4d7c-ad58-56bb666b2f65',
provider_refresh_token = '21442_6802599_91:01c6b335-3f2a-42e4-85ff-8a08fa65fceb',
expires = 1733998131,
state = 'connected'
WHERE id = 348;
# [PASSWORD_DOTS]
select * from teams where id = 31;
select * from crm_configurations where id = 18;
select * from users where team_id = 31; # 257
select u.email, cp.* from users u
join crm_profiles cp on u.id = cp.user_id
where u.team_id = 31;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 31
and sa.provider = 'close';
select * from contacts where crm_configuration_id = 18;
# [PASSWORD_DOTS] NEPTUNE [PASSWORD_DOTS]
select * from teams;
select * from users where id IN (1030, 1035, 1052);
select * from crm_configurations;
select * from users where team_id = 65; # 257
select * from team_settings where team_id = 65; # 257
select * from invitations where team_id = 65; # 257
select * from users where email = '[EMAIL]'; # 257
select u.email, cp.* from users u
join crm_profiles cp on u.id = cp.user_id
where u.team_id = 65;
select * from crm_configurations where id = 53;
select * from accounts where crm_configuration_id = 53 order by id desc;
select * from leads where crm_configuration_id = 53 order by id desc;
select * from contacts where crm_configuration_id = 53 order by id desc;
select * from opportunities where crm_configuration_id = 53 order by id desc;
select * from crm_profiles where crm_configuration_id = 53 order by id desc;
select * from crm_fields where crm_configuration_id = 53 order by id desc;
select * from crm_field_values where crm_field_id = 3341 order by id desc;
select * from crm_layouts where crm_configuration_id = 53 order by id desc;
select * from stages where crm_configuration_id = 53 order by id desc;
select * from crm_profiles where crm_configuration_id = 13;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 65
and sa.provider = 'integration-app';
select * from contacts where crm_configuration_id = 13;
select * from social_accounts where sociable_id = 283;
SELECT * FROM opportunities WHERE crm_provider_id = '006O400000E9bzeIAB';
select * from activity_providers where team_id = 65;
SELECT * FROM activities WHERE crm_configuration_id IN (51, 52, 53);
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 65
;
# [PASSWORD_DOTS] STAGING [PASSWORD_DOTS]
SELECT * FROM teams;
SELECT * FROM teams WHERE id = 88;
SELECT * FROM teams WHERE id = 89;
select * from team_settings where team_id = 89;
SELECT * FROM users WHERE team_id = 89;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 89;
select * from users;
SELECT * FROM social_accounts WHERE sociable_id = 1761;
SELECT * FROM crm_configurations WHERE id = 70;
select * from accounts where crm_configuration_id = 70 order by id desc;
select * from leads where crm_configuration_id = 70 order by id desc;
select * from contacts where crm_configuration_id = 70 order by id desc;
select * from opportunities where crm_configuration_id = 70 order by id desc;
select * from crm_profiles where crm_configuration_id = 70 order by id desc;
select * from crm_fields where crm_configuration_id = 70 order by id desc;
select * from crm_field_values where crm_field_id = 3536 order by id desc;
select * from crm_layouts where crm_configuration_id = 70 order by id desc;
select * from stages where crm_configuration_id = 70 order by id desc;
select * from business_processes where crm_configuration_id = 70 order by id desc;
select * from business_process_stages where business_process_id = 34;
select * from contacts where id = 10468;
select * from crm_layouts where crm_configuration_id = 70;
SELECT * FROM crm_layout_entities WHERE crm_layout_id = 388;
SELECT * FROM crm_fields WHERE id IN (3533,3534,3535);
select * from activities where crm_configuration_id = 70
and (account_id IS NOT NULL or lead_id IS NOT NULL or contact_id IS NOT NULL or opportunity_id IS NOT NULL) order by id desc;
SELECT * FROM activities WHERE uuid_to_bin('2e10b60f-8a61-41c5-a3d4-28835353dc65') = uuid;
SELECT * FROM activities where crm_configuration_id = 69 ;
SELECT * FROM users WHERE email LIKE '%[EMAIL]%';
SELECT * FROM activities WHERE uuid_to_bin('5a150c93-40fc-42ec-b3bd-c1d328e09f6e') = uuid;
SELECT * FROM opportunities WHERE id = 385;
select * from participants p
join activities a on p.activity_id = a.id
where a.crm_configuration_id = 70
and (p.lead_id IS NOT NULL or p.contact_id IS NOT NULL);
SELECT * FROM participants WHERE id = 1013638;
select * from teams where id = 90;
select * from users where team_id = 90;
select * from social_accounts where social_accounts.sociable_id IN (1960,1760);
SELECT * FROM crm_profiles WHERE crm_configuration_id = 71;
select * from invitations where team_id = 90;
select * from crm_configurations where id = 71;
select * from accounts where crm_configuration_id = 71 order by id desc;
select * from leads where crm_configuration_id = 71 order by id desc;
select * from contacts where crm_configuration_id = 71 order by id desc;
select * from opportunities where crm_configuration_id = 71 order by id desc;
select * from crm_profiles where crm_configuration_id = 71 order by id desc;
select * from crm_fields where crm_configuration_id = 71 order by id desc;
select * from crm_field_values where crm_field_id = 3341 order by id desc;
select * from crm_layouts where crm_configuration_id = 71 order by id desc;
select * from stages where crm_configuration_id = 71 order by id desc;
select * from users order by secondary_email desc;
select u.id, u.email, u.status, sa.id, sa.provider_user_id from social_accounts sa
join users u on sa.sociable_id = u.id
where sa.provider = 'google' and u.email LIKE 'aneliya%';
select * from failed_jobs order by id desc;
select * from users where email = '[EMAIL]' or secondary_email = '[EMAIL]';
select * from teams;
SELECT * FROM crm_profiles WHERE crm_configuration_id = 39;
SELECT * FROM crm_fields WHERE crm_configuration_id = 39 and object_type = 'task';
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 1
and sa.provider = 'salesforce';
# [PASSWORD_DOTS]
SELECT * FROM activities WHERE uuid_to_bin('c38b3895-fd0f-4b1f-9fb2-c170dba137c6') = uuid;
SELECT * FROM crm_configurations WHERE id = 70;
select * from teams where id = 1;
select * from groups where team_id = 1;
select * from users where team_id = 1;
select o.id, o.name,o.close_date, u.id, u.name, u.group_id, r.id, r.display_name, g.name, g.scope from opportunities o
join users u on o.user_id = u.id
join groups g on u.group_id = g.id
join role_user ru on u.id = ru.user_id
join roles r on ru.role_id = r.id
where o.crm_configuration_id = 39 and close_date > '2024-01-01 00:00:00';
select * from role_user where user_id = 143;
select * from roles;
select * from role_user;
select * from groups where id = 9;
select * from scope_groups where group_id = 9;
# [PASSWORD_DOTS]
select * from teams where id = 36;
select * from crm_configurations;
SELECT * FROM social_accounts WHERE sociable_id = 121;
[URL_WITH_CREDENTIALS] this will add filter, however if we need to control feature by FF we need conditional logic
public const array TYPES = [
['id' => 'exec_summary', 'name' => 'Exec Summary'],
['id' => 'coaching_profiles', 'name' => 'Coaching Profiles'],
['id' => 'product_feedback', 'name' => 'Product Feedback'],
['id' => self::TYPE_LOSS_ANALYSIS, 'name' => 'Loss Analysis'],
// ['id' => 'questions', 'name' => 'Questions'],
// ['id' => 'statistical_quant', 'name' => 'Statistical Quantitative'],
];
public const array ALL_TYPES = [
...self::TYPES,
['id' => self::TYPE_ASK_JIMINNY, 'name' => 'Ask Jiminny'],
];
public const string FREQUENCY_DAILY = 'daily';
public const string FREQUENCY_WEEKLY = 'weekly';
public const string FREQUENCY_MONTHLY = 'monthly';
public const string FREQUENCY_QUARTERLY = 'quarterly';
public const string FREQUENCY_ONE_OFF = 'one_off';
/**
* Frequencies for standard (non-Ask Jiminny) reports.
*/
public const array FREQUENCIES = [
['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],
['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],
['id' => self::FREQUENCY_QUARTERLY, 'name' => 'Quarterly'],
['id' => self::FREQUENCY_ONE_OFF, 'name' => 'One-off'],
];
/**
* Frequencies for Ask Jiminny reports.
*/
public const array ASK_JIMINNY_FREQUENCIES = [
['id' => self::FREQUENCY_DAILY, 'name' => 'Daily'],
['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],
['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],
];
public const string MEDIA_TYPE_PDF = 'pdf';
public const string MEDIA_TYPE_PODCAST = 'podcast';
public const array MEDIA_TYPES = [self::MEDIA_TYPE_PDF, self::MEDIA_TYPE_PODCAST];
public const array MEDIA_TYPE_OBJECT_PDF = ['id' => self::MEDIA_TYPE_PDF, 'name' => 'PDF'];
public const array MEDIA_TYPE_OBJECT_PODCAST = ['id' => self::MEDIA_TYPE_PODCAST, 'name' => 'Podcast'];
public const array MEDIA_TYPE_OBJECTS = [self::MEDIA_TYPE_OBJECT_PDF, self::MEDIA_TYPE_OBJECT_PODCAST];
public const array CALL_TYPE_CONFERENCE = ['id' => 'conference', 'name' => 'Conference'];
public const array CALL_TYPE_DIALER = ['id' => 'dialer', 'name' => 'Dialer'];
public const int SENT_REPORT_AT_HOURS = 5;
public const string PDF_KEY = 'pdf';
public const string AUDIO_KEY = 'audio';
private const array ALL_FREQUENCIES = [
['id' => self::FREQUENCY_DAILY, 'name' => 'Daily'],
['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],
['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],
['id' => self::FREQUENCY_QUARTERLY, 'name' => 'Quarterly'],
['id' => self::FREQUENCY_ONE_OFF, 'name' => 'One-off'],
];
private const string S3_DIR = 'reports';
private const array FILE_EXTENSIONS_VARIANTS = ['html', 'MD', 'pdf'];
private const array FILE_PODCAST_EXTENSIONS_VARIANTS = ['json', 'mp3', 'ssml'];
public function __construct(
private readonly TeamRepository $teamRepository,
private readonly GroupRepository $groupRepository,
private readonly UserRepository $userRepository,
private readonly StageRepository $stageRepository,
private readonly DealStagesService $dealStagesService,
private readonly RecipientsService $recipientsService,
private readonly AutomatedReportsRepository $automatedReportsRepository,
private readonly Webhook $webhookService,
private readonly BusDispatcher $dispatcher,
private readonly ActivityTypeService $activityTypeService,
private readonly PlaybookCategoryRepository $playbookCategoryRepository,
private readonly AskAnythingPromptService $askAnythingPromptService,
private readonly SearchRepository $activitySearchRepository,
private readonly AskAnythingRepository $askAnythingRepository,
) {
}
public static function getTypes(): array
{
$types = self::TYPES;
return array_map(static function ($type) {
return $type['id'];
}, $types);
}
public static function getCallTypes(): array
{
return array_map(static function ($callType) {
return $callType['id'];
}, [self::CALL_TYPE_CONFERENCE, self::CALL_TYPE_DIALER]);
}
public static function getFrequencies(): array
{
return array_map(static function ($frequency) {
return $frequency['id'];
}, self::FREQUENCIES);
}
// front-facing structure
public function getReportEnabledFieldData(bool $value = false): array
{
return [
'id' => 'report_enabled',
'label' => '',
'inputType' => InputTypeEnum::TOGGLE,
'value' => $value,
];
}
// Organizations = Teams
public function getOrganizationFieldData(?string $value = null, bool $shortVersion = false): array
{
$options = $this->getTeams();
if ($shortVersion) {
return [
'id' => 'organization',
'label' => 'Organization',
'options' => $options,
];
}
return [
'id' => 'organization',
'label' => 'Organization',
'inputType' => InputTypeEnum::DROPDOWN,
'required' => true,
'placeholder' => 'Select',
'options' => $options,
'value' => $value,
'dependencies' => [
'teams',
'deal_stage_at_call',
'current_deal_stage',
'recipients',
ActivityTypeService::PLAYBOOK_CATEGORIES_KEY,
],
'dependsOn' => [],
];
}
// Teams = Groups
public function getTeamFieldData(array $options = [], array $value = [], bool $shortVersion = false): array
{
if ($shortVersion) {
return [
'id' => 'teams',
'label' => 'Team',
'options' => $options,
];
}
return [
'id' => 'teams',
'label' => 'Team',
'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,
'required' => false,
'placeholder' => 'Select',
'options' => $options,
'value' => $value, // value should be an array of objects {id, name}
'dependencies' => [ActivityTypeService::PLAYBOOK_CATEGORIES_KEY],
'dependsOn' => [],
];
}
public function getReportTypeFieldData(?string $value = null, bool $shortVersion = false, ?Team $team = null): array
{
$types = [];
if ($team instanceof Team) {
if ($team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {
$types = self::TYPES;
}
if ($team->hasFeature(FeatureEnum::ASK_JIMINNY_REPORTS)) {
$types[] = ['id' => self::TYPE_ASK_JIMINNY, 'name' => 'Ask Jiminny'];
}
} else {
$types = self::TYPES;
}
if ($shortVersion) {
return [
'id' => 'report_type',
'label' => 'Report Type',
'options' => $types,
];
}
return [
'id' => 'report_type',
'label' => 'Report Type',
'inputType' => InputTypeEnum::DROPDOWN,
'required' => true,
'placeholder' => 'Select',
'options' => $types,
'value' => $value,
'dependencies' => [],
'dependsOn' => [],
];
}
public function getFrequencyFieldData(?string $value = null): array
{
return [
'id' => 'frequency',
'label' => 'Frequency',
'inputType' => InputTypeEnum::DROPDOWN,
'required' => true,
'placeholder' => 'Select',
'options' => self::FREQUENCIES,
'value' => $value,
'dependencies' => ['period'],
'dependsOn' => [],
];
}
public function getPeriodFieldData(?string $valueStartDate = null, ?string $valueEndDate = null): array
{
return [
'id' => 'period',
'label' => 'Select one-off period',
'inputType' => InputTypeEnum::DATE_RANGE,
'required' => true,
'placeholder' => 'Select',
'value' => ['startDate' => $valueStartDate, 'endDate' => $valueEndDate],
'queryParams' => [
'startDate' => 'start_date_period',
'endDate' => 'end_date_period',
],
'dependencies' => [],
'dependsOn' => ['frequency'],
];
}
public function getActivityTypesFieldData(?Team $team = null, array $value = [], array $teamsFilter = []): array
{
return $this->activityTypeService->getActivityTypeFieldData(team: $team, value: $value, groupIds: $teamsFilter);
}
public function getDealStageAtCallFieldData(?Team $team = null, array $value = []): array
{
return $this->dealStagesService->getDealStageAtCallFieldData(team: $team, value: $value);
}
public function getCurrentDealStageFieldData(?Team $team = null, array $value = []): array
{
return $this->dealStagesService->getCurrentDealStageFieldData(team: $team, value: $value);
}
public function getDealValueFieldData(?int $valueMin = null, ?int $valueMax = null): array
{
return [
'id' => 'deal_value',
'label' => 'Deal Value',
'inputType' => InputTypeEnum::INTEGER_RANGE,
'required' => false,
'value' => ['min' => $valueMin, 'max' => $valueMax],
'queryParams' => [
'min' => 'min_deal_value',
'max' => 'max_deal_value',
],
'dependencies' => [],
'dependsOn' => [],
];
}
public function getCallTypeFieldData(bool $conferenceOn = false, bool $dialerOn = false): array
{
$value = [];
$conferenceOn && $value[] = self::CALL_TYPE_CONFERENCE;
$dialerOn && $value[] = self::CALL_TYPE_DIALER;
return [
'id' => 'call_type',
'label' => 'Call Type',
'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,
'required' => true,
'options' => [
self::CALL_TYPE_CONFERENCE,
self::CALL_TYPE_DIALER,
],
'value' => $value,
'dependencies' => [],
'dependsOn' => [],
];
}
public function getMediaTypeFieldData(?AutomatedReport $report = null): array
{
$value = [];
if ($report) {
$value = $this->transformMediaTypes($report);
}
return [
'id' => 'media_types',
'label' => 'Export as',
'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,
'required' => true,
'options' => self::MEDIA_TYPE_OBJECTS,
'value' => $value,
'dependencies' => [],
'dependsOn' => [],
];
}
public function getCallDurationFieldData(?int $valueMin = null, ?int $valueMax = null): array
{
return [
'id' => 'call_duration',
'label' => 'Call Duration',
'inputType' => InputTypeEnum::INTEGER_RANGE,
'required' => false,
'value' => ['min' => $valueMin, 'max' => $valueMax],
'queryParams' => [
'min' => 'min_call_duration',
'max' => 'max_call_duration',
],
'dependencies' => [],
'dependsOn' => [],
];
}
public function getRecipientsFieldData(?Team $team = null, array $value = []): array
{
return $this->recipientsService->getRecipientsFieldData(team: $team, value: $value);
}
public function getJiminnyRecipientsFieldData(array $value = []): array
{
return $this->recipientsService->getJiminnyRecipientsFieldData($value);
}
public function getAdditionalPromptInputFieldData(?string $value = null): array
{
return [
'id' => 'additional_prompt_input',
'label' => 'Special requirements',
'inputType' => InputTypeEnum::TEXTAREA,
'required' => false,
'placeholder' => 'What should be the focus of the report?',
'value' => $value,
'dependencies' => [],
'dependsOn' => [],
];
}
public function getCustomReportNameFieldData(?string $value = null): array
{
return [
'id' => 'custom_name',
'label' => 'Custom report name',
'inputType' => InputTypeEnum::TEXT,
'required' => false,
'placeholder' => 'Enter custom name',
'value' => $value,
'dependencies' => [],
'dependsOn' => [],
];
}
// data providers
public function getTeams(): array
{
$teams = $this->teamRepository->getTeamsForKiosk(status: Team::STATUS_ACTIVE);
$teamData = [];
foreach ($teams as $team) {
if (! $team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {
continue;
}
$teamData[] = $this->transformTeam($team);
}
return $teamData;
}
public function getTeamGroups(string $teamUuid): array
{
$data = [];
$team = $this->getTeam($teamUuid);
if ($team !== null) {
$groups = $team->groups()->get();
foreach ($groups as $group) {
$data[] = [
'id' => $group->getUuid(),
'name' => $group->getName(),
];
}
}
return $data;
}
public function getTeamsGroupsOptions(array $filterTeamUuids = []): array
{
$data = [];
$teams = $this->getTeams();
foreach ($teams as $team) {
if (! empty($filterTeamUuids) && ! in_array($team['id'], $filterTeamUuids, true)) {
continue;
}
$data[] = [
'label' => $team['name'],
'groups' => $this->getTeamGroups($team['id']),
];
}
return $data;
}
public function getTeam(string $teamUuid): ?Team
{
return $this->teamRepository->idOrUuid($teamUuid);
}
public function getTeamById(int $teamId): ?Team
{
return $this->teamRepository->find($teamId);
}
public function getGroupsUuids(AutomatedReport $report): array
{
$uuids = [];
$reportGroups = $report->getGroups();
foreach ($reportGroups as $groupId) {
if ($group = $this->groupRepository->find($groupId)) {
$uuids[] = $group->getUuid();
}
}
return $uuids;
}
public function getPlaybookCategoriesUuids(AutomatedReport $report): array
{
$uuids = [];
$playbookCategories = $report->getPlaybookCategories();
foreach ($playbookCategories as $id) {
if ($category = $this->playbookCategoryRepository->find($id)) {
$uuids[] = $category->getUuid();
}
}
return $uuids;
}
public function getDealAtCallStagesUuids(AutomatedReport $report): array
{
$uuids = [];
$reportStages = $report->getDealAtCallStages();
foreach ($reportStages as $id) {
if ($stage = $this->stageRepository->find($id)) {
$uuids[] = $stage->getUuid();
}
}
return $uuids;
}
public function getCurrentDealStagesUuids(AutomatedReport $report): array
{
$uuids = [];
$reportStages = $report->getCurrentDealStages();
foreach ($reportStages as $id) {
if ($stage = $this->stageRepository->find($id)) {
$uuids[] = $stage->getUuid();
}
}
return $uuids;
}
public function getUsersUuids(AutomatedReport $report): array
{
return $this->extractUserUuids($report->getRecipients());
}
public function getJiminnyUsersUuids(AutomatedReport $report): array
{
return $this->extractUserUuids($report->getJiminnyRecipients());
}
/**
* @param array<string, mixed> $recipients
*/
private function extractUserUuids(array $recipients): array
{
$userIds = $recipients['users'] ?? [];
return collect($userIds)
->map(fn ($id) => $this->userRepository->find((int) $id))
->filter()
->map(fn (UserContract $user) => $user->getUuid())
->values()
->all();
}
// get mail data
public function getRecipientUsers(AutomatedReport $report): array
{
return $this->buildRecipientUsers($report->getRecipients());
}
private function getJiminnyRecipientUsers(AutomatedReport $report): array
{
return $this->buildRecipientUsers($report->getJiminnyRecipients());
}
/**
* @param array<string, mixed> $recipients
*/
private function buildRecipientUsers(array $recipients): array
{
$userIds = $recipients['users'] ?? [];
return collect($userIds)
->map(fn ($id) => $this->userRepository->find((int) $id))
->filter()
->map(fn (UserContract $user) => [
'email' => $user->getEmailAddress(),
'name' => $user->getName(),
'timezone' => $user->getTimezone()->getName(),
])
->values()
->all();
}
public function getValidRecipientUsers(AutomatedReport $report, bool $includeJiminny = false): array
{
if ($report->isAskJiminnyReport()) {
$recipients = $this->resolveAskJiminnyRecipients($report);
} else {
$recipients = $this->getRecipientUsers($report);
if ($includeJiminny) {
$recipients = array_merge($recipients, $this->getJiminnyRecipientUsers($report));
}
}
$emails = [];
return array_values(array_filter(
$recipients,
static function ($recipient) use (&$emails) {
if (empty($recipient['email']) || in_array($recipient['email'], $emails, true)) {
return false;
}
$emails[] = $recipient['email'];
return true;
}
));
}
private function resolveAskJiminnyRecipients(AutomatedReport $report): array
{
$recipients = [];
$creator = $report->getCreator();
if ($creator !== null) {
$recipients[] = [
'email' => $creator->getEmailAddress(),
'name' => $creator->getName(),
'timezone' => $creator->getTimezone()->getName(),
];
}
return array_merge(
$recipients,
$this->buildRecipientUsers($report->getRecipients()),
$this->getGroupRecipientUsers($report),
);
}
private function getGroupRecipientUsers(AutomatedReport $report): array
{
$users = [];
foreach ($report->getGroups() as $groupId) {
$group = $this->groupRepository->find($groupId);
if ($group === null) {
continue;
}
foreach ($group->getMembers() as $member) {
$users[] = [
'email' => $member->getEmailAddress(),
'name' => $member->getName(),
'timezone' => $member->getTimezone()->getName(),
];
}
}
return $users;
}
public function getReportTypeName(AutomatedReportResult $report): string
{
$type = $report->getReport()->getType();
$getType = $this->transformReportType($type);
return $getType['name'];
}
public function getReportPeriodName(AutomatedReportResult $report): string
{
$from = $report->getFromDate();
$to = $report->getToDate();
$frequency = $report->getReport()->getFrequency();
if ($from === null || $to === null) {
if (! $report->getReport()->isAskJiminnyReport()) {
$invalidPeriod = $from === null ? 'from' : 'to';
throw new ApplicationException('Report period is invalid: ' . $invalidPeriod);
}
$period = $this->calculateFromAndToDatePeriod($frequency);
$from = $period['fromDate'];
$to = $period['toDate'];
}
return $this->formatReportPeriodName($frequency, $from, $to);
}
private function formatReportPeriodName(string $frequency, Carbon $from, Carbon $to): string
{
$fromYear = $from->format('Y');
$toYear = $to->format('Y');
$differentYears = $fromYear !== $toYear;
switch ($frequency) {
case self::FREQUENCY_DAILY:
return $from->format('j M Y');
case self::FREQUENCY_QUARTERLY:
// 'Jan-Mar 2025' or 'Nov 2024-Jan 2025' if years differ
$startMonth = $from->format('M');
$endMonth = $to->copy()->subMonth();
$endMonthName = $endMonth->format('M');
$endMonthYear = $endMonth->format('Y');
if ($differentYears) {
return "{$startMonth} {$fromYear} - {$endMonthName} {$endMonthYear}";
}
return "{$startMonth} - {$endMonthName} {$toYear}";
case self::FREQUENCY_MONTHLY:
// 'May 2025' - monthly reports are always within the same year
return $from->format('M Y');
case self::FREQUENCY_WEEKLY:
// '4 - 8 Aug 2025', '27 Oct - 3 Nov 2025', or '28 Dec 2024 - 3 Jan 2025' if years differ
$startDay = $from->format('j');
$endDay = $to->format('j');
$startMonth = $from->format('M');
$endMonth = $to->format('M');
if ($differentYears) {
return "{$startDay} {$startMonth} {$fromYear} - {$endDay} {$endMonth} {$toYear}";
}
if ($startMonth !== $endMonth) {
return "{$startDay} {$startMonth} - {$endDay} {$endMonth} {$toYear}";
}
return "{$startDay} - {$endDay} {$endMonth} {$toYear}";
case self::FREQUENCY_ONE_OFF:
// '2 May-31 May 2025' or '15 Dec 2024-15 Jan 2025' if years differ
$startDay = $from->format('j');
$startMonth = $from->format('M');
$endDay = $to->format('j');
$endMonth = $to->format('M');
// If same month and year, use a format like '2-31 May 2025'
if ($startMonth === $endMonth && ! $differentYears) {
return "{$startDay} - {$endDay} {$startMonth} {$toYear}";
}
// If different years, include both years
if ($differentYears) {
return "{$startDay} {$startMonth} {$fromYear} - {$endDay} {$endMonth} {$toYear}";
}
// Same year but different months
return "{$startDay} {$startMonth} - {$endDay} {$endMonth} {$toYear}";
default:
// Default format for unknown frequencies
return $from->format('j M Y') . ' - ' . $to->format('j M Y');
}
}
public function getReportTeamsName(AutomatedReportResult $report): string
{
$groups = $report->getGroups();
if (empty($groups)) {
return 'All';
}
// Get group names from repository
$groupNames = [];
foreach ($groups as $groupId) {
$group = $this->groupRepository->find($groupId);
if ($group) {
$groupNames[] = $group->getName();
}
}
if (count($groupNames) === 1) {
// Single team format
$teamsName = $groupNames[0];
} else {
// Multiple teams format
$teamsName = implode(', ', $groupNames);
}
return $teamsName;
}
public function getReportFileName(AutomatedReportResult $report): string
...
|
12308
|
|
12313
|
260
|
34
|
2026-04-14T11:02:59.573756+00:00
|
/Users/lukas/.screenpipe/data/data/2026-04-14/1776 /Users/lukas/.screenpipe/data/data/2026-04-14/1776164579573_m1.jpg...
|
PhpStorm
|
faVsco.js – AutomatedReportsService.php
|
1
|
NULL
|
monitor_1
|
NULL
|
NULL
|
NULL
|
NULL
|
Project: faVsco.js, menu
#11894 on JY-18909-automa Project: faVsco.js, menu
#11894 on JY-18909-automated-reports-ask-jiminny, menu
Start Listening for PHP Debug Connections
AutomatedReportsCommandTest
Run 'AutomatedReportsCommandTest'
Debug 'AutomatedReportsCommandTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Execute
Explain Plan
Browse Query History
View Parameters
Open Query Execution Settings…
In-Editor Results
Tx: Auto
Cancel Running Statements
Playground
jiminny
Sync Changes
Hide This Notification
Code changed:
Hide
16
13
13
Previous Highlighted Error
Next Highlighted Error
SELECT * FROM teams WHERE id = 1;
select * from crm_layouts where crm_configuration_id = 39;
SELECT * FROM crm_layout_entities WHERE crm_layout_id = 283;
SELECT * FROM crm_fields WHERE id = 2234;
SELECT * FROM crm_field_values WHERE crm_field_id = 2234;
select * from crm_profiles where user_id = 143;
select * from record_types where crm_configuration_id = 39; # 0121K000001MHElQAO,0121K000001MHEqQAO
select * from business_processes where crm_configuration_id = 39;
# 01941000000H669AAC, 01941000000H66JAAS
select * from record_type_field_values
where record_type_id IN (24);
select * from crm_field_values where id IN (2730);
select * from crm_configurations where id = 39;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 1
and sa.provider = 'salesforce'; #1035
select * from users where team_id = 1; # 222 group 3
SELECT * FROM activities WHERE user_id = 222 order by id desc;
select * from sidekick_settings where team_id = 1;
select * from teams where id = 1;
select * from team_features where team_id = 1;
select * from activities where crm_configuration_id = 2
and provider = 'ms-teams' and id = 608765;
SELECT * FROM activities WHERE crm_configuration_id = 2 and crm_provider_id = '59523413338';
select * from sidekick_settings where team_id = 2;
SELECT * FROM activities WHERE id = 608660;
select * from activity_summary_logs where activity_id = 608660;
select * from ai_prompts where transcription_id = 11214;
# [PASSWORD_DOTS]
SELECT * FROM activities WHERE uuid_to_bin('ed78a437-2804-450e-ab2f-56ab1c641346') = uuid;
# id: 608818, crm: 59628809737
SELECT * FROM activities WHERE uuid_to_bin('36b06e55-afdd-4782-8dee-c624cd0af191') = uuid;
# id: 608821, crm: 59632069252
SELECT ce.start_time, ce.end_time, a.id, a.uuid, crm_provider_id, calendar_event_id, title,
playbook_category_id, user_id, lead_id, contact_id, account_id, opportunity_id,
scheduled_start_time, scheduled_end_time, actual_start_time, actual_end_time, a.created_at
FROM activities a
join calendar_events ce on a.calendar_event_id = ce.id
WHERE a.id IN (608818, 608821);
select * from users where team_id = 1;
select * from team_settings where team_id = 1;
select * from crm_profiles where crm_configuration_id = 39 order by user_id;
select * from team_features where team_id = 1;
select * from users where team_id = 2;
SELECT * FROM activities WHERE uuid_to_bin('ec7647e9-5225-458b-b475-f31aa2769204') = uuid; # 612639
# Preslava N. Ivanova, grou id 3
SELECT * FROM opportunities WHERE uuid_to_bin('a2928fe5-aec5-46cb-85d9-7654c89e46a6') = uuid;
select * from activities where opportunity_id = 344 and actual_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00';
select
a.id,
a.type,
a.scheduled_start_time,
a.actual_start_time,
a.created_at,
a.opportunity_id,
a.status
FROM activities a
WHERE opportunity_id = 344
and status IN ('completed', 'received', 'delivered')
and (
(a.actual_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00')
OR (a.created_at between '2024-10-11 00:00:00' and '2024-10-12 00:00:00')
OR (a.scheduled_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00'))
;
SELECT * FROM users WHERE id = 222;
SELECT * FROM crm_profiles WHERE user_id = 222;
select * from crm_layouts where crm_configuration_id = 39;
SELECT * FROM crm_layout_entities WHERE crm_layout_id = 281;
select * from group_deal_risk_types;
select * from opportunities where team_id = 1;
SELECT * FROM opportunities WHERE id = 315;
SELECT * FROM crm_field_data WHERE object_id = 315;
select * from crm_field_data where object_id = 260;
select * from generic_ai_prompts where subject_id = 315;
select * from teams; # 36, 21, 121, [EMAIL]
SELECT * FROM social_accounts WHERE sociable_id = 121 and provider = 'bullhorn';
# [PASSWORD_DOTS]
select * from teams where id = 1;
select * from crm_configurations where id = 39;
select * from users where team_id = 1;
select u.email, cp.* from users u
join crm_profiles cp on u.id = cp.user_id
where u.team_id = 1;
# 1 - 00541000004281rAAA
# 204 - 0052g000003freeAAA
# 429 - 0052g000003qGOiAAM
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 1
and sa.provider = 'salesforce';
select * from activities where type = 'softphone'
and created_at > '2024-12-11 15:24:36' order by id desc;
select * from activity_providers where team_id = 1;
select * from activity_provider_users where activity_provider_id = 328;
select * from opportunities where crm_configuration_id = 39
AND account_id = 178 AND is_closed = false
order by created_at DESC;
select * from contacts where id = 3952;
select * from accounts where id = 178;
# [PASSWORD_DOTS]
select * from teams where id = 36;
select * from crm_configurations where id = 21;
select * from users where team_id = 36;
select u.email, cp.* from users u
join crm_profiles cp on u.id = cp.user_id
where u.team_id = 36;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 36
and sa.provider = 'bullhorn';
select * from social_accounts where id = 348;
UPDATE social_accounts SET
provider_user_token = '21442_6802599_91:41179a58-21e7-4d7c-ad58-56bb666b2f65',
provider_refresh_token = '21442_6802599_91:01c6b335-3f2a-42e4-85ff-8a08fa65fceb',
expires = 1733998131,
state = 'connected'
WHERE id = 348;
# [PASSWORD_DOTS]
select * from teams where id = 31;
select * from crm_configurations where id = 18;
select * from users where team_id = 31; # 257
select u.email, cp.* from users u
join crm_profiles cp on u.id = cp.user_id
where u.team_id = 31;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 31
and sa.provider = 'close';
select * from contacts where crm_configuration_id = 18;
# [PASSWORD_DOTS] NEPTUNE [PASSWORD_DOTS]
select * from teams;
select * from users where id IN (1030, 1035, 1052);
select * from crm_configurations;
select * from users where team_id = 65; # 257
select * from team_settings where team_id = 65; # 257
select * from invitations where team_id = 65; # 257
select * from users where email = '[EMAIL]'; # 257
select u.email, cp.* from users u
join crm_profiles cp on u.id = cp.user_id
where u.team_id = 65;
select * from crm_configurations where id = 53;
select * from accounts where crm_configuration_id = 53 order by id desc;
select * from leads where crm_configuration_id = 53 order by id desc;
select * from contacts where crm_configuration_id = 53 order by id desc;
select * from opportunities where crm_configuration_id = 53 order by id desc;
select * from crm_profiles where crm_configuration_id = 53 order by id desc;
select * from crm_fields where crm_configuration_id = 53 order by id desc;
select * from crm_field_values where crm_field_id = 3341 order by id desc;
select * from crm_layouts where crm_configuration_id = 53 order by id desc;
select * from stages where crm_configuration_id = 53 order by id desc;
select * from crm_profiles where crm_configuration_id = 13;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 65
and sa.provider = 'integration-app';
select * from contacts where crm_configuration_id = 13;
select * from social_accounts where sociable_id = 283;
SELECT * FROM opportunities WHERE crm_provider_id = '006O400000E9bzeIAB';
select * from activity_providers where team_id = 65;
SELECT * FROM activities WHERE crm_configuration_id IN (51, 52, 53);
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 65
;
# [PASSWORD_DOTS] STAGING [PASSWORD_DOTS]
SELECT * FROM teams;
SELECT * FROM teams WHERE id = 88;
SELECT * FROM teams WHERE id = 89;
select * from team_settings where team_id = 89;
SELECT * FROM users WHERE team_id = 89;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 89;
select * from users;
SELECT * FROM social_accounts WHERE sociable_id = 1761;
SELECT * FROM crm_configurations WHERE id = 70;
select * from accounts where crm_configuration_id = 70 order by id desc;
select * from leads where crm_configuration_id = 70 order by id desc;
select * from contacts where crm_configuration_id = 70 order by id desc;
select * from opportunities where crm_configuration_id = 70 order by id desc;
select * from crm_profiles where crm_configuration_id = 70 order by id desc;
select * from crm_fields where crm_configuration_id = 70 order by id desc;
select * from crm_field_values where crm_field_id = 3536 order by id desc;
select * from crm_layouts where crm_configuration_id = 70 order by id desc;
select * from stages where crm_configuration_id = 70 order by id desc;
select * from business_processes where crm_configuration_id = 70 order by id desc;
select * from business_process_stages where business_process_id = 34;
select * from contacts where id = 10468;
select * from crm_layouts where crm_configuration_id = 70;
SELECT * FROM crm_layout_entities WHERE crm_layout_id = 388;
SELECT * FROM crm_fields WHERE id IN (3533,3534,3535);
select * from activities where crm_configuration_id = 70
and (account_id IS NOT NULL or lead_id IS NOT NULL or contact_id IS NOT NULL or opportunity_id IS NOT NULL) order by id desc;
SELECT * FROM activities WHERE uuid_to_bin('2e10b60f-8a61-41c5-a3d4-28835353dc65') = uuid;
SELECT * FROM activities where crm_configuration_id = 69 ;
SELECT * FROM users WHERE email LIKE '%[EMAIL]%';
SELECT * FROM activities WHERE uuid_to_bin('5a150c93-40fc-42ec-b3bd-c1d328e09f6e') = uuid;
SELECT * FROM opportunities WHERE id = 385;
select * from participants p
join activities a on p.activity_id = a.id
where a.crm_configuration_id = 70
and (p.lead_id IS NOT NULL or p.contact_id IS NOT NULL);
SELECT * FROM participants WHERE id = 1013638;
select * from teams where id = 90;
select * from users where team_id = 90;
select * from social_accounts where social_accounts.sociable_id IN (1960,1760);
SELECT * FROM crm_profiles WHERE crm_configuration_id = 71;
select * from invitations where team_id = 90;
select * from crm_configurations where id = 71;
select * from accounts where crm_configuration_id = 71 order by id desc;
select * from leads where crm_configuration_id = 71 order by id desc;
select * from contacts where crm_configuration_id = 71 order by id desc;
select * from opportunities where crm_configuration_id = 71 order by id desc;
select * from crm_profiles where crm_configuration_id = 71 order by id desc;
select * from crm_fields where crm_configuration_id = 71 order by id desc;
select * from crm_field_values where crm_field_id = 3341 order by id desc;
select * from crm_layouts where crm_configuration_id = 71 order by id desc;
select * from stages where crm_configuration_id = 71 order by id desc;
select * from users order by secondary_email desc;
select u.id, u.email, u.status, sa.id, sa.provider_user_id from social_accounts sa
join users u on sa.sociable_id = u.id
where sa.provider = 'google' and u.email LIKE 'aneliya%';
select * from failed_jobs order by id desc;
select * from users where email = '[EMAIL]' or secondary_email = '[EMAIL]';
select * from teams;
SELECT * FROM crm_profiles WHERE crm_configuration_id = 39;
SELECT * FROM crm_fields WHERE crm_configuration_id = 39 and object_type = 'task';
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 1
and sa.provider = 'salesforce';
# [PASSWORD_DOTS]
SELECT * FROM activities WHERE uuid_to_bin('c38b3895-fd0f-4b1f-9fb2-c170dba137c6') = uuid;
SELECT * FROM crm_configurations WHERE id = 70;
select * from teams where id = 1;
select * from groups where team_id = 1;
select * from users where team_id = 1;
select o.id, o.name,o.close_date, u.id, u.name, u.group_id, r.id, r.display_name, g.name, g.scope from opportunities o
join users u on o.user_id = u.id
join groups g on u.group_id = g.id
join role_user ru on u.id = ru.user_id
join roles r on ru.role_id = r.id
where o.crm_configuration_id = 39 and close_date > '2024-01-01 00:00:00';
select * from role_user where user_id = 143;
select * from roles;
select * from role_user;
select * from groups where id = 9;
select * from scope_groups where group_id = 9;
# [PASSWORD_DOTS]
select * from teams where id = 36;
select * from crm_configurations;
SELECT * FROM social_accounts WHERE sociable_id = 121;
[URL_WITH_CREDENTIALS] this will add filter, however if we need to control feature by FF we need conditional logic
public const array TYPES = [
['id' => 'exec_summary', 'name' => 'Exec Summary'],
['id' => 'coaching_profiles', 'name' => 'Coaching Profiles'],
['id' => 'product_feedback', 'name' => 'Product Feedback'],
['id' => self::TYPE_LOSS_ANALYSIS, 'name' => 'Loss Analysis'],
// ['id' => 'questions', 'name' => 'Questions'],
// ['id' => 'statistical_quant', 'name' => 'Statistical Quantitative'],
];
public const array ALL_TYPES = [
...self::TYPES,
['id' => self::TYPE_ASK_JIMINNY, 'name' => 'Ask Jiminny'],
];
public const string FREQUENCY_DAILY = 'daily';
public const string FREQUENCY_WEEKLY = 'weekly';
public const string FREQUENCY_MONTHLY = 'monthly';
public const string FREQUENCY_QUARTERLY = 'quarterly';
public const string FREQUENCY_ONE_OFF = 'one_off';
/**
* Frequencies for standard (non-Ask Jiminny) reports.
*/
public const array FREQUENCIES = [
['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],
['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],
['id' => self::FREQUENCY_QUARTERLY, 'name' => 'Quarterly'],
['id' => self::FREQUENCY_ONE_OFF, 'name' => 'One-off'],
];
/**
* Frequencies for Ask Jiminny reports.
*/
public const array ASK_JIMINNY_FREQUENCIES = [
['id' => self::FREQUENCY_DAILY, 'name' => 'Daily'],
['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],
['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],
];
public const string MEDIA_TYPE_PDF = 'pdf';
public const string MEDIA_TYPE_PODCAST = 'podcast';
public const array MEDIA_TYPES = [self::MEDIA_TYPE_PDF, self::MEDIA_TYPE_PODCAST];
public const array MEDIA_TYPE_OBJECT_PDF = ['id' => self::MEDIA_TYPE_PDF, 'name' => 'PDF'];
public const array MEDIA_TYPE_OBJECT_PODCAST = ['id' => self::MEDIA_TYPE_PODCAST, 'name' => 'Podcast'];
public const array MEDIA_TYPE_OBJECTS = [self::MEDIA_TYPE_OBJECT_PDF, self::MEDIA_TYPE_OBJECT_PODCAST];
public const array CALL_TYPE_CONFERENCE = ['id' => 'conference', 'name' => 'Conference'];
public const array CALL_TYPE_DIALER = ['id' => 'dialer', 'name' => 'Dialer'];
public const int SENT_REPORT_AT_HOURS = 5;
public const string PDF_KEY = 'pdf';
public const string AUDIO_KEY = 'audio';
private const array ALL_FREQUENCIES = [
['id' => self::FREQUENCY_DAILY, 'name' => 'Daily'],
['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],
['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],
['id' => self::FREQUENCY_QUARTERLY, 'name' => 'Quarterly'],
['id' => self::FREQUENCY_ONE_OFF, 'name' => 'One-off'],
];
private const string S3_DIR = 'reports';
private const array FILE_EXTENSIONS_VARIANTS = ['html', 'MD', 'pdf'];
private const array FILE_PODCAST_EXTENSIONS_VARIANTS = ['json', 'mp3', 'ssml'];
public function __construct(
private readonly TeamRepository $teamRepository,
private readonly GroupRepository $groupRepository,
private readonly UserRepository $userRepository,
private readonly StageRepository $stageRepository,
private readonly DealStagesService $dealStagesService,
private readonly RecipientsService $recipientsService,
private readonly AutomatedReportsRepository $automatedReportsRepository,
private readonly Webhook $webhookService,
private readonly BusDispatcher $dispatcher,
private readonly ActivityTypeService $activityTypeService,
private readonly PlaybookCategoryRepository $playbookCategoryRepository,
private readonly AskAnythingPromptService $askAnythingPromptService,
private readonly SearchRepository $activitySearchRepository,
private readonly AskAnythingRepository $askAnythingRepository,
) {
}
public static function getTypes(): array
{
$types = self::TYPES;
return array_map(static function ($type) {
return $type['id'];
}, $types);
}
public static function getCallTypes(): array
{
return array_map(static function ($callType) {
return $callType['id'];
}, [self::CALL_TYPE_CONFERENCE, self::CALL_TYPE_DIALER]);
}
public static function getFrequencies(): array
{
return array_map(static function ($frequency) {
return $frequency['id'];
}, self::FREQUENCIES);
}
// front-facing structure
public function getReportEnabledFieldData(bool $value = false): array
{
return [
'id' => 'report_enabled',
'label' => '',
'inputType' => InputTypeEnum::TOGGLE,
'value' => $value,
];
}
// Organizations = Teams
public function getOrganizationFieldData(?string $value = null, bool $shortVersion = false): array
{
$options = $this->getTeams();
if ($shortVersion) {
return [
'id' => 'organization',
'label' => 'Organization',
'options' => $options,
];
}
return [
'id' => 'organization',
'label' => 'Organization',
'inputType' => InputTypeEnum::DROPDOWN,
'required' => true,
'placeholder' => 'Select',
'options' => $options,
'value' => $value,
'dependencies' => [
'teams',
'deal_stage_at_call',
'current_deal_stage',
'recipients',
ActivityTypeService::PLAYBOOK_CATEGORIES_KEY,
],
'dependsOn' => [],
];
}
// Teams = Groups
public function getTeamFieldData(array $options = [], array $value = [], bool $shortVersion = false): array
{
if ($shortVersion) {
return [
'id' => 'teams',
'label' => 'Team',
'options' => $options,
];
}
return [
'id' => 'teams',
'label' => 'Team',
'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,
'required' => false,
'placeholder' => 'Select',
'options' => $options,
'value' => $value, // value should be an array of objects {id, name}
'dependencies' => [ActivityTypeService::PLAYBOOK_CATEGORIES_KEY],
'dependsOn' => [],
];
}
public function getReportTypeFieldData(?string $value = null, bool $shortVersion = false, ?Team $team = null): array
{
$types = [];
if ($team instanceof Team) {
if ($team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {
$types = self::TYPES;
}
if ($team->hasFeature(FeatureEnum::ASK_JIMINNY_REPORTS)) {
$types[] = ['id' => self::TYPE_ASK_JIMINNY, 'name' => 'Ask Jiminny'];
}
} else {
$types = self::TYPES;
}
if ($shortVersion) {
return [
'id' => 'report_type',
'label' => 'Report Type',
'options' => $types,
];
}
return [
'id' => 'report_type',
'label' => 'Report Type',
'inputType' => InputTypeEnum::DROPDOWN,
'required' => true,
'placeholder' => 'Select',
'options' => $types,
'value' => $value,
'dependencies' => [],
'dependsOn' => [],
];
}
public function getFrequencyFieldData(?string $value = null): array
{
return [
'id' => 'frequency',
'label' => 'Frequency',
'inputType' => InputTypeEnum::DROPDOWN,
'required' => true,
'placeholder' => 'Select',
'options' => self::FREQUENCIES,
'value' => $value,
'dependencies' => ['period'],
'dependsOn' => [],
];
}
public function getPeriodFieldData(?string $valueStartDate = null, ?string $valueEndDate = null): array
{
return [
'id' => 'period',
'label' => 'Select one-off period',
'inputType' => InputTypeEnum::DATE_RANGE,
'required' => true,
'placeholder' => 'Select',
'value' => ['startDate' => $valueStartDate, 'endDate' => $valueEndDate],
'queryParams' => [
'startDate' => 'start_date_period',
'endDate' => 'end_date_period',
],
'dependencies' => [],
'dependsOn' => ['frequency'],
];
}
public function getActivityTypesFieldData(?Team $team = null, array $value = [], array $teamsFilter = []): array
{
return $this->activityTypeService->getActivityTypeFieldData(team: $team, value: $value, groupIds: $teamsFilter);
}
public function getDealStageAtCallFieldData(?Team $team = null, array $value = []): array
{
return $this->dealStagesService->getDealStageAtCallFieldData(team: $team, value: $value);
}
public function getCurrentDealStageFieldData(?Team $team = null, array $value = []): array
{
return $this->dealStagesService->getCurrentDealStageFieldData(team: $team, value: $value);
}
public function getDealValueFieldData(?int $valueMin = null, ?int $valueMax = null): array
{
return [
'id' => 'deal_value',
'label' => 'Deal Value',
'inputType' => InputTypeEnum::INTEGER_RANGE,
'required' => false,
'value' => ['min' => $valueMin, 'max' => $valueMax],
'queryParams' => [
'min' => 'min_deal_value',
'max' => 'max_deal_value',
],
'dependencies' => [],
'dependsOn' => [],
];
}
public function getCallTypeFieldData(bool $conferenceOn = false, bool $dialerOn = false): array
{
$value = [];
$conferenceOn && $value[] = self::CALL_TYPE_CONFERENCE;
$dialerOn && $value[] = self::CALL_TYPE_DIALER;
return [
'id' => 'call_type',
'label' => 'Call Type',
'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,
'required' => true,
'options' => [
self::CALL_TYPE_CONFERENCE,
self::CALL_TYPE_DIALER,
],
'value' => $value,
'dependencies' => [],
'dependsOn' => [],
];
}
public function getMediaTypeFieldData(?AutomatedReport $report = null): array
{
$value = [];
if ($report) {
$value = $this->transformMediaTypes($report);
}
return [
'id' => 'media_types',
'label' => 'Export as',
'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,
'required' => true,
'options' => self::MEDIA_TYPE_OBJECTS,
'value' => $value,
'dependencies' => [],
'dependsOn' => [],
];
}
public function getCallDurationFieldData(?int $valueMin = null, ?int $valueMax = null): array
{
return [
'id' => 'call_duration',
'label' => 'Call Duration',
'inputType' => InputTypeEnum::INTEGER_RANGE,
'required' => false,
'value' => ['min' => $valueMin, 'max' => $valueMax],
'queryParams' => [
'min' => 'min_call_duration',
'max' => 'max_call_duration',
],
'dependencies' => [],
'dependsOn' => [],
];
}
public function getRecipientsFieldData(?Team $team = null, array $value = []): array
{
return $this->recipientsService->getRecipientsFieldData(team: $team, value: $value);
}
public function getJiminnyRecipientsFieldData(array $value = []): array
{
return $this->recipientsService->getJiminnyRecipientsFieldData($value);
}
public function getAdditionalPromptInputFieldData(?string $value = null): array
{
return [
'id' => 'additional_prompt_input',
'label' => 'Special requirements',
'inputType' => InputTypeEnum::TEXTAREA,
'required' => false,
'placeholder' => 'What should be the focus of the report?',
'value' => $value,
'dependencies' => [],
'dependsOn' => [],
];
}
public function getCustomReportNameFieldData(?string $value = null): array
{
return [
'id' => 'custom_name',
'label' => 'Custom report name',
'inputType' => InputTypeEnum::TEXT,
'required' => false,
'placeholder' => 'Enter custom name',
'value' => $value,
'dependencies' => [],
'dependsOn' => [],
];
}
// data providers
public function getTeams(): array
{
$teams = $this->teamRepository->getTeamsForKiosk(status: Team::STATUS_ACTIVE);
$teamData = [];
foreach ($teams as $team) {
if (! $team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {
continue;
}
$teamData[] = $this->transformTeam($team);
}
return $teamData;
}
public function getTeamGroups(string $teamUuid): array
{
$data = [];
$team = $this->getTeam($teamUuid);
if ($team !== null) {
$groups = $team->groups()->get();
foreach ($groups as $group) {
$data[] = [
'id' => $group->getUuid(),
'name' => $group->getName(),
];
}
}
return $data;
}
public function getTeamsGroupsOptions(array $filterTeamUuids = []): array
{
$data = [];
$teams = $this->getTeams();
foreach ($teams as $team) {
if (! empty($filterTeamUuids) && ! in_array($team['id'], $filterTeamUuids, true)) {
continue;
}
$data[] = [
'label' => $team['name'],
'groups' => $this->getTeamGroups($team['id']),
];
}
return $data;
}
public function getTeam(string $teamUuid): ?Team
{
return $this->teamRepository->idOrUuid($teamUuid);
}
public function getTeamById(int $teamId): ?Team
{
return $this->teamRepository->find($teamId);
}
public function getGroupsUuids(AutomatedReport $report): array
{
$uuids = [];
$reportGroups = $report->getGroups();
foreach ($reportGroups as $groupId) {
if ($group = $this->groupRepository->find($groupId)) {
$uuids[] = $group->getUuid();
}
}
return $uuids;
}
public function getPlaybookCategoriesUuids(AutomatedReport $report): array
{
$uuids = [];
$playbookCategories = $report->getPlaybookCategories();
foreach ($playbookCategories as $id) {
if ($category = $this->playbookCategoryRepository->find($id)) {
$uuids[] = $category->getUuid();
}
}
return $uuids;
}
public function getDealAtCallStagesUuids(AutomatedReport $report): array
{
$uuids = [];
$reportStages = $report->getDealAtCallStages();
foreach ($reportStages as $id) {
if ($stage = $this->stageRepository->find($id)) {
$uuids[] = $stage->getUuid();
}
}
return $uuids;
}
public function getCurrentDealStagesUuids(AutomatedReport $report): array
{
$uuids = [];
$reportStages = $report->getCurrentDealStages();
foreach ($reportStages as $id) {
if ($stage = $this->stageRepository->find($id)) {
$uuids[] = $stage->getUuid();
}
}
return $uuids;
}
public function getUsersUuids(AutomatedReport $report): array
{
return $this->extractUserUuids($report->getRecipients());
}
public function getJiminnyUsersUuids(AutomatedReport $report): array
{
return $this->extractUserUuids($report->getJiminnyRecipients());
}
/**
* @param array<string, mixed> $recipients
*/
private function extractUserUuids(array $recipients): array
{
$userIds = $recipients['users'] ?? [];
return collect($userIds)
->map(fn ($id) => $this->userRepository->find((int) $id))
->filter()
->map(fn (UserContract $user) => $user->getUuid())
->values()
->all();
}
// get mail data
public function getRecipientUsers(AutomatedReport $report): array
{
return $this->buildRecipientUsers($report->getRecipients());
}
private function getJiminnyRecipientUsers(AutomatedReport $report): array
{
return $this->buildRecipientUsers($report->getJiminnyRecipients());
}
/**
* @param array<string, mixed> $recipients
*/
private function buildRecipientUsers(array $recipients): array
{
$userIds = $recipients['users'] ?? [];
return collect($userIds)
->map(fn ($id) => $this->userRepository->find((int) $id))
->filter()
->map(fn (UserContract $user) => [
'email' => $user->getEmailAddress(),
'name' => $user->getName(),
'timezone' => $user->getTimezone()->getName(),
])
->values()
->all();
}
public function getValidRecipientUsers(AutomatedReport $report, bool $includeJiminny = false): array
{
if ($report->isAskJiminnyReport()) {
$recipients = $this->resolveAskJiminnyRecipients($report);
} else {
$recipients = $this->getRecipientUsers($report);
if ($includeJiminny) {
$recipients = array_merge($recipients, $this->getJiminnyRecipientUsers($report));
}
}
$emails = [];
return array_values(array_filter(
$recipients,
static function ($recipient) use (&$emails) {
if (empty($recipient['email']) || in_array($recipient['email'], $emails, true)) {
return false;
}
$emails[] = $recipient['email'];
return true;
}
));
}
private function resolveAskJiminnyRecipients(AutomatedReport $report): array
{
$recipients = [];
$creator = $report->getCreator();
if ($creator !== null) {
$recipients[] = [
'email' => $creator->getEmailAddress(),
'name' => $creator->getName(),
'timezone' => $creator->getTimezone()->getName(),
];
}
return array_merge(
$recipients,
$this->buildRecipientUsers($report->getRecipients()),
$this->getGroupRecipientUsers($report),
);
}
private function getGroupRecipientUsers(AutomatedReport $report): array
{
$users = [];
foreach ($report->getGroups() as $groupId) {
$group = $this->groupRepository->find($groupId);
if ($group === null) {
continue;
}
foreach ($group->getMembers() as $member) {
$users[] = [
'email' => $member->getEmailAddress(),
'name' => $member->getName(),
'timezone' => $member->getTimezone()->getName(),
];
}
}
return $users;
}
public function getReportTypeName(AutomatedReportResult $report): string
{
$type = $report->getReport()->getType();
$getType = $this->transformReportType($type);
return $getType['name'];
}
public function getReportPeriodName(AutomatedReportResult $report): string
{
$from = $report->getFromDate();
$to = $report->getToDate();
$frequency = $report->getReport()->getFrequency();
if ($from === null || $to === null) {
if (! $report->getReport()->isAskJiminnyReport()) {
$invalidPeriod = $from === null ? 'from' : 'to';
throw new ApplicationException('Report period is invalid: ' . $invalidPeriod);
}
$period = $this->calculateFromAndToDatePeriod($frequency);
$from = $period['fromDate'];
$to = $period['toDate'];
}
return $this->formatReportPeriodName($frequency, $from, $to);
}
private function formatReportPeriodName(string $frequency, Carbon $from, Carbon $to): string
{
$fromYear = $from->format('Y');
$toYear = $to->format('Y');
$differentYears = $fromYear !== $toYear;
switch ($frequency) {
case self::FREQUENCY_DAILY:
return $from->format('j M Y');
case self::FREQUENCY_QUARTERLY:
// 'Jan-Mar 2025' or 'Nov 2024-Jan 2025' if years differ
$startMonth = $from->format('M');
$endMonth = $to->copy()->subMonth();
$endMonthName = $endMonth->format('M');
$endMonthYear = $endMonth->format('Y');
if ($differentYears) {
return "{$startMonth} {$fromYear} - {$endMonthName} {$endMonthYear}";
}
return "{$startMonth} - {$endMonthName} {$toYear}";
case self::FREQUENCY_MONTHLY:
// 'May 2025' - monthly reports are always within the same year
return $from->format('M Y');
case self::FREQUENCY_WEEKLY:
// '4 - 8 Aug 2025', '27 Oct - 3 Nov 2025', or '28 Dec 2024 - 3 Jan 2025' if years differ
$startDay = $from->format('j');
$endDay = $to->format('j');
$startMonth = $from->format('M');
$endMonth = $to->format('M');
if ($differentYears) {
return "{$startDay} {$startMonth} {$fromYear} - {$endDay} {$endMonth} {$toYear}";
}
if ($startMonth !== $endMonth) {
return "{$startDay} {$startMonth} - {$endDay} {$endMonth} {$toYear}";
}
return "{$startDay} - {$endDay} {$endMonth} {$toYear}";
case self::FREQUENCY_ONE_OFF:
// '2 May-31 May 2025' or '15 Dec 2024-15 Jan 2025' if years differ
$startDay = $from->format('j');
$startMonth = $from->format('M');
$endDay = $to->format('j');
$endMonth = $to->format('M');
// If same month and year, use a format like '2-31 May 2025'
if ($startMonth === $endMonth && ! $differentYears) {
return "{$startDay} - {$endDay} {$startMonth} {$toYear}";
}
// If different years, include both years
if ($differentYears) {
return "{$startDay} {$startMonth} {$fromYear} - {$endDay} {$endMonth} {$toYear}";
}
// Same year but different months
return "{$startDay} {$startMonth} - {$endDay} {$endMonth} {$toYear}";
default:
// Default format for unknown frequencies
return $from->format('j M Y') . ' - ' . $to->format('j M Y');
}
}
public function getReportTeamsName(AutomatedReportResult $report): string
{
$groups = $report->getGroups();
if (empty($groups)) {
return 'All';
}
// Get group names from repository
$groupNames = [];
foreach ($groups as $groupId) {
$group = $this->groupRepository->find($groupId);
if ($group) {
$groupNames[] = $group->getName();
}
}
if (count($groupNames) === 1) {
// Single team format
$teamsName = $groupNames[0];
} else {
// Multiple teams format
$teamsName = implode(', ', $groupNames);
}
return $teamsName;
}
public function getReportFileName(AutomatedReportResult $report): string
...
|
[{"role":"AXButton","text" [{"role":"AXButton","text":"Project: faVsco.js, menu","depth":5,"help_text":"~/jiminny/app","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"#11894 on JY-18909-automated-reports-ask-jiminny, menu","depth":5,"help_text":"Pull request #11894 exists for current branch JY-18909-automated-reports-ask-jiminny","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Start Listening for PHP Debug Connections","depth":5,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"AutomatedReportsCommandTest","depth":6,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Run 'AutomatedReportsCommandTest'","depth":6,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Debug 'AutomatedReportsCommandTest'","depth":6,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"More Actions","depth":6,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JetBrains AI","depth":5,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Search Everywhere","depth":5,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"IDE and Project Settings","depth":5,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Execute","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Explain Plan","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Browse Query History","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"View Parameters","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Open Query Execution Settings…","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"In-Editor Results","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Tx: Auto","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Cancel Running Statements","depth":4,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Playground","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"jiminny","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.088194445,"height":0.027777778},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"16","depth":4,"role_description":"text"},{"role":"AXStaticText","text":"13","depth":4,"role_description":"text"},{"role":"AXStaticText","text":"13","depth":4,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"SELECT * FROM teams WHERE id = 1;\n\nselect * from crm_layouts where crm_configuration_id = 39;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 283;\nSELECT * FROM crm_fields WHERE id = 2234;\nSELECT * FROM crm_field_values WHERE crm_field_id = 2234;\n\nselect * from crm_profiles where user_id = 143;\n\nselect * from record_types where crm_configuration_id = 39; # 0121K000001MHElQAO,0121K000001MHEqQAO\nselect * from business_processes where crm_configuration_id = 39;\n# 01941000000H669AAC, 01941000000H66JAAS\n\nselect * from record_type_field_values\n where record_type_id IN (24);\n\nselect * from crm_field_values where id IN (2730);\n\nselect * from crm_configurations where id = 39;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 1\nand sa.provider = 'salesforce'; #1035\n\n\nselect * from users where team_id = 1; # 222 group 3\nSELECT * FROM activities WHERE user_id = 222 order by id desc;\nselect * from sidekick_settings where team_id = 1;\nselect * from teams where id = 1;\nselect * from team_features where team_id = 1;\n\nselect * from activities where crm_configuration_id = 2\nand provider = 'ms-teams' and id = 608765;\n\nSELECT * FROM activities WHERE crm_configuration_id = 2 and crm_provider_id = '59523413338';\n\nselect * from sidekick_settings where team_id = 2;\n\nSELECT * FROM activities WHERE id = 608660;\nselect * from activity_summary_logs where activity_id = 608660;\nselect * from ai_prompts where transcription_id = 11214;\n\n# ********************************************************************************************************\nSELECT * FROM activities WHERE uuid_to_bin('ed78a437-2804-450e-ab2f-56ab1c641346') = uuid;\n# id: 608818, crm: 59628809737\nSELECT * FROM activities WHERE uuid_to_bin('36b06e55-afdd-4782-8dee-c624cd0af191') = uuid;\n# id: 608821, crm: 59632069252\nSELECT ce.start_time, ce.end_time, a.id, a.uuid, crm_provider_id, calendar_event_id, title,\nplaybook_category_id, user_id, lead_id, contact_id, account_id, opportunity_id,\nscheduled_start_time, scheduled_end_time, actual_start_time, actual_end_time, a.created_at\nFROM activities a\njoin calendar_events ce on a.calendar_event_id = ce.id\nWHERE a.id IN (608818, 608821);\n\nselect * from users where team_id = 1;\nselect * from team_settings where team_id = 1;\nselect * from crm_profiles where crm_configuration_id = 39 order by user_id;\n\nselect * from team_features where team_id = 1;\n\nselect * from users where team_id = 2;\n\nSELECT * FROM activities WHERE uuid_to_bin('ec7647e9-5225-458b-b475-f31aa2769204') = uuid; # 612639\n# Preslava N. Ivanova, grou id 3\n\nSELECT * FROM opportunities WHERE uuid_to_bin('a2928fe5-aec5-46cb-85d9-7654c89e46a6') = uuid;\n\nselect * from activities where opportunity_id = 344 and actual_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00';\n\nselect\n a.id,\n a.type,\n a.scheduled_start_time,\n a.actual_start_time,\n a.created_at,\n a.opportunity_id,\n a.status\nFROM activities a\nWHERE opportunity_id = 344\nand status IN ('completed', 'received', 'delivered')\nand (\n (a.actual_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00')\nOR (a.created_at between '2024-10-11 00:00:00' and '2024-10-12 00:00:00')\nOR (a.scheduled_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00'))\n;\n\nSELECT * FROM users WHERE id = 222;\n\nSELECT * FROM crm_profiles WHERE user_id = 222;\nselect * from crm_layouts where crm_configuration_id = 39;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 281;\n\nselect * from group_deal_risk_types;\n\nselect * from opportunities where team_id = 1;\n\nSELECT * FROM opportunities WHERE id = 315;\nSELECT * FROM crm_field_data WHERE object_id = 315;\nselect * from crm_field_data where object_id = 260;\n\nselect * from generic_ai_prompts where subject_id = 315;\n\nselect * from teams; # 36, 21, 121, james.graham@bullhorn.jiminny.com\nSELECT * FROM social_accounts WHERE sociable_id = 121 and provider = 'bullhorn';\n\n# ************************************************************************************\nselect * from teams where id = 1;\nselect * from crm_configurations where id = 39;\nselect * from users where team_id = 1;\nselect u.email, cp.* from users u\njoin crm_profiles cp on u.id = cp.user_id\nwhere u.team_id = 1;\n# 1 - 00541000004281rAAA\n# 204 - 0052g000003freeAAA\n# 429 - 0052g000003qGOiAAM\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 1\nand sa.provider = 'salesforce';\n\nselect * from activities where type = 'softphone'\nand created_at > '2024-12-11 15:24:36' order by id desc;\n\nselect * from activity_providers where team_id = 1;\nselect * from activity_provider_users where activity_provider_id = 328;\n\nselect * from opportunities where crm_configuration_id = 39\nAND account_id = 178 AND is_closed = false\norder by created_at DESC;\n\nselect * from contacts where id = 3952;\nselect * from accounts where id = 178;\n\n# ************************************************************************************\nselect * from teams where id = 36;\nselect * from crm_configurations where id = 21;\nselect * from users where team_id = 36;\nselect u.email, cp.* from users u\njoin crm_profiles cp on u.id = cp.user_id\nwhere u.team_id = 36;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 36\nand sa.provider = 'bullhorn';\n\nselect * from social_accounts where id = 348;\nUPDATE social_accounts SET\nprovider_user_token = '21442_6802599_91:41179a58-21e7-4d7c-ad58-56bb666b2f65',\nprovider_refresh_token = '21442_6802599_91:01c6b335-3f2a-42e4-85ff-8a08fa65fceb',\nexpires = 1733998131,\nstate = 'connected'\nWHERE id = 348;\n\n# ************************************************************************************\nselect * from teams where id = 31;\nselect * from crm_configurations where id = 18;\n\nselect * from users where team_id = 31; # 257\nselect u.email, cp.* from users u\njoin crm_profiles cp on u.id = cp.user_id\nwhere u.team_id = 31;\n\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 31\nand sa.provider = 'close';\n\nselect * from contacts where crm_configuration_id = 18;\n\n# ********************** NEPTUNE **************************************************************\nselect * from teams;\nselect * from users where id IN (1030, 1035, 1052);\nselect * from crm_configurations;\n\nselect * from users where team_id = 65; # 257\nselect * from team_settings where team_id = 65; # 257\nselect * from invitations where team_id = 65; # 257\nselect * from users where email = 'integration-account@jiminny.com'; # 257\nselect u.email, cp.* from users u\njoin crm_profiles cp on u.id = cp.user_id\nwhere u.team_id = 65;\n\nselect * from crm_configurations where id = 53;\nselect * from accounts where crm_configuration_id = 53 order by id desc;\nselect * from leads where crm_configuration_id = 53 order by id desc;\nselect * from contacts where crm_configuration_id = 53 order by id desc;\nselect * from opportunities where crm_configuration_id = 53 order by id desc;\nselect * from crm_profiles where crm_configuration_id = 53 order by id desc;\nselect * from crm_fields where crm_configuration_id = 53 order by id desc;\nselect * from crm_field_values where crm_field_id = 3341 order by id desc;\nselect * from crm_layouts where crm_configuration_id = 53 order by id desc;\nselect * from stages where crm_configuration_id = 53 order by id desc;\n\n\nselect * from crm_profiles where crm_configuration_id = 13;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 65\nand sa.provider = 'integration-app';\n\nselect * from contacts where crm_configuration_id = 13;\n\nselect * from social_accounts where sociable_id = 283;\n\nSELECT * FROM opportunities WHERE crm_provider_id = '006O400000E9bzeIAB';\n\nselect * from activity_providers where team_id = 65;\nSELECT * FROM activities WHERE crm_configuration_id IN (51, 52, 53);\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 65\n;\n\n# ***************************** STAGING ********************************************\nSELECT * FROM teams;\nSELECT * FROM teams WHERE id = 88;\nSELECT * FROM teams WHERE id = 89;\nselect * from team_settings where team_id = 89;\nSELECT * FROM users WHERE team_id = 89;\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 89;\n\nselect * from users;\nSELECT * FROM social_accounts WHERE sociable_id = 1761;\nSELECT * FROM crm_configurations WHERE id = 70;\nselect * from accounts where crm_configuration_id = 70 order by id desc;\nselect * from leads where crm_configuration_id = 70 order by id desc;\nselect * from contacts where crm_configuration_id = 70 order by id desc;\nselect * from opportunities where crm_configuration_id = 70 order by id desc;\nselect * from crm_profiles where crm_configuration_id = 70 order by id desc;\nselect * from crm_fields where crm_configuration_id = 70 order by id desc;\nselect * from crm_field_values where crm_field_id = 3536 order by id desc;\nselect * from crm_layouts where crm_configuration_id = 70 order by id desc;\nselect * from stages where crm_configuration_id = 70 order by id desc;\nselect * from business_processes where crm_configuration_id = 70 order by id desc;\nselect * from business_process_stages where business_process_id = 34;\n\nselect * from contacts where id = 10468;\n\nselect * from crm_layouts where crm_configuration_id = 70;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 388;\nSELECT * FROM crm_fields WHERE id IN (3533,3534,3535);\n\nselect * from activities where crm_configuration_id = 70\nand (account_id IS NOT NULL or lead_id IS NOT NULL or contact_id IS NOT NULL or opportunity_id IS NOT NULL) order by id desc;\n\nSELECT * FROM activities WHERE uuid_to_bin('2e10b60f-8a61-41c5-a3d4-28835353dc65') = uuid;\nSELECT * FROM activities where crm_configuration_id = 69 ;\n\nSELECT * FROM users WHERE email LIKE '%jiminny_web_sa2@jiminny.com%';\nSELECT * FROM activities WHERE uuid_to_bin('5a150c93-40fc-42ec-b3bd-c1d328e09f6e') = uuid;\nSELECT * FROM opportunities WHERE id = 385;\n\nselect * from participants p\njoin activities a on p.activity_id = a.id\nwhere a.crm_configuration_id = 70\nand (p.lead_id IS NOT NULL or p.contact_id IS NOT NULL);\nSELECT * FROM participants WHERE id = 1013638;\n\nselect * from teams where id = 90;\nselect * from users where team_id = 90;\nselect * from social_accounts where social_accounts.sociable_id IN (1960,1760);\nSELECT * FROM crm_profiles WHERE crm_configuration_id = 71;\nselect * from invitations where team_id = 90;\n\nselect * from crm_configurations where id = 71;\nselect * from accounts where crm_configuration_id = 71 order by id desc;\nselect * from leads where crm_configuration_id = 71 order by id desc;\nselect * from contacts where crm_configuration_id = 71 order by id desc;\nselect * from opportunities where crm_configuration_id = 71 order by id desc;\nselect * from crm_profiles where crm_configuration_id = 71 order by id desc;\nselect * from crm_fields where crm_configuration_id = 71 order by id desc;\nselect * from crm_field_values where crm_field_id = 3341 order by id desc;\nselect * from crm_layouts where crm_configuration_id = 71 order by id desc;\nselect * from stages where crm_configuration_id = 71 order by id desc;\n\nselect * from users order by secondary_email desc;\nselect u.id, u.email, u.status, sa.id, sa.provider_user_id from social_accounts sa\n join users u on sa.sociable_id = u.id\nwhere sa.provider = 'google' and u.email LIKE 'aneliya%';\n\nselect * from failed_jobs order by id desc;\n\nselect * from users where email = 'ben.allwright@learningpeople.co.uk' or secondary_email = 'ben.allwright@learningpeople.co.uk';\n\nselect * from teams;\nSELECT * FROM crm_profiles WHERE crm_configuration_id = 39;\nSELECT * FROM crm_fields WHERE crm_configuration_id = 39 and object_type = 'task';\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 1\nand sa.provider = 'salesforce';\n\n# ************************************************************************************\nSELECT * FROM activities WHERE uuid_to_bin('c38b3895-fd0f-4b1f-9fb2-c170dba137c6') = uuid;\nSELECT * FROM crm_configurations WHERE id = 70;\n\nselect * from teams where id = 1;\nselect * from groups where team_id = 1;\nselect * from users where team_id = 1;\n\nselect o.id, o.name,o.close_date, u.id, u.name, u.group_id, r.id, r.display_name, g.name, g.scope from opportunities o\njoin users u on o.user_id = u.id\njoin groups g on u.group_id = g.id\njoin role_user ru on u.id = ru.user_id\njoin roles r on ru.role_id = r.id\nwhere o.crm_configuration_id = 39 and close_date > '2024-01-01 00:00:00';\n\nselect * from role_user where user_id = 143;\nselect * from roles;\n\nselect * from role_user;\nselect * from groups where id = 9;\nselect * from scope_groups where group_id = 9;\n\n# ************************************************************************************\nselect * from teams where id = 36;\nselect * from crm_configurations;\nSELECT * FROM social_accounts WHERE sociable_id = 121;\n\nhttps://crmsandbox.zoho.com/crm/jiminnyw4/tab/Leads/4776201000005049105\nhttps://crmsandbox.zoho.com/crm/\n\nhttps://crm.zoho.com/crm/org3469620/tab/Leads/230045000229559080\n https://crm.zoho.com/crm/\n org3469620\n\nSELECT * FROM activities WHERE uuid_to_bin('03382d20-c8bc-48e7-a3d4-90b52fa5ceab') = uuid;\n\nselect * from users where email LIKE \"%mobile_automation_%\";\nselect * from social_accounts where sociable_id IN (2228);\nselect * from crm_profiles where user_id IN (2222,2223,2226,2227);\n\nselect * from teams order by id desc;\nSELECT * FROM users WHERE id = 2229;\nSELECT * FROM crm_profiles WHERE user_id = 2229;\nselect * from opportunities where crm_configuration_id = 88;\nselect * from crm_fields where crm_configuration_id = 88;\nselect * from crm_profiles where crm_configuration_id = 88;\n\nSELECT * FROM teams WHERE id = 1;\n\nSELECT * FROM users WHERE id = 143;\nSELECT * FROM users WHERE uuid_to_bin('fde193d3-06a2-4e1a-8895-62b94039215d') = uuid;\nSELECT * FROM teams WHERE uuid_to_bin('73385071-a756-42ae-9c73-8b53f2309467') = uuid;\n\nhttps://app.staging.jiminny.com/ondemand?\n min_duration=1\n &\n only_recorded=1\n &\n user_id%5B%5D=641f1acb-16b8-42d1-8726-df52979dad0e\n &\n sequence_number=2\n\n select * from users where team_id = 1 and email like '%stoyan%'\n\nselect * from coaching_feedbacks;\n\nselect * from teams;\nSELECT * FROM users WHERE team_id = 36;\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 19\nand sa.provider = 'pipedrive';\n\nselect * from users where id = 143;\n\nSELECT * FROM users WHERE uuid_to_bin('73180eeb-33de-4065-977d-ccbe0e6c94fc') = uuid;\nSELECT * FROM teams WHERE uuid_to_bin('73180eeb-33de-4065-977d-ccbe0e6c94fc') = uuid;\nSELECT * FROM activity_shares WHERE uuid_to_bin('73180eeb-33de-4065-977d-ccbe0e6c94fc') = uuid;\n\nselect * from users where team_id = 2;\nselect * from activities where crm_configuration_id = 39\nand activities.scheduled_start_time BETWEEN '2025-04-09 00:00:00' AND '2025-04-09 23:59:59'\nAND user_id = 143\norder by id desc;\n\n# ************************************************************************************\nselect * from teams where id = 142; # 2312, 126\nselect * from team_settings;\nselect * from users where team_id = 142; # 21642\nSELECT * FROM social_accounts WHERE sociable_id = 21642;\nSELECT * FROM crm_profiles cp join users u ON u.id = cp.user_id WHERE team_id = 142;\nselect * from crm_profiles where id IN (93);\nselect * from invitations;\nselect * from team_features where team_id = 1;\n\nSELECT * FROM crm_configurations WHERE id = 126;\nselect * from accounts where crm_configuration_id = 126 order by id desc;\nselect * from leads where crm_configuration_id = 126 order by id desc;\nselect * from contacts where crm_configuration_id = 126 order by id desc;\nselect * from opportunities where crm_configuration_id = 126 order by id desc;\nselect * from crm_profiles where crm_configuration_id = 126 order by id desc;\nselect * from crm_fields where crm_configuration_id = 126 # 11060\n# and type IN ('picklist', 'status')\n# and object_type = 'task'\norder by id desc;\n# 5731,5732,5733\nselect DISTINCT crm_field_id from crm_field_values where crm_field_id IN (11151,12239,12215,12185,12175,12165,12144,12137,12127,12109,12107,12105,12103,12092,12037,12005,12003,11987,11969,11958,11951,11942,11931,11924,11921,11917,11915,11901,11893,11883,11872,11870,11868,11866,11839,11833,11821,11793,11780,11777,11769,11757,11737,11735,11656,11645,11638,11629,11618,11611,11602,11591,11584,11581,11558,11544,11543,11534,11532,11529,11527,11503,11497,11493,11488,11470,11468,11457,11455,11397,11387,11372,11363,11348,11323,11318,11309,11301,11300,11292,11290,11286,11284,11256,11252,11242,11237,11233,11219,11176,11160) order by id desc;\nselect * from crm_layouts where crm_configuration_id = 126 order by id desc;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id in (300,299,298);\nselect * from stages where crm_configuration_id = 126 order by id desc;\nselect * from business_processes where crm_configuration_id = 126 order by id desc;\nselect * from business_process_stages where business_process_id IN (76,75,74,73);\nselect * from playbooks where team_id = 142;\nselect * from playbook_layouts where playbook_id IN (108);\nSELECT * FROM playbook_categories WHERE playbook_id IN (108);\n\nselect * from teams where id = 130;\nSELECT * FROM social_accounts WHERE sociable_id = 2291;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 2\nand sa.provider = 'hubspot';\n\nSELECT * FROM activities\n WHERE crm_configuration_id = 110;\n\nselect * from teams;\nselect * from crm_configurations;\n\nSELECT * FROM activities WHERE id = 628773;\nSELECT * FROM crm_profiles WHERE user_id = 1460;\nSELECT * FROM social_accounts WHERE sociable_id = 2291;\n\nselect * from teams;\nselect ru.*, pr.*, p.* from users u join role_user ru on ru.user_id = u.id\njoin permission_role pr on pr.role_id = ru.role_id\n join permissions p on p.id = pr.permission_id\nwhere team_id = 495 and p.name IN ('dial');\n\nselect * from teams where id = 145;\nselect * from crm_configurations where id = 129;\nselect * from social_accounts where sociable_id = 2317;\nSELECT * FROM activities WHERE uuid_to_bin('8dbab184-a333-4268-ad57-fb41f8d53a9a') = uuid;\n\nselect * from teams where id = 1;\nSELECT * FROM crm_layouts WHERE crm_configuration_id = 39;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 280;\nSELECT * FROM crm_layout_entities WHERE id = 5507;\nSELECT * FROM crm_fields WHERE crm_configuration_id = 39 and object_type IN ('event');\n\nselect * from teams;\nselect * from activities where crm_configuration_id = 14;\n\nSELECT * FROM social_accounts where provider = 'copper';\n\nselect * from activities where id = 628467;\nselect * from participants where activity_id = 628467;\n\nSELECT * FROM contacts WHERE id = 3969;\nSELECT * FROM accounts WHERE id = 177;\n\nSELECT * FROM activities WHERE uuid_to_bin('4eb54c77-cfa3-2bd4-84a7-9ed46a21c988') = uuid;\n\n# ********************* BH\nselect * from teams where id = 36;\nSELECT * FROM crm_configurations WHERE id = 21;\nselect * from activities where crm_configuration_id = 21 and id = 607901;\nselect * from activities where crm_configuration_id = 21;\n\nselect * roles;\nselect * from permissions;\nselect * from permission_role where permission_id = 226;\n\nselect * from migrations order by id desc;\n\n# mercury\n# neptune\n# earth\n\nselect * from teams;\nselect * from teams where id = 19;\nselect * from teams where id = 27;\nselect * from users where team_id = 27;\nSELECT * FROM crm_configurations WHERE id = 42;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 19\nand sa.provider = 'pipedrive';\n\nselect * from activities where id = 631461;\nSELECT * FROM crm_field_values WHERE crm_field_id = 180;\n\nselect * from teams where id = 2;\nSELECT * FROM social_accounts WHERE sociable_id = 89;\n\nSELECT * FROM activities WHERE uuid_to_bin('ba0c029a-bc14-4e17-8603-64174acebcbb') = uuid; # 634273\nselect * from activity_summary_logs where activity_id = 634273;\n\nselect * from sidekick_settings where team_id = 2;\n\nselect * from teams; # 2, 2\nSELECT * FROM crm_configurations WHERE team_id = 2; # 2\nselect * from team_features where team_id = 2;\nselect * from features;\nSELECT * FROM opportunities WHERE crm_configuration_id = 2 and crm_provider_id = '51317301383';\nSELECT * FROM opportunities WHERE crm_configuration_id = 2 order by id desc;\n\nselect * from automated_reports order by id desc;\nselect * from automated_report_results order by id desc;\nselect * from users where team_id = 1 and id IN (7160, 3248);\nselect * from migrations order by id desc;\n\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 1 and sa.provider = 'salesforce';\n\nselect * from teams where id = 1;\nselect * from groups g JOIN playbooks p on g.playbook_id = p.id where g.team_id = 1;\nselect * from groups where id = 565;\nselect * from playbooks where team_id = 1;\nselect * from playbooks where id = 175;\nselect * from playbook_categories where playbook_id = 175;\nselect * from users where team_id = 1;\nselect * from users where id = 7160;\nselect * from crm_profiles where user_id = 7160;\nselect * from features;\nselect\n *\n# id, uuid, type, provider, playbook_category_id, user_id, lead_id, contact_id, account_id, opportunity_id, stage_id,\n# crm_configuration_id, crm_provider_id, transcription_id, status\nfrom activities where crm_configuration_id = 1 and type = 'conference'\n# and crm_provider_id IS NOT NULL\nand provider != 'uploader' and actual_start_time IS NOT NULL\nORDER by id desc;\nselect * from activities where id = 54747783; # 00UO400000pCzojMAC\n\nselect p.id, p.activity_type, pc.id, pc.name\nFROM playbooks p\njoin playbook_categories pc on p.id = pc.playbook_id\nwhere p.team_id = 1 and p.activity_type = 'event';\n\nSELECT * FROM crm_fields WHERE crm_configuration_id = 1 and object_type = 'event';\nSELECT * FROM crm_field_values WHERE crm_field_id = 4;\n\nselect * from crm_layouts cl join playbook_layouts pl on cl.id = pl.layout_id\nwhere crm_configuration_id = 1 and pl.playbook_id = 175;\n\nselect * from teams;\nSELECT r.* FROM automated_reports r\njoin teams t on r.team_id = t.id\nWHERE r.frequency = 'daily'\n and r.status = 1\nAND t.status = 'active'\nAND (r.expires_at >= now() OR r.expires_at IS NULL);\n\nselect * from automated_report_results where report_id IN (18, 33);\n\nselect * from activity_searches where id = 10932;\nselect * from activity_search_filters where activity_search_id = 10932;\nselect * from automated_reports;\nselect * from automated_report_results where report_id IN (34, 35);","depth":4,"value":"SELECT * FROM teams WHERE id = 1;\n\nselect * from crm_layouts where crm_configuration_id = 39;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 283;\nSELECT * FROM crm_fields WHERE id = 2234;\nSELECT * FROM crm_field_values WHERE crm_field_id = 2234;\n\nselect * from crm_profiles where user_id = 143;\n\nselect * from record_types where crm_configuration_id = 39; # 0121K000001MHElQAO,0121K000001MHEqQAO\nselect * from business_processes where crm_configuration_id = 39;\n# 01941000000H669AAC, 01941000000H66JAAS\n\nselect * from record_type_field_values\n where record_type_id IN (24);\n\nselect * from crm_field_values where id IN (2730);\n\nselect * from crm_configurations where id = 39;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 1\nand sa.provider = 'salesforce'; #1035\n\n\nselect * from users where team_id = 1; # 222 group 3\nSELECT * FROM activities WHERE user_id = 222 order by id desc;\nselect * from sidekick_settings where team_id = 1;\nselect * from teams where id = 1;\nselect * from team_features where team_id = 1;\n\nselect * from activities where crm_configuration_id = 2\nand provider = 'ms-teams' and id = 608765;\n\nSELECT * FROM activities WHERE crm_configuration_id = 2 and crm_provider_id = '59523413338';\n\nselect * from sidekick_settings where team_id = 2;\n\nSELECT * FROM activities WHERE id = 608660;\nselect * from activity_summary_logs where activity_id = 608660;\nselect * from ai_prompts where transcription_id = 11214;\n\n# ********************************************************************************************************\nSELECT * FROM activities WHERE uuid_to_bin('ed78a437-2804-450e-ab2f-56ab1c641346') = uuid;\n# id: 608818, crm: 59628809737\nSELECT * FROM activities WHERE uuid_to_bin('36b06e55-afdd-4782-8dee-c624cd0af191') = uuid;\n# id: 608821, crm: 59632069252\nSELECT ce.start_time, ce.end_time, a.id, a.uuid, crm_provider_id, calendar_event_id, title,\nplaybook_category_id, user_id, lead_id, contact_id, account_id, opportunity_id,\nscheduled_start_time, scheduled_end_time, actual_start_time, actual_end_time, a.created_at\nFROM activities a\njoin calendar_events ce on a.calendar_event_id = ce.id\nWHERE a.id IN (608818, 608821);\n\nselect * from users where team_id = 1;\nselect * from team_settings where team_id = 1;\nselect * from crm_profiles where crm_configuration_id = 39 order by user_id;\n\nselect * from team_features where team_id = 1;\n\nselect * from users where team_id = 2;\n\nSELECT * FROM activities WHERE uuid_to_bin('ec7647e9-5225-458b-b475-f31aa2769204') = uuid; # 612639\n# Preslava N. Ivanova, grou id 3\n\nSELECT * FROM opportunities WHERE uuid_to_bin('a2928fe5-aec5-46cb-85d9-7654c89e46a6') = uuid;\n\nselect * from activities where opportunity_id = 344 and actual_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00';\n\nselect\n a.id,\n a.type,\n a.scheduled_start_time,\n a.actual_start_time,\n a.created_at,\n a.opportunity_id,\n a.status\nFROM activities a\nWHERE opportunity_id = 344\nand status IN ('completed', 'received', 'delivered')\nand (\n (a.actual_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00')\nOR (a.created_at between '2024-10-11 00:00:00' and '2024-10-12 00:00:00')\nOR (a.scheduled_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00'))\n;\n\nSELECT * FROM users WHERE id = 222;\n\nSELECT * FROM crm_profiles WHERE user_id = 222;\nselect * from crm_layouts where crm_configuration_id = 39;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 281;\n\nselect * from group_deal_risk_types;\n\nselect * from opportunities where team_id = 1;\n\nSELECT * FROM opportunities WHERE id = 315;\nSELECT * FROM crm_field_data WHERE object_id = 315;\nselect * from crm_field_data where object_id = 260;\n\nselect * from generic_ai_prompts where subject_id = 315;\n\nselect * from teams; # 36, 21, 121, james.graham@bullhorn.jiminny.com\nSELECT * FROM social_accounts WHERE sociable_id = 121 and provider = 'bullhorn';\n\n# ************************************************************************************\nselect * from teams where id = 1;\nselect * from crm_configurations where id = 39;\nselect * from users where team_id = 1;\nselect u.email, cp.* from users u\njoin crm_profiles cp on u.id = cp.user_id\nwhere u.team_id = 1;\n# 1 - 00541000004281rAAA\n# 204 - 0052g000003freeAAA\n# 429 - 0052g000003qGOiAAM\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 1\nand sa.provider = 'salesforce';\n\nselect * from activities where type = 'softphone'\nand created_at > '2024-12-11 15:24:36' order by id desc;\n\nselect * from activity_providers where team_id = 1;\nselect * from activity_provider_users where activity_provider_id = 328;\n\nselect * from opportunities where crm_configuration_id = 39\nAND account_id = 178 AND is_closed = false\norder by created_at DESC;\n\nselect * from contacts where id = 3952;\nselect * from accounts where id = 178;\n\n# ************************************************************************************\nselect * from teams where id = 36;\nselect * from crm_configurations where id = 21;\nselect * from users where team_id = 36;\nselect u.email, cp.* from users u\njoin crm_profiles cp on u.id = cp.user_id\nwhere u.team_id = 36;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 36\nand sa.provider = 'bullhorn';\n\nselect * from social_accounts where id = 348;\nUPDATE social_accounts SET\nprovider_user_token = '21442_6802599_91:41179a58-21e7-4d7c-ad58-56bb666b2f65',\nprovider_refresh_token = '21442_6802599_91:01c6b335-3f2a-42e4-85ff-8a08fa65fceb',\nexpires = 1733998131,\nstate = 'connected'\nWHERE id = 348;\n\n# ************************************************************************************\nselect * from teams where id = 31;\nselect * from crm_configurations where id = 18;\n\nselect * from users where team_id = 31; # 257\nselect u.email, cp.* from users u\njoin crm_profiles cp on u.id = cp.user_id\nwhere u.team_id = 31;\n\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 31\nand sa.provider = 'close';\n\nselect * from contacts where crm_configuration_id = 18;\n\n# ********************** NEPTUNE **************************************************************\nselect * from teams;\nselect * from users where id IN (1030, 1035, 1052);\nselect * from crm_configurations;\n\nselect * from users where team_id = 65; # 257\nselect * from team_settings where team_id = 65; # 257\nselect * from invitations where team_id = 65; # 257\nselect * from users where email = 'integration-account@jiminny.com'; # 257\nselect u.email, cp.* from users u\njoin crm_profiles cp on u.id = cp.user_id\nwhere u.team_id = 65;\n\nselect * from crm_configurations where id = 53;\nselect * from accounts where crm_configuration_id = 53 order by id desc;\nselect * from leads where crm_configuration_id = 53 order by id desc;\nselect * from contacts where crm_configuration_id = 53 order by id desc;\nselect * from opportunities where crm_configuration_id = 53 order by id desc;\nselect * from crm_profiles where crm_configuration_id = 53 order by id desc;\nselect * from crm_fields where crm_configuration_id = 53 order by id desc;\nselect * from crm_field_values where crm_field_id = 3341 order by id desc;\nselect * from crm_layouts where crm_configuration_id = 53 order by id desc;\nselect * from stages where crm_configuration_id = 53 order by id desc;\n\n\nselect * from crm_profiles where crm_configuration_id = 13;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 65\nand sa.provider = 'integration-app';\n\nselect * from contacts where crm_configuration_id = 13;\n\nselect * from social_accounts where sociable_id = 283;\n\nSELECT * FROM opportunities WHERE crm_provider_id = '006O400000E9bzeIAB';\n\nselect * from activity_providers where team_id = 65;\nSELECT * FROM activities WHERE crm_configuration_id IN (51, 52, 53);\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 65\n;\n\n# ***************************** STAGING ********************************************\nSELECT * FROM teams;\nSELECT * FROM teams WHERE id = 88;\nSELECT * FROM teams WHERE id = 89;\nselect * from team_settings where team_id = 89;\nSELECT * FROM users WHERE team_id = 89;\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 89;\n\nselect * from users;\nSELECT * FROM social_accounts WHERE sociable_id = 1761;\nSELECT * FROM crm_configurations WHERE id = 70;\nselect * from accounts where crm_configuration_id = 70 order by id desc;\nselect * from leads where crm_configuration_id = 70 order by id desc;\nselect * from contacts where crm_configuration_id = 70 order by id desc;\nselect * from opportunities where crm_configuration_id = 70 order by id desc;\nselect * from crm_profiles where crm_configuration_id = 70 order by id desc;\nselect * from crm_fields where crm_configuration_id = 70 order by id desc;\nselect * from crm_field_values where crm_field_id = 3536 order by id desc;\nselect * from crm_layouts where crm_configuration_id = 70 order by id desc;\nselect * from stages where crm_configuration_id = 70 order by id desc;\nselect * from business_processes where crm_configuration_id = 70 order by id desc;\nselect * from business_process_stages where business_process_id = 34;\n\nselect * from contacts where id = 10468;\n\nselect * from crm_layouts where crm_configuration_id = 70;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 388;\nSELECT * FROM crm_fields WHERE id IN (3533,3534,3535);\n\nselect * from activities where crm_configuration_id = 70\nand (account_id IS NOT NULL or lead_id IS NOT NULL or contact_id IS NOT NULL or opportunity_id IS NOT NULL) order by id desc;\n\nSELECT * FROM activities WHERE uuid_to_bin('2e10b60f-8a61-41c5-a3d4-28835353dc65') = uuid;\nSELECT * FROM activities where crm_configuration_id = 69 ;\n\nSELECT * FROM users WHERE email LIKE '%jiminny_web_sa2@jiminny.com%';\nSELECT * FROM activities WHERE uuid_to_bin('5a150c93-40fc-42ec-b3bd-c1d328e09f6e') = uuid;\nSELECT * FROM opportunities WHERE id = 385;\n\nselect * from participants p\njoin activities a on p.activity_id = a.id\nwhere a.crm_configuration_id = 70\nand (p.lead_id IS NOT NULL or p.contact_id IS NOT NULL);\nSELECT * FROM participants WHERE id = 1013638;\n\nselect * from teams where id = 90;\nselect * from users where team_id = 90;\nselect * from social_accounts where social_accounts.sociable_id IN (1960,1760);\nSELECT * FROM crm_profiles WHERE crm_configuration_id = 71;\nselect * from invitations where team_id = 90;\n\nselect * from crm_configurations where id = 71;\nselect * from accounts where crm_configuration_id = 71 order by id desc;\nselect * from leads where crm_configuration_id = 71 order by id desc;\nselect * from contacts where crm_configuration_id = 71 order by id desc;\nselect * from opportunities where crm_configuration_id = 71 order by id desc;\nselect * from crm_profiles where crm_configuration_id = 71 order by id desc;\nselect * from crm_fields where crm_configuration_id = 71 order by id desc;\nselect * from crm_field_values where crm_field_id = 3341 order by id desc;\nselect * from crm_layouts where crm_configuration_id = 71 order by id desc;\nselect * from stages where crm_configuration_id = 71 order by id desc;\n\nselect * from users order by secondary_email desc;\nselect u.id, u.email, u.status, sa.id, sa.provider_user_id from social_accounts sa\n join users u on sa.sociable_id = u.id\nwhere sa.provider = 'google' and u.email LIKE 'aneliya%';\n\nselect * from failed_jobs order by id desc;\n\nselect * from users where email = 'ben.allwright@learningpeople.co.uk' or secondary_email = 'ben.allwright@learningpeople.co.uk';\n\nselect * from teams;\nSELECT * FROM crm_profiles WHERE crm_configuration_id = 39;\nSELECT * FROM crm_fields WHERE crm_configuration_id = 39 and object_type = 'task';\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 1\nand sa.provider = 'salesforce';\n\n# ************************************************************************************\nSELECT * FROM activities WHERE uuid_to_bin('c38b3895-fd0f-4b1f-9fb2-c170dba137c6') = uuid;\nSELECT * FROM crm_configurations WHERE id = 70;\n\nselect * from teams where id = 1;\nselect * from groups where team_id = 1;\nselect * from users where team_id = 1;\n\nselect o.id, o.name,o.close_date, u.id, u.name, u.group_id, r.id, r.display_name, g.name, g.scope from opportunities o\njoin users u on o.user_id = u.id\njoin groups g on u.group_id = g.id\njoin role_user ru on u.id = ru.user_id\njoin roles r on ru.role_id = r.id\nwhere o.crm_configuration_id = 39 and close_date > '2024-01-01 00:00:00';\n\nselect * from role_user where user_id = 143;\nselect * from roles;\n\nselect * from role_user;\nselect * from groups where id = 9;\nselect * from scope_groups where group_id = 9;\n\n# ************************************************************************************\nselect * from teams where id = 36;\nselect * from crm_configurations;\nSELECT * FROM social_accounts WHERE sociable_id = 121;\n\nhttps://crmsandbox.zoho.com/crm/jiminnyw4/tab/Leads/4776201000005049105\nhttps://crmsandbox.zoho.com/crm/\n\nhttps://crm.zoho.com/crm/org3469620/tab/Leads/230045000229559080\n https://crm.zoho.com/crm/\n org3469620\n\nSELECT * FROM activities WHERE uuid_to_bin('03382d20-c8bc-48e7-a3d4-90b52fa5ceab') = uuid;\n\nselect * from users where email LIKE \"%mobile_automation_%\";\nselect * from social_accounts where sociable_id IN (2228);\nselect * from crm_profiles where user_id IN (2222,2223,2226,2227);\n\nselect * from teams order by id desc;\nSELECT * FROM users WHERE id = 2229;\nSELECT * FROM crm_profiles WHERE user_id = 2229;\nselect * from opportunities where crm_configuration_id = 88;\nselect * from crm_fields where crm_configuration_id = 88;\nselect * from crm_profiles where crm_configuration_id = 88;\n\nSELECT * FROM teams WHERE id = 1;\n\nSELECT * FROM users WHERE id = 143;\nSELECT * FROM users WHERE uuid_to_bin('fde193d3-06a2-4e1a-8895-62b94039215d') = uuid;\nSELECT * FROM teams WHERE uuid_to_bin('73385071-a756-42ae-9c73-8b53f2309467') = uuid;\n\nhttps://app.staging.jiminny.com/ondemand?\n min_duration=1\n &\n only_recorded=1\n &\n user_id%5B%5D=641f1acb-16b8-42d1-8726-df52979dad0e\n &\n sequence_number=2\n\n select * from users where team_id = 1 and email like '%stoyan%'\n\nselect * from coaching_feedbacks;\n\nselect * from teams;\nSELECT * FROM users WHERE team_id = 36;\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 19\nand sa.provider = 'pipedrive';\n\nselect * from users where id = 143;\n\nSELECT * FROM users WHERE uuid_to_bin('73180eeb-33de-4065-977d-ccbe0e6c94fc') = uuid;\nSELECT * FROM teams WHERE uuid_to_bin('73180eeb-33de-4065-977d-ccbe0e6c94fc') = uuid;\nSELECT * FROM activity_shares WHERE uuid_to_bin('73180eeb-33de-4065-977d-ccbe0e6c94fc') = uuid;\n\nselect * from users where team_id = 2;\nselect * from activities where crm_configuration_id = 39\nand activities.scheduled_start_time BETWEEN '2025-04-09 00:00:00' AND '2025-04-09 23:59:59'\nAND user_id = 143\norder by id desc;\n\n# ************************************************************************************\nselect * from teams where id = 142; # 2312, 126\nselect * from team_settings;\nselect * from users where team_id = 142; # 21642\nSELECT * FROM social_accounts WHERE sociable_id = 21642;\nSELECT * FROM crm_profiles cp join users u ON u.id = cp.user_id WHERE team_id = 142;\nselect * from crm_profiles where id IN (93);\nselect * from invitations;\nselect * from team_features where team_id = 1;\n\nSELECT * FROM crm_configurations WHERE id = 126;\nselect * from accounts where crm_configuration_id = 126 order by id desc;\nselect * from leads where crm_configuration_id = 126 order by id desc;\nselect * from contacts where crm_configuration_id = 126 order by id desc;\nselect * from opportunities where crm_configuration_id = 126 order by id desc;\nselect * from crm_profiles where crm_configuration_id = 126 order by id desc;\nselect * from crm_fields where crm_configuration_id = 126 # 11060\n# and type IN ('picklist', 'status')\n# and object_type = 'task'\norder by id desc;\n# 5731,5732,5733\nselect DISTINCT crm_field_id from crm_field_values where crm_field_id IN (11151,12239,12215,12185,12175,12165,12144,12137,12127,12109,12107,12105,12103,12092,12037,12005,12003,11987,11969,11958,11951,11942,11931,11924,11921,11917,11915,11901,11893,11883,11872,11870,11868,11866,11839,11833,11821,11793,11780,11777,11769,11757,11737,11735,11656,11645,11638,11629,11618,11611,11602,11591,11584,11581,11558,11544,11543,11534,11532,11529,11527,11503,11497,11493,11488,11470,11468,11457,11455,11397,11387,11372,11363,11348,11323,11318,11309,11301,11300,11292,11290,11286,11284,11256,11252,11242,11237,11233,11219,11176,11160) order by id desc;\nselect * from crm_layouts where crm_configuration_id = 126 order by id desc;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id in (300,299,298);\nselect * from stages where crm_configuration_id = 126 order by id desc;\nselect * from business_processes where crm_configuration_id = 126 order by id desc;\nselect * from business_process_stages where business_process_id IN (76,75,74,73);\nselect * from playbooks where team_id = 142;\nselect * from playbook_layouts where playbook_id IN (108);\nSELECT * FROM playbook_categories WHERE playbook_id IN (108);\n\nselect * from teams where id = 130;\nSELECT * FROM social_accounts WHERE sociable_id = 2291;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 2\nand sa.provider = 'hubspot';\n\nSELECT * FROM activities\n WHERE crm_configuration_id = 110;\n\nselect * from teams;\nselect * from crm_configurations;\n\nSELECT * FROM activities WHERE id = 628773;\nSELECT * FROM crm_profiles WHERE user_id = 1460;\nSELECT * FROM social_accounts WHERE sociable_id = 2291;\n\nselect * from teams;\nselect ru.*, pr.*, p.* from users u join role_user ru on ru.user_id = u.id\njoin permission_role pr on pr.role_id = ru.role_id\n join permissions p on p.id = pr.permission_id\nwhere team_id = 495 and p.name IN ('dial');\n\nselect * from teams where id = 145;\nselect * from crm_configurations where id = 129;\nselect * from social_accounts where sociable_id = 2317;\nSELECT * FROM activities WHERE uuid_to_bin('8dbab184-a333-4268-ad57-fb41f8d53a9a') = uuid;\n\nselect * from teams where id = 1;\nSELECT * FROM crm_layouts WHERE crm_configuration_id = 39;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 280;\nSELECT * FROM crm_layout_entities WHERE id = 5507;\nSELECT * FROM crm_fields WHERE crm_configuration_id = 39 and object_type IN ('event');\n\nselect * from teams;\nselect * from activities where crm_configuration_id = 14;\n\nSELECT * FROM social_accounts where provider = 'copper';\n\nselect * from activities where id = 628467;\nselect * from participants where activity_id = 628467;\n\nSELECT * FROM contacts WHERE id = 3969;\nSELECT * FROM accounts WHERE id = 177;\n\nSELECT * FROM activities WHERE uuid_to_bin('4eb54c77-cfa3-2bd4-84a7-9ed46a21c988') = uuid;\n\n# ********************* BH\nselect * from teams where id = 36;\nSELECT * FROM crm_configurations WHERE id = 21;\nselect * from activities where crm_configuration_id = 21 and id = 607901;\nselect * from activities where crm_configuration_id = 21;\n\nselect * roles;\nselect * from permissions;\nselect * from permission_role where permission_id = 226;\n\nselect * from migrations order by id desc;\n\n# mercury\n# neptune\n# earth\n\nselect * from teams;\nselect * from teams where id = 19;\nselect * from teams where id = 27;\nselect * from users where team_id = 27;\nSELECT * FROM crm_configurations WHERE id = 42;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 19\nand sa.provider = 'pipedrive';\n\nselect * from activities where id = 631461;\nSELECT * FROM crm_field_values WHERE crm_field_id = 180;\n\nselect * from teams where id = 2;\nSELECT * FROM social_accounts WHERE sociable_id = 89;\n\nSELECT * FROM activities WHERE uuid_to_bin('ba0c029a-bc14-4e17-8603-64174acebcbb') = uuid; # 634273\nselect * from activity_summary_logs where activity_id = 634273;\n\nselect * from sidekick_settings where team_id = 2;\n\nselect * from teams; # 2, 2\nSELECT * FROM crm_configurations WHERE team_id = 2; # 2\nselect * from team_features where team_id = 2;\nselect * from features;\nSELECT * FROM opportunities WHERE crm_configuration_id = 2 and crm_provider_id = '51317301383';\nSELECT * FROM opportunities WHERE crm_configuration_id = 2 order by id desc;\n\nselect * from automated_reports order by id desc;\nselect * from automated_report_results order by id desc;\nselect * from users where team_id = 1 and id IN (7160, 3248);\nselect * from migrations order by id desc;\n\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 1 and sa.provider = 'salesforce';\n\nselect * from teams where id = 1;\nselect * from groups g JOIN playbooks p on g.playbook_id = p.id where g.team_id = 1;\nselect * from groups where id = 565;\nselect * from playbooks where team_id = 1;\nselect * from playbooks where id = 175;\nselect * from playbook_categories where playbook_id = 175;\nselect * from users where team_id = 1;\nselect * from users where id = 7160;\nselect * from crm_profiles where user_id = 7160;\nselect * from features;\nselect\n *\n# id, uuid, type, provider, playbook_category_id, user_id, lead_id, contact_id, account_id, opportunity_id, stage_id,\n# crm_configuration_id, crm_provider_id, transcription_id, status\nfrom activities where crm_configuration_id = 1 and type = 'conference'\n# and crm_provider_id IS NOT NULL\nand provider != 'uploader' and actual_start_time IS NOT NULL\nORDER by id desc;\nselect * from activities where id = 54747783; # 00UO400000pCzojMAC\n\nselect p.id, p.activity_type, pc.id, pc.name\nFROM playbooks p\njoin playbook_categories pc on p.id = pc.playbook_id\nwhere p.team_id = 1 and p.activity_type = 'event';\n\nSELECT * FROM crm_fields WHERE crm_configuration_id = 1 and object_type = 'event';\nSELECT * FROM crm_field_values WHERE crm_field_id = 4;\n\nselect * from crm_layouts cl join playbook_layouts pl on cl.id = pl.layout_id\nwhere crm_configuration_id = 1 and pl.playbook_id = 175;\n\nselect * from teams;\nSELECT r.* FROM automated_reports r\njoin teams t on r.team_id = t.id\nWHERE r.frequency = 'daily'\n and r.status = 1\nAND t.status = 'active'\nAND (r.expires_at >= now() OR r.expires_at IS NULL);\n\nselect * from automated_report_results where report_id IN (18, 33);\n\nselect * from activity_searches where id = 10932;\nselect * from activity_search_filters where activity_search_id = 10932;\nselect * from automated_reports;\nselect * from automated_report_results where report_id IN (34, 35);","role_description":"text entry area","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.088194445,"height":0.027777778},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"102","depth":4,"role_description":"text"},{"role":"AXStaticText","text":"3","depth":4,"role_description":"text"},{"role":"AXStaticText","text":"34","depth":4,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Services\\Kiosk\\AutomatedReports;\n\nuse Carbon\\CarbonImmutable;\nuse Carbon\\CarbonInterface;\nuse Carbon\\Exceptions\\InvalidFormatException;\nuse DateTime;\nuse DateTimeInterface;\nuse DateTimeZone;\nuse Illuminate\\Contracts\\Bus\\Dispatcher as BusDispatcher;\nuse Illuminate\\Database\\Eloquent\\Builder;\nuse Illuminate\\Support\\Carbon;\nuse Illuminate\\Support\\Collection;\nuse Illuminate\\Support\\Facades\\Log;\nuse Illuminate\\Support\\Facades\\Storage;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinition\\InputTypeEnum;\nuse Jiminny\\Component\\AskAnything\\AskAnythingPromptService;\nuse Jiminny\\Component\\AskAnything\\Dtos\\AskAnythingPromptDto;\nuse Jiminny\\Component\\UrlGenerator\\Webhook;\nuse Jiminny\\Contracts\\Repositories\\PlaybookCategoryRepository;\nuse Jiminny\\Contracts\\Repositories\\TeamRepository;\nuse Jiminny\\Contracts\\Repositories\\UserRepository;\nuse Jiminny\\Exceptions\\ApplicationException;\nuse Jiminny\\Exceptions\\InvalidArgumentException;\nuse Jiminny\\Exceptions\\ModelNotFoundException;\nuse Jiminny\\Jobs\\AutomatedReports\\RequestGenerateReportJob;\nuse Jiminny\\Models\\Activity\\Search;\nuse Jiminny\\Models\\AskAnything\\AskAnythingPrompt;\nuse Jiminny\\Models\\AskAnything\\AskAnythingPromptTarget;\nuse Jiminny\\Models\\AutomatedReport;\nuse Jiminny\\Models\\AutomatedReportResult;\nuse Jiminny\\Models\\Contracts\\UserContract;\nuse Jiminny\\Models\\Feature\\FeatureEnum;\nuse Jiminny\\Models\\Team;\nuse Jiminny\\Models\\User;\nuse Jiminny\\Repositories\\AskAnythingRepository;\nuse Jiminny\\Repositories\\AutomatedReportsRepository;\nuse Jiminny\\Repositories\\GroupRepository;\nuse Jiminny\\Repositories\\SearchRepository;\nuse Jiminny\\Repositories\\StageRepository;\nuse Throwable;\n\nclass AutomatedReportsService\n{\n public const string TYPE_LOSS_ANALYSIS = 'loss_analysis';\n public const string TYPE_ASK_JIMINNY = 'ask_jiminny';\n\n /**\n * Standard report types (used by kiosk for existing automated reports).\n */\n // @TODO this will add filter, however if we need to control feature by FF we need conditional logic\n public const array TYPES = [\n ['id' => 'exec_summary', 'name' => 'Exec Summary'],\n ['id' => 'coaching_profiles', 'name' => 'Coaching Profiles'],\n ['id' => 'product_feedback', 'name' => 'Product Feedback'],\n ['id' => self::TYPE_LOSS_ANALYSIS, 'name' => 'Loss Analysis'],\n// ['id' => 'questions', 'name' => 'Questions'],\n// ['id' => 'statistical_quant', 'name' => 'Statistical Quantitative'],\n ];\n\n public const array ALL_TYPES = [\n ...self::TYPES,\n ['id' => self::TYPE_ASK_JIMINNY, 'name' => 'Ask Jiminny'],\n ];\n\n public const string FREQUENCY_DAILY = 'daily';\n public const string FREQUENCY_WEEKLY = 'weekly';\n public const string FREQUENCY_MONTHLY = 'monthly';\n public const string FREQUENCY_QUARTERLY = 'quarterly';\n public const string FREQUENCY_ONE_OFF = 'one_off';\n\n /**\n * Frequencies for standard (non-Ask Jiminny) reports.\n */\n public const array FREQUENCIES = [\n ['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],\n ['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],\n ['id' => self::FREQUENCY_QUARTERLY, 'name' => 'Quarterly'],\n ['id' => self::FREQUENCY_ONE_OFF, 'name' => 'One-off'],\n ];\n\n /**\n * Frequencies for Ask Jiminny reports.\n */\n public const array ASK_JIMINNY_FREQUENCIES = [\n ['id' => self::FREQUENCY_DAILY, 'name' => 'Daily'],\n ['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],\n ['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],\n ];\n\n public const string MEDIA_TYPE_PDF = 'pdf';\n public const string MEDIA_TYPE_PODCAST = 'podcast';\n public const array MEDIA_TYPES = [self::MEDIA_TYPE_PDF, self::MEDIA_TYPE_PODCAST];\n public const array MEDIA_TYPE_OBJECT_PDF = ['id' => self::MEDIA_TYPE_PDF, 'name' => 'PDF'];\n public const array MEDIA_TYPE_OBJECT_PODCAST = ['id' => self::MEDIA_TYPE_PODCAST, 'name' => 'Podcast'];\n public const array MEDIA_TYPE_OBJECTS = [self::MEDIA_TYPE_OBJECT_PDF, self::MEDIA_TYPE_OBJECT_PODCAST];\n\n public const array CALL_TYPE_CONFERENCE = ['id' => 'conference', 'name' => 'Conference'];\n public const array CALL_TYPE_DIALER = ['id' => 'dialer', 'name' => 'Dialer'];\n public const int SENT_REPORT_AT_HOURS = 5;\n public const string PDF_KEY = 'pdf';\n public const string AUDIO_KEY = 'audio';\n\n private const array ALL_FREQUENCIES = [\n ['id' => self::FREQUENCY_DAILY, 'name' => 'Daily'],\n ['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],\n ['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],\n ['id' => self::FREQUENCY_QUARTERLY, 'name' => 'Quarterly'],\n ['id' => self::FREQUENCY_ONE_OFF, 'name' => 'One-off'],\n ];\n private const string S3_DIR = 'reports';\n private const array FILE_EXTENSIONS_VARIANTS = ['html', 'MD', 'pdf'];\n private const array FILE_PODCAST_EXTENSIONS_VARIANTS = ['json', 'mp3', 'ssml'];\n\n public function __construct(\n private readonly TeamRepository $teamRepository,\n private readonly GroupRepository $groupRepository,\n private readonly UserRepository $userRepository,\n private readonly StageRepository $stageRepository,\n private readonly DealStagesService $dealStagesService,\n private readonly RecipientsService $recipientsService,\n private readonly AutomatedReportsRepository $automatedReportsRepository,\n private readonly Webhook $webhookService,\n private readonly BusDispatcher $dispatcher,\n private readonly ActivityTypeService $activityTypeService,\n private readonly PlaybookCategoryRepository $playbookCategoryRepository,\n private readonly AskAnythingPromptService $askAnythingPromptService,\n private readonly SearchRepository $activitySearchRepository,\n private readonly AskAnythingRepository $askAnythingRepository,\n ) {\n }\n\n public static function getTypes(): array\n {\n $types = self::TYPES;\n\n return array_map(static function ($type) {\n return $type['id'];\n }, $types);\n }\n\n public static function getCallTypes(): array\n {\n return array_map(static function ($callType) {\n return $callType['id'];\n }, [self::CALL_TYPE_CONFERENCE, self::CALL_TYPE_DIALER]);\n }\n\n public static function getFrequencies(): array\n {\n return array_map(static function ($frequency) {\n return $frequency['id'];\n }, self::FREQUENCIES);\n }\n\n // front-facing structure\n public function getReportEnabledFieldData(bool $value = false): array\n {\n return [\n 'id' => 'report_enabled',\n 'label' => '',\n 'inputType' => InputTypeEnum::TOGGLE,\n 'value' => $value,\n ];\n }\n\n // Organizations = Teams\n public function getOrganizationFieldData(?string $value = null, bool $shortVersion = false): array\n {\n $options = $this->getTeams();\n\n if ($shortVersion) {\n return [\n 'id' => 'organization',\n 'label' => 'Organization',\n 'options' => $options,\n ];\n }\n\n return [\n 'id' => 'organization',\n 'label' => 'Organization',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => $options,\n 'value' => $value,\n 'dependencies' => [\n 'teams',\n 'deal_stage_at_call',\n 'current_deal_stage',\n 'recipients',\n ActivityTypeService::PLAYBOOK_CATEGORIES_KEY,\n ],\n 'dependsOn' => [],\n ];\n }\n\n // Teams = Groups\n public function getTeamFieldData(array $options = [], array $value = [], bool $shortVersion = false): array\n {\n if ($shortVersion) {\n return [\n 'id' => 'teams',\n 'label' => 'Team',\n 'options' => $options,\n ];\n }\n\n return [\n 'id' => 'teams',\n 'label' => 'Team',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'required' => false,\n 'placeholder' => 'Select',\n 'options' => $options,\n 'value' => $value, // value should be an array of objects {id, name}\n 'dependencies' => [ActivityTypeService::PLAYBOOK_CATEGORIES_KEY],\n 'dependsOn' => [],\n ];\n }\n\n public function getReportTypeFieldData(?string $value = null, bool $shortVersion = false, ?Team $team = null): array\n {\n $types = [];\n if ($team instanceof Team) {\n if ($team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {\n $types = self::TYPES;\n }\n if ($team->hasFeature(FeatureEnum::ASK_JIMINNY_REPORTS)) {\n $types[] = ['id' => self::TYPE_ASK_JIMINNY, 'name' => 'Ask Jiminny'];\n }\n } else {\n $types = self::TYPES;\n }\n\n if ($shortVersion) {\n return [\n 'id' => 'report_type',\n 'label' => 'Report Type',\n 'options' => $types,\n ];\n }\n\n return [\n 'id' => 'report_type',\n 'label' => 'Report Type',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => $types,\n 'value' => $value,\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getFrequencyFieldData(?string $value = null): array\n {\n return [\n 'id' => 'frequency',\n 'label' => 'Frequency',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => self::FREQUENCIES,\n 'value' => $value,\n 'dependencies' => ['period'],\n 'dependsOn' => [],\n ];\n }\n\n public function getPeriodFieldData(?string $valueStartDate = null, ?string $valueEndDate = null): array\n {\n return [\n 'id' => 'period',\n 'label' => 'Select one-off period',\n 'inputType' => InputTypeEnum::DATE_RANGE,\n 'required' => true,\n 'placeholder' => 'Select',\n 'value' => ['startDate' => $valueStartDate, 'endDate' => $valueEndDate],\n 'queryParams' => [\n 'startDate' => 'start_date_period',\n 'endDate' => 'end_date_period',\n ],\n 'dependencies' => [],\n 'dependsOn' => ['frequency'],\n ];\n }\n\n public function getActivityTypesFieldData(?Team $team = null, array $value = [], array $teamsFilter = []): array\n {\n return $this->activityTypeService->getActivityTypeFieldData(team: $team, value: $value, groupIds: $teamsFilter);\n }\n\n public function getDealStageAtCallFieldData(?Team $team = null, array $value = []): array\n {\n return $this->dealStagesService->getDealStageAtCallFieldData(team: $team, value: $value);\n }\n\n public function getCurrentDealStageFieldData(?Team $team = null, array $value = []): array\n {\n return $this->dealStagesService->getCurrentDealStageFieldData(team: $team, value: $value);\n }\n\n public function getDealValueFieldData(?int $valueMin = null, ?int $valueMax = null): array\n {\n return [\n 'id' => 'deal_value',\n 'label' => 'Deal Value',\n 'inputType' => InputTypeEnum::INTEGER_RANGE,\n 'required' => false,\n 'value' => ['min' => $valueMin, 'max' => $valueMax],\n 'queryParams' => [\n 'min' => 'min_deal_value',\n 'max' => 'max_deal_value',\n ],\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getCallTypeFieldData(bool $conferenceOn = false, bool $dialerOn = false): array\n {\n $value = [];\n $conferenceOn && $value[] = self::CALL_TYPE_CONFERENCE;\n $dialerOn && $value[] = self::CALL_TYPE_DIALER;\n\n return [\n 'id' => 'call_type',\n 'label' => 'Call Type',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'required' => true,\n 'options' => [\n self::CALL_TYPE_CONFERENCE,\n self::CALL_TYPE_DIALER,\n ],\n 'value' => $value,\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getMediaTypeFieldData(?AutomatedReport $report = null): array\n {\n $value = [];\n\n if ($report) {\n $value = $this->transformMediaTypes($report);\n }\n\n return [\n 'id' => 'media_types',\n 'label' => 'Export as',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'required' => true,\n 'options' => self::MEDIA_TYPE_OBJECTS,\n 'value' => $value,\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getCallDurationFieldData(?int $valueMin = null, ?int $valueMax = null): array\n {\n return [\n 'id' => 'call_duration',\n 'label' => 'Call Duration',\n 'inputType' => InputTypeEnum::INTEGER_RANGE,\n 'required' => false,\n 'value' => ['min' => $valueMin, 'max' => $valueMax],\n 'queryParams' => [\n 'min' => 'min_call_duration',\n 'max' => 'max_call_duration',\n ],\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getRecipientsFieldData(?Team $team = null, array $value = []): array\n {\n return $this->recipientsService->getRecipientsFieldData(team: $team, value: $value);\n }\n\n public function getJiminnyRecipientsFieldData(array $value = []): array\n {\n return $this->recipientsService->getJiminnyRecipientsFieldData($value);\n }\n\n public function getAdditionalPromptInputFieldData(?string $value = null): array\n {\n return [\n 'id' => 'additional_prompt_input',\n 'label' => 'Special requirements',\n 'inputType' => InputTypeEnum::TEXTAREA,\n 'required' => false,\n 'placeholder' => 'What should be the focus of the report?',\n 'value' => $value,\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getCustomReportNameFieldData(?string $value = null): array\n {\n return [\n 'id' => 'custom_name',\n 'label' => 'Custom report name',\n 'inputType' => InputTypeEnum::TEXT,\n 'required' => false,\n 'placeholder' => 'Enter custom name',\n 'value' => $value,\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n // data providers\n public function getTeams(): array\n {\n $teams = $this->teamRepository->getTeamsForKiosk(status: Team::STATUS_ACTIVE);\n\n $teamData = [];\n foreach ($teams as $team) {\n if (! $team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {\n continue;\n }\n\n $teamData[] = $this->transformTeam($team);\n }\n\n return $teamData;\n }\n\n public function getTeamGroups(string $teamUuid): array\n {\n $data = [];\n $team = $this->getTeam($teamUuid);\n\n if ($team !== null) {\n $groups = $team->groups()->get();\n\n foreach ($groups as $group) {\n $data[] = [\n 'id' => $group->getUuid(),\n 'name' => $group->getName(),\n ];\n }\n }\n\n return $data;\n }\n\n public function getTeamsGroupsOptions(array $filterTeamUuids = []): array\n {\n $data = [];\n $teams = $this->getTeams();\n\n foreach ($teams as $team) {\n if (! empty($filterTeamUuids) && ! in_array($team['id'], $filterTeamUuids, true)) {\n continue;\n }\n\n $data[] = [\n 'label' => $team['name'],\n 'groups' => $this->getTeamGroups($team['id']),\n ];\n }\n\n return $data;\n }\n\n public function getTeam(string $teamUuid): ?Team\n {\n return $this->teamRepository->idOrUuid($teamUuid);\n }\n\n public function getTeamById(int $teamId): ?Team\n {\n return $this->teamRepository->find($teamId);\n }\n\n public function getGroupsUuids(AutomatedReport $report): array\n {\n $uuids = [];\n $reportGroups = $report->getGroups();\n foreach ($reportGroups as $groupId) {\n if ($group = $this->groupRepository->find($groupId)) {\n $uuids[] = $group->getUuid();\n }\n }\n\n return $uuids;\n }\n\n public function getPlaybookCategoriesUuids(AutomatedReport $report): array\n {\n $uuids = [];\n $playbookCategories = $report->getPlaybookCategories();\n foreach ($playbookCategories as $id) {\n if ($category = $this->playbookCategoryRepository->find($id)) {\n $uuids[] = $category->getUuid();\n }\n }\n\n return $uuids;\n }\n\n public function getDealAtCallStagesUuids(AutomatedReport $report): array\n {\n $uuids = [];\n $reportStages = $report->getDealAtCallStages();\n foreach ($reportStages as $id) {\n if ($stage = $this->stageRepository->find($id)) {\n $uuids[] = $stage->getUuid();\n }\n }\n\n return $uuids;\n }\n\n public function getCurrentDealStagesUuids(AutomatedReport $report): array\n {\n $uuids = [];\n $reportStages = $report->getCurrentDealStages();\n foreach ($reportStages as $id) {\n if ($stage = $this->stageRepository->find($id)) {\n $uuids[] = $stage->getUuid();\n }\n }\n\n return $uuids;\n }\n\n public function getUsersUuids(AutomatedReport $report): array\n {\n return $this->extractUserUuids($report->getRecipients());\n }\n\n public function getJiminnyUsersUuids(AutomatedReport $report): array\n {\n return $this->extractUserUuids($report->getJiminnyRecipients());\n }\n\n /**\n * @param array<string, mixed> $recipients\n */\n private function extractUserUuids(array $recipients): array\n {\n $userIds = $recipients['users'] ?? [];\n\n return collect($userIds)\n ->map(fn ($id) => $this->userRepository->find((int) $id))\n ->filter()\n ->map(fn (UserContract $user) => $user->getUuid())\n ->values()\n ->all();\n }\n\n // get mail data\n public function getRecipientUsers(AutomatedReport $report): array\n {\n return $this->buildRecipientUsers($report->getRecipients());\n }\n\n private function getJiminnyRecipientUsers(AutomatedReport $report): array\n {\n return $this->buildRecipientUsers($report->getJiminnyRecipients());\n }\n\n /**\n * @param array<string, mixed> $recipients\n */\n private function buildRecipientUsers(array $recipients): array\n {\n $userIds = $recipients['users'] ?? [];\n\n return collect($userIds)\n ->map(fn ($id) => $this->userRepository->find((int) $id))\n ->filter()\n ->map(fn (UserContract $user) => [\n 'email' => $user->getEmailAddress(),\n 'name' => $user->getName(),\n 'timezone' => $user->getTimezone()->getName(),\n ])\n ->values()\n ->all();\n }\n\n public function getValidRecipientUsers(AutomatedReport $report, bool $includeJiminny = false): array\n {\n if ($report->isAskJiminnyReport()) {\n $recipients = $this->resolveAskJiminnyRecipients($report);\n } else {\n $recipients = $this->getRecipientUsers($report);\n if ($includeJiminny) {\n $recipients = array_merge($recipients, $this->getJiminnyRecipientUsers($report));\n }\n }\n\n $emails = [];\n\n return array_values(array_filter(\n $recipients,\n static function ($recipient) use (&$emails) {\n if (empty($recipient['email']) || in_array($recipient['email'], $emails, true)) {\n return false;\n }\n $emails[] = $recipient['email'];\n\n return true;\n }\n ));\n }\n\n private function resolveAskJiminnyRecipients(AutomatedReport $report): array\n {\n $recipients = [];\n\n $creator = $report->getCreator();\n if ($creator !== null) {\n $recipients[] = [\n 'email' => $creator->getEmailAddress(),\n 'name' => $creator->getName(),\n 'timezone' => $creator->getTimezone()->getName(),\n ];\n }\n\n return array_merge(\n $recipients,\n $this->buildRecipientUsers($report->getRecipients()),\n $this->getGroupRecipientUsers($report),\n );\n }\n\n private function getGroupRecipientUsers(AutomatedReport $report): array\n {\n $users = [];\n foreach ($report->getGroups() as $groupId) {\n $group = $this->groupRepository->find($groupId);\n if ($group === null) {\n continue;\n }\n foreach ($group->getMembers() as $member) {\n $users[] = [\n 'email' => $member->getEmailAddress(),\n 'name' => $member->getName(),\n 'timezone' => $member->getTimezone()->getName(),\n ];\n }\n }\n\n return $users;\n }\n\n public function getReportTypeName(AutomatedReportResult $report): string\n {\n $type = $report->getReport()->getType();\n\n $getType = $this->transformReportType($type);\n\n return $getType['name'];\n }\n\n public function getReportPeriodName(AutomatedReportResult $report): string\n {\n $from = $report->getFromDate();\n $to = $report->getToDate();\n $frequency = $report->getReport()->getFrequency();\n\n if ($from === null || $to === null) {\n if (! $report->getReport()->isAskJiminnyReport()) {\n $invalidPeriod = $from === null ? 'from' : 'to';\n\n throw new ApplicationException('Report period is invalid: ' . $invalidPeriod);\n }\n\n $period = $this->calculateFromAndToDatePeriod($frequency);\n $from = $period['fromDate'];\n $to = $period['toDate'];\n }\n\n return $this->formatReportPeriodName($frequency, $from, $to);\n }\n\n private function formatReportPeriodName(string $frequency, Carbon $from, Carbon $to): string\n {\n $fromYear = $from->format('Y');\n $toYear = $to->format('Y');\n $differentYears = $fromYear !== $toYear;\n\n switch ($frequency) {\n case self::FREQUENCY_DAILY:\n return $from->format('j M Y');\n\n case self::FREQUENCY_QUARTERLY:\n // 'Jan-Mar 2025' or 'Nov 2024-Jan 2025' if years differ\n $startMonth = $from->format('M');\n $endMonth = $to->copy()->subMonth();\n $endMonthName = $endMonth->format('M');\n $endMonthYear = $endMonth->format('Y');\n\n if ($differentYears) {\n return \"{$startMonth} {$fromYear} - {$endMonthName} {$endMonthYear}\";\n }\n\n return \"{$startMonth} - {$endMonthName} {$toYear}\";\n\n case self::FREQUENCY_MONTHLY:\n // 'May 2025' - monthly reports are always within the same year\n return $from->format('M Y');\n\n case self::FREQUENCY_WEEKLY:\n // '4 - 8 Aug 2025', '27 Oct - 3 Nov 2025', or '28 Dec 2024 - 3 Jan 2025' if years differ\n $startDay = $from->format('j');\n $endDay = $to->format('j');\n $startMonth = $from->format('M');\n $endMonth = $to->format('M');\n\n if ($differentYears) {\n return \"{$startDay} {$startMonth} {$fromYear} - {$endDay} {$endMonth} {$toYear}\";\n }\n\n if ($startMonth !== $endMonth) {\n return \"{$startDay} {$startMonth} - {$endDay} {$endMonth} {$toYear}\";\n }\n\n return \"{$startDay} - {$endDay} {$endMonth} {$toYear}\";\n\n case self::FREQUENCY_ONE_OFF:\n // '2 May-31 May 2025' or '15 Dec 2024-15 Jan 2025' if years differ\n $startDay = $from->format('j');\n $startMonth = $from->format('M');\n $endDay = $to->format('j');\n $endMonth = $to->format('M');\n\n // If same month and year, use a format like '2-31 May 2025'\n if ($startMonth === $endMonth && ! $differentYears) {\n return \"{$startDay} - {$endDay} {$startMonth} {$toYear}\";\n }\n\n // If different years, include both years\n if ($differentYears) {\n return \"{$startDay} {$startMonth} {$fromYear} - {$endDay} {$endMonth} {$toYear}\";\n }\n\n // Same year but different months\n return \"{$startDay} {$startMonth} - {$endDay} {$endMonth} {$toYear}\";\n\n default:\n // Default format for unknown frequencies\n return $from->format('j M Y') . ' - ' . $to->format('j M Y');\n }\n }\n\n public function getReportTeamsName(AutomatedReportResult $report): string\n {\n $groups = $report->getGroups();\n\n if (empty($groups)) {\n return 'All';\n }\n\n // Get group names from repository\n $groupNames = [];\n foreach ($groups as $groupId) {\n $group = $this->groupRepository->find($groupId);\n if ($group) {\n $groupNames[] = $group->getName();\n }\n }\n\n if (count($groupNames) === 1) {\n // Single team format\n $teamsName = $groupNames[0];\n } else {\n // Multiple teams format\n $teamsName = implode(', ', $groupNames);\n }\n\n return $teamsName;\n }\n\n public function getReportFileName(AutomatedReportResult $report): string\n {\n $customName = $report->getReport()->getCustomName();\n $periodName = $this->getReportPeriodName($report);\n $filenameSuffix = $this->getFilenameSuffix($report);\n\n if ($customName) {\n if ($filenameSuffix) {\n $customName .= \" {$filenameSuffix}\";\n }\n\n return $this->sanitizeFileName(\"{$customName} - {$periodName}\");\n }\n\n $baseName = $this->getReportTypeName($report);\n\n if ($filenameSuffix) {\n $baseName .= \" {$filenameSuffix}\";\n }\n\n return $this->sanitizeFileName(\"{$baseName} - {$periodName} - {$this->getReportTeamsName($report)}\");\n }\n\n public function getReportFileNameWithExtension(AutomatedReportResult $result): string\n {\n $extension = $this->getMediaTypeMetadata($result)['extension'];\n\n return $this->getReportFileName($result) . '.' . $extension;\n }\n\n public function sanitizeFileName(string $fileName): string\n {\n return str_replace(['/', '\\\\'], '-', $fileName);\n }\n\n public function isUserRecipientOfReport(User $user, AutomatedReport $report): bool\n {\n $recipients = array_map('intval', $report->getRecipients()['users'] ?? []);\n\n return in_array($user->getId(), $recipients);\n }\n\n public function transformReportResults(Collection $automatedReportResults): array\n {\n $data = [];\n foreach ($automatedReportResults as $automatedReportResult) {\n /** @var AutomatedReportResult $automatedReportResult */\n\n $report = $automatedReportResult->getReport();\n\n $createdBy = $report->getCreator();\n $creator = [\n 'id' => $createdBy?->getUuid(),\n 'name' => $createdBy?->getName(),\n 'email' => $createdBy?->getEmailAddress(),\n 'photoUrl' => $createdBy?->getPhotoUrl(),\n ];\n\n $data[] = [\n 'id' => $automatedReportResult->getUuid(),\n 'name' => $automatedReportResult->getName(),\n 'frequency' => $this->transformFrequency($report->getFrequency()),\n 'recipients' => [\n ...array_values($this->transformGroups(team: $report->getTeam(), groupsIds: $report->getGroups())),\n ...array_values($this->transformRecipients($report->getRecipients())),\n ],\n 'report_type' => $this->transformReportType($report->getType()),\n 'media_type' => $automatedReportResult->getMediaType(),\n 'downloadUrl' => $this->generateReportResultDownloadUrl($automatedReportResult),\n 'viewUrl' => $this->generateReportResultViewUrl($automatedReportResult),\n 'generated_at' => $automatedReportResult->getGeneratedAt()?->toIso8601String(),\n 'creator' => $creator,\n ];\n }\n\n return $data;\n }\n\n public function hasCallTypeConference(AutomatedReport $report): bool\n {\n return in_array(self::CALL_TYPE_CONFERENCE['id'], $report->getCallTypes(), true);\n }\n\n public function hasCallTypeDialer(AutomatedReport $report): bool\n {\n return in_array(self::CALL_TYPE_DIALER['id'], $report->getCallTypes(), true);\n }\n\n // transformers\n private function transformTeam(Team $team): array\n {\n if (! $team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {\n return [];\n }\n\n return [\n 'id' => $team->getUuid(),\n 'name' => $team->getName(),\n ];\n }\n\n private function transformReportFullView(AutomatedReport $report): array\n {\n $base = $this->transformReportBase($report);\n\n return $report->getType() === self::TYPE_ASK_JIMINNY\n ? $base + $this->transformAskJiminnyFields($report)\n : $base + $this->transformStandardReportFields($report);\n }\n\n private function transformReportBase(AutomatedReport $report): array\n {\n return [\n 'id' => $report->getUuid(),\n 'organization' => $this->transformOrganization(team: $report->getTeam()),\n 'report_type' => $this->transformReportType($report->getType()),\n 'frequency' => $this->transformFrequency($report->getFrequency()),\n ];\n }\n\n private function transformStandardReportFields(AutomatedReport $report): array\n {\n $team = $report->getTeam();\n\n return [\n 'report_enabled' => $report->getStatus(),\n 'start_date_period' => $report->getFrom()?->format('Y-m-d H:i:s'),\n 'end_date_period' => $report->getTo()?->format('Y-m-d H:i:s'),\n 'deal_value_min' => $report->getDealValueMin(),\n 'deal_value_max' => $report->getDealValueMax(),\n 'call_types' => $this->transformCallType($report->getCallTypes()),\n 'media_types' => $this->transformMediaTypes($report),\n 'call_duration_min' => $this->transformDurationToMinutes($report->getCallDurationMin()),\n 'call_duration_max' => $this->transformDurationToMinutes($report->getCallDurationMax()),\n 'teams' => $this->transformGroups(team: $team, groupsIds: $report->getGroups()),\n 'deal_at_call_stages' => $this->transformStages(team: $team, stagesIds: $report->getDealAtCallStages()),\n 'current_deal_stages' => $this->transformStages(team: $team, stagesIds: $report->getCurrentDealStages()),\n 'recipients' => $this->transformRecipients($report->getRecipients()),\n 'created_by' => $this->transformCreator($report->getCreator()),\n 'additional_prompt_input' => $report->getAdditionalPromptInput(),\n 'custom_name' => $report->getCustomName(),\n 'created_at' => $report->getCreatedAt()->format('Y-m-d H:i:s'),\n 'updated_at' => $report->getUpdatedAt()->format('Y-m-d H:i:s'),\n 'deleted_at' => $report->getDeletedAt()?->format('Y-m-d H:i:s'),\n ];\n }\n\n private function transformAskJiminnyFields(AutomatedReport $report): array\n {\n $team = $report->getTeam();\n $creatorId = $report->getAttribute('created_by');\n $explicitUserIds = array_values(array_filter(\n $report->getRecipients()['users'] ?? [],\n static fn ($id) => $id !== $creatorId\n ));\n\n return [\n 'report_name' => $report->getCustomName(),\n 'enabled' => $report->getStatus(),\n 'share_teams' => $this->transformGroups(team: $team, groupsIds: $report->getGroups()),\n 'share_users' => $this->transformRecipients(['users' => $explicitUserIds]),\n 'saved_search' => $this->transformSafeSearch($report->getSavedSearch()),\n 'ask_jiminny_prompt' => $this->transformAskJiminnyPrompt($report->getAskAnythingPrompt()),\n 'expires_on' => $report->getExpiresAt()?->format('Y-m-d'),\n ];\n }\n\n private function transformOrganization(?Team $team): array\n {\n return [\n 'id' => $team?->getUuid(),\n 'name' => $team?->getName(),\n ];\n }\n\n private function transformReportType(string $type): array\n {\n foreach (self::ALL_TYPES as $typeItem) {\n if ($typeItem['id'] === $type) {\n return $typeItem;\n }\n }\n\n return [];\n }\n\n private function transformCallType(array $types): array\n {\n $result = [];\n $callTypes = [self::CALL_TYPE_CONFERENCE, self::CALL_TYPE_DIALER];\n\n foreach ($types as $type) {\n foreach ($callTypes as $callTypeItem) {\n if ($callTypeItem['id'] === $type) {\n $result[] = $callTypeItem;\n\n break;\n }\n }\n }\n\n return $result;\n }\n\n private function transformMediaTypes(AutomatedReport $report): array\n {\n $values = [];\n\n foreach ($report->getMediaTypes() as $mediaType) {\n if (! in_array($mediaType, self::MEDIA_TYPES, true)) {\n continue;\n }\n\n $values[] = match ($mediaType) {\n self::MEDIA_TYPE_PDF => self::MEDIA_TYPE_OBJECT_PDF,\n self::MEDIA_TYPE_PODCAST => self::MEDIA_TYPE_OBJECT_PODCAST,\n };\n }\n\n return $values;\n }\n\n private function transformFrequency(string $frequency): array\n {\n foreach (self::ALL_FREQUENCIES as $frequencyItem) {\n if ($frequencyItem['id'] === $frequency) {\n return $frequencyItem;\n }\n }\n\n return [];\n }\n\n public function transformDurationToMinutes(?int $duration): ?int\n {\n if (! $duration) {\n return null;\n }\n\n return (int) ($duration / 60);\n }\n\n private function transformGroups(?Team $team, array $groupsIds): array\n {\n if (empty($groupsIds) || ! $team) {\n return [];\n }\n\n $data = [];\n foreach ($groupsIds as $groupId) {\n $group = $team->groups()->where('id', $groupId)->first();\n\n if ($group) {\n $data[] = [\n 'id' => $group->getUuid(),\n 'name' => $group->getName(),\n 'photoUrl' => $group->getPhotoUrl(),\n ];\n }\n }\n\n return $data;\n }\n\n private function transformStages(?Team $team, array $stagesIds): array\n {\n if (empty($stagesIds) || ! $team) {\n return [];\n }\n\n $data = [];\n foreach ($stagesIds as $stageId) {\n $stage = $team->stages()->where('id', $stageId)->first();\n\n if ($stage) {\n $data[] = [\n 'id' => $stage->getUuid(),\n 'name' => $stage->getName(),\n ];\n }\n }\n\n return $data;\n }\n\n private function transformRecipients(array $recipients): array\n {\n $users = [];\n foreach ($recipients['users'] ?? [] as $userId) {\n $users[] = $this->transformUser($userId);\n }\n\n return $users;\n }\n\n private function transformCreator(?User $user): ?array\n {\n if ($user === null) {\n return null;\n }\n\n return $this->transformUser($user->getId());\n }\n\n private function transformAskJiminnyPrompt(?AskAnythingPrompt $prompt): ?array\n {\n if ($prompt === null) {\n return null;\n }\n\n return [\n 'id' => $prompt->getUuid(),\n 'name' => $prompt->getTitle(),\n ];\n }\n\n private function transformSafeSearch(?Search $search): ?array\n {\n if ($search === null) {\n return null;\n }\n\n return [\n 'id' => $search->getUuid(),\n 'name' => $search->getName(),\n ];\n }\n\n private function transformUser(int $userId): array\n {\n /* @var ?User $user */\n $user = $this->userRepository->find($userId);\n\n return [\n 'id' => $user?->getUuid(),\n 'name' => $user?->getName(),\n 'email' => $user?->getEmailAddress(),\n 'photoUrl' => $user?->getPhotoUrl(),\n ];\n }\n\n public function create(array $data): array\n {\n $validatedData = $this->validateAndTransformData($data);\n $validatedData['created_by'] = auth()->id();\n\n $automatedReport = $this->automatedReportsRepository->create($validatedData);\n\n $this->generateOneOffReport($automatedReport);\n\n return $this->transformReportFullView($automatedReport);\n }\n\n public function update(string $uuid, array $data): array\n {\n $validatedData = $this->validateAndTransformData($data);\n $report = $this->automatedReportsRepository->findByUuid($uuid);\n\n if (! $report) {\n throw new InvalidArgumentException('Report not found');\n }\n\n $oldCustomName = $report->getCustomName();\n\n $automatedReport = $this->automatedReportsRepository->update($report, $validatedData);\n\n if ($oldCustomName !== $automatedReport->getCustomName()) {\n $this->updateResultNames($automatedReport);\n }\n\n $this->generateOneOffReport($automatedReport);\n\n return $this->transformReportFullView($automatedReport);\n }\n\n /**\n * Create an Ask Jiminny report.\n */\n public function createAskJiminnyReport(array $data, User $creator): array\n {\n $validatedData = $this->validateAskJiminnyReportData($data, $creator);\n $validatedData['created_by'] = $creator->getId();\n\n $automatedReport = $this->automatedReportsRepository->create($validatedData);\n\n return $this->transformReportFullView($automatedReport);\n }\n\n /**\n * Update an Ask Jiminny report.\n */\n public function updateAskJiminnyReport(AutomatedReport $report, array $data, User $user): array\n {\n if (! $report->isAskJiminnyReport()) {\n throw new InvalidArgumentException('Report is not an Ask Jiminny report');\n }\n\n $validatedData = $this->validateAskJiminnyReportData($data, $user);\n\n $oldCustomName = $report->getCustomName();\n\n $automatedReport = $this->automatedReportsRepository->update($report, $validatedData);\n\n if ($oldCustomName !== $automatedReport->getCustomName()) {\n $this->updateResultNames($automatedReport);\n }\n\n return $this->transformReportFullView($automatedReport);\n }\n\n public function updateAskJiminnyReportStatus(AutomatedReport $report, bool $status): array\n {\n $this->automatedReportsRepository->update($report, ['status' => $status]);\n\n return $this->transformReportFullView($report->fresh());\n }\n\n /**\n * Validate and transform data for Ask Jiminny reports.\n */\n private function validateAskJiminnyReportData(array $data, User $user): array\n {\n // Validate name\n $name = trim($data['report_name'] ?? '');\n if (empty($name)) {\n throw new InvalidArgumentException('Report name is required');\n }\n if (mb_strlen($name) > 50) {\n throw new InvalidArgumentException('Report name must be 50 characters or less');\n }\n\n // Validate frequency (only daily, weekly, monthly for Ask Jiminny)\n $frequency = $data['frequency'] ?? null;\n $askJiminnyFrequencies = [self::FREQUENCY_DAILY, self::FREQUENCY_WEEKLY, self::FREQUENCY_MONTHLY];\n if (! in_array($frequency, $askJiminnyFrequencies, true)) {\n throw new InvalidArgumentException('Frequency must be daily, weekly, or monthly');\n }\n\n // Validate expiration date\n $expiresAt = $data['expires_on'] ?? null;\n if (empty($expiresAt)) {\n throw new InvalidArgumentException('Expiration date is required');\n }\n\n try {\n $expiresAtDate = Carbon::parse($expiresAt);\n } catch (InvalidFormatException $e) {\n throw new InvalidArgumentException('Expiration date format is invalid');\n }\n $maxExpiration = Carbon::now()->addYear();\n if ($expiresAtDate->gt($maxExpiration)) {\n throw new InvalidArgumentException('Expiration date cannot be more than 1 year from now');\n }\n if ($expiresAtDate->isPast()) {\n throw new InvalidArgumentException('Expiration date cannot be in the past');\n }\n\n // Validate saved search\n $activitySearchId = $data['saved_search'] ?? null;\n if (empty($activitySearchId)) {\n throw new InvalidArgumentException('Saved search is required');\n }\n $savedSearch = $this->activitySearchRepository->findByUuidAndUser($activitySearchId, $user);\n if (! $savedSearch) {\n throw new InvalidArgumentException('Saved search not found or does not belong to you');\n }\n\n // Validate saved prompt\n $askAnythingPromptId = $data['ask_jiminny_prompt'] ?? null;\n if (empty($askAnythingPromptId)) {\n throw new InvalidArgumentException('Ask Jiminny prompt is required');\n }\n $prompt = $this->askAnythingRepository->getPromptByUuid($askAnythingPromptId);\n if (! $prompt) {\n throw new InvalidArgumentException('Ask Jiminny prompt not found');\n }\n\n // Validate status\n $status = $data['enabled'] ?? false;\n\n $recipientUserIds = [$user->getId()];\n\n if (! empty($data['share_users'])) {\n $sharedUserIds = $this->validateAndGetUserIdsByTeam(\n $user->team,\n (array) $data['share_users']\n );\n $recipientUserIds = array_merge($recipientUserIds, $sharedUserIds);\n }\n\n $sharedGroupIds = [];\n if (! empty($data['share_teams'])) {\n $sharedGroupIds = $this->validateAndGetGroupIds($user->team, (array) $data['share_teams']);\n }\n\n $recipientUserIds = array_values(array_unique($recipientUserIds));\n\n return [\n 'team_id' => $user->getTeamId(),\n 'type' => self::TYPE_ASK_JIMINNY,\n 'status' => (bool) $status,\n 'frequency' => $frequency,\n 'custom_name' => $name,\n 'activity_search_id' => $savedSearch->getId(),\n 'ask_anything_prompt_id' => $prompt->getId(),\n 'expires_at' => $expiresAtDate->toDateString(),\n 'media_types' => [self::MEDIA_TYPE_PDF],\n 'call_types' => [],\n 'recipients' => ['users' => $recipientUserIds],\n 'groups' => $sharedGroupIds,\n ];\n }\n\n public static function getAskJiminnyFrequencies(): array\n {\n return array_map(static function ($frequency) {\n return $frequency['id'];\n }, self::ASK_JIMINNY_FREQUENCIES);\n }\n\n public function getAskJiminnyReportFilters(User $user): array\n {\n $savedSearches = $this->activitySearchRepository->findByUserOrderedByName($user)\n ->map(fn (Search $search) => [\n 'id' => $search->getUuid(),\n 'name' => $search->getName(),\n ])\n ->values()->all();\n\n $prompts = collect(\n $this->askAnythingPromptService->get($user, AskAnythingPromptTarget::on_demand)\n )->map(fn (AskAnythingPromptDto $prompt) => [\n 'id' => $prompt->id,\n 'name' => $prompt->title,\n ])->values()->all();\n\n return [\n [\n 'id' => 'prompt',\n 'label' => 'Prompt',\n 'options' => $prompts,\n ],\n [\n 'id' => 'saved_search',\n 'label' => 'Saved Search',\n 'options' => $savedSearches,\n ],\n ];\n }\n\n public function getAskJiminnyReportFormData(User $user, ?AutomatedReport $report = null): array\n {\n $team = $user->getTeam();\n $userTimezone = $user->getTimezone();\n\n $savedSearches = $this->activitySearchRepository->findByUserOrderedByName($user)\n ->map(fn (Search $search) => [\n 'id' => $search->getUuid(),\n 'name' => $search->getName(),\n ])\n ->values()->all();\n\n $prompts = collect(\n $this->askAnythingPromptService->get($user, AskAnythingPromptTarget::on_demand)\n )->map(fn (AskAnythingPromptDto $prompt) => [\n 'id' => $prompt->id,\n 'name' => $prompt->title,\n ])->values()->all();\n\n $teamGroups = $this->groupRepository->getAllByTeam($team)->map(fn ($group) => [\n 'id' => $group->getUuid(),\n 'name' => $group->getName(),\n ])->values()->all();\n\n $shareUsers = $this->recipientsService->getRecipientsFieldData(team: $team)['options'] ?? [];\n\n $sharedTeamsValue = [];\n $sharedUsersValue = [];\n if ($report) {\n $sharedTeamsValue = $this->transformGroups($team, $report->getGroups());\n\n $recipientUserIds = $report->getRecipients()['users'] ?? [];\n $creatorId = $report->getAttribute('created_by');\n $sharedUserIds = array_values(array_filter(\n $recipientUserIds,\n static fn ($id) => $id !== $creatorId\n ));\n $sharedUsersValue = collect($sharedUserIds)\n ->map(fn ($id) => $this->userRepository->find((int) $id))\n ->filter()\n ->map(fn (User $u) => [\n 'id' => $u->getUuid(),\n 'name' => $u->getName(),\n ])\n ->values()\n ->all();\n }\n\n return [\n 'fields' => [\n [\n 'id' => 'enabled',\n 'inputType' => InputTypeEnum::TOGGLE,\n 'label' => '',\n 'value' => $report?->getStatus() ?? false,\n ],\n [\n 'id' => 'report_name',\n 'inputType' => InputTypeEnum::TEXT,\n 'label' => 'Name',\n 'placeholder' => 'Enter name',\n 'required' => true,\n 'validation' => ['maxLength' => 50],\n 'value' => $report?->getCustomName() ?? '',\n ],\n [\n 'id' => 'frequency',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'label' => 'Frequency',\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => self::ASK_JIMINNY_FREQUENCIES,\n 'value' => $report ? $this->transformFrequency($report->getFrequency()) : null,\n ],\n [\n 'id' => 'expires_on',\n 'inputType' => InputTypeEnum::DATE,\n 'label' => 'Expires on',\n 'required' => true,\n 'placeholder' => 'Select',\n 'validation' => [\n 'minDate' => now($userTimezone)->toDateString(),\n 'maxDate' => now($userTimezone)->addYear()->toDateString(),\n ],\n 'value' => $report?->getExpiresAt()?->toDateString(),\n ],\n [\n 'id' => 'share_teams',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'label' => 'Team',\n 'required' => false,\n 'placeholder' => 'Select',\n 'options' => $teamGroups,\n 'value' => $sharedTeamsValue,\n ],\n [\n 'id' => 'share_users',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'label' => 'Team member',\n 'required' => false,\n 'placeholder' => 'Select',\n 'groupLabelKey' => 'label',\n 'groupValuesKey' => 'users',\n 'optionLabelKey' => 'name',\n 'optionValueKey' => 'id',\n 'options' => $shareUsers,\n 'value' => $sharedUsersValue,\n ],\n [\n 'id' => 'saved_search',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'label' => 'Saved search',\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => $savedSearches,\n 'value' => $report && $report->getSavedSearch() ? [\n 'id' => $report->getSavedSearch()->getUuid(),\n 'name' => $report->getSavedSearch()->getName(),\n ] : null,\n ],\n [\n 'id' => 'ask_jiminny_prompt',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'label' => 'Ask Jiminny prompt',\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => $prompts,\n 'value' => $report && $report->getAskAnythingPrompt() ? [\n 'id' => $report->getAskAnythingPrompt()->getUuid(),\n 'name' => $report->getAskAnythingPrompt()->getTitle(),\n ] : null,\n ],\n ],\n ];\n }\n\n private function updateResultNames(AutomatedReport $automatedReport): void\n {\n $results = $this->automatedReportsRepository->getResultsByReport($automatedReport);\n\n foreach ($results as $result) {\n $result->update(['name' => $this->getReportFileName($result)]);\n }\n }\n\n public function updateStatus(string $uuid, array $data): array\n {\n $automatedReport = $this->automatedReportsRepository->findByUuid($uuid);\n\n if (! $automatedReport) {\n throw new ModelNotFoundException('Report not found');\n }\n\n $status = $this->validateReportStatus($data['report_enabled'] ?? null);\n $automatedReport->update([\n 'status' => $status,\n ]);\n\n $this->generateOneOffReport($automatedReport);\n\n return $this->transformReportFullView($automatedReport);\n }\n\n private function generateOneOffReport(AutomatedReport $automatedReport): void\n {\n // the scheduler handles all the other frequency types\n if ($automatedReport->getStatus() === false || $automatedReport->getFrequency() !== self::FREQUENCY_ONE_OFF) {\n return;\n }\n\n $this->dispatcher->dispatch(new RequestGenerateReportJob($automatedReport->getUuid()));\n }\n\n public function getReport(string $uuid): AutomatedReport\n {\n $automatedReport = $this->automatedReportsRepository->findByUuid($uuid);\n\n if (! $automatedReport) {\n throw new ModelNotFoundException('Report not found');\n }\n\n return $automatedReport;\n }\n\n public function get(string $uuid): array\n {\n $automatedReport = $this->getReport($uuid);\n\n return $this->transformReportFullView($automatedReport);\n }\n\n public function list(string $sortColumn = 'created_at', string $sortDirection = 'desc'): array\n {\n $results = [];\n $collection = $this->automatedReportsRepository->getAllStandardReports($sortColumn, $sortDirection);\n\n /** @var AutomatedReport $report */\n foreach ($collection as $report) {\n $results[] = $this->transformReportFullView($report);\n }\n\n return ['data' => $results];\n }\n\n public function listAskJiminnyReports(\n User $user,\n string $sortColumn = 'created_at',\n string $sortDirection = 'desc'\n ): array {\n $results = [];\n $collection = $this->automatedReportsRepository->getAskJiminnyReportsByUser($user, $sortColumn, $sortDirection);\n\n /** @var AutomatedReport $report */\n foreach ($collection as $report) {\n $results[] = $this->transformReportFullView($report);\n }\n\n return ['data' => $results];\n }\n\n public function delete(string $uuid): void\n {\n $automatedReport = $this->automatedReportsRepository->findByUuid($uuid);\n\n if (! $automatedReport) {\n throw new ModelNotFoundException('Report not found');\n }\n\n $automatedReport->delete();\n }\n\n public function createReportResult(AutomatedReport $automatedReport, array $data = []): AutomatedReportResult\n {\n return $this->automatedReportsRepository->createResult(\n array_merge(\n [\n 'report_id' => $automatedReport->getId(),\n 'status' => AutomatedReportResult::STATUS_DEFAULT,\n ],\n $data\n )\n );\n }\n\n public function getReportResult(string $resultUuid): AutomatedReportResult\n {\n $report = $this->automatedReportsRepository->findResultByUuid($resultUuid);\n\n if (! $report) {\n throw new ModelNotFoundException('Report Result not found');\n }\n\n return $report;\n }\n\n public function findChildResult(AutomatedReportResult $result, string $type): ?AutomatedReportResult\n {\n return $this->automatedReportsRepository->findChildResult($result, $type);\n }\n\n // prophet API calls\n /**\n * @throws ApplicationException\n */\n public function getGenerateReportPayload(AutomatedReport $automatedReport, string $reportResultUuid): array\n {\n $period = $this->calculateFromAndToDate($automatedReport);\n $fromDate = $period['fromDate'];\n $toDate = $period['toDate'];\n\n return [\n 'team_id' => $automatedReport->getTeamId(),\n 'request_id' => $reportResultUuid,\n 'report_type' => $automatedReport->getType(),\n 'media_types' => $automatedReport->getMediaTypes(),\n 'from_date' => $fromDate->startOfDay()->format(DateTimeInterface::RFC3339),\n 'to_date' => $toDate->endOfDay()->format(DateTimeInterface::RFC3339),\n 'group_ids' => $automatedReport->getGroups(),\n 'call_deal_stage' => $automatedReport->getDealAtCallStages(),\n 'current_deal_stage' => $automatedReport->getCurrentDealStages(),\n 'deal_min_value' => $automatedReport->getDealValueMin(),\n 'deal_max_value' => $automatedReport->getDealValueMax(),\n 'call_types' => $automatedReport->getCallTypes(),\n 'call_duration_min_seconds' => $automatedReport->getCallDurationMin(),\n 'call_duration_max_seconds' => $automatedReport->getCallDurationMax(),\n 'special_requirements' => $automatedReport->getAdditionalPromptInput(),\n 'callback_url' => $this->getCallbackUrl(),\n 'report_period' => $this->formatReportPeriodName(\n $automatedReport->getFrequency(),\n $fromDate,\n $toDate,\n ),\n 'playbook_categories' => $automatedReport->getPlaybookCategories(),\n 'custom_name' => $automatedReport->getCustomName(),\n ];\n }\n\n // $inputPayload - FE payload structure\n public function getActivitiesCountPayload(array $inputPayload): array\n {\n // Use validateAndTransformData to validate and normalize input\n $validatedData = $this->validateAndTransformData($inputPayload);\n $period = $this->calculateFromAndToDatePeriod(\n $validatedData['frequency'],\n Carbon::parse($validatedData['from']),\n Carbon::parse($validatedData['to']),\n );\n $fromDate = $period['fromDate'];\n $toDate = $period['toDate'];\n\n // Create payload similar to getGenerateReportPayload\n return [\n 'team_id' => $validatedData['team_id'],\n 'group_ids' => $validatedData['groups'] ?? [],\n 'report_type' => $validatedData['type'],\n 'from_date' => $fromDate->format(DateTimeInterface::RFC3339),\n 'to_date' => $toDate->format(DateTimeInterface::RFC3339),\n 'call_deal_stage' => $validatedData['deal_at_call_stages'] ?? [],\n 'current_deal_stage' => $validatedData['current_deal_stages'] ?? [],\n 'deal_min_value' => $validatedData['deal_value_min'] ?? null,\n 'deal_max_value' => $validatedData['deal_value_max'] ?? null,\n 'call_types' => $validatedData['call_types'],\n 'call_duration_min_seconds' => $validatedData['call_duration_min'] ?? null,\n 'call_duration_max_seconds' => $validatedData['call_duration_max'] ?? null,\n 'special_requirements' => $validatedData['additional_prompt_input'] ?? null,\n 'playbook_categories' => $validatedData['playbook_categories'] ?? [],\n 'request_id' => null,\n 'callback_url' => null,\n ];\n }\n\n public function shouldSendReport(array $users, ?CarbonInterface $generatedAt = null): bool\n {\n if (empty($users)) {\n return false;\n }\n\n $earliestTz = collect($users)\n ->mapWithKeys(function (array $user) {\n $tz = new DateTimeZone($user['timezone']);\n $nowUtc = new DateTime('now', new DateTimeZone('UTC'));\n $offset = $tz->getOffset($nowUtc);\n\n return [$user['timezone'] => $offset];\n })\n ->sortDesc()\n ->keys()\n ->first();\n\n $now = Carbon::now($earliestTz);\n $isScheduledTime = (int) $now->format('H') === self::SENT_REPORT_AT_HOURS;\n\n if ($isScheduledTime) {\n return true;\n }\n\n return $this->hasPassedScheduledTime($generatedAt, $earliestTz);\n }\n\n public function hasPassedScheduledTime(?CarbonInterface $generatedAt, string $timezone): bool\n {\n if ($generatedAt === null) {\n return false;\n }\n\n $now = Carbon::now($timezone);\n $scheduledTime = $now->copy()->setTime(self::SENT_REPORT_AT_HOURS, 0, 0);\n\n if ($now->hour < self::SENT_REPORT_AT_HOURS) {\n $scheduledTime = $scheduledTime->subDay();\n }\n\n $scheduledTimeUtc = $scheduledTime->copy()->utc();\n $generatedAtUtc = $generatedAt->copy()->utc();\n $nowUtc = $now->copy()->utc();\n\n return $generatedAtUtc->lt($scheduledTimeUtc) && $nowUtc->gt($scheduledTimeUtc);\n }\n\n public function calculateFromAndToDatePeriod(\n string $frequency,\n ?Carbon $fromDate = null,\n ?Carbon $toDate = null\n ): array {\n if ($frequency === self::FREQUENCY_ONE_OFF) {\n return [\n 'fromDate' => $fromDate,\n 'toDate' => $toDate,\n ];\n }\n\n $now = Carbon::now();\n\n return match ($frequency) {\n self::FREQUENCY_DAILY => [\n 'fromDate' => $now->copy()->subDay()->startOfDay(),\n 'toDate' => $now->copy()->subDay()->endOfDay(),\n ],\n self::FREQUENCY_WEEKLY => [\n 'fromDate' => $now->copy()->subWeeks(1)->startOfDay(),\n 'toDate' => $now->copy()->subDay()->endOfDay(),\n ],\n self::FREQUENCY_MONTHLY => [\n 'fromDate' => $now->copy()->subMonths(1)->startOfDay(),\n 'toDate' => $now->copy()->subDay()->endOfDay(),\n ],\n self::FREQUENCY_QUARTERLY => [\n 'fromDate' => $now->copy()->subMonths(3)->startOfDay(),\n 'toDate' => $now->copy()->subDay()->endOfDay(),\n ],\n default => throw new InvalidArgumentException(\"Unsupported frequency: {$frequency}\"),\n };\n }\n\n private function calculateFromAndToDate(AutomatedReport $automatedReport): array\n {\n return $this->calculateFromAndToDatePeriod(\n $automatedReport->getFrequency(),\n $automatedReport->getFrom(),\n $automatedReport->getTo()\n );\n }\n\n public function getAskJiminnyGenerateReportPayload(\n AutomatedReport $automatedReport,\n AutomatedReportResult $reportResult,\n array $activityIds,\n ): array {\n return [\n 'user_question' => $automatedReport->getAskAnythingPrompt()?->getContent(),\n 'call_ids' => array_map('strval', $activityIds),\n 'team_id' => $automatedReport->getTeamId(),\n 'request_id' => $reportResult->getUuid(),\n 'callback_url' => $this->getCallbackUrl(),\n 'report_period' => $this->getReportPeriodName($reportResult),\n 'report_name' => $automatedReport->getCustomName(),\n ];\n }\n\n private function getCallbackUrl(): string\n {\n return $this->webhookService->route('jiminny.webhook.reports.ready');\n }\n\n /**\n * Validate and transform payload data for automated reports\n *\n * @param array $data\n *\n * @throws InvalidArgumentException\n *\n * @return array\n */\n private function validateAndTransformData(array $data): array\n {\n // Validate organization (team) and check feature\n $team = $this->validateOrganization($data['organization'] ?? null);\n\n $status = $this->validateReportStatus($data['report_enabled'] ?? null);\n $type = $this->validateReportType($data['report_type'] ?? null);\n $frequency = $this->validateFrequency($data['frequency'] ?? null);\n $additionalPromptInput = $this->validateAdditionalPromptInput(\n $data['additional_prompt_input'] ?? null\n );\n $customReportName = $this->validateCustomReportName($data['custom_name'] ?? null);\n\n // Prepare data for the database\n $reportData = [\n 'team_id' => $team->getId(),\n 'type' => $type,\n 'status' => $status,\n 'frequency' => $frequency,\n 'additional_prompt_input' => $additionalPromptInput,\n 'custom_name' => $customReportName,\n ];\n\n // Validate deal values\n $reportData = $this->validateDealValues($data, $reportData);\n\n // Validate date range\n $reportData = $this->validateDateRange($data, $reportData, $frequency);\n\n // Validate call durations\n $reportData = $this->validateCallDurations($data, $reportData);\n\n // Validate call types\n $reportData = $this->validateCallTypes($data, $reportData);\n\n // Validate media types\n $reportData = $this->validateMediaTypes($data, $reportData);\n\n // Validate groups\n if (isset($data['teams'])) {\n $reportData['groups'] = $this->validateAndGetGroupIds($team, $data['teams']);\n }\n\n // Validate deal stages\n $reportData = $this->validateDealStages($data, $reportData, $team, $type);\n\n // Validate playbook categories\n $reportData = $this->validatePlaybookCategories($data, $reportData, $team);\n\n // Validate recipients\n $reportData['recipients'] = [\n 'users' => $this->validateAndGetUserIdsByTeam($team, $data['recipients'] ?? []),\n ];\n\n if (isset($data['jiminny_recipients'])) {\n // Validate Jiminny recipients\n $reportData['jiminny_recipients'] = [\n 'users' => $this->validateAndGetJiminnyUserIds((array) $data['jiminny_recipients']),\n ];\n }\n\n return $reportData;\n }\n\n private function validateDealValues(array $data, array $reportData): array\n {\n if (isset($data['min_deal_value'])) {\n $reportData['deal_value_min'] = (int) $data['min_deal_value'];\n\n if ($reportData['deal_value_min'] > 4294967295 || $reportData['deal_value_min'] < 0) {\n throw new InvalidArgumentException('Min deal value should be between 0 and 4294967295');\n }\n }\n\n if (isset($data['max_deal_value'])) {\n $reportData['deal_value_max'] = (int) $data['max_deal_value'];\n\n if ($reportData['deal_value_max'] > 4294967295 || $reportData['deal_value_max'] < 0) {\n throw new InvalidArgumentException('Max deal value should be between 0 and 4294967295');\n }\n }\n\n if (isset($data['min_deal_value'], $data['max_deal_value'])\n && $data['min_deal_value'] > $data['max_deal_value']\n ) {\n throw new InvalidArgumentException('Min deal value cannot be greater than max deal value');\n }\n\n return $reportData;\n }\n\n private function validateDateRange(array $data, array $reportData, string $frequency): array\n {\n // Set date range only for one_off frequency\n if ($frequency === 'one_off') {\n if (isset($data['start_date_period'])) {\n $reportData['from'] = $this->parseDate($data['start_date_period']);\n }\n\n if (isset($data['end_date_period'])) {\n $reportData['to'] = $this->parseDate($data['end_date_period']);\n }\n\n if (empty($reportData['from']) || empty($reportData['to'])) {\n throw new InvalidArgumentException(\n 'Start date and end date are required for one_off frequency'\n );\n }\n } else {\n $reportData['from'] = null;\n $reportData['to'] = null;\n }\n\n return $reportData;\n }\n\n private function validateCallDurations(array $data, array $reportData): array\n {\n // Convert call durations from minutes to seconds\n if (isset($data['min_call_duration'])) {\n $reportData['call_duration_min'] = (int) $data['min_call_duration'] * 60;\n\n if ($reportData['call_duration_min'] > 4294967295 || $reportData['call_duration_min'] < 0) {\n throw new InvalidArgumentException('Min call duration should be between 0 and 4294967295');\n }\n }\n\n if (isset($data['max_call_duration'])) {\n $reportData['call_duration_max'] = (int) $data['max_call_duration'] * 60;\n\n if ($reportData['call_duration_max'] > 4294967295 || $reportData['call_duration_max'] < 0) {\n throw new InvalidArgumentException('Max call duration should be between 0 and 4294967295');\n }\n }\n\n return $reportData;\n }\n\n private function validateCallTypes(array $data, array $reportData): array\n {\n // Set call types\n $reportData['call_types'] = $data['call_type'] ?? [];\n if (empty($reportData['call_types'])) {\n $reportData['call_types'] = self::getCallTypes();\n }\n\n foreach ($reportData['call_types'] as $callType) {\n if (! in_array($callType, self::getCallTypes(), true)) {\n throw new InvalidArgumentException(sprintf('Call type %s is invalid', $callType));\n }\n }\n\n return $reportData;\n }\n\n private function validateMediaTypes(array $data, array $reportData): array\n {\n // Set media types from input data\n $reportData['media_types'] = $data['media_types'] ?? [];\n\n if (empty($reportData['media_types'])) {\n throw new InvalidArgumentException('Media types are required');\n }\n\n foreach ($reportData['media_types'] as $mediaType) {\n if (! in_array($mediaType, self::MEDIA_TYPES, true)) {\n throw new InvalidArgumentException(sprintf('Media type %s is invalid', $mediaType));\n }\n }\n\n return $reportData;\n }\n\n private function validateDealStages(array $data, array $reportData, Team $team, string $reportType): array\n {\n // Validate and set deal stages\n if (isset($data['deal_stage_at_call'])) {\n $reportData['deal_at_call_stages'] =\n $this->validateAndGetDealStageIds($team, $data['deal_stage_at_call'], 'Deal stage at call');\n }\n\n if (isset($data['current_deal_stage'])) {\n $reportData['current_deal_stages'] =\n $this->validateAndGetDealStageIds($team, $data['current_deal_stage'], 'Current deal stage');\n }\n\n // Ensure current_deal_stage is not provided for loss_analysis report type\n if ($reportType === self::TYPE_LOSS_ANALYSIS && ! empty($data['current_deal_stage'])) {\n throw new InvalidArgumentException('Current deal stage is not applicable for Loss Analysis reports');\n }\n\n return $reportData;\n }\n\n // transform uuid to id\n private function validatePlaybookCategories(array $data, array $reportData, Team $team): array\n {\n $key = 'playbook_categories';\n\n if (isset($data[$key])) {\n $payloadIds = $data[$key];\n $ids = [];\n\n foreach ($payloadIds as $uuid) {\n $uuid = (string) $uuid;\n\n try {\n $playbookCategory = $this->playbookCategoryRepository->findByUuid($uuid);\n } catch (Throwable $throwable) {\n Log::error(__METHOD__ . ' ' . $throwable->getMessage());\n\n throw new InvalidArgumentException(sprintf('Playbook category %s not found', $uuid));\n }\n\n if (! $playbookCategory) {\n throw new InvalidArgumentException(sprintf('Playbook category %s not found', $uuid));\n }\n\n if (! $playbookCategory->hasPlaybook()) {\n throw new InvalidArgumentException(sprintf('Playbook category %s has no playbook', $uuid));\n }\n\n if ($playbookCategory->getPlaybook()->getTeamId() !== $team->getId()) {\n throw new InvalidArgumentException(\n sprintf('Playbook category %s not found for team %s', $uuid, $team->getUuid())\n );\n }\n\n $ids[] = $playbookCategory->getId();\n }\n\n $reportData[$key] = $ids;\n }\n\n return $reportData;\n }\n\n private function validateReportStatus($status): bool\n {\n if (! in_array($status, [true, false], true)) {\n throw new InvalidArgumentException('Report status is invalid');\n }\n\n return $status;\n }\n\n private function validateReportType($type): string\n {\n if (! in_array($type, self::getTypes(), true)) {\n throw new InvalidArgumentException(sprintf('Report type is invalid: %s', $type));\n }\n\n return $type;\n }\n\n private function validateFrequency($frequency): string\n {\n if (! in_array($frequency, self::getFrequencies(), true)) {\n throw new InvalidArgumentException('Frequency is invalid');\n }\n\n return $frequency;\n }\n\n private function validateAdditionalPromptInput(?string $additionalPromptInput): ?string\n {\n if ($additionalPromptInput && strlen($additionalPromptInput) > 5000) {\n throw new InvalidArgumentException('Additional Prompt Input should be less than 5000 characters');\n }\n\n return $additionalPromptInput;\n }\n\n private function validateCustomReportName(?string $customReportName): ?string\n {\n if ($customReportName === null || $customReportName === '') {\n return null;\n }\n\n if (strlen($customReportName) > 70) {\n throw new InvalidArgumentException('Custom report name should be less than 70 characters');\n }\n\n return $customReportName;\n }\n\n private function validateOrganization(?string $organizationUuid): Team\n {\n if (! $organizationUuid) {\n throw new InvalidArgumentException('Organization is required');\n }\n\n $team = $this->teamRepository->idOrUuid($organizationUuid);\n\n if (! $team) {\n throw new InvalidArgumentException('Organization not found');\n }\n\n if (! $team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {\n throw new InvalidArgumentException('Organization does not have the Automated Reports feature');\n }\n\n return $team;\n }\n\n private function validateAndGetGroupIds(Team $team, array $teamUuids): array\n {\n $groupIds = [];\n\n foreach ($teamUuids as $uuid) {\n $group = $this->groupRepository->findByUuid($uuid);\n\n if ($group === null || $group->getTeamId() !== $team->getId()) {\n throw new InvalidArgumentException(\n sprintf('Group %s not found for team %s', $uuid, $team->getUuid())\n );\n }\n\n $groupIds[] = $group->getId();\n\n }\n\n return $groupIds;\n }\n\n private function validateAndGetDealStageIds(Team $team, array $stageUuids, string $propertyLabel): array\n {\n $stageIds = [];\n\n foreach ($stageUuids as $uuid) {\n $stage = $this->stageRepository->findByUuid($uuid);\n\n if ($stage === null || $stage->getTeamId() !== $team->getId()) {\n throw new InvalidArgumentException(\n sprintf('Stage %s not found for team %s for %s', $uuid, $team->getUuid(), $propertyLabel)\n );\n }\n\n $stageIds[] = $stage->getId();\n }\n\n return $stageIds;\n }\n\n private function validateAndGetUserIds(array $userUuids, callable $teamCheck): array\n {\n if (empty($userUuids)) {\n return [];\n }\n\n $userIds = [];\n\n foreach ($userUuids as $uuid) {\n $user = $this->userRepository->findByUuid($uuid);\n\n if (! $user || ! $user->isStatusActive()) {\n throw new InvalidArgumentException(\n sprintf('User %s not found or is not active', $uuid)\n );\n }\n\n if (! $teamCheck($user)) {\n throw new InvalidArgumentException(\n sprintf('User %s does not belong to the allowed team(s)', $uuid)\n );\n }\n\n $userIds[] = $user->getId();\n }\n\n return $userIds;\n }\n\n private function validateAndGetUserIdsByTeam(Team $team, array $userUuids): array\n {\n return $this->validateAndGetUserIds($userUuids, fn ($user) => $user->getTeamId() === $team->getId());\n }\n\n private function validateAndGetJiminnyUserIds(array $userUuids): array\n {\n $allowedTeamIds = config('kiosk.teamIds', []);\n\n return $this->validateAndGetUserIds($userUuids, fn ($user) => in_array($user->getTeamId(), $allowedTeamIds, true));\n }\n\n private function parseDate(string $dateString): string\n {\n return date('Y-m-d H:i:s', strtotime($dateString));\n }\n\n private function generateReportResultViewUrl(AutomatedReportResult $result): string\n {\n $mediaResource = $this->getReportMediaRouteResource($result);\n\n return route('ai-reports.' . $mediaResource . '.view', ['uuid' => $result->getUuid()]);\n }\n\n private function generateReportResultDownloadUrl(AutomatedReportResult $result): string\n {\n $mediaResource = $this->getReportMediaRouteResource($result);\n\n return route('ai-reports.' . $mediaResource . '.download', ['uuid' => $result->getUuid()]);\n }\n\n private function getReportMediaRouteResource(AutomatedReportResult $result): string\n {\n if ($result->getMediaType() === self::MEDIA_TYPE_PDF) {\n return self::PDF_KEY;\n } elseif ($result->getMediaType() === self::MEDIA_TYPE_PODCAST) {\n return self::AUDIO_KEY;\n }\n\n throw new \\InvalidArgumentException('Unknown media type.');\n }\n\n public function getMediaPath(AutomatedReportResult $result): ?string\n {\n $url = match ($result->getMediaType()) {\n self::MEDIA_TYPE_PDF => $result->getPdfUrl(),\n self::MEDIA_TYPE_PODCAST => $result->getPodcastAudioUrl(),\n default => null,\n };\n\n if ($url === null) {\n return null;\n }\n\n $path = parse_url(trim($url, '\"\\''), PHP_URL_PATH);\n\n return $path ?: null;\n }\n\n public function getFilenameSuffix(AutomatedReportResult $result): ?string\n {\n return match ($result->getMediaType()) {\n self::MEDIA_TYPE_PODCAST => 'Podcast',\n default => null,\n };\n }\n\n public function getMailSubjectSuffix(AutomatedReportResult $result): string\n {\n return match ($result->getMediaType()) {\n self::MEDIA_TYPE_PDF => 'report',\n self::MEDIA_TYPE_PODCAST => 'podcast',\n default => '',\n };\n }\n\n public function getMediaTypeMetadata(AutomatedReportResult $result): array\n {\n return match ($result->getMediaType()) {\n self::MEDIA_TYPE_PODCAST => ['extension' => 'mp3', 'mime' => 'audio/mpeg'],\n self::MEDIA_TYPE_PDF => ['extension' => 'pdf', 'mime' => 'application/pdf'],\n default => ['extension' => null, 'mime' => null],\n };\n }\n\n public function deleteS3Files(AutomatedReportResult $result): void\n {\n $teamUuid = $result->getReport()->getTeam()->getUuid();\n $reportUuid = $result->getUuid();\n\n // delete all files for a report uuid no mather of pdf, podcast, or both\n // in case of both - the podcast files are linked to the pdf (parent) uuid\n // pdf and podcast date times should be close\n $path = sprintf('%s/%s/%s', $teamUuid, self::S3_DIR, $reportUuid);\n\n foreach (self::FILE_EXTENSIONS_VARIANTS as $extension) {\n $file = $path . '.' . $extension;\n\n if (Storage::exists($file)) {\n Storage::delete($file);\n Log::info('[Reports] Deleted S3 file', [\n 'path' => $file,\n ]);\n }\n }\n\n foreach (self::FILE_PODCAST_EXTENSIONS_VARIANTS as $extension) {\n $file = $path . '_podcast.' . $extension;\n\n if (Storage::exists($file)) {\n Storage::delete($file);\n Log::info('[Reports] Deleted Podcast S3 file', [\n 'path' => $file,\n ]);\n }\n }\n }\n\n /**\n *\n * @param int|null $teamId Optional team ID to filter results\n *\n * @return Collection<int, int> Collection of team IDs\n */\n public function getTeamIdsWithReportsResults(?int $teamId = null): Collection\n {\n return $this->automatedReportsRepository->getTeamIdsWithReportsResults($teamId);\n }\n\n /**\n * Core delete logic for report results using a query\n *\n * @param Builder $query\n * @param array $logContext\n *\n * @return int\n */\n private function deleteReportResultsByQuery(Builder $query, array $logContext = []): int\n {\n $deletedCount = 0;\n\n if ($query->exists()) {\n Log::info(\n 'Run delete report results',\n array_merge(\n $logContext,\n [\n 'service' => 'AutomatedReportsService',\n ]\n )\n );\n\n $query->chunkById(50, function ($results) use (&$deletedCount, $logContext) {\n foreach ($results as $result) {\n $this->deleteReportResult($result);\n $deletedCount++;\n\n Log::info(\n 'Deleted a report result',\n array_merge(\n $logContext,\n [\n 'result_id' => $result->getId(),\n 'report_id' => $result->getReportId(),\n ]\n )\n );\n }\n });\n }\n\n return $deletedCount;\n }\n\n /**\n * Delete report results for a team by retention period\n *\n * @param Team $team\n * @param CarbonImmutable $retentionDate\n *\n * @return int Number of deleted report results\n */\n public function deleteReportsResultsInRetentionPeriod(Team $team, CarbonImmutable $retentionDate): int\n {\n $reportIds = $this->automatedReportsRepository->getReportIdsByTeam($team);\n\n if ($reportIds->isEmpty()) {\n return 0;\n }\n\n $query = $this->automatedReportsRepository\n ->getReportResultsQueryForRetention($team, $retentionDate);\n\n return $this->deleteReportResultsByQuery($query, [\n 'team_id' => $team->getId(),\n 'retention_date' => $retentionDate->toDateTimeString(),\n ]);\n }\n\n /**\n * Delete ALL report results for a specific automated report\n *\n * @param string $uuid\n *\n * @return int\n */\n public function deleteReportResults(string $uuid): int\n {\n $report = $this->getReport($uuid);\n\n $query = $this->automatedReportsRepository->getResultsByReportQuery($report);\n\n return $this->deleteReportResultsByQuery($query, [\n 'report_uuid' => $uuid,\n 'report_id' => $report->getId(),\n ]);\n }\n\n public function deleteReportResult(AutomatedReportResult $result): void\n {\n $this->deleteS3Files($result);\n\n $result->delete();\n }\n\n /**\n * Get all reports for a specific team\n *\n * @param Team $team\n *\n * @return \\Illuminate\\Database\\Eloquent\\Collection\n */\n public function getTeamReports(Team $team): \\Illuminate\\Database\\Eloquent\\Collection\n {\n return $this->automatedReportsRepository->getReportsByTeam($team);\n }\n\n /**\n * Get all report results for a specific report\n *\n * @param AutomatedReport $report\n *\n * @return \\Illuminate\\Database\\Eloquent\\Collection\n */\n public function getReportResults(AutomatedReport $report): \\Illuminate\\Database\\Eloquent\\Collection\n {\n return $this->automatedReportsRepository->getResultsByReport($report);\n }\n\n public function deleteAllReportResults(AutomatedReport $report): void\n {\n $results = $this->getReportResults($report);\n\n /** @var AutomatedReportResult $result */\n foreach ($results as $result) {\n Log::info('Deleting result', [\n 'report' => $report->getId(),\n 'result' => $result->getId(),\n ]);\n\n $this->deleteReportResult($result);\n }\n }\n\n public function deleteAllData(Team $team): void\n {\n Log::info('Deleting automated report and results for team', [\n 'team' => $team->getId(),\n ]);\n\n $reports = $this->getTeamReports($team);\n\n /** @var AutomatedReport $report */\n foreach ($reports as $report) {\n Log::info('Deleting report', [\n 'team' => $team->getId(),\n 'report' => $report->getId(),\n ]);\n\n $this->deleteAllReportResults($report);\n\n $report->delete();\n }\n }\n}","depth":4,"value":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Services\\Kiosk\\AutomatedReports;\n\nuse Carbon\\CarbonImmutable;\nuse Carbon\\CarbonInterface;\nuse Carbon\\Exceptions\\InvalidFormatException;\nuse DateTime;\nuse DateTimeInterface;\nuse DateTimeZone;\nuse Illuminate\\Contracts\\Bus\\Dispatcher as BusDispatcher;\nuse Illuminate\\Database\\Eloquent\\Builder;\nuse Illuminate\\Support\\Carbon;\nuse Illuminate\\Support\\Collection;\nuse Illuminate\\Support\\Facades\\Log;\nuse Illuminate\\Support\\Facades\\Storage;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinition\\InputTypeEnum;\nuse Jiminny\\Component\\AskAnything\\AskAnythingPromptService;\nuse Jiminny\\Component\\AskAnything\\Dtos\\AskAnythingPromptDto;\nuse Jiminny\\Component\\UrlGenerator\\Webhook;\nuse Jiminny\\Contracts\\Repositories\\PlaybookCategoryRepository;\nuse Jiminny\\Contracts\\Repositories\\TeamRepository;\nuse Jiminny\\Contracts\\Repositories\\UserRepository;\nuse Jiminny\\Exceptions\\ApplicationException;\nuse Jiminny\\Exceptions\\InvalidArgumentException;\nuse Jiminny\\Exceptions\\ModelNotFoundException;\nuse Jiminny\\Jobs\\AutomatedReports\\RequestGenerateReportJob;\nuse Jiminny\\Models\\Activity\\Search;\nuse Jiminny\\Models\\AskAnything\\AskAnythingPrompt;\nuse Jiminny\\Models\\AskAnything\\AskAnythingPromptTarget;\nuse Jiminny\\Models\\AutomatedReport;\nuse Jiminny\\Models\\AutomatedReportResult;\nuse Jiminny\\Models\\Contracts\\UserContract;\nuse Jiminny\\Models\\Feature\\FeatureEnum;\nuse Jiminny\\Models\\Team;\nuse Jiminny\\Models\\User;\nuse Jiminny\\Repositories\\AskAnythingRepository;\nuse Jiminny\\Repositories\\AutomatedReportsRepository;\nuse Jiminny\\Repositories\\GroupRepository;\nuse Jiminny\\Repositories\\SearchRepository;\nuse Jiminny\\Repositories\\StageRepository;\nuse Throwable;\n\nclass AutomatedReportsService\n{\n public const string TYPE_LOSS_ANALYSIS = 'loss_analysis';\n public const string TYPE_ASK_JIMINNY = 'ask_jiminny';\n\n /**\n * Standard report types (used by kiosk for existing automated reports).\n */\n // @TODO this will add filter, however if we need to control feature by FF we need conditional logic\n public const array TYPES = [\n ['id' => 'exec_summary', 'name' => 'Exec Summary'],\n ['id' => 'coaching_profiles', 'name' => 'Coaching Profiles'],\n ['id' => 'product_feedback', 'name' => 'Product Feedback'],\n ['id' => self::TYPE_LOSS_ANALYSIS, 'name' => 'Loss Analysis'],\n// ['id' => 'questions', 'name' => 'Questions'],\n// ['id' => 'statistical_quant', 'name' => 'Statistical Quantitative'],\n ];\n\n public const array ALL_TYPES = [\n ...self::TYPES,\n ['id' => self::TYPE_ASK_JIMINNY, 'name' => 'Ask Jiminny'],\n ];\n\n public const string FREQUENCY_DAILY = 'daily';\n public const string FREQUENCY_WEEKLY = 'weekly';\n public const string FREQUENCY_MONTHLY = 'monthly';\n public const string FREQUENCY_QUARTERLY = 'quarterly';\n public const string FREQUENCY_ONE_OFF = 'one_off';\n\n /**\n * Frequencies for standard (non-Ask Jiminny) reports.\n */\n public const array FREQUENCIES = [\n ['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],\n ['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],\n ['id' => self::FREQUENCY_QUARTERLY, 'name' => 'Quarterly'],\n ['id' => self::FREQUENCY_ONE_OFF, 'name' => 'One-off'],\n ];\n\n /**\n * Frequencies for Ask Jiminny reports.\n */\n public const array ASK_JIMINNY_FREQUENCIES = [\n ['id' => self::FREQUENCY_DAILY, 'name' => 'Daily'],\n ['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],\n ['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],\n ];\n\n public const string MEDIA_TYPE_PDF = 'pdf';\n public const string MEDIA_TYPE_PODCAST = 'podcast';\n public const array MEDIA_TYPES = [self::MEDIA_TYPE_PDF, self::MEDIA_TYPE_PODCAST];\n public const array MEDIA_TYPE_OBJECT_PDF = ['id' => self::MEDIA_TYPE_PDF, 'name' => 'PDF'];\n public const array MEDIA_TYPE_OBJECT_PODCAST = ['id' => self::MEDIA_TYPE_PODCAST, 'name' => 'Podcast'];\n public const array MEDIA_TYPE_OBJECTS = [self::MEDIA_TYPE_OBJECT_PDF, self::MEDIA_TYPE_OBJECT_PODCAST];\n\n public const array CALL_TYPE_CONFERENCE = ['id' => 'conference', 'name' => 'Conference'];\n public const array CALL_TYPE_DIALER = ['id' => 'dialer', 'name' => 'Dialer'];\n public const int SENT_REPORT_AT_HOURS = 5;\n public const string PDF_KEY = 'pdf';\n public const string AUDIO_KEY = 'audio';\n\n private const array ALL_FREQUENCIES = [\n ['id' => self::FREQUENCY_DAILY, 'name' => 'Daily'],\n ['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],\n ['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],\n ['id' => self::FREQUENCY_QUARTERLY, 'name' => 'Quarterly'],\n ['id' => self::FREQUENCY_ONE_OFF, 'name' => 'One-off'],\n ];\n private const string S3_DIR = 'reports';\n private const array FILE_EXTENSIONS_VARIANTS = ['html', 'MD', 'pdf'];\n private const array FILE_PODCAST_EXTENSIONS_VARIANTS = ['json', 'mp3', 'ssml'];\n\n public function __construct(\n private readonly TeamRepository $teamRepository,\n private readonly GroupRepository $groupRepository,\n private readonly UserRepository $userRepository,\n private readonly StageRepository $stageRepository,\n private readonly DealStagesService $dealStagesService,\n private readonly RecipientsService $recipientsService,\n private readonly AutomatedReportsRepository $automatedReportsRepository,\n private readonly Webhook $webhookService,\n private readonly BusDispatcher $dispatcher,\n private readonly ActivityTypeService $activityTypeService,\n private readonly PlaybookCategoryRepository $playbookCategoryRepository,\n private readonly AskAnythingPromptService $askAnythingPromptService,\n private readonly SearchRepository $activitySearchRepository,\n private readonly AskAnythingRepository $askAnythingRepository,\n ) {\n }\n\n public static function getTypes(): array\n {\n $types = self::TYPES;\n\n return array_map(static function ($type) {\n return $type['id'];\n }, $types);\n }\n\n public static function getCallTypes(): array\n {\n return array_map(static function ($callType) {\n return $callType['id'];\n }, [self::CALL_TYPE_CONFERENCE, self::CALL_TYPE_DIALER]);\n }\n\n public static function getFrequencies(): array\n {\n return array_map(static function ($frequency) {\n return $frequency['id'];\n }, self::FREQUENCIES);\n }\n\n // front-facing structure\n public function getReportEnabledFieldData(bool $value = false): array\n {\n return [\n 'id' => 'report_enabled',\n 'label' => '',\n 'inputType' => InputTypeEnum::TOGGLE,\n 'value' => $value,\n ];\n }\n\n // Organizations = Teams\n public function getOrganizationFieldData(?string $value = null, bool $shortVersion = false): array\n {\n $options = $this->getTeams();\n\n if ($shortVersion) {\n return [\n 'id' => 'organization',\n 'label' => 'Organization',\n 'options' => $options,\n ];\n }\n\n return [\n 'id' => 'organization',\n 'label' => 'Organization',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => $options,\n 'value' => $value,\n 'dependencies' => [\n 'teams',\n 'deal_stage_at_call',\n 'current_deal_stage',\n 'recipients',\n ActivityTypeService::PLAYBOOK_CATEGORIES_KEY,\n ],\n 'dependsOn' => [],\n ];\n }\n\n // Teams = Groups\n public function getTeamFieldData(array $options = [], array $value = [], bool $shortVersion = false): array\n {\n if ($shortVersion) {\n return [\n 'id' => 'teams',\n 'label' => 'Team',\n 'options' => $options,\n ];\n }\n\n return [\n 'id' => 'teams',\n 'label' => 'Team',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'required' => false,\n 'placeholder' => 'Select',\n 'options' => $options,\n 'value' => $value, // value should be an array of objects {id, name}\n 'dependencies' => [ActivityTypeService::PLAYBOOK_CATEGORIES_KEY],\n 'dependsOn' => [],\n ];\n }\n\n public function getReportTypeFieldData(?string $value = null, bool $shortVersion = false, ?Team $team = null): array\n {\n $types = [];\n if ($team instanceof Team) {\n if ($team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {\n $types = self::TYPES;\n }\n if ($team->hasFeature(FeatureEnum::ASK_JIMINNY_REPORTS)) {\n $types[] = ['id' => self::TYPE_ASK_JIMINNY, 'name' => 'Ask Jiminny'];\n }\n } else {\n $types = self::TYPES;\n }\n\n if ($shortVersion) {\n return [\n 'id' => 'report_type',\n 'label' => 'Report Type',\n 'options' => $types,\n ];\n }\n\n return [\n 'id' => 'report_type',\n 'label' => 'Report Type',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => $types,\n 'value' => $value,\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getFrequencyFieldData(?string $value = null): array\n {\n return [\n 'id' => 'frequency',\n 'label' => 'Frequency',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => self::FREQUENCIES,\n 'value' => $value,\n 'dependencies' => ['period'],\n 'dependsOn' => [],\n ];\n }\n\n public function getPeriodFieldData(?string $valueStartDate = null, ?string $valueEndDate = null): array\n {\n return [\n 'id' => 'period',\n 'label' => 'Select one-off period',\n 'inputType' => InputTypeEnum::DATE_RANGE,\n 'required' => true,\n 'placeholder' => 'Select',\n 'value' => ['startDate' => $valueStartDate, 'endDate' => $valueEndDate],\n 'queryParams' => [\n 'startDate' => 'start_date_period',\n 'endDate' => 'end_date_period',\n ],\n 'dependencies' => [],\n 'dependsOn' => ['frequency'],\n ];\n }\n\n public function getActivityTypesFieldData(?Team $team = null, array $value = [], array $teamsFilter = []): array\n {\n return $this->activityTypeService->getActivityTypeFieldData(team: $team, value: $value, groupIds: $teamsFilter);\n }\n\n public function getDealStageAtCallFieldData(?Team $team = null, array $value = []): array\n {\n return $this->dealStagesService->getDealStageAtCallFieldData(team: $team, value: $value);\n }\n\n public function getCurrentDealStageFieldData(?Team $team = null, array $value = []): array\n {\n return $this->dealStagesService->getCurrentDealStageFieldData(team: $team, value: $value);\n }\n\n public function getDealValueFieldData(?int $valueMin = null, ?int $valueMax = null): array\n {\n return [\n 'id' => 'deal_value',\n 'label' => 'Deal Value',\n 'inputType' => InputTypeEnum::INTEGER_RANGE,\n 'required' => false,\n 'value' => ['min' => $valueMin, 'max' => $valueMax],\n 'queryParams' => [\n 'min' => 'min_deal_value',\n 'max' => 'max_deal_value',\n ],\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getCallTypeFieldData(bool $conferenceOn = false, bool $dialerOn = false): array\n {\n $value = [];\n $conferenceOn && $value[] = self::CALL_TYPE_CONFERENCE;\n $dialerOn && $value[] = self::CALL_TYPE_DIALER;\n\n return [\n 'id' => 'call_type',\n 'label' => 'Call Type',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'required' => true,\n 'options' => [\n self::CALL_TYPE_CONFERENCE,\n self::CALL_TYPE_DIALER,\n ],\n 'value' => $value,\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getMediaTypeFieldData(?AutomatedReport $report = null): array\n {\n $value = [];\n\n if ($report) {\n $value = $this->transformMediaTypes($report);\n }\n\n return [\n 'id' => 'media_types',\n 'label' => 'Export as',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'required' => true,\n 'options' => self::MEDIA_TYPE_OBJECTS,\n 'value' => $value,\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getCallDurationFieldData(?int $valueMin = null, ?int $valueMax = null): array\n {\n return [\n 'id' => 'call_duration',\n 'label' => 'Call Duration',\n 'inputType' => InputTypeEnum::INTEGER_RANGE,\n 'required' => false,\n 'value' => ['min' => $valueMin, 'max' => $valueMax],\n 'queryParams' => [\n 'min' => 'min_call_duration',\n 'max' => 'max_call_duration',\n ],\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getRecipientsFieldData(?Team $team = null, array $value = []): array\n {\n return $this->recipientsService->getRecipientsFieldData(team: $team, value: $value);\n }\n\n public function getJiminnyRecipientsFieldData(array $value = []): array\n {\n return $this->recipientsService->getJiminnyRecipientsFieldData($value);\n }\n\n public function getAdditionalPromptInputFieldData(?string $value = null): array\n {\n return [\n 'id' => 'additional_prompt_input',\n 'label' => 'Special requirements',\n 'inputType' => InputTypeEnum::TEXTAREA,\n 'required' => false,\n 'placeholder' => 'What should be the focus of the report?',\n 'value' => $value,\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getCustomReportNameFieldData(?string $value = null): array\n {\n return [\n 'id' => 'custom_name',\n 'label' => 'Custom report name',\n 'inputType' => InputTypeEnum::TEXT,\n 'required' => false,\n 'placeholder' => 'Enter custom name',\n 'value' => $value,\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n // data providers\n public function getTeams(): array\n {\n $teams = $this->teamRepository->getTeamsForKiosk(status: Team::STATUS_ACTIVE);\n\n $teamData = [];\n foreach ($teams as $team) {\n if (! $team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {\n continue;\n }\n\n $teamData[] = $this->transformTeam($team);\n }\n\n return $teamData;\n }\n\n public function getTeamGroups(string $teamUuid): array\n {\n $data = [];\n $team = $this->getTeam($teamUuid);\n\n if ($team !== null) {\n $groups = $team->groups()->get();\n\n foreach ($groups as $group) {\n $data[] = [\n 'id' => $group->getUuid(),\n 'name' => $group->getName(),\n ];\n }\n }\n\n return $data;\n }\n\n public function getTeamsGroupsOptions(array $filterTeamUuids = []): array\n {\n $data = [];\n $teams = $this->getTeams();\n\n foreach ($teams as $team) {\n if (! empty($filterTeamUuids) && ! in_array($team['id'], $filterTeamUuids, true)) {\n continue;\n }\n\n $data[] = [\n 'label' => $team['name'],\n 'groups' => $this->getTeamGroups($team['id']),\n ];\n }\n\n return $data;\n }\n\n public function getTeam(string $teamUuid): ?Team\n {\n return $this->teamRepository->idOrUuid($teamUuid);\n }\n\n public function getTeamById(int $teamId): ?Team\n {\n return $this->teamRepository->find($teamId);\n }\n\n public function getGroupsUuids(AutomatedReport $report): array\n {\n $uuids = [];\n $reportGroups = $report->getGroups();\n foreach ($reportGroups as $groupId) {\n if ($group = $this->groupRepository->find($groupId)) {\n $uuids[] = $group->getUuid();\n }\n }\n\n return $uuids;\n }\n\n public function getPlaybookCategoriesUuids(AutomatedReport $report): array\n {\n $uuids = [];\n $playbookCategories = $report->getPlaybookCategories();\n foreach ($playbookCategories as $id) {\n if ($category = $this->playbookCategoryRepository->find($id)) {\n $uuids[] = $category->getUuid();\n }\n }\n\n return $uuids;\n }\n\n public function getDealAtCallStagesUuids(AutomatedReport $report): array\n {\n $uuids = [];\n $reportStages = $report->getDealAtCallStages();\n foreach ($reportStages as $id) {\n if ($stage = $this->stageRepository->find($id)) {\n $uuids[] = $stage->getUuid();\n }\n }\n\n return $uuids;\n }\n\n public function getCurrentDealStagesUuids(AutomatedReport $report): array\n {\n $uuids = [];\n $reportStages = $report->getCurrentDealStages();\n foreach ($reportStages as $id) {\n if ($stage = $this->stageRepository->find($id)) {\n $uuids[] = $stage->getUuid();\n }\n }\n\n return $uuids;\n }\n\n public function getUsersUuids(AutomatedReport $report): array\n {\n return $this->extractUserUuids($report->getRecipients());\n }\n\n public function getJiminnyUsersUuids(AutomatedReport $report): array\n {\n return $this->extractUserUuids($report->getJiminnyRecipients());\n }\n\n /**\n * @param array<string, mixed> $recipients\n */\n private function extractUserUuids(array $recipients): array\n {\n $userIds = $recipients['users'] ?? [];\n\n return collect($userIds)\n ->map(fn ($id) => $this->userRepository->find((int) $id))\n ->filter()\n ->map(fn (UserContract $user) => $user->getUuid())\n ->values()\n ->all();\n }\n\n // get mail data\n public function getRecipientUsers(AutomatedReport $report): array\n {\n return $this->buildRecipientUsers($report->getRecipients());\n }\n\n private function getJiminnyRecipientUsers(AutomatedReport $report): array\n {\n return $this->buildRecipientUsers($report->getJiminnyRecipients());\n }\n\n /**\n * @param array<string, mixed> $recipients\n */\n private function buildRecipientUsers(array $recipients): array\n {\n $userIds = $recipients['users'] ?? [];\n\n return collect($userIds)\n ->map(fn ($id) => $this->userRepository->find((int) $id))\n ->filter()\n ->map(fn (UserContract $user) => [\n 'email' => $user->getEmailAddress(),\n 'name' => $user->getName(),\n 'timezone' => $user->getTimezone()->getName(),\n ])\n ->values()\n ->all();\n }\n\n public function getValidRecipientUsers(AutomatedReport $report, bool $includeJiminny = false): array\n {\n if ($report->isAskJiminnyReport()) {\n $recipients = $this->resolveAskJiminnyRecipients($report);\n } else {\n $recipients = $this->getRecipientUsers($report);\n if ($includeJiminny) {\n $recipients = array_merge($recipients, $this->getJiminnyRecipientUsers($report));\n }\n }\n\n $emails = [];\n\n return array_values(array_filter(\n $recipients,\n static function ($recipient) use (&$emails) {\n if (empty($recipient['email']) || in_array($recipient['email'], $emails, true)) {\n return false;\n }\n $emails[] = $recipient['email'];\n\n return true;\n }\n ));\n }\n\n private function resolveAskJiminnyRecipients(AutomatedReport $report): array\n {\n $recipients = [];\n\n $creator = $report->getCreator();\n if ($creator !== null) {\n $recipients[] = [\n 'email' => $creator->getEmailAddress(),\n 'name' => $creator->getName(),\n 'timezone' => $creator->getTimezone()->getName(),\n ];\n }\n\n return array_merge(\n $recipients,\n $this->buildRecipientUsers($report->getRecipients()),\n $this->getGroupRecipientUsers($report),\n );\n }\n\n private function getGroupRecipientUsers(AutomatedReport $report): array\n {\n $users = [];\n foreach ($report->getGroups() as $groupId) {\n $group = $this->groupRepository->find($groupId);\n if ($group === null) {\n continue;\n }\n foreach ($group->getMembers() as $member) {\n $users[] = [\n 'email' => $member->getEmailAddress(),\n 'name' => $member->getName(),\n 'timezone' => $member->getTimezone()->getName(),\n ];\n }\n }\n\n return $users;\n }\n\n public function getReportTypeName(AutomatedReportResult $report): string\n {\n $type = $report->getReport()->getType();\n\n $getType = $this->transformReportType($type);\n\n return $getType['name'];\n }\n\n public function getReportPeriodName(AutomatedReportResult $report): string\n {\n $from = $report->getFromDate();\n $to = $report->getToDate();\n $frequency = $report->getReport()->getFrequency();\n\n if ($from === null || $to === null) {\n if (! $report->getReport()->isAskJiminnyReport()) {\n $invalidPeriod = $from === null ? 'from' : 'to';\n\n throw new ApplicationException('Report period is invalid: ' . $invalidPeriod);\n }\n\n $period = $this->calculateFromAndToDatePeriod($frequency);\n $from = $period['fromDate'];\n $to = $period['toDate'];\n }\n\n return $this->formatReportPeriodName($frequency, $from, $to);\n }\n\n private function formatReportPeriodName(string $frequency, Carbon $from, Carbon $to): string\n {\n $fromYear = $from->format('Y');\n $toYear = $to->format('Y');\n $differentYears = $fromYear !== $toYear;\n\n switch ($frequency) {\n case self::FREQUENCY_DAILY:\n return $from->format('j M Y');\n\n case self::FREQUENCY_QUARTERLY:\n // 'Jan-Mar 2025' or 'Nov 2024-Jan 2025' if years differ\n $startMonth = $from->format('M');\n $endMonth = $to->copy()->subMonth();\n $endMonthName = $endMonth->format('M');\n $endMonthYear = $endMonth->format('Y');\n\n if ($differentYears) {\n return \"{$startMonth} {$fromYear} - {$endMonthName} {$endMonthYear}\";\n }\n\n return \"{$startMonth} - {$endMonthName} {$toYear}\";\n\n case self::FREQUENCY_MONTHLY:\n // 'May 2025' - monthly reports are always within the same year\n return $from->format('M Y');\n\n case self::FREQUENCY_WEEKLY:\n // '4 - 8 Aug 2025', '27 Oct - 3 Nov 2025', or '28 Dec 2024 - 3 Jan 2025' if years differ\n $startDay = $from->format('j');\n $endDay = $to->format('j');\n $startMonth = $from->format('M');\n $endMonth = $to->format('M');\n\n if ($differentYears) {\n return \"{$startDay} {$startMonth} {$fromYear} - {$endDay} {$endMonth} {$toYear}\";\n }\n\n if ($startMonth !== $endMonth) {\n return \"{$startDay} {$startMonth} - {$endDay} {$endMonth} {$toYear}\";\n }\n\n return \"{$startDay} - {$endDay} {$endMonth} {$toYear}\";\n\n case self::FREQUENCY_ONE_OFF:\n // '2 May-31 May 2025' or '15 Dec 2024-15 Jan 2025' if years differ\n $startDay = $from->format('j');\n $startMonth = $from->format('M');\n $endDay = $to->format('j');\n $endMonth = $to->format('M');\n\n // If same month and year, use a format like '2-31 May 2025'\n if ($startMonth === $endMonth && ! $differentYears) {\n return \"{$startDay} - {$endDay} {$startMonth} {$toYear}\";\n }\n\n // If different years, include both years\n if ($differentYears) {\n return \"{$startDay} {$startMonth} {$fromYear} - {$endDay} {$endMonth} {$toYear}\";\n }\n\n // Same year but different months\n return \"{$startDay} {$startMonth} - {$endDay} {$endMonth} {$toYear}\";\n\n default:\n // Default format for unknown frequencies\n return $from->format('j M Y') . ' - ' . $to->format('j M Y');\n }\n }\n\n public function getReportTeamsName(AutomatedReportResult $report): string\n {\n $groups = $report->getGroups();\n\n if (empty($groups)) {\n return 'All';\n }\n\n // Get group names from repository\n $groupNames = [];\n foreach ($groups as $groupId) {\n $group = $this->groupRepository->find($groupId);\n if ($group) {\n $groupNames[] = $group->getName();\n }\n }\n\n if (count($groupNames) === 1) {\n // Single team format\n $teamsName = $groupNames[0];\n } else {\n // Multiple teams format\n $teamsName = implode(', ', $groupNames);\n }\n\n return $teamsName;\n }\n\n public function getReportFileName(AutomatedReportResult $report): string\n {\n $customName = $report->getReport()->getCustomName();\n $periodName = $this->getReportPeriodName($report);\n $filenameSuffix = $this->getFilenameSuffix($report);\n\n if ($customName) {\n if ($filenameSuffix) {\n $customName .= \" {$filenameSuffix}\";\n }\n\n return $this->sanitizeFileName(\"{$customName} - {$periodName}\");\n }\n\n $baseName = $this->getReportTypeName($report);\n\n if ($filenameSuffix) {\n $baseName .= \" {$filenameSuffix}\";\n }\n\n return $this->sanitizeFileName(\"{$baseName} - {$periodName} - {$this->getReportTeamsName($report)}\");\n }\n\n public function getReportFileNameWithExtension(AutomatedReportResult $result): string\n {\n $extension = $this->getMediaTypeMetadata($result)['extension'];\n\n return $this->getReportFileName($result) . '.' . $extension;\n }\n\n public function sanitizeFileName(string $fileName): string\n {\n return str_replace(['/', '\\\\'], '-', $fileName);\n }\n\n public function isUserRecipientOfReport(User $user, AutomatedReport $report): bool\n {\n $recipients = array_map('intval', $report->getRecipients()['users'] ?? []);\n\n return in_array($user->getId(), $recipients);\n }\n\n public function transformReportResults(Collection $automatedReportResults): array\n {\n $data = [];\n foreach ($automatedReportResults as $automatedReportResult) {\n /** @var AutomatedReportResult $automatedReportResult */\n\n $report = $automatedReportResult->getReport();\n\n $createdBy = $report->getCreator();\n $creator = [\n 'id' => $createdBy?->getUuid(),\n 'name' => $createdBy?->getName(),\n 'email' => $createdBy?->getEmailAddress(),\n 'photoUrl' => $createdBy?->getPhotoUrl(),\n ];\n\n $data[] = [\n 'id' => $automatedReportResult->getUuid(),\n 'name' => $automatedReportResult->getName(),\n 'frequency' => $this->transformFrequency($report->getFrequency()),\n 'recipients' => [\n ...array_values($this->transformGroups(team: $report->getTeam(), groupsIds: $report->getGroups())),\n ...array_values($this->transformRecipients($report->getRecipients())),\n ],\n 'report_type' => $this->transformReportType($report->getType()),\n 'media_type' => $automatedReportResult->getMediaType(),\n 'downloadUrl' => $this->generateReportResultDownloadUrl($automatedReportResult),\n 'viewUrl' => $this->generateReportResultViewUrl($automatedReportResult),\n 'generated_at' => $automatedReportResult->getGeneratedAt()?->toIso8601String(),\n 'creator' => $creator,\n ];\n }\n\n return $data;\n }\n\n public function hasCallTypeConference(AutomatedReport $report): bool\n {\n return in_array(self::CALL_TYPE_CONFERENCE['id'], $report->getCallTypes(), true);\n }\n\n public function hasCallTypeDialer(AutomatedReport $report): bool\n {\n return in_array(self::CALL_TYPE_DIALER['id'], $report->getCallTypes(), true);\n }\n\n // transformers\n private function transformTeam(Team $team): array\n {\n if (! $team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {\n return [];\n }\n\n return [\n 'id' => $team->getUuid(),\n 'name' => $team->getName(),\n ];\n }\n\n private function transformReportFullView(AutomatedReport $report): array\n {\n $base = $this->transformReportBase($report);\n\n return $report->getType() === self::TYPE_ASK_JIMINNY\n ? $base + $this->transformAskJiminnyFields($report)\n : $base + $this->transformStandardReportFields($report);\n }\n\n private function transformReportBase(AutomatedReport $report): array\n {\n return [\n 'id' => $report->getUuid(),\n 'organization' => $this->transformOrganization(team: $report->getTeam()),\n 'report_type' => $this->transformReportType($report->getType()),\n 'frequency' => $this->transformFrequency($report->getFrequency()),\n ];\n }\n\n private function transformStandardReportFields(AutomatedReport $report): array\n {\n $team = $report->getTeam();\n\n return [\n 'report_enabled' => $report->getStatus(),\n 'start_date_period' => $report->getFrom()?->format('Y-m-d H:i:s'),\n 'end_date_period' => $report->getTo()?->format('Y-m-d H:i:s'),\n 'deal_value_min' => $report->getDealValueMin(),\n 'deal_value_max' => $report->getDealValueMax(),\n 'call_types' => $this->transformCallType($report->getCallTypes()),\n 'media_types' => $this->transformMediaTypes($report),\n 'call_duration_min' => $this->transformDurationToMinutes($report->getCallDurationMin()),\n 'call_duration_max' => $this->transformDurationToMinutes($report->getCallDurationMax()),\n 'teams' => $this->transformGroups(team: $team, groupsIds: $report->getGroups()),\n 'deal_at_call_stages' => $this->transformStages(team: $team, stagesIds: $report->getDealAtCallStages()),\n 'current_deal_stages' => $this->transformStages(team: $team, stagesIds: $report->getCurrentDealStages()),\n 'recipients' => $this->transformRecipients($report->getRecipients()),\n 'created_by' => $this->transformCreator($report->getCreator()),\n 'additional_prompt_input' => $report->getAdditionalPromptInput(),\n 'custom_name' => $report->getCustomName(),\n 'created_at' => $report->getCreatedAt()->format('Y-m-d H:i:s'),\n 'updated_at' => $report->getUpdatedAt()->format('Y-m-d H:i:s'),\n 'deleted_at' => $report->getDeletedAt()?->format('Y-m-d H:i:s'),\n ];\n }\n\n private function transformAskJiminnyFields(AutomatedReport $report): array\n {\n $team = $report->getTeam();\n $creatorId = $report->getAttribute('created_by');\n $explicitUserIds = array_values(array_filter(\n $report->getRecipients()['users'] ?? [],\n static fn ($id) => $id !== $creatorId\n ));\n\n return [\n 'report_name' => $report->getCustomName(),\n 'enabled' => $report->getStatus(),\n 'share_teams' => $this->transformGroups(team: $team, groupsIds: $report->getGroups()),\n 'share_users' => $this->transformRecipients(['users' => $explicitUserIds]),\n 'saved_search' => $this->transformSafeSearch($report->getSavedSearch()),\n 'ask_jiminny_prompt' => $this->transformAskJiminnyPrompt($report->getAskAnythingPrompt()),\n 'expires_on' => $report->getExpiresAt()?->format('Y-m-d'),\n ];\n }\n\n private function transformOrganization(?Team $team): array\n {\n return [\n 'id' => $team?->getUuid(),\n 'name' => $team?->getName(),\n ];\n }\n\n private function transformReportType(string $type): array\n {\n foreach (self::ALL_TYPES as $typeItem) {\n if ($typeItem['id'] === $type) {\n return $typeItem;\n }\n }\n\n return [];\n }\n\n private function transformCallType(array $types): array\n {\n $result = [];\n $callTypes = [self::CALL_TYPE_CONFERENCE, self::CALL_TYPE_DIALER];\n\n foreach ($types as $type) {\n foreach ($callTypes as $callTypeItem) {\n if ($callTypeItem['id'] === $type) {\n $result[] = $callTypeItem;\n\n break;\n }\n }\n }\n\n return $result;\n }\n\n private function transformMediaTypes(AutomatedReport $report): array\n {\n $values = [];\n\n foreach ($report->getMediaTypes() as $mediaType) {\n if (! in_array($mediaType, self::MEDIA_TYPES, true)) {\n continue;\n }\n\n $values[] = match ($mediaType) {\n self::MEDIA_TYPE_PDF => self::MEDIA_TYPE_OBJECT_PDF,\n self::MEDIA_TYPE_PODCAST => self::MEDIA_TYPE_OBJECT_PODCAST,\n };\n }\n\n return $values;\n }\n\n private function transformFrequency(string $frequency): array\n {\n foreach (self::ALL_FREQUENCIES as $frequencyItem) {\n if ($frequencyItem['id'] === $frequency) {\n return $frequencyItem;\n }\n }\n\n return [];\n }\n\n public function transformDurationToMinutes(?int $duration): ?int\n {\n if (! $duration) {\n return null;\n }\n\n return (int) ($duration / 60);\n }\n\n private function transformGroups(?Team $team, array $groupsIds): array\n {\n if (empty($groupsIds) || ! $team) {\n return [];\n }\n\n $data = [];\n foreach ($groupsIds as $groupId) {\n $group = $team->groups()->where('id', $groupId)->first();\n\n if ($group) {\n $data[] = [\n 'id' => $group->getUuid(),\n 'name' => $group->getName(),\n 'photoUrl' => $group->getPhotoUrl(),\n ];\n }\n }\n\n return $data;\n }\n\n private function transformStages(?Team $team, array $stagesIds): array\n {\n if (empty($stagesIds) || ! $team) {\n return [];\n }\n\n $data = [];\n foreach ($stagesIds as $stageId) {\n $stage = $team->stages()->where('id', $stageId)->first();\n\n if ($stage) {\n $data[] = [\n 'id' => $stage->getUuid(),\n 'name' => $stage->getName(),\n ];\n }\n }\n\n return $data;\n }\n\n private function transformRecipients(array $recipients): array\n {\n $users = [];\n foreach ($recipients['users'] ?? [] as $userId) {\n $users[] = $this->transformUser($userId);\n }\n\n return $users;\n }\n\n private function transformCreator(?User $user): ?array\n {\n if ($user === null) {\n return null;\n }\n\n return $this->transformUser($user->getId());\n }\n\n private function transformAskJiminnyPrompt(?AskAnythingPrompt $prompt): ?array\n {\n if ($prompt === null) {\n return null;\n }\n\n return [\n 'id' => $prompt->getUuid(),\n 'name' => $prompt->getTitle(),\n ];\n }\n\n private function transformSafeSearch(?Search $search): ?array\n {\n if ($search === null) {\n return null;\n }\n\n return [\n 'id' => $search->getUuid(),\n 'name' => $search->getName(),\n ];\n }\n\n private function transformUser(int $userId): array\n {\n /* @var ?User $user */\n $user = $this->userRepository->find($userId);\n\n return [\n 'id' => $user?->getUuid(),\n 'name' => $user?->getName(),\n 'email' => $user?->getEmailAddress(),\n 'photoUrl' => $user?->getPhotoUrl(),\n ];\n }\n\n public function create(array $data): array\n {\n $validatedData = $this->validateAndTransformData($data);\n $validatedData['created_by'] = auth()->id();\n\n $automatedReport = $this->automatedReportsRepository->create($validatedData);\n\n $this->generateOneOffReport($automatedReport);\n\n return $this->transformReportFullView($automatedReport);\n }\n\n public function update(string $uuid, array $data): array\n {\n $validatedData = $this->validateAndTransformData($data);\n $report = $this->automatedReportsRepository->findByUuid($uuid);\n\n if (! $report) {\n throw new InvalidArgumentException('Report not found');\n }\n\n $oldCustomName = $report->getCustomName();\n\n $automatedReport = $this->automatedReportsRepository->update($report, $validatedData);\n\n if ($oldCustomName !== $automatedReport->getCustomName()) {\n $this->updateResultNames($automatedReport);\n }\n\n $this->generateOneOffReport($automatedReport);\n\n return $this->transformReportFullView($automatedReport);\n }\n\n /**\n * Create an Ask Jiminny report.\n */\n public function createAskJiminnyReport(array $data, User $creator): array\n {\n $validatedData = $this->validateAskJiminnyReportData($data, $creator);\n $validatedData['created_by'] = $creator->getId();\n\n $automatedReport = $this->automatedReportsRepository->create($validatedData);\n\n return $this->transformReportFullView($automatedReport);\n }\n\n /**\n * Update an Ask Jiminny report.\n */\n public function updateAskJiminnyReport(AutomatedReport $report, array $data, User $user): array\n {\n if (! $report->isAskJiminnyReport()) {\n throw new InvalidArgumentException('Report is not an Ask Jiminny report');\n }\n\n $validatedData = $this->validateAskJiminnyReportData($data, $user);\n\n $oldCustomName = $report->getCustomName();\n\n $automatedReport = $this->automatedReportsRepository->update($report, $validatedData);\n\n if ($oldCustomName !== $automatedReport->getCustomName()) {\n $this->updateResultNames($automatedReport);\n }\n\n return $this->transformReportFullView($automatedReport);\n }\n\n public function updateAskJiminnyReportStatus(AutomatedReport $report, bool $status): array\n {\n $this->automatedReportsRepository->update($report, ['status' => $status]);\n\n return $this->transformReportFullView($report->fresh());\n }\n\n /**\n * Validate and transform data for Ask Jiminny reports.\n */\n private function validateAskJiminnyReportData(array $data, User $user): array\n {\n // Validate name\n $name = trim($data['report_name'] ?? '');\n if (empty($name)) {\n throw new InvalidArgumentException('Report name is required');\n }\n if (mb_strlen($name) > 50) {\n throw new InvalidArgumentException('Report name must be 50 characters or less');\n }\n\n // Validate frequency (only daily, weekly, monthly for Ask Jiminny)\n $frequency = $data['frequency'] ?? null;\n $askJiminnyFrequencies = [self::FREQUENCY_DAILY, self::FREQUENCY_WEEKLY, self::FREQUENCY_MONTHLY];\n if (! in_array($frequency, $askJiminnyFrequencies, true)) {\n throw new InvalidArgumentException('Frequency must be daily, weekly, or monthly');\n }\n\n // Validate expiration date\n $expiresAt = $data['expires_on'] ?? null;\n if (empty($expiresAt)) {\n throw new InvalidArgumentException('Expiration date is required');\n }\n\n try {\n $expiresAtDate = Carbon::parse($expiresAt);\n } catch (InvalidFormatException $e) {\n throw new InvalidArgumentException('Expiration date format is invalid');\n }\n $maxExpiration = Carbon::now()->addYear();\n if ($expiresAtDate->gt($maxExpiration)) {\n throw new InvalidArgumentException('Expiration date cannot be more than 1 year from now');\n }\n if ($expiresAtDate->isPast()) {\n throw new InvalidArgumentException('Expiration date cannot be in the past');\n }\n\n // Validate saved search\n $activitySearchId = $data['saved_search'] ?? null;\n if (empty($activitySearchId)) {\n throw new InvalidArgumentException('Saved search is required');\n }\n $savedSearch = $this->activitySearchRepository->findByUuidAndUser($activitySearchId, $user);\n if (! $savedSearch) {\n throw new InvalidArgumentException('Saved search not found or does not belong to you');\n }\n\n // Validate saved prompt\n $askAnythingPromptId = $data['ask_jiminny_prompt'] ?? null;\n if (empty($askAnythingPromptId)) {\n throw new InvalidArgumentException('Ask Jiminny prompt is required');\n }\n $prompt = $this->askAnythingRepository->getPromptByUuid($askAnythingPromptId);\n if (! $prompt) {\n throw new InvalidArgumentException('Ask Jiminny prompt not found');\n }\n\n // Validate status\n $status = $data['enabled'] ?? false;\n\n $recipientUserIds = [$user->getId()];\n\n if (! empty($data['share_users'])) {\n $sharedUserIds = $this->validateAndGetUserIdsByTeam(\n $user->team,\n (array) $data['share_users']\n );\n $recipientUserIds = array_merge($recipientUserIds, $sharedUserIds);\n }\n\n $sharedGroupIds = [];\n if (! empty($data['share_teams'])) {\n $sharedGroupIds = $this->validateAndGetGroupIds($user->team, (array) $data['share_teams']);\n }\n\n $recipientUserIds = array_values(array_unique($recipientUserIds));\n\n return [\n 'team_id' => $user->getTeamId(),\n 'type' => self::TYPE_ASK_JIMINNY,\n 'status' => (bool) $status,\n 'frequency' => $frequency,\n 'custom_name' => $name,\n 'activity_search_id' => $savedSearch->getId(),\n 'ask_anything_prompt_id' => $prompt->getId(),\n 'expires_at' => $expiresAtDate->toDateString(),\n 'media_types' => [self::MEDIA_TYPE_PDF],\n 'call_types' => [],\n 'recipients' => ['users' => $recipientUserIds],\n 'groups' => $sharedGroupIds,\n ];\n }\n\n public static function getAskJiminnyFrequencies(): array\n {\n return array_map(static function ($frequency) {\n return $frequency['id'];\n }, self::ASK_JIMINNY_FREQUENCIES);\n }\n\n public function getAskJiminnyReportFilters(User $user): array\n {\n $savedSearches = $this->activitySearchRepository->findByUserOrderedByName($user)\n ->map(fn (Search $search) => [\n 'id' => $search->getUuid(),\n 'name' => $search->getName(),\n ])\n ->values()->all();\n\n $prompts = collect(\n $this->askAnythingPromptService->get($user, AskAnythingPromptTarget::on_demand)\n )->map(fn (AskAnythingPromptDto $prompt) => [\n 'id' => $prompt->id,\n 'name' => $prompt->title,\n ])->values()->all();\n\n return [\n [\n 'id' => 'prompt',\n 'label' => 'Prompt',\n 'options' => $prompts,\n ],\n [\n 'id' => 'saved_search',\n 'label' => 'Saved Search',\n 'options' => $savedSearches,\n ],\n ];\n }\n\n public function getAskJiminnyReportFormData(User $user, ?AutomatedReport $report = null): array\n {\n $team = $user->getTeam();\n $userTimezone = $user->getTimezone();\n\n $savedSearches = $this->activitySearchRepository->findByUserOrderedByName($user)\n ->map(fn (Search $search) => [\n 'id' => $search->getUuid(),\n 'name' => $search->getName(),\n ])\n ->values()->all();\n\n $prompts = collect(\n $this->askAnythingPromptService->get($user, AskAnythingPromptTarget::on_demand)\n )->map(fn (AskAnythingPromptDto $prompt) => [\n 'id' => $prompt->id,\n 'name' => $prompt->title,\n ])->values()->all();\n\n $teamGroups = $this->groupRepository->getAllByTeam($team)->map(fn ($group) => [\n 'id' => $group->getUuid(),\n 'name' => $group->getName(),\n ])->values()->all();\n\n $shareUsers = $this->recipientsService->getRecipientsFieldData(team: $team)['options'] ?? [];\n\n $sharedTeamsValue = [];\n $sharedUsersValue = [];\n if ($report) {\n $sharedTeamsValue = $this->transformGroups($team, $report->getGroups());\n\n $recipientUserIds = $report->getRecipients()['users'] ?? [];\n $creatorId = $report->getAttribute('created_by');\n $sharedUserIds = array_values(array_filter(\n $recipientUserIds,\n static fn ($id) => $id !== $creatorId\n ));\n $sharedUsersValue = collect($sharedUserIds)\n ->map(fn ($id) => $this->userRepository->find((int) $id))\n ->filter()\n ->map(fn (User $u) => [\n 'id' => $u->getUuid(),\n 'name' => $u->getName(),\n ])\n ->values()\n ->all();\n }\n\n return [\n 'fields' => [\n [\n 'id' => 'enabled',\n 'inputType' => InputTypeEnum::TOGGLE,\n 'label' => '',\n 'value' => $report?->getStatus() ?? false,\n ],\n [\n 'id' => 'report_name',\n 'inputType' => InputTypeEnum::TEXT,\n 'label' => 'Name',\n 'placeholder' => 'Enter name',\n 'required' => true,\n 'validation' => ['maxLength' => 50],\n 'value' => $report?->getCustomName() ?? '',\n ],\n [\n 'id' => 'frequency',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'label' => 'Frequency',\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => self::ASK_JIMINNY_FREQUENCIES,\n 'value' => $report ? $this->transformFrequency($report->getFrequency()) : null,\n ],\n [\n 'id' => 'expires_on',\n 'inputType' => InputTypeEnum::DATE,\n 'label' => 'Expires on',\n 'required' => true,\n 'placeholder' => 'Select',\n 'validation' => [\n 'minDate' => now($userTimezone)->toDateString(),\n 'maxDate' => now($userTimezone)->addYear()->toDateString(),\n ],\n 'value' => $report?->getExpiresAt()?->toDateString(),\n ],\n [\n 'id' => 'share_teams',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'label' => 'Team',\n 'required' => false,\n 'placeholder' => 'Select',\n 'options' => $teamGroups,\n 'value' => $sharedTeamsValue,\n ],\n [\n 'id' => 'share_users',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'label' => 'Team member',\n 'required' => false,\n 'placeholder' => 'Select',\n 'groupLabelKey' => 'label',\n 'groupValuesKey' => 'users',\n 'optionLabelKey' => 'name',\n 'optionValueKey' => 'id',\n 'options' => $shareUsers,\n 'value' => $sharedUsersValue,\n ],\n [\n 'id' => 'saved_search',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'label' => 'Saved search',\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => $savedSearches,\n 'value' => $report && $report->getSavedSearch() ? [\n 'id' => $report->getSavedSearch()->getUuid(),\n 'name' => $report->getSavedSearch()->getName(),\n ] : null,\n ],\n [\n 'id' => 'ask_jiminny_prompt',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'label' => 'Ask Jiminny prompt',\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => $prompts,\n 'value' => $report && $report->getAskAnythingPrompt() ? [\n 'id' => $report->getAskAnythingPrompt()->getUuid(),\n 'name' => $report->getAskAnythingPrompt()->getTitle(),\n ] : null,\n ],\n ],\n ];\n }\n\n private function updateResultNames(AutomatedReport $automatedReport): void\n {\n $results = $this->automatedReportsRepository->getResultsByReport($automatedReport);\n\n foreach ($results as $result) {\n $result->update(['name' => $this->getReportFileName($result)]);\n }\n }\n\n public function updateStatus(string $uuid, array $data): array\n {\n $automatedReport = $this->automatedReportsRepository->findByUuid($uuid);\n\n if (! $automatedReport) {\n throw new ModelNotFoundException('Report not found');\n }\n\n $status = $this->validateReportStatus($data['report_enabled'] ?? null);\n $automatedReport->update([\n 'status' => $status,\n ]);\n\n $this->generateOneOffReport($automatedReport);\n\n return $this->transformReportFullView($automatedReport);\n }\n\n private function generateOneOffReport(AutomatedReport $automatedReport): void\n {\n // the scheduler handles all the other frequency types\n if ($automatedReport->getStatus() === false || $automatedReport->getFrequency() !== self::FREQUENCY_ONE_OFF) {\n return;\n }\n\n $this->dispatcher->dispatch(new RequestGenerateReportJob($automatedReport->getUuid()));\n }\n\n public function getReport(string $uuid): AutomatedReport\n {\n $automatedReport = $this->automatedReportsRepository->findByUuid($uuid);\n\n if (! $automatedReport) {\n throw new ModelNotFoundException('Report not found');\n }\n\n return $automatedReport;\n }\n\n public function get(string $uuid): array\n {\n $automatedReport = $this->getReport($uuid);\n\n return $this->transformReportFullView($automatedReport);\n }\n\n public function list(string $sortColumn = 'created_at', string $sortDirection = 'desc'): array\n {\n $results = [];\n $collection = $this->automatedReportsRepository->getAllStandardReports($sortColumn, $sortDirection);\n\n /** @var AutomatedReport $report */\n foreach ($collection as $report) {\n $results[] = $this->transformReportFullView($report);\n }\n\n return ['data' => $results];\n }\n\n public function listAskJiminnyReports(\n User $user,\n string $sortColumn = 'created_at',\n string $sortDirection = 'desc'\n ): array {\n $results = [];\n $collection = $this->automatedReportsRepository->getAskJiminnyReportsByUser($user, $sortColumn, $sortDirection);\n\n /** @var AutomatedReport $report */\n foreach ($collection as $report) {\n $results[] = $this->transformReportFullView($report);\n }\n\n return ['data' => $results];\n }\n\n public function delete(string $uuid): void\n {\n $automatedReport = $this->automatedReportsRepository->findByUuid($uuid);\n\n if (! $automatedReport) {\n throw new ModelNotFoundException('Report not found');\n }\n\n $automatedReport->delete();\n }\n\n public function createReportResult(AutomatedReport $automatedReport, array $data = []): AutomatedReportResult\n {\n return $this->automatedReportsRepository->createResult(\n array_merge(\n [\n 'report_id' => $automatedReport->getId(),\n 'status' => AutomatedReportResult::STATUS_DEFAULT,\n ],\n $data\n )\n );\n }\n\n public function getReportResult(string $resultUuid): AutomatedReportResult\n {\n $report = $this->automatedReportsRepository->findResultByUuid($resultUuid);\n\n if (! $report) {\n throw new ModelNotFoundException('Report Result not found');\n }\n\n return $report;\n }\n\n public function findChildResult(AutomatedReportResult $result, string $type): ?AutomatedReportResult\n {\n return $this->automatedReportsRepository->findChildResult($result, $type);\n }\n\n // prophet API calls\n /**\n * @throws ApplicationException\n */\n public function getGenerateReportPayload(AutomatedReport $automatedReport, string $reportResultUuid): array\n {\n $period = $this->calculateFromAndToDate($automatedReport);\n $fromDate = $period['fromDate'];\n $toDate = $period['toDate'];\n\n return [\n 'team_id' => $automatedReport->getTeamId(),\n 'request_id' => $reportResultUuid,\n 'report_type' => $automatedReport->getType(),\n 'media_types' => $automatedReport->getMediaTypes(),\n 'from_date' => $fromDate->startOfDay()->format(DateTimeInterface::RFC3339),\n 'to_date' => $toDate->endOfDay()->format(DateTimeInterface::RFC3339),\n 'group_ids' => $automatedReport->getGroups(),\n 'call_deal_stage' => $automatedReport->getDealAtCallStages(),\n 'current_deal_stage' => $automatedReport->getCurrentDealStages(),\n 'deal_min_value' => $automatedReport->getDealValueMin(),\n 'deal_max_value' => $automatedReport->getDealValueMax(),\n 'call_types' => $automatedReport->getCallTypes(),\n 'call_duration_min_seconds' => $automatedReport->getCallDurationMin(),\n 'call_duration_max_seconds' => $automatedReport->getCallDurationMax(),\n 'special_requirements' => $automatedReport->getAdditionalPromptInput(),\n 'callback_url' => $this->getCallbackUrl(),\n 'report_period' => $this->formatReportPeriodName(\n $automatedReport->getFrequency(),\n $fromDate,\n $toDate,\n ),\n 'playbook_categories' => $automatedReport->getPlaybookCategories(),\n 'custom_name' => $automatedReport->getCustomName(),\n ];\n }\n\n // $inputPayload - FE payload structure\n public function getActivitiesCountPayload(array $inputPayload): array\n {\n // Use validateAndTransformData to validate and normalize input\n $validatedData = $this->validateAndTransformData($inputPayload);\n $period = $this->calculateFromAndToDatePeriod(\n $validatedData['frequency'],\n Carbon::parse($validatedData['from']),\n Carbon::parse($validatedData['to']),\n );\n $fromDate = $period['fromDate'];\n $toDate = $period['toDate'];\n\n // Create payload similar to getGenerateReportPayload\n return [\n 'team_id' => $validatedData['team_id'],\n 'group_ids' => $validatedData['groups'] ?? [],\n 'report_type' => $validatedData['type'],\n 'from_date' => $fromDate->format(DateTimeInterface::RFC3339),\n 'to_date' => $toDate->format(DateTimeInterface::RFC3339),\n 'call_deal_stage' => $validatedData['deal_at_call_stages'] ?? [],\n 'current_deal_stage' => $validatedData['current_deal_stages'] ?? [],\n 'deal_min_value' => $validatedData['deal_value_min'] ?? null,\n 'deal_max_value' => $validatedData['deal_value_max'] ?? null,\n 'call_types' => $validatedData['call_types'],\n 'call_duration_min_seconds' => $validatedData['call_duration_min'] ?? null,\n 'call_duration_max_seconds' => $validatedData['call_duration_max'] ?? null,\n 'special_requirements' => $validatedData['additional_prompt_input'] ?? null,\n 'playbook_categories' => $validatedData['playbook_categories'] ?? [],\n 'request_id' => null,\n 'callback_url' => null,\n ];\n }\n\n public function shouldSendReport(array $users, ?CarbonInterface $generatedAt = null): bool\n {\n if (empty($users)) {\n return false;\n }\n\n $earliestTz = collect($users)\n ->mapWithKeys(function (array $user) {\n $tz = new DateTimeZone($user['timezone']);\n $nowUtc = new DateTime('now', new DateTimeZone('UTC'));\n $offset = $tz->getOffset($nowUtc);\n\n return [$user['timezone'] => $offset];\n })\n ->sortDesc()\n ->keys()\n ->first();\n\n $now = Carbon::now($earliestTz);\n $isScheduledTime = (int) $now->format('H') === self::SENT_REPORT_AT_HOURS;\n\n if ($isScheduledTime) {\n return true;\n }\n\n return $this->hasPassedScheduledTime($generatedAt, $earliestTz);\n }\n\n public function hasPassedScheduledTime(?CarbonInterface $generatedAt, string $timezone): bool\n {\n if ($generatedAt === null) {\n return false;\n }\n\n $now = Carbon::now($timezone);\n $scheduledTime = $now->copy()->setTime(self::SENT_REPORT_AT_HOURS, 0, 0);\n\n if ($now->hour < self::SENT_REPORT_AT_HOURS) {\n $scheduledTime = $scheduledTime->subDay();\n }\n\n $scheduledTimeUtc = $scheduledTime->copy()->utc();\n $generatedAtUtc = $generatedAt->copy()->utc();\n $nowUtc = $now->copy()->utc();\n\n return $generatedAtUtc->lt($scheduledTimeUtc) && $nowUtc->gt($scheduledTimeUtc);\n }\n\n public function calculateFromAndToDatePeriod(\n string $frequency,\n ?Carbon $fromDate = null,\n ?Carbon $toDate = null\n ): array {\n if ($frequency === self::FREQUENCY_ONE_OFF) {\n return [\n 'fromDate' => $fromDate,\n 'toDate' => $toDate,\n ];\n }\n\n $now = Carbon::now();\n\n return match ($frequency) {\n self::FREQUENCY_DAILY => [\n 'fromDate' => $now->copy()->subDay()->startOfDay(),\n 'toDate' => $now->copy()->subDay()->endOfDay(),\n ],\n self::FREQUENCY_WEEKLY => [\n 'fromDate' => $now->copy()->subWeeks(1)->startOfDay(),\n 'toDate' => $now->copy()->subDay()->endOfDay(),\n ],\n self::FREQUENCY_MONTHLY => [\n 'fromDate' => $now->copy()->subMonths(1)->startOfDay(),\n 'toDate' => $now->copy()->subDay()->endOfDay(),\n ],\n self::FREQUENCY_QUARTERLY => [\n 'fromDate' => $now->copy()->subMonths(3)->startOfDay(),\n 'toDate' => $now->copy()->subDay()->endOfDay(),\n ],\n default => throw new InvalidArgumentException(\"Unsupported frequency: {$frequency}\"),\n };\n }\n\n private function calculateFromAndToDate(AutomatedReport $automatedReport): array\n {\n return $this->calculateFromAndToDatePeriod(\n $automatedReport->getFrequency(),\n $automatedReport->getFrom(),\n $automatedReport->getTo()\n );\n }\n\n public function getAskJiminnyGenerateReportPayload(\n AutomatedReport $automatedReport,\n AutomatedReportResult $reportResult,\n array $activityIds,\n ): array {\n return [\n 'user_question' => $automatedReport->getAskAnythingPrompt()?->getContent(),\n 'call_ids' => array_map('strval', $activityIds),\n 'team_id' => $automatedReport->getTeamId(),\n 'request_id' => $reportResult->getUuid(),\n 'callback_url' => $this->getCallbackUrl(),\n 'report_period' => $this->getReportPeriodName($reportResult),\n 'report_name' => $automatedReport->getCustomName(),\n ];\n }\n\n private function getCallbackUrl(): string\n {\n return $this->webhookService->route('jiminny.webhook.reports.ready');\n }\n\n /**\n * Validate and transform payload data for automated reports\n *\n * @param array $data\n *\n * @throws InvalidArgumentException\n *\n * @return array\n */\n private function validateAndTransformData(array $data): array\n {\n // Validate organization (team) and check feature\n $team = $this->validateOrganization($data['organization'] ?? null);\n\n $status = $this->validateReportStatus($data['report_enabled'] ?? null);\n $type = $this->validateReportType($data['report_type'] ?? null);\n $frequency = $this->validateFrequency($data['frequency'] ?? null);\n $additionalPromptInput = $this->validateAdditionalPromptInput(\n $data['additional_prompt_input'] ?? null\n );\n $customReportName = $this->validateCustomReportName($data['custom_name'] ?? null);\n\n // Prepare data for the database\n $reportData = [\n 'team_id' => $team->getId(),\n 'type' => $type,\n 'status' => $status,\n 'frequency' => $frequency,\n 'additional_prompt_input' => $additionalPromptInput,\n 'custom_name' => $customReportName,\n ];\n\n // Validate deal values\n $reportData = $this->validateDealValues($data, $reportData);\n\n // Validate date range\n $reportData = $this->validateDateRange($data, $reportData, $frequency);\n\n // Validate call durations\n $reportData = $this->validateCallDurations($data, $reportData);\n\n // Validate call types\n $reportData = $this->validateCallTypes($data, $reportData);\n\n // Validate media types\n $reportData = $this->validateMediaTypes($data, $reportData);\n\n // Validate groups\n if (isset($data['teams'])) {\n $reportData['groups'] = $this->validateAndGetGroupIds($team, $data['teams']);\n }\n\n // Validate deal stages\n $reportData = $this->validateDealStages($data, $reportData, $team, $type);\n\n // Validate playbook categories\n $reportData = $this->validatePlaybookCategories($data, $reportData, $team);\n\n // Validate recipients\n $reportData['recipients'] = [\n 'users' => $this->validateAndGetUserIdsByTeam($team, $data['recipients'] ?? []),\n ];\n\n if (isset($data['jiminny_recipients'])) {\n // Validate Jiminny recipients\n $reportData['jiminny_recipients'] = [\n 'users' => $this->validateAndGetJiminnyUserIds((array) $data['jiminny_recipients']),\n ];\n }\n\n return $reportData;\n }\n\n private function validateDealValues(array $data, array $reportData): array\n {\n if (isset($data['min_deal_value'])) {\n $reportData['deal_value_min'] = (int) $data['min_deal_value'];\n\n if ($reportData['deal_value_min'] > 4294967295 || $reportData['deal_value_min'] < 0) {\n throw new InvalidArgumentException('Min deal value should be between 0 and 4294967295');\n }\n }\n\n if (isset($data['max_deal_value'])) {\n $reportData['deal_value_max'] = (int) $data['max_deal_value'];\n\n if ($reportData['deal_value_max'] > 4294967295 || $reportData['deal_value_max'] < 0) {\n throw new InvalidArgumentException('Max deal value should be between 0 and 4294967295');\n }\n }\n\n if (isset($data['min_deal_value'], $data['max_deal_value'])\n && $data['min_deal_value'] > $data['max_deal_value']\n ) {\n throw new InvalidArgumentException('Min deal value cannot be greater than max deal value');\n }\n\n return $reportData;\n }\n\n private function validateDateRange(array $data, array $reportData, string $frequency): array\n {\n // Set date range only for one_off frequency\n if ($frequency === 'one_off') {\n if (isset($data['start_date_period'])) {\n $reportData['from'] = $this->parseDate($data['start_date_period']);\n }\n\n if (isset($data['end_date_period'])) {\n $reportData['to'] = $this->parseDate($data['end_date_period']);\n }\n\n if (empty($reportData['from']) || empty($reportData['to'])) {\n throw new InvalidArgumentException(\n 'Start date and end date are required for one_off frequency'\n );\n }\n } else {\n $reportData['from'] = null;\n $reportData['to'] = null;\n }\n\n return $reportData;\n }\n\n private function validateCallDurations(array $data, array $reportData): array\n {\n // Convert call durations from minutes to seconds\n if (isset($data['min_call_duration'])) {\n $reportData['call_duration_min'] = (int) $data['min_call_duration'] * 60;\n\n if ($reportData['call_duration_min'] > 4294967295 || $reportData['call_duration_min'] < 0) {\n throw new InvalidArgumentException('Min call duration should be between 0 and 4294967295');\n }\n }\n\n if (isset($data['max_call_duration'])) {\n $reportData['call_duration_max'] = (int) $data['max_call_duration'] * 60;\n\n if ($reportData['call_duration_max'] > 4294967295 || $reportData['call_duration_max'] < 0) {\n throw new InvalidArgumentException('Max call duration should be between 0 and 4294967295');\n }\n }\n\n return $reportData;\n }\n\n private function validateCallTypes(array $data, array $reportData): array\n {\n // Set call types\n $reportData['call_types'] = $data['call_type'] ?? [];\n if (empty($reportData['call_types'])) {\n $reportData['call_types'] = self::getCallTypes();\n }\n\n foreach ($reportData['call_types'] as $callType) {\n if (! in_array($callType, self::getCallTypes(), true)) {\n throw new InvalidArgumentException(sprintf('Call type %s is invalid', $callType));\n }\n }\n\n return $reportData;\n }\n\n private function validateMediaTypes(array $data, array $reportData): array\n {\n // Set media types from input data\n $reportData['media_types'] = $data['media_types'] ?? [];\n\n if (empty($reportData['media_types'])) {\n throw new InvalidArgumentException('Media types are required');\n }\n\n foreach ($reportData['media_types'] as $mediaType) {\n if (! in_array($mediaType, self::MEDIA_TYPES, true)) {\n throw new InvalidArgumentException(sprintf('Media type %s is invalid', $mediaType));\n }\n }\n\n return $reportData;\n }\n\n private function validateDealStages(array $data, array $reportData, Team $team, string $reportType): array\n {\n // Validate and set deal stages\n if (isset($data['deal_stage_at_call'])) {\n $reportData['deal_at_call_stages'] =\n $this->validateAndGetDealStageIds($team, $data['deal_stage_at_call'], 'Deal stage at call');\n }\n\n if (isset($data['current_deal_stage'])) {\n $reportData['current_deal_stages'] =\n $this->validateAndGetDealStageIds($team, $data['current_deal_stage'], 'Current deal stage');\n }\n\n // Ensure current_deal_stage is not provided for loss_analysis report type\n if ($reportType === self::TYPE_LOSS_ANALYSIS && ! empty($data['current_deal_stage'])) {\n throw new InvalidArgumentException('Current deal stage is not applicable for Loss Analysis reports');\n }\n\n return $reportData;\n }\n\n // transform uuid to id\n private function validatePlaybookCategories(array $data, array $reportData, Team $team): array\n {\n $key = 'playbook_categories';\n\n if (isset($data[$key])) {\n $payloadIds = $data[$key];\n $ids = [];\n\n foreach ($payloadIds as $uuid) {\n $uuid = (string) $uuid;\n\n try {\n $playbookCategory = $this->playbookCategoryRepository->findByUuid($uuid);\n } catch (Throwable $throwable) {\n Log::error(__METHOD__ . ' ' . $throwable->getMessage());\n\n throw new InvalidArgumentException(sprintf('Playbook category %s not found', $uuid));\n }\n\n if (! $playbookCategory) {\n throw new InvalidArgumentException(sprintf('Playbook category %s not found', $uuid));\n }\n\n if (! $playbookCategory->hasPlaybook()) {\n throw new InvalidArgumentException(sprintf('Playbook category %s has no playbook', $uuid));\n }\n\n if ($playbookCategory->getPlaybook()->getTeamId() !== $team->getId()) {\n throw new InvalidArgumentException(\n sprintf('Playbook category %s not found for team %s', $uuid, $team->getUuid())\n );\n }\n\n $ids[] = $playbookCategory->getId();\n }\n\n $reportData[$key] = $ids;\n }\n\n return $reportData;\n }\n\n private function validateReportStatus($status): bool\n {\n if (! in_array($status, [true, false], true)) {\n throw new InvalidArgumentException('Report status is invalid');\n }\n\n return $status;\n }\n\n private function validateReportType($type): string\n {\n if (! in_array($type, self::getTypes(), true)) {\n throw new InvalidArgumentException(sprintf('Report type is invalid: %s', $type));\n }\n\n return $type;\n }\n\n private function validateFrequency($frequency): string\n {\n if (! in_array($frequency, self::getFrequencies(), true)) {\n throw new InvalidArgumentException('Frequency is invalid');\n }\n\n return $frequency;\n }\n\n private function validateAdditionalPromptInput(?string $additionalPromptInput): ?string\n {\n if ($additionalPromptInput && strlen($additionalPromptInput) > 5000) {\n throw new InvalidArgumentException('Additional Prompt Input should be less than 5000 characters');\n }\n\n return $additionalPromptInput;\n }\n\n private function validateCustomReportName(?string $customReportName): ?string\n {\n if ($customReportName === null || $customReportName === '') {\n return null;\n }\n\n if (strlen($customReportName) > 70) {\n throw new InvalidArgumentException('Custom report name should be less than 70 characters');\n }\n\n return $customReportName;\n }\n\n private function validateOrganization(?string $organizationUuid): Team\n {\n if (! $organizationUuid) {\n throw new InvalidArgumentException('Organization is required');\n }\n\n $team = $this->teamRepository->idOrUuid($organizationUuid);\n\n if (! $team) {\n throw new InvalidArgumentException('Organization not found');\n }\n\n if (! $team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {\n throw new InvalidArgumentException('Organization does not have the Automated Reports feature');\n }\n\n return $team;\n }\n\n private function validateAndGetGroupIds(Team $team, array $teamUuids): array\n {\n $groupIds = [];\n\n foreach ($teamUuids as $uuid) {\n $group = $this->groupRepository->findByUuid($uuid);\n\n if ($group === null || $group->getTeamId() !== $team->getId()) {\n throw new InvalidArgumentException(\n sprintf('Group %s not found for team %s', $uuid, $team->getUuid())\n );\n }\n\n $groupIds[] = $group->getId();\n\n }\n\n return $groupIds;\n }\n\n private function validateAndGetDealStageIds(Team $team, array $stageUuids, string $propertyLabel): array\n {\n $stageIds = [];\n\n foreach ($stageUuids as $uuid) {\n $stage = $this->stageRepository->findByUuid($uuid);\n\n if ($stage === null || $stage->getTeamId() !== $team->getId()) {\n throw new InvalidArgumentException(\n sprintf('Stage %s not found for team %s for %s', $uuid, $team->getUuid(), $propertyLabel)\n );\n }\n\n $stageIds[] = $stage->getId();\n }\n\n return $stageIds;\n }\n\n private function validateAndGetUserIds(array $userUuids, callable $teamCheck): array\n {\n if (empty($userUuids)) {\n return [];\n }\n\n $userIds = [];\n\n foreach ($userUuids as $uuid) {\n $user = $this->userRepository->findByUuid($uuid);\n\n if (! $user || ! $user->isStatusActive()) {\n throw new InvalidArgumentException(\n sprintf('User %s not found or is not active', $uuid)\n );\n }\n\n if (! $teamCheck($user)) {\n throw new InvalidArgumentException(\n sprintf('User %s does not belong to the allowed team(s)', $uuid)\n );\n }\n\n $userIds[] = $user->getId();\n }\n\n return $userIds;\n }\n\n private function validateAndGetUserIdsByTeam(Team $team, array $userUuids): array\n {\n return $this->validateAndGetUserIds($userUuids, fn ($user) => $user->getTeamId() === $team->getId());\n }\n\n private function validateAndGetJiminnyUserIds(array $userUuids): array\n {\n $allowedTeamIds = config('kiosk.teamIds', []);\n\n return $this->validateAndGetUserIds($userUuids, fn ($user) => in_array($user->getTeamId(), $allowedTeamIds, true));\n }\n\n private function parseDate(string $dateString): string\n {\n return date('Y-m-d H:i:s', strtotime($dateString));\n }\n\n private function generateReportResultViewUrl(AutomatedReportResult $result): string\n {\n $mediaResource = $this->getReportMediaRouteResource($result);\n\n return route('ai-reports.' . $mediaResource . '.view', ['uuid' => $result->getUuid()]);\n }\n\n private function generateReportResultDownloadUrl(AutomatedReportResult $result): string\n {\n $mediaResource = $this->getReportMediaRouteResource($result);\n\n return route('ai-reports.' . $mediaResource . '.download', ['uuid' => $result->getUuid()]);\n }\n\n private function getReportMediaRouteResource(AutomatedReportResult $result): string\n {\n if ($result->getMediaType() === self::MEDIA_TYPE_PDF) {\n return self::PDF_KEY;\n } elseif ($result->getMediaType() === self::MEDIA_TYPE_PODCAST) {\n return self::AUDIO_KEY;\n }\n\n throw new \\InvalidArgumentException('Unknown media type.');\n }\n\n public function getMediaPath(AutomatedReportResult $result): ?string\n {\n $url = match ($result->getMediaType()) {\n self::MEDIA_TYPE_PDF => $result->getPdfUrl(),\n self::MEDIA_TYPE_PODCAST => $result->getPodcastAudioUrl(),\n default => null,\n };\n\n if ($url === null) {\n return null;\n }\n\n $path = parse_url(trim($url, '\"\\''), PHP_URL_PATH);\n\n return $path ?: null;\n }\n\n public function getFilenameSuffix(AutomatedReportResult $result): ?string\n {\n return match ($result->getMediaType()) {\n self::MEDIA_TYPE_PODCAST => 'Podcast',\n default => null,\n };\n }\n\n public function getMailSubjectSuffix(AutomatedReportResult $result): string\n {\n return match ($result->getMediaType()) {\n self::MEDIA_TYPE_PDF => 'report',\n self::MEDIA_TYPE_PODCAST => 'podcast',\n default => '',\n };\n }\n\n public function getMediaTypeMetadata(AutomatedReportResult $result): array\n {\n return match ($result->getMediaType()) {\n self::MEDIA_TYPE_PODCAST => ['extension' => 'mp3', 'mime' => 'audio/mpeg'],\n self::MEDIA_TYPE_PDF => ['extension' => 'pdf', 'mime' => 'application/pdf'],\n default => ['extension' => null, 'mime' => null],\n };\n }\n\n public function deleteS3Files(AutomatedReportResult $result): void\n {\n $teamUuid = $result->getReport()->getTeam()->getUuid();\n $reportUuid = $result->getUuid();\n\n // delete all files for a report uuid no mather of pdf, podcast, or both\n // in case of both - the podcast files are linked to the pdf (parent) uuid\n // pdf and podcast date times should be close\n $path = sprintf('%s/%s/%s', $teamUuid, self::S3_DIR, $reportUuid);\n\n foreach (self::FILE_EXTENSIONS_VARIANTS as $extension) {\n $file = $path . '.' . $extension;\n\n if (Storage::exists($file)) {\n Storage::delete($file);\n Log::info('[Reports] Deleted S3 file', [\n 'path' => $file,\n ]);\n }\n }\n\n foreach (self::FILE_PODCAST_EXTENSIONS_VARIANTS as $extension) {\n $file = $path . '_podcast.' . $extension;\n\n if (Storage::exists($file)) {\n Storage::delete($file);\n Log::info('[Reports] Deleted Podcast S3 file', [\n 'path' => $file,\n ]);\n }\n }\n }\n\n /**\n *\n * @param int|null $teamId Optional team ID to filter results\n *\n * @return Collection<int, int> Collection of team IDs\n */\n public function getTeamIdsWithReportsResults(?int $teamId = null): Collection\n {\n return $this->automatedReportsRepository->getTeamIdsWithReportsResults($teamId);\n }\n\n /**\n * Core delete logic for report results using a query\n *\n * @param Builder $query\n * @param array $logContext\n *\n * @return int\n */\n private function deleteReportResultsByQuery(Builder $query, array $logContext = []): int\n {\n $deletedCount = 0;\n\n if ($query->exists()) {\n Log::info(\n 'Run delete report results',\n array_merge(\n $logContext,\n [\n 'service' => 'AutomatedReportsService',\n ]\n )\n );\n\n $query->chunkById(50, function ($results) use (&$deletedCount, $logContext) {\n foreach ($results as $result) {\n $this->deleteReportResult($result);\n $deletedCount++;\n\n Log::info(\n 'Deleted a report result',\n array_merge(\n $logContext,\n [\n 'result_id' => $result->getId(),\n 'report_id' => $result->getReportId(),\n ]\n )\n );\n }\n });\n }\n\n return $deletedCount;\n }\n\n /**\n * Delete report results for a team by retention period\n *\n * @param Team $team\n * @param CarbonImmutable $retentionDate\n *\n * @return int Number of deleted report results\n */\n public function deleteReportsResultsInRetentionPeriod(Team $team, CarbonImmutable $retentionDate): int\n {\n $reportIds = $this->automatedReportsRepository->getReportIdsByTeam($team);\n\n if ($reportIds->isEmpty()) {\n return 0;\n }\n\n $query = $this->automatedReportsRepository\n ->getReportResultsQueryForRetention($team, $retentionDate);\n\n return $this->deleteReportResultsByQuery($query, [\n 'team_id' => $team->getId(),\n 'retention_date' => $retentionDate->toDateTimeString(),\n ]);\n }\n\n /**\n * Delete ALL report results for a specific automated report\n *\n * @param string $uuid\n *\n * @return int\n */\n public function deleteReportResults(string $uuid): int\n {\n $report = $this->getReport($uuid);\n\n $query = $this->automatedReportsRepository->getResultsByReportQuery($report);\n\n return $this->deleteReportResultsByQuery($query, [\n 'report_uuid' => $uuid,\n 'report_id' => $report->getId(),\n ]);\n }\n\n public function deleteReportResult(AutomatedReportResult $result): void\n {\n $this->deleteS3Files($result);\n\n $result->delete();\n }\n\n /**\n * Get all reports for a specific team\n *\n * @param Team $team\n *\n * @return \\Illuminate\\Database\\Eloquent\\Collection\n */\n public function getTeamReports(Team $team): \\Illuminate\\Database\\Eloquent\\Collection\n {\n return $this->automatedReportsRepository->getReportsByTeam($team);\n }\n\n /**\n * Get all report results for a specific report\n *\n * @param AutomatedReport $report\n *\n * @return \\Illuminate\\Database\\Eloquent\\Collection\n */\n public function getReportResults(AutomatedReport $report): \\Illuminate\\Database\\Eloquent\\Collection\n {\n return $this->automatedReportsRepository->getResultsByReport($report);\n }\n\n public function deleteAllReportResults(AutomatedReport $report): void\n {\n $results = $this->getReportResults($report);\n\n /** @var AutomatedReportResult $result */\n foreach ($results as $result) {\n Log::info('Deleting result', [\n 'report' => $report->getId(),\n 'result' => $result->getId(),\n ]);\n\n $this->deleteReportResult($result);\n }\n }\n\n public function deleteAllData(Team $team): void\n {\n Log::info('Deleting automated report and results for team', [\n 'team' => $team->getId(),\n ]);\n\n $reports = $this->getTeamReports($team);\n\n /** @var AutomatedReport $report */\n foreach ($reports as $report) {\n Log::info('Deleting report', [\n 'team' => $team->getId(),\n 'report' => $report->getId(),\n ]);\n\n $this->deleteAllReportResults($report);\n\n $report->delete();\n }\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":true,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"Project","depth":3,"role_description":"text"},{"role":"AXButton","text":"Project","depth":3,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"New File or Directory…","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Expand Selected","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Collapse All","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Options","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false}]...
|
3397592283435315795
|
6686367547760219213
|
idle
|
accessibility
|
NULL
|
Project: faVsco.js, menu
#11894 on JY-18909-automa Project: faVsco.js, menu
#11894 on JY-18909-automated-reports-ask-jiminny, menu
Start Listening for PHP Debug Connections
AutomatedReportsCommandTest
Run 'AutomatedReportsCommandTest'
Debug 'AutomatedReportsCommandTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Execute
Explain Plan
Browse Query History
View Parameters
Open Query Execution Settings…
In-Editor Results
Tx: Auto
Cancel Running Statements
Playground
jiminny
Sync Changes
Hide This Notification
Code changed:
Hide
16
13
13
Previous Highlighted Error
Next Highlighted Error
SELECT * FROM teams WHERE id = 1;
select * from crm_layouts where crm_configuration_id = 39;
SELECT * FROM crm_layout_entities WHERE crm_layout_id = 283;
SELECT * FROM crm_fields WHERE id = 2234;
SELECT * FROM crm_field_values WHERE crm_field_id = 2234;
select * from crm_profiles where user_id = 143;
select * from record_types where crm_configuration_id = 39; # 0121K000001MHElQAO,0121K000001MHEqQAO
select * from business_processes where crm_configuration_id = 39;
# 01941000000H669AAC, 01941000000H66JAAS
select * from record_type_field_values
where record_type_id IN (24);
select * from crm_field_values where id IN (2730);
select * from crm_configurations where id = 39;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 1
and sa.provider = 'salesforce'; #1035
select * from users where team_id = 1; # 222 group 3
SELECT * FROM activities WHERE user_id = 222 order by id desc;
select * from sidekick_settings where team_id = 1;
select * from teams where id = 1;
select * from team_features where team_id = 1;
select * from activities where crm_configuration_id = 2
and provider = 'ms-teams' and id = 608765;
SELECT * FROM activities WHERE crm_configuration_id = 2 and crm_provider_id = '59523413338';
select * from sidekick_settings where team_id = 2;
SELECT * FROM activities WHERE id = 608660;
select * from activity_summary_logs where activity_id = 608660;
select * from ai_prompts where transcription_id = 11214;
# [PASSWORD_DOTS]
SELECT * FROM activities WHERE uuid_to_bin('ed78a437-2804-450e-ab2f-56ab1c641346') = uuid;
# id: 608818, crm: 59628809737
SELECT * FROM activities WHERE uuid_to_bin('36b06e55-afdd-4782-8dee-c624cd0af191') = uuid;
# id: 608821, crm: 59632069252
SELECT ce.start_time, ce.end_time, a.id, a.uuid, crm_provider_id, calendar_event_id, title,
playbook_category_id, user_id, lead_id, contact_id, account_id, opportunity_id,
scheduled_start_time, scheduled_end_time, actual_start_time, actual_end_time, a.created_at
FROM activities a
join calendar_events ce on a.calendar_event_id = ce.id
WHERE a.id IN (608818, 608821);
select * from users where team_id = 1;
select * from team_settings where team_id = 1;
select * from crm_profiles where crm_configuration_id = 39 order by user_id;
select * from team_features where team_id = 1;
select * from users where team_id = 2;
SELECT * FROM activities WHERE uuid_to_bin('ec7647e9-5225-458b-b475-f31aa2769204') = uuid; # 612639
# Preslava N. Ivanova, grou id 3
SELECT * FROM opportunities WHERE uuid_to_bin('a2928fe5-aec5-46cb-85d9-7654c89e46a6') = uuid;
select * from activities where opportunity_id = 344 and actual_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00';
select
a.id,
a.type,
a.scheduled_start_time,
a.actual_start_time,
a.created_at,
a.opportunity_id,
a.status
FROM activities a
WHERE opportunity_id = 344
and status IN ('completed', 'received', 'delivered')
and (
(a.actual_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00')
OR (a.created_at between '2024-10-11 00:00:00' and '2024-10-12 00:00:00')
OR (a.scheduled_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00'))
;
SELECT * FROM users WHERE id = 222;
SELECT * FROM crm_profiles WHERE user_id = 222;
select * from crm_layouts where crm_configuration_id = 39;
SELECT * FROM crm_layout_entities WHERE crm_layout_id = 281;
select * from group_deal_risk_types;
select * from opportunities where team_id = 1;
SELECT * FROM opportunities WHERE id = 315;
SELECT * FROM crm_field_data WHERE object_id = 315;
select * from crm_field_data where object_id = 260;
select * from generic_ai_prompts where subject_id = 315;
select * from teams; # 36, 21, 121, [EMAIL]
SELECT * FROM social_accounts WHERE sociable_id = 121 and provider = 'bullhorn';
# [PASSWORD_DOTS]
select * from teams where id = 1;
select * from crm_configurations where id = 39;
select * from users where team_id = 1;
select u.email, cp.* from users u
join crm_profiles cp on u.id = cp.user_id
where u.team_id = 1;
# 1 - 00541000004281rAAA
# 204 - 0052g000003freeAAA
# 429 - 0052g000003qGOiAAM
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 1
and sa.provider = 'salesforce';
select * from activities where type = 'softphone'
and created_at > '2024-12-11 15:24:36' order by id desc;
select * from activity_providers where team_id = 1;
select * from activity_provider_users where activity_provider_id = 328;
select * from opportunities where crm_configuration_id = 39
AND account_id = 178 AND is_closed = false
order by created_at DESC;
select * from contacts where id = 3952;
select * from accounts where id = 178;
# [PASSWORD_DOTS]
select * from teams where id = 36;
select * from crm_configurations where id = 21;
select * from users where team_id = 36;
select u.email, cp.* from users u
join crm_profiles cp on u.id = cp.user_id
where u.team_id = 36;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 36
and sa.provider = 'bullhorn';
select * from social_accounts where id = 348;
UPDATE social_accounts SET
provider_user_token = '21442_6802599_91:41179a58-21e7-4d7c-ad58-56bb666b2f65',
provider_refresh_token = '21442_6802599_91:01c6b335-3f2a-42e4-85ff-8a08fa65fceb',
expires = 1733998131,
state = 'connected'
WHERE id = 348;
# [PASSWORD_DOTS]
select * from teams where id = 31;
select * from crm_configurations where id = 18;
select * from users where team_id = 31; # 257
select u.email, cp.* from users u
join crm_profiles cp on u.id = cp.user_id
where u.team_id = 31;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 31
and sa.provider = 'close';
select * from contacts where crm_configuration_id = 18;
# [PASSWORD_DOTS] NEPTUNE [PASSWORD_DOTS]
select * from teams;
select * from users where id IN (1030, 1035, 1052);
select * from crm_configurations;
select * from users where team_id = 65; # 257
select * from team_settings where team_id = 65; # 257
select * from invitations where team_id = 65; # 257
select * from users where email = '[EMAIL]'; # 257
select u.email, cp.* from users u
join crm_profiles cp on u.id = cp.user_id
where u.team_id = 65;
select * from crm_configurations where id = 53;
select * from accounts where crm_configuration_id = 53 order by id desc;
select * from leads where crm_configuration_id = 53 order by id desc;
select * from contacts where crm_configuration_id = 53 order by id desc;
select * from opportunities where crm_configuration_id = 53 order by id desc;
select * from crm_profiles where crm_configuration_id = 53 order by id desc;
select * from crm_fields where crm_configuration_id = 53 order by id desc;
select * from crm_field_values where crm_field_id = 3341 order by id desc;
select * from crm_layouts where crm_configuration_id = 53 order by id desc;
select * from stages where crm_configuration_id = 53 order by id desc;
select * from crm_profiles where crm_configuration_id = 13;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 65
and sa.provider = 'integration-app';
select * from contacts where crm_configuration_id = 13;
select * from social_accounts where sociable_id = 283;
SELECT * FROM opportunities WHERE crm_provider_id = '006O400000E9bzeIAB';
select * from activity_providers where team_id = 65;
SELECT * FROM activities WHERE crm_configuration_id IN (51, 52, 53);
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 65
;
# [PASSWORD_DOTS] STAGING [PASSWORD_DOTS]
SELECT * FROM teams;
SELECT * FROM teams WHERE id = 88;
SELECT * FROM teams WHERE id = 89;
select * from team_settings where team_id = 89;
SELECT * FROM users WHERE team_id = 89;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 89;
select * from users;
SELECT * FROM social_accounts WHERE sociable_id = 1761;
SELECT * FROM crm_configurations WHERE id = 70;
select * from accounts where crm_configuration_id = 70 order by id desc;
select * from leads where crm_configuration_id = 70 order by id desc;
select * from contacts where crm_configuration_id = 70 order by id desc;
select * from opportunities where crm_configuration_id = 70 order by id desc;
select * from crm_profiles where crm_configuration_id = 70 order by id desc;
select * from crm_fields where crm_configuration_id = 70 order by id desc;
select * from crm_field_values where crm_field_id = 3536 order by id desc;
select * from crm_layouts where crm_configuration_id = 70 order by id desc;
select * from stages where crm_configuration_id = 70 order by id desc;
select * from business_processes where crm_configuration_id = 70 order by id desc;
select * from business_process_stages where business_process_id = 34;
select * from contacts where id = 10468;
select * from crm_layouts where crm_configuration_id = 70;
SELECT * FROM crm_layout_entities WHERE crm_layout_id = 388;
SELECT * FROM crm_fields WHERE id IN (3533,3534,3535);
select * from activities where crm_configuration_id = 70
and (account_id IS NOT NULL or lead_id IS NOT NULL or contact_id IS NOT NULL or opportunity_id IS NOT NULL) order by id desc;
SELECT * FROM activities WHERE uuid_to_bin('2e10b60f-8a61-41c5-a3d4-28835353dc65') = uuid;
SELECT * FROM activities where crm_configuration_id = 69 ;
SELECT * FROM users WHERE email LIKE '%[EMAIL]%';
SELECT * FROM activities WHERE uuid_to_bin('5a150c93-40fc-42ec-b3bd-c1d328e09f6e') = uuid;
SELECT * FROM opportunities WHERE id = 385;
select * from participants p
join activities a on p.activity_id = a.id
where a.crm_configuration_id = 70
and (p.lead_id IS NOT NULL or p.contact_id IS NOT NULL);
SELECT * FROM participants WHERE id = 1013638;
select * from teams where id = 90;
select * from users where team_id = 90;
select * from social_accounts where social_accounts.sociable_id IN (1960,1760);
SELECT * FROM crm_profiles WHERE crm_configuration_id = 71;
select * from invitations where team_id = 90;
select * from crm_configurations where id = 71;
select * from accounts where crm_configuration_id = 71 order by id desc;
select * from leads where crm_configuration_id = 71 order by id desc;
select * from contacts where crm_configuration_id = 71 order by id desc;
select * from opportunities where crm_configuration_id = 71 order by id desc;
select * from crm_profiles where crm_configuration_id = 71 order by id desc;
select * from crm_fields where crm_configuration_id = 71 order by id desc;
select * from crm_field_values where crm_field_id = 3341 order by id desc;
select * from crm_layouts where crm_configuration_id = 71 order by id desc;
select * from stages where crm_configuration_id = 71 order by id desc;
select * from users order by secondary_email desc;
select u.id, u.email, u.status, sa.id, sa.provider_user_id from social_accounts sa
join users u on sa.sociable_id = u.id
where sa.provider = 'google' and u.email LIKE 'aneliya%';
select * from failed_jobs order by id desc;
select * from users where email = '[EMAIL]' or secondary_email = '[EMAIL]';
select * from teams;
SELECT * FROM crm_profiles WHERE crm_configuration_id = 39;
SELECT * FROM crm_fields WHERE crm_configuration_id = 39 and object_type = 'task';
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 1
and sa.provider = 'salesforce';
# [PASSWORD_DOTS]
SELECT * FROM activities WHERE uuid_to_bin('c38b3895-fd0f-4b1f-9fb2-c170dba137c6') = uuid;
SELECT * FROM crm_configurations WHERE id = 70;
select * from teams where id = 1;
select * from groups where team_id = 1;
select * from users where team_id = 1;
select o.id, o.name,o.close_date, u.id, u.name, u.group_id, r.id, r.display_name, g.name, g.scope from opportunities o
join users u on o.user_id = u.id
join groups g on u.group_id = g.id
join role_user ru on u.id = ru.user_id
join roles r on ru.role_id = r.id
where o.crm_configuration_id = 39 and close_date > '2024-01-01 00:00:00';
select * from role_user where user_id = 143;
select * from roles;
select * from role_user;
select * from groups where id = 9;
select * from scope_groups where group_id = 9;
# [PASSWORD_DOTS]
select * from teams where id = 36;
select * from crm_configurations;
SELECT * FROM social_accounts WHERE sociable_id = 121;
[URL_WITH_CREDENTIALS] this will add filter, however if we need to control feature by FF we need conditional logic
public const array TYPES = [
['id' => 'exec_summary', 'name' => 'Exec Summary'],
['id' => 'coaching_profiles', 'name' => 'Coaching Profiles'],
['id' => 'product_feedback', 'name' => 'Product Feedback'],
['id' => self::TYPE_LOSS_ANALYSIS, 'name' => 'Loss Analysis'],
// ['id' => 'questions', 'name' => 'Questions'],
// ['id' => 'statistical_quant', 'name' => 'Statistical Quantitative'],
];
public const array ALL_TYPES = [
...self::TYPES,
['id' => self::TYPE_ASK_JIMINNY, 'name' => 'Ask Jiminny'],
];
public const string FREQUENCY_DAILY = 'daily';
public const string FREQUENCY_WEEKLY = 'weekly';
public const string FREQUENCY_MONTHLY = 'monthly';
public const string FREQUENCY_QUARTERLY = 'quarterly';
public const string FREQUENCY_ONE_OFF = 'one_off';
/**
* Frequencies for standard (non-Ask Jiminny) reports.
*/
public const array FREQUENCIES = [
['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],
['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],
['id' => self::FREQUENCY_QUARTERLY, 'name' => 'Quarterly'],
['id' => self::FREQUENCY_ONE_OFF, 'name' => 'One-off'],
];
/**
* Frequencies for Ask Jiminny reports.
*/
public const array ASK_JIMINNY_FREQUENCIES = [
['id' => self::FREQUENCY_DAILY, 'name' => 'Daily'],
['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],
['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],
];
public const string MEDIA_TYPE_PDF = 'pdf';
public const string MEDIA_TYPE_PODCAST = 'podcast';
public const array MEDIA_TYPES = [self::MEDIA_TYPE_PDF, self::MEDIA_TYPE_PODCAST];
public const array MEDIA_TYPE_OBJECT_PDF = ['id' => self::MEDIA_TYPE_PDF, 'name' => 'PDF'];
public const array MEDIA_TYPE_OBJECT_PODCAST = ['id' => self::MEDIA_TYPE_PODCAST, 'name' => 'Podcast'];
public const array MEDIA_TYPE_OBJECTS = [self::MEDIA_TYPE_OBJECT_PDF, self::MEDIA_TYPE_OBJECT_PODCAST];
public const array CALL_TYPE_CONFERENCE = ['id' => 'conference', 'name' => 'Conference'];
public const array CALL_TYPE_DIALER = ['id' => 'dialer', 'name' => 'Dialer'];
public const int SENT_REPORT_AT_HOURS = 5;
public const string PDF_KEY = 'pdf';
public const string AUDIO_KEY = 'audio';
private const array ALL_FREQUENCIES = [
['id' => self::FREQUENCY_DAILY, 'name' => 'Daily'],
['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],
['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],
['id' => self::FREQUENCY_QUARTERLY, 'name' => 'Quarterly'],
['id' => self::FREQUENCY_ONE_OFF, 'name' => 'One-off'],
];
private const string S3_DIR = 'reports';
private const array FILE_EXTENSIONS_VARIANTS = ['html', 'MD', 'pdf'];
private const array FILE_PODCAST_EXTENSIONS_VARIANTS = ['json', 'mp3', 'ssml'];
public function __construct(
private readonly TeamRepository $teamRepository,
private readonly GroupRepository $groupRepository,
private readonly UserRepository $userRepository,
private readonly StageRepository $stageRepository,
private readonly DealStagesService $dealStagesService,
private readonly RecipientsService $recipientsService,
private readonly AutomatedReportsRepository $automatedReportsRepository,
private readonly Webhook $webhookService,
private readonly BusDispatcher $dispatcher,
private readonly ActivityTypeService $activityTypeService,
private readonly PlaybookCategoryRepository $playbookCategoryRepository,
private readonly AskAnythingPromptService $askAnythingPromptService,
private readonly SearchRepository $activitySearchRepository,
private readonly AskAnythingRepository $askAnythingRepository,
) {
}
public static function getTypes(): array
{
$types = self::TYPES;
return array_map(static function ($type) {
return $type['id'];
}, $types);
}
public static function getCallTypes(): array
{
return array_map(static function ($callType) {
return $callType['id'];
}, [self::CALL_TYPE_CONFERENCE, self::CALL_TYPE_DIALER]);
}
public static function getFrequencies(): array
{
return array_map(static function ($frequency) {
return $frequency['id'];
}, self::FREQUENCIES);
}
// front-facing structure
public function getReportEnabledFieldData(bool $value = false): array
{
return [
'id' => 'report_enabled',
'label' => '',
'inputType' => InputTypeEnum::TOGGLE,
'value' => $value,
];
}
// Organizations = Teams
public function getOrganizationFieldData(?string $value = null, bool $shortVersion = false): array
{
$options = $this->getTeams();
if ($shortVersion) {
return [
'id' => 'organization',
'label' => 'Organization',
'options' => $options,
];
}
return [
'id' => 'organization',
'label' => 'Organization',
'inputType' => InputTypeEnum::DROPDOWN,
'required' => true,
'placeholder' => 'Select',
'options' => $options,
'value' => $value,
'dependencies' => [
'teams',
'deal_stage_at_call',
'current_deal_stage',
'recipients',
ActivityTypeService::PLAYBOOK_CATEGORIES_KEY,
],
'dependsOn' => [],
];
}
// Teams = Groups
public function getTeamFieldData(array $options = [], array $value = [], bool $shortVersion = false): array
{
if ($shortVersion) {
return [
'id' => 'teams',
'label' => 'Team',
'options' => $options,
];
}
return [
'id' => 'teams',
'label' => 'Team',
'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,
'required' => false,
'placeholder' => 'Select',
'options' => $options,
'value' => $value, // value should be an array of objects {id, name}
'dependencies' => [ActivityTypeService::PLAYBOOK_CATEGORIES_KEY],
'dependsOn' => [],
];
}
public function getReportTypeFieldData(?string $value = null, bool $shortVersion = false, ?Team $team = null): array
{
$types = [];
if ($team instanceof Team) {
if ($team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {
$types = self::TYPES;
}
if ($team->hasFeature(FeatureEnum::ASK_JIMINNY_REPORTS)) {
$types[] = ['id' => self::TYPE_ASK_JIMINNY, 'name' => 'Ask Jiminny'];
}
} else {
$types = self::TYPES;
}
if ($shortVersion) {
return [
'id' => 'report_type',
'label' => 'Report Type',
'options' => $types,
];
}
return [
'id' => 'report_type',
'label' => 'Report Type',
'inputType' => InputTypeEnum::DROPDOWN,
'required' => true,
'placeholder' => 'Select',
'options' => $types,
'value' => $value,
'dependencies' => [],
'dependsOn' => [],
];
}
public function getFrequencyFieldData(?string $value = null): array
{
return [
'id' => 'frequency',
'label' => 'Frequency',
'inputType' => InputTypeEnum::DROPDOWN,
'required' => true,
'placeholder' => 'Select',
'options' => self::FREQUENCIES,
'value' => $value,
'dependencies' => ['period'],
'dependsOn' => [],
];
}
public function getPeriodFieldData(?string $valueStartDate = null, ?string $valueEndDate = null): array
{
return [
'id' => 'period',
'label' => 'Select one-off period',
'inputType' => InputTypeEnum::DATE_RANGE,
'required' => true,
'placeholder' => 'Select',
'value' => ['startDate' => $valueStartDate, 'endDate' => $valueEndDate],
'queryParams' => [
'startDate' => 'start_date_period',
'endDate' => 'end_date_period',
],
'dependencies' => [],
'dependsOn' => ['frequency'],
];
}
public function getActivityTypesFieldData(?Team $team = null, array $value = [], array $teamsFilter = []): array
{
return $this->activityTypeService->getActivityTypeFieldData(team: $team, value: $value, groupIds: $teamsFilter);
}
public function getDealStageAtCallFieldData(?Team $team = null, array $value = []): array
{
return $this->dealStagesService->getDealStageAtCallFieldData(team: $team, value: $value);
}
public function getCurrentDealStageFieldData(?Team $team = null, array $value = []): array
{
return $this->dealStagesService->getCurrentDealStageFieldData(team: $team, value: $value);
}
public function getDealValueFieldData(?int $valueMin = null, ?int $valueMax = null): array
{
return [
'id' => 'deal_value',
'label' => 'Deal Value',
'inputType' => InputTypeEnum::INTEGER_RANGE,
'required' => false,
'value' => ['min' => $valueMin, 'max' => $valueMax],
'queryParams' => [
'min' => 'min_deal_value',
'max' => 'max_deal_value',
],
'dependencies' => [],
'dependsOn' => [],
];
}
public function getCallTypeFieldData(bool $conferenceOn = false, bool $dialerOn = false): array
{
$value = [];
$conferenceOn && $value[] = self::CALL_TYPE_CONFERENCE;
$dialerOn && $value[] = self::CALL_TYPE_DIALER;
return [
'id' => 'call_type',
'label' => 'Call Type',
'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,
'required' => true,
'options' => [
self::CALL_TYPE_CONFERENCE,
self::CALL_TYPE_DIALER,
],
'value' => $value,
'dependencies' => [],
'dependsOn' => [],
];
}
public function getMediaTypeFieldData(?AutomatedReport $report = null): array
{
$value = [];
if ($report) {
$value = $this->transformMediaTypes($report);
}
return [
'id' => 'media_types',
'label' => 'Export as',
'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,
'required' => true,
'options' => self::MEDIA_TYPE_OBJECTS,
'value' => $value,
'dependencies' => [],
'dependsOn' => [],
];
}
public function getCallDurationFieldData(?int $valueMin = null, ?int $valueMax = null): array
{
return [
'id' => 'call_duration',
'label' => 'Call Duration',
'inputType' => InputTypeEnum::INTEGER_RANGE,
'required' => false,
'value' => ['min' => $valueMin, 'max' => $valueMax],
'queryParams' => [
'min' => 'min_call_duration',
'max' => 'max_call_duration',
],
'dependencies' => [],
'dependsOn' => [],
];
}
public function getRecipientsFieldData(?Team $team = null, array $value = []): array
{
return $this->recipientsService->getRecipientsFieldData(team: $team, value: $value);
}
public function getJiminnyRecipientsFieldData(array $value = []): array
{
return $this->recipientsService->getJiminnyRecipientsFieldData($value);
}
public function getAdditionalPromptInputFieldData(?string $value = null): array
{
return [
'id' => 'additional_prompt_input',
'label' => 'Special requirements',
'inputType' => InputTypeEnum::TEXTAREA,
'required' => false,
'placeholder' => 'What should be the focus of the report?',
'value' => $value,
'dependencies' => [],
'dependsOn' => [],
];
}
public function getCustomReportNameFieldData(?string $value = null): array
{
return [
'id' => 'custom_name',
'label' => 'Custom report name',
'inputType' => InputTypeEnum::TEXT,
'required' => false,
'placeholder' => 'Enter custom name',
'value' => $value,
'dependencies' => [],
'dependsOn' => [],
];
}
// data providers
public function getTeams(): array
{
$teams = $this->teamRepository->getTeamsForKiosk(status: Team::STATUS_ACTIVE);
$teamData = [];
foreach ($teams as $team) {
if (! $team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {
continue;
}
$teamData[] = $this->transformTeam($team);
}
return $teamData;
}
public function getTeamGroups(string $teamUuid): array
{
$data = [];
$team = $this->getTeam($teamUuid);
if ($team !== null) {
$groups = $team->groups()->get();
foreach ($groups as $group) {
$data[] = [
'id' => $group->getUuid(),
'name' => $group->getName(),
];
}
}
return $data;
}
public function getTeamsGroupsOptions(array $filterTeamUuids = []): array
{
$data = [];
$teams = $this->getTeams();
foreach ($teams as $team) {
if (! empty($filterTeamUuids) && ! in_array($team['id'], $filterTeamUuids, true)) {
continue;
}
$data[] = [
'label' => $team['name'],
'groups' => $this->getTeamGroups($team['id']),
];
}
return $data;
}
public function getTeam(string $teamUuid): ?Team
{
return $this->teamRepository->idOrUuid($teamUuid);
}
public function getTeamById(int $teamId): ?Team
{
return $this->teamRepository->find($teamId);
}
public function getGroupsUuids(AutomatedReport $report): array
{
$uuids = [];
$reportGroups = $report->getGroups();
foreach ($reportGroups as $groupId) {
if ($group = $this->groupRepository->find($groupId)) {
$uuids[] = $group->getUuid();
}
}
return $uuids;
}
public function getPlaybookCategoriesUuids(AutomatedReport $report): array
{
$uuids = [];
$playbookCategories = $report->getPlaybookCategories();
foreach ($playbookCategories as $id) {
if ($category = $this->playbookCategoryRepository->find($id)) {
$uuids[] = $category->getUuid();
}
}
return $uuids;
}
public function getDealAtCallStagesUuids(AutomatedReport $report): array
{
$uuids = [];
$reportStages = $report->getDealAtCallStages();
foreach ($reportStages as $id) {
if ($stage = $this->stageRepository->find($id)) {
$uuids[] = $stage->getUuid();
}
}
return $uuids;
}
public function getCurrentDealStagesUuids(AutomatedReport $report): array
{
$uuids = [];
$reportStages = $report->getCurrentDealStages();
foreach ($reportStages as $id) {
if ($stage = $this->stageRepository->find($id)) {
$uuids[] = $stage->getUuid();
}
}
return $uuids;
}
public function getUsersUuids(AutomatedReport $report): array
{
return $this->extractUserUuids($report->getRecipients());
}
public function getJiminnyUsersUuids(AutomatedReport $report): array
{
return $this->extractUserUuids($report->getJiminnyRecipients());
}
/**
* @param array<string, mixed> $recipients
*/
private function extractUserUuids(array $recipients): array
{
$userIds = $recipients['users'] ?? [];
return collect($userIds)
->map(fn ($id) => $this->userRepository->find((int) $id))
->filter()
->map(fn (UserContract $user) => $user->getUuid())
->values()
->all();
}
// get mail data
public function getRecipientUsers(AutomatedReport $report): array
{
return $this->buildRecipientUsers($report->getRecipients());
}
private function getJiminnyRecipientUsers(AutomatedReport $report): array
{
return $this->buildRecipientUsers($report->getJiminnyRecipients());
}
/**
* @param array<string, mixed> $recipients
*/
private function buildRecipientUsers(array $recipients): array
{
$userIds = $recipients['users'] ?? [];
return collect($userIds)
->map(fn ($id) => $this->userRepository->find((int) $id))
->filter()
->map(fn (UserContract $user) => [
'email' => $user->getEmailAddress(),
'name' => $user->getName(),
'timezone' => $user->getTimezone()->getName(),
])
->values()
->all();
}
public function getValidRecipientUsers(AutomatedReport $report, bool $includeJiminny = false): array
{
if ($report->isAskJiminnyReport()) {
$recipients = $this->resolveAskJiminnyRecipients($report);
} else {
$recipients = $this->getRecipientUsers($report);
if ($includeJiminny) {
$recipients = array_merge($recipients, $this->getJiminnyRecipientUsers($report));
}
}
$emails = [];
return array_values(array_filter(
$recipients,
static function ($recipient) use (&$emails) {
if (empty($recipient['email']) || in_array($recipient['email'], $emails, true)) {
return false;
}
$emails[] = $recipient['email'];
return true;
}
));
}
private function resolveAskJiminnyRecipients(AutomatedReport $report): array
{
$recipients = [];
$creator = $report->getCreator();
if ($creator !== null) {
$recipients[] = [
'email' => $creator->getEmailAddress(),
'name' => $creator->getName(),
'timezone' => $creator->getTimezone()->getName(),
];
}
return array_merge(
$recipients,
$this->buildRecipientUsers($report->getRecipients()),
$this->getGroupRecipientUsers($report),
);
}
private function getGroupRecipientUsers(AutomatedReport $report): array
{
$users = [];
foreach ($report->getGroups() as $groupId) {
$group = $this->groupRepository->find($groupId);
if ($group === null) {
continue;
}
foreach ($group->getMembers() as $member) {
$users[] = [
'email' => $member->getEmailAddress(),
'name' => $member->getName(),
'timezone' => $member->getTimezone()->getName(),
];
}
}
return $users;
}
public function getReportTypeName(AutomatedReportResult $report): string
{
$type = $report->getReport()->getType();
$getType = $this->transformReportType($type);
return $getType['name'];
}
public function getReportPeriodName(AutomatedReportResult $report): string
{
$from = $report->getFromDate();
$to = $report->getToDate();
$frequency = $report->getReport()->getFrequency();
if ($from === null || $to === null) {
if (! $report->getReport()->isAskJiminnyReport()) {
$invalidPeriod = $from === null ? 'from' : 'to';
throw new ApplicationException('Report period is invalid: ' . $invalidPeriod);
}
$period = $this->calculateFromAndToDatePeriod($frequency);
$from = $period['fromDate'];
$to = $period['toDate'];
}
return $this->formatReportPeriodName($frequency, $from, $to);
}
private function formatReportPeriodName(string $frequency, Carbon $from, Carbon $to): string
{
$fromYear = $from->format('Y');
$toYear = $to->format('Y');
$differentYears = $fromYear !== $toYear;
switch ($frequency) {
case self::FREQUENCY_DAILY:
return $from->format('j M Y');
case self::FREQUENCY_QUARTERLY:
// 'Jan-Mar 2025' or 'Nov 2024-Jan 2025' if years differ
$startMonth = $from->format('M');
$endMonth = $to->copy()->subMonth();
$endMonthName = $endMonth->format('M');
$endMonthYear = $endMonth->format('Y');
if ($differentYears) {
return "{$startMonth} {$fromYear} - {$endMonthName} {$endMonthYear}";
}
return "{$startMonth} - {$endMonthName} {$toYear}";
case self::FREQUENCY_MONTHLY:
// 'May 2025' - monthly reports are always within the same year
return $from->format('M Y');
case self::FREQUENCY_WEEKLY:
// '4 - 8 Aug 2025', '27 Oct - 3 Nov 2025', or '28 Dec 2024 - 3 Jan 2025' if years differ
$startDay = $from->format('j');
$endDay = $to->format('j');
$startMonth = $from->format('M');
$endMonth = $to->format('M');
if ($differentYears) {
return "{$startDay} {$startMonth} {$fromYear} - {$endDay} {$endMonth} {$toYear}";
}
if ($startMonth !== $endMonth) {
return "{$startDay} {$startMonth} - {$endDay} {$endMonth} {$toYear}";
}
return "{$startDay} - {$endDay} {$endMonth} {$toYear}";
case self::FREQUENCY_ONE_OFF:
// '2 May-31 May 2025' or '15 Dec 2024-15 Jan 2025' if years differ
$startDay = $from->format('j');
$startMonth = $from->format('M');
$endDay = $to->format('j');
$endMonth = $to->format('M');
// If same month and year, use a format like '2-31 May 2025'
if ($startMonth === $endMonth && ! $differentYears) {
return "{$startDay} - {$endDay} {$startMonth} {$toYear}";
}
// If different years, include both years
if ($differentYears) {
return "{$startDay} {$startMonth} {$fromYear} - {$endDay} {$endMonth} {$toYear}";
}
// Same year but different months
return "{$startDay} {$startMonth} - {$endDay} {$endMonth} {$toYear}";
default:
// Default format for unknown frequencies
return $from->format('j M Y') . ' - ' . $to->format('j M Y');
}
}
public function getReportTeamsName(AutomatedReportResult $report): string
{
$groups = $report->getGroups();
if (empty($groups)) {
return 'All';
}
// Get group names from repository
$groupNames = [];
foreach ($groups as $groupId) {
$group = $this->groupRepository->find($groupId);
if ($group) {
$groupNames[] = $group->getName();
}
}
if (count($groupNames) === 1) {
// Single team format
$teamsName = $groupNames[0];
} else {
// Multiple teams format
$teamsName = implode(', ', $groupNames);
}
return $teamsName;
}
public function getReportFileName(AutomatedReportResult $report): string
...
|
12308
|
|
12315
|
260
|
35
|
2026-04-14T11:03:29.882275+00:00
|
/Users/lukas/.screenpipe/data/data/2026-04-14/1776 /Users/lukas/.screenpipe/data/data/2026-04-14/1776164609882_m1.jpg...
|
PhpStorm
|
faVsco.js – AutomatedReportsService.php
|
1
|
NULL
|
monitor_1
|
NULL
|
NULL
|
NULL
|
NULL
|
Project: faVsco.js, menu
#11894 on JY-18909-automa Project: faVsco.js, menu
#11894 on JY-18909-automated-reports-ask-jiminny, menu
Start Listening for PHP Debug Connections
AutomatedReportsCommandTest
Run 'AutomatedReportsCommandTest'
Debug 'AutomatedReportsCommandTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Execute
Explain Plan
Browse Query History
View Parameters
Open Query Execution Settings…
In-Editor Results
Tx: Auto
Cancel Running Statements
Playground
jiminny
Sync Changes
Hide This Notification
Code changed:
Hide
16
13
13
Previous Highlighted Error
Next Highlighted Error
SELECT * FROM teams WHERE id = 1;
select * from crm_layouts where crm_configuration_id = 39;
SELECT * FROM crm_layout_entities WHERE crm_layout_id = 283;
SELECT * FROM crm_fields WHERE id = 2234;
SELECT * FROM crm_field_values WHERE crm_field_id = 2234;
select * from crm_profiles where user_id = 143;
select * from record_types where crm_configuration_id = 39; # 0121K000001MHElQAO,0121K000001MHEqQAO
select * from business_processes where crm_configuration_id = 39;
# 01941000000H669AAC, 01941000000H66JAAS
select * from record_type_field_values
where record_type_id IN (24);
select * from crm_field_values where id IN (2730);
select * from crm_configurations where id = 39;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 1
and sa.provider = 'salesforce'; #1035
select * from users where team_id = 1; # 222 group 3
SELECT * FROM activities WHERE user_id = 222 order by id desc;
select * from sidekick_settings where team_id = 1;
select * from teams where id = 1;
select * from team_features where team_id = 1;
select * from activities where crm_configuration_id = 2
and provider = 'ms-teams' and id = 608765;
SELECT * FROM activities WHERE crm_configuration_id = 2 and crm_provider_id = '59523413338';
select * from sidekick_settings where team_id = 2;
SELECT * FROM activities WHERE id = 608660;
select * from activity_summary_logs where activity_id = 608660;
select * from ai_prompts where transcription_id = 11214;
# [PASSWORD_DOTS]
SELECT * FROM activities WHERE uuid_to_bin('ed78a437-2804-450e-ab2f-56ab1c641346') = uuid;
# id: 608818, crm: 59628809737
SELECT * FROM activities WHERE uuid_to_bin('36b06e55-afdd-4782-8dee-c624cd0af191') = uuid;
# id: 608821, crm: 59632069252
SELECT ce.start_time, ce.end_time, a.id, a.uuid, crm_provider_id, calendar_event_id, title,
playbook_category_id, user_id, lead_id, contact_id, account_id, opportunity_id,
scheduled_start_time, scheduled_end_time, actual_start_time, actual_end_time, a.created_at
FROM activities a
join calendar_events ce on a.calendar_event_id = ce.id
WHERE a.id IN (608818, 608821);
select * from users where team_id = 1;
select * from team_settings where team_id = 1;
select * from crm_profiles where crm_configuration_id = 39 order by user_id;
select * from team_features where team_id = 1;
select * from users where team_id = 2;
SELECT * FROM activities WHERE uuid_to_bin('ec7647e9-5225-458b-b475-f31aa2769204') = uuid; # 612639
# Preslava N. Ivanova, grou id 3
SELECT * FROM opportunities WHERE uuid_to_bin('a2928fe5-aec5-46cb-85d9-7654c89e46a6') = uuid;
select * from activities where opportunity_id = 344 and actual_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00';
select
a.id,
a.type,
a.scheduled_start_time,
a.actual_start_time,
a.created_at,
a.opportunity_id,
a.status
FROM activities a
WHERE opportunity_id = 344
and status IN ('completed', 'received', 'delivered')
and (
(a.actual_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00')
OR (a.created_at between '2024-10-11 00:00:00' and '2024-10-12 00:00:00')
OR (a.scheduled_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00'))
;
SELECT * FROM users WHERE id = 222;
SELECT * FROM crm_profiles WHERE user_id = 222;
select * from crm_layouts where crm_configuration_id = 39;
SELECT * FROM crm_layout_entities WHERE crm_layout_id = 281;
select * from group_deal_risk_types;
select * from opportunities where team_id = 1;
SELECT * FROM opportunities WHERE id = 315;
SELECT * FROM crm_field_data WHERE object_id = 315;
select * from crm_field_data where object_id = 260;
select * from generic_ai_prompts where subject_id = 315;
select * from teams; # 36, 21, 121, [EMAIL]
SELECT * FROM social_accounts WHERE sociable_id = 121 and provider = 'bullhorn';
# [PASSWORD_DOTS]
select * from teams where id = 1;
select * from crm_configurations where id = 39;
select * from users where team_id = 1;
select u.email, cp.* from users u
join crm_profiles cp on u.id = cp.user_id
where u.team_id = 1;
# 1 - 00541000004281rAAA
# 204 - 0052g000003freeAAA
# 429 - 0052g000003qGOiAAM
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 1
and sa.provider = 'salesforce';
select * from activities where type = 'softphone'
and created_at > '2024-12-11 15:24:36' order by id desc;
select * from activity_providers where team_id = 1;
select * from activity_provider_users where activity_provider_id = 328;
select * from opportunities where crm_configuration_id = 39
AND account_id = 178 AND is_closed = false
order by created_at DESC;
select * from contacts where id = 3952;
select * from accounts where id = 178;
# [PASSWORD_DOTS]
select * from teams where id = 36;
select * from crm_configurations where id = 21;
select * from users where team_id = 36;
select u.email, cp.* from users u
join crm_profiles cp on u.id = cp.user_id
where u.team_id = 36;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 36
and sa.provider = 'bullhorn';
select * from social_accounts where id = 348;
UPDATE social_accounts SET
provider_user_token = '21442_6802599_91:41179a58-21e7-4d7c-ad58-56bb666b2f65',
provider_refresh_token = '21442_6802599_91:01c6b335-3f2a-42e4-85ff-8a08fa65fceb',
expires = 1733998131,
state = 'connected'
WHERE id = 348;
# [PASSWORD_DOTS]
select * from teams where id = 31;
select * from crm_configurations where id = 18;
select * from users where team_id = 31; # 257
select u.email, cp.* from users u
join crm_profiles cp on u.id = cp.user_id
where u.team_id = 31;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 31
and sa.provider = 'close';
select * from contacts where crm_configuration_id = 18;
# [PASSWORD_DOTS] NEPTUNE [PASSWORD_DOTS]
select * from teams;
select * from users where id IN (1030, 1035, 1052);
select * from crm_configurations;
select * from users where team_id = 65; # 257
select * from team_settings where team_id = 65; # 257
select * from invitations where team_id = 65; # 257
select * from users where email = '[EMAIL]'; # 257
select u.email, cp.* from users u
join crm_profiles cp on u.id = cp.user_id
where u.team_id = 65;
select * from crm_configurations where id = 53;
select * from accounts where crm_configuration_id = 53 order by id desc;
select * from leads where crm_configuration_id = 53 order by id desc;
select * from contacts where crm_configuration_id = 53 order by id desc;
select * from opportunities where crm_configuration_id = 53 order by id desc;
select * from crm_profiles where crm_configuration_id = 53 order by id desc;
select * from crm_fields where crm_configuration_id = 53 order by id desc;
select * from crm_field_values where crm_field_id = 3341 order by id desc;
select * from crm_layouts where crm_configuration_id = 53 order by id desc;
select * from stages where crm_configuration_id = 53 order by id desc;
select * from crm_profiles where crm_configuration_id = 13;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 65
and sa.provider = 'integration-app';
select * from contacts where crm_configuration_id = 13;
select * from social_accounts where sociable_id = 283;
SELECT * FROM opportunities WHERE crm_provider_id = '006O400000E9bzeIAB';
select * from activity_providers where team_id = 65;
SELECT * FROM activities WHERE crm_configuration_id IN (51, 52, 53);
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 65
;
# [PASSWORD_DOTS] STAGING [PASSWORD_DOTS]
SELECT * FROM teams;
SELECT * FROM teams WHERE id = 88;
SELECT * FROM teams WHERE id = 89;
select * from team_settings where team_id = 89;
SELECT * FROM users WHERE team_id = 89;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 89;
select * from users;
SELECT * FROM social_accounts WHERE sociable_id = 1761;
SELECT * FROM crm_configurations WHERE id = 70;
select * from accounts where crm_configuration_id = 70 order by id desc;
select * from leads where crm_configuration_id = 70 order by id desc;
select * from contacts where crm_configuration_id = 70 order by id desc;
select * from opportunities where crm_configuration_id = 70 order by id desc;
select * from crm_profiles where crm_configuration_id = 70 order by id desc;
select * from crm_fields where crm_configuration_id = 70 order by id desc;
select * from crm_field_values where crm_field_id = 3536 order by id desc;
select * from crm_layouts where crm_configuration_id = 70 order by id desc;
select * from stages where crm_configuration_id = 70 order by id desc;
select * from business_processes where crm_configuration_id = 70 order by id desc;
select * from business_process_stages where business_process_id = 34;
select * from contacts where id = 10468;
select * from crm_layouts where crm_configuration_id = 70;
SELECT * FROM crm_layout_entities WHERE crm_layout_id = 388;
SELECT * FROM crm_fields WHERE id IN (3533,3534,3535);
select * from activities where crm_configuration_id = 70
and (account_id IS NOT NULL or lead_id IS NOT NULL or contact_id IS NOT NULL or opportunity_id IS NOT NULL) order by id desc;
SELECT * FROM activities WHERE uuid_to_bin('2e10b60f-8a61-41c5-a3d4-28835353dc65') = uuid;
SELECT * FROM activities where crm_configuration_id = 69 ;
SELECT * FROM users WHERE email LIKE '%[EMAIL]%';
SELECT * FROM activities WHERE uuid_to_bin('5a150c93-40fc-42ec-b3bd-c1d328e09f6e') = uuid;
SELECT * FROM opportunities WHERE id = 385;
select * from participants p
join activities a on p.activity_id = a.id
where a.crm_configuration_id = 70
and (p.lead_id IS NOT NULL or p.contact_id IS NOT NULL);
SELECT * FROM participants WHERE id = 1013638;
select * from teams where id = 90;
select * from users where team_id = 90;
select * from social_accounts where social_accounts.sociable_id IN (1960,1760);
SELECT * FROM crm_profiles WHERE crm_configuration_id = 71;
select * from invitations where team_id = 90;
select * from crm_configurations where id = 71;
select * from accounts where crm_configuration_id = 71 order by id desc;
select * from leads where crm_configuration_id = 71 order by id desc;
select * from contacts where crm_configuration_id = 71 order by id desc;
select * from opportunities where crm_configuration_id = 71 order by id desc;
select * from crm_profiles where crm_configuration_id = 71 order by id desc;
select * from crm_fields where crm_configuration_id = 71 order by id desc;
select * from crm_field_values where crm_field_id = 3341 order by id desc;
select * from crm_layouts where crm_configuration_id = 71 order by id desc;
select * from stages where crm_configuration_id = 71 order by id desc;
select * from users order by secondary_email desc;
select u.id, u.email, u.status, sa.id, sa.provider_user_id from social_accounts sa
join users u on sa.sociable_id = u.id
where sa.provider = 'google' and u.email LIKE 'aneliya%';
select * from failed_jobs order by id desc;
select * from users where email = '[EMAIL]' or secondary_email = '[EMAIL]';
select * from teams;
SELECT * FROM crm_profiles WHERE crm_configuration_id = 39;
SELECT * FROM crm_fields WHERE crm_configuration_id = 39 and object_type = 'task';
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 1
and sa.provider = 'salesforce';
# [PASSWORD_DOTS]
SELECT * FROM activities WHERE uuid_to_bin('c38b3895-fd0f-4b1f-9fb2-c170dba137c6') = uuid;
SELECT * FROM crm_configurations WHERE id = 70;
select * from teams where id = 1;
select * from groups where team_id = 1;
select * from users where team_id = 1;
select o.id, o.name,o.close_date, u.id, u.name, u.group_id, r.id, r.display_name, g.name, g.scope from opportunities o
join users u on o.user_id = u.id
join groups g on u.group_id = g.id
join role_user ru on u.id = ru.user_id
join roles r on ru.role_id = r.id
where o.crm_configuration_id = 39 and close_date > '2024-01-01 00:00:00';
select * from role_user where user_id = 143;
select * from roles;
select * from role_user;
select * from groups where id = 9;
select * from scope_groups where group_id = 9;
# [PASSWORD_DOTS]
select * from teams where id = 36;
select * from crm_configurations;
SELECT * FROM social_accounts WHERE sociable_id = 121;
[URL_WITH_CREDENTIALS] this will add filter, however if we need to control feature by FF we need conditional logic
public const array TYPES = [
['id' => 'exec_summary', 'name' => 'Exec Summary'],
['id' => 'coaching_profiles', 'name' => 'Coaching Profiles'],
['id' => 'product_feedback', 'name' => 'Product Feedback'],
['id' => self::TYPE_LOSS_ANALYSIS, 'name' => 'Loss Analysis'],
// ['id' => 'questions', 'name' => 'Questions'],
// ['id' => 'statistical_quant', 'name' => 'Statistical Quantitative'],
];
public const array ALL_TYPES = [
...self::TYPES,
['id' => self::TYPE_ASK_JIMINNY, 'name' => 'Ask Jiminny'],
];
public const string FREQUENCY_DAILY = 'daily';
public const string FREQUENCY_WEEKLY = 'weekly';
public const string FREQUENCY_MONTHLY = 'monthly';
public const string FREQUENCY_QUARTERLY = 'quarterly';
public const string FREQUENCY_ONE_OFF = 'one_off';
/**
* Frequencies for standard (non-Ask Jiminny) reports.
*/
public const array FREQUENCIES = [
['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],
['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],
['id' => self::FREQUENCY_QUARTERLY, 'name' => 'Quarterly'],
['id' => self::FREQUENCY_ONE_OFF, 'name' => 'One-off'],
];
/**
* Frequencies for Ask Jiminny reports.
*/
public const array ASK_JIMINNY_FREQUENCIES = [
['id' => self::FREQUENCY_DAILY, 'name' => 'Daily'],
['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],
['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],
];
public const string MEDIA_TYPE_PDF = 'pdf';
public const string MEDIA_TYPE_PODCAST = 'podcast';
public const array MEDIA_TYPES = [self::MEDIA_TYPE_PDF, self::MEDIA_TYPE_PODCAST];
public const array MEDIA_TYPE_OBJECT_PDF = ['id' => self::MEDIA_TYPE_PDF, 'name' => 'PDF'];
public const array MEDIA_TYPE_OBJECT_PODCAST = ['id' => self::MEDIA_TYPE_PODCAST, 'name' => 'Podcast'];
public const array MEDIA_TYPE_OBJECTS = [self::MEDIA_TYPE_OBJECT_PDF, self::MEDIA_TYPE_OBJECT_PODCAST];
public const array CALL_TYPE_CONFERENCE = ['id' => 'conference', 'name' => 'Conference'];
public const array CALL_TYPE_DIALER = ['id' => 'dialer', 'name' => 'Dialer'];
public const int SENT_REPORT_AT_HOURS = 5;
public const string PDF_KEY = 'pdf';
public const string AUDIO_KEY = 'audio';
private const array ALL_FREQUENCIES = [
['id' => self::FREQUENCY_DAILY, 'name' => 'Daily'],
['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],
['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],
['id' => self::FREQUENCY_QUARTERLY, 'name' => 'Quarterly'],
['id' => self::FREQUENCY_ONE_OFF, 'name' => 'One-off'],
];
private const string S3_DIR = 'reports';
private const array FILE_EXTENSIONS_VARIANTS = ['html', 'MD', 'pdf'];
private const array FILE_PODCAST_EXTENSIONS_VARIANTS = ['json', 'mp3', 'ssml'];
public function __construct(
private readonly TeamRepository $teamRepository,
private readonly GroupRepository $groupRepository,
private readonly UserRepository $userRepository,
private readonly StageRepository $stageRepository,
private readonly DealStagesService $dealStagesService,
private readonly RecipientsService $recipientsService,
private readonly AutomatedReportsRepository $automatedReportsRepository,
private readonly Webhook $webhookService,
private readonly BusDispatcher $dispatcher,
private readonly ActivityTypeService $activityTypeService,
private readonly PlaybookCategoryRepository $playbookCategoryRepository,
private readonly AskAnythingPromptService $askAnythingPromptService,
private readonly SearchRepository $activitySearchRepository,
private readonly AskAnythingRepository $askAnythingRepository,
) {
}
public static function getTypes(): array
{
$types = self::TYPES;
return array_map(static function ($type) {
return $type['id'];
}, $types);
}
public static function getCallTypes(): array
{
return array_map(static function ($callType) {
return $callType['id'];
}, [self::CALL_TYPE_CONFERENCE, self::CALL_TYPE_DIALER]);
}
public static function getFrequencies(): array
{
return array_map(static function ($frequency) {
return $frequency['id'];
}, self::FREQUENCIES);
}
// front-facing structure
public function getReportEnabledFieldData(bool $value = false): array
{
return [
'id' => 'report_enabled',
'label' => '',
'inputType' => InputTypeEnum::TOGGLE,
'value' => $value,
];
}
// Organizations = Teams
public function getOrganizationFieldData(?string $value = null, bool $shortVersion = false): array
{
$options = $this->getTeams();
if ($shortVersion) {
return [
'id' => 'organization',
'label' => 'Organization',
'options' => $options,
];
}
return [
'id' => 'organization',
'label' => 'Organization',
'inputType' => InputTypeEnum::DROPDOWN,
'required' => true,
'placeholder' => 'Select',
'options' => $options,
'value' => $value,
'dependencies' => [
'teams',
'deal_stage_at_call',
'current_deal_stage',
'recipients',
ActivityTypeService::PLAYBOOK_CATEGORIES_KEY,
],
'dependsOn' => [],
];
}
// Teams = Groups
public function getTeamFieldData(array $options = [], array $value = [], bool $shortVersion = false): array
{
if ($shortVersion) {
return [
'id' => 'teams',
'label' => 'Team',
'options' => $options,
];
}
return [
'id' => 'teams',
'label' => 'Team',
'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,
'required' => false,
'placeholder' => 'Select',
'options' => $options,
'value' => $value, // value should be an array of objects {id, name}
'dependencies' => [ActivityTypeService::PLAYBOOK_CATEGORIES_KEY],
'dependsOn' => [],
];
}
public function getReportTypeFieldData(?string $value = null, bool $shortVersion = false, ?Team $team = null): array
{
$types = [];
if ($team instanceof Team) {
if ($team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {
$types = self::TYPES;
}
if ($team->hasFeature(FeatureEnum::ASK_JIMINNY_REPORTS)) {
$types[] = ['id' => self::TYPE_ASK_JIMINNY, 'name' => 'Ask Jiminny'];
}
} else {
$types = self::TYPES;
}
if ($shortVersion) {
return [
'id' => 'report_type',
'label' => 'Report Type',
'options' => $types,
];
}
return [
'id' => 'report_type',
'label' => 'Report Type',
'inputType' => InputTypeEnum::DROPDOWN,
'required' => true,
'placeholder' => 'Select',
'options' => $types,
'value' => $value,
'dependencies' => [],
'dependsOn' => [],
];
}
public function getFrequencyFieldData(?string $value = null): array
{
return [
'id' => 'frequency',
'label' => 'Frequency',
'inputType' => InputTypeEnum::DROPDOWN,
'required' => true,
'placeholder' => 'Select',
'options' => self::FREQUENCIES,
'value' => $value,
'dependencies' => ['period'],
'dependsOn' => [],
];
}
public function getPeriodFieldData(?string $valueStartDate = null, ?string $valueEndDate = null): array
{
return [
'id' => 'period',
'label' => 'Select one-off period',
'inputType' => InputTypeEnum::DATE_RANGE,
'required' => true,
'placeholder' => 'Select',
'value' => ['startDate' => $valueStartDate, 'endDate' => $valueEndDate],
'queryParams' => [
'startDate' => 'start_date_period',
'endDate' => 'end_date_period',
],
'dependencies' => [],
'dependsOn' => ['frequency'],
];
}
public function getActivityTypesFieldData(?Team $team = null, array $value = [], array $teamsFilter = []): array
{
return $this->activityTypeService->getActivityTypeFieldData(team: $team, value: $value, groupIds: $teamsFilter);
}
public function getDealStageAtCallFieldData(?Team $team = null, array $value = []): array
{
return $this->dealStagesService->getDealStageAtCallFieldData(team: $team, value: $value);
}
public function getCurrentDealStageFieldData(?Team $team = null, array $value = []): array
{
return $this->dealStagesService->getCurrentDealStageFieldData(team: $team, value: $value);
}
public function getDealValueFieldData(?int $valueMin = null, ?int $valueMax = null): array
{
return [
'id' => 'deal_value',
'label' => 'Deal Value',
'inputType' => InputTypeEnum::INTEGER_RANGE,
'required' => false,
'value' => ['min' => $valueMin, 'max' => $valueMax],
'queryParams' => [
'min' => 'min_deal_value',
'max' => 'max_deal_value',
],
'dependencies' => [],
'dependsOn' => [],
];
}
public function getCallTypeFieldData(bool $conferenceOn = false, bool $dialerOn = false): array
{
$value = [];
$conferenceOn && $value[] = self::CALL_TYPE_CONFERENCE;
$dialerOn && $value[] = self::CALL_TYPE_DIALER;
return [
'id' => 'call_type',
'label' => 'Call Type',
'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,
'required' => true,
'options' => [
self::CALL_TYPE_CONFERENCE,
self::CALL_TYPE_DIALER,
],
'value' => $value,
'dependencies' => [],
'dependsOn' => [],
];
}
public function getMediaTypeFieldData(?AutomatedReport $report = null): array
{
$value = [];
if ($report) {
$value = $this->transformMediaTypes($report);
}
return [
'id' => 'media_types',
'label' => 'Export as',
'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,
'required' => true,
'options' => self::MEDIA_TYPE_OBJECTS,
'value' => $value,
'dependencies' => [],
'dependsOn' => [],
];
}
public function getCallDurationFieldData(?int $valueMin = null, ?int $valueMax = null): array
{
return [
'id' => 'call_duration',
'label' => 'Call Duration',
'inputType' => InputTypeEnum::INTEGER_RANGE,
'required' => false,
'value' => ['min' => $valueMin, 'max' => $valueMax],
'queryParams' => [
'min' => 'min_call_duration',
'max' => 'max_call_duration',
],
'dependencies' => [],
'dependsOn' => [],
];
}
public function getRecipientsFieldData(?Team $team = null, array $value = []): array
{
return $this->recipientsService->getRecipientsFieldData(team: $team, value: $value);
}
public function getJiminnyRecipientsFieldData(array $value = []): array
{
return $this->recipientsService->getJiminnyRecipientsFieldData($value);
}
public function getAdditionalPromptInputFieldData(?string $value = null): array
{
return [
'id' => 'additional_prompt_input',
'label' => 'Special requirements',
'inputType' => InputTypeEnum::TEXTAREA,
'required' => false,
'placeholder' => 'What should be the focus of the report?',
'value' => $value,
'dependencies' => [],
'dependsOn' => [],
];
}
public function getCustomReportNameFieldData(?string $value = null): array
{
return [
'id' => 'custom_name',
'label' => 'Custom report name',
'inputType' => InputTypeEnum::TEXT,
'required' => false,
'placeholder' => 'Enter custom name',
'value' => $value,
'dependencies' => [],
'dependsOn' => [],
];
}
// data providers
public function getTeams(): array
{
$teams = $this->teamRepository->getTeamsForKiosk(status: Team::STATUS_ACTIVE);
$teamData = [];
foreach ($teams as $team) {
if (! $team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {
continue;
}
$teamData[] = $this->transformTeam($team);
}
return $teamData;
}
public function getTeamGroups(string $teamUuid): array
{
$data = [];
$team = $this->getTeam($teamUuid);
if ($team !== null) {
$groups = $team->groups()->get();
foreach ($groups as $group) {
$data[] = [
'id' => $group->getUuid(),
'name' => $group->getName(),
];
}
}
return $data;
}
public function getTeamsGroupsOptions(array $filterTeamUuids = []): array
{
$data = [];
$teams = $this->getTeams();
foreach ($teams as $team) {
if (! empty($filterTeamUuids) && ! in_array($team['id'], $filterTeamUuids, true)) {
continue;
}
$data[] = [
'label' => $team['name'],
'groups' => $this->getTeamGroups($team['id']),
];
}
return $data;
}
public function getTeam(string $teamUuid): ?Team
{
return $this->teamRepository->idOrUuid($teamUuid);
}
public function getTeamById(int $teamId): ?Team
{
return $this->teamRepository->find($teamId);
}
public function getGroupsUuids(AutomatedReport $report): array
{
$uuids = [];
$reportGroups = $report->getGroups();
foreach ($reportGroups as $groupId) {
if ($group = $this->groupRepository->find($groupId)) {
$uuids[] = $group->getUuid();
}
}
return $uuids;
}
public function getPlaybookCategoriesUuids(AutomatedReport $report): array
{
$uuids = [];
$playbookCategories = $report->getPlaybookCategories();
foreach ($playbookCategories as $id) {
if ($category = $this->playbookCategoryRepository->find($id)) {
$uuids[] = $category->getUuid();
}
}
return $uuids;
}
public function getDealAtCallStagesUuids(AutomatedReport $report): array
{
$uuids = [];
$reportStages = $report->getDealAtCallStages();
foreach ($reportStages as $id) {
if ($stage = $this->stageRepository->find($id)) {
$uuids[] = $stage->getUuid();
}
}
return $uuids;
}
public function getCurrentDealStagesUuids(AutomatedReport $report): array
{
$uuids = [];
$reportStages = $report->getCurrentDealStages();
foreach ($reportStages as $id) {
if ($stage = $this->stageRepository->find($id)) {
$uuids[] = $stage->getUuid();
}
}
return $uuids;
}
public function getUsersUuids(AutomatedReport $report): array
{
return $this->extractUserUuids($report->getRecipients());
}
public function getJiminnyUsersUuids(AutomatedReport $report): array
{
return $this->extractUserUuids($report->getJiminnyRecipients());
}
/**
* @param array<string, mixed> $recipients
*/
private function extractUserUuids(array $recipients): array
{
$userIds = $recipients['users'] ?? [];
return collect($userIds)
->map(fn ($id) => $this->userRepository->find((int) $id))
->filter()
->map(fn (UserContract $user) => $user->getUuid())
->values()
->all();
}
// get mail data
public function getRecipientUsers(AutomatedReport $report): array
{
return $this->buildRecipientUsers($report->getRecipients());
}
private function getJiminnyRecipientUsers(AutomatedReport $report): array
{
return $this->buildRecipientUsers($report->getJiminnyRecipients());
}
/**
* @param array<string, mixed> $recipients
*/
private function buildRecipientUsers(array $recipients): array
{
$userIds = $recipients['users'] ?? [];
return collect($userIds)
->map(fn ($id) => $this->userRepository->find((int) $id))
->filter()
->map(fn (UserContract $user) => [
'email' => $user->getEmailAddress(),
'name' => $user->getName(),
'timezone' => $user->getTimezone()->getName(),
])
->values()
->all();
}
public function getValidRecipientUsers(AutomatedReport $report, bool $includeJiminny = false): array
{
if ($report->isAskJiminnyReport()) {
$recipients = $this->resolveAskJiminnyRecipients($report);
} else {
$recipients = $this->getRecipientUsers($report);
if ($includeJiminny) {
$recipients = array_merge($recipients, $this->getJiminnyRecipientUsers($report));
}
}
$emails = [];
return array_values(array_filter(
$recipients,
static function ($recipient) use (&$emails) {
if (empty($recipient['email']) || in_array($recipient['email'], $emails, true)) {
return false;
}
$emails[] = $recipient['email'];
return true;
}
));
}
private function resolveAskJiminnyRecipients(AutomatedReport $report): array
{
$recipients = [];
$creator = $report->getCreator();
if ($creator !== null) {
$recipients[] = [
'email' => $creator->getEmailAddress(),
'name' => $creator->getName(),
'timezone' => $creator->getTimezone()->getName(),
];
}
return array_merge(
$recipients,
$this->buildRecipientUsers($report->getRecipients()),
$this->getGroupRecipientUsers($report),
);
}
private function getGroupRecipientUsers(AutomatedReport $report): array
{
$users = [];
foreach ($report->getGroups() as $groupId) {
$group = $this->groupRepository->find($groupId);
if ($group === null) {
continue;
}
foreach ($group->getMembers() as $member) {
$users[] = [
'email' => $member->getEmailAddress(),
'name' => $member->getName(),
'timezone' => $member->getTimezone()->getName(),
];
}
}
return $users;
}
public function getReportTypeName(AutomatedReportResult $report): string
{
$type = $report->getReport()->getType();
$getType = $this->transformReportType($type);
return $getType['name'];
}
public function getReportPeriodName(AutomatedReportResult $report): string
{
$from = $report->getFromDate();
$to = $report->getToDate();
$frequency = $report->getReport()->getFrequency();
if ($from === null || $to === null) {
if (! $report->getReport()->isAskJiminnyReport()) {
$invalidPeriod = $from === null ? 'from' : 'to';
throw new ApplicationException('Report period is invalid: ' . $invalidPeriod);
}
$period = $this->calculateFromAndToDatePeriod($frequency);
$from = $period['fromDate'];
$to = $period['toDate'];
}
return $this->formatReportPeriodName($frequency, $from, $to);
}
private function formatReportPeriodName(string $frequency, Carbon $from, Carbon $to): string
{
$fromYear = $from->format('Y');
$toYear = $to->format('Y');
$differentYears = $fromYear !== $toYear;
switch ($frequency) {
case self::FREQUENCY_DAILY:
return $from->format('j M Y');
case self::FREQUENCY_QUARTERLY:
// 'Jan-Mar 2025' or 'Nov 2024-Jan 2025' if years differ
$startMonth = $from->format('M');
$endMonth = $to->copy()->subMonth();
$endMonthName = $endMonth->format('M');
$endMonthYear = $endMonth->format('Y');
if ($differentYears) {
return "{$startMonth} {$fromYear} - {$endMonthName} {$endMonthYear}";
}
return "{$startMonth} - {$endMonthName} {$toYear}";
case self::FREQUENCY_MONTHLY:
// 'May 2025' - monthly reports are always within the same year
return $from->format('M Y');
case self::FREQUENCY_WEEKLY:
// '4 - 8 Aug 2025', '27 Oct - 3 Nov 2025', or '28 Dec 2024 - 3 Jan 2025' if years differ
$startDay = $from->format('j');
$endDay = $to->format('j');
$startMonth = $from->format('M');
$endMonth = $to->format('M');
if ($differentYears) {
return "{$startDay} {$startMonth} {$fromYear} - {$endDay} {$endMonth} {$toYear}";
}
if ($startMonth !== $endMonth) {
return "{$startDay} {$startMonth} - {$endDay} {$endMonth} {$toYear}";
}
return "{$startDay} - {$endDay} {$endMonth} {$toYear}";
case self::FREQUENCY_ONE_OFF:
// '2 May-31 May 2025' or '15 Dec 2024-15 Jan 2025' if years differ
$startDay = $from->format('j');
$startMonth = $from->format('M');
$endDay = $to->format('j');
$endMonth = $to->format('M');
// If same month and year, use a format like '2-31 May 2025'
if ($startMonth === $endMonth && ! $differentYears) {
return "{$startDay} - {$endDay} {$startMonth} {$toYear}";
}
// If different years, include both years
if ($differentYears) {
return "{$startDay} {$startMonth} {$fromYear} - {$endDay} {$endMonth} {$toYear}";
}
// Same year but different months
return "{$startDay} {$startMonth} - {$endDay} {$endMonth} {$toYear}";
default:
// Default format for unknown frequencies
return $from->format('j M Y') . ' - ' . $to->format('j M Y');
}
}
public function getReportTeamsName(AutomatedReportResult $report): string
{
$groups = $report->getGroups();
if (empty($groups)) {
return 'All';
}
// Get group names from repository
$groupNames = [];
foreach ($groups as $groupId) {
$group = $this->groupRepository->find($groupId);
if ($group) {
$groupNames[] = $group->getName();
}
}
if (count($groupNames) === 1) {
// Single team format
$teamsName = $groupNames[0];
} else {
// Multiple teams format
$teamsName = implode(', ', $groupNames);
}
return $teamsName;
}
public function getReportFileName(AutomatedReportResult $report): string
...
|
[{"role":"AXButton","text" [{"role":"AXButton","text":"Project: faVsco.js, menu","depth":5,"help_text":"~/jiminny/app","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"#11894 on JY-18909-automated-reports-ask-jiminny, menu","depth":5,"help_text":"Pull request #11894 exists for current branch JY-18909-automated-reports-ask-jiminny","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Start Listening for PHP Debug Connections","depth":5,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"AutomatedReportsCommandTest","depth":6,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Run 'AutomatedReportsCommandTest'","depth":6,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Debug 'AutomatedReportsCommandTest'","depth":6,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"More Actions","depth":6,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JetBrains AI","depth":5,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Search Everywhere","depth":5,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"IDE and Project Settings","depth":5,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Execute","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Explain Plan","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Browse Query History","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"View Parameters","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Open Query Execution Settings…","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"In-Editor Results","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Tx: Auto","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Cancel Running Statements","depth":4,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Playground","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"jiminny","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.088194445,"height":0.027777778},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"16","depth":4,"role_description":"text"},{"role":"AXStaticText","text":"13","depth":4,"role_description":"text"},{"role":"AXStaticText","text":"13","depth":4,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"SELECT * FROM teams WHERE id = 1;\n\nselect * from crm_layouts where crm_configuration_id = 39;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 283;\nSELECT * FROM crm_fields WHERE id = 2234;\nSELECT * FROM crm_field_values WHERE crm_field_id = 2234;\n\nselect * from crm_profiles where user_id = 143;\n\nselect * from record_types where crm_configuration_id = 39; # 0121K000001MHElQAO,0121K000001MHEqQAO\nselect * from business_processes where crm_configuration_id = 39;\n# 01941000000H669AAC, 01941000000H66JAAS\n\nselect * from record_type_field_values\n where record_type_id IN (24);\n\nselect * from crm_field_values where id IN (2730);\n\nselect * from crm_configurations where id = 39;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 1\nand sa.provider = 'salesforce'; #1035\n\n\nselect * from users where team_id = 1; # 222 group 3\nSELECT * FROM activities WHERE user_id = 222 order by id desc;\nselect * from sidekick_settings where team_id = 1;\nselect * from teams where id = 1;\nselect * from team_features where team_id = 1;\n\nselect * from activities where crm_configuration_id = 2\nand provider = 'ms-teams' and id = 608765;\n\nSELECT * FROM activities WHERE crm_configuration_id = 2 and crm_provider_id = '59523413338';\n\nselect * from sidekick_settings where team_id = 2;\n\nSELECT * FROM activities WHERE id = 608660;\nselect * from activity_summary_logs where activity_id = 608660;\nselect * from ai_prompts where transcription_id = 11214;\n\n# ********************************************************************************************************\nSELECT * FROM activities WHERE uuid_to_bin('ed78a437-2804-450e-ab2f-56ab1c641346') = uuid;\n# id: 608818, crm: 59628809737\nSELECT * FROM activities WHERE uuid_to_bin('36b06e55-afdd-4782-8dee-c624cd0af191') = uuid;\n# id: 608821, crm: 59632069252\nSELECT ce.start_time, ce.end_time, a.id, a.uuid, crm_provider_id, calendar_event_id, title,\nplaybook_category_id, user_id, lead_id, contact_id, account_id, opportunity_id,\nscheduled_start_time, scheduled_end_time, actual_start_time, actual_end_time, a.created_at\nFROM activities a\njoin calendar_events ce on a.calendar_event_id = ce.id\nWHERE a.id IN (608818, 608821);\n\nselect * from users where team_id = 1;\nselect * from team_settings where team_id = 1;\nselect * from crm_profiles where crm_configuration_id = 39 order by user_id;\n\nselect * from team_features where team_id = 1;\n\nselect * from users where team_id = 2;\n\nSELECT * FROM activities WHERE uuid_to_bin('ec7647e9-5225-458b-b475-f31aa2769204') = uuid; # 612639\n# Preslava N. Ivanova, grou id 3\n\nSELECT * FROM opportunities WHERE uuid_to_bin('a2928fe5-aec5-46cb-85d9-7654c89e46a6') = uuid;\n\nselect * from activities where opportunity_id = 344 and actual_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00';\n\nselect\n a.id,\n a.type,\n a.scheduled_start_time,\n a.actual_start_time,\n a.created_at,\n a.opportunity_id,\n a.status\nFROM activities a\nWHERE opportunity_id = 344\nand status IN ('completed', 'received', 'delivered')\nand (\n (a.actual_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00')\nOR (a.created_at between '2024-10-11 00:00:00' and '2024-10-12 00:00:00')\nOR (a.scheduled_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00'))\n;\n\nSELECT * FROM users WHERE id = 222;\n\nSELECT * FROM crm_profiles WHERE user_id = 222;\nselect * from crm_layouts where crm_configuration_id = 39;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 281;\n\nselect * from group_deal_risk_types;\n\nselect * from opportunities where team_id = 1;\n\nSELECT * FROM opportunities WHERE id = 315;\nSELECT * FROM crm_field_data WHERE object_id = 315;\nselect * from crm_field_data where object_id = 260;\n\nselect * from generic_ai_prompts where subject_id = 315;\n\nselect * from teams; # 36, 21, 121, james.graham@bullhorn.jiminny.com\nSELECT * FROM social_accounts WHERE sociable_id = 121 and provider = 'bullhorn';\n\n# ************************************************************************************\nselect * from teams where id = 1;\nselect * from crm_configurations where id = 39;\nselect * from users where team_id = 1;\nselect u.email, cp.* from users u\njoin crm_profiles cp on u.id = cp.user_id\nwhere u.team_id = 1;\n# 1 - 00541000004281rAAA\n# 204 - 0052g000003freeAAA\n# 429 - 0052g000003qGOiAAM\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 1\nand sa.provider = 'salesforce';\n\nselect * from activities where type = 'softphone'\nand created_at > '2024-12-11 15:24:36' order by id desc;\n\nselect * from activity_providers where team_id = 1;\nselect * from activity_provider_users where activity_provider_id = 328;\n\nselect * from opportunities where crm_configuration_id = 39\nAND account_id = 178 AND is_closed = false\norder by created_at DESC;\n\nselect * from contacts where id = 3952;\nselect * from accounts where id = 178;\n\n# ************************************************************************************\nselect * from teams where id = 36;\nselect * from crm_configurations where id = 21;\nselect * from users where team_id = 36;\nselect u.email, cp.* from users u\njoin crm_profiles cp on u.id = cp.user_id\nwhere u.team_id = 36;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 36\nand sa.provider = 'bullhorn';\n\nselect * from social_accounts where id = 348;\nUPDATE social_accounts SET\nprovider_user_token = '21442_6802599_91:41179a58-21e7-4d7c-ad58-56bb666b2f65',\nprovider_refresh_token = '21442_6802599_91:01c6b335-3f2a-42e4-85ff-8a08fa65fceb',\nexpires = 1733998131,\nstate = 'connected'\nWHERE id = 348;\n\n# ************************************************************************************\nselect * from teams where id = 31;\nselect * from crm_configurations where id = 18;\n\nselect * from users where team_id = 31; # 257\nselect u.email, cp.* from users u\njoin crm_profiles cp on u.id = cp.user_id\nwhere u.team_id = 31;\n\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 31\nand sa.provider = 'close';\n\nselect * from contacts where crm_configuration_id = 18;\n\n# ********************** NEPTUNE **************************************************************\nselect * from teams;\nselect * from users where id IN (1030, 1035, 1052);\nselect * from crm_configurations;\n\nselect * from users where team_id = 65; # 257\nselect * from team_settings where team_id = 65; # 257\nselect * from invitations where team_id = 65; # 257\nselect * from users where email = 'integration-account@jiminny.com'; # 257\nselect u.email, cp.* from users u\njoin crm_profiles cp on u.id = cp.user_id\nwhere u.team_id = 65;\n\nselect * from crm_configurations where id = 53;\nselect * from accounts where crm_configuration_id = 53 order by id desc;\nselect * from leads where crm_configuration_id = 53 order by id desc;\nselect * from contacts where crm_configuration_id = 53 order by id desc;\nselect * from opportunities where crm_configuration_id = 53 order by id desc;\nselect * from crm_profiles where crm_configuration_id = 53 order by id desc;\nselect * from crm_fields where crm_configuration_id = 53 order by id desc;\nselect * from crm_field_values where crm_field_id = 3341 order by id desc;\nselect * from crm_layouts where crm_configuration_id = 53 order by id desc;\nselect * from stages where crm_configuration_id = 53 order by id desc;\n\n\nselect * from crm_profiles where crm_configuration_id = 13;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 65\nand sa.provider = 'integration-app';\n\nselect * from contacts where crm_configuration_id = 13;\n\nselect * from social_accounts where sociable_id = 283;\n\nSELECT * FROM opportunities WHERE crm_provider_id = '006O400000E9bzeIAB';\n\nselect * from activity_providers where team_id = 65;\nSELECT * FROM activities WHERE crm_configuration_id IN (51, 52, 53);\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 65\n;\n\n# ***************************** STAGING ********************************************\nSELECT * FROM teams;\nSELECT * FROM teams WHERE id = 88;\nSELECT * FROM teams WHERE id = 89;\nselect * from team_settings where team_id = 89;\nSELECT * FROM users WHERE team_id = 89;\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 89;\n\nselect * from users;\nSELECT * FROM social_accounts WHERE sociable_id = 1761;\nSELECT * FROM crm_configurations WHERE id = 70;\nselect * from accounts where crm_configuration_id = 70 order by id desc;\nselect * from leads where crm_configuration_id = 70 order by id desc;\nselect * from contacts where crm_configuration_id = 70 order by id desc;\nselect * from opportunities where crm_configuration_id = 70 order by id desc;\nselect * from crm_profiles where crm_configuration_id = 70 order by id desc;\nselect * from crm_fields where crm_configuration_id = 70 order by id desc;\nselect * from crm_field_values where crm_field_id = 3536 order by id desc;\nselect * from crm_layouts where crm_configuration_id = 70 order by id desc;\nselect * from stages where crm_configuration_id = 70 order by id desc;\nselect * from business_processes where crm_configuration_id = 70 order by id desc;\nselect * from business_process_stages where business_process_id = 34;\n\nselect * from contacts where id = 10468;\n\nselect * from crm_layouts where crm_configuration_id = 70;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 388;\nSELECT * FROM crm_fields WHERE id IN (3533,3534,3535);\n\nselect * from activities where crm_configuration_id = 70\nand (account_id IS NOT NULL or lead_id IS NOT NULL or contact_id IS NOT NULL or opportunity_id IS NOT NULL) order by id desc;\n\nSELECT * FROM activities WHERE uuid_to_bin('2e10b60f-8a61-41c5-a3d4-28835353dc65') = uuid;\nSELECT * FROM activities where crm_configuration_id = 69 ;\n\nSELECT * FROM users WHERE email LIKE '%jiminny_web_sa2@jiminny.com%';\nSELECT * FROM activities WHERE uuid_to_bin('5a150c93-40fc-42ec-b3bd-c1d328e09f6e') = uuid;\nSELECT * FROM opportunities WHERE id = 385;\n\nselect * from participants p\njoin activities a on p.activity_id = a.id\nwhere a.crm_configuration_id = 70\nand (p.lead_id IS NOT NULL or p.contact_id IS NOT NULL);\nSELECT * FROM participants WHERE id = 1013638;\n\nselect * from teams where id = 90;\nselect * from users where team_id = 90;\nselect * from social_accounts where social_accounts.sociable_id IN (1960,1760);\nSELECT * FROM crm_profiles WHERE crm_configuration_id = 71;\nselect * from invitations where team_id = 90;\n\nselect * from crm_configurations where id = 71;\nselect * from accounts where crm_configuration_id = 71 order by id desc;\nselect * from leads where crm_configuration_id = 71 order by id desc;\nselect * from contacts where crm_configuration_id = 71 order by id desc;\nselect * from opportunities where crm_configuration_id = 71 order by id desc;\nselect * from crm_profiles where crm_configuration_id = 71 order by id desc;\nselect * from crm_fields where crm_configuration_id = 71 order by id desc;\nselect * from crm_field_values where crm_field_id = 3341 order by id desc;\nselect * from crm_layouts where crm_configuration_id = 71 order by id desc;\nselect * from stages where crm_configuration_id = 71 order by id desc;\n\nselect * from users order by secondary_email desc;\nselect u.id, u.email, u.status, sa.id, sa.provider_user_id from social_accounts sa\n join users u on sa.sociable_id = u.id\nwhere sa.provider = 'google' and u.email LIKE 'aneliya%';\n\nselect * from failed_jobs order by id desc;\n\nselect * from users where email = 'ben.allwright@learningpeople.co.uk' or secondary_email = 'ben.allwright@learningpeople.co.uk';\n\nselect * from teams;\nSELECT * FROM crm_profiles WHERE crm_configuration_id = 39;\nSELECT * FROM crm_fields WHERE crm_configuration_id = 39 and object_type = 'task';\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 1\nand sa.provider = 'salesforce';\n\n# ************************************************************************************\nSELECT * FROM activities WHERE uuid_to_bin('c38b3895-fd0f-4b1f-9fb2-c170dba137c6') = uuid;\nSELECT * FROM crm_configurations WHERE id = 70;\n\nselect * from teams where id = 1;\nselect * from groups where team_id = 1;\nselect * from users where team_id = 1;\n\nselect o.id, o.name,o.close_date, u.id, u.name, u.group_id, r.id, r.display_name, g.name, g.scope from opportunities o\njoin users u on o.user_id = u.id\njoin groups g on u.group_id = g.id\njoin role_user ru on u.id = ru.user_id\njoin roles r on ru.role_id = r.id\nwhere o.crm_configuration_id = 39 and close_date > '2024-01-01 00:00:00';\n\nselect * from role_user where user_id = 143;\nselect * from roles;\n\nselect * from role_user;\nselect * from groups where id = 9;\nselect * from scope_groups where group_id = 9;\n\n# ************************************************************************************\nselect * from teams where id = 36;\nselect * from crm_configurations;\nSELECT * FROM social_accounts WHERE sociable_id = 121;\n\nhttps://crmsandbox.zoho.com/crm/jiminnyw4/tab/Leads/4776201000005049105\nhttps://crmsandbox.zoho.com/crm/\n\nhttps://crm.zoho.com/crm/org3469620/tab/Leads/230045000229559080\n https://crm.zoho.com/crm/\n org3469620\n\nSELECT * FROM activities WHERE uuid_to_bin('03382d20-c8bc-48e7-a3d4-90b52fa5ceab') = uuid;\n\nselect * from users where email LIKE \"%mobile_automation_%\";\nselect * from social_accounts where sociable_id IN (2228);\nselect * from crm_profiles where user_id IN (2222,2223,2226,2227);\n\nselect * from teams order by id desc;\nSELECT * FROM users WHERE id = 2229;\nSELECT * FROM crm_profiles WHERE user_id = 2229;\nselect * from opportunities where crm_configuration_id = 88;\nselect * from crm_fields where crm_configuration_id = 88;\nselect * from crm_profiles where crm_configuration_id = 88;\n\nSELECT * FROM teams WHERE id = 1;\n\nSELECT * FROM users WHERE id = 143;\nSELECT * FROM users WHERE uuid_to_bin('fde193d3-06a2-4e1a-8895-62b94039215d') = uuid;\nSELECT * FROM teams WHERE uuid_to_bin('73385071-a756-42ae-9c73-8b53f2309467') = uuid;\n\nhttps://app.staging.jiminny.com/ondemand?\n min_duration=1\n &\n only_recorded=1\n &\n user_id%5B%5D=641f1acb-16b8-42d1-8726-df52979dad0e\n &\n sequence_number=2\n\n select * from users where team_id = 1 and email like '%stoyan%'\n\nselect * from coaching_feedbacks;\n\nselect * from teams;\nSELECT * FROM users WHERE team_id = 36;\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 19\nand sa.provider = 'pipedrive';\n\nselect * from users where id = 143;\n\nSELECT * FROM users WHERE uuid_to_bin('73180eeb-33de-4065-977d-ccbe0e6c94fc') = uuid;\nSELECT * FROM teams WHERE uuid_to_bin('73180eeb-33de-4065-977d-ccbe0e6c94fc') = uuid;\nSELECT * FROM activity_shares WHERE uuid_to_bin('73180eeb-33de-4065-977d-ccbe0e6c94fc') = uuid;\n\nselect * from users where team_id = 2;\nselect * from activities where crm_configuration_id = 39\nand activities.scheduled_start_time BETWEEN '2025-04-09 00:00:00' AND '2025-04-09 23:59:59'\nAND user_id = 143\norder by id desc;\n\n# ************************************************************************************\nselect * from teams where id = 142; # 2312, 126\nselect * from team_settings;\nselect * from users where team_id = 142; # 21642\nSELECT * FROM social_accounts WHERE sociable_id = 21642;\nSELECT * FROM crm_profiles cp join users u ON u.id = cp.user_id WHERE team_id = 142;\nselect * from crm_profiles where id IN (93);\nselect * from invitations;\nselect * from team_features where team_id = 1;\n\nSELECT * FROM crm_configurations WHERE id = 126;\nselect * from accounts where crm_configuration_id = 126 order by id desc;\nselect * from leads where crm_configuration_id = 126 order by id desc;\nselect * from contacts where crm_configuration_id = 126 order by id desc;\nselect * from opportunities where crm_configuration_id = 126 order by id desc;\nselect * from crm_profiles where crm_configuration_id = 126 order by id desc;\nselect * from crm_fields where crm_configuration_id = 126 # 11060\n# and type IN ('picklist', 'status')\n# and object_type = 'task'\norder by id desc;\n# 5731,5732,5733\nselect DISTINCT crm_field_id from crm_field_values where crm_field_id IN (11151,12239,12215,12185,12175,12165,12144,12137,12127,12109,12107,12105,12103,12092,12037,12005,12003,11987,11969,11958,11951,11942,11931,11924,11921,11917,11915,11901,11893,11883,11872,11870,11868,11866,11839,11833,11821,11793,11780,11777,11769,11757,11737,11735,11656,11645,11638,11629,11618,11611,11602,11591,11584,11581,11558,11544,11543,11534,11532,11529,11527,11503,11497,11493,11488,11470,11468,11457,11455,11397,11387,11372,11363,11348,11323,11318,11309,11301,11300,11292,11290,11286,11284,11256,11252,11242,11237,11233,11219,11176,11160) order by id desc;\nselect * from crm_layouts where crm_configuration_id = 126 order by id desc;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id in (300,299,298);\nselect * from stages where crm_configuration_id = 126 order by id desc;\nselect * from business_processes where crm_configuration_id = 126 order by id desc;\nselect * from business_process_stages where business_process_id IN (76,75,74,73);\nselect * from playbooks where team_id = 142;\nselect * from playbook_layouts where playbook_id IN (108);\nSELECT * FROM playbook_categories WHERE playbook_id IN (108);\n\nselect * from teams where id = 130;\nSELECT * FROM social_accounts WHERE sociable_id = 2291;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 2\nand sa.provider = 'hubspot';\n\nSELECT * FROM activities\n WHERE crm_configuration_id = 110;\n\nselect * from teams;\nselect * from crm_configurations;\n\nSELECT * FROM activities WHERE id = 628773;\nSELECT * FROM crm_profiles WHERE user_id = 1460;\nSELECT * FROM social_accounts WHERE sociable_id = 2291;\n\nselect * from teams;\nselect ru.*, pr.*, p.* from users u join role_user ru on ru.user_id = u.id\njoin permission_role pr on pr.role_id = ru.role_id\n join permissions p on p.id = pr.permission_id\nwhere team_id = 495 and p.name IN ('dial');\n\nselect * from teams where id = 145;\nselect * from crm_configurations where id = 129;\nselect * from social_accounts where sociable_id = 2317;\nSELECT * FROM activities WHERE uuid_to_bin('8dbab184-a333-4268-ad57-fb41f8d53a9a') = uuid;\n\nselect * from teams where id = 1;\nSELECT * FROM crm_layouts WHERE crm_configuration_id = 39;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 280;\nSELECT * FROM crm_layout_entities WHERE id = 5507;\nSELECT * FROM crm_fields WHERE crm_configuration_id = 39 and object_type IN ('event');\n\nselect * from teams;\nselect * from activities where crm_configuration_id = 14;\n\nSELECT * FROM social_accounts where provider = 'copper';\n\nselect * from activities where id = 628467;\nselect * from participants where activity_id = 628467;\n\nSELECT * FROM contacts WHERE id = 3969;\nSELECT * FROM accounts WHERE id = 177;\n\nSELECT * FROM activities WHERE uuid_to_bin('4eb54c77-cfa3-2bd4-84a7-9ed46a21c988') = uuid;\n\n# ********************* BH\nselect * from teams where id = 36;\nSELECT * FROM crm_configurations WHERE id = 21;\nselect * from activities where crm_configuration_id = 21 and id = 607901;\nselect * from activities where crm_configuration_id = 21;\n\nselect * roles;\nselect * from permissions;\nselect * from permission_role where permission_id = 226;\n\nselect * from migrations order by id desc;\n\n# mercury\n# neptune\n# earth\n\nselect * from teams;\nselect * from teams where id = 19;\nselect * from teams where id = 27;\nselect * from users where team_id = 27;\nSELECT * FROM crm_configurations WHERE id = 42;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 19\nand sa.provider = 'pipedrive';\n\nselect * from activities where id = 631461;\nSELECT * FROM crm_field_values WHERE crm_field_id = 180;\n\nselect * from teams where id = 2;\nSELECT * FROM social_accounts WHERE sociable_id = 89;\n\nSELECT * FROM activities WHERE uuid_to_bin('ba0c029a-bc14-4e17-8603-64174acebcbb') = uuid; # 634273\nselect * from activity_summary_logs where activity_id = 634273;\n\nselect * from sidekick_settings where team_id = 2;\n\nselect * from teams; # 2, 2\nSELECT * FROM crm_configurations WHERE team_id = 2; # 2\nselect * from team_features where team_id = 2;\nselect * from features;\nSELECT * FROM opportunities WHERE crm_configuration_id = 2 and crm_provider_id = '51317301383';\nSELECT * FROM opportunities WHERE crm_configuration_id = 2 order by id desc;\n\nselect * from automated_reports order by id desc;\nselect * from automated_report_results order by id desc;\nselect * from users where team_id = 1 and id IN (7160, 3248);\nselect * from migrations order by id desc;\n\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 1 and sa.provider = 'salesforce';\n\nselect * from teams where id = 1;\nselect * from groups g JOIN playbooks p on g.playbook_id = p.id where g.team_id = 1;\nselect * from groups where id = 565;\nselect * from playbooks where team_id = 1;\nselect * from playbooks where id = 175;\nselect * from playbook_categories where playbook_id = 175;\nselect * from users where team_id = 1;\nselect * from users where id = 7160;\nselect * from crm_profiles where user_id = 7160;\nselect * from features;\nselect\n *\n# id, uuid, type, provider, playbook_category_id, user_id, lead_id, contact_id, account_id, opportunity_id, stage_id,\n# crm_configuration_id, crm_provider_id, transcription_id, status\nfrom activities where crm_configuration_id = 1 and type = 'conference'\n# and crm_provider_id IS NOT NULL\nand provider != 'uploader' and actual_start_time IS NOT NULL\nORDER by id desc;\nselect * from activities where id = 54747783; # 00UO400000pCzojMAC\n\nselect p.id, p.activity_type, pc.id, pc.name\nFROM playbooks p\njoin playbook_categories pc on p.id = pc.playbook_id\nwhere p.team_id = 1 and p.activity_type = 'event';\n\nSELECT * FROM crm_fields WHERE crm_configuration_id = 1 and object_type = 'event';\nSELECT * FROM crm_field_values WHERE crm_field_id = 4;\n\nselect * from crm_layouts cl join playbook_layouts pl on cl.id = pl.layout_id\nwhere crm_configuration_id = 1 and pl.playbook_id = 175;\n\nselect * from teams;\nSELECT r.* FROM automated_reports r\njoin teams t on r.team_id = t.id\nWHERE r.frequency = 'daily'\n and r.status = 1\nAND t.status = 'active'\nAND (r.expires_at >= now() OR r.expires_at IS NULL);\n\nselect * from automated_report_results where report_id IN (18, 33);\n\nselect * from activity_searches where id = 10932;\nselect * from activity_search_filters where activity_search_id = 10932;\nselect * from automated_reports;\nselect * from automated_report_results where report_id IN (34, 35);","depth":4,"value":"SELECT * FROM teams WHERE id = 1;\n\nselect * from crm_layouts where crm_configuration_id = 39;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 283;\nSELECT * FROM crm_fields WHERE id = 2234;\nSELECT * FROM crm_field_values WHERE crm_field_id = 2234;\n\nselect * from crm_profiles where user_id = 143;\n\nselect * from record_types where crm_configuration_id = 39; # 0121K000001MHElQAO,0121K000001MHEqQAO\nselect * from business_processes where crm_configuration_id = 39;\n# 01941000000H669AAC, 01941000000H66JAAS\n\nselect * from record_type_field_values\n where record_type_id IN (24);\n\nselect * from crm_field_values where id IN (2730);\n\nselect * from crm_configurations where id = 39;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 1\nand sa.provider = 'salesforce'; #1035\n\n\nselect * from users where team_id = 1; # 222 group 3\nSELECT * FROM activities WHERE user_id = 222 order by id desc;\nselect * from sidekick_settings where team_id = 1;\nselect * from teams where id = 1;\nselect * from team_features where team_id = 1;\n\nselect * from activities where crm_configuration_id = 2\nand provider = 'ms-teams' and id = 608765;\n\nSELECT * FROM activities WHERE crm_configuration_id = 2 and crm_provider_id = '59523413338';\n\nselect * from sidekick_settings where team_id = 2;\n\nSELECT * FROM activities WHERE id = 608660;\nselect * from activity_summary_logs where activity_id = 608660;\nselect * from ai_prompts where transcription_id = 11214;\n\n# ********************************************************************************************************\nSELECT * FROM activities WHERE uuid_to_bin('ed78a437-2804-450e-ab2f-56ab1c641346') = uuid;\n# id: 608818, crm: 59628809737\nSELECT * FROM activities WHERE uuid_to_bin('36b06e55-afdd-4782-8dee-c624cd0af191') = uuid;\n# id: 608821, crm: 59632069252\nSELECT ce.start_time, ce.end_time, a.id, a.uuid, crm_provider_id, calendar_event_id, title,\nplaybook_category_id, user_id, lead_id, contact_id, account_id, opportunity_id,\nscheduled_start_time, scheduled_end_time, actual_start_time, actual_end_time, a.created_at\nFROM activities a\njoin calendar_events ce on a.calendar_event_id = ce.id\nWHERE a.id IN (608818, 608821);\n\nselect * from users where team_id = 1;\nselect * from team_settings where team_id = 1;\nselect * from crm_profiles where crm_configuration_id = 39 order by user_id;\n\nselect * from team_features where team_id = 1;\n\nselect * from users where team_id = 2;\n\nSELECT * FROM activities WHERE uuid_to_bin('ec7647e9-5225-458b-b475-f31aa2769204') = uuid; # 612639\n# Preslava N. Ivanova, grou id 3\n\nSELECT * FROM opportunities WHERE uuid_to_bin('a2928fe5-aec5-46cb-85d9-7654c89e46a6') = uuid;\n\nselect * from activities where opportunity_id = 344 and actual_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00';\n\nselect\n a.id,\n a.type,\n a.scheduled_start_time,\n a.actual_start_time,\n a.created_at,\n a.opportunity_id,\n a.status\nFROM activities a\nWHERE opportunity_id = 344\nand status IN ('completed', 'received', 'delivered')\nand (\n (a.actual_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00')\nOR (a.created_at between '2024-10-11 00:00:00' and '2024-10-12 00:00:00')\nOR (a.scheduled_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00'))\n;\n\nSELECT * FROM users WHERE id = 222;\n\nSELECT * FROM crm_profiles WHERE user_id = 222;\nselect * from crm_layouts where crm_configuration_id = 39;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 281;\n\nselect * from group_deal_risk_types;\n\nselect * from opportunities where team_id = 1;\n\nSELECT * FROM opportunities WHERE id = 315;\nSELECT * FROM crm_field_data WHERE object_id = 315;\nselect * from crm_field_data where object_id = 260;\n\nselect * from generic_ai_prompts where subject_id = 315;\n\nselect * from teams; # 36, 21, 121, james.graham@bullhorn.jiminny.com\nSELECT * FROM social_accounts WHERE sociable_id = 121 and provider = 'bullhorn';\n\n# ************************************************************************************\nselect * from teams where id = 1;\nselect * from crm_configurations where id = 39;\nselect * from users where team_id = 1;\nselect u.email, cp.* from users u\njoin crm_profiles cp on u.id = cp.user_id\nwhere u.team_id = 1;\n# 1 - 00541000004281rAAA\n# 204 - 0052g000003freeAAA\n# 429 - 0052g000003qGOiAAM\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 1\nand sa.provider = 'salesforce';\n\nselect * from activities where type = 'softphone'\nand created_at > '2024-12-11 15:24:36' order by id desc;\n\nselect * from activity_providers where team_id = 1;\nselect * from activity_provider_users where activity_provider_id = 328;\n\nselect * from opportunities where crm_configuration_id = 39\nAND account_id = 178 AND is_closed = false\norder by created_at DESC;\n\nselect * from contacts where id = 3952;\nselect * from accounts where id = 178;\n\n# ************************************************************************************\nselect * from teams where id = 36;\nselect * from crm_configurations where id = 21;\nselect * from users where team_id = 36;\nselect u.email, cp.* from users u\njoin crm_profiles cp on u.id = cp.user_id\nwhere u.team_id = 36;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 36\nand sa.provider = 'bullhorn';\n\nselect * from social_accounts where id = 348;\nUPDATE social_accounts SET\nprovider_user_token = '21442_6802599_91:41179a58-21e7-4d7c-ad58-56bb666b2f65',\nprovider_refresh_token = '21442_6802599_91:01c6b335-3f2a-42e4-85ff-8a08fa65fceb',\nexpires = 1733998131,\nstate = 'connected'\nWHERE id = 348;\n\n# ************************************************************************************\nselect * from teams where id = 31;\nselect * from crm_configurations where id = 18;\n\nselect * from users where team_id = 31; # 257\nselect u.email, cp.* from users u\njoin crm_profiles cp on u.id = cp.user_id\nwhere u.team_id = 31;\n\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 31\nand sa.provider = 'close';\n\nselect * from contacts where crm_configuration_id = 18;\n\n# ********************** NEPTUNE **************************************************************\nselect * from teams;\nselect * from users where id IN (1030, 1035, 1052);\nselect * from crm_configurations;\n\nselect * from users where team_id = 65; # 257\nselect * from team_settings where team_id = 65; # 257\nselect * from invitations where team_id = 65; # 257\nselect * from users where email = 'integration-account@jiminny.com'; # 257\nselect u.email, cp.* from users u\njoin crm_profiles cp on u.id = cp.user_id\nwhere u.team_id = 65;\n\nselect * from crm_configurations where id = 53;\nselect * from accounts where crm_configuration_id = 53 order by id desc;\nselect * from leads where crm_configuration_id = 53 order by id desc;\nselect * from contacts where crm_configuration_id = 53 order by id desc;\nselect * from opportunities where crm_configuration_id = 53 order by id desc;\nselect * from crm_profiles where crm_configuration_id = 53 order by id desc;\nselect * from crm_fields where crm_configuration_id = 53 order by id desc;\nselect * from crm_field_values where crm_field_id = 3341 order by id desc;\nselect * from crm_layouts where crm_configuration_id = 53 order by id desc;\nselect * from stages where crm_configuration_id = 53 order by id desc;\n\n\nselect * from crm_profiles where crm_configuration_id = 13;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 65\nand sa.provider = 'integration-app';\n\nselect * from contacts where crm_configuration_id = 13;\n\nselect * from social_accounts where sociable_id = 283;\n\nSELECT * FROM opportunities WHERE crm_provider_id = '006O400000E9bzeIAB';\n\nselect * from activity_providers where team_id = 65;\nSELECT * FROM activities WHERE crm_configuration_id IN (51, 52, 53);\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 65\n;\n\n# ***************************** STAGING ********************************************\nSELECT * FROM teams;\nSELECT * FROM teams WHERE id = 88;\nSELECT * FROM teams WHERE id = 89;\nselect * from team_settings where team_id = 89;\nSELECT * FROM users WHERE team_id = 89;\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 89;\n\nselect * from users;\nSELECT * FROM social_accounts WHERE sociable_id = 1761;\nSELECT * FROM crm_configurations WHERE id = 70;\nselect * from accounts where crm_configuration_id = 70 order by id desc;\nselect * from leads where crm_configuration_id = 70 order by id desc;\nselect * from contacts where crm_configuration_id = 70 order by id desc;\nselect * from opportunities where crm_configuration_id = 70 order by id desc;\nselect * from crm_profiles where crm_configuration_id = 70 order by id desc;\nselect * from crm_fields where crm_configuration_id = 70 order by id desc;\nselect * from crm_field_values where crm_field_id = 3536 order by id desc;\nselect * from crm_layouts where crm_configuration_id = 70 order by id desc;\nselect * from stages where crm_configuration_id = 70 order by id desc;\nselect * from business_processes where crm_configuration_id = 70 order by id desc;\nselect * from business_process_stages where business_process_id = 34;\n\nselect * from contacts where id = 10468;\n\nselect * from crm_layouts where crm_configuration_id = 70;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 388;\nSELECT * FROM crm_fields WHERE id IN (3533,3534,3535);\n\nselect * from activities where crm_configuration_id = 70\nand (account_id IS NOT NULL or lead_id IS NOT NULL or contact_id IS NOT NULL or opportunity_id IS NOT NULL) order by id desc;\n\nSELECT * FROM activities WHERE uuid_to_bin('2e10b60f-8a61-41c5-a3d4-28835353dc65') = uuid;\nSELECT * FROM activities where crm_configuration_id = 69 ;\n\nSELECT * FROM users WHERE email LIKE '%jiminny_web_sa2@jiminny.com%';\nSELECT * FROM activities WHERE uuid_to_bin('5a150c93-40fc-42ec-b3bd-c1d328e09f6e') = uuid;\nSELECT * FROM opportunities WHERE id = 385;\n\nselect * from participants p\njoin activities a on p.activity_id = a.id\nwhere a.crm_configuration_id = 70\nand (p.lead_id IS NOT NULL or p.contact_id IS NOT NULL);\nSELECT * FROM participants WHERE id = 1013638;\n\nselect * from teams where id = 90;\nselect * from users where team_id = 90;\nselect * from social_accounts where social_accounts.sociable_id IN (1960,1760);\nSELECT * FROM crm_profiles WHERE crm_configuration_id = 71;\nselect * from invitations where team_id = 90;\n\nselect * from crm_configurations where id = 71;\nselect * from accounts where crm_configuration_id = 71 order by id desc;\nselect * from leads where crm_configuration_id = 71 order by id desc;\nselect * from contacts where crm_configuration_id = 71 order by id desc;\nselect * from opportunities where crm_configuration_id = 71 order by id desc;\nselect * from crm_profiles where crm_configuration_id = 71 order by id desc;\nselect * from crm_fields where crm_configuration_id = 71 order by id desc;\nselect * from crm_field_values where crm_field_id = 3341 order by id desc;\nselect * from crm_layouts where crm_configuration_id = 71 order by id desc;\nselect * from stages where crm_configuration_id = 71 order by id desc;\n\nselect * from users order by secondary_email desc;\nselect u.id, u.email, u.status, sa.id, sa.provider_user_id from social_accounts sa\n join users u on sa.sociable_id = u.id\nwhere sa.provider = 'google' and u.email LIKE 'aneliya%';\n\nselect * from failed_jobs order by id desc;\n\nselect * from users where email = 'ben.allwright@learningpeople.co.uk' or secondary_email = 'ben.allwright@learningpeople.co.uk';\n\nselect * from teams;\nSELECT * FROM crm_profiles WHERE crm_configuration_id = 39;\nSELECT * FROM crm_fields WHERE crm_configuration_id = 39 and object_type = 'task';\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 1\nand sa.provider = 'salesforce';\n\n# ************************************************************************************\nSELECT * FROM activities WHERE uuid_to_bin('c38b3895-fd0f-4b1f-9fb2-c170dba137c6') = uuid;\nSELECT * FROM crm_configurations WHERE id = 70;\n\nselect * from teams where id = 1;\nselect * from groups where team_id = 1;\nselect * from users where team_id = 1;\n\nselect o.id, o.name,o.close_date, u.id, u.name, u.group_id, r.id, r.display_name, g.name, g.scope from opportunities o\njoin users u on o.user_id = u.id\njoin groups g on u.group_id = g.id\njoin role_user ru on u.id = ru.user_id\njoin roles r on ru.role_id = r.id\nwhere o.crm_configuration_id = 39 and close_date > '2024-01-01 00:00:00';\n\nselect * from role_user where user_id = 143;\nselect * from roles;\n\nselect * from role_user;\nselect * from groups where id = 9;\nselect * from scope_groups where group_id = 9;\n\n# ************************************************************************************\nselect * from teams where id = 36;\nselect * from crm_configurations;\nSELECT * FROM social_accounts WHERE sociable_id = 121;\n\nhttps://crmsandbox.zoho.com/crm/jiminnyw4/tab/Leads/4776201000005049105\nhttps://crmsandbox.zoho.com/crm/\n\nhttps://crm.zoho.com/crm/org3469620/tab/Leads/230045000229559080\n https://crm.zoho.com/crm/\n org3469620\n\nSELECT * FROM activities WHERE uuid_to_bin('03382d20-c8bc-48e7-a3d4-90b52fa5ceab') = uuid;\n\nselect * from users where email LIKE \"%mobile_automation_%\";\nselect * from social_accounts where sociable_id IN (2228);\nselect * from crm_profiles where user_id IN (2222,2223,2226,2227);\n\nselect * from teams order by id desc;\nSELECT * FROM users WHERE id = 2229;\nSELECT * FROM crm_profiles WHERE user_id = 2229;\nselect * from opportunities where crm_configuration_id = 88;\nselect * from crm_fields where crm_configuration_id = 88;\nselect * from crm_profiles where crm_configuration_id = 88;\n\nSELECT * FROM teams WHERE id = 1;\n\nSELECT * FROM users WHERE id = 143;\nSELECT * FROM users WHERE uuid_to_bin('fde193d3-06a2-4e1a-8895-62b94039215d') = uuid;\nSELECT * FROM teams WHERE uuid_to_bin('73385071-a756-42ae-9c73-8b53f2309467') = uuid;\n\nhttps://app.staging.jiminny.com/ondemand?\n min_duration=1\n &\n only_recorded=1\n &\n user_id%5B%5D=641f1acb-16b8-42d1-8726-df52979dad0e\n &\n sequence_number=2\n\n select * from users where team_id = 1 and email like '%stoyan%'\n\nselect * from coaching_feedbacks;\n\nselect * from teams;\nSELECT * FROM users WHERE team_id = 36;\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 19\nand sa.provider = 'pipedrive';\n\nselect * from users where id = 143;\n\nSELECT * FROM users WHERE uuid_to_bin('73180eeb-33de-4065-977d-ccbe0e6c94fc') = uuid;\nSELECT * FROM teams WHERE uuid_to_bin('73180eeb-33de-4065-977d-ccbe0e6c94fc') = uuid;\nSELECT * FROM activity_shares WHERE uuid_to_bin('73180eeb-33de-4065-977d-ccbe0e6c94fc') = uuid;\n\nselect * from users where team_id = 2;\nselect * from activities where crm_configuration_id = 39\nand activities.scheduled_start_time BETWEEN '2025-04-09 00:00:00' AND '2025-04-09 23:59:59'\nAND user_id = 143\norder by id desc;\n\n# ************************************************************************************\nselect * from teams where id = 142; # 2312, 126\nselect * from team_settings;\nselect * from users where team_id = 142; # 21642\nSELECT * FROM social_accounts WHERE sociable_id = 21642;\nSELECT * FROM crm_profiles cp join users u ON u.id = cp.user_id WHERE team_id = 142;\nselect * from crm_profiles where id IN (93);\nselect * from invitations;\nselect * from team_features where team_id = 1;\n\nSELECT * FROM crm_configurations WHERE id = 126;\nselect * from accounts where crm_configuration_id = 126 order by id desc;\nselect * from leads where crm_configuration_id = 126 order by id desc;\nselect * from contacts where crm_configuration_id = 126 order by id desc;\nselect * from opportunities where crm_configuration_id = 126 order by id desc;\nselect * from crm_profiles where crm_configuration_id = 126 order by id desc;\nselect * from crm_fields where crm_configuration_id = 126 # 11060\n# and type IN ('picklist', 'status')\n# and object_type = 'task'\norder by id desc;\n# 5731,5732,5733\nselect DISTINCT crm_field_id from crm_field_values where crm_field_id IN (11151,12239,12215,12185,12175,12165,12144,12137,12127,12109,12107,12105,12103,12092,12037,12005,12003,11987,11969,11958,11951,11942,11931,11924,11921,11917,11915,11901,11893,11883,11872,11870,11868,11866,11839,11833,11821,11793,11780,11777,11769,11757,11737,11735,11656,11645,11638,11629,11618,11611,11602,11591,11584,11581,11558,11544,11543,11534,11532,11529,11527,11503,11497,11493,11488,11470,11468,11457,11455,11397,11387,11372,11363,11348,11323,11318,11309,11301,11300,11292,11290,11286,11284,11256,11252,11242,11237,11233,11219,11176,11160) order by id desc;\nselect * from crm_layouts where crm_configuration_id = 126 order by id desc;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id in (300,299,298);\nselect * from stages where crm_configuration_id = 126 order by id desc;\nselect * from business_processes where crm_configuration_id = 126 order by id desc;\nselect * from business_process_stages where business_process_id IN (76,75,74,73);\nselect * from playbooks where team_id = 142;\nselect * from playbook_layouts where playbook_id IN (108);\nSELECT * FROM playbook_categories WHERE playbook_id IN (108);\n\nselect * from teams where id = 130;\nSELECT * FROM social_accounts WHERE sociable_id = 2291;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 2\nand sa.provider = 'hubspot';\n\nSELECT * FROM activities\n WHERE crm_configuration_id = 110;\n\nselect * from teams;\nselect * from crm_configurations;\n\nSELECT * FROM activities WHERE id = 628773;\nSELECT * FROM crm_profiles WHERE user_id = 1460;\nSELECT * FROM social_accounts WHERE sociable_id = 2291;\n\nselect * from teams;\nselect ru.*, pr.*, p.* from users u join role_user ru on ru.user_id = u.id\njoin permission_role pr on pr.role_id = ru.role_id\n join permissions p on p.id = pr.permission_id\nwhere team_id = 495 and p.name IN ('dial');\n\nselect * from teams where id = 145;\nselect * from crm_configurations where id = 129;\nselect * from social_accounts where sociable_id = 2317;\nSELECT * FROM activities WHERE uuid_to_bin('8dbab184-a333-4268-ad57-fb41f8d53a9a') = uuid;\n\nselect * from teams where id = 1;\nSELECT * FROM crm_layouts WHERE crm_configuration_id = 39;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 280;\nSELECT * FROM crm_layout_entities WHERE id = 5507;\nSELECT * FROM crm_fields WHERE crm_configuration_id = 39 and object_type IN ('event');\n\nselect * from teams;\nselect * from activities where crm_configuration_id = 14;\n\nSELECT * FROM social_accounts where provider = 'copper';\n\nselect * from activities where id = 628467;\nselect * from participants where activity_id = 628467;\n\nSELECT * FROM contacts WHERE id = 3969;\nSELECT * FROM accounts WHERE id = 177;\n\nSELECT * FROM activities WHERE uuid_to_bin('4eb54c77-cfa3-2bd4-84a7-9ed46a21c988') = uuid;\n\n# ********************* BH\nselect * from teams where id = 36;\nSELECT * FROM crm_configurations WHERE id = 21;\nselect * from activities where crm_configuration_id = 21 and id = 607901;\nselect * from activities where crm_configuration_id = 21;\n\nselect * roles;\nselect * from permissions;\nselect * from permission_role where permission_id = 226;\n\nselect * from migrations order by id desc;\n\n# mercury\n# neptune\n# earth\n\nselect * from teams;\nselect * from teams where id = 19;\nselect * from teams where id = 27;\nselect * from users where team_id = 27;\nSELECT * FROM crm_configurations WHERE id = 42;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 19\nand sa.provider = 'pipedrive';\n\nselect * from activities where id = 631461;\nSELECT * FROM crm_field_values WHERE crm_field_id = 180;\n\nselect * from teams where id = 2;\nSELECT * FROM social_accounts WHERE sociable_id = 89;\n\nSELECT * FROM activities WHERE uuid_to_bin('ba0c029a-bc14-4e17-8603-64174acebcbb') = uuid; # 634273\nselect * from activity_summary_logs where activity_id = 634273;\n\nselect * from sidekick_settings where team_id = 2;\n\nselect * from teams; # 2, 2\nSELECT * FROM crm_configurations WHERE team_id = 2; # 2\nselect * from team_features where team_id = 2;\nselect * from features;\nSELECT * FROM opportunities WHERE crm_configuration_id = 2 and crm_provider_id = '51317301383';\nSELECT * FROM opportunities WHERE crm_configuration_id = 2 order by id desc;\n\nselect * from automated_reports order by id desc;\nselect * from automated_report_results order by id desc;\nselect * from users where team_id = 1 and id IN (7160, 3248);\nselect * from migrations order by id desc;\n\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 1 and sa.provider = 'salesforce';\n\nselect * from teams where id = 1;\nselect * from groups g JOIN playbooks p on g.playbook_id = p.id where g.team_id = 1;\nselect * from groups where id = 565;\nselect * from playbooks where team_id = 1;\nselect * from playbooks where id = 175;\nselect * from playbook_categories where playbook_id = 175;\nselect * from users where team_id = 1;\nselect * from users where id = 7160;\nselect * from crm_profiles where user_id = 7160;\nselect * from features;\nselect\n *\n# id, uuid, type, provider, playbook_category_id, user_id, lead_id, contact_id, account_id, opportunity_id, stage_id,\n# crm_configuration_id, crm_provider_id, transcription_id, status\nfrom activities where crm_configuration_id = 1 and type = 'conference'\n# and crm_provider_id IS NOT NULL\nand provider != 'uploader' and actual_start_time IS NOT NULL\nORDER by id desc;\nselect * from activities where id = 54747783; # 00UO400000pCzojMAC\n\nselect p.id, p.activity_type, pc.id, pc.name\nFROM playbooks p\njoin playbook_categories pc on p.id = pc.playbook_id\nwhere p.team_id = 1 and p.activity_type = 'event';\n\nSELECT * FROM crm_fields WHERE crm_configuration_id = 1 and object_type = 'event';\nSELECT * FROM crm_field_values WHERE crm_field_id = 4;\n\nselect * from crm_layouts cl join playbook_layouts pl on cl.id = pl.layout_id\nwhere crm_configuration_id = 1 and pl.playbook_id = 175;\n\nselect * from teams;\nSELECT r.* FROM automated_reports r\njoin teams t on r.team_id = t.id\nWHERE r.frequency = 'daily'\n and r.status = 1\nAND t.status = 'active'\nAND (r.expires_at >= now() OR r.expires_at IS NULL);\n\nselect * from automated_report_results where report_id IN (18, 33);\n\nselect * from activity_searches where id = 10932;\nselect * from activity_search_filters where activity_search_id = 10932;\nselect * from automated_reports;\nselect * from automated_report_results where report_id IN (34, 35);","role_description":"text entry area","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.088194445,"height":0.027777778},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"102","depth":4,"role_description":"text"},{"role":"AXStaticText","text":"3","depth":4,"role_description":"text"},{"role":"AXStaticText","text":"34","depth":4,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Services\\Kiosk\\AutomatedReports;\n\nuse Carbon\\CarbonImmutable;\nuse Carbon\\CarbonInterface;\nuse Carbon\\Exceptions\\InvalidFormatException;\nuse DateTime;\nuse DateTimeInterface;\nuse DateTimeZone;\nuse Illuminate\\Contracts\\Bus\\Dispatcher as BusDispatcher;\nuse Illuminate\\Database\\Eloquent\\Builder;\nuse Illuminate\\Support\\Carbon;\nuse Illuminate\\Support\\Collection;\nuse Illuminate\\Support\\Facades\\Log;\nuse Illuminate\\Support\\Facades\\Storage;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinition\\InputTypeEnum;\nuse Jiminny\\Component\\AskAnything\\AskAnythingPromptService;\nuse Jiminny\\Component\\AskAnything\\Dtos\\AskAnythingPromptDto;\nuse Jiminny\\Component\\UrlGenerator\\Webhook;\nuse Jiminny\\Contracts\\Repositories\\PlaybookCategoryRepository;\nuse Jiminny\\Contracts\\Repositories\\TeamRepository;\nuse Jiminny\\Contracts\\Repositories\\UserRepository;\nuse Jiminny\\Exceptions\\ApplicationException;\nuse Jiminny\\Exceptions\\InvalidArgumentException;\nuse Jiminny\\Exceptions\\ModelNotFoundException;\nuse Jiminny\\Jobs\\AutomatedReports\\RequestGenerateReportJob;\nuse Jiminny\\Models\\Activity\\Search;\nuse Jiminny\\Models\\AskAnything\\AskAnythingPrompt;\nuse Jiminny\\Models\\AskAnything\\AskAnythingPromptTarget;\nuse Jiminny\\Models\\AutomatedReport;\nuse Jiminny\\Models\\AutomatedReportResult;\nuse Jiminny\\Models\\Contracts\\UserContract;\nuse Jiminny\\Models\\Feature\\FeatureEnum;\nuse Jiminny\\Models\\Team;\nuse Jiminny\\Models\\User;\nuse Jiminny\\Repositories\\AskAnythingRepository;\nuse Jiminny\\Repositories\\AutomatedReportsRepository;\nuse Jiminny\\Repositories\\GroupRepository;\nuse Jiminny\\Repositories\\SearchRepository;\nuse Jiminny\\Repositories\\StageRepository;\nuse Throwable;\n\nclass AutomatedReportsService\n{\n public const string TYPE_LOSS_ANALYSIS = 'loss_analysis';\n public const string TYPE_ASK_JIMINNY = 'ask_jiminny';\n\n /**\n * Standard report types (used by kiosk for existing automated reports).\n */\n // @TODO this will add filter, however if we need to control feature by FF we need conditional logic\n public const array TYPES = [\n ['id' => 'exec_summary', 'name' => 'Exec Summary'],\n ['id' => 'coaching_profiles', 'name' => 'Coaching Profiles'],\n ['id' => 'product_feedback', 'name' => 'Product Feedback'],\n ['id' => self::TYPE_LOSS_ANALYSIS, 'name' => 'Loss Analysis'],\n// ['id' => 'questions', 'name' => 'Questions'],\n// ['id' => 'statistical_quant', 'name' => 'Statistical Quantitative'],\n ];\n\n public const array ALL_TYPES = [\n ...self::TYPES,\n ['id' => self::TYPE_ASK_JIMINNY, 'name' => 'Ask Jiminny'],\n ];\n\n public const string FREQUENCY_DAILY = 'daily';\n public const string FREQUENCY_WEEKLY = 'weekly';\n public const string FREQUENCY_MONTHLY = 'monthly';\n public const string FREQUENCY_QUARTERLY = 'quarterly';\n public const string FREQUENCY_ONE_OFF = 'one_off';\n\n /**\n * Frequencies for standard (non-Ask Jiminny) reports.\n */\n public const array FREQUENCIES = [\n ['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],\n ['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],\n ['id' => self::FREQUENCY_QUARTERLY, 'name' => 'Quarterly'],\n ['id' => self::FREQUENCY_ONE_OFF, 'name' => 'One-off'],\n ];\n\n /**\n * Frequencies for Ask Jiminny reports.\n */\n public const array ASK_JIMINNY_FREQUENCIES = [\n ['id' => self::FREQUENCY_DAILY, 'name' => 'Daily'],\n ['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],\n ['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],\n ];\n\n public const string MEDIA_TYPE_PDF = 'pdf';\n public const string MEDIA_TYPE_PODCAST = 'podcast';\n public const array MEDIA_TYPES = [self::MEDIA_TYPE_PDF, self::MEDIA_TYPE_PODCAST];\n public const array MEDIA_TYPE_OBJECT_PDF = ['id' => self::MEDIA_TYPE_PDF, 'name' => 'PDF'];\n public const array MEDIA_TYPE_OBJECT_PODCAST = ['id' => self::MEDIA_TYPE_PODCAST, 'name' => 'Podcast'];\n public const array MEDIA_TYPE_OBJECTS = [self::MEDIA_TYPE_OBJECT_PDF, self::MEDIA_TYPE_OBJECT_PODCAST];\n\n public const array CALL_TYPE_CONFERENCE = ['id' => 'conference', 'name' => 'Conference'];\n public const array CALL_TYPE_DIALER = ['id' => 'dialer', 'name' => 'Dialer'];\n public const int SENT_REPORT_AT_HOURS = 5;\n public const string PDF_KEY = 'pdf';\n public const string AUDIO_KEY = 'audio';\n\n private const array ALL_FREQUENCIES = [\n ['id' => self::FREQUENCY_DAILY, 'name' => 'Daily'],\n ['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],\n ['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],\n ['id' => self::FREQUENCY_QUARTERLY, 'name' => 'Quarterly'],\n ['id' => self::FREQUENCY_ONE_OFF, 'name' => 'One-off'],\n ];\n private const string S3_DIR = 'reports';\n private const array FILE_EXTENSIONS_VARIANTS = ['html', 'MD', 'pdf'];\n private const array FILE_PODCAST_EXTENSIONS_VARIANTS = ['json', 'mp3', 'ssml'];\n\n public function __construct(\n private readonly TeamRepository $teamRepository,\n private readonly GroupRepository $groupRepository,\n private readonly UserRepository $userRepository,\n private readonly StageRepository $stageRepository,\n private readonly DealStagesService $dealStagesService,\n private readonly RecipientsService $recipientsService,\n private readonly AutomatedReportsRepository $automatedReportsRepository,\n private readonly Webhook $webhookService,\n private readonly BusDispatcher $dispatcher,\n private readonly ActivityTypeService $activityTypeService,\n private readonly PlaybookCategoryRepository $playbookCategoryRepository,\n private readonly AskAnythingPromptService $askAnythingPromptService,\n private readonly SearchRepository $activitySearchRepository,\n private readonly AskAnythingRepository $askAnythingRepository,\n ) {\n }\n\n public static function getTypes(): array\n {\n $types = self::TYPES;\n\n return array_map(static function ($type) {\n return $type['id'];\n }, $types);\n }\n\n public static function getCallTypes(): array\n {\n return array_map(static function ($callType) {\n return $callType['id'];\n }, [self::CALL_TYPE_CONFERENCE, self::CALL_TYPE_DIALER]);\n }\n\n public static function getFrequencies(): array\n {\n return array_map(static function ($frequency) {\n return $frequency['id'];\n }, self::FREQUENCIES);\n }\n\n // front-facing structure\n public function getReportEnabledFieldData(bool $value = false): array\n {\n return [\n 'id' => 'report_enabled',\n 'label' => '',\n 'inputType' => InputTypeEnum::TOGGLE,\n 'value' => $value,\n ];\n }\n\n // Organizations = Teams\n public function getOrganizationFieldData(?string $value = null, bool $shortVersion = false): array\n {\n $options = $this->getTeams();\n\n if ($shortVersion) {\n return [\n 'id' => 'organization',\n 'label' => 'Organization',\n 'options' => $options,\n ];\n }\n\n return [\n 'id' => 'organization',\n 'label' => 'Organization',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => $options,\n 'value' => $value,\n 'dependencies' => [\n 'teams',\n 'deal_stage_at_call',\n 'current_deal_stage',\n 'recipients',\n ActivityTypeService::PLAYBOOK_CATEGORIES_KEY,\n ],\n 'dependsOn' => [],\n ];\n }\n\n // Teams = Groups\n public function getTeamFieldData(array $options = [], array $value = [], bool $shortVersion = false): array\n {\n if ($shortVersion) {\n return [\n 'id' => 'teams',\n 'label' => 'Team',\n 'options' => $options,\n ];\n }\n\n return [\n 'id' => 'teams',\n 'label' => 'Team',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'required' => false,\n 'placeholder' => 'Select',\n 'options' => $options,\n 'value' => $value, // value should be an array of objects {id, name}\n 'dependencies' => [ActivityTypeService::PLAYBOOK_CATEGORIES_KEY],\n 'dependsOn' => [],\n ];\n }\n\n public function getReportTypeFieldData(?string $value = null, bool $shortVersion = false, ?Team $team = null): array\n {\n $types = [];\n if ($team instanceof Team) {\n if ($team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {\n $types = self::TYPES;\n }\n if ($team->hasFeature(FeatureEnum::ASK_JIMINNY_REPORTS)) {\n $types[] = ['id' => self::TYPE_ASK_JIMINNY, 'name' => 'Ask Jiminny'];\n }\n } else {\n $types = self::TYPES;\n }\n\n if ($shortVersion) {\n return [\n 'id' => 'report_type',\n 'label' => 'Report Type',\n 'options' => $types,\n ];\n }\n\n return [\n 'id' => 'report_type',\n 'label' => 'Report Type',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => $types,\n 'value' => $value,\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getFrequencyFieldData(?string $value = null): array\n {\n return [\n 'id' => 'frequency',\n 'label' => 'Frequency',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => self::FREQUENCIES,\n 'value' => $value,\n 'dependencies' => ['period'],\n 'dependsOn' => [],\n ];\n }\n\n public function getPeriodFieldData(?string $valueStartDate = null, ?string $valueEndDate = null): array\n {\n return [\n 'id' => 'period',\n 'label' => 'Select one-off period',\n 'inputType' => InputTypeEnum::DATE_RANGE,\n 'required' => true,\n 'placeholder' => 'Select',\n 'value' => ['startDate' => $valueStartDate, 'endDate' => $valueEndDate],\n 'queryParams' => [\n 'startDate' => 'start_date_period',\n 'endDate' => 'end_date_period',\n ],\n 'dependencies' => [],\n 'dependsOn' => ['frequency'],\n ];\n }\n\n public function getActivityTypesFieldData(?Team $team = null, array $value = [], array $teamsFilter = []): array\n {\n return $this->activityTypeService->getActivityTypeFieldData(team: $team, value: $value, groupIds: $teamsFilter);\n }\n\n public function getDealStageAtCallFieldData(?Team $team = null, array $value = []): array\n {\n return $this->dealStagesService->getDealStageAtCallFieldData(team: $team, value: $value);\n }\n\n public function getCurrentDealStageFieldData(?Team $team = null, array $value = []): array\n {\n return $this->dealStagesService->getCurrentDealStageFieldData(team: $team, value: $value);\n }\n\n public function getDealValueFieldData(?int $valueMin = null, ?int $valueMax = null): array\n {\n return [\n 'id' => 'deal_value',\n 'label' => 'Deal Value',\n 'inputType' => InputTypeEnum::INTEGER_RANGE,\n 'required' => false,\n 'value' => ['min' => $valueMin, 'max' => $valueMax],\n 'queryParams' => [\n 'min' => 'min_deal_value',\n 'max' => 'max_deal_value',\n ],\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getCallTypeFieldData(bool $conferenceOn = false, bool $dialerOn = false): array\n {\n $value = [];\n $conferenceOn && $value[] = self::CALL_TYPE_CONFERENCE;\n $dialerOn && $value[] = self::CALL_TYPE_DIALER;\n\n return [\n 'id' => 'call_type',\n 'label' => 'Call Type',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'required' => true,\n 'options' => [\n self::CALL_TYPE_CONFERENCE,\n self::CALL_TYPE_DIALER,\n ],\n 'value' => $value,\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getMediaTypeFieldData(?AutomatedReport $report = null): array\n {\n $value = [];\n\n if ($report) {\n $value = $this->transformMediaTypes($report);\n }\n\n return [\n 'id' => 'media_types',\n 'label' => 'Export as',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'required' => true,\n 'options' => self::MEDIA_TYPE_OBJECTS,\n 'value' => $value,\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getCallDurationFieldData(?int $valueMin = null, ?int $valueMax = null): array\n {\n return [\n 'id' => 'call_duration',\n 'label' => 'Call Duration',\n 'inputType' => InputTypeEnum::INTEGER_RANGE,\n 'required' => false,\n 'value' => ['min' => $valueMin, 'max' => $valueMax],\n 'queryParams' => [\n 'min' => 'min_call_duration',\n 'max' => 'max_call_duration',\n ],\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getRecipientsFieldData(?Team $team = null, array $value = []): array\n {\n return $this->recipientsService->getRecipientsFieldData(team: $team, value: $value);\n }\n\n public function getJiminnyRecipientsFieldData(array $value = []): array\n {\n return $this->recipientsService->getJiminnyRecipientsFieldData($value);\n }\n\n public function getAdditionalPromptInputFieldData(?string $value = null): array\n {\n return [\n 'id' => 'additional_prompt_input',\n 'label' => 'Special requirements',\n 'inputType' => InputTypeEnum::TEXTAREA,\n 'required' => false,\n 'placeholder' => 'What should be the focus of the report?',\n 'value' => $value,\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getCustomReportNameFieldData(?string $value = null): array\n {\n return [\n 'id' => 'custom_name',\n 'label' => 'Custom report name',\n 'inputType' => InputTypeEnum::TEXT,\n 'required' => false,\n 'placeholder' => 'Enter custom name',\n 'value' => $value,\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n // data providers\n public function getTeams(): array\n {\n $teams = $this->teamRepository->getTeamsForKiosk(status: Team::STATUS_ACTIVE);\n\n $teamData = [];\n foreach ($teams as $team) {\n if (! $team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {\n continue;\n }\n\n $teamData[] = $this->transformTeam($team);\n }\n\n return $teamData;\n }\n\n public function getTeamGroups(string $teamUuid): array\n {\n $data = [];\n $team = $this->getTeam($teamUuid);\n\n if ($team !== null) {\n $groups = $team->groups()->get();\n\n foreach ($groups as $group) {\n $data[] = [\n 'id' => $group->getUuid(),\n 'name' => $group->getName(),\n ];\n }\n }\n\n return $data;\n }\n\n public function getTeamsGroupsOptions(array $filterTeamUuids = []): array\n {\n $data = [];\n $teams = $this->getTeams();\n\n foreach ($teams as $team) {\n if (! empty($filterTeamUuids) && ! in_array($team['id'], $filterTeamUuids, true)) {\n continue;\n }\n\n $data[] = [\n 'label' => $team['name'],\n 'groups' => $this->getTeamGroups($team['id']),\n ];\n }\n\n return $data;\n }\n\n public function getTeam(string $teamUuid): ?Team\n {\n return $this->teamRepository->idOrUuid($teamUuid);\n }\n\n public function getTeamById(int $teamId): ?Team\n {\n return $this->teamRepository->find($teamId);\n }\n\n public function getGroupsUuids(AutomatedReport $report): array\n {\n $uuids = [];\n $reportGroups = $report->getGroups();\n foreach ($reportGroups as $groupId) {\n if ($group = $this->groupRepository->find($groupId)) {\n $uuids[] = $group->getUuid();\n }\n }\n\n return $uuids;\n }\n\n public function getPlaybookCategoriesUuids(AutomatedReport $report): array\n {\n $uuids = [];\n $playbookCategories = $report->getPlaybookCategories();\n foreach ($playbookCategories as $id) {\n if ($category = $this->playbookCategoryRepository->find($id)) {\n $uuids[] = $category->getUuid();\n }\n }\n\n return $uuids;\n }\n\n public function getDealAtCallStagesUuids(AutomatedReport $report): array\n {\n $uuids = [];\n $reportStages = $report->getDealAtCallStages();\n foreach ($reportStages as $id) {\n if ($stage = $this->stageRepository->find($id)) {\n $uuids[] = $stage->getUuid();\n }\n }\n\n return $uuids;\n }\n\n public function getCurrentDealStagesUuids(AutomatedReport $report): array\n {\n $uuids = [];\n $reportStages = $report->getCurrentDealStages();\n foreach ($reportStages as $id) {\n if ($stage = $this->stageRepository->find($id)) {\n $uuids[] = $stage->getUuid();\n }\n }\n\n return $uuids;\n }\n\n public function getUsersUuids(AutomatedReport $report): array\n {\n return $this->extractUserUuids($report->getRecipients());\n }\n\n public function getJiminnyUsersUuids(AutomatedReport $report): array\n {\n return $this->extractUserUuids($report->getJiminnyRecipients());\n }\n\n /**\n * @param array<string, mixed> $recipients\n */\n private function extractUserUuids(array $recipients): array\n {\n $userIds = $recipients['users'] ?? [];\n\n return collect($userIds)\n ->map(fn ($id) => $this->userRepository->find((int) $id))\n ->filter()\n ->map(fn (UserContract $user) => $user->getUuid())\n ->values()\n ->all();\n }\n\n // get mail data\n public function getRecipientUsers(AutomatedReport $report): array\n {\n return $this->buildRecipientUsers($report->getRecipients());\n }\n\n private function getJiminnyRecipientUsers(AutomatedReport $report): array\n {\n return $this->buildRecipientUsers($report->getJiminnyRecipients());\n }\n\n /**\n * @param array<string, mixed> $recipients\n */\n private function buildRecipientUsers(array $recipients): array\n {\n $userIds = $recipients['users'] ?? [];\n\n return collect($userIds)\n ->map(fn ($id) => $this->userRepository->find((int) $id))\n ->filter()\n ->map(fn (UserContract $user) => [\n 'email' => $user->getEmailAddress(),\n 'name' => $user->getName(),\n 'timezone' => $user->getTimezone()->getName(),\n ])\n ->values()\n ->all();\n }\n\n public function getValidRecipientUsers(AutomatedReport $report, bool $includeJiminny = false): array\n {\n if ($report->isAskJiminnyReport()) {\n $recipients = $this->resolveAskJiminnyRecipients($report);\n } else {\n $recipients = $this->getRecipientUsers($report);\n if ($includeJiminny) {\n $recipients = array_merge($recipients, $this->getJiminnyRecipientUsers($report));\n }\n }\n\n $emails = [];\n\n return array_values(array_filter(\n $recipients,\n static function ($recipient) use (&$emails) {\n if (empty($recipient['email']) || in_array($recipient['email'], $emails, true)) {\n return false;\n }\n $emails[] = $recipient['email'];\n\n return true;\n }\n ));\n }\n\n private function resolveAskJiminnyRecipients(AutomatedReport $report): array\n {\n $recipients = [];\n\n $creator = $report->getCreator();\n if ($creator !== null) {\n $recipients[] = [\n 'email' => $creator->getEmailAddress(),\n 'name' => $creator->getName(),\n 'timezone' => $creator->getTimezone()->getName(),\n ];\n }\n\n return array_merge(\n $recipients,\n $this->buildRecipientUsers($report->getRecipients()),\n $this->getGroupRecipientUsers($report),\n );\n }\n\n private function getGroupRecipientUsers(AutomatedReport $report): array\n {\n $users = [];\n foreach ($report->getGroups() as $groupId) {\n $group = $this->groupRepository->find($groupId);\n if ($group === null) {\n continue;\n }\n foreach ($group->getMembers() as $member) {\n $users[] = [\n 'email' => $member->getEmailAddress(),\n 'name' => $member->getName(),\n 'timezone' => $member->getTimezone()->getName(),\n ];\n }\n }\n\n return $users;\n }\n\n public function getReportTypeName(AutomatedReportResult $report): string\n {\n $type = $report->getReport()->getType();\n\n $getType = $this->transformReportType($type);\n\n return $getType['name'];\n }\n\n public function getReportPeriodName(AutomatedReportResult $report): string\n {\n $from = $report->getFromDate();\n $to = $report->getToDate();\n $frequency = $report->getReport()->getFrequency();\n\n if ($from === null || $to === null) {\n if (! $report->getReport()->isAskJiminnyReport()) {\n $invalidPeriod = $from === null ? 'from' : 'to';\n\n throw new ApplicationException('Report period is invalid: ' . $invalidPeriod);\n }\n\n $period = $this->calculateFromAndToDatePeriod($frequency);\n $from = $period['fromDate'];\n $to = $period['toDate'];\n }\n\n return $this->formatReportPeriodName($frequency, $from, $to);\n }\n\n private function formatReportPeriodName(string $frequency, Carbon $from, Carbon $to): string\n {\n $fromYear = $from->format('Y');\n $toYear = $to->format('Y');\n $differentYears = $fromYear !== $toYear;\n\n switch ($frequency) {\n case self::FREQUENCY_DAILY:\n return $from->format('j M Y');\n\n case self::FREQUENCY_QUARTERLY:\n // 'Jan-Mar 2025' or 'Nov 2024-Jan 2025' if years differ\n $startMonth = $from->format('M');\n $endMonth = $to->copy()->subMonth();\n $endMonthName = $endMonth->format('M');\n $endMonthYear = $endMonth->format('Y');\n\n if ($differentYears) {\n return \"{$startMonth} {$fromYear} - {$endMonthName} {$endMonthYear}\";\n }\n\n return \"{$startMonth} - {$endMonthName} {$toYear}\";\n\n case self::FREQUENCY_MONTHLY:\n // 'May 2025' - monthly reports are always within the same year\n return $from->format('M Y');\n\n case self::FREQUENCY_WEEKLY:\n // '4 - 8 Aug 2025', '27 Oct - 3 Nov 2025', or '28 Dec 2024 - 3 Jan 2025' if years differ\n $startDay = $from->format('j');\n $endDay = $to->format('j');\n $startMonth = $from->format('M');\n $endMonth = $to->format('M');\n\n if ($differentYears) {\n return \"{$startDay} {$startMonth} {$fromYear} - {$endDay} {$endMonth} {$toYear}\";\n }\n\n if ($startMonth !== $endMonth) {\n return \"{$startDay} {$startMonth} - {$endDay} {$endMonth} {$toYear}\";\n }\n\n return \"{$startDay} - {$endDay} {$endMonth} {$toYear}\";\n\n case self::FREQUENCY_ONE_OFF:\n // '2 May-31 May 2025' or '15 Dec 2024-15 Jan 2025' if years differ\n $startDay = $from->format('j');\n $startMonth = $from->format('M');\n $endDay = $to->format('j');\n $endMonth = $to->format('M');\n\n // If same month and year, use a format like '2-31 May 2025'\n if ($startMonth === $endMonth && ! $differentYears) {\n return \"{$startDay} - {$endDay} {$startMonth} {$toYear}\";\n }\n\n // If different years, include both years\n if ($differentYears) {\n return \"{$startDay} {$startMonth} {$fromYear} - {$endDay} {$endMonth} {$toYear}\";\n }\n\n // Same year but different months\n return \"{$startDay} {$startMonth} - {$endDay} {$endMonth} {$toYear}\";\n\n default:\n // Default format for unknown frequencies\n return $from->format('j M Y') . ' - ' . $to->format('j M Y');\n }\n }\n\n public function getReportTeamsName(AutomatedReportResult $report): string\n {\n $groups = $report->getGroups();\n\n if (empty($groups)) {\n return 'All';\n }\n\n // Get group names from repository\n $groupNames = [];\n foreach ($groups as $groupId) {\n $group = $this->groupRepository->find($groupId);\n if ($group) {\n $groupNames[] = $group->getName();\n }\n }\n\n if (count($groupNames) === 1) {\n // Single team format\n $teamsName = $groupNames[0];\n } else {\n // Multiple teams format\n $teamsName = implode(', ', $groupNames);\n }\n\n return $teamsName;\n }\n\n public function getReportFileName(AutomatedReportResult $report): string\n {\n $customName = $report->getReport()->getCustomName();\n $periodName = $this->getReportPeriodName($report);\n $filenameSuffix = $this->getFilenameSuffix($report);\n\n if ($customName) {\n if ($filenameSuffix) {\n $customName .= \" {$filenameSuffix}\";\n }\n\n return $this->sanitizeFileName(\"{$customName} - {$periodName}\");\n }\n\n $baseName = $this->getReportTypeName($report);\n\n if ($filenameSuffix) {\n $baseName .= \" {$filenameSuffix}\";\n }\n\n return $this->sanitizeFileName(\"{$baseName} - {$periodName} - {$this->getReportTeamsName($report)}\");\n }\n\n public function getReportFileNameWithExtension(AutomatedReportResult $result): string\n {\n $extension = $this->getMediaTypeMetadata($result)['extension'];\n\n return $this->getReportFileName($result) . '.' . $extension;\n }\n\n public function sanitizeFileName(string $fileName): string\n {\n return str_replace(['/', '\\\\'], '-', $fileName);\n }\n\n public function isUserRecipientOfReport(User $user, AutomatedReport $report): bool\n {\n $recipients = array_map('intval', $report->getRecipients()['users'] ?? []);\n\n return in_array($user->getId(), $recipients);\n }\n\n public function transformReportResults(Collection $automatedReportResults): array\n {\n $data = [];\n foreach ($automatedReportResults as $automatedReportResult) {\n /** @var AutomatedReportResult $automatedReportResult */\n\n $report = $automatedReportResult->getReport();\n\n $createdBy = $report->getCreator();\n $creator = [\n 'id' => $createdBy?->getUuid(),\n 'name' => $createdBy?->getName(),\n 'email' => $createdBy?->getEmailAddress(),\n 'photoUrl' => $createdBy?->getPhotoUrl(),\n ];\n\n $data[] = [\n 'id' => $automatedReportResult->getUuid(),\n 'name' => $automatedReportResult->getName(),\n 'frequency' => $this->transformFrequency($report->getFrequency()),\n 'recipients' => [\n ...array_values($this->transformGroups(team: $report->getTeam(), groupsIds: $report->getGroups())),\n ...array_values($this->transformRecipients($report->getRecipients())),\n ],\n 'report_type' => $this->transformReportType($report->getType()),\n 'media_type' => $automatedReportResult->getMediaType(),\n 'downloadUrl' => $this->generateReportResultDownloadUrl($automatedReportResult),\n 'viewUrl' => $this->generateReportResultViewUrl($automatedReportResult),\n 'generated_at' => $automatedReportResult->getGeneratedAt()?->toIso8601String(),\n 'creator' => $creator,\n ];\n }\n\n return $data;\n }\n\n public function hasCallTypeConference(AutomatedReport $report): bool\n {\n return in_array(self::CALL_TYPE_CONFERENCE['id'], $report->getCallTypes(), true);\n }\n\n public function hasCallTypeDialer(AutomatedReport $report): bool\n {\n return in_array(self::CALL_TYPE_DIALER['id'], $report->getCallTypes(), true);\n }\n\n // transformers\n private function transformTeam(Team $team): array\n {\n if (! $team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {\n return [];\n }\n\n return [\n 'id' => $team->getUuid(),\n 'name' => $team->getName(),\n ];\n }\n\n private function transformReportFullView(AutomatedReport $report): array\n {\n $base = $this->transformReportBase($report);\n\n return $report->getType() === self::TYPE_ASK_JIMINNY\n ? $base + $this->transformAskJiminnyFields($report)\n : $base + $this->transformStandardReportFields($report);\n }\n\n private function transformReportBase(AutomatedReport $report): array\n {\n return [\n 'id' => $report->getUuid(),\n 'organization' => $this->transformOrganization(team: $report->getTeam()),\n 'report_type' => $this->transformReportType($report->getType()),\n 'frequency' => $this->transformFrequency($report->getFrequency()),\n ];\n }\n\n private function transformStandardReportFields(AutomatedReport $report): array\n {\n $team = $report->getTeam();\n\n return [\n 'report_enabled' => $report->getStatus(),\n 'start_date_period' => $report->getFrom()?->format('Y-m-d H:i:s'),\n 'end_date_period' => $report->getTo()?->format('Y-m-d H:i:s'),\n 'deal_value_min' => $report->getDealValueMin(),\n 'deal_value_max' => $report->getDealValueMax(),\n 'call_types' => $this->transformCallType($report->getCallTypes()),\n 'media_types' => $this->transformMediaTypes($report),\n 'call_duration_min' => $this->transformDurationToMinutes($report->getCallDurationMin()),\n 'call_duration_max' => $this->transformDurationToMinutes($report->getCallDurationMax()),\n 'teams' => $this->transformGroups(team: $team, groupsIds: $report->getGroups()),\n 'deal_at_call_stages' => $this->transformStages(team: $team, stagesIds: $report->getDealAtCallStages()),\n 'current_deal_stages' => $this->transformStages(team: $team, stagesIds: $report->getCurrentDealStages()),\n 'recipients' => $this->transformRecipients($report->getRecipients()),\n 'created_by' => $this->transformCreator($report->getCreator()),\n 'additional_prompt_input' => $report->getAdditionalPromptInput(),\n 'custom_name' => $report->getCustomName(),\n 'created_at' => $report->getCreatedAt()->format('Y-m-d H:i:s'),\n 'updated_at' => $report->getUpdatedAt()->format('Y-m-d H:i:s'),\n 'deleted_at' => $report->getDeletedAt()?->format('Y-m-d H:i:s'),\n ];\n }\n\n private function transformAskJiminnyFields(AutomatedReport $report): array\n {\n $team = $report->getTeam();\n $creatorId = $report->getAttribute('created_by');\n $explicitUserIds = array_values(array_filter(\n $report->getRecipients()['users'] ?? [],\n static fn ($id) => $id !== $creatorId\n ));\n\n return [\n 'report_name' => $report->getCustomName(),\n 'enabled' => $report->getStatus(),\n 'share_teams' => $this->transformGroups(team: $team, groupsIds: $report->getGroups()),\n 'share_users' => $this->transformRecipients(['users' => $explicitUserIds]),\n 'saved_search' => $this->transformSafeSearch($report->getSavedSearch()),\n 'ask_jiminny_prompt' => $this->transformAskJiminnyPrompt($report->getAskAnythingPrompt()),\n 'expires_on' => $report->getExpiresAt()?->format('Y-m-d'),\n ];\n }\n\n private function transformOrganization(?Team $team): array\n {\n return [\n 'id' => $team?->getUuid(),\n 'name' => $team?->getName(),\n ];\n }\n\n private function transformReportType(string $type): array\n {\n foreach (self::ALL_TYPES as $typeItem) {\n if ($typeItem['id'] === $type) {\n return $typeItem;\n }\n }\n\n return [];\n }\n\n private function transformCallType(array $types): array\n {\n $result = [];\n $callTypes = [self::CALL_TYPE_CONFERENCE, self::CALL_TYPE_DIALER];\n\n foreach ($types as $type) {\n foreach ($callTypes as $callTypeItem) {\n if ($callTypeItem['id'] === $type) {\n $result[] = $callTypeItem;\n\n break;\n }\n }\n }\n\n return $result;\n }\n\n private function transformMediaTypes(AutomatedReport $report): array\n {\n $values = [];\n\n foreach ($report->getMediaTypes() as $mediaType) {\n if (! in_array($mediaType, self::MEDIA_TYPES, true)) {\n continue;\n }\n\n $values[] = match ($mediaType) {\n self::MEDIA_TYPE_PDF => self::MEDIA_TYPE_OBJECT_PDF,\n self::MEDIA_TYPE_PODCAST => self::MEDIA_TYPE_OBJECT_PODCAST,\n };\n }\n\n return $values;\n }\n\n private function transformFrequency(string $frequency): array\n {\n foreach (self::ALL_FREQUENCIES as $frequencyItem) {\n if ($frequencyItem['id'] === $frequency) {\n return $frequencyItem;\n }\n }\n\n return [];\n }\n\n public function transformDurationToMinutes(?int $duration): ?int\n {\n if (! $duration) {\n return null;\n }\n\n return (int) ($duration / 60);\n }\n\n private function transformGroups(?Team $team, array $groupsIds): array\n {\n if (empty($groupsIds) || ! $team) {\n return [];\n }\n\n $data = [];\n foreach ($groupsIds as $groupId) {\n $group = $team->groups()->where('id', $groupId)->first();\n\n if ($group) {\n $data[] = [\n 'id' => $group->getUuid(),\n 'name' => $group->getName(),\n 'photoUrl' => $group->getPhotoUrl(),\n ];\n }\n }\n\n return $data;\n }\n\n private function transformStages(?Team $team, array $stagesIds): array\n {\n if (empty($stagesIds) || ! $team) {\n return [];\n }\n\n $data = [];\n foreach ($stagesIds as $stageId) {\n $stage = $team->stages()->where('id', $stageId)->first();\n\n if ($stage) {\n $data[] = [\n 'id' => $stage->getUuid(),\n 'name' => $stage->getName(),\n ];\n }\n }\n\n return $data;\n }\n\n private function transformRecipients(array $recipients): array\n {\n $users = [];\n foreach ($recipients['users'] ?? [] as $userId) {\n $users[] = $this->transformUser($userId);\n }\n\n return $users;\n }\n\n private function transformCreator(?User $user): ?array\n {\n if ($user === null) {\n return null;\n }\n\n return $this->transformUser($user->getId());\n }\n\n private function transformAskJiminnyPrompt(?AskAnythingPrompt $prompt): ?array\n {\n if ($prompt === null) {\n return null;\n }\n\n return [\n 'id' => $prompt->getUuid(),\n 'name' => $prompt->getTitle(),\n ];\n }\n\n private function transformSafeSearch(?Search $search): ?array\n {\n if ($search === null) {\n return null;\n }\n\n return [\n 'id' => $search->getUuid(),\n 'name' => $search->getName(),\n ];\n }\n\n private function transformUser(int $userId): array\n {\n /* @var ?User $user */\n $user = $this->userRepository->find($userId);\n\n return [\n 'id' => $user?->getUuid(),\n 'name' => $user?->getName(),\n 'email' => $user?->getEmailAddress(),\n 'photoUrl' => $user?->getPhotoUrl(),\n ];\n }\n\n public function create(array $data): array\n {\n $validatedData = $this->validateAndTransformData($data);\n $validatedData['created_by'] = auth()->id();\n\n $automatedReport = $this->automatedReportsRepository->create($validatedData);\n\n $this->generateOneOffReport($automatedReport);\n\n return $this->transformReportFullView($automatedReport);\n }\n\n public function update(string $uuid, array $data): array\n {\n $validatedData = $this->validateAndTransformData($data);\n $report = $this->automatedReportsRepository->findByUuid($uuid);\n\n if (! $report) {\n throw new InvalidArgumentException('Report not found');\n }\n\n $oldCustomName = $report->getCustomName();\n\n $automatedReport = $this->automatedReportsRepository->update($report, $validatedData);\n\n if ($oldCustomName !== $automatedReport->getCustomName()) {\n $this->updateResultNames($automatedReport);\n }\n\n $this->generateOneOffReport($automatedReport);\n\n return $this->transformReportFullView($automatedReport);\n }\n\n /**\n * Create an Ask Jiminny report.\n */\n public function createAskJiminnyReport(array $data, User $creator): array\n {\n $validatedData = $this->validateAskJiminnyReportData($data, $creator);\n $validatedData['created_by'] = $creator->getId();\n\n $automatedReport = $this->automatedReportsRepository->create($validatedData);\n\n return $this->transformReportFullView($automatedReport);\n }\n\n /**\n * Update an Ask Jiminny report.\n */\n public function updateAskJiminnyReport(AutomatedReport $report, array $data, User $user): array\n {\n if (! $report->isAskJiminnyReport()) {\n throw new InvalidArgumentException('Report is not an Ask Jiminny report');\n }\n\n $validatedData = $this->validateAskJiminnyReportData($data, $user);\n\n $oldCustomName = $report->getCustomName();\n\n $automatedReport = $this->automatedReportsRepository->update($report, $validatedData);\n\n if ($oldCustomName !== $automatedReport->getCustomName()) {\n $this->updateResultNames($automatedReport);\n }\n\n return $this->transformReportFullView($automatedReport);\n }\n\n public function updateAskJiminnyReportStatus(AutomatedReport $report, bool $status): array\n {\n $this->automatedReportsRepository->update($report, ['status' => $status]);\n\n return $this->transformReportFullView($report->fresh());\n }\n\n /**\n * Validate and transform data for Ask Jiminny reports.\n */\n private function validateAskJiminnyReportData(array $data, User $user): array\n {\n // Validate name\n $name = trim($data['report_name'] ?? '');\n if (empty($name)) {\n throw new InvalidArgumentException('Report name is required');\n }\n if (mb_strlen($name) > 50) {\n throw new InvalidArgumentException('Report name must be 50 characters or less');\n }\n\n // Validate frequency (only daily, weekly, monthly for Ask Jiminny)\n $frequency = $data['frequency'] ?? null;\n $askJiminnyFrequencies = [self::FREQUENCY_DAILY, self::FREQUENCY_WEEKLY, self::FREQUENCY_MONTHLY];\n if (! in_array($frequency, $askJiminnyFrequencies, true)) {\n throw new InvalidArgumentException('Frequency must be daily, weekly, or monthly');\n }\n\n // Validate expiration date\n $expiresAt = $data['expires_on'] ?? null;\n if (empty($expiresAt)) {\n throw new InvalidArgumentException('Expiration date is required');\n }\n\n try {\n $expiresAtDate = Carbon::parse($expiresAt);\n } catch (InvalidFormatException $e) {\n throw new InvalidArgumentException('Expiration date format is invalid');\n }\n $maxExpiration = Carbon::now()->addYear();\n if ($expiresAtDate->gt($maxExpiration)) {\n throw new InvalidArgumentException('Expiration date cannot be more than 1 year from now');\n }\n if ($expiresAtDate->isPast()) {\n throw new InvalidArgumentException('Expiration date cannot be in the past');\n }\n\n // Validate saved search\n $activitySearchId = $data['saved_search'] ?? null;\n if (empty($activitySearchId)) {\n throw new InvalidArgumentException('Saved search is required');\n }\n $savedSearch = $this->activitySearchRepository->findByUuidAndUser($activitySearchId, $user);\n if (! $savedSearch) {\n throw new InvalidArgumentException('Saved search not found or does not belong to you');\n }\n\n // Validate saved prompt\n $askAnythingPromptId = $data['ask_jiminny_prompt'] ?? null;\n if (empty($askAnythingPromptId)) {\n throw new InvalidArgumentException('Ask Jiminny prompt is required');\n }\n $prompt = $this->askAnythingRepository->getPromptByUuid($askAnythingPromptId);\n if (! $prompt) {\n throw new InvalidArgumentException('Ask Jiminny prompt not found');\n }\n\n // Validate status\n $status = $data['enabled'] ?? false;\n\n $recipientUserIds = [$user->getId()];\n\n if (! empty($data['share_users'])) {\n $sharedUserIds = $this->validateAndGetUserIdsByTeam(\n $user->team,\n (array) $data['share_users']\n );\n $recipientUserIds = array_merge($recipientUserIds, $sharedUserIds);\n }\n\n $sharedGroupIds = [];\n if (! empty($data['share_teams'])) {\n $sharedGroupIds = $this->validateAndGetGroupIds($user->team, (array) $data['share_teams']);\n }\n\n $recipientUserIds = array_values(array_unique($recipientUserIds));\n\n return [\n 'team_id' => $user->getTeamId(),\n 'type' => self::TYPE_ASK_JIMINNY,\n 'status' => (bool) $status,\n 'frequency' => $frequency,\n 'custom_name' => $name,\n 'activity_search_id' => $savedSearch->getId(),\n 'ask_anything_prompt_id' => $prompt->getId(),\n 'expires_at' => $expiresAtDate->toDateString(),\n 'media_types' => [self::MEDIA_TYPE_PDF],\n 'call_types' => [],\n 'recipients' => ['users' => $recipientUserIds],\n 'groups' => $sharedGroupIds,\n ];\n }\n\n public static function getAskJiminnyFrequencies(): array\n {\n return array_map(static function ($frequency) {\n return $frequency['id'];\n }, self::ASK_JIMINNY_FREQUENCIES);\n }\n\n public function getAskJiminnyReportFilters(User $user): array\n {\n $savedSearches = $this->activitySearchRepository->findByUserOrderedByName($user)\n ->map(fn (Search $search) => [\n 'id' => $search->getUuid(),\n 'name' => $search->getName(),\n ])\n ->values()->all();\n\n $prompts = collect(\n $this->askAnythingPromptService->get($user, AskAnythingPromptTarget::on_demand)\n )->map(fn (AskAnythingPromptDto $prompt) => [\n 'id' => $prompt->id,\n 'name' => $prompt->title,\n ])->values()->all();\n\n return [\n [\n 'id' => 'prompt',\n 'label' => 'Prompt',\n 'options' => $prompts,\n ],\n [\n 'id' => 'saved_search',\n 'label' => 'Saved Search',\n 'options' => $savedSearches,\n ],\n ];\n }\n\n public function getAskJiminnyReportFormData(User $user, ?AutomatedReport $report = null): array\n {\n $team = $user->getTeam();\n $userTimezone = $user->getTimezone();\n\n $savedSearches = $this->activitySearchRepository->findByUserOrderedByName($user)\n ->map(fn (Search $search) => [\n 'id' => $search->getUuid(),\n 'name' => $search->getName(),\n ])\n ->values()->all();\n\n $prompts = collect(\n $this->askAnythingPromptService->get($user, AskAnythingPromptTarget::on_demand)\n )->map(fn (AskAnythingPromptDto $prompt) => [\n 'id' => $prompt->id,\n 'name' => $prompt->title,\n ])->values()->all();\n\n $teamGroups = $this->groupRepository->getAllByTeam($team)->map(fn ($group) => [\n 'id' => $group->getUuid(),\n 'name' => $group->getName(),\n ])->values()->all();\n\n $shareUsers = $this->recipientsService->getRecipientsFieldData(team: $team)['options'] ?? [];\n\n $sharedTeamsValue = [];\n $sharedUsersValue = [];\n if ($report) {\n $sharedTeamsValue = $this->transformGroups($team, $report->getGroups());\n\n $recipientUserIds = $report->getRecipients()['users'] ?? [];\n $creatorId = $report->getAttribute('created_by');\n $sharedUserIds = array_values(array_filter(\n $recipientUserIds,\n static fn ($id) => $id !== $creatorId\n ));\n $sharedUsersValue = collect($sharedUserIds)\n ->map(fn ($id) => $this->userRepository->find((int) $id))\n ->filter()\n ->map(fn (User $u) => [\n 'id' => $u->getUuid(),\n 'name' => $u->getName(),\n ])\n ->values()\n ->all();\n }\n\n return [\n 'fields' => [\n [\n 'id' => 'enabled',\n 'inputType' => InputTypeEnum::TOGGLE,\n 'label' => '',\n 'value' => $report?->getStatus() ?? false,\n ],\n [\n 'id' => 'report_name',\n 'inputType' => InputTypeEnum::TEXT,\n 'label' => 'Name',\n 'placeholder' => 'Enter name',\n 'required' => true,\n 'validation' => ['maxLength' => 50],\n 'value' => $report?->getCustomName() ?? '',\n ],\n [\n 'id' => 'frequency',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'label' => 'Frequency',\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => self::ASK_JIMINNY_FREQUENCIES,\n 'value' => $report ? $this->transformFrequency($report->getFrequency()) : null,\n ],\n [\n 'id' => 'expires_on',\n 'inputType' => InputTypeEnum::DATE,\n 'label' => 'Expires on',\n 'required' => true,\n 'placeholder' => 'Select',\n 'validation' => [\n 'minDate' => now($userTimezone)->toDateString(),\n 'maxDate' => now($userTimezone)->addYear()->toDateString(),\n ],\n 'value' => $report?->getExpiresAt()?->toDateString(),\n ],\n [\n 'id' => 'share_teams',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'label' => 'Team',\n 'required' => false,\n 'placeholder' => 'Select',\n 'options' => $teamGroups,\n 'value' => $sharedTeamsValue,\n ],\n [\n 'id' => 'share_users',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'label' => 'Team member',\n 'required' => false,\n 'placeholder' => 'Select',\n 'groupLabelKey' => 'label',\n 'groupValuesKey' => 'users',\n 'optionLabelKey' => 'name',\n 'optionValueKey' => 'id',\n 'options' => $shareUsers,\n 'value' => $sharedUsersValue,\n ],\n [\n 'id' => 'saved_search',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'label' => 'Saved search',\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => $savedSearches,\n 'value' => $report && $report->getSavedSearch() ? [\n 'id' => $report->getSavedSearch()->getUuid(),\n 'name' => $report->getSavedSearch()->getName(),\n ] : null,\n ],\n [\n 'id' => 'ask_jiminny_prompt',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'label' => 'Ask Jiminny prompt',\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => $prompts,\n 'value' => $report && $report->getAskAnythingPrompt() ? [\n 'id' => $report->getAskAnythingPrompt()->getUuid(),\n 'name' => $report->getAskAnythingPrompt()->getTitle(),\n ] : null,\n ],\n ],\n ];\n }\n\n private function updateResultNames(AutomatedReport $automatedReport): void\n {\n $results = $this->automatedReportsRepository->getResultsByReport($automatedReport);\n\n foreach ($results as $result) {\n $result->update(['name' => $this->getReportFileName($result)]);\n }\n }\n\n public function updateStatus(string $uuid, array $data): array\n {\n $automatedReport = $this->automatedReportsRepository->findByUuid($uuid);\n\n if (! $automatedReport) {\n throw new ModelNotFoundException('Report not found');\n }\n\n $status = $this->validateReportStatus($data['report_enabled'] ?? null);\n $automatedReport->update([\n 'status' => $status,\n ]);\n\n $this->generateOneOffReport($automatedReport);\n\n return $this->transformReportFullView($automatedReport);\n }\n\n private function generateOneOffReport(AutomatedReport $automatedReport): void\n {\n // the scheduler handles all the other frequency types\n if ($automatedReport->getStatus() === false || $automatedReport->getFrequency() !== self::FREQUENCY_ONE_OFF) {\n return;\n }\n\n $this->dispatcher->dispatch(new RequestGenerateReportJob($automatedReport->getUuid()));\n }\n\n public function getReport(string $uuid): AutomatedReport\n {\n $automatedReport = $this->automatedReportsRepository->findByUuid($uuid);\n\n if (! $automatedReport) {\n throw new ModelNotFoundException('Report not found');\n }\n\n return $automatedReport;\n }\n\n public function get(string $uuid): array\n {\n $automatedReport = $this->getReport($uuid);\n\n return $this->transformReportFullView($automatedReport);\n }\n\n public function list(string $sortColumn = 'created_at', string $sortDirection = 'desc'): array\n {\n $results = [];\n $collection = $this->automatedReportsRepository->getAllStandardReports($sortColumn, $sortDirection);\n\n /** @var AutomatedReport $report */\n foreach ($collection as $report) {\n $results[] = $this->transformReportFullView($report);\n }\n\n return ['data' => $results];\n }\n\n public function listAskJiminnyReports(\n User $user,\n string $sortColumn = 'created_at',\n string $sortDirection = 'desc'\n ): array {\n $results = [];\n $collection = $this->automatedReportsRepository->getAskJiminnyReportsByUser($user, $sortColumn, $sortDirection);\n\n /** @var AutomatedReport $report */\n foreach ($collection as $report) {\n $results[] = $this->transformReportFullView($report);\n }\n\n return ['data' => $results];\n }\n\n public function delete(string $uuid): void\n {\n $automatedReport = $this->automatedReportsRepository->findByUuid($uuid);\n\n if (! $automatedReport) {\n throw new ModelNotFoundException('Report not found');\n }\n\n $automatedReport->delete();\n }\n\n public function createReportResult(AutomatedReport $automatedReport, array $data = []): AutomatedReportResult\n {\n return $this->automatedReportsRepository->createResult(\n array_merge(\n [\n 'report_id' => $automatedReport->getId(),\n 'status' => AutomatedReportResult::STATUS_DEFAULT,\n ],\n $data\n )\n );\n }\n\n public function getReportResult(string $resultUuid): AutomatedReportResult\n {\n $report = $this->automatedReportsRepository->findResultByUuid($resultUuid);\n\n if (! $report) {\n throw new ModelNotFoundException('Report Result not found');\n }\n\n return $report;\n }\n\n public function findChildResult(AutomatedReportResult $result, string $type): ?AutomatedReportResult\n {\n return $this->automatedReportsRepository->findChildResult($result, $type);\n }\n\n // prophet API calls\n /**\n * @throws ApplicationException\n */\n public function getGenerateReportPayload(AutomatedReport $automatedReport, string $reportResultUuid): array\n {\n $period = $this->calculateFromAndToDate($automatedReport);\n $fromDate = $period['fromDate'];\n $toDate = $period['toDate'];\n\n return [\n 'team_id' => $automatedReport->getTeamId(),\n 'request_id' => $reportResultUuid,\n 'report_type' => $automatedReport->getType(),\n 'media_types' => $automatedReport->getMediaTypes(),\n 'from_date' => $fromDate->startOfDay()->format(DateTimeInterface::RFC3339),\n 'to_date' => $toDate->endOfDay()->format(DateTimeInterface::RFC3339),\n 'group_ids' => $automatedReport->getGroups(),\n 'call_deal_stage' => $automatedReport->getDealAtCallStages(),\n 'current_deal_stage' => $automatedReport->getCurrentDealStages(),\n 'deal_min_value' => $automatedReport->getDealValueMin(),\n 'deal_max_value' => $automatedReport->getDealValueMax(),\n 'call_types' => $automatedReport->getCallTypes(),\n 'call_duration_min_seconds' => $automatedReport->getCallDurationMin(),\n 'call_duration_max_seconds' => $automatedReport->getCallDurationMax(),\n 'special_requirements' => $automatedReport->getAdditionalPromptInput(),\n 'callback_url' => $this->getCallbackUrl(),\n 'report_period' => $this->formatReportPeriodName(\n $automatedReport->getFrequency(),\n $fromDate,\n $toDate,\n ),\n 'playbook_categories' => $automatedReport->getPlaybookCategories(),\n 'custom_name' => $automatedReport->getCustomName(),\n ];\n }\n\n // $inputPayload - FE payload structure\n public function getActivitiesCountPayload(array $inputPayload): array\n {\n // Use validateAndTransformData to validate and normalize input\n $validatedData = $this->validateAndTransformData($inputPayload);\n $period = $this->calculateFromAndToDatePeriod(\n $validatedData['frequency'],\n Carbon::parse($validatedData['from']),\n Carbon::parse($validatedData['to']),\n );\n $fromDate = $period['fromDate'];\n $toDate = $period['toDate'];\n\n // Create payload similar to getGenerateReportPayload\n return [\n 'team_id' => $validatedData['team_id'],\n 'group_ids' => $validatedData['groups'] ?? [],\n 'report_type' => $validatedData['type'],\n 'from_date' => $fromDate->format(DateTimeInterface::RFC3339),\n 'to_date' => $toDate->format(DateTimeInterface::RFC3339),\n 'call_deal_stage' => $validatedData['deal_at_call_stages'] ?? [],\n 'current_deal_stage' => $validatedData['current_deal_stages'] ?? [],\n 'deal_min_value' => $validatedData['deal_value_min'] ?? null,\n 'deal_max_value' => $validatedData['deal_value_max'] ?? null,\n 'call_types' => $validatedData['call_types'],\n 'call_duration_min_seconds' => $validatedData['call_duration_min'] ?? null,\n 'call_duration_max_seconds' => $validatedData['call_duration_max'] ?? null,\n 'special_requirements' => $validatedData['additional_prompt_input'] ?? null,\n 'playbook_categories' => $validatedData['playbook_categories'] ?? [],\n 'request_id' => null,\n 'callback_url' => null,\n ];\n }\n\n public function shouldSendReport(array $users, ?CarbonInterface $generatedAt = null): bool\n {\n if (empty($users)) {\n return false;\n }\n\n $earliestTz = collect($users)\n ->mapWithKeys(function (array $user) {\n $tz = new DateTimeZone($user['timezone']);\n $nowUtc = new DateTime('now', new DateTimeZone('UTC'));\n $offset = $tz->getOffset($nowUtc);\n\n return [$user['timezone'] => $offset];\n })\n ->sortDesc()\n ->keys()\n ->first();\n\n $now = Carbon::now($earliestTz);\n $isScheduledTime = (int) $now->format('H') === self::SENT_REPORT_AT_HOURS;\n\n if ($isScheduledTime) {\n return true;\n }\n\n return $this->hasPassedScheduledTime($generatedAt, $earliestTz);\n }\n\n public function hasPassedScheduledTime(?CarbonInterface $generatedAt, string $timezone): bool\n {\n if ($generatedAt === null) {\n return false;\n }\n\n $now = Carbon::now($timezone);\n $scheduledTime = $now->copy()->setTime(self::SENT_REPORT_AT_HOURS, 0, 0);\n\n if ($now->hour < self::SENT_REPORT_AT_HOURS) {\n $scheduledTime = $scheduledTime->subDay();\n }\n\n $scheduledTimeUtc = $scheduledTime->copy()->utc();\n $generatedAtUtc = $generatedAt->copy()->utc();\n $nowUtc = $now->copy()->utc();\n\n return $generatedAtUtc->lt($scheduledTimeUtc) && $nowUtc->gt($scheduledTimeUtc);\n }\n\n public function calculateFromAndToDatePeriod(\n string $frequency,\n ?Carbon $fromDate = null,\n ?Carbon $toDate = null\n ): array {\n if ($frequency === self::FREQUENCY_ONE_OFF) {\n return [\n 'fromDate' => $fromDate,\n 'toDate' => $toDate,\n ];\n }\n\n $now = Carbon::now();\n\n return match ($frequency) {\n self::FREQUENCY_DAILY => [\n 'fromDate' => $now->copy()->subDay()->startOfDay(),\n 'toDate' => $now->copy()->subDay()->endOfDay(),\n ],\n self::FREQUENCY_WEEKLY => [\n 'fromDate' => $now->copy()->subWeeks(1)->startOfDay(),\n 'toDate' => $now->copy()->subDay()->endOfDay(),\n ],\n self::FREQUENCY_MONTHLY => [\n 'fromDate' => $now->copy()->subMonths(1)->startOfDay(),\n 'toDate' => $now->copy()->subDay()->endOfDay(),\n ],\n self::FREQUENCY_QUARTERLY => [\n 'fromDate' => $now->copy()->subMonths(3)->startOfDay(),\n 'toDate' => $now->copy()->subDay()->endOfDay(),\n ],\n default => throw new InvalidArgumentException(\"Unsupported frequency: {$frequency}\"),\n };\n }\n\n private function calculateFromAndToDate(AutomatedReport $automatedReport): array\n {\n return $this->calculateFromAndToDatePeriod(\n $automatedReport->getFrequency(),\n $automatedReport->getFrom(),\n $automatedReport->getTo()\n );\n }\n\n public function getAskJiminnyGenerateReportPayload(\n AutomatedReport $automatedReport,\n AutomatedReportResult $reportResult,\n array $activityIds,\n ): array {\n return [\n 'user_question' => $automatedReport->getAskAnythingPrompt()?->getContent(),\n 'call_ids' => array_map('strval', $activityIds),\n 'team_id' => $automatedReport->getTeamId(),\n 'request_id' => $reportResult->getUuid(),\n 'callback_url' => $this->getCallbackUrl(),\n 'report_period' => $this->getReportPeriodName($reportResult),\n 'report_name' => $automatedReport->getCustomName(),\n ];\n }\n\n private function getCallbackUrl(): string\n {\n return $this->webhookService->route('jiminny.webhook.reports.ready');\n }\n\n /**\n * Validate and transform payload data for automated reports\n *\n * @param array $data\n *\n * @throws InvalidArgumentException\n *\n * @return array\n */\n private function validateAndTransformData(array $data): array\n {\n // Validate organization (team) and check feature\n $team = $this->validateOrganization($data['organization'] ?? null);\n\n $status = $this->validateReportStatus($data['report_enabled'] ?? null);\n $type = $this->validateReportType($data['report_type'] ?? null);\n $frequency = $this->validateFrequency($data['frequency'] ?? null);\n $additionalPromptInput = $this->validateAdditionalPromptInput(\n $data['additional_prompt_input'] ?? null\n );\n $customReportName = $this->validateCustomReportName($data['custom_name'] ?? null);\n\n // Prepare data for the database\n $reportData = [\n 'team_id' => $team->getId(),\n 'type' => $type,\n 'status' => $status,\n 'frequency' => $frequency,\n 'additional_prompt_input' => $additionalPromptInput,\n 'custom_name' => $customReportName,\n ];\n\n // Validate deal values\n $reportData = $this->validateDealValues($data, $reportData);\n\n // Validate date range\n $reportData = $this->validateDateRange($data, $reportData, $frequency);\n\n // Validate call durations\n $reportData = $this->validateCallDurations($data, $reportData);\n\n // Validate call types\n $reportData = $this->validateCallTypes($data, $reportData);\n\n // Validate media types\n $reportData = $this->validateMediaTypes($data, $reportData);\n\n // Validate groups\n if (isset($data['teams'])) {\n $reportData['groups'] = $this->validateAndGetGroupIds($team, $data['teams']);\n }\n\n // Validate deal stages\n $reportData = $this->validateDealStages($data, $reportData, $team, $type);\n\n // Validate playbook categories\n $reportData = $this->validatePlaybookCategories($data, $reportData, $team);\n\n // Validate recipients\n $reportData['recipients'] = [\n 'users' => $this->validateAndGetUserIdsByTeam($team, $data['recipients'] ?? []),\n ];\n\n if (isset($data['jiminny_recipients'])) {\n // Validate Jiminny recipients\n $reportData['jiminny_recipients'] = [\n 'users' => $this->validateAndGetJiminnyUserIds((array) $data['jiminny_recipients']),\n ];\n }\n\n return $reportData;\n }\n\n private function validateDealValues(array $data, array $reportData): array\n {\n if (isset($data['min_deal_value'])) {\n $reportData['deal_value_min'] = (int) $data['min_deal_value'];\n\n if ($reportData['deal_value_min'] > 4294967295 || $reportData['deal_value_min'] < 0) {\n throw new InvalidArgumentException('Min deal value should be between 0 and 4294967295');\n }\n }\n\n if (isset($data['max_deal_value'])) {\n $reportData['deal_value_max'] = (int) $data['max_deal_value'];\n\n if ($reportData['deal_value_max'] > 4294967295 || $reportData['deal_value_max'] < 0) {\n throw new InvalidArgumentException('Max deal value should be between 0 and 4294967295');\n }\n }\n\n if (isset($data['min_deal_value'], $data['max_deal_value'])\n && $data['min_deal_value'] > $data['max_deal_value']\n ) {\n throw new InvalidArgumentException('Min deal value cannot be greater than max deal value');\n }\n\n return $reportData;\n }\n\n private function validateDateRange(array $data, array $reportData, string $frequency): array\n {\n // Set date range only for one_off frequency\n if ($frequency === 'one_off') {\n if (isset($data['start_date_period'])) {\n $reportData['from'] = $this->parseDate($data['start_date_period']);\n }\n\n if (isset($data['end_date_period'])) {\n $reportData['to'] = $this->parseDate($data['end_date_period']);\n }\n\n if (empty($reportData['from']) || empty($reportData['to'])) {\n throw new InvalidArgumentException(\n 'Start date and end date are required for one_off frequency'\n );\n }\n } else {\n $reportData['from'] = null;\n $reportData['to'] = null;\n }\n\n return $reportData;\n }\n\n private function validateCallDurations(array $data, array $reportData): array\n {\n // Convert call durations from minutes to seconds\n if (isset($data['min_call_duration'])) {\n $reportData['call_duration_min'] = (int) $data['min_call_duration'] * 60;\n\n if ($reportData['call_duration_min'] > 4294967295 || $reportData['call_duration_min'] < 0) {\n throw new InvalidArgumentException('Min call duration should be between 0 and 4294967295');\n }\n }\n\n if (isset($data['max_call_duration'])) {\n $reportData['call_duration_max'] = (int) $data['max_call_duration'] * 60;\n\n if ($reportData['call_duration_max'] > 4294967295 || $reportData['call_duration_max'] < 0) {\n throw new InvalidArgumentException('Max call duration should be between 0 and 4294967295');\n }\n }\n\n return $reportData;\n }\n\n private function validateCallTypes(array $data, array $reportData): array\n {\n // Set call types\n $reportData['call_types'] = $data['call_type'] ?? [];\n if (empty($reportData['call_types'])) {\n $reportData['call_types'] = self::getCallTypes();\n }\n\n foreach ($reportData['call_types'] as $callType) {\n if (! in_array($callType, self::getCallTypes(), true)) {\n throw new InvalidArgumentException(sprintf('Call type %s is invalid', $callType));\n }\n }\n\n return $reportData;\n }\n\n private function validateMediaTypes(array $data, array $reportData): array\n {\n // Set media types from input data\n $reportData['media_types'] = $data['media_types'] ?? [];\n\n if (empty($reportData['media_types'])) {\n throw new InvalidArgumentException('Media types are required');\n }\n\n foreach ($reportData['media_types'] as $mediaType) {\n if (! in_array($mediaType, self::MEDIA_TYPES, true)) {\n throw new InvalidArgumentException(sprintf('Media type %s is invalid', $mediaType));\n }\n }\n\n return $reportData;\n }\n\n private function validateDealStages(array $data, array $reportData, Team $team, string $reportType): array\n {\n // Validate and set deal stages\n if (isset($data['deal_stage_at_call'])) {\n $reportData['deal_at_call_stages'] =\n $this->validateAndGetDealStageIds($team, $data['deal_stage_at_call'], 'Deal stage at call');\n }\n\n if (isset($data['current_deal_stage'])) {\n $reportData['current_deal_stages'] =\n $this->validateAndGetDealStageIds($team, $data['current_deal_stage'], 'Current deal stage');\n }\n\n // Ensure current_deal_stage is not provided for loss_analysis report type\n if ($reportType === self::TYPE_LOSS_ANALYSIS && ! empty($data['current_deal_stage'])) {\n throw new InvalidArgumentException('Current deal stage is not applicable for Loss Analysis reports');\n }\n\n return $reportData;\n }\n\n // transform uuid to id\n private function validatePlaybookCategories(array $data, array $reportData, Team $team): array\n {\n $key = 'playbook_categories';\n\n if (isset($data[$key])) {\n $payloadIds = $data[$key];\n $ids = [];\n\n foreach ($payloadIds as $uuid) {\n $uuid = (string) $uuid;\n\n try {\n $playbookCategory = $this->playbookCategoryRepository->findByUuid($uuid);\n } catch (Throwable $throwable) {\n Log::error(__METHOD__ . ' ' . $throwable->getMessage());\n\n throw new InvalidArgumentException(sprintf('Playbook category %s not found', $uuid));\n }\n\n if (! $playbookCategory) {\n throw new InvalidArgumentException(sprintf('Playbook category %s not found', $uuid));\n }\n\n if (! $playbookCategory->hasPlaybook()) {\n throw new InvalidArgumentException(sprintf('Playbook category %s has no playbook', $uuid));\n }\n\n if ($playbookCategory->getPlaybook()->getTeamId() !== $team->getId()) {\n throw new InvalidArgumentException(\n sprintf('Playbook category %s not found for team %s', $uuid, $team->getUuid())\n );\n }\n\n $ids[] = $playbookCategory->getId();\n }\n\n $reportData[$key] = $ids;\n }\n\n return $reportData;\n }\n\n private function validateReportStatus($status): bool\n {\n if (! in_array($status, [true, false], true)) {\n throw new InvalidArgumentException('Report status is invalid');\n }\n\n return $status;\n }\n\n private function validateReportType($type): string\n {\n if (! in_array($type, self::getTypes(), true)) {\n throw new InvalidArgumentException(sprintf('Report type is invalid: %s', $type));\n }\n\n return $type;\n }\n\n private function validateFrequency($frequency): string\n {\n if (! in_array($frequency, self::getFrequencies(), true)) {\n throw new InvalidArgumentException('Frequency is invalid');\n }\n\n return $frequency;\n }\n\n private function validateAdditionalPromptInput(?string $additionalPromptInput): ?string\n {\n if ($additionalPromptInput && strlen($additionalPromptInput) > 5000) {\n throw new InvalidArgumentException('Additional Prompt Input should be less than 5000 characters');\n }\n\n return $additionalPromptInput;\n }\n\n private function validateCustomReportName(?string $customReportName): ?string\n {\n if ($customReportName === null || $customReportName === '') {\n return null;\n }\n\n if (strlen($customReportName) > 70) {\n throw new InvalidArgumentException('Custom report name should be less than 70 characters');\n }\n\n return $customReportName;\n }\n\n private function validateOrganization(?string $organizationUuid): Team\n {\n if (! $organizationUuid) {\n throw new InvalidArgumentException('Organization is required');\n }\n\n $team = $this->teamRepository->idOrUuid($organizationUuid);\n\n if (! $team) {\n throw new InvalidArgumentException('Organization not found');\n }\n\n if (! $team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {\n throw new InvalidArgumentException('Organization does not have the Automated Reports feature');\n }\n\n return $team;\n }\n\n private function validateAndGetGroupIds(Team $team, array $teamUuids): array\n {\n $groupIds = [];\n\n foreach ($teamUuids as $uuid) {\n $group = $this->groupRepository->findByUuid($uuid);\n\n if ($group === null || $group->getTeamId() !== $team->getId()) {\n throw new InvalidArgumentException(\n sprintf('Group %s not found for team %s', $uuid, $team->getUuid())\n );\n }\n\n $groupIds[] = $group->getId();\n\n }\n\n return $groupIds;\n }\n\n private function validateAndGetDealStageIds(Team $team, array $stageUuids, string $propertyLabel): array\n {\n $stageIds = [];\n\n foreach ($stageUuids as $uuid) {\n $stage = $this->stageRepository->findByUuid($uuid);\n\n if ($stage === null || $stage->getTeamId() !== $team->getId()) {\n throw new InvalidArgumentException(\n sprintf('Stage %s not found for team %s for %s', $uuid, $team->getUuid(), $propertyLabel)\n );\n }\n\n $stageIds[] = $stage->getId();\n }\n\n return $stageIds;\n }\n\n private function validateAndGetUserIds(array $userUuids, callable $teamCheck): array\n {\n if (empty($userUuids)) {\n return [];\n }\n\n $userIds = [];\n\n foreach ($userUuids as $uuid) {\n $user = $this->userRepository->findByUuid($uuid);\n\n if (! $user || ! $user->isStatusActive()) {\n throw new InvalidArgumentException(\n sprintf('User %s not found or is not active', $uuid)\n );\n }\n\n if (! $teamCheck($user)) {\n throw new InvalidArgumentException(\n sprintf('User %s does not belong to the allowed team(s)', $uuid)\n );\n }\n\n $userIds[] = $user->getId();\n }\n\n return $userIds;\n }\n\n private function validateAndGetUserIdsByTeam(Team $team, array $userUuids): array\n {\n return $this->validateAndGetUserIds($userUuids, fn ($user) => $user->getTeamId() === $team->getId());\n }\n\n private function validateAndGetJiminnyUserIds(array $userUuids): array\n {\n $allowedTeamIds = config('kiosk.teamIds', []);\n\n return $this->validateAndGetUserIds($userUuids, fn ($user) => in_array($user->getTeamId(), $allowedTeamIds, true));\n }\n\n private function parseDate(string $dateString): string\n {\n return date('Y-m-d H:i:s', strtotime($dateString));\n }\n\n private function generateReportResultViewUrl(AutomatedReportResult $result): string\n {\n $mediaResource = $this->getReportMediaRouteResource($result);\n\n return route('ai-reports.' . $mediaResource . '.view', ['uuid' => $result->getUuid()]);\n }\n\n private function generateReportResultDownloadUrl(AutomatedReportResult $result): string\n {\n $mediaResource = $this->getReportMediaRouteResource($result);\n\n return route('ai-reports.' . $mediaResource . '.download', ['uuid' => $result->getUuid()]);\n }\n\n private function getReportMediaRouteResource(AutomatedReportResult $result): string\n {\n if ($result->getMediaType() === self::MEDIA_TYPE_PDF) {\n return self::PDF_KEY;\n } elseif ($result->getMediaType() === self::MEDIA_TYPE_PODCAST) {\n return self::AUDIO_KEY;\n }\n\n throw new \\InvalidArgumentException('Unknown media type.');\n }\n\n public function getMediaPath(AutomatedReportResult $result): ?string\n {\n $url = match ($result->getMediaType()) {\n self::MEDIA_TYPE_PDF => $result->getPdfUrl(),\n self::MEDIA_TYPE_PODCAST => $result->getPodcastAudioUrl(),\n default => null,\n };\n\n if ($url === null) {\n return null;\n }\n\n $path = parse_url(trim($url, '\"\\''), PHP_URL_PATH);\n\n return $path ?: null;\n }\n\n public function getFilenameSuffix(AutomatedReportResult $result): ?string\n {\n return match ($result->getMediaType()) {\n self::MEDIA_TYPE_PODCAST => 'Podcast',\n default => null,\n };\n }\n\n public function getMailSubjectSuffix(AutomatedReportResult $result): string\n {\n return match ($result->getMediaType()) {\n self::MEDIA_TYPE_PDF => 'report',\n self::MEDIA_TYPE_PODCAST => 'podcast',\n default => '',\n };\n }\n\n public function getMediaTypeMetadata(AutomatedReportResult $result): array\n {\n return match ($result->getMediaType()) {\n self::MEDIA_TYPE_PODCAST => ['extension' => 'mp3', 'mime' => 'audio/mpeg'],\n self::MEDIA_TYPE_PDF => ['extension' => 'pdf', 'mime' => 'application/pdf'],\n default => ['extension' => null, 'mime' => null],\n };\n }\n\n public function deleteS3Files(AutomatedReportResult $result): void\n {\n $teamUuid = $result->getReport()->getTeam()->getUuid();\n $reportUuid = $result->getUuid();\n\n // delete all files for a report uuid no mather of pdf, podcast, or both\n // in case of both - the podcast files are linked to the pdf (parent) uuid\n // pdf and podcast date times should be close\n $path = sprintf('%s/%s/%s', $teamUuid, self::S3_DIR, $reportUuid);\n\n foreach (self::FILE_EXTENSIONS_VARIANTS as $extension) {\n $file = $path . '.' . $extension;\n\n if (Storage::exists($file)) {\n Storage::delete($file);\n Log::info('[Reports] Deleted S3 file', [\n 'path' => $file,\n ]);\n }\n }\n\n foreach (self::FILE_PODCAST_EXTENSIONS_VARIANTS as $extension) {\n $file = $path . '_podcast.' . $extension;\n\n if (Storage::exists($file)) {\n Storage::delete($file);\n Log::info('[Reports] Deleted Podcast S3 file', [\n 'path' => $file,\n ]);\n }\n }\n }\n\n /**\n *\n * @param int|null $teamId Optional team ID to filter results\n *\n * @return Collection<int, int> Collection of team IDs\n */\n public function getTeamIdsWithReportsResults(?int $teamId = null): Collection\n {\n return $this->automatedReportsRepository->getTeamIdsWithReportsResults($teamId);\n }\n\n /**\n * Core delete logic for report results using a query\n *\n * @param Builder $query\n * @param array $logContext\n *\n * @return int\n */\n private function deleteReportResultsByQuery(Builder $query, array $logContext = []): int\n {\n $deletedCount = 0;\n\n if ($query->exists()) {\n Log::info(\n 'Run delete report results',\n array_merge(\n $logContext,\n [\n 'service' => 'AutomatedReportsService',\n ]\n )\n );\n\n $query->chunkById(50, function ($results) use (&$deletedCount, $logContext) {\n foreach ($results as $result) {\n $this->deleteReportResult($result);\n $deletedCount++;\n\n Log::info(\n 'Deleted a report result',\n array_merge(\n $logContext,\n [\n 'result_id' => $result->getId(),\n 'report_id' => $result->getReportId(),\n ]\n )\n );\n }\n });\n }\n\n return $deletedCount;\n }\n\n /**\n * Delete report results for a team by retention period\n *\n * @param Team $team\n * @param CarbonImmutable $retentionDate\n *\n * @return int Number of deleted report results\n */\n public function deleteReportsResultsInRetentionPeriod(Team $team, CarbonImmutable $retentionDate): int\n {\n $reportIds = $this->automatedReportsRepository->getReportIdsByTeam($team);\n\n if ($reportIds->isEmpty()) {\n return 0;\n }\n\n $query = $this->automatedReportsRepository\n ->getReportResultsQueryForRetention($team, $retentionDate);\n\n return $this->deleteReportResultsByQuery($query, [\n 'team_id' => $team->getId(),\n 'retention_date' => $retentionDate->toDateTimeString(),\n ]);\n }\n\n /**\n * Delete ALL report results for a specific automated report\n *\n * @param string $uuid\n *\n * @return int\n */\n public function deleteReportResults(string $uuid): int\n {\n $report = $this->getReport($uuid);\n\n $query = $this->automatedReportsRepository->getResultsByReportQuery($report);\n\n return $this->deleteReportResultsByQuery($query, [\n 'report_uuid' => $uuid,\n 'report_id' => $report->getId(),\n ]);\n }\n\n public function deleteReportResult(AutomatedReportResult $result): void\n {\n $this->deleteS3Files($result);\n\n $result->delete();\n }\n\n /**\n * Get all reports for a specific team\n *\n * @param Team $team\n *\n * @return \\Illuminate\\Database\\Eloquent\\Collection\n */\n public function getTeamReports(Team $team): \\Illuminate\\Database\\Eloquent\\Collection\n {\n return $this->automatedReportsRepository->getReportsByTeam($team);\n }\n\n /**\n * Get all report results for a specific report\n *\n * @param AutomatedReport $report\n *\n * @return \\Illuminate\\Database\\Eloquent\\Collection\n */\n public function getReportResults(AutomatedReport $report): \\Illuminate\\Database\\Eloquent\\Collection\n {\n return $this->automatedReportsRepository->getResultsByReport($report);\n }\n\n public function deleteAllReportResults(AutomatedReport $report): void\n {\n $results = $this->getReportResults($report);\n\n /** @var AutomatedReportResult $result */\n foreach ($results as $result) {\n Log::info('Deleting result', [\n 'report' => $report->getId(),\n 'result' => $result->getId(),\n ]);\n\n $this->deleteReportResult($result);\n }\n }\n\n public function deleteAllData(Team $team): void\n {\n Log::info('Deleting automated report and results for team', [\n 'team' => $team->getId(),\n ]);\n\n $reports = $this->getTeamReports($team);\n\n /** @var AutomatedReport $report */\n foreach ($reports as $report) {\n Log::info('Deleting report', [\n 'team' => $team->getId(),\n 'report' => $report->getId(),\n ]);\n\n $this->deleteAllReportResults($report);\n\n $report->delete();\n }\n }\n}","depth":4,"value":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Services\\Kiosk\\AutomatedReports;\n\nuse Carbon\\CarbonImmutable;\nuse Carbon\\CarbonInterface;\nuse Carbon\\Exceptions\\InvalidFormatException;\nuse DateTime;\nuse DateTimeInterface;\nuse DateTimeZone;\nuse Illuminate\\Contracts\\Bus\\Dispatcher as BusDispatcher;\nuse Illuminate\\Database\\Eloquent\\Builder;\nuse Illuminate\\Support\\Carbon;\nuse Illuminate\\Support\\Collection;\nuse Illuminate\\Support\\Facades\\Log;\nuse Illuminate\\Support\\Facades\\Storage;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinition\\InputTypeEnum;\nuse Jiminny\\Component\\AskAnything\\AskAnythingPromptService;\nuse Jiminny\\Component\\AskAnything\\Dtos\\AskAnythingPromptDto;\nuse Jiminny\\Component\\UrlGenerator\\Webhook;\nuse Jiminny\\Contracts\\Repositories\\PlaybookCategoryRepository;\nuse Jiminny\\Contracts\\Repositories\\TeamRepository;\nuse Jiminny\\Contracts\\Repositories\\UserRepository;\nuse Jiminny\\Exceptions\\ApplicationException;\nuse Jiminny\\Exceptions\\InvalidArgumentException;\nuse Jiminny\\Exceptions\\ModelNotFoundException;\nuse Jiminny\\Jobs\\AutomatedReports\\RequestGenerateReportJob;\nuse Jiminny\\Models\\Activity\\Search;\nuse Jiminny\\Models\\AskAnything\\AskAnythingPrompt;\nuse Jiminny\\Models\\AskAnything\\AskAnythingPromptTarget;\nuse Jiminny\\Models\\AutomatedReport;\nuse Jiminny\\Models\\AutomatedReportResult;\nuse Jiminny\\Models\\Contracts\\UserContract;\nuse Jiminny\\Models\\Feature\\FeatureEnum;\nuse Jiminny\\Models\\Team;\nuse Jiminny\\Models\\User;\nuse Jiminny\\Repositories\\AskAnythingRepository;\nuse Jiminny\\Repositories\\AutomatedReportsRepository;\nuse Jiminny\\Repositories\\GroupRepository;\nuse Jiminny\\Repositories\\SearchRepository;\nuse Jiminny\\Repositories\\StageRepository;\nuse Throwable;\n\nclass AutomatedReportsService\n{\n public const string TYPE_LOSS_ANALYSIS = 'loss_analysis';\n public const string TYPE_ASK_JIMINNY = 'ask_jiminny';\n\n /**\n * Standard report types (used by kiosk for existing automated reports).\n */\n // @TODO this will add filter, however if we need to control feature by FF we need conditional logic\n public const array TYPES = [\n ['id' => 'exec_summary', 'name' => 'Exec Summary'],\n ['id' => 'coaching_profiles', 'name' => 'Coaching Profiles'],\n ['id' => 'product_feedback', 'name' => 'Product Feedback'],\n ['id' => self::TYPE_LOSS_ANALYSIS, 'name' => 'Loss Analysis'],\n// ['id' => 'questions', 'name' => 'Questions'],\n// ['id' => 'statistical_quant', 'name' => 'Statistical Quantitative'],\n ];\n\n public const array ALL_TYPES = [\n ...self::TYPES,\n ['id' => self::TYPE_ASK_JIMINNY, 'name' => 'Ask Jiminny'],\n ];\n\n public const string FREQUENCY_DAILY = 'daily';\n public const string FREQUENCY_WEEKLY = 'weekly';\n public const string FREQUENCY_MONTHLY = 'monthly';\n public const string FREQUENCY_QUARTERLY = 'quarterly';\n public const string FREQUENCY_ONE_OFF = 'one_off';\n\n /**\n * Frequencies for standard (non-Ask Jiminny) reports.\n */\n public const array FREQUENCIES = [\n ['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],\n ['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],\n ['id' => self::FREQUENCY_QUARTERLY, 'name' => 'Quarterly'],\n ['id' => self::FREQUENCY_ONE_OFF, 'name' => 'One-off'],\n ];\n\n /**\n * Frequencies for Ask Jiminny reports.\n */\n public const array ASK_JIMINNY_FREQUENCIES = [\n ['id' => self::FREQUENCY_DAILY, 'name' => 'Daily'],\n ['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],\n ['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],\n ];\n\n public const string MEDIA_TYPE_PDF = 'pdf';\n public const string MEDIA_TYPE_PODCAST = 'podcast';\n public const array MEDIA_TYPES = [self::MEDIA_TYPE_PDF, self::MEDIA_TYPE_PODCAST];\n public const array MEDIA_TYPE_OBJECT_PDF = ['id' => self::MEDIA_TYPE_PDF, 'name' => 'PDF'];\n public const array MEDIA_TYPE_OBJECT_PODCAST = ['id' => self::MEDIA_TYPE_PODCAST, 'name' => 'Podcast'];\n public const array MEDIA_TYPE_OBJECTS = [self::MEDIA_TYPE_OBJECT_PDF, self::MEDIA_TYPE_OBJECT_PODCAST];\n\n public const array CALL_TYPE_CONFERENCE = ['id' => 'conference', 'name' => 'Conference'];\n public const array CALL_TYPE_DIALER = ['id' => 'dialer', 'name' => 'Dialer'];\n public const int SENT_REPORT_AT_HOURS = 5;\n public const string PDF_KEY = 'pdf';\n public const string AUDIO_KEY = 'audio';\n\n private const array ALL_FREQUENCIES = [\n ['id' => self::FREQUENCY_DAILY, 'name' => 'Daily'],\n ['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],\n ['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],\n ['id' => self::FREQUENCY_QUARTERLY, 'name' => 'Quarterly'],\n ['id' => self::FREQUENCY_ONE_OFF, 'name' => 'One-off'],\n ];\n private const string S3_DIR = 'reports';\n private const array FILE_EXTENSIONS_VARIANTS = ['html', 'MD', 'pdf'];\n private const array FILE_PODCAST_EXTENSIONS_VARIANTS = ['json', 'mp3', 'ssml'];\n\n public function __construct(\n private readonly TeamRepository $teamRepository,\n private readonly GroupRepository $groupRepository,\n private readonly UserRepository $userRepository,\n private readonly StageRepository $stageRepository,\n private readonly DealStagesService $dealStagesService,\n private readonly RecipientsService $recipientsService,\n private readonly AutomatedReportsRepository $automatedReportsRepository,\n private readonly Webhook $webhookService,\n private readonly BusDispatcher $dispatcher,\n private readonly ActivityTypeService $activityTypeService,\n private readonly PlaybookCategoryRepository $playbookCategoryRepository,\n private readonly AskAnythingPromptService $askAnythingPromptService,\n private readonly SearchRepository $activitySearchRepository,\n private readonly AskAnythingRepository $askAnythingRepository,\n ) {\n }\n\n public static function getTypes(): array\n {\n $types = self::TYPES;\n\n return array_map(static function ($type) {\n return $type['id'];\n }, $types);\n }\n\n public static function getCallTypes(): array\n {\n return array_map(static function ($callType) {\n return $callType['id'];\n }, [self::CALL_TYPE_CONFERENCE, self::CALL_TYPE_DIALER]);\n }\n\n public static function getFrequencies(): array\n {\n return array_map(static function ($frequency) {\n return $frequency['id'];\n }, self::FREQUENCIES);\n }\n\n // front-facing structure\n public function getReportEnabledFieldData(bool $value = false): array\n {\n return [\n 'id' => 'report_enabled',\n 'label' => '',\n 'inputType' => InputTypeEnum::TOGGLE,\n 'value' => $value,\n ];\n }\n\n // Organizations = Teams\n public function getOrganizationFieldData(?string $value = null, bool $shortVersion = false): array\n {\n $options = $this->getTeams();\n\n if ($shortVersion) {\n return [\n 'id' => 'organization',\n 'label' => 'Organization',\n 'options' => $options,\n ];\n }\n\n return [\n 'id' => 'organization',\n 'label' => 'Organization',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => $options,\n 'value' => $value,\n 'dependencies' => [\n 'teams',\n 'deal_stage_at_call',\n 'current_deal_stage',\n 'recipients',\n ActivityTypeService::PLAYBOOK_CATEGORIES_KEY,\n ],\n 'dependsOn' => [],\n ];\n }\n\n // Teams = Groups\n public function getTeamFieldData(array $options = [], array $value = [], bool $shortVersion = false): array\n {\n if ($shortVersion) {\n return [\n 'id' => 'teams',\n 'label' => 'Team',\n 'options' => $options,\n ];\n }\n\n return [\n 'id' => 'teams',\n 'label' => 'Team',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'required' => false,\n 'placeholder' => 'Select',\n 'options' => $options,\n 'value' => $value, // value should be an array of objects {id, name}\n 'dependencies' => [ActivityTypeService::PLAYBOOK_CATEGORIES_KEY],\n 'dependsOn' => [],\n ];\n }\n\n public function getReportTypeFieldData(?string $value = null, bool $shortVersion = false, ?Team $team = null): array\n {\n $types = [];\n if ($team instanceof Team) {\n if ($team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {\n $types = self::TYPES;\n }\n if ($team->hasFeature(FeatureEnum::ASK_JIMINNY_REPORTS)) {\n $types[] = ['id' => self::TYPE_ASK_JIMINNY, 'name' => 'Ask Jiminny'];\n }\n } else {\n $types = self::TYPES;\n }\n\n if ($shortVersion) {\n return [\n 'id' => 'report_type',\n 'label' => 'Report Type',\n 'options' => $types,\n ];\n }\n\n return [\n 'id' => 'report_type',\n 'label' => 'Report Type',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => $types,\n 'value' => $value,\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getFrequencyFieldData(?string $value = null): array\n {\n return [\n 'id' => 'frequency',\n 'label' => 'Frequency',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => self::FREQUENCIES,\n 'value' => $value,\n 'dependencies' => ['period'],\n 'dependsOn' => [],\n ];\n }\n\n public function getPeriodFieldData(?string $valueStartDate = null, ?string $valueEndDate = null): array\n {\n return [\n 'id' => 'period',\n 'label' => 'Select one-off period',\n 'inputType' => InputTypeEnum::DATE_RANGE,\n 'required' => true,\n 'placeholder' => 'Select',\n 'value' => ['startDate' => $valueStartDate, 'endDate' => $valueEndDate],\n 'queryParams' => [\n 'startDate' => 'start_date_period',\n 'endDate' => 'end_date_period',\n ],\n 'dependencies' => [],\n 'dependsOn' => ['frequency'],\n ];\n }\n\n public function getActivityTypesFieldData(?Team $team = null, array $value = [], array $teamsFilter = []): array\n {\n return $this->activityTypeService->getActivityTypeFieldData(team: $team, value: $value, groupIds: $teamsFilter);\n }\n\n public function getDealStageAtCallFieldData(?Team $team = null, array $value = []): array\n {\n return $this->dealStagesService->getDealStageAtCallFieldData(team: $team, value: $value);\n }\n\n public function getCurrentDealStageFieldData(?Team $team = null, array $value = []): array\n {\n return $this->dealStagesService->getCurrentDealStageFieldData(team: $team, value: $value);\n }\n\n public function getDealValueFieldData(?int $valueMin = null, ?int $valueMax = null): array\n {\n return [\n 'id' => 'deal_value',\n 'label' => 'Deal Value',\n 'inputType' => InputTypeEnum::INTEGER_RANGE,\n 'required' => false,\n 'value' => ['min' => $valueMin, 'max' => $valueMax],\n 'queryParams' => [\n 'min' => 'min_deal_value',\n 'max' => 'max_deal_value',\n ],\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getCallTypeFieldData(bool $conferenceOn = false, bool $dialerOn = false): array\n {\n $value = [];\n $conferenceOn && $value[] = self::CALL_TYPE_CONFERENCE;\n $dialerOn && $value[] = self::CALL_TYPE_DIALER;\n\n return [\n 'id' => 'call_type',\n 'label' => 'Call Type',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'required' => true,\n 'options' => [\n self::CALL_TYPE_CONFERENCE,\n self::CALL_TYPE_DIALER,\n ],\n 'value' => $value,\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getMediaTypeFieldData(?AutomatedReport $report = null): array\n {\n $value = [];\n\n if ($report) {\n $value = $this->transformMediaTypes($report);\n }\n\n return [\n 'id' => 'media_types',\n 'label' => 'Export as',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'required' => true,\n 'options' => self::MEDIA_TYPE_OBJECTS,\n 'value' => $value,\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getCallDurationFieldData(?int $valueMin = null, ?int $valueMax = null): array\n {\n return [\n 'id' => 'call_duration',\n 'label' => 'Call Duration',\n 'inputType' => InputTypeEnum::INTEGER_RANGE,\n 'required' => false,\n 'value' => ['min' => $valueMin, 'max' => $valueMax],\n 'queryParams' => [\n 'min' => 'min_call_duration',\n 'max' => 'max_call_duration',\n ],\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getRecipientsFieldData(?Team $team = null, array $value = []): array\n {\n return $this->recipientsService->getRecipientsFieldData(team: $team, value: $value);\n }\n\n public function getJiminnyRecipientsFieldData(array $value = []): array\n {\n return $this->recipientsService->getJiminnyRecipientsFieldData($value);\n }\n\n public function getAdditionalPromptInputFieldData(?string $value = null): array\n {\n return [\n 'id' => 'additional_prompt_input',\n 'label' => 'Special requirements',\n 'inputType' => InputTypeEnum::TEXTAREA,\n 'required' => false,\n 'placeholder' => 'What should be the focus of the report?',\n 'value' => $value,\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getCustomReportNameFieldData(?string $value = null): array\n {\n return [\n 'id' => 'custom_name',\n 'label' => 'Custom report name',\n 'inputType' => InputTypeEnum::TEXT,\n 'required' => false,\n 'placeholder' => 'Enter custom name',\n 'value' => $value,\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n // data providers\n public function getTeams(): array\n {\n $teams = $this->teamRepository->getTeamsForKiosk(status: Team::STATUS_ACTIVE);\n\n $teamData = [];\n foreach ($teams as $team) {\n if (! $team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {\n continue;\n }\n\n $teamData[] = $this->transformTeam($team);\n }\n\n return $teamData;\n }\n\n public function getTeamGroups(string $teamUuid): array\n {\n $data = [];\n $team = $this->getTeam($teamUuid);\n\n if ($team !== null) {\n $groups = $team->groups()->get();\n\n foreach ($groups as $group) {\n $data[] = [\n 'id' => $group->getUuid(),\n 'name' => $group->getName(),\n ];\n }\n }\n\n return $data;\n }\n\n public function getTeamsGroupsOptions(array $filterTeamUuids = []): array\n {\n $data = [];\n $teams = $this->getTeams();\n\n foreach ($teams as $team) {\n if (! empty($filterTeamUuids) && ! in_array($team['id'], $filterTeamUuids, true)) {\n continue;\n }\n\n $data[] = [\n 'label' => $team['name'],\n 'groups' => $this->getTeamGroups($team['id']),\n ];\n }\n\n return $data;\n }\n\n public function getTeam(string $teamUuid): ?Team\n {\n return $this->teamRepository->idOrUuid($teamUuid);\n }\n\n public function getTeamById(int $teamId): ?Team\n {\n return $this->teamRepository->find($teamId);\n }\n\n public function getGroupsUuids(AutomatedReport $report): array\n {\n $uuids = [];\n $reportGroups = $report->getGroups();\n foreach ($reportGroups as $groupId) {\n if ($group = $this->groupRepository->find($groupId)) {\n $uuids[] = $group->getUuid();\n }\n }\n\n return $uuids;\n }\n\n public function getPlaybookCategoriesUuids(AutomatedReport $report): array\n {\n $uuids = [];\n $playbookCategories = $report->getPlaybookCategories();\n foreach ($playbookCategories as $id) {\n if ($category = $this->playbookCategoryRepository->find($id)) {\n $uuids[] = $category->getUuid();\n }\n }\n\n return $uuids;\n }\n\n public function getDealAtCallStagesUuids(AutomatedReport $report): array\n {\n $uuids = [];\n $reportStages = $report->getDealAtCallStages();\n foreach ($reportStages as $id) {\n if ($stage = $this->stageRepository->find($id)) {\n $uuids[] = $stage->getUuid();\n }\n }\n\n return $uuids;\n }\n\n public function getCurrentDealStagesUuids(AutomatedReport $report): array\n {\n $uuids = [];\n $reportStages = $report->getCurrentDealStages();\n foreach ($reportStages as $id) {\n if ($stage = $this->stageRepository->find($id)) {\n $uuids[] = $stage->getUuid();\n }\n }\n\n return $uuids;\n }\n\n public function getUsersUuids(AutomatedReport $report): array\n {\n return $this->extractUserUuids($report->getRecipients());\n }\n\n public function getJiminnyUsersUuids(AutomatedReport $report): array\n {\n return $this->extractUserUuids($report->getJiminnyRecipients());\n }\n\n /**\n * @param array<string, mixed> $recipients\n */\n private function extractUserUuids(array $recipients): array\n {\n $userIds = $recipients['users'] ?? [];\n\n return collect($userIds)\n ->map(fn ($id) => $this->userRepository->find((int) $id))\n ->filter()\n ->map(fn (UserContract $user) => $user->getUuid())\n ->values()\n ->all();\n }\n\n // get mail data\n public function getRecipientUsers(AutomatedReport $report): array\n {\n return $this->buildRecipientUsers($report->getRecipients());\n }\n\n private function getJiminnyRecipientUsers(AutomatedReport $report): array\n {\n return $this->buildRecipientUsers($report->getJiminnyRecipients());\n }\n\n /**\n * @param array<string, mixed> $recipients\n */\n private function buildRecipientUsers(array $recipients): array\n {\n $userIds = $recipients['users'] ?? [];\n\n return collect($userIds)\n ->map(fn ($id) => $this->userRepository->find((int) $id))\n ->filter()\n ->map(fn (UserContract $user) => [\n 'email' => $user->getEmailAddress(),\n 'name' => $user->getName(),\n 'timezone' => $user->getTimezone()->getName(),\n ])\n ->values()\n ->all();\n }\n\n public function getValidRecipientUsers(AutomatedReport $report, bool $includeJiminny = false): array\n {\n if ($report->isAskJiminnyReport()) {\n $recipients = $this->resolveAskJiminnyRecipients($report);\n } else {\n $recipients = $this->getRecipientUsers($report);\n if ($includeJiminny) {\n $recipients = array_merge($recipients, $this->getJiminnyRecipientUsers($report));\n }\n }\n\n $emails = [];\n\n return array_values(array_filter(\n $recipients,\n static function ($recipient) use (&$emails) {\n if (empty($recipient['email']) || in_array($recipient['email'], $emails, true)) {\n return false;\n }\n $emails[] = $recipient['email'];\n\n return true;\n }\n ));\n }\n\n private function resolveAskJiminnyRecipients(AutomatedReport $report): array\n {\n $recipients = [];\n\n $creator = $report->getCreator();\n if ($creator !== null) {\n $recipients[] = [\n 'email' => $creator->getEmailAddress(),\n 'name' => $creator->getName(),\n 'timezone' => $creator->getTimezone()->getName(),\n ];\n }\n\n return array_merge(\n $recipients,\n $this->buildRecipientUsers($report->getRecipients()),\n $this->getGroupRecipientUsers($report),\n );\n }\n\n private function getGroupRecipientUsers(AutomatedReport $report): array\n {\n $users = [];\n foreach ($report->getGroups() as $groupId) {\n $group = $this->groupRepository->find($groupId);\n if ($group === null) {\n continue;\n }\n foreach ($group->getMembers() as $member) {\n $users[] = [\n 'email' => $member->getEmailAddress(),\n 'name' => $member->getName(),\n 'timezone' => $member->getTimezone()->getName(),\n ];\n }\n }\n\n return $users;\n }\n\n public function getReportTypeName(AutomatedReportResult $report): string\n {\n $type = $report->getReport()->getType();\n\n $getType = $this->transformReportType($type);\n\n return $getType['name'];\n }\n\n public function getReportPeriodName(AutomatedReportResult $report): string\n {\n $from = $report->getFromDate();\n $to = $report->getToDate();\n $frequency = $report->getReport()->getFrequency();\n\n if ($from === null || $to === null) {\n if (! $report->getReport()->isAskJiminnyReport()) {\n $invalidPeriod = $from === null ? 'from' : 'to';\n\n throw new ApplicationException('Report period is invalid: ' . $invalidPeriod);\n }\n\n $period = $this->calculateFromAndToDatePeriod($frequency);\n $from = $period['fromDate'];\n $to = $period['toDate'];\n }\n\n return $this->formatReportPeriodName($frequency, $from, $to);\n }\n\n private function formatReportPeriodName(string $frequency, Carbon $from, Carbon $to): string\n {\n $fromYear = $from->format('Y');\n $toYear = $to->format('Y');\n $differentYears = $fromYear !== $toYear;\n\n switch ($frequency) {\n case self::FREQUENCY_DAILY:\n return $from->format('j M Y');\n\n case self::FREQUENCY_QUARTERLY:\n // 'Jan-Mar 2025' or 'Nov 2024-Jan 2025' if years differ\n $startMonth = $from->format('M');\n $endMonth = $to->copy()->subMonth();\n $endMonthName = $endMonth->format('M');\n $endMonthYear = $endMonth->format('Y');\n\n if ($differentYears) {\n return \"{$startMonth} {$fromYear} - {$endMonthName} {$endMonthYear}\";\n }\n\n return \"{$startMonth} - {$endMonthName} {$toYear}\";\n\n case self::FREQUENCY_MONTHLY:\n // 'May 2025' - monthly reports are always within the same year\n return $from->format('M Y');\n\n case self::FREQUENCY_WEEKLY:\n // '4 - 8 Aug 2025', '27 Oct - 3 Nov 2025', or '28 Dec 2024 - 3 Jan 2025' if years differ\n $startDay = $from->format('j');\n $endDay = $to->format('j');\n $startMonth = $from->format('M');\n $endMonth = $to->format('M');\n\n if ($differentYears) {\n return \"{$startDay} {$startMonth} {$fromYear} - {$endDay} {$endMonth} {$toYear}\";\n }\n\n if ($startMonth !== $endMonth) {\n return \"{$startDay} {$startMonth} - {$endDay} {$endMonth} {$toYear}\";\n }\n\n return \"{$startDay} - {$endDay} {$endMonth} {$toYear}\";\n\n case self::FREQUENCY_ONE_OFF:\n // '2 May-31 May 2025' or '15 Dec 2024-15 Jan 2025' if years differ\n $startDay = $from->format('j');\n $startMonth = $from->format('M');\n $endDay = $to->format('j');\n $endMonth = $to->format('M');\n\n // If same month and year, use a format like '2-31 May 2025'\n if ($startMonth === $endMonth && ! $differentYears) {\n return \"{$startDay} - {$endDay} {$startMonth} {$toYear}\";\n }\n\n // If different years, include both years\n if ($differentYears) {\n return \"{$startDay} {$startMonth} {$fromYear} - {$endDay} {$endMonth} {$toYear}\";\n }\n\n // Same year but different months\n return \"{$startDay} {$startMonth} - {$endDay} {$endMonth} {$toYear}\";\n\n default:\n // Default format for unknown frequencies\n return $from->format('j M Y') . ' - ' . $to->format('j M Y');\n }\n }\n\n public function getReportTeamsName(AutomatedReportResult $report): string\n {\n $groups = $report->getGroups();\n\n if (empty($groups)) {\n return 'All';\n }\n\n // Get group names from repository\n $groupNames = [];\n foreach ($groups as $groupId) {\n $group = $this->groupRepository->find($groupId);\n if ($group) {\n $groupNames[] = $group->getName();\n }\n }\n\n if (count($groupNames) === 1) {\n // Single team format\n $teamsName = $groupNames[0];\n } else {\n // Multiple teams format\n $teamsName = implode(', ', $groupNames);\n }\n\n return $teamsName;\n }\n\n public function getReportFileName(AutomatedReportResult $report): string\n {\n $customName = $report->getReport()->getCustomName();\n $periodName = $this->getReportPeriodName($report);\n $filenameSuffix = $this->getFilenameSuffix($report);\n\n if ($customName) {\n if ($filenameSuffix) {\n $customName .= \" {$filenameSuffix}\";\n }\n\n return $this->sanitizeFileName(\"{$customName} - {$periodName}\");\n }\n\n $baseName = $this->getReportTypeName($report);\n\n if ($filenameSuffix) {\n $baseName .= \" {$filenameSuffix}\";\n }\n\n return $this->sanitizeFileName(\"{$baseName} - {$periodName} - {$this->getReportTeamsName($report)}\");\n }\n\n public function getReportFileNameWithExtension(AutomatedReportResult $result): string\n {\n $extension = $this->getMediaTypeMetadata($result)['extension'];\n\n return $this->getReportFileName($result) . '.' . $extension;\n }\n\n public function sanitizeFileName(string $fileName): string\n {\n return str_replace(['/', '\\\\'], '-', $fileName);\n }\n\n public function isUserRecipientOfReport(User $user, AutomatedReport $report): bool\n {\n $recipients = array_map('intval', $report->getRecipients()['users'] ?? []);\n\n return in_array($user->getId(), $recipients);\n }\n\n public function transformReportResults(Collection $automatedReportResults): array\n {\n $data = [];\n foreach ($automatedReportResults as $automatedReportResult) {\n /** @var AutomatedReportResult $automatedReportResult */\n\n $report = $automatedReportResult->getReport();\n\n $createdBy = $report->getCreator();\n $creator = [\n 'id' => $createdBy?->getUuid(),\n 'name' => $createdBy?->getName(),\n 'email' => $createdBy?->getEmailAddress(),\n 'photoUrl' => $createdBy?->getPhotoUrl(),\n ];\n\n $data[] = [\n 'id' => $automatedReportResult->getUuid(),\n 'name' => $automatedReportResult->getName(),\n 'frequency' => $this->transformFrequency($report->getFrequency()),\n 'recipients' => [\n ...array_values($this->transformGroups(team: $report->getTeam(), groupsIds: $report->getGroups())),\n ...array_values($this->transformRecipients($report->getRecipients())),\n ],\n 'report_type' => $this->transformReportType($report->getType()),\n 'media_type' => $automatedReportResult->getMediaType(),\n 'downloadUrl' => $this->generateReportResultDownloadUrl($automatedReportResult),\n 'viewUrl' => $this->generateReportResultViewUrl($automatedReportResult),\n 'generated_at' => $automatedReportResult->getGeneratedAt()?->toIso8601String(),\n 'creator' => $creator,\n ];\n }\n\n return $data;\n }\n\n public function hasCallTypeConference(AutomatedReport $report): bool\n {\n return in_array(self::CALL_TYPE_CONFERENCE['id'], $report->getCallTypes(), true);\n }\n\n public function hasCallTypeDialer(AutomatedReport $report): bool\n {\n return in_array(self::CALL_TYPE_DIALER['id'], $report->getCallTypes(), true);\n }\n\n // transformers\n private function transformTeam(Team $team): array\n {\n if (! $team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {\n return [];\n }\n\n return [\n 'id' => $team->getUuid(),\n 'name' => $team->getName(),\n ];\n }\n\n private function transformReportFullView(AutomatedReport $report): array\n {\n $base = $this->transformReportBase($report);\n\n return $report->getType() === self::TYPE_ASK_JIMINNY\n ? $base + $this->transformAskJiminnyFields($report)\n : $base + $this->transformStandardReportFields($report);\n }\n\n private function transformReportBase(AutomatedReport $report): array\n {\n return [\n 'id' => $report->getUuid(),\n 'organization' => $this->transformOrganization(team: $report->getTeam()),\n 'report_type' => $this->transformReportType($report->getType()),\n 'frequency' => $this->transformFrequency($report->getFrequency()),\n ];\n }\n\n private function transformStandardReportFields(AutomatedReport $report): array\n {\n $team = $report->getTeam();\n\n return [\n 'report_enabled' => $report->getStatus(),\n 'start_date_period' => $report->getFrom()?->format('Y-m-d H:i:s'),\n 'end_date_period' => $report->getTo()?->format('Y-m-d H:i:s'),\n 'deal_value_min' => $report->getDealValueMin(),\n 'deal_value_max' => $report->getDealValueMax(),\n 'call_types' => $this->transformCallType($report->getCallTypes()),\n 'media_types' => $this->transformMediaTypes($report),\n 'call_duration_min' => $this->transformDurationToMinutes($report->getCallDurationMin()),\n 'call_duration_max' => $this->transformDurationToMinutes($report->getCallDurationMax()),\n 'teams' => $this->transformGroups(team: $team, groupsIds: $report->getGroups()),\n 'deal_at_call_stages' => $this->transformStages(team: $team, stagesIds: $report->getDealAtCallStages()),\n 'current_deal_stages' => $this->transformStages(team: $team, stagesIds: $report->getCurrentDealStages()),\n 'recipients' => $this->transformRecipients($report->getRecipients()),\n 'created_by' => $this->transformCreator($report->getCreator()),\n 'additional_prompt_input' => $report->getAdditionalPromptInput(),\n 'custom_name' => $report->getCustomName(),\n 'created_at' => $report->getCreatedAt()->format('Y-m-d H:i:s'),\n 'updated_at' => $report->getUpdatedAt()->format('Y-m-d H:i:s'),\n 'deleted_at' => $report->getDeletedAt()?->format('Y-m-d H:i:s'),\n ];\n }\n\n private function transformAskJiminnyFields(AutomatedReport $report): array\n {\n $team = $report->getTeam();\n $creatorId = $report->getAttribute('created_by');\n $explicitUserIds = array_values(array_filter(\n $report->getRecipients()['users'] ?? [],\n static fn ($id) => $id !== $creatorId\n ));\n\n return [\n 'report_name' => $report->getCustomName(),\n 'enabled' => $report->getStatus(),\n 'share_teams' => $this->transformGroups(team: $team, groupsIds: $report->getGroups()),\n 'share_users' => $this->transformRecipients(['users' => $explicitUserIds]),\n 'saved_search' => $this->transformSafeSearch($report->getSavedSearch()),\n 'ask_jiminny_prompt' => $this->transformAskJiminnyPrompt($report->getAskAnythingPrompt()),\n 'expires_on' => $report->getExpiresAt()?->format('Y-m-d'),\n ];\n }\n\n private function transformOrganization(?Team $team): array\n {\n return [\n 'id' => $team?->getUuid(),\n 'name' => $team?->getName(),\n ];\n }\n\n private function transformReportType(string $type): array\n {\n foreach (self::ALL_TYPES as $typeItem) {\n if ($typeItem['id'] === $type) {\n return $typeItem;\n }\n }\n\n return [];\n }\n\n private function transformCallType(array $types): array\n {\n $result = [];\n $callTypes = [self::CALL_TYPE_CONFERENCE, self::CALL_TYPE_DIALER];\n\n foreach ($types as $type) {\n foreach ($callTypes as $callTypeItem) {\n if ($callTypeItem['id'] === $type) {\n $result[] = $callTypeItem;\n\n break;\n }\n }\n }\n\n return $result;\n }\n\n private function transformMediaTypes(AutomatedReport $report): array\n {\n $values = [];\n\n foreach ($report->getMediaTypes() as $mediaType) {\n if (! in_array($mediaType, self::MEDIA_TYPES, true)) {\n continue;\n }\n\n $values[] = match ($mediaType) {\n self::MEDIA_TYPE_PDF => self::MEDIA_TYPE_OBJECT_PDF,\n self::MEDIA_TYPE_PODCAST => self::MEDIA_TYPE_OBJECT_PODCAST,\n };\n }\n\n return $values;\n }\n\n private function transformFrequency(string $frequency): array\n {\n foreach (self::ALL_FREQUENCIES as $frequencyItem) {\n if ($frequencyItem['id'] === $frequency) {\n return $frequencyItem;\n }\n }\n\n return [];\n }\n\n public function transformDurationToMinutes(?int $duration): ?int\n {\n if (! $duration) {\n return null;\n }\n\n return (int) ($duration / 60);\n }\n\n private function transformGroups(?Team $team, array $groupsIds): array\n {\n if (empty($groupsIds) || ! $team) {\n return [];\n }\n\n $data = [];\n foreach ($groupsIds as $groupId) {\n $group = $team->groups()->where('id', $groupId)->first();\n\n if ($group) {\n $data[] = [\n 'id' => $group->getUuid(),\n 'name' => $group->getName(),\n 'photoUrl' => $group->getPhotoUrl(),\n ];\n }\n }\n\n return $data;\n }\n\n private function transformStages(?Team $team, array $stagesIds): array\n {\n if (empty($stagesIds) || ! $team) {\n return [];\n }\n\n $data = [];\n foreach ($stagesIds as $stageId) {\n $stage = $team->stages()->where('id', $stageId)->first();\n\n if ($stage) {\n $data[] = [\n 'id' => $stage->getUuid(),\n 'name' => $stage->getName(),\n ];\n }\n }\n\n return $data;\n }\n\n private function transformRecipients(array $recipients): array\n {\n $users = [];\n foreach ($recipients['users'] ?? [] as $userId) {\n $users[] = $this->transformUser($userId);\n }\n\n return $users;\n }\n\n private function transformCreator(?User $user): ?array\n {\n if ($user === null) {\n return null;\n }\n\n return $this->transformUser($user->getId());\n }\n\n private function transformAskJiminnyPrompt(?AskAnythingPrompt $prompt): ?array\n {\n if ($prompt === null) {\n return null;\n }\n\n return [\n 'id' => $prompt->getUuid(),\n 'name' => $prompt->getTitle(),\n ];\n }\n\n private function transformSafeSearch(?Search $search): ?array\n {\n if ($search === null) {\n return null;\n }\n\n return [\n 'id' => $search->getUuid(),\n 'name' => $search->getName(),\n ];\n }\n\n private function transformUser(int $userId): array\n {\n /* @var ?User $user */\n $user = $this->userRepository->find($userId);\n\n return [\n 'id' => $user?->getUuid(),\n 'name' => $user?->getName(),\n 'email' => $user?->getEmailAddress(),\n 'photoUrl' => $user?->getPhotoUrl(),\n ];\n }\n\n public function create(array $data): array\n {\n $validatedData = $this->validateAndTransformData($data);\n $validatedData['created_by'] = auth()->id();\n\n $automatedReport = $this->automatedReportsRepository->create($validatedData);\n\n $this->generateOneOffReport($automatedReport);\n\n return $this->transformReportFullView($automatedReport);\n }\n\n public function update(string $uuid, array $data): array\n {\n $validatedData = $this->validateAndTransformData($data);\n $report = $this->automatedReportsRepository->findByUuid($uuid);\n\n if (! $report) {\n throw new InvalidArgumentException('Report not found');\n }\n\n $oldCustomName = $report->getCustomName();\n\n $automatedReport = $this->automatedReportsRepository->update($report, $validatedData);\n\n if ($oldCustomName !== $automatedReport->getCustomName()) {\n $this->updateResultNames($automatedReport);\n }\n\n $this->generateOneOffReport($automatedReport);\n\n return $this->transformReportFullView($automatedReport);\n }\n\n /**\n * Create an Ask Jiminny report.\n */\n public function createAskJiminnyReport(array $data, User $creator): array\n {\n $validatedData = $this->validateAskJiminnyReportData($data, $creator);\n $validatedData['created_by'] = $creator->getId();\n\n $automatedReport = $this->automatedReportsRepository->create($validatedData);\n\n return $this->transformReportFullView($automatedReport);\n }\n\n /**\n * Update an Ask Jiminny report.\n */\n public function updateAskJiminnyReport(AutomatedReport $report, array $data, User $user): array\n {\n if (! $report->isAskJiminnyReport()) {\n throw new InvalidArgumentException('Report is not an Ask Jiminny report');\n }\n\n $validatedData = $this->validateAskJiminnyReportData($data, $user);\n\n $oldCustomName = $report->getCustomName();\n\n $automatedReport = $this->automatedReportsRepository->update($report, $validatedData);\n\n if ($oldCustomName !== $automatedReport->getCustomName()) {\n $this->updateResultNames($automatedReport);\n }\n\n return $this->transformReportFullView($automatedReport);\n }\n\n public function updateAskJiminnyReportStatus(AutomatedReport $report, bool $status): array\n {\n $this->automatedReportsRepository->update($report, ['status' => $status]);\n\n return $this->transformReportFullView($report->fresh());\n }\n\n /**\n * Validate and transform data for Ask Jiminny reports.\n */\n private function validateAskJiminnyReportData(array $data, User $user): array\n {\n // Validate name\n $name = trim($data['report_name'] ?? '');\n if (empty($name)) {\n throw new InvalidArgumentException('Report name is required');\n }\n if (mb_strlen($name) > 50) {\n throw new InvalidArgumentException('Report name must be 50 characters or less');\n }\n\n // Validate frequency (only daily, weekly, monthly for Ask Jiminny)\n $frequency = $data['frequency'] ?? null;\n $askJiminnyFrequencies = [self::FREQUENCY_DAILY, self::FREQUENCY_WEEKLY, self::FREQUENCY_MONTHLY];\n if (! in_array($frequency, $askJiminnyFrequencies, true)) {\n throw new InvalidArgumentException('Frequency must be daily, weekly, or monthly');\n }\n\n // Validate expiration date\n $expiresAt = $data['expires_on'] ?? null;\n if (empty($expiresAt)) {\n throw new InvalidArgumentException('Expiration date is required');\n }\n\n try {\n $expiresAtDate = Carbon::parse($expiresAt);\n } catch (InvalidFormatException $e) {\n throw new InvalidArgumentException('Expiration date format is invalid');\n }\n $maxExpiration = Carbon::now()->addYear();\n if ($expiresAtDate->gt($maxExpiration)) {\n throw new InvalidArgumentException('Expiration date cannot be more than 1 year from now');\n }\n if ($expiresAtDate->isPast()) {\n throw new InvalidArgumentException('Expiration date cannot be in the past');\n }\n\n // Validate saved search\n $activitySearchId = $data['saved_search'] ?? null;\n if (empty($activitySearchId)) {\n throw new InvalidArgumentException('Saved search is required');\n }\n $savedSearch = $this->activitySearchRepository->findByUuidAndUser($activitySearchId, $user);\n if (! $savedSearch) {\n throw new InvalidArgumentException('Saved search not found or does not belong to you');\n }\n\n // Validate saved prompt\n $askAnythingPromptId = $data['ask_jiminny_prompt'] ?? null;\n if (empty($askAnythingPromptId)) {\n throw new InvalidArgumentException('Ask Jiminny prompt is required');\n }\n $prompt = $this->askAnythingRepository->getPromptByUuid($askAnythingPromptId);\n if (! $prompt) {\n throw new InvalidArgumentException('Ask Jiminny prompt not found');\n }\n\n // Validate status\n $status = $data['enabled'] ?? false;\n\n $recipientUserIds = [$user->getId()];\n\n if (! empty($data['share_users'])) {\n $sharedUserIds = $this->validateAndGetUserIdsByTeam(\n $user->team,\n (array) $data['share_users']\n );\n $recipientUserIds = array_merge($recipientUserIds, $sharedUserIds);\n }\n\n $sharedGroupIds = [];\n if (! empty($data['share_teams'])) {\n $sharedGroupIds = $this->validateAndGetGroupIds($user->team, (array) $data['share_teams']);\n }\n\n $recipientUserIds = array_values(array_unique($recipientUserIds));\n\n return [\n 'team_id' => $user->getTeamId(),\n 'type' => self::TYPE_ASK_JIMINNY,\n 'status' => (bool) $status,\n 'frequency' => $frequency,\n 'custom_name' => $name,\n 'activity_search_id' => $savedSearch->getId(),\n 'ask_anything_prompt_id' => $prompt->getId(),\n 'expires_at' => $expiresAtDate->toDateString(),\n 'media_types' => [self::MEDIA_TYPE_PDF],\n 'call_types' => [],\n 'recipients' => ['users' => $recipientUserIds],\n 'groups' => $sharedGroupIds,\n ];\n }\n\n public static function getAskJiminnyFrequencies(): array\n {\n return array_map(static function ($frequency) {\n return $frequency['id'];\n }, self::ASK_JIMINNY_FREQUENCIES);\n }\n\n public function getAskJiminnyReportFilters(User $user): array\n {\n $savedSearches = $this->activitySearchRepository->findByUserOrderedByName($user)\n ->map(fn (Search $search) => [\n 'id' => $search->getUuid(),\n 'name' => $search->getName(),\n ])\n ->values()->all();\n\n $prompts = collect(\n $this->askAnythingPromptService->get($user, AskAnythingPromptTarget::on_demand)\n )->map(fn (AskAnythingPromptDto $prompt) => [\n 'id' => $prompt->id,\n 'name' => $prompt->title,\n ])->values()->all();\n\n return [\n [\n 'id' => 'prompt',\n 'label' => 'Prompt',\n 'options' => $prompts,\n ],\n [\n 'id' => 'saved_search',\n 'label' => 'Saved Search',\n 'options' => $savedSearches,\n ],\n ];\n }\n\n public function getAskJiminnyReportFormData(User $user, ?AutomatedReport $report = null): array\n {\n $team = $user->getTeam();\n $userTimezone = $user->getTimezone();\n\n $savedSearches = $this->activitySearchRepository->findByUserOrderedByName($user)\n ->map(fn (Search $search) => [\n 'id' => $search->getUuid(),\n 'name' => $search->getName(),\n ])\n ->values()->all();\n\n $prompts = collect(\n $this->askAnythingPromptService->get($user, AskAnythingPromptTarget::on_demand)\n )->map(fn (AskAnythingPromptDto $prompt) => [\n 'id' => $prompt->id,\n 'name' => $prompt->title,\n ])->values()->all();\n\n $teamGroups = $this->groupRepository->getAllByTeam($team)->map(fn ($group) => [\n 'id' => $group->getUuid(),\n 'name' => $group->getName(),\n ])->values()->all();\n\n $shareUsers = $this->recipientsService->getRecipientsFieldData(team: $team)['options'] ?? [];\n\n $sharedTeamsValue = [];\n $sharedUsersValue = [];\n if ($report) {\n $sharedTeamsValue = $this->transformGroups($team, $report->getGroups());\n\n $recipientUserIds = $report->getRecipients()['users'] ?? [];\n $creatorId = $report->getAttribute('created_by');\n $sharedUserIds = array_values(array_filter(\n $recipientUserIds,\n static fn ($id) => $id !== $creatorId\n ));\n $sharedUsersValue = collect($sharedUserIds)\n ->map(fn ($id) => $this->userRepository->find((int) $id))\n ->filter()\n ->map(fn (User $u) => [\n 'id' => $u->getUuid(),\n 'name' => $u->getName(),\n ])\n ->values()\n ->all();\n }\n\n return [\n 'fields' => [\n [\n 'id' => 'enabled',\n 'inputType' => InputTypeEnum::TOGGLE,\n 'label' => '',\n 'value' => $report?->getStatus() ?? false,\n ],\n [\n 'id' => 'report_name',\n 'inputType' => InputTypeEnum::TEXT,\n 'label' => 'Name',\n 'placeholder' => 'Enter name',\n 'required' => true,\n 'validation' => ['maxLength' => 50],\n 'value' => $report?->getCustomName() ?? '',\n ],\n [\n 'id' => 'frequency',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'label' => 'Frequency',\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => self::ASK_JIMINNY_FREQUENCIES,\n 'value' => $report ? $this->transformFrequency($report->getFrequency()) : null,\n ],\n [\n 'id' => 'expires_on',\n 'inputType' => InputTypeEnum::DATE,\n 'label' => 'Expires on',\n 'required' => true,\n 'placeholder' => 'Select',\n 'validation' => [\n 'minDate' => now($userTimezone)->toDateString(),\n 'maxDate' => now($userTimezone)->addYear()->toDateString(),\n ],\n 'value' => $report?->getExpiresAt()?->toDateString(),\n ],\n [\n 'id' => 'share_teams',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'label' => 'Team',\n 'required' => false,\n 'placeholder' => 'Select',\n 'options' => $teamGroups,\n 'value' => $sharedTeamsValue,\n ],\n [\n 'id' => 'share_users',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'label' => 'Team member',\n 'required' => false,\n 'placeholder' => 'Select',\n 'groupLabelKey' => 'label',\n 'groupValuesKey' => 'users',\n 'optionLabelKey' => 'name',\n 'optionValueKey' => 'id',\n 'options' => $shareUsers,\n 'value' => $sharedUsersValue,\n ],\n [\n 'id' => 'saved_search',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'label' => 'Saved search',\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => $savedSearches,\n 'value' => $report && $report->getSavedSearch() ? [\n 'id' => $report->getSavedSearch()->getUuid(),\n 'name' => $report->getSavedSearch()->getName(),\n ] : null,\n ],\n [\n 'id' => 'ask_jiminny_prompt',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'label' => 'Ask Jiminny prompt',\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => $prompts,\n 'value' => $report && $report->getAskAnythingPrompt() ? [\n 'id' => $report->getAskAnythingPrompt()->getUuid(),\n 'name' => $report->getAskAnythingPrompt()->getTitle(),\n ] : null,\n ],\n ],\n ];\n }\n\n private function updateResultNames(AutomatedReport $automatedReport): void\n {\n $results = $this->automatedReportsRepository->getResultsByReport($automatedReport);\n\n foreach ($results as $result) {\n $result->update(['name' => $this->getReportFileName($result)]);\n }\n }\n\n public function updateStatus(string $uuid, array $data): array\n {\n $automatedReport = $this->automatedReportsRepository->findByUuid($uuid);\n\n if (! $automatedReport) {\n throw new ModelNotFoundException('Report not found');\n }\n\n $status = $this->validateReportStatus($data['report_enabled'] ?? null);\n $automatedReport->update([\n 'status' => $status,\n ]);\n\n $this->generateOneOffReport($automatedReport);\n\n return $this->transformReportFullView($automatedReport);\n }\n\n private function generateOneOffReport(AutomatedReport $automatedReport): void\n {\n // the scheduler handles all the other frequency types\n if ($automatedReport->getStatus() === false || $automatedReport->getFrequency() !== self::FREQUENCY_ONE_OFF) {\n return;\n }\n\n $this->dispatcher->dispatch(new RequestGenerateReportJob($automatedReport->getUuid()));\n }\n\n public function getReport(string $uuid): AutomatedReport\n {\n $automatedReport = $this->automatedReportsRepository->findByUuid($uuid);\n\n if (! $automatedReport) {\n throw new ModelNotFoundException('Report not found');\n }\n\n return $automatedReport;\n }\n\n public function get(string $uuid): array\n {\n $automatedReport = $this->getReport($uuid);\n\n return $this->transformReportFullView($automatedReport);\n }\n\n public function list(string $sortColumn = 'created_at', string $sortDirection = 'desc'): array\n {\n $results = [];\n $collection = $this->automatedReportsRepository->getAllStandardReports($sortColumn, $sortDirection);\n\n /** @var AutomatedReport $report */\n foreach ($collection as $report) {\n $results[] = $this->transformReportFullView($report);\n }\n\n return ['data' => $results];\n }\n\n public function listAskJiminnyReports(\n User $user,\n string $sortColumn = 'created_at',\n string $sortDirection = 'desc'\n ): array {\n $results = [];\n $collection = $this->automatedReportsRepository->getAskJiminnyReportsByUser($user, $sortColumn, $sortDirection);\n\n /** @var AutomatedReport $report */\n foreach ($collection as $report) {\n $results[] = $this->transformReportFullView($report);\n }\n\n return ['data' => $results];\n }\n\n public function delete(string $uuid): void\n {\n $automatedReport = $this->automatedReportsRepository->findByUuid($uuid);\n\n if (! $automatedReport) {\n throw new ModelNotFoundException('Report not found');\n }\n\n $automatedReport->delete();\n }\n\n public function createReportResult(AutomatedReport $automatedReport, array $data = []): AutomatedReportResult\n {\n return $this->automatedReportsRepository->createResult(\n array_merge(\n [\n 'report_id' => $automatedReport->getId(),\n 'status' => AutomatedReportResult::STATUS_DEFAULT,\n ],\n $data\n )\n );\n }\n\n public function getReportResult(string $resultUuid): AutomatedReportResult\n {\n $report = $this->automatedReportsRepository->findResultByUuid($resultUuid);\n\n if (! $report) {\n throw new ModelNotFoundException('Report Result not found');\n }\n\n return $report;\n }\n\n public function findChildResult(AutomatedReportResult $result, string $type): ?AutomatedReportResult\n {\n return $this->automatedReportsRepository->findChildResult($result, $type);\n }\n\n // prophet API calls\n /**\n * @throws ApplicationException\n */\n public function getGenerateReportPayload(AutomatedReport $automatedReport, string $reportResultUuid): array\n {\n $period = $this->calculateFromAndToDate($automatedReport);\n $fromDate = $period['fromDate'];\n $toDate = $period['toDate'];\n\n return [\n 'team_id' => $automatedReport->getTeamId(),\n 'request_id' => $reportResultUuid,\n 'report_type' => $automatedReport->getType(),\n 'media_types' => $automatedReport->getMediaTypes(),\n 'from_date' => $fromDate->startOfDay()->format(DateTimeInterface::RFC3339),\n 'to_date' => $toDate->endOfDay()->format(DateTimeInterface::RFC3339),\n 'group_ids' => $automatedReport->getGroups(),\n 'call_deal_stage' => $automatedReport->getDealAtCallStages(),\n 'current_deal_stage' => $automatedReport->getCurrentDealStages(),\n 'deal_min_value' => $automatedReport->getDealValueMin(),\n 'deal_max_value' => $automatedReport->getDealValueMax(),\n 'call_types' => $automatedReport->getCallTypes(),\n 'call_duration_min_seconds' => $automatedReport->getCallDurationMin(),\n 'call_duration_max_seconds' => $automatedReport->getCallDurationMax(),\n 'special_requirements' => $automatedReport->getAdditionalPromptInput(),\n 'callback_url' => $this->getCallbackUrl(),\n 'report_period' => $this->formatReportPeriodName(\n $automatedReport->getFrequency(),\n $fromDate,\n $toDate,\n ),\n 'playbook_categories' => $automatedReport->getPlaybookCategories(),\n 'custom_name' => $automatedReport->getCustomName(),\n ];\n }\n\n // $inputPayload - FE payload structure\n public function getActivitiesCountPayload(array $inputPayload): array\n {\n // Use validateAndTransformData to validate and normalize input\n $validatedData = $this->validateAndTransformData($inputPayload);\n $period = $this->calculateFromAndToDatePeriod(\n $validatedData['frequency'],\n Carbon::parse($validatedData['from']),\n Carbon::parse($validatedData['to']),\n );\n $fromDate = $period['fromDate'];\n $toDate = $period['toDate'];\n\n // Create payload similar to getGenerateReportPayload\n return [\n 'team_id' => $validatedData['team_id'],\n 'group_ids' => $validatedData['groups'] ?? [],\n 'report_type' => $validatedData['type'],\n 'from_date' => $fromDate->format(DateTimeInterface::RFC3339),\n 'to_date' => $toDate->format(DateTimeInterface::RFC3339),\n 'call_deal_stage' => $validatedData['deal_at_call_stages'] ?? [],\n 'current_deal_stage' => $validatedData['current_deal_stages'] ?? [],\n 'deal_min_value' => $validatedData['deal_value_min'] ?? null,\n 'deal_max_value' => $validatedData['deal_value_max'] ?? null,\n 'call_types' => $validatedData['call_types'],\n 'call_duration_min_seconds' => $validatedData['call_duration_min'] ?? null,\n 'call_duration_max_seconds' => $validatedData['call_duration_max'] ?? null,\n 'special_requirements' => $validatedData['additional_prompt_input'] ?? null,\n 'playbook_categories' => $validatedData['playbook_categories'] ?? [],\n 'request_id' => null,\n 'callback_url' => null,\n ];\n }\n\n public function shouldSendReport(array $users, ?CarbonInterface $generatedAt = null): bool\n {\n if (empty($users)) {\n return false;\n }\n\n $earliestTz = collect($users)\n ->mapWithKeys(function (array $user) {\n $tz = new DateTimeZone($user['timezone']);\n $nowUtc = new DateTime('now', new DateTimeZone('UTC'));\n $offset = $tz->getOffset($nowUtc);\n\n return [$user['timezone'] => $offset];\n })\n ->sortDesc()\n ->keys()\n ->first();\n\n $now = Carbon::now($earliestTz);\n $isScheduledTime = (int) $now->format('H') === self::SENT_REPORT_AT_HOURS;\n\n if ($isScheduledTime) {\n return true;\n }\n\n return $this->hasPassedScheduledTime($generatedAt, $earliestTz);\n }\n\n public function hasPassedScheduledTime(?CarbonInterface $generatedAt, string $timezone): bool\n {\n if ($generatedAt === null) {\n return false;\n }\n\n $now = Carbon::now($timezone);\n $scheduledTime = $now->copy()->setTime(self::SENT_REPORT_AT_HOURS, 0, 0);\n\n if ($now->hour < self::SENT_REPORT_AT_HOURS) {\n $scheduledTime = $scheduledTime->subDay();\n }\n\n $scheduledTimeUtc = $scheduledTime->copy()->utc();\n $generatedAtUtc = $generatedAt->copy()->utc();\n $nowUtc = $now->copy()->utc();\n\n return $generatedAtUtc->lt($scheduledTimeUtc) && $nowUtc->gt($scheduledTimeUtc);\n }\n\n public function calculateFromAndToDatePeriod(\n string $frequency,\n ?Carbon $fromDate = null,\n ?Carbon $toDate = null\n ): array {\n if ($frequency === self::FREQUENCY_ONE_OFF) {\n return [\n 'fromDate' => $fromDate,\n 'toDate' => $toDate,\n ];\n }\n\n $now = Carbon::now();\n\n return match ($frequency) {\n self::FREQUENCY_DAILY => [\n 'fromDate' => $now->copy()->subDay()->startOfDay(),\n 'toDate' => $now->copy()->subDay()->endOfDay(),\n ],\n self::FREQUENCY_WEEKLY => [\n 'fromDate' => $now->copy()->subWeeks(1)->startOfDay(),\n 'toDate' => $now->copy()->subDay()->endOfDay(),\n ],\n self::FREQUENCY_MONTHLY => [\n 'fromDate' => $now->copy()->subMonths(1)->startOfDay(),\n 'toDate' => $now->copy()->subDay()->endOfDay(),\n ],\n self::FREQUENCY_QUARTERLY => [\n 'fromDate' => $now->copy()->subMonths(3)->startOfDay(),\n 'toDate' => $now->copy()->subDay()->endOfDay(),\n ],\n default => throw new InvalidArgumentException(\"Unsupported frequency: {$frequency}\"),\n };\n }\n\n private function calculateFromAndToDate(AutomatedReport $automatedReport): array\n {\n return $this->calculateFromAndToDatePeriod(\n $automatedReport->getFrequency(),\n $automatedReport->getFrom(),\n $automatedReport->getTo()\n );\n }\n\n public function getAskJiminnyGenerateReportPayload(\n AutomatedReport $automatedReport,\n AutomatedReportResult $reportResult,\n array $activityIds,\n ): array {\n return [\n 'user_question' => $automatedReport->getAskAnythingPrompt()?->getContent(),\n 'call_ids' => array_map('strval', $activityIds),\n 'team_id' => $automatedReport->getTeamId(),\n 'request_id' => $reportResult->getUuid(),\n 'callback_url' => $this->getCallbackUrl(),\n 'report_period' => $this->getReportPeriodName($reportResult),\n 'report_name' => $automatedReport->getCustomName(),\n ];\n }\n\n private function getCallbackUrl(): string\n {\n return $this->webhookService->route('jiminny.webhook.reports.ready');\n }\n\n /**\n * Validate and transform payload data for automated reports\n *\n * @param array $data\n *\n * @throws InvalidArgumentException\n *\n * @return array\n */\n private function validateAndTransformData(array $data): array\n {\n // Validate organization (team) and check feature\n $team = $this->validateOrganization($data['organization'] ?? null);\n\n $status = $this->validateReportStatus($data['report_enabled'] ?? null);\n $type = $this->validateReportType($data['report_type'] ?? null);\n $frequency = $this->validateFrequency($data['frequency'] ?? null);\n $additionalPromptInput = $this->validateAdditionalPromptInput(\n $data['additional_prompt_input'] ?? null\n );\n $customReportName = $this->validateCustomReportName($data['custom_name'] ?? null);\n\n // Prepare data for the database\n $reportData = [\n 'team_id' => $team->getId(),\n 'type' => $type,\n 'status' => $status,\n 'frequency' => $frequency,\n 'additional_prompt_input' => $additionalPromptInput,\n 'custom_name' => $customReportName,\n ];\n\n // Validate deal values\n $reportData = $this->validateDealValues($data, $reportData);\n\n // Validate date range\n $reportData = $this->validateDateRange($data, $reportData, $frequency);\n\n // Validate call durations\n $reportData = $this->validateCallDurations($data, $reportData);\n\n // Validate call types\n $reportData = $this->validateCallTypes($data, $reportData);\n\n // Validate media types\n $reportData = $this->validateMediaTypes($data, $reportData);\n\n // Validate groups\n if (isset($data['teams'])) {\n $reportData['groups'] = $this->validateAndGetGroupIds($team, $data['teams']);\n }\n\n // Validate deal stages\n $reportData = $this->validateDealStages($data, $reportData, $team, $type);\n\n // Validate playbook categories\n $reportData = $this->validatePlaybookCategories($data, $reportData, $team);\n\n // Validate recipients\n $reportData['recipients'] = [\n 'users' => $this->validateAndGetUserIdsByTeam($team, $data['recipients'] ?? []),\n ];\n\n if (isset($data['jiminny_recipients'])) {\n // Validate Jiminny recipients\n $reportData['jiminny_recipients'] = [\n 'users' => $this->validateAndGetJiminnyUserIds((array) $data['jiminny_recipients']),\n ];\n }\n\n return $reportData;\n }\n\n private function validateDealValues(array $data, array $reportData): array\n {\n if (isset($data['min_deal_value'])) {\n $reportData['deal_value_min'] = (int) $data['min_deal_value'];\n\n if ($reportData['deal_value_min'] > 4294967295 || $reportData['deal_value_min'] < 0) {\n throw new InvalidArgumentException('Min deal value should be between 0 and 4294967295');\n }\n }\n\n if (isset($data['max_deal_value'])) {\n $reportData['deal_value_max'] = (int) $data['max_deal_value'];\n\n if ($reportData['deal_value_max'] > 4294967295 || $reportData['deal_value_max'] < 0) {\n throw new InvalidArgumentException('Max deal value should be between 0 and 4294967295');\n }\n }\n\n if (isset($data['min_deal_value'], $data['max_deal_value'])\n && $data['min_deal_value'] > $data['max_deal_value']\n ) {\n throw new InvalidArgumentException('Min deal value cannot be greater than max deal value');\n }\n\n return $reportData;\n }\n\n private function validateDateRange(array $data, array $reportData, string $frequency): array\n {\n // Set date range only for one_off frequency\n if ($frequency === 'one_off') {\n if (isset($data['start_date_period'])) {\n $reportData['from'] = $this->parseDate($data['start_date_period']);\n }\n\n if (isset($data['end_date_period'])) {\n $reportData['to'] = $this->parseDate($data['end_date_period']);\n }\n\n if (empty($reportData['from']) || empty($reportData['to'])) {\n throw new InvalidArgumentException(\n 'Start date and end date are required for one_off frequency'\n );\n }\n } else {\n $reportData['from'] = null;\n $reportData['to'] = null;\n }\n\n return $reportData;\n }\n\n private function validateCallDurations(array $data, array $reportData): array\n {\n // Convert call durations from minutes to seconds\n if (isset($data['min_call_duration'])) {\n $reportData['call_duration_min'] = (int) $data['min_call_duration'] * 60;\n\n if ($reportData['call_duration_min'] > 4294967295 || $reportData['call_duration_min'] < 0) {\n throw new InvalidArgumentException('Min call duration should be between 0 and 4294967295');\n }\n }\n\n if (isset($data['max_call_duration'])) {\n $reportData['call_duration_max'] = (int) $data['max_call_duration'] * 60;\n\n if ($reportData['call_duration_max'] > 4294967295 || $reportData['call_duration_max'] < 0) {\n throw new InvalidArgumentException('Max call duration should be between 0 and 4294967295');\n }\n }\n\n return $reportData;\n }\n\n private function validateCallTypes(array $data, array $reportData): array\n {\n // Set call types\n $reportData['call_types'] = $data['call_type'] ?? [];\n if (empty($reportData['call_types'])) {\n $reportData['call_types'] = self::getCallTypes();\n }\n\n foreach ($reportData['call_types'] as $callType) {\n if (! in_array($callType, self::getCallTypes(), true)) {\n throw new InvalidArgumentException(sprintf('Call type %s is invalid', $callType));\n }\n }\n\n return $reportData;\n }\n\n private function validateMediaTypes(array $data, array $reportData): array\n {\n // Set media types from input data\n $reportData['media_types'] = $data['media_types'] ?? [];\n\n if (empty($reportData['media_types'])) {\n throw new InvalidArgumentException('Media types are required');\n }\n\n foreach ($reportData['media_types'] as $mediaType) {\n if (! in_array($mediaType, self::MEDIA_TYPES, true)) {\n throw new InvalidArgumentException(sprintf('Media type %s is invalid', $mediaType));\n }\n }\n\n return $reportData;\n }\n\n private function validateDealStages(array $data, array $reportData, Team $team, string $reportType): array\n {\n // Validate and set deal stages\n if (isset($data['deal_stage_at_call'])) {\n $reportData['deal_at_call_stages'] =\n $this->validateAndGetDealStageIds($team, $data['deal_stage_at_call'], 'Deal stage at call');\n }\n\n if (isset($data['current_deal_stage'])) {\n $reportData['current_deal_stages'] =\n $this->validateAndGetDealStageIds($team, $data['current_deal_stage'], 'Current deal stage');\n }\n\n // Ensure current_deal_stage is not provided for loss_analysis report type\n if ($reportType === self::TYPE_LOSS_ANALYSIS && ! empty($data['current_deal_stage'])) {\n throw new InvalidArgumentException('Current deal stage is not applicable for Loss Analysis reports');\n }\n\n return $reportData;\n }\n\n // transform uuid to id\n private function validatePlaybookCategories(array $data, array $reportData, Team $team): array\n {\n $key = 'playbook_categories';\n\n if (isset($data[$key])) {\n $payloadIds = $data[$key];\n $ids = [];\n\n foreach ($payloadIds as $uuid) {\n $uuid = (string) $uuid;\n\n try {\n $playbookCategory = $this->playbookCategoryRepository->findByUuid($uuid);\n } catch (Throwable $throwable) {\n Log::error(__METHOD__ . ' ' . $throwable->getMessage());\n\n throw new InvalidArgumentException(sprintf('Playbook category %s not found', $uuid));\n }\n\n if (! $playbookCategory) {\n throw new InvalidArgumentException(sprintf('Playbook category %s not found', $uuid));\n }\n\n if (! $playbookCategory->hasPlaybook()) {\n throw new InvalidArgumentException(sprintf('Playbook category %s has no playbook', $uuid));\n }\n\n if ($playbookCategory->getPlaybook()->getTeamId() !== $team->getId()) {\n throw new InvalidArgumentException(\n sprintf('Playbook category %s not found for team %s', $uuid, $team->getUuid())\n );\n }\n\n $ids[] = $playbookCategory->getId();\n }\n\n $reportData[$key] = $ids;\n }\n\n return $reportData;\n }\n\n private function validateReportStatus($status): bool\n {\n if (! in_array($status, [true, false], true)) {\n throw new InvalidArgumentException('Report status is invalid');\n }\n\n return $status;\n }\n\n private function validateReportType($type): string\n {\n if (! in_array($type, self::getTypes(), true)) {\n throw new InvalidArgumentException(sprintf('Report type is invalid: %s', $type));\n }\n\n return $type;\n }\n\n private function validateFrequency($frequency): string\n {\n if (! in_array($frequency, self::getFrequencies(), true)) {\n throw new InvalidArgumentException('Frequency is invalid');\n }\n\n return $frequency;\n }\n\n private function validateAdditionalPromptInput(?string $additionalPromptInput): ?string\n {\n if ($additionalPromptInput && strlen($additionalPromptInput) > 5000) {\n throw new InvalidArgumentException('Additional Prompt Input should be less than 5000 characters');\n }\n\n return $additionalPromptInput;\n }\n\n private function validateCustomReportName(?string $customReportName): ?string\n {\n if ($customReportName === null || $customReportName === '') {\n return null;\n }\n\n if (strlen($customReportName) > 70) {\n throw new InvalidArgumentException('Custom report name should be less than 70 characters');\n }\n\n return $customReportName;\n }\n\n private function validateOrganization(?string $organizationUuid): Team\n {\n if (! $organizationUuid) {\n throw new InvalidArgumentException('Organization is required');\n }\n\n $team = $this->teamRepository->idOrUuid($organizationUuid);\n\n if (! $team) {\n throw new InvalidArgumentException('Organization not found');\n }\n\n if (! $team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {\n throw new InvalidArgumentException('Organization does not have the Automated Reports feature');\n }\n\n return $team;\n }\n\n private function validateAndGetGroupIds(Team $team, array $teamUuids): array\n {\n $groupIds = [];\n\n foreach ($teamUuids as $uuid) {\n $group = $this->groupRepository->findByUuid($uuid);\n\n if ($group === null || $group->getTeamId() !== $team->getId()) {\n throw new InvalidArgumentException(\n sprintf('Group %s not found for team %s', $uuid, $team->getUuid())\n );\n }\n\n $groupIds[] = $group->getId();\n\n }\n\n return $groupIds;\n }\n\n private function validateAndGetDealStageIds(Team $team, array $stageUuids, string $propertyLabel): array\n {\n $stageIds = [];\n\n foreach ($stageUuids as $uuid) {\n $stage = $this->stageRepository->findByUuid($uuid);\n\n if ($stage === null || $stage->getTeamId() !== $team->getId()) {\n throw new InvalidArgumentException(\n sprintf('Stage %s not found for team %s for %s', $uuid, $team->getUuid(), $propertyLabel)\n );\n }\n\n $stageIds[] = $stage->getId();\n }\n\n return $stageIds;\n }\n\n private function validateAndGetUserIds(array $userUuids, callable $teamCheck): array\n {\n if (empty($userUuids)) {\n return [];\n }\n\n $userIds = [];\n\n foreach ($userUuids as $uuid) {\n $user = $this->userRepository->findByUuid($uuid);\n\n if (! $user || ! $user->isStatusActive()) {\n throw new InvalidArgumentException(\n sprintf('User %s not found or is not active', $uuid)\n );\n }\n\n if (! $teamCheck($user)) {\n throw new InvalidArgumentException(\n sprintf('User %s does not belong to the allowed team(s)', $uuid)\n );\n }\n\n $userIds[] = $user->getId();\n }\n\n return $userIds;\n }\n\n private function validateAndGetUserIdsByTeam(Team $team, array $userUuids): array\n {\n return $this->validateAndGetUserIds($userUuids, fn ($user) => $user->getTeamId() === $team->getId());\n }\n\n private function validateAndGetJiminnyUserIds(array $userUuids): array\n {\n $allowedTeamIds = config('kiosk.teamIds', []);\n\n return $this->validateAndGetUserIds($userUuids, fn ($user) => in_array($user->getTeamId(), $allowedTeamIds, true));\n }\n\n private function parseDate(string $dateString): string\n {\n return date('Y-m-d H:i:s', strtotime($dateString));\n }\n\n private function generateReportResultViewUrl(AutomatedReportResult $result): string\n {\n $mediaResource = $this->getReportMediaRouteResource($result);\n\n return route('ai-reports.' . $mediaResource . '.view', ['uuid' => $result->getUuid()]);\n }\n\n private function generateReportResultDownloadUrl(AutomatedReportResult $result): string\n {\n $mediaResource = $this->getReportMediaRouteResource($result);\n\n return route('ai-reports.' . $mediaResource . '.download', ['uuid' => $result->getUuid()]);\n }\n\n private function getReportMediaRouteResource(AutomatedReportResult $result): string\n {\n if ($result->getMediaType() === self::MEDIA_TYPE_PDF) {\n return self::PDF_KEY;\n } elseif ($result->getMediaType() === self::MEDIA_TYPE_PODCAST) {\n return self::AUDIO_KEY;\n }\n\n throw new \\InvalidArgumentException('Unknown media type.');\n }\n\n public function getMediaPath(AutomatedReportResult $result): ?string\n {\n $url = match ($result->getMediaType()) {\n self::MEDIA_TYPE_PDF => $result->getPdfUrl(),\n self::MEDIA_TYPE_PODCAST => $result->getPodcastAudioUrl(),\n default => null,\n };\n\n if ($url === null) {\n return null;\n }\n\n $path = parse_url(trim($url, '\"\\''), PHP_URL_PATH);\n\n return $path ?: null;\n }\n\n public function getFilenameSuffix(AutomatedReportResult $result): ?string\n {\n return match ($result->getMediaType()) {\n self::MEDIA_TYPE_PODCAST => 'Podcast',\n default => null,\n };\n }\n\n public function getMailSubjectSuffix(AutomatedReportResult $result): string\n {\n return match ($result->getMediaType()) {\n self::MEDIA_TYPE_PDF => 'report',\n self::MEDIA_TYPE_PODCAST => 'podcast',\n default => '',\n };\n }\n\n public function getMediaTypeMetadata(AutomatedReportResult $result): array\n {\n return match ($result->getMediaType()) {\n self::MEDIA_TYPE_PODCAST => ['extension' => 'mp3', 'mime' => 'audio/mpeg'],\n self::MEDIA_TYPE_PDF => ['extension' => 'pdf', 'mime' => 'application/pdf'],\n default => ['extension' => null, 'mime' => null],\n };\n }\n\n public function deleteS3Files(AutomatedReportResult $result): void\n {\n $teamUuid = $result->getReport()->getTeam()->getUuid();\n $reportUuid = $result->getUuid();\n\n // delete all files for a report uuid no mather of pdf, podcast, or both\n // in case of both - the podcast files are linked to the pdf (parent) uuid\n // pdf and podcast date times should be close\n $path = sprintf('%s/%s/%s', $teamUuid, self::S3_DIR, $reportUuid);\n\n foreach (self::FILE_EXTENSIONS_VARIANTS as $extension) {\n $file = $path . '.' . $extension;\n\n if (Storage::exists($file)) {\n Storage::delete($file);\n Log::info('[Reports] Deleted S3 file', [\n 'path' => $file,\n ]);\n }\n }\n\n foreach (self::FILE_PODCAST_EXTENSIONS_VARIANTS as $extension) {\n $file = $path . '_podcast.' . $extension;\n\n if (Storage::exists($file)) {\n Storage::delete($file);\n Log::info('[Reports] Deleted Podcast S3 file', [\n 'path' => $file,\n ]);\n }\n }\n }\n\n /**\n *\n * @param int|null $teamId Optional team ID to filter results\n *\n * @return Collection<int, int> Collection of team IDs\n */\n public function getTeamIdsWithReportsResults(?int $teamId = null): Collection\n {\n return $this->automatedReportsRepository->getTeamIdsWithReportsResults($teamId);\n }\n\n /**\n * Core delete logic for report results using a query\n *\n * @param Builder $query\n * @param array $logContext\n *\n * @return int\n */\n private function deleteReportResultsByQuery(Builder $query, array $logContext = []): int\n {\n $deletedCount = 0;\n\n if ($query->exists()) {\n Log::info(\n 'Run delete report results',\n array_merge(\n $logContext,\n [\n 'service' => 'AutomatedReportsService',\n ]\n )\n );\n\n $query->chunkById(50, function ($results) use (&$deletedCount, $logContext) {\n foreach ($results as $result) {\n $this->deleteReportResult($result);\n $deletedCount++;\n\n Log::info(\n 'Deleted a report result',\n array_merge(\n $logContext,\n [\n 'result_id' => $result->getId(),\n 'report_id' => $result->getReportId(),\n ]\n )\n );\n }\n });\n }\n\n return $deletedCount;\n }\n\n /**\n * Delete report results for a team by retention period\n *\n * @param Team $team\n * @param CarbonImmutable $retentionDate\n *\n * @return int Number of deleted report results\n */\n public function deleteReportsResultsInRetentionPeriod(Team $team, CarbonImmutable $retentionDate): int\n {\n $reportIds = $this->automatedReportsRepository->getReportIdsByTeam($team);\n\n if ($reportIds->isEmpty()) {\n return 0;\n }\n\n $query = $this->automatedReportsRepository\n ->getReportResultsQueryForRetention($team, $retentionDate);\n\n return $this->deleteReportResultsByQuery($query, [\n 'team_id' => $team->getId(),\n 'retention_date' => $retentionDate->toDateTimeString(),\n ]);\n }\n\n /**\n * Delete ALL report results for a specific automated report\n *\n * @param string $uuid\n *\n * @return int\n */\n public function deleteReportResults(string $uuid): int\n {\n $report = $this->getReport($uuid);\n\n $query = $this->automatedReportsRepository->getResultsByReportQuery($report);\n\n return $this->deleteReportResultsByQuery($query, [\n 'report_uuid' => $uuid,\n 'report_id' => $report->getId(),\n ]);\n }\n\n public function deleteReportResult(AutomatedReportResult $result): void\n {\n $this->deleteS3Files($result);\n\n $result->delete();\n }\n\n /**\n * Get all reports for a specific team\n *\n * @param Team $team\n *\n * @return \\Illuminate\\Database\\Eloquent\\Collection\n */\n public function getTeamReports(Team $team): \\Illuminate\\Database\\Eloquent\\Collection\n {\n return $this->automatedReportsRepository->getReportsByTeam($team);\n }\n\n /**\n * Get all report results for a specific report\n *\n * @param AutomatedReport $report\n *\n * @return \\Illuminate\\Database\\Eloquent\\Collection\n */\n public function getReportResults(AutomatedReport $report): \\Illuminate\\Database\\Eloquent\\Collection\n {\n return $this->automatedReportsRepository->getResultsByReport($report);\n }\n\n public function deleteAllReportResults(AutomatedReport $report): void\n {\n $results = $this->getReportResults($report);\n\n /** @var AutomatedReportResult $result */\n foreach ($results as $result) {\n Log::info('Deleting result', [\n 'report' => $report->getId(),\n 'result' => $result->getId(),\n ]);\n\n $this->deleteReportResult($result);\n }\n }\n\n public function deleteAllData(Team $team): void\n {\n Log::info('Deleting automated report and results for team', [\n 'team' => $team->getId(),\n ]);\n\n $reports = $this->getTeamReports($team);\n\n /** @var AutomatedReport $report */\n foreach ($reports as $report) {\n Log::info('Deleting report', [\n 'team' => $team->getId(),\n 'report' => $report->getId(),\n ]);\n\n $this->deleteAllReportResults($report);\n\n $report->delete();\n }\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":true,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"Project","depth":3,"role_description":"text"},{"role":"AXButton","text":"Project","depth":3,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"New File or Directory…","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Expand Selected","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Collapse All","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Options","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false}]...
|
3397592283435315795
|
6686367547760219213
|
idle
|
accessibility
|
NULL
|
Project: faVsco.js, menu
#11894 on JY-18909-automa Project: faVsco.js, menu
#11894 on JY-18909-automated-reports-ask-jiminny, menu
Start Listening for PHP Debug Connections
AutomatedReportsCommandTest
Run 'AutomatedReportsCommandTest'
Debug 'AutomatedReportsCommandTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Execute
Explain Plan
Browse Query History
View Parameters
Open Query Execution Settings…
In-Editor Results
Tx: Auto
Cancel Running Statements
Playground
jiminny
Sync Changes
Hide This Notification
Code changed:
Hide
16
13
13
Previous Highlighted Error
Next Highlighted Error
SELECT * FROM teams WHERE id = 1;
select * from crm_layouts where crm_configuration_id = 39;
SELECT * FROM crm_layout_entities WHERE crm_layout_id = 283;
SELECT * FROM crm_fields WHERE id = 2234;
SELECT * FROM crm_field_values WHERE crm_field_id = 2234;
select * from crm_profiles where user_id = 143;
select * from record_types where crm_configuration_id = 39; # 0121K000001MHElQAO,0121K000001MHEqQAO
select * from business_processes where crm_configuration_id = 39;
# 01941000000H669AAC, 01941000000H66JAAS
select * from record_type_field_values
where record_type_id IN (24);
select * from crm_field_values where id IN (2730);
select * from crm_configurations where id = 39;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 1
and sa.provider = 'salesforce'; #1035
select * from users where team_id = 1; # 222 group 3
SELECT * FROM activities WHERE user_id = 222 order by id desc;
select * from sidekick_settings where team_id = 1;
select * from teams where id = 1;
select * from team_features where team_id = 1;
select * from activities where crm_configuration_id = 2
and provider = 'ms-teams' and id = 608765;
SELECT * FROM activities WHERE crm_configuration_id = 2 and crm_provider_id = '59523413338';
select * from sidekick_settings where team_id = 2;
SELECT * FROM activities WHERE id = 608660;
select * from activity_summary_logs where activity_id = 608660;
select * from ai_prompts where transcription_id = 11214;
# [PASSWORD_DOTS]
SELECT * FROM activities WHERE uuid_to_bin('ed78a437-2804-450e-ab2f-56ab1c641346') = uuid;
# id: 608818, crm: 59628809737
SELECT * FROM activities WHERE uuid_to_bin('36b06e55-afdd-4782-8dee-c624cd0af191') = uuid;
# id: 608821, crm: 59632069252
SELECT ce.start_time, ce.end_time, a.id, a.uuid, crm_provider_id, calendar_event_id, title,
playbook_category_id, user_id, lead_id, contact_id, account_id, opportunity_id,
scheduled_start_time, scheduled_end_time, actual_start_time, actual_end_time, a.created_at
FROM activities a
join calendar_events ce on a.calendar_event_id = ce.id
WHERE a.id IN (608818, 608821);
select * from users where team_id = 1;
select * from team_settings where team_id = 1;
select * from crm_profiles where crm_configuration_id = 39 order by user_id;
select * from team_features where team_id = 1;
select * from users where team_id = 2;
SELECT * FROM activities WHERE uuid_to_bin('ec7647e9-5225-458b-b475-f31aa2769204') = uuid; # 612639
# Preslava N. Ivanova, grou id 3
SELECT * FROM opportunities WHERE uuid_to_bin('a2928fe5-aec5-46cb-85d9-7654c89e46a6') = uuid;
select * from activities where opportunity_id = 344 and actual_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00';
select
a.id,
a.type,
a.scheduled_start_time,
a.actual_start_time,
a.created_at,
a.opportunity_id,
a.status
FROM activities a
WHERE opportunity_id = 344
and status IN ('completed', 'received', 'delivered')
and (
(a.actual_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00')
OR (a.created_at between '2024-10-11 00:00:00' and '2024-10-12 00:00:00')
OR (a.scheduled_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00'))
;
SELECT * FROM users WHERE id = 222;
SELECT * FROM crm_profiles WHERE user_id = 222;
select * from crm_layouts where crm_configuration_id = 39;
SELECT * FROM crm_layout_entities WHERE crm_layout_id = 281;
select * from group_deal_risk_types;
select * from opportunities where team_id = 1;
SELECT * FROM opportunities WHERE id = 315;
SELECT * FROM crm_field_data WHERE object_id = 315;
select * from crm_field_data where object_id = 260;
select * from generic_ai_prompts where subject_id = 315;
select * from teams; # 36, 21, 121, [EMAIL]
SELECT * FROM social_accounts WHERE sociable_id = 121 and provider = 'bullhorn';
# [PASSWORD_DOTS]
select * from teams where id = 1;
select * from crm_configurations where id = 39;
select * from users where team_id = 1;
select u.email, cp.* from users u
join crm_profiles cp on u.id = cp.user_id
where u.team_id = 1;
# 1 - 00541000004281rAAA
# 204 - 0052g000003freeAAA
# 429 - 0052g000003qGOiAAM
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 1
and sa.provider = 'salesforce';
select * from activities where type = 'softphone'
and created_at > '2024-12-11 15:24:36' order by id desc;
select * from activity_providers where team_id = 1;
select * from activity_provider_users where activity_provider_id = 328;
select * from opportunities where crm_configuration_id = 39
AND account_id = 178 AND is_closed = false
order by created_at DESC;
select * from contacts where id = 3952;
select * from accounts where id = 178;
# [PASSWORD_DOTS]
select * from teams where id = 36;
select * from crm_configurations where id = 21;
select * from users where team_id = 36;
select u.email, cp.* from users u
join crm_profiles cp on u.id = cp.user_id
where u.team_id = 36;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 36
and sa.provider = 'bullhorn';
select * from social_accounts where id = 348;
UPDATE social_accounts SET
provider_user_token = '21442_6802599_91:41179a58-21e7-4d7c-ad58-56bb666b2f65',
provider_refresh_token = '21442_6802599_91:01c6b335-3f2a-42e4-85ff-8a08fa65fceb',
expires = 1733998131,
state = 'connected'
WHERE id = 348;
# [PASSWORD_DOTS]
select * from teams where id = 31;
select * from crm_configurations where id = 18;
select * from users where team_id = 31; # 257
select u.email, cp.* from users u
join crm_profiles cp on u.id = cp.user_id
where u.team_id = 31;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 31
and sa.provider = 'close';
select * from contacts where crm_configuration_id = 18;
# [PASSWORD_DOTS] NEPTUNE [PASSWORD_DOTS]
select * from teams;
select * from users where id IN (1030, 1035, 1052);
select * from crm_configurations;
select * from users where team_id = 65; # 257
select * from team_settings where team_id = 65; # 257
select * from invitations where team_id = 65; # 257
select * from users where email = '[EMAIL]'; # 257
select u.email, cp.* from users u
join crm_profiles cp on u.id = cp.user_id
where u.team_id = 65;
select * from crm_configurations where id = 53;
select * from accounts where crm_configuration_id = 53 order by id desc;
select * from leads where crm_configuration_id = 53 order by id desc;
select * from contacts where crm_configuration_id = 53 order by id desc;
select * from opportunities where crm_configuration_id = 53 order by id desc;
select * from crm_profiles where crm_configuration_id = 53 order by id desc;
select * from crm_fields where crm_configuration_id = 53 order by id desc;
select * from crm_field_values where crm_field_id = 3341 order by id desc;
select * from crm_layouts where crm_configuration_id = 53 order by id desc;
select * from stages where crm_configuration_id = 53 order by id desc;
select * from crm_profiles where crm_configuration_id = 13;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 65
and sa.provider = 'integration-app';
select * from contacts where crm_configuration_id = 13;
select * from social_accounts where sociable_id = 283;
SELECT * FROM opportunities WHERE crm_provider_id = '006O400000E9bzeIAB';
select * from activity_providers where team_id = 65;
SELECT * FROM activities WHERE crm_configuration_id IN (51, 52, 53);
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 65
;
# [PASSWORD_DOTS] STAGING [PASSWORD_DOTS]
SELECT * FROM teams;
SELECT * FROM teams WHERE id = 88;
SELECT * FROM teams WHERE id = 89;
select * from team_settings where team_id = 89;
SELECT * FROM users WHERE team_id = 89;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 89;
select * from users;
SELECT * FROM social_accounts WHERE sociable_id = 1761;
SELECT * FROM crm_configurations WHERE id = 70;
select * from accounts where crm_configuration_id = 70 order by id desc;
select * from leads where crm_configuration_id = 70 order by id desc;
select * from contacts where crm_configuration_id = 70 order by id desc;
select * from opportunities where crm_configuration_id = 70 order by id desc;
select * from crm_profiles where crm_configuration_id = 70 order by id desc;
select * from crm_fields where crm_configuration_id = 70 order by id desc;
select * from crm_field_values where crm_field_id = 3536 order by id desc;
select * from crm_layouts where crm_configuration_id = 70 order by id desc;
select * from stages where crm_configuration_id = 70 order by id desc;
select * from business_processes where crm_configuration_id = 70 order by id desc;
select * from business_process_stages where business_process_id = 34;
select * from contacts where id = 10468;
select * from crm_layouts where crm_configuration_id = 70;
SELECT * FROM crm_layout_entities WHERE crm_layout_id = 388;
SELECT * FROM crm_fields WHERE id IN (3533,3534,3535);
select * from activities where crm_configuration_id = 70
and (account_id IS NOT NULL or lead_id IS NOT NULL or contact_id IS NOT NULL or opportunity_id IS NOT NULL) order by id desc;
SELECT * FROM activities WHERE uuid_to_bin('2e10b60f-8a61-41c5-a3d4-28835353dc65') = uuid;
SELECT * FROM activities where crm_configuration_id = 69 ;
SELECT * FROM users WHERE email LIKE '%[EMAIL]%';
SELECT * FROM activities WHERE uuid_to_bin('5a150c93-40fc-42ec-b3bd-c1d328e09f6e') = uuid;
SELECT * FROM opportunities WHERE id = 385;
select * from participants p
join activities a on p.activity_id = a.id
where a.crm_configuration_id = 70
and (p.lead_id IS NOT NULL or p.contact_id IS NOT NULL);
SELECT * FROM participants WHERE id = 1013638;
select * from teams where id = 90;
select * from users where team_id = 90;
select * from social_accounts where social_accounts.sociable_id IN (1960,1760);
SELECT * FROM crm_profiles WHERE crm_configuration_id = 71;
select * from invitations where team_id = 90;
select * from crm_configurations where id = 71;
select * from accounts where crm_configuration_id = 71 order by id desc;
select * from leads where crm_configuration_id = 71 order by id desc;
select * from contacts where crm_configuration_id = 71 order by id desc;
select * from opportunities where crm_configuration_id = 71 order by id desc;
select * from crm_profiles where crm_configuration_id = 71 order by id desc;
select * from crm_fields where crm_configuration_id = 71 order by id desc;
select * from crm_field_values where crm_field_id = 3341 order by id desc;
select * from crm_layouts where crm_configuration_id = 71 order by id desc;
select * from stages where crm_configuration_id = 71 order by id desc;
select * from users order by secondary_email desc;
select u.id, u.email, u.status, sa.id, sa.provider_user_id from social_accounts sa
join users u on sa.sociable_id = u.id
where sa.provider = 'google' and u.email LIKE 'aneliya%';
select * from failed_jobs order by id desc;
select * from users where email = '[EMAIL]' or secondary_email = '[EMAIL]';
select * from teams;
SELECT * FROM crm_profiles WHERE crm_configuration_id = 39;
SELECT * FROM crm_fields WHERE crm_configuration_id = 39 and object_type = 'task';
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 1
and sa.provider = 'salesforce';
# [PASSWORD_DOTS]
SELECT * FROM activities WHERE uuid_to_bin('c38b3895-fd0f-4b1f-9fb2-c170dba137c6') = uuid;
SELECT * FROM crm_configurations WHERE id = 70;
select * from teams where id = 1;
select * from groups where team_id = 1;
select * from users where team_id = 1;
select o.id, o.name,o.close_date, u.id, u.name, u.group_id, r.id, r.display_name, g.name, g.scope from opportunities o
join users u on o.user_id = u.id
join groups g on u.group_id = g.id
join role_user ru on u.id = ru.user_id
join roles r on ru.role_id = r.id
where o.crm_configuration_id = 39 and close_date > '2024-01-01 00:00:00';
select * from role_user where user_id = 143;
select * from roles;
select * from role_user;
select * from groups where id = 9;
select * from scope_groups where group_id = 9;
# [PASSWORD_DOTS]
select * from teams where id = 36;
select * from crm_configurations;
SELECT * FROM social_accounts WHERE sociable_id = 121;
[URL_WITH_CREDENTIALS] this will add filter, however if we need to control feature by FF we need conditional logic
public const array TYPES = [
['id' => 'exec_summary', 'name' => 'Exec Summary'],
['id' => 'coaching_profiles', 'name' => 'Coaching Profiles'],
['id' => 'product_feedback', 'name' => 'Product Feedback'],
['id' => self::TYPE_LOSS_ANALYSIS, 'name' => 'Loss Analysis'],
// ['id' => 'questions', 'name' => 'Questions'],
// ['id' => 'statistical_quant', 'name' => 'Statistical Quantitative'],
];
public const array ALL_TYPES = [
...self::TYPES,
['id' => self::TYPE_ASK_JIMINNY, 'name' => 'Ask Jiminny'],
];
public const string FREQUENCY_DAILY = 'daily';
public const string FREQUENCY_WEEKLY = 'weekly';
public const string FREQUENCY_MONTHLY = 'monthly';
public const string FREQUENCY_QUARTERLY = 'quarterly';
public const string FREQUENCY_ONE_OFF = 'one_off';
/**
* Frequencies for standard (non-Ask Jiminny) reports.
*/
public const array FREQUENCIES = [
['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],
['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],
['id' => self::FREQUENCY_QUARTERLY, 'name' => 'Quarterly'],
['id' => self::FREQUENCY_ONE_OFF, 'name' => 'One-off'],
];
/**
* Frequencies for Ask Jiminny reports.
*/
public const array ASK_JIMINNY_FREQUENCIES = [
['id' => self::FREQUENCY_DAILY, 'name' => 'Daily'],
['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],
['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],
];
public const string MEDIA_TYPE_PDF = 'pdf';
public const string MEDIA_TYPE_PODCAST = 'podcast';
public const array MEDIA_TYPES = [self::MEDIA_TYPE_PDF, self::MEDIA_TYPE_PODCAST];
public const array MEDIA_TYPE_OBJECT_PDF = ['id' => self::MEDIA_TYPE_PDF, 'name' => 'PDF'];
public const array MEDIA_TYPE_OBJECT_PODCAST = ['id' => self::MEDIA_TYPE_PODCAST, 'name' => 'Podcast'];
public const array MEDIA_TYPE_OBJECTS = [self::MEDIA_TYPE_OBJECT_PDF, self::MEDIA_TYPE_OBJECT_PODCAST];
public const array CALL_TYPE_CONFERENCE = ['id' => 'conference', 'name' => 'Conference'];
public const array CALL_TYPE_DIALER = ['id' => 'dialer', 'name' => 'Dialer'];
public const int SENT_REPORT_AT_HOURS = 5;
public const string PDF_KEY = 'pdf';
public const string AUDIO_KEY = 'audio';
private const array ALL_FREQUENCIES = [
['id' => self::FREQUENCY_DAILY, 'name' => 'Daily'],
['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],
['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],
['id' => self::FREQUENCY_QUARTERLY, 'name' => 'Quarterly'],
['id' => self::FREQUENCY_ONE_OFF, 'name' => 'One-off'],
];
private const string S3_DIR = 'reports';
private const array FILE_EXTENSIONS_VARIANTS = ['html', 'MD', 'pdf'];
private const array FILE_PODCAST_EXTENSIONS_VARIANTS = ['json', 'mp3', 'ssml'];
public function __construct(
private readonly TeamRepository $teamRepository,
private readonly GroupRepository $groupRepository,
private readonly UserRepository $userRepository,
private readonly StageRepository $stageRepository,
private readonly DealStagesService $dealStagesService,
private readonly RecipientsService $recipientsService,
private readonly AutomatedReportsRepository $automatedReportsRepository,
private readonly Webhook $webhookService,
private readonly BusDispatcher $dispatcher,
private readonly ActivityTypeService $activityTypeService,
private readonly PlaybookCategoryRepository $playbookCategoryRepository,
private readonly AskAnythingPromptService $askAnythingPromptService,
private readonly SearchRepository $activitySearchRepository,
private readonly AskAnythingRepository $askAnythingRepository,
) {
}
public static function getTypes(): array
{
$types = self::TYPES;
return array_map(static function ($type) {
return $type['id'];
}, $types);
}
public static function getCallTypes(): array
{
return array_map(static function ($callType) {
return $callType['id'];
}, [self::CALL_TYPE_CONFERENCE, self::CALL_TYPE_DIALER]);
}
public static function getFrequencies(): array
{
return array_map(static function ($frequency) {
return $frequency['id'];
}, self::FREQUENCIES);
}
// front-facing structure
public function getReportEnabledFieldData(bool $value = false): array
{
return [
'id' => 'report_enabled',
'label' => '',
'inputType' => InputTypeEnum::TOGGLE,
'value' => $value,
];
}
// Organizations = Teams
public function getOrganizationFieldData(?string $value = null, bool $shortVersion = false): array
{
$options = $this->getTeams();
if ($shortVersion) {
return [
'id' => 'organization',
'label' => 'Organization',
'options' => $options,
];
}
return [
'id' => 'organization',
'label' => 'Organization',
'inputType' => InputTypeEnum::DROPDOWN,
'required' => true,
'placeholder' => 'Select',
'options' => $options,
'value' => $value,
'dependencies' => [
'teams',
'deal_stage_at_call',
'current_deal_stage',
'recipients',
ActivityTypeService::PLAYBOOK_CATEGORIES_KEY,
],
'dependsOn' => [],
];
}
// Teams = Groups
public function getTeamFieldData(array $options = [], array $value = [], bool $shortVersion = false): array
{
if ($shortVersion) {
return [
'id' => 'teams',
'label' => 'Team',
'options' => $options,
];
}
return [
'id' => 'teams',
'label' => 'Team',
'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,
'required' => false,
'placeholder' => 'Select',
'options' => $options,
'value' => $value, // value should be an array of objects {id, name}
'dependencies' => [ActivityTypeService::PLAYBOOK_CATEGORIES_KEY],
'dependsOn' => [],
];
}
public function getReportTypeFieldData(?string $value = null, bool $shortVersion = false, ?Team $team = null): array
{
$types = [];
if ($team instanceof Team) {
if ($team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {
$types = self::TYPES;
}
if ($team->hasFeature(FeatureEnum::ASK_JIMINNY_REPORTS)) {
$types[] = ['id' => self::TYPE_ASK_JIMINNY, 'name' => 'Ask Jiminny'];
}
} else {
$types = self::TYPES;
}
if ($shortVersion) {
return [
'id' => 'report_type',
'label' => 'Report Type',
'options' => $types,
];
}
return [
'id' => 'report_type',
'label' => 'Report Type',
'inputType' => InputTypeEnum::DROPDOWN,
'required' => true,
'placeholder' => 'Select',
'options' => $types,
'value' => $value,
'dependencies' => [],
'dependsOn' => [],
];
}
public function getFrequencyFieldData(?string $value = null): array
{
return [
'id' => 'frequency',
'label' => 'Frequency',
'inputType' => InputTypeEnum::DROPDOWN,
'required' => true,
'placeholder' => 'Select',
'options' => self::FREQUENCIES,
'value' => $value,
'dependencies' => ['period'],
'dependsOn' => [],
];
}
public function getPeriodFieldData(?string $valueStartDate = null, ?string $valueEndDate = null): array
{
return [
'id' => 'period',
'label' => 'Select one-off period',
'inputType' => InputTypeEnum::DATE_RANGE,
'required' => true,
'placeholder' => 'Select',
'value' => ['startDate' => $valueStartDate, 'endDate' => $valueEndDate],
'queryParams' => [
'startDate' => 'start_date_period',
'endDate' => 'end_date_period',
],
'dependencies' => [],
'dependsOn' => ['frequency'],
];
}
public function getActivityTypesFieldData(?Team $team = null, array $value = [], array $teamsFilter = []): array
{
return $this->activityTypeService->getActivityTypeFieldData(team: $team, value: $value, groupIds: $teamsFilter);
}
public function getDealStageAtCallFieldData(?Team $team = null, array $value = []): array
{
return $this->dealStagesService->getDealStageAtCallFieldData(team: $team, value: $value);
}
public function getCurrentDealStageFieldData(?Team $team = null, array $value = []): array
{
return $this->dealStagesService->getCurrentDealStageFieldData(team: $team, value: $value);
}
public function getDealValueFieldData(?int $valueMin = null, ?int $valueMax = null): array
{
return [
'id' => 'deal_value',
'label' => 'Deal Value',
'inputType' => InputTypeEnum::INTEGER_RANGE,
'required' => false,
'value' => ['min' => $valueMin, 'max' => $valueMax],
'queryParams' => [
'min' => 'min_deal_value',
'max' => 'max_deal_value',
],
'dependencies' => [],
'dependsOn' => [],
];
}
public function getCallTypeFieldData(bool $conferenceOn = false, bool $dialerOn = false): array
{
$value = [];
$conferenceOn && $value[] = self::CALL_TYPE_CONFERENCE;
$dialerOn && $value[] = self::CALL_TYPE_DIALER;
return [
'id' => 'call_type',
'label' => 'Call Type',
'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,
'required' => true,
'options' => [
self::CALL_TYPE_CONFERENCE,
self::CALL_TYPE_DIALER,
],
'value' => $value,
'dependencies' => [],
'dependsOn' => [],
];
}
public function getMediaTypeFieldData(?AutomatedReport $report = null): array
{
$value = [];
if ($report) {
$value = $this->transformMediaTypes($report);
}
return [
'id' => 'media_types',
'label' => 'Export as',
'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,
'required' => true,
'options' => self::MEDIA_TYPE_OBJECTS,
'value' => $value,
'dependencies' => [],
'dependsOn' => [],
];
}
public function getCallDurationFieldData(?int $valueMin = null, ?int $valueMax = null): array
{
return [
'id' => 'call_duration',
'label' => 'Call Duration',
'inputType' => InputTypeEnum::INTEGER_RANGE,
'required' => false,
'value' => ['min' => $valueMin, 'max' => $valueMax],
'queryParams' => [
'min' => 'min_call_duration',
'max' => 'max_call_duration',
],
'dependencies' => [],
'dependsOn' => [],
];
}
public function getRecipientsFieldData(?Team $team = null, array $value = []): array
{
return $this->recipientsService->getRecipientsFieldData(team: $team, value: $value);
}
public function getJiminnyRecipientsFieldData(array $value = []): array
{
return $this->recipientsService->getJiminnyRecipientsFieldData($value);
}
public function getAdditionalPromptInputFieldData(?string $value = null): array
{
return [
'id' => 'additional_prompt_input',
'label' => 'Special requirements',
'inputType' => InputTypeEnum::TEXTAREA,
'required' => false,
'placeholder' => 'What should be the focus of the report?',
'value' => $value,
'dependencies' => [],
'dependsOn' => [],
];
}
public function getCustomReportNameFieldData(?string $value = null): array
{
return [
'id' => 'custom_name',
'label' => 'Custom report name',
'inputType' => InputTypeEnum::TEXT,
'required' => false,
'placeholder' => 'Enter custom name',
'value' => $value,
'dependencies' => [],
'dependsOn' => [],
];
}
// data providers
public function getTeams(): array
{
$teams = $this->teamRepository->getTeamsForKiosk(status: Team::STATUS_ACTIVE);
$teamData = [];
foreach ($teams as $team) {
if (! $team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {
continue;
}
$teamData[] = $this->transformTeam($team);
}
return $teamData;
}
public function getTeamGroups(string $teamUuid): array
{
$data = [];
$team = $this->getTeam($teamUuid);
if ($team !== null) {
$groups = $team->groups()->get();
foreach ($groups as $group) {
$data[] = [
'id' => $group->getUuid(),
'name' => $group->getName(),
];
}
}
return $data;
}
public function getTeamsGroupsOptions(array $filterTeamUuids = []): array
{
$data = [];
$teams = $this->getTeams();
foreach ($teams as $team) {
if (! empty($filterTeamUuids) && ! in_array($team['id'], $filterTeamUuids, true)) {
continue;
}
$data[] = [
'label' => $team['name'],
'groups' => $this->getTeamGroups($team['id']),
];
}
return $data;
}
public function getTeam(string $teamUuid): ?Team
{
return $this->teamRepository->idOrUuid($teamUuid);
}
public function getTeamById(int $teamId): ?Team
{
return $this->teamRepository->find($teamId);
}
public function getGroupsUuids(AutomatedReport $report): array
{
$uuids = [];
$reportGroups = $report->getGroups();
foreach ($reportGroups as $groupId) {
if ($group = $this->groupRepository->find($groupId)) {
$uuids[] = $group->getUuid();
}
}
return $uuids;
}
public function getPlaybookCategoriesUuids(AutomatedReport $report): array
{
$uuids = [];
$playbookCategories = $report->getPlaybookCategories();
foreach ($playbookCategories as $id) {
if ($category = $this->playbookCategoryRepository->find($id)) {
$uuids[] = $category->getUuid();
}
}
return $uuids;
}
public function getDealAtCallStagesUuids(AutomatedReport $report): array
{
$uuids = [];
$reportStages = $report->getDealAtCallStages();
foreach ($reportStages as $id) {
if ($stage = $this->stageRepository->find($id)) {
$uuids[] = $stage->getUuid();
}
}
return $uuids;
}
public function getCurrentDealStagesUuids(AutomatedReport $report): array
{
$uuids = [];
$reportStages = $report->getCurrentDealStages();
foreach ($reportStages as $id) {
if ($stage = $this->stageRepository->find($id)) {
$uuids[] = $stage->getUuid();
}
}
return $uuids;
}
public function getUsersUuids(AutomatedReport $report): array
{
return $this->extractUserUuids($report->getRecipients());
}
public function getJiminnyUsersUuids(AutomatedReport $report): array
{
return $this->extractUserUuids($report->getJiminnyRecipients());
}
/**
* @param array<string, mixed> $recipients
*/
private function extractUserUuids(array $recipients): array
{
$userIds = $recipients['users'] ?? [];
return collect($userIds)
->map(fn ($id) => $this->userRepository->find((int) $id))
->filter()
->map(fn (UserContract $user) => $user->getUuid())
->values()
->all();
}
// get mail data
public function getRecipientUsers(AutomatedReport $report): array
{
return $this->buildRecipientUsers($report->getRecipients());
}
private function getJiminnyRecipientUsers(AutomatedReport $report): array
{
return $this->buildRecipientUsers($report->getJiminnyRecipients());
}
/**
* @param array<string, mixed> $recipients
*/
private function buildRecipientUsers(array $recipients): array
{
$userIds = $recipients['users'] ?? [];
return collect($userIds)
->map(fn ($id) => $this->userRepository->find((int) $id))
->filter()
->map(fn (UserContract $user) => [
'email' => $user->getEmailAddress(),
'name' => $user->getName(),
'timezone' => $user->getTimezone()->getName(),
])
->values()
->all();
}
public function getValidRecipientUsers(AutomatedReport $report, bool $includeJiminny = false): array
{
if ($report->isAskJiminnyReport()) {
$recipients = $this->resolveAskJiminnyRecipients($report);
} else {
$recipients = $this->getRecipientUsers($report);
if ($includeJiminny) {
$recipients = array_merge($recipients, $this->getJiminnyRecipientUsers($report));
}
}
$emails = [];
return array_values(array_filter(
$recipients,
static function ($recipient) use (&$emails) {
if (empty($recipient['email']) || in_array($recipient['email'], $emails, true)) {
return false;
}
$emails[] = $recipient['email'];
return true;
}
));
}
private function resolveAskJiminnyRecipients(AutomatedReport $report): array
{
$recipients = [];
$creator = $report->getCreator();
if ($creator !== null) {
$recipients[] = [
'email' => $creator->getEmailAddress(),
'name' => $creator->getName(),
'timezone' => $creator->getTimezone()->getName(),
];
}
return array_merge(
$recipients,
$this->buildRecipientUsers($report->getRecipients()),
$this->getGroupRecipientUsers($report),
);
}
private function getGroupRecipientUsers(AutomatedReport $report): array
{
$users = [];
foreach ($report->getGroups() as $groupId) {
$group = $this->groupRepository->find($groupId);
if ($group === null) {
continue;
}
foreach ($group->getMembers() as $member) {
$users[] = [
'email' => $member->getEmailAddress(),
'name' => $member->getName(),
'timezone' => $member->getTimezone()->getName(),
];
}
}
return $users;
}
public function getReportTypeName(AutomatedReportResult $report): string
{
$type = $report->getReport()->getType();
$getType = $this->transformReportType($type);
return $getType['name'];
}
public function getReportPeriodName(AutomatedReportResult $report): string
{
$from = $report->getFromDate();
$to = $report->getToDate();
$frequency = $report->getReport()->getFrequency();
if ($from === null || $to === null) {
if (! $report->getReport()->isAskJiminnyReport()) {
$invalidPeriod = $from === null ? 'from' : 'to';
throw new ApplicationException('Report period is invalid: ' . $invalidPeriod);
}
$period = $this->calculateFromAndToDatePeriod($frequency);
$from = $period['fromDate'];
$to = $period['toDate'];
}
return $this->formatReportPeriodName($frequency, $from, $to);
}
private function formatReportPeriodName(string $frequency, Carbon $from, Carbon $to): string
{
$fromYear = $from->format('Y');
$toYear = $to->format('Y');
$differentYears = $fromYear !== $toYear;
switch ($frequency) {
case self::FREQUENCY_DAILY:
return $from->format('j M Y');
case self::FREQUENCY_QUARTERLY:
// 'Jan-Mar 2025' or 'Nov 2024-Jan 2025' if years differ
$startMonth = $from->format('M');
$endMonth = $to->copy()->subMonth();
$endMonthName = $endMonth->format('M');
$endMonthYear = $endMonth->format('Y');
if ($differentYears) {
return "{$startMonth} {$fromYear} - {$endMonthName} {$endMonthYear}";
}
return "{$startMonth} - {$endMonthName} {$toYear}";
case self::FREQUENCY_MONTHLY:
// 'May 2025' - monthly reports are always within the same year
return $from->format('M Y');
case self::FREQUENCY_WEEKLY:
// '4 - 8 Aug 2025', '27 Oct - 3 Nov 2025', or '28 Dec 2024 - 3 Jan 2025' if years differ
$startDay = $from->format('j');
$endDay = $to->format('j');
$startMonth = $from->format('M');
$endMonth = $to->format('M');
if ($differentYears) {
return "{$startDay} {$startMonth} {$fromYear} - {$endDay} {$endMonth} {$toYear}";
}
if ($startMonth !== $endMonth) {
return "{$startDay} {$startMonth} - {$endDay} {$endMonth} {$toYear}";
}
return "{$startDay} - {$endDay} {$endMonth} {$toYear}";
case self::FREQUENCY_ONE_OFF:
// '2 May-31 May 2025' or '15 Dec 2024-15 Jan 2025' if years differ
$startDay = $from->format('j');
$startMonth = $from->format('M');
$endDay = $to->format('j');
$endMonth = $to->format('M');
// If same month and year, use a format like '2-31 May 2025'
if ($startMonth === $endMonth && ! $differentYears) {
return "{$startDay} - {$endDay} {$startMonth} {$toYear}";
}
// If different years, include both years
if ($differentYears) {
return "{$startDay} {$startMonth} {$fromYear} - {$endDay} {$endMonth} {$toYear}";
}
// Same year but different months
return "{$startDay} {$startMonth} - {$endDay} {$endMonth} {$toYear}";
default:
// Default format for unknown frequencies
return $from->format('j M Y') . ' - ' . $to->format('j M Y');
}
}
public function getReportTeamsName(AutomatedReportResult $report): string
{
$groups = $report->getGroups();
if (empty($groups)) {
return 'All';
}
// Get group names from repository
$groupNames = [];
foreach ($groups as $groupId) {
$group = $this->groupRepository->find($groupId);
if ($group) {
$groupNames[] = $group->getName();
}
}
if (count($groupNames) === 1) {
// Single team format
$teamsName = $groupNames[0];
} else {
// Multiple teams format
$teamsName = implode(', ', $groupNames);
}
return $teamsName;
}
public function getReportFileName(AutomatedReportResult $report): string
...
|
12308
|
|
12317
|
260
|
36
|
2026-04-14T11:04:00.158649+00:00
|
/Users/lukas/.screenpipe/data/data/2026-04-14/1776 /Users/lukas/.screenpipe/data/data/2026-04-14/1776164640158_m1.jpg...
|
PhpStorm
|
faVsco.js – AutomatedReportsService.php
|
1
|
NULL
|
monitor_1
|
NULL
|
NULL
|
NULL
|
NULL
|
Project: faVsco.js, menu
#11894 on JY-18909-automa Project: faVsco.js, menu
#11894 on JY-18909-automated-reports-ask-jiminny, menu
Start Listening for PHP Debug Connections
AutomatedReportsCommandTest
Run 'AutomatedReportsCommandTest'
Debug 'AutomatedReportsCommandTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Execute
Explain Plan
Browse Query History
View Parameters
Open Query Execution Settings…
In-Editor Results
Tx: Auto
Cancel Running Statements
Playground
jiminny
Sync Changes
Hide This Notification
Code changed:
Hide
16
13
13
Previous Highlighted Error
Next Highlighted Error
SELECT * FROM teams WHERE id = 1;
select * from crm_layouts where crm_configuration_id = 39;
SELECT * FROM crm_layout_entities WHERE crm_layout_id = 283;
SELECT * FROM crm_fields WHERE id = 2234;
SELECT * FROM crm_field_values WHERE crm_field_id = 2234;
select * from crm_profiles where user_id = 143;
select * from record_types where crm_configuration_id = 39; # 0121K000001MHElQAO,0121K000001MHEqQAO
select * from business_processes where crm_configuration_id = 39;
# 01941000000H669AAC, 01941000000H66JAAS
select * from record_type_field_values
where record_type_id IN (24);
select * from crm_field_values where id IN (2730);
select * from crm_configurations where id = 39;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 1
and sa.provider = 'salesforce'; #1035
select * from users where team_id = 1; # 222 group 3
SELECT * FROM activities WHERE user_id = 222 order by id desc;
select * from sidekick_settings where team_id = 1;
select * from teams where id = 1;
select * from team_features where team_id = 1;
select * from activities where crm_configuration_id = 2
and provider = 'ms-teams' and id = 608765;
SELECT * FROM activities WHERE crm_configuration_id = 2 and crm_provider_id = '59523413338';
select * from sidekick_settings where team_id = 2;
SELECT * FROM activities WHERE id = 608660;
select * from activity_summary_logs where activity_id = 608660;
select * from ai_prompts where transcription_id = 11214;
# [PASSWORD_DOTS]
SELECT * FROM activities WHERE uuid_to_bin('ed78a437-2804-450e-ab2f-56ab1c641346') = uuid;
# id: 608818, crm: 59628809737
SELECT * FROM activities WHERE uuid_to_bin('36b06e55-afdd-4782-8dee-c624cd0af191') = uuid;
# id: 608821, crm: 59632069252
SELECT ce.start_time, ce.end_time, a.id, a.uuid, crm_provider_id, calendar_event_id, title,
playbook_category_id, user_id, lead_id, contact_id, account_id, opportunity_id,
scheduled_start_time, scheduled_end_time, actual_start_time, actual_end_time, a.created_at
FROM activities a
join calendar_events ce on a.calendar_event_id = ce.id
WHERE a.id IN (608818, 608821);
select * from users where team_id = 1;
select * from team_settings where team_id = 1;
select * from crm_profiles where crm_configuration_id = 39 order by user_id;
select * from team_features where team_id = 1;
select * from users where team_id = 2;
SELECT * FROM activities WHERE uuid_to_bin('ec7647e9-5225-458b-b475-f31aa2769204') = uuid; # 612639
# Preslava N. Ivanova, grou id 3
SELECT * FROM opportunities WHERE uuid_to_bin('a2928fe5-aec5-46cb-85d9-7654c89e46a6') = uuid;
select * from activities where opportunity_id = 344 and actual_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00';
select
a.id,
a.type,
a.scheduled_start_time,
a.actual_start_time,
a.created_at,
a.opportunity_id,
a.status
FROM activities a
WHERE opportunity_id = 344
and status IN ('completed', 'received', 'delivered')
and (
(a.actual_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00')
OR (a.created_at between '2024-10-11 00:00:00' and '2024-10-12 00:00:00')
OR (a.scheduled_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00'))
;
SELECT * FROM users WHERE id = 222;
SELECT * FROM crm_profiles WHERE user_id = 222;
select * from crm_layouts where crm_configuration_id = 39;
SELECT * FROM crm_layout_entities WHERE crm_layout_id = 281;
select * from group_deal_risk_types;
select * from opportunities where team_id = 1;
SELECT * FROM opportunities WHERE id = 315;
SELECT * FROM crm_field_data WHERE object_id = 315;
select * from crm_field_data where object_id = 260;
select * from generic_ai_prompts where subject_id = 315;
select * from teams; # 36, 21, 121, [EMAIL]
SELECT * FROM social_accounts WHERE sociable_id = 121 and provider = 'bullhorn';
# [PASSWORD_DOTS]
select * from teams where id = 1;
select * from crm_configurations where id = 39;
select * from users where team_id = 1;
select u.email, cp.* from users u
join crm_profiles cp on u.id = cp.user_id
where u.team_id = 1;
# 1 - 00541000004281rAAA
# 204 - 0052g000003freeAAA
# 429 - 0052g000003qGOiAAM
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 1
and sa.provider = 'salesforce';
select * from activities where type = 'softphone'
and created_at > '2024-12-11 15:24:36' order by id desc;
select * from activity_providers where team_id = 1;
select * from activity_provider_users where activity_provider_id = 328;
select * from opportunities where crm_configuration_id = 39
AND account_id = 178 AND is_closed = false
order by created_at DESC;
select * from contacts where id = 3952;
select * from accounts where id = 178;
# [PASSWORD_DOTS]
select * from teams where id = 36;
select * from crm_configurations where id = 21;
select * from users where team_id = 36;
select u.email, cp.* from users u
join crm_profiles cp on u.id = cp.user_id
where u.team_id = 36;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 36
and sa.provider = 'bullhorn';
select * from social_accounts where id = 348;
UPDATE social_accounts SET
provider_user_token = '21442_6802599_91:41179a58-21e7-4d7c-ad58-56bb666b2f65',
provider_refresh_token = '21442_6802599_91:01c6b335-3f2a-42e4-85ff-8a08fa65fceb',
expires = 1733998131,
state = 'connected'
WHERE id = 348;
# [PASSWORD_DOTS]
select * from teams where id = 31;
select * from crm_configurations where id = 18;
select * from users where team_id = 31; # 257
select u.email, cp.* from users u
join crm_profiles cp on u.id = cp.user_id
where u.team_id = 31;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 31
and sa.provider = 'close';
select * from contacts where crm_configuration_id = 18;
# [PASSWORD_DOTS] NEPTUNE [PASSWORD_DOTS]
select * from teams;
select * from users where id IN (1030, 1035, 1052);
select * from crm_configurations;
select * from users where team_id = 65; # 257
select * from team_settings where team_id = 65; # 257
select * from invitations where team_id = 65; # 257
select * from users where email = '[EMAIL]'; # 257
select u.email, cp.* from users u
join crm_profiles cp on u.id = cp.user_id
where u.team_id = 65;
select * from crm_configurations where id = 53;
select * from accounts where crm_configuration_id = 53 order by id desc;
select * from leads where crm_configuration_id = 53 order by id desc;
select * from contacts where crm_configuration_id = 53 order by id desc;
select * from opportunities where crm_configuration_id = 53 order by id desc;
select * from crm_profiles where crm_configuration_id = 53 order by id desc;
select * from crm_fields where crm_configuration_id = 53 order by id desc;
select * from crm_field_values where crm_field_id = 3341 order by id desc;
select * from crm_layouts where crm_configuration_id = 53 order by id desc;
select * from stages where crm_configuration_id = 53 order by id desc;
select * from crm_profiles where crm_configuration_id = 13;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 65
and sa.provider = 'integration-app';
select * from contacts where crm_configuration_id = 13;
select * from social_accounts where sociable_id = 283;
SELECT * FROM opportunities WHERE crm_provider_id = '006O400000E9bzeIAB';
select * from activity_providers where team_id = 65;
SELECT * FROM activities WHERE crm_configuration_id IN (51, 52, 53);
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 65
;
# [PASSWORD_DOTS] STAGING [PASSWORD_DOTS]
SELECT * FROM teams;
SELECT * FROM teams WHERE id = 88;
SELECT * FROM teams WHERE id = 89;
select * from team_settings where team_id = 89;
SELECT * FROM users WHERE team_id = 89;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 89;
select * from users;
SELECT * FROM social_accounts WHERE sociable_id = 1761;
SELECT * FROM crm_configurations WHERE id = 70;
select * from accounts where crm_configuration_id = 70 order by id desc;
select * from leads where crm_configuration_id = 70 order by id desc;
select * from contacts where crm_configuration_id = 70 order by id desc;
select * from opportunities where crm_configuration_id = 70 order by id desc;
select * from crm_profiles where crm_configuration_id = 70 order by id desc;
select * from crm_fields where crm_configuration_id = 70 order by id desc;
select * from crm_field_values where crm_field_id = 3536 order by id desc;
select * from crm_layouts where crm_configuration_id = 70 order by id desc;
select * from stages where crm_configuration_id = 70 order by id desc;
select * from business_processes where crm_configuration_id = 70 order by id desc;
select * from business_process_stages where business_process_id = 34;
select * from contacts where id = 10468;
select * from crm_layouts where crm_configuration_id = 70;
SELECT * FROM crm_layout_entities WHERE crm_layout_id = 388;
SELECT * FROM crm_fields WHERE id IN (3533,3534,3535);
select * from activities where crm_configuration_id = 70
and (account_id IS NOT NULL or lead_id IS NOT NULL or contact_id IS NOT NULL or opportunity_id IS NOT NULL) order by id desc;
SELECT * FROM activities WHERE uuid_to_bin('2e10b60f-8a61-41c5-a3d4-28835353dc65') = uuid;
SELECT * FROM activities where crm_configuration_id = 69 ;
SELECT * FROM users WHERE email LIKE '%[EMAIL]%';
SELECT * FROM activities WHERE uuid_to_bin('5a150c93-40fc-42ec-b3bd-c1d328e09f6e') = uuid;
SELECT * FROM opportunities WHERE id = 385;
select * from participants p
join activities a on p.activity_id = a.id
where a.crm_configuration_id = 70
and (p.lead_id IS NOT NULL or p.contact_id IS NOT NULL);
SELECT * FROM participants WHERE id = 1013638;
select * from teams where id = 90;
select * from users where team_id = 90;
select * from social_accounts where social_accounts.sociable_id IN (1960,1760);
SELECT * FROM crm_profiles WHERE crm_configuration_id = 71;
select * from invitations where team_id = 90;
select * from crm_configurations where id = 71;
select * from accounts where crm_configuration_id = 71 order by id desc;
select * from leads where crm_configuration_id = 71 order by id desc;
select * from contacts where crm_configuration_id = 71 order by id desc;
select * from opportunities where crm_configuration_id = 71 order by id desc;
select * from crm_profiles where crm_configuration_id = 71 order by id desc;
select * from crm_fields where crm_configuration_id = 71 order by id desc;
select * from crm_field_values where crm_field_id = 3341 order by id desc;
select * from crm_layouts where crm_configuration_id = 71 order by id desc;
select * from stages where crm_configuration_id = 71 order by id desc;
select * from users order by secondary_email desc;
select u.id, u.email, u.status, sa.id, sa.provider_user_id from social_accounts sa
join users u on sa.sociable_id = u.id
where sa.provider = 'google' and u.email LIKE 'aneliya%';
select * from failed_jobs order by id desc;
select * from users where email = '[EMAIL]' or secondary_email = '[EMAIL]';
select * from teams;
SELECT * FROM crm_profiles WHERE crm_configuration_id = 39;
SELECT * FROM crm_fields WHERE crm_configuration_id = 39 and object_type = 'task';
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 1
and sa.provider = 'salesforce';
# [PASSWORD_DOTS]
SELECT * FROM activities WHERE uuid_to_bin('c38b3895-fd0f-4b1f-9fb2-c170dba137c6') = uuid;
SELECT * FROM crm_configurations WHERE id = 70;
select * from teams where id = 1;
select * from groups where team_id = 1;
select * from users where team_id = 1;
select o.id, o.name,o.close_date, u.id, u.name, u.group_id, r.id, r.display_name, g.name, g.scope from opportunities o
join users u on o.user_id = u.id
join groups g on u.group_id = g.id
join role_user ru on u.id = ru.user_id
join roles r on ru.role_id = r.id
where o.crm_configuration_id = 39 and close_date > '2024-01-01 00:00:00';
select * from role_user where user_id = 143;
select * from roles;
select * from role_user;
select * from groups where id = 9;
select * from scope_groups where group_id = 9;
# [PASSWORD_DOTS]
select * from teams where id = 36;
select * from crm_configurations;
SELECT * FROM social_accounts WHERE sociable_id = 121;
[URL_WITH_CREDENTIALS] this will add filter, however if we need to control feature by FF we need conditional logic
public const array TYPES = [
['id' => 'exec_summary', 'name' => 'Exec Summary'],
['id' => 'coaching_profiles', 'name' => 'Coaching Profiles'],
['id' => 'product_feedback', 'name' => 'Product Feedback'],
['id' => self::TYPE_LOSS_ANALYSIS, 'name' => 'Loss Analysis'],
// ['id' => 'questions', 'name' => 'Questions'],
// ['id' => 'statistical_quant', 'name' => 'Statistical Quantitative'],
];
public const array ALL_TYPES = [
...self::TYPES,
['id' => self::TYPE_ASK_JIMINNY, 'name' => 'Ask Jiminny'],
];
public const string FREQUENCY_DAILY = 'daily';
public const string FREQUENCY_WEEKLY = 'weekly';
public const string FREQUENCY_MONTHLY = 'monthly';
public const string FREQUENCY_QUARTERLY = 'quarterly';
public const string FREQUENCY_ONE_OFF = 'one_off';
/**
* Frequencies for standard (non-Ask Jiminny) reports.
*/
public const array FREQUENCIES = [
['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],
['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],
['id' => self::FREQUENCY_QUARTERLY, 'name' => 'Quarterly'],
['id' => self::FREQUENCY_ONE_OFF, 'name' => 'One-off'],
];
/**
* Frequencies for Ask Jiminny reports.
*/
public const array ASK_JIMINNY_FREQUENCIES = [
['id' => self::FREQUENCY_DAILY, 'name' => 'Daily'],
['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],
['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],
];
public const string MEDIA_TYPE_PDF = 'pdf';
public const string MEDIA_TYPE_PODCAST = 'podcast';
public const array MEDIA_TYPES = [self::MEDIA_TYPE_PDF, self::MEDIA_TYPE_PODCAST];
public const array MEDIA_TYPE_OBJECT_PDF = ['id' => self::MEDIA_TYPE_PDF, 'name' => 'PDF'];
public const array MEDIA_TYPE_OBJECT_PODCAST = ['id' => self::MEDIA_TYPE_PODCAST, 'name' => 'Podcast'];
public const array MEDIA_TYPE_OBJECTS = [self::MEDIA_TYPE_OBJECT_PDF, self::MEDIA_TYPE_OBJECT_PODCAST];
public const array CALL_TYPE_CONFERENCE = ['id' => 'conference', 'name' => 'Conference'];
public const array CALL_TYPE_DIALER = ['id' => 'dialer', 'name' => 'Dialer'];
public const int SENT_REPORT_AT_HOURS = 5;
public const string PDF_KEY = 'pdf';
public const string AUDIO_KEY = 'audio';
private const array ALL_FREQUENCIES = [
['id' => self::FREQUENCY_DAILY, 'name' => 'Daily'],
['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],
['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],
['id' => self::FREQUENCY_QUARTERLY, 'name' => 'Quarterly'],
['id' => self::FREQUENCY_ONE_OFF, 'name' => 'One-off'],
];
private const string S3_DIR = 'reports';
private const array FILE_EXTENSIONS_VARIANTS = ['html', 'MD', 'pdf'];
private const array FILE_PODCAST_EXTENSIONS_VARIANTS = ['json', 'mp3', 'ssml'];
public function __construct(
private readonly TeamRepository $teamRepository,
private readonly GroupRepository $groupRepository,
private readonly UserRepository $userRepository,
private readonly StageRepository $stageRepository,
private readonly DealStagesService $dealStagesService,
private readonly RecipientsService $recipientsService,
private readonly AutomatedReportsRepository $automatedReportsRepository,
private readonly Webhook $webhookService,
private readonly BusDispatcher $dispatcher,
private readonly ActivityTypeService $activityTypeService,
private readonly PlaybookCategoryRepository $playbookCategoryRepository,
private readonly AskAnythingPromptService $askAnythingPromptService,
private readonly SearchRepository $activitySearchRepository,
private readonly AskAnythingRepository $askAnythingRepository,
) {
}
public static function getTypes(): array
{
$types = self::TYPES;
return array_map(static function ($type) {
return $type['id'];
}, $types);
}
public static function getCallTypes(): array
{
return array_map(static function ($callType) {
return $callType['id'];
}, [self::CALL_TYPE_CONFERENCE, self::CALL_TYPE_DIALER]);
}
public static function getFrequencies(): array
{
return array_map(static function ($frequency) {
return $frequency['id'];
}, self::FREQUENCIES);
}
// front-facing structure
public function getReportEnabledFieldData(bool $value = false): array
{
return [
'id' => 'report_enabled',
'label' => '',
'inputType' => InputTypeEnum::TOGGLE,
'value' => $value,
];
}
// Organizations = Teams
public function getOrganizationFieldData(?string $value = null, bool $shortVersion = false): array
{
$options = $this->getTeams();
if ($shortVersion) {
return [
'id' => 'organization',
'label' => 'Organization',
'options' => $options,
];
}
return [
'id' => 'organization',
'label' => 'Organization',
'inputType' => InputTypeEnum::DROPDOWN,
'required' => true,
'placeholder' => 'Select',
'options' => $options,
'value' => $value,
'dependencies' => [
'teams',
'deal_stage_at_call',
'current_deal_stage',
'recipients',
ActivityTypeService::PLAYBOOK_CATEGORIES_KEY,
],
'dependsOn' => [],
];
}
// Teams = Groups
public function getTeamFieldData(array $options = [], array $value = [], bool $shortVersion = false): array
{
if ($shortVersion) {
return [
'id' => 'teams',
'label' => 'Team',
'options' => $options,
];
}
return [
'id' => 'teams',
'label' => 'Team',
'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,
'required' => false,
'placeholder' => 'Select',
'options' => $options,
'value' => $value, // value should be an array of objects {id, name}
'dependencies' => [ActivityTypeService::PLAYBOOK_CATEGORIES_KEY],
'dependsOn' => [],
];
}
public function getReportTypeFieldData(?string $value = null, bool $shortVersion = false, ?Team $team = null): array
{
$types = [];
if ($team instanceof Team) {
if ($team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {
$types = self::TYPES;
}
if ($team->hasFeature(FeatureEnum::ASK_JIMINNY_REPORTS)) {
$types[] = ['id' => self::TYPE_ASK_JIMINNY, 'name' => 'Ask Jiminny'];
}
} else {
$types = self::TYPES;
}
if ($shortVersion) {
return [
'id' => 'report_type',
'label' => 'Report Type',
'options' => $types,
];
}
return [
'id' => 'report_type',
'label' => 'Report Type',
'inputType' => InputTypeEnum::DROPDOWN,
'required' => true,
'placeholder' => 'Select',
'options' => $types,
'value' => $value,
'dependencies' => [],
'dependsOn' => [],
];
}
public function getFrequencyFieldData(?string $value = null): array
{
return [
'id' => 'frequency',
'label' => 'Frequency',
'inputType' => InputTypeEnum::DROPDOWN,
'required' => true,
'placeholder' => 'Select',
'options' => self::FREQUENCIES,
'value' => $value,
'dependencies' => ['period'],
'dependsOn' => [],
];
}
public function getPeriodFieldData(?string $valueStartDate = null, ?string $valueEndDate = null): array
{
return [
'id' => 'period',
'label' => 'Select one-off period',
'inputType' => InputTypeEnum::DATE_RANGE,
'required' => true,
'placeholder' => 'Select',
'value' => ['startDate' => $valueStartDate, 'endDate' => $valueEndDate],
'queryParams' => [
'startDate' => 'start_date_period',
'endDate' => 'end_date_period',
],
'dependencies' => [],
'dependsOn' => ['frequency'],
];
}
public function getActivityTypesFieldData(?Team $team = null, array $value = [], array $teamsFilter = []): array
{
return $this->activityTypeService->getActivityTypeFieldData(team: $team, value: $value, groupIds: $teamsFilter);
}
public function getDealStageAtCallFieldData(?Team $team = null, array $value = []): array
{
return $this->dealStagesService->getDealStageAtCallFieldData(team: $team, value: $value);
}
public function getCurrentDealStageFieldData(?Team $team = null, array $value = []): array
{
return $this->dealStagesService->getCurrentDealStageFieldData(team: $team, value: $value);
}
public function getDealValueFieldData(?int $valueMin = null, ?int $valueMax = null): array
{
return [
'id' => 'deal_value',
'label' => 'Deal Value',
'inputType' => InputTypeEnum::INTEGER_RANGE,
'required' => false,
'value' => ['min' => $valueMin, 'max' => $valueMax],
'queryParams' => [
'min' => 'min_deal_value',
'max' => 'max_deal_value',
],
'dependencies' => [],
'dependsOn' => [],
];
}
public function getCallTypeFieldData(bool $conferenceOn = false, bool $dialerOn = false): array
{
$value = [];
$conferenceOn && $value[] = self::CALL_TYPE_CONFERENCE;
$dialerOn && $value[] = self::CALL_TYPE_DIALER;
return [
'id' => 'call_type',
'label' => 'Call Type',
'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,
'required' => true,
'options' => [
self::CALL_TYPE_CONFERENCE,
self::CALL_TYPE_DIALER,
],
'value' => $value,
'dependencies' => [],
'dependsOn' => [],
];
}
public function getMediaTypeFieldData(?AutomatedReport $report = null): array
{
$value = [];
if ($report) {
$value = $this->transformMediaTypes($report);
}
return [
'id' => 'media_types',
'label' => 'Export as',
'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,
'required' => true,
'options' => self::MEDIA_TYPE_OBJECTS,
'value' => $value,
'dependencies' => [],
'dependsOn' => [],
];
}
public function getCallDurationFieldData(?int $valueMin = null, ?int $valueMax = null): array
{
return [
'id' => 'call_duration',
'label' => 'Call Duration',
'inputType' => InputTypeEnum::INTEGER_RANGE,
'required' => false,
'value' => ['min' => $valueMin, 'max' => $valueMax],
'queryParams' => [
'min' => 'min_call_duration',
'max' => 'max_call_duration',
],
'dependencies' => [],
'dependsOn' => [],
];
}
public function getRecipientsFieldData(?Team $team = null, array $value = []): array
{
return $this->recipientsService->getRecipientsFieldData(team: $team, value: $value);
}
public function getJiminnyRecipientsFieldData(array $value = []): array
{
return $this->recipientsService->getJiminnyRecipientsFieldData($value);
}
public function getAdditionalPromptInputFieldData(?string $value = null): array
{
return [
'id' => 'additional_prompt_input',
'label' => 'Special requirements',
'inputType' => InputTypeEnum::TEXTAREA,
'required' => false,
'placeholder' => 'What should be the focus of the report?',
'value' => $value,
'dependencies' => [],
'dependsOn' => [],
];
}
public function getCustomReportNameFieldData(?string $value = null): array
{
return [
'id' => 'custom_name',
'label' => 'Custom report name',
'inputType' => InputTypeEnum::TEXT,
'required' => false,
'placeholder' => 'Enter custom name',
'value' => $value,
'dependencies' => [],
'dependsOn' => [],
];
}
// data providers
public function getTeams(): array
{
$teams = $this->teamRepository->getTeamsForKiosk(status: Team::STATUS_ACTIVE);
$teamData = [];
foreach ($teams as $team) {
if (! $team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {
continue;
}
$teamData[] = $this->transformTeam($team);
}
return $teamData;
}
public function getTeamGroups(string $teamUuid): array
{
$data = [];
$team = $this->getTeam($teamUuid);
if ($team !== null) {
$groups = $team->groups()->get();
foreach ($groups as $group) {
$data[] = [
'id' => $group->getUuid(),
'name' => $group->getName(),
];
}
}
return $data;
}
public function getTeamsGroupsOptions(array $filterTeamUuids = []): array
{
$data = [];
$teams = $this->getTeams();
foreach ($teams as $team) {
if (! empty($filterTeamUuids) && ! in_array($team['id'], $filterTeamUuids, true)) {
continue;
}
$data[] = [
'label' => $team['name'],
'groups' => $this->getTeamGroups($team['id']),
];
}
return $data;
}
public function getTeam(string $teamUuid): ?Team
{
return $this->teamRepository->idOrUuid($teamUuid);
}
public function getTeamById(int $teamId): ?Team
{
return $this->teamRepository->find($teamId);
}
public function getGroupsUuids(AutomatedReport $report): array
{
$uuids = [];
$reportGroups = $report->getGroups();
foreach ($reportGroups as $groupId) {
if ($group = $this->groupRepository->find($groupId)) {
$uuids[] = $group->getUuid();
}
}
return $uuids;
}
public function getPlaybookCategoriesUuids(AutomatedReport $report): array
{
$uuids = [];
$playbookCategories = $report->getPlaybookCategories();
foreach ($playbookCategories as $id) {
if ($category = $this->playbookCategoryRepository->find($id)) {
$uuids[] = $category->getUuid();
}
}
return $uuids;
}
public function getDealAtCallStagesUuids(AutomatedReport $report): array
{
$uuids = [];
$reportStages = $report->getDealAtCallStages();
foreach ($reportStages as $id) {
if ($stage = $this->stageRepository->find($id)) {
$uuids[] = $stage->getUuid();
}
}
return $uuids;
}
public function getCurrentDealStagesUuids(AutomatedReport $report): array
{
$uuids = [];
$reportStages = $report->getCurrentDealStages();
foreach ($reportStages as $id) {
if ($stage = $this->stageRepository->find($id)) {
$uuids[] = $stage->getUuid();
}
}
return $uuids;
}
public function getUsersUuids(AutomatedReport $report): array
{
return $this->extractUserUuids($report->getRecipients());
}
public function getJiminnyUsersUuids(AutomatedReport $report): array
{
return $this->extractUserUuids($report->getJiminnyRecipients());
}
/**
* @param array<string, mixed> $recipients
*/
private function extractUserUuids(array $recipients): array
{
$userIds = $recipients['users'] ?? [];
return collect($userIds)
->map(fn ($id) => $this->userRepository->find((int) $id))
->filter()
->map(fn (UserContract $user) => $user->getUuid())
->values()
->all();
}
// get mail data
public function getRecipientUsers(AutomatedReport $report): array
{
return $this->buildRecipientUsers($report->getRecipients());
}
private function getJiminnyRecipientUsers(AutomatedReport $report): array
{
return $this->buildRecipientUsers($report->getJiminnyRecipients());
}
/**
* @param array<string, mixed> $recipients
*/
private function buildRecipientUsers(array $recipients): array
{
$userIds = $recipients['users'] ?? [];
return collect($userIds)
->map(fn ($id) => $this->userRepository->find((int) $id))
->filter()
->map(fn (UserContract $user) => [
'email' => $user->getEmailAddress(),
'name' => $user->getName(),
'timezone' => $user->getTimezone()->getName(),
])
->values()
->all();
}
public function getValidRecipientUsers(AutomatedReport $report, bool $includeJiminny = false): array
{
if ($report->isAskJiminnyReport()) {
$recipients = $this->resolveAskJiminnyRecipients($report);
} else {
$recipients = $this->getRecipientUsers($report);
if ($includeJiminny) {
$recipients = array_merge($recipients, $this->getJiminnyRecipientUsers($report));
}
}
$emails = [];
return array_values(array_filter(
$recipients,
static function ($recipient) use (&$emails) {
if (empty($recipient['email']) || in_array($recipient['email'], $emails, true)) {
return false;
}
$emails[] = $recipient['email'];
return true;
}
));
}
private function resolveAskJiminnyRecipients(AutomatedReport $report): array
{
$recipients = [];
$creator = $report->getCreator();
if ($creator !== null) {
$recipients[] = [
'email' => $creator->getEmailAddress(),
'name' => $creator->getName(),
'timezone' => $creator->getTimezone()->getName(),
];
}
return array_merge(
$recipients,
$this->buildRecipientUsers($report->getRecipients()),
$this->getGroupRecipientUsers($report),
);
}
private function getGroupRecipientUsers(AutomatedReport $report): array
{
$users = [];
foreach ($report->getGroups() as $groupId) {
$group = $this->groupRepository->find($groupId);
if ($group === null) {
continue;
}
foreach ($group->getMembers() as $member) {
$users[] = [
'email' => $member->getEmailAddress(),
'name' => $member->getName(),
'timezone' => $member->getTimezone()->getName(),
];
}
}
return $users;
}
public function getReportTypeName(AutomatedReportResult $report): string
{
$type = $report->getReport()->getType();
$getType = $this->transformReportType($type);
return $getType['name'];
}
public function getReportPeriodName(AutomatedReportResult $report): string
{
$from = $report->getFromDate();
$to = $report->getToDate();
$frequency = $report->getReport()->getFrequency();
if ($from === null || $to === null) {
if (! $report->getReport()->isAskJiminnyReport()) {
$invalidPeriod = $from === null ? 'from' : 'to';
throw new ApplicationException('Report period is invalid: ' . $invalidPeriod);
}
$period = $this->calculateFromAndToDatePeriod($frequency);
$from = $period['fromDate'];
$to = $period['toDate'];
}
return $this->formatReportPeriodName($frequency, $from, $to);
}
private function formatReportPeriodName(string $frequency, Carbon $from, Carbon $to): string
{
$fromYear = $from->format('Y');
$toYear = $to->format('Y');
$differentYears = $fromYear !== $toYear;
switch ($frequency) {
case self::FREQUENCY_DAILY:
return $from->format('j M Y');
case self::FREQUENCY_QUARTERLY:
// 'Jan-Mar 2025' or 'Nov 2024-Jan 2025' if years differ
$startMonth = $from->format('M');
$endMonth = $to->copy()->subMonth();
$endMonthName = $endMonth->format('M');
$endMonthYear = $endMonth->format('Y');
if ($differentYears) {
return "{$startMonth} {$fromYear} - {$endMonthName} {$endMonthYear}";
}
return "{$startMonth} - {$endMonthName} {$toYear}";
case self::FREQUENCY_MONTHLY:
// 'May 2025' - monthly reports are always within the same year
return $from->format('M Y');
case self::FREQUENCY_WEEKLY:
// '4 - 8 Aug 2025', '27 Oct - 3 Nov 2025', or '28 Dec 2024 - 3 Jan 2025' if years differ
$startDay = $from->format('j');
$endDay = $to->format('j');
$startMonth = $from->format('M');
$endMonth = $to->format('M');
if ($differentYears) {
return "{$startDay} {$startMonth} {$fromYear} - {$endDay} {$endMonth} {$toYear}";
}
if ($startMonth !== $endMonth) {
return "{$startDay} {$startMonth} - {$endDay} {$endMonth} {$toYear}";
}
return "{$startDay} - {$endDay} {$endMonth} {$toYear}";
case self::FREQUENCY_ONE_OFF:
// '2 May-31 May 2025' or '15 Dec 2024-15 Jan 2025' if years differ
$startDay = $from->format('j');
$startMonth = $from->format('M');
$endDay = $to->format('j');
$endMonth = $to->format('M');
// If same month and year, use a format like '2-31 May 2025'
if ($startMonth === $endMonth && ! $differentYears) {
return "{$startDay} - {$endDay} {$startMonth} {$toYear}";
}
// If different years, include both years
if ($differentYears) {
return "{$startDay} {$startMonth} {$fromYear} - {$endDay} {$endMonth} {$toYear}";
}
// Same year but different months
return "{$startDay} {$startMonth} - {$endDay} {$endMonth} {$toYear}";
default:
// Default format for unknown frequencies
return $from->format('j M Y') . ' - ' . $to->format('j M Y');
}
}
public function getReportTeamsName(AutomatedReportResult $report): string
{
$groups = $report->getGroups();
if (empty($groups)) {
return 'All';
}
// Get group names from repository
$groupNames = [];
foreach ($groups as $groupId) {
$group = $this->groupRepository->find($groupId);
if ($group) {
$groupNames[] = $group->getName();
}
}
if (count($groupNames) === 1) {
// Single team format
$teamsName = $groupNames[0];
} else {
// Multiple teams format
$teamsName = implode(', ', $groupNames);
}
return $teamsName;
}
public function getReportFileName(AutomatedReportResult $report): string
...
|
[{"role":"AXButton","text" [{"role":"AXButton","text":"Project: faVsco.js, menu","depth":5,"help_text":"~/jiminny/app","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"#11894 on JY-18909-automated-reports-ask-jiminny, menu","depth":5,"help_text":"Pull request #11894 exists for current branch JY-18909-automated-reports-ask-jiminny","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Start Listening for PHP Debug Connections","depth":5,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"AutomatedReportsCommandTest","depth":6,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Run 'AutomatedReportsCommandTest'","depth":6,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Debug 'AutomatedReportsCommandTest'","depth":6,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"More Actions","depth":6,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JetBrains AI","depth":5,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Search Everywhere","depth":5,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"IDE and Project Settings","depth":5,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Execute","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Explain Plan","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Browse Query History","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"View Parameters","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Open Query Execution Settings…","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"In-Editor Results","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Tx: Auto","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Cancel Running Statements","depth":4,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Playground","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"jiminny","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.088194445,"height":0.027777778},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"16","depth":4,"role_description":"text"},{"role":"AXStaticText","text":"13","depth":4,"role_description":"text"},{"role":"AXStaticText","text":"13","depth":4,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"SELECT * FROM teams WHERE id = 1;\n\nselect * from crm_layouts where crm_configuration_id = 39;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 283;\nSELECT * FROM crm_fields WHERE id = 2234;\nSELECT * FROM crm_field_values WHERE crm_field_id = 2234;\n\nselect * from crm_profiles where user_id = 143;\n\nselect * from record_types where crm_configuration_id = 39; # 0121K000001MHElQAO,0121K000001MHEqQAO\nselect * from business_processes where crm_configuration_id = 39;\n# 01941000000H669AAC, 01941000000H66JAAS\n\nselect * from record_type_field_values\n where record_type_id IN (24);\n\nselect * from crm_field_values where id IN (2730);\n\nselect * from crm_configurations where id = 39;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 1\nand sa.provider = 'salesforce'; #1035\n\n\nselect * from users where team_id = 1; # 222 group 3\nSELECT * FROM activities WHERE user_id = 222 order by id desc;\nselect * from sidekick_settings where team_id = 1;\nselect * from teams where id = 1;\nselect * from team_features where team_id = 1;\n\nselect * from activities where crm_configuration_id = 2\nand provider = 'ms-teams' and id = 608765;\n\nSELECT * FROM activities WHERE crm_configuration_id = 2 and crm_provider_id = '59523413338';\n\nselect * from sidekick_settings where team_id = 2;\n\nSELECT * FROM activities WHERE id = 608660;\nselect * from activity_summary_logs where activity_id = 608660;\nselect * from ai_prompts where transcription_id = 11214;\n\n# ********************************************************************************************************\nSELECT * FROM activities WHERE uuid_to_bin('ed78a437-2804-450e-ab2f-56ab1c641346') = uuid;\n# id: 608818, crm: 59628809737\nSELECT * FROM activities WHERE uuid_to_bin('36b06e55-afdd-4782-8dee-c624cd0af191') = uuid;\n# id: 608821, crm: 59632069252\nSELECT ce.start_time, ce.end_time, a.id, a.uuid, crm_provider_id, calendar_event_id, title,\nplaybook_category_id, user_id, lead_id, contact_id, account_id, opportunity_id,\nscheduled_start_time, scheduled_end_time, actual_start_time, actual_end_time, a.created_at\nFROM activities a\njoin calendar_events ce on a.calendar_event_id = ce.id\nWHERE a.id IN (608818, 608821);\n\nselect * from users where team_id = 1;\nselect * from team_settings where team_id = 1;\nselect * from crm_profiles where crm_configuration_id = 39 order by user_id;\n\nselect * from team_features where team_id = 1;\n\nselect * from users where team_id = 2;\n\nSELECT * FROM activities WHERE uuid_to_bin('ec7647e9-5225-458b-b475-f31aa2769204') = uuid; # 612639\n# Preslava N. Ivanova, grou id 3\n\nSELECT * FROM opportunities WHERE uuid_to_bin('a2928fe5-aec5-46cb-85d9-7654c89e46a6') = uuid;\n\nselect * from activities where opportunity_id = 344 and actual_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00';\n\nselect\n a.id,\n a.type,\n a.scheduled_start_time,\n a.actual_start_time,\n a.created_at,\n a.opportunity_id,\n a.status\nFROM activities a\nWHERE opportunity_id = 344\nand status IN ('completed', 'received', 'delivered')\nand (\n (a.actual_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00')\nOR (a.created_at between '2024-10-11 00:00:00' and '2024-10-12 00:00:00')\nOR (a.scheduled_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00'))\n;\n\nSELECT * FROM users WHERE id = 222;\n\nSELECT * FROM crm_profiles WHERE user_id = 222;\nselect * from crm_layouts where crm_configuration_id = 39;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 281;\n\nselect * from group_deal_risk_types;\n\nselect * from opportunities where team_id = 1;\n\nSELECT * FROM opportunities WHERE id = 315;\nSELECT * FROM crm_field_data WHERE object_id = 315;\nselect * from crm_field_data where object_id = 260;\n\nselect * from generic_ai_prompts where subject_id = 315;\n\nselect * from teams; # 36, 21, 121, james.graham@bullhorn.jiminny.com\nSELECT * FROM social_accounts WHERE sociable_id = 121 and provider = 'bullhorn';\n\n# ************************************************************************************\nselect * from teams where id = 1;\nselect * from crm_configurations where id = 39;\nselect * from users where team_id = 1;\nselect u.email, cp.* from users u\njoin crm_profiles cp on u.id = cp.user_id\nwhere u.team_id = 1;\n# 1 - 00541000004281rAAA\n# 204 - 0052g000003freeAAA\n# 429 - 0052g000003qGOiAAM\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 1\nand sa.provider = 'salesforce';\n\nselect * from activities where type = 'softphone'\nand created_at > '2024-12-11 15:24:36' order by id desc;\n\nselect * from activity_providers where team_id = 1;\nselect * from activity_provider_users where activity_provider_id = 328;\n\nselect * from opportunities where crm_configuration_id = 39\nAND account_id = 178 AND is_closed = false\norder by created_at DESC;\n\nselect * from contacts where id = 3952;\nselect * from accounts where id = 178;\n\n# ************************************************************************************\nselect * from teams where id = 36;\nselect * from crm_configurations where id = 21;\nselect * from users where team_id = 36;\nselect u.email, cp.* from users u\njoin crm_profiles cp on u.id = cp.user_id\nwhere u.team_id = 36;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 36\nand sa.provider = 'bullhorn';\n\nselect * from social_accounts where id = 348;\nUPDATE social_accounts SET\nprovider_user_token = '21442_6802599_91:41179a58-21e7-4d7c-ad58-56bb666b2f65',\nprovider_refresh_token = '21442_6802599_91:01c6b335-3f2a-42e4-85ff-8a08fa65fceb',\nexpires = 1733998131,\nstate = 'connected'\nWHERE id = 348;\n\n# ************************************************************************************\nselect * from teams where id = 31;\nselect * from crm_configurations where id = 18;\n\nselect * from users where team_id = 31; # 257\nselect u.email, cp.* from users u\njoin crm_profiles cp on u.id = cp.user_id\nwhere u.team_id = 31;\n\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 31\nand sa.provider = 'close';\n\nselect * from contacts where crm_configuration_id = 18;\n\n# ********************** NEPTUNE **************************************************************\nselect * from teams;\nselect * from users where id IN (1030, 1035, 1052);\nselect * from crm_configurations;\n\nselect * from users where team_id = 65; # 257\nselect * from team_settings where team_id = 65; # 257\nselect * from invitations where team_id = 65; # 257\nselect * from users where email = 'integration-account@jiminny.com'; # 257\nselect u.email, cp.* from users u\njoin crm_profiles cp on u.id = cp.user_id\nwhere u.team_id = 65;\n\nselect * from crm_configurations where id = 53;\nselect * from accounts where crm_configuration_id = 53 order by id desc;\nselect * from leads where crm_configuration_id = 53 order by id desc;\nselect * from contacts where crm_configuration_id = 53 order by id desc;\nselect * from opportunities where crm_configuration_id = 53 order by id desc;\nselect * from crm_profiles where crm_configuration_id = 53 order by id desc;\nselect * from crm_fields where crm_configuration_id = 53 order by id desc;\nselect * from crm_field_values where crm_field_id = 3341 order by id desc;\nselect * from crm_layouts where crm_configuration_id = 53 order by id desc;\nselect * from stages where crm_configuration_id = 53 order by id desc;\n\n\nselect * from crm_profiles where crm_configuration_id = 13;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 65\nand sa.provider = 'integration-app';\n\nselect * from contacts where crm_configuration_id = 13;\n\nselect * from social_accounts where sociable_id = 283;\n\nSELECT * FROM opportunities WHERE crm_provider_id = '006O400000E9bzeIAB';\n\nselect * from activity_providers where team_id = 65;\nSELECT * FROM activities WHERE crm_configuration_id IN (51, 52, 53);\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 65\n;\n\n# ***************************** STAGING ********************************************\nSELECT * FROM teams;\nSELECT * FROM teams WHERE id = 88;\nSELECT * FROM teams WHERE id = 89;\nselect * from team_settings where team_id = 89;\nSELECT * FROM users WHERE team_id = 89;\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 89;\n\nselect * from users;\nSELECT * FROM social_accounts WHERE sociable_id = 1761;\nSELECT * FROM crm_configurations WHERE id = 70;\nselect * from accounts where crm_configuration_id = 70 order by id desc;\nselect * from leads where crm_configuration_id = 70 order by id desc;\nselect * from contacts where crm_configuration_id = 70 order by id desc;\nselect * from opportunities where crm_configuration_id = 70 order by id desc;\nselect * from crm_profiles where crm_configuration_id = 70 order by id desc;\nselect * from crm_fields where crm_configuration_id = 70 order by id desc;\nselect * from crm_field_values where crm_field_id = 3536 order by id desc;\nselect * from crm_layouts where crm_configuration_id = 70 order by id desc;\nselect * from stages where crm_configuration_id = 70 order by id desc;\nselect * from business_processes where crm_configuration_id = 70 order by id desc;\nselect * from business_process_stages where business_process_id = 34;\n\nselect * from contacts where id = 10468;\n\nselect * from crm_layouts where crm_configuration_id = 70;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 388;\nSELECT * FROM crm_fields WHERE id IN (3533,3534,3535);\n\nselect * from activities where crm_configuration_id = 70\nand (account_id IS NOT NULL or lead_id IS NOT NULL or contact_id IS NOT NULL or opportunity_id IS NOT NULL) order by id desc;\n\nSELECT * FROM activities WHERE uuid_to_bin('2e10b60f-8a61-41c5-a3d4-28835353dc65') = uuid;\nSELECT * FROM activities where crm_configuration_id = 69 ;\n\nSELECT * FROM users WHERE email LIKE '%jiminny_web_sa2@jiminny.com%';\nSELECT * FROM activities WHERE uuid_to_bin('5a150c93-40fc-42ec-b3bd-c1d328e09f6e') = uuid;\nSELECT * FROM opportunities WHERE id = 385;\n\nselect * from participants p\njoin activities a on p.activity_id = a.id\nwhere a.crm_configuration_id = 70\nand (p.lead_id IS NOT NULL or p.contact_id IS NOT NULL);\nSELECT * FROM participants WHERE id = 1013638;\n\nselect * from teams where id = 90;\nselect * from users where team_id = 90;\nselect * from social_accounts where social_accounts.sociable_id IN (1960,1760);\nSELECT * FROM crm_profiles WHERE crm_configuration_id = 71;\nselect * from invitations where team_id = 90;\n\nselect * from crm_configurations where id = 71;\nselect * from accounts where crm_configuration_id = 71 order by id desc;\nselect * from leads where crm_configuration_id = 71 order by id desc;\nselect * from contacts where crm_configuration_id = 71 order by id desc;\nselect * from opportunities where crm_configuration_id = 71 order by id desc;\nselect * from crm_profiles where crm_configuration_id = 71 order by id desc;\nselect * from crm_fields where crm_configuration_id = 71 order by id desc;\nselect * from crm_field_values where crm_field_id = 3341 order by id desc;\nselect * from crm_layouts where crm_configuration_id = 71 order by id desc;\nselect * from stages where crm_configuration_id = 71 order by id desc;\n\nselect * from users order by secondary_email desc;\nselect u.id, u.email, u.status, sa.id, sa.provider_user_id from social_accounts sa\n join users u on sa.sociable_id = u.id\nwhere sa.provider = 'google' and u.email LIKE 'aneliya%';\n\nselect * from failed_jobs order by id desc;\n\nselect * from users where email = 'ben.allwright@learningpeople.co.uk' or secondary_email = 'ben.allwright@learningpeople.co.uk';\n\nselect * from teams;\nSELECT * FROM crm_profiles WHERE crm_configuration_id = 39;\nSELECT * FROM crm_fields WHERE crm_configuration_id = 39 and object_type = 'task';\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 1\nand sa.provider = 'salesforce';\n\n# ************************************************************************************\nSELECT * FROM activities WHERE uuid_to_bin('c38b3895-fd0f-4b1f-9fb2-c170dba137c6') = uuid;\nSELECT * FROM crm_configurations WHERE id = 70;\n\nselect * from teams where id = 1;\nselect * from groups where team_id = 1;\nselect * from users where team_id = 1;\n\nselect o.id, o.name,o.close_date, u.id, u.name, u.group_id, r.id, r.display_name, g.name, g.scope from opportunities o\njoin users u on o.user_id = u.id\njoin groups g on u.group_id = g.id\njoin role_user ru on u.id = ru.user_id\njoin roles r on ru.role_id = r.id\nwhere o.crm_configuration_id = 39 and close_date > '2024-01-01 00:00:00';\n\nselect * from role_user where user_id = 143;\nselect * from roles;\n\nselect * from role_user;\nselect * from groups where id = 9;\nselect * from scope_groups where group_id = 9;\n\n# ************************************************************************************\nselect * from teams where id = 36;\nselect * from crm_configurations;\nSELECT * FROM social_accounts WHERE sociable_id = 121;\n\nhttps://crmsandbox.zoho.com/crm/jiminnyw4/tab/Leads/4776201000005049105\nhttps://crmsandbox.zoho.com/crm/\n\nhttps://crm.zoho.com/crm/org3469620/tab/Leads/230045000229559080\n https://crm.zoho.com/crm/\n org3469620\n\nSELECT * FROM activities WHERE uuid_to_bin('03382d20-c8bc-48e7-a3d4-90b52fa5ceab') = uuid;\n\nselect * from users where email LIKE \"%mobile_automation_%\";\nselect * from social_accounts where sociable_id IN (2228);\nselect * from crm_profiles where user_id IN (2222,2223,2226,2227);\n\nselect * from teams order by id desc;\nSELECT * FROM users WHERE id = 2229;\nSELECT * FROM crm_profiles WHERE user_id = 2229;\nselect * from opportunities where crm_configuration_id = 88;\nselect * from crm_fields where crm_configuration_id = 88;\nselect * from crm_profiles where crm_configuration_id = 88;\n\nSELECT * FROM teams WHERE id = 1;\n\nSELECT * FROM users WHERE id = 143;\nSELECT * FROM users WHERE uuid_to_bin('fde193d3-06a2-4e1a-8895-62b94039215d') = uuid;\nSELECT * FROM teams WHERE uuid_to_bin('73385071-a756-42ae-9c73-8b53f2309467') = uuid;\n\nhttps://app.staging.jiminny.com/ondemand?\n min_duration=1\n &\n only_recorded=1\n &\n user_id%5B%5D=641f1acb-16b8-42d1-8726-df52979dad0e\n &\n sequence_number=2\n\n select * from users where team_id = 1 and email like '%stoyan%'\n\nselect * from coaching_feedbacks;\n\nselect * from teams;\nSELECT * FROM users WHERE team_id = 36;\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 19\nand sa.provider = 'pipedrive';\n\nselect * from users where id = 143;\n\nSELECT * FROM users WHERE uuid_to_bin('73180eeb-33de-4065-977d-ccbe0e6c94fc') = uuid;\nSELECT * FROM teams WHERE uuid_to_bin('73180eeb-33de-4065-977d-ccbe0e6c94fc') = uuid;\nSELECT * FROM activity_shares WHERE uuid_to_bin('73180eeb-33de-4065-977d-ccbe0e6c94fc') = uuid;\n\nselect * from users where team_id = 2;\nselect * from activities where crm_configuration_id = 39\nand activities.scheduled_start_time BETWEEN '2025-04-09 00:00:00' AND '2025-04-09 23:59:59'\nAND user_id = 143\norder by id desc;\n\n# ************************************************************************************\nselect * from teams where id = 142; # 2312, 126\nselect * from team_settings;\nselect * from users where team_id = 142; # 21642\nSELECT * FROM social_accounts WHERE sociable_id = 21642;\nSELECT * FROM crm_profiles cp join users u ON u.id = cp.user_id WHERE team_id = 142;\nselect * from crm_profiles where id IN (93);\nselect * from invitations;\nselect * from team_features where team_id = 1;\n\nSELECT * FROM crm_configurations WHERE id = 126;\nselect * from accounts where crm_configuration_id = 126 order by id desc;\nselect * from leads where crm_configuration_id = 126 order by id desc;\nselect * from contacts where crm_configuration_id = 126 order by id desc;\nselect * from opportunities where crm_configuration_id = 126 order by id desc;\nselect * from crm_profiles where crm_configuration_id = 126 order by id desc;\nselect * from crm_fields where crm_configuration_id = 126 # 11060\n# and type IN ('picklist', 'status')\n# and object_type = 'task'\norder by id desc;\n# 5731,5732,5733\nselect DISTINCT crm_field_id from crm_field_values where crm_field_id IN (11151,12239,12215,12185,12175,12165,12144,12137,12127,12109,12107,12105,12103,12092,12037,12005,12003,11987,11969,11958,11951,11942,11931,11924,11921,11917,11915,11901,11893,11883,11872,11870,11868,11866,11839,11833,11821,11793,11780,11777,11769,11757,11737,11735,11656,11645,11638,11629,11618,11611,11602,11591,11584,11581,11558,11544,11543,11534,11532,11529,11527,11503,11497,11493,11488,11470,11468,11457,11455,11397,11387,11372,11363,11348,11323,11318,11309,11301,11300,11292,11290,11286,11284,11256,11252,11242,11237,11233,11219,11176,11160) order by id desc;\nselect * from crm_layouts where crm_configuration_id = 126 order by id desc;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id in (300,299,298);\nselect * from stages where crm_configuration_id = 126 order by id desc;\nselect * from business_processes where crm_configuration_id = 126 order by id desc;\nselect * from business_process_stages where business_process_id IN (76,75,74,73);\nselect * from playbooks where team_id = 142;\nselect * from playbook_layouts where playbook_id IN (108);\nSELECT * FROM playbook_categories WHERE playbook_id IN (108);\n\nselect * from teams where id = 130;\nSELECT * FROM social_accounts WHERE sociable_id = 2291;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 2\nand sa.provider = 'hubspot';\n\nSELECT * FROM activities\n WHERE crm_configuration_id = 110;\n\nselect * from teams;\nselect * from crm_configurations;\n\nSELECT * FROM activities WHERE id = 628773;\nSELECT * FROM crm_profiles WHERE user_id = 1460;\nSELECT * FROM social_accounts WHERE sociable_id = 2291;\n\nselect * from teams;\nselect ru.*, pr.*, p.* from users u join role_user ru on ru.user_id = u.id\njoin permission_role pr on pr.role_id = ru.role_id\n join permissions p on p.id = pr.permission_id\nwhere team_id = 495 and p.name IN ('dial');\n\nselect * from teams where id = 145;\nselect * from crm_configurations where id = 129;\nselect * from social_accounts where sociable_id = 2317;\nSELECT * FROM activities WHERE uuid_to_bin('8dbab184-a333-4268-ad57-fb41f8d53a9a') = uuid;\n\nselect * from teams where id = 1;\nSELECT * FROM crm_layouts WHERE crm_configuration_id = 39;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 280;\nSELECT * FROM crm_layout_entities WHERE id = 5507;\nSELECT * FROM crm_fields WHERE crm_configuration_id = 39 and object_type IN ('event');\n\nselect * from teams;\nselect * from activities where crm_configuration_id = 14;\n\nSELECT * FROM social_accounts where provider = 'copper';\n\nselect * from activities where id = 628467;\nselect * from participants where activity_id = 628467;\n\nSELECT * FROM contacts WHERE id = 3969;\nSELECT * FROM accounts WHERE id = 177;\n\nSELECT * FROM activities WHERE uuid_to_bin('4eb54c77-cfa3-2bd4-84a7-9ed46a21c988') = uuid;\n\n# ********************* BH\nselect * from teams where id = 36;\nSELECT * FROM crm_configurations WHERE id = 21;\nselect * from activities where crm_configuration_id = 21 and id = 607901;\nselect * from activities where crm_configuration_id = 21;\n\nselect * roles;\nselect * from permissions;\nselect * from permission_role where permission_id = 226;\n\nselect * from migrations order by id desc;\n\n# mercury\n# neptune\n# earth\n\nselect * from teams;\nselect * from teams where id = 19;\nselect * from teams where id = 27;\nselect * from users where team_id = 27;\nSELECT * FROM crm_configurations WHERE id = 42;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 19\nand sa.provider = 'pipedrive';\n\nselect * from activities where id = 631461;\nSELECT * FROM crm_field_values WHERE crm_field_id = 180;\n\nselect * from teams where id = 2;\nSELECT * FROM social_accounts WHERE sociable_id = 89;\n\nSELECT * FROM activities WHERE uuid_to_bin('ba0c029a-bc14-4e17-8603-64174acebcbb') = uuid; # 634273\nselect * from activity_summary_logs where activity_id = 634273;\n\nselect * from sidekick_settings where team_id = 2;\n\nselect * from teams; # 2, 2\nSELECT * FROM crm_configurations WHERE team_id = 2; # 2\nselect * from team_features where team_id = 2;\nselect * from features;\nSELECT * FROM opportunities WHERE crm_configuration_id = 2 and crm_provider_id = '51317301383';\nSELECT * FROM opportunities WHERE crm_configuration_id = 2 order by id desc;\n\nselect * from automated_reports order by id desc;\nselect * from automated_report_results order by id desc;\nselect * from users where team_id = 1 and id IN (7160, 3248);\nselect * from migrations order by id desc;\n\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 1 and sa.provider = 'salesforce';\n\nselect * from teams where id = 1;\nselect * from groups g JOIN playbooks p on g.playbook_id = p.id where g.team_id = 1;\nselect * from groups where id = 565;\nselect * from playbooks where team_id = 1;\nselect * from playbooks where id = 175;\nselect * from playbook_categories where playbook_id = 175;\nselect * from users where team_id = 1;\nselect * from users where id = 7160;\nselect * from crm_profiles where user_id = 7160;\nselect * from features;\nselect\n *\n# id, uuid, type, provider, playbook_category_id, user_id, lead_id, contact_id, account_id, opportunity_id, stage_id,\n# crm_configuration_id, crm_provider_id, transcription_id, status\nfrom activities where crm_configuration_id = 1 and type = 'conference'\n# and crm_provider_id IS NOT NULL\nand provider != 'uploader' and actual_start_time IS NOT NULL\nORDER by id desc;\nselect * from activities where id = 54747783; # 00UO400000pCzojMAC\n\nselect p.id, p.activity_type, pc.id, pc.name\nFROM playbooks p\njoin playbook_categories pc on p.id = pc.playbook_id\nwhere p.team_id = 1 and p.activity_type = 'event';\n\nSELECT * FROM crm_fields WHERE crm_configuration_id = 1 and object_type = 'event';\nSELECT * FROM crm_field_values WHERE crm_field_id = 4;\n\nselect * from crm_layouts cl join playbook_layouts pl on cl.id = pl.layout_id\nwhere crm_configuration_id = 1 and pl.playbook_id = 175;\n\nselect * from teams;\nSELECT r.* FROM automated_reports r\njoin teams t on r.team_id = t.id\nWHERE r.frequency = 'daily'\n and r.status = 1\nAND t.status = 'active'\nAND (r.expires_at >= now() OR r.expires_at IS NULL);\n\nselect * from automated_report_results where report_id IN (18, 33);\n\nselect * from activity_searches where id = 10932;\nselect * from activity_search_filters where activity_search_id = 10932;\nselect * from automated_reports;\nselect * from automated_report_results where report_id IN (34, 35);","depth":4,"value":"SELECT * FROM teams WHERE id = 1;\n\nselect * from crm_layouts where crm_configuration_id = 39;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 283;\nSELECT * FROM crm_fields WHERE id = 2234;\nSELECT * FROM crm_field_values WHERE crm_field_id = 2234;\n\nselect * from crm_profiles where user_id = 143;\n\nselect * from record_types where crm_configuration_id = 39; # 0121K000001MHElQAO,0121K000001MHEqQAO\nselect * from business_processes where crm_configuration_id = 39;\n# 01941000000H669AAC, 01941000000H66JAAS\n\nselect * from record_type_field_values\n where record_type_id IN (24);\n\nselect * from crm_field_values where id IN (2730);\n\nselect * from crm_configurations where id = 39;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 1\nand sa.provider = 'salesforce'; #1035\n\n\nselect * from users where team_id = 1; # 222 group 3\nSELECT * FROM activities WHERE user_id = 222 order by id desc;\nselect * from sidekick_settings where team_id = 1;\nselect * from teams where id = 1;\nselect * from team_features where team_id = 1;\n\nselect * from activities where crm_configuration_id = 2\nand provider = 'ms-teams' and id = 608765;\n\nSELECT * FROM activities WHERE crm_configuration_id = 2 and crm_provider_id = '59523413338';\n\nselect * from sidekick_settings where team_id = 2;\n\nSELECT * FROM activities WHERE id = 608660;\nselect * from activity_summary_logs where activity_id = 608660;\nselect * from ai_prompts where transcription_id = 11214;\n\n# ********************************************************************************************************\nSELECT * FROM activities WHERE uuid_to_bin('ed78a437-2804-450e-ab2f-56ab1c641346') = uuid;\n# id: 608818, crm: 59628809737\nSELECT * FROM activities WHERE uuid_to_bin('36b06e55-afdd-4782-8dee-c624cd0af191') = uuid;\n# id: 608821, crm: 59632069252\nSELECT ce.start_time, ce.end_time, a.id, a.uuid, crm_provider_id, calendar_event_id, title,\nplaybook_category_id, user_id, lead_id, contact_id, account_id, opportunity_id,\nscheduled_start_time, scheduled_end_time, actual_start_time, actual_end_time, a.created_at\nFROM activities a\njoin calendar_events ce on a.calendar_event_id = ce.id\nWHERE a.id IN (608818, 608821);\n\nselect * from users where team_id = 1;\nselect * from team_settings where team_id = 1;\nselect * from crm_profiles where crm_configuration_id = 39 order by user_id;\n\nselect * from team_features where team_id = 1;\n\nselect * from users where team_id = 2;\n\nSELECT * FROM activities WHERE uuid_to_bin('ec7647e9-5225-458b-b475-f31aa2769204') = uuid; # 612639\n# Preslava N. Ivanova, grou id 3\n\nSELECT * FROM opportunities WHERE uuid_to_bin('a2928fe5-aec5-46cb-85d9-7654c89e46a6') = uuid;\n\nselect * from activities where opportunity_id = 344 and actual_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00';\n\nselect\n a.id,\n a.type,\n a.scheduled_start_time,\n a.actual_start_time,\n a.created_at,\n a.opportunity_id,\n a.status\nFROM activities a\nWHERE opportunity_id = 344\nand status IN ('completed', 'received', 'delivered')\nand (\n (a.actual_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00')\nOR (a.created_at between '2024-10-11 00:00:00' and '2024-10-12 00:00:00')\nOR (a.scheduled_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00'))\n;\n\nSELECT * FROM users WHERE id = 222;\n\nSELECT * FROM crm_profiles WHERE user_id = 222;\nselect * from crm_layouts where crm_configuration_id = 39;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 281;\n\nselect * from group_deal_risk_types;\n\nselect * from opportunities where team_id = 1;\n\nSELECT * FROM opportunities WHERE id = 315;\nSELECT * FROM crm_field_data WHERE object_id = 315;\nselect * from crm_field_data where object_id = 260;\n\nselect * from generic_ai_prompts where subject_id = 315;\n\nselect * from teams; # 36, 21, 121, james.graham@bullhorn.jiminny.com\nSELECT * FROM social_accounts WHERE sociable_id = 121 and provider = 'bullhorn';\n\n# ************************************************************************************\nselect * from teams where id = 1;\nselect * from crm_configurations where id = 39;\nselect * from users where team_id = 1;\nselect u.email, cp.* from users u\njoin crm_profiles cp on u.id = cp.user_id\nwhere u.team_id = 1;\n# 1 - 00541000004281rAAA\n# 204 - 0052g000003freeAAA\n# 429 - 0052g000003qGOiAAM\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 1\nand sa.provider = 'salesforce';\n\nselect * from activities where type = 'softphone'\nand created_at > '2024-12-11 15:24:36' order by id desc;\n\nselect * from activity_providers where team_id = 1;\nselect * from activity_provider_users where activity_provider_id = 328;\n\nselect * from opportunities where crm_configuration_id = 39\nAND account_id = 178 AND is_closed = false\norder by created_at DESC;\n\nselect * from contacts where id = 3952;\nselect * from accounts where id = 178;\n\n# ************************************************************************************\nselect * from teams where id = 36;\nselect * from crm_configurations where id = 21;\nselect * from users where team_id = 36;\nselect u.email, cp.* from users u\njoin crm_profiles cp on u.id = cp.user_id\nwhere u.team_id = 36;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 36\nand sa.provider = 'bullhorn';\n\nselect * from social_accounts where id = 348;\nUPDATE social_accounts SET\nprovider_user_token = '21442_6802599_91:41179a58-21e7-4d7c-ad58-56bb666b2f65',\nprovider_refresh_token = '21442_6802599_91:01c6b335-3f2a-42e4-85ff-8a08fa65fceb',\nexpires = 1733998131,\nstate = 'connected'\nWHERE id = 348;\n\n# ************************************************************************************\nselect * from teams where id = 31;\nselect * from crm_configurations where id = 18;\n\nselect * from users where team_id = 31; # 257\nselect u.email, cp.* from users u\njoin crm_profiles cp on u.id = cp.user_id\nwhere u.team_id = 31;\n\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 31\nand sa.provider = 'close';\n\nselect * from contacts where crm_configuration_id = 18;\n\n# ********************** NEPTUNE **************************************************************\nselect * from teams;\nselect * from users where id IN (1030, 1035, 1052);\nselect * from crm_configurations;\n\nselect * from users where team_id = 65; # 257\nselect * from team_settings where team_id = 65; # 257\nselect * from invitations where team_id = 65; # 257\nselect * from users where email = 'integration-account@jiminny.com'; # 257\nselect u.email, cp.* from users u\njoin crm_profiles cp on u.id = cp.user_id\nwhere u.team_id = 65;\n\nselect * from crm_configurations where id = 53;\nselect * from accounts where crm_configuration_id = 53 order by id desc;\nselect * from leads where crm_configuration_id = 53 order by id desc;\nselect * from contacts where crm_configuration_id = 53 order by id desc;\nselect * from opportunities where crm_configuration_id = 53 order by id desc;\nselect * from crm_profiles where crm_configuration_id = 53 order by id desc;\nselect * from crm_fields where crm_configuration_id = 53 order by id desc;\nselect * from crm_field_values where crm_field_id = 3341 order by id desc;\nselect * from crm_layouts where crm_configuration_id = 53 order by id desc;\nselect * from stages where crm_configuration_id = 53 order by id desc;\n\n\nselect * from crm_profiles where crm_configuration_id = 13;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 65\nand sa.provider = 'integration-app';\n\nselect * from contacts where crm_configuration_id = 13;\n\nselect * from social_accounts where sociable_id = 283;\n\nSELECT * FROM opportunities WHERE crm_provider_id = '006O400000E9bzeIAB';\n\nselect * from activity_providers where team_id = 65;\nSELECT * FROM activities WHERE crm_configuration_id IN (51, 52, 53);\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 65\n;\n\n# ***************************** STAGING ********************************************\nSELECT * FROM teams;\nSELECT * FROM teams WHERE id = 88;\nSELECT * FROM teams WHERE id = 89;\nselect * from team_settings where team_id = 89;\nSELECT * FROM users WHERE team_id = 89;\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 89;\n\nselect * from users;\nSELECT * FROM social_accounts WHERE sociable_id = 1761;\nSELECT * FROM crm_configurations WHERE id = 70;\nselect * from accounts where crm_configuration_id = 70 order by id desc;\nselect * from leads where crm_configuration_id = 70 order by id desc;\nselect * from contacts where crm_configuration_id = 70 order by id desc;\nselect * from opportunities where crm_configuration_id = 70 order by id desc;\nselect * from crm_profiles where crm_configuration_id = 70 order by id desc;\nselect * from crm_fields where crm_configuration_id = 70 order by id desc;\nselect * from crm_field_values where crm_field_id = 3536 order by id desc;\nselect * from crm_layouts where crm_configuration_id = 70 order by id desc;\nselect * from stages where crm_configuration_id = 70 order by id desc;\nselect * from business_processes where crm_configuration_id = 70 order by id desc;\nselect * from business_process_stages where business_process_id = 34;\n\nselect * from contacts where id = 10468;\n\nselect * from crm_layouts where crm_configuration_id = 70;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 388;\nSELECT * FROM crm_fields WHERE id IN (3533,3534,3535);\n\nselect * from activities where crm_configuration_id = 70\nand (account_id IS NOT NULL or lead_id IS NOT NULL or contact_id IS NOT NULL or opportunity_id IS NOT NULL) order by id desc;\n\nSELECT * FROM activities WHERE uuid_to_bin('2e10b60f-8a61-41c5-a3d4-28835353dc65') = uuid;\nSELECT * FROM activities where crm_configuration_id = 69 ;\n\nSELECT * FROM users WHERE email LIKE '%jiminny_web_sa2@jiminny.com%';\nSELECT * FROM activities WHERE uuid_to_bin('5a150c93-40fc-42ec-b3bd-c1d328e09f6e') = uuid;\nSELECT * FROM opportunities WHERE id = 385;\n\nselect * from participants p\njoin activities a on p.activity_id = a.id\nwhere a.crm_configuration_id = 70\nand (p.lead_id IS NOT NULL or p.contact_id IS NOT NULL);\nSELECT * FROM participants WHERE id = 1013638;\n\nselect * from teams where id = 90;\nselect * from users where team_id = 90;\nselect * from social_accounts where social_accounts.sociable_id IN (1960,1760);\nSELECT * FROM crm_profiles WHERE crm_configuration_id = 71;\nselect * from invitations where team_id = 90;\n\nselect * from crm_configurations where id = 71;\nselect * from accounts where crm_configuration_id = 71 order by id desc;\nselect * from leads where crm_configuration_id = 71 order by id desc;\nselect * from contacts where crm_configuration_id = 71 order by id desc;\nselect * from opportunities where crm_configuration_id = 71 order by id desc;\nselect * from crm_profiles where crm_configuration_id = 71 order by id desc;\nselect * from crm_fields where crm_configuration_id = 71 order by id desc;\nselect * from crm_field_values where crm_field_id = 3341 order by id desc;\nselect * from crm_layouts where crm_configuration_id = 71 order by id desc;\nselect * from stages where crm_configuration_id = 71 order by id desc;\n\nselect * from users order by secondary_email desc;\nselect u.id, u.email, u.status, sa.id, sa.provider_user_id from social_accounts sa\n join users u on sa.sociable_id = u.id\nwhere sa.provider = 'google' and u.email LIKE 'aneliya%';\n\nselect * from failed_jobs order by id desc;\n\nselect * from users where email = 'ben.allwright@learningpeople.co.uk' or secondary_email = 'ben.allwright@learningpeople.co.uk';\n\nselect * from teams;\nSELECT * FROM crm_profiles WHERE crm_configuration_id = 39;\nSELECT * FROM crm_fields WHERE crm_configuration_id = 39 and object_type = 'task';\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 1\nand sa.provider = 'salesforce';\n\n# ************************************************************************************\nSELECT * FROM activities WHERE uuid_to_bin('c38b3895-fd0f-4b1f-9fb2-c170dba137c6') = uuid;\nSELECT * FROM crm_configurations WHERE id = 70;\n\nselect * from teams where id = 1;\nselect * from groups where team_id = 1;\nselect * from users where team_id = 1;\n\nselect o.id, o.name,o.close_date, u.id, u.name, u.group_id, r.id, r.display_name, g.name, g.scope from opportunities o\njoin users u on o.user_id = u.id\njoin groups g on u.group_id = g.id\njoin role_user ru on u.id = ru.user_id\njoin roles r on ru.role_id = r.id\nwhere o.crm_configuration_id = 39 and close_date > '2024-01-01 00:00:00';\n\nselect * from role_user where user_id = 143;\nselect * from roles;\n\nselect * from role_user;\nselect * from groups where id = 9;\nselect * from scope_groups where group_id = 9;\n\n# ************************************************************************************\nselect * from teams where id = 36;\nselect * from crm_configurations;\nSELECT * FROM social_accounts WHERE sociable_id = 121;\n\nhttps://crmsandbox.zoho.com/crm/jiminnyw4/tab/Leads/4776201000005049105\nhttps://crmsandbox.zoho.com/crm/\n\nhttps://crm.zoho.com/crm/org3469620/tab/Leads/230045000229559080\n https://crm.zoho.com/crm/\n org3469620\n\nSELECT * FROM activities WHERE uuid_to_bin('03382d20-c8bc-48e7-a3d4-90b52fa5ceab') = uuid;\n\nselect * from users where email LIKE \"%mobile_automation_%\";\nselect * from social_accounts where sociable_id IN (2228);\nselect * from crm_profiles where user_id IN (2222,2223,2226,2227);\n\nselect * from teams order by id desc;\nSELECT * FROM users WHERE id = 2229;\nSELECT * FROM crm_profiles WHERE user_id = 2229;\nselect * from opportunities where crm_configuration_id = 88;\nselect * from crm_fields where crm_configuration_id = 88;\nselect * from crm_profiles where crm_configuration_id = 88;\n\nSELECT * FROM teams WHERE id = 1;\n\nSELECT * FROM users WHERE id = 143;\nSELECT * FROM users WHERE uuid_to_bin('fde193d3-06a2-4e1a-8895-62b94039215d') = uuid;\nSELECT * FROM teams WHERE uuid_to_bin('73385071-a756-42ae-9c73-8b53f2309467') = uuid;\n\nhttps://app.staging.jiminny.com/ondemand?\n min_duration=1\n &\n only_recorded=1\n &\n user_id%5B%5D=641f1acb-16b8-42d1-8726-df52979dad0e\n &\n sequence_number=2\n\n select * from users where team_id = 1 and email like '%stoyan%'\n\nselect * from coaching_feedbacks;\n\nselect * from teams;\nSELECT * FROM users WHERE team_id = 36;\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 19\nand sa.provider = 'pipedrive';\n\nselect * from users where id = 143;\n\nSELECT * FROM users WHERE uuid_to_bin('73180eeb-33de-4065-977d-ccbe0e6c94fc') = uuid;\nSELECT * FROM teams WHERE uuid_to_bin('73180eeb-33de-4065-977d-ccbe0e6c94fc') = uuid;\nSELECT * FROM activity_shares WHERE uuid_to_bin('73180eeb-33de-4065-977d-ccbe0e6c94fc') = uuid;\n\nselect * from users where team_id = 2;\nselect * from activities where crm_configuration_id = 39\nand activities.scheduled_start_time BETWEEN '2025-04-09 00:00:00' AND '2025-04-09 23:59:59'\nAND user_id = 143\norder by id desc;\n\n# ************************************************************************************\nselect * from teams where id = 142; # 2312, 126\nselect * from team_settings;\nselect * from users where team_id = 142; # 21642\nSELECT * FROM social_accounts WHERE sociable_id = 21642;\nSELECT * FROM crm_profiles cp join users u ON u.id = cp.user_id WHERE team_id = 142;\nselect * from crm_profiles where id IN (93);\nselect * from invitations;\nselect * from team_features where team_id = 1;\n\nSELECT * FROM crm_configurations WHERE id = 126;\nselect * from accounts where crm_configuration_id = 126 order by id desc;\nselect * from leads where crm_configuration_id = 126 order by id desc;\nselect * from contacts where crm_configuration_id = 126 order by id desc;\nselect * from opportunities where crm_configuration_id = 126 order by id desc;\nselect * from crm_profiles where crm_configuration_id = 126 order by id desc;\nselect * from crm_fields where crm_configuration_id = 126 # 11060\n# and type IN ('picklist', 'status')\n# and object_type = 'task'\norder by id desc;\n# 5731,5732,5733\nselect DISTINCT crm_field_id from crm_field_values where crm_field_id IN (11151,12239,12215,12185,12175,12165,12144,12137,12127,12109,12107,12105,12103,12092,12037,12005,12003,11987,11969,11958,11951,11942,11931,11924,11921,11917,11915,11901,11893,11883,11872,11870,11868,11866,11839,11833,11821,11793,11780,11777,11769,11757,11737,11735,11656,11645,11638,11629,11618,11611,11602,11591,11584,11581,11558,11544,11543,11534,11532,11529,11527,11503,11497,11493,11488,11470,11468,11457,11455,11397,11387,11372,11363,11348,11323,11318,11309,11301,11300,11292,11290,11286,11284,11256,11252,11242,11237,11233,11219,11176,11160) order by id desc;\nselect * from crm_layouts where crm_configuration_id = 126 order by id desc;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id in (300,299,298);\nselect * from stages where crm_configuration_id = 126 order by id desc;\nselect * from business_processes where crm_configuration_id = 126 order by id desc;\nselect * from business_process_stages where business_process_id IN (76,75,74,73);\nselect * from playbooks where team_id = 142;\nselect * from playbook_layouts where playbook_id IN (108);\nSELECT * FROM playbook_categories WHERE playbook_id IN (108);\n\nselect * from teams where id = 130;\nSELECT * FROM social_accounts WHERE sociable_id = 2291;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 2\nand sa.provider = 'hubspot';\n\nSELECT * FROM activities\n WHERE crm_configuration_id = 110;\n\nselect * from teams;\nselect * from crm_configurations;\n\nSELECT * FROM activities WHERE id = 628773;\nSELECT * FROM crm_profiles WHERE user_id = 1460;\nSELECT * FROM social_accounts WHERE sociable_id = 2291;\n\nselect * from teams;\nselect ru.*, pr.*, p.* from users u join role_user ru on ru.user_id = u.id\njoin permission_role pr on pr.role_id = ru.role_id\n join permissions p on p.id = pr.permission_id\nwhere team_id = 495 and p.name IN ('dial');\n\nselect * from teams where id = 145;\nselect * from crm_configurations where id = 129;\nselect * from social_accounts where sociable_id = 2317;\nSELECT * FROM activities WHERE uuid_to_bin('8dbab184-a333-4268-ad57-fb41f8d53a9a') = uuid;\n\nselect * from teams where id = 1;\nSELECT * FROM crm_layouts WHERE crm_configuration_id = 39;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 280;\nSELECT * FROM crm_layout_entities WHERE id = 5507;\nSELECT * FROM crm_fields WHERE crm_configuration_id = 39 and object_type IN ('event');\n\nselect * from teams;\nselect * from activities where crm_configuration_id = 14;\n\nSELECT * FROM social_accounts where provider = 'copper';\n\nselect * from activities where id = 628467;\nselect * from participants where activity_id = 628467;\n\nSELECT * FROM contacts WHERE id = 3969;\nSELECT * FROM accounts WHERE id = 177;\n\nSELECT * FROM activities WHERE uuid_to_bin('4eb54c77-cfa3-2bd4-84a7-9ed46a21c988') = uuid;\n\n# ********************* BH\nselect * from teams where id = 36;\nSELECT * FROM crm_configurations WHERE id = 21;\nselect * from activities where crm_configuration_id = 21 and id = 607901;\nselect * from activities where crm_configuration_id = 21;\n\nselect * roles;\nselect * from permissions;\nselect * from permission_role where permission_id = 226;\n\nselect * from migrations order by id desc;\n\n# mercury\n# neptune\n# earth\n\nselect * from teams;\nselect * from teams where id = 19;\nselect * from teams where id = 27;\nselect * from users where team_id = 27;\nSELECT * FROM crm_configurations WHERE id = 42;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 19\nand sa.provider = 'pipedrive';\n\nselect * from activities where id = 631461;\nSELECT * FROM crm_field_values WHERE crm_field_id = 180;\n\nselect * from teams where id = 2;\nSELECT * FROM social_accounts WHERE sociable_id = 89;\n\nSELECT * FROM activities WHERE uuid_to_bin('ba0c029a-bc14-4e17-8603-64174acebcbb') = uuid; # 634273\nselect * from activity_summary_logs where activity_id = 634273;\n\nselect * from sidekick_settings where team_id = 2;\n\nselect * from teams; # 2, 2\nSELECT * FROM crm_configurations WHERE team_id = 2; # 2\nselect * from team_features where team_id = 2;\nselect * from features;\nSELECT * FROM opportunities WHERE crm_configuration_id = 2 and crm_provider_id = '51317301383';\nSELECT * FROM opportunities WHERE crm_configuration_id = 2 order by id desc;\n\nselect * from automated_reports order by id desc;\nselect * from automated_report_results order by id desc;\nselect * from users where team_id = 1 and id IN (7160, 3248);\nselect * from migrations order by id desc;\n\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 1 and sa.provider = 'salesforce';\n\nselect * from teams where id = 1;\nselect * from groups g JOIN playbooks p on g.playbook_id = p.id where g.team_id = 1;\nselect * from groups where id = 565;\nselect * from playbooks where team_id = 1;\nselect * from playbooks where id = 175;\nselect * from playbook_categories where playbook_id = 175;\nselect * from users where team_id = 1;\nselect * from users where id = 7160;\nselect * from crm_profiles where user_id = 7160;\nselect * from features;\nselect\n *\n# id, uuid, type, provider, playbook_category_id, user_id, lead_id, contact_id, account_id, opportunity_id, stage_id,\n# crm_configuration_id, crm_provider_id, transcription_id, status\nfrom activities where crm_configuration_id = 1 and type = 'conference'\n# and crm_provider_id IS NOT NULL\nand provider != 'uploader' and actual_start_time IS NOT NULL\nORDER by id desc;\nselect * from activities where id = 54747783; # 00UO400000pCzojMAC\n\nselect p.id, p.activity_type, pc.id, pc.name\nFROM playbooks p\njoin playbook_categories pc on p.id = pc.playbook_id\nwhere p.team_id = 1 and p.activity_type = 'event';\n\nSELECT * FROM crm_fields WHERE crm_configuration_id = 1 and object_type = 'event';\nSELECT * FROM crm_field_values WHERE crm_field_id = 4;\n\nselect * from crm_layouts cl join playbook_layouts pl on cl.id = pl.layout_id\nwhere crm_configuration_id = 1 and pl.playbook_id = 175;\n\nselect * from teams;\nSELECT r.* FROM automated_reports r\njoin teams t on r.team_id = t.id\nWHERE r.frequency = 'daily'\n and r.status = 1\nAND t.status = 'active'\nAND (r.expires_at >= now() OR r.expires_at IS NULL);\n\nselect * from automated_report_results where report_id IN (18, 33);\n\nselect * from activity_searches where id = 10932;\nselect * from activity_search_filters where activity_search_id = 10932;\nselect * from automated_reports;\nselect * from automated_report_results where report_id IN (34, 35);","role_description":"text entry area","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.088194445,"height":0.027777778},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"102","depth":4,"role_description":"text"},{"role":"AXStaticText","text":"3","depth":4,"role_description":"text"},{"role":"AXStaticText","text":"34","depth":4,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Services\\Kiosk\\AutomatedReports;\n\nuse Carbon\\CarbonImmutable;\nuse Carbon\\CarbonInterface;\nuse Carbon\\Exceptions\\InvalidFormatException;\nuse DateTime;\nuse DateTimeInterface;\nuse DateTimeZone;\nuse Illuminate\\Contracts\\Bus\\Dispatcher as BusDispatcher;\nuse Illuminate\\Database\\Eloquent\\Builder;\nuse Illuminate\\Support\\Carbon;\nuse Illuminate\\Support\\Collection;\nuse Illuminate\\Support\\Facades\\Log;\nuse Illuminate\\Support\\Facades\\Storage;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinition\\InputTypeEnum;\nuse Jiminny\\Component\\AskAnything\\AskAnythingPromptService;\nuse Jiminny\\Component\\AskAnything\\Dtos\\AskAnythingPromptDto;\nuse Jiminny\\Component\\UrlGenerator\\Webhook;\nuse Jiminny\\Contracts\\Repositories\\PlaybookCategoryRepository;\nuse Jiminny\\Contracts\\Repositories\\TeamRepository;\nuse Jiminny\\Contracts\\Repositories\\UserRepository;\nuse Jiminny\\Exceptions\\ApplicationException;\nuse Jiminny\\Exceptions\\InvalidArgumentException;\nuse Jiminny\\Exceptions\\ModelNotFoundException;\nuse Jiminny\\Jobs\\AutomatedReports\\RequestGenerateReportJob;\nuse Jiminny\\Models\\Activity\\Search;\nuse Jiminny\\Models\\AskAnything\\AskAnythingPrompt;\nuse Jiminny\\Models\\AskAnything\\AskAnythingPromptTarget;\nuse Jiminny\\Models\\AutomatedReport;\nuse Jiminny\\Models\\AutomatedReportResult;\nuse Jiminny\\Models\\Contracts\\UserContract;\nuse Jiminny\\Models\\Feature\\FeatureEnum;\nuse Jiminny\\Models\\Team;\nuse Jiminny\\Models\\User;\nuse Jiminny\\Repositories\\AskAnythingRepository;\nuse Jiminny\\Repositories\\AutomatedReportsRepository;\nuse Jiminny\\Repositories\\GroupRepository;\nuse Jiminny\\Repositories\\SearchRepository;\nuse Jiminny\\Repositories\\StageRepository;\nuse Throwable;\n\nclass AutomatedReportsService\n{\n public const string TYPE_LOSS_ANALYSIS = 'loss_analysis';\n public const string TYPE_ASK_JIMINNY = 'ask_jiminny';\n\n /**\n * Standard report types (used by kiosk for existing automated reports).\n */\n // @TODO this will add filter, however if we need to control feature by FF we need conditional logic\n public const array TYPES = [\n ['id' => 'exec_summary', 'name' => 'Exec Summary'],\n ['id' => 'coaching_profiles', 'name' => 'Coaching Profiles'],\n ['id' => 'product_feedback', 'name' => 'Product Feedback'],\n ['id' => self::TYPE_LOSS_ANALYSIS, 'name' => 'Loss Analysis'],\n// ['id' => 'questions', 'name' => 'Questions'],\n// ['id' => 'statistical_quant', 'name' => 'Statistical Quantitative'],\n ];\n\n public const array ALL_TYPES = [\n ...self::TYPES,\n ['id' => self::TYPE_ASK_JIMINNY, 'name' => 'Ask Jiminny'],\n ];\n\n public const string FREQUENCY_DAILY = 'daily';\n public const string FREQUENCY_WEEKLY = 'weekly';\n public const string FREQUENCY_MONTHLY = 'monthly';\n public const string FREQUENCY_QUARTERLY = 'quarterly';\n public const string FREQUENCY_ONE_OFF = 'one_off';\n\n /**\n * Frequencies for standard (non-Ask Jiminny) reports.\n */\n public const array FREQUENCIES = [\n ['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],\n ['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],\n ['id' => self::FREQUENCY_QUARTERLY, 'name' => 'Quarterly'],\n ['id' => self::FREQUENCY_ONE_OFF, 'name' => 'One-off'],\n ];\n\n /**\n * Frequencies for Ask Jiminny reports.\n */\n public const array ASK_JIMINNY_FREQUENCIES = [\n ['id' => self::FREQUENCY_DAILY, 'name' => 'Daily'],\n ['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],\n ['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],\n ];\n\n public const string MEDIA_TYPE_PDF = 'pdf';\n public const string MEDIA_TYPE_PODCAST = 'podcast';\n public const array MEDIA_TYPES = [self::MEDIA_TYPE_PDF, self::MEDIA_TYPE_PODCAST];\n public const array MEDIA_TYPE_OBJECT_PDF = ['id' => self::MEDIA_TYPE_PDF, 'name' => 'PDF'];\n public const array MEDIA_TYPE_OBJECT_PODCAST = ['id' => self::MEDIA_TYPE_PODCAST, 'name' => 'Podcast'];\n public const array MEDIA_TYPE_OBJECTS = [self::MEDIA_TYPE_OBJECT_PDF, self::MEDIA_TYPE_OBJECT_PODCAST];\n\n public const array CALL_TYPE_CONFERENCE = ['id' => 'conference', 'name' => 'Conference'];\n public const array CALL_TYPE_DIALER = ['id' => 'dialer', 'name' => 'Dialer'];\n public const int SENT_REPORT_AT_HOURS = 5;\n public const string PDF_KEY = 'pdf';\n public const string AUDIO_KEY = 'audio';\n\n private const array ALL_FREQUENCIES = [\n ['id' => self::FREQUENCY_DAILY, 'name' => 'Daily'],\n ['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],\n ['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],\n ['id' => self::FREQUENCY_QUARTERLY, 'name' => 'Quarterly'],\n ['id' => self::FREQUENCY_ONE_OFF, 'name' => 'One-off'],\n ];\n private const string S3_DIR = 'reports';\n private const array FILE_EXTENSIONS_VARIANTS = ['html', 'MD', 'pdf'];\n private const array FILE_PODCAST_EXTENSIONS_VARIANTS = ['json', 'mp3', 'ssml'];\n\n public function __construct(\n private readonly TeamRepository $teamRepository,\n private readonly GroupRepository $groupRepository,\n private readonly UserRepository $userRepository,\n private readonly StageRepository $stageRepository,\n private readonly DealStagesService $dealStagesService,\n private readonly RecipientsService $recipientsService,\n private readonly AutomatedReportsRepository $automatedReportsRepository,\n private readonly Webhook $webhookService,\n private readonly BusDispatcher $dispatcher,\n private readonly ActivityTypeService $activityTypeService,\n private readonly PlaybookCategoryRepository $playbookCategoryRepository,\n private readonly AskAnythingPromptService $askAnythingPromptService,\n private readonly SearchRepository $activitySearchRepository,\n private readonly AskAnythingRepository $askAnythingRepository,\n ) {\n }\n\n public static function getTypes(): array\n {\n $types = self::TYPES;\n\n return array_map(static function ($type) {\n return $type['id'];\n }, $types);\n }\n\n public static function getCallTypes(): array\n {\n return array_map(static function ($callType) {\n return $callType['id'];\n }, [self::CALL_TYPE_CONFERENCE, self::CALL_TYPE_DIALER]);\n }\n\n public static function getFrequencies(): array\n {\n return array_map(static function ($frequency) {\n return $frequency['id'];\n }, self::FREQUENCIES);\n }\n\n // front-facing structure\n public function getReportEnabledFieldData(bool $value = false): array\n {\n return [\n 'id' => 'report_enabled',\n 'label' => '',\n 'inputType' => InputTypeEnum::TOGGLE,\n 'value' => $value,\n ];\n }\n\n // Organizations = Teams\n public function getOrganizationFieldData(?string $value = null, bool $shortVersion = false): array\n {\n $options = $this->getTeams();\n\n if ($shortVersion) {\n return [\n 'id' => 'organization',\n 'label' => 'Organization',\n 'options' => $options,\n ];\n }\n\n return [\n 'id' => 'organization',\n 'label' => 'Organization',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => $options,\n 'value' => $value,\n 'dependencies' => [\n 'teams',\n 'deal_stage_at_call',\n 'current_deal_stage',\n 'recipients',\n ActivityTypeService::PLAYBOOK_CATEGORIES_KEY,\n ],\n 'dependsOn' => [],\n ];\n }\n\n // Teams = Groups\n public function getTeamFieldData(array $options = [], array $value = [], bool $shortVersion = false): array\n {\n if ($shortVersion) {\n return [\n 'id' => 'teams',\n 'label' => 'Team',\n 'options' => $options,\n ];\n }\n\n return [\n 'id' => 'teams',\n 'label' => 'Team',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'required' => false,\n 'placeholder' => 'Select',\n 'options' => $options,\n 'value' => $value, // value should be an array of objects {id, name}\n 'dependencies' => [ActivityTypeService::PLAYBOOK_CATEGORIES_KEY],\n 'dependsOn' => [],\n ];\n }\n\n public function getReportTypeFieldData(?string $value = null, bool $shortVersion = false, ?Team $team = null): array\n {\n $types = [];\n if ($team instanceof Team) {\n if ($team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {\n $types = self::TYPES;\n }\n if ($team->hasFeature(FeatureEnum::ASK_JIMINNY_REPORTS)) {\n $types[] = ['id' => self::TYPE_ASK_JIMINNY, 'name' => 'Ask Jiminny'];\n }\n } else {\n $types = self::TYPES;\n }\n\n if ($shortVersion) {\n return [\n 'id' => 'report_type',\n 'label' => 'Report Type',\n 'options' => $types,\n ];\n }\n\n return [\n 'id' => 'report_type',\n 'label' => 'Report Type',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => $types,\n 'value' => $value,\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getFrequencyFieldData(?string $value = null): array\n {\n return [\n 'id' => 'frequency',\n 'label' => 'Frequency',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => self::FREQUENCIES,\n 'value' => $value,\n 'dependencies' => ['period'],\n 'dependsOn' => [],\n ];\n }\n\n public function getPeriodFieldData(?string $valueStartDate = null, ?string $valueEndDate = null): array\n {\n return [\n 'id' => 'period',\n 'label' => 'Select one-off period',\n 'inputType' => InputTypeEnum::DATE_RANGE,\n 'required' => true,\n 'placeholder' => 'Select',\n 'value' => ['startDate' => $valueStartDate, 'endDate' => $valueEndDate],\n 'queryParams' => [\n 'startDate' => 'start_date_period',\n 'endDate' => 'end_date_period',\n ],\n 'dependencies' => [],\n 'dependsOn' => ['frequency'],\n ];\n }\n\n public function getActivityTypesFieldData(?Team $team = null, array $value = [], array $teamsFilter = []): array\n {\n return $this->activityTypeService->getActivityTypeFieldData(team: $team, value: $value, groupIds: $teamsFilter);\n }\n\n public function getDealStageAtCallFieldData(?Team $team = null, array $value = []): array\n {\n return $this->dealStagesService->getDealStageAtCallFieldData(team: $team, value: $value);\n }\n\n public function getCurrentDealStageFieldData(?Team $team = null, array $value = []): array\n {\n return $this->dealStagesService->getCurrentDealStageFieldData(team: $team, value: $value);\n }\n\n public function getDealValueFieldData(?int $valueMin = null, ?int $valueMax = null): array\n {\n return [\n 'id' => 'deal_value',\n 'label' => 'Deal Value',\n 'inputType' => InputTypeEnum::INTEGER_RANGE,\n 'required' => false,\n 'value' => ['min' => $valueMin, 'max' => $valueMax],\n 'queryParams' => [\n 'min' => 'min_deal_value',\n 'max' => 'max_deal_value',\n ],\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getCallTypeFieldData(bool $conferenceOn = false, bool $dialerOn = false): array\n {\n $value = [];\n $conferenceOn && $value[] = self::CALL_TYPE_CONFERENCE;\n $dialerOn && $value[] = self::CALL_TYPE_DIALER;\n\n return [\n 'id' => 'call_type',\n 'label' => 'Call Type',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'required' => true,\n 'options' => [\n self::CALL_TYPE_CONFERENCE,\n self::CALL_TYPE_DIALER,\n ],\n 'value' => $value,\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getMediaTypeFieldData(?AutomatedReport $report = null): array\n {\n $value = [];\n\n if ($report) {\n $value = $this->transformMediaTypes($report);\n }\n\n return [\n 'id' => 'media_types',\n 'label' => 'Export as',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'required' => true,\n 'options' => self::MEDIA_TYPE_OBJECTS,\n 'value' => $value,\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getCallDurationFieldData(?int $valueMin = null, ?int $valueMax = null): array\n {\n return [\n 'id' => 'call_duration',\n 'label' => 'Call Duration',\n 'inputType' => InputTypeEnum::INTEGER_RANGE,\n 'required' => false,\n 'value' => ['min' => $valueMin, 'max' => $valueMax],\n 'queryParams' => [\n 'min' => 'min_call_duration',\n 'max' => 'max_call_duration',\n ],\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getRecipientsFieldData(?Team $team = null, array $value = []): array\n {\n return $this->recipientsService->getRecipientsFieldData(team: $team, value: $value);\n }\n\n public function getJiminnyRecipientsFieldData(array $value = []): array\n {\n return $this->recipientsService->getJiminnyRecipientsFieldData($value);\n }\n\n public function getAdditionalPromptInputFieldData(?string $value = null): array\n {\n return [\n 'id' => 'additional_prompt_input',\n 'label' => 'Special requirements',\n 'inputType' => InputTypeEnum::TEXTAREA,\n 'required' => false,\n 'placeholder' => 'What should be the focus of the report?',\n 'value' => $value,\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getCustomReportNameFieldData(?string $value = null): array\n {\n return [\n 'id' => 'custom_name',\n 'label' => 'Custom report name',\n 'inputType' => InputTypeEnum::TEXT,\n 'required' => false,\n 'placeholder' => 'Enter custom name',\n 'value' => $value,\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n // data providers\n public function getTeams(): array\n {\n $teams = $this->teamRepository->getTeamsForKiosk(status: Team::STATUS_ACTIVE);\n\n $teamData = [];\n foreach ($teams as $team) {\n if (! $team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {\n continue;\n }\n\n $teamData[] = $this->transformTeam($team);\n }\n\n return $teamData;\n }\n\n public function getTeamGroups(string $teamUuid): array\n {\n $data = [];\n $team = $this->getTeam($teamUuid);\n\n if ($team !== null) {\n $groups = $team->groups()->get();\n\n foreach ($groups as $group) {\n $data[] = [\n 'id' => $group->getUuid(),\n 'name' => $group->getName(),\n ];\n }\n }\n\n return $data;\n }\n\n public function getTeamsGroupsOptions(array $filterTeamUuids = []): array\n {\n $data = [];\n $teams = $this->getTeams();\n\n foreach ($teams as $team) {\n if (! empty($filterTeamUuids) && ! in_array($team['id'], $filterTeamUuids, true)) {\n continue;\n }\n\n $data[] = [\n 'label' => $team['name'],\n 'groups' => $this->getTeamGroups($team['id']),\n ];\n }\n\n return $data;\n }\n\n public function getTeam(string $teamUuid): ?Team\n {\n return $this->teamRepository->idOrUuid($teamUuid);\n }\n\n public function getTeamById(int $teamId): ?Team\n {\n return $this->teamRepository->find($teamId);\n }\n\n public function getGroupsUuids(AutomatedReport $report): array\n {\n $uuids = [];\n $reportGroups = $report->getGroups();\n foreach ($reportGroups as $groupId) {\n if ($group = $this->groupRepository->find($groupId)) {\n $uuids[] = $group->getUuid();\n }\n }\n\n return $uuids;\n }\n\n public function getPlaybookCategoriesUuids(AutomatedReport $report): array\n {\n $uuids = [];\n $playbookCategories = $report->getPlaybookCategories();\n foreach ($playbookCategories as $id) {\n if ($category = $this->playbookCategoryRepository->find($id)) {\n $uuids[] = $category->getUuid();\n }\n }\n\n return $uuids;\n }\n\n public function getDealAtCallStagesUuids(AutomatedReport $report): array\n {\n $uuids = [];\n $reportStages = $report->getDealAtCallStages();\n foreach ($reportStages as $id) {\n if ($stage = $this->stageRepository->find($id)) {\n $uuids[] = $stage->getUuid();\n }\n }\n\n return $uuids;\n }\n\n public function getCurrentDealStagesUuids(AutomatedReport $report): array\n {\n $uuids = [];\n $reportStages = $report->getCurrentDealStages();\n foreach ($reportStages as $id) {\n if ($stage = $this->stageRepository->find($id)) {\n $uuids[] = $stage->getUuid();\n }\n }\n\n return $uuids;\n }\n\n public function getUsersUuids(AutomatedReport $report): array\n {\n return $this->extractUserUuids($report->getRecipients());\n }\n\n public function getJiminnyUsersUuids(AutomatedReport $report): array\n {\n return $this->extractUserUuids($report->getJiminnyRecipients());\n }\n\n /**\n * @param array<string, mixed> $recipients\n */\n private function extractUserUuids(array $recipients): array\n {\n $userIds = $recipients['users'] ?? [];\n\n return collect($userIds)\n ->map(fn ($id) => $this->userRepository->find((int) $id))\n ->filter()\n ->map(fn (UserContract $user) => $user->getUuid())\n ->values()\n ->all();\n }\n\n // get mail data\n public function getRecipientUsers(AutomatedReport $report): array\n {\n return $this->buildRecipientUsers($report->getRecipients());\n }\n\n private function getJiminnyRecipientUsers(AutomatedReport $report): array\n {\n return $this->buildRecipientUsers($report->getJiminnyRecipients());\n }\n\n /**\n * @param array<string, mixed> $recipients\n */\n private function buildRecipientUsers(array $recipients): array\n {\n $userIds = $recipients['users'] ?? [];\n\n return collect($userIds)\n ->map(fn ($id) => $this->userRepository->find((int) $id))\n ->filter()\n ->map(fn (UserContract $user) => [\n 'email' => $user->getEmailAddress(),\n 'name' => $user->getName(),\n 'timezone' => $user->getTimezone()->getName(),\n ])\n ->values()\n ->all();\n }\n\n public function getValidRecipientUsers(AutomatedReport $report, bool $includeJiminny = false): array\n {\n if ($report->isAskJiminnyReport()) {\n $recipients = $this->resolveAskJiminnyRecipients($report);\n } else {\n $recipients = $this->getRecipientUsers($report);\n if ($includeJiminny) {\n $recipients = array_merge($recipients, $this->getJiminnyRecipientUsers($report));\n }\n }\n\n $emails = [];\n\n return array_values(array_filter(\n $recipients,\n static function ($recipient) use (&$emails) {\n if (empty($recipient['email']) || in_array($recipient['email'], $emails, true)) {\n return false;\n }\n $emails[] = $recipient['email'];\n\n return true;\n }\n ));\n }\n\n private function resolveAskJiminnyRecipients(AutomatedReport $report): array\n {\n $recipients = [];\n\n $creator = $report->getCreator();\n if ($creator !== null) {\n $recipients[] = [\n 'email' => $creator->getEmailAddress(),\n 'name' => $creator->getName(),\n 'timezone' => $creator->getTimezone()->getName(),\n ];\n }\n\n return array_merge(\n $recipients,\n $this->buildRecipientUsers($report->getRecipients()),\n $this->getGroupRecipientUsers($report),\n );\n }\n\n private function getGroupRecipientUsers(AutomatedReport $report): array\n {\n $users = [];\n foreach ($report->getGroups() as $groupId) {\n $group = $this->groupRepository->find($groupId);\n if ($group === null) {\n continue;\n }\n foreach ($group->getMembers() as $member) {\n $users[] = [\n 'email' => $member->getEmailAddress(),\n 'name' => $member->getName(),\n 'timezone' => $member->getTimezone()->getName(),\n ];\n }\n }\n\n return $users;\n }\n\n public function getReportTypeName(AutomatedReportResult $report): string\n {\n $type = $report->getReport()->getType();\n\n $getType = $this->transformReportType($type);\n\n return $getType['name'];\n }\n\n public function getReportPeriodName(AutomatedReportResult $report): string\n {\n $from = $report->getFromDate();\n $to = $report->getToDate();\n $frequency = $report->getReport()->getFrequency();\n\n if ($from === null || $to === null) {\n if (! $report->getReport()->isAskJiminnyReport()) {\n $invalidPeriod = $from === null ? 'from' : 'to';\n\n throw new ApplicationException('Report period is invalid: ' . $invalidPeriod);\n }\n\n $period = $this->calculateFromAndToDatePeriod($frequency);\n $from = $period['fromDate'];\n $to = $period['toDate'];\n }\n\n return $this->formatReportPeriodName($frequency, $from, $to);\n }\n\n private function formatReportPeriodName(string $frequency, Carbon $from, Carbon $to): string\n {\n $fromYear = $from->format('Y');\n $toYear = $to->format('Y');\n $differentYears = $fromYear !== $toYear;\n\n switch ($frequency) {\n case self::FREQUENCY_DAILY:\n return $from->format('j M Y');\n\n case self::FREQUENCY_QUARTERLY:\n // 'Jan-Mar 2025' or 'Nov 2024-Jan 2025' if years differ\n $startMonth = $from->format('M');\n $endMonth = $to->copy()->subMonth();\n $endMonthName = $endMonth->format('M');\n $endMonthYear = $endMonth->format('Y');\n\n if ($differentYears) {\n return \"{$startMonth} {$fromYear} - {$endMonthName} {$endMonthYear}\";\n }\n\n return \"{$startMonth} - {$endMonthName} {$toYear}\";\n\n case self::FREQUENCY_MONTHLY:\n // 'May 2025' - monthly reports are always within the same year\n return $from->format('M Y');\n\n case self::FREQUENCY_WEEKLY:\n // '4 - 8 Aug 2025', '27 Oct - 3 Nov 2025', or '28 Dec 2024 - 3 Jan 2025' if years differ\n $startDay = $from->format('j');\n $endDay = $to->format('j');\n $startMonth = $from->format('M');\n $endMonth = $to->format('M');\n\n if ($differentYears) {\n return \"{$startDay} {$startMonth} {$fromYear} - {$endDay} {$endMonth} {$toYear}\";\n }\n\n if ($startMonth !== $endMonth) {\n return \"{$startDay} {$startMonth} - {$endDay} {$endMonth} {$toYear}\";\n }\n\n return \"{$startDay} - {$endDay} {$endMonth} {$toYear}\";\n\n case self::FREQUENCY_ONE_OFF:\n // '2 May-31 May 2025' or '15 Dec 2024-15 Jan 2025' if years differ\n $startDay = $from->format('j');\n $startMonth = $from->format('M');\n $endDay = $to->format('j');\n $endMonth = $to->format('M');\n\n // If same month and year, use a format like '2-31 May 2025'\n if ($startMonth === $endMonth && ! $differentYears) {\n return \"{$startDay} - {$endDay} {$startMonth} {$toYear}\";\n }\n\n // If different years, include both years\n if ($differentYears) {\n return \"{$startDay} {$startMonth} {$fromYear} - {$endDay} {$endMonth} {$toYear}\";\n }\n\n // Same year but different months\n return \"{$startDay} {$startMonth} - {$endDay} {$endMonth} {$toYear}\";\n\n default:\n // Default format for unknown frequencies\n return $from->format('j M Y') . ' - ' . $to->format('j M Y');\n }\n }\n\n public function getReportTeamsName(AutomatedReportResult $report): string\n {\n $groups = $report->getGroups();\n\n if (empty($groups)) {\n return 'All';\n }\n\n // Get group names from repository\n $groupNames = [];\n foreach ($groups as $groupId) {\n $group = $this->groupRepository->find($groupId);\n if ($group) {\n $groupNames[] = $group->getName();\n }\n }\n\n if (count($groupNames) === 1) {\n // Single team format\n $teamsName = $groupNames[0];\n } else {\n // Multiple teams format\n $teamsName = implode(', ', $groupNames);\n }\n\n return $teamsName;\n }\n\n public function getReportFileName(AutomatedReportResult $report): string\n {\n $customName = $report->getReport()->getCustomName();\n $periodName = $this->getReportPeriodName($report);\n $filenameSuffix = $this->getFilenameSuffix($report);\n\n if ($customName) {\n if ($filenameSuffix) {\n $customName .= \" {$filenameSuffix}\";\n }\n\n return $this->sanitizeFileName(\"{$customName} - {$periodName}\");\n }\n\n $baseName = $this->getReportTypeName($report);\n\n if ($filenameSuffix) {\n $baseName .= \" {$filenameSuffix}\";\n }\n\n return $this->sanitizeFileName(\"{$baseName} - {$periodName} - {$this->getReportTeamsName($report)}\");\n }\n\n public function getReportFileNameWithExtension(AutomatedReportResult $result): string\n {\n $extension = $this->getMediaTypeMetadata($result)['extension'];\n\n return $this->getReportFileName($result) . '.' . $extension;\n }\n\n public function sanitizeFileName(string $fileName): string\n {\n return str_replace(['/', '\\\\'], '-', $fileName);\n }\n\n public function isUserRecipientOfReport(User $user, AutomatedReport $report): bool\n {\n $recipients = array_map('intval', $report->getRecipients()['users'] ?? []);\n\n return in_array($user->getId(), $recipients);\n }\n\n public function transformReportResults(Collection $automatedReportResults): array\n {\n $data = [];\n foreach ($automatedReportResults as $automatedReportResult) {\n /** @var AutomatedReportResult $automatedReportResult */\n\n $report = $automatedReportResult->getReport();\n\n $createdBy = $report->getCreator();\n $creator = [\n 'id' => $createdBy?->getUuid(),\n 'name' => $createdBy?->getName(),\n 'email' => $createdBy?->getEmailAddress(),\n 'photoUrl' => $createdBy?->getPhotoUrl(),\n ];\n\n $data[] = [\n 'id' => $automatedReportResult->getUuid(),\n 'name' => $automatedReportResult->getName(),\n 'frequency' => $this->transformFrequency($report->getFrequency()),\n 'recipients' => [\n ...array_values($this->transformGroups(team: $report->getTeam(), groupsIds: $report->getGroups())),\n ...array_values($this->transformRecipients($report->getRecipients())),\n ],\n 'report_type' => $this->transformReportType($report->getType()),\n 'media_type' => $automatedReportResult->getMediaType(),\n 'downloadUrl' => $this->generateReportResultDownloadUrl($automatedReportResult),\n 'viewUrl' => $this->generateReportResultViewUrl($automatedReportResult),\n 'generated_at' => $automatedReportResult->getGeneratedAt()?->toIso8601String(),\n 'creator' => $creator,\n ];\n }\n\n return $data;\n }\n\n public function hasCallTypeConference(AutomatedReport $report): bool\n {\n return in_array(self::CALL_TYPE_CONFERENCE['id'], $report->getCallTypes(), true);\n }\n\n public function hasCallTypeDialer(AutomatedReport $report): bool\n {\n return in_array(self::CALL_TYPE_DIALER['id'], $report->getCallTypes(), true);\n }\n\n // transformers\n private function transformTeam(Team $team): array\n {\n if (! $team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {\n return [];\n }\n\n return [\n 'id' => $team->getUuid(),\n 'name' => $team->getName(),\n ];\n }\n\n private function transformReportFullView(AutomatedReport $report): array\n {\n $base = $this->transformReportBase($report);\n\n return $report->getType() === self::TYPE_ASK_JIMINNY\n ? $base + $this->transformAskJiminnyFields($report)\n : $base + $this->transformStandardReportFields($report);\n }\n\n private function transformReportBase(AutomatedReport $report): array\n {\n return [\n 'id' => $report->getUuid(),\n 'organization' => $this->transformOrganization(team: $report->getTeam()),\n 'report_type' => $this->transformReportType($report->getType()),\n 'frequency' => $this->transformFrequency($report->getFrequency()),\n ];\n }\n\n private function transformStandardReportFields(AutomatedReport $report): array\n {\n $team = $report->getTeam();\n\n return [\n 'report_enabled' => $report->getStatus(),\n 'start_date_period' => $report->getFrom()?->format('Y-m-d H:i:s'),\n 'end_date_period' => $report->getTo()?->format('Y-m-d H:i:s'),\n 'deal_value_min' => $report->getDealValueMin(),\n 'deal_value_max' => $report->getDealValueMax(),\n 'call_types' => $this->transformCallType($report->getCallTypes()),\n 'media_types' => $this->transformMediaTypes($report),\n 'call_duration_min' => $this->transformDurationToMinutes($report->getCallDurationMin()),\n 'call_duration_max' => $this->transformDurationToMinutes($report->getCallDurationMax()),\n 'teams' => $this->transformGroups(team: $team, groupsIds: $report->getGroups()),\n 'deal_at_call_stages' => $this->transformStages(team: $team, stagesIds: $report->getDealAtCallStages()),\n 'current_deal_stages' => $this->transformStages(team: $team, stagesIds: $report->getCurrentDealStages()),\n 'recipients' => $this->transformRecipients($report->getRecipients()),\n 'created_by' => $this->transformCreator($report->getCreator()),\n 'additional_prompt_input' => $report->getAdditionalPromptInput(),\n 'custom_name' => $report->getCustomName(),\n 'created_at' => $report->getCreatedAt()->format('Y-m-d H:i:s'),\n 'updated_at' => $report->getUpdatedAt()->format('Y-m-d H:i:s'),\n 'deleted_at' => $report->getDeletedAt()?->format('Y-m-d H:i:s'),\n ];\n }\n\n private function transformAskJiminnyFields(AutomatedReport $report): array\n {\n $team = $report->getTeam();\n $creatorId = $report->getAttribute('created_by');\n $explicitUserIds = array_values(array_filter(\n $report->getRecipients()['users'] ?? [],\n static fn ($id) => $id !== $creatorId\n ));\n\n return [\n 'report_name' => $report->getCustomName(),\n 'enabled' => $report->getStatus(),\n 'share_teams' => $this->transformGroups(team: $team, groupsIds: $report->getGroups()),\n 'share_users' => $this->transformRecipients(['users' => $explicitUserIds]),\n 'saved_search' => $this->transformSafeSearch($report->getSavedSearch()),\n 'ask_jiminny_prompt' => $this->transformAskJiminnyPrompt($report->getAskAnythingPrompt()),\n 'expires_on' => $report->getExpiresAt()?->format('Y-m-d'),\n ];\n }\n\n private function transformOrganization(?Team $team): array\n {\n return [\n 'id' => $team?->getUuid(),\n 'name' => $team?->getName(),\n ];\n }\n\n private function transformReportType(string $type): array\n {\n foreach (self::ALL_TYPES as $typeItem) {\n if ($typeItem['id'] === $type) {\n return $typeItem;\n }\n }\n\n return [];\n }\n\n private function transformCallType(array $types): array\n {\n $result = [];\n $callTypes = [self::CALL_TYPE_CONFERENCE, self::CALL_TYPE_DIALER];\n\n foreach ($types as $type) {\n foreach ($callTypes as $callTypeItem) {\n if ($callTypeItem['id'] === $type) {\n $result[] = $callTypeItem;\n\n break;\n }\n }\n }\n\n return $result;\n }\n\n private function transformMediaTypes(AutomatedReport $report): array\n {\n $values = [];\n\n foreach ($report->getMediaTypes() as $mediaType) {\n if (! in_array($mediaType, self::MEDIA_TYPES, true)) {\n continue;\n }\n\n $values[] = match ($mediaType) {\n self::MEDIA_TYPE_PDF => self::MEDIA_TYPE_OBJECT_PDF,\n self::MEDIA_TYPE_PODCAST => self::MEDIA_TYPE_OBJECT_PODCAST,\n };\n }\n\n return $values;\n }\n\n private function transformFrequency(string $frequency): array\n {\n foreach (self::ALL_FREQUENCIES as $frequencyItem) {\n if ($frequencyItem['id'] === $frequency) {\n return $frequencyItem;\n }\n }\n\n return [];\n }\n\n public function transformDurationToMinutes(?int $duration): ?int\n {\n if (! $duration) {\n return null;\n }\n\n return (int) ($duration / 60);\n }\n\n private function transformGroups(?Team $team, array $groupsIds): array\n {\n if (empty($groupsIds) || ! $team) {\n return [];\n }\n\n $data = [];\n foreach ($groupsIds as $groupId) {\n $group = $team->groups()->where('id', $groupId)->first();\n\n if ($group) {\n $data[] = [\n 'id' => $group->getUuid(),\n 'name' => $group->getName(),\n 'photoUrl' => $group->getPhotoUrl(),\n ];\n }\n }\n\n return $data;\n }\n\n private function transformStages(?Team $team, array $stagesIds): array\n {\n if (empty($stagesIds) || ! $team) {\n return [];\n }\n\n $data = [];\n foreach ($stagesIds as $stageId) {\n $stage = $team->stages()->where('id', $stageId)->first();\n\n if ($stage) {\n $data[] = [\n 'id' => $stage->getUuid(),\n 'name' => $stage->getName(),\n ];\n }\n }\n\n return $data;\n }\n\n private function transformRecipients(array $recipients): array\n {\n $users = [];\n foreach ($recipients['users'] ?? [] as $userId) {\n $users[] = $this->transformUser($userId);\n }\n\n return $users;\n }\n\n private function transformCreator(?User $user): ?array\n {\n if ($user === null) {\n return null;\n }\n\n return $this->transformUser($user->getId());\n }\n\n private function transformAskJiminnyPrompt(?AskAnythingPrompt $prompt): ?array\n {\n if ($prompt === null) {\n return null;\n }\n\n return [\n 'id' => $prompt->getUuid(),\n 'name' => $prompt->getTitle(),\n ];\n }\n\n private function transformSafeSearch(?Search $search): ?array\n {\n if ($search === null) {\n return null;\n }\n\n return [\n 'id' => $search->getUuid(),\n 'name' => $search->getName(),\n ];\n }\n\n private function transformUser(int $userId): array\n {\n /* @var ?User $user */\n $user = $this->userRepository->find($userId);\n\n return [\n 'id' => $user?->getUuid(),\n 'name' => $user?->getName(),\n 'email' => $user?->getEmailAddress(),\n 'photoUrl' => $user?->getPhotoUrl(),\n ];\n }\n\n public function create(array $data): array\n {\n $validatedData = $this->validateAndTransformData($data);\n $validatedData['created_by'] = auth()->id();\n\n $automatedReport = $this->automatedReportsRepository->create($validatedData);\n\n $this->generateOneOffReport($automatedReport);\n\n return $this->transformReportFullView($automatedReport);\n }\n\n public function update(string $uuid, array $data): array\n {\n $validatedData = $this->validateAndTransformData($data);\n $report = $this->automatedReportsRepository->findByUuid($uuid);\n\n if (! $report) {\n throw new InvalidArgumentException('Report not found');\n }\n\n $oldCustomName = $report->getCustomName();\n\n $automatedReport = $this->automatedReportsRepository->update($report, $validatedData);\n\n if ($oldCustomName !== $automatedReport->getCustomName()) {\n $this->updateResultNames($automatedReport);\n }\n\n $this->generateOneOffReport($automatedReport);\n\n return $this->transformReportFullView($automatedReport);\n }\n\n /**\n * Create an Ask Jiminny report.\n */\n public function createAskJiminnyReport(array $data, User $creator): array\n {\n $validatedData = $this->validateAskJiminnyReportData($data, $creator);\n $validatedData['created_by'] = $creator->getId();\n\n $automatedReport = $this->automatedReportsRepository->create($validatedData);\n\n return $this->transformReportFullView($automatedReport);\n }\n\n /**\n * Update an Ask Jiminny report.\n */\n public function updateAskJiminnyReport(AutomatedReport $report, array $data, User $user): array\n {\n if (! $report->isAskJiminnyReport()) {\n throw new InvalidArgumentException('Report is not an Ask Jiminny report');\n }\n\n $validatedData = $this->validateAskJiminnyReportData($data, $user);\n\n $oldCustomName = $report->getCustomName();\n\n $automatedReport = $this->automatedReportsRepository->update($report, $validatedData);\n\n if ($oldCustomName !== $automatedReport->getCustomName()) {\n $this->updateResultNames($automatedReport);\n }\n\n return $this->transformReportFullView($automatedReport);\n }\n\n public function updateAskJiminnyReportStatus(AutomatedReport $report, bool $status): array\n {\n $this->automatedReportsRepository->update($report, ['status' => $status]);\n\n return $this->transformReportFullView($report->fresh());\n }\n\n /**\n * Validate and transform data for Ask Jiminny reports.\n */\n private function validateAskJiminnyReportData(array $data, User $user): array\n {\n // Validate name\n $name = trim($data['report_name'] ?? '');\n if (empty($name)) {\n throw new InvalidArgumentException('Report name is required');\n }\n if (mb_strlen($name) > 50) {\n throw new InvalidArgumentException('Report name must be 50 characters or less');\n }\n\n // Validate frequency (only daily, weekly, monthly for Ask Jiminny)\n $frequency = $data['frequency'] ?? null;\n $askJiminnyFrequencies = [self::FREQUENCY_DAILY, self::FREQUENCY_WEEKLY, self::FREQUENCY_MONTHLY];\n if (! in_array($frequency, $askJiminnyFrequencies, true)) {\n throw new InvalidArgumentException('Frequency must be daily, weekly, or monthly');\n }\n\n // Validate expiration date\n $expiresAt = $data['expires_on'] ?? null;\n if (empty($expiresAt)) {\n throw new InvalidArgumentException('Expiration date is required');\n }\n\n try {\n $expiresAtDate = Carbon::parse($expiresAt);\n } catch (InvalidFormatException $e) {\n throw new InvalidArgumentException('Expiration date format is invalid');\n }\n $maxExpiration = Carbon::now()->addYear();\n if ($expiresAtDate->gt($maxExpiration)) {\n throw new InvalidArgumentException('Expiration date cannot be more than 1 year from now');\n }\n if ($expiresAtDate->isPast()) {\n throw new InvalidArgumentException('Expiration date cannot be in the past');\n }\n\n // Validate saved search\n $activitySearchId = $data['saved_search'] ?? null;\n if (empty($activitySearchId)) {\n throw new InvalidArgumentException('Saved search is required');\n }\n $savedSearch = $this->activitySearchRepository->findByUuidAndUser($activitySearchId, $user);\n if (! $savedSearch) {\n throw new InvalidArgumentException('Saved search not found or does not belong to you');\n }\n\n // Validate saved prompt\n $askAnythingPromptId = $data['ask_jiminny_prompt'] ?? null;\n if (empty($askAnythingPromptId)) {\n throw new InvalidArgumentException('Ask Jiminny prompt is required');\n }\n $prompt = $this->askAnythingRepository->getPromptByUuid($askAnythingPromptId);\n if (! $prompt) {\n throw new InvalidArgumentException('Ask Jiminny prompt not found');\n }\n\n // Validate status\n $status = $data['enabled'] ?? false;\n\n $recipientUserIds = [$user->getId()];\n\n if (! empty($data['share_users'])) {\n $sharedUserIds = $this->validateAndGetUserIdsByTeam(\n $user->team,\n (array) $data['share_users']\n );\n $recipientUserIds = array_merge($recipientUserIds, $sharedUserIds);\n }\n\n $sharedGroupIds = [];\n if (! empty($data['share_teams'])) {\n $sharedGroupIds = $this->validateAndGetGroupIds($user->team, (array) $data['share_teams']);\n }\n\n $recipientUserIds = array_values(array_unique($recipientUserIds));\n\n return [\n 'team_id' => $user->getTeamId(),\n 'type' => self::TYPE_ASK_JIMINNY,\n 'status' => (bool) $status,\n 'frequency' => $frequency,\n 'custom_name' => $name,\n 'activity_search_id' => $savedSearch->getId(),\n 'ask_anything_prompt_id' => $prompt->getId(),\n 'expires_at' => $expiresAtDate->toDateString(),\n 'media_types' => [self::MEDIA_TYPE_PDF],\n 'call_types' => [],\n 'recipients' => ['users' => $recipientUserIds],\n 'groups' => $sharedGroupIds,\n ];\n }\n\n public static function getAskJiminnyFrequencies(): array\n {\n return array_map(static function ($frequency) {\n return $frequency['id'];\n }, self::ASK_JIMINNY_FREQUENCIES);\n }\n\n public function getAskJiminnyReportFilters(User $user): array\n {\n $savedSearches = $this->activitySearchRepository->findByUserOrderedByName($user)\n ->map(fn (Search $search) => [\n 'id' => $search->getUuid(),\n 'name' => $search->getName(),\n ])\n ->values()->all();\n\n $prompts = collect(\n $this->askAnythingPromptService->get($user, AskAnythingPromptTarget::on_demand)\n )->map(fn (AskAnythingPromptDto $prompt) => [\n 'id' => $prompt->id,\n 'name' => $prompt->title,\n ])->values()->all();\n\n return [\n [\n 'id' => 'prompt',\n 'label' => 'Prompt',\n 'options' => $prompts,\n ],\n [\n 'id' => 'saved_search',\n 'label' => 'Saved Search',\n 'options' => $savedSearches,\n ],\n ];\n }\n\n public function getAskJiminnyReportFormData(User $user, ?AutomatedReport $report = null): array\n {\n $team = $user->getTeam();\n $userTimezone = $user->getTimezone();\n\n $savedSearches = $this->activitySearchRepository->findByUserOrderedByName($user)\n ->map(fn (Search $search) => [\n 'id' => $search->getUuid(),\n 'name' => $search->getName(),\n ])\n ->values()->all();\n\n $prompts = collect(\n $this->askAnythingPromptService->get($user, AskAnythingPromptTarget::on_demand)\n )->map(fn (AskAnythingPromptDto $prompt) => [\n 'id' => $prompt->id,\n 'name' => $prompt->title,\n ])->values()->all();\n\n $teamGroups = $this->groupRepository->getAllByTeam($team)->map(fn ($group) => [\n 'id' => $group->getUuid(),\n 'name' => $group->getName(),\n ])->values()->all();\n\n $shareUsers = $this->recipientsService->getRecipientsFieldData(team: $team)['options'] ?? [];\n\n $sharedTeamsValue = [];\n $sharedUsersValue = [];\n if ($report) {\n $sharedTeamsValue = $this->transformGroups($team, $report->getGroups());\n\n $recipientUserIds = $report->getRecipients()['users'] ?? [];\n $creatorId = $report->getAttribute('created_by');\n $sharedUserIds = array_values(array_filter(\n $recipientUserIds,\n static fn ($id) => $id !== $creatorId\n ));\n $sharedUsersValue = collect($sharedUserIds)\n ->map(fn ($id) => $this->userRepository->find((int) $id))\n ->filter()\n ->map(fn (User $u) => [\n 'id' => $u->getUuid(),\n 'name' => $u->getName(),\n ])\n ->values()\n ->all();\n }\n\n return [\n 'fields' => [\n [\n 'id' => 'enabled',\n 'inputType' => InputTypeEnum::TOGGLE,\n 'label' => '',\n 'value' => $report?->getStatus() ?? false,\n ],\n [\n 'id' => 'report_name',\n 'inputType' => InputTypeEnum::TEXT,\n 'label' => 'Name',\n 'placeholder' => 'Enter name',\n 'required' => true,\n 'validation' => ['maxLength' => 50],\n 'value' => $report?->getCustomName() ?? '',\n ],\n [\n 'id' => 'frequency',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'label' => 'Frequency',\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => self::ASK_JIMINNY_FREQUENCIES,\n 'value' => $report ? $this->transformFrequency($report->getFrequency()) : null,\n ],\n [\n 'id' => 'expires_on',\n 'inputType' => InputTypeEnum::DATE,\n 'label' => 'Expires on',\n 'required' => true,\n 'placeholder' => 'Select',\n 'validation' => [\n 'minDate' => now($userTimezone)->toDateString(),\n 'maxDate' => now($userTimezone)->addYear()->toDateString(),\n ],\n 'value' => $report?->getExpiresAt()?->toDateString(),\n ],\n [\n 'id' => 'share_teams',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'label' => 'Team',\n 'required' => false,\n 'placeholder' => 'Select',\n 'options' => $teamGroups,\n 'value' => $sharedTeamsValue,\n ],\n [\n 'id' => 'share_users',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'label' => 'Team member',\n 'required' => false,\n 'placeholder' => 'Select',\n 'groupLabelKey' => 'label',\n 'groupValuesKey' => 'users',\n 'optionLabelKey' => 'name',\n 'optionValueKey' => 'id',\n 'options' => $shareUsers,\n 'value' => $sharedUsersValue,\n ],\n [\n 'id' => 'saved_search',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'label' => 'Saved search',\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => $savedSearches,\n 'value' => $report && $report->getSavedSearch() ? [\n 'id' => $report->getSavedSearch()->getUuid(),\n 'name' => $report->getSavedSearch()->getName(),\n ] : null,\n ],\n [\n 'id' => 'ask_jiminny_prompt',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'label' => 'Ask Jiminny prompt',\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => $prompts,\n 'value' => $report && $report->getAskAnythingPrompt() ? [\n 'id' => $report->getAskAnythingPrompt()->getUuid(),\n 'name' => $report->getAskAnythingPrompt()->getTitle(),\n ] : null,\n ],\n ],\n ];\n }\n\n private function updateResultNames(AutomatedReport $automatedReport): void\n {\n $results = $this->automatedReportsRepository->getResultsByReport($automatedReport);\n\n foreach ($results as $result) {\n $result->update(['name' => $this->getReportFileName($result)]);\n }\n }\n\n public function updateStatus(string $uuid, array $data): array\n {\n $automatedReport = $this->automatedReportsRepository->findByUuid($uuid);\n\n if (! $automatedReport) {\n throw new ModelNotFoundException('Report not found');\n }\n\n $status = $this->validateReportStatus($data['report_enabled'] ?? null);\n $automatedReport->update([\n 'status' => $status,\n ]);\n\n $this->generateOneOffReport($automatedReport);\n\n return $this->transformReportFullView($automatedReport);\n }\n\n private function generateOneOffReport(AutomatedReport $automatedReport): void\n {\n // the scheduler handles all the other frequency types\n if ($automatedReport->getStatus() === false || $automatedReport->getFrequency() !== self::FREQUENCY_ONE_OFF) {\n return;\n }\n\n $this->dispatcher->dispatch(new RequestGenerateReportJob($automatedReport->getUuid()));\n }\n\n public function getReport(string $uuid): AutomatedReport\n {\n $automatedReport = $this->automatedReportsRepository->findByUuid($uuid);\n\n if (! $automatedReport) {\n throw new ModelNotFoundException('Report not found');\n }\n\n return $automatedReport;\n }\n\n public function get(string $uuid): array\n {\n $automatedReport = $this->getReport($uuid);\n\n return $this->transformReportFullView($automatedReport);\n }\n\n public function list(string $sortColumn = 'created_at', string $sortDirection = 'desc'): array\n {\n $results = [];\n $collection = $this->automatedReportsRepository->getAllStandardReports($sortColumn, $sortDirection);\n\n /** @var AutomatedReport $report */\n foreach ($collection as $report) {\n $results[] = $this->transformReportFullView($report);\n }\n\n return ['data' => $results];\n }\n\n public function listAskJiminnyReports(\n User $user,\n string $sortColumn = 'created_at',\n string $sortDirection = 'desc'\n ): array {\n $results = [];\n $collection = $this->automatedReportsRepository->getAskJiminnyReportsByUser($user, $sortColumn, $sortDirection);\n\n /** @var AutomatedReport $report */\n foreach ($collection as $report) {\n $results[] = $this->transformReportFullView($report);\n }\n\n return ['data' => $results];\n }\n\n public function delete(string $uuid): void\n {\n $automatedReport = $this->automatedReportsRepository->findByUuid($uuid);\n\n if (! $automatedReport) {\n throw new ModelNotFoundException('Report not found');\n }\n\n $automatedReport->delete();\n }\n\n public function createReportResult(AutomatedReport $automatedReport, array $data = []): AutomatedReportResult\n {\n return $this->automatedReportsRepository->createResult(\n array_merge(\n [\n 'report_id' => $automatedReport->getId(),\n 'status' => AutomatedReportResult::STATUS_DEFAULT,\n ],\n $data\n )\n );\n }\n\n public function getReportResult(string $resultUuid): AutomatedReportResult\n {\n $report = $this->automatedReportsRepository->findResultByUuid($resultUuid);\n\n if (! $report) {\n throw new ModelNotFoundException('Report Result not found');\n }\n\n return $report;\n }\n\n public function findChildResult(AutomatedReportResult $result, string $type): ?AutomatedReportResult\n {\n return $this->automatedReportsRepository->findChildResult($result, $type);\n }\n\n // prophet API calls\n /**\n * @throws ApplicationException\n */\n public function getGenerateReportPayload(AutomatedReport $automatedReport, string $reportResultUuid): array\n {\n $period = $this->calculateFromAndToDate($automatedReport);\n $fromDate = $period['fromDate'];\n $toDate = $period['toDate'];\n\n return [\n 'team_id' => $automatedReport->getTeamId(),\n 'request_id' => $reportResultUuid,\n 'report_type' => $automatedReport->getType(),\n 'media_types' => $automatedReport->getMediaTypes(),\n 'from_date' => $fromDate->startOfDay()->format(DateTimeInterface::RFC3339),\n 'to_date' => $toDate->endOfDay()->format(DateTimeInterface::RFC3339),\n 'group_ids' => $automatedReport->getGroups(),\n 'call_deal_stage' => $automatedReport->getDealAtCallStages(),\n 'current_deal_stage' => $automatedReport->getCurrentDealStages(),\n 'deal_min_value' => $automatedReport->getDealValueMin(),\n 'deal_max_value' => $automatedReport->getDealValueMax(),\n 'call_types' => $automatedReport->getCallTypes(),\n 'call_duration_min_seconds' => $automatedReport->getCallDurationMin(),\n 'call_duration_max_seconds' => $automatedReport->getCallDurationMax(),\n 'special_requirements' => $automatedReport->getAdditionalPromptInput(),\n 'callback_url' => $this->getCallbackUrl(),\n 'report_period' => $this->formatReportPeriodName(\n $automatedReport->getFrequency(),\n $fromDate,\n $toDate,\n ),\n 'playbook_categories' => $automatedReport->getPlaybookCategories(),\n 'custom_name' => $automatedReport->getCustomName(),\n ];\n }\n\n // $inputPayload - FE payload structure\n public function getActivitiesCountPayload(array $inputPayload): array\n {\n // Use validateAndTransformData to validate and normalize input\n $validatedData = $this->validateAndTransformData($inputPayload);\n $period = $this->calculateFromAndToDatePeriod(\n $validatedData['frequency'],\n Carbon::parse($validatedData['from']),\n Carbon::parse($validatedData['to']),\n );\n $fromDate = $period['fromDate'];\n $toDate = $period['toDate'];\n\n // Create payload similar to getGenerateReportPayload\n return [\n 'team_id' => $validatedData['team_id'],\n 'group_ids' => $validatedData['groups'] ?? [],\n 'report_type' => $validatedData['type'],\n 'from_date' => $fromDate->format(DateTimeInterface::RFC3339),\n 'to_date' => $toDate->format(DateTimeInterface::RFC3339),\n 'call_deal_stage' => $validatedData['deal_at_call_stages'] ?? [],\n 'current_deal_stage' => $validatedData['current_deal_stages'] ?? [],\n 'deal_min_value' => $validatedData['deal_value_min'] ?? null,\n 'deal_max_value' => $validatedData['deal_value_max'] ?? null,\n 'call_types' => $validatedData['call_types'],\n 'call_duration_min_seconds' => $validatedData['call_duration_min'] ?? null,\n 'call_duration_max_seconds' => $validatedData['call_duration_max'] ?? null,\n 'special_requirements' => $validatedData['additional_prompt_input'] ?? null,\n 'playbook_categories' => $validatedData['playbook_categories'] ?? [],\n 'request_id' => null,\n 'callback_url' => null,\n ];\n }\n\n public function shouldSendReport(array $users, ?CarbonInterface $generatedAt = null): bool\n {\n if (empty($users)) {\n return false;\n }\n\n $earliestTz = collect($users)\n ->mapWithKeys(function (array $user) {\n $tz = new DateTimeZone($user['timezone']);\n $nowUtc = new DateTime('now', new DateTimeZone('UTC'));\n $offset = $tz->getOffset($nowUtc);\n\n return [$user['timezone'] => $offset];\n })\n ->sortDesc()\n ->keys()\n ->first();\n\n $now = Carbon::now($earliestTz);\n $isScheduledTime = (int) $now->format('H') === self::SENT_REPORT_AT_HOURS;\n\n if ($isScheduledTime) {\n return true;\n }\n\n return $this->hasPassedScheduledTime($generatedAt, $earliestTz);\n }\n\n public function hasPassedScheduledTime(?CarbonInterface $generatedAt, string $timezone): bool\n {\n if ($generatedAt === null) {\n return false;\n }\n\n $now = Carbon::now($timezone);\n $scheduledTime = $now->copy()->setTime(self::SENT_REPORT_AT_HOURS, 0, 0);\n\n if ($now->hour < self::SENT_REPORT_AT_HOURS) {\n $scheduledTime = $scheduledTime->subDay();\n }\n\n $scheduledTimeUtc = $scheduledTime->copy()->utc();\n $generatedAtUtc = $generatedAt->copy()->utc();\n $nowUtc = $now->copy()->utc();\n\n return $generatedAtUtc->lt($scheduledTimeUtc) && $nowUtc->gt($scheduledTimeUtc);\n }\n\n public function calculateFromAndToDatePeriod(\n string $frequency,\n ?Carbon $fromDate = null,\n ?Carbon $toDate = null\n ): array {\n if ($frequency === self::FREQUENCY_ONE_OFF) {\n return [\n 'fromDate' => $fromDate,\n 'toDate' => $toDate,\n ];\n }\n\n $now = Carbon::now();\n\n return match ($frequency) {\n self::FREQUENCY_DAILY => [\n 'fromDate' => $now->copy()->subDay()->startOfDay(),\n 'toDate' => $now->copy()->subDay()->endOfDay(),\n ],\n self::FREQUENCY_WEEKLY => [\n 'fromDate' => $now->copy()->subWeeks(1)->startOfDay(),\n 'toDate' => $now->copy()->subDay()->endOfDay(),\n ],\n self::FREQUENCY_MONTHLY => [\n 'fromDate' => $now->copy()->subMonths(1)->startOfDay(),\n 'toDate' => $now->copy()->subDay()->endOfDay(),\n ],\n self::FREQUENCY_QUARTERLY => [\n 'fromDate' => $now->copy()->subMonths(3)->startOfDay(),\n 'toDate' => $now->copy()->subDay()->endOfDay(),\n ],\n default => throw new InvalidArgumentException(\"Unsupported frequency: {$frequency}\"),\n };\n }\n\n private function calculateFromAndToDate(AutomatedReport $automatedReport): array\n {\n return $this->calculateFromAndToDatePeriod(\n $automatedReport->getFrequency(),\n $automatedReport->getFrom(),\n $automatedReport->getTo()\n );\n }\n\n public function getAskJiminnyGenerateReportPayload(\n AutomatedReport $automatedReport,\n AutomatedReportResult $reportResult,\n array $activityIds,\n ): array {\n return [\n 'user_question' => $automatedReport->getAskAnythingPrompt()?->getContent(),\n 'call_ids' => array_map('strval', $activityIds),\n 'team_id' => $automatedReport->getTeamId(),\n 'request_id' => $reportResult->getUuid(),\n 'callback_url' => $this->getCallbackUrl(),\n 'report_period' => $this->getReportPeriodName($reportResult),\n 'report_name' => $automatedReport->getCustomName(),\n ];\n }\n\n private function getCallbackUrl(): string\n {\n return $this->webhookService->route('jiminny.webhook.reports.ready');\n }\n\n /**\n * Validate and transform payload data for automated reports\n *\n * @param array $data\n *\n * @throws InvalidArgumentException\n *\n * @return array\n */\n private function validateAndTransformData(array $data): array\n {\n // Validate organization (team) and check feature\n $team = $this->validateOrganization($data['organization'] ?? null);\n\n $status = $this->validateReportStatus($data['report_enabled'] ?? null);\n $type = $this->validateReportType($data['report_type'] ?? null);\n $frequency = $this->validateFrequency($data['frequency'] ?? null);\n $additionalPromptInput = $this->validateAdditionalPromptInput(\n $data['additional_prompt_input'] ?? null\n );\n $customReportName = $this->validateCustomReportName($data['custom_name'] ?? null);\n\n // Prepare data for the database\n $reportData = [\n 'team_id' => $team->getId(),\n 'type' => $type,\n 'status' => $status,\n 'frequency' => $frequency,\n 'additional_prompt_input' => $additionalPromptInput,\n 'custom_name' => $customReportName,\n ];\n\n // Validate deal values\n $reportData = $this->validateDealValues($data, $reportData);\n\n // Validate date range\n $reportData = $this->validateDateRange($data, $reportData, $frequency);\n\n // Validate call durations\n $reportData = $this->validateCallDurations($data, $reportData);\n\n // Validate call types\n $reportData = $this->validateCallTypes($data, $reportData);\n\n // Validate media types\n $reportData = $this->validateMediaTypes($data, $reportData);\n\n // Validate groups\n if (isset($data['teams'])) {\n $reportData['groups'] = $this->validateAndGetGroupIds($team, $data['teams']);\n }\n\n // Validate deal stages\n $reportData = $this->validateDealStages($data, $reportData, $team, $type);\n\n // Validate playbook categories\n $reportData = $this->validatePlaybookCategories($data, $reportData, $team);\n\n // Validate recipients\n $reportData['recipients'] = [\n 'users' => $this->validateAndGetUserIdsByTeam($team, $data['recipients'] ?? []),\n ];\n\n if (isset($data['jiminny_recipients'])) {\n // Validate Jiminny recipients\n $reportData['jiminny_recipients'] = [\n 'users' => $this->validateAndGetJiminnyUserIds((array) $data['jiminny_recipients']),\n ];\n }\n\n return $reportData;\n }\n\n private function validateDealValues(array $data, array $reportData): array\n {\n if (isset($data['min_deal_value'])) {\n $reportData['deal_value_min'] = (int) $data['min_deal_value'];\n\n if ($reportData['deal_value_min'] > 4294967295 || $reportData['deal_value_min'] < 0) {\n throw new InvalidArgumentException('Min deal value should be between 0 and 4294967295');\n }\n }\n\n if (isset($data['max_deal_value'])) {\n $reportData['deal_value_max'] = (int) $data['max_deal_value'];\n\n if ($reportData['deal_value_max'] > 4294967295 || $reportData['deal_value_max'] < 0) {\n throw new InvalidArgumentException('Max deal value should be between 0 and 4294967295');\n }\n }\n\n if (isset($data['min_deal_value'], $data['max_deal_value'])\n && $data['min_deal_value'] > $data['max_deal_value']\n ) {\n throw new InvalidArgumentException('Min deal value cannot be greater than max deal value');\n }\n\n return $reportData;\n }\n\n private function validateDateRange(array $data, array $reportData, string $frequency): array\n {\n // Set date range only for one_off frequency\n if ($frequency === 'one_off') {\n if (isset($data['start_date_period'])) {\n $reportData['from'] = $this->parseDate($data['start_date_period']);\n }\n\n if (isset($data['end_date_period'])) {\n $reportData['to'] = $this->parseDate($data['end_date_period']);\n }\n\n if (empty($reportData['from']) || empty($reportData['to'])) {\n throw new InvalidArgumentException(\n 'Start date and end date are required for one_off frequency'\n );\n }\n } else {\n $reportData['from'] = null;\n $reportData['to'] = null;\n }\n\n return $reportData;\n }\n\n private function validateCallDurations(array $data, array $reportData): array\n {\n // Convert call durations from minutes to seconds\n if (isset($data['min_call_duration'])) {\n $reportData['call_duration_min'] = (int) $data['min_call_duration'] * 60;\n\n if ($reportData['call_duration_min'] > 4294967295 || $reportData['call_duration_min'] < 0) {\n throw new InvalidArgumentException('Min call duration should be between 0 and 4294967295');\n }\n }\n\n if (isset($data['max_call_duration'])) {\n $reportData['call_duration_max'] = (int) $data['max_call_duration'] * 60;\n\n if ($reportData['call_duration_max'] > 4294967295 || $reportData['call_duration_max'] < 0) {\n throw new InvalidArgumentException('Max call duration should be between 0 and 4294967295');\n }\n }\n\n return $reportData;\n }\n\n private function validateCallTypes(array $data, array $reportData): array\n {\n // Set call types\n $reportData['call_types'] = $data['call_type'] ?? [];\n if (empty($reportData['call_types'])) {\n $reportData['call_types'] = self::getCallTypes();\n }\n\n foreach ($reportData['call_types'] as $callType) {\n if (! in_array($callType, self::getCallTypes(), true)) {\n throw new InvalidArgumentException(sprintf('Call type %s is invalid', $callType));\n }\n }\n\n return $reportData;\n }\n\n private function validateMediaTypes(array $data, array $reportData): array\n {\n // Set media types from input data\n $reportData['media_types'] = $data['media_types'] ?? [];\n\n if (empty($reportData['media_types'])) {\n throw new InvalidArgumentException('Media types are required');\n }\n\n foreach ($reportData['media_types'] as $mediaType) {\n if (! in_array($mediaType, self::MEDIA_TYPES, true)) {\n throw new InvalidArgumentException(sprintf('Media type %s is invalid', $mediaType));\n }\n }\n\n return $reportData;\n }\n\n private function validateDealStages(array $data, array $reportData, Team $team, string $reportType): array\n {\n // Validate and set deal stages\n if (isset($data['deal_stage_at_call'])) {\n $reportData['deal_at_call_stages'] =\n $this->validateAndGetDealStageIds($team, $data['deal_stage_at_call'], 'Deal stage at call');\n }\n\n if (isset($data['current_deal_stage'])) {\n $reportData['current_deal_stages'] =\n $this->validateAndGetDealStageIds($team, $data['current_deal_stage'], 'Current deal stage');\n }\n\n // Ensure current_deal_stage is not provided for loss_analysis report type\n if ($reportType === self::TYPE_LOSS_ANALYSIS && ! empty($data['current_deal_stage'])) {\n throw new InvalidArgumentException('Current deal stage is not applicable for Loss Analysis reports');\n }\n\n return $reportData;\n }\n\n // transform uuid to id\n private function validatePlaybookCategories(array $data, array $reportData, Team $team): array\n {\n $key = 'playbook_categories';\n\n if (isset($data[$key])) {\n $payloadIds = $data[$key];\n $ids = [];\n\n foreach ($payloadIds as $uuid) {\n $uuid = (string) $uuid;\n\n try {\n $playbookCategory = $this->playbookCategoryRepository->findByUuid($uuid);\n } catch (Throwable $throwable) {\n Log::error(__METHOD__ . ' ' . $throwable->getMessage());\n\n throw new InvalidArgumentException(sprintf('Playbook category %s not found', $uuid));\n }\n\n if (! $playbookCategory) {\n throw new InvalidArgumentException(sprintf('Playbook category %s not found', $uuid));\n }\n\n if (! $playbookCategory->hasPlaybook()) {\n throw new InvalidArgumentException(sprintf('Playbook category %s has no playbook', $uuid));\n }\n\n if ($playbookCategory->getPlaybook()->getTeamId() !== $team->getId()) {\n throw new InvalidArgumentException(\n sprintf('Playbook category %s not found for team %s', $uuid, $team->getUuid())\n );\n }\n\n $ids[] = $playbookCategory->getId();\n }\n\n $reportData[$key] = $ids;\n }\n\n return $reportData;\n }\n\n private function validateReportStatus($status): bool\n {\n if (! in_array($status, [true, false], true)) {\n throw new InvalidArgumentException('Report status is invalid');\n }\n\n return $status;\n }\n\n private function validateReportType($type): string\n {\n if (! in_array($type, self::getTypes(), true)) {\n throw new InvalidArgumentException(sprintf('Report type is invalid: %s', $type));\n }\n\n return $type;\n }\n\n private function validateFrequency($frequency): string\n {\n if (! in_array($frequency, self::getFrequencies(), true)) {\n throw new InvalidArgumentException('Frequency is invalid');\n }\n\n return $frequency;\n }\n\n private function validateAdditionalPromptInput(?string $additionalPromptInput): ?string\n {\n if ($additionalPromptInput && strlen($additionalPromptInput) > 5000) {\n throw new InvalidArgumentException('Additional Prompt Input should be less than 5000 characters');\n }\n\n return $additionalPromptInput;\n }\n\n private function validateCustomReportName(?string $customReportName): ?string\n {\n if ($customReportName === null || $customReportName === '') {\n return null;\n }\n\n if (strlen($customReportName) > 70) {\n throw new InvalidArgumentException('Custom report name should be less than 70 characters');\n }\n\n return $customReportName;\n }\n\n private function validateOrganization(?string $organizationUuid): Team\n {\n if (! $organizationUuid) {\n throw new InvalidArgumentException('Organization is required');\n }\n\n $team = $this->teamRepository->idOrUuid($organizationUuid);\n\n if (! $team) {\n throw new InvalidArgumentException('Organization not found');\n }\n\n if (! $team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {\n throw new InvalidArgumentException('Organization does not have the Automated Reports feature');\n }\n\n return $team;\n }\n\n private function validateAndGetGroupIds(Team $team, array $teamUuids): array\n {\n $groupIds = [];\n\n foreach ($teamUuids as $uuid) {\n $group = $this->groupRepository->findByUuid($uuid);\n\n if ($group === null || $group->getTeamId() !== $team->getId()) {\n throw new InvalidArgumentException(\n sprintf('Group %s not found for team %s', $uuid, $team->getUuid())\n );\n }\n\n $groupIds[] = $group->getId();\n\n }\n\n return $groupIds;\n }\n\n private function validateAndGetDealStageIds(Team $team, array $stageUuids, string $propertyLabel): array\n {\n $stageIds = [];\n\n foreach ($stageUuids as $uuid) {\n $stage = $this->stageRepository->findByUuid($uuid);\n\n if ($stage === null || $stage->getTeamId() !== $team->getId()) {\n throw new InvalidArgumentException(\n sprintf('Stage %s not found for team %s for %s', $uuid, $team->getUuid(), $propertyLabel)\n );\n }\n\n $stageIds[] = $stage->getId();\n }\n\n return $stageIds;\n }\n\n private function validateAndGetUserIds(array $userUuids, callable $teamCheck): array\n {\n if (empty($userUuids)) {\n return [];\n }\n\n $userIds = [];\n\n foreach ($userUuids as $uuid) {\n $user = $this->userRepository->findByUuid($uuid);\n\n if (! $user || ! $user->isStatusActive()) {\n throw new InvalidArgumentException(\n sprintf('User %s not found or is not active', $uuid)\n );\n }\n\n if (! $teamCheck($user)) {\n throw new InvalidArgumentException(\n sprintf('User %s does not belong to the allowed team(s)', $uuid)\n );\n }\n\n $userIds[] = $user->getId();\n }\n\n return $userIds;\n }\n\n private function validateAndGetUserIdsByTeam(Team $team, array $userUuids): array\n {\n return $this->validateAndGetUserIds($userUuids, fn ($user) => $user->getTeamId() === $team->getId());\n }\n\n private function validateAndGetJiminnyUserIds(array $userUuids): array\n {\n $allowedTeamIds = config('kiosk.teamIds', []);\n\n return $this->validateAndGetUserIds($userUuids, fn ($user) => in_array($user->getTeamId(), $allowedTeamIds, true));\n }\n\n private function parseDate(string $dateString): string\n {\n return date('Y-m-d H:i:s', strtotime($dateString));\n }\n\n private function generateReportResultViewUrl(AutomatedReportResult $result): string\n {\n $mediaResource = $this->getReportMediaRouteResource($result);\n\n return route('ai-reports.' . $mediaResource . '.view', ['uuid' => $result->getUuid()]);\n }\n\n private function generateReportResultDownloadUrl(AutomatedReportResult $result): string\n {\n $mediaResource = $this->getReportMediaRouteResource($result);\n\n return route('ai-reports.' . $mediaResource . '.download', ['uuid' => $result->getUuid()]);\n }\n\n private function getReportMediaRouteResource(AutomatedReportResult $result): string\n {\n if ($result->getMediaType() === self::MEDIA_TYPE_PDF) {\n return self::PDF_KEY;\n } elseif ($result->getMediaType() === self::MEDIA_TYPE_PODCAST) {\n return self::AUDIO_KEY;\n }\n\n throw new \\InvalidArgumentException('Unknown media type.');\n }\n\n public function getMediaPath(AutomatedReportResult $result): ?string\n {\n $url = match ($result->getMediaType()) {\n self::MEDIA_TYPE_PDF => $result->getPdfUrl(),\n self::MEDIA_TYPE_PODCAST => $result->getPodcastAudioUrl(),\n default => null,\n };\n\n if ($url === null) {\n return null;\n }\n\n $path = parse_url(trim($url, '\"\\''), PHP_URL_PATH);\n\n return $path ?: null;\n }\n\n public function getFilenameSuffix(AutomatedReportResult $result): ?string\n {\n return match ($result->getMediaType()) {\n self::MEDIA_TYPE_PODCAST => 'Podcast',\n default => null,\n };\n }\n\n public function getMailSubjectSuffix(AutomatedReportResult $result): string\n {\n return match ($result->getMediaType()) {\n self::MEDIA_TYPE_PDF => 'report',\n self::MEDIA_TYPE_PODCAST => 'podcast',\n default => '',\n };\n }\n\n public function getMediaTypeMetadata(AutomatedReportResult $result): array\n {\n return match ($result->getMediaType()) {\n self::MEDIA_TYPE_PODCAST => ['extension' => 'mp3', 'mime' => 'audio/mpeg'],\n self::MEDIA_TYPE_PDF => ['extension' => 'pdf', 'mime' => 'application/pdf'],\n default => ['extension' => null, 'mime' => null],\n };\n }\n\n public function deleteS3Files(AutomatedReportResult $result): void\n {\n $teamUuid = $result->getReport()->getTeam()->getUuid();\n $reportUuid = $result->getUuid();\n\n // delete all files for a report uuid no mather of pdf, podcast, or both\n // in case of both - the podcast files are linked to the pdf (parent) uuid\n // pdf and podcast date times should be close\n $path = sprintf('%s/%s/%s', $teamUuid, self::S3_DIR, $reportUuid);\n\n foreach (self::FILE_EXTENSIONS_VARIANTS as $extension) {\n $file = $path . '.' . $extension;\n\n if (Storage::exists($file)) {\n Storage::delete($file);\n Log::info('[Reports] Deleted S3 file', [\n 'path' => $file,\n ]);\n }\n }\n\n foreach (self::FILE_PODCAST_EXTENSIONS_VARIANTS as $extension) {\n $file = $path . '_podcast.' . $extension;\n\n if (Storage::exists($file)) {\n Storage::delete($file);\n Log::info('[Reports] Deleted Podcast S3 file', [\n 'path' => $file,\n ]);\n }\n }\n }\n\n /**\n *\n * @param int|null $teamId Optional team ID to filter results\n *\n * @return Collection<int, int> Collection of team IDs\n */\n public function getTeamIdsWithReportsResults(?int $teamId = null): Collection\n {\n return $this->automatedReportsRepository->getTeamIdsWithReportsResults($teamId);\n }\n\n /**\n * Core delete logic for report results using a query\n *\n * @param Builder $query\n * @param array $logContext\n *\n * @return int\n */\n private function deleteReportResultsByQuery(Builder $query, array $logContext = []): int\n {\n $deletedCount = 0;\n\n if ($query->exists()) {\n Log::info(\n 'Run delete report results',\n array_merge(\n $logContext,\n [\n 'service' => 'AutomatedReportsService',\n ]\n )\n );\n\n $query->chunkById(50, function ($results) use (&$deletedCount, $logContext) {\n foreach ($results as $result) {\n $this->deleteReportResult($result);\n $deletedCount++;\n\n Log::info(\n 'Deleted a report result',\n array_merge(\n $logContext,\n [\n 'result_id' => $result->getId(),\n 'report_id' => $result->getReportId(),\n ]\n )\n );\n }\n });\n }\n\n return $deletedCount;\n }\n\n /**\n * Delete report results for a team by retention period\n *\n * @param Team $team\n * @param CarbonImmutable $retentionDate\n *\n * @return int Number of deleted report results\n */\n public function deleteReportsResultsInRetentionPeriod(Team $team, CarbonImmutable $retentionDate): int\n {\n $reportIds = $this->automatedReportsRepository->getReportIdsByTeam($team);\n\n if ($reportIds->isEmpty()) {\n return 0;\n }\n\n $query = $this->automatedReportsRepository\n ->getReportResultsQueryForRetention($team, $retentionDate);\n\n return $this->deleteReportResultsByQuery($query, [\n 'team_id' => $team->getId(),\n 'retention_date' => $retentionDate->toDateTimeString(),\n ]);\n }\n\n /**\n * Delete ALL report results for a specific automated report\n *\n * @param string $uuid\n *\n * @return int\n */\n public function deleteReportResults(string $uuid): int\n {\n $report = $this->getReport($uuid);\n\n $query = $this->automatedReportsRepository->getResultsByReportQuery($report);\n\n return $this->deleteReportResultsByQuery($query, [\n 'report_uuid' => $uuid,\n 'report_id' => $report->getId(),\n ]);\n }\n\n public function deleteReportResult(AutomatedReportResult $result): void\n {\n $this->deleteS3Files($result);\n\n $result->delete();\n }\n\n /**\n * Get all reports for a specific team\n *\n * @param Team $team\n *\n * @return \\Illuminate\\Database\\Eloquent\\Collection\n */\n public function getTeamReports(Team $team): \\Illuminate\\Database\\Eloquent\\Collection\n {\n return $this->automatedReportsRepository->getReportsByTeam($team);\n }\n\n /**\n * Get all report results for a specific report\n *\n * @param AutomatedReport $report\n *\n * @return \\Illuminate\\Database\\Eloquent\\Collection\n */\n public function getReportResults(AutomatedReport $report): \\Illuminate\\Database\\Eloquent\\Collection\n {\n return $this->automatedReportsRepository->getResultsByReport($report);\n }\n\n public function deleteAllReportResults(AutomatedReport $report): void\n {\n $results = $this->getReportResults($report);\n\n /** @var AutomatedReportResult $result */\n foreach ($results as $result) {\n Log::info('Deleting result', [\n 'report' => $report->getId(),\n 'result' => $result->getId(),\n ]);\n\n $this->deleteReportResult($result);\n }\n }\n\n public function deleteAllData(Team $team): void\n {\n Log::info('Deleting automated report and results for team', [\n 'team' => $team->getId(),\n ]);\n\n $reports = $this->getTeamReports($team);\n\n /** @var AutomatedReport $report */\n foreach ($reports as $report) {\n Log::info('Deleting report', [\n 'team' => $team->getId(),\n 'report' => $report->getId(),\n ]);\n\n $this->deleteAllReportResults($report);\n\n $report->delete();\n }\n }\n}","depth":4,"value":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Services\\Kiosk\\AutomatedReports;\n\nuse Carbon\\CarbonImmutable;\nuse Carbon\\CarbonInterface;\nuse Carbon\\Exceptions\\InvalidFormatException;\nuse DateTime;\nuse DateTimeInterface;\nuse DateTimeZone;\nuse Illuminate\\Contracts\\Bus\\Dispatcher as BusDispatcher;\nuse Illuminate\\Database\\Eloquent\\Builder;\nuse Illuminate\\Support\\Carbon;\nuse Illuminate\\Support\\Collection;\nuse Illuminate\\Support\\Facades\\Log;\nuse Illuminate\\Support\\Facades\\Storage;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinition\\InputTypeEnum;\nuse Jiminny\\Component\\AskAnything\\AskAnythingPromptService;\nuse Jiminny\\Component\\AskAnything\\Dtos\\AskAnythingPromptDto;\nuse Jiminny\\Component\\UrlGenerator\\Webhook;\nuse Jiminny\\Contracts\\Repositories\\PlaybookCategoryRepository;\nuse Jiminny\\Contracts\\Repositories\\TeamRepository;\nuse Jiminny\\Contracts\\Repositories\\UserRepository;\nuse Jiminny\\Exceptions\\ApplicationException;\nuse Jiminny\\Exceptions\\InvalidArgumentException;\nuse Jiminny\\Exceptions\\ModelNotFoundException;\nuse Jiminny\\Jobs\\AutomatedReports\\RequestGenerateReportJob;\nuse Jiminny\\Models\\Activity\\Search;\nuse Jiminny\\Models\\AskAnything\\AskAnythingPrompt;\nuse Jiminny\\Models\\AskAnything\\AskAnythingPromptTarget;\nuse Jiminny\\Models\\AutomatedReport;\nuse Jiminny\\Models\\AutomatedReportResult;\nuse Jiminny\\Models\\Contracts\\UserContract;\nuse Jiminny\\Models\\Feature\\FeatureEnum;\nuse Jiminny\\Models\\Team;\nuse Jiminny\\Models\\User;\nuse Jiminny\\Repositories\\AskAnythingRepository;\nuse Jiminny\\Repositories\\AutomatedReportsRepository;\nuse Jiminny\\Repositories\\GroupRepository;\nuse Jiminny\\Repositories\\SearchRepository;\nuse Jiminny\\Repositories\\StageRepository;\nuse Throwable;\n\nclass AutomatedReportsService\n{\n public const string TYPE_LOSS_ANALYSIS = 'loss_analysis';\n public const string TYPE_ASK_JIMINNY = 'ask_jiminny';\n\n /**\n * Standard report types (used by kiosk for existing automated reports).\n */\n // @TODO this will add filter, however if we need to control feature by FF we need conditional logic\n public const array TYPES = [\n ['id' => 'exec_summary', 'name' => 'Exec Summary'],\n ['id' => 'coaching_profiles', 'name' => 'Coaching Profiles'],\n ['id' => 'product_feedback', 'name' => 'Product Feedback'],\n ['id' => self::TYPE_LOSS_ANALYSIS, 'name' => 'Loss Analysis'],\n// ['id' => 'questions', 'name' => 'Questions'],\n// ['id' => 'statistical_quant', 'name' => 'Statistical Quantitative'],\n ];\n\n public const array ALL_TYPES = [\n ...self::TYPES,\n ['id' => self::TYPE_ASK_JIMINNY, 'name' => 'Ask Jiminny'],\n ];\n\n public const string FREQUENCY_DAILY = 'daily';\n public const string FREQUENCY_WEEKLY = 'weekly';\n public const string FREQUENCY_MONTHLY = 'monthly';\n public const string FREQUENCY_QUARTERLY = 'quarterly';\n public const string FREQUENCY_ONE_OFF = 'one_off';\n\n /**\n * Frequencies for standard (non-Ask Jiminny) reports.\n */\n public const array FREQUENCIES = [\n ['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],\n ['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],\n ['id' => self::FREQUENCY_QUARTERLY, 'name' => 'Quarterly'],\n ['id' => self::FREQUENCY_ONE_OFF, 'name' => 'One-off'],\n ];\n\n /**\n * Frequencies for Ask Jiminny reports.\n */\n public const array ASK_JIMINNY_FREQUENCIES = [\n ['id' => self::FREQUENCY_DAILY, 'name' => 'Daily'],\n ['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],\n ['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],\n ];\n\n public const string MEDIA_TYPE_PDF = 'pdf';\n public const string MEDIA_TYPE_PODCAST = 'podcast';\n public const array MEDIA_TYPES = [self::MEDIA_TYPE_PDF, self::MEDIA_TYPE_PODCAST];\n public const array MEDIA_TYPE_OBJECT_PDF = ['id' => self::MEDIA_TYPE_PDF, 'name' => 'PDF'];\n public const array MEDIA_TYPE_OBJECT_PODCAST = ['id' => self::MEDIA_TYPE_PODCAST, 'name' => 'Podcast'];\n public const array MEDIA_TYPE_OBJECTS = [self::MEDIA_TYPE_OBJECT_PDF, self::MEDIA_TYPE_OBJECT_PODCAST];\n\n public const array CALL_TYPE_CONFERENCE = ['id' => 'conference', 'name' => 'Conference'];\n public const array CALL_TYPE_DIALER = ['id' => 'dialer', 'name' => 'Dialer'];\n public const int SENT_REPORT_AT_HOURS = 5;\n public const string PDF_KEY = 'pdf';\n public const string AUDIO_KEY = 'audio';\n\n private const array ALL_FREQUENCIES = [\n ['id' => self::FREQUENCY_DAILY, 'name' => 'Daily'],\n ['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],\n ['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],\n ['id' => self::FREQUENCY_QUARTERLY, 'name' => 'Quarterly'],\n ['id' => self::FREQUENCY_ONE_OFF, 'name' => 'One-off'],\n ];\n private const string S3_DIR = 'reports';\n private const array FILE_EXTENSIONS_VARIANTS = ['html', 'MD', 'pdf'];\n private const array FILE_PODCAST_EXTENSIONS_VARIANTS = ['json', 'mp3', 'ssml'];\n\n public function __construct(\n private readonly TeamRepository $teamRepository,\n private readonly GroupRepository $groupRepository,\n private readonly UserRepository $userRepository,\n private readonly StageRepository $stageRepository,\n private readonly DealStagesService $dealStagesService,\n private readonly RecipientsService $recipientsService,\n private readonly AutomatedReportsRepository $automatedReportsRepository,\n private readonly Webhook $webhookService,\n private readonly BusDispatcher $dispatcher,\n private readonly ActivityTypeService $activityTypeService,\n private readonly PlaybookCategoryRepository $playbookCategoryRepository,\n private readonly AskAnythingPromptService $askAnythingPromptService,\n private readonly SearchRepository $activitySearchRepository,\n private readonly AskAnythingRepository $askAnythingRepository,\n ) {\n }\n\n public static function getTypes(): array\n {\n $types = self::TYPES;\n\n return array_map(static function ($type) {\n return $type['id'];\n }, $types);\n }\n\n public static function getCallTypes(): array\n {\n return array_map(static function ($callType) {\n return $callType['id'];\n }, [self::CALL_TYPE_CONFERENCE, self::CALL_TYPE_DIALER]);\n }\n\n public static function getFrequencies(): array\n {\n return array_map(static function ($frequency) {\n return $frequency['id'];\n }, self::FREQUENCIES);\n }\n\n // front-facing structure\n public function getReportEnabledFieldData(bool $value = false): array\n {\n return [\n 'id' => 'report_enabled',\n 'label' => '',\n 'inputType' => InputTypeEnum::TOGGLE,\n 'value' => $value,\n ];\n }\n\n // Organizations = Teams\n public function getOrganizationFieldData(?string $value = null, bool $shortVersion = false): array\n {\n $options = $this->getTeams();\n\n if ($shortVersion) {\n return [\n 'id' => 'organization',\n 'label' => 'Organization',\n 'options' => $options,\n ];\n }\n\n return [\n 'id' => 'organization',\n 'label' => 'Organization',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => $options,\n 'value' => $value,\n 'dependencies' => [\n 'teams',\n 'deal_stage_at_call',\n 'current_deal_stage',\n 'recipients',\n ActivityTypeService::PLAYBOOK_CATEGORIES_KEY,\n ],\n 'dependsOn' => [],\n ];\n }\n\n // Teams = Groups\n public function getTeamFieldData(array $options = [], array $value = [], bool $shortVersion = false): array\n {\n if ($shortVersion) {\n return [\n 'id' => 'teams',\n 'label' => 'Team',\n 'options' => $options,\n ];\n }\n\n return [\n 'id' => 'teams',\n 'label' => 'Team',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'required' => false,\n 'placeholder' => 'Select',\n 'options' => $options,\n 'value' => $value, // value should be an array of objects {id, name}\n 'dependencies' => [ActivityTypeService::PLAYBOOK_CATEGORIES_KEY],\n 'dependsOn' => [],\n ];\n }\n\n public function getReportTypeFieldData(?string $value = null, bool $shortVersion = false, ?Team $team = null): array\n {\n $types = [];\n if ($team instanceof Team) {\n if ($team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {\n $types = self::TYPES;\n }\n if ($team->hasFeature(FeatureEnum::ASK_JIMINNY_REPORTS)) {\n $types[] = ['id' => self::TYPE_ASK_JIMINNY, 'name' => 'Ask Jiminny'];\n }\n } else {\n $types = self::TYPES;\n }\n\n if ($shortVersion) {\n return [\n 'id' => 'report_type',\n 'label' => 'Report Type',\n 'options' => $types,\n ];\n }\n\n return [\n 'id' => 'report_type',\n 'label' => 'Report Type',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => $types,\n 'value' => $value,\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getFrequencyFieldData(?string $value = null): array\n {\n return [\n 'id' => 'frequency',\n 'label' => 'Frequency',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => self::FREQUENCIES,\n 'value' => $value,\n 'dependencies' => ['period'],\n 'dependsOn' => [],\n ];\n }\n\n public function getPeriodFieldData(?string $valueStartDate = null, ?string $valueEndDate = null): array\n {\n return [\n 'id' => 'period',\n 'label' => 'Select one-off period',\n 'inputType' => InputTypeEnum::DATE_RANGE,\n 'required' => true,\n 'placeholder' => 'Select',\n 'value' => ['startDate' => $valueStartDate, 'endDate' => $valueEndDate],\n 'queryParams' => [\n 'startDate' => 'start_date_period',\n 'endDate' => 'end_date_period',\n ],\n 'dependencies' => [],\n 'dependsOn' => ['frequency'],\n ];\n }\n\n public function getActivityTypesFieldData(?Team $team = null, array $value = [], array $teamsFilter = []): array\n {\n return $this->activityTypeService->getActivityTypeFieldData(team: $team, value: $value, groupIds: $teamsFilter);\n }\n\n public function getDealStageAtCallFieldData(?Team $team = null, array $value = []): array\n {\n return $this->dealStagesService->getDealStageAtCallFieldData(team: $team, value: $value);\n }\n\n public function getCurrentDealStageFieldData(?Team $team = null, array $value = []): array\n {\n return $this->dealStagesService->getCurrentDealStageFieldData(team: $team, value: $value);\n }\n\n public function getDealValueFieldData(?int $valueMin = null, ?int $valueMax = null): array\n {\n return [\n 'id' => 'deal_value',\n 'label' => 'Deal Value',\n 'inputType' => InputTypeEnum::INTEGER_RANGE,\n 'required' => false,\n 'value' => ['min' => $valueMin, 'max' => $valueMax],\n 'queryParams' => [\n 'min' => 'min_deal_value',\n 'max' => 'max_deal_value',\n ],\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getCallTypeFieldData(bool $conferenceOn = false, bool $dialerOn = false): array\n {\n $value = [];\n $conferenceOn && $value[] = self::CALL_TYPE_CONFERENCE;\n $dialerOn && $value[] = self::CALL_TYPE_DIALER;\n\n return [\n 'id' => 'call_type',\n 'label' => 'Call Type',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'required' => true,\n 'options' => [\n self::CALL_TYPE_CONFERENCE,\n self::CALL_TYPE_DIALER,\n ],\n 'value' => $value,\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getMediaTypeFieldData(?AutomatedReport $report = null): array\n {\n $value = [];\n\n if ($report) {\n $value = $this->transformMediaTypes($report);\n }\n\n return [\n 'id' => 'media_types',\n 'label' => 'Export as',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'required' => true,\n 'options' => self::MEDIA_TYPE_OBJECTS,\n 'value' => $value,\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getCallDurationFieldData(?int $valueMin = null, ?int $valueMax = null): array\n {\n return [\n 'id' => 'call_duration',\n 'label' => 'Call Duration',\n 'inputType' => InputTypeEnum::INTEGER_RANGE,\n 'required' => false,\n 'value' => ['min' => $valueMin, 'max' => $valueMax],\n 'queryParams' => [\n 'min' => 'min_call_duration',\n 'max' => 'max_call_duration',\n ],\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getRecipientsFieldData(?Team $team = null, array $value = []): array\n {\n return $this->recipientsService->getRecipientsFieldData(team: $team, value: $value);\n }\n\n public function getJiminnyRecipientsFieldData(array $value = []): array\n {\n return $this->recipientsService->getJiminnyRecipientsFieldData($value);\n }\n\n public function getAdditionalPromptInputFieldData(?string $value = null): array\n {\n return [\n 'id' => 'additional_prompt_input',\n 'label' => 'Special requirements',\n 'inputType' => InputTypeEnum::TEXTAREA,\n 'required' => false,\n 'placeholder' => 'What should be the focus of the report?',\n 'value' => $value,\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getCustomReportNameFieldData(?string $value = null): array\n {\n return [\n 'id' => 'custom_name',\n 'label' => 'Custom report name',\n 'inputType' => InputTypeEnum::TEXT,\n 'required' => false,\n 'placeholder' => 'Enter custom name',\n 'value' => $value,\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n // data providers\n public function getTeams(): array\n {\n $teams = $this->teamRepository->getTeamsForKiosk(status: Team::STATUS_ACTIVE);\n\n $teamData = [];\n foreach ($teams as $team) {\n if (! $team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {\n continue;\n }\n\n $teamData[] = $this->transformTeam($team);\n }\n\n return $teamData;\n }\n\n public function getTeamGroups(string $teamUuid): array\n {\n $data = [];\n $team = $this->getTeam($teamUuid);\n\n if ($team !== null) {\n $groups = $team->groups()->get();\n\n foreach ($groups as $group) {\n $data[] = [\n 'id' => $group->getUuid(),\n 'name' => $group->getName(),\n ];\n }\n }\n\n return $data;\n }\n\n public function getTeamsGroupsOptions(array $filterTeamUuids = []): array\n {\n $data = [];\n $teams = $this->getTeams();\n\n foreach ($teams as $team) {\n if (! empty($filterTeamUuids) && ! in_array($team['id'], $filterTeamUuids, true)) {\n continue;\n }\n\n $data[] = [\n 'label' => $team['name'],\n 'groups' => $this->getTeamGroups($team['id']),\n ];\n }\n\n return $data;\n }\n\n public function getTeam(string $teamUuid): ?Team\n {\n return $this->teamRepository->idOrUuid($teamUuid);\n }\n\n public function getTeamById(int $teamId): ?Team\n {\n return $this->teamRepository->find($teamId);\n }\n\n public function getGroupsUuids(AutomatedReport $report): array\n {\n $uuids = [];\n $reportGroups = $report->getGroups();\n foreach ($reportGroups as $groupId) {\n if ($group = $this->groupRepository->find($groupId)) {\n $uuids[] = $group->getUuid();\n }\n }\n\n return $uuids;\n }\n\n public function getPlaybookCategoriesUuids(AutomatedReport $report): array\n {\n $uuids = [];\n $playbookCategories = $report->getPlaybookCategories();\n foreach ($playbookCategories as $id) {\n if ($category = $this->playbookCategoryRepository->find($id)) {\n $uuids[] = $category->getUuid();\n }\n }\n\n return $uuids;\n }\n\n public function getDealAtCallStagesUuids(AutomatedReport $report): array\n {\n $uuids = [];\n $reportStages = $report->getDealAtCallStages();\n foreach ($reportStages as $id) {\n if ($stage = $this->stageRepository->find($id)) {\n $uuids[] = $stage->getUuid();\n }\n }\n\n return $uuids;\n }\n\n public function getCurrentDealStagesUuids(AutomatedReport $report): array\n {\n $uuids = [];\n $reportStages = $report->getCurrentDealStages();\n foreach ($reportStages as $id) {\n if ($stage = $this->stageRepository->find($id)) {\n $uuids[] = $stage->getUuid();\n }\n }\n\n return $uuids;\n }\n\n public function getUsersUuids(AutomatedReport $report): array\n {\n return $this->extractUserUuids($report->getRecipients());\n }\n\n public function getJiminnyUsersUuids(AutomatedReport $report): array\n {\n return $this->extractUserUuids($report->getJiminnyRecipients());\n }\n\n /**\n * @param array<string, mixed> $recipients\n */\n private function extractUserUuids(array $recipients): array\n {\n $userIds = $recipients['users'] ?? [];\n\n return collect($userIds)\n ->map(fn ($id) => $this->userRepository->find((int) $id))\n ->filter()\n ->map(fn (UserContract $user) => $user->getUuid())\n ->values()\n ->all();\n }\n\n // get mail data\n public function getRecipientUsers(AutomatedReport $report): array\n {\n return $this->buildRecipientUsers($report->getRecipients());\n }\n\n private function getJiminnyRecipientUsers(AutomatedReport $report): array\n {\n return $this->buildRecipientUsers($report->getJiminnyRecipients());\n }\n\n /**\n * @param array<string, mixed> $recipients\n */\n private function buildRecipientUsers(array $recipients): array\n {\n $userIds = $recipients['users'] ?? [];\n\n return collect($userIds)\n ->map(fn ($id) => $this->userRepository->find((int) $id))\n ->filter()\n ->map(fn (UserContract $user) => [\n 'email' => $user->getEmailAddress(),\n 'name' => $user->getName(),\n 'timezone' => $user->getTimezone()->getName(),\n ])\n ->values()\n ->all();\n }\n\n public function getValidRecipientUsers(AutomatedReport $report, bool $includeJiminny = false): array\n {\n if ($report->isAskJiminnyReport()) {\n $recipients = $this->resolveAskJiminnyRecipients($report);\n } else {\n $recipients = $this->getRecipientUsers($report);\n if ($includeJiminny) {\n $recipients = array_merge($recipients, $this->getJiminnyRecipientUsers($report));\n }\n }\n\n $emails = [];\n\n return array_values(array_filter(\n $recipients,\n static function ($recipient) use (&$emails) {\n if (empty($recipient['email']) || in_array($recipient['email'], $emails, true)) {\n return false;\n }\n $emails[] = $recipient['email'];\n\n return true;\n }\n ));\n }\n\n private function resolveAskJiminnyRecipients(AutomatedReport $report): array\n {\n $recipients = [];\n\n $creator = $report->getCreator();\n if ($creator !== null) {\n $recipients[] = [\n 'email' => $creator->getEmailAddress(),\n 'name' => $creator->getName(),\n 'timezone' => $creator->getTimezone()->getName(),\n ];\n }\n\n return array_merge(\n $recipients,\n $this->buildRecipientUsers($report->getRecipients()),\n $this->getGroupRecipientUsers($report),\n );\n }\n\n private function getGroupRecipientUsers(AutomatedReport $report): array\n {\n $users = [];\n foreach ($report->getGroups() as $groupId) {\n $group = $this->groupRepository->find($groupId);\n if ($group === null) {\n continue;\n }\n foreach ($group->getMembers() as $member) {\n $users[] = [\n 'email' => $member->getEmailAddress(),\n 'name' => $member->getName(),\n 'timezone' => $member->getTimezone()->getName(),\n ];\n }\n }\n\n return $users;\n }\n\n public function getReportTypeName(AutomatedReportResult $report): string\n {\n $type = $report->getReport()->getType();\n\n $getType = $this->transformReportType($type);\n\n return $getType['name'];\n }\n\n public function getReportPeriodName(AutomatedReportResult $report): string\n {\n $from = $report->getFromDate();\n $to = $report->getToDate();\n $frequency = $report->getReport()->getFrequency();\n\n if ($from === null || $to === null) {\n if (! $report->getReport()->isAskJiminnyReport()) {\n $invalidPeriod = $from === null ? 'from' : 'to';\n\n throw new ApplicationException('Report period is invalid: ' . $invalidPeriod);\n }\n\n $period = $this->calculateFromAndToDatePeriod($frequency);\n $from = $period['fromDate'];\n $to = $period['toDate'];\n }\n\n return $this->formatReportPeriodName($frequency, $from, $to);\n }\n\n private function formatReportPeriodName(string $frequency, Carbon $from, Carbon $to): string\n {\n $fromYear = $from->format('Y');\n $toYear = $to->format('Y');\n $differentYears = $fromYear !== $toYear;\n\n switch ($frequency) {\n case self::FREQUENCY_DAILY:\n return $from->format('j M Y');\n\n case self::FREQUENCY_QUARTERLY:\n // 'Jan-Mar 2025' or 'Nov 2024-Jan 2025' if years differ\n $startMonth = $from->format('M');\n $endMonth = $to->copy()->subMonth();\n $endMonthName = $endMonth->format('M');\n $endMonthYear = $endMonth->format('Y');\n\n if ($differentYears) {\n return \"{$startMonth} {$fromYear} - {$endMonthName} {$endMonthYear}\";\n }\n\n return \"{$startMonth} - {$endMonthName} {$toYear}\";\n\n case self::FREQUENCY_MONTHLY:\n // 'May 2025' - monthly reports are always within the same year\n return $from->format('M Y');\n\n case self::FREQUENCY_WEEKLY:\n // '4 - 8 Aug 2025', '27 Oct - 3 Nov 2025', or '28 Dec 2024 - 3 Jan 2025' if years differ\n $startDay = $from->format('j');\n $endDay = $to->format('j');\n $startMonth = $from->format('M');\n $endMonth = $to->format('M');\n\n if ($differentYears) {\n return \"{$startDay} {$startMonth} {$fromYear} - {$endDay} {$endMonth} {$toYear}\";\n }\n\n if ($startMonth !== $endMonth) {\n return \"{$startDay} {$startMonth} - {$endDay} {$endMonth} {$toYear}\";\n }\n\n return \"{$startDay} - {$endDay} {$endMonth} {$toYear}\";\n\n case self::FREQUENCY_ONE_OFF:\n // '2 May-31 May 2025' or '15 Dec 2024-15 Jan 2025' if years differ\n $startDay = $from->format('j');\n $startMonth = $from->format('M');\n $endDay = $to->format('j');\n $endMonth = $to->format('M');\n\n // If same month and year, use a format like '2-31 May 2025'\n if ($startMonth === $endMonth && ! $differentYears) {\n return \"{$startDay} - {$endDay} {$startMonth} {$toYear}\";\n }\n\n // If different years, include both years\n if ($differentYears) {\n return \"{$startDay} {$startMonth} {$fromYear} - {$endDay} {$endMonth} {$toYear}\";\n }\n\n // Same year but different months\n return \"{$startDay} {$startMonth} - {$endDay} {$endMonth} {$toYear}\";\n\n default:\n // Default format for unknown frequencies\n return $from->format('j M Y') . ' - ' . $to->format('j M Y');\n }\n }\n\n public function getReportTeamsName(AutomatedReportResult $report): string\n {\n $groups = $report->getGroups();\n\n if (empty($groups)) {\n return 'All';\n }\n\n // Get group names from repository\n $groupNames = [];\n foreach ($groups as $groupId) {\n $group = $this->groupRepository->find($groupId);\n if ($group) {\n $groupNames[] = $group->getName();\n }\n }\n\n if (count($groupNames) === 1) {\n // Single team format\n $teamsName = $groupNames[0];\n } else {\n // Multiple teams format\n $teamsName = implode(', ', $groupNames);\n }\n\n return $teamsName;\n }\n\n public function getReportFileName(AutomatedReportResult $report): string\n {\n $customName = $report->getReport()->getCustomName();\n $periodName = $this->getReportPeriodName($report);\n $filenameSuffix = $this->getFilenameSuffix($report);\n\n if ($customName) {\n if ($filenameSuffix) {\n $customName .= \" {$filenameSuffix}\";\n }\n\n return $this->sanitizeFileName(\"{$customName} - {$periodName}\");\n }\n\n $baseName = $this->getReportTypeName($report);\n\n if ($filenameSuffix) {\n $baseName .= \" {$filenameSuffix}\";\n }\n\n return $this->sanitizeFileName(\"{$baseName} - {$periodName} - {$this->getReportTeamsName($report)}\");\n }\n\n public function getReportFileNameWithExtension(AutomatedReportResult $result): string\n {\n $extension = $this->getMediaTypeMetadata($result)['extension'];\n\n return $this->getReportFileName($result) . '.' . $extension;\n }\n\n public function sanitizeFileName(string $fileName): string\n {\n return str_replace(['/', '\\\\'], '-', $fileName);\n }\n\n public function isUserRecipientOfReport(User $user, AutomatedReport $report): bool\n {\n $recipients = array_map('intval', $report->getRecipients()['users'] ?? []);\n\n return in_array($user->getId(), $recipients);\n }\n\n public function transformReportResults(Collection $automatedReportResults): array\n {\n $data = [];\n foreach ($automatedReportResults as $automatedReportResult) {\n /** @var AutomatedReportResult $automatedReportResult */\n\n $report = $automatedReportResult->getReport();\n\n $createdBy = $report->getCreator();\n $creator = [\n 'id' => $createdBy?->getUuid(),\n 'name' => $createdBy?->getName(),\n 'email' => $createdBy?->getEmailAddress(),\n 'photoUrl' => $createdBy?->getPhotoUrl(),\n ];\n\n $data[] = [\n 'id' => $automatedReportResult->getUuid(),\n 'name' => $automatedReportResult->getName(),\n 'frequency' => $this->transformFrequency($report->getFrequency()),\n 'recipients' => [\n ...array_values($this->transformGroups(team: $report->getTeam(), groupsIds: $report->getGroups())),\n ...array_values($this->transformRecipients($report->getRecipients())),\n ],\n 'report_type' => $this->transformReportType($report->getType()),\n 'media_type' => $automatedReportResult->getMediaType(),\n 'downloadUrl' => $this->generateReportResultDownloadUrl($automatedReportResult),\n 'viewUrl' => $this->generateReportResultViewUrl($automatedReportResult),\n 'generated_at' => $automatedReportResult->getGeneratedAt()?->toIso8601String(),\n 'creator' => $creator,\n ];\n }\n\n return $data;\n }\n\n public function hasCallTypeConference(AutomatedReport $report): bool\n {\n return in_array(self::CALL_TYPE_CONFERENCE['id'], $report->getCallTypes(), true);\n }\n\n public function hasCallTypeDialer(AutomatedReport $report): bool\n {\n return in_array(self::CALL_TYPE_DIALER['id'], $report->getCallTypes(), true);\n }\n\n // transformers\n private function transformTeam(Team $team): array\n {\n if (! $team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {\n return [];\n }\n\n return [\n 'id' => $team->getUuid(),\n 'name' => $team->getName(),\n ];\n }\n\n private function transformReportFullView(AutomatedReport $report): array\n {\n $base = $this->transformReportBase($report);\n\n return $report->getType() === self::TYPE_ASK_JIMINNY\n ? $base + $this->transformAskJiminnyFields($report)\n : $base + $this->transformStandardReportFields($report);\n }\n\n private function transformReportBase(AutomatedReport $report): array\n {\n return [\n 'id' => $report->getUuid(),\n 'organization' => $this->transformOrganization(team: $report->getTeam()),\n 'report_type' => $this->transformReportType($report->getType()),\n 'frequency' => $this->transformFrequency($report->getFrequency()),\n ];\n }\n\n private function transformStandardReportFields(AutomatedReport $report): array\n {\n $team = $report->getTeam();\n\n return [\n 'report_enabled' => $report->getStatus(),\n 'start_date_period' => $report->getFrom()?->format('Y-m-d H:i:s'),\n 'end_date_period' => $report->getTo()?->format('Y-m-d H:i:s'),\n 'deal_value_min' => $report->getDealValueMin(),\n 'deal_value_max' => $report->getDealValueMax(),\n 'call_types' => $this->transformCallType($report->getCallTypes()),\n 'media_types' => $this->transformMediaTypes($report),\n 'call_duration_min' => $this->transformDurationToMinutes($report->getCallDurationMin()),\n 'call_duration_max' => $this->transformDurationToMinutes($report->getCallDurationMax()),\n 'teams' => $this->transformGroups(team: $team, groupsIds: $report->getGroups()),\n 'deal_at_call_stages' => $this->transformStages(team: $team, stagesIds: $report->getDealAtCallStages()),\n 'current_deal_stages' => $this->transformStages(team: $team, stagesIds: $report->getCurrentDealStages()),\n 'recipients' => $this->transformRecipients($report->getRecipients()),\n 'created_by' => $this->transformCreator($report->getCreator()),\n 'additional_prompt_input' => $report->getAdditionalPromptInput(),\n 'custom_name' => $report->getCustomName(),\n 'created_at' => $report->getCreatedAt()->format('Y-m-d H:i:s'),\n 'updated_at' => $report->getUpdatedAt()->format('Y-m-d H:i:s'),\n 'deleted_at' => $report->getDeletedAt()?->format('Y-m-d H:i:s'),\n ];\n }\n\n private function transformAskJiminnyFields(AutomatedReport $report): array\n {\n $team = $report->getTeam();\n $creatorId = $report->getAttribute('created_by');\n $explicitUserIds = array_values(array_filter(\n $report->getRecipients()['users'] ?? [],\n static fn ($id) => $id !== $creatorId\n ));\n\n return [\n 'report_name' => $report->getCustomName(),\n 'enabled' => $report->getStatus(),\n 'share_teams' => $this->transformGroups(team: $team, groupsIds: $report->getGroups()),\n 'share_users' => $this->transformRecipients(['users' => $explicitUserIds]),\n 'saved_search' => $this->transformSafeSearch($report->getSavedSearch()),\n 'ask_jiminny_prompt' => $this->transformAskJiminnyPrompt($report->getAskAnythingPrompt()),\n 'expires_on' => $report->getExpiresAt()?->format('Y-m-d'),\n ];\n }\n\n private function transformOrganization(?Team $team): array\n {\n return [\n 'id' => $team?->getUuid(),\n 'name' => $team?->getName(),\n ];\n }\n\n private function transformReportType(string $type): array\n {\n foreach (self::ALL_TYPES as $typeItem) {\n if ($typeItem['id'] === $type) {\n return $typeItem;\n }\n }\n\n return [];\n }\n\n private function transformCallType(array $types): array\n {\n $result = [];\n $callTypes = [self::CALL_TYPE_CONFERENCE, self::CALL_TYPE_DIALER];\n\n foreach ($types as $type) {\n foreach ($callTypes as $callTypeItem) {\n if ($callTypeItem['id'] === $type) {\n $result[] = $callTypeItem;\n\n break;\n }\n }\n }\n\n return $result;\n }\n\n private function transformMediaTypes(AutomatedReport $report): array\n {\n $values = [];\n\n foreach ($report->getMediaTypes() as $mediaType) {\n if (! in_array($mediaType, self::MEDIA_TYPES, true)) {\n continue;\n }\n\n $values[] = match ($mediaType) {\n self::MEDIA_TYPE_PDF => self::MEDIA_TYPE_OBJECT_PDF,\n self::MEDIA_TYPE_PODCAST => self::MEDIA_TYPE_OBJECT_PODCAST,\n };\n }\n\n return $values;\n }\n\n private function transformFrequency(string $frequency): array\n {\n foreach (self::ALL_FREQUENCIES as $frequencyItem) {\n if ($frequencyItem['id'] === $frequency) {\n return $frequencyItem;\n }\n }\n\n return [];\n }\n\n public function transformDurationToMinutes(?int $duration): ?int\n {\n if (! $duration) {\n return null;\n }\n\n return (int) ($duration / 60);\n }\n\n private function transformGroups(?Team $team, array $groupsIds): array\n {\n if (empty($groupsIds) || ! $team) {\n return [];\n }\n\n $data = [];\n foreach ($groupsIds as $groupId) {\n $group = $team->groups()->where('id', $groupId)->first();\n\n if ($group) {\n $data[] = [\n 'id' => $group->getUuid(),\n 'name' => $group->getName(),\n 'photoUrl' => $group->getPhotoUrl(),\n ];\n }\n }\n\n return $data;\n }\n\n private function transformStages(?Team $team, array $stagesIds): array\n {\n if (empty($stagesIds) || ! $team) {\n return [];\n }\n\n $data = [];\n foreach ($stagesIds as $stageId) {\n $stage = $team->stages()->where('id', $stageId)->first();\n\n if ($stage) {\n $data[] = [\n 'id' => $stage->getUuid(),\n 'name' => $stage->getName(),\n ];\n }\n }\n\n return $data;\n }\n\n private function transformRecipients(array $recipients): array\n {\n $users = [];\n foreach ($recipients['users'] ?? [] as $userId) {\n $users[] = $this->transformUser($userId);\n }\n\n return $users;\n }\n\n private function transformCreator(?User $user): ?array\n {\n if ($user === null) {\n return null;\n }\n\n return $this->transformUser($user->getId());\n }\n\n private function transformAskJiminnyPrompt(?AskAnythingPrompt $prompt): ?array\n {\n if ($prompt === null) {\n return null;\n }\n\n return [\n 'id' => $prompt->getUuid(),\n 'name' => $prompt->getTitle(),\n ];\n }\n\n private function transformSafeSearch(?Search $search): ?array\n {\n if ($search === null) {\n return null;\n }\n\n return [\n 'id' => $search->getUuid(),\n 'name' => $search->getName(),\n ];\n }\n\n private function transformUser(int $userId): array\n {\n /* @var ?User $user */\n $user = $this->userRepository->find($userId);\n\n return [\n 'id' => $user?->getUuid(),\n 'name' => $user?->getName(),\n 'email' => $user?->getEmailAddress(),\n 'photoUrl' => $user?->getPhotoUrl(),\n ];\n }\n\n public function create(array $data): array\n {\n $validatedData = $this->validateAndTransformData($data);\n $validatedData['created_by'] = auth()->id();\n\n $automatedReport = $this->automatedReportsRepository->create($validatedData);\n\n $this->generateOneOffReport($automatedReport);\n\n return $this->transformReportFullView($automatedReport);\n }\n\n public function update(string $uuid, array $data): array\n {\n $validatedData = $this->validateAndTransformData($data);\n $report = $this->automatedReportsRepository->findByUuid($uuid);\n\n if (! $report) {\n throw new InvalidArgumentException('Report not found');\n }\n\n $oldCustomName = $report->getCustomName();\n\n $automatedReport = $this->automatedReportsRepository->update($report, $validatedData);\n\n if ($oldCustomName !== $automatedReport->getCustomName()) {\n $this->updateResultNames($automatedReport);\n }\n\n $this->generateOneOffReport($automatedReport);\n\n return $this->transformReportFullView($automatedReport);\n }\n\n /**\n * Create an Ask Jiminny report.\n */\n public function createAskJiminnyReport(array $data, User $creator): array\n {\n $validatedData = $this->validateAskJiminnyReportData($data, $creator);\n $validatedData['created_by'] = $creator->getId();\n\n $automatedReport = $this->automatedReportsRepository->create($validatedData);\n\n return $this->transformReportFullView($automatedReport);\n }\n\n /**\n * Update an Ask Jiminny report.\n */\n public function updateAskJiminnyReport(AutomatedReport $report, array $data, User $user): array\n {\n if (! $report->isAskJiminnyReport()) {\n throw new InvalidArgumentException('Report is not an Ask Jiminny report');\n }\n\n $validatedData = $this->validateAskJiminnyReportData($data, $user);\n\n $oldCustomName = $report->getCustomName();\n\n $automatedReport = $this->automatedReportsRepository->update($report, $validatedData);\n\n if ($oldCustomName !== $automatedReport->getCustomName()) {\n $this->updateResultNames($automatedReport);\n }\n\n return $this->transformReportFullView($automatedReport);\n }\n\n public function updateAskJiminnyReportStatus(AutomatedReport $report, bool $status): array\n {\n $this->automatedReportsRepository->update($report, ['status' => $status]);\n\n return $this->transformReportFullView($report->fresh());\n }\n\n /**\n * Validate and transform data for Ask Jiminny reports.\n */\n private function validateAskJiminnyReportData(array $data, User $user): array\n {\n // Validate name\n $name = trim($data['report_name'] ?? '');\n if (empty($name)) {\n throw new InvalidArgumentException('Report name is required');\n }\n if (mb_strlen($name) > 50) {\n throw new InvalidArgumentException('Report name must be 50 characters or less');\n }\n\n // Validate frequency (only daily, weekly, monthly for Ask Jiminny)\n $frequency = $data['frequency'] ?? null;\n $askJiminnyFrequencies = [self::FREQUENCY_DAILY, self::FREQUENCY_WEEKLY, self::FREQUENCY_MONTHLY];\n if (! in_array($frequency, $askJiminnyFrequencies, true)) {\n throw new InvalidArgumentException('Frequency must be daily, weekly, or monthly');\n }\n\n // Validate expiration date\n $expiresAt = $data['expires_on'] ?? null;\n if (empty($expiresAt)) {\n throw new InvalidArgumentException('Expiration date is required');\n }\n\n try {\n $expiresAtDate = Carbon::parse($expiresAt);\n } catch (InvalidFormatException $e) {\n throw new InvalidArgumentException('Expiration date format is invalid');\n }\n $maxExpiration = Carbon::now()->addYear();\n if ($expiresAtDate->gt($maxExpiration)) {\n throw new InvalidArgumentException('Expiration date cannot be more than 1 year from now');\n }\n if ($expiresAtDate->isPast()) {\n throw new InvalidArgumentException('Expiration date cannot be in the past');\n }\n\n // Validate saved search\n $activitySearchId = $data['saved_search'] ?? null;\n if (empty($activitySearchId)) {\n throw new InvalidArgumentException('Saved search is required');\n }\n $savedSearch = $this->activitySearchRepository->findByUuidAndUser($activitySearchId, $user);\n if (! $savedSearch) {\n throw new InvalidArgumentException('Saved search not found or does not belong to you');\n }\n\n // Validate saved prompt\n $askAnythingPromptId = $data['ask_jiminny_prompt'] ?? null;\n if (empty($askAnythingPromptId)) {\n throw new InvalidArgumentException('Ask Jiminny prompt is required');\n }\n $prompt = $this->askAnythingRepository->getPromptByUuid($askAnythingPromptId);\n if (! $prompt) {\n throw new InvalidArgumentException('Ask Jiminny prompt not found');\n }\n\n // Validate status\n $status = $data['enabled'] ?? false;\n\n $recipientUserIds = [$user->getId()];\n\n if (! empty($data['share_users'])) {\n $sharedUserIds = $this->validateAndGetUserIdsByTeam(\n $user->team,\n (array) $data['share_users']\n );\n $recipientUserIds = array_merge($recipientUserIds, $sharedUserIds);\n }\n\n $sharedGroupIds = [];\n if (! empty($data['share_teams'])) {\n $sharedGroupIds = $this->validateAndGetGroupIds($user->team, (array) $data['share_teams']);\n }\n\n $recipientUserIds = array_values(array_unique($recipientUserIds));\n\n return [\n 'team_id' => $user->getTeamId(),\n 'type' => self::TYPE_ASK_JIMINNY,\n 'status' => (bool) $status,\n 'frequency' => $frequency,\n 'custom_name' => $name,\n 'activity_search_id' => $savedSearch->getId(),\n 'ask_anything_prompt_id' => $prompt->getId(),\n 'expires_at' => $expiresAtDate->toDateString(),\n 'media_types' => [self::MEDIA_TYPE_PDF],\n 'call_types' => [],\n 'recipients' => ['users' => $recipientUserIds],\n 'groups' => $sharedGroupIds,\n ];\n }\n\n public static function getAskJiminnyFrequencies(): array\n {\n return array_map(static function ($frequency) {\n return $frequency['id'];\n }, self::ASK_JIMINNY_FREQUENCIES);\n }\n\n public function getAskJiminnyReportFilters(User $user): array\n {\n $savedSearches = $this->activitySearchRepository->findByUserOrderedByName($user)\n ->map(fn (Search $search) => [\n 'id' => $search->getUuid(),\n 'name' => $search->getName(),\n ])\n ->values()->all();\n\n $prompts = collect(\n $this->askAnythingPromptService->get($user, AskAnythingPromptTarget::on_demand)\n )->map(fn (AskAnythingPromptDto $prompt) => [\n 'id' => $prompt->id,\n 'name' => $prompt->title,\n ])->values()->all();\n\n return [\n [\n 'id' => 'prompt',\n 'label' => 'Prompt',\n 'options' => $prompts,\n ],\n [\n 'id' => 'saved_search',\n 'label' => 'Saved Search',\n 'options' => $savedSearches,\n ],\n ];\n }\n\n public function getAskJiminnyReportFormData(User $user, ?AutomatedReport $report = null): array\n {\n $team = $user->getTeam();\n $userTimezone = $user->getTimezone();\n\n $savedSearches = $this->activitySearchRepository->findByUserOrderedByName($user)\n ->map(fn (Search $search) => [\n 'id' => $search->getUuid(),\n 'name' => $search->getName(),\n ])\n ->values()->all();\n\n $prompts = collect(\n $this->askAnythingPromptService->get($user, AskAnythingPromptTarget::on_demand)\n )->map(fn (AskAnythingPromptDto $prompt) => [\n 'id' => $prompt->id,\n 'name' => $prompt->title,\n ])->values()->all();\n\n $teamGroups = $this->groupRepository->getAllByTeam($team)->map(fn ($group) => [\n 'id' => $group->getUuid(),\n 'name' => $group->getName(),\n ])->values()->all();\n\n $shareUsers = $this->recipientsService->getRecipientsFieldData(team: $team)['options'] ?? [];\n\n $sharedTeamsValue = [];\n $sharedUsersValue = [];\n if ($report) {\n $sharedTeamsValue = $this->transformGroups($team, $report->getGroups());\n\n $recipientUserIds = $report->getRecipients()['users'] ?? [];\n $creatorId = $report->getAttribute('created_by');\n $sharedUserIds = array_values(array_filter(\n $recipientUserIds,\n static fn ($id) => $id !== $creatorId\n ));\n $sharedUsersValue = collect($sharedUserIds)\n ->map(fn ($id) => $this->userRepository->find((int) $id))\n ->filter()\n ->map(fn (User $u) => [\n 'id' => $u->getUuid(),\n 'name' => $u->getName(),\n ])\n ->values()\n ->all();\n }\n\n return [\n 'fields' => [\n [\n 'id' => 'enabled',\n 'inputType' => InputTypeEnum::TOGGLE,\n 'label' => '',\n 'value' => $report?->getStatus() ?? false,\n ],\n [\n 'id' => 'report_name',\n 'inputType' => InputTypeEnum::TEXT,\n 'label' => 'Name',\n 'placeholder' => 'Enter name',\n 'required' => true,\n 'validation' => ['maxLength' => 50],\n 'value' => $report?->getCustomName() ?? '',\n ],\n [\n 'id' => 'frequency',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'label' => 'Frequency',\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => self::ASK_JIMINNY_FREQUENCIES,\n 'value' => $report ? $this->transformFrequency($report->getFrequency()) : null,\n ],\n [\n 'id' => 'expires_on',\n 'inputType' => InputTypeEnum::DATE,\n 'label' => 'Expires on',\n 'required' => true,\n 'placeholder' => 'Select',\n 'validation' => [\n 'minDate' => now($userTimezone)->toDateString(),\n 'maxDate' => now($userTimezone)->addYear()->toDateString(),\n ],\n 'value' => $report?->getExpiresAt()?->toDateString(),\n ],\n [\n 'id' => 'share_teams',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'label' => 'Team',\n 'required' => false,\n 'placeholder' => 'Select',\n 'options' => $teamGroups,\n 'value' => $sharedTeamsValue,\n ],\n [\n 'id' => 'share_users',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'label' => 'Team member',\n 'required' => false,\n 'placeholder' => 'Select',\n 'groupLabelKey' => 'label',\n 'groupValuesKey' => 'users',\n 'optionLabelKey' => 'name',\n 'optionValueKey' => 'id',\n 'options' => $shareUsers,\n 'value' => $sharedUsersValue,\n ],\n [\n 'id' => 'saved_search',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'label' => 'Saved search',\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => $savedSearches,\n 'value' => $report && $report->getSavedSearch() ? [\n 'id' => $report->getSavedSearch()->getUuid(),\n 'name' => $report->getSavedSearch()->getName(),\n ] : null,\n ],\n [\n 'id' => 'ask_jiminny_prompt',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'label' => 'Ask Jiminny prompt',\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => $prompts,\n 'value' => $report && $report->getAskAnythingPrompt() ? [\n 'id' => $report->getAskAnythingPrompt()->getUuid(),\n 'name' => $report->getAskAnythingPrompt()->getTitle(),\n ] : null,\n ],\n ],\n ];\n }\n\n private function updateResultNames(AutomatedReport $automatedReport): void\n {\n $results = $this->automatedReportsRepository->getResultsByReport($automatedReport);\n\n foreach ($results as $result) {\n $result->update(['name' => $this->getReportFileName($result)]);\n }\n }\n\n public function updateStatus(string $uuid, array $data): array\n {\n $automatedReport = $this->automatedReportsRepository->findByUuid($uuid);\n\n if (! $automatedReport) {\n throw new ModelNotFoundException('Report not found');\n }\n\n $status = $this->validateReportStatus($data['report_enabled'] ?? null);\n $automatedReport->update([\n 'status' => $status,\n ]);\n\n $this->generateOneOffReport($automatedReport);\n\n return $this->transformReportFullView($automatedReport);\n }\n\n private function generateOneOffReport(AutomatedReport $automatedReport): void\n {\n // the scheduler handles all the other frequency types\n if ($automatedReport->getStatus() === false || $automatedReport->getFrequency() !== self::FREQUENCY_ONE_OFF) {\n return;\n }\n\n $this->dispatcher->dispatch(new RequestGenerateReportJob($automatedReport->getUuid()));\n }\n\n public function getReport(string $uuid): AutomatedReport\n {\n $automatedReport = $this->automatedReportsRepository->findByUuid($uuid);\n\n if (! $automatedReport) {\n throw new ModelNotFoundException('Report not found');\n }\n\n return $automatedReport;\n }\n\n public function get(string $uuid): array\n {\n $automatedReport = $this->getReport($uuid);\n\n return $this->transformReportFullView($automatedReport);\n }\n\n public function list(string $sortColumn = 'created_at', string $sortDirection = 'desc'): array\n {\n $results = [];\n $collection = $this->automatedReportsRepository->getAllStandardReports($sortColumn, $sortDirection);\n\n /** @var AutomatedReport $report */\n foreach ($collection as $report) {\n $results[] = $this->transformReportFullView($report);\n }\n\n return ['data' => $results];\n }\n\n public function listAskJiminnyReports(\n User $user,\n string $sortColumn = 'created_at',\n string $sortDirection = 'desc'\n ): array {\n $results = [];\n $collection = $this->automatedReportsRepository->getAskJiminnyReportsByUser($user, $sortColumn, $sortDirection);\n\n /** @var AutomatedReport $report */\n foreach ($collection as $report) {\n $results[] = $this->transformReportFullView($report);\n }\n\n return ['data' => $results];\n }\n\n public function delete(string $uuid): void\n {\n $automatedReport = $this->automatedReportsRepository->findByUuid($uuid);\n\n if (! $automatedReport) {\n throw new ModelNotFoundException('Report not found');\n }\n\n $automatedReport->delete();\n }\n\n public function createReportResult(AutomatedReport $automatedReport, array $data = []): AutomatedReportResult\n {\n return $this->automatedReportsRepository->createResult(\n array_merge(\n [\n 'report_id' => $automatedReport->getId(),\n 'status' => AutomatedReportResult::STATUS_DEFAULT,\n ],\n $data\n )\n );\n }\n\n public function getReportResult(string $resultUuid): AutomatedReportResult\n {\n $report = $this->automatedReportsRepository->findResultByUuid($resultUuid);\n\n if (! $report) {\n throw new ModelNotFoundException('Report Result not found');\n }\n\n return $report;\n }\n\n public function findChildResult(AutomatedReportResult $result, string $type): ?AutomatedReportResult\n {\n return $this->automatedReportsRepository->findChildResult($result, $type);\n }\n\n // prophet API calls\n /**\n * @throws ApplicationException\n */\n public function getGenerateReportPayload(AutomatedReport $automatedReport, string $reportResultUuid): array\n {\n $period = $this->calculateFromAndToDate($automatedReport);\n $fromDate = $period['fromDate'];\n $toDate = $period['toDate'];\n\n return [\n 'team_id' => $automatedReport->getTeamId(),\n 'request_id' => $reportResultUuid,\n 'report_type' => $automatedReport->getType(),\n 'media_types' => $automatedReport->getMediaTypes(),\n 'from_date' => $fromDate->startOfDay()->format(DateTimeInterface::RFC3339),\n 'to_date' => $toDate->endOfDay()->format(DateTimeInterface::RFC3339),\n 'group_ids' => $automatedReport->getGroups(),\n 'call_deal_stage' => $automatedReport->getDealAtCallStages(),\n 'current_deal_stage' => $automatedReport->getCurrentDealStages(),\n 'deal_min_value' => $automatedReport->getDealValueMin(),\n 'deal_max_value' => $automatedReport->getDealValueMax(),\n 'call_types' => $automatedReport->getCallTypes(),\n 'call_duration_min_seconds' => $automatedReport->getCallDurationMin(),\n 'call_duration_max_seconds' => $automatedReport->getCallDurationMax(),\n 'special_requirements' => $automatedReport->getAdditionalPromptInput(),\n 'callback_url' => $this->getCallbackUrl(),\n 'report_period' => $this->formatReportPeriodName(\n $automatedReport->getFrequency(),\n $fromDate,\n $toDate,\n ),\n 'playbook_categories' => $automatedReport->getPlaybookCategories(),\n 'custom_name' => $automatedReport->getCustomName(),\n ];\n }\n\n // $inputPayload - FE payload structure\n public function getActivitiesCountPayload(array $inputPayload): array\n {\n // Use validateAndTransformData to validate and normalize input\n $validatedData = $this->validateAndTransformData($inputPayload);\n $period = $this->calculateFromAndToDatePeriod(\n $validatedData['frequency'],\n Carbon::parse($validatedData['from']),\n Carbon::parse($validatedData['to']),\n );\n $fromDate = $period['fromDate'];\n $toDate = $period['toDate'];\n\n // Create payload similar to getGenerateReportPayload\n return [\n 'team_id' => $validatedData['team_id'],\n 'group_ids' => $validatedData['groups'] ?? [],\n 'report_type' => $validatedData['type'],\n 'from_date' => $fromDate->format(DateTimeInterface::RFC3339),\n 'to_date' => $toDate->format(DateTimeInterface::RFC3339),\n 'call_deal_stage' => $validatedData['deal_at_call_stages'] ?? [],\n 'current_deal_stage' => $validatedData['current_deal_stages'] ?? [],\n 'deal_min_value' => $validatedData['deal_value_min'] ?? null,\n 'deal_max_value' => $validatedData['deal_value_max'] ?? null,\n 'call_types' => $validatedData['call_types'],\n 'call_duration_min_seconds' => $validatedData['call_duration_min'] ?? null,\n 'call_duration_max_seconds' => $validatedData['call_duration_max'] ?? null,\n 'special_requirements' => $validatedData['additional_prompt_input'] ?? null,\n 'playbook_categories' => $validatedData['playbook_categories'] ?? [],\n 'request_id' => null,\n 'callback_url' => null,\n ];\n }\n\n public function shouldSendReport(array $users, ?CarbonInterface $generatedAt = null): bool\n {\n if (empty($users)) {\n return false;\n }\n\n $earliestTz = collect($users)\n ->mapWithKeys(function (array $user) {\n $tz = new DateTimeZone($user['timezone']);\n $nowUtc = new DateTime('now', new DateTimeZone('UTC'));\n $offset = $tz->getOffset($nowUtc);\n\n return [$user['timezone'] => $offset];\n })\n ->sortDesc()\n ->keys()\n ->first();\n\n $now = Carbon::now($earliestTz);\n $isScheduledTime = (int) $now->format('H') === self::SENT_REPORT_AT_HOURS;\n\n if ($isScheduledTime) {\n return true;\n }\n\n return $this->hasPassedScheduledTime($generatedAt, $earliestTz);\n }\n\n public function hasPassedScheduledTime(?CarbonInterface $generatedAt, string $timezone): bool\n {\n if ($generatedAt === null) {\n return false;\n }\n\n $now = Carbon::now($timezone);\n $scheduledTime = $now->copy()->setTime(self::SENT_REPORT_AT_HOURS, 0, 0);\n\n if ($now->hour < self::SENT_REPORT_AT_HOURS) {\n $scheduledTime = $scheduledTime->subDay();\n }\n\n $scheduledTimeUtc = $scheduledTime->copy()->utc();\n $generatedAtUtc = $generatedAt->copy()->utc();\n $nowUtc = $now->copy()->utc();\n\n return $generatedAtUtc->lt($scheduledTimeUtc) && $nowUtc->gt($scheduledTimeUtc);\n }\n\n public function calculateFromAndToDatePeriod(\n string $frequency,\n ?Carbon $fromDate = null,\n ?Carbon $toDate = null\n ): array {\n if ($frequency === self::FREQUENCY_ONE_OFF) {\n return [\n 'fromDate' => $fromDate,\n 'toDate' => $toDate,\n ];\n }\n\n $now = Carbon::now();\n\n return match ($frequency) {\n self::FREQUENCY_DAILY => [\n 'fromDate' => $now->copy()->subDay()->startOfDay(),\n 'toDate' => $now->copy()->subDay()->endOfDay(),\n ],\n self::FREQUENCY_WEEKLY => [\n 'fromDate' => $now->copy()->subWeeks(1)->startOfDay(),\n 'toDate' => $now->copy()->subDay()->endOfDay(),\n ],\n self::FREQUENCY_MONTHLY => [\n 'fromDate' => $now->copy()->subMonths(1)->startOfDay(),\n 'toDate' => $now->copy()->subDay()->endOfDay(),\n ],\n self::FREQUENCY_QUARTERLY => [\n 'fromDate' => $now->copy()->subMonths(3)->startOfDay(),\n 'toDate' => $now->copy()->subDay()->endOfDay(),\n ],\n default => throw new InvalidArgumentException(\"Unsupported frequency: {$frequency}\"),\n };\n }\n\n private function calculateFromAndToDate(AutomatedReport $automatedReport): array\n {\n return $this->calculateFromAndToDatePeriod(\n $automatedReport->getFrequency(),\n $automatedReport->getFrom(),\n $automatedReport->getTo()\n );\n }\n\n public function getAskJiminnyGenerateReportPayload(\n AutomatedReport $automatedReport,\n AutomatedReportResult $reportResult,\n array $activityIds,\n ): array {\n return [\n 'user_question' => $automatedReport->getAskAnythingPrompt()?->getContent(),\n 'call_ids' => array_map('strval', $activityIds),\n 'team_id' => $automatedReport->getTeamId(),\n 'request_id' => $reportResult->getUuid(),\n 'callback_url' => $this->getCallbackUrl(),\n 'report_period' => $this->getReportPeriodName($reportResult),\n 'report_name' => $automatedReport->getCustomName(),\n ];\n }\n\n private function getCallbackUrl(): string\n {\n return $this->webhookService->route('jiminny.webhook.reports.ready');\n }\n\n /**\n * Validate and transform payload data for automated reports\n *\n * @param array $data\n *\n * @throws InvalidArgumentException\n *\n * @return array\n */\n private function validateAndTransformData(array $data): array\n {\n // Validate organization (team) and check feature\n $team = $this->validateOrganization($data['organization'] ?? null);\n\n $status = $this->validateReportStatus($data['report_enabled'] ?? null);\n $type = $this->validateReportType($data['report_type'] ?? null);\n $frequency = $this->validateFrequency($data['frequency'] ?? null);\n $additionalPromptInput = $this->validateAdditionalPromptInput(\n $data['additional_prompt_input'] ?? null\n );\n $customReportName = $this->validateCustomReportName($data['custom_name'] ?? null);\n\n // Prepare data for the database\n $reportData = [\n 'team_id' => $team->getId(),\n 'type' => $type,\n 'status' => $status,\n 'frequency' => $frequency,\n 'additional_prompt_input' => $additionalPromptInput,\n 'custom_name' => $customReportName,\n ];\n\n // Validate deal values\n $reportData = $this->validateDealValues($data, $reportData);\n\n // Validate date range\n $reportData = $this->validateDateRange($data, $reportData, $frequency);\n\n // Validate call durations\n $reportData = $this->validateCallDurations($data, $reportData);\n\n // Validate call types\n $reportData = $this->validateCallTypes($data, $reportData);\n\n // Validate media types\n $reportData = $this->validateMediaTypes($data, $reportData);\n\n // Validate groups\n if (isset($data['teams'])) {\n $reportData['groups'] = $this->validateAndGetGroupIds($team, $data['teams']);\n }\n\n // Validate deal stages\n $reportData = $this->validateDealStages($data, $reportData, $team, $type);\n\n // Validate playbook categories\n $reportData = $this->validatePlaybookCategories($data, $reportData, $team);\n\n // Validate recipients\n $reportData['recipients'] = [\n 'users' => $this->validateAndGetUserIdsByTeam($team, $data['recipients'] ?? []),\n ];\n\n if (isset($data['jiminny_recipients'])) {\n // Validate Jiminny recipients\n $reportData['jiminny_recipients'] = [\n 'users' => $this->validateAndGetJiminnyUserIds((array) $data['jiminny_recipients']),\n ];\n }\n\n return $reportData;\n }\n\n private function validateDealValues(array $data, array $reportData): array\n {\n if (isset($data['min_deal_value'])) {\n $reportData['deal_value_min'] = (int) $data['min_deal_value'];\n\n if ($reportData['deal_value_min'] > 4294967295 || $reportData['deal_value_min'] < 0) {\n throw new InvalidArgumentException('Min deal value should be between 0 and 4294967295');\n }\n }\n\n if (isset($data['max_deal_value'])) {\n $reportData['deal_value_max'] = (int) $data['max_deal_value'];\n\n if ($reportData['deal_value_max'] > 4294967295 || $reportData['deal_value_max'] < 0) {\n throw new InvalidArgumentException('Max deal value should be between 0 and 4294967295');\n }\n }\n\n if (isset($data['min_deal_value'], $data['max_deal_value'])\n && $data['min_deal_value'] > $data['max_deal_value']\n ) {\n throw new InvalidArgumentException('Min deal value cannot be greater than max deal value');\n }\n\n return $reportData;\n }\n\n private function validateDateRange(array $data, array $reportData, string $frequency): array\n {\n // Set date range only for one_off frequency\n if ($frequency === 'one_off') {\n if (isset($data['start_date_period'])) {\n $reportData['from'] = $this->parseDate($data['start_date_period']);\n }\n\n if (isset($data['end_date_period'])) {\n $reportData['to'] = $this->parseDate($data['end_date_period']);\n }\n\n if (empty($reportData['from']) || empty($reportData['to'])) {\n throw new InvalidArgumentException(\n 'Start date and end date are required for one_off frequency'\n );\n }\n } else {\n $reportData['from'] = null;\n $reportData['to'] = null;\n }\n\n return $reportData;\n }\n\n private function validateCallDurations(array $data, array $reportData): array\n {\n // Convert call durations from minutes to seconds\n if (isset($data['min_call_duration'])) {\n $reportData['call_duration_min'] = (int) $data['min_call_duration'] * 60;\n\n if ($reportData['call_duration_min'] > 4294967295 || $reportData['call_duration_min'] < 0) {\n throw new InvalidArgumentException('Min call duration should be between 0 and 4294967295');\n }\n }\n\n if (isset($data['max_call_duration'])) {\n $reportData['call_duration_max'] = (int) $data['max_call_duration'] * 60;\n\n if ($reportData['call_duration_max'] > 4294967295 || $reportData['call_duration_max'] < 0) {\n throw new InvalidArgumentException('Max call duration should be between 0 and 4294967295');\n }\n }\n\n return $reportData;\n }\n\n private function validateCallTypes(array $data, array $reportData): array\n {\n // Set call types\n $reportData['call_types'] = $data['call_type'] ?? [];\n if (empty($reportData['call_types'])) {\n $reportData['call_types'] = self::getCallTypes();\n }\n\n foreach ($reportData['call_types'] as $callType) {\n if (! in_array($callType, self::getCallTypes(), true)) {\n throw new InvalidArgumentException(sprintf('Call type %s is invalid', $callType));\n }\n }\n\n return $reportData;\n }\n\n private function validateMediaTypes(array $data, array $reportData): array\n {\n // Set media types from input data\n $reportData['media_types'] = $data['media_types'] ?? [];\n\n if (empty($reportData['media_types'])) {\n throw new InvalidArgumentException('Media types are required');\n }\n\n foreach ($reportData['media_types'] as $mediaType) {\n if (! in_array($mediaType, self::MEDIA_TYPES, true)) {\n throw new InvalidArgumentException(sprintf('Media type %s is invalid', $mediaType));\n }\n }\n\n return $reportData;\n }\n\n private function validateDealStages(array $data, array $reportData, Team $team, string $reportType): array\n {\n // Validate and set deal stages\n if (isset($data['deal_stage_at_call'])) {\n $reportData['deal_at_call_stages'] =\n $this->validateAndGetDealStageIds($team, $data['deal_stage_at_call'], 'Deal stage at call');\n }\n\n if (isset($data['current_deal_stage'])) {\n $reportData['current_deal_stages'] =\n $this->validateAndGetDealStageIds($team, $data['current_deal_stage'], 'Current deal stage');\n }\n\n // Ensure current_deal_stage is not provided for loss_analysis report type\n if ($reportType === self::TYPE_LOSS_ANALYSIS && ! empty($data['current_deal_stage'])) {\n throw new InvalidArgumentException('Current deal stage is not applicable for Loss Analysis reports');\n }\n\n return $reportData;\n }\n\n // transform uuid to id\n private function validatePlaybookCategories(array $data, array $reportData, Team $team): array\n {\n $key = 'playbook_categories';\n\n if (isset($data[$key])) {\n $payloadIds = $data[$key];\n $ids = [];\n\n foreach ($payloadIds as $uuid) {\n $uuid = (string) $uuid;\n\n try {\n $playbookCategory = $this->playbookCategoryRepository->findByUuid($uuid);\n } catch (Throwable $throwable) {\n Log::error(__METHOD__ . ' ' . $throwable->getMessage());\n\n throw new InvalidArgumentException(sprintf('Playbook category %s not found', $uuid));\n }\n\n if (! $playbookCategory) {\n throw new InvalidArgumentException(sprintf('Playbook category %s not found', $uuid));\n }\n\n if (! $playbookCategory->hasPlaybook()) {\n throw new InvalidArgumentException(sprintf('Playbook category %s has no playbook', $uuid));\n }\n\n if ($playbookCategory->getPlaybook()->getTeamId() !== $team->getId()) {\n throw new InvalidArgumentException(\n sprintf('Playbook category %s not found for team %s', $uuid, $team->getUuid())\n );\n }\n\n $ids[] = $playbookCategory->getId();\n }\n\n $reportData[$key] = $ids;\n }\n\n return $reportData;\n }\n\n private function validateReportStatus($status): bool\n {\n if (! in_array($status, [true, false], true)) {\n throw new InvalidArgumentException('Report status is invalid');\n }\n\n return $status;\n }\n\n private function validateReportType($type): string\n {\n if (! in_array($type, self::getTypes(), true)) {\n throw new InvalidArgumentException(sprintf('Report type is invalid: %s', $type));\n }\n\n return $type;\n }\n\n private function validateFrequency($frequency): string\n {\n if (! in_array($frequency, self::getFrequencies(), true)) {\n throw new InvalidArgumentException('Frequency is invalid');\n }\n\n return $frequency;\n }\n\n private function validateAdditionalPromptInput(?string $additionalPromptInput): ?string\n {\n if ($additionalPromptInput && strlen($additionalPromptInput) > 5000) {\n throw new InvalidArgumentException('Additional Prompt Input should be less than 5000 characters');\n }\n\n return $additionalPromptInput;\n }\n\n private function validateCustomReportName(?string $customReportName): ?string\n {\n if ($customReportName === null || $customReportName === '') {\n return null;\n }\n\n if (strlen($customReportName) > 70) {\n throw new InvalidArgumentException('Custom report name should be less than 70 characters');\n }\n\n return $customReportName;\n }\n\n private function validateOrganization(?string $organizationUuid): Team\n {\n if (! $organizationUuid) {\n throw new InvalidArgumentException('Organization is required');\n }\n\n $team = $this->teamRepository->idOrUuid($organizationUuid);\n\n if (! $team) {\n throw new InvalidArgumentException('Organization not found');\n }\n\n if (! $team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {\n throw new InvalidArgumentException('Organization does not have the Automated Reports feature');\n }\n\n return $team;\n }\n\n private function validateAndGetGroupIds(Team $team, array $teamUuids): array\n {\n $groupIds = [];\n\n foreach ($teamUuids as $uuid) {\n $group = $this->groupRepository->findByUuid($uuid);\n\n if ($group === null || $group->getTeamId() !== $team->getId()) {\n throw new InvalidArgumentException(\n sprintf('Group %s not found for team %s', $uuid, $team->getUuid())\n );\n }\n\n $groupIds[] = $group->getId();\n\n }\n\n return $groupIds;\n }\n\n private function validateAndGetDealStageIds(Team $team, array $stageUuids, string $propertyLabel): array\n {\n $stageIds = [];\n\n foreach ($stageUuids as $uuid) {\n $stage = $this->stageRepository->findByUuid($uuid);\n\n if ($stage === null || $stage->getTeamId() !== $team->getId()) {\n throw new InvalidArgumentException(\n sprintf('Stage %s not found for team %s for %s', $uuid, $team->getUuid(), $propertyLabel)\n );\n }\n\n $stageIds[] = $stage->getId();\n }\n\n return $stageIds;\n }\n\n private function validateAndGetUserIds(array $userUuids, callable $teamCheck): array\n {\n if (empty($userUuids)) {\n return [];\n }\n\n $userIds = [];\n\n foreach ($userUuids as $uuid) {\n $user = $this->userRepository->findByUuid($uuid);\n\n if (! $user || ! $user->isStatusActive()) {\n throw new InvalidArgumentException(\n sprintf('User %s not found or is not active', $uuid)\n );\n }\n\n if (! $teamCheck($user)) {\n throw new InvalidArgumentException(\n sprintf('User %s does not belong to the allowed team(s)', $uuid)\n );\n }\n\n $userIds[] = $user->getId();\n }\n\n return $userIds;\n }\n\n private function validateAndGetUserIdsByTeam(Team $team, array $userUuids): array\n {\n return $this->validateAndGetUserIds($userUuids, fn ($user) => $user->getTeamId() === $team->getId());\n }\n\n private function validateAndGetJiminnyUserIds(array $userUuids): array\n {\n $allowedTeamIds = config('kiosk.teamIds', []);\n\n return $this->validateAndGetUserIds($userUuids, fn ($user) => in_array($user->getTeamId(), $allowedTeamIds, true));\n }\n\n private function parseDate(string $dateString): string\n {\n return date('Y-m-d H:i:s', strtotime($dateString));\n }\n\n private function generateReportResultViewUrl(AutomatedReportResult $result): string\n {\n $mediaResource = $this->getReportMediaRouteResource($result);\n\n return route('ai-reports.' . $mediaResource . '.view', ['uuid' => $result->getUuid()]);\n }\n\n private function generateReportResultDownloadUrl(AutomatedReportResult $result): string\n {\n $mediaResource = $this->getReportMediaRouteResource($result);\n\n return route('ai-reports.' . $mediaResource . '.download', ['uuid' => $result->getUuid()]);\n }\n\n private function getReportMediaRouteResource(AutomatedReportResult $result): string\n {\n if ($result->getMediaType() === self::MEDIA_TYPE_PDF) {\n return self::PDF_KEY;\n } elseif ($result->getMediaType() === self::MEDIA_TYPE_PODCAST) {\n return self::AUDIO_KEY;\n }\n\n throw new \\InvalidArgumentException('Unknown media type.');\n }\n\n public function getMediaPath(AutomatedReportResult $result): ?string\n {\n $url = match ($result->getMediaType()) {\n self::MEDIA_TYPE_PDF => $result->getPdfUrl(),\n self::MEDIA_TYPE_PODCAST => $result->getPodcastAudioUrl(),\n default => null,\n };\n\n if ($url === null) {\n return null;\n }\n\n $path = parse_url(trim($url, '\"\\''), PHP_URL_PATH);\n\n return $path ?: null;\n }\n\n public function getFilenameSuffix(AutomatedReportResult $result): ?string\n {\n return match ($result->getMediaType()) {\n self::MEDIA_TYPE_PODCAST => 'Podcast',\n default => null,\n };\n }\n\n public function getMailSubjectSuffix(AutomatedReportResult $result): string\n {\n return match ($result->getMediaType()) {\n self::MEDIA_TYPE_PDF => 'report',\n self::MEDIA_TYPE_PODCAST => 'podcast',\n default => '',\n };\n }\n\n public function getMediaTypeMetadata(AutomatedReportResult $result): array\n {\n return match ($result->getMediaType()) {\n self::MEDIA_TYPE_PODCAST => ['extension' => 'mp3', 'mime' => 'audio/mpeg'],\n self::MEDIA_TYPE_PDF => ['extension' => 'pdf', 'mime' => 'application/pdf'],\n default => ['extension' => null, 'mime' => null],\n };\n }\n\n public function deleteS3Files(AutomatedReportResult $result): void\n {\n $teamUuid = $result->getReport()->getTeam()->getUuid();\n $reportUuid = $result->getUuid();\n\n // delete all files for a report uuid no mather of pdf, podcast, or both\n // in case of both - the podcast files are linked to the pdf (parent) uuid\n // pdf and podcast date times should be close\n $path = sprintf('%s/%s/%s', $teamUuid, self::S3_DIR, $reportUuid);\n\n foreach (self::FILE_EXTENSIONS_VARIANTS as $extension) {\n $file = $path . '.' . $extension;\n\n if (Storage::exists($file)) {\n Storage::delete($file);\n Log::info('[Reports] Deleted S3 file', [\n 'path' => $file,\n ]);\n }\n }\n\n foreach (self::FILE_PODCAST_EXTENSIONS_VARIANTS as $extension) {\n $file = $path . '_podcast.' . $extension;\n\n if (Storage::exists($file)) {\n Storage::delete($file);\n Log::info('[Reports] Deleted Podcast S3 file', [\n 'path' => $file,\n ]);\n }\n }\n }\n\n /**\n *\n * @param int|null $teamId Optional team ID to filter results\n *\n * @return Collection<int, int> Collection of team IDs\n */\n public function getTeamIdsWithReportsResults(?int $teamId = null): Collection\n {\n return $this->automatedReportsRepository->getTeamIdsWithReportsResults($teamId);\n }\n\n /**\n * Core delete logic for report results using a query\n *\n * @param Builder $query\n * @param array $logContext\n *\n * @return int\n */\n private function deleteReportResultsByQuery(Builder $query, array $logContext = []): int\n {\n $deletedCount = 0;\n\n if ($query->exists()) {\n Log::info(\n 'Run delete report results',\n array_merge(\n $logContext,\n [\n 'service' => 'AutomatedReportsService',\n ]\n )\n );\n\n $query->chunkById(50, function ($results) use (&$deletedCount, $logContext) {\n foreach ($results as $result) {\n $this->deleteReportResult($result);\n $deletedCount++;\n\n Log::info(\n 'Deleted a report result',\n array_merge(\n $logContext,\n [\n 'result_id' => $result->getId(),\n 'report_id' => $result->getReportId(),\n ]\n )\n );\n }\n });\n }\n\n return $deletedCount;\n }\n\n /**\n * Delete report results for a team by retention period\n *\n * @param Team $team\n * @param CarbonImmutable $retentionDate\n *\n * @return int Number of deleted report results\n */\n public function deleteReportsResultsInRetentionPeriod(Team $team, CarbonImmutable $retentionDate): int\n {\n $reportIds = $this->automatedReportsRepository->getReportIdsByTeam($team);\n\n if ($reportIds->isEmpty()) {\n return 0;\n }\n\n $query = $this->automatedReportsRepository\n ->getReportResultsQueryForRetention($team, $retentionDate);\n\n return $this->deleteReportResultsByQuery($query, [\n 'team_id' => $team->getId(),\n 'retention_date' => $retentionDate->toDateTimeString(),\n ]);\n }\n\n /**\n * Delete ALL report results for a specific automated report\n *\n * @param string $uuid\n *\n * @return int\n */\n public function deleteReportResults(string $uuid): int\n {\n $report = $this->getReport($uuid);\n\n $query = $this->automatedReportsRepository->getResultsByReportQuery($report);\n\n return $this->deleteReportResultsByQuery($query, [\n 'report_uuid' => $uuid,\n 'report_id' => $report->getId(),\n ]);\n }\n\n public function deleteReportResult(AutomatedReportResult $result): void\n {\n $this->deleteS3Files($result);\n\n $result->delete();\n }\n\n /**\n * Get all reports for a specific team\n *\n * @param Team $team\n *\n * @return \\Illuminate\\Database\\Eloquent\\Collection\n */\n public function getTeamReports(Team $team): \\Illuminate\\Database\\Eloquent\\Collection\n {\n return $this->automatedReportsRepository->getReportsByTeam($team);\n }\n\n /**\n * Get all report results for a specific report\n *\n * @param AutomatedReport $report\n *\n * @return \\Illuminate\\Database\\Eloquent\\Collection\n */\n public function getReportResults(AutomatedReport $report): \\Illuminate\\Database\\Eloquent\\Collection\n {\n return $this->automatedReportsRepository->getResultsByReport($report);\n }\n\n public function deleteAllReportResults(AutomatedReport $report): void\n {\n $results = $this->getReportResults($report);\n\n /** @var AutomatedReportResult $result */\n foreach ($results as $result) {\n Log::info('Deleting result', [\n 'report' => $report->getId(),\n 'result' => $result->getId(),\n ]);\n\n $this->deleteReportResult($result);\n }\n }\n\n public function deleteAllData(Team $team): void\n {\n Log::info('Deleting automated report and results for team', [\n 'team' => $team->getId(),\n ]);\n\n $reports = $this->getTeamReports($team);\n\n /** @var AutomatedReport $report */\n foreach ($reports as $report) {\n Log::info('Deleting report', [\n 'team' => $team->getId(),\n 'report' => $report->getId(),\n ]);\n\n $this->deleteAllReportResults($report);\n\n $report->delete();\n }\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":true,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"Project","depth":3,"role_description":"text"},{"role":"AXButton","text":"Project","depth":3,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"New File or Directory…","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Expand Selected","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Collapse All","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Options","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false}]...
|
3397592283435315795
|
6686367547760219213
|
idle
|
accessibility
|
NULL
|
Project: faVsco.js, menu
#11894 on JY-18909-automa Project: faVsco.js, menu
#11894 on JY-18909-automated-reports-ask-jiminny, menu
Start Listening for PHP Debug Connections
AutomatedReportsCommandTest
Run 'AutomatedReportsCommandTest'
Debug 'AutomatedReportsCommandTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Execute
Explain Plan
Browse Query History
View Parameters
Open Query Execution Settings…
In-Editor Results
Tx: Auto
Cancel Running Statements
Playground
jiminny
Sync Changes
Hide This Notification
Code changed:
Hide
16
13
13
Previous Highlighted Error
Next Highlighted Error
SELECT * FROM teams WHERE id = 1;
select * from crm_layouts where crm_configuration_id = 39;
SELECT * FROM crm_layout_entities WHERE crm_layout_id = 283;
SELECT * FROM crm_fields WHERE id = 2234;
SELECT * FROM crm_field_values WHERE crm_field_id = 2234;
select * from crm_profiles where user_id = 143;
select * from record_types where crm_configuration_id = 39; # 0121K000001MHElQAO,0121K000001MHEqQAO
select * from business_processes where crm_configuration_id = 39;
# 01941000000H669AAC, 01941000000H66JAAS
select * from record_type_field_values
where record_type_id IN (24);
select * from crm_field_values where id IN (2730);
select * from crm_configurations where id = 39;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 1
and sa.provider = 'salesforce'; #1035
select * from users where team_id = 1; # 222 group 3
SELECT * FROM activities WHERE user_id = 222 order by id desc;
select * from sidekick_settings where team_id = 1;
select * from teams where id = 1;
select * from team_features where team_id = 1;
select * from activities where crm_configuration_id = 2
and provider = 'ms-teams' and id = 608765;
SELECT * FROM activities WHERE crm_configuration_id = 2 and crm_provider_id = '59523413338';
select * from sidekick_settings where team_id = 2;
SELECT * FROM activities WHERE id = 608660;
select * from activity_summary_logs where activity_id = 608660;
select * from ai_prompts where transcription_id = 11214;
# [PASSWORD_DOTS]
SELECT * FROM activities WHERE uuid_to_bin('ed78a437-2804-450e-ab2f-56ab1c641346') = uuid;
# id: 608818, crm: 59628809737
SELECT * FROM activities WHERE uuid_to_bin('36b06e55-afdd-4782-8dee-c624cd0af191') = uuid;
# id: 608821, crm: 59632069252
SELECT ce.start_time, ce.end_time, a.id, a.uuid, crm_provider_id, calendar_event_id, title,
playbook_category_id, user_id, lead_id, contact_id, account_id, opportunity_id,
scheduled_start_time, scheduled_end_time, actual_start_time, actual_end_time, a.created_at
FROM activities a
join calendar_events ce on a.calendar_event_id = ce.id
WHERE a.id IN (608818, 608821);
select * from users where team_id = 1;
select * from team_settings where team_id = 1;
select * from crm_profiles where crm_configuration_id = 39 order by user_id;
select * from team_features where team_id = 1;
select * from users where team_id = 2;
SELECT * FROM activities WHERE uuid_to_bin('ec7647e9-5225-458b-b475-f31aa2769204') = uuid; # 612639
# Preslava N. Ivanova, grou id 3
SELECT * FROM opportunities WHERE uuid_to_bin('a2928fe5-aec5-46cb-85d9-7654c89e46a6') = uuid;
select * from activities where opportunity_id = 344 and actual_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00';
select
a.id,
a.type,
a.scheduled_start_time,
a.actual_start_time,
a.created_at,
a.opportunity_id,
a.status
FROM activities a
WHERE opportunity_id = 344
and status IN ('completed', 'received', 'delivered')
and (
(a.actual_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00')
OR (a.created_at between '2024-10-11 00:00:00' and '2024-10-12 00:00:00')
OR (a.scheduled_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00'))
;
SELECT * FROM users WHERE id = 222;
SELECT * FROM crm_profiles WHERE user_id = 222;
select * from crm_layouts where crm_configuration_id = 39;
SELECT * FROM crm_layout_entities WHERE crm_layout_id = 281;
select * from group_deal_risk_types;
select * from opportunities where team_id = 1;
SELECT * FROM opportunities WHERE id = 315;
SELECT * FROM crm_field_data WHERE object_id = 315;
select * from crm_field_data where object_id = 260;
select * from generic_ai_prompts where subject_id = 315;
select * from teams; # 36, 21, 121, [EMAIL]
SELECT * FROM social_accounts WHERE sociable_id = 121 and provider = 'bullhorn';
# [PASSWORD_DOTS]
select * from teams where id = 1;
select * from crm_configurations where id = 39;
select * from users where team_id = 1;
select u.email, cp.* from users u
join crm_profiles cp on u.id = cp.user_id
where u.team_id = 1;
# 1 - 00541000004281rAAA
# 204 - 0052g000003freeAAA
# 429 - 0052g000003qGOiAAM
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 1
and sa.provider = 'salesforce';
select * from activities where type = 'softphone'
and created_at > '2024-12-11 15:24:36' order by id desc;
select * from activity_providers where team_id = 1;
select * from activity_provider_users where activity_provider_id = 328;
select * from opportunities where crm_configuration_id = 39
AND account_id = 178 AND is_closed = false
order by created_at DESC;
select * from contacts where id = 3952;
select * from accounts where id = 178;
# [PASSWORD_DOTS]
select * from teams where id = 36;
select * from crm_configurations where id = 21;
select * from users where team_id = 36;
select u.email, cp.* from users u
join crm_profiles cp on u.id = cp.user_id
where u.team_id = 36;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 36
and sa.provider = 'bullhorn';
select * from social_accounts where id = 348;
UPDATE social_accounts SET
provider_user_token = '21442_6802599_91:41179a58-21e7-4d7c-ad58-56bb666b2f65',
provider_refresh_token = '21442_6802599_91:01c6b335-3f2a-42e4-85ff-8a08fa65fceb',
expires = 1733998131,
state = 'connected'
WHERE id = 348;
# [PASSWORD_DOTS]
select * from teams where id = 31;
select * from crm_configurations where id = 18;
select * from users where team_id = 31; # 257
select u.email, cp.* from users u
join crm_profiles cp on u.id = cp.user_id
where u.team_id = 31;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 31
and sa.provider = 'close';
select * from contacts where crm_configuration_id = 18;
# [PASSWORD_DOTS] NEPTUNE [PASSWORD_DOTS]
select * from teams;
select * from users where id IN (1030, 1035, 1052);
select * from crm_configurations;
select * from users where team_id = 65; # 257
select * from team_settings where team_id = 65; # 257
select * from invitations where team_id = 65; # 257
select * from users where email = '[EMAIL]'; # 257
select u.email, cp.* from users u
join crm_profiles cp on u.id = cp.user_id
where u.team_id = 65;
select * from crm_configurations where id = 53;
select * from accounts where crm_configuration_id = 53 order by id desc;
select * from leads where crm_configuration_id = 53 order by id desc;
select * from contacts where crm_configuration_id = 53 order by id desc;
select * from opportunities where crm_configuration_id = 53 order by id desc;
select * from crm_profiles where crm_configuration_id = 53 order by id desc;
select * from crm_fields where crm_configuration_id = 53 order by id desc;
select * from crm_field_values where crm_field_id = 3341 order by id desc;
select * from crm_layouts where crm_configuration_id = 53 order by id desc;
select * from stages where crm_configuration_id = 53 order by id desc;
select * from crm_profiles where crm_configuration_id = 13;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 65
and sa.provider = 'integration-app';
select * from contacts where crm_configuration_id = 13;
select * from social_accounts where sociable_id = 283;
SELECT * FROM opportunities WHERE crm_provider_id = '006O400000E9bzeIAB';
select * from activity_providers where team_id = 65;
SELECT * FROM activities WHERE crm_configuration_id IN (51, 52, 53);
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 65
;
# [PASSWORD_DOTS] STAGING [PASSWORD_DOTS]
SELECT * FROM teams;
SELECT * FROM teams WHERE id = 88;
SELECT * FROM teams WHERE id = 89;
select * from team_settings where team_id = 89;
SELECT * FROM users WHERE team_id = 89;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 89;
select * from users;
SELECT * FROM social_accounts WHERE sociable_id = 1761;
SELECT * FROM crm_configurations WHERE id = 70;
select * from accounts where crm_configuration_id = 70 order by id desc;
select * from leads where crm_configuration_id = 70 order by id desc;
select * from contacts where crm_configuration_id = 70 order by id desc;
select * from opportunities where crm_configuration_id = 70 order by id desc;
select * from crm_profiles where crm_configuration_id = 70 order by id desc;
select * from crm_fields where crm_configuration_id = 70 order by id desc;
select * from crm_field_values where crm_field_id = 3536 order by id desc;
select * from crm_layouts where crm_configuration_id = 70 order by id desc;
select * from stages where crm_configuration_id = 70 order by id desc;
select * from business_processes where crm_configuration_id = 70 order by id desc;
select * from business_process_stages where business_process_id = 34;
select * from contacts where id = 10468;
select * from crm_layouts where crm_configuration_id = 70;
SELECT * FROM crm_layout_entities WHERE crm_layout_id = 388;
SELECT * FROM crm_fields WHERE id IN (3533,3534,3535);
select * from activities where crm_configuration_id = 70
and (account_id IS NOT NULL or lead_id IS NOT NULL or contact_id IS NOT NULL or opportunity_id IS NOT NULL) order by id desc;
SELECT * FROM activities WHERE uuid_to_bin('2e10b60f-8a61-41c5-a3d4-28835353dc65') = uuid;
SELECT * FROM activities where crm_configuration_id = 69 ;
SELECT * FROM users WHERE email LIKE '%[EMAIL]%';
SELECT * FROM activities WHERE uuid_to_bin('5a150c93-40fc-42ec-b3bd-c1d328e09f6e') = uuid;
SELECT * FROM opportunities WHERE id = 385;
select * from participants p
join activities a on p.activity_id = a.id
where a.crm_configuration_id = 70
and (p.lead_id IS NOT NULL or p.contact_id IS NOT NULL);
SELECT * FROM participants WHERE id = 1013638;
select * from teams where id = 90;
select * from users where team_id = 90;
select * from social_accounts where social_accounts.sociable_id IN (1960,1760);
SELECT * FROM crm_profiles WHERE crm_configuration_id = 71;
select * from invitations where team_id = 90;
select * from crm_configurations where id = 71;
select * from accounts where crm_configuration_id = 71 order by id desc;
select * from leads where crm_configuration_id = 71 order by id desc;
select * from contacts where crm_configuration_id = 71 order by id desc;
select * from opportunities where crm_configuration_id = 71 order by id desc;
select * from crm_profiles where crm_configuration_id = 71 order by id desc;
select * from crm_fields where crm_configuration_id = 71 order by id desc;
select * from crm_field_values where crm_field_id = 3341 order by id desc;
select * from crm_layouts where crm_configuration_id = 71 order by id desc;
select * from stages where crm_configuration_id = 71 order by id desc;
select * from users order by secondary_email desc;
select u.id, u.email, u.status, sa.id, sa.provider_user_id from social_accounts sa
join users u on sa.sociable_id = u.id
where sa.provider = 'google' and u.email LIKE 'aneliya%';
select * from failed_jobs order by id desc;
select * from users where email = '[EMAIL]' or secondary_email = '[EMAIL]';
select * from teams;
SELECT * FROM crm_profiles WHERE crm_configuration_id = 39;
SELECT * FROM crm_fields WHERE crm_configuration_id = 39 and object_type = 'task';
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 1
and sa.provider = 'salesforce';
# [PASSWORD_DOTS]
SELECT * FROM activities WHERE uuid_to_bin('c38b3895-fd0f-4b1f-9fb2-c170dba137c6') = uuid;
SELECT * FROM crm_configurations WHERE id = 70;
select * from teams where id = 1;
select * from groups where team_id = 1;
select * from users where team_id = 1;
select o.id, o.name,o.close_date, u.id, u.name, u.group_id, r.id, r.display_name, g.name, g.scope from opportunities o
join users u on o.user_id = u.id
join groups g on u.group_id = g.id
join role_user ru on u.id = ru.user_id
join roles r on ru.role_id = r.id
where o.crm_configuration_id = 39 and close_date > '2024-01-01 00:00:00';
select * from role_user where user_id = 143;
select * from roles;
select * from role_user;
select * from groups where id = 9;
select * from scope_groups where group_id = 9;
# [PASSWORD_DOTS]
select * from teams where id = 36;
select * from crm_configurations;
SELECT * FROM social_accounts WHERE sociable_id = 121;
[URL_WITH_CREDENTIALS] this will add filter, however if we need to control feature by FF we need conditional logic
public const array TYPES = [
['id' => 'exec_summary', 'name' => 'Exec Summary'],
['id' => 'coaching_profiles', 'name' => 'Coaching Profiles'],
['id' => 'product_feedback', 'name' => 'Product Feedback'],
['id' => self::TYPE_LOSS_ANALYSIS, 'name' => 'Loss Analysis'],
// ['id' => 'questions', 'name' => 'Questions'],
// ['id' => 'statistical_quant', 'name' => 'Statistical Quantitative'],
];
public const array ALL_TYPES = [
...self::TYPES,
['id' => self::TYPE_ASK_JIMINNY, 'name' => 'Ask Jiminny'],
];
public const string FREQUENCY_DAILY = 'daily';
public const string FREQUENCY_WEEKLY = 'weekly';
public const string FREQUENCY_MONTHLY = 'monthly';
public const string FREQUENCY_QUARTERLY = 'quarterly';
public const string FREQUENCY_ONE_OFF = 'one_off';
/**
* Frequencies for standard (non-Ask Jiminny) reports.
*/
public const array FREQUENCIES = [
['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],
['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],
['id' => self::FREQUENCY_QUARTERLY, 'name' => 'Quarterly'],
['id' => self::FREQUENCY_ONE_OFF, 'name' => 'One-off'],
];
/**
* Frequencies for Ask Jiminny reports.
*/
public const array ASK_JIMINNY_FREQUENCIES = [
['id' => self::FREQUENCY_DAILY, 'name' => 'Daily'],
['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],
['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],
];
public const string MEDIA_TYPE_PDF = 'pdf';
public const string MEDIA_TYPE_PODCAST = 'podcast';
public const array MEDIA_TYPES = [self::MEDIA_TYPE_PDF, self::MEDIA_TYPE_PODCAST];
public const array MEDIA_TYPE_OBJECT_PDF = ['id' => self::MEDIA_TYPE_PDF, 'name' => 'PDF'];
public const array MEDIA_TYPE_OBJECT_PODCAST = ['id' => self::MEDIA_TYPE_PODCAST, 'name' => 'Podcast'];
public const array MEDIA_TYPE_OBJECTS = [self::MEDIA_TYPE_OBJECT_PDF, self::MEDIA_TYPE_OBJECT_PODCAST];
public const array CALL_TYPE_CONFERENCE = ['id' => 'conference', 'name' => 'Conference'];
public const array CALL_TYPE_DIALER = ['id' => 'dialer', 'name' => 'Dialer'];
public const int SENT_REPORT_AT_HOURS = 5;
public const string PDF_KEY = 'pdf';
public const string AUDIO_KEY = 'audio';
private const array ALL_FREQUENCIES = [
['id' => self::FREQUENCY_DAILY, 'name' => 'Daily'],
['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],
['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],
['id' => self::FREQUENCY_QUARTERLY, 'name' => 'Quarterly'],
['id' => self::FREQUENCY_ONE_OFF, 'name' => 'One-off'],
];
private const string S3_DIR = 'reports';
private const array FILE_EXTENSIONS_VARIANTS = ['html', 'MD', 'pdf'];
private const array FILE_PODCAST_EXTENSIONS_VARIANTS = ['json', 'mp3', 'ssml'];
public function __construct(
private readonly TeamRepository $teamRepository,
private readonly GroupRepository $groupRepository,
private readonly UserRepository $userRepository,
private readonly StageRepository $stageRepository,
private readonly DealStagesService $dealStagesService,
private readonly RecipientsService $recipientsService,
private readonly AutomatedReportsRepository $automatedReportsRepository,
private readonly Webhook $webhookService,
private readonly BusDispatcher $dispatcher,
private readonly ActivityTypeService $activityTypeService,
private readonly PlaybookCategoryRepository $playbookCategoryRepository,
private readonly AskAnythingPromptService $askAnythingPromptService,
private readonly SearchRepository $activitySearchRepository,
private readonly AskAnythingRepository $askAnythingRepository,
) {
}
public static function getTypes(): array
{
$types = self::TYPES;
return array_map(static function ($type) {
return $type['id'];
}, $types);
}
public static function getCallTypes(): array
{
return array_map(static function ($callType) {
return $callType['id'];
}, [self::CALL_TYPE_CONFERENCE, self::CALL_TYPE_DIALER]);
}
public static function getFrequencies(): array
{
return array_map(static function ($frequency) {
return $frequency['id'];
}, self::FREQUENCIES);
}
// front-facing structure
public function getReportEnabledFieldData(bool $value = false): array
{
return [
'id' => 'report_enabled',
'label' => '',
'inputType' => InputTypeEnum::TOGGLE,
'value' => $value,
];
}
// Organizations = Teams
public function getOrganizationFieldData(?string $value = null, bool $shortVersion = false): array
{
$options = $this->getTeams();
if ($shortVersion) {
return [
'id' => 'organization',
'label' => 'Organization',
'options' => $options,
];
}
return [
'id' => 'organization',
'label' => 'Organization',
'inputType' => InputTypeEnum::DROPDOWN,
'required' => true,
'placeholder' => 'Select',
'options' => $options,
'value' => $value,
'dependencies' => [
'teams',
'deal_stage_at_call',
'current_deal_stage',
'recipients',
ActivityTypeService::PLAYBOOK_CATEGORIES_KEY,
],
'dependsOn' => [],
];
}
// Teams = Groups
public function getTeamFieldData(array $options = [], array $value = [], bool $shortVersion = false): array
{
if ($shortVersion) {
return [
'id' => 'teams',
'label' => 'Team',
'options' => $options,
];
}
return [
'id' => 'teams',
'label' => 'Team',
'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,
'required' => false,
'placeholder' => 'Select',
'options' => $options,
'value' => $value, // value should be an array of objects {id, name}
'dependencies' => [ActivityTypeService::PLAYBOOK_CATEGORIES_KEY],
'dependsOn' => [],
];
}
public function getReportTypeFieldData(?string $value = null, bool $shortVersion = false, ?Team $team = null): array
{
$types = [];
if ($team instanceof Team) {
if ($team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {
$types = self::TYPES;
}
if ($team->hasFeature(FeatureEnum::ASK_JIMINNY_REPORTS)) {
$types[] = ['id' => self::TYPE_ASK_JIMINNY, 'name' => 'Ask Jiminny'];
}
} else {
$types = self::TYPES;
}
if ($shortVersion) {
return [
'id' => 'report_type',
'label' => 'Report Type',
'options' => $types,
];
}
return [
'id' => 'report_type',
'label' => 'Report Type',
'inputType' => InputTypeEnum::DROPDOWN,
'required' => true,
'placeholder' => 'Select',
'options' => $types,
'value' => $value,
'dependencies' => [],
'dependsOn' => [],
];
}
public function getFrequencyFieldData(?string $value = null): array
{
return [
'id' => 'frequency',
'label' => 'Frequency',
'inputType' => InputTypeEnum::DROPDOWN,
'required' => true,
'placeholder' => 'Select',
'options' => self::FREQUENCIES,
'value' => $value,
'dependencies' => ['period'],
'dependsOn' => [],
];
}
public function getPeriodFieldData(?string $valueStartDate = null, ?string $valueEndDate = null): array
{
return [
'id' => 'period',
'label' => 'Select one-off period',
'inputType' => InputTypeEnum::DATE_RANGE,
'required' => true,
'placeholder' => 'Select',
'value' => ['startDate' => $valueStartDate, 'endDate' => $valueEndDate],
'queryParams' => [
'startDate' => 'start_date_period',
'endDate' => 'end_date_period',
],
'dependencies' => [],
'dependsOn' => ['frequency'],
];
}
public function getActivityTypesFieldData(?Team $team = null, array $value = [], array $teamsFilter = []): array
{
return $this->activityTypeService->getActivityTypeFieldData(team: $team, value: $value, groupIds: $teamsFilter);
}
public function getDealStageAtCallFieldData(?Team $team = null, array $value = []): array
{
return $this->dealStagesService->getDealStageAtCallFieldData(team: $team, value: $value);
}
public function getCurrentDealStageFieldData(?Team $team = null, array $value = []): array
{
return $this->dealStagesService->getCurrentDealStageFieldData(team: $team, value: $value);
}
public function getDealValueFieldData(?int $valueMin = null, ?int $valueMax = null): array
{
return [
'id' => 'deal_value',
'label' => 'Deal Value',
'inputType' => InputTypeEnum::INTEGER_RANGE,
'required' => false,
'value' => ['min' => $valueMin, 'max' => $valueMax],
'queryParams' => [
'min' => 'min_deal_value',
'max' => 'max_deal_value',
],
'dependencies' => [],
'dependsOn' => [],
];
}
public function getCallTypeFieldData(bool $conferenceOn = false, bool $dialerOn = false): array
{
$value = [];
$conferenceOn && $value[] = self::CALL_TYPE_CONFERENCE;
$dialerOn && $value[] = self::CALL_TYPE_DIALER;
return [
'id' => 'call_type',
'label' => 'Call Type',
'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,
'required' => true,
'options' => [
self::CALL_TYPE_CONFERENCE,
self::CALL_TYPE_DIALER,
],
'value' => $value,
'dependencies' => [],
'dependsOn' => [],
];
}
public function getMediaTypeFieldData(?AutomatedReport $report = null): array
{
$value = [];
if ($report) {
$value = $this->transformMediaTypes($report);
}
return [
'id' => 'media_types',
'label' => 'Export as',
'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,
'required' => true,
'options' => self::MEDIA_TYPE_OBJECTS,
'value' => $value,
'dependencies' => [],
'dependsOn' => [],
];
}
public function getCallDurationFieldData(?int $valueMin = null, ?int $valueMax = null): array
{
return [
'id' => 'call_duration',
'label' => 'Call Duration',
'inputType' => InputTypeEnum::INTEGER_RANGE,
'required' => false,
'value' => ['min' => $valueMin, 'max' => $valueMax],
'queryParams' => [
'min' => 'min_call_duration',
'max' => 'max_call_duration',
],
'dependencies' => [],
'dependsOn' => [],
];
}
public function getRecipientsFieldData(?Team $team = null, array $value = []): array
{
return $this->recipientsService->getRecipientsFieldData(team: $team, value: $value);
}
public function getJiminnyRecipientsFieldData(array $value = []): array
{
return $this->recipientsService->getJiminnyRecipientsFieldData($value);
}
public function getAdditionalPromptInputFieldData(?string $value = null): array
{
return [
'id' => 'additional_prompt_input',
'label' => 'Special requirements',
'inputType' => InputTypeEnum::TEXTAREA,
'required' => false,
'placeholder' => 'What should be the focus of the report?',
'value' => $value,
'dependencies' => [],
'dependsOn' => [],
];
}
public function getCustomReportNameFieldData(?string $value = null): array
{
return [
'id' => 'custom_name',
'label' => 'Custom report name',
'inputType' => InputTypeEnum::TEXT,
'required' => false,
'placeholder' => 'Enter custom name',
'value' => $value,
'dependencies' => [],
'dependsOn' => [],
];
}
// data providers
public function getTeams(): array
{
$teams = $this->teamRepository->getTeamsForKiosk(status: Team::STATUS_ACTIVE);
$teamData = [];
foreach ($teams as $team) {
if (! $team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {
continue;
}
$teamData[] = $this->transformTeam($team);
}
return $teamData;
}
public function getTeamGroups(string $teamUuid): array
{
$data = [];
$team = $this->getTeam($teamUuid);
if ($team !== null) {
$groups = $team->groups()->get();
foreach ($groups as $group) {
$data[] = [
'id' => $group->getUuid(),
'name' => $group->getName(),
];
}
}
return $data;
}
public function getTeamsGroupsOptions(array $filterTeamUuids = []): array
{
$data = [];
$teams = $this->getTeams();
foreach ($teams as $team) {
if (! empty($filterTeamUuids) && ! in_array($team['id'], $filterTeamUuids, true)) {
continue;
}
$data[] = [
'label' => $team['name'],
'groups' => $this->getTeamGroups($team['id']),
];
}
return $data;
}
public function getTeam(string $teamUuid): ?Team
{
return $this->teamRepository->idOrUuid($teamUuid);
}
public function getTeamById(int $teamId): ?Team
{
return $this->teamRepository->find($teamId);
}
public function getGroupsUuids(AutomatedReport $report): array
{
$uuids = [];
$reportGroups = $report->getGroups();
foreach ($reportGroups as $groupId) {
if ($group = $this->groupRepository->find($groupId)) {
$uuids[] = $group->getUuid();
}
}
return $uuids;
}
public function getPlaybookCategoriesUuids(AutomatedReport $report): array
{
$uuids = [];
$playbookCategories = $report->getPlaybookCategories();
foreach ($playbookCategories as $id) {
if ($category = $this->playbookCategoryRepository->find($id)) {
$uuids[] = $category->getUuid();
}
}
return $uuids;
}
public function getDealAtCallStagesUuids(AutomatedReport $report): array
{
$uuids = [];
$reportStages = $report->getDealAtCallStages();
foreach ($reportStages as $id) {
if ($stage = $this->stageRepository->find($id)) {
$uuids[] = $stage->getUuid();
}
}
return $uuids;
}
public function getCurrentDealStagesUuids(AutomatedReport $report): array
{
$uuids = [];
$reportStages = $report->getCurrentDealStages();
foreach ($reportStages as $id) {
if ($stage = $this->stageRepository->find($id)) {
$uuids[] = $stage->getUuid();
}
}
return $uuids;
}
public function getUsersUuids(AutomatedReport $report): array
{
return $this->extractUserUuids($report->getRecipients());
}
public function getJiminnyUsersUuids(AutomatedReport $report): array
{
return $this->extractUserUuids($report->getJiminnyRecipients());
}
/**
* @param array<string, mixed> $recipients
*/
private function extractUserUuids(array $recipients): array
{
$userIds = $recipients['users'] ?? [];
return collect($userIds)
->map(fn ($id) => $this->userRepository->find((int) $id))
->filter()
->map(fn (UserContract $user) => $user->getUuid())
->values()
->all();
}
// get mail data
public function getRecipientUsers(AutomatedReport $report): array
{
return $this->buildRecipientUsers($report->getRecipients());
}
private function getJiminnyRecipientUsers(AutomatedReport $report): array
{
return $this->buildRecipientUsers($report->getJiminnyRecipients());
}
/**
* @param array<string, mixed> $recipients
*/
private function buildRecipientUsers(array $recipients): array
{
$userIds = $recipients['users'] ?? [];
return collect($userIds)
->map(fn ($id) => $this->userRepository->find((int) $id))
->filter()
->map(fn (UserContract $user) => [
'email' => $user->getEmailAddress(),
'name' => $user->getName(),
'timezone' => $user->getTimezone()->getName(),
])
->values()
->all();
}
public function getValidRecipientUsers(AutomatedReport $report, bool $includeJiminny = false): array
{
if ($report->isAskJiminnyReport()) {
$recipients = $this->resolveAskJiminnyRecipients($report);
} else {
$recipients = $this->getRecipientUsers($report);
if ($includeJiminny) {
$recipients = array_merge($recipients, $this->getJiminnyRecipientUsers($report));
}
}
$emails = [];
return array_values(array_filter(
$recipients,
static function ($recipient) use (&$emails) {
if (empty($recipient['email']) || in_array($recipient['email'], $emails, true)) {
return false;
}
$emails[] = $recipient['email'];
return true;
}
));
}
private function resolveAskJiminnyRecipients(AutomatedReport $report): array
{
$recipients = [];
$creator = $report->getCreator();
if ($creator !== null) {
$recipients[] = [
'email' => $creator->getEmailAddress(),
'name' => $creator->getName(),
'timezone' => $creator->getTimezone()->getName(),
];
}
return array_merge(
$recipients,
$this->buildRecipientUsers($report->getRecipients()),
$this->getGroupRecipientUsers($report),
);
}
private function getGroupRecipientUsers(AutomatedReport $report): array
{
$users = [];
foreach ($report->getGroups() as $groupId) {
$group = $this->groupRepository->find($groupId);
if ($group === null) {
continue;
}
foreach ($group->getMembers() as $member) {
$users[] = [
'email' => $member->getEmailAddress(),
'name' => $member->getName(),
'timezone' => $member->getTimezone()->getName(),
];
}
}
return $users;
}
public function getReportTypeName(AutomatedReportResult $report): string
{
$type = $report->getReport()->getType();
$getType = $this->transformReportType($type);
return $getType['name'];
}
public function getReportPeriodName(AutomatedReportResult $report): string
{
$from = $report->getFromDate();
$to = $report->getToDate();
$frequency = $report->getReport()->getFrequency();
if ($from === null || $to === null) {
if (! $report->getReport()->isAskJiminnyReport()) {
$invalidPeriod = $from === null ? 'from' : 'to';
throw new ApplicationException('Report period is invalid: ' . $invalidPeriod);
}
$period = $this->calculateFromAndToDatePeriod($frequency);
$from = $period['fromDate'];
$to = $period['toDate'];
}
return $this->formatReportPeriodName($frequency, $from, $to);
}
private function formatReportPeriodName(string $frequency, Carbon $from, Carbon $to): string
{
$fromYear = $from->format('Y');
$toYear = $to->format('Y');
$differentYears = $fromYear !== $toYear;
switch ($frequency) {
case self::FREQUENCY_DAILY:
return $from->format('j M Y');
case self::FREQUENCY_QUARTERLY:
// 'Jan-Mar 2025' or 'Nov 2024-Jan 2025' if years differ
$startMonth = $from->format('M');
$endMonth = $to->copy()->subMonth();
$endMonthName = $endMonth->format('M');
$endMonthYear = $endMonth->format('Y');
if ($differentYears) {
return "{$startMonth} {$fromYear} - {$endMonthName} {$endMonthYear}";
}
return "{$startMonth} - {$endMonthName} {$toYear}";
case self::FREQUENCY_MONTHLY:
// 'May 2025' - monthly reports are always within the same year
return $from->format('M Y');
case self::FREQUENCY_WEEKLY:
// '4 - 8 Aug 2025', '27 Oct - 3 Nov 2025', or '28 Dec 2024 - 3 Jan 2025' if years differ
$startDay = $from->format('j');
$endDay = $to->format('j');
$startMonth = $from->format('M');
$endMonth = $to->format('M');
if ($differentYears) {
return "{$startDay} {$startMonth} {$fromYear} - {$endDay} {$endMonth} {$toYear}";
}
if ($startMonth !== $endMonth) {
return "{$startDay} {$startMonth} - {$endDay} {$endMonth} {$toYear}";
}
return "{$startDay} - {$endDay} {$endMonth} {$toYear}";
case self::FREQUENCY_ONE_OFF:
// '2 May-31 May 2025' or '15 Dec 2024-15 Jan 2025' if years differ
$startDay = $from->format('j');
$startMonth = $from->format('M');
$endDay = $to->format('j');
$endMonth = $to->format('M');
// If same month and year, use a format like '2-31 May 2025'
if ($startMonth === $endMonth && ! $differentYears) {
return "{$startDay} - {$endDay} {$startMonth} {$toYear}";
}
// If different years, include both years
if ($differentYears) {
return "{$startDay} {$startMonth} {$fromYear} - {$endDay} {$endMonth} {$toYear}";
}
// Same year but different months
return "{$startDay} {$startMonth} - {$endDay} {$endMonth} {$toYear}";
default:
// Default format for unknown frequencies
return $from->format('j M Y') . ' - ' . $to->format('j M Y');
}
}
public function getReportTeamsName(AutomatedReportResult $report): string
{
$groups = $report->getGroups();
if (empty($groups)) {
return 'All';
}
// Get group names from repository
$groupNames = [];
foreach ($groups as $groupId) {
$group = $this->groupRepository->find($groupId);
if ($group) {
$groupNames[] = $group->getName();
}
}
if (count($groupNames) === 1) {
// Single team format
$teamsName = $groupNames[0];
} else {
// Multiple teams format
$teamsName = implode(', ', $groupNames);
}
return $teamsName;
}
public function getReportFileName(AutomatedReportResult $report): string
...
|
12308
|
|
12319
|
260
|
37
|
2026-04-14T11:04:30.419076+00:00
|
/Users/lukas/.screenpipe/data/data/2026-04-14/1776 /Users/lukas/.screenpipe/data/data/2026-04-14/1776164670419_m1.jpg...
|
PhpStorm
|
faVsco.js – AutomatedReportsService.php
|
1
|
NULL
|
monitor_1
|
NULL
|
NULL
|
NULL
|
NULL
|
Project: faVsco.js, menu
#11894 on JY-18909-automa Project: faVsco.js, menu
#11894 on JY-18909-automated-reports-ask-jiminny, menu
Start Listening for PHP Debug Connections
AutomatedReportsCommandTest
Run 'AutomatedReportsCommandTest'
Debug 'AutomatedReportsCommandTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Execute
Explain Plan
Browse Query History
View Parameters
Open Query Execution Settings…
In-Editor Results
Tx: Auto
Cancel Running Statements
Playground
jiminny
Sync Changes
Hide This Notification
Code changed:
Hide
16
13
13
Previous Highlighted Error
Next Highlighted Error
SELECT * FROM teams WHERE id = 1;
select * from crm_layouts where crm_configuration_id = 39;
SELECT * FROM crm_layout_entities WHERE crm_layout_id = 283;
SELECT * FROM crm_fields WHERE id = 2234;
SELECT * FROM crm_field_values WHERE crm_field_id = 2234;
select * from crm_profiles where user_id = 143;
select * from record_types where crm_configuration_id = 39; # 0121K000001MHElQAO,0121K000001MHEqQAO
select * from business_processes where crm_configuration_id = 39;
# 01941000000H669AAC, 01941000000H66JAAS
select * from record_type_field_values
where record_type_id IN (24);
select * from crm_field_values where id IN (2730);
select * from crm_configurations where id = 39;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 1
and sa.provider = 'salesforce'; #1035
select * from users where team_id = 1; # 222 group 3
SELECT * FROM activities WHERE user_id = 222 order by id desc;
select * from sidekick_settings where team_id = 1;
select * from teams where id = 1;
select * from team_features where team_id = 1;
select * from activities where crm_configuration_id = 2
and provider = 'ms-teams' and id = 608765;
SELECT * FROM activities WHERE crm_configuration_id = 2 and crm_provider_id = '59523413338';
select * from sidekick_settings where team_id = 2;
SELECT * FROM activities WHERE id = 608660;
select * from activity_summary_logs where activity_id = 608660;
select * from ai_prompts where transcription_id = 11214;
# [PASSWORD_DOTS]
SELECT * FROM activities WHERE uuid_to_bin('ed78a437-2804-450e-ab2f-56ab1c641346') = uuid;
# id: 608818, crm: 59628809737
SELECT * FROM activities WHERE uuid_to_bin('36b06e55-afdd-4782-8dee-c624cd0af191') = uuid;
# id: 608821, crm: 59632069252
SELECT ce.start_time, ce.end_time, a.id, a.uuid, crm_provider_id, calendar_event_id, title,
playbook_category_id, user_id, lead_id, contact_id, account_id, opportunity_id,
scheduled_start_time, scheduled_end_time, actual_start_time, actual_end_time, a.created_at
FROM activities a
join calendar_events ce on a.calendar_event_id = ce.id
WHERE a.id IN (608818, 608821);
select * from users where team_id = 1;
select * from team_settings where team_id = 1;
select * from crm_profiles where crm_configuration_id = 39 order by user_id;
select * from team_features where team_id = 1;
select * from users where team_id = 2;
SELECT * FROM activities WHERE uuid_to_bin('ec7647e9-5225-458b-b475-f31aa2769204') = uuid; # 612639
# Preslava N. Ivanova, grou id 3
SELECT * FROM opportunities WHERE uuid_to_bin('a2928fe5-aec5-46cb-85d9-7654c89e46a6') = uuid;
select * from activities where opportunity_id = 344 and actual_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00';
select
a.id,
a.type,
a.scheduled_start_time,
a.actual_start_time,
a.created_at,
a.opportunity_id,
a.status
FROM activities a
WHERE opportunity_id = 344
and status IN ('completed', 'received', 'delivered')
and (
(a.actual_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00')
OR (a.created_at between '2024-10-11 00:00:00' and '2024-10-12 00:00:00')
OR (a.scheduled_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00'))
;
SELECT * FROM users WHERE id = 222;
SELECT * FROM crm_profiles WHERE user_id = 222;
select * from crm_layouts where crm_configuration_id = 39;
SELECT * FROM crm_layout_entities WHERE crm_layout_id = 281;
select * from group_deal_risk_types;
select * from opportunities where team_id = 1;
SELECT * FROM opportunities WHERE id = 315;
SELECT * FROM crm_field_data WHERE object_id = 315;
select * from crm_field_data where object_id = 260;
select * from generic_ai_prompts where subject_id = 315;
select * from teams; # 36, 21, 121, [EMAIL]
SELECT * FROM social_accounts WHERE sociable_id = 121 and provider = 'bullhorn';
# [PASSWORD_DOTS]
select * from teams where id = 1;
select * from crm_configurations where id = 39;
select * from users where team_id = 1;
select u.email, cp.* from users u
join crm_profiles cp on u.id = cp.user_id
where u.team_id = 1;
# 1 - 00541000004281rAAA
# 204 - 0052g000003freeAAA
# 429 - 0052g000003qGOiAAM
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 1
and sa.provider = 'salesforce';
select * from activities where type = 'softphone'
and created_at > '2024-12-11 15:24:36' order by id desc;
select * from activity_providers where team_id = 1;
select * from activity_provider_users where activity_provider_id = 328;
select * from opportunities where crm_configuration_id = 39
AND account_id = 178 AND is_closed = false
order by created_at DESC;
select * from contacts where id = 3952;
select * from accounts where id = 178;
# [PASSWORD_DOTS]
select * from teams where id = 36;
select * from crm_configurations where id = 21;
select * from users where team_id = 36;
select u.email, cp.* from users u
join crm_profiles cp on u.id = cp.user_id
where u.team_id = 36;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 36
and sa.provider = 'bullhorn';
select * from social_accounts where id = 348;
UPDATE social_accounts SET
provider_user_token = '21442_6802599_91:41179a58-21e7-4d7c-ad58-56bb666b2f65',
provider_refresh_token = '21442_6802599_91:01c6b335-3f2a-42e4-85ff-8a08fa65fceb',
expires = 1733998131,
state = 'connected'
WHERE id = 348;
# [PASSWORD_DOTS]
select * from teams where id = 31;
select * from crm_configurations where id = 18;
select * from users where team_id = 31; # 257
select u.email, cp.* from users u
join crm_profiles cp on u.id = cp.user_id
where u.team_id = 31;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 31
and sa.provider = 'close';
select * from contacts where crm_configuration_id = 18;
# [PASSWORD_DOTS] NEPTUNE [PASSWORD_DOTS]
select * from teams;
select * from users where id IN (1030, 1035, 1052);
select * from crm_configurations;
select * from users where team_id = 65; # 257
select * from team_settings where team_id = 65; # 257
select * from invitations where team_id = 65; # 257
select * from users where email = '[EMAIL]'; # 257
select u.email, cp.* from users u
join crm_profiles cp on u.id = cp.user_id
where u.team_id = 65;
select * from crm_configurations where id = 53;
select * from accounts where crm_configuration_id = 53 order by id desc;
select * from leads where crm_configuration_id = 53 order by id desc;
select * from contacts where crm_configuration_id = 53 order by id desc;
select * from opportunities where crm_configuration_id = 53 order by id desc;
select * from crm_profiles where crm_configuration_id = 53 order by id desc;
select * from crm_fields where crm_configuration_id = 53 order by id desc;
select * from crm_field_values where crm_field_id = 3341 order by id desc;
select * from crm_layouts where crm_configuration_id = 53 order by id desc;
select * from stages where crm_configuration_id = 53 order by id desc;
select * from crm_profiles where crm_configuration_id = 13;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 65
and sa.provider = 'integration-app';
select * from contacts where crm_configuration_id = 13;
select * from social_accounts where sociable_id = 283;
SELECT * FROM opportunities WHERE crm_provider_id = '006O400000E9bzeIAB';
select * from activity_providers where team_id = 65;
SELECT * FROM activities WHERE crm_configuration_id IN (51, 52, 53);
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 65
;
# [PASSWORD_DOTS] STAGING [PASSWORD_DOTS]
SELECT * FROM teams;
SELECT * FROM teams WHERE id = 88;
SELECT * FROM teams WHERE id = 89;
select * from team_settings where team_id = 89;
SELECT * FROM users WHERE team_id = 89;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 89;
select * from users;
SELECT * FROM social_accounts WHERE sociable_id = 1761;
SELECT * FROM crm_configurations WHERE id = 70;
select * from accounts where crm_configuration_id = 70 order by id desc;
select * from leads where crm_configuration_id = 70 order by id desc;
select * from contacts where crm_configuration_id = 70 order by id desc;
select * from opportunities where crm_configuration_id = 70 order by id desc;
select * from crm_profiles where crm_configuration_id = 70 order by id desc;
select * from crm_fields where crm_configuration_id = 70 order by id desc;
select * from crm_field_values where crm_field_id = 3536 order by id desc;
select * from crm_layouts where crm_configuration_id = 70 order by id desc;
select * from stages where crm_configuration_id = 70 order by id desc;
select * from business_processes where crm_configuration_id = 70 order by id desc;
select * from business_process_stages where business_process_id = 34;
select * from contacts where id = 10468;
select * from crm_layouts where crm_configuration_id = 70;
SELECT * FROM crm_layout_entities WHERE crm_layout_id = 388;
SELECT * FROM crm_fields WHERE id IN (3533,3534,3535);
select * from activities where crm_configuration_id = 70
and (account_id IS NOT NULL or lead_id IS NOT NULL or contact_id IS NOT NULL or opportunity_id IS NOT NULL) order by id desc;
SELECT * FROM activities WHERE uuid_to_bin('2e10b60f-8a61-41c5-a3d4-28835353dc65') = uuid;
SELECT * FROM activities where crm_configuration_id = 69 ;
SELECT * FROM users WHERE email LIKE '%[EMAIL]%';
SELECT * FROM activities WHERE uuid_to_bin('5a150c93-40fc-42ec-b3bd-c1d328e09f6e') = uuid;
SELECT * FROM opportunities WHERE id = 385;
select * from participants p
join activities a on p.activity_id = a.id
where a.crm_configuration_id = 70
and (p.lead_id IS NOT NULL or p.contact_id IS NOT NULL);
SELECT * FROM participants WHERE id = 1013638;
select * from teams where id = 90;
select * from users where team_id = 90;
select * from social_accounts where social_accounts.sociable_id IN (1960,1760);
SELECT * FROM crm_profiles WHERE crm_configuration_id = 71;
select * from invitations where team_id = 90;
select * from crm_configurations where id = 71;
select * from accounts where crm_configuration_id = 71 order by id desc;
select * from leads where crm_configuration_id = 71 order by id desc;
select * from contacts where crm_configuration_id = 71 order by id desc;
select * from opportunities where crm_configuration_id = 71 order by id desc;
select * from crm_profiles where crm_configuration_id = 71 order by id desc;
select * from crm_fields where crm_configuration_id = 71 order by id desc;
select * from crm_field_values where crm_field_id = 3341 order by id desc;
select * from crm_layouts where crm_configuration_id = 71 order by id desc;
select * from stages where crm_configuration_id = 71 order by id desc;
select * from users order by secondary_email desc;
select u.id, u.email, u.status, sa.id, sa.provider_user_id from social_accounts sa
join users u on sa.sociable_id = u.id
where sa.provider = 'google' and u.email LIKE 'aneliya%';
select * from failed_jobs order by id desc;
select * from users where email = '[EMAIL]' or secondary_email = '[EMAIL]';
select * from teams;
SELECT * FROM crm_profiles WHERE crm_configuration_id = 39;
SELECT * FROM crm_fields WHERE crm_configuration_id = 39 and object_type = 'task';
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 1
and sa.provider = 'salesforce';
# [PASSWORD_DOTS]
SELECT * FROM activities WHERE uuid_to_bin('c38b3895-fd0f-4b1f-9fb2-c170dba137c6') = uuid;
SELECT * FROM crm_configurations WHERE id = 70;
select * from teams where id = 1;
select * from groups where team_id = 1;
select * from users where team_id = 1;
select o.id, o.name,o.close_date, u.id, u.name, u.group_id, r.id, r.display_name, g.name, g.scope from opportunities o
join users u on o.user_id = u.id
join groups g on u.group_id = g.id
join role_user ru on u.id = ru.user_id
join roles r on ru.role_id = r.id
where o.crm_configuration_id = 39 and close_date > '2024-01-01 00:00:00';
select * from role_user where user_id = 143;
select * from roles;
select * from role_user;
select * from groups where id = 9;
select * from scope_groups where group_id = 9;
# [PASSWORD_DOTS]
select * from teams where id = 36;
select * from crm_configurations;
SELECT * FROM social_accounts WHERE sociable_id = 121;
[URL_WITH_CREDENTIALS] this will add filter, however if we need to control feature by FF we need conditional logic
public const array TYPES = [
['id' => 'exec_summary', 'name' => 'Exec Summary'],
['id' => 'coaching_profiles', 'name' => 'Coaching Profiles'],
['id' => 'product_feedback', 'name' => 'Product Feedback'],
['id' => self::TYPE_LOSS_ANALYSIS, 'name' => 'Loss Analysis'],
// ['id' => 'questions', 'name' => 'Questions'],
// ['id' => 'statistical_quant', 'name' => 'Statistical Quantitative'],
];
public const array ALL_TYPES = [
...self::TYPES,
['id' => self::TYPE_ASK_JIMINNY, 'name' => 'Ask Jiminny'],
];
public const string FREQUENCY_DAILY = 'daily';
public const string FREQUENCY_WEEKLY = 'weekly';
public const string FREQUENCY_MONTHLY = 'monthly';
public const string FREQUENCY_QUARTERLY = 'quarterly';
public const string FREQUENCY_ONE_OFF = 'one_off';
/**
* Frequencies for standard (non-Ask Jiminny) reports.
*/
public const array FREQUENCIES = [
['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],
['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],
['id' => self::FREQUENCY_QUARTERLY, 'name' => 'Quarterly'],
['id' => self::FREQUENCY_ONE_OFF, 'name' => 'One-off'],
];
/**
* Frequencies for Ask Jiminny reports.
*/
public const array ASK_JIMINNY_FREQUENCIES = [
['id' => self::FREQUENCY_DAILY, 'name' => 'Daily'],
['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],
['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],
];
public const string MEDIA_TYPE_PDF = 'pdf';
public const string MEDIA_TYPE_PODCAST = 'podcast';
public const array MEDIA_TYPES = [self::MEDIA_TYPE_PDF, self::MEDIA_TYPE_PODCAST];
public const array MEDIA_TYPE_OBJECT_PDF = ['id' => self::MEDIA_TYPE_PDF, 'name' => 'PDF'];
public const array MEDIA_TYPE_OBJECT_PODCAST = ['id' => self::MEDIA_TYPE_PODCAST, 'name' => 'Podcast'];
public const array MEDIA_TYPE_OBJECTS = [self::MEDIA_TYPE_OBJECT_PDF, self::MEDIA_TYPE_OBJECT_PODCAST];
public const array CALL_TYPE_CONFERENCE = ['id' => 'conference', 'name' => 'Conference'];
public const array CALL_TYPE_DIALER = ['id' => 'dialer', 'name' => 'Dialer'];
public const int SENT_REPORT_AT_HOURS = 5;
public const string PDF_KEY = 'pdf';
public const string AUDIO_KEY = 'audio';
private const array ALL_FREQUENCIES = [
['id' => self::FREQUENCY_DAILY, 'name' => 'Daily'],
['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],
['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],
['id' => self::FREQUENCY_QUARTERLY, 'name' => 'Quarterly'],
['id' => self::FREQUENCY_ONE_OFF, 'name' => 'One-off'],
];
private const string S3_DIR = 'reports';
private const array FILE_EXTENSIONS_VARIANTS = ['html', 'MD', 'pdf'];
private const array FILE_PODCAST_EXTENSIONS_VARIANTS = ['json', 'mp3', 'ssml'];
public function __construct(
private readonly TeamRepository $teamRepository,
private readonly GroupRepository $groupRepository,
private readonly UserRepository $userRepository,
private readonly StageRepository $stageRepository,
private readonly DealStagesService $dealStagesService,
private readonly RecipientsService $recipientsService,
private readonly AutomatedReportsRepository $automatedReportsRepository,
private readonly Webhook $webhookService,
private readonly BusDispatcher $dispatcher,
private readonly ActivityTypeService $activityTypeService,
private readonly PlaybookCategoryRepository $playbookCategoryRepository,
private readonly AskAnythingPromptService $askAnythingPromptService,
private readonly SearchRepository $activitySearchRepository,
private readonly AskAnythingRepository $askAnythingRepository,
) {
}
public static function getTypes(): array
{
$types = self::TYPES;
return array_map(static function ($type) {
return $type['id'];
}, $types);
}
public static function getCallTypes(): array
{
return array_map(static function ($callType) {
return $callType['id'];
}, [self::CALL_TYPE_CONFERENCE, self::CALL_TYPE_DIALER]);
}
public static function getFrequencies(): array
{
return array_map(static function ($frequency) {
return $frequency['id'];
}, self::FREQUENCIES);
}
// front-facing structure
public function getReportEnabledFieldData(bool $value = false): array
{
return [
'id' => 'report_enabled',
'label' => '',
'inputType' => InputTypeEnum::TOGGLE,
'value' => $value,
];
}
// Organizations = Teams
public function getOrganizationFieldData(?string $value = null, bool $shortVersion = false): array
{
$options = $this->getTeams();
if ($shortVersion) {
return [
'id' => 'organization',
'label' => 'Organization',
'options' => $options,
];
}
return [
'id' => 'organization',
'label' => 'Organization',
'inputType' => InputTypeEnum::DROPDOWN,
'required' => true,
'placeholder' => 'Select',
'options' => $options,
'value' => $value,
'dependencies' => [
'teams',
'deal_stage_at_call',
'current_deal_stage',
'recipients',
ActivityTypeService::PLAYBOOK_CATEGORIES_KEY,
],
'dependsOn' => [],
];
}
// Teams = Groups
public function getTeamFieldData(array $options = [], array $value = [], bool $shortVersion = false): array
{
if ($shortVersion) {
return [
'id' => 'teams',
'label' => 'Team',
'options' => $options,
];
}
return [
'id' => 'teams',
'label' => 'Team',
'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,
'required' => false,
'placeholder' => 'Select',
'options' => $options,
'value' => $value, // value should be an array of objects {id, name}
'dependencies' => [ActivityTypeService::PLAYBOOK_CATEGORIES_KEY],
'dependsOn' => [],
];
}
public function getReportTypeFieldData(?string $value = null, bool $shortVersion = false, ?Team $team = null): array
{
$types = [];
if ($team instanceof Team) {
if ($team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {
$types = self::TYPES;
}
if ($team->hasFeature(FeatureEnum::ASK_JIMINNY_REPORTS)) {
$types[] = ['id' => self::TYPE_ASK_JIMINNY, 'name' => 'Ask Jiminny'];
}
} else {
$types = self::TYPES;
}
if ($shortVersion) {
return [
'id' => 'report_type',
'label' => 'Report Type',
'options' => $types,
];
}
return [
'id' => 'report_type',
'label' => 'Report Type',
'inputType' => InputTypeEnum::DROPDOWN,
'required' => true,
'placeholder' => 'Select',
'options' => $types,
'value' => $value,
'dependencies' => [],
'dependsOn' => [],
];
}
public function getFrequencyFieldData(?string $value = null): array
{
return [
'id' => 'frequency',
'label' => 'Frequency',
'inputType' => InputTypeEnum::DROPDOWN,
'required' => true,
'placeholder' => 'Select',
'options' => self::FREQUENCIES,
'value' => $value,
'dependencies' => ['period'],
'dependsOn' => [],
];
}
public function getPeriodFieldData(?string $valueStartDate = null, ?string $valueEndDate = null): array
{
return [
'id' => 'period',
'label' => 'Select one-off period',
'inputType' => InputTypeEnum::DATE_RANGE,
'required' => true,
'placeholder' => 'Select',
'value' => ['startDate' => $valueStartDate, 'endDate' => $valueEndDate],
'queryParams' => [
'startDate' => 'start_date_period',
'endDate' => 'end_date_period',
],
'dependencies' => [],
'dependsOn' => ['frequency'],
];
}
public function getActivityTypesFieldData(?Team $team = null, array $value = [], array $teamsFilter = []): array
{
return $this->activityTypeService->getActivityTypeFieldData(team: $team, value: $value, groupIds: $teamsFilter);
}
public function getDealStageAtCallFieldData(?Team $team = null, array $value = []): array
{
return $this->dealStagesService->getDealStageAtCallFieldData(team: $team, value: $value);
}
public function getCurrentDealStageFieldData(?Team $team = null, array $value = []): array
{
return $this->dealStagesService->getCurrentDealStageFieldData(team: $team, value: $value);
}
public function getDealValueFieldData(?int $valueMin = null, ?int $valueMax = null): array
{
return [
'id' => 'deal_value',
'label' => 'Deal Value',
'inputType' => InputTypeEnum::INTEGER_RANGE,
'required' => false,
'value' => ['min' => $valueMin, 'max' => $valueMax],
'queryParams' => [
'min' => 'min_deal_value',
'max' => 'max_deal_value',
],
'dependencies' => [],
'dependsOn' => [],
];
}
public function getCallTypeFieldData(bool $conferenceOn = false, bool $dialerOn = false): array
{
$value = [];
$conferenceOn && $value[] = self::CALL_TYPE_CONFERENCE;
$dialerOn && $value[] = self::CALL_TYPE_DIALER;
return [
'id' => 'call_type',
'label' => 'Call Type',
'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,
'required' => true,
'options' => [
self::CALL_TYPE_CONFERENCE,
self::CALL_TYPE_DIALER,
],
'value' => $value,
'dependencies' => [],
'dependsOn' => [],
];
}
public function getMediaTypeFieldData(?AutomatedReport $report = null): array
{
$value = [];
if ($report) {
$value = $this->transformMediaTypes($report);
}
return [
'id' => 'media_types',
'label' => 'Export as',
'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,
'required' => true,
'options' => self::MEDIA_TYPE_OBJECTS,
'value' => $value,
'dependencies' => [],
'dependsOn' => [],
];
}
public function getCallDurationFieldData(?int $valueMin = null, ?int $valueMax = null): array
{
return [
'id' => 'call_duration',
'label' => 'Call Duration',
'inputType' => InputTypeEnum::INTEGER_RANGE,
'required' => false,
'value' => ['min' => $valueMin, 'max' => $valueMax],
'queryParams' => [
'min' => 'min_call_duration',
'max' => 'max_call_duration',
],
'dependencies' => [],
'dependsOn' => [],
];
}
public function getRecipientsFieldData(?Team $team = null, array $value = []): array
{
return $this->recipientsService->getRecipientsFieldData(team: $team, value: $value);
}
public function getJiminnyRecipientsFieldData(array $value = []): array
{
return $this->recipientsService->getJiminnyRecipientsFieldData($value);
}
public function getAdditionalPromptInputFieldData(?string $value = null): array
{
return [
'id' => 'additional_prompt_input',
'label' => 'Special requirements',
'inputType' => InputTypeEnum::TEXTAREA,
'required' => false,
'placeholder' => 'What should be the focus of the report?',
'value' => $value,
'dependencies' => [],
'dependsOn' => [],
];
}
public function getCustomReportNameFieldData(?string $value = null): array
{
return [
'id' => 'custom_name',
'label' => 'Custom report name',
'inputType' => InputTypeEnum::TEXT,
'required' => false,
'placeholder' => 'Enter custom name',
'value' => $value,
'dependencies' => [],
'dependsOn' => [],
];
}
// data providers
public function getTeams(): array
{
$teams = $this->teamRepository->getTeamsForKiosk(status: Team::STATUS_ACTIVE);
$teamData = [];
foreach ($teams as $team) {
if (! $team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {
continue;
}
$teamData[] = $this->transformTeam($team);
}
return $teamData;
}
public function getTeamGroups(string $teamUuid): array
{
$data = [];
$team = $this->getTeam($teamUuid);
if ($team !== null) {
$groups = $team->groups()->get();
foreach ($groups as $group) {
$data[] = [
'id' => $group->getUuid(),
'name' => $group->getName(),
];
}
}
return $data;
}
public function getTeamsGroupsOptions(array $filterTeamUuids = []): array
{
$data = [];
$teams = $this->getTeams();
foreach ($teams as $team) {
if (! empty($filterTeamUuids) && ! in_array($team['id'], $filterTeamUuids, true)) {
continue;
}
$data[] = [
'label' => $team['name'],
'groups' => $this->getTeamGroups($team['id']),
];
}
return $data;
}
public function getTeam(string $teamUuid): ?Team
{
return $this->teamRepository->idOrUuid($teamUuid);
}
public function getTeamById(int $teamId): ?Team
{
return $this->teamRepository->find($teamId);
}
public function getGroupsUuids(AutomatedReport $report): array
{
$uuids = [];
$reportGroups = $report->getGroups();
foreach ($reportGroups as $groupId) {
if ($group = $this->groupRepository->find($groupId)) {
$uuids[] = $group->getUuid();
}
}
return $uuids;
}
public function getPlaybookCategoriesUuids(AutomatedReport $report): array
{
$uuids = [];
$playbookCategories = $report->getPlaybookCategories();
foreach ($playbookCategories as $id) {
if ($category = $this->playbookCategoryRepository->find($id)) {
$uuids[] = $category->getUuid();
}
}
return $uuids;
}
public function getDealAtCallStagesUuids(AutomatedReport $report): array
{
$uuids = [];
$reportStages = $report->getDealAtCallStages();
foreach ($reportStages as $id) {
if ($stage = $this->stageRepository->find($id)) {
$uuids[] = $stage->getUuid();
}
}
return $uuids;
}
public function getCurrentDealStagesUuids(AutomatedReport $report): array
{
$uuids = [];
$reportStages = $report->getCurrentDealStages();
foreach ($reportStages as $id) {
if ($stage = $this->stageRepository->find($id)) {
$uuids[] = $stage->getUuid();
}
}
return $uuids;
}
public function getUsersUuids(AutomatedReport $report): array
{
return $this->extractUserUuids($report->getRecipients());
}
public function getJiminnyUsersUuids(AutomatedReport $report): array
{
return $this->extractUserUuids($report->getJiminnyRecipients());
}
/**
* @param array<string, mixed> $recipients
*/
private function extractUserUuids(array $recipients): array
{
$userIds = $recipients['users'] ?? [];
return collect($userIds)
->map(fn ($id) => $this->userRepository->find((int) $id))
->filter()
->map(fn (UserContract $user) => $user->getUuid())
->values()
->all();
}
// get mail data
public function getRecipientUsers(AutomatedReport $report): array
{
return $this->buildRecipientUsers($report->getRecipients());
}
private function getJiminnyRecipientUsers(AutomatedReport $report): array
{
return $this->buildRecipientUsers($report->getJiminnyRecipients());
}
/**
* @param array<string, mixed> $recipients
*/
private function buildRecipientUsers(array $recipients): array
{
$userIds = $recipients['users'] ?? [];
return collect($userIds)
->map(fn ($id) => $this->userRepository->find((int) $id))
->filter()
->map(fn (UserContract $user) => [
'email' => $user->getEmailAddress(),
'name' => $user->getName(),
'timezone' => $user->getTimezone()->getName(),
])
->values()
->all();
}
public function getValidRecipientUsers(AutomatedReport $report, bool $includeJiminny = false): array
{
if ($report->isAskJiminnyReport()) {
$recipients = $this->resolveAskJiminnyRecipients($report);
} else {
$recipients = $this->getRecipientUsers($report);
if ($includeJiminny) {
$recipients = array_merge($recipients, $this->getJiminnyRecipientUsers($report));
}
}
$emails = [];
return array_values(array_filter(
$recipients,
static function ($recipient) use (&$emails) {
if (empty($recipient['email']) || in_array($recipient['email'], $emails, true)) {
return false;
}
$emails[] = $recipient['email'];
return true;
}
));
}
private function resolveAskJiminnyRecipients(AutomatedReport $report): array
{
$recipients = [];
$creator = $report->getCreator();
if ($creator !== null) {
$recipients[] = [
'email' => $creator->getEmailAddress(),
'name' => $creator->getName(),
'timezone' => $creator->getTimezone()->getName(),
];
}
return array_merge(
$recipients,
$this->buildRecipientUsers($report->getRecipients()),
$this->getGroupRecipientUsers($report),
);
}
private function getGroupRecipientUsers(AutomatedReport $report): array
{
$users = [];
foreach ($report->getGroups() as $groupId) {
$group = $this->groupRepository->find($groupId);
if ($group === null) {
continue;
}
foreach ($group->getMembers() as $member) {
$users[] = [
'email' => $member->getEmailAddress(),
'name' => $member->getName(),
'timezone' => $member->getTimezone()->getName(),
];
}
}
return $users;
}
public function getReportTypeName(AutomatedReportResult $report): string
{
$type = $report->getReport()->getType();
$getType = $this->transformReportType($type);
return $getType['name'];
}
public function getReportPeriodName(AutomatedReportResult $report): string
{
$from = $report->getFromDate();
$to = $report->getToDate();
$frequency = $report->getReport()->getFrequency();
if ($from === null || $to === null) {
if (! $report->getReport()->isAskJiminnyReport()) {
$invalidPeriod = $from === null ? 'from' : 'to';
throw new ApplicationException('Report period is invalid: ' . $invalidPeriod);
}
$period = $this->calculateFromAndToDatePeriod($frequency);
$from = $period['fromDate'];
$to = $period['toDate'];
}
return $this->formatReportPeriodName($frequency, $from, $to);
}
private function formatReportPeriodName(string $frequency, Carbon $from, Carbon $to): string
{
$fromYear = $from->format('Y');
$toYear = $to->format('Y');
$differentYears = $fromYear !== $toYear;
switch ($frequency) {
case self::FREQUENCY_DAILY:
return $from->format('j M Y');
case self::FREQUENCY_QUARTERLY:
// 'Jan-Mar 2025' or 'Nov 2024-Jan 2025' if years differ
$startMonth = $from->format('M');
$endMonth = $to->copy()->subMonth();
$endMonthName = $endMonth->format('M');
$endMonthYear = $endMonth->format('Y');
if ($differentYears) {
return "{$startMonth} {$fromYear} - {$endMonthName} {$endMonthYear}";
}
return "{$startMonth} - {$endMonthName} {$toYear}";
case self::FREQUENCY_MONTHLY:
// 'May 2025' - monthly reports are always within the same year
return $from->format('M Y');
case self::FREQUENCY_WEEKLY:
// '4 - 8 Aug 2025', '27 Oct - 3 Nov 2025', or '28 Dec 2024 - 3 Jan 2025' if years differ
$startDay = $from->format('j');
$endDay = $to->format('j');
$startMonth = $from->format('M');
$endMonth = $to->format('M');
if ($differentYears) {
return "{$startDay} {$startMonth} {$fromYear} - {$endDay} {$endMonth} {$toYear}";
}
if ($startMonth !== $endMonth) {
return "{$startDay} {$startMonth} - {$endDay} {$endMonth} {$toYear}";
}
return "{$startDay} - {$endDay} {$endMonth} {$toYear}";
case self::FREQUENCY_ONE_OFF:
// '2 May-31 May 2025' or '15 Dec 2024-15 Jan 2025' if years differ
$startDay = $from->format('j');
$startMonth = $from->format('M');
$endDay = $to->format('j');
$endMonth = $to->format('M');
// If same month and year, use a format like '2-31 May 2025'
if ($startMonth === $endMonth && ! $differentYears) {
return "{$startDay} - {$endDay} {$startMonth} {$toYear}";
}
// If different years, include both years
if ($differentYears) {
return "{$startDay} {$startMonth} {$fromYear} - {$endDay} {$endMonth} {$toYear}";
}
// Same year but different months
return "{$startDay} {$startMonth} - {$endDay} {$endMonth} {$toYear}";
default:
// Default format for unknown frequencies
return $from->format('j M Y') . ' - ' . $to->format('j M Y');
}
}
public function getReportTeamsName(AutomatedReportResult $report): string
{
$groups = $report->getGroups();
if (empty($groups)) {
return 'All';
}
// Get group names from repository
$groupNames = [];
foreach ($groups as $groupId) {
$group = $this->groupRepository->find($groupId);
if ($group) {
$groupNames[] = $group->getName();
}
}
if (count($groupNames) === 1) {
// Single team format
$teamsName = $groupNames[0];
} else {
// Multiple teams format
$teamsName = implode(', ', $groupNames);
}
return $teamsName;
}
public function getReportFileName(AutomatedReportResult $report): string
...
|
[{"role":"AXButton","text" [{"role":"AXButton","text":"Project: faVsco.js, menu","depth":5,"help_text":"~/jiminny/app","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"#11894 on JY-18909-automated-reports-ask-jiminny, menu","depth":5,"help_text":"Pull request #11894 exists for current branch JY-18909-automated-reports-ask-jiminny","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Start Listening for PHP Debug Connections","depth":5,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"AutomatedReportsCommandTest","depth":6,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Run 'AutomatedReportsCommandTest'","depth":6,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Debug 'AutomatedReportsCommandTest'","depth":6,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"More Actions","depth":6,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JetBrains AI","depth":5,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Search Everywhere","depth":5,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"IDE and Project Settings","depth":5,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Execute","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Explain Plan","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Browse Query History","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"View Parameters","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Open Query Execution Settings…","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"In-Editor Results","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Tx: Auto","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Cancel Running Statements","depth":4,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Playground","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"jiminny","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.088194445,"height":0.027777778},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"16","depth":4,"role_description":"text"},{"role":"AXStaticText","text":"13","depth":4,"role_description":"text"},{"role":"AXStaticText","text":"13","depth":4,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"SELECT * FROM teams WHERE id = 1;\n\nselect * from crm_layouts where crm_configuration_id = 39;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 283;\nSELECT * FROM crm_fields WHERE id = 2234;\nSELECT * FROM crm_field_values WHERE crm_field_id = 2234;\n\nselect * from crm_profiles where user_id = 143;\n\nselect * from record_types where crm_configuration_id = 39; # 0121K000001MHElQAO,0121K000001MHEqQAO\nselect * from business_processes where crm_configuration_id = 39;\n# 01941000000H669AAC, 01941000000H66JAAS\n\nselect * from record_type_field_values\n where record_type_id IN (24);\n\nselect * from crm_field_values where id IN (2730);\n\nselect * from crm_configurations where id = 39;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 1\nand sa.provider = 'salesforce'; #1035\n\n\nselect * from users where team_id = 1; # 222 group 3\nSELECT * FROM activities WHERE user_id = 222 order by id desc;\nselect * from sidekick_settings where team_id = 1;\nselect * from teams where id = 1;\nselect * from team_features where team_id = 1;\n\nselect * from activities where crm_configuration_id = 2\nand provider = 'ms-teams' and id = 608765;\n\nSELECT * FROM activities WHERE crm_configuration_id = 2 and crm_provider_id = '59523413338';\n\nselect * from sidekick_settings where team_id = 2;\n\nSELECT * FROM activities WHERE id = 608660;\nselect * from activity_summary_logs where activity_id = 608660;\nselect * from ai_prompts where transcription_id = 11214;\n\n# ********************************************************************************************************\nSELECT * FROM activities WHERE uuid_to_bin('ed78a437-2804-450e-ab2f-56ab1c641346') = uuid;\n# id: 608818, crm: 59628809737\nSELECT * FROM activities WHERE uuid_to_bin('36b06e55-afdd-4782-8dee-c624cd0af191') = uuid;\n# id: 608821, crm: 59632069252\nSELECT ce.start_time, ce.end_time, a.id, a.uuid, crm_provider_id, calendar_event_id, title,\nplaybook_category_id, user_id, lead_id, contact_id, account_id, opportunity_id,\nscheduled_start_time, scheduled_end_time, actual_start_time, actual_end_time, a.created_at\nFROM activities a\njoin calendar_events ce on a.calendar_event_id = ce.id\nWHERE a.id IN (608818, 608821);\n\nselect * from users where team_id = 1;\nselect * from team_settings where team_id = 1;\nselect * from crm_profiles where crm_configuration_id = 39 order by user_id;\n\nselect * from team_features where team_id = 1;\n\nselect * from users where team_id = 2;\n\nSELECT * FROM activities WHERE uuid_to_bin('ec7647e9-5225-458b-b475-f31aa2769204') = uuid; # 612639\n# Preslava N. Ivanova, grou id 3\n\nSELECT * FROM opportunities WHERE uuid_to_bin('a2928fe5-aec5-46cb-85d9-7654c89e46a6') = uuid;\n\nselect * from activities where opportunity_id = 344 and actual_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00';\n\nselect\n a.id,\n a.type,\n a.scheduled_start_time,\n a.actual_start_time,\n a.created_at,\n a.opportunity_id,\n a.status\nFROM activities a\nWHERE opportunity_id = 344\nand status IN ('completed', 'received', 'delivered')\nand (\n (a.actual_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00')\nOR (a.created_at between '2024-10-11 00:00:00' and '2024-10-12 00:00:00')\nOR (a.scheduled_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00'))\n;\n\nSELECT * FROM users WHERE id = 222;\n\nSELECT * FROM crm_profiles WHERE user_id = 222;\nselect * from crm_layouts where crm_configuration_id = 39;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 281;\n\nselect * from group_deal_risk_types;\n\nselect * from opportunities where team_id = 1;\n\nSELECT * FROM opportunities WHERE id = 315;\nSELECT * FROM crm_field_data WHERE object_id = 315;\nselect * from crm_field_data where object_id = 260;\n\nselect * from generic_ai_prompts where subject_id = 315;\n\nselect * from teams; # 36, 21, 121, james.graham@bullhorn.jiminny.com\nSELECT * FROM social_accounts WHERE sociable_id = 121 and provider = 'bullhorn';\n\n# ************************************************************************************\nselect * from teams where id = 1;\nselect * from crm_configurations where id = 39;\nselect * from users where team_id = 1;\nselect u.email, cp.* from users u\njoin crm_profiles cp on u.id = cp.user_id\nwhere u.team_id = 1;\n# 1 - 00541000004281rAAA\n# 204 - 0052g000003freeAAA\n# 429 - 0052g000003qGOiAAM\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 1\nand sa.provider = 'salesforce';\n\nselect * from activities where type = 'softphone'\nand created_at > '2024-12-11 15:24:36' order by id desc;\n\nselect * from activity_providers where team_id = 1;\nselect * from activity_provider_users where activity_provider_id = 328;\n\nselect * from opportunities where crm_configuration_id = 39\nAND account_id = 178 AND is_closed = false\norder by created_at DESC;\n\nselect * from contacts where id = 3952;\nselect * from accounts where id = 178;\n\n# ************************************************************************************\nselect * from teams where id = 36;\nselect * from crm_configurations where id = 21;\nselect * from users where team_id = 36;\nselect u.email, cp.* from users u\njoin crm_profiles cp on u.id = cp.user_id\nwhere u.team_id = 36;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 36\nand sa.provider = 'bullhorn';\n\nselect * from social_accounts where id = 348;\nUPDATE social_accounts SET\nprovider_user_token = '21442_6802599_91:41179a58-21e7-4d7c-ad58-56bb666b2f65',\nprovider_refresh_token = '21442_6802599_91:01c6b335-3f2a-42e4-85ff-8a08fa65fceb',\nexpires = 1733998131,\nstate = 'connected'\nWHERE id = 348;\n\n# ************************************************************************************\nselect * from teams where id = 31;\nselect * from crm_configurations where id = 18;\n\nselect * from users where team_id = 31; # 257\nselect u.email, cp.* from users u\njoin crm_profiles cp on u.id = cp.user_id\nwhere u.team_id = 31;\n\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 31\nand sa.provider = 'close';\n\nselect * from contacts where crm_configuration_id = 18;\n\n# ********************** NEPTUNE **************************************************************\nselect * from teams;\nselect * from users where id IN (1030, 1035, 1052);\nselect * from crm_configurations;\n\nselect * from users where team_id = 65; # 257\nselect * from team_settings where team_id = 65; # 257\nselect * from invitations where team_id = 65; # 257\nselect * from users where email = 'integration-account@jiminny.com'; # 257\nselect u.email, cp.* from users u\njoin crm_profiles cp on u.id = cp.user_id\nwhere u.team_id = 65;\n\nselect * from crm_configurations where id = 53;\nselect * from accounts where crm_configuration_id = 53 order by id desc;\nselect * from leads where crm_configuration_id = 53 order by id desc;\nselect * from contacts where crm_configuration_id = 53 order by id desc;\nselect * from opportunities where crm_configuration_id = 53 order by id desc;\nselect * from crm_profiles where crm_configuration_id = 53 order by id desc;\nselect * from crm_fields where crm_configuration_id = 53 order by id desc;\nselect * from crm_field_values where crm_field_id = 3341 order by id desc;\nselect * from crm_layouts where crm_configuration_id = 53 order by id desc;\nselect * from stages where crm_configuration_id = 53 order by id desc;\n\n\nselect * from crm_profiles where crm_configuration_id = 13;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 65\nand sa.provider = 'integration-app';\n\nselect * from contacts where crm_configuration_id = 13;\n\nselect * from social_accounts where sociable_id = 283;\n\nSELECT * FROM opportunities WHERE crm_provider_id = '006O400000E9bzeIAB';\n\nselect * from activity_providers where team_id = 65;\nSELECT * FROM activities WHERE crm_configuration_id IN (51, 52, 53);\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 65\n;\n\n# ***************************** STAGING ********************************************\nSELECT * FROM teams;\nSELECT * FROM teams WHERE id = 88;\nSELECT * FROM teams WHERE id = 89;\nselect * from team_settings where team_id = 89;\nSELECT * FROM users WHERE team_id = 89;\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 89;\n\nselect * from users;\nSELECT * FROM social_accounts WHERE sociable_id = 1761;\nSELECT * FROM crm_configurations WHERE id = 70;\nselect * from accounts where crm_configuration_id = 70 order by id desc;\nselect * from leads where crm_configuration_id = 70 order by id desc;\nselect * from contacts where crm_configuration_id = 70 order by id desc;\nselect * from opportunities where crm_configuration_id = 70 order by id desc;\nselect * from crm_profiles where crm_configuration_id = 70 order by id desc;\nselect * from crm_fields where crm_configuration_id = 70 order by id desc;\nselect * from crm_field_values where crm_field_id = 3536 order by id desc;\nselect * from crm_layouts where crm_configuration_id = 70 order by id desc;\nselect * from stages where crm_configuration_id = 70 order by id desc;\nselect * from business_processes where crm_configuration_id = 70 order by id desc;\nselect * from business_process_stages where business_process_id = 34;\n\nselect * from contacts where id = 10468;\n\nselect * from crm_layouts where crm_configuration_id = 70;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 388;\nSELECT * FROM crm_fields WHERE id IN (3533,3534,3535);\n\nselect * from activities where crm_configuration_id = 70\nand (account_id IS NOT NULL or lead_id IS NOT NULL or contact_id IS NOT NULL or opportunity_id IS NOT NULL) order by id desc;\n\nSELECT * FROM activities WHERE uuid_to_bin('2e10b60f-8a61-41c5-a3d4-28835353dc65') = uuid;\nSELECT * FROM activities where crm_configuration_id = 69 ;\n\nSELECT * FROM users WHERE email LIKE '%jiminny_web_sa2@jiminny.com%';\nSELECT * FROM activities WHERE uuid_to_bin('5a150c93-40fc-42ec-b3bd-c1d328e09f6e') = uuid;\nSELECT * FROM opportunities WHERE id = 385;\n\nselect * from participants p\njoin activities a on p.activity_id = a.id\nwhere a.crm_configuration_id = 70\nand (p.lead_id IS NOT NULL or p.contact_id IS NOT NULL);\nSELECT * FROM participants WHERE id = 1013638;\n\nselect * from teams where id = 90;\nselect * from users where team_id = 90;\nselect * from social_accounts where social_accounts.sociable_id IN (1960,1760);\nSELECT * FROM crm_profiles WHERE crm_configuration_id = 71;\nselect * from invitations where team_id = 90;\n\nselect * from crm_configurations where id = 71;\nselect * from accounts where crm_configuration_id = 71 order by id desc;\nselect * from leads where crm_configuration_id = 71 order by id desc;\nselect * from contacts where crm_configuration_id = 71 order by id desc;\nselect * from opportunities where crm_configuration_id = 71 order by id desc;\nselect * from crm_profiles where crm_configuration_id = 71 order by id desc;\nselect * from crm_fields where crm_configuration_id = 71 order by id desc;\nselect * from crm_field_values where crm_field_id = 3341 order by id desc;\nselect * from crm_layouts where crm_configuration_id = 71 order by id desc;\nselect * from stages where crm_configuration_id = 71 order by id desc;\n\nselect * from users order by secondary_email desc;\nselect u.id, u.email, u.status, sa.id, sa.provider_user_id from social_accounts sa\n join users u on sa.sociable_id = u.id\nwhere sa.provider = 'google' and u.email LIKE 'aneliya%';\n\nselect * from failed_jobs order by id desc;\n\nselect * from users where email = 'ben.allwright@learningpeople.co.uk' or secondary_email = 'ben.allwright@learningpeople.co.uk';\n\nselect * from teams;\nSELECT * FROM crm_profiles WHERE crm_configuration_id = 39;\nSELECT * FROM crm_fields WHERE crm_configuration_id = 39 and object_type = 'task';\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 1\nand sa.provider = 'salesforce';\n\n# ************************************************************************************\nSELECT * FROM activities WHERE uuid_to_bin('c38b3895-fd0f-4b1f-9fb2-c170dba137c6') = uuid;\nSELECT * FROM crm_configurations WHERE id = 70;\n\nselect * from teams where id = 1;\nselect * from groups where team_id = 1;\nselect * from users where team_id = 1;\n\nselect o.id, o.name,o.close_date, u.id, u.name, u.group_id, r.id, r.display_name, g.name, g.scope from opportunities o\njoin users u on o.user_id = u.id\njoin groups g on u.group_id = g.id\njoin role_user ru on u.id = ru.user_id\njoin roles r on ru.role_id = r.id\nwhere o.crm_configuration_id = 39 and close_date > '2024-01-01 00:00:00';\n\nselect * from role_user where user_id = 143;\nselect * from roles;\n\nselect * from role_user;\nselect * from groups where id = 9;\nselect * from scope_groups where group_id = 9;\n\n# ************************************************************************************\nselect * from teams where id = 36;\nselect * from crm_configurations;\nSELECT * FROM social_accounts WHERE sociable_id = 121;\n\nhttps://crmsandbox.zoho.com/crm/jiminnyw4/tab/Leads/4776201000005049105\nhttps://crmsandbox.zoho.com/crm/\n\nhttps://crm.zoho.com/crm/org3469620/tab/Leads/230045000229559080\n https://crm.zoho.com/crm/\n org3469620\n\nSELECT * FROM activities WHERE uuid_to_bin('03382d20-c8bc-48e7-a3d4-90b52fa5ceab') = uuid;\n\nselect * from users where email LIKE \"%mobile_automation_%\";\nselect * from social_accounts where sociable_id IN (2228);\nselect * from crm_profiles where user_id IN (2222,2223,2226,2227);\n\nselect * from teams order by id desc;\nSELECT * FROM users WHERE id = 2229;\nSELECT * FROM crm_profiles WHERE user_id = 2229;\nselect * from opportunities where crm_configuration_id = 88;\nselect * from crm_fields where crm_configuration_id = 88;\nselect * from crm_profiles where crm_configuration_id = 88;\n\nSELECT * FROM teams WHERE id = 1;\n\nSELECT * FROM users WHERE id = 143;\nSELECT * FROM users WHERE uuid_to_bin('fde193d3-06a2-4e1a-8895-62b94039215d') = uuid;\nSELECT * FROM teams WHERE uuid_to_bin('73385071-a756-42ae-9c73-8b53f2309467') = uuid;\n\nhttps://app.staging.jiminny.com/ondemand?\n min_duration=1\n &\n only_recorded=1\n &\n user_id%5B%5D=641f1acb-16b8-42d1-8726-df52979dad0e\n &\n sequence_number=2\n\n select * from users where team_id = 1 and email like '%stoyan%'\n\nselect * from coaching_feedbacks;\n\nselect * from teams;\nSELECT * FROM users WHERE team_id = 36;\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 19\nand sa.provider = 'pipedrive';\n\nselect * from users where id = 143;\n\nSELECT * FROM users WHERE uuid_to_bin('73180eeb-33de-4065-977d-ccbe0e6c94fc') = uuid;\nSELECT * FROM teams WHERE uuid_to_bin('73180eeb-33de-4065-977d-ccbe0e6c94fc') = uuid;\nSELECT * FROM activity_shares WHERE uuid_to_bin('73180eeb-33de-4065-977d-ccbe0e6c94fc') = uuid;\n\nselect * from users where team_id = 2;\nselect * from activities where crm_configuration_id = 39\nand activities.scheduled_start_time BETWEEN '2025-04-09 00:00:00' AND '2025-04-09 23:59:59'\nAND user_id = 143\norder by id desc;\n\n# ************************************************************************************\nselect * from teams where id = 142; # 2312, 126\nselect * from team_settings;\nselect * from users where team_id = 142; # 21642\nSELECT * FROM social_accounts WHERE sociable_id = 21642;\nSELECT * FROM crm_profiles cp join users u ON u.id = cp.user_id WHERE team_id = 142;\nselect * from crm_profiles where id IN (93);\nselect * from invitations;\nselect * from team_features where team_id = 1;\n\nSELECT * FROM crm_configurations WHERE id = 126;\nselect * from accounts where crm_configuration_id = 126 order by id desc;\nselect * from leads where crm_configuration_id = 126 order by id desc;\nselect * from contacts where crm_configuration_id = 126 order by id desc;\nselect * from opportunities where crm_configuration_id = 126 order by id desc;\nselect * from crm_profiles where crm_configuration_id = 126 order by id desc;\nselect * from crm_fields where crm_configuration_id = 126 # 11060\n# and type IN ('picklist', 'status')\n# and object_type = 'task'\norder by id desc;\n# 5731,5732,5733\nselect DISTINCT crm_field_id from crm_field_values where crm_field_id IN (11151,12239,12215,12185,12175,12165,12144,12137,12127,12109,12107,12105,12103,12092,12037,12005,12003,11987,11969,11958,11951,11942,11931,11924,11921,11917,11915,11901,11893,11883,11872,11870,11868,11866,11839,11833,11821,11793,11780,11777,11769,11757,11737,11735,11656,11645,11638,11629,11618,11611,11602,11591,11584,11581,11558,11544,11543,11534,11532,11529,11527,11503,11497,11493,11488,11470,11468,11457,11455,11397,11387,11372,11363,11348,11323,11318,11309,11301,11300,11292,11290,11286,11284,11256,11252,11242,11237,11233,11219,11176,11160) order by id desc;\nselect * from crm_layouts where crm_configuration_id = 126 order by id desc;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id in (300,299,298);\nselect * from stages where crm_configuration_id = 126 order by id desc;\nselect * from business_processes where crm_configuration_id = 126 order by id desc;\nselect * from business_process_stages where business_process_id IN (76,75,74,73);\nselect * from playbooks where team_id = 142;\nselect * from playbook_layouts where playbook_id IN (108);\nSELECT * FROM playbook_categories WHERE playbook_id IN (108);\n\nselect * from teams where id = 130;\nSELECT * FROM social_accounts WHERE sociable_id = 2291;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 2\nand sa.provider = 'hubspot';\n\nSELECT * FROM activities\n WHERE crm_configuration_id = 110;\n\nselect * from teams;\nselect * from crm_configurations;\n\nSELECT * FROM activities WHERE id = 628773;\nSELECT * FROM crm_profiles WHERE user_id = 1460;\nSELECT * FROM social_accounts WHERE sociable_id = 2291;\n\nselect * from teams;\nselect ru.*, pr.*, p.* from users u join role_user ru on ru.user_id = u.id\njoin permission_role pr on pr.role_id = ru.role_id\n join permissions p on p.id = pr.permission_id\nwhere team_id = 495 and p.name IN ('dial');\n\nselect * from teams where id = 145;\nselect * from crm_configurations where id = 129;\nselect * from social_accounts where sociable_id = 2317;\nSELECT * FROM activities WHERE uuid_to_bin('8dbab184-a333-4268-ad57-fb41f8d53a9a') = uuid;\n\nselect * from teams where id = 1;\nSELECT * FROM crm_layouts WHERE crm_configuration_id = 39;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 280;\nSELECT * FROM crm_layout_entities WHERE id = 5507;\nSELECT * FROM crm_fields WHERE crm_configuration_id = 39 and object_type IN ('event');\n\nselect * from teams;\nselect * from activities where crm_configuration_id = 14;\n\nSELECT * FROM social_accounts where provider = 'copper';\n\nselect * from activities where id = 628467;\nselect * from participants where activity_id = 628467;\n\nSELECT * FROM contacts WHERE id = 3969;\nSELECT * FROM accounts WHERE id = 177;\n\nSELECT * FROM activities WHERE uuid_to_bin('4eb54c77-cfa3-2bd4-84a7-9ed46a21c988') = uuid;\n\n# ********************* BH\nselect * from teams where id = 36;\nSELECT * FROM crm_configurations WHERE id = 21;\nselect * from activities where crm_configuration_id = 21 and id = 607901;\nselect * from activities where crm_configuration_id = 21;\n\nselect * roles;\nselect * from permissions;\nselect * from permission_role where permission_id = 226;\n\nselect * from migrations order by id desc;\n\n# mercury\n# neptune\n# earth\n\nselect * from teams;\nselect * from teams where id = 19;\nselect * from teams where id = 27;\nselect * from users where team_id = 27;\nSELECT * FROM crm_configurations WHERE id = 42;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 19\nand sa.provider = 'pipedrive';\n\nselect * from activities where id = 631461;\nSELECT * FROM crm_field_values WHERE crm_field_id = 180;\n\nselect * from teams where id = 2;\nSELECT * FROM social_accounts WHERE sociable_id = 89;\n\nSELECT * FROM activities WHERE uuid_to_bin('ba0c029a-bc14-4e17-8603-64174acebcbb') = uuid; # 634273\nselect * from activity_summary_logs where activity_id = 634273;\n\nselect * from sidekick_settings where team_id = 2;\n\nselect * from teams; # 2, 2\nSELECT * FROM crm_configurations WHERE team_id = 2; # 2\nselect * from team_features where team_id = 2;\nselect * from features;\nSELECT * FROM opportunities WHERE crm_configuration_id = 2 and crm_provider_id = '51317301383';\nSELECT * FROM opportunities WHERE crm_configuration_id = 2 order by id desc;\n\nselect * from automated_reports order by id desc;\nselect * from automated_report_results order by id desc;\nselect * from users where team_id = 1 and id IN (7160, 3248);\nselect * from migrations order by id desc;\n\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 1 and sa.provider = 'salesforce';\n\nselect * from teams where id = 1;\nselect * from groups g JOIN playbooks p on g.playbook_id = p.id where g.team_id = 1;\nselect * from groups where id = 565;\nselect * from playbooks where team_id = 1;\nselect * from playbooks where id = 175;\nselect * from playbook_categories where playbook_id = 175;\nselect * from users where team_id = 1;\nselect * from users where id = 7160;\nselect * from crm_profiles where user_id = 7160;\nselect * from features;\nselect\n *\n# id, uuid, type, provider, playbook_category_id, user_id, lead_id, contact_id, account_id, opportunity_id, stage_id,\n# crm_configuration_id, crm_provider_id, transcription_id, status\nfrom activities where crm_configuration_id = 1 and type = 'conference'\n# and crm_provider_id IS NOT NULL\nand provider != 'uploader' and actual_start_time IS NOT NULL\nORDER by id desc;\nselect * from activities where id = 54747783; # 00UO400000pCzojMAC\n\nselect p.id, p.activity_type, pc.id, pc.name\nFROM playbooks p\njoin playbook_categories pc on p.id = pc.playbook_id\nwhere p.team_id = 1 and p.activity_type = 'event';\n\nSELECT * FROM crm_fields WHERE crm_configuration_id = 1 and object_type = 'event';\nSELECT * FROM crm_field_values WHERE crm_field_id = 4;\n\nselect * from crm_layouts cl join playbook_layouts pl on cl.id = pl.layout_id\nwhere crm_configuration_id = 1 and pl.playbook_id = 175;\n\nselect * from teams;\nSELECT r.* FROM automated_reports r\njoin teams t on r.team_id = t.id\nWHERE r.frequency = 'daily'\n and r.status = 1\nAND t.status = 'active'\nAND (r.expires_at >= now() OR r.expires_at IS NULL);\n\nselect * from automated_report_results where report_id IN (18, 33);\n\nselect * from activity_searches where id = 10932;\nselect * from activity_search_filters where activity_search_id = 10932;\nselect * from automated_reports;\nselect * from automated_report_results where report_id IN (34, 35);","depth":4,"value":"SELECT * FROM teams WHERE id = 1;\n\nselect * from crm_layouts where crm_configuration_id = 39;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 283;\nSELECT * FROM crm_fields WHERE id = 2234;\nSELECT * FROM crm_field_values WHERE crm_field_id = 2234;\n\nselect * from crm_profiles where user_id = 143;\n\nselect * from record_types where crm_configuration_id = 39; # 0121K000001MHElQAO,0121K000001MHEqQAO\nselect * from business_processes where crm_configuration_id = 39;\n# 01941000000H669AAC, 01941000000H66JAAS\n\nselect * from record_type_field_values\n where record_type_id IN (24);\n\nselect * from crm_field_values where id IN (2730);\n\nselect * from crm_configurations where id = 39;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 1\nand sa.provider = 'salesforce'; #1035\n\n\nselect * from users where team_id = 1; # 222 group 3\nSELECT * FROM activities WHERE user_id = 222 order by id desc;\nselect * from sidekick_settings where team_id = 1;\nselect * from teams where id = 1;\nselect * from team_features where team_id = 1;\n\nselect * from activities where crm_configuration_id = 2\nand provider = 'ms-teams' and id = 608765;\n\nSELECT * FROM activities WHERE crm_configuration_id = 2 and crm_provider_id = '59523413338';\n\nselect * from sidekick_settings where team_id = 2;\n\nSELECT * FROM activities WHERE id = 608660;\nselect * from activity_summary_logs where activity_id = 608660;\nselect * from ai_prompts where transcription_id = 11214;\n\n# ********************************************************************************************************\nSELECT * FROM activities WHERE uuid_to_bin('ed78a437-2804-450e-ab2f-56ab1c641346') = uuid;\n# id: 608818, crm: 59628809737\nSELECT * FROM activities WHERE uuid_to_bin('36b06e55-afdd-4782-8dee-c624cd0af191') = uuid;\n# id: 608821, crm: 59632069252\nSELECT ce.start_time, ce.end_time, a.id, a.uuid, crm_provider_id, calendar_event_id, title,\nplaybook_category_id, user_id, lead_id, contact_id, account_id, opportunity_id,\nscheduled_start_time, scheduled_end_time, actual_start_time, actual_end_time, a.created_at\nFROM activities a\njoin calendar_events ce on a.calendar_event_id = ce.id\nWHERE a.id IN (608818, 608821);\n\nselect * from users where team_id = 1;\nselect * from team_settings where team_id = 1;\nselect * from crm_profiles where crm_configuration_id = 39 order by user_id;\n\nselect * from team_features where team_id = 1;\n\nselect * from users where team_id = 2;\n\nSELECT * FROM activities WHERE uuid_to_bin('ec7647e9-5225-458b-b475-f31aa2769204') = uuid; # 612639\n# Preslava N. Ivanova, grou id 3\n\nSELECT * FROM opportunities WHERE uuid_to_bin('a2928fe5-aec5-46cb-85d9-7654c89e46a6') = uuid;\n\nselect * from activities where opportunity_id = 344 and actual_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00';\n\nselect\n a.id,\n a.type,\n a.scheduled_start_time,\n a.actual_start_time,\n a.created_at,\n a.opportunity_id,\n a.status\nFROM activities a\nWHERE opportunity_id = 344\nand status IN ('completed', 'received', 'delivered')\nand (\n (a.actual_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00')\nOR (a.created_at between '2024-10-11 00:00:00' and '2024-10-12 00:00:00')\nOR (a.scheduled_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00'))\n;\n\nSELECT * FROM users WHERE id = 222;\n\nSELECT * FROM crm_profiles WHERE user_id = 222;\nselect * from crm_layouts where crm_configuration_id = 39;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 281;\n\nselect * from group_deal_risk_types;\n\nselect * from opportunities where team_id = 1;\n\nSELECT * FROM opportunities WHERE id = 315;\nSELECT * FROM crm_field_data WHERE object_id = 315;\nselect * from crm_field_data where object_id = 260;\n\nselect * from generic_ai_prompts where subject_id = 315;\n\nselect * from teams; # 36, 21, 121, james.graham@bullhorn.jiminny.com\nSELECT * FROM social_accounts WHERE sociable_id = 121 and provider = 'bullhorn';\n\n# ************************************************************************************\nselect * from teams where id = 1;\nselect * from crm_configurations where id = 39;\nselect * from users where team_id = 1;\nselect u.email, cp.* from users u\njoin crm_profiles cp on u.id = cp.user_id\nwhere u.team_id = 1;\n# 1 - 00541000004281rAAA\n# 204 - 0052g000003freeAAA\n# 429 - 0052g000003qGOiAAM\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 1\nand sa.provider = 'salesforce';\n\nselect * from activities where type = 'softphone'\nand created_at > '2024-12-11 15:24:36' order by id desc;\n\nselect * from activity_providers where team_id = 1;\nselect * from activity_provider_users where activity_provider_id = 328;\n\nselect * from opportunities where crm_configuration_id = 39\nAND account_id = 178 AND is_closed = false\norder by created_at DESC;\n\nselect * from contacts where id = 3952;\nselect * from accounts where id = 178;\n\n# ************************************************************************************\nselect * from teams where id = 36;\nselect * from crm_configurations where id = 21;\nselect * from users where team_id = 36;\nselect u.email, cp.* from users u\njoin crm_profiles cp on u.id = cp.user_id\nwhere u.team_id = 36;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 36\nand sa.provider = 'bullhorn';\n\nselect * from social_accounts where id = 348;\nUPDATE social_accounts SET\nprovider_user_token = '21442_6802599_91:41179a58-21e7-4d7c-ad58-56bb666b2f65',\nprovider_refresh_token = '21442_6802599_91:01c6b335-3f2a-42e4-85ff-8a08fa65fceb',\nexpires = 1733998131,\nstate = 'connected'\nWHERE id = 348;\n\n# ************************************************************************************\nselect * from teams where id = 31;\nselect * from crm_configurations where id = 18;\n\nselect * from users where team_id = 31; # 257\nselect u.email, cp.* from users u\njoin crm_profiles cp on u.id = cp.user_id\nwhere u.team_id = 31;\n\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 31\nand sa.provider = 'close';\n\nselect * from contacts where crm_configuration_id = 18;\n\n# ********************** NEPTUNE **************************************************************\nselect * from teams;\nselect * from users where id IN (1030, 1035, 1052);\nselect * from crm_configurations;\n\nselect * from users where team_id = 65; # 257\nselect * from team_settings where team_id = 65; # 257\nselect * from invitations where team_id = 65; # 257\nselect * from users where email = 'integration-account@jiminny.com'; # 257\nselect u.email, cp.* from users u\njoin crm_profiles cp on u.id = cp.user_id\nwhere u.team_id = 65;\n\nselect * from crm_configurations where id = 53;\nselect * from accounts where crm_configuration_id = 53 order by id desc;\nselect * from leads where crm_configuration_id = 53 order by id desc;\nselect * from contacts where crm_configuration_id = 53 order by id desc;\nselect * from opportunities where crm_configuration_id = 53 order by id desc;\nselect * from crm_profiles where crm_configuration_id = 53 order by id desc;\nselect * from crm_fields where crm_configuration_id = 53 order by id desc;\nselect * from crm_field_values where crm_field_id = 3341 order by id desc;\nselect * from crm_layouts where crm_configuration_id = 53 order by id desc;\nselect * from stages where crm_configuration_id = 53 order by id desc;\n\n\nselect * from crm_profiles where crm_configuration_id = 13;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 65\nand sa.provider = 'integration-app';\n\nselect * from contacts where crm_configuration_id = 13;\n\nselect * from social_accounts where sociable_id = 283;\n\nSELECT * FROM opportunities WHERE crm_provider_id = '006O400000E9bzeIAB';\n\nselect * from activity_providers where team_id = 65;\nSELECT * FROM activities WHERE crm_configuration_id IN (51, 52, 53);\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 65\n;\n\n# ***************************** STAGING ********************************************\nSELECT * FROM teams;\nSELECT * FROM teams WHERE id = 88;\nSELECT * FROM teams WHERE id = 89;\nselect * from team_settings where team_id = 89;\nSELECT * FROM users WHERE team_id = 89;\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 89;\n\nselect * from users;\nSELECT * FROM social_accounts WHERE sociable_id = 1761;\nSELECT * FROM crm_configurations WHERE id = 70;\nselect * from accounts where crm_configuration_id = 70 order by id desc;\nselect * from leads where crm_configuration_id = 70 order by id desc;\nselect * from contacts where crm_configuration_id = 70 order by id desc;\nselect * from opportunities where crm_configuration_id = 70 order by id desc;\nselect * from crm_profiles where crm_configuration_id = 70 order by id desc;\nselect * from crm_fields where crm_configuration_id = 70 order by id desc;\nselect * from crm_field_values where crm_field_id = 3536 order by id desc;\nselect * from crm_layouts where crm_configuration_id = 70 order by id desc;\nselect * from stages where crm_configuration_id = 70 order by id desc;\nselect * from business_processes where crm_configuration_id = 70 order by id desc;\nselect * from business_process_stages where business_process_id = 34;\n\nselect * from contacts where id = 10468;\n\nselect * from crm_layouts where crm_configuration_id = 70;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 388;\nSELECT * FROM crm_fields WHERE id IN (3533,3534,3535);\n\nselect * from activities where crm_configuration_id = 70\nand (account_id IS NOT NULL or lead_id IS NOT NULL or contact_id IS NOT NULL or opportunity_id IS NOT NULL) order by id desc;\n\nSELECT * FROM activities WHERE uuid_to_bin('2e10b60f-8a61-41c5-a3d4-28835353dc65') = uuid;\nSELECT * FROM activities where crm_configuration_id = 69 ;\n\nSELECT * FROM users WHERE email LIKE '%jiminny_web_sa2@jiminny.com%';\nSELECT * FROM activities WHERE uuid_to_bin('5a150c93-40fc-42ec-b3bd-c1d328e09f6e') = uuid;\nSELECT * FROM opportunities WHERE id = 385;\n\nselect * from participants p\njoin activities a on p.activity_id = a.id\nwhere a.crm_configuration_id = 70\nand (p.lead_id IS NOT NULL or p.contact_id IS NOT NULL);\nSELECT * FROM participants WHERE id = 1013638;\n\nselect * from teams where id = 90;\nselect * from users where team_id = 90;\nselect * from social_accounts where social_accounts.sociable_id IN (1960,1760);\nSELECT * FROM crm_profiles WHERE crm_configuration_id = 71;\nselect * from invitations where team_id = 90;\n\nselect * from crm_configurations where id = 71;\nselect * from accounts where crm_configuration_id = 71 order by id desc;\nselect * from leads where crm_configuration_id = 71 order by id desc;\nselect * from contacts where crm_configuration_id = 71 order by id desc;\nselect * from opportunities where crm_configuration_id = 71 order by id desc;\nselect * from crm_profiles where crm_configuration_id = 71 order by id desc;\nselect * from crm_fields where crm_configuration_id = 71 order by id desc;\nselect * from crm_field_values where crm_field_id = 3341 order by id desc;\nselect * from crm_layouts where crm_configuration_id = 71 order by id desc;\nselect * from stages where crm_configuration_id = 71 order by id desc;\n\nselect * from users order by secondary_email desc;\nselect u.id, u.email, u.status, sa.id, sa.provider_user_id from social_accounts sa\n join users u on sa.sociable_id = u.id\nwhere sa.provider = 'google' and u.email LIKE 'aneliya%';\n\nselect * from failed_jobs order by id desc;\n\nselect * from users where email = 'ben.allwright@learningpeople.co.uk' or secondary_email = 'ben.allwright@learningpeople.co.uk';\n\nselect * from teams;\nSELECT * FROM crm_profiles WHERE crm_configuration_id = 39;\nSELECT * FROM crm_fields WHERE crm_configuration_id = 39 and object_type = 'task';\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 1\nand sa.provider = 'salesforce';\n\n# ************************************************************************************\nSELECT * FROM activities WHERE uuid_to_bin('c38b3895-fd0f-4b1f-9fb2-c170dba137c6') = uuid;\nSELECT * FROM crm_configurations WHERE id = 70;\n\nselect * from teams where id = 1;\nselect * from groups where team_id = 1;\nselect * from users where team_id = 1;\n\nselect o.id, o.name,o.close_date, u.id, u.name, u.group_id, r.id, r.display_name, g.name, g.scope from opportunities o\njoin users u on o.user_id = u.id\njoin groups g on u.group_id = g.id\njoin role_user ru on u.id = ru.user_id\njoin roles r on ru.role_id = r.id\nwhere o.crm_configuration_id = 39 and close_date > '2024-01-01 00:00:00';\n\nselect * from role_user where user_id = 143;\nselect * from roles;\n\nselect * from role_user;\nselect * from groups where id = 9;\nselect * from scope_groups where group_id = 9;\n\n# ************************************************************************************\nselect * from teams where id = 36;\nselect * from crm_configurations;\nSELECT * FROM social_accounts WHERE sociable_id = 121;\n\nhttps://crmsandbox.zoho.com/crm/jiminnyw4/tab/Leads/4776201000005049105\nhttps://crmsandbox.zoho.com/crm/\n\nhttps://crm.zoho.com/crm/org3469620/tab/Leads/230045000229559080\n https://crm.zoho.com/crm/\n org3469620\n\nSELECT * FROM activities WHERE uuid_to_bin('03382d20-c8bc-48e7-a3d4-90b52fa5ceab') = uuid;\n\nselect * from users where email LIKE \"%mobile_automation_%\";\nselect * from social_accounts where sociable_id IN (2228);\nselect * from crm_profiles where user_id IN (2222,2223,2226,2227);\n\nselect * from teams order by id desc;\nSELECT * FROM users WHERE id = 2229;\nSELECT * FROM crm_profiles WHERE user_id = 2229;\nselect * from opportunities where crm_configuration_id = 88;\nselect * from crm_fields where crm_configuration_id = 88;\nselect * from crm_profiles where crm_configuration_id = 88;\n\nSELECT * FROM teams WHERE id = 1;\n\nSELECT * FROM users WHERE id = 143;\nSELECT * FROM users WHERE uuid_to_bin('fde193d3-06a2-4e1a-8895-62b94039215d') = uuid;\nSELECT * FROM teams WHERE uuid_to_bin('73385071-a756-42ae-9c73-8b53f2309467') = uuid;\n\nhttps://app.staging.jiminny.com/ondemand?\n min_duration=1\n &\n only_recorded=1\n &\n user_id%5B%5D=641f1acb-16b8-42d1-8726-df52979dad0e\n &\n sequence_number=2\n\n select * from users where team_id = 1 and email like '%stoyan%'\n\nselect * from coaching_feedbacks;\n\nselect * from teams;\nSELECT * FROM users WHERE team_id = 36;\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 19\nand sa.provider = 'pipedrive';\n\nselect * from users where id = 143;\n\nSELECT * FROM users WHERE uuid_to_bin('73180eeb-33de-4065-977d-ccbe0e6c94fc') = uuid;\nSELECT * FROM teams WHERE uuid_to_bin('73180eeb-33de-4065-977d-ccbe0e6c94fc') = uuid;\nSELECT * FROM activity_shares WHERE uuid_to_bin('73180eeb-33de-4065-977d-ccbe0e6c94fc') = uuid;\n\nselect * from users where team_id = 2;\nselect * from activities where crm_configuration_id = 39\nand activities.scheduled_start_time BETWEEN '2025-04-09 00:00:00' AND '2025-04-09 23:59:59'\nAND user_id = 143\norder by id desc;\n\n# ************************************************************************************\nselect * from teams where id = 142; # 2312, 126\nselect * from team_settings;\nselect * from users where team_id = 142; # 21642\nSELECT * FROM social_accounts WHERE sociable_id = 21642;\nSELECT * FROM crm_profiles cp join users u ON u.id = cp.user_id WHERE team_id = 142;\nselect * from crm_profiles where id IN (93);\nselect * from invitations;\nselect * from team_features where team_id = 1;\n\nSELECT * FROM crm_configurations WHERE id = 126;\nselect * from accounts where crm_configuration_id = 126 order by id desc;\nselect * from leads where crm_configuration_id = 126 order by id desc;\nselect * from contacts where crm_configuration_id = 126 order by id desc;\nselect * from opportunities where crm_configuration_id = 126 order by id desc;\nselect * from crm_profiles where crm_configuration_id = 126 order by id desc;\nselect * from crm_fields where crm_configuration_id = 126 # 11060\n# and type IN ('picklist', 'status')\n# and object_type = 'task'\norder by id desc;\n# 5731,5732,5733\nselect DISTINCT crm_field_id from crm_field_values where crm_field_id IN (11151,12239,12215,12185,12175,12165,12144,12137,12127,12109,12107,12105,12103,12092,12037,12005,12003,11987,11969,11958,11951,11942,11931,11924,11921,11917,11915,11901,11893,11883,11872,11870,11868,11866,11839,11833,11821,11793,11780,11777,11769,11757,11737,11735,11656,11645,11638,11629,11618,11611,11602,11591,11584,11581,11558,11544,11543,11534,11532,11529,11527,11503,11497,11493,11488,11470,11468,11457,11455,11397,11387,11372,11363,11348,11323,11318,11309,11301,11300,11292,11290,11286,11284,11256,11252,11242,11237,11233,11219,11176,11160) order by id desc;\nselect * from crm_layouts where crm_configuration_id = 126 order by id desc;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id in (300,299,298);\nselect * from stages where crm_configuration_id = 126 order by id desc;\nselect * from business_processes where crm_configuration_id = 126 order by id desc;\nselect * from business_process_stages where business_process_id IN (76,75,74,73);\nselect * from playbooks where team_id = 142;\nselect * from playbook_layouts where playbook_id IN (108);\nSELECT * FROM playbook_categories WHERE playbook_id IN (108);\n\nselect * from teams where id = 130;\nSELECT * FROM social_accounts WHERE sociable_id = 2291;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 2\nand sa.provider = 'hubspot';\n\nSELECT * FROM activities\n WHERE crm_configuration_id = 110;\n\nselect * from teams;\nselect * from crm_configurations;\n\nSELECT * FROM activities WHERE id = 628773;\nSELECT * FROM crm_profiles WHERE user_id = 1460;\nSELECT * FROM social_accounts WHERE sociable_id = 2291;\n\nselect * from teams;\nselect ru.*, pr.*, p.* from users u join role_user ru on ru.user_id = u.id\njoin permission_role pr on pr.role_id = ru.role_id\n join permissions p on p.id = pr.permission_id\nwhere team_id = 495 and p.name IN ('dial');\n\nselect * from teams where id = 145;\nselect * from crm_configurations where id = 129;\nselect * from social_accounts where sociable_id = 2317;\nSELECT * FROM activities WHERE uuid_to_bin('8dbab184-a333-4268-ad57-fb41f8d53a9a') = uuid;\n\nselect * from teams where id = 1;\nSELECT * FROM crm_layouts WHERE crm_configuration_id = 39;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 280;\nSELECT * FROM crm_layout_entities WHERE id = 5507;\nSELECT * FROM crm_fields WHERE crm_configuration_id = 39 and object_type IN ('event');\n\nselect * from teams;\nselect * from activities where crm_configuration_id = 14;\n\nSELECT * FROM social_accounts where provider = 'copper';\n\nselect * from activities where id = 628467;\nselect * from participants where activity_id = 628467;\n\nSELECT * FROM contacts WHERE id = 3969;\nSELECT * FROM accounts WHERE id = 177;\n\nSELECT * FROM activities WHERE uuid_to_bin('4eb54c77-cfa3-2bd4-84a7-9ed46a21c988') = uuid;\n\n# ********************* BH\nselect * from teams where id = 36;\nSELECT * FROM crm_configurations WHERE id = 21;\nselect * from activities where crm_configuration_id = 21 and id = 607901;\nselect * from activities where crm_configuration_id = 21;\n\nselect * roles;\nselect * from permissions;\nselect * from permission_role where permission_id = 226;\n\nselect * from migrations order by id desc;\n\n# mercury\n# neptune\n# earth\n\nselect * from teams;\nselect * from teams where id = 19;\nselect * from teams where id = 27;\nselect * from users where team_id = 27;\nSELECT * FROM crm_configurations WHERE id = 42;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 19\nand sa.provider = 'pipedrive';\n\nselect * from activities where id = 631461;\nSELECT * FROM crm_field_values WHERE crm_field_id = 180;\n\nselect * from teams where id = 2;\nSELECT * FROM social_accounts WHERE sociable_id = 89;\n\nSELECT * FROM activities WHERE uuid_to_bin('ba0c029a-bc14-4e17-8603-64174acebcbb') = uuid; # 634273\nselect * from activity_summary_logs where activity_id = 634273;\n\nselect * from sidekick_settings where team_id = 2;\n\nselect * from teams; # 2, 2\nSELECT * FROM crm_configurations WHERE team_id = 2; # 2\nselect * from team_features where team_id = 2;\nselect * from features;\nSELECT * FROM opportunities WHERE crm_configuration_id = 2 and crm_provider_id = '51317301383';\nSELECT * FROM opportunities WHERE crm_configuration_id = 2 order by id desc;\n\nselect * from automated_reports order by id desc;\nselect * from automated_report_results order by id desc;\nselect * from users where team_id = 1 and id IN (7160, 3248);\nselect * from migrations order by id desc;\n\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 1 and sa.provider = 'salesforce';\n\nselect * from teams where id = 1;\nselect * from groups g JOIN playbooks p on g.playbook_id = p.id where g.team_id = 1;\nselect * from groups where id = 565;\nselect * from playbooks where team_id = 1;\nselect * from playbooks where id = 175;\nselect * from playbook_categories where playbook_id = 175;\nselect * from users where team_id = 1;\nselect * from users where id = 7160;\nselect * from crm_profiles where user_id = 7160;\nselect * from features;\nselect\n *\n# id, uuid, type, provider, playbook_category_id, user_id, lead_id, contact_id, account_id, opportunity_id, stage_id,\n# crm_configuration_id, crm_provider_id, transcription_id, status\nfrom activities where crm_configuration_id = 1 and type = 'conference'\n# and crm_provider_id IS NOT NULL\nand provider != 'uploader' and actual_start_time IS NOT NULL\nORDER by id desc;\nselect * from activities where id = 54747783; # 00UO400000pCzojMAC\n\nselect p.id, p.activity_type, pc.id, pc.name\nFROM playbooks p\njoin playbook_categories pc on p.id = pc.playbook_id\nwhere p.team_id = 1 and p.activity_type = 'event';\n\nSELECT * FROM crm_fields WHERE crm_configuration_id = 1 and object_type = 'event';\nSELECT * FROM crm_field_values WHERE crm_field_id = 4;\n\nselect * from crm_layouts cl join playbook_layouts pl on cl.id = pl.layout_id\nwhere crm_configuration_id = 1 and pl.playbook_id = 175;\n\nselect * from teams;\nSELECT r.* FROM automated_reports r\njoin teams t on r.team_id = t.id\nWHERE r.frequency = 'daily'\n and r.status = 1\nAND t.status = 'active'\nAND (r.expires_at >= now() OR r.expires_at IS NULL);\n\nselect * from automated_report_results where report_id IN (18, 33);\n\nselect * from activity_searches where id = 10932;\nselect * from activity_search_filters where activity_search_id = 10932;\nselect * from automated_reports;\nselect * from automated_report_results where report_id IN (34, 35);","role_description":"text entry area","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.088194445,"height":0.027777778},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"102","depth":4,"role_description":"text"},{"role":"AXStaticText","text":"3","depth":4,"role_description":"text"},{"role":"AXStaticText","text":"34","depth":4,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Services\\Kiosk\\AutomatedReports;\n\nuse Carbon\\CarbonImmutable;\nuse Carbon\\CarbonInterface;\nuse Carbon\\Exceptions\\InvalidFormatException;\nuse DateTime;\nuse DateTimeInterface;\nuse DateTimeZone;\nuse Illuminate\\Contracts\\Bus\\Dispatcher as BusDispatcher;\nuse Illuminate\\Database\\Eloquent\\Builder;\nuse Illuminate\\Support\\Carbon;\nuse Illuminate\\Support\\Collection;\nuse Illuminate\\Support\\Facades\\Log;\nuse Illuminate\\Support\\Facades\\Storage;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinition\\InputTypeEnum;\nuse Jiminny\\Component\\AskAnything\\AskAnythingPromptService;\nuse Jiminny\\Component\\AskAnything\\Dtos\\AskAnythingPromptDto;\nuse Jiminny\\Component\\UrlGenerator\\Webhook;\nuse Jiminny\\Contracts\\Repositories\\PlaybookCategoryRepository;\nuse Jiminny\\Contracts\\Repositories\\TeamRepository;\nuse Jiminny\\Contracts\\Repositories\\UserRepository;\nuse Jiminny\\Exceptions\\ApplicationException;\nuse Jiminny\\Exceptions\\InvalidArgumentException;\nuse Jiminny\\Exceptions\\ModelNotFoundException;\nuse Jiminny\\Jobs\\AutomatedReports\\RequestGenerateReportJob;\nuse Jiminny\\Models\\Activity\\Search;\nuse Jiminny\\Models\\AskAnything\\AskAnythingPrompt;\nuse Jiminny\\Models\\AskAnything\\AskAnythingPromptTarget;\nuse Jiminny\\Models\\AutomatedReport;\nuse Jiminny\\Models\\AutomatedReportResult;\nuse Jiminny\\Models\\Contracts\\UserContract;\nuse Jiminny\\Models\\Feature\\FeatureEnum;\nuse Jiminny\\Models\\Team;\nuse Jiminny\\Models\\User;\nuse Jiminny\\Repositories\\AskAnythingRepository;\nuse Jiminny\\Repositories\\AutomatedReportsRepository;\nuse Jiminny\\Repositories\\GroupRepository;\nuse Jiminny\\Repositories\\SearchRepository;\nuse Jiminny\\Repositories\\StageRepository;\nuse Throwable;\n\nclass AutomatedReportsService\n{\n public const string TYPE_LOSS_ANALYSIS = 'loss_analysis';\n public const string TYPE_ASK_JIMINNY = 'ask_jiminny';\n\n /**\n * Standard report types (used by kiosk for existing automated reports).\n */\n // @TODO this will add filter, however if we need to control feature by FF we need conditional logic\n public const array TYPES = [\n ['id' => 'exec_summary', 'name' => 'Exec Summary'],\n ['id' => 'coaching_profiles', 'name' => 'Coaching Profiles'],\n ['id' => 'product_feedback', 'name' => 'Product Feedback'],\n ['id' => self::TYPE_LOSS_ANALYSIS, 'name' => 'Loss Analysis'],\n// ['id' => 'questions', 'name' => 'Questions'],\n// ['id' => 'statistical_quant', 'name' => 'Statistical Quantitative'],\n ];\n\n public const array ALL_TYPES = [\n ...self::TYPES,\n ['id' => self::TYPE_ASK_JIMINNY, 'name' => 'Ask Jiminny'],\n ];\n\n public const string FREQUENCY_DAILY = 'daily';\n public const string FREQUENCY_WEEKLY = 'weekly';\n public const string FREQUENCY_MONTHLY = 'monthly';\n public const string FREQUENCY_QUARTERLY = 'quarterly';\n public const string FREQUENCY_ONE_OFF = 'one_off';\n\n /**\n * Frequencies for standard (non-Ask Jiminny) reports.\n */\n public const array FREQUENCIES = [\n ['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],\n ['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],\n ['id' => self::FREQUENCY_QUARTERLY, 'name' => 'Quarterly'],\n ['id' => self::FREQUENCY_ONE_OFF, 'name' => 'One-off'],\n ];\n\n /**\n * Frequencies for Ask Jiminny reports.\n */\n public const array ASK_JIMINNY_FREQUENCIES = [\n ['id' => self::FREQUENCY_DAILY, 'name' => 'Daily'],\n ['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],\n ['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],\n ];\n\n public const string MEDIA_TYPE_PDF = 'pdf';\n public const string MEDIA_TYPE_PODCAST = 'podcast';\n public const array MEDIA_TYPES = [self::MEDIA_TYPE_PDF, self::MEDIA_TYPE_PODCAST];\n public const array MEDIA_TYPE_OBJECT_PDF = ['id' => self::MEDIA_TYPE_PDF, 'name' => 'PDF'];\n public const array MEDIA_TYPE_OBJECT_PODCAST = ['id' => self::MEDIA_TYPE_PODCAST, 'name' => 'Podcast'];\n public const array MEDIA_TYPE_OBJECTS = [self::MEDIA_TYPE_OBJECT_PDF, self::MEDIA_TYPE_OBJECT_PODCAST];\n\n public const array CALL_TYPE_CONFERENCE = ['id' => 'conference', 'name' => 'Conference'];\n public const array CALL_TYPE_DIALER = ['id' => 'dialer', 'name' => 'Dialer'];\n public const int SENT_REPORT_AT_HOURS = 5;\n public const string PDF_KEY = 'pdf';\n public const string AUDIO_KEY = 'audio';\n\n private const array ALL_FREQUENCIES = [\n ['id' => self::FREQUENCY_DAILY, 'name' => 'Daily'],\n ['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],\n ['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],\n ['id' => self::FREQUENCY_QUARTERLY, 'name' => 'Quarterly'],\n ['id' => self::FREQUENCY_ONE_OFF, 'name' => 'One-off'],\n ];\n private const string S3_DIR = 'reports';\n private const array FILE_EXTENSIONS_VARIANTS = ['html', 'MD', 'pdf'];\n private const array FILE_PODCAST_EXTENSIONS_VARIANTS = ['json', 'mp3', 'ssml'];\n\n public function __construct(\n private readonly TeamRepository $teamRepository,\n private readonly GroupRepository $groupRepository,\n private readonly UserRepository $userRepository,\n private readonly StageRepository $stageRepository,\n private readonly DealStagesService $dealStagesService,\n private readonly RecipientsService $recipientsService,\n private readonly AutomatedReportsRepository $automatedReportsRepository,\n private readonly Webhook $webhookService,\n private readonly BusDispatcher $dispatcher,\n private readonly ActivityTypeService $activityTypeService,\n private readonly PlaybookCategoryRepository $playbookCategoryRepository,\n private readonly AskAnythingPromptService $askAnythingPromptService,\n private readonly SearchRepository $activitySearchRepository,\n private readonly AskAnythingRepository $askAnythingRepository,\n ) {\n }\n\n public static function getTypes(): array\n {\n $types = self::TYPES;\n\n return array_map(static function ($type) {\n return $type['id'];\n }, $types);\n }\n\n public static function getCallTypes(): array\n {\n return array_map(static function ($callType) {\n return $callType['id'];\n }, [self::CALL_TYPE_CONFERENCE, self::CALL_TYPE_DIALER]);\n }\n\n public static function getFrequencies(): array\n {\n return array_map(static function ($frequency) {\n return $frequency['id'];\n }, self::FREQUENCIES);\n }\n\n // front-facing structure\n public function getReportEnabledFieldData(bool $value = false): array\n {\n return [\n 'id' => 'report_enabled',\n 'label' => '',\n 'inputType' => InputTypeEnum::TOGGLE,\n 'value' => $value,\n ];\n }\n\n // Organizations = Teams\n public function getOrganizationFieldData(?string $value = null, bool $shortVersion = false): array\n {\n $options = $this->getTeams();\n\n if ($shortVersion) {\n return [\n 'id' => 'organization',\n 'label' => 'Organization',\n 'options' => $options,\n ];\n }\n\n return [\n 'id' => 'organization',\n 'label' => 'Organization',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => $options,\n 'value' => $value,\n 'dependencies' => [\n 'teams',\n 'deal_stage_at_call',\n 'current_deal_stage',\n 'recipients',\n ActivityTypeService::PLAYBOOK_CATEGORIES_KEY,\n ],\n 'dependsOn' => [],\n ];\n }\n\n // Teams = Groups\n public function getTeamFieldData(array $options = [], array $value = [], bool $shortVersion = false): array\n {\n if ($shortVersion) {\n return [\n 'id' => 'teams',\n 'label' => 'Team',\n 'options' => $options,\n ];\n }\n\n return [\n 'id' => 'teams',\n 'label' => 'Team',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'required' => false,\n 'placeholder' => 'Select',\n 'options' => $options,\n 'value' => $value, // value should be an array of objects {id, name}\n 'dependencies' => [ActivityTypeService::PLAYBOOK_CATEGORIES_KEY],\n 'dependsOn' => [],\n ];\n }\n\n public function getReportTypeFieldData(?string $value = null, bool $shortVersion = false, ?Team $team = null): array\n {\n $types = [];\n if ($team instanceof Team) {\n if ($team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {\n $types = self::TYPES;\n }\n if ($team->hasFeature(FeatureEnum::ASK_JIMINNY_REPORTS)) {\n $types[] = ['id' => self::TYPE_ASK_JIMINNY, 'name' => 'Ask Jiminny'];\n }\n } else {\n $types = self::TYPES;\n }\n\n if ($shortVersion) {\n return [\n 'id' => 'report_type',\n 'label' => 'Report Type',\n 'options' => $types,\n ];\n }\n\n return [\n 'id' => 'report_type',\n 'label' => 'Report Type',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => $types,\n 'value' => $value,\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getFrequencyFieldData(?string $value = null): array\n {\n return [\n 'id' => 'frequency',\n 'label' => 'Frequency',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => self::FREQUENCIES,\n 'value' => $value,\n 'dependencies' => ['period'],\n 'dependsOn' => [],\n ];\n }\n\n public function getPeriodFieldData(?string $valueStartDate = null, ?string $valueEndDate = null): array\n {\n return [\n 'id' => 'period',\n 'label' => 'Select one-off period',\n 'inputType' => InputTypeEnum::DATE_RANGE,\n 'required' => true,\n 'placeholder' => 'Select',\n 'value' => ['startDate' => $valueStartDate, 'endDate' => $valueEndDate],\n 'queryParams' => [\n 'startDate' => 'start_date_period',\n 'endDate' => 'end_date_period',\n ],\n 'dependencies' => [],\n 'dependsOn' => ['frequency'],\n ];\n }\n\n public function getActivityTypesFieldData(?Team $team = null, array $value = [], array $teamsFilter = []): array\n {\n return $this->activityTypeService->getActivityTypeFieldData(team: $team, value: $value, groupIds: $teamsFilter);\n }\n\n public function getDealStageAtCallFieldData(?Team $team = null, array $value = []): array\n {\n return $this->dealStagesService->getDealStageAtCallFieldData(team: $team, value: $value);\n }\n\n public function getCurrentDealStageFieldData(?Team $team = null, array $value = []): array\n {\n return $this->dealStagesService->getCurrentDealStageFieldData(team: $team, value: $value);\n }\n\n public function getDealValueFieldData(?int $valueMin = null, ?int $valueMax = null): array\n {\n return [\n 'id' => 'deal_value',\n 'label' => 'Deal Value',\n 'inputType' => InputTypeEnum::INTEGER_RANGE,\n 'required' => false,\n 'value' => ['min' => $valueMin, 'max' => $valueMax],\n 'queryParams' => [\n 'min' => 'min_deal_value',\n 'max' => 'max_deal_value',\n ],\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getCallTypeFieldData(bool $conferenceOn = false, bool $dialerOn = false): array\n {\n $value = [];\n $conferenceOn && $value[] = self::CALL_TYPE_CONFERENCE;\n $dialerOn && $value[] = self::CALL_TYPE_DIALER;\n\n return [\n 'id' => 'call_type',\n 'label' => 'Call Type',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'required' => true,\n 'options' => [\n self::CALL_TYPE_CONFERENCE,\n self::CALL_TYPE_DIALER,\n ],\n 'value' => $value,\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getMediaTypeFieldData(?AutomatedReport $report = null): array\n {\n $value = [];\n\n if ($report) {\n $value = $this->transformMediaTypes($report);\n }\n\n return [\n 'id' => 'media_types',\n 'label' => 'Export as',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'required' => true,\n 'options' => self::MEDIA_TYPE_OBJECTS,\n 'value' => $value,\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getCallDurationFieldData(?int $valueMin = null, ?int $valueMax = null): array\n {\n return [\n 'id' => 'call_duration',\n 'label' => 'Call Duration',\n 'inputType' => InputTypeEnum::INTEGER_RANGE,\n 'required' => false,\n 'value' => ['min' => $valueMin, 'max' => $valueMax],\n 'queryParams' => [\n 'min' => 'min_call_duration',\n 'max' => 'max_call_duration',\n ],\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getRecipientsFieldData(?Team $team = null, array $value = []): array\n {\n return $this->recipientsService->getRecipientsFieldData(team: $team, value: $value);\n }\n\n public function getJiminnyRecipientsFieldData(array $value = []): array\n {\n return $this->recipientsService->getJiminnyRecipientsFieldData($value);\n }\n\n public function getAdditionalPromptInputFieldData(?string $value = null): array\n {\n return [\n 'id' => 'additional_prompt_input',\n 'label' => 'Special requirements',\n 'inputType' => InputTypeEnum::TEXTAREA,\n 'required' => false,\n 'placeholder' => 'What should be the focus of the report?',\n 'value' => $value,\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getCustomReportNameFieldData(?string $value = null): array\n {\n return [\n 'id' => 'custom_name',\n 'label' => 'Custom report name',\n 'inputType' => InputTypeEnum::TEXT,\n 'required' => false,\n 'placeholder' => 'Enter custom name',\n 'value' => $value,\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n // data providers\n public function getTeams(): array\n {\n $teams = $this->teamRepository->getTeamsForKiosk(status: Team::STATUS_ACTIVE);\n\n $teamData = [];\n foreach ($teams as $team) {\n if (! $team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {\n continue;\n }\n\n $teamData[] = $this->transformTeam($team);\n }\n\n return $teamData;\n }\n\n public function getTeamGroups(string $teamUuid): array\n {\n $data = [];\n $team = $this->getTeam($teamUuid);\n\n if ($team !== null) {\n $groups = $team->groups()->get();\n\n foreach ($groups as $group) {\n $data[] = [\n 'id' => $group->getUuid(),\n 'name' => $group->getName(),\n ];\n }\n }\n\n return $data;\n }\n\n public function getTeamsGroupsOptions(array $filterTeamUuids = []): array\n {\n $data = [];\n $teams = $this->getTeams();\n\n foreach ($teams as $team) {\n if (! empty($filterTeamUuids) && ! in_array($team['id'], $filterTeamUuids, true)) {\n continue;\n }\n\n $data[] = [\n 'label' => $team['name'],\n 'groups' => $this->getTeamGroups($team['id']),\n ];\n }\n\n return $data;\n }\n\n public function getTeam(string $teamUuid): ?Team\n {\n return $this->teamRepository->idOrUuid($teamUuid);\n }\n\n public function getTeamById(int $teamId): ?Team\n {\n return $this->teamRepository->find($teamId);\n }\n\n public function getGroupsUuids(AutomatedReport $report): array\n {\n $uuids = [];\n $reportGroups = $report->getGroups();\n foreach ($reportGroups as $groupId) {\n if ($group = $this->groupRepository->find($groupId)) {\n $uuids[] = $group->getUuid();\n }\n }\n\n return $uuids;\n }\n\n public function getPlaybookCategoriesUuids(AutomatedReport $report): array\n {\n $uuids = [];\n $playbookCategories = $report->getPlaybookCategories();\n foreach ($playbookCategories as $id) {\n if ($category = $this->playbookCategoryRepository->find($id)) {\n $uuids[] = $category->getUuid();\n }\n }\n\n return $uuids;\n }\n\n public function getDealAtCallStagesUuids(AutomatedReport $report): array\n {\n $uuids = [];\n $reportStages = $report->getDealAtCallStages();\n foreach ($reportStages as $id) {\n if ($stage = $this->stageRepository->find($id)) {\n $uuids[] = $stage->getUuid();\n }\n }\n\n return $uuids;\n }\n\n public function getCurrentDealStagesUuids(AutomatedReport $report): array\n {\n $uuids = [];\n $reportStages = $report->getCurrentDealStages();\n foreach ($reportStages as $id) {\n if ($stage = $this->stageRepository->find($id)) {\n $uuids[] = $stage->getUuid();\n }\n }\n\n return $uuids;\n }\n\n public function getUsersUuids(AutomatedReport $report): array\n {\n return $this->extractUserUuids($report->getRecipients());\n }\n\n public function getJiminnyUsersUuids(AutomatedReport $report): array\n {\n return $this->extractUserUuids($report->getJiminnyRecipients());\n }\n\n /**\n * @param array<string, mixed> $recipients\n */\n private function extractUserUuids(array $recipients): array\n {\n $userIds = $recipients['users'] ?? [];\n\n return collect($userIds)\n ->map(fn ($id) => $this->userRepository->find((int) $id))\n ->filter()\n ->map(fn (UserContract $user) => $user->getUuid())\n ->values()\n ->all();\n }\n\n // get mail data\n public function getRecipientUsers(AutomatedReport $report): array\n {\n return $this->buildRecipientUsers($report->getRecipients());\n }\n\n private function getJiminnyRecipientUsers(AutomatedReport $report): array\n {\n return $this->buildRecipientUsers($report->getJiminnyRecipients());\n }\n\n /**\n * @param array<string, mixed> $recipients\n */\n private function buildRecipientUsers(array $recipients): array\n {\n $userIds = $recipients['users'] ?? [];\n\n return collect($userIds)\n ->map(fn ($id) => $this->userRepository->find((int) $id))\n ->filter()\n ->map(fn (UserContract $user) => [\n 'email' => $user->getEmailAddress(),\n 'name' => $user->getName(),\n 'timezone' => $user->getTimezone()->getName(),\n ])\n ->values()\n ->all();\n }\n\n public function getValidRecipientUsers(AutomatedReport $report, bool $includeJiminny = false): array\n {\n if ($report->isAskJiminnyReport()) {\n $recipients = $this->resolveAskJiminnyRecipients($report);\n } else {\n $recipients = $this->getRecipientUsers($report);\n if ($includeJiminny) {\n $recipients = array_merge($recipients, $this->getJiminnyRecipientUsers($report));\n }\n }\n\n $emails = [];\n\n return array_values(array_filter(\n $recipients,\n static function ($recipient) use (&$emails) {\n if (empty($recipient['email']) || in_array($recipient['email'], $emails, true)) {\n return false;\n }\n $emails[] = $recipient['email'];\n\n return true;\n }\n ));\n }\n\n private function resolveAskJiminnyRecipients(AutomatedReport $report): array\n {\n $recipients = [];\n\n $creator = $report->getCreator();\n if ($creator !== null) {\n $recipients[] = [\n 'email' => $creator->getEmailAddress(),\n 'name' => $creator->getName(),\n 'timezone' => $creator->getTimezone()->getName(),\n ];\n }\n\n return array_merge(\n $recipients,\n $this->buildRecipientUsers($report->getRecipients()),\n $this->getGroupRecipientUsers($report),\n );\n }\n\n private function getGroupRecipientUsers(AutomatedReport $report): array\n {\n $users = [];\n foreach ($report->getGroups() as $groupId) {\n $group = $this->groupRepository->find($groupId);\n if ($group === null) {\n continue;\n }\n foreach ($group->getMembers() as $member) {\n $users[] = [\n 'email' => $member->getEmailAddress(),\n 'name' => $member->getName(),\n 'timezone' => $member->getTimezone()->getName(),\n ];\n }\n }\n\n return $users;\n }\n\n public function getReportTypeName(AutomatedReportResult $report): string\n {\n $type = $report->getReport()->getType();\n\n $getType = $this->transformReportType($type);\n\n return $getType['name'];\n }\n\n public function getReportPeriodName(AutomatedReportResult $report): string\n {\n $from = $report->getFromDate();\n $to = $report->getToDate();\n $frequency = $report->getReport()->getFrequency();\n\n if ($from === null || $to === null) {\n if (! $report->getReport()->isAskJiminnyReport()) {\n $invalidPeriod = $from === null ? 'from' : 'to';\n\n throw new ApplicationException('Report period is invalid: ' . $invalidPeriod);\n }\n\n $period = $this->calculateFromAndToDatePeriod($frequency);\n $from = $period['fromDate'];\n $to = $period['toDate'];\n }\n\n return $this->formatReportPeriodName($frequency, $from, $to);\n }\n\n private function formatReportPeriodName(string $frequency, Carbon $from, Carbon $to): string\n {\n $fromYear = $from->format('Y');\n $toYear = $to->format('Y');\n $differentYears = $fromYear !== $toYear;\n\n switch ($frequency) {\n case self::FREQUENCY_DAILY:\n return $from->format('j M Y');\n\n case self::FREQUENCY_QUARTERLY:\n // 'Jan-Mar 2025' or 'Nov 2024-Jan 2025' if years differ\n $startMonth = $from->format('M');\n $endMonth = $to->copy()->subMonth();\n $endMonthName = $endMonth->format('M');\n $endMonthYear = $endMonth->format('Y');\n\n if ($differentYears) {\n return \"{$startMonth} {$fromYear} - {$endMonthName} {$endMonthYear}\";\n }\n\n return \"{$startMonth} - {$endMonthName} {$toYear}\";\n\n case self::FREQUENCY_MONTHLY:\n // 'May 2025' - monthly reports are always within the same year\n return $from->format('M Y');\n\n case self::FREQUENCY_WEEKLY:\n // '4 - 8 Aug 2025', '27 Oct - 3 Nov 2025', or '28 Dec 2024 - 3 Jan 2025' if years differ\n $startDay = $from->format('j');\n $endDay = $to->format('j');\n $startMonth = $from->format('M');\n $endMonth = $to->format('M');\n\n if ($differentYears) {\n return \"{$startDay} {$startMonth} {$fromYear} - {$endDay} {$endMonth} {$toYear}\";\n }\n\n if ($startMonth !== $endMonth) {\n return \"{$startDay} {$startMonth} - {$endDay} {$endMonth} {$toYear}\";\n }\n\n return \"{$startDay} - {$endDay} {$endMonth} {$toYear}\";\n\n case self::FREQUENCY_ONE_OFF:\n // '2 May-31 May 2025' or '15 Dec 2024-15 Jan 2025' if years differ\n $startDay = $from->format('j');\n $startMonth = $from->format('M');\n $endDay = $to->format('j');\n $endMonth = $to->format('M');\n\n // If same month and year, use a format like '2-31 May 2025'\n if ($startMonth === $endMonth && ! $differentYears) {\n return \"{$startDay} - {$endDay} {$startMonth} {$toYear}\";\n }\n\n // If different years, include both years\n if ($differentYears) {\n return \"{$startDay} {$startMonth} {$fromYear} - {$endDay} {$endMonth} {$toYear}\";\n }\n\n // Same year but different months\n return \"{$startDay} {$startMonth} - {$endDay} {$endMonth} {$toYear}\";\n\n default:\n // Default format for unknown frequencies\n return $from->format('j M Y') . ' - ' . $to->format('j M Y');\n }\n }\n\n public function getReportTeamsName(AutomatedReportResult $report): string\n {\n $groups = $report->getGroups();\n\n if (empty($groups)) {\n return 'All';\n }\n\n // Get group names from repository\n $groupNames = [];\n foreach ($groups as $groupId) {\n $group = $this->groupRepository->find($groupId);\n if ($group) {\n $groupNames[] = $group->getName();\n }\n }\n\n if (count($groupNames) === 1) {\n // Single team format\n $teamsName = $groupNames[0];\n } else {\n // Multiple teams format\n $teamsName = implode(', ', $groupNames);\n }\n\n return $teamsName;\n }\n\n public function getReportFileName(AutomatedReportResult $report): string\n {\n $customName = $report->getReport()->getCustomName();\n $periodName = $this->getReportPeriodName($report);\n $filenameSuffix = $this->getFilenameSuffix($report);\n\n if ($customName) {\n if ($filenameSuffix) {\n $customName .= \" {$filenameSuffix}\";\n }\n\n return $this->sanitizeFileName(\"{$customName} - {$periodName}\");\n }\n\n $baseName = $this->getReportTypeName($report);\n\n if ($filenameSuffix) {\n $baseName .= \" {$filenameSuffix}\";\n }\n\n return $this->sanitizeFileName(\"{$baseName} - {$periodName} - {$this->getReportTeamsName($report)}\");\n }\n\n public function getReportFileNameWithExtension(AutomatedReportResult $result): string\n {\n $extension = $this->getMediaTypeMetadata($result)['extension'];\n\n return $this->getReportFileName($result) . '.' . $extension;\n }\n\n public function sanitizeFileName(string $fileName): string\n {\n return str_replace(['/', '\\\\'], '-', $fileName);\n }\n\n public function isUserRecipientOfReport(User $user, AutomatedReport $report): bool\n {\n $recipients = array_map('intval', $report->getRecipients()['users'] ?? []);\n\n return in_array($user->getId(), $recipients);\n }\n\n public function transformReportResults(Collection $automatedReportResults): array\n {\n $data = [];\n foreach ($automatedReportResults as $automatedReportResult) {\n /** @var AutomatedReportResult $automatedReportResult */\n\n $report = $automatedReportResult->getReport();\n\n $createdBy = $report->getCreator();\n $creator = [\n 'id' => $createdBy?->getUuid(),\n 'name' => $createdBy?->getName(),\n 'email' => $createdBy?->getEmailAddress(),\n 'photoUrl' => $createdBy?->getPhotoUrl(),\n ];\n\n $data[] = [\n 'id' => $automatedReportResult->getUuid(),\n 'name' => $automatedReportResult->getName(),\n 'frequency' => $this->transformFrequency($report->getFrequency()),\n 'recipients' => [\n ...array_values($this->transformGroups(team: $report->getTeam(), groupsIds: $report->getGroups())),\n ...array_values($this->transformRecipients($report->getRecipients())),\n ],\n 'report_type' => $this->transformReportType($report->getType()),\n 'media_type' => $automatedReportResult->getMediaType(),\n 'downloadUrl' => $this->generateReportResultDownloadUrl($automatedReportResult),\n 'viewUrl' => $this->generateReportResultViewUrl($automatedReportResult),\n 'generated_at' => $automatedReportResult->getGeneratedAt()?->toIso8601String(),\n 'creator' => $creator,\n ];\n }\n\n return $data;\n }\n\n public function hasCallTypeConference(AutomatedReport $report): bool\n {\n return in_array(self::CALL_TYPE_CONFERENCE['id'], $report->getCallTypes(), true);\n }\n\n public function hasCallTypeDialer(AutomatedReport $report): bool\n {\n return in_array(self::CALL_TYPE_DIALER['id'], $report->getCallTypes(), true);\n }\n\n // transformers\n private function transformTeam(Team $team): array\n {\n if (! $team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {\n return [];\n }\n\n return [\n 'id' => $team->getUuid(),\n 'name' => $team->getName(),\n ];\n }\n\n private function transformReportFullView(AutomatedReport $report): array\n {\n $base = $this->transformReportBase($report);\n\n return $report->getType() === self::TYPE_ASK_JIMINNY\n ? $base + $this->transformAskJiminnyFields($report)\n : $base + $this->transformStandardReportFields($report);\n }\n\n private function transformReportBase(AutomatedReport $report): array\n {\n return [\n 'id' => $report->getUuid(),\n 'organization' => $this->transformOrganization(team: $report->getTeam()),\n 'report_type' => $this->transformReportType($report->getType()),\n 'frequency' => $this->transformFrequency($report->getFrequency()),\n ];\n }\n\n private function transformStandardReportFields(AutomatedReport $report): array\n {\n $team = $report->getTeam();\n\n return [\n 'report_enabled' => $report->getStatus(),\n 'start_date_period' => $report->getFrom()?->format('Y-m-d H:i:s'),\n 'end_date_period' => $report->getTo()?->format('Y-m-d H:i:s'),\n 'deal_value_min' => $report->getDealValueMin(),\n 'deal_value_max' => $report->getDealValueMax(),\n 'call_types' => $this->transformCallType($report->getCallTypes()),\n 'media_types' => $this->transformMediaTypes($report),\n 'call_duration_min' => $this->transformDurationToMinutes($report->getCallDurationMin()),\n 'call_duration_max' => $this->transformDurationToMinutes($report->getCallDurationMax()),\n 'teams' => $this->transformGroups(team: $team, groupsIds: $report->getGroups()),\n 'deal_at_call_stages' => $this->transformStages(team: $team, stagesIds: $report->getDealAtCallStages()),\n 'current_deal_stages' => $this->transformStages(team: $team, stagesIds: $report->getCurrentDealStages()),\n 'recipients' => $this->transformRecipients($report->getRecipients()),\n 'created_by' => $this->transformCreator($report->getCreator()),\n 'additional_prompt_input' => $report->getAdditionalPromptInput(),\n 'custom_name' => $report->getCustomName(),\n 'created_at' => $report->getCreatedAt()->format('Y-m-d H:i:s'),\n 'updated_at' => $report->getUpdatedAt()->format('Y-m-d H:i:s'),\n 'deleted_at' => $report->getDeletedAt()?->format('Y-m-d H:i:s'),\n ];\n }\n\n private function transformAskJiminnyFields(AutomatedReport $report): array\n {\n $team = $report->getTeam();\n $creatorId = $report->getAttribute('created_by');\n $explicitUserIds = array_values(array_filter(\n $report->getRecipients()['users'] ?? [],\n static fn ($id) => $id !== $creatorId\n ));\n\n return [\n 'report_name' => $report->getCustomName(),\n 'enabled' => $report->getStatus(),\n 'share_teams' => $this->transformGroups(team: $team, groupsIds: $report->getGroups()),\n 'share_users' => $this->transformRecipients(['users' => $explicitUserIds]),\n 'saved_search' => $this->transformSafeSearch($report->getSavedSearch()),\n 'ask_jiminny_prompt' => $this->transformAskJiminnyPrompt($report->getAskAnythingPrompt()),\n 'expires_on' => $report->getExpiresAt()?->format('Y-m-d'),\n ];\n }\n\n private function transformOrganization(?Team $team): array\n {\n return [\n 'id' => $team?->getUuid(),\n 'name' => $team?->getName(),\n ];\n }\n\n private function transformReportType(string $type): array\n {\n foreach (self::ALL_TYPES as $typeItem) {\n if ($typeItem['id'] === $type) {\n return $typeItem;\n }\n }\n\n return [];\n }\n\n private function transformCallType(array $types): array\n {\n $result = [];\n $callTypes = [self::CALL_TYPE_CONFERENCE, self::CALL_TYPE_DIALER];\n\n foreach ($types as $type) {\n foreach ($callTypes as $callTypeItem) {\n if ($callTypeItem['id'] === $type) {\n $result[] = $callTypeItem;\n\n break;\n }\n }\n }\n\n return $result;\n }\n\n private function transformMediaTypes(AutomatedReport $report): array\n {\n $values = [];\n\n foreach ($report->getMediaTypes() as $mediaType) {\n if (! in_array($mediaType, self::MEDIA_TYPES, true)) {\n continue;\n }\n\n $values[] = match ($mediaType) {\n self::MEDIA_TYPE_PDF => self::MEDIA_TYPE_OBJECT_PDF,\n self::MEDIA_TYPE_PODCAST => self::MEDIA_TYPE_OBJECT_PODCAST,\n };\n }\n\n return $values;\n }\n\n private function transformFrequency(string $frequency): array\n {\n foreach (self::ALL_FREQUENCIES as $frequencyItem) {\n if ($frequencyItem['id'] === $frequency) {\n return $frequencyItem;\n }\n }\n\n return [];\n }\n\n public function transformDurationToMinutes(?int $duration): ?int\n {\n if (! $duration) {\n return null;\n }\n\n return (int) ($duration / 60);\n }\n\n private function transformGroups(?Team $team, array $groupsIds): array\n {\n if (empty($groupsIds) || ! $team) {\n return [];\n }\n\n $data = [];\n foreach ($groupsIds as $groupId) {\n $group = $team->groups()->where('id', $groupId)->first();\n\n if ($group) {\n $data[] = [\n 'id' => $group->getUuid(),\n 'name' => $group->getName(),\n 'photoUrl' => $group->getPhotoUrl(),\n ];\n }\n }\n\n return $data;\n }\n\n private function transformStages(?Team $team, array $stagesIds): array\n {\n if (empty($stagesIds) || ! $team) {\n return [];\n }\n\n $data = [];\n foreach ($stagesIds as $stageId) {\n $stage = $team->stages()->where('id', $stageId)->first();\n\n if ($stage) {\n $data[] = [\n 'id' => $stage->getUuid(),\n 'name' => $stage->getName(),\n ];\n }\n }\n\n return $data;\n }\n\n private function transformRecipients(array $recipients): array\n {\n $users = [];\n foreach ($recipients['users'] ?? [] as $userId) {\n $users[] = $this->transformUser($userId);\n }\n\n return $users;\n }\n\n private function transformCreator(?User $user): ?array\n {\n if ($user === null) {\n return null;\n }\n\n return $this->transformUser($user->getId());\n }\n\n private function transformAskJiminnyPrompt(?AskAnythingPrompt $prompt): ?array\n {\n if ($prompt === null) {\n return null;\n }\n\n return [\n 'id' => $prompt->getUuid(),\n 'name' => $prompt->getTitle(),\n ];\n }\n\n private function transformSafeSearch(?Search $search): ?array\n {\n if ($search === null) {\n return null;\n }\n\n return [\n 'id' => $search->getUuid(),\n 'name' => $search->getName(),\n ];\n }\n\n private function transformUser(int $userId): array\n {\n /* @var ?User $user */\n $user = $this->userRepository->find($userId);\n\n return [\n 'id' => $user?->getUuid(),\n 'name' => $user?->getName(),\n 'email' => $user?->getEmailAddress(),\n 'photoUrl' => $user?->getPhotoUrl(),\n ];\n }\n\n public function create(array $data): array\n {\n $validatedData = $this->validateAndTransformData($data);\n $validatedData['created_by'] = auth()->id();\n\n $automatedReport = $this->automatedReportsRepository->create($validatedData);\n\n $this->generateOneOffReport($automatedReport);\n\n return $this->transformReportFullView($automatedReport);\n }\n\n public function update(string $uuid, array $data): array\n {\n $validatedData = $this->validateAndTransformData($data);\n $report = $this->automatedReportsRepository->findByUuid($uuid);\n\n if (! $report) {\n throw new InvalidArgumentException('Report not found');\n }\n\n $oldCustomName = $report->getCustomName();\n\n $automatedReport = $this->automatedReportsRepository->update($report, $validatedData);\n\n if ($oldCustomName !== $automatedReport->getCustomName()) {\n $this->updateResultNames($automatedReport);\n }\n\n $this->generateOneOffReport($automatedReport);\n\n return $this->transformReportFullView($automatedReport);\n }\n\n /**\n * Create an Ask Jiminny report.\n */\n public function createAskJiminnyReport(array $data, User $creator): array\n {\n $validatedData = $this->validateAskJiminnyReportData($data, $creator);\n $validatedData['created_by'] = $creator->getId();\n\n $automatedReport = $this->automatedReportsRepository->create($validatedData);\n\n return $this->transformReportFullView($automatedReport);\n }\n\n /**\n * Update an Ask Jiminny report.\n */\n public function updateAskJiminnyReport(AutomatedReport $report, array $data, User $user): array\n {\n if (! $report->isAskJiminnyReport()) {\n throw new InvalidArgumentException('Report is not an Ask Jiminny report');\n }\n\n $validatedData = $this->validateAskJiminnyReportData($data, $user);\n\n $oldCustomName = $report->getCustomName();\n\n $automatedReport = $this->automatedReportsRepository->update($report, $validatedData);\n\n if ($oldCustomName !== $automatedReport->getCustomName()) {\n $this->updateResultNames($automatedReport);\n }\n\n return $this->transformReportFullView($automatedReport);\n }\n\n public function updateAskJiminnyReportStatus(AutomatedReport $report, bool $status): array\n {\n $this->automatedReportsRepository->update($report, ['status' => $status]);\n\n return $this->transformReportFullView($report->fresh());\n }\n\n /**\n * Validate and transform data for Ask Jiminny reports.\n */\n private function validateAskJiminnyReportData(array $data, User $user): array\n {\n // Validate name\n $name = trim($data['report_name'] ?? '');\n if (empty($name)) {\n throw new InvalidArgumentException('Report name is required');\n }\n if (mb_strlen($name) > 50) {\n throw new InvalidArgumentException('Report name must be 50 characters or less');\n }\n\n // Validate frequency (only daily, weekly, monthly for Ask Jiminny)\n $frequency = $data['frequency'] ?? null;\n $askJiminnyFrequencies = [self::FREQUENCY_DAILY, self::FREQUENCY_WEEKLY, self::FREQUENCY_MONTHLY];\n if (! in_array($frequency, $askJiminnyFrequencies, true)) {\n throw new InvalidArgumentException('Frequency must be daily, weekly, or monthly');\n }\n\n // Validate expiration date\n $expiresAt = $data['expires_on'] ?? null;\n if (empty($expiresAt)) {\n throw new InvalidArgumentException('Expiration date is required');\n }\n\n try {\n $expiresAtDate = Carbon::parse($expiresAt);\n } catch (InvalidFormatException $e) {\n throw new InvalidArgumentException('Expiration date format is invalid');\n }\n $maxExpiration = Carbon::now()->addYear();\n if ($expiresAtDate->gt($maxExpiration)) {\n throw new InvalidArgumentException('Expiration date cannot be more than 1 year from now');\n }\n if ($expiresAtDate->isPast()) {\n throw new InvalidArgumentException('Expiration date cannot be in the past');\n }\n\n // Validate saved search\n $activitySearchId = $data['saved_search'] ?? null;\n if (empty($activitySearchId)) {\n throw new InvalidArgumentException('Saved search is required');\n }\n $savedSearch = $this->activitySearchRepository->findByUuidAndUser($activitySearchId, $user);\n if (! $savedSearch) {\n throw new InvalidArgumentException('Saved search not found or does not belong to you');\n }\n\n // Validate saved prompt\n $askAnythingPromptId = $data['ask_jiminny_prompt'] ?? null;\n if (empty($askAnythingPromptId)) {\n throw new InvalidArgumentException('Ask Jiminny prompt is required');\n }\n $prompt = $this->askAnythingRepository->getPromptByUuid($askAnythingPromptId);\n if (! $prompt) {\n throw new InvalidArgumentException('Ask Jiminny prompt not found');\n }\n\n // Validate status\n $status = $data['enabled'] ?? false;\n\n $recipientUserIds = [$user->getId()];\n\n if (! empty($data['share_users'])) {\n $sharedUserIds = $this->validateAndGetUserIdsByTeam(\n $user->team,\n (array) $data['share_users']\n );\n $recipientUserIds = array_merge($recipientUserIds, $sharedUserIds);\n }\n\n $sharedGroupIds = [];\n if (! empty($data['share_teams'])) {\n $sharedGroupIds = $this->validateAndGetGroupIds($user->team, (array) $data['share_teams']);\n }\n\n $recipientUserIds = array_values(array_unique($recipientUserIds));\n\n return [\n 'team_id' => $user->getTeamId(),\n 'type' => self::TYPE_ASK_JIMINNY,\n 'status' => (bool) $status,\n 'frequency' => $frequency,\n 'custom_name' => $name,\n 'activity_search_id' => $savedSearch->getId(),\n 'ask_anything_prompt_id' => $prompt->getId(),\n 'expires_at' => $expiresAtDate->toDateString(),\n 'media_types' => [self::MEDIA_TYPE_PDF],\n 'call_types' => [],\n 'recipients' => ['users' => $recipientUserIds],\n 'groups' => $sharedGroupIds,\n ];\n }\n\n public static function getAskJiminnyFrequencies(): array\n {\n return array_map(static function ($frequency) {\n return $frequency['id'];\n }, self::ASK_JIMINNY_FREQUENCIES);\n }\n\n public function getAskJiminnyReportFilters(User $user): array\n {\n $savedSearches = $this->activitySearchRepository->findByUserOrderedByName($user)\n ->map(fn (Search $search) => [\n 'id' => $search->getUuid(),\n 'name' => $search->getName(),\n ])\n ->values()->all();\n\n $prompts = collect(\n $this->askAnythingPromptService->get($user, AskAnythingPromptTarget::on_demand)\n )->map(fn (AskAnythingPromptDto $prompt) => [\n 'id' => $prompt->id,\n 'name' => $prompt->title,\n ])->values()->all();\n\n return [\n [\n 'id' => 'prompt',\n 'label' => 'Prompt',\n 'options' => $prompts,\n ],\n [\n 'id' => 'saved_search',\n 'label' => 'Saved Search',\n 'options' => $savedSearches,\n ],\n ];\n }\n\n public function getAskJiminnyReportFormData(User $user, ?AutomatedReport $report = null): array\n {\n $team = $user->getTeam();\n $userTimezone = $user->getTimezone();\n\n $savedSearches = $this->activitySearchRepository->findByUserOrderedByName($user)\n ->map(fn (Search $search) => [\n 'id' => $search->getUuid(),\n 'name' => $search->getName(),\n ])\n ->values()->all();\n\n $prompts = collect(\n $this->askAnythingPromptService->get($user, AskAnythingPromptTarget::on_demand)\n )->map(fn (AskAnythingPromptDto $prompt) => [\n 'id' => $prompt->id,\n 'name' => $prompt->title,\n ])->values()->all();\n\n $teamGroups = $this->groupRepository->getAllByTeam($team)->map(fn ($group) => [\n 'id' => $group->getUuid(),\n 'name' => $group->getName(),\n ])->values()->all();\n\n $shareUsers = $this->recipientsService->getRecipientsFieldData(team: $team)['options'] ?? [];\n\n $sharedTeamsValue = [];\n $sharedUsersValue = [];\n if ($report) {\n $sharedTeamsValue = $this->transformGroups($team, $report->getGroups());\n\n $recipientUserIds = $report->getRecipients()['users'] ?? [];\n $creatorId = $report->getAttribute('created_by');\n $sharedUserIds = array_values(array_filter(\n $recipientUserIds,\n static fn ($id) => $id !== $creatorId\n ));\n $sharedUsersValue = collect($sharedUserIds)\n ->map(fn ($id) => $this->userRepository->find((int) $id))\n ->filter()\n ->map(fn (User $u) => [\n 'id' => $u->getUuid(),\n 'name' => $u->getName(),\n ])\n ->values()\n ->all();\n }\n\n return [\n 'fields' => [\n [\n 'id' => 'enabled',\n 'inputType' => InputTypeEnum::TOGGLE,\n 'label' => '',\n 'value' => $report?->getStatus() ?? false,\n ],\n [\n 'id' => 'report_name',\n 'inputType' => InputTypeEnum::TEXT,\n 'label' => 'Name',\n 'placeholder' => 'Enter name',\n 'required' => true,\n 'validation' => ['maxLength' => 50],\n 'value' => $report?->getCustomName() ?? '',\n ],\n [\n 'id' => 'frequency',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'label' => 'Frequency',\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => self::ASK_JIMINNY_FREQUENCIES,\n 'value' => $report ? $this->transformFrequency($report->getFrequency()) : null,\n ],\n [\n 'id' => 'expires_on',\n 'inputType' => InputTypeEnum::DATE,\n 'label' => 'Expires on',\n 'required' => true,\n 'placeholder' => 'Select',\n 'validation' => [\n 'minDate' => now($userTimezone)->toDateString(),\n 'maxDate' => now($userTimezone)->addYear()->toDateString(),\n ],\n 'value' => $report?->getExpiresAt()?->toDateString(),\n ],\n [\n 'id' => 'share_teams',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'label' => 'Team',\n 'required' => false,\n 'placeholder' => 'Select',\n 'options' => $teamGroups,\n 'value' => $sharedTeamsValue,\n ],\n [\n 'id' => 'share_users',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'label' => 'Team member',\n 'required' => false,\n 'placeholder' => 'Select',\n 'groupLabelKey' => 'label',\n 'groupValuesKey' => 'users',\n 'optionLabelKey' => 'name',\n 'optionValueKey' => 'id',\n 'options' => $shareUsers,\n 'value' => $sharedUsersValue,\n ],\n [\n 'id' => 'saved_search',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'label' => 'Saved search',\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => $savedSearches,\n 'value' => $report && $report->getSavedSearch() ? [\n 'id' => $report->getSavedSearch()->getUuid(),\n 'name' => $report->getSavedSearch()->getName(),\n ] : null,\n ],\n [\n 'id' => 'ask_jiminny_prompt',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'label' => 'Ask Jiminny prompt',\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => $prompts,\n 'value' => $report && $report->getAskAnythingPrompt() ? [\n 'id' => $report->getAskAnythingPrompt()->getUuid(),\n 'name' => $report->getAskAnythingPrompt()->getTitle(),\n ] : null,\n ],\n ],\n ];\n }\n\n private function updateResultNames(AutomatedReport $automatedReport): void\n {\n $results = $this->automatedReportsRepository->getResultsByReport($automatedReport);\n\n foreach ($results as $result) {\n $result->update(['name' => $this->getReportFileName($result)]);\n }\n }\n\n public function updateStatus(string $uuid, array $data): array\n {\n $automatedReport = $this->automatedReportsRepository->findByUuid($uuid);\n\n if (! $automatedReport) {\n throw new ModelNotFoundException('Report not found');\n }\n\n $status = $this->validateReportStatus($data['report_enabled'] ?? null);\n $automatedReport->update([\n 'status' => $status,\n ]);\n\n $this->generateOneOffReport($automatedReport);\n\n return $this->transformReportFullView($automatedReport);\n }\n\n private function generateOneOffReport(AutomatedReport $automatedReport): void\n {\n // the scheduler handles all the other frequency types\n if ($automatedReport->getStatus() === false || $automatedReport->getFrequency() !== self::FREQUENCY_ONE_OFF) {\n return;\n }\n\n $this->dispatcher->dispatch(new RequestGenerateReportJob($automatedReport->getUuid()));\n }\n\n public function getReport(string $uuid): AutomatedReport\n {\n $automatedReport = $this->automatedReportsRepository->findByUuid($uuid);\n\n if (! $automatedReport) {\n throw new ModelNotFoundException('Report not found');\n }\n\n return $automatedReport;\n }\n\n public function get(string $uuid): array\n {\n $automatedReport = $this->getReport($uuid);\n\n return $this->transformReportFullView($automatedReport);\n }\n\n public function list(string $sortColumn = 'created_at', string $sortDirection = 'desc'): array\n {\n $results = [];\n $collection = $this->automatedReportsRepository->getAllStandardReports($sortColumn, $sortDirection);\n\n /** @var AutomatedReport $report */\n foreach ($collection as $report) {\n $results[] = $this->transformReportFullView($report);\n }\n\n return ['data' => $results];\n }\n\n public function listAskJiminnyReports(\n User $user,\n string $sortColumn = 'created_at',\n string $sortDirection = 'desc'\n ): array {\n $results = [];\n $collection = $this->automatedReportsRepository->getAskJiminnyReportsByUser($user, $sortColumn, $sortDirection);\n\n /** @var AutomatedReport $report */\n foreach ($collection as $report) {\n $results[] = $this->transformReportFullView($report);\n }\n\n return ['data' => $results];\n }\n\n public function delete(string $uuid): void\n {\n $automatedReport = $this->automatedReportsRepository->findByUuid($uuid);\n\n if (! $automatedReport) {\n throw new ModelNotFoundException('Report not found');\n }\n\n $automatedReport->delete();\n }\n\n public function createReportResult(AutomatedReport $automatedReport, array $data = []): AutomatedReportResult\n {\n return $this->automatedReportsRepository->createResult(\n array_merge(\n [\n 'report_id' => $automatedReport->getId(),\n 'status' => AutomatedReportResult::STATUS_DEFAULT,\n ],\n $data\n )\n );\n }\n\n public function getReportResult(string $resultUuid): AutomatedReportResult\n {\n $report = $this->automatedReportsRepository->findResultByUuid($resultUuid);\n\n if (! $report) {\n throw new ModelNotFoundException('Report Result not found');\n }\n\n return $report;\n }\n\n public function findChildResult(AutomatedReportResult $result, string $type): ?AutomatedReportResult\n {\n return $this->automatedReportsRepository->findChildResult($result, $type);\n }\n\n // prophet API calls\n /**\n * @throws ApplicationException\n */\n public function getGenerateReportPayload(AutomatedReport $automatedReport, string $reportResultUuid): array\n {\n $period = $this->calculateFromAndToDate($automatedReport);\n $fromDate = $period['fromDate'];\n $toDate = $period['toDate'];\n\n return [\n 'team_id' => $automatedReport->getTeamId(),\n 'request_id' => $reportResultUuid,\n 'report_type' => $automatedReport->getType(),\n 'media_types' => $automatedReport->getMediaTypes(),\n 'from_date' => $fromDate->startOfDay()->format(DateTimeInterface::RFC3339),\n 'to_date' => $toDate->endOfDay()->format(DateTimeInterface::RFC3339),\n 'group_ids' => $automatedReport->getGroups(),\n 'call_deal_stage' => $automatedReport->getDealAtCallStages(),\n 'current_deal_stage' => $automatedReport->getCurrentDealStages(),\n 'deal_min_value' => $automatedReport->getDealValueMin(),\n 'deal_max_value' => $automatedReport->getDealValueMax(),\n 'call_types' => $automatedReport->getCallTypes(),\n 'call_duration_min_seconds' => $automatedReport->getCallDurationMin(),\n 'call_duration_max_seconds' => $automatedReport->getCallDurationMax(),\n 'special_requirements' => $automatedReport->getAdditionalPromptInput(),\n 'callback_url' => $this->getCallbackUrl(),\n 'report_period' => $this->formatReportPeriodName(\n $automatedReport->getFrequency(),\n $fromDate,\n $toDate,\n ),\n 'playbook_categories' => $automatedReport->getPlaybookCategories(),\n 'custom_name' => $automatedReport->getCustomName(),\n ];\n }\n\n // $inputPayload - FE payload structure\n public function getActivitiesCountPayload(array $inputPayload): array\n {\n // Use validateAndTransformData to validate and normalize input\n $validatedData = $this->validateAndTransformData($inputPayload);\n $period = $this->calculateFromAndToDatePeriod(\n $validatedData['frequency'],\n Carbon::parse($validatedData['from']),\n Carbon::parse($validatedData['to']),\n );\n $fromDate = $period['fromDate'];\n $toDate = $period['toDate'];\n\n // Create payload similar to getGenerateReportPayload\n return [\n 'team_id' => $validatedData['team_id'],\n 'group_ids' => $validatedData['groups'] ?? [],\n 'report_type' => $validatedData['type'],\n 'from_date' => $fromDate->format(DateTimeInterface::RFC3339),\n 'to_date' => $toDate->format(DateTimeInterface::RFC3339),\n 'call_deal_stage' => $validatedData['deal_at_call_stages'] ?? [],\n 'current_deal_stage' => $validatedData['current_deal_stages'] ?? [],\n 'deal_min_value' => $validatedData['deal_value_min'] ?? null,\n 'deal_max_value' => $validatedData['deal_value_max'] ?? null,\n 'call_types' => $validatedData['call_types'],\n 'call_duration_min_seconds' => $validatedData['call_duration_min'] ?? null,\n 'call_duration_max_seconds' => $validatedData['call_duration_max'] ?? null,\n 'special_requirements' => $validatedData['additional_prompt_input'] ?? null,\n 'playbook_categories' => $validatedData['playbook_categories'] ?? [],\n 'request_id' => null,\n 'callback_url' => null,\n ];\n }\n\n public function shouldSendReport(array $users, ?CarbonInterface $generatedAt = null): bool\n {\n if (empty($users)) {\n return false;\n }\n\n $earliestTz = collect($users)\n ->mapWithKeys(function (array $user) {\n $tz = new DateTimeZone($user['timezone']);\n $nowUtc = new DateTime('now', new DateTimeZone('UTC'));\n $offset = $tz->getOffset($nowUtc);\n\n return [$user['timezone'] => $offset];\n })\n ->sortDesc()\n ->keys()\n ->first();\n\n $now = Carbon::now($earliestTz);\n $isScheduledTime = (int) $now->format('H') === self::SENT_REPORT_AT_HOURS;\n\n if ($isScheduledTime) {\n return true;\n }\n\n return $this->hasPassedScheduledTime($generatedAt, $earliestTz);\n }\n\n public function hasPassedScheduledTime(?CarbonInterface $generatedAt, string $timezone): bool\n {\n if ($generatedAt === null) {\n return false;\n }\n\n $now = Carbon::now($timezone);\n $scheduledTime = $now->copy()->setTime(self::SENT_REPORT_AT_HOURS, 0, 0);\n\n if ($now->hour < self::SENT_REPORT_AT_HOURS) {\n $scheduledTime = $scheduledTime->subDay();\n }\n\n $scheduledTimeUtc = $scheduledTime->copy()->utc();\n $generatedAtUtc = $generatedAt->copy()->utc();\n $nowUtc = $now->copy()->utc();\n\n return $generatedAtUtc->lt($scheduledTimeUtc) && $nowUtc->gt($scheduledTimeUtc);\n }\n\n public function calculateFromAndToDatePeriod(\n string $frequency,\n ?Carbon $fromDate = null,\n ?Carbon $toDate = null\n ): array {\n if ($frequency === self::FREQUENCY_ONE_OFF) {\n return [\n 'fromDate' => $fromDate,\n 'toDate' => $toDate,\n ];\n }\n\n $now = Carbon::now();\n\n return match ($frequency) {\n self::FREQUENCY_DAILY => [\n 'fromDate' => $now->copy()->subDay()->startOfDay(),\n 'toDate' => $now->copy()->subDay()->endOfDay(),\n ],\n self::FREQUENCY_WEEKLY => [\n 'fromDate' => $now->copy()->subWeeks(1)->startOfDay(),\n 'toDate' => $now->copy()->subDay()->endOfDay(),\n ],\n self::FREQUENCY_MONTHLY => [\n 'fromDate' => $now->copy()->subMonths(1)->startOfDay(),\n 'toDate' => $now->copy()->subDay()->endOfDay(),\n ],\n self::FREQUENCY_QUARTERLY => [\n 'fromDate' => $now->copy()->subMonths(3)->startOfDay(),\n 'toDate' => $now->copy()->subDay()->endOfDay(),\n ],\n default => throw new InvalidArgumentException(\"Unsupported frequency: {$frequency}\"),\n };\n }\n\n private function calculateFromAndToDate(AutomatedReport $automatedReport): array\n {\n return $this->calculateFromAndToDatePeriod(\n $automatedReport->getFrequency(),\n $automatedReport->getFrom(),\n $automatedReport->getTo()\n );\n }\n\n public function getAskJiminnyGenerateReportPayload(\n AutomatedReport $automatedReport,\n AutomatedReportResult $reportResult,\n array $activityIds,\n ): array {\n return [\n 'user_question' => $automatedReport->getAskAnythingPrompt()?->getContent(),\n 'call_ids' => array_map('strval', $activityIds),\n 'team_id' => $automatedReport->getTeamId(),\n 'request_id' => $reportResult->getUuid(),\n 'callback_url' => $this->getCallbackUrl(),\n 'report_period' => $this->getReportPeriodName($reportResult),\n 'report_name' => $automatedReport->getCustomName(),\n ];\n }\n\n private function getCallbackUrl(): string\n {\n return $this->webhookService->route('jiminny.webhook.reports.ready');\n }\n\n /**\n * Validate and transform payload data for automated reports\n *\n * @param array $data\n *\n * @throws InvalidArgumentException\n *\n * @return array\n */\n private function validateAndTransformData(array $data): array\n {\n // Validate organization (team) and check feature\n $team = $this->validateOrganization($data['organization'] ?? null);\n\n $status = $this->validateReportStatus($data['report_enabled'] ?? null);\n $type = $this->validateReportType($data['report_type'] ?? null);\n $frequency = $this->validateFrequency($data['frequency'] ?? null);\n $additionalPromptInput = $this->validateAdditionalPromptInput(\n $data['additional_prompt_input'] ?? null\n );\n $customReportName = $this->validateCustomReportName($data['custom_name'] ?? null);\n\n // Prepare data for the database\n $reportData = [\n 'team_id' => $team->getId(),\n 'type' => $type,\n 'status' => $status,\n 'frequency' => $frequency,\n 'additional_prompt_input' => $additionalPromptInput,\n 'custom_name' => $customReportName,\n ];\n\n // Validate deal values\n $reportData = $this->validateDealValues($data, $reportData);\n\n // Validate date range\n $reportData = $this->validateDateRange($data, $reportData, $frequency);\n\n // Validate call durations\n $reportData = $this->validateCallDurations($data, $reportData);\n\n // Validate call types\n $reportData = $this->validateCallTypes($data, $reportData);\n\n // Validate media types\n $reportData = $this->validateMediaTypes($data, $reportData);\n\n // Validate groups\n if (isset($data['teams'])) {\n $reportData['groups'] = $this->validateAndGetGroupIds($team, $data['teams']);\n }\n\n // Validate deal stages\n $reportData = $this->validateDealStages($data, $reportData, $team, $type);\n\n // Validate playbook categories\n $reportData = $this->validatePlaybookCategories($data, $reportData, $team);\n\n // Validate recipients\n $reportData['recipients'] = [\n 'users' => $this->validateAndGetUserIdsByTeam($team, $data['recipients'] ?? []),\n ];\n\n if (isset($data['jiminny_recipients'])) {\n // Validate Jiminny recipients\n $reportData['jiminny_recipients'] = [\n 'users' => $this->validateAndGetJiminnyUserIds((array) $data['jiminny_recipients']),\n ];\n }\n\n return $reportData;\n }\n\n private function validateDealValues(array $data, array $reportData): array\n {\n if (isset($data['min_deal_value'])) {\n $reportData['deal_value_min'] = (int) $data['min_deal_value'];\n\n if ($reportData['deal_value_min'] > 4294967295 || $reportData['deal_value_min'] < 0) {\n throw new InvalidArgumentException('Min deal value should be between 0 and 4294967295');\n }\n }\n\n if (isset($data['max_deal_value'])) {\n $reportData['deal_value_max'] = (int) $data['max_deal_value'];\n\n if ($reportData['deal_value_max'] > 4294967295 || $reportData['deal_value_max'] < 0) {\n throw new InvalidArgumentException('Max deal value should be between 0 and 4294967295');\n }\n }\n\n if (isset($data['min_deal_value'], $data['max_deal_value'])\n && $data['min_deal_value'] > $data['max_deal_value']\n ) {\n throw new InvalidArgumentException('Min deal value cannot be greater than max deal value');\n }\n\n return $reportData;\n }\n\n private function validateDateRange(array $data, array $reportData, string $frequency): array\n {\n // Set date range only for one_off frequency\n if ($frequency === 'one_off') {\n if (isset($data['start_date_period'])) {\n $reportData['from'] = $this->parseDate($data['start_date_period']);\n }\n\n if (isset($data['end_date_period'])) {\n $reportData['to'] = $this->parseDate($data['end_date_period']);\n }\n\n if (empty($reportData['from']) || empty($reportData['to'])) {\n throw new InvalidArgumentException(\n 'Start date and end date are required for one_off frequency'\n );\n }\n } else {\n $reportData['from'] = null;\n $reportData['to'] = null;\n }\n\n return $reportData;\n }\n\n private function validateCallDurations(array $data, array $reportData): array\n {\n // Convert call durations from minutes to seconds\n if (isset($data['min_call_duration'])) {\n $reportData['call_duration_min'] = (int) $data['min_call_duration'] * 60;\n\n if ($reportData['call_duration_min'] > 4294967295 || $reportData['call_duration_min'] < 0) {\n throw new InvalidArgumentException('Min call duration should be between 0 and 4294967295');\n }\n }\n\n if (isset($data['max_call_duration'])) {\n $reportData['call_duration_max'] = (int) $data['max_call_duration'] * 60;\n\n if ($reportData['call_duration_max'] > 4294967295 || $reportData['call_duration_max'] < 0) {\n throw new InvalidArgumentException('Max call duration should be between 0 and 4294967295');\n }\n }\n\n return $reportData;\n }\n\n private function validateCallTypes(array $data, array $reportData): array\n {\n // Set call types\n $reportData['call_types'] = $data['call_type'] ?? [];\n if (empty($reportData['call_types'])) {\n $reportData['call_types'] = self::getCallTypes();\n }\n\n foreach ($reportData['call_types'] as $callType) {\n if (! in_array($callType, self::getCallTypes(), true)) {\n throw new InvalidArgumentException(sprintf('Call type %s is invalid', $callType));\n }\n }\n\n return $reportData;\n }\n\n private function validateMediaTypes(array $data, array $reportData): array\n {\n // Set media types from input data\n $reportData['media_types'] = $data['media_types'] ?? [];\n\n if (empty($reportData['media_types'])) {\n throw new InvalidArgumentException('Media types are required');\n }\n\n foreach ($reportData['media_types'] as $mediaType) {\n if (! in_array($mediaType, self::MEDIA_TYPES, true)) {\n throw new InvalidArgumentException(sprintf('Media type %s is invalid', $mediaType));\n }\n }\n\n return $reportData;\n }\n\n private function validateDealStages(array $data, array $reportData, Team $team, string $reportType): array\n {\n // Validate and set deal stages\n if (isset($data['deal_stage_at_call'])) {\n $reportData['deal_at_call_stages'] =\n $this->validateAndGetDealStageIds($team, $data['deal_stage_at_call'], 'Deal stage at call');\n }\n\n if (isset($data['current_deal_stage'])) {\n $reportData['current_deal_stages'] =\n $this->validateAndGetDealStageIds($team, $data['current_deal_stage'], 'Current deal stage');\n }\n\n // Ensure current_deal_stage is not provided for loss_analysis report type\n if ($reportType === self::TYPE_LOSS_ANALYSIS && ! empty($data['current_deal_stage'])) {\n throw new InvalidArgumentException('Current deal stage is not applicable for Loss Analysis reports');\n }\n\n return $reportData;\n }\n\n // transform uuid to id\n private function validatePlaybookCategories(array $data, array $reportData, Team $team): array\n {\n $key = 'playbook_categories';\n\n if (isset($data[$key])) {\n $payloadIds = $data[$key];\n $ids = [];\n\n foreach ($payloadIds as $uuid) {\n $uuid = (string) $uuid;\n\n try {\n $playbookCategory = $this->playbookCategoryRepository->findByUuid($uuid);\n } catch (Throwable $throwable) {\n Log::error(__METHOD__ . ' ' . $throwable->getMessage());\n\n throw new InvalidArgumentException(sprintf('Playbook category %s not found', $uuid));\n }\n\n if (! $playbookCategory) {\n throw new InvalidArgumentException(sprintf('Playbook category %s not found', $uuid));\n }\n\n if (! $playbookCategory->hasPlaybook()) {\n throw new InvalidArgumentException(sprintf('Playbook category %s has no playbook', $uuid));\n }\n\n if ($playbookCategory->getPlaybook()->getTeamId() !== $team->getId()) {\n throw new InvalidArgumentException(\n sprintf('Playbook category %s not found for team %s', $uuid, $team->getUuid())\n );\n }\n\n $ids[] = $playbookCategory->getId();\n }\n\n $reportData[$key] = $ids;\n }\n\n return $reportData;\n }\n\n private function validateReportStatus($status): bool\n {\n if (! in_array($status, [true, false], true)) {\n throw new InvalidArgumentException('Report status is invalid');\n }\n\n return $status;\n }\n\n private function validateReportType($type): string\n {\n if (! in_array($type, self::getTypes(), true)) {\n throw new InvalidArgumentException(sprintf('Report type is invalid: %s', $type));\n }\n\n return $type;\n }\n\n private function validateFrequency($frequency): string\n {\n if (! in_array($frequency, self::getFrequencies(), true)) {\n throw new InvalidArgumentException('Frequency is invalid');\n }\n\n return $frequency;\n }\n\n private function validateAdditionalPromptInput(?string $additionalPromptInput): ?string\n {\n if ($additionalPromptInput && strlen($additionalPromptInput) > 5000) {\n throw new InvalidArgumentException('Additional Prompt Input should be less than 5000 characters');\n }\n\n return $additionalPromptInput;\n }\n\n private function validateCustomReportName(?string $customReportName): ?string\n {\n if ($customReportName === null || $customReportName === '') {\n return null;\n }\n\n if (strlen($customReportName) > 70) {\n throw new InvalidArgumentException('Custom report name should be less than 70 characters');\n }\n\n return $customReportName;\n }\n\n private function validateOrganization(?string $organizationUuid): Team\n {\n if (! $organizationUuid) {\n throw new InvalidArgumentException('Organization is required');\n }\n\n $team = $this->teamRepository->idOrUuid($organizationUuid);\n\n if (! $team) {\n throw new InvalidArgumentException('Organization not found');\n }\n\n if (! $team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {\n throw new InvalidArgumentException('Organization does not have the Automated Reports feature');\n }\n\n return $team;\n }\n\n private function validateAndGetGroupIds(Team $team, array $teamUuids): array\n {\n $groupIds = [];\n\n foreach ($teamUuids as $uuid) {\n $group = $this->groupRepository->findByUuid($uuid);\n\n if ($group === null || $group->getTeamId() !== $team->getId()) {\n throw new InvalidArgumentException(\n sprintf('Group %s not found for team %s', $uuid, $team->getUuid())\n );\n }\n\n $groupIds[] = $group->getId();\n\n }\n\n return $groupIds;\n }\n\n private function validateAndGetDealStageIds(Team $team, array $stageUuids, string $propertyLabel): array\n {\n $stageIds = [];\n\n foreach ($stageUuids as $uuid) {\n $stage = $this->stageRepository->findByUuid($uuid);\n\n if ($stage === null || $stage->getTeamId() !== $team->getId()) {\n throw new InvalidArgumentException(\n sprintf('Stage %s not found for team %s for %s', $uuid, $team->getUuid(), $propertyLabel)\n );\n }\n\n $stageIds[] = $stage->getId();\n }\n\n return $stageIds;\n }\n\n private function validateAndGetUserIds(array $userUuids, callable $teamCheck): array\n {\n if (empty($userUuids)) {\n return [];\n }\n\n $userIds = [];\n\n foreach ($userUuids as $uuid) {\n $user = $this->userRepository->findByUuid($uuid);\n\n if (! $user || ! $user->isStatusActive()) {\n throw new InvalidArgumentException(\n sprintf('User %s not found or is not active', $uuid)\n );\n }\n\n if (! $teamCheck($user)) {\n throw new InvalidArgumentException(\n sprintf('User %s does not belong to the allowed team(s)', $uuid)\n );\n }\n\n $userIds[] = $user->getId();\n }\n\n return $userIds;\n }\n\n private function validateAndGetUserIdsByTeam(Team $team, array $userUuids): array\n {\n return $this->validateAndGetUserIds($userUuids, fn ($user) => $user->getTeamId() === $team->getId());\n }\n\n private function validateAndGetJiminnyUserIds(array $userUuids): array\n {\n $allowedTeamIds = config('kiosk.teamIds', []);\n\n return $this->validateAndGetUserIds($userUuids, fn ($user) => in_array($user->getTeamId(), $allowedTeamIds, true));\n }\n\n private function parseDate(string $dateString): string\n {\n return date('Y-m-d H:i:s', strtotime($dateString));\n }\n\n private function generateReportResultViewUrl(AutomatedReportResult $result): string\n {\n $mediaResource = $this->getReportMediaRouteResource($result);\n\n return route('ai-reports.' . $mediaResource . '.view', ['uuid' => $result->getUuid()]);\n }\n\n private function generateReportResultDownloadUrl(AutomatedReportResult $result): string\n {\n $mediaResource = $this->getReportMediaRouteResource($result);\n\n return route('ai-reports.' . $mediaResource . '.download', ['uuid' => $result->getUuid()]);\n }\n\n private function getReportMediaRouteResource(AutomatedReportResult $result): string\n {\n if ($result->getMediaType() === self::MEDIA_TYPE_PDF) {\n return self::PDF_KEY;\n } elseif ($result->getMediaType() === self::MEDIA_TYPE_PODCAST) {\n return self::AUDIO_KEY;\n }\n\n throw new \\InvalidArgumentException('Unknown media type.');\n }\n\n public function getMediaPath(AutomatedReportResult $result): ?string\n {\n $url = match ($result->getMediaType()) {\n self::MEDIA_TYPE_PDF => $result->getPdfUrl(),\n self::MEDIA_TYPE_PODCAST => $result->getPodcastAudioUrl(),\n default => null,\n };\n\n if ($url === null) {\n return null;\n }\n\n $path = parse_url(trim($url, '\"\\''), PHP_URL_PATH);\n\n return $path ?: null;\n }\n\n public function getFilenameSuffix(AutomatedReportResult $result): ?string\n {\n return match ($result->getMediaType()) {\n self::MEDIA_TYPE_PODCAST => 'Podcast',\n default => null,\n };\n }\n\n public function getMailSubjectSuffix(AutomatedReportResult $result): string\n {\n return match ($result->getMediaType()) {\n self::MEDIA_TYPE_PDF => 'report',\n self::MEDIA_TYPE_PODCAST => 'podcast',\n default => '',\n };\n }\n\n public function getMediaTypeMetadata(AutomatedReportResult $result): array\n {\n return match ($result->getMediaType()) {\n self::MEDIA_TYPE_PODCAST => ['extension' => 'mp3', 'mime' => 'audio/mpeg'],\n self::MEDIA_TYPE_PDF => ['extension' => 'pdf', 'mime' => 'application/pdf'],\n default => ['extension' => null, 'mime' => null],\n };\n }\n\n public function deleteS3Files(AutomatedReportResult $result): void\n {\n $teamUuid = $result->getReport()->getTeam()->getUuid();\n $reportUuid = $result->getUuid();\n\n // delete all files for a report uuid no mather of pdf, podcast, or both\n // in case of both - the podcast files are linked to the pdf (parent) uuid\n // pdf and podcast date times should be close\n $path = sprintf('%s/%s/%s', $teamUuid, self::S3_DIR, $reportUuid);\n\n foreach (self::FILE_EXTENSIONS_VARIANTS as $extension) {\n $file = $path . '.' . $extension;\n\n if (Storage::exists($file)) {\n Storage::delete($file);\n Log::info('[Reports] Deleted S3 file', [\n 'path' => $file,\n ]);\n }\n }\n\n foreach (self::FILE_PODCAST_EXTENSIONS_VARIANTS as $extension) {\n $file = $path . '_podcast.' . $extension;\n\n if (Storage::exists($file)) {\n Storage::delete($file);\n Log::info('[Reports] Deleted Podcast S3 file', [\n 'path' => $file,\n ]);\n }\n }\n }\n\n /**\n *\n * @param int|null $teamId Optional team ID to filter results\n *\n * @return Collection<int, int> Collection of team IDs\n */\n public function getTeamIdsWithReportsResults(?int $teamId = null): Collection\n {\n return $this->automatedReportsRepository->getTeamIdsWithReportsResults($teamId);\n }\n\n /**\n * Core delete logic for report results using a query\n *\n * @param Builder $query\n * @param array $logContext\n *\n * @return int\n */\n private function deleteReportResultsByQuery(Builder $query, array $logContext = []): int\n {\n $deletedCount = 0;\n\n if ($query->exists()) {\n Log::info(\n 'Run delete report results',\n array_merge(\n $logContext,\n [\n 'service' => 'AutomatedReportsService',\n ]\n )\n );\n\n $query->chunkById(50, function ($results) use (&$deletedCount, $logContext) {\n foreach ($results as $result) {\n $this->deleteReportResult($result);\n $deletedCount++;\n\n Log::info(\n 'Deleted a report result',\n array_merge(\n $logContext,\n [\n 'result_id' => $result->getId(),\n 'report_id' => $result->getReportId(),\n ]\n )\n );\n }\n });\n }\n\n return $deletedCount;\n }\n\n /**\n * Delete report results for a team by retention period\n *\n * @param Team $team\n * @param CarbonImmutable $retentionDate\n *\n * @return int Number of deleted report results\n */\n public function deleteReportsResultsInRetentionPeriod(Team $team, CarbonImmutable $retentionDate): int\n {\n $reportIds = $this->automatedReportsRepository->getReportIdsByTeam($team);\n\n if ($reportIds->isEmpty()) {\n return 0;\n }\n\n $query = $this->automatedReportsRepository\n ->getReportResultsQueryForRetention($team, $retentionDate);\n\n return $this->deleteReportResultsByQuery($query, [\n 'team_id' => $team->getId(),\n 'retention_date' => $retentionDate->toDateTimeString(),\n ]);\n }\n\n /**\n * Delete ALL report results for a specific automated report\n *\n * @param string $uuid\n *\n * @return int\n */\n public function deleteReportResults(string $uuid): int\n {\n $report = $this->getReport($uuid);\n\n $query = $this->automatedReportsRepository->getResultsByReportQuery($report);\n\n return $this->deleteReportResultsByQuery($query, [\n 'report_uuid' => $uuid,\n 'report_id' => $report->getId(),\n ]);\n }\n\n public function deleteReportResult(AutomatedReportResult $result): void\n {\n $this->deleteS3Files($result);\n\n $result->delete();\n }\n\n /**\n * Get all reports for a specific team\n *\n * @param Team $team\n *\n * @return \\Illuminate\\Database\\Eloquent\\Collection\n */\n public function getTeamReports(Team $team): \\Illuminate\\Database\\Eloquent\\Collection\n {\n return $this->automatedReportsRepository->getReportsByTeam($team);\n }\n\n /**\n * Get all report results for a specific report\n *\n * @param AutomatedReport $report\n *\n * @return \\Illuminate\\Database\\Eloquent\\Collection\n */\n public function getReportResults(AutomatedReport $report): \\Illuminate\\Database\\Eloquent\\Collection\n {\n return $this->automatedReportsRepository->getResultsByReport($report);\n }\n\n public function deleteAllReportResults(AutomatedReport $report): void\n {\n $results = $this->getReportResults($report);\n\n /** @var AutomatedReportResult $result */\n foreach ($results as $result) {\n Log::info('Deleting result', [\n 'report' => $report->getId(),\n 'result' => $result->getId(),\n ]);\n\n $this->deleteReportResult($result);\n }\n }\n\n public function deleteAllData(Team $team): void\n {\n Log::info('Deleting automated report and results for team', [\n 'team' => $team->getId(),\n ]);\n\n $reports = $this->getTeamReports($team);\n\n /** @var AutomatedReport $report */\n foreach ($reports as $report) {\n Log::info('Deleting report', [\n 'team' => $team->getId(),\n 'report' => $report->getId(),\n ]);\n\n $this->deleteAllReportResults($report);\n\n $report->delete();\n }\n }\n}","depth":4,"value":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Services\\Kiosk\\AutomatedReports;\n\nuse Carbon\\CarbonImmutable;\nuse Carbon\\CarbonInterface;\nuse Carbon\\Exceptions\\InvalidFormatException;\nuse DateTime;\nuse DateTimeInterface;\nuse DateTimeZone;\nuse Illuminate\\Contracts\\Bus\\Dispatcher as BusDispatcher;\nuse Illuminate\\Database\\Eloquent\\Builder;\nuse Illuminate\\Support\\Carbon;\nuse Illuminate\\Support\\Collection;\nuse Illuminate\\Support\\Facades\\Log;\nuse Illuminate\\Support\\Facades\\Storage;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinition\\InputTypeEnum;\nuse Jiminny\\Component\\AskAnything\\AskAnythingPromptService;\nuse Jiminny\\Component\\AskAnything\\Dtos\\AskAnythingPromptDto;\nuse Jiminny\\Component\\UrlGenerator\\Webhook;\nuse Jiminny\\Contracts\\Repositories\\PlaybookCategoryRepository;\nuse Jiminny\\Contracts\\Repositories\\TeamRepository;\nuse Jiminny\\Contracts\\Repositories\\UserRepository;\nuse Jiminny\\Exceptions\\ApplicationException;\nuse Jiminny\\Exceptions\\InvalidArgumentException;\nuse Jiminny\\Exceptions\\ModelNotFoundException;\nuse Jiminny\\Jobs\\AutomatedReports\\RequestGenerateReportJob;\nuse Jiminny\\Models\\Activity\\Search;\nuse Jiminny\\Models\\AskAnything\\AskAnythingPrompt;\nuse Jiminny\\Models\\AskAnything\\AskAnythingPromptTarget;\nuse Jiminny\\Models\\AutomatedReport;\nuse Jiminny\\Models\\AutomatedReportResult;\nuse Jiminny\\Models\\Contracts\\UserContract;\nuse Jiminny\\Models\\Feature\\FeatureEnum;\nuse Jiminny\\Models\\Team;\nuse Jiminny\\Models\\User;\nuse Jiminny\\Repositories\\AskAnythingRepository;\nuse Jiminny\\Repositories\\AutomatedReportsRepository;\nuse Jiminny\\Repositories\\GroupRepository;\nuse Jiminny\\Repositories\\SearchRepository;\nuse Jiminny\\Repositories\\StageRepository;\nuse Throwable;\n\nclass AutomatedReportsService\n{\n public const string TYPE_LOSS_ANALYSIS = 'loss_analysis';\n public const string TYPE_ASK_JIMINNY = 'ask_jiminny';\n\n /**\n * Standard report types (used by kiosk for existing automated reports).\n */\n // @TODO this will add filter, however if we need to control feature by FF we need conditional logic\n public const array TYPES = [\n ['id' => 'exec_summary', 'name' => 'Exec Summary'],\n ['id' => 'coaching_profiles', 'name' => 'Coaching Profiles'],\n ['id' => 'product_feedback', 'name' => 'Product Feedback'],\n ['id' => self::TYPE_LOSS_ANALYSIS, 'name' => 'Loss Analysis'],\n// ['id' => 'questions', 'name' => 'Questions'],\n// ['id' => 'statistical_quant', 'name' => 'Statistical Quantitative'],\n ];\n\n public const array ALL_TYPES = [\n ...self::TYPES,\n ['id' => self::TYPE_ASK_JIMINNY, 'name' => 'Ask Jiminny'],\n ];\n\n public const string FREQUENCY_DAILY = 'daily';\n public const string FREQUENCY_WEEKLY = 'weekly';\n public const string FREQUENCY_MONTHLY = 'monthly';\n public const string FREQUENCY_QUARTERLY = 'quarterly';\n public const string FREQUENCY_ONE_OFF = 'one_off';\n\n /**\n * Frequencies for standard (non-Ask Jiminny) reports.\n */\n public const array FREQUENCIES = [\n ['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],\n ['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],\n ['id' => self::FREQUENCY_QUARTERLY, 'name' => 'Quarterly'],\n ['id' => self::FREQUENCY_ONE_OFF, 'name' => 'One-off'],\n ];\n\n /**\n * Frequencies for Ask Jiminny reports.\n */\n public const array ASK_JIMINNY_FREQUENCIES = [\n ['id' => self::FREQUENCY_DAILY, 'name' => 'Daily'],\n ['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],\n ['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],\n ];\n\n public const string MEDIA_TYPE_PDF = 'pdf';\n public const string MEDIA_TYPE_PODCAST = 'podcast';\n public const array MEDIA_TYPES = [self::MEDIA_TYPE_PDF, self::MEDIA_TYPE_PODCAST];\n public const array MEDIA_TYPE_OBJECT_PDF = ['id' => self::MEDIA_TYPE_PDF, 'name' => 'PDF'];\n public const array MEDIA_TYPE_OBJECT_PODCAST = ['id' => self::MEDIA_TYPE_PODCAST, 'name' => 'Podcast'];\n public const array MEDIA_TYPE_OBJECTS = [self::MEDIA_TYPE_OBJECT_PDF, self::MEDIA_TYPE_OBJECT_PODCAST];\n\n public const array CALL_TYPE_CONFERENCE = ['id' => 'conference', 'name' => 'Conference'];\n public const array CALL_TYPE_DIALER = ['id' => 'dialer', 'name' => 'Dialer'];\n public const int SENT_REPORT_AT_HOURS = 5;\n public const string PDF_KEY = 'pdf';\n public const string AUDIO_KEY = 'audio';\n\n private const array ALL_FREQUENCIES = [\n ['id' => self::FREQUENCY_DAILY, 'name' => 'Daily'],\n ['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],\n ['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],\n ['id' => self::FREQUENCY_QUARTERLY, 'name' => 'Quarterly'],\n ['id' => self::FREQUENCY_ONE_OFF, 'name' => 'One-off'],\n ];\n private const string S3_DIR = 'reports';\n private const array FILE_EXTENSIONS_VARIANTS = ['html', 'MD', 'pdf'];\n private const array FILE_PODCAST_EXTENSIONS_VARIANTS = ['json', 'mp3', 'ssml'];\n\n public function __construct(\n private readonly TeamRepository $teamRepository,\n private readonly GroupRepository $groupRepository,\n private readonly UserRepository $userRepository,\n private readonly StageRepository $stageRepository,\n private readonly DealStagesService $dealStagesService,\n private readonly RecipientsService $recipientsService,\n private readonly AutomatedReportsRepository $automatedReportsRepository,\n private readonly Webhook $webhookService,\n private readonly BusDispatcher $dispatcher,\n private readonly ActivityTypeService $activityTypeService,\n private readonly PlaybookCategoryRepository $playbookCategoryRepository,\n private readonly AskAnythingPromptService $askAnythingPromptService,\n private readonly SearchRepository $activitySearchRepository,\n private readonly AskAnythingRepository $askAnythingRepository,\n ) {\n }\n\n public static function getTypes(): array\n {\n $types = self::TYPES;\n\n return array_map(static function ($type) {\n return $type['id'];\n }, $types);\n }\n\n public static function getCallTypes(): array\n {\n return array_map(static function ($callType) {\n return $callType['id'];\n }, [self::CALL_TYPE_CONFERENCE, self::CALL_TYPE_DIALER]);\n }\n\n public static function getFrequencies(): array\n {\n return array_map(static function ($frequency) {\n return $frequency['id'];\n }, self::FREQUENCIES);\n }\n\n // front-facing structure\n public function getReportEnabledFieldData(bool $value = false): array\n {\n return [\n 'id' => 'report_enabled',\n 'label' => '',\n 'inputType' => InputTypeEnum::TOGGLE,\n 'value' => $value,\n ];\n }\n\n // Organizations = Teams\n public function getOrganizationFieldData(?string $value = null, bool $shortVersion = false): array\n {\n $options = $this->getTeams();\n\n if ($shortVersion) {\n return [\n 'id' => 'organization',\n 'label' => 'Organization',\n 'options' => $options,\n ];\n }\n\n return [\n 'id' => 'organization',\n 'label' => 'Organization',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => $options,\n 'value' => $value,\n 'dependencies' => [\n 'teams',\n 'deal_stage_at_call',\n 'current_deal_stage',\n 'recipients',\n ActivityTypeService::PLAYBOOK_CATEGORIES_KEY,\n ],\n 'dependsOn' => [],\n ];\n }\n\n // Teams = Groups\n public function getTeamFieldData(array $options = [], array $value = [], bool $shortVersion = false): array\n {\n if ($shortVersion) {\n return [\n 'id' => 'teams',\n 'label' => 'Team',\n 'options' => $options,\n ];\n }\n\n return [\n 'id' => 'teams',\n 'label' => 'Team',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'required' => false,\n 'placeholder' => 'Select',\n 'options' => $options,\n 'value' => $value, // value should be an array of objects {id, name}\n 'dependencies' => [ActivityTypeService::PLAYBOOK_CATEGORIES_KEY],\n 'dependsOn' => [],\n ];\n }\n\n public function getReportTypeFieldData(?string $value = null, bool $shortVersion = false, ?Team $team = null): array\n {\n $types = [];\n if ($team instanceof Team) {\n if ($team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {\n $types = self::TYPES;\n }\n if ($team->hasFeature(FeatureEnum::ASK_JIMINNY_REPORTS)) {\n $types[] = ['id' => self::TYPE_ASK_JIMINNY, 'name' => 'Ask Jiminny'];\n }\n } else {\n $types = self::TYPES;\n }\n\n if ($shortVersion) {\n return [\n 'id' => 'report_type',\n 'label' => 'Report Type',\n 'options' => $types,\n ];\n }\n\n return [\n 'id' => 'report_type',\n 'label' => 'Report Type',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => $types,\n 'value' => $value,\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getFrequencyFieldData(?string $value = null): array\n {\n return [\n 'id' => 'frequency',\n 'label' => 'Frequency',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => self::FREQUENCIES,\n 'value' => $value,\n 'dependencies' => ['period'],\n 'dependsOn' => [],\n ];\n }\n\n public function getPeriodFieldData(?string $valueStartDate = null, ?string $valueEndDate = null): array\n {\n return [\n 'id' => 'period',\n 'label' => 'Select one-off period',\n 'inputType' => InputTypeEnum::DATE_RANGE,\n 'required' => true,\n 'placeholder' => 'Select',\n 'value' => ['startDate' => $valueStartDate, 'endDate' => $valueEndDate],\n 'queryParams' => [\n 'startDate' => 'start_date_period',\n 'endDate' => 'end_date_period',\n ],\n 'dependencies' => [],\n 'dependsOn' => ['frequency'],\n ];\n }\n\n public function getActivityTypesFieldData(?Team $team = null, array $value = [], array $teamsFilter = []): array\n {\n return $this->activityTypeService->getActivityTypeFieldData(team: $team, value: $value, groupIds: $teamsFilter);\n }\n\n public function getDealStageAtCallFieldData(?Team $team = null, array $value = []): array\n {\n return $this->dealStagesService->getDealStageAtCallFieldData(team: $team, value: $value);\n }\n\n public function getCurrentDealStageFieldData(?Team $team = null, array $value = []): array\n {\n return $this->dealStagesService->getCurrentDealStageFieldData(team: $team, value: $value);\n }\n\n public function getDealValueFieldData(?int $valueMin = null, ?int $valueMax = null): array\n {\n return [\n 'id' => 'deal_value',\n 'label' => 'Deal Value',\n 'inputType' => InputTypeEnum::INTEGER_RANGE,\n 'required' => false,\n 'value' => ['min' => $valueMin, 'max' => $valueMax],\n 'queryParams' => [\n 'min' => 'min_deal_value',\n 'max' => 'max_deal_value',\n ],\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getCallTypeFieldData(bool $conferenceOn = false, bool $dialerOn = false): array\n {\n $value = [];\n $conferenceOn && $value[] = self::CALL_TYPE_CONFERENCE;\n $dialerOn && $value[] = self::CALL_TYPE_DIALER;\n\n return [\n 'id' => 'call_type',\n 'label' => 'Call Type',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'required' => true,\n 'options' => [\n self::CALL_TYPE_CONFERENCE,\n self::CALL_TYPE_DIALER,\n ],\n 'value' => $value,\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getMediaTypeFieldData(?AutomatedReport $report = null): array\n {\n $value = [];\n\n if ($report) {\n $value = $this->transformMediaTypes($report);\n }\n\n return [\n 'id' => 'media_types',\n 'label' => 'Export as',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'required' => true,\n 'options' => self::MEDIA_TYPE_OBJECTS,\n 'value' => $value,\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getCallDurationFieldData(?int $valueMin = null, ?int $valueMax = null): array\n {\n return [\n 'id' => 'call_duration',\n 'label' => 'Call Duration',\n 'inputType' => InputTypeEnum::INTEGER_RANGE,\n 'required' => false,\n 'value' => ['min' => $valueMin, 'max' => $valueMax],\n 'queryParams' => [\n 'min' => 'min_call_duration',\n 'max' => 'max_call_duration',\n ],\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getRecipientsFieldData(?Team $team = null, array $value = []): array\n {\n return $this->recipientsService->getRecipientsFieldData(team: $team, value: $value);\n }\n\n public function getJiminnyRecipientsFieldData(array $value = []): array\n {\n return $this->recipientsService->getJiminnyRecipientsFieldData($value);\n }\n\n public function getAdditionalPromptInputFieldData(?string $value = null): array\n {\n return [\n 'id' => 'additional_prompt_input',\n 'label' => 'Special requirements',\n 'inputType' => InputTypeEnum::TEXTAREA,\n 'required' => false,\n 'placeholder' => 'What should be the focus of the report?',\n 'value' => $value,\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getCustomReportNameFieldData(?string $value = null): array\n {\n return [\n 'id' => 'custom_name',\n 'label' => 'Custom report name',\n 'inputType' => InputTypeEnum::TEXT,\n 'required' => false,\n 'placeholder' => 'Enter custom name',\n 'value' => $value,\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n // data providers\n public function getTeams(): array\n {\n $teams = $this->teamRepository->getTeamsForKiosk(status: Team::STATUS_ACTIVE);\n\n $teamData = [];\n foreach ($teams as $team) {\n if (! $team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {\n continue;\n }\n\n $teamData[] = $this->transformTeam($team);\n }\n\n return $teamData;\n }\n\n public function getTeamGroups(string $teamUuid): array\n {\n $data = [];\n $team = $this->getTeam($teamUuid);\n\n if ($team !== null) {\n $groups = $team->groups()->get();\n\n foreach ($groups as $group) {\n $data[] = [\n 'id' => $group->getUuid(),\n 'name' => $group->getName(),\n ];\n }\n }\n\n return $data;\n }\n\n public function getTeamsGroupsOptions(array $filterTeamUuids = []): array\n {\n $data = [];\n $teams = $this->getTeams();\n\n foreach ($teams as $team) {\n if (! empty($filterTeamUuids) && ! in_array($team['id'], $filterTeamUuids, true)) {\n continue;\n }\n\n $data[] = [\n 'label' => $team['name'],\n 'groups' => $this->getTeamGroups($team['id']),\n ];\n }\n\n return $data;\n }\n\n public function getTeam(string $teamUuid): ?Team\n {\n return $this->teamRepository->idOrUuid($teamUuid);\n }\n\n public function getTeamById(int $teamId): ?Team\n {\n return $this->teamRepository->find($teamId);\n }\n\n public function getGroupsUuids(AutomatedReport $report): array\n {\n $uuids = [];\n $reportGroups = $report->getGroups();\n foreach ($reportGroups as $groupId) {\n if ($group = $this->groupRepository->find($groupId)) {\n $uuids[] = $group->getUuid();\n }\n }\n\n return $uuids;\n }\n\n public function getPlaybookCategoriesUuids(AutomatedReport $report): array\n {\n $uuids = [];\n $playbookCategories = $report->getPlaybookCategories();\n foreach ($playbookCategories as $id) {\n if ($category = $this->playbookCategoryRepository->find($id)) {\n $uuids[] = $category->getUuid();\n }\n }\n\n return $uuids;\n }\n\n public function getDealAtCallStagesUuids(AutomatedReport $report): array\n {\n $uuids = [];\n $reportStages = $report->getDealAtCallStages();\n foreach ($reportStages as $id) {\n if ($stage = $this->stageRepository->find($id)) {\n $uuids[] = $stage->getUuid();\n }\n }\n\n return $uuids;\n }\n\n public function getCurrentDealStagesUuids(AutomatedReport $report): array\n {\n $uuids = [];\n $reportStages = $report->getCurrentDealStages();\n foreach ($reportStages as $id) {\n if ($stage = $this->stageRepository->find($id)) {\n $uuids[] = $stage->getUuid();\n }\n }\n\n return $uuids;\n }\n\n public function getUsersUuids(AutomatedReport $report): array\n {\n return $this->extractUserUuids($report->getRecipients());\n }\n\n public function getJiminnyUsersUuids(AutomatedReport $report): array\n {\n return $this->extractUserUuids($report->getJiminnyRecipients());\n }\n\n /**\n * @param array<string, mixed> $recipients\n */\n private function extractUserUuids(array $recipients): array\n {\n $userIds = $recipients['users'] ?? [];\n\n return collect($userIds)\n ->map(fn ($id) => $this->userRepository->find((int) $id))\n ->filter()\n ->map(fn (UserContract $user) => $user->getUuid())\n ->values()\n ->all();\n }\n\n // get mail data\n public function getRecipientUsers(AutomatedReport $report): array\n {\n return $this->buildRecipientUsers($report->getRecipients());\n }\n\n private function getJiminnyRecipientUsers(AutomatedReport $report): array\n {\n return $this->buildRecipientUsers($report->getJiminnyRecipients());\n }\n\n /**\n * @param array<string, mixed> $recipients\n */\n private function buildRecipientUsers(array $recipients): array\n {\n $userIds = $recipients['users'] ?? [];\n\n return collect($userIds)\n ->map(fn ($id) => $this->userRepository->find((int) $id))\n ->filter()\n ->map(fn (UserContract $user) => [\n 'email' => $user->getEmailAddress(),\n 'name' => $user->getName(),\n 'timezone' => $user->getTimezone()->getName(),\n ])\n ->values()\n ->all();\n }\n\n public function getValidRecipientUsers(AutomatedReport $report, bool $includeJiminny = false): array\n {\n if ($report->isAskJiminnyReport()) {\n $recipients = $this->resolveAskJiminnyRecipients($report);\n } else {\n $recipients = $this->getRecipientUsers($report);\n if ($includeJiminny) {\n $recipients = array_merge($recipients, $this->getJiminnyRecipientUsers($report));\n }\n }\n\n $emails = [];\n\n return array_values(array_filter(\n $recipients,\n static function ($recipient) use (&$emails) {\n if (empty($recipient['email']) || in_array($recipient['email'], $emails, true)) {\n return false;\n }\n $emails[] = $recipient['email'];\n\n return true;\n }\n ));\n }\n\n private function resolveAskJiminnyRecipients(AutomatedReport $report): array\n {\n $recipients = [];\n\n $creator = $report->getCreator();\n if ($creator !== null) {\n $recipients[] = [\n 'email' => $creator->getEmailAddress(),\n 'name' => $creator->getName(),\n 'timezone' => $creator->getTimezone()->getName(),\n ];\n }\n\n return array_merge(\n $recipients,\n $this->buildRecipientUsers($report->getRecipients()),\n $this->getGroupRecipientUsers($report),\n );\n }\n\n private function getGroupRecipientUsers(AutomatedReport $report): array\n {\n $users = [];\n foreach ($report->getGroups() as $groupId) {\n $group = $this->groupRepository->find($groupId);\n if ($group === null) {\n continue;\n }\n foreach ($group->getMembers() as $member) {\n $users[] = [\n 'email' => $member->getEmailAddress(),\n 'name' => $member->getName(),\n 'timezone' => $member->getTimezone()->getName(),\n ];\n }\n }\n\n return $users;\n }\n\n public function getReportTypeName(AutomatedReportResult $report): string\n {\n $type = $report->getReport()->getType();\n\n $getType = $this->transformReportType($type);\n\n return $getType['name'];\n }\n\n public function getReportPeriodName(AutomatedReportResult $report): string\n {\n $from = $report->getFromDate();\n $to = $report->getToDate();\n $frequency = $report->getReport()->getFrequency();\n\n if ($from === null || $to === null) {\n if (! $report->getReport()->isAskJiminnyReport()) {\n $invalidPeriod = $from === null ? 'from' : 'to';\n\n throw new ApplicationException('Report period is invalid: ' . $invalidPeriod);\n }\n\n $period = $this->calculateFromAndToDatePeriod($frequency);\n $from = $period['fromDate'];\n $to = $period['toDate'];\n }\n\n return $this->formatReportPeriodName($frequency, $from, $to);\n }\n\n private function formatReportPeriodName(string $frequency, Carbon $from, Carbon $to): string\n {\n $fromYear = $from->format('Y');\n $toYear = $to->format('Y');\n $differentYears = $fromYear !== $toYear;\n\n switch ($frequency) {\n case self::FREQUENCY_DAILY:\n return $from->format('j M Y');\n\n case self::FREQUENCY_QUARTERLY:\n // 'Jan-Mar 2025' or 'Nov 2024-Jan 2025' if years differ\n $startMonth = $from->format('M');\n $endMonth = $to->copy()->subMonth();\n $endMonthName = $endMonth->format('M');\n $endMonthYear = $endMonth->format('Y');\n\n if ($differentYears) {\n return \"{$startMonth} {$fromYear} - {$endMonthName} {$endMonthYear}\";\n }\n\n return \"{$startMonth} - {$endMonthName} {$toYear}\";\n\n case self::FREQUENCY_MONTHLY:\n // 'May 2025' - monthly reports are always within the same year\n return $from->format('M Y');\n\n case self::FREQUENCY_WEEKLY:\n // '4 - 8 Aug 2025', '27 Oct - 3 Nov 2025', or '28 Dec 2024 - 3 Jan 2025' if years differ\n $startDay = $from->format('j');\n $endDay = $to->format('j');\n $startMonth = $from->format('M');\n $endMonth = $to->format('M');\n\n if ($differentYears) {\n return \"{$startDay} {$startMonth} {$fromYear} - {$endDay} {$endMonth} {$toYear}\";\n }\n\n if ($startMonth !== $endMonth) {\n return \"{$startDay} {$startMonth} - {$endDay} {$endMonth} {$toYear}\";\n }\n\n return \"{$startDay} - {$endDay} {$endMonth} {$toYear}\";\n\n case self::FREQUENCY_ONE_OFF:\n // '2 May-31 May 2025' or '15 Dec 2024-15 Jan 2025' if years differ\n $startDay = $from->format('j');\n $startMonth = $from->format('M');\n $endDay = $to->format('j');\n $endMonth = $to->format('M');\n\n // If same month and year, use a format like '2-31 May 2025'\n if ($startMonth === $endMonth && ! $differentYears) {\n return \"{$startDay} - {$endDay} {$startMonth} {$toYear}\";\n }\n\n // If different years, include both years\n if ($differentYears) {\n return \"{$startDay} {$startMonth} {$fromYear} - {$endDay} {$endMonth} {$toYear}\";\n }\n\n // Same year but different months\n return \"{$startDay} {$startMonth} - {$endDay} {$endMonth} {$toYear}\";\n\n default:\n // Default format for unknown frequencies\n return $from->format('j M Y') . ' - ' . $to->format('j M Y');\n }\n }\n\n public function getReportTeamsName(AutomatedReportResult $report): string\n {\n $groups = $report->getGroups();\n\n if (empty($groups)) {\n return 'All';\n }\n\n // Get group names from repository\n $groupNames = [];\n foreach ($groups as $groupId) {\n $group = $this->groupRepository->find($groupId);\n if ($group) {\n $groupNames[] = $group->getName();\n }\n }\n\n if (count($groupNames) === 1) {\n // Single team format\n $teamsName = $groupNames[0];\n } else {\n // Multiple teams format\n $teamsName = implode(', ', $groupNames);\n }\n\n return $teamsName;\n }\n\n public function getReportFileName(AutomatedReportResult $report): string\n {\n $customName = $report->getReport()->getCustomName();\n $periodName = $this->getReportPeriodName($report);\n $filenameSuffix = $this->getFilenameSuffix($report);\n\n if ($customName) {\n if ($filenameSuffix) {\n $customName .= \" {$filenameSuffix}\";\n }\n\n return $this->sanitizeFileName(\"{$customName} - {$periodName}\");\n }\n\n $baseName = $this->getReportTypeName($report);\n\n if ($filenameSuffix) {\n $baseName .= \" {$filenameSuffix}\";\n }\n\n return $this->sanitizeFileName(\"{$baseName} - {$periodName} - {$this->getReportTeamsName($report)}\");\n }\n\n public function getReportFileNameWithExtension(AutomatedReportResult $result): string\n {\n $extension = $this->getMediaTypeMetadata($result)['extension'];\n\n return $this->getReportFileName($result) . '.' . $extension;\n }\n\n public function sanitizeFileName(string $fileName): string\n {\n return str_replace(['/', '\\\\'], '-', $fileName);\n }\n\n public function isUserRecipientOfReport(User $user, AutomatedReport $report): bool\n {\n $recipients = array_map('intval', $report->getRecipients()['users'] ?? []);\n\n return in_array($user->getId(), $recipients);\n }\n\n public function transformReportResults(Collection $automatedReportResults): array\n {\n $data = [];\n foreach ($automatedReportResults as $automatedReportResult) {\n /** @var AutomatedReportResult $automatedReportResult */\n\n $report = $automatedReportResult->getReport();\n\n $createdBy = $report->getCreator();\n $creator = [\n 'id' => $createdBy?->getUuid(),\n 'name' => $createdBy?->getName(),\n 'email' => $createdBy?->getEmailAddress(),\n 'photoUrl' => $createdBy?->getPhotoUrl(),\n ];\n\n $data[] = [\n 'id' => $automatedReportResult->getUuid(),\n 'name' => $automatedReportResult->getName(),\n 'frequency' => $this->transformFrequency($report->getFrequency()),\n 'recipients' => [\n ...array_values($this->transformGroups(team: $report->getTeam(), groupsIds: $report->getGroups())),\n ...array_values($this->transformRecipients($report->getRecipients())),\n ],\n 'report_type' => $this->transformReportType($report->getType()),\n 'media_type' => $automatedReportResult->getMediaType(),\n 'downloadUrl' => $this->generateReportResultDownloadUrl($automatedReportResult),\n 'viewUrl' => $this->generateReportResultViewUrl($automatedReportResult),\n 'generated_at' => $automatedReportResult->getGeneratedAt()?->toIso8601String(),\n 'creator' => $creator,\n ];\n }\n\n return $data;\n }\n\n public function hasCallTypeConference(AutomatedReport $report): bool\n {\n return in_array(self::CALL_TYPE_CONFERENCE['id'], $report->getCallTypes(), true);\n }\n\n public function hasCallTypeDialer(AutomatedReport $report): bool\n {\n return in_array(self::CALL_TYPE_DIALER['id'], $report->getCallTypes(), true);\n }\n\n // transformers\n private function transformTeam(Team $team): array\n {\n if (! $team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {\n return [];\n }\n\n return [\n 'id' => $team->getUuid(),\n 'name' => $team->getName(),\n ];\n }\n\n private function transformReportFullView(AutomatedReport $report): array\n {\n $base = $this->transformReportBase($report);\n\n return $report->getType() === self::TYPE_ASK_JIMINNY\n ? $base + $this->transformAskJiminnyFields($report)\n : $base + $this->transformStandardReportFields($report);\n }\n\n private function transformReportBase(AutomatedReport $report): array\n {\n return [\n 'id' => $report->getUuid(),\n 'organization' => $this->transformOrganization(team: $report->getTeam()),\n 'report_type' => $this->transformReportType($report->getType()),\n 'frequency' => $this->transformFrequency($report->getFrequency()),\n ];\n }\n\n private function transformStandardReportFields(AutomatedReport $report): array\n {\n $team = $report->getTeam();\n\n return [\n 'report_enabled' => $report->getStatus(),\n 'start_date_period' => $report->getFrom()?->format('Y-m-d H:i:s'),\n 'end_date_period' => $report->getTo()?->format('Y-m-d H:i:s'),\n 'deal_value_min' => $report->getDealValueMin(),\n 'deal_value_max' => $report->getDealValueMax(),\n 'call_types' => $this->transformCallType($report->getCallTypes()),\n 'media_types' => $this->transformMediaTypes($report),\n 'call_duration_min' => $this->transformDurationToMinutes($report->getCallDurationMin()),\n 'call_duration_max' => $this->transformDurationToMinutes($report->getCallDurationMax()),\n 'teams' => $this->transformGroups(team: $team, groupsIds: $report->getGroups()),\n 'deal_at_call_stages' => $this->transformStages(team: $team, stagesIds: $report->getDealAtCallStages()),\n 'current_deal_stages' => $this->transformStages(team: $team, stagesIds: $report->getCurrentDealStages()),\n 'recipients' => $this->transformRecipients($report->getRecipients()),\n 'created_by' => $this->transformCreator($report->getCreator()),\n 'additional_prompt_input' => $report->getAdditionalPromptInput(),\n 'custom_name' => $report->getCustomName(),\n 'created_at' => $report->getCreatedAt()->format('Y-m-d H:i:s'),\n 'updated_at' => $report->getUpdatedAt()->format('Y-m-d H:i:s'),\n 'deleted_at' => $report->getDeletedAt()?->format('Y-m-d H:i:s'),\n ];\n }\n\n private function transformAskJiminnyFields(AutomatedReport $report): array\n {\n $team = $report->getTeam();\n $creatorId = $report->getAttribute('created_by');\n $explicitUserIds = array_values(array_filter(\n $report->getRecipients()['users'] ?? [],\n static fn ($id) => $id !== $creatorId\n ));\n\n return [\n 'report_name' => $report->getCustomName(),\n 'enabled' => $report->getStatus(),\n 'share_teams' => $this->transformGroups(team: $team, groupsIds: $report->getGroups()),\n 'share_users' => $this->transformRecipients(['users' => $explicitUserIds]),\n 'saved_search' => $this->transformSafeSearch($report->getSavedSearch()),\n 'ask_jiminny_prompt' => $this->transformAskJiminnyPrompt($report->getAskAnythingPrompt()),\n 'expires_on' => $report->getExpiresAt()?->format('Y-m-d'),\n ];\n }\n\n private function transformOrganization(?Team $team): array\n {\n return [\n 'id' => $team?->getUuid(),\n 'name' => $team?->getName(),\n ];\n }\n\n private function transformReportType(string $type): array\n {\n foreach (self::ALL_TYPES as $typeItem) {\n if ($typeItem['id'] === $type) {\n return $typeItem;\n }\n }\n\n return [];\n }\n\n private function transformCallType(array $types): array\n {\n $result = [];\n $callTypes = [self::CALL_TYPE_CONFERENCE, self::CALL_TYPE_DIALER];\n\n foreach ($types as $type) {\n foreach ($callTypes as $callTypeItem) {\n if ($callTypeItem['id'] === $type) {\n $result[] = $callTypeItem;\n\n break;\n }\n }\n }\n\n return $result;\n }\n\n private function transformMediaTypes(AutomatedReport $report): array\n {\n $values = [];\n\n foreach ($report->getMediaTypes() as $mediaType) {\n if (! in_array($mediaType, self::MEDIA_TYPES, true)) {\n continue;\n }\n\n $values[] = match ($mediaType) {\n self::MEDIA_TYPE_PDF => self::MEDIA_TYPE_OBJECT_PDF,\n self::MEDIA_TYPE_PODCAST => self::MEDIA_TYPE_OBJECT_PODCAST,\n };\n }\n\n return $values;\n }\n\n private function transformFrequency(string $frequency): array\n {\n foreach (self::ALL_FREQUENCIES as $frequencyItem) {\n if ($frequencyItem['id'] === $frequency) {\n return $frequencyItem;\n }\n }\n\n return [];\n }\n\n public function transformDurationToMinutes(?int $duration): ?int\n {\n if (! $duration) {\n return null;\n }\n\n return (int) ($duration / 60);\n }\n\n private function transformGroups(?Team $team, array $groupsIds): array\n {\n if (empty($groupsIds) || ! $team) {\n return [];\n }\n\n $data = [];\n foreach ($groupsIds as $groupId) {\n $group = $team->groups()->where('id', $groupId)->first();\n\n if ($group) {\n $data[] = [\n 'id' => $group->getUuid(),\n 'name' => $group->getName(),\n 'photoUrl' => $group->getPhotoUrl(),\n ];\n }\n }\n\n return $data;\n }\n\n private function transformStages(?Team $team, array $stagesIds): array\n {\n if (empty($stagesIds) || ! $team) {\n return [];\n }\n\n $data = [];\n foreach ($stagesIds as $stageId) {\n $stage = $team->stages()->where('id', $stageId)->first();\n\n if ($stage) {\n $data[] = [\n 'id' => $stage->getUuid(),\n 'name' => $stage->getName(),\n ];\n }\n }\n\n return $data;\n }\n\n private function transformRecipients(array $recipients): array\n {\n $users = [];\n foreach ($recipients['users'] ?? [] as $userId) {\n $users[] = $this->transformUser($userId);\n }\n\n return $users;\n }\n\n private function transformCreator(?User $user): ?array\n {\n if ($user === null) {\n return null;\n }\n\n return $this->transformUser($user->getId());\n }\n\n private function transformAskJiminnyPrompt(?AskAnythingPrompt $prompt): ?array\n {\n if ($prompt === null) {\n return null;\n }\n\n return [\n 'id' => $prompt->getUuid(),\n 'name' => $prompt->getTitle(),\n ];\n }\n\n private function transformSafeSearch(?Search $search): ?array\n {\n if ($search === null) {\n return null;\n }\n\n return [\n 'id' => $search->getUuid(),\n 'name' => $search->getName(),\n ];\n }\n\n private function transformUser(int $userId): array\n {\n /* @var ?User $user */\n $user = $this->userRepository->find($userId);\n\n return [\n 'id' => $user?->getUuid(),\n 'name' => $user?->getName(),\n 'email' => $user?->getEmailAddress(),\n 'photoUrl' => $user?->getPhotoUrl(),\n ];\n }\n\n public function create(array $data): array\n {\n $validatedData = $this->validateAndTransformData($data);\n $validatedData['created_by'] = auth()->id();\n\n $automatedReport = $this->automatedReportsRepository->create($validatedData);\n\n $this->generateOneOffReport($automatedReport);\n\n return $this->transformReportFullView($automatedReport);\n }\n\n public function update(string $uuid, array $data): array\n {\n $validatedData = $this->validateAndTransformData($data);\n $report = $this->automatedReportsRepository->findByUuid($uuid);\n\n if (! $report) {\n throw new InvalidArgumentException('Report not found');\n }\n\n $oldCustomName = $report->getCustomName();\n\n $automatedReport = $this->automatedReportsRepository->update($report, $validatedData);\n\n if ($oldCustomName !== $automatedReport->getCustomName()) {\n $this->updateResultNames($automatedReport);\n }\n\n $this->generateOneOffReport($automatedReport);\n\n return $this->transformReportFullView($automatedReport);\n }\n\n /**\n * Create an Ask Jiminny report.\n */\n public function createAskJiminnyReport(array $data, User $creator): array\n {\n $validatedData = $this->validateAskJiminnyReportData($data, $creator);\n $validatedData['created_by'] = $creator->getId();\n\n $automatedReport = $this->automatedReportsRepository->create($validatedData);\n\n return $this->transformReportFullView($automatedReport);\n }\n\n /**\n * Update an Ask Jiminny report.\n */\n public function updateAskJiminnyReport(AutomatedReport $report, array $data, User $user): array\n {\n if (! $report->isAskJiminnyReport()) {\n throw new InvalidArgumentException('Report is not an Ask Jiminny report');\n }\n\n $validatedData = $this->validateAskJiminnyReportData($data, $user);\n\n $oldCustomName = $report->getCustomName();\n\n $automatedReport = $this->automatedReportsRepository->update($report, $validatedData);\n\n if ($oldCustomName !== $automatedReport->getCustomName()) {\n $this->updateResultNames($automatedReport);\n }\n\n return $this->transformReportFullView($automatedReport);\n }\n\n public function updateAskJiminnyReportStatus(AutomatedReport $report, bool $status): array\n {\n $this->automatedReportsRepository->update($report, ['status' => $status]);\n\n return $this->transformReportFullView($report->fresh());\n }\n\n /**\n * Validate and transform data for Ask Jiminny reports.\n */\n private function validateAskJiminnyReportData(array $data, User $user): array\n {\n // Validate name\n $name = trim($data['report_name'] ?? '');\n if (empty($name)) {\n throw new InvalidArgumentException('Report name is required');\n }\n if (mb_strlen($name) > 50) {\n throw new InvalidArgumentException('Report name must be 50 characters or less');\n }\n\n // Validate frequency (only daily, weekly, monthly for Ask Jiminny)\n $frequency = $data['frequency'] ?? null;\n $askJiminnyFrequencies = [self::FREQUENCY_DAILY, self::FREQUENCY_WEEKLY, self::FREQUENCY_MONTHLY];\n if (! in_array($frequency, $askJiminnyFrequencies, true)) {\n throw new InvalidArgumentException('Frequency must be daily, weekly, or monthly');\n }\n\n // Validate expiration date\n $expiresAt = $data['expires_on'] ?? null;\n if (empty($expiresAt)) {\n throw new InvalidArgumentException('Expiration date is required');\n }\n\n try {\n $expiresAtDate = Carbon::parse($expiresAt);\n } catch (InvalidFormatException $e) {\n throw new InvalidArgumentException('Expiration date format is invalid');\n }\n $maxExpiration = Carbon::now()->addYear();\n if ($expiresAtDate->gt($maxExpiration)) {\n throw new InvalidArgumentException('Expiration date cannot be more than 1 year from now');\n }\n if ($expiresAtDate->isPast()) {\n throw new InvalidArgumentException('Expiration date cannot be in the past');\n }\n\n // Validate saved search\n $activitySearchId = $data['saved_search'] ?? null;\n if (empty($activitySearchId)) {\n throw new InvalidArgumentException('Saved search is required');\n }\n $savedSearch = $this->activitySearchRepository->findByUuidAndUser($activitySearchId, $user);\n if (! $savedSearch) {\n throw new InvalidArgumentException('Saved search not found or does not belong to you');\n }\n\n // Validate saved prompt\n $askAnythingPromptId = $data['ask_jiminny_prompt'] ?? null;\n if (empty($askAnythingPromptId)) {\n throw new InvalidArgumentException('Ask Jiminny prompt is required');\n }\n $prompt = $this->askAnythingRepository->getPromptByUuid($askAnythingPromptId);\n if (! $prompt) {\n throw new InvalidArgumentException('Ask Jiminny prompt not found');\n }\n\n // Validate status\n $status = $data['enabled'] ?? false;\n\n $recipientUserIds = [$user->getId()];\n\n if (! empty($data['share_users'])) {\n $sharedUserIds = $this->validateAndGetUserIdsByTeam(\n $user->team,\n (array) $data['share_users']\n );\n $recipientUserIds = array_merge($recipientUserIds, $sharedUserIds);\n }\n\n $sharedGroupIds = [];\n if (! empty($data['share_teams'])) {\n $sharedGroupIds = $this->validateAndGetGroupIds($user->team, (array) $data['share_teams']);\n }\n\n $recipientUserIds = array_values(array_unique($recipientUserIds));\n\n return [\n 'team_id' => $user->getTeamId(),\n 'type' => self::TYPE_ASK_JIMINNY,\n 'status' => (bool) $status,\n 'frequency' => $frequency,\n 'custom_name' => $name,\n 'activity_search_id' => $savedSearch->getId(),\n 'ask_anything_prompt_id' => $prompt->getId(),\n 'expires_at' => $expiresAtDate->toDateString(),\n 'media_types' => [self::MEDIA_TYPE_PDF],\n 'call_types' => [],\n 'recipients' => ['users' => $recipientUserIds],\n 'groups' => $sharedGroupIds,\n ];\n }\n\n public static function getAskJiminnyFrequencies(): array\n {\n return array_map(static function ($frequency) {\n return $frequency['id'];\n }, self::ASK_JIMINNY_FREQUENCIES);\n }\n\n public function getAskJiminnyReportFilters(User $user): array\n {\n $savedSearches = $this->activitySearchRepository->findByUserOrderedByName($user)\n ->map(fn (Search $search) => [\n 'id' => $search->getUuid(),\n 'name' => $search->getName(),\n ])\n ->values()->all();\n\n $prompts = collect(\n $this->askAnythingPromptService->get($user, AskAnythingPromptTarget::on_demand)\n )->map(fn (AskAnythingPromptDto $prompt) => [\n 'id' => $prompt->id,\n 'name' => $prompt->title,\n ])->values()->all();\n\n return [\n [\n 'id' => 'prompt',\n 'label' => 'Prompt',\n 'options' => $prompts,\n ],\n [\n 'id' => 'saved_search',\n 'label' => 'Saved Search',\n 'options' => $savedSearches,\n ],\n ];\n }\n\n public function getAskJiminnyReportFormData(User $user, ?AutomatedReport $report = null): array\n {\n $team = $user->getTeam();\n $userTimezone = $user->getTimezone();\n\n $savedSearches = $this->activitySearchRepository->findByUserOrderedByName($user)\n ->map(fn (Search $search) => [\n 'id' => $search->getUuid(),\n 'name' => $search->getName(),\n ])\n ->values()->all();\n\n $prompts = collect(\n $this->askAnythingPromptService->get($user, AskAnythingPromptTarget::on_demand)\n )->map(fn (AskAnythingPromptDto $prompt) => [\n 'id' => $prompt->id,\n 'name' => $prompt->title,\n ])->values()->all();\n\n $teamGroups = $this->groupRepository->getAllByTeam($team)->map(fn ($group) => [\n 'id' => $group->getUuid(),\n 'name' => $group->getName(),\n ])->values()->all();\n\n $shareUsers = $this->recipientsService->getRecipientsFieldData(team: $team)['options'] ?? [];\n\n $sharedTeamsValue = [];\n $sharedUsersValue = [];\n if ($report) {\n $sharedTeamsValue = $this->transformGroups($team, $report->getGroups());\n\n $recipientUserIds = $report->getRecipients()['users'] ?? [];\n $creatorId = $report->getAttribute('created_by');\n $sharedUserIds = array_values(array_filter(\n $recipientUserIds,\n static fn ($id) => $id !== $creatorId\n ));\n $sharedUsersValue = collect($sharedUserIds)\n ->map(fn ($id) => $this->userRepository->find((int) $id))\n ->filter()\n ->map(fn (User $u) => [\n 'id' => $u->getUuid(),\n 'name' => $u->getName(),\n ])\n ->values()\n ->all();\n }\n\n return [\n 'fields' => [\n [\n 'id' => 'enabled',\n 'inputType' => InputTypeEnum::TOGGLE,\n 'label' => '',\n 'value' => $report?->getStatus() ?? false,\n ],\n [\n 'id' => 'report_name',\n 'inputType' => InputTypeEnum::TEXT,\n 'label' => 'Name',\n 'placeholder' => 'Enter name',\n 'required' => true,\n 'validation' => ['maxLength' => 50],\n 'value' => $report?->getCustomName() ?? '',\n ],\n [\n 'id' => 'frequency',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'label' => 'Frequency',\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => self::ASK_JIMINNY_FREQUENCIES,\n 'value' => $report ? $this->transformFrequency($report->getFrequency()) : null,\n ],\n [\n 'id' => 'expires_on',\n 'inputType' => InputTypeEnum::DATE,\n 'label' => 'Expires on',\n 'required' => true,\n 'placeholder' => 'Select',\n 'validation' => [\n 'minDate' => now($userTimezone)->toDateString(),\n 'maxDate' => now($userTimezone)->addYear()->toDateString(),\n ],\n 'value' => $report?->getExpiresAt()?->toDateString(),\n ],\n [\n 'id' => 'share_teams',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'label' => 'Team',\n 'required' => false,\n 'placeholder' => 'Select',\n 'options' => $teamGroups,\n 'value' => $sharedTeamsValue,\n ],\n [\n 'id' => 'share_users',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'label' => 'Team member',\n 'required' => false,\n 'placeholder' => 'Select',\n 'groupLabelKey' => 'label',\n 'groupValuesKey' => 'users',\n 'optionLabelKey' => 'name',\n 'optionValueKey' => 'id',\n 'options' => $shareUsers,\n 'value' => $sharedUsersValue,\n ],\n [\n 'id' => 'saved_search',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'label' => 'Saved search',\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => $savedSearches,\n 'value' => $report && $report->getSavedSearch() ? [\n 'id' => $report->getSavedSearch()->getUuid(),\n 'name' => $report->getSavedSearch()->getName(),\n ] : null,\n ],\n [\n 'id' => 'ask_jiminny_prompt',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'label' => 'Ask Jiminny prompt',\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => $prompts,\n 'value' => $report && $report->getAskAnythingPrompt() ? [\n 'id' => $report->getAskAnythingPrompt()->getUuid(),\n 'name' => $report->getAskAnythingPrompt()->getTitle(),\n ] : null,\n ],\n ],\n ];\n }\n\n private function updateResultNames(AutomatedReport $automatedReport): void\n {\n $results = $this->automatedReportsRepository->getResultsByReport($automatedReport);\n\n foreach ($results as $result) {\n $result->update(['name' => $this->getReportFileName($result)]);\n }\n }\n\n public function updateStatus(string $uuid, array $data): array\n {\n $automatedReport = $this->automatedReportsRepository->findByUuid($uuid);\n\n if (! $automatedReport) {\n throw new ModelNotFoundException('Report not found');\n }\n\n $status = $this->validateReportStatus($data['report_enabled'] ?? null);\n $automatedReport->update([\n 'status' => $status,\n ]);\n\n $this->generateOneOffReport($automatedReport);\n\n return $this->transformReportFullView($automatedReport);\n }\n\n private function generateOneOffReport(AutomatedReport $automatedReport): void\n {\n // the scheduler handles all the other frequency types\n if ($automatedReport->getStatus() === false || $automatedReport->getFrequency() !== self::FREQUENCY_ONE_OFF) {\n return;\n }\n\n $this->dispatcher->dispatch(new RequestGenerateReportJob($automatedReport->getUuid()));\n }\n\n public function getReport(string $uuid): AutomatedReport\n {\n $automatedReport = $this->automatedReportsRepository->findByUuid($uuid);\n\n if (! $automatedReport) {\n throw new ModelNotFoundException('Report not found');\n }\n\n return $automatedReport;\n }\n\n public function get(string $uuid): array\n {\n $automatedReport = $this->getReport($uuid);\n\n return $this->transformReportFullView($automatedReport);\n }\n\n public function list(string $sortColumn = 'created_at', string $sortDirection = 'desc'): array\n {\n $results = [];\n $collection = $this->automatedReportsRepository->getAllStandardReports($sortColumn, $sortDirection);\n\n /** @var AutomatedReport $report */\n foreach ($collection as $report) {\n $results[] = $this->transformReportFullView($report);\n }\n\n return ['data' => $results];\n }\n\n public function listAskJiminnyReports(\n User $user,\n string $sortColumn = 'created_at',\n string $sortDirection = 'desc'\n ): array {\n $results = [];\n $collection = $this->automatedReportsRepository->getAskJiminnyReportsByUser($user, $sortColumn, $sortDirection);\n\n /** @var AutomatedReport $report */\n foreach ($collection as $report) {\n $results[] = $this->transformReportFullView($report);\n }\n\n return ['data' => $results];\n }\n\n public function delete(string $uuid): void\n {\n $automatedReport = $this->automatedReportsRepository->findByUuid($uuid);\n\n if (! $automatedReport) {\n throw new ModelNotFoundException('Report not found');\n }\n\n $automatedReport->delete();\n }\n\n public function createReportResult(AutomatedReport $automatedReport, array $data = []): AutomatedReportResult\n {\n return $this->automatedReportsRepository->createResult(\n array_merge(\n [\n 'report_id' => $automatedReport->getId(),\n 'status' => AutomatedReportResult::STATUS_DEFAULT,\n ],\n $data\n )\n );\n }\n\n public function getReportResult(string $resultUuid): AutomatedReportResult\n {\n $report = $this->automatedReportsRepository->findResultByUuid($resultUuid);\n\n if (! $report) {\n throw new ModelNotFoundException('Report Result not found');\n }\n\n return $report;\n }\n\n public function findChildResult(AutomatedReportResult $result, string $type): ?AutomatedReportResult\n {\n return $this->automatedReportsRepository->findChildResult($result, $type);\n }\n\n // prophet API calls\n /**\n * @throws ApplicationException\n */\n public function getGenerateReportPayload(AutomatedReport $automatedReport, string $reportResultUuid): array\n {\n $period = $this->calculateFromAndToDate($automatedReport);\n $fromDate = $period['fromDate'];\n $toDate = $period['toDate'];\n\n return [\n 'team_id' => $automatedReport->getTeamId(),\n 'request_id' => $reportResultUuid,\n 'report_type' => $automatedReport->getType(),\n 'media_types' => $automatedReport->getMediaTypes(),\n 'from_date' => $fromDate->startOfDay()->format(DateTimeInterface::RFC3339),\n 'to_date' => $toDate->endOfDay()->format(DateTimeInterface::RFC3339),\n 'group_ids' => $automatedReport->getGroups(),\n 'call_deal_stage' => $automatedReport->getDealAtCallStages(),\n 'current_deal_stage' => $automatedReport->getCurrentDealStages(),\n 'deal_min_value' => $automatedReport->getDealValueMin(),\n 'deal_max_value' => $automatedReport->getDealValueMax(),\n 'call_types' => $automatedReport->getCallTypes(),\n 'call_duration_min_seconds' => $automatedReport->getCallDurationMin(),\n 'call_duration_max_seconds' => $automatedReport->getCallDurationMax(),\n 'special_requirements' => $automatedReport->getAdditionalPromptInput(),\n 'callback_url' => $this->getCallbackUrl(),\n 'report_period' => $this->formatReportPeriodName(\n $automatedReport->getFrequency(),\n $fromDate,\n $toDate,\n ),\n 'playbook_categories' => $automatedReport->getPlaybookCategories(),\n 'custom_name' => $automatedReport->getCustomName(),\n ];\n }\n\n // $inputPayload - FE payload structure\n public function getActivitiesCountPayload(array $inputPayload): array\n {\n // Use validateAndTransformData to validate and normalize input\n $validatedData = $this->validateAndTransformData($inputPayload);\n $period = $this->calculateFromAndToDatePeriod(\n $validatedData['frequency'],\n Carbon::parse($validatedData['from']),\n Carbon::parse($validatedData['to']),\n );\n $fromDate = $period['fromDate'];\n $toDate = $period['toDate'];\n\n // Create payload similar to getGenerateReportPayload\n return [\n 'team_id' => $validatedData['team_id'],\n 'group_ids' => $validatedData['groups'] ?? [],\n 'report_type' => $validatedData['type'],\n 'from_date' => $fromDate->format(DateTimeInterface::RFC3339),\n 'to_date' => $toDate->format(DateTimeInterface::RFC3339),\n 'call_deal_stage' => $validatedData['deal_at_call_stages'] ?? [],\n 'current_deal_stage' => $validatedData['current_deal_stages'] ?? [],\n 'deal_min_value' => $validatedData['deal_value_min'] ?? null,\n 'deal_max_value' => $validatedData['deal_value_max'] ?? null,\n 'call_types' => $validatedData['call_types'],\n 'call_duration_min_seconds' => $validatedData['call_duration_min'] ?? null,\n 'call_duration_max_seconds' => $validatedData['call_duration_max'] ?? null,\n 'special_requirements' => $validatedData['additional_prompt_input'] ?? null,\n 'playbook_categories' => $validatedData['playbook_categories'] ?? [],\n 'request_id' => null,\n 'callback_url' => null,\n ];\n }\n\n public function shouldSendReport(array $users, ?CarbonInterface $generatedAt = null): bool\n {\n if (empty($users)) {\n return false;\n }\n\n $earliestTz = collect($users)\n ->mapWithKeys(function (array $user) {\n $tz = new DateTimeZone($user['timezone']);\n $nowUtc = new DateTime('now', new DateTimeZone('UTC'));\n $offset = $tz->getOffset($nowUtc);\n\n return [$user['timezone'] => $offset];\n })\n ->sortDesc()\n ->keys()\n ->first();\n\n $now = Carbon::now($earliestTz);\n $isScheduledTime = (int) $now->format('H') === self::SENT_REPORT_AT_HOURS;\n\n if ($isScheduledTime) {\n return true;\n }\n\n return $this->hasPassedScheduledTime($generatedAt, $earliestTz);\n }\n\n public function hasPassedScheduledTime(?CarbonInterface $generatedAt, string $timezone): bool\n {\n if ($generatedAt === null) {\n return false;\n }\n\n $now = Carbon::now($timezone);\n $scheduledTime = $now->copy()->setTime(self::SENT_REPORT_AT_HOURS, 0, 0);\n\n if ($now->hour < self::SENT_REPORT_AT_HOURS) {\n $scheduledTime = $scheduledTime->subDay();\n }\n\n $scheduledTimeUtc = $scheduledTime->copy()->utc();\n $generatedAtUtc = $generatedAt->copy()->utc();\n $nowUtc = $now->copy()->utc();\n\n return $generatedAtUtc->lt($scheduledTimeUtc) && $nowUtc->gt($scheduledTimeUtc);\n }\n\n public function calculateFromAndToDatePeriod(\n string $frequency,\n ?Carbon $fromDate = null,\n ?Carbon $toDate = null\n ): array {\n if ($frequency === self::FREQUENCY_ONE_OFF) {\n return [\n 'fromDate' => $fromDate,\n 'toDate' => $toDate,\n ];\n }\n\n $now = Carbon::now();\n\n return match ($frequency) {\n self::FREQUENCY_DAILY => [\n 'fromDate' => $now->copy()->subDay()->startOfDay(),\n 'toDate' => $now->copy()->subDay()->endOfDay(),\n ],\n self::FREQUENCY_WEEKLY => [\n 'fromDate' => $now->copy()->subWeeks(1)->startOfDay(),\n 'toDate' => $now->copy()->subDay()->endOfDay(),\n ],\n self::FREQUENCY_MONTHLY => [\n 'fromDate' => $now->copy()->subMonths(1)->startOfDay(),\n 'toDate' => $now->copy()->subDay()->endOfDay(),\n ],\n self::FREQUENCY_QUARTERLY => [\n 'fromDate' => $now->copy()->subMonths(3)->startOfDay(),\n 'toDate' => $now->copy()->subDay()->endOfDay(),\n ],\n default => throw new InvalidArgumentException(\"Unsupported frequency: {$frequency}\"),\n };\n }\n\n private function calculateFromAndToDate(AutomatedReport $automatedReport): array\n {\n return $this->calculateFromAndToDatePeriod(\n $automatedReport->getFrequency(),\n $automatedReport->getFrom(),\n $automatedReport->getTo()\n );\n }\n\n public function getAskJiminnyGenerateReportPayload(\n AutomatedReport $automatedReport,\n AutomatedReportResult $reportResult,\n array $activityIds,\n ): array {\n return [\n 'user_question' => $automatedReport->getAskAnythingPrompt()?->getContent(),\n 'call_ids' => array_map('strval', $activityIds),\n 'team_id' => $automatedReport->getTeamId(),\n 'request_id' => $reportResult->getUuid(),\n 'callback_url' => $this->getCallbackUrl(),\n 'report_period' => $this->getReportPeriodName($reportResult),\n 'report_name' => $automatedReport->getCustomName(),\n ];\n }\n\n private function getCallbackUrl(): string\n {\n return $this->webhookService->route('jiminny.webhook.reports.ready');\n }\n\n /**\n * Validate and transform payload data for automated reports\n *\n * @param array $data\n *\n * @throws InvalidArgumentException\n *\n * @return array\n */\n private function validateAndTransformData(array $data): array\n {\n // Validate organization (team) and check feature\n $team = $this->validateOrganization($data['organization'] ?? null);\n\n $status = $this->validateReportStatus($data['report_enabled'] ?? null);\n $type = $this->validateReportType($data['report_type'] ?? null);\n $frequency = $this->validateFrequency($data['frequency'] ?? null);\n $additionalPromptInput = $this->validateAdditionalPromptInput(\n $data['additional_prompt_input'] ?? null\n );\n $customReportName = $this->validateCustomReportName($data['custom_name'] ?? null);\n\n // Prepare data for the database\n $reportData = [\n 'team_id' => $team->getId(),\n 'type' => $type,\n 'status' => $status,\n 'frequency' => $frequency,\n 'additional_prompt_input' => $additionalPromptInput,\n 'custom_name' => $customReportName,\n ];\n\n // Validate deal values\n $reportData = $this->validateDealValues($data, $reportData);\n\n // Validate date range\n $reportData = $this->validateDateRange($data, $reportData, $frequency);\n\n // Validate call durations\n $reportData = $this->validateCallDurations($data, $reportData);\n\n // Validate call types\n $reportData = $this->validateCallTypes($data, $reportData);\n\n // Validate media types\n $reportData = $this->validateMediaTypes($data, $reportData);\n\n // Validate groups\n if (isset($data['teams'])) {\n $reportData['groups'] = $this->validateAndGetGroupIds($team, $data['teams']);\n }\n\n // Validate deal stages\n $reportData = $this->validateDealStages($data, $reportData, $team, $type);\n\n // Validate playbook categories\n $reportData = $this->validatePlaybookCategories($data, $reportData, $team);\n\n // Validate recipients\n $reportData['recipients'] = [\n 'users' => $this->validateAndGetUserIdsByTeam($team, $data['recipients'] ?? []),\n ];\n\n if (isset($data['jiminny_recipients'])) {\n // Validate Jiminny recipients\n $reportData['jiminny_recipients'] = [\n 'users' => $this->validateAndGetJiminnyUserIds((array) $data['jiminny_recipients']),\n ];\n }\n\n return $reportData;\n }\n\n private function validateDealValues(array $data, array $reportData): array\n {\n if (isset($data['min_deal_value'])) {\n $reportData['deal_value_min'] = (int) $data['min_deal_value'];\n\n if ($reportData['deal_value_min'] > 4294967295 || $reportData['deal_value_min'] < 0) {\n throw new InvalidArgumentException('Min deal value should be between 0 and 4294967295');\n }\n }\n\n if (isset($data['max_deal_value'])) {\n $reportData['deal_value_max'] = (int) $data['max_deal_value'];\n\n if ($reportData['deal_value_max'] > 4294967295 || $reportData['deal_value_max'] < 0) {\n throw new InvalidArgumentException('Max deal value should be between 0 and 4294967295');\n }\n }\n\n if (isset($data['min_deal_value'], $data['max_deal_value'])\n && $data['min_deal_value'] > $data['max_deal_value']\n ) {\n throw new InvalidArgumentException('Min deal value cannot be greater than max deal value');\n }\n\n return $reportData;\n }\n\n private function validateDateRange(array $data, array $reportData, string $frequency): array\n {\n // Set date range only for one_off frequency\n if ($frequency === 'one_off') {\n if (isset($data['start_date_period'])) {\n $reportData['from'] = $this->parseDate($data['start_date_period']);\n }\n\n if (isset($data['end_date_period'])) {\n $reportData['to'] = $this->parseDate($data['end_date_period']);\n }\n\n if (empty($reportData['from']) || empty($reportData['to'])) {\n throw new InvalidArgumentException(\n 'Start date and end date are required for one_off frequency'\n );\n }\n } else {\n $reportData['from'] = null;\n $reportData['to'] = null;\n }\n\n return $reportData;\n }\n\n private function validateCallDurations(array $data, array $reportData): array\n {\n // Convert call durations from minutes to seconds\n if (isset($data['min_call_duration'])) {\n $reportData['call_duration_min'] = (int) $data['min_call_duration'] * 60;\n\n if ($reportData['call_duration_min'] > 4294967295 || $reportData['call_duration_min'] < 0) {\n throw new InvalidArgumentException('Min call duration should be between 0 and 4294967295');\n }\n }\n\n if (isset($data['max_call_duration'])) {\n $reportData['call_duration_max'] = (int) $data['max_call_duration'] * 60;\n\n if ($reportData['call_duration_max'] > 4294967295 || $reportData['call_duration_max'] < 0) {\n throw new InvalidArgumentException('Max call duration should be between 0 and 4294967295');\n }\n }\n\n return $reportData;\n }\n\n private function validateCallTypes(array $data, array $reportData): array\n {\n // Set call types\n $reportData['call_types'] = $data['call_type'] ?? [];\n if (empty($reportData['call_types'])) {\n $reportData['call_types'] = self::getCallTypes();\n }\n\n foreach ($reportData['call_types'] as $callType) {\n if (! in_array($callType, self::getCallTypes(), true)) {\n throw new InvalidArgumentException(sprintf('Call type %s is invalid', $callType));\n }\n }\n\n return $reportData;\n }\n\n private function validateMediaTypes(array $data, array $reportData): array\n {\n // Set media types from input data\n $reportData['media_types'] = $data['media_types'] ?? [];\n\n if (empty($reportData['media_types'])) {\n throw new InvalidArgumentException('Media types are required');\n }\n\n foreach ($reportData['media_types'] as $mediaType) {\n if (! in_array($mediaType, self::MEDIA_TYPES, true)) {\n throw new InvalidArgumentException(sprintf('Media type %s is invalid', $mediaType));\n }\n }\n\n return $reportData;\n }\n\n private function validateDealStages(array $data, array $reportData, Team $team, string $reportType): array\n {\n // Validate and set deal stages\n if (isset($data['deal_stage_at_call'])) {\n $reportData['deal_at_call_stages'] =\n $this->validateAndGetDealStageIds($team, $data['deal_stage_at_call'], 'Deal stage at call');\n }\n\n if (isset($data['current_deal_stage'])) {\n $reportData['current_deal_stages'] =\n $this->validateAndGetDealStageIds($team, $data['current_deal_stage'], 'Current deal stage');\n }\n\n // Ensure current_deal_stage is not provided for loss_analysis report type\n if ($reportType === self::TYPE_LOSS_ANALYSIS && ! empty($data['current_deal_stage'])) {\n throw new InvalidArgumentException('Current deal stage is not applicable for Loss Analysis reports');\n }\n\n return $reportData;\n }\n\n // transform uuid to id\n private function validatePlaybookCategories(array $data, array $reportData, Team $team): array\n {\n $key = 'playbook_categories';\n\n if (isset($data[$key])) {\n $payloadIds = $data[$key];\n $ids = [];\n\n foreach ($payloadIds as $uuid) {\n $uuid = (string) $uuid;\n\n try {\n $playbookCategory = $this->playbookCategoryRepository->findByUuid($uuid);\n } catch (Throwable $throwable) {\n Log::error(__METHOD__ . ' ' . $throwable->getMessage());\n\n throw new InvalidArgumentException(sprintf('Playbook category %s not found', $uuid));\n }\n\n if (! $playbookCategory) {\n throw new InvalidArgumentException(sprintf('Playbook category %s not found', $uuid));\n }\n\n if (! $playbookCategory->hasPlaybook()) {\n throw new InvalidArgumentException(sprintf('Playbook category %s has no playbook', $uuid));\n }\n\n if ($playbookCategory->getPlaybook()->getTeamId() !== $team->getId()) {\n throw new InvalidArgumentException(\n sprintf('Playbook category %s not found for team %s', $uuid, $team->getUuid())\n );\n }\n\n $ids[] = $playbookCategory->getId();\n }\n\n $reportData[$key] = $ids;\n }\n\n return $reportData;\n }\n\n private function validateReportStatus($status): bool\n {\n if (! in_array($status, [true, false], true)) {\n throw new InvalidArgumentException('Report status is invalid');\n }\n\n return $status;\n }\n\n private function validateReportType($type): string\n {\n if (! in_array($type, self::getTypes(), true)) {\n throw new InvalidArgumentException(sprintf('Report type is invalid: %s', $type));\n }\n\n return $type;\n }\n\n private function validateFrequency($frequency): string\n {\n if (! in_array($frequency, self::getFrequencies(), true)) {\n throw new InvalidArgumentException('Frequency is invalid');\n }\n\n return $frequency;\n }\n\n private function validateAdditionalPromptInput(?string $additionalPromptInput): ?string\n {\n if ($additionalPromptInput && strlen($additionalPromptInput) > 5000) {\n throw new InvalidArgumentException('Additional Prompt Input should be less than 5000 characters');\n }\n\n return $additionalPromptInput;\n }\n\n private function validateCustomReportName(?string $customReportName): ?string\n {\n if ($customReportName === null || $customReportName === '') {\n return null;\n }\n\n if (strlen($customReportName) > 70) {\n throw new InvalidArgumentException('Custom report name should be less than 70 characters');\n }\n\n return $customReportName;\n }\n\n private function validateOrganization(?string $organizationUuid): Team\n {\n if (! $organizationUuid) {\n throw new InvalidArgumentException('Organization is required');\n }\n\n $team = $this->teamRepository->idOrUuid($organizationUuid);\n\n if (! $team) {\n throw new InvalidArgumentException('Organization not found');\n }\n\n if (! $team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {\n throw new InvalidArgumentException('Organization does not have the Automated Reports feature');\n }\n\n return $team;\n }\n\n private function validateAndGetGroupIds(Team $team, array $teamUuids): array\n {\n $groupIds = [];\n\n foreach ($teamUuids as $uuid) {\n $group = $this->groupRepository->findByUuid($uuid);\n\n if ($group === null || $group->getTeamId() !== $team->getId()) {\n throw new InvalidArgumentException(\n sprintf('Group %s not found for team %s', $uuid, $team->getUuid())\n );\n }\n\n $groupIds[] = $group->getId();\n\n }\n\n return $groupIds;\n }\n\n private function validateAndGetDealStageIds(Team $team, array $stageUuids, string $propertyLabel): array\n {\n $stageIds = [];\n\n foreach ($stageUuids as $uuid) {\n $stage = $this->stageRepository->findByUuid($uuid);\n\n if ($stage === null || $stage->getTeamId() !== $team->getId()) {\n throw new InvalidArgumentException(\n sprintf('Stage %s not found for team %s for %s', $uuid, $team->getUuid(), $propertyLabel)\n );\n }\n\n $stageIds[] = $stage->getId();\n }\n\n return $stageIds;\n }\n\n private function validateAndGetUserIds(array $userUuids, callable $teamCheck): array\n {\n if (empty($userUuids)) {\n return [];\n }\n\n $userIds = [];\n\n foreach ($userUuids as $uuid) {\n $user = $this->userRepository->findByUuid($uuid);\n\n if (! $user || ! $user->isStatusActive()) {\n throw new InvalidArgumentException(\n sprintf('User %s not found or is not active', $uuid)\n );\n }\n\n if (! $teamCheck($user)) {\n throw new InvalidArgumentException(\n sprintf('User %s does not belong to the allowed team(s)', $uuid)\n );\n }\n\n $userIds[] = $user->getId();\n }\n\n return $userIds;\n }\n\n private function validateAndGetUserIdsByTeam(Team $team, array $userUuids): array\n {\n return $this->validateAndGetUserIds($userUuids, fn ($user) => $user->getTeamId() === $team->getId());\n }\n\n private function validateAndGetJiminnyUserIds(array $userUuids): array\n {\n $allowedTeamIds = config('kiosk.teamIds', []);\n\n return $this->validateAndGetUserIds($userUuids, fn ($user) => in_array($user->getTeamId(), $allowedTeamIds, true));\n }\n\n private function parseDate(string $dateString): string\n {\n return date('Y-m-d H:i:s', strtotime($dateString));\n }\n\n private function generateReportResultViewUrl(AutomatedReportResult $result): string\n {\n $mediaResource = $this->getReportMediaRouteResource($result);\n\n return route('ai-reports.' . $mediaResource . '.view', ['uuid' => $result->getUuid()]);\n }\n\n private function generateReportResultDownloadUrl(AutomatedReportResult $result): string\n {\n $mediaResource = $this->getReportMediaRouteResource($result);\n\n return route('ai-reports.' . $mediaResource . '.download', ['uuid' => $result->getUuid()]);\n }\n\n private function getReportMediaRouteResource(AutomatedReportResult $result): string\n {\n if ($result->getMediaType() === self::MEDIA_TYPE_PDF) {\n return self::PDF_KEY;\n } elseif ($result->getMediaType() === self::MEDIA_TYPE_PODCAST) {\n return self::AUDIO_KEY;\n }\n\n throw new \\InvalidArgumentException('Unknown media type.');\n }\n\n public function getMediaPath(AutomatedReportResult $result): ?string\n {\n $url = match ($result->getMediaType()) {\n self::MEDIA_TYPE_PDF => $result->getPdfUrl(),\n self::MEDIA_TYPE_PODCAST => $result->getPodcastAudioUrl(),\n default => null,\n };\n\n if ($url === null) {\n return null;\n }\n\n $path = parse_url(trim($url, '\"\\''), PHP_URL_PATH);\n\n return $path ?: null;\n }\n\n public function getFilenameSuffix(AutomatedReportResult $result): ?string\n {\n return match ($result->getMediaType()) {\n self::MEDIA_TYPE_PODCAST => 'Podcast',\n default => null,\n };\n }\n\n public function getMailSubjectSuffix(AutomatedReportResult $result): string\n {\n return match ($result->getMediaType()) {\n self::MEDIA_TYPE_PDF => 'report',\n self::MEDIA_TYPE_PODCAST => 'podcast',\n default => '',\n };\n }\n\n public function getMediaTypeMetadata(AutomatedReportResult $result): array\n {\n return match ($result->getMediaType()) {\n self::MEDIA_TYPE_PODCAST => ['extension' => 'mp3', 'mime' => 'audio/mpeg'],\n self::MEDIA_TYPE_PDF => ['extension' => 'pdf', 'mime' => 'application/pdf'],\n default => ['extension' => null, 'mime' => null],\n };\n }\n\n public function deleteS3Files(AutomatedReportResult $result): void\n {\n $teamUuid = $result->getReport()->getTeam()->getUuid();\n $reportUuid = $result->getUuid();\n\n // delete all files for a report uuid no mather of pdf, podcast, or both\n // in case of both - the podcast files are linked to the pdf (parent) uuid\n // pdf and podcast date times should be close\n $path = sprintf('%s/%s/%s', $teamUuid, self::S3_DIR, $reportUuid);\n\n foreach (self::FILE_EXTENSIONS_VARIANTS as $extension) {\n $file = $path . '.' . $extension;\n\n if (Storage::exists($file)) {\n Storage::delete($file);\n Log::info('[Reports] Deleted S3 file', [\n 'path' => $file,\n ]);\n }\n }\n\n foreach (self::FILE_PODCAST_EXTENSIONS_VARIANTS as $extension) {\n $file = $path . '_podcast.' . $extension;\n\n if (Storage::exists($file)) {\n Storage::delete($file);\n Log::info('[Reports] Deleted Podcast S3 file', [\n 'path' => $file,\n ]);\n }\n }\n }\n\n /**\n *\n * @param int|null $teamId Optional team ID to filter results\n *\n * @return Collection<int, int> Collection of team IDs\n */\n public function getTeamIdsWithReportsResults(?int $teamId = null): Collection\n {\n return $this->automatedReportsRepository->getTeamIdsWithReportsResults($teamId);\n }\n\n /**\n * Core delete logic for report results using a query\n *\n * @param Builder $query\n * @param array $logContext\n *\n * @return int\n */\n private function deleteReportResultsByQuery(Builder $query, array $logContext = []): int\n {\n $deletedCount = 0;\n\n if ($query->exists()) {\n Log::info(\n 'Run delete report results',\n array_merge(\n $logContext,\n [\n 'service' => 'AutomatedReportsService',\n ]\n )\n );\n\n $query->chunkById(50, function ($results) use (&$deletedCount, $logContext) {\n foreach ($results as $result) {\n $this->deleteReportResult($result);\n $deletedCount++;\n\n Log::info(\n 'Deleted a report result',\n array_merge(\n $logContext,\n [\n 'result_id' => $result->getId(),\n 'report_id' => $result->getReportId(),\n ]\n )\n );\n }\n });\n }\n\n return $deletedCount;\n }\n\n /**\n * Delete report results for a team by retention period\n *\n * @param Team $team\n * @param CarbonImmutable $retentionDate\n *\n * @return int Number of deleted report results\n */\n public function deleteReportsResultsInRetentionPeriod(Team $team, CarbonImmutable $retentionDate): int\n {\n $reportIds = $this->automatedReportsRepository->getReportIdsByTeam($team);\n\n if ($reportIds->isEmpty()) {\n return 0;\n }\n\n $query = $this->automatedReportsRepository\n ->getReportResultsQueryForRetention($team, $retentionDate);\n\n return $this->deleteReportResultsByQuery($query, [\n 'team_id' => $team->getId(),\n 'retention_date' => $retentionDate->toDateTimeString(),\n ]);\n }\n\n /**\n * Delete ALL report results for a specific automated report\n *\n * @param string $uuid\n *\n * @return int\n */\n public function deleteReportResults(string $uuid): int\n {\n $report = $this->getReport($uuid);\n\n $query = $this->automatedReportsRepository->getResultsByReportQuery($report);\n\n return $this->deleteReportResultsByQuery($query, [\n 'report_uuid' => $uuid,\n 'report_id' => $report->getId(),\n ]);\n }\n\n public function deleteReportResult(AutomatedReportResult $result): void\n {\n $this->deleteS3Files($result);\n\n $result->delete();\n }\n\n /**\n * Get all reports for a specific team\n *\n * @param Team $team\n *\n * @return \\Illuminate\\Database\\Eloquent\\Collection\n */\n public function getTeamReports(Team $team): \\Illuminate\\Database\\Eloquent\\Collection\n {\n return $this->automatedReportsRepository->getReportsByTeam($team);\n }\n\n /**\n * Get all report results for a specific report\n *\n * @param AutomatedReport $report\n *\n * @return \\Illuminate\\Database\\Eloquent\\Collection\n */\n public function getReportResults(AutomatedReport $report): \\Illuminate\\Database\\Eloquent\\Collection\n {\n return $this->automatedReportsRepository->getResultsByReport($report);\n }\n\n public function deleteAllReportResults(AutomatedReport $report): void\n {\n $results = $this->getReportResults($report);\n\n /** @var AutomatedReportResult $result */\n foreach ($results as $result) {\n Log::info('Deleting result', [\n 'report' => $report->getId(),\n 'result' => $result->getId(),\n ]);\n\n $this->deleteReportResult($result);\n }\n }\n\n public function deleteAllData(Team $team): void\n {\n Log::info('Deleting automated report and results for team', [\n 'team' => $team->getId(),\n ]);\n\n $reports = $this->getTeamReports($team);\n\n /** @var AutomatedReport $report */\n foreach ($reports as $report) {\n Log::info('Deleting report', [\n 'team' => $team->getId(),\n 'report' => $report->getId(),\n ]);\n\n $this->deleteAllReportResults($report);\n\n $report->delete();\n }\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":true,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"Project","depth":3,"role_description":"text"},{"role":"AXButton","text":"Project","depth":3,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"New File or Directory…","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Expand Selected","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Collapse All","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Options","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false}]...
|
3397592283435315795
|
6686367547760219213
|
idle
|
accessibility
|
NULL
|
Project: faVsco.js, menu
#11894 on JY-18909-automa Project: faVsco.js, menu
#11894 on JY-18909-automated-reports-ask-jiminny, menu
Start Listening for PHP Debug Connections
AutomatedReportsCommandTest
Run 'AutomatedReportsCommandTest'
Debug 'AutomatedReportsCommandTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Execute
Explain Plan
Browse Query History
View Parameters
Open Query Execution Settings…
In-Editor Results
Tx: Auto
Cancel Running Statements
Playground
jiminny
Sync Changes
Hide This Notification
Code changed:
Hide
16
13
13
Previous Highlighted Error
Next Highlighted Error
SELECT * FROM teams WHERE id = 1;
select * from crm_layouts where crm_configuration_id = 39;
SELECT * FROM crm_layout_entities WHERE crm_layout_id = 283;
SELECT * FROM crm_fields WHERE id = 2234;
SELECT * FROM crm_field_values WHERE crm_field_id = 2234;
select * from crm_profiles where user_id = 143;
select * from record_types where crm_configuration_id = 39; # 0121K000001MHElQAO,0121K000001MHEqQAO
select * from business_processes where crm_configuration_id = 39;
# 01941000000H669AAC, 01941000000H66JAAS
select * from record_type_field_values
where record_type_id IN (24);
select * from crm_field_values where id IN (2730);
select * from crm_configurations where id = 39;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 1
and sa.provider = 'salesforce'; #1035
select * from users where team_id = 1; # 222 group 3
SELECT * FROM activities WHERE user_id = 222 order by id desc;
select * from sidekick_settings where team_id = 1;
select * from teams where id = 1;
select * from team_features where team_id = 1;
select * from activities where crm_configuration_id = 2
and provider = 'ms-teams' and id = 608765;
SELECT * FROM activities WHERE crm_configuration_id = 2 and crm_provider_id = '59523413338';
select * from sidekick_settings where team_id = 2;
SELECT * FROM activities WHERE id = 608660;
select * from activity_summary_logs where activity_id = 608660;
select * from ai_prompts where transcription_id = 11214;
# [PASSWORD_DOTS]
SELECT * FROM activities WHERE uuid_to_bin('ed78a437-2804-450e-ab2f-56ab1c641346') = uuid;
# id: 608818, crm: 59628809737
SELECT * FROM activities WHERE uuid_to_bin('36b06e55-afdd-4782-8dee-c624cd0af191') = uuid;
# id: 608821, crm: 59632069252
SELECT ce.start_time, ce.end_time, a.id, a.uuid, crm_provider_id, calendar_event_id, title,
playbook_category_id, user_id, lead_id, contact_id, account_id, opportunity_id,
scheduled_start_time, scheduled_end_time, actual_start_time, actual_end_time, a.created_at
FROM activities a
join calendar_events ce on a.calendar_event_id = ce.id
WHERE a.id IN (608818, 608821);
select * from users where team_id = 1;
select * from team_settings where team_id = 1;
select * from crm_profiles where crm_configuration_id = 39 order by user_id;
select * from team_features where team_id = 1;
select * from users where team_id = 2;
SELECT * FROM activities WHERE uuid_to_bin('ec7647e9-5225-458b-b475-f31aa2769204') = uuid; # 612639
# Preslava N. Ivanova, grou id 3
SELECT * FROM opportunities WHERE uuid_to_bin('a2928fe5-aec5-46cb-85d9-7654c89e46a6') = uuid;
select * from activities where opportunity_id = 344 and actual_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00';
select
a.id,
a.type,
a.scheduled_start_time,
a.actual_start_time,
a.created_at,
a.opportunity_id,
a.status
FROM activities a
WHERE opportunity_id = 344
and status IN ('completed', 'received', 'delivered')
and (
(a.actual_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00')
OR (a.created_at between '2024-10-11 00:00:00' and '2024-10-12 00:00:00')
OR (a.scheduled_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00'))
;
SELECT * FROM users WHERE id = 222;
SELECT * FROM crm_profiles WHERE user_id = 222;
select * from crm_layouts where crm_configuration_id = 39;
SELECT * FROM crm_layout_entities WHERE crm_layout_id = 281;
select * from group_deal_risk_types;
select * from opportunities where team_id = 1;
SELECT * FROM opportunities WHERE id = 315;
SELECT * FROM crm_field_data WHERE object_id = 315;
select * from crm_field_data where object_id = 260;
select * from generic_ai_prompts where subject_id = 315;
select * from teams; # 36, 21, 121, [EMAIL]
SELECT * FROM social_accounts WHERE sociable_id = 121 and provider = 'bullhorn';
# [PASSWORD_DOTS]
select * from teams where id = 1;
select * from crm_configurations where id = 39;
select * from users where team_id = 1;
select u.email, cp.* from users u
join crm_profiles cp on u.id = cp.user_id
where u.team_id = 1;
# 1 - 00541000004281rAAA
# 204 - 0052g000003freeAAA
# 429 - 0052g000003qGOiAAM
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 1
and sa.provider = 'salesforce';
select * from activities where type = 'softphone'
and created_at > '2024-12-11 15:24:36' order by id desc;
select * from activity_providers where team_id = 1;
select * from activity_provider_users where activity_provider_id = 328;
select * from opportunities where crm_configuration_id = 39
AND account_id = 178 AND is_closed = false
order by created_at DESC;
select * from contacts where id = 3952;
select * from accounts where id = 178;
# [PASSWORD_DOTS]
select * from teams where id = 36;
select * from crm_configurations where id = 21;
select * from users where team_id = 36;
select u.email, cp.* from users u
join crm_profiles cp on u.id = cp.user_id
where u.team_id = 36;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 36
and sa.provider = 'bullhorn';
select * from social_accounts where id = 348;
UPDATE social_accounts SET
provider_user_token = '21442_6802599_91:41179a58-21e7-4d7c-ad58-56bb666b2f65',
provider_refresh_token = '21442_6802599_91:01c6b335-3f2a-42e4-85ff-8a08fa65fceb',
expires = 1733998131,
state = 'connected'
WHERE id = 348;
# [PASSWORD_DOTS]
select * from teams where id = 31;
select * from crm_configurations where id = 18;
select * from users where team_id = 31; # 257
select u.email, cp.* from users u
join crm_profiles cp on u.id = cp.user_id
where u.team_id = 31;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 31
and sa.provider = 'close';
select * from contacts where crm_configuration_id = 18;
# [PASSWORD_DOTS] NEPTUNE [PASSWORD_DOTS]
select * from teams;
select * from users where id IN (1030, 1035, 1052);
select * from crm_configurations;
select * from users where team_id = 65; # 257
select * from team_settings where team_id = 65; # 257
select * from invitations where team_id = 65; # 257
select * from users where email = '[EMAIL]'; # 257
select u.email, cp.* from users u
join crm_profiles cp on u.id = cp.user_id
where u.team_id = 65;
select * from crm_configurations where id = 53;
select * from accounts where crm_configuration_id = 53 order by id desc;
select * from leads where crm_configuration_id = 53 order by id desc;
select * from contacts where crm_configuration_id = 53 order by id desc;
select * from opportunities where crm_configuration_id = 53 order by id desc;
select * from crm_profiles where crm_configuration_id = 53 order by id desc;
select * from crm_fields where crm_configuration_id = 53 order by id desc;
select * from crm_field_values where crm_field_id = 3341 order by id desc;
select * from crm_layouts where crm_configuration_id = 53 order by id desc;
select * from stages where crm_configuration_id = 53 order by id desc;
select * from crm_profiles where crm_configuration_id = 13;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 65
and sa.provider = 'integration-app';
select * from contacts where crm_configuration_id = 13;
select * from social_accounts where sociable_id = 283;
SELECT * FROM opportunities WHERE crm_provider_id = '006O400000E9bzeIAB';
select * from activity_providers where team_id = 65;
SELECT * FROM activities WHERE crm_configuration_id IN (51, 52, 53);
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 65
;
# [PASSWORD_DOTS] STAGING [PASSWORD_DOTS]
SELECT * FROM teams;
SELECT * FROM teams WHERE id = 88;
SELECT * FROM teams WHERE id = 89;
select * from team_settings where team_id = 89;
SELECT * FROM users WHERE team_id = 89;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 89;
select * from users;
SELECT * FROM social_accounts WHERE sociable_id = 1761;
SELECT * FROM crm_configurations WHERE id = 70;
select * from accounts where crm_configuration_id = 70 order by id desc;
select * from leads where crm_configuration_id = 70 order by id desc;
select * from contacts where crm_configuration_id = 70 order by id desc;
select * from opportunities where crm_configuration_id = 70 order by id desc;
select * from crm_profiles where crm_configuration_id = 70 order by id desc;
select * from crm_fields where crm_configuration_id = 70 order by id desc;
select * from crm_field_values where crm_field_id = 3536 order by id desc;
select * from crm_layouts where crm_configuration_id = 70 order by id desc;
select * from stages where crm_configuration_id = 70 order by id desc;
select * from business_processes where crm_configuration_id = 70 order by id desc;
select * from business_process_stages where business_process_id = 34;
select * from contacts where id = 10468;
select * from crm_layouts where crm_configuration_id = 70;
SELECT * FROM crm_layout_entities WHERE crm_layout_id = 388;
SELECT * FROM crm_fields WHERE id IN (3533,3534,3535);
select * from activities where crm_configuration_id = 70
and (account_id IS NOT NULL or lead_id IS NOT NULL or contact_id IS NOT NULL or opportunity_id IS NOT NULL) order by id desc;
SELECT * FROM activities WHERE uuid_to_bin('2e10b60f-8a61-41c5-a3d4-28835353dc65') = uuid;
SELECT * FROM activities where crm_configuration_id = 69 ;
SELECT * FROM users WHERE email LIKE '%[EMAIL]%';
SELECT * FROM activities WHERE uuid_to_bin('5a150c93-40fc-42ec-b3bd-c1d328e09f6e') = uuid;
SELECT * FROM opportunities WHERE id = 385;
select * from participants p
join activities a on p.activity_id = a.id
where a.crm_configuration_id = 70
and (p.lead_id IS NOT NULL or p.contact_id IS NOT NULL);
SELECT * FROM participants WHERE id = 1013638;
select * from teams where id = 90;
select * from users where team_id = 90;
select * from social_accounts where social_accounts.sociable_id IN (1960,1760);
SELECT * FROM crm_profiles WHERE crm_configuration_id = 71;
select * from invitations where team_id = 90;
select * from crm_configurations where id = 71;
select * from accounts where crm_configuration_id = 71 order by id desc;
select * from leads where crm_configuration_id = 71 order by id desc;
select * from contacts where crm_configuration_id = 71 order by id desc;
select * from opportunities where crm_configuration_id = 71 order by id desc;
select * from crm_profiles where crm_configuration_id = 71 order by id desc;
select * from crm_fields where crm_configuration_id = 71 order by id desc;
select * from crm_field_values where crm_field_id = 3341 order by id desc;
select * from crm_layouts where crm_configuration_id = 71 order by id desc;
select * from stages where crm_configuration_id = 71 order by id desc;
select * from users order by secondary_email desc;
select u.id, u.email, u.status, sa.id, sa.provider_user_id from social_accounts sa
join users u on sa.sociable_id = u.id
where sa.provider = 'google' and u.email LIKE 'aneliya%';
select * from failed_jobs order by id desc;
select * from users where email = '[EMAIL]' or secondary_email = '[EMAIL]';
select * from teams;
SELECT * FROM crm_profiles WHERE crm_configuration_id = 39;
SELECT * FROM crm_fields WHERE crm_configuration_id = 39 and object_type = 'task';
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 1
and sa.provider = 'salesforce';
# [PASSWORD_DOTS]
SELECT * FROM activities WHERE uuid_to_bin('c38b3895-fd0f-4b1f-9fb2-c170dba137c6') = uuid;
SELECT * FROM crm_configurations WHERE id = 70;
select * from teams where id = 1;
select * from groups where team_id = 1;
select * from users where team_id = 1;
select o.id, o.name,o.close_date, u.id, u.name, u.group_id, r.id, r.display_name, g.name, g.scope from opportunities o
join users u on o.user_id = u.id
join groups g on u.group_id = g.id
join role_user ru on u.id = ru.user_id
join roles r on ru.role_id = r.id
where o.crm_configuration_id = 39 and close_date > '2024-01-01 00:00:00';
select * from role_user where user_id = 143;
select * from roles;
select * from role_user;
select * from groups where id = 9;
select * from scope_groups where group_id = 9;
# [PASSWORD_DOTS]
select * from teams where id = 36;
select * from crm_configurations;
SELECT * FROM social_accounts WHERE sociable_id = 121;
[URL_WITH_CREDENTIALS] this will add filter, however if we need to control feature by FF we need conditional logic
public const array TYPES = [
['id' => 'exec_summary', 'name' => 'Exec Summary'],
['id' => 'coaching_profiles', 'name' => 'Coaching Profiles'],
['id' => 'product_feedback', 'name' => 'Product Feedback'],
['id' => self::TYPE_LOSS_ANALYSIS, 'name' => 'Loss Analysis'],
// ['id' => 'questions', 'name' => 'Questions'],
// ['id' => 'statistical_quant', 'name' => 'Statistical Quantitative'],
];
public const array ALL_TYPES = [
...self::TYPES,
['id' => self::TYPE_ASK_JIMINNY, 'name' => 'Ask Jiminny'],
];
public const string FREQUENCY_DAILY = 'daily';
public const string FREQUENCY_WEEKLY = 'weekly';
public const string FREQUENCY_MONTHLY = 'monthly';
public const string FREQUENCY_QUARTERLY = 'quarterly';
public const string FREQUENCY_ONE_OFF = 'one_off';
/**
* Frequencies for standard (non-Ask Jiminny) reports.
*/
public const array FREQUENCIES = [
['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],
['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],
['id' => self::FREQUENCY_QUARTERLY, 'name' => 'Quarterly'],
['id' => self::FREQUENCY_ONE_OFF, 'name' => 'One-off'],
];
/**
* Frequencies for Ask Jiminny reports.
*/
public const array ASK_JIMINNY_FREQUENCIES = [
['id' => self::FREQUENCY_DAILY, 'name' => 'Daily'],
['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],
['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],
];
public const string MEDIA_TYPE_PDF = 'pdf';
public const string MEDIA_TYPE_PODCAST = 'podcast';
public const array MEDIA_TYPES = [self::MEDIA_TYPE_PDF, self::MEDIA_TYPE_PODCAST];
public const array MEDIA_TYPE_OBJECT_PDF = ['id' => self::MEDIA_TYPE_PDF, 'name' => 'PDF'];
public const array MEDIA_TYPE_OBJECT_PODCAST = ['id' => self::MEDIA_TYPE_PODCAST, 'name' => 'Podcast'];
public const array MEDIA_TYPE_OBJECTS = [self::MEDIA_TYPE_OBJECT_PDF, self::MEDIA_TYPE_OBJECT_PODCAST];
public const array CALL_TYPE_CONFERENCE = ['id' => 'conference', 'name' => 'Conference'];
public const array CALL_TYPE_DIALER = ['id' => 'dialer', 'name' => 'Dialer'];
public const int SENT_REPORT_AT_HOURS = 5;
public const string PDF_KEY = 'pdf';
public const string AUDIO_KEY = 'audio';
private const array ALL_FREQUENCIES = [
['id' => self::FREQUENCY_DAILY, 'name' => 'Daily'],
['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],
['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],
['id' => self::FREQUENCY_QUARTERLY, 'name' => 'Quarterly'],
['id' => self::FREQUENCY_ONE_OFF, 'name' => 'One-off'],
];
private const string S3_DIR = 'reports';
private const array FILE_EXTENSIONS_VARIANTS = ['html', 'MD', 'pdf'];
private const array FILE_PODCAST_EXTENSIONS_VARIANTS = ['json', 'mp3', 'ssml'];
public function __construct(
private readonly TeamRepository $teamRepository,
private readonly GroupRepository $groupRepository,
private readonly UserRepository $userRepository,
private readonly StageRepository $stageRepository,
private readonly DealStagesService $dealStagesService,
private readonly RecipientsService $recipientsService,
private readonly AutomatedReportsRepository $automatedReportsRepository,
private readonly Webhook $webhookService,
private readonly BusDispatcher $dispatcher,
private readonly ActivityTypeService $activityTypeService,
private readonly PlaybookCategoryRepository $playbookCategoryRepository,
private readonly AskAnythingPromptService $askAnythingPromptService,
private readonly SearchRepository $activitySearchRepository,
private readonly AskAnythingRepository $askAnythingRepository,
) {
}
public static function getTypes(): array
{
$types = self::TYPES;
return array_map(static function ($type) {
return $type['id'];
}, $types);
}
public static function getCallTypes(): array
{
return array_map(static function ($callType) {
return $callType['id'];
}, [self::CALL_TYPE_CONFERENCE, self::CALL_TYPE_DIALER]);
}
public static function getFrequencies(): array
{
return array_map(static function ($frequency) {
return $frequency['id'];
}, self::FREQUENCIES);
}
// front-facing structure
public function getReportEnabledFieldData(bool $value = false): array
{
return [
'id' => 'report_enabled',
'label' => '',
'inputType' => InputTypeEnum::TOGGLE,
'value' => $value,
];
}
// Organizations = Teams
public function getOrganizationFieldData(?string $value = null, bool $shortVersion = false): array
{
$options = $this->getTeams();
if ($shortVersion) {
return [
'id' => 'organization',
'label' => 'Organization',
'options' => $options,
];
}
return [
'id' => 'organization',
'label' => 'Organization',
'inputType' => InputTypeEnum::DROPDOWN,
'required' => true,
'placeholder' => 'Select',
'options' => $options,
'value' => $value,
'dependencies' => [
'teams',
'deal_stage_at_call',
'current_deal_stage',
'recipients',
ActivityTypeService::PLAYBOOK_CATEGORIES_KEY,
],
'dependsOn' => [],
];
}
// Teams = Groups
public function getTeamFieldData(array $options = [], array $value = [], bool $shortVersion = false): array
{
if ($shortVersion) {
return [
'id' => 'teams',
'label' => 'Team',
'options' => $options,
];
}
return [
'id' => 'teams',
'label' => 'Team',
'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,
'required' => false,
'placeholder' => 'Select',
'options' => $options,
'value' => $value, // value should be an array of objects {id, name}
'dependencies' => [ActivityTypeService::PLAYBOOK_CATEGORIES_KEY],
'dependsOn' => [],
];
}
public function getReportTypeFieldData(?string $value = null, bool $shortVersion = false, ?Team $team = null): array
{
$types = [];
if ($team instanceof Team) {
if ($team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {
$types = self::TYPES;
}
if ($team->hasFeature(FeatureEnum::ASK_JIMINNY_REPORTS)) {
$types[] = ['id' => self::TYPE_ASK_JIMINNY, 'name' => 'Ask Jiminny'];
}
} else {
$types = self::TYPES;
}
if ($shortVersion) {
return [
'id' => 'report_type',
'label' => 'Report Type',
'options' => $types,
];
}
return [
'id' => 'report_type',
'label' => 'Report Type',
'inputType' => InputTypeEnum::DROPDOWN,
'required' => true,
'placeholder' => 'Select',
'options' => $types,
'value' => $value,
'dependencies' => [],
'dependsOn' => [],
];
}
public function getFrequencyFieldData(?string $value = null): array
{
return [
'id' => 'frequency',
'label' => 'Frequency',
'inputType' => InputTypeEnum::DROPDOWN,
'required' => true,
'placeholder' => 'Select',
'options' => self::FREQUENCIES,
'value' => $value,
'dependencies' => ['period'],
'dependsOn' => [],
];
}
public function getPeriodFieldData(?string $valueStartDate = null, ?string $valueEndDate = null): array
{
return [
'id' => 'period',
'label' => 'Select one-off period',
'inputType' => InputTypeEnum::DATE_RANGE,
'required' => true,
'placeholder' => 'Select',
'value' => ['startDate' => $valueStartDate, 'endDate' => $valueEndDate],
'queryParams' => [
'startDate' => 'start_date_period',
'endDate' => 'end_date_period',
],
'dependencies' => [],
'dependsOn' => ['frequency'],
];
}
public function getActivityTypesFieldData(?Team $team = null, array $value = [], array $teamsFilter = []): array
{
return $this->activityTypeService->getActivityTypeFieldData(team: $team, value: $value, groupIds: $teamsFilter);
}
public function getDealStageAtCallFieldData(?Team $team = null, array $value = []): array
{
return $this->dealStagesService->getDealStageAtCallFieldData(team: $team, value: $value);
}
public function getCurrentDealStageFieldData(?Team $team = null, array $value = []): array
{
return $this->dealStagesService->getCurrentDealStageFieldData(team: $team, value: $value);
}
public function getDealValueFieldData(?int $valueMin = null, ?int $valueMax = null): array
{
return [
'id' => 'deal_value',
'label' => 'Deal Value',
'inputType' => InputTypeEnum::INTEGER_RANGE,
'required' => false,
'value' => ['min' => $valueMin, 'max' => $valueMax],
'queryParams' => [
'min' => 'min_deal_value',
'max' => 'max_deal_value',
],
'dependencies' => [],
'dependsOn' => [],
];
}
public function getCallTypeFieldData(bool $conferenceOn = false, bool $dialerOn = false): array
{
$value = [];
$conferenceOn && $value[] = self::CALL_TYPE_CONFERENCE;
$dialerOn && $value[] = self::CALL_TYPE_DIALER;
return [
'id' => 'call_type',
'label' => 'Call Type',
'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,
'required' => true,
'options' => [
self::CALL_TYPE_CONFERENCE,
self::CALL_TYPE_DIALER,
],
'value' => $value,
'dependencies' => [],
'dependsOn' => [],
];
}
public function getMediaTypeFieldData(?AutomatedReport $report = null): array
{
$value = [];
if ($report) {
$value = $this->transformMediaTypes($report);
}
return [
'id' => 'media_types',
'label' => 'Export as',
'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,
'required' => true,
'options' => self::MEDIA_TYPE_OBJECTS,
'value' => $value,
'dependencies' => [],
'dependsOn' => [],
];
}
public function getCallDurationFieldData(?int $valueMin = null, ?int $valueMax = null): array
{
return [
'id' => 'call_duration',
'label' => 'Call Duration',
'inputType' => InputTypeEnum::INTEGER_RANGE,
'required' => false,
'value' => ['min' => $valueMin, 'max' => $valueMax],
'queryParams' => [
'min' => 'min_call_duration',
'max' => 'max_call_duration',
],
'dependencies' => [],
'dependsOn' => [],
];
}
public function getRecipientsFieldData(?Team $team = null, array $value = []): array
{
return $this->recipientsService->getRecipientsFieldData(team: $team, value: $value);
}
public function getJiminnyRecipientsFieldData(array $value = []): array
{
return $this->recipientsService->getJiminnyRecipientsFieldData($value);
}
public function getAdditionalPromptInputFieldData(?string $value = null): array
{
return [
'id' => 'additional_prompt_input',
'label' => 'Special requirements',
'inputType' => InputTypeEnum::TEXTAREA,
'required' => false,
'placeholder' => 'What should be the focus of the report?',
'value' => $value,
'dependencies' => [],
'dependsOn' => [],
];
}
public function getCustomReportNameFieldData(?string $value = null): array
{
return [
'id' => 'custom_name',
'label' => 'Custom report name',
'inputType' => InputTypeEnum::TEXT,
'required' => false,
'placeholder' => 'Enter custom name',
'value' => $value,
'dependencies' => [],
'dependsOn' => [],
];
}
// data providers
public function getTeams(): array
{
$teams = $this->teamRepository->getTeamsForKiosk(status: Team::STATUS_ACTIVE);
$teamData = [];
foreach ($teams as $team) {
if (! $team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {
continue;
}
$teamData[] = $this->transformTeam($team);
}
return $teamData;
}
public function getTeamGroups(string $teamUuid): array
{
$data = [];
$team = $this->getTeam($teamUuid);
if ($team !== null) {
$groups = $team->groups()->get();
foreach ($groups as $group) {
$data[] = [
'id' => $group->getUuid(),
'name' => $group->getName(),
];
}
}
return $data;
}
public function getTeamsGroupsOptions(array $filterTeamUuids = []): array
{
$data = [];
$teams = $this->getTeams();
foreach ($teams as $team) {
if (! empty($filterTeamUuids) && ! in_array($team['id'], $filterTeamUuids, true)) {
continue;
}
$data[] = [
'label' => $team['name'],
'groups' => $this->getTeamGroups($team['id']),
];
}
return $data;
}
public function getTeam(string $teamUuid): ?Team
{
return $this->teamRepository->idOrUuid($teamUuid);
}
public function getTeamById(int $teamId): ?Team
{
return $this->teamRepository->find($teamId);
}
public function getGroupsUuids(AutomatedReport $report): array
{
$uuids = [];
$reportGroups = $report->getGroups();
foreach ($reportGroups as $groupId) {
if ($group = $this->groupRepository->find($groupId)) {
$uuids[] = $group->getUuid();
}
}
return $uuids;
}
public function getPlaybookCategoriesUuids(AutomatedReport $report): array
{
$uuids = [];
$playbookCategories = $report->getPlaybookCategories();
foreach ($playbookCategories as $id) {
if ($category = $this->playbookCategoryRepository->find($id)) {
$uuids[] = $category->getUuid();
}
}
return $uuids;
}
public function getDealAtCallStagesUuids(AutomatedReport $report): array
{
$uuids = [];
$reportStages = $report->getDealAtCallStages();
foreach ($reportStages as $id) {
if ($stage = $this->stageRepository->find($id)) {
$uuids[] = $stage->getUuid();
}
}
return $uuids;
}
public function getCurrentDealStagesUuids(AutomatedReport $report): array
{
$uuids = [];
$reportStages = $report->getCurrentDealStages();
foreach ($reportStages as $id) {
if ($stage = $this->stageRepository->find($id)) {
$uuids[] = $stage->getUuid();
}
}
return $uuids;
}
public function getUsersUuids(AutomatedReport $report): array
{
return $this->extractUserUuids($report->getRecipients());
}
public function getJiminnyUsersUuids(AutomatedReport $report): array
{
return $this->extractUserUuids($report->getJiminnyRecipients());
}
/**
* @param array<string, mixed> $recipients
*/
private function extractUserUuids(array $recipients): array
{
$userIds = $recipients['users'] ?? [];
return collect($userIds)
->map(fn ($id) => $this->userRepository->find((int) $id))
->filter()
->map(fn (UserContract $user) => $user->getUuid())
->values()
->all();
}
// get mail data
public function getRecipientUsers(AutomatedReport $report): array
{
return $this->buildRecipientUsers($report->getRecipients());
}
private function getJiminnyRecipientUsers(AutomatedReport $report): array
{
return $this->buildRecipientUsers($report->getJiminnyRecipients());
}
/**
* @param array<string, mixed> $recipients
*/
private function buildRecipientUsers(array $recipients): array
{
$userIds = $recipients['users'] ?? [];
return collect($userIds)
->map(fn ($id) => $this->userRepository->find((int) $id))
->filter()
->map(fn (UserContract $user) => [
'email' => $user->getEmailAddress(),
'name' => $user->getName(),
'timezone' => $user->getTimezone()->getName(),
])
->values()
->all();
}
public function getValidRecipientUsers(AutomatedReport $report, bool $includeJiminny = false): array
{
if ($report->isAskJiminnyReport()) {
$recipients = $this->resolveAskJiminnyRecipients($report);
} else {
$recipients = $this->getRecipientUsers($report);
if ($includeJiminny) {
$recipients = array_merge($recipients, $this->getJiminnyRecipientUsers($report));
}
}
$emails = [];
return array_values(array_filter(
$recipients,
static function ($recipient) use (&$emails) {
if (empty($recipient['email']) || in_array($recipient['email'], $emails, true)) {
return false;
}
$emails[] = $recipient['email'];
return true;
}
));
}
private function resolveAskJiminnyRecipients(AutomatedReport $report): array
{
$recipients = [];
$creator = $report->getCreator();
if ($creator !== null) {
$recipients[] = [
'email' => $creator->getEmailAddress(),
'name' => $creator->getName(),
'timezone' => $creator->getTimezone()->getName(),
];
}
return array_merge(
$recipients,
$this->buildRecipientUsers($report->getRecipients()),
$this->getGroupRecipientUsers($report),
);
}
private function getGroupRecipientUsers(AutomatedReport $report): array
{
$users = [];
foreach ($report->getGroups() as $groupId) {
$group = $this->groupRepository->find($groupId);
if ($group === null) {
continue;
}
foreach ($group->getMembers() as $member) {
$users[] = [
'email' => $member->getEmailAddress(),
'name' => $member->getName(),
'timezone' => $member->getTimezone()->getName(),
];
}
}
return $users;
}
public function getReportTypeName(AutomatedReportResult $report): string
{
$type = $report->getReport()->getType();
$getType = $this->transformReportType($type);
return $getType['name'];
}
public function getReportPeriodName(AutomatedReportResult $report): string
{
$from = $report->getFromDate();
$to = $report->getToDate();
$frequency = $report->getReport()->getFrequency();
if ($from === null || $to === null) {
if (! $report->getReport()->isAskJiminnyReport()) {
$invalidPeriod = $from === null ? 'from' : 'to';
throw new ApplicationException('Report period is invalid: ' . $invalidPeriod);
}
$period = $this->calculateFromAndToDatePeriod($frequency);
$from = $period['fromDate'];
$to = $period['toDate'];
}
return $this->formatReportPeriodName($frequency, $from, $to);
}
private function formatReportPeriodName(string $frequency, Carbon $from, Carbon $to): string
{
$fromYear = $from->format('Y');
$toYear = $to->format('Y');
$differentYears = $fromYear !== $toYear;
switch ($frequency) {
case self::FREQUENCY_DAILY:
return $from->format('j M Y');
case self::FREQUENCY_QUARTERLY:
// 'Jan-Mar 2025' or 'Nov 2024-Jan 2025' if years differ
$startMonth = $from->format('M');
$endMonth = $to->copy()->subMonth();
$endMonthName = $endMonth->format('M');
$endMonthYear = $endMonth->format('Y');
if ($differentYears) {
return "{$startMonth} {$fromYear} - {$endMonthName} {$endMonthYear}";
}
return "{$startMonth} - {$endMonthName} {$toYear}";
case self::FREQUENCY_MONTHLY:
// 'May 2025' - monthly reports are always within the same year
return $from->format('M Y');
case self::FREQUENCY_WEEKLY:
// '4 - 8 Aug 2025', '27 Oct - 3 Nov 2025', or '28 Dec 2024 - 3 Jan 2025' if years differ
$startDay = $from->format('j');
$endDay = $to->format('j');
$startMonth = $from->format('M');
$endMonth = $to->format('M');
if ($differentYears) {
return "{$startDay} {$startMonth} {$fromYear} - {$endDay} {$endMonth} {$toYear}";
}
if ($startMonth !== $endMonth) {
return "{$startDay} {$startMonth} - {$endDay} {$endMonth} {$toYear}";
}
return "{$startDay} - {$endDay} {$endMonth} {$toYear}";
case self::FREQUENCY_ONE_OFF:
// '2 May-31 May 2025' or '15 Dec 2024-15 Jan 2025' if years differ
$startDay = $from->format('j');
$startMonth = $from->format('M');
$endDay = $to->format('j');
$endMonth = $to->format('M');
// If same month and year, use a format like '2-31 May 2025'
if ($startMonth === $endMonth && ! $differentYears) {
return "{$startDay} - {$endDay} {$startMonth} {$toYear}";
}
// If different years, include both years
if ($differentYears) {
return "{$startDay} {$startMonth} {$fromYear} - {$endDay} {$endMonth} {$toYear}";
}
// Same year but different months
return "{$startDay} {$startMonth} - {$endDay} {$endMonth} {$toYear}";
default:
// Default format for unknown frequencies
return $from->format('j M Y') . ' - ' . $to->format('j M Y');
}
}
public function getReportTeamsName(AutomatedReportResult $report): string
{
$groups = $report->getGroups();
if (empty($groups)) {
return 'All';
}
// Get group names from repository
$groupNames = [];
foreach ($groups as $groupId) {
$group = $this->groupRepository->find($groupId);
if ($group) {
$groupNames[] = $group->getName();
}
}
if (count($groupNames) === 1) {
// Single team format
$teamsName = $groupNames[0];
} else {
// Multiple teams format
$teamsName = implode(', ', $groupNames);
}
return $teamsName;
}
public function getReportFileName(AutomatedReportResult $report): string
...
|
12308
|
|
12321
|
NULL
|
0
|
2026-04-14T11:05:00.689167+00:00
|
/Users/lukas/.screenpipe/data/data/2026-04-14/1776 /Users/lukas/.screenpipe/data/data/2026-04-14/1776164700689_m1.jpg...
|
PhpStorm
|
faVsco.js – AutomatedReportsService.php
|
1
|
NULL
|
monitor_1
|
NULL
|
NULL
|
NULL
|
NULL
|
Project: faVsco.js, menu
#11894 on JY-18909-automa Project: faVsco.js, menu
#11894 on JY-18909-automated-reports-ask-jiminny, menu
Start Listening for PHP Debug Connections
AutomatedReportsCommandTest
Run 'AutomatedReportsCommandTest'
Debug 'AutomatedReportsCommandTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Execute
Explain Plan
Browse Query History
View Parameters
Open Query Execution Settings…
In-Editor Results
Tx: Auto
Cancel Running Statements
Playground
jiminny
Sync Changes
Hide This Notification
Code changed:
Hide
16
13
13
Previous Highlighted Error
Next Highlighted Error
SELECT * FROM teams WHERE id = 1;
select * from crm_layouts where crm_configuration_id = 39;
SELECT * FROM crm_layout_entities WHERE crm_layout_id = 283;
SELECT * FROM crm_fields WHERE id = 2234;
SELECT * FROM crm_field_values WHERE crm_field_id = 2234;
select * from crm_profiles where user_id = 143;
select * from record_types where crm_configuration_id = 39; # 0121K000001MHElQAO,0121K000001MHEqQAO
select * from business_processes where crm_configuration_id = 39;
# 01941000000H669AAC, 01941000000H66JAAS
select * from record_type_field_values
where record_type_id IN (24);
select * from crm_field_values where id IN (2730);
select * from crm_configurations where id = 39;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 1
and sa.provider = 'salesforce'; #1035
select * from users where team_id = 1; # 222 group 3
SELECT * FROM activities WHERE user_id = 222 order by id desc;
select * from sidekick_settings where team_id = 1;
select * from teams where id = 1;
select * from team_features where team_id = 1;
select * from activities where crm_configuration_id = 2
and provider = 'ms-teams' and id = 608765;
SELECT * FROM activities WHERE crm_configuration_id = 2 and crm_provider_id = '59523413338';
select * from sidekick_settings where team_id = 2;
SELECT * FROM activities WHERE id = 608660;
select * from activity_summary_logs where activity_id = 608660;
select * from ai_prompts where transcription_id = 11214;
# [PASSWORD_DOTS]
SELECT * FROM activities WHERE uuid_to_bin('ed78a437-2804-450e-ab2f-56ab1c641346') = uuid;
# id: 608818, crm: 59628809737
SELECT * FROM activities WHERE uuid_to_bin('36b06e55-afdd-4782-8dee-c624cd0af191') = uuid;
# id: 608821, crm: 59632069252
SELECT ce.start_time, ce.end_time, a.id, a.uuid, crm_provider_id, calendar_event_id, title,
playbook_category_id, user_id, lead_id, contact_id, account_id, opportunity_id,
scheduled_start_time, scheduled_end_time, actual_start_time, actual_end_time, a.created_at
FROM activities a
join calendar_events ce on a.calendar_event_id = ce.id
WHERE a.id IN (608818, 608821);
select * from users where team_id = 1;
select * from team_settings where team_id = 1;
select * from crm_profiles where crm_configuration_id = 39 order by user_id;
select * from team_features where team_id = 1;
select * from users where team_id = 2;
SELECT * FROM activities WHERE uuid_to_bin('ec7647e9-5225-458b-b475-f31aa2769204') = uuid; # 612639
# Preslava N. Ivanova, grou id 3
SELECT * FROM opportunities WHERE uuid_to_bin('a2928fe5-aec5-46cb-85d9-7654c89e46a6') = uuid;
select * from activities where opportunity_id = 344 and actual_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00';
select
a.id,
a.type,
a.scheduled_start_time,
a.actual_start_time,
a.created_at,
a.opportunity_id,
a.status
FROM activities a
WHERE opportunity_id = 344
and status IN ('completed', 'received', 'delivered')
and (
(a.actual_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00')
OR (a.created_at between '2024-10-11 00:00:00' and '2024-10-12 00:00:00')
OR (a.scheduled_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00'))
;
SELECT * FROM users WHERE id = 222;
SELECT * FROM crm_profiles WHERE user_id = 222;
select * from crm_layouts where crm_configuration_id = 39;
SELECT * FROM crm_layout_entities WHERE crm_layout_id = 281;
select * from group_deal_risk_types;
select * from opportunities where team_id = 1;
SELECT * FROM opportunities WHERE id = 315;
SELECT * FROM crm_field_data WHERE object_id = 315;
select * from crm_field_data where object_id = 260;
select * from generic_ai_prompts where subject_id = 315;
select * from teams; # 36, 21, 121, [EMAIL]
SELECT * FROM social_accounts WHERE sociable_id = 121 and provider = 'bullhorn';
# [PASSWORD_DOTS]
select * from teams where id = 1;
select * from crm_configurations where id = 39;
select * from users where team_id = 1;
select u.email, cp.* from users u
join crm_profiles cp on u.id = cp.user_id
where u.team_id = 1;
# 1 - 00541000004281rAAA
# 204 - 0052g000003freeAAA
# 429 - 0052g000003qGOiAAM
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 1
and sa.provider = 'salesforce';
select * from activities where type = 'softphone'
and created_at > '2024-12-11 15:24:36' order by id desc;
select * from activity_providers where team_id = 1;
select * from activity_provider_users where activity_provider_id = 328;
select * from opportunities where crm_configuration_id = 39
AND account_id = 178 AND is_closed = false
order by created_at DESC;
select * from contacts where id = 3952;
select * from accounts where id = 178;
# [PASSWORD_DOTS]
select * from teams where id = 36;
select * from crm_configurations where id = 21;
select * from users where team_id = 36;
select u.email, cp.* from users u
join crm_profiles cp on u.id = cp.user_id
where u.team_id = 36;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 36
and sa.provider = 'bullhorn';
select * from social_accounts where id = 348;
UPDATE social_accounts SET
provider_user_token = '21442_6802599_91:41179a58-21e7-4d7c-ad58-56bb666b2f65',
provider_refresh_token = '21442_6802599_91:01c6b335-3f2a-42e4-85ff-8a08fa65fceb',
expires = 1733998131,
state = 'connected'
WHERE id = 348;
# [PASSWORD_DOTS]
select * from teams where id = 31;
select * from crm_configurations where id = 18;
select * from users where team_id = 31; # 257
select u.email, cp.* from users u
join crm_profiles cp on u.id = cp.user_id
where u.team_id = 31;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 31
and sa.provider = 'close';
select * from contacts where crm_configuration_id = 18;
# [PASSWORD_DOTS] NEPTUNE [PASSWORD_DOTS]
select * from teams;
select * from users where id IN (1030, 1035, 1052);
select * from crm_configurations;
select * from users where team_id = 65; # 257
select * from team_settings where team_id = 65; # 257
select * from invitations where team_id = 65; # 257
select * from users where email = '[EMAIL]'; # 257
select u.email, cp.* from users u
join crm_profiles cp on u.id = cp.user_id
where u.team_id = 65;
select * from crm_configurations where id = 53;
select * from accounts where crm_configuration_id = 53 order by id desc;
select * from leads where crm_configuration_id = 53 order by id desc;
select * from contacts where crm_configuration_id = 53 order by id desc;
select * from opportunities where crm_configuration_id = 53 order by id desc;
select * from crm_profiles where crm_configuration_id = 53 order by id desc;
select * from crm_fields where crm_configuration_id = 53 order by id desc;
select * from crm_field_values where crm_field_id = 3341 order by id desc;
select * from crm_layouts where crm_configuration_id = 53 order by id desc;
select * from stages where crm_configuration_id = 53 order by id desc;
select * from crm_profiles where crm_configuration_id = 13;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 65
and sa.provider = 'integration-app';
select * from contacts where crm_configuration_id = 13;
select * from social_accounts where sociable_id = 283;
SELECT * FROM opportunities WHERE crm_provider_id = '006O400000E9bzeIAB';
select * from activity_providers where team_id = 65;
SELECT * FROM activities WHERE crm_configuration_id IN (51, 52, 53);
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 65
;
# [PASSWORD_DOTS] STAGING [PASSWORD_DOTS]
SELECT * FROM teams;
SELECT * FROM teams WHERE id = 88;
SELECT * FROM teams WHERE id = 89;
select * from team_settings where team_id = 89;
SELECT * FROM users WHERE team_id = 89;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 89;
select * from users;
SELECT * FROM social_accounts WHERE sociable_id = 1761;
SELECT * FROM crm_configurations WHERE id = 70;
select * from accounts where crm_configuration_id = 70 order by id desc;
select * from leads where crm_configuration_id = 70 order by id desc;
select * from contacts where crm_configuration_id = 70 order by id desc;
select * from opportunities where crm_configuration_id = 70 order by id desc;
select * from crm_profiles where crm_configuration_id = 70 order by id desc;
select * from crm_fields where crm_configuration_id = 70 order by id desc;
select * from crm_field_values where crm_field_id = 3536 order by id desc;
select * from crm_layouts where crm_configuration_id = 70 order by id desc;
select * from stages where crm_configuration_id = 70 order by id desc;
select * from business_processes where crm_configuration_id = 70 order by id desc;
select * from business_process_stages where business_process_id = 34;
select * from contacts where id = 10468;
select * from crm_layouts where crm_configuration_id = 70;
SELECT * FROM crm_layout_entities WHERE crm_layout_id = 388;
SELECT * FROM crm_fields WHERE id IN (3533,3534,3535);
select * from activities where crm_configuration_id = 70
and (account_id IS NOT NULL or lead_id IS NOT NULL or contact_id IS NOT NULL or opportunity_id IS NOT NULL) order by id desc;
SELECT * FROM activities WHERE uuid_to_bin('2e10b60f-8a61-41c5-a3d4-28835353dc65') = uuid;
SELECT * FROM activities where crm_configuration_id = 69 ;
SELECT * FROM users WHERE email LIKE '%[EMAIL]%';
SELECT * FROM activities WHERE uuid_to_bin('5a150c93-40fc-42ec-b3bd-c1d328e09f6e') = uuid;
SELECT * FROM opportunities WHERE id = 385;
select * from participants p
join activities a on p.activity_id = a.id
where a.crm_configuration_id = 70
and (p.lead_id IS NOT NULL or p.contact_id IS NOT NULL);
SELECT * FROM participants WHERE id = 1013638;
select * from teams where id = 90;
select * from users where team_id = 90;
select * from social_accounts where social_accounts.sociable_id IN (1960,1760);
SELECT * FROM crm_profiles WHERE crm_configuration_id = 71;
select * from invitations where team_id = 90;
select * from crm_configurations where id = 71;
select * from accounts where crm_configuration_id = 71 order by id desc;
select * from leads where crm_configuration_id = 71 order by id desc;
select * from contacts where crm_configuration_id = 71 order by id desc;
select * from opportunities where crm_configuration_id = 71 order by id desc;
select * from crm_profiles where crm_configuration_id = 71 order by id desc;
select * from crm_fields where crm_configuration_id = 71 order by id desc;
select * from crm_field_values where crm_field_id = 3341 order by id desc;
select * from crm_layouts where crm_configuration_id = 71 order by id desc;
select * from stages where crm_configuration_id = 71 order by id desc;
select * from users order by secondary_email desc;
select u.id, u.email, u.status, sa.id, sa.provider_user_id from social_accounts sa
join users u on sa.sociable_id = u.id
where sa.provider = 'google' and u.email LIKE 'aneliya%';
select * from failed_jobs order by id desc;
select * from users where email = '[EMAIL]' or secondary_email = '[EMAIL]';
select * from teams;
SELECT * FROM crm_profiles WHERE crm_configuration_id = 39;
SELECT * FROM crm_fields WHERE crm_configuration_id = 39 and object_type = 'task';
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 1
and sa.provider = 'salesforce';
# [PASSWORD_DOTS]
SELECT * FROM activities WHERE uuid_to_bin('c38b3895-fd0f-4b1f-9fb2-c170dba137c6') = uuid;
SELECT * FROM crm_configurations WHERE id = 70;
select * from teams where id = 1;
select * from groups where team_id = 1;
select * from users where team_id = 1;
select o.id, o.name,o.close_date, u.id, u.name, u.group_id, r.id, r.display_name, g.name, g.scope from opportunities o
join users u on o.user_id = u.id
join groups g on u.group_id = g.id
join role_user ru on u.id = ru.user_id
join roles r on ru.role_id = r.id
where o.crm_configuration_id = 39 and close_date > '2024-01-01 00:00:00';
select * from role_user where user_id = 143;
select * from roles;
select * from role_user;
select * from groups where id = 9;
select * from scope_groups where group_id = 9;
# [PASSWORD_DOTS]
select * from teams where id = 36;
select * from crm_configurations;
SELECT * FROM social_accounts WHERE sociable_id = 121;
[URL_WITH_CREDENTIALS] this will add filter, however if we need to control feature by FF we need conditional logic
public const array TYPES = [
['id' => 'exec_summary', 'name' => 'Exec Summary'],
['id' => 'coaching_profiles', 'name' => 'Coaching Profiles'],
['id' => 'product_feedback', 'name' => 'Product Feedback'],
['id' => self::TYPE_LOSS_ANALYSIS, 'name' => 'Loss Analysis'],
// ['id' => 'questions', 'name' => 'Questions'],
// ['id' => 'statistical_quant', 'name' => 'Statistical Quantitative'],
];
public const array ALL_TYPES = [
...self::TYPES,
['id' => self::TYPE_ASK_JIMINNY, 'name' => 'Ask Jiminny'],
];
public const string FREQUENCY_DAILY = 'daily';
public const string FREQUENCY_WEEKLY = 'weekly';
public const string FREQUENCY_MONTHLY = 'monthly';
public const string FREQUENCY_QUARTERLY = 'quarterly';
public const string FREQUENCY_ONE_OFF = 'one_off';
/**
* Frequencies for standard (non-Ask Jiminny) reports.
*/
public const array FREQUENCIES = [
['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],
['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],
['id' => self::FREQUENCY_QUARTERLY, 'name' => 'Quarterly'],
['id' => self::FREQUENCY_ONE_OFF, 'name' => 'One-off'],
];
/**
* Frequencies for Ask Jiminny reports.
*/
public const array ASK_JIMINNY_FREQUENCIES = [
['id' => self::FREQUENCY_DAILY, 'name' => 'Daily'],
['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],
['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],
];
public const string MEDIA_TYPE_PDF = 'pdf';
public const string MEDIA_TYPE_PODCAST = 'podcast';
public const array MEDIA_TYPES = [self::MEDIA_TYPE_PDF, self::MEDIA_TYPE_PODCAST];
public const array MEDIA_TYPE_OBJECT_PDF = ['id' => self::MEDIA_TYPE_PDF, 'name' => 'PDF'];
public const array MEDIA_TYPE_OBJECT_PODCAST = ['id' => self::MEDIA_TYPE_PODCAST, 'name' => 'Podcast'];
public const array MEDIA_TYPE_OBJECTS = [self::MEDIA_TYPE_OBJECT_PDF, self::MEDIA_TYPE_OBJECT_PODCAST];
public const array CALL_TYPE_CONFERENCE = ['id' => 'conference', 'name' => 'Conference'];
public const array CALL_TYPE_DIALER = ['id' => 'dialer', 'name' => 'Dialer'];
public const int SENT_REPORT_AT_HOURS = 5;
public const string PDF_KEY = 'pdf';
public const string AUDIO_KEY = 'audio';
private const array ALL_FREQUENCIES = [
['id' => self::FREQUENCY_DAILY, 'name' => 'Daily'],
['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],
['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],
['id' => self::FREQUENCY_QUARTERLY, 'name' => 'Quarterly'],
['id' => self::FREQUENCY_ONE_OFF, 'name' => 'One-off'],
];
private const string S3_DIR = 'reports';
private const array FILE_EXTENSIONS_VARIANTS = ['html', 'MD', 'pdf'];
private const array FILE_PODCAST_EXTENSIONS_VARIANTS = ['json', 'mp3', 'ssml'];
public function __construct(
private readonly TeamRepository $teamRepository,
private readonly GroupRepository $groupRepository,
private readonly UserRepository $userRepository,
private readonly StageRepository $stageRepository,
private readonly DealStagesService $dealStagesService,
private readonly RecipientsService $recipientsService,
private readonly AutomatedReportsRepository $automatedReportsRepository,
private readonly Webhook $webhookService,
private readonly BusDispatcher $dispatcher,
private readonly ActivityTypeService $activityTypeService,
private readonly PlaybookCategoryRepository $playbookCategoryRepository,
private readonly AskAnythingPromptService $askAnythingPromptService,
private readonly SearchRepository $activitySearchRepository,
private readonly AskAnythingRepository $askAnythingRepository,
) {
}
public static function getTypes(): array
{
$types = self::TYPES;
return array_map(static function ($type) {
return $type['id'];
}, $types);
}
public static function getCallTypes(): array
{
return array_map(static function ($callType) {
return $callType['id'];
}, [self::CALL_TYPE_CONFERENCE, self::CALL_TYPE_DIALER]);
}
public static function getFrequencies(): array
{
return array_map(static function ($frequency) {
return $frequency['id'];
}, self::FREQUENCIES);
}
// front-facing structure
public function getReportEnabledFieldData(bool $value = false): array
{
return [
'id' => 'report_enabled',
'label' => '',
'inputType' => InputTypeEnum::TOGGLE,
'value' => $value,
];
}
// Organizations = Teams
public function getOrganizationFieldData(?string $value = null, bool $shortVersion = false): array
{
$options = $this->getTeams();
if ($shortVersion) {
return [
'id' => 'organization',
'label' => 'Organization',
'options' => $options,
];
}
return [
'id' => 'organization',
'label' => 'Organization',
'inputType' => InputTypeEnum::DROPDOWN,
'required' => true,
'placeholder' => 'Select',
'options' => $options,
'value' => $value,
'dependencies' => [
'teams',
'deal_stage_at_call',
'current_deal_stage',
'recipients',
ActivityTypeService::PLAYBOOK_CATEGORIES_KEY,
],
'dependsOn' => [],
];
}
// Teams = Groups
public function getTeamFieldData(array $options = [], array $value = [], bool $shortVersion = false): array
{
if ($shortVersion) {
return [
'id' => 'teams',
'label' => 'Team',
'options' => $options,
];
}
return [
'id' => 'teams',
'label' => 'Team',
'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,
'required' => false,
'placeholder' => 'Select',
'options' => $options,
'value' => $value, // value should be an array of objects {id, name}
'dependencies' => [ActivityTypeService::PLAYBOOK_CATEGORIES_KEY],
'dependsOn' => [],
];
}
public function getReportTypeFieldData(?string $value = null, bool $shortVersion = false, ?Team $team = null): array
{
$types = [];
if ($team instanceof Team) {
if ($team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {
$types = self::TYPES;
}
if ($team->hasFeature(FeatureEnum::ASK_JIMINNY_REPORTS)) {
$types[] = ['id' => self::TYPE_ASK_JIMINNY, 'name' => 'Ask Jiminny'];
}
} else {
$types = self::TYPES;
}
if ($shortVersion) {
return [
'id' => 'report_type',
'label' => 'Report Type',
'options' => $types,
];
}
return [
'id' => 'report_type',
'label' => 'Report Type',
'inputType' => InputTypeEnum::DROPDOWN,
'required' => true,
'placeholder' => 'Select',
'options' => $types,
'value' => $value,
'dependencies' => [],
'dependsOn' => [],
];
}
public function getFrequencyFieldData(?string $value = null): array
{
return [
'id' => 'frequency',
'label' => 'Frequency',
'inputType' => InputTypeEnum::DROPDOWN,
'required' => true,
'placeholder' => 'Select',
'options' => self::FREQUENCIES,
'value' => $value,
'dependencies' => ['period'],
'dependsOn' => [],
];
}
public function getPeriodFieldData(?string $valueStartDate = null, ?string $valueEndDate = null): array
{
return [
'id' => 'period',
'label' => 'Select one-off period',
'inputType' => InputTypeEnum::DATE_RANGE,
'required' => true,
'placeholder' => 'Select',
'value' => ['startDate' => $valueStartDate, 'endDate' => $valueEndDate],
'queryParams' => [
'startDate' => 'start_date_period',
'endDate' => 'end_date_period',
],
'dependencies' => [],
'dependsOn' => ['frequency'],
];
}
public function getActivityTypesFieldData(?Team $team = null, array $value = [], array $teamsFilter = []): array
{
return $this->activityTypeService->getActivityTypeFieldData(team: $team, value: $value, groupIds: $teamsFilter);
}
public function getDealStageAtCallFieldData(?Team $team = null, array $value = []): array
{
return $this->dealStagesService->getDealStageAtCallFieldData(team: $team, value: $value);
}
public function getCurrentDealStageFieldData(?Team $team = null, array $value = []): array
{
return $this->dealStagesService->getCurrentDealStageFieldData(team: $team, value: $value);
}
public function getDealValueFieldData(?int $valueMin = null, ?int $valueMax = null): array
{
return [
'id' => 'deal_value',
'label' => 'Deal Value',
'inputType' => InputTypeEnum::INTEGER_RANGE,
'required' => false,
'value' => ['min' => $valueMin, 'max' => $valueMax],
'queryParams' => [
'min' => 'min_deal_value',
'max' => 'max_deal_value',
],
'dependencies' => [],
'dependsOn' => [],
];
}
public function getCallTypeFieldData(bool $conferenceOn = false, bool $dialerOn = false): array
{
$value = [];
$conferenceOn && $value[] = self::CALL_TYPE_CONFERENCE;
$dialerOn && $value[] = self::CALL_TYPE_DIALER;
return [
'id' => 'call_type',
'label' => 'Call Type',
'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,
'required' => true,
'options' => [
self::CALL_TYPE_CONFERENCE,
self::CALL_TYPE_DIALER,
],
'value' => $value,
'dependencies' => [],
'dependsOn' => [],
];
}
public function getMediaTypeFieldData(?AutomatedReport $report = null): array
{
$value = [];
if ($report) {
$value = $this->transformMediaTypes($report);
}
return [
'id' => 'media_types',
'label' => 'Export as',
'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,
'required' => true,
'options' => self::MEDIA_TYPE_OBJECTS,
'value' => $value,
'dependencies' => [],
'dependsOn' => [],
];
}
public function getCallDurationFieldData(?int $valueMin = null, ?int $valueMax = null): array
{
return [
'id' => 'call_duration',
'label' => 'Call Duration',
'inputType' => InputTypeEnum::INTEGER_RANGE,
'required' => false,
'value' => ['min' => $valueMin, 'max' => $valueMax],
'queryParams' => [
'min' => 'min_call_duration',
'max' => 'max_call_duration',
],
'dependencies' => [],
'dependsOn' => [],
];
}
public function getRecipientsFieldData(?Team $team = null, array $value = []): array
{
return $this->recipientsService->getRecipientsFieldData(team: $team, value: $value);
}
public function getJiminnyRecipientsFieldData(array $value = []): array
{
return $this->recipientsService->getJiminnyRecipientsFieldData($value);
}
public function getAdditionalPromptInputFieldData(?string $value = null): array
{
return [
'id' => 'additional_prompt_input',
'label' => 'Special requirements',
'inputType' => InputTypeEnum::TEXTAREA,
'required' => false,
'placeholder' => 'What should be the focus of the report?',
'value' => $value,
'dependencies' => [],
'dependsOn' => [],
];
}
public function getCustomReportNameFieldData(?string $value = null): array
{
return [
'id' => 'custom_name',
'label' => 'Custom report name',
'inputType' => InputTypeEnum::TEXT,
'required' => false,
'placeholder' => 'Enter custom name',
'value' => $value,
'dependencies' => [],
'dependsOn' => [],
];
}
// data providers
public function getTeams(): array
{
$teams = $this->teamRepository->getTeamsForKiosk(status: Team::STATUS_ACTIVE);
$teamData = [];
foreach ($teams as $team) {
if (! $team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {
continue;
}
$teamData[] = $this->transformTeam($team);
}
return $teamData;
}
public function getTeamGroups(string $teamUuid): array
{
$data = [];
$team = $this->getTeam($teamUuid);
if ($team !== null) {
$groups = $team->groups()->get();
foreach ($groups as $group) {
$data[] = [
'id' => $group->getUuid(),
'name' => $group->getName(),
];
}
}
return $data;
}
public function getTeamsGroupsOptions(array $filterTeamUuids = []): array
{
$data = [];
$teams = $this->getTeams();
foreach ($teams as $team) {
if (! empty($filterTeamUuids) && ! in_array($team['id'], $filterTeamUuids, true)) {
continue;
}
$data[] = [
'label' => $team['name'],
'groups' => $this->getTeamGroups($team['id']),
];
}
return $data;
}
public function getTeam(string $teamUuid): ?Team
{
return $this->teamRepository->idOrUuid($teamUuid);
}
public function getTeamById(int $teamId): ?Team
{
return $this->teamRepository->find($teamId);
}
public function getGroupsUuids(AutomatedReport $report): array
{
$uuids = [];
$reportGroups = $report->getGroups();
foreach ($reportGroups as $groupId) {
if ($group = $this->groupRepository->find($groupId)) {
$uuids[] = $group->getUuid();
}
}
return $uuids;
}
public function getPlaybookCategoriesUuids(AutomatedReport $report): array
{
$uuids = [];
$playbookCategories = $report->getPlaybookCategories();
foreach ($playbookCategories as $id) {
if ($category = $this->playbookCategoryRepository->find($id)) {
$uuids[] = $category->getUuid();
}
}
return $uuids;
}
public function getDealAtCallStagesUuids(AutomatedReport $report): array
{
$uuids = [];
$reportStages = $report->getDealAtCallStages();
foreach ($reportStages as $id) {
if ($stage = $this->stageRepository->find($id)) {
$uuids[] = $stage->getUuid();
}
}
return $uuids;
}
public function getCurrentDealStagesUuids(AutomatedReport $report): array
{
$uuids = [];
$reportStages = $report->getCurrentDealStages();
foreach ($reportStages as $id) {
if ($stage = $this->stageRepository->find($id)) {
$uuids[] = $stage->getUuid();
}
}
return $uuids;
}
public function getUsersUuids(AutomatedReport $report): array
{
return $this->extractUserUuids($report->getRecipients());
}
public function getJiminnyUsersUuids(AutomatedReport $report): array
{
return $this->extractUserUuids($report->getJiminnyRecipients());
}
/**
* @param array<string, mixed> $recipients
*/
private function extractUserUuids(array $recipients): array
{
$userIds = $recipients['users'] ?? [];
return collect($userIds)
->map(fn ($id) => $this->userRepository->find((int) $id))
->filter()
->map(fn (UserContract $user) => $user->getUuid())
->values()
->all();
}
// get mail data
public function getRecipientUsers(AutomatedReport $report): array
{
return $this->buildRecipientUsers($report->getRecipients());
}
private function getJiminnyRecipientUsers(AutomatedReport $report): array
{
return $this->buildRecipientUsers($report->getJiminnyRecipients());
}
/**
* @param array<string, mixed> $recipients
*/
private function buildRecipientUsers(array $recipients): array
{
$userIds = $recipients['users'] ?? [];
return collect($userIds)
->map(fn ($id) => $this->userRepository->find((int) $id))
->filter()
->map(fn (UserContract $user) => [
'email' => $user->getEmailAddress(),
'name' => $user->getName(),
'timezone' => $user->getTimezone()->getName(),
])
->values()
->all();
}
public function getValidRecipientUsers(AutomatedReport $report, bool $includeJiminny = false): array
{
if ($report->isAskJiminnyReport()) {
$recipients = $this->resolveAskJiminnyRecipients($report);
} else {
$recipients = $this->getRecipientUsers($report);
if ($includeJiminny) {
$recipients = array_merge($recipients, $this->getJiminnyRecipientUsers($report));
}
}
$emails = [];
return array_values(array_filter(
$recipients,
static function ($recipient) use (&$emails) {
if (empty($recipient['email']) || in_array($recipient['email'], $emails, true)) {
return false;
}
$emails[] = $recipient['email'];
return true;
}
));
}
private function resolveAskJiminnyRecipients(AutomatedReport $report): array
{
$recipients = [];
$creator = $report->getCreator();
if ($creator !== null) {
$recipients[] = [
'email' => $creator->getEmailAddress(),
'name' => $creator->getName(),
'timezone' => $creator->getTimezone()->getName(),
];
}
return array_merge(
$recipients,
$this->buildRecipientUsers($report->getRecipients()),
$this->getGroupRecipientUsers($report),
);
}
private function getGroupRecipientUsers(AutomatedReport $report): array
{
$users = [];
foreach ($report->getGroups() as $groupId) {
$group = $this->groupRepository->find($groupId);
if ($group === null) {
continue;
}
foreach ($group->getMembers() as $member) {
$users[] = [
'email' => $member->getEmailAddress(),
'name' => $member->getName(),
'timezone' => $member->getTimezone()->getName(),
];
}
}
return $users;
}
public function getReportTypeName(AutomatedReportResult $report): string
{
$type = $report->getReport()->getType();
$getType = $this->transformReportType($type);
return $getType['name'];
}
public function getReportPeriodName(AutomatedReportResult $report): string
{
$from = $report->getFromDate();
$to = $report->getToDate();
$frequency = $report->getReport()->getFrequency();
if ($from === null || $to === null) {
if (! $report->getReport()->isAskJiminnyReport()) {
$invalidPeriod = $from === null ? 'from' : 'to';
throw new ApplicationException('Report period is invalid: ' . $invalidPeriod);
}
$period = $this->calculateFromAndToDatePeriod($frequency);
$from = $period['fromDate'];
$to = $period['toDate'];
}
return $this->formatReportPeriodName($frequency, $from, $to);
}
private function formatReportPeriodName(string $frequency, Carbon $from, Carbon $to): string
{
$fromYear = $from->format('Y');
$toYear = $to->format('Y');
$differentYears = $fromYear !== $toYear;
switch ($frequency) {
case self::FREQUENCY_DAILY:
return $from->format('j M Y');
case self::FREQUENCY_QUARTERLY:
// 'Jan-Mar 2025' or 'Nov 2024-Jan 2025' if years differ
$startMonth = $from->format('M');
$endMonth = $to->copy()->subMonth();
$endMonthName = $endMonth->format('M');
$endMonthYear = $endMonth->format('Y');
if ($differentYears) {
return "{$startMonth} {$fromYear} - {$endMonthName} {$endMonthYear}";
}
return "{$startMonth} - {$endMonthName} {$toYear}";
case self::FREQUENCY_MONTHLY:
// 'May 2025' - monthly reports are always within the same year
return $from->format('M Y');
case self::FREQUENCY_WEEKLY:
// '4 - 8 Aug 2025', '27 Oct - 3 Nov 2025', or '28 Dec 2024 - 3 Jan 2025' if years differ
$startDay = $from->format('j');
$endDay = $to->format('j');
$startMonth = $from->format('M');
$endMonth = $to->format('M');
if ($differentYears) {
return "{$startDay} {$startMonth} {$fromYear} - {$endDay} {$endMonth} {$toYear}";
}
if ($startMonth !== $endMonth) {
return "{$startDay} {$startMonth} - {$endDay} {$endMonth} {$toYear}";
}
return "{$startDay} - {$endDay} {$endMonth} {$toYear}";
case self::FREQUENCY_ONE_OFF:
// '2 May-31 May 2025' or '15 Dec 2024-15 Jan 2025' if years differ
$startDay = $from->format('j');
$startMonth = $from->format('M');
$endDay = $to->format('j');
$endMonth = $to->format('M');
// If same month and year, use a format like '2-31 May 2025'
if ($startMonth === $endMonth && ! $differentYears) {
return "{$startDay} - {$endDay} {$startMonth} {$toYear}";
}
// If different years, include both years
if ($differentYears) {
return "{$startDay} {$startMonth} {$fromYear} - {$endDay} {$endMonth} {$toYear}";
}
// Same year but different months
return "{$startDay} {$startMonth} - {$endDay} {$endMonth} {$toYear}";
default:
// Default format for unknown frequencies
return $from->format('j M Y') . ' - ' . $to->format('j M Y');
}
}
public function getReportTeamsName(AutomatedReportResult $report): string
{
$groups = $report->getGroups();
if (empty($groups)) {
return 'All';
}
// Get group names from repository
$groupNames = [];
foreach ($groups as $groupId) {
$group = $this->groupRepository->find($groupId);
if ($group) {
$groupNames[] = $group->getName();
}
}
if (count($groupNames) === 1) {
// Single team format
$teamsName = $groupNames[0];
} else {
// Multiple teams format
$teamsName = implode(', ', $groupNames);
}
return $teamsName;
}
public function getReportFileName(AutomatedReportResult $report): string
...
|
[{"role":"AXButton","text" [{"role":"AXButton","text":"Project: faVsco.js, menu","depth":5,"help_text":"~/jiminny/app","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"#11894 on JY-18909-automated-reports-ask-jiminny, menu","depth":5,"help_text":"Pull request #11894 exists for current branch JY-18909-automated-reports-ask-jiminny","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Start Listening for PHP Debug Connections","depth":5,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"AutomatedReportsCommandTest","depth":6,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Run 'AutomatedReportsCommandTest'","depth":6,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Debug 'AutomatedReportsCommandTest'","depth":6,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"More Actions","depth":6,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JetBrains AI","depth":5,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Search Everywhere","depth":5,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"IDE and Project Settings","depth":5,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Execute","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Explain Plan","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Browse Query History","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"View Parameters","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Open Query Execution Settings…","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"In-Editor Results","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Tx: Auto","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Cancel Running Statements","depth":4,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Playground","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"jiminny","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.088194445,"height":0.027777778},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"16","depth":4,"role_description":"text"},{"role":"AXStaticText","text":"13","depth":4,"role_description":"text"},{"role":"AXStaticText","text":"13","depth":4,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"SELECT * FROM teams WHERE id = 1;\n\nselect * from crm_layouts where crm_configuration_id = 39;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 283;\nSELECT * FROM crm_fields WHERE id = 2234;\nSELECT * FROM crm_field_values WHERE crm_field_id = 2234;\n\nselect * from crm_profiles where user_id = 143;\n\nselect * from record_types where crm_configuration_id = 39; # 0121K000001MHElQAO,0121K000001MHEqQAO\nselect * from business_processes where crm_configuration_id = 39;\n# 01941000000H669AAC, 01941000000H66JAAS\n\nselect * from record_type_field_values\n where record_type_id IN (24);\n\nselect * from crm_field_values where id IN (2730);\n\nselect * from crm_configurations where id = 39;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 1\nand sa.provider = 'salesforce'; #1035\n\n\nselect * from users where team_id = 1; # 222 group 3\nSELECT * FROM activities WHERE user_id = 222 order by id desc;\nselect * from sidekick_settings where team_id = 1;\nselect * from teams where id = 1;\nselect * from team_features where team_id = 1;\n\nselect * from activities where crm_configuration_id = 2\nand provider = 'ms-teams' and id = 608765;\n\nSELECT * FROM activities WHERE crm_configuration_id = 2 and crm_provider_id = '59523413338';\n\nselect * from sidekick_settings where team_id = 2;\n\nSELECT * FROM activities WHERE id = 608660;\nselect * from activity_summary_logs where activity_id = 608660;\nselect * from ai_prompts where transcription_id = 11214;\n\n# ********************************************************************************************************\nSELECT * FROM activities WHERE uuid_to_bin('ed78a437-2804-450e-ab2f-56ab1c641346') = uuid;\n# id: 608818, crm: 59628809737\nSELECT * FROM activities WHERE uuid_to_bin('36b06e55-afdd-4782-8dee-c624cd0af191') = uuid;\n# id: 608821, crm: 59632069252\nSELECT ce.start_time, ce.end_time, a.id, a.uuid, crm_provider_id, calendar_event_id, title,\nplaybook_category_id, user_id, lead_id, contact_id, account_id, opportunity_id,\nscheduled_start_time, scheduled_end_time, actual_start_time, actual_end_time, a.created_at\nFROM activities a\njoin calendar_events ce on a.calendar_event_id = ce.id\nWHERE a.id IN (608818, 608821);\n\nselect * from users where team_id = 1;\nselect * from team_settings where team_id = 1;\nselect * from crm_profiles where crm_configuration_id = 39 order by user_id;\n\nselect * from team_features where team_id = 1;\n\nselect * from users where team_id = 2;\n\nSELECT * FROM activities WHERE uuid_to_bin('ec7647e9-5225-458b-b475-f31aa2769204') = uuid; # 612639\n# Preslava N. Ivanova, grou id 3\n\nSELECT * FROM opportunities WHERE uuid_to_bin('a2928fe5-aec5-46cb-85d9-7654c89e46a6') = uuid;\n\nselect * from activities where opportunity_id = 344 and actual_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00';\n\nselect\n a.id,\n a.type,\n a.scheduled_start_time,\n a.actual_start_time,\n a.created_at,\n a.opportunity_id,\n a.status\nFROM activities a\nWHERE opportunity_id = 344\nand status IN ('completed', 'received', 'delivered')\nand (\n (a.actual_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00')\nOR (a.created_at between '2024-10-11 00:00:00' and '2024-10-12 00:00:00')\nOR (a.scheduled_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00'))\n;\n\nSELECT * FROM users WHERE id = 222;\n\nSELECT * FROM crm_profiles WHERE user_id = 222;\nselect * from crm_layouts where crm_configuration_id = 39;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 281;\n\nselect * from group_deal_risk_types;\n\nselect * from opportunities where team_id = 1;\n\nSELECT * FROM opportunities WHERE id = 315;\nSELECT * FROM crm_field_data WHERE object_id = 315;\nselect * from crm_field_data where object_id = 260;\n\nselect * from generic_ai_prompts where subject_id = 315;\n\nselect * from teams; # 36, 21, 121, james.graham@bullhorn.jiminny.com\nSELECT * FROM social_accounts WHERE sociable_id = 121 and provider = 'bullhorn';\n\n# ************************************************************************************\nselect * from teams where id = 1;\nselect * from crm_configurations where id = 39;\nselect * from users where team_id = 1;\nselect u.email, cp.* from users u\njoin crm_profiles cp on u.id = cp.user_id\nwhere u.team_id = 1;\n# 1 - 00541000004281rAAA\n# 204 - 0052g000003freeAAA\n# 429 - 0052g000003qGOiAAM\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 1\nand sa.provider = 'salesforce';\n\nselect * from activities where type = 'softphone'\nand created_at > '2024-12-11 15:24:36' order by id desc;\n\nselect * from activity_providers where team_id = 1;\nselect * from activity_provider_users where activity_provider_id = 328;\n\nselect * from opportunities where crm_configuration_id = 39\nAND account_id = 178 AND is_closed = false\norder by created_at DESC;\n\nselect * from contacts where id = 3952;\nselect * from accounts where id = 178;\n\n# ************************************************************************************\nselect * from teams where id = 36;\nselect * from crm_configurations where id = 21;\nselect * from users where team_id = 36;\nselect u.email, cp.* from users u\njoin crm_profiles cp on u.id = cp.user_id\nwhere u.team_id = 36;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 36\nand sa.provider = 'bullhorn';\n\nselect * from social_accounts where id = 348;\nUPDATE social_accounts SET\nprovider_user_token = '21442_6802599_91:41179a58-21e7-4d7c-ad58-56bb666b2f65',\nprovider_refresh_token = '21442_6802599_91:01c6b335-3f2a-42e4-85ff-8a08fa65fceb',\nexpires = 1733998131,\nstate = 'connected'\nWHERE id = 348;\n\n# ************************************************************************************\nselect * from teams where id = 31;\nselect * from crm_configurations where id = 18;\n\nselect * from users where team_id = 31; # 257\nselect u.email, cp.* from users u\njoin crm_profiles cp on u.id = cp.user_id\nwhere u.team_id = 31;\n\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 31\nand sa.provider = 'close';\n\nselect * from contacts where crm_configuration_id = 18;\n\n# ********************** NEPTUNE **************************************************************\nselect * from teams;\nselect * from users where id IN (1030, 1035, 1052);\nselect * from crm_configurations;\n\nselect * from users where team_id = 65; # 257\nselect * from team_settings where team_id = 65; # 257\nselect * from invitations where team_id = 65; # 257\nselect * from users where email = 'integration-account@jiminny.com'; # 257\nselect u.email, cp.* from users u\njoin crm_profiles cp on u.id = cp.user_id\nwhere u.team_id = 65;\n\nselect * from crm_configurations where id = 53;\nselect * from accounts where crm_configuration_id = 53 order by id desc;\nselect * from leads where crm_configuration_id = 53 order by id desc;\nselect * from contacts where crm_configuration_id = 53 order by id desc;\nselect * from opportunities where crm_configuration_id = 53 order by id desc;\nselect * from crm_profiles where crm_configuration_id = 53 order by id desc;\nselect * from crm_fields where crm_configuration_id = 53 order by id desc;\nselect * from crm_field_values where crm_field_id = 3341 order by id desc;\nselect * from crm_layouts where crm_configuration_id = 53 order by id desc;\nselect * from stages where crm_configuration_id = 53 order by id desc;\n\n\nselect * from crm_profiles where crm_configuration_id = 13;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 65\nand sa.provider = 'integration-app';\n\nselect * from contacts where crm_configuration_id = 13;\n\nselect * from social_accounts where sociable_id = 283;\n\nSELECT * FROM opportunities WHERE crm_provider_id = '006O400000E9bzeIAB';\n\nselect * from activity_providers where team_id = 65;\nSELECT * FROM activities WHERE crm_configuration_id IN (51, 52, 53);\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 65\n;\n\n# ***************************** STAGING ********************************************\nSELECT * FROM teams;\nSELECT * FROM teams WHERE id = 88;\nSELECT * FROM teams WHERE id = 89;\nselect * from team_settings where team_id = 89;\nSELECT * FROM users WHERE team_id = 89;\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 89;\n\nselect * from users;\nSELECT * FROM social_accounts WHERE sociable_id = 1761;\nSELECT * FROM crm_configurations WHERE id = 70;\nselect * from accounts where crm_configuration_id = 70 order by id desc;\nselect * from leads where crm_configuration_id = 70 order by id desc;\nselect * from contacts where crm_configuration_id = 70 order by id desc;\nselect * from opportunities where crm_configuration_id = 70 order by id desc;\nselect * from crm_profiles where crm_configuration_id = 70 order by id desc;\nselect * from crm_fields where crm_configuration_id = 70 order by id desc;\nselect * from crm_field_values where crm_field_id = 3536 order by id desc;\nselect * from crm_layouts where crm_configuration_id = 70 order by id desc;\nselect * from stages where crm_configuration_id = 70 order by id desc;\nselect * from business_processes where crm_configuration_id = 70 order by id desc;\nselect * from business_process_stages where business_process_id = 34;\n\nselect * from contacts where id = 10468;\n\nselect * from crm_layouts where crm_configuration_id = 70;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 388;\nSELECT * FROM crm_fields WHERE id IN (3533,3534,3535);\n\nselect * from activities where crm_configuration_id = 70\nand (account_id IS NOT NULL or lead_id IS NOT NULL or contact_id IS NOT NULL or opportunity_id IS NOT NULL) order by id desc;\n\nSELECT * FROM activities WHERE uuid_to_bin('2e10b60f-8a61-41c5-a3d4-28835353dc65') = uuid;\nSELECT * FROM activities where crm_configuration_id = 69 ;\n\nSELECT * FROM users WHERE email LIKE '%jiminny_web_sa2@jiminny.com%';\nSELECT * FROM activities WHERE uuid_to_bin('5a150c93-40fc-42ec-b3bd-c1d328e09f6e') = uuid;\nSELECT * FROM opportunities WHERE id = 385;\n\nselect * from participants p\njoin activities a on p.activity_id = a.id\nwhere a.crm_configuration_id = 70\nand (p.lead_id IS NOT NULL or p.contact_id IS NOT NULL);\nSELECT * FROM participants WHERE id = 1013638;\n\nselect * from teams where id = 90;\nselect * from users where team_id = 90;\nselect * from social_accounts where social_accounts.sociable_id IN (1960,1760);\nSELECT * FROM crm_profiles WHERE crm_configuration_id = 71;\nselect * from invitations where team_id = 90;\n\nselect * from crm_configurations where id = 71;\nselect * from accounts where crm_configuration_id = 71 order by id desc;\nselect * from leads where crm_configuration_id = 71 order by id desc;\nselect * from contacts where crm_configuration_id = 71 order by id desc;\nselect * from opportunities where crm_configuration_id = 71 order by id desc;\nselect * from crm_profiles where crm_configuration_id = 71 order by id desc;\nselect * from crm_fields where crm_configuration_id = 71 order by id desc;\nselect * from crm_field_values where crm_field_id = 3341 order by id desc;\nselect * from crm_layouts where crm_configuration_id = 71 order by id desc;\nselect * from stages where crm_configuration_id = 71 order by id desc;\n\nselect * from users order by secondary_email desc;\nselect u.id, u.email, u.status, sa.id, sa.provider_user_id from social_accounts sa\n join users u on sa.sociable_id = u.id\nwhere sa.provider = 'google' and u.email LIKE 'aneliya%';\n\nselect * from failed_jobs order by id desc;\n\nselect * from users where email = 'ben.allwright@learningpeople.co.uk' or secondary_email = 'ben.allwright@learningpeople.co.uk';\n\nselect * from teams;\nSELECT * FROM crm_profiles WHERE crm_configuration_id = 39;\nSELECT * FROM crm_fields WHERE crm_configuration_id = 39 and object_type = 'task';\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 1\nand sa.provider = 'salesforce';\n\n# ************************************************************************************\nSELECT * FROM activities WHERE uuid_to_bin('c38b3895-fd0f-4b1f-9fb2-c170dba137c6') = uuid;\nSELECT * FROM crm_configurations WHERE id = 70;\n\nselect * from teams where id = 1;\nselect * from groups where team_id = 1;\nselect * from users where team_id = 1;\n\nselect o.id, o.name,o.close_date, u.id, u.name, u.group_id, r.id, r.display_name, g.name, g.scope from opportunities o\njoin users u on o.user_id = u.id\njoin groups g on u.group_id = g.id\njoin role_user ru on u.id = ru.user_id\njoin roles r on ru.role_id = r.id\nwhere o.crm_configuration_id = 39 and close_date > '2024-01-01 00:00:00';\n\nselect * from role_user where user_id = 143;\nselect * from roles;\n\nselect * from role_user;\nselect * from groups where id = 9;\nselect * from scope_groups where group_id = 9;\n\n# ************************************************************************************\nselect * from teams where id = 36;\nselect * from crm_configurations;\nSELECT * FROM social_accounts WHERE sociable_id = 121;\n\nhttps://crmsandbox.zoho.com/crm/jiminnyw4/tab/Leads/4776201000005049105\nhttps://crmsandbox.zoho.com/crm/\n\nhttps://crm.zoho.com/crm/org3469620/tab/Leads/230045000229559080\n https://crm.zoho.com/crm/\n org3469620\n\nSELECT * FROM activities WHERE uuid_to_bin('03382d20-c8bc-48e7-a3d4-90b52fa5ceab') = uuid;\n\nselect * from users where email LIKE \"%mobile_automation_%\";\nselect * from social_accounts where sociable_id IN (2228);\nselect * from crm_profiles where user_id IN (2222,2223,2226,2227);\n\nselect * from teams order by id desc;\nSELECT * FROM users WHERE id = 2229;\nSELECT * FROM crm_profiles WHERE user_id = 2229;\nselect * from opportunities where crm_configuration_id = 88;\nselect * from crm_fields where crm_configuration_id = 88;\nselect * from crm_profiles where crm_configuration_id = 88;\n\nSELECT * FROM teams WHERE id = 1;\n\nSELECT * FROM users WHERE id = 143;\nSELECT * FROM users WHERE uuid_to_bin('fde193d3-06a2-4e1a-8895-62b94039215d') = uuid;\nSELECT * FROM teams WHERE uuid_to_bin('73385071-a756-42ae-9c73-8b53f2309467') = uuid;\n\nhttps://app.staging.jiminny.com/ondemand?\n min_duration=1\n &\n only_recorded=1\n &\n user_id%5B%5D=641f1acb-16b8-42d1-8726-df52979dad0e\n &\n sequence_number=2\n\n select * from users where team_id = 1 and email like '%stoyan%'\n\nselect * from coaching_feedbacks;\n\nselect * from teams;\nSELECT * FROM users WHERE team_id = 36;\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 19\nand sa.provider = 'pipedrive';\n\nselect * from users where id = 143;\n\nSELECT * FROM users WHERE uuid_to_bin('73180eeb-33de-4065-977d-ccbe0e6c94fc') = uuid;\nSELECT * FROM teams WHERE uuid_to_bin('73180eeb-33de-4065-977d-ccbe0e6c94fc') = uuid;\nSELECT * FROM activity_shares WHERE uuid_to_bin('73180eeb-33de-4065-977d-ccbe0e6c94fc') = uuid;\n\nselect * from users where team_id = 2;\nselect * from activities where crm_configuration_id = 39\nand activities.scheduled_start_time BETWEEN '2025-04-09 00:00:00' AND '2025-04-09 23:59:59'\nAND user_id = 143\norder by id desc;\n\n# ************************************************************************************\nselect * from teams where id = 142; # 2312, 126\nselect * from team_settings;\nselect * from users where team_id = 142; # 21642\nSELECT * FROM social_accounts WHERE sociable_id = 21642;\nSELECT * FROM crm_profiles cp join users u ON u.id = cp.user_id WHERE team_id = 142;\nselect * from crm_profiles where id IN (93);\nselect * from invitations;\nselect * from team_features where team_id = 1;\n\nSELECT * FROM crm_configurations WHERE id = 126;\nselect * from accounts where crm_configuration_id = 126 order by id desc;\nselect * from leads where crm_configuration_id = 126 order by id desc;\nselect * from contacts where crm_configuration_id = 126 order by id desc;\nselect * from opportunities where crm_configuration_id = 126 order by id desc;\nselect * from crm_profiles where crm_configuration_id = 126 order by id desc;\nselect * from crm_fields where crm_configuration_id = 126 # 11060\n# and type IN ('picklist', 'status')\n# and object_type = 'task'\norder by id desc;\n# 5731,5732,5733\nselect DISTINCT crm_field_id from crm_field_values where crm_field_id IN (11151,12239,12215,12185,12175,12165,12144,12137,12127,12109,12107,12105,12103,12092,12037,12005,12003,11987,11969,11958,11951,11942,11931,11924,11921,11917,11915,11901,11893,11883,11872,11870,11868,11866,11839,11833,11821,11793,11780,11777,11769,11757,11737,11735,11656,11645,11638,11629,11618,11611,11602,11591,11584,11581,11558,11544,11543,11534,11532,11529,11527,11503,11497,11493,11488,11470,11468,11457,11455,11397,11387,11372,11363,11348,11323,11318,11309,11301,11300,11292,11290,11286,11284,11256,11252,11242,11237,11233,11219,11176,11160) order by id desc;\nselect * from crm_layouts where crm_configuration_id = 126 order by id desc;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id in (300,299,298);\nselect * from stages where crm_configuration_id = 126 order by id desc;\nselect * from business_processes where crm_configuration_id = 126 order by id desc;\nselect * from business_process_stages where business_process_id IN (76,75,74,73);\nselect * from playbooks where team_id = 142;\nselect * from playbook_layouts where playbook_id IN (108);\nSELECT * FROM playbook_categories WHERE playbook_id IN (108);\n\nselect * from teams where id = 130;\nSELECT * FROM social_accounts WHERE sociable_id = 2291;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 2\nand sa.provider = 'hubspot';\n\nSELECT * FROM activities\n WHERE crm_configuration_id = 110;\n\nselect * from teams;\nselect * from crm_configurations;\n\nSELECT * FROM activities WHERE id = 628773;\nSELECT * FROM crm_profiles WHERE user_id = 1460;\nSELECT * FROM social_accounts WHERE sociable_id = 2291;\n\nselect * from teams;\nselect ru.*, pr.*, p.* from users u join role_user ru on ru.user_id = u.id\njoin permission_role pr on pr.role_id = ru.role_id\n join permissions p on p.id = pr.permission_id\nwhere team_id = 495 and p.name IN ('dial');\n\nselect * from teams where id = 145;\nselect * from crm_configurations where id = 129;\nselect * from social_accounts where sociable_id = 2317;\nSELECT * FROM activities WHERE uuid_to_bin('8dbab184-a333-4268-ad57-fb41f8d53a9a') = uuid;\n\nselect * from teams where id = 1;\nSELECT * FROM crm_layouts WHERE crm_configuration_id = 39;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 280;\nSELECT * FROM crm_layout_entities WHERE id = 5507;\nSELECT * FROM crm_fields WHERE crm_configuration_id = 39 and object_type IN ('event');\n\nselect * from teams;\nselect * from activities where crm_configuration_id = 14;\n\nSELECT * FROM social_accounts where provider = 'copper';\n\nselect * from activities where id = 628467;\nselect * from participants where activity_id = 628467;\n\nSELECT * FROM contacts WHERE id = 3969;\nSELECT * FROM accounts WHERE id = 177;\n\nSELECT * FROM activities WHERE uuid_to_bin('4eb54c77-cfa3-2bd4-84a7-9ed46a21c988') = uuid;\n\n# ********************* BH\nselect * from teams where id = 36;\nSELECT * FROM crm_configurations WHERE id = 21;\nselect * from activities where crm_configuration_id = 21 and id = 607901;\nselect * from activities where crm_configuration_id = 21;\n\nselect * roles;\nselect * from permissions;\nselect * from permission_role where permission_id = 226;\n\nselect * from migrations order by id desc;\n\n# mercury\n# neptune\n# earth\n\nselect * from teams;\nselect * from teams where id = 19;\nselect * from teams where id = 27;\nselect * from users where team_id = 27;\nSELECT * FROM crm_configurations WHERE id = 42;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 19\nand sa.provider = 'pipedrive';\n\nselect * from activities where id = 631461;\nSELECT * FROM crm_field_values WHERE crm_field_id = 180;\n\nselect * from teams where id = 2;\nSELECT * FROM social_accounts WHERE sociable_id = 89;\n\nSELECT * FROM activities WHERE uuid_to_bin('ba0c029a-bc14-4e17-8603-64174acebcbb') = uuid; # 634273\nselect * from activity_summary_logs where activity_id = 634273;\n\nselect * from sidekick_settings where team_id = 2;\n\nselect * from teams; # 2, 2\nSELECT * FROM crm_configurations WHERE team_id = 2; # 2\nselect * from team_features where team_id = 2;\nselect * from features;\nSELECT * FROM opportunities WHERE crm_configuration_id = 2 and crm_provider_id = '51317301383';\nSELECT * FROM opportunities WHERE crm_configuration_id = 2 order by id desc;\n\nselect * from automated_reports order by id desc;\nselect * from automated_report_results order by id desc;\nselect * from users where team_id = 1 and id IN (7160, 3248);\nselect * from migrations order by id desc;\n\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 1 and sa.provider = 'salesforce';\n\nselect * from teams where id = 1;\nselect * from groups g JOIN playbooks p on g.playbook_id = p.id where g.team_id = 1;\nselect * from groups where id = 565;\nselect * from playbooks where team_id = 1;\nselect * from playbooks where id = 175;\nselect * from playbook_categories where playbook_id = 175;\nselect * from users where team_id = 1;\nselect * from users where id = 7160;\nselect * from crm_profiles where user_id = 7160;\nselect * from features;\nselect\n *\n# id, uuid, type, provider, playbook_category_id, user_id, lead_id, contact_id, account_id, opportunity_id, stage_id,\n# crm_configuration_id, crm_provider_id, transcription_id, status\nfrom activities where crm_configuration_id = 1 and type = 'conference'\n# and crm_provider_id IS NOT NULL\nand provider != 'uploader' and actual_start_time IS NOT NULL\nORDER by id desc;\nselect * from activities where id = 54747783; # 00UO400000pCzojMAC\n\nselect p.id, p.activity_type, pc.id, pc.name\nFROM playbooks p\njoin playbook_categories pc on p.id = pc.playbook_id\nwhere p.team_id = 1 and p.activity_type = 'event';\n\nSELECT * FROM crm_fields WHERE crm_configuration_id = 1 and object_type = 'event';\nSELECT * FROM crm_field_values WHERE crm_field_id = 4;\n\nselect * from crm_layouts cl join playbook_layouts pl on cl.id = pl.layout_id\nwhere crm_configuration_id = 1 and pl.playbook_id = 175;\n\nselect * from teams;\nSELECT r.* FROM automated_reports r\njoin teams t on r.team_id = t.id\nWHERE r.frequency = 'daily'\n and r.status = 1\nAND t.status = 'active'\nAND (r.expires_at >= now() OR r.expires_at IS NULL);\n\nselect * from automated_report_results where report_id IN (18, 33);\n\nselect * from activity_searches where id = 10932;\nselect * from activity_search_filters where activity_search_id = 10932;\nselect * from automated_reports;\nselect * from automated_report_results where report_id IN (34, 35);","depth":4,"value":"SELECT * FROM teams WHERE id = 1;\n\nselect * from crm_layouts where crm_configuration_id = 39;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 283;\nSELECT * FROM crm_fields WHERE id = 2234;\nSELECT * FROM crm_field_values WHERE crm_field_id = 2234;\n\nselect * from crm_profiles where user_id = 143;\n\nselect * from record_types where crm_configuration_id = 39; # 0121K000001MHElQAO,0121K000001MHEqQAO\nselect * from business_processes where crm_configuration_id = 39;\n# 01941000000H669AAC, 01941000000H66JAAS\n\nselect * from record_type_field_values\n where record_type_id IN (24);\n\nselect * from crm_field_values where id IN (2730);\n\nselect * from crm_configurations where id = 39;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 1\nand sa.provider = 'salesforce'; #1035\n\n\nselect * from users where team_id = 1; # 222 group 3\nSELECT * FROM activities WHERE user_id = 222 order by id desc;\nselect * from sidekick_settings where team_id = 1;\nselect * from teams where id = 1;\nselect * from team_features where team_id = 1;\n\nselect * from activities where crm_configuration_id = 2\nand provider = 'ms-teams' and id = 608765;\n\nSELECT * FROM activities WHERE crm_configuration_id = 2 and crm_provider_id = '59523413338';\n\nselect * from sidekick_settings where team_id = 2;\n\nSELECT * FROM activities WHERE id = 608660;\nselect * from activity_summary_logs where activity_id = 608660;\nselect * from ai_prompts where transcription_id = 11214;\n\n# ********************************************************************************************************\nSELECT * FROM activities WHERE uuid_to_bin('ed78a437-2804-450e-ab2f-56ab1c641346') = uuid;\n# id: 608818, crm: 59628809737\nSELECT * FROM activities WHERE uuid_to_bin('36b06e55-afdd-4782-8dee-c624cd0af191') = uuid;\n# id: 608821, crm: 59632069252\nSELECT ce.start_time, ce.end_time, a.id, a.uuid, crm_provider_id, calendar_event_id, title,\nplaybook_category_id, user_id, lead_id, contact_id, account_id, opportunity_id,\nscheduled_start_time, scheduled_end_time, actual_start_time, actual_end_time, a.created_at\nFROM activities a\njoin calendar_events ce on a.calendar_event_id = ce.id\nWHERE a.id IN (608818, 608821);\n\nselect * from users where team_id = 1;\nselect * from team_settings where team_id = 1;\nselect * from crm_profiles where crm_configuration_id = 39 order by user_id;\n\nselect * from team_features where team_id = 1;\n\nselect * from users where team_id = 2;\n\nSELECT * FROM activities WHERE uuid_to_bin('ec7647e9-5225-458b-b475-f31aa2769204') = uuid; # 612639\n# Preslava N. Ivanova, grou id 3\n\nSELECT * FROM opportunities WHERE uuid_to_bin('a2928fe5-aec5-46cb-85d9-7654c89e46a6') = uuid;\n\nselect * from activities where opportunity_id = 344 and actual_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00';\n\nselect\n a.id,\n a.type,\n a.scheduled_start_time,\n a.actual_start_time,\n a.created_at,\n a.opportunity_id,\n a.status\nFROM activities a\nWHERE opportunity_id = 344\nand status IN ('completed', 'received', 'delivered')\nand (\n (a.actual_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00')\nOR (a.created_at between '2024-10-11 00:00:00' and '2024-10-12 00:00:00')\nOR (a.scheduled_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00'))\n;\n\nSELECT * FROM users WHERE id = 222;\n\nSELECT * FROM crm_profiles WHERE user_id = 222;\nselect * from crm_layouts where crm_configuration_id = 39;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 281;\n\nselect * from group_deal_risk_types;\n\nselect * from opportunities where team_id = 1;\n\nSELECT * FROM opportunities WHERE id = 315;\nSELECT * FROM crm_field_data WHERE object_id = 315;\nselect * from crm_field_data where object_id = 260;\n\nselect * from generic_ai_prompts where subject_id = 315;\n\nselect * from teams; # 36, 21, 121, james.graham@bullhorn.jiminny.com\nSELECT * FROM social_accounts WHERE sociable_id = 121 and provider = 'bullhorn';\n\n# ************************************************************************************\nselect * from teams where id = 1;\nselect * from crm_configurations where id = 39;\nselect * from users where team_id = 1;\nselect u.email, cp.* from users u\njoin crm_profiles cp on u.id = cp.user_id\nwhere u.team_id = 1;\n# 1 - 00541000004281rAAA\n# 204 - 0052g000003freeAAA\n# 429 - 0052g000003qGOiAAM\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 1\nand sa.provider = 'salesforce';\n\nselect * from activities where type = 'softphone'\nand created_at > '2024-12-11 15:24:36' order by id desc;\n\nselect * from activity_providers where team_id = 1;\nselect * from activity_provider_users where activity_provider_id = 328;\n\nselect * from opportunities where crm_configuration_id = 39\nAND account_id = 178 AND is_closed = false\norder by created_at DESC;\n\nselect * from contacts where id = 3952;\nselect * from accounts where id = 178;\n\n# ************************************************************************************\nselect * from teams where id = 36;\nselect * from crm_configurations where id = 21;\nselect * from users where team_id = 36;\nselect u.email, cp.* from users u\njoin crm_profiles cp on u.id = cp.user_id\nwhere u.team_id = 36;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 36\nand sa.provider = 'bullhorn';\n\nselect * from social_accounts where id = 348;\nUPDATE social_accounts SET\nprovider_user_token = '21442_6802599_91:41179a58-21e7-4d7c-ad58-56bb666b2f65',\nprovider_refresh_token = '21442_6802599_91:01c6b335-3f2a-42e4-85ff-8a08fa65fceb',\nexpires = 1733998131,\nstate = 'connected'\nWHERE id = 348;\n\n# ************************************************************************************\nselect * from teams where id = 31;\nselect * from crm_configurations where id = 18;\n\nselect * from users where team_id = 31; # 257\nselect u.email, cp.* from users u\njoin crm_profiles cp on u.id = cp.user_id\nwhere u.team_id = 31;\n\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 31\nand sa.provider = 'close';\n\nselect * from contacts where crm_configuration_id = 18;\n\n# ********************** NEPTUNE **************************************************************\nselect * from teams;\nselect * from users where id IN (1030, 1035, 1052);\nselect * from crm_configurations;\n\nselect * from users where team_id = 65; # 257\nselect * from team_settings where team_id = 65; # 257\nselect * from invitations where team_id = 65; # 257\nselect * from users where email = 'integration-account@jiminny.com'; # 257\nselect u.email, cp.* from users u\njoin crm_profiles cp on u.id = cp.user_id\nwhere u.team_id = 65;\n\nselect * from crm_configurations where id = 53;\nselect * from accounts where crm_configuration_id = 53 order by id desc;\nselect * from leads where crm_configuration_id = 53 order by id desc;\nselect * from contacts where crm_configuration_id = 53 order by id desc;\nselect * from opportunities where crm_configuration_id = 53 order by id desc;\nselect * from crm_profiles where crm_configuration_id = 53 order by id desc;\nselect * from crm_fields where crm_configuration_id = 53 order by id desc;\nselect * from crm_field_values where crm_field_id = 3341 order by id desc;\nselect * from crm_layouts where crm_configuration_id = 53 order by id desc;\nselect * from stages where crm_configuration_id = 53 order by id desc;\n\n\nselect * from crm_profiles where crm_configuration_id = 13;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 65\nand sa.provider = 'integration-app';\n\nselect * from contacts where crm_configuration_id = 13;\n\nselect * from social_accounts where sociable_id = 283;\n\nSELECT * FROM opportunities WHERE crm_provider_id = '006O400000E9bzeIAB';\n\nselect * from activity_providers where team_id = 65;\nSELECT * FROM activities WHERE crm_configuration_id IN (51, 52, 53);\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 65\n;\n\n# ***************************** STAGING ********************************************\nSELECT * FROM teams;\nSELECT * FROM teams WHERE id = 88;\nSELECT * FROM teams WHERE id = 89;\nselect * from team_settings where team_id = 89;\nSELECT * FROM users WHERE team_id = 89;\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 89;\n\nselect * from users;\nSELECT * FROM social_accounts WHERE sociable_id = 1761;\nSELECT * FROM crm_configurations WHERE id = 70;\nselect * from accounts where crm_configuration_id = 70 order by id desc;\nselect * from leads where crm_configuration_id = 70 order by id desc;\nselect * from contacts where crm_configuration_id = 70 order by id desc;\nselect * from opportunities where crm_configuration_id = 70 order by id desc;\nselect * from crm_profiles where crm_configuration_id = 70 order by id desc;\nselect * from crm_fields where crm_configuration_id = 70 order by id desc;\nselect * from crm_field_values where crm_field_id = 3536 order by id desc;\nselect * from crm_layouts where crm_configuration_id = 70 order by id desc;\nselect * from stages where crm_configuration_id = 70 order by id desc;\nselect * from business_processes where crm_configuration_id = 70 order by id desc;\nselect * from business_process_stages where business_process_id = 34;\n\nselect * from contacts where id = 10468;\n\nselect * from crm_layouts where crm_configuration_id = 70;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 388;\nSELECT * FROM crm_fields WHERE id IN (3533,3534,3535);\n\nselect * from activities where crm_configuration_id = 70\nand (account_id IS NOT NULL or lead_id IS NOT NULL or contact_id IS NOT NULL or opportunity_id IS NOT NULL) order by id desc;\n\nSELECT * FROM activities WHERE uuid_to_bin('2e10b60f-8a61-41c5-a3d4-28835353dc65') = uuid;\nSELECT * FROM activities where crm_configuration_id = 69 ;\n\nSELECT * FROM users WHERE email LIKE '%jiminny_web_sa2@jiminny.com%';\nSELECT * FROM activities WHERE uuid_to_bin('5a150c93-40fc-42ec-b3bd-c1d328e09f6e') = uuid;\nSELECT * FROM opportunities WHERE id = 385;\n\nselect * from participants p\njoin activities a on p.activity_id = a.id\nwhere a.crm_configuration_id = 70\nand (p.lead_id IS NOT NULL or p.contact_id IS NOT NULL);\nSELECT * FROM participants WHERE id = 1013638;\n\nselect * from teams where id = 90;\nselect * from users where team_id = 90;\nselect * from social_accounts where social_accounts.sociable_id IN (1960,1760);\nSELECT * FROM crm_profiles WHERE crm_configuration_id = 71;\nselect * from invitations where team_id = 90;\n\nselect * from crm_configurations where id = 71;\nselect * from accounts where crm_configuration_id = 71 order by id desc;\nselect * from leads where crm_configuration_id = 71 order by id desc;\nselect * from contacts where crm_configuration_id = 71 order by id desc;\nselect * from opportunities where crm_configuration_id = 71 order by id desc;\nselect * from crm_profiles where crm_configuration_id = 71 order by id desc;\nselect * from crm_fields where crm_configuration_id = 71 order by id desc;\nselect * from crm_field_values where crm_field_id = 3341 order by id desc;\nselect * from crm_layouts where crm_configuration_id = 71 order by id desc;\nselect * from stages where crm_configuration_id = 71 order by id desc;\n\nselect * from users order by secondary_email desc;\nselect u.id, u.email, u.status, sa.id, sa.provider_user_id from social_accounts sa\n join users u on sa.sociable_id = u.id\nwhere sa.provider = 'google' and u.email LIKE 'aneliya%';\n\nselect * from failed_jobs order by id desc;\n\nselect * from users where email = 'ben.allwright@learningpeople.co.uk' or secondary_email = 'ben.allwright@learningpeople.co.uk';\n\nselect * from teams;\nSELECT * FROM crm_profiles WHERE crm_configuration_id = 39;\nSELECT * FROM crm_fields WHERE crm_configuration_id = 39 and object_type = 'task';\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 1\nand sa.provider = 'salesforce';\n\n# ************************************************************************************\nSELECT * FROM activities WHERE uuid_to_bin('c38b3895-fd0f-4b1f-9fb2-c170dba137c6') = uuid;\nSELECT * FROM crm_configurations WHERE id = 70;\n\nselect * from teams where id = 1;\nselect * from groups where team_id = 1;\nselect * from users where team_id = 1;\n\nselect o.id, o.name,o.close_date, u.id, u.name, u.group_id, r.id, r.display_name, g.name, g.scope from opportunities o\njoin users u on o.user_id = u.id\njoin groups g on u.group_id = g.id\njoin role_user ru on u.id = ru.user_id\njoin roles r on ru.role_id = r.id\nwhere o.crm_configuration_id = 39 and close_date > '2024-01-01 00:00:00';\n\nselect * from role_user where user_id = 143;\nselect * from roles;\n\nselect * from role_user;\nselect * from groups where id = 9;\nselect * from scope_groups where group_id = 9;\n\n# ************************************************************************************\nselect * from teams where id = 36;\nselect * from crm_configurations;\nSELECT * FROM social_accounts WHERE sociable_id = 121;\n\nhttps://crmsandbox.zoho.com/crm/jiminnyw4/tab/Leads/4776201000005049105\nhttps://crmsandbox.zoho.com/crm/\n\nhttps://crm.zoho.com/crm/org3469620/tab/Leads/230045000229559080\n https://crm.zoho.com/crm/\n org3469620\n\nSELECT * FROM activities WHERE uuid_to_bin('03382d20-c8bc-48e7-a3d4-90b52fa5ceab') = uuid;\n\nselect * from users where email LIKE \"%mobile_automation_%\";\nselect * from social_accounts where sociable_id IN (2228);\nselect * from crm_profiles where user_id IN (2222,2223,2226,2227);\n\nselect * from teams order by id desc;\nSELECT * FROM users WHERE id = 2229;\nSELECT * FROM crm_profiles WHERE user_id = 2229;\nselect * from opportunities where crm_configuration_id = 88;\nselect * from crm_fields where crm_configuration_id = 88;\nselect * from crm_profiles where crm_configuration_id = 88;\n\nSELECT * FROM teams WHERE id = 1;\n\nSELECT * FROM users WHERE id = 143;\nSELECT * FROM users WHERE uuid_to_bin('fde193d3-06a2-4e1a-8895-62b94039215d') = uuid;\nSELECT * FROM teams WHERE uuid_to_bin('73385071-a756-42ae-9c73-8b53f2309467') = uuid;\n\nhttps://app.staging.jiminny.com/ondemand?\n min_duration=1\n &\n only_recorded=1\n &\n user_id%5B%5D=641f1acb-16b8-42d1-8726-df52979dad0e\n &\n sequence_number=2\n\n select * from users where team_id = 1 and email like '%stoyan%'\n\nselect * from coaching_feedbacks;\n\nselect * from teams;\nSELECT * FROM users WHERE team_id = 36;\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 19\nand sa.provider = 'pipedrive';\n\nselect * from users where id = 143;\n\nSELECT * FROM users WHERE uuid_to_bin('73180eeb-33de-4065-977d-ccbe0e6c94fc') = uuid;\nSELECT * FROM teams WHERE uuid_to_bin('73180eeb-33de-4065-977d-ccbe0e6c94fc') = uuid;\nSELECT * FROM activity_shares WHERE uuid_to_bin('73180eeb-33de-4065-977d-ccbe0e6c94fc') = uuid;\n\nselect * from users where team_id = 2;\nselect * from activities where crm_configuration_id = 39\nand activities.scheduled_start_time BETWEEN '2025-04-09 00:00:00' AND '2025-04-09 23:59:59'\nAND user_id = 143\norder by id desc;\n\n# ************************************************************************************\nselect * from teams where id = 142; # 2312, 126\nselect * from team_settings;\nselect * from users where team_id = 142; # 21642\nSELECT * FROM social_accounts WHERE sociable_id = 21642;\nSELECT * FROM crm_profiles cp join users u ON u.id = cp.user_id WHERE team_id = 142;\nselect * from crm_profiles where id IN (93);\nselect * from invitations;\nselect * from team_features where team_id = 1;\n\nSELECT * FROM crm_configurations WHERE id = 126;\nselect * from accounts where crm_configuration_id = 126 order by id desc;\nselect * from leads where crm_configuration_id = 126 order by id desc;\nselect * from contacts where crm_configuration_id = 126 order by id desc;\nselect * from opportunities where crm_configuration_id = 126 order by id desc;\nselect * from crm_profiles where crm_configuration_id = 126 order by id desc;\nselect * from crm_fields where crm_configuration_id = 126 # 11060\n# and type IN ('picklist', 'status')\n# and object_type = 'task'\norder by id desc;\n# 5731,5732,5733\nselect DISTINCT crm_field_id from crm_field_values where crm_field_id IN (11151,12239,12215,12185,12175,12165,12144,12137,12127,12109,12107,12105,12103,12092,12037,12005,12003,11987,11969,11958,11951,11942,11931,11924,11921,11917,11915,11901,11893,11883,11872,11870,11868,11866,11839,11833,11821,11793,11780,11777,11769,11757,11737,11735,11656,11645,11638,11629,11618,11611,11602,11591,11584,11581,11558,11544,11543,11534,11532,11529,11527,11503,11497,11493,11488,11470,11468,11457,11455,11397,11387,11372,11363,11348,11323,11318,11309,11301,11300,11292,11290,11286,11284,11256,11252,11242,11237,11233,11219,11176,11160) order by id desc;\nselect * from crm_layouts where crm_configuration_id = 126 order by id desc;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id in (300,299,298);\nselect * from stages where crm_configuration_id = 126 order by id desc;\nselect * from business_processes where crm_configuration_id = 126 order by id desc;\nselect * from business_process_stages where business_process_id IN (76,75,74,73);\nselect * from playbooks where team_id = 142;\nselect * from playbook_layouts where playbook_id IN (108);\nSELECT * FROM playbook_categories WHERE playbook_id IN (108);\n\nselect * from teams where id = 130;\nSELECT * FROM social_accounts WHERE sociable_id = 2291;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 2\nand sa.provider = 'hubspot';\n\nSELECT * FROM activities\n WHERE crm_configuration_id = 110;\n\nselect * from teams;\nselect * from crm_configurations;\n\nSELECT * FROM activities WHERE id = 628773;\nSELECT * FROM crm_profiles WHERE user_id = 1460;\nSELECT * FROM social_accounts WHERE sociable_id = 2291;\n\nselect * from teams;\nselect ru.*, pr.*, p.* from users u join role_user ru on ru.user_id = u.id\njoin permission_role pr on pr.role_id = ru.role_id\n join permissions p on p.id = pr.permission_id\nwhere team_id = 495 and p.name IN ('dial');\n\nselect * from teams where id = 145;\nselect * from crm_configurations where id = 129;\nselect * from social_accounts where sociable_id = 2317;\nSELECT * FROM activities WHERE uuid_to_bin('8dbab184-a333-4268-ad57-fb41f8d53a9a') = uuid;\n\nselect * from teams where id = 1;\nSELECT * FROM crm_layouts WHERE crm_configuration_id = 39;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 280;\nSELECT * FROM crm_layout_entities WHERE id = 5507;\nSELECT * FROM crm_fields WHERE crm_configuration_id = 39 and object_type IN ('event');\n\nselect * from teams;\nselect * from activities where crm_configuration_id = 14;\n\nSELECT * FROM social_accounts where provider = 'copper';\n\nselect * from activities where id = 628467;\nselect * from participants where activity_id = 628467;\n\nSELECT * FROM contacts WHERE id = 3969;\nSELECT * FROM accounts WHERE id = 177;\n\nSELECT * FROM activities WHERE uuid_to_bin('4eb54c77-cfa3-2bd4-84a7-9ed46a21c988') = uuid;\n\n# ********************* BH\nselect * from teams where id = 36;\nSELECT * FROM crm_configurations WHERE id = 21;\nselect * from activities where crm_configuration_id = 21 and id = 607901;\nselect * from activities where crm_configuration_id = 21;\n\nselect * roles;\nselect * from permissions;\nselect * from permission_role where permission_id = 226;\n\nselect * from migrations order by id desc;\n\n# mercury\n# neptune\n# earth\n\nselect * from teams;\nselect * from teams where id = 19;\nselect * from teams where id = 27;\nselect * from users where team_id = 27;\nSELECT * FROM crm_configurations WHERE id = 42;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 19\nand sa.provider = 'pipedrive';\n\nselect * from activities where id = 631461;\nSELECT * FROM crm_field_values WHERE crm_field_id = 180;\n\nselect * from teams where id = 2;\nSELECT * FROM social_accounts WHERE sociable_id = 89;\n\nSELECT * FROM activities WHERE uuid_to_bin('ba0c029a-bc14-4e17-8603-64174acebcbb') = uuid; # 634273\nselect * from activity_summary_logs where activity_id = 634273;\n\nselect * from sidekick_settings where team_id = 2;\n\nselect * from teams; # 2, 2\nSELECT * FROM crm_configurations WHERE team_id = 2; # 2\nselect * from team_features where team_id = 2;\nselect * from features;\nSELECT * FROM opportunities WHERE crm_configuration_id = 2 and crm_provider_id = '51317301383';\nSELECT * FROM opportunities WHERE crm_configuration_id = 2 order by id desc;\n\nselect * from automated_reports order by id desc;\nselect * from automated_report_results order by id desc;\nselect * from users where team_id = 1 and id IN (7160, 3248);\nselect * from migrations order by id desc;\n\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 1 and sa.provider = 'salesforce';\n\nselect * from teams where id = 1;\nselect * from groups g JOIN playbooks p on g.playbook_id = p.id where g.team_id = 1;\nselect * from groups where id = 565;\nselect * from playbooks where team_id = 1;\nselect * from playbooks where id = 175;\nselect * from playbook_categories where playbook_id = 175;\nselect * from users where team_id = 1;\nselect * from users where id = 7160;\nselect * from crm_profiles where user_id = 7160;\nselect * from features;\nselect\n *\n# id, uuid, type, provider, playbook_category_id, user_id, lead_id, contact_id, account_id, opportunity_id, stage_id,\n# crm_configuration_id, crm_provider_id, transcription_id, status\nfrom activities where crm_configuration_id = 1 and type = 'conference'\n# and crm_provider_id IS NOT NULL\nand provider != 'uploader' and actual_start_time IS NOT NULL\nORDER by id desc;\nselect * from activities where id = 54747783; # 00UO400000pCzojMAC\n\nselect p.id, p.activity_type, pc.id, pc.name\nFROM playbooks p\njoin playbook_categories pc on p.id = pc.playbook_id\nwhere p.team_id = 1 and p.activity_type = 'event';\n\nSELECT * FROM crm_fields WHERE crm_configuration_id = 1 and object_type = 'event';\nSELECT * FROM crm_field_values WHERE crm_field_id = 4;\n\nselect * from crm_layouts cl join playbook_layouts pl on cl.id = pl.layout_id\nwhere crm_configuration_id = 1 and pl.playbook_id = 175;\n\nselect * from teams;\nSELECT r.* FROM automated_reports r\njoin teams t on r.team_id = t.id\nWHERE r.frequency = 'daily'\n and r.status = 1\nAND t.status = 'active'\nAND (r.expires_at >= now() OR r.expires_at IS NULL);\n\nselect * from automated_report_results where report_id IN (18, 33);\n\nselect * from activity_searches where id = 10932;\nselect * from activity_search_filters where activity_search_id = 10932;\nselect * from automated_reports;\nselect * from automated_report_results where report_id IN (34, 35);","role_description":"text entry area","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.088194445,"height":0.027777778},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"102","depth":4,"role_description":"text"},{"role":"AXStaticText","text":"3","depth":4,"role_description":"text"},{"role":"AXStaticText","text":"34","depth":4,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Services\\Kiosk\\AutomatedReports;\n\nuse Carbon\\CarbonImmutable;\nuse Carbon\\CarbonInterface;\nuse Carbon\\Exceptions\\InvalidFormatException;\nuse DateTime;\nuse DateTimeInterface;\nuse DateTimeZone;\nuse Illuminate\\Contracts\\Bus\\Dispatcher as BusDispatcher;\nuse Illuminate\\Database\\Eloquent\\Builder;\nuse Illuminate\\Support\\Carbon;\nuse Illuminate\\Support\\Collection;\nuse Illuminate\\Support\\Facades\\Log;\nuse Illuminate\\Support\\Facades\\Storage;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinition\\InputTypeEnum;\nuse Jiminny\\Component\\AskAnything\\AskAnythingPromptService;\nuse Jiminny\\Component\\AskAnything\\Dtos\\AskAnythingPromptDto;\nuse Jiminny\\Component\\UrlGenerator\\Webhook;\nuse Jiminny\\Contracts\\Repositories\\PlaybookCategoryRepository;\nuse Jiminny\\Contracts\\Repositories\\TeamRepository;\nuse Jiminny\\Contracts\\Repositories\\UserRepository;\nuse Jiminny\\Exceptions\\ApplicationException;\nuse Jiminny\\Exceptions\\InvalidArgumentException;\nuse Jiminny\\Exceptions\\ModelNotFoundException;\nuse Jiminny\\Jobs\\AutomatedReports\\RequestGenerateReportJob;\nuse Jiminny\\Models\\Activity\\Search;\nuse Jiminny\\Models\\AskAnything\\AskAnythingPrompt;\nuse Jiminny\\Models\\AskAnything\\AskAnythingPromptTarget;\nuse Jiminny\\Models\\AutomatedReport;\nuse Jiminny\\Models\\AutomatedReportResult;\nuse Jiminny\\Models\\Contracts\\UserContract;\nuse Jiminny\\Models\\Feature\\FeatureEnum;\nuse Jiminny\\Models\\Team;\nuse Jiminny\\Models\\User;\nuse Jiminny\\Repositories\\AskAnythingRepository;\nuse Jiminny\\Repositories\\AutomatedReportsRepository;\nuse Jiminny\\Repositories\\GroupRepository;\nuse Jiminny\\Repositories\\SearchRepository;\nuse Jiminny\\Repositories\\StageRepository;\nuse Throwable;\n\nclass AutomatedReportsService\n{\n public const string TYPE_LOSS_ANALYSIS = 'loss_analysis';\n public const string TYPE_ASK_JIMINNY = 'ask_jiminny';\n\n /**\n * Standard report types (used by kiosk for existing automated reports).\n */\n // @TODO this will add filter, however if we need to control feature by FF we need conditional logic\n public const array TYPES = [\n ['id' => 'exec_summary', 'name' => 'Exec Summary'],\n ['id' => 'coaching_profiles', 'name' => 'Coaching Profiles'],\n ['id' => 'product_feedback', 'name' => 'Product Feedback'],\n ['id' => self::TYPE_LOSS_ANALYSIS, 'name' => 'Loss Analysis'],\n// ['id' => 'questions', 'name' => 'Questions'],\n// ['id' => 'statistical_quant', 'name' => 'Statistical Quantitative'],\n ];\n\n public const array ALL_TYPES = [\n ...self::TYPES,\n ['id' => self::TYPE_ASK_JIMINNY, 'name' => 'Ask Jiminny'],\n ];\n\n public const string FREQUENCY_DAILY = 'daily';\n public const string FREQUENCY_WEEKLY = 'weekly';\n public const string FREQUENCY_MONTHLY = 'monthly';\n public const string FREQUENCY_QUARTERLY = 'quarterly';\n public const string FREQUENCY_ONE_OFF = 'one_off';\n\n /**\n * Frequencies for standard (non-Ask Jiminny) reports.\n */\n public const array FREQUENCIES = [\n ['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],\n ['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],\n ['id' => self::FREQUENCY_QUARTERLY, 'name' => 'Quarterly'],\n ['id' => self::FREQUENCY_ONE_OFF, 'name' => 'One-off'],\n ];\n\n /**\n * Frequencies for Ask Jiminny reports.\n */\n public const array ASK_JIMINNY_FREQUENCIES = [\n ['id' => self::FREQUENCY_DAILY, 'name' => 'Daily'],\n ['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],\n ['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],\n ];\n\n public const string MEDIA_TYPE_PDF = 'pdf';\n public const string MEDIA_TYPE_PODCAST = 'podcast';\n public const array MEDIA_TYPES = [self::MEDIA_TYPE_PDF, self::MEDIA_TYPE_PODCAST];\n public const array MEDIA_TYPE_OBJECT_PDF = ['id' => self::MEDIA_TYPE_PDF, 'name' => 'PDF'];\n public const array MEDIA_TYPE_OBJECT_PODCAST = ['id' => self::MEDIA_TYPE_PODCAST, 'name' => 'Podcast'];\n public const array MEDIA_TYPE_OBJECTS = [self::MEDIA_TYPE_OBJECT_PDF, self::MEDIA_TYPE_OBJECT_PODCAST];\n\n public const array CALL_TYPE_CONFERENCE = ['id' => 'conference', 'name' => 'Conference'];\n public const array CALL_TYPE_DIALER = ['id' => 'dialer', 'name' => 'Dialer'];\n public const int SENT_REPORT_AT_HOURS = 5;\n public const string PDF_KEY = 'pdf';\n public const string AUDIO_KEY = 'audio';\n\n private const array ALL_FREQUENCIES = [\n ['id' => self::FREQUENCY_DAILY, 'name' => 'Daily'],\n ['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],\n ['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],\n ['id' => self::FREQUENCY_QUARTERLY, 'name' => 'Quarterly'],\n ['id' => self::FREQUENCY_ONE_OFF, 'name' => 'One-off'],\n ];\n private const string S3_DIR = 'reports';\n private const array FILE_EXTENSIONS_VARIANTS = ['html', 'MD', 'pdf'];\n private const array FILE_PODCAST_EXTENSIONS_VARIANTS = ['json', 'mp3', 'ssml'];\n\n public function __construct(\n private readonly TeamRepository $teamRepository,\n private readonly GroupRepository $groupRepository,\n private readonly UserRepository $userRepository,\n private readonly StageRepository $stageRepository,\n private readonly DealStagesService $dealStagesService,\n private readonly RecipientsService $recipientsService,\n private readonly AutomatedReportsRepository $automatedReportsRepository,\n private readonly Webhook $webhookService,\n private readonly BusDispatcher $dispatcher,\n private readonly ActivityTypeService $activityTypeService,\n private readonly PlaybookCategoryRepository $playbookCategoryRepository,\n private readonly AskAnythingPromptService $askAnythingPromptService,\n private readonly SearchRepository $activitySearchRepository,\n private readonly AskAnythingRepository $askAnythingRepository,\n ) {\n }\n\n public static function getTypes(): array\n {\n $types = self::TYPES;\n\n return array_map(static function ($type) {\n return $type['id'];\n }, $types);\n }\n\n public static function getCallTypes(): array\n {\n return array_map(static function ($callType) {\n return $callType['id'];\n }, [self::CALL_TYPE_CONFERENCE, self::CALL_TYPE_DIALER]);\n }\n\n public static function getFrequencies(): array\n {\n return array_map(static function ($frequency) {\n return $frequency['id'];\n }, self::FREQUENCIES);\n }\n\n // front-facing structure\n public function getReportEnabledFieldData(bool $value = false): array\n {\n return [\n 'id' => 'report_enabled',\n 'label' => '',\n 'inputType' => InputTypeEnum::TOGGLE,\n 'value' => $value,\n ];\n }\n\n // Organizations = Teams\n public function getOrganizationFieldData(?string $value = null, bool $shortVersion = false): array\n {\n $options = $this->getTeams();\n\n if ($shortVersion) {\n return [\n 'id' => 'organization',\n 'label' => 'Organization',\n 'options' => $options,\n ];\n }\n\n return [\n 'id' => 'organization',\n 'label' => 'Organization',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => $options,\n 'value' => $value,\n 'dependencies' => [\n 'teams',\n 'deal_stage_at_call',\n 'current_deal_stage',\n 'recipients',\n ActivityTypeService::PLAYBOOK_CATEGORIES_KEY,\n ],\n 'dependsOn' => [],\n ];\n }\n\n // Teams = Groups\n public function getTeamFieldData(array $options = [], array $value = [], bool $shortVersion = false): array\n {\n if ($shortVersion) {\n return [\n 'id' => 'teams',\n 'label' => 'Team',\n 'options' => $options,\n ];\n }\n\n return [\n 'id' => 'teams',\n 'label' => 'Team',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'required' => false,\n 'placeholder' => 'Select',\n 'options' => $options,\n 'value' => $value, // value should be an array of objects {id, name}\n 'dependencies' => [ActivityTypeService::PLAYBOOK_CATEGORIES_KEY],\n 'dependsOn' => [],\n ];\n }\n\n public function getReportTypeFieldData(?string $value = null, bool $shortVersion = false, ?Team $team = null): array\n {\n $types = [];\n if ($team instanceof Team) {\n if ($team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {\n $types = self::TYPES;\n }\n if ($team->hasFeature(FeatureEnum::ASK_JIMINNY_REPORTS)) {\n $types[] = ['id' => self::TYPE_ASK_JIMINNY, 'name' => 'Ask Jiminny'];\n }\n } else {\n $types = self::TYPES;\n }\n\n if ($shortVersion) {\n return [\n 'id' => 'report_type',\n 'label' => 'Report Type',\n 'options' => $types,\n ];\n }\n\n return [\n 'id' => 'report_type',\n 'label' => 'Report Type',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => $types,\n 'value' => $value,\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getFrequencyFieldData(?string $value = null): array\n {\n return [\n 'id' => 'frequency',\n 'label' => 'Frequency',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => self::FREQUENCIES,\n 'value' => $value,\n 'dependencies' => ['period'],\n 'dependsOn' => [],\n ];\n }\n\n public function getPeriodFieldData(?string $valueStartDate = null, ?string $valueEndDate = null): array\n {\n return [\n 'id' => 'period',\n 'label' => 'Select one-off period',\n 'inputType' => InputTypeEnum::DATE_RANGE,\n 'required' => true,\n 'placeholder' => 'Select',\n 'value' => ['startDate' => $valueStartDate, 'endDate' => $valueEndDate],\n 'queryParams' => [\n 'startDate' => 'start_date_period',\n 'endDate' => 'end_date_period',\n ],\n 'dependencies' => [],\n 'dependsOn' => ['frequency'],\n ];\n }\n\n public function getActivityTypesFieldData(?Team $team = null, array $value = [], array $teamsFilter = []): array\n {\n return $this->activityTypeService->getActivityTypeFieldData(team: $team, value: $value, groupIds: $teamsFilter);\n }\n\n public function getDealStageAtCallFieldData(?Team $team = null, array $value = []): array\n {\n return $this->dealStagesService->getDealStageAtCallFieldData(team: $team, value: $value);\n }\n\n public function getCurrentDealStageFieldData(?Team $team = null, array $value = []): array\n {\n return $this->dealStagesService->getCurrentDealStageFieldData(team: $team, value: $value);\n }\n\n public function getDealValueFieldData(?int $valueMin = null, ?int $valueMax = null): array\n {\n return [\n 'id' => 'deal_value',\n 'label' => 'Deal Value',\n 'inputType' => InputTypeEnum::INTEGER_RANGE,\n 'required' => false,\n 'value' => ['min' => $valueMin, 'max' => $valueMax],\n 'queryParams' => [\n 'min' => 'min_deal_value',\n 'max' => 'max_deal_value',\n ],\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getCallTypeFieldData(bool $conferenceOn = false, bool $dialerOn = false): array\n {\n $value = [];\n $conferenceOn && $value[] = self::CALL_TYPE_CONFERENCE;\n $dialerOn && $value[] = self::CALL_TYPE_DIALER;\n\n return [\n 'id' => 'call_type',\n 'label' => 'Call Type',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'required' => true,\n 'options' => [\n self::CALL_TYPE_CONFERENCE,\n self::CALL_TYPE_DIALER,\n ],\n 'value' => $value,\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getMediaTypeFieldData(?AutomatedReport $report = null): array\n {\n $value = [];\n\n if ($report) {\n $value = $this->transformMediaTypes($report);\n }\n\n return [\n 'id' => 'media_types',\n 'label' => 'Export as',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'required' => true,\n 'options' => self::MEDIA_TYPE_OBJECTS,\n 'value' => $value,\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getCallDurationFieldData(?int $valueMin = null, ?int $valueMax = null): array\n {\n return [\n 'id' => 'call_duration',\n 'label' => 'Call Duration',\n 'inputType' => InputTypeEnum::INTEGER_RANGE,\n 'required' => false,\n 'value' => ['min' => $valueMin, 'max' => $valueMax],\n 'queryParams' => [\n 'min' => 'min_call_duration',\n 'max' => 'max_call_duration',\n ],\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getRecipientsFieldData(?Team $team = null, array $value = []): array\n {\n return $this->recipientsService->getRecipientsFieldData(team: $team, value: $value);\n }\n\n public function getJiminnyRecipientsFieldData(array $value = []): array\n {\n return $this->recipientsService->getJiminnyRecipientsFieldData($value);\n }\n\n public function getAdditionalPromptInputFieldData(?string $value = null): array\n {\n return [\n 'id' => 'additional_prompt_input',\n 'label' => 'Special requirements',\n 'inputType' => InputTypeEnum::TEXTAREA,\n 'required' => false,\n 'placeholder' => 'What should be the focus of the report?',\n 'value' => $value,\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getCustomReportNameFieldData(?string $value = null): array\n {\n return [\n 'id' => 'custom_name',\n 'label' => 'Custom report name',\n 'inputType' => InputTypeEnum::TEXT,\n 'required' => false,\n 'placeholder' => 'Enter custom name',\n 'value' => $value,\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n // data providers\n public function getTeams(): array\n {\n $teams = $this->teamRepository->getTeamsForKiosk(status: Team::STATUS_ACTIVE);\n\n $teamData = [];\n foreach ($teams as $team) {\n if (! $team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {\n continue;\n }\n\n $teamData[] = $this->transformTeam($team);\n }\n\n return $teamData;\n }\n\n public function getTeamGroups(string $teamUuid): array\n {\n $data = [];\n $team = $this->getTeam($teamUuid);\n\n if ($team !== null) {\n $groups = $team->groups()->get();\n\n foreach ($groups as $group) {\n $data[] = [\n 'id' => $group->getUuid(),\n 'name' => $group->getName(),\n ];\n }\n }\n\n return $data;\n }\n\n public function getTeamsGroupsOptions(array $filterTeamUuids = []): array\n {\n $data = [];\n $teams = $this->getTeams();\n\n foreach ($teams as $team) {\n if (! empty($filterTeamUuids) && ! in_array($team['id'], $filterTeamUuids, true)) {\n continue;\n }\n\n $data[] = [\n 'label' => $team['name'],\n 'groups' => $this->getTeamGroups($team['id']),\n ];\n }\n\n return $data;\n }\n\n public function getTeam(string $teamUuid): ?Team\n {\n return $this->teamRepository->idOrUuid($teamUuid);\n }\n\n public function getTeamById(int $teamId): ?Team\n {\n return $this->teamRepository->find($teamId);\n }\n\n public function getGroupsUuids(AutomatedReport $report): array\n {\n $uuids = [];\n $reportGroups = $report->getGroups();\n foreach ($reportGroups as $groupId) {\n if ($group = $this->groupRepository->find($groupId)) {\n $uuids[] = $group->getUuid();\n }\n }\n\n return $uuids;\n }\n\n public function getPlaybookCategoriesUuids(AutomatedReport $report): array\n {\n $uuids = [];\n $playbookCategories = $report->getPlaybookCategories();\n foreach ($playbookCategories as $id) {\n if ($category = $this->playbookCategoryRepository->find($id)) {\n $uuids[] = $category->getUuid();\n }\n }\n\n return $uuids;\n }\n\n public function getDealAtCallStagesUuids(AutomatedReport $report): array\n {\n $uuids = [];\n $reportStages = $report->getDealAtCallStages();\n foreach ($reportStages as $id) {\n if ($stage = $this->stageRepository->find($id)) {\n $uuids[] = $stage->getUuid();\n }\n }\n\n return $uuids;\n }\n\n public function getCurrentDealStagesUuids(AutomatedReport $report): array\n {\n $uuids = [];\n $reportStages = $report->getCurrentDealStages();\n foreach ($reportStages as $id) {\n if ($stage = $this->stageRepository->find($id)) {\n $uuids[] = $stage->getUuid();\n }\n }\n\n return $uuids;\n }\n\n public function getUsersUuids(AutomatedReport $report): array\n {\n return $this->extractUserUuids($report->getRecipients());\n }\n\n public function getJiminnyUsersUuids(AutomatedReport $report): array\n {\n return $this->extractUserUuids($report->getJiminnyRecipients());\n }\n\n /**\n * @param array<string, mixed> $recipients\n */\n private function extractUserUuids(array $recipients): array\n {\n $userIds = $recipients['users'] ?? [];\n\n return collect($userIds)\n ->map(fn ($id) => $this->userRepository->find((int) $id))\n ->filter()\n ->map(fn (UserContract $user) => $user->getUuid())\n ->values()\n ->all();\n }\n\n // get mail data\n public function getRecipientUsers(AutomatedReport $report): array\n {\n return $this->buildRecipientUsers($report->getRecipients());\n }\n\n private function getJiminnyRecipientUsers(AutomatedReport $report): array\n {\n return $this->buildRecipientUsers($report->getJiminnyRecipients());\n }\n\n /**\n * @param array<string, mixed> $recipients\n */\n private function buildRecipientUsers(array $recipients): array\n {\n $userIds = $recipients['users'] ?? [];\n\n return collect($userIds)\n ->map(fn ($id) => $this->userRepository->find((int) $id))\n ->filter()\n ->map(fn (UserContract $user) => [\n 'email' => $user->getEmailAddress(),\n 'name' => $user->getName(),\n 'timezone' => $user->getTimezone()->getName(),\n ])\n ->values()\n ->all();\n }\n\n public function getValidRecipientUsers(AutomatedReport $report, bool $includeJiminny = false): array\n {\n if ($report->isAskJiminnyReport()) {\n $recipients = $this->resolveAskJiminnyRecipients($report);\n } else {\n $recipients = $this->getRecipientUsers($report);\n if ($includeJiminny) {\n $recipients = array_merge($recipients, $this->getJiminnyRecipientUsers($report));\n }\n }\n\n $emails = [];\n\n return array_values(array_filter(\n $recipients,\n static function ($recipient) use (&$emails) {\n if (empty($recipient['email']) || in_array($recipient['email'], $emails, true)) {\n return false;\n }\n $emails[] = $recipient['email'];\n\n return true;\n }\n ));\n }\n\n private function resolveAskJiminnyRecipients(AutomatedReport $report): array\n {\n $recipients = [];\n\n $creator = $report->getCreator();\n if ($creator !== null) {\n $recipients[] = [\n 'email' => $creator->getEmailAddress(),\n 'name' => $creator->getName(),\n 'timezone' => $creator->getTimezone()->getName(),\n ];\n }\n\n return array_merge(\n $recipients,\n $this->buildRecipientUsers($report->getRecipients()),\n $this->getGroupRecipientUsers($report),\n );\n }\n\n private function getGroupRecipientUsers(AutomatedReport $report): array\n {\n $users = [];\n foreach ($report->getGroups() as $groupId) {\n $group = $this->groupRepository->find($groupId);\n if ($group === null) {\n continue;\n }\n foreach ($group->getMembers() as $member) {\n $users[] = [\n 'email' => $member->getEmailAddress(),\n 'name' => $member->getName(),\n 'timezone' => $member->getTimezone()->getName(),\n ];\n }\n }\n\n return $users;\n }\n\n public function getReportTypeName(AutomatedReportResult $report): string\n {\n $type = $report->getReport()->getType();\n\n $getType = $this->transformReportType($type);\n\n return $getType['name'];\n }\n\n public function getReportPeriodName(AutomatedReportResult $report): string\n {\n $from = $report->getFromDate();\n $to = $report->getToDate();\n $frequency = $report->getReport()->getFrequency();\n\n if ($from === null || $to === null) {\n if (! $report->getReport()->isAskJiminnyReport()) {\n $invalidPeriod = $from === null ? 'from' : 'to';\n\n throw new ApplicationException('Report period is invalid: ' . $invalidPeriod);\n }\n\n $period = $this->calculateFromAndToDatePeriod($frequency);\n $from = $period['fromDate'];\n $to = $period['toDate'];\n }\n\n return $this->formatReportPeriodName($frequency, $from, $to);\n }\n\n private function formatReportPeriodName(string $frequency, Carbon $from, Carbon $to): string\n {\n $fromYear = $from->format('Y');\n $toYear = $to->format('Y');\n $differentYears = $fromYear !== $toYear;\n\n switch ($frequency) {\n case self::FREQUENCY_DAILY:\n return $from->format('j M Y');\n\n case self::FREQUENCY_QUARTERLY:\n // 'Jan-Mar 2025' or 'Nov 2024-Jan 2025' if years differ\n $startMonth = $from->format('M');\n $endMonth = $to->copy()->subMonth();\n $endMonthName = $endMonth->format('M');\n $endMonthYear = $endMonth->format('Y');\n\n if ($differentYears) {\n return \"{$startMonth} {$fromYear} - {$endMonthName} {$endMonthYear}\";\n }\n\n return \"{$startMonth} - {$endMonthName} {$toYear}\";\n\n case self::FREQUENCY_MONTHLY:\n // 'May 2025' - monthly reports are always within the same year\n return $from->format('M Y');\n\n case self::FREQUENCY_WEEKLY:\n // '4 - 8 Aug 2025', '27 Oct - 3 Nov 2025', or '28 Dec 2024 - 3 Jan 2025' if years differ\n $startDay = $from->format('j');\n $endDay = $to->format('j');\n $startMonth = $from->format('M');\n $endMonth = $to->format('M');\n\n if ($differentYears) {\n return \"{$startDay} {$startMonth} {$fromYear} - {$endDay} {$endMonth} {$toYear}\";\n }\n\n if ($startMonth !== $endMonth) {\n return \"{$startDay} {$startMonth} - {$endDay} {$endMonth} {$toYear}\";\n }\n\n return \"{$startDay} - {$endDay} {$endMonth} {$toYear}\";\n\n case self::FREQUENCY_ONE_OFF:\n // '2 May-31 May 2025' or '15 Dec 2024-15 Jan 2025' if years differ\n $startDay = $from->format('j');\n $startMonth = $from->format('M');\n $endDay = $to->format('j');\n $endMonth = $to->format('M');\n\n // If same month and year, use a format like '2-31 May 2025'\n if ($startMonth === $endMonth && ! $differentYears) {\n return \"{$startDay} - {$endDay} {$startMonth} {$toYear}\";\n }\n\n // If different years, include both years\n if ($differentYears) {\n return \"{$startDay} {$startMonth} {$fromYear} - {$endDay} {$endMonth} {$toYear}\";\n }\n\n // Same year but different months\n return \"{$startDay} {$startMonth} - {$endDay} {$endMonth} {$toYear}\";\n\n default:\n // Default format for unknown frequencies\n return $from->format('j M Y') . ' - ' . $to->format('j M Y');\n }\n }\n\n public function getReportTeamsName(AutomatedReportResult $report): string\n {\n $groups = $report->getGroups();\n\n if (empty($groups)) {\n return 'All';\n }\n\n // Get group names from repository\n $groupNames = [];\n foreach ($groups as $groupId) {\n $group = $this->groupRepository->find($groupId);\n if ($group) {\n $groupNames[] = $group->getName();\n }\n }\n\n if (count($groupNames) === 1) {\n // Single team format\n $teamsName = $groupNames[0];\n } else {\n // Multiple teams format\n $teamsName = implode(', ', $groupNames);\n }\n\n return $teamsName;\n }\n\n public function getReportFileName(AutomatedReportResult $report): string\n {\n $customName = $report->getReport()->getCustomName();\n $periodName = $this->getReportPeriodName($report);\n $filenameSuffix = $this->getFilenameSuffix($report);\n\n if ($customName) {\n if ($filenameSuffix) {\n $customName .= \" {$filenameSuffix}\";\n }\n\n return $this->sanitizeFileName(\"{$customName} - {$periodName}\");\n }\n\n $baseName = $this->getReportTypeName($report);\n\n if ($filenameSuffix) {\n $baseName .= \" {$filenameSuffix}\";\n }\n\n return $this->sanitizeFileName(\"{$baseName} - {$periodName} - {$this->getReportTeamsName($report)}\");\n }\n\n public function getReportFileNameWithExtension(AutomatedReportResult $result): string\n {\n $extension = $this->getMediaTypeMetadata($result)['extension'];\n\n return $this->getReportFileName($result) . '.' . $extension;\n }\n\n public function sanitizeFileName(string $fileName): string\n {\n return str_replace(['/', '\\\\'], '-', $fileName);\n }\n\n public function isUserRecipientOfReport(User $user, AutomatedReport $report): bool\n {\n $recipients = array_map('intval', $report->getRecipients()['users'] ?? []);\n\n return in_array($user->getId(), $recipients);\n }\n\n public function transformReportResults(Collection $automatedReportResults): array\n {\n $data = [];\n foreach ($automatedReportResults as $automatedReportResult) {\n /** @var AutomatedReportResult $automatedReportResult */\n\n $report = $automatedReportResult->getReport();\n\n $createdBy = $report->getCreator();\n $creator = [\n 'id' => $createdBy?->getUuid(),\n 'name' => $createdBy?->getName(),\n 'email' => $createdBy?->getEmailAddress(),\n 'photoUrl' => $createdBy?->getPhotoUrl(),\n ];\n\n $data[] = [\n 'id' => $automatedReportResult->getUuid(),\n 'name' => $automatedReportResult->getName(),\n 'frequency' => $this->transformFrequency($report->getFrequency()),\n 'recipients' => [\n ...array_values($this->transformGroups(team: $report->getTeam(), groupsIds: $report->getGroups())),\n ...array_values($this->transformRecipients($report->getRecipients())),\n ],\n 'report_type' => $this->transformReportType($report->getType()),\n 'media_type' => $automatedReportResult->getMediaType(),\n 'downloadUrl' => $this->generateReportResultDownloadUrl($automatedReportResult),\n 'viewUrl' => $this->generateReportResultViewUrl($automatedReportResult),\n 'generated_at' => $automatedReportResult->getGeneratedAt()?->toIso8601String(),\n 'creator' => $creator,\n ];\n }\n\n return $data;\n }\n\n public function hasCallTypeConference(AutomatedReport $report): bool\n {\n return in_array(self::CALL_TYPE_CONFERENCE['id'], $report->getCallTypes(), true);\n }\n\n public function hasCallTypeDialer(AutomatedReport $report): bool\n {\n return in_array(self::CALL_TYPE_DIALER['id'], $report->getCallTypes(), true);\n }\n\n // transformers\n private function transformTeam(Team $team): array\n {\n if (! $team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {\n return [];\n }\n\n return [\n 'id' => $team->getUuid(),\n 'name' => $team->getName(),\n ];\n }\n\n private function transformReportFullView(AutomatedReport $report): array\n {\n $base = $this->transformReportBase($report);\n\n return $report->getType() === self::TYPE_ASK_JIMINNY\n ? $base + $this->transformAskJiminnyFields($report)\n : $base + $this->transformStandardReportFields($report);\n }\n\n private function transformReportBase(AutomatedReport $report): array\n {\n return [\n 'id' => $report->getUuid(),\n 'organization' => $this->transformOrganization(team: $report->getTeam()),\n 'report_type' => $this->transformReportType($report->getType()),\n 'frequency' => $this->transformFrequency($report->getFrequency()),\n ];\n }\n\n private function transformStandardReportFields(AutomatedReport $report): array\n {\n $team = $report->getTeam();\n\n return [\n 'report_enabled' => $report->getStatus(),\n 'start_date_period' => $report->getFrom()?->format('Y-m-d H:i:s'),\n 'end_date_period' => $report->getTo()?->format('Y-m-d H:i:s'),\n 'deal_value_min' => $report->getDealValueMin(),\n 'deal_value_max' => $report->getDealValueMax(),\n 'call_types' => $this->transformCallType($report->getCallTypes()),\n 'media_types' => $this->transformMediaTypes($report),\n 'call_duration_min' => $this->transformDurationToMinutes($report->getCallDurationMin()),\n 'call_duration_max' => $this->transformDurationToMinutes($report->getCallDurationMax()),\n 'teams' => $this->transformGroups(team: $team, groupsIds: $report->getGroups()),\n 'deal_at_call_stages' => $this->transformStages(team: $team, stagesIds: $report->getDealAtCallStages()),\n 'current_deal_stages' => $this->transformStages(team: $team, stagesIds: $report->getCurrentDealStages()),\n 'recipients' => $this->transformRecipients($report->getRecipients()),\n 'created_by' => $this->transformCreator($report->getCreator()),\n 'additional_prompt_input' => $report->getAdditionalPromptInput(),\n 'custom_name' => $report->getCustomName(),\n 'created_at' => $report->getCreatedAt()->format('Y-m-d H:i:s'),\n 'updated_at' => $report->getUpdatedAt()->format('Y-m-d H:i:s'),\n 'deleted_at' => $report->getDeletedAt()?->format('Y-m-d H:i:s'),\n ];\n }\n\n private function transformAskJiminnyFields(AutomatedReport $report): array\n {\n $team = $report->getTeam();\n $creatorId = $report->getAttribute('created_by');\n $explicitUserIds = array_values(array_filter(\n $report->getRecipients()['users'] ?? [],\n static fn ($id) => $id !== $creatorId\n ));\n\n return [\n 'report_name' => $report->getCustomName(),\n 'enabled' => $report->getStatus(),\n 'share_teams' => $this->transformGroups(team: $team, groupsIds: $report->getGroups()),\n 'share_users' => $this->transformRecipients(['users' => $explicitUserIds]),\n 'saved_search' => $this->transformSafeSearch($report->getSavedSearch()),\n 'ask_jiminny_prompt' => $this->transformAskJiminnyPrompt($report->getAskAnythingPrompt()),\n 'expires_on' => $report->getExpiresAt()?->format('Y-m-d'),\n ];\n }\n\n private function transformOrganization(?Team $team): array\n {\n return [\n 'id' => $team?->getUuid(),\n 'name' => $team?->getName(),\n ];\n }\n\n private function transformReportType(string $type): array\n {\n foreach (self::ALL_TYPES as $typeItem) {\n if ($typeItem['id'] === $type) {\n return $typeItem;\n }\n }\n\n return [];\n }\n\n private function transformCallType(array $types): array\n {\n $result = [];\n $callTypes = [self::CALL_TYPE_CONFERENCE, self::CALL_TYPE_DIALER];\n\n foreach ($types as $type) {\n foreach ($callTypes as $callTypeItem) {\n if ($callTypeItem['id'] === $type) {\n $result[] = $callTypeItem;\n\n break;\n }\n }\n }\n\n return $result;\n }\n\n private function transformMediaTypes(AutomatedReport $report): array\n {\n $values = [];\n\n foreach ($report->getMediaTypes() as $mediaType) {\n if (! in_array($mediaType, self::MEDIA_TYPES, true)) {\n continue;\n }\n\n $values[] = match ($mediaType) {\n self::MEDIA_TYPE_PDF => self::MEDIA_TYPE_OBJECT_PDF,\n self::MEDIA_TYPE_PODCAST => self::MEDIA_TYPE_OBJECT_PODCAST,\n };\n }\n\n return $values;\n }\n\n private function transformFrequency(string $frequency): array\n {\n foreach (self::ALL_FREQUENCIES as $frequencyItem) {\n if ($frequencyItem['id'] === $frequency) {\n return $frequencyItem;\n }\n }\n\n return [];\n }\n\n public function transformDurationToMinutes(?int $duration): ?int\n {\n if (! $duration) {\n return null;\n }\n\n return (int) ($duration / 60);\n }\n\n private function transformGroups(?Team $team, array $groupsIds): array\n {\n if (empty($groupsIds) || ! $team) {\n return [];\n }\n\n $data = [];\n foreach ($groupsIds as $groupId) {\n $group = $team->groups()->where('id', $groupId)->first();\n\n if ($group) {\n $data[] = [\n 'id' => $group->getUuid(),\n 'name' => $group->getName(),\n 'photoUrl' => $group->getPhotoUrl(),\n ];\n }\n }\n\n return $data;\n }\n\n private function transformStages(?Team $team, array $stagesIds): array\n {\n if (empty($stagesIds) || ! $team) {\n return [];\n }\n\n $data = [];\n foreach ($stagesIds as $stageId) {\n $stage = $team->stages()->where('id', $stageId)->first();\n\n if ($stage) {\n $data[] = [\n 'id' => $stage->getUuid(),\n 'name' => $stage->getName(),\n ];\n }\n }\n\n return $data;\n }\n\n private function transformRecipients(array $recipients): array\n {\n $users = [];\n foreach ($recipients['users'] ?? [] as $userId) {\n $users[] = $this->transformUser($userId);\n }\n\n return $users;\n }\n\n private function transformCreator(?User $user): ?array\n {\n if ($user === null) {\n return null;\n }\n\n return $this->transformUser($user->getId());\n }\n\n private function transformAskJiminnyPrompt(?AskAnythingPrompt $prompt): ?array\n {\n if ($prompt === null) {\n return null;\n }\n\n return [\n 'id' => $prompt->getUuid(),\n 'name' => $prompt->getTitle(),\n ];\n }\n\n private function transformSafeSearch(?Search $search): ?array\n {\n if ($search === null) {\n return null;\n }\n\n return [\n 'id' => $search->getUuid(),\n 'name' => $search->getName(),\n ];\n }\n\n private function transformUser(int $userId): array\n {\n /* @var ?User $user */\n $user = $this->userRepository->find($userId);\n\n return [\n 'id' => $user?->getUuid(),\n 'name' => $user?->getName(),\n 'email' => $user?->getEmailAddress(),\n 'photoUrl' => $user?->getPhotoUrl(),\n ];\n }\n\n public function create(array $data): array\n {\n $validatedData = $this->validateAndTransformData($data);\n $validatedData['created_by'] = auth()->id();\n\n $automatedReport = $this->automatedReportsRepository->create($validatedData);\n\n $this->generateOneOffReport($automatedReport);\n\n return $this->transformReportFullView($automatedReport);\n }\n\n public function update(string $uuid, array $data): array\n {\n $validatedData = $this->validateAndTransformData($data);\n $report = $this->automatedReportsRepository->findByUuid($uuid);\n\n if (! $report) {\n throw new InvalidArgumentException('Report not found');\n }\n\n $oldCustomName = $report->getCustomName();\n\n $automatedReport = $this->automatedReportsRepository->update($report, $validatedData);\n\n if ($oldCustomName !== $automatedReport->getCustomName()) {\n $this->updateResultNames($automatedReport);\n }\n\n $this->generateOneOffReport($automatedReport);\n\n return $this->transformReportFullView($automatedReport);\n }\n\n /**\n * Create an Ask Jiminny report.\n */\n public function createAskJiminnyReport(array $data, User $creator): array\n {\n $validatedData = $this->validateAskJiminnyReportData($data, $creator);\n $validatedData['created_by'] = $creator->getId();\n\n $automatedReport = $this->automatedReportsRepository->create($validatedData);\n\n return $this->transformReportFullView($automatedReport);\n }\n\n /**\n * Update an Ask Jiminny report.\n */\n public function updateAskJiminnyReport(AutomatedReport $report, array $data, User $user): array\n {\n if (! $report->isAskJiminnyReport()) {\n throw new InvalidArgumentException('Report is not an Ask Jiminny report');\n }\n\n $validatedData = $this->validateAskJiminnyReportData($data, $user);\n\n $oldCustomName = $report->getCustomName();\n\n $automatedReport = $this->automatedReportsRepository->update($report, $validatedData);\n\n if ($oldCustomName !== $automatedReport->getCustomName()) {\n $this->updateResultNames($automatedReport);\n }\n\n return $this->transformReportFullView($automatedReport);\n }\n\n public function updateAskJiminnyReportStatus(AutomatedReport $report, bool $status): array\n {\n $this->automatedReportsRepository->update($report, ['status' => $status]);\n\n return $this->transformReportFullView($report->fresh());\n }\n\n /**\n * Validate and transform data for Ask Jiminny reports.\n */\n private function validateAskJiminnyReportData(array $data, User $user): array\n {\n // Validate name\n $name = trim($data['report_name'] ?? '');\n if (empty($name)) {\n throw new InvalidArgumentException('Report name is required');\n }\n if (mb_strlen($name) > 50) {\n throw new InvalidArgumentException('Report name must be 50 characters or less');\n }\n\n // Validate frequency (only daily, weekly, monthly for Ask Jiminny)\n $frequency = $data['frequency'] ?? null;\n $askJiminnyFrequencies = [self::FREQUENCY_DAILY, self::FREQUENCY_WEEKLY, self::FREQUENCY_MONTHLY];\n if (! in_array($frequency, $askJiminnyFrequencies, true)) {\n throw new InvalidArgumentException('Frequency must be daily, weekly, or monthly');\n }\n\n // Validate expiration date\n $expiresAt = $data['expires_on'] ?? null;\n if (empty($expiresAt)) {\n throw new InvalidArgumentException('Expiration date is required');\n }\n\n try {\n $expiresAtDate = Carbon::parse($expiresAt);\n } catch (InvalidFormatException $e) {\n throw new InvalidArgumentException('Expiration date format is invalid');\n }\n $maxExpiration = Carbon::now()->addYear();\n if ($expiresAtDate->gt($maxExpiration)) {\n throw new InvalidArgumentException('Expiration date cannot be more than 1 year from now');\n }\n if ($expiresAtDate->isPast()) {\n throw new InvalidArgumentException('Expiration date cannot be in the past');\n }\n\n // Validate saved search\n $activitySearchId = $data['saved_search'] ?? null;\n if (empty($activitySearchId)) {\n throw new InvalidArgumentException('Saved search is required');\n }\n $savedSearch = $this->activitySearchRepository->findByUuidAndUser($activitySearchId, $user);\n if (! $savedSearch) {\n throw new InvalidArgumentException('Saved search not found or does not belong to you');\n }\n\n // Validate saved prompt\n $askAnythingPromptId = $data['ask_jiminny_prompt'] ?? null;\n if (empty($askAnythingPromptId)) {\n throw new InvalidArgumentException('Ask Jiminny prompt is required');\n }\n $prompt = $this->askAnythingRepository->getPromptByUuid($askAnythingPromptId);\n if (! $prompt) {\n throw new InvalidArgumentException('Ask Jiminny prompt not found');\n }\n\n // Validate status\n $status = $data['enabled'] ?? false;\n\n $recipientUserIds = [$user->getId()];\n\n if (! empty($data['share_users'])) {\n $sharedUserIds = $this->validateAndGetUserIdsByTeam(\n $user->team,\n (array) $data['share_users']\n );\n $recipientUserIds = array_merge($recipientUserIds, $sharedUserIds);\n }\n\n $sharedGroupIds = [];\n if (! empty($data['share_teams'])) {\n $sharedGroupIds = $this->validateAndGetGroupIds($user->team, (array) $data['share_teams']);\n }\n\n $recipientUserIds = array_values(array_unique($recipientUserIds));\n\n return [\n 'team_id' => $user->getTeamId(),\n 'type' => self::TYPE_ASK_JIMINNY,\n 'status' => (bool) $status,\n 'frequency' => $frequency,\n 'custom_name' => $name,\n 'activity_search_id' => $savedSearch->getId(),\n 'ask_anything_prompt_id' => $prompt->getId(),\n 'expires_at' => $expiresAtDate->toDateString(),\n 'media_types' => [self::MEDIA_TYPE_PDF],\n 'call_types' => [],\n 'recipients' => ['users' => $recipientUserIds],\n 'groups' => $sharedGroupIds,\n ];\n }\n\n public static function getAskJiminnyFrequencies(): array\n {\n return array_map(static function ($frequency) {\n return $frequency['id'];\n }, self::ASK_JIMINNY_FREQUENCIES);\n }\n\n public function getAskJiminnyReportFilters(User $user): array\n {\n $savedSearches = $this->activitySearchRepository->findByUserOrderedByName($user)\n ->map(fn (Search $search) => [\n 'id' => $search->getUuid(),\n 'name' => $search->getName(),\n ])\n ->values()->all();\n\n $prompts = collect(\n $this->askAnythingPromptService->get($user, AskAnythingPromptTarget::on_demand)\n )->map(fn (AskAnythingPromptDto $prompt) => [\n 'id' => $prompt->id,\n 'name' => $prompt->title,\n ])->values()->all();\n\n return [\n [\n 'id' => 'prompt',\n 'label' => 'Prompt',\n 'options' => $prompts,\n ],\n [\n 'id' => 'saved_search',\n 'label' => 'Saved Search',\n 'options' => $savedSearches,\n ],\n ];\n }\n\n public function getAskJiminnyReportFormData(User $user, ?AutomatedReport $report = null): array\n {\n $team = $user->getTeam();\n $userTimezone = $user->getTimezone();\n\n $savedSearches = $this->activitySearchRepository->findByUserOrderedByName($user)\n ->map(fn (Search $search) => [\n 'id' => $search->getUuid(),\n 'name' => $search->getName(),\n ])\n ->values()->all();\n\n $prompts = collect(\n $this->askAnythingPromptService->get($user, AskAnythingPromptTarget::on_demand)\n )->map(fn (AskAnythingPromptDto $prompt) => [\n 'id' => $prompt->id,\n 'name' => $prompt->title,\n ])->values()->all();\n\n $teamGroups = $this->groupRepository->getAllByTeam($team)->map(fn ($group) => [\n 'id' => $group->getUuid(),\n 'name' => $group->getName(),\n ])->values()->all();\n\n $shareUsers = $this->recipientsService->getRecipientsFieldData(team: $team)['options'] ?? [];\n\n $sharedTeamsValue = [];\n $sharedUsersValue = [];\n if ($report) {\n $sharedTeamsValue = $this->transformGroups($team, $report->getGroups());\n\n $recipientUserIds = $report->getRecipients()['users'] ?? [];\n $creatorId = $report->getAttribute('created_by');\n $sharedUserIds = array_values(array_filter(\n $recipientUserIds,\n static fn ($id) => $id !== $creatorId\n ));\n $sharedUsersValue = collect($sharedUserIds)\n ->map(fn ($id) => $this->userRepository->find((int) $id))\n ->filter()\n ->map(fn (User $u) => [\n 'id' => $u->getUuid(),\n 'name' => $u->getName(),\n ])\n ->values()\n ->all();\n }\n\n return [\n 'fields' => [\n [\n 'id' => 'enabled',\n 'inputType' => InputTypeEnum::TOGGLE,\n 'label' => '',\n 'value' => $report?->getStatus() ?? false,\n ],\n [\n 'id' => 'report_name',\n 'inputType' => InputTypeEnum::TEXT,\n 'label' => 'Name',\n 'placeholder' => 'Enter name',\n 'required' => true,\n 'validation' => ['maxLength' => 50],\n 'value' => $report?->getCustomName() ?? '',\n ],\n [\n 'id' => 'frequency',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'label' => 'Frequency',\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => self::ASK_JIMINNY_FREQUENCIES,\n 'value' => $report ? $this->transformFrequency($report->getFrequency()) : null,\n ],\n [\n 'id' => 'expires_on',\n 'inputType' => InputTypeEnum::DATE,\n 'label' => 'Expires on',\n 'required' => true,\n 'placeholder' => 'Select',\n 'validation' => [\n 'minDate' => now($userTimezone)->toDateString(),\n 'maxDate' => now($userTimezone)->addYear()->toDateString(),\n ],\n 'value' => $report?->getExpiresAt()?->toDateString(),\n ],\n [\n 'id' => 'share_teams',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'label' => 'Team',\n 'required' => false,\n 'placeholder' => 'Select',\n 'options' => $teamGroups,\n 'value' => $sharedTeamsValue,\n ],\n [\n 'id' => 'share_users',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'label' => 'Team member',\n 'required' => false,\n 'placeholder' => 'Select',\n 'groupLabelKey' => 'label',\n 'groupValuesKey' => 'users',\n 'optionLabelKey' => 'name',\n 'optionValueKey' => 'id',\n 'options' => $shareUsers,\n 'value' => $sharedUsersValue,\n ],\n [\n 'id' => 'saved_search',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'label' => 'Saved search',\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => $savedSearches,\n 'value' => $report && $report->getSavedSearch() ? [\n 'id' => $report->getSavedSearch()->getUuid(),\n 'name' => $report->getSavedSearch()->getName(),\n ] : null,\n ],\n [\n 'id' => 'ask_jiminny_prompt',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'label' => 'Ask Jiminny prompt',\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => $prompts,\n 'value' => $report && $report->getAskAnythingPrompt() ? [\n 'id' => $report->getAskAnythingPrompt()->getUuid(),\n 'name' => $report->getAskAnythingPrompt()->getTitle(),\n ] : null,\n ],\n ],\n ];\n }\n\n private function updateResultNames(AutomatedReport $automatedReport): void\n {\n $results = $this->automatedReportsRepository->getResultsByReport($automatedReport);\n\n foreach ($results as $result) {\n $result->update(['name' => $this->getReportFileName($result)]);\n }\n }\n\n public function updateStatus(string $uuid, array $data): array\n {\n $automatedReport = $this->automatedReportsRepository->findByUuid($uuid);\n\n if (! $automatedReport) {\n throw new ModelNotFoundException('Report not found');\n }\n\n $status = $this->validateReportStatus($data['report_enabled'] ?? null);\n $automatedReport->update([\n 'status' => $status,\n ]);\n\n $this->generateOneOffReport($automatedReport);\n\n return $this->transformReportFullView($automatedReport);\n }\n\n private function generateOneOffReport(AutomatedReport $automatedReport): void\n {\n // the scheduler handles all the other frequency types\n if ($automatedReport->getStatus() === false || $automatedReport->getFrequency() !== self::FREQUENCY_ONE_OFF) {\n return;\n }\n\n $this->dispatcher->dispatch(new RequestGenerateReportJob($automatedReport->getUuid()));\n }\n\n public function getReport(string $uuid): AutomatedReport\n {\n $automatedReport = $this->automatedReportsRepository->findByUuid($uuid);\n\n if (! $automatedReport) {\n throw new ModelNotFoundException('Report not found');\n }\n\n return $automatedReport;\n }\n\n public function get(string $uuid): array\n {\n $automatedReport = $this->getReport($uuid);\n\n return $this->transformReportFullView($automatedReport);\n }\n\n public function list(string $sortColumn = 'created_at', string $sortDirection = 'desc'): array\n {\n $results = [];\n $collection = $this->automatedReportsRepository->getAllStandardReports($sortColumn, $sortDirection);\n\n /** @var AutomatedReport $report */\n foreach ($collection as $report) {\n $results[] = $this->transformReportFullView($report);\n }\n\n return ['data' => $results];\n }\n\n public function listAskJiminnyReports(\n User $user,\n string $sortColumn = 'created_at',\n string $sortDirection = 'desc'\n ): array {\n $results = [];\n $collection = $this->automatedReportsRepository->getAskJiminnyReportsByUser($user, $sortColumn, $sortDirection);\n\n /** @var AutomatedReport $report */\n foreach ($collection as $report) {\n $results[] = $this->transformReportFullView($report);\n }\n\n return ['data' => $results];\n }\n\n public function delete(string $uuid): void\n {\n $automatedReport = $this->automatedReportsRepository->findByUuid($uuid);\n\n if (! $automatedReport) {\n throw new ModelNotFoundException('Report not found');\n }\n\n $automatedReport->delete();\n }\n\n public function createReportResult(AutomatedReport $automatedReport, array $data = []): AutomatedReportResult\n {\n return $this->automatedReportsRepository->createResult(\n array_merge(\n [\n 'report_id' => $automatedReport->getId(),\n 'status' => AutomatedReportResult::STATUS_DEFAULT,\n ],\n $data\n )\n );\n }\n\n public function getReportResult(string $resultUuid): AutomatedReportResult\n {\n $report = $this->automatedReportsRepository->findResultByUuid($resultUuid);\n\n if (! $report) {\n throw new ModelNotFoundException('Report Result not found');\n }\n\n return $report;\n }\n\n public function findChildResult(AutomatedReportResult $result, string $type): ?AutomatedReportResult\n {\n return $this->automatedReportsRepository->findChildResult($result, $type);\n }\n\n // prophet API calls\n /**\n * @throws ApplicationException\n */\n public function getGenerateReportPayload(AutomatedReport $automatedReport, string $reportResultUuid): array\n {\n $period = $this->calculateFromAndToDate($automatedReport);\n $fromDate = $period['fromDate'];\n $toDate = $period['toDate'];\n\n return [\n 'team_id' => $automatedReport->getTeamId(),\n 'request_id' => $reportResultUuid,\n 'report_type' => $automatedReport->getType(),\n 'media_types' => $automatedReport->getMediaTypes(),\n 'from_date' => $fromDate->startOfDay()->format(DateTimeInterface::RFC3339),\n 'to_date' => $toDate->endOfDay()->format(DateTimeInterface::RFC3339),\n 'group_ids' => $automatedReport->getGroups(),\n 'call_deal_stage' => $automatedReport->getDealAtCallStages(),\n 'current_deal_stage' => $automatedReport->getCurrentDealStages(),\n 'deal_min_value' => $automatedReport->getDealValueMin(),\n 'deal_max_value' => $automatedReport->getDealValueMax(),\n 'call_types' => $automatedReport->getCallTypes(),\n 'call_duration_min_seconds' => $automatedReport->getCallDurationMin(),\n 'call_duration_max_seconds' => $automatedReport->getCallDurationMax(),\n 'special_requirements' => $automatedReport->getAdditionalPromptInput(),\n 'callback_url' => $this->getCallbackUrl(),\n 'report_period' => $this->formatReportPeriodName(\n $automatedReport->getFrequency(),\n $fromDate,\n $toDate,\n ),\n 'playbook_categories' => $automatedReport->getPlaybookCategories(),\n 'custom_name' => $automatedReport->getCustomName(),\n ];\n }\n\n // $inputPayload - FE payload structure\n public function getActivitiesCountPayload(array $inputPayload): array\n {\n // Use validateAndTransformData to validate and normalize input\n $validatedData = $this->validateAndTransformData($inputPayload);\n $period = $this->calculateFromAndToDatePeriod(\n $validatedData['frequency'],\n Carbon::parse($validatedData['from']),\n Carbon::parse($validatedData['to']),\n );\n $fromDate = $period['fromDate'];\n $toDate = $period['toDate'];\n\n // Create payload similar to getGenerateReportPayload\n return [\n 'team_id' => $validatedData['team_id'],\n 'group_ids' => $validatedData['groups'] ?? [],\n 'report_type' => $validatedData['type'],\n 'from_date' => $fromDate->format(DateTimeInterface::RFC3339),\n 'to_date' => $toDate->format(DateTimeInterface::RFC3339),\n 'call_deal_stage' => $validatedData['deal_at_call_stages'] ?? [],\n 'current_deal_stage' => $validatedData['current_deal_stages'] ?? [],\n 'deal_min_value' => $validatedData['deal_value_min'] ?? null,\n 'deal_max_value' => $validatedData['deal_value_max'] ?? null,\n 'call_types' => $validatedData['call_types'],\n 'call_duration_min_seconds' => $validatedData['call_duration_min'] ?? null,\n 'call_duration_max_seconds' => $validatedData['call_duration_max'] ?? null,\n 'special_requirements' => $validatedData['additional_prompt_input'] ?? null,\n 'playbook_categories' => $validatedData['playbook_categories'] ?? [],\n 'request_id' => null,\n 'callback_url' => null,\n ];\n }\n\n public function shouldSendReport(array $users, ?CarbonInterface $generatedAt = null): bool\n {\n if (empty($users)) {\n return false;\n }\n\n $earliestTz = collect($users)\n ->mapWithKeys(function (array $user) {\n $tz = new DateTimeZone($user['timezone']);\n $nowUtc = new DateTime('now', new DateTimeZone('UTC'));\n $offset = $tz->getOffset($nowUtc);\n\n return [$user['timezone'] => $offset];\n })\n ->sortDesc()\n ->keys()\n ->first();\n\n $now = Carbon::now($earliestTz);\n $isScheduledTime = (int) $now->format('H') === self::SENT_REPORT_AT_HOURS;\n\n if ($isScheduledTime) {\n return true;\n }\n\n return $this->hasPassedScheduledTime($generatedAt, $earliestTz);\n }\n\n public function hasPassedScheduledTime(?CarbonInterface $generatedAt, string $timezone): bool\n {\n if ($generatedAt === null) {\n return false;\n }\n\n $now = Carbon::now($timezone);\n $scheduledTime = $now->copy()->setTime(self::SENT_REPORT_AT_HOURS, 0, 0);\n\n if ($now->hour < self::SENT_REPORT_AT_HOURS) {\n $scheduledTime = $scheduledTime->subDay();\n }\n\n $scheduledTimeUtc = $scheduledTime->copy()->utc();\n $generatedAtUtc = $generatedAt->copy()->utc();\n $nowUtc = $now->copy()->utc();\n\n return $generatedAtUtc->lt($scheduledTimeUtc) && $nowUtc->gt($scheduledTimeUtc);\n }\n\n public function calculateFromAndToDatePeriod(\n string $frequency,\n ?Carbon $fromDate = null,\n ?Carbon $toDate = null\n ): array {\n if ($frequency === self::FREQUENCY_ONE_OFF) {\n return [\n 'fromDate' => $fromDate,\n 'toDate' => $toDate,\n ];\n }\n\n $now = Carbon::now();\n\n return match ($frequency) {\n self::FREQUENCY_DAILY => [\n 'fromDate' => $now->copy()->subDay()->startOfDay(),\n 'toDate' => $now->copy()->subDay()->endOfDay(),\n ],\n self::FREQUENCY_WEEKLY => [\n 'fromDate' => $now->copy()->subWeeks(1)->startOfDay(),\n 'toDate' => $now->copy()->subDay()->endOfDay(),\n ],\n self::FREQUENCY_MONTHLY => [\n 'fromDate' => $now->copy()->subMonths(1)->startOfDay(),\n 'toDate' => $now->copy()->subDay()->endOfDay(),\n ],\n self::FREQUENCY_QUARTERLY => [\n 'fromDate' => $now->copy()->subMonths(3)->startOfDay(),\n 'toDate' => $now->copy()->subDay()->endOfDay(),\n ],\n default => throw new InvalidArgumentException(\"Unsupported frequency: {$frequency}\"),\n };\n }\n\n private function calculateFromAndToDate(AutomatedReport $automatedReport): array\n {\n return $this->calculateFromAndToDatePeriod(\n $automatedReport->getFrequency(),\n $automatedReport->getFrom(),\n $automatedReport->getTo()\n );\n }\n\n public function getAskJiminnyGenerateReportPayload(\n AutomatedReport $automatedReport,\n AutomatedReportResult $reportResult,\n array $activityIds,\n ): array {\n return [\n 'user_question' => $automatedReport->getAskAnythingPrompt()?->getContent(),\n 'call_ids' => array_map('strval', $activityIds),\n 'team_id' => $automatedReport->getTeamId(),\n 'request_id' => $reportResult->getUuid(),\n 'callback_url' => $this->getCallbackUrl(),\n 'report_period' => $this->getReportPeriodName($reportResult),\n 'report_name' => $automatedReport->getCustomName(),\n ];\n }\n\n private function getCallbackUrl(): string\n {\n return $this->webhookService->route('jiminny.webhook.reports.ready');\n }\n\n /**\n * Validate and transform payload data for automated reports\n *\n * @param array $data\n *\n * @throws InvalidArgumentException\n *\n * @return array\n */\n private function validateAndTransformData(array $data): array\n {\n // Validate organization (team) and check feature\n $team = $this->validateOrganization($data['organization'] ?? null);\n\n $status = $this->validateReportStatus($data['report_enabled'] ?? null);\n $type = $this->validateReportType($data['report_type'] ?? null);\n $frequency = $this->validateFrequency($data['frequency'] ?? null);\n $additionalPromptInput = $this->validateAdditionalPromptInput(\n $data['additional_prompt_input'] ?? null\n );\n $customReportName = $this->validateCustomReportName($data['custom_name'] ?? null);\n\n // Prepare data for the database\n $reportData = [\n 'team_id' => $team->getId(),\n 'type' => $type,\n 'status' => $status,\n 'frequency' => $frequency,\n 'additional_prompt_input' => $additionalPromptInput,\n 'custom_name' => $customReportName,\n ];\n\n // Validate deal values\n $reportData = $this->validateDealValues($data, $reportData);\n\n // Validate date range\n $reportData = $this->validateDateRange($data, $reportData, $frequency);\n\n // Validate call durations\n $reportData = $this->validateCallDurations($data, $reportData);\n\n // Validate call types\n $reportData = $this->validateCallTypes($data, $reportData);\n\n // Validate media types\n $reportData = $this->validateMediaTypes($data, $reportData);\n\n // Validate groups\n if (isset($data['teams'])) {\n $reportData['groups'] = $this->validateAndGetGroupIds($team, $data['teams']);\n }\n\n // Validate deal stages\n $reportData = $this->validateDealStages($data, $reportData, $team, $type);\n\n // Validate playbook categories\n $reportData = $this->validatePlaybookCategories($data, $reportData, $team);\n\n // Validate recipients\n $reportData['recipients'] = [\n 'users' => $this->validateAndGetUserIdsByTeam($team, $data['recipients'] ?? []),\n ];\n\n if (isset($data['jiminny_recipients'])) {\n // Validate Jiminny recipients\n $reportData['jiminny_recipients'] = [\n 'users' => $this->validateAndGetJiminnyUserIds((array) $data['jiminny_recipients']),\n ];\n }\n\n return $reportData;\n }\n\n private function validateDealValues(array $data, array $reportData): array\n {\n if (isset($data['min_deal_value'])) {\n $reportData['deal_value_min'] = (int) $data['min_deal_value'];\n\n if ($reportData['deal_value_min'] > 4294967295 || $reportData['deal_value_min'] < 0) {\n throw new InvalidArgumentException('Min deal value should be between 0 and 4294967295');\n }\n }\n\n if (isset($data['max_deal_value'])) {\n $reportData['deal_value_max'] = (int) $data['max_deal_value'];\n\n if ($reportData['deal_value_max'] > 4294967295 || $reportData['deal_value_max'] < 0) {\n throw new InvalidArgumentException('Max deal value should be between 0 and 4294967295');\n }\n }\n\n if (isset($data['min_deal_value'], $data['max_deal_value'])\n && $data['min_deal_value'] > $data['max_deal_value']\n ) {\n throw new InvalidArgumentException('Min deal value cannot be greater than max deal value');\n }\n\n return $reportData;\n }\n\n private function validateDateRange(array $data, array $reportData, string $frequency): array\n {\n // Set date range only for one_off frequency\n if ($frequency === 'one_off') {\n if (isset($data['start_date_period'])) {\n $reportData['from'] = $this->parseDate($data['start_date_period']);\n }\n\n if (isset($data['end_date_period'])) {\n $reportData['to'] = $this->parseDate($data['end_date_period']);\n }\n\n if (empty($reportData['from']) || empty($reportData['to'])) {\n throw new InvalidArgumentException(\n 'Start date and end date are required for one_off frequency'\n );\n }\n } else {\n $reportData['from'] = null;\n $reportData['to'] = null;\n }\n\n return $reportData;\n }\n\n private function validateCallDurations(array $data, array $reportData): array\n {\n // Convert call durations from minutes to seconds\n if (isset($data['min_call_duration'])) {\n $reportData['call_duration_min'] = (int) $data['min_call_duration'] * 60;\n\n if ($reportData['call_duration_min'] > 4294967295 || $reportData['call_duration_min'] < 0) {\n throw new InvalidArgumentException('Min call duration should be between 0 and 4294967295');\n }\n }\n\n if (isset($data['max_call_duration'])) {\n $reportData['call_duration_max'] = (int) $data['max_call_duration'] * 60;\n\n if ($reportData['call_duration_max'] > 4294967295 || $reportData['call_duration_max'] < 0) {\n throw new InvalidArgumentException('Max call duration should be between 0 and 4294967295');\n }\n }\n\n return $reportData;\n }\n\n private function validateCallTypes(array $data, array $reportData): array\n {\n // Set call types\n $reportData['call_types'] = $data['call_type'] ?? [];\n if (empty($reportData['call_types'])) {\n $reportData['call_types'] = self::getCallTypes();\n }\n\n foreach ($reportData['call_types'] as $callType) {\n if (! in_array($callType, self::getCallTypes(), true)) {\n throw new InvalidArgumentException(sprintf('Call type %s is invalid', $callType));\n }\n }\n\n return $reportData;\n }\n\n private function validateMediaTypes(array $data, array $reportData): array\n {\n // Set media types from input data\n $reportData['media_types'] = $data['media_types'] ?? [];\n\n if (empty($reportData['media_types'])) {\n throw new InvalidArgumentException('Media types are required');\n }\n\n foreach ($reportData['media_types'] as $mediaType) {\n if (! in_array($mediaType, self::MEDIA_TYPES, true)) {\n throw new InvalidArgumentException(sprintf('Media type %s is invalid', $mediaType));\n }\n }\n\n return $reportData;\n }\n\n private function validateDealStages(array $data, array $reportData, Team $team, string $reportType): array\n {\n // Validate and set deal stages\n if (isset($data['deal_stage_at_call'])) {\n $reportData['deal_at_call_stages'] =\n $this->validateAndGetDealStageIds($team, $data['deal_stage_at_call'], 'Deal stage at call');\n }\n\n if (isset($data['current_deal_stage'])) {\n $reportData['current_deal_stages'] =\n $this->validateAndGetDealStageIds($team, $data['current_deal_stage'], 'Current deal stage');\n }\n\n // Ensure current_deal_stage is not provided for loss_analysis report type\n if ($reportType === self::TYPE_LOSS_ANALYSIS && ! empty($data['current_deal_stage'])) {\n throw new InvalidArgumentException('Current deal stage is not applicable for Loss Analysis reports');\n }\n\n return $reportData;\n }\n\n // transform uuid to id\n private function validatePlaybookCategories(array $data, array $reportData, Team $team): array\n {\n $key = 'playbook_categories';\n\n if (isset($data[$key])) {\n $payloadIds = $data[$key];\n $ids = [];\n\n foreach ($payloadIds as $uuid) {\n $uuid = (string) $uuid;\n\n try {\n $playbookCategory = $this->playbookCategoryRepository->findByUuid($uuid);\n } catch (Throwable $throwable) {\n Log::error(__METHOD__ . ' ' . $throwable->getMessage());\n\n throw new InvalidArgumentException(sprintf('Playbook category %s not found', $uuid));\n }\n\n if (! $playbookCategory) {\n throw new InvalidArgumentException(sprintf('Playbook category %s not found', $uuid));\n }\n\n if (! $playbookCategory->hasPlaybook()) {\n throw new InvalidArgumentException(sprintf('Playbook category %s has no playbook', $uuid));\n }\n\n if ($playbookCategory->getPlaybook()->getTeamId() !== $team->getId()) {\n throw new InvalidArgumentException(\n sprintf('Playbook category %s not found for team %s', $uuid, $team->getUuid())\n );\n }\n\n $ids[] = $playbookCategory->getId();\n }\n\n $reportData[$key] = $ids;\n }\n\n return $reportData;\n }\n\n private function validateReportStatus($status): bool\n {\n if (! in_array($status, [true, false], true)) {\n throw new InvalidArgumentException('Report status is invalid');\n }\n\n return $status;\n }\n\n private function validateReportType($type): string\n {\n if (! in_array($type, self::getTypes(), true)) {\n throw new InvalidArgumentException(sprintf('Report type is invalid: %s', $type));\n }\n\n return $type;\n }\n\n private function validateFrequency($frequency): string\n {\n if (! in_array($frequency, self::getFrequencies(), true)) {\n throw new InvalidArgumentException('Frequency is invalid');\n }\n\n return $frequency;\n }\n\n private function validateAdditionalPromptInput(?string $additionalPromptInput): ?string\n {\n if ($additionalPromptInput && strlen($additionalPromptInput) > 5000) {\n throw new InvalidArgumentException('Additional Prompt Input should be less than 5000 characters');\n }\n\n return $additionalPromptInput;\n }\n\n private function validateCustomReportName(?string $customReportName): ?string\n {\n if ($customReportName === null || $customReportName === '') {\n return null;\n }\n\n if (strlen($customReportName) > 70) {\n throw new InvalidArgumentException('Custom report name should be less than 70 characters');\n }\n\n return $customReportName;\n }\n\n private function validateOrganization(?string $organizationUuid): Team\n {\n if (! $organizationUuid) {\n throw new InvalidArgumentException('Organization is required');\n }\n\n $team = $this->teamRepository->idOrUuid($organizationUuid);\n\n if (! $team) {\n throw new InvalidArgumentException('Organization not found');\n }\n\n if (! $team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {\n throw new InvalidArgumentException('Organization does not have the Automated Reports feature');\n }\n\n return $team;\n }\n\n private function validateAndGetGroupIds(Team $team, array $teamUuids): array\n {\n $groupIds = [];\n\n foreach ($teamUuids as $uuid) {\n $group = $this->groupRepository->findByUuid($uuid);\n\n if ($group === null || $group->getTeamId() !== $team->getId()) {\n throw new InvalidArgumentException(\n sprintf('Group %s not found for team %s', $uuid, $team->getUuid())\n );\n }\n\n $groupIds[] = $group->getId();\n\n }\n\n return $groupIds;\n }\n\n private function validateAndGetDealStageIds(Team $team, array $stageUuids, string $propertyLabel): array\n {\n $stageIds = [];\n\n foreach ($stageUuids as $uuid) {\n $stage = $this->stageRepository->findByUuid($uuid);\n\n if ($stage === null || $stage->getTeamId() !== $team->getId()) {\n throw new InvalidArgumentException(\n sprintf('Stage %s not found for team %s for %s', $uuid, $team->getUuid(), $propertyLabel)\n );\n }\n\n $stageIds[] = $stage->getId();\n }\n\n return $stageIds;\n }\n\n private function validateAndGetUserIds(array $userUuids, callable $teamCheck): array\n {\n if (empty($userUuids)) {\n return [];\n }\n\n $userIds = [];\n\n foreach ($userUuids as $uuid) {\n $user = $this->userRepository->findByUuid($uuid);\n\n if (! $user || ! $user->isStatusActive()) {\n throw new InvalidArgumentException(\n sprintf('User %s not found or is not active', $uuid)\n );\n }\n\n if (! $teamCheck($user)) {\n throw new InvalidArgumentException(\n sprintf('User %s does not belong to the allowed team(s)', $uuid)\n );\n }\n\n $userIds[] = $user->getId();\n }\n\n return $userIds;\n }\n\n private function validateAndGetUserIdsByTeam(Team $team, array $userUuids): array\n {\n return $this->validateAndGetUserIds($userUuids, fn ($user) => $user->getTeamId() === $team->getId());\n }\n\n private function validateAndGetJiminnyUserIds(array $userUuids): array\n {\n $allowedTeamIds = config('kiosk.teamIds', []);\n\n return $this->validateAndGetUserIds($userUuids, fn ($user) => in_array($user->getTeamId(), $allowedTeamIds, true));\n }\n\n private function parseDate(string $dateString): string\n {\n return date('Y-m-d H:i:s', strtotime($dateString));\n }\n\n private function generateReportResultViewUrl(AutomatedReportResult $result): string\n {\n $mediaResource = $this->getReportMediaRouteResource($result);\n\n return route('ai-reports.' . $mediaResource . '.view', ['uuid' => $result->getUuid()]);\n }\n\n private function generateReportResultDownloadUrl(AutomatedReportResult $result): string\n {\n $mediaResource = $this->getReportMediaRouteResource($result);\n\n return route('ai-reports.' . $mediaResource . '.download', ['uuid' => $result->getUuid()]);\n }\n\n private function getReportMediaRouteResource(AutomatedReportResult $result): string\n {\n if ($result->getMediaType() === self::MEDIA_TYPE_PDF) {\n return self::PDF_KEY;\n } elseif ($result->getMediaType() === self::MEDIA_TYPE_PODCAST) {\n return self::AUDIO_KEY;\n }\n\n throw new \\InvalidArgumentException('Unknown media type.');\n }\n\n public function getMediaPath(AutomatedReportResult $result): ?string\n {\n $url = match ($result->getMediaType()) {\n self::MEDIA_TYPE_PDF => $result->getPdfUrl(),\n self::MEDIA_TYPE_PODCAST => $result->getPodcastAudioUrl(),\n default => null,\n };\n\n if ($url === null) {\n return null;\n }\n\n $path = parse_url(trim($url, '\"\\''), PHP_URL_PATH);\n\n return $path ?: null;\n }\n\n public function getFilenameSuffix(AutomatedReportResult $result): ?string\n {\n return match ($result->getMediaType()) {\n self::MEDIA_TYPE_PODCAST => 'Podcast',\n default => null,\n };\n }\n\n public function getMailSubjectSuffix(AutomatedReportResult $result): string\n {\n return match ($result->getMediaType()) {\n self::MEDIA_TYPE_PDF => 'report',\n self::MEDIA_TYPE_PODCAST => 'podcast',\n default => '',\n };\n }\n\n public function getMediaTypeMetadata(AutomatedReportResult $result): array\n {\n return match ($result->getMediaType()) {\n self::MEDIA_TYPE_PODCAST => ['extension' => 'mp3', 'mime' => 'audio/mpeg'],\n self::MEDIA_TYPE_PDF => ['extension' => 'pdf', 'mime' => 'application/pdf'],\n default => ['extension' => null, 'mime' => null],\n };\n }\n\n public function deleteS3Files(AutomatedReportResult $result): void\n {\n $teamUuid = $result->getReport()->getTeam()->getUuid();\n $reportUuid = $result->getUuid();\n\n // delete all files for a report uuid no mather of pdf, podcast, or both\n // in case of both - the podcast files are linked to the pdf (parent) uuid\n // pdf and podcast date times should be close\n $path = sprintf('%s/%s/%s', $teamUuid, self::S3_DIR, $reportUuid);\n\n foreach (self::FILE_EXTENSIONS_VARIANTS as $extension) {\n $file = $path . '.' . $extension;\n\n if (Storage::exists($file)) {\n Storage::delete($file);\n Log::info('[Reports] Deleted S3 file', [\n 'path' => $file,\n ]);\n }\n }\n\n foreach (self::FILE_PODCAST_EXTENSIONS_VARIANTS as $extension) {\n $file = $path . '_podcast.' . $extension;\n\n if (Storage::exists($file)) {\n Storage::delete($file);\n Log::info('[Reports] Deleted Podcast S3 file', [\n 'path' => $file,\n ]);\n }\n }\n }\n\n /**\n *\n * @param int|null $teamId Optional team ID to filter results\n *\n * @return Collection<int, int> Collection of team IDs\n */\n public function getTeamIdsWithReportsResults(?int $teamId = null): Collection\n {\n return $this->automatedReportsRepository->getTeamIdsWithReportsResults($teamId);\n }\n\n /**\n * Core delete logic for report results using a query\n *\n * @param Builder $query\n * @param array $logContext\n *\n * @return int\n */\n private function deleteReportResultsByQuery(Builder $query, array $logContext = []): int\n {\n $deletedCount = 0;\n\n if ($query->exists()) {\n Log::info(\n 'Run delete report results',\n array_merge(\n $logContext,\n [\n 'service' => 'AutomatedReportsService',\n ]\n )\n );\n\n $query->chunkById(50, function ($results) use (&$deletedCount, $logContext) {\n foreach ($results as $result) {\n $this->deleteReportResult($result);\n $deletedCount++;\n\n Log::info(\n 'Deleted a report result',\n array_merge(\n $logContext,\n [\n 'result_id' => $result->getId(),\n 'report_id' => $result->getReportId(),\n ]\n )\n );\n }\n });\n }\n\n return $deletedCount;\n }\n\n /**\n * Delete report results for a team by retention period\n *\n * @param Team $team\n * @param CarbonImmutable $retentionDate\n *\n * @return int Number of deleted report results\n */\n public function deleteReportsResultsInRetentionPeriod(Team $team, CarbonImmutable $retentionDate): int\n {\n $reportIds = $this->automatedReportsRepository->getReportIdsByTeam($team);\n\n if ($reportIds->isEmpty()) {\n return 0;\n }\n\n $query = $this->automatedReportsRepository\n ->getReportResultsQueryForRetention($team, $retentionDate);\n\n return $this->deleteReportResultsByQuery($query, [\n 'team_id' => $team->getId(),\n 'retention_date' => $retentionDate->toDateTimeString(),\n ]);\n }\n\n /**\n * Delete ALL report results for a specific automated report\n *\n * @param string $uuid\n *\n * @return int\n */\n public function deleteReportResults(string $uuid): int\n {\n $report = $this->getReport($uuid);\n\n $query = $this->automatedReportsRepository->getResultsByReportQuery($report);\n\n return $this->deleteReportResultsByQuery($query, [\n 'report_uuid' => $uuid,\n 'report_id' => $report->getId(),\n ]);\n }\n\n public function deleteReportResult(AutomatedReportResult $result): void\n {\n $this->deleteS3Files($result);\n\n $result->delete();\n }\n\n /**\n * Get all reports for a specific team\n *\n * @param Team $team\n *\n * @return \\Illuminate\\Database\\Eloquent\\Collection\n */\n public function getTeamReports(Team $team): \\Illuminate\\Database\\Eloquent\\Collection\n {\n return $this->automatedReportsRepository->getReportsByTeam($team);\n }\n\n /**\n * Get all report results for a specific report\n *\n * @param AutomatedReport $report\n *\n * @return \\Illuminate\\Database\\Eloquent\\Collection\n */\n public function getReportResults(AutomatedReport $report): \\Illuminate\\Database\\Eloquent\\Collection\n {\n return $this->automatedReportsRepository->getResultsByReport($report);\n }\n\n public function deleteAllReportResults(AutomatedReport $report): void\n {\n $results = $this->getReportResults($report);\n\n /** @var AutomatedReportResult $result */\n foreach ($results as $result) {\n Log::info('Deleting result', [\n 'report' => $report->getId(),\n 'result' => $result->getId(),\n ]);\n\n $this->deleteReportResult($result);\n }\n }\n\n public function deleteAllData(Team $team): void\n {\n Log::info('Deleting automated report and results for team', [\n 'team' => $team->getId(),\n ]);\n\n $reports = $this->getTeamReports($team);\n\n /** @var AutomatedReport $report */\n foreach ($reports as $report) {\n Log::info('Deleting report', [\n 'team' => $team->getId(),\n 'report' => $report->getId(),\n ]);\n\n $this->deleteAllReportResults($report);\n\n $report->delete();\n }\n }\n}","depth":4,"value":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Services\\Kiosk\\AutomatedReports;\n\nuse Carbon\\CarbonImmutable;\nuse Carbon\\CarbonInterface;\nuse Carbon\\Exceptions\\InvalidFormatException;\nuse DateTime;\nuse DateTimeInterface;\nuse DateTimeZone;\nuse Illuminate\\Contracts\\Bus\\Dispatcher as BusDispatcher;\nuse Illuminate\\Database\\Eloquent\\Builder;\nuse Illuminate\\Support\\Carbon;\nuse Illuminate\\Support\\Collection;\nuse Illuminate\\Support\\Facades\\Log;\nuse Illuminate\\Support\\Facades\\Storage;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinition\\InputTypeEnum;\nuse Jiminny\\Component\\AskAnything\\AskAnythingPromptService;\nuse Jiminny\\Component\\AskAnything\\Dtos\\AskAnythingPromptDto;\nuse Jiminny\\Component\\UrlGenerator\\Webhook;\nuse Jiminny\\Contracts\\Repositories\\PlaybookCategoryRepository;\nuse Jiminny\\Contracts\\Repositories\\TeamRepository;\nuse Jiminny\\Contracts\\Repositories\\UserRepository;\nuse Jiminny\\Exceptions\\ApplicationException;\nuse Jiminny\\Exceptions\\InvalidArgumentException;\nuse Jiminny\\Exceptions\\ModelNotFoundException;\nuse Jiminny\\Jobs\\AutomatedReports\\RequestGenerateReportJob;\nuse Jiminny\\Models\\Activity\\Search;\nuse Jiminny\\Models\\AskAnything\\AskAnythingPrompt;\nuse Jiminny\\Models\\AskAnything\\AskAnythingPromptTarget;\nuse Jiminny\\Models\\AutomatedReport;\nuse Jiminny\\Models\\AutomatedReportResult;\nuse Jiminny\\Models\\Contracts\\UserContract;\nuse Jiminny\\Models\\Feature\\FeatureEnum;\nuse Jiminny\\Models\\Team;\nuse Jiminny\\Models\\User;\nuse Jiminny\\Repositories\\AskAnythingRepository;\nuse Jiminny\\Repositories\\AutomatedReportsRepository;\nuse Jiminny\\Repositories\\GroupRepository;\nuse Jiminny\\Repositories\\SearchRepository;\nuse Jiminny\\Repositories\\StageRepository;\nuse Throwable;\n\nclass AutomatedReportsService\n{\n public const string TYPE_LOSS_ANALYSIS = 'loss_analysis';\n public const string TYPE_ASK_JIMINNY = 'ask_jiminny';\n\n /**\n * Standard report types (used by kiosk for existing automated reports).\n */\n // @TODO this will add filter, however if we need to control feature by FF we need conditional logic\n public const array TYPES = [\n ['id' => 'exec_summary', 'name' => 'Exec Summary'],\n ['id' => 'coaching_profiles', 'name' => 'Coaching Profiles'],\n ['id' => 'product_feedback', 'name' => 'Product Feedback'],\n ['id' => self::TYPE_LOSS_ANALYSIS, 'name' => 'Loss Analysis'],\n// ['id' => 'questions', 'name' => 'Questions'],\n// ['id' => 'statistical_quant', 'name' => 'Statistical Quantitative'],\n ];\n\n public const array ALL_TYPES = [\n ...self::TYPES,\n ['id' => self::TYPE_ASK_JIMINNY, 'name' => 'Ask Jiminny'],\n ];\n\n public const string FREQUENCY_DAILY = 'daily';\n public const string FREQUENCY_WEEKLY = 'weekly';\n public const string FREQUENCY_MONTHLY = 'monthly';\n public const string FREQUENCY_QUARTERLY = 'quarterly';\n public const string FREQUENCY_ONE_OFF = 'one_off';\n\n /**\n * Frequencies for standard (non-Ask Jiminny) reports.\n */\n public const array FREQUENCIES = [\n ['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],\n ['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],\n ['id' => self::FREQUENCY_QUARTERLY, 'name' => 'Quarterly'],\n ['id' => self::FREQUENCY_ONE_OFF, 'name' => 'One-off'],\n ];\n\n /**\n * Frequencies for Ask Jiminny reports.\n */\n public const array ASK_JIMINNY_FREQUENCIES = [\n ['id' => self::FREQUENCY_DAILY, 'name' => 'Daily'],\n ['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],\n ['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],\n ];\n\n public const string MEDIA_TYPE_PDF = 'pdf';\n public const string MEDIA_TYPE_PODCAST = 'podcast';\n public const array MEDIA_TYPES = [self::MEDIA_TYPE_PDF, self::MEDIA_TYPE_PODCAST];\n public const array MEDIA_TYPE_OBJECT_PDF = ['id' => self::MEDIA_TYPE_PDF, 'name' => 'PDF'];\n public const array MEDIA_TYPE_OBJECT_PODCAST = ['id' => self::MEDIA_TYPE_PODCAST, 'name' => 'Podcast'];\n public const array MEDIA_TYPE_OBJECTS = [self::MEDIA_TYPE_OBJECT_PDF, self::MEDIA_TYPE_OBJECT_PODCAST];\n\n public const array CALL_TYPE_CONFERENCE = ['id' => 'conference', 'name' => 'Conference'];\n public const array CALL_TYPE_DIALER = ['id' => 'dialer', 'name' => 'Dialer'];\n public const int SENT_REPORT_AT_HOURS = 5;\n public const string PDF_KEY = 'pdf';\n public const string AUDIO_KEY = 'audio';\n\n private const array ALL_FREQUENCIES = [\n ['id' => self::FREQUENCY_DAILY, 'name' => 'Daily'],\n ['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],\n ['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],\n ['id' => self::FREQUENCY_QUARTERLY, 'name' => 'Quarterly'],\n ['id' => self::FREQUENCY_ONE_OFF, 'name' => 'One-off'],\n ];\n private const string S3_DIR = 'reports';\n private const array FILE_EXTENSIONS_VARIANTS = ['html', 'MD', 'pdf'];\n private const array FILE_PODCAST_EXTENSIONS_VARIANTS = ['json', 'mp3', 'ssml'];\n\n public function __construct(\n private readonly TeamRepository $teamRepository,\n private readonly GroupRepository $groupRepository,\n private readonly UserRepository $userRepository,\n private readonly StageRepository $stageRepository,\n private readonly DealStagesService $dealStagesService,\n private readonly RecipientsService $recipientsService,\n private readonly AutomatedReportsRepository $automatedReportsRepository,\n private readonly Webhook $webhookService,\n private readonly BusDispatcher $dispatcher,\n private readonly ActivityTypeService $activityTypeService,\n private readonly PlaybookCategoryRepository $playbookCategoryRepository,\n private readonly AskAnythingPromptService $askAnythingPromptService,\n private readonly SearchRepository $activitySearchRepository,\n private readonly AskAnythingRepository $askAnythingRepository,\n ) {\n }\n\n public static function getTypes(): array\n {\n $types = self::TYPES;\n\n return array_map(static function ($type) {\n return $type['id'];\n }, $types);\n }\n\n public static function getCallTypes(): array\n {\n return array_map(static function ($callType) {\n return $callType['id'];\n }, [self::CALL_TYPE_CONFERENCE, self::CALL_TYPE_DIALER]);\n }\n\n public static function getFrequencies(): array\n {\n return array_map(static function ($frequency) {\n return $frequency['id'];\n }, self::FREQUENCIES);\n }\n\n // front-facing structure\n public function getReportEnabledFieldData(bool $value = false): array\n {\n return [\n 'id' => 'report_enabled',\n 'label' => '',\n 'inputType' => InputTypeEnum::TOGGLE,\n 'value' => $value,\n ];\n }\n\n // Organizations = Teams\n public function getOrganizationFieldData(?string $value = null, bool $shortVersion = false): array\n {\n $options = $this->getTeams();\n\n if ($shortVersion) {\n return [\n 'id' => 'organization',\n 'label' => 'Organization',\n 'options' => $options,\n ];\n }\n\n return [\n 'id' => 'organization',\n 'label' => 'Organization',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => $options,\n 'value' => $value,\n 'dependencies' => [\n 'teams',\n 'deal_stage_at_call',\n 'current_deal_stage',\n 'recipients',\n ActivityTypeService::PLAYBOOK_CATEGORIES_KEY,\n ],\n 'dependsOn' => [],\n ];\n }\n\n // Teams = Groups\n public function getTeamFieldData(array $options = [], array $value = [], bool $shortVersion = false): array\n {\n if ($shortVersion) {\n return [\n 'id' => 'teams',\n 'label' => 'Team',\n 'options' => $options,\n ];\n }\n\n return [\n 'id' => 'teams',\n 'label' => 'Team',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'required' => false,\n 'placeholder' => 'Select',\n 'options' => $options,\n 'value' => $value, // value should be an array of objects {id, name}\n 'dependencies' => [ActivityTypeService::PLAYBOOK_CATEGORIES_KEY],\n 'dependsOn' => [],\n ];\n }\n\n public function getReportTypeFieldData(?string $value = null, bool $shortVersion = false, ?Team $team = null): array\n {\n $types = [];\n if ($team instanceof Team) {\n if ($team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {\n $types = self::TYPES;\n }\n if ($team->hasFeature(FeatureEnum::ASK_JIMINNY_REPORTS)) {\n $types[] = ['id' => self::TYPE_ASK_JIMINNY, 'name' => 'Ask Jiminny'];\n }\n } else {\n $types = self::TYPES;\n }\n\n if ($shortVersion) {\n return [\n 'id' => 'report_type',\n 'label' => 'Report Type',\n 'options' => $types,\n ];\n }\n\n return [\n 'id' => 'report_type',\n 'label' => 'Report Type',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => $types,\n 'value' => $value,\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getFrequencyFieldData(?string $value = null): array\n {\n return [\n 'id' => 'frequency',\n 'label' => 'Frequency',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => self::FREQUENCIES,\n 'value' => $value,\n 'dependencies' => ['period'],\n 'dependsOn' => [],\n ];\n }\n\n public function getPeriodFieldData(?string $valueStartDate = null, ?string $valueEndDate = null): array\n {\n return [\n 'id' => 'period',\n 'label' => 'Select one-off period',\n 'inputType' => InputTypeEnum::DATE_RANGE,\n 'required' => true,\n 'placeholder' => 'Select',\n 'value' => ['startDate' => $valueStartDate, 'endDate' => $valueEndDate],\n 'queryParams' => [\n 'startDate' => 'start_date_period',\n 'endDate' => 'end_date_period',\n ],\n 'dependencies' => [],\n 'dependsOn' => ['frequency'],\n ];\n }\n\n public function getActivityTypesFieldData(?Team $team = null, array $value = [], array $teamsFilter = []): array\n {\n return $this->activityTypeService->getActivityTypeFieldData(team: $team, value: $value, groupIds: $teamsFilter);\n }\n\n public function getDealStageAtCallFieldData(?Team $team = null, array $value = []): array\n {\n return $this->dealStagesService->getDealStageAtCallFieldData(team: $team, value: $value);\n }\n\n public function getCurrentDealStageFieldData(?Team $team = null, array $value = []): array\n {\n return $this->dealStagesService->getCurrentDealStageFieldData(team: $team, value: $value);\n }\n\n public function getDealValueFieldData(?int $valueMin = null, ?int $valueMax = null): array\n {\n return [\n 'id' => 'deal_value',\n 'label' => 'Deal Value',\n 'inputType' => InputTypeEnum::INTEGER_RANGE,\n 'required' => false,\n 'value' => ['min' => $valueMin, 'max' => $valueMax],\n 'queryParams' => [\n 'min' => 'min_deal_value',\n 'max' => 'max_deal_value',\n ],\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getCallTypeFieldData(bool $conferenceOn = false, bool $dialerOn = false): array\n {\n $value = [];\n $conferenceOn && $value[] = self::CALL_TYPE_CONFERENCE;\n $dialerOn && $value[] = self::CALL_TYPE_DIALER;\n\n return [\n 'id' => 'call_type',\n 'label' => 'Call Type',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'required' => true,\n 'options' => [\n self::CALL_TYPE_CONFERENCE,\n self::CALL_TYPE_DIALER,\n ],\n 'value' => $value,\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getMediaTypeFieldData(?AutomatedReport $report = null): array\n {\n $value = [];\n\n if ($report) {\n $value = $this->transformMediaTypes($report);\n }\n\n return [\n 'id' => 'media_types',\n 'label' => 'Export as',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'required' => true,\n 'options' => self::MEDIA_TYPE_OBJECTS,\n 'value' => $value,\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getCallDurationFieldData(?int $valueMin = null, ?int $valueMax = null): array\n {\n return [\n 'id' => 'call_duration',\n 'label' => 'Call Duration',\n 'inputType' => InputTypeEnum::INTEGER_RANGE,\n 'required' => false,\n 'value' => ['min' => $valueMin, 'max' => $valueMax],\n 'queryParams' => [\n 'min' => 'min_call_duration',\n 'max' => 'max_call_duration',\n ],\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getRecipientsFieldData(?Team $team = null, array $value = []): array\n {\n return $this->recipientsService->getRecipientsFieldData(team: $team, value: $value);\n }\n\n public function getJiminnyRecipientsFieldData(array $value = []): array\n {\n return $this->recipientsService->getJiminnyRecipientsFieldData($value);\n }\n\n public function getAdditionalPromptInputFieldData(?string $value = null): array\n {\n return [\n 'id' => 'additional_prompt_input',\n 'label' => 'Special requirements',\n 'inputType' => InputTypeEnum::TEXTAREA,\n 'required' => false,\n 'placeholder' => 'What should be the focus of the report?',\n 'value' => $value,\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getCustomReportNameFieldData(?string $value = null): array\n {\n return [\n 'id' => 'custom_name',\n 'label' => 'Custom report name',\n 'inputType' => InputTypeEnum::TEXT,\n 'required' => false,\n 'placeholder' => 'Enter custom name',\n 'value' => $value,\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n // data providers\n public function getTeams(): array\n {\n $teams = $this->teamRepository->getTeamsForKiosk(status: Team::STATUS_ACTIVE);\n\n $teamData = [];\n foreach ($teams as $team) {\n if (! $team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {\n continue;\n }\n\n $teamData[] = $this->transformTeam($team);\n }\n\n return $teamData;\n }\n\n public function getTeamGroups(string $teamUuid): array\n {\n $data = [];\n $team = $this->getTeam($teamUuid);\n\n if ($team !== null) {\n $groups = $team->groups()->get();\n\n foreach ($groups as $group) {\n $data[] = [\n 'id' => $group->getUuid(),\n 'name' => $group->getName(),\n ];\n }\n }\n\n return $data;\n }\n\n public function getTeamsGroupsOptions(array $filterTeamUuids = []): array\n {\n $data = [];\n $teams = $this->getTeams();\n\n foreach ($teams as $team) {\n if (! empty($filterTeamUuids) && ! in_array($team['id'], $filterTeamUuids, true)) {\n continue;\n }\n\n $data[] = [\n 'label' => $team['name'],\n 'groups' => $this->getTeamGroups($team['id']),\n ];\n }\n\n return $data;\n }\n\n public function getTeam(string $teamUuid): ?Team\n {\n return $this->teamRepository->idOrUuid($teamUuid);\n }\n\n public function getTeamById(int $teamId): ?Team\n {\n return $this->teamRepository->find($teamId);\n }\n\n public function getGroupsUuids(AutomatedReport $report): array\n {\n $uuids = [];\n $reportGroups = $report->getGroups();\n foreach ($reportGroups as $groupId) {\n if ($group = $this->groupRepository->find($groupId)) {\n $uuids[] = $group->getUuid();\n }\n }\n\n return $uuids;\n }\n\n public function getPlaybookCategoriesUuids(AutomatedReport $report): array\n {\n $uuids = [];\n $playbookCategories = $report->getPlaybookCategories();\n foreach ($playbookCategories as $id) {\n if ($category = $this->playbookCategoryRepository->find($id)) {\n $uuids[] = $category->getUuid();\n }\n }\n\n return $uuids;\n }\n\n public function getDealAtCallStagesUuids(AutomatedReport $report): array\n {\n $uuids = [];\n $reportStages = $report->getDealAtCallStages();\n foreach ($reportStages as $id) {\n if ($stage = $this->stageRepository->find($id)) {\n $uuids[] = $stage->getUuid();\n }\n }\n\n return $uuids;\n }\n\n public function getCurrentDealStagesUuids(AutomatedReport $report): array\n {\n $uuids = [];\n $reportStages = $report->getCurrentDealStages();\n foreach ($reportStages as $id) {\n if ($stage = $this->stageRepository->find($id)) {\n $uuids[] = $stage->getUuid();\n }\n }\n\n return $uuids;\n }\n\n public function getUsersUuids(AutomatedReport $report): array\n {\n return $this->extractUserUuids($report->getRecipients());\n }\n\n public function getJiminnyUsersUuids(AutomatedReport $report): array\n {\n return $this->extractUserUuids($report->getJiminnyRecipients());\n }\n\n /**\n * @param array<string, mixed> $recipients\n */\n private function extractUserUuids(array $recipients): array\n {\n $userIds = $recipients['users'] ?? [];\n\n return collect($userIds)\n ->map(fn ($id) => $this->userRepository->find((int) $id))\n ->filter()\n ->map(fn (UserContract $user) => $user->getUuid())\n ->values()\n ->all();\n }\n\n // get mail data\n public function getRecipientUsers(AutomatedReport $report): array\n {\n return $this->buildRecipientUsers($report->getRecipients());\n }\n\n private function getJiminnyRecipientUsers(AutomatedReport $report): array\n {\n return $this->buildRecipientUsers($report->getJiminnyRecipients());\n }\n\n /**\n * @param array<string, mixed> $recipients\n */\n private function buildRecipientUsers(array $recipients): array\n {\n $userIds = $recipients['users'] ?? [];\n\n return collect($userIds)\n ->map(fn ($id) => $this->userRepository->find((int) $id))\n ->filter()\n ->map(fn (UserContract $user) => [\n 'email' => $user->getEmailAddress(),\n 'name' => $user->getName(),\n 'timezone' => $user->getTimezone()->getName(),\n ])\n ->values()\n ->all();\n }\n\n public function getValidRecipientUsers(AutomatedReport $report, bool $includeJiminny = false): array\n {\n if ($report->isAskJiminnyReport()) {\n $recipients = $this->resolveAskJiminnyRecipients($report);\n } else {\n $recipients = $this->getRecipientUsers($report);\n if ($includeJiminny) {\n $recipients = array_merge($recipients, $this->getJiminnyRecipientUsers($report));\n }\n }\n\n $emails = [];\n\n return array_values(array_filter(\n $recipients,\n static function ($recipient) use (&$emails) {\n if (empty($recipient['email']) || in_array($recipient['email'], $emails, true)) {\n return false;\n }\n $emails[] = $recipient['email'];\n\n return true;\n }\n ));\n }\n\n private function resolveAskJiminnyRecipients(AutomatedReport $report): array\n {\n $recipients = [];\n\n $creator = $report->getCreator();\n if ($creator !== null) {\n $recipients[] = [\n 'email' => $creator->getEmailAddress(),\n 'name' => $creator->getName(),\n 'timezone' => $creator->getTimezone()->getName(),\n ];\n }\n\n return array_merge(\n $recipients,\n $this->buildRecipientUsers($report->getRecipients()),\n $this->getGroupRecipientUsers($report),\n );\n }\n\n private function getGroupRecipientUsers(AutomatedReport $report): array\n {\n $users = [];\n foreach ($report->getGroups() as $groupId) {\n $group = $this->groupRepository->find($groupId);\n if ($group === null) {\n continue;\n }\n foreach ($group->getMembers() as $member) {\n $users[] = [\n 'email' => $member->getEmailAddress(),\n 'name' => $member->getName(),\n 'timezone' => $member->getTimezone()->getName(),\n ];\n }\n }\n\n return $users;\n }\n\n public function getReportTypeName(AutomatedReportResult $report): string\n {\n $type = $report->getReport()->getType();\n\n $getType = $this->transformReportType($type);\n\n return $getType['name'];\n }\n\n public function getReportPeriodName(AutomatedReportResult $report): string\n {\n $from = $report->getFromDate();\n $to = $report->getToDate();\n $frequency = $report->getReport()->getFrequency();\n\n if ($from === null || $to === null) {\n if (! $report->getReport()->isAskJiminnyReport()) {\n $invalidPeriod = $from === null ? 'from' : 'to';\n\n throw new ApplicationException('Report period is invalid: ' . $invalidPeriod);\n }\n\n $period = $this->calculateFromAndToDatePeriod($frequency);\n $from = $period['fromDate'];\n $to = $period['toDate'];\n }\n\n return $this->formatReportPeriodName($frequency, $from, $to);\n }\n\n private function formatReportPeriodName(string $frequency, Carbon $from, Carbon $to): string\n {\n $fromYear = $from->format('Y');\n $toYear = $to->format('Y');\n $differentYears = $fromYear !== $toYear;\n\n switch ($frequency) {\n case self::FREQUENCY_DAILY:\n return $from->format('j M Y');\n\n case self::FREQUENCY_QUARTERLY:\n // 'Jan-Mar 2025' or 'Nov 2024-Jan 2025' if years differ\n $startMonth = $from->format('M');\n $endMonth = $to->copy()->subMonth();\n $endMonthName = $endMonth->format('M');\n $endMonthYear = $endMonth->format('Y');\n\n if ($differentYears) {\n return \"{$startMonth} {$fromYear} - {$endMonthName} {$endMonthYear}\";\n }\n\n return \"{$startMonth} - {$endMonthName} {$toYear}\";\n\n case self::FREQUENCY_MONTHLY:\n // 'May 2025' - monthly reports are always within the same year\n return $from->format('M Y');\n\n case self::FREQUENCY_WEEKLY:\n // '4 - 8 Aug 2025', '27 Oct - 3 Nov 2025', or '28 Dec 2024 - 3 Jan 2025' if years differ\n $startDay = $from->format('j');\n $endDay = $to->format('j');\n $startMonth = $from->format('M');\n $endMonth = $to->format('M');\n\n if ($differentYears) {\n return \"{$startDay} {$startMonth} {$fromYear} - {$endDay} {$endMonth} {$toYear}\";\n }\n\n if ($startMonth !== $endMonth) {\n return \"{$startDay} {$startMonth} - {$endDay} {$endMonth} {$toYear}\";\n }\n\n return \"{$startDay} - {$endDay} {$endMonth} {$toYear}\";\n\n case self::FREQUENCY_ONE_OFF:\n // '2 May-31 May 2025' or '15 Dec 2024-15 Jan 2025' if years differ\n $startDay = $from->format('j');\n $startMonth = $from->format('M');\n $endDay = $to->format('j');\n $endMonth = $to->format('M');\n\n // If same month and year, use a format like '2-31 May 2025'\n if ($startMonth === $endMonth && ! $differentYears) {\n return \"{$startDay} - {$endDay} {$startMonth} {$toYear}\";\n }\n\n // If different years, include both years\n if ($differentYears) {\n return \"{$startDay} {$startMonth} {$fromYear} - {$endDay} {$endMonth} {$toYear}\";\n }\n\n // Same year but different months\n return \"{$startDay} {$startMonth} - {$endDay} {$endMonth} {$toYear}\";\n\n default:\n // Default format for unknown frequencies\n return $from->format('j M Y') . ' - ' . $to->format('j M Y');\n }\n }\n\n public function getReportTeamsName(AutomatedReportResult $report): string\n {\n $groups = $report->getGroups();\n\n if (empty($groups)) {\n return 'All';\n }\n\n // Get group names from repository\n $groupNames = [];\n foreach ($groups as $groupId) {\n $group = $this->groupRepository->find($groupId);\n if ($group) {\n $groupNames[] = $group->getName();\n }\n }\n\n if (count($groupNames) === 1) {\n // Single team format\n $teamsName = $groupNames[0];\n } else {\n // Multiple teams format\n $teamsName = implode(', ', $groupNames);\n }\n\n return $teamsName;\n }\n\n public function getReportFileName(AutomatedReportResult $report): string\n {\n $customName = $report->getReport()->getCustomName();\n $periodName = $this->getReportPeriodName($report);\n $filenameSuffix = $this->getFilenameSuffix($report);\n\n if ($customName) {\n if ($filenameSuffix) {\n $customName .= \" {$filenameSuffix}\";\n }\n\n return $this->sanitizeFileName(\"{$customName} - {$periodName}\");\n }\n\n $baseName = $this->getReportTypeName($report);\n\n if ($filenameSuffix) {\n $baseName .= \" {$filenameSuffix}\";\n }\n\n return $this->sanitizeFileName(\"{$baseName} - {$periodName} - {$this->getReportTeamsName($report)}\");\n }\n\n public function getReportFileNameWithExtension(AutomatedReportResult $result): string\n {\n $extension = $this->getMediaTypeMetadata($result)['extension'];\n\n return $this->getReportFileName($result) . '.' . $extension;\n }\n\n public function sanitizeFileName(string $fileName): string\n {\n return str_replace(['/', '\\\\'], '-', $fileName);\n }\n\n public function isUserRecipientOfReport(User $user, AutomatedReport $report): bool\n {\n $recipients = array_map('intval', $report->getRecipients()['users'] ?? []);\n\n return in_array($user->getId(), $recipients);\n }\n\n public function transformReportResults(Collection $automatedReportResults): array\n {\n $data = [];\n foreach ($automatedReportResults as $automatedReportResult) {\n /** @var AutomatedReportResult $automatedReportResult */\n\n $report = $automatedReportResult->getReport();\n\n $createdBy = $report->getCreator();\n $creator = [\n 'id' => $createdBy?->getUuid(),\n 'name' => $createdBy?->getName(),\n 'email' => $createdBy?->getEmailAddress(),\n 'photoUrl' => $createdBy?->getPhotoUrl(),\n ];\n\n $data[] = [\n 'id' => $automatedReportResult->getUuid(),\n 'name' => $automatedReportResult->getName(),\n 'frequency' => $this->transformFrequency($report->getFrequency()),\n 'recipients' => [\n ...array_values($this->transformGroups(team: $report->getTeam(), groupsIds: $report->getGroups())),\n ...array_values($this->transformRecipients($report->getRecipients())),\n ],\n 'report_type' => $this->transformReportType($report->getType()),\n 'media_type' => $automatedReportResult->getMediaType(),\n 'downloadUrl' => $this->generateReportResultDownloadUrl($automatedReportResult),\n 'viewUrl' => $this->generateReportResultViewUrl($automatedReportResult),\n 'generated_at' => $automatedReportResult->getGeneratedAt()?->toIso8601String(),\n 'creator' => $creator,\n ];\n }\n\n return $data;\n }\n\n public function hasCallTypeConference(AutomatedReport $report): bool\n {\n return in_array(self::CALL_TYPE_CONFERENCE['id'], $report->getCallTypes(), true);\n }\n\n public function hasCallTypeDialer(AutomatedReport $report): bool\n {\n return in_array(self::CALL_TYPE_DIALER['id'], $report->getCallTypes(), true);\n }\n\n // transformers\n private function transformTeam(Team $team): array\n {\n if (! $team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {\n return [];\n }\n\n return [\n 'id' => $team->getUuid(),\n 'name' => $team->getName(),\n ];\n }\n\n private function transformReportFullView(AutomatedReport $report): array\n {\n $base = $this->transformReportBase($report);\n\n return $report->getType() === self::TYPE_ASK_JIMINNY\n ? $base + $this->transformAskJiminnyFields($report)\n : $base + $this->transformStandardReportFields($report);\n }\n\n private function transformReportBase(AutomatedReport $report): array\n {\n return [\n 'id' => $report->getUuid(),\n 'organization' => $this->transformOrganization(team: $report->getTeam()),\n 'report_type' => $this->transformReportType($report->getType()),\n 'frequency' => $this->transformFrequency($report->getFrequency()),\n ];\n }\n\n private function transformStandardReportFields(AutomatedReport $report): array\n {\n $team = $report->getTeam();\n\n return [\n 'report_enabled' => $report->getStatus(),\n 'start_date_period' => $report->getFrom()?->format('Y-m-d H:i:s'),\n 'end_date_period' => $report->getTo()?->format('Y-m-d H:i:s'),\n 'deal_value_min' => $report->getDealValueMin(),\n 'deal_value_max' => $report->getDealValueMax(),\n 'call_types' => $this->transformCallType($report->getCallTypes()),\n 'media_types' => $this->transformMediaTypes($report),\n 'call_duration_min' => $this->transformDurationToMinutes($report->getCallDurationMin()),\n 'call_duration_max' => $this->transformDurationToMinutes($report->getCallDurationMax()),\n 'teams' => $this->transformGroups(team: $team, groupsIds: $report->getGroups()),\n 'deal_at_call_stages' => $this->transformStages(team: $team, stagesIds: $report->getDealAtCallStages()),\n 'current_deal_stages' => $this->transformStages(team: $team, stagesIds: $report->getCurrentDealStages()),\n 'recipients' => $this->transformRecipients($report->getRecipients()),\n 'created_by' => $this->transformCreator($report->getCreator()),\n 'additional_prompt_input' => $report->getAdditionalPromptInput(),\n 'custom_name' => $report->getCustomName(),\n 'created_at' => $report->getCreatedAt()->format('Y-m-d H:i:s'),\n 'updated_at' => $report->getUpdatedAt()->format('Y-m-d H:i:s'),\n 'deleted_at' => $report->getDeletedAt()?->format('Y-m-d H:i:s'),\n ];\n }\n\n private function transformAskJiminnyFields(AutomatedReport $report): array\n {\n $team = $report->getTeam();\n $creatorId = $report->getAttribute('created_by');\n $explicitUserIds = array_values(array_filter(\n $report->getRecipients()['users'] ?? [],\n static fn ($id) => $id !== $creatorId\n ));\n\n return [\n 'report_name' => $report->getCustomName(),\n 'enabled' => $report->getStatus(),\n 'share_teams' => $this->transformGroups(team: $team, groupsIds: $report->getGroups()),\n 'share_users' => $this->transformRecipients(['users' => $explicitUserIds]),\n 'saved_search' => $this->transformSafeSearch($report->getSavedSearch()),\n 'ask_jiminny_prompt' => $this->transformAskJiminnyPrompt($report->getAskAnythingPrompt()),\n 'expires_on' => $report->getExpiresAt()?->format('Y-m-d'),\n ];\n }\n\n private function transformOrganization(?Team $team): array\n {\n return [\n 'id' => $team?->getUuid(),\n 'name' => $team?->getName(),\n ];\n }\n\n private function transformReportType(string $type): array\n {\n foreach (self::ALL_TYPES as $typeItem) {\n if ($typeItem['id'] === $type) {\n return $typeItem;\n }\n }\n\n return [];\n }\n\n private function transformCallType(array $types): array\n {\n $result = [];\n $callTypes = [self::CALL_TYPE_CONFERENCE, self::CALL_TYPE_DIALER];\n\n foreach ($types as $type) {\n foreach ($callTypes as $callTypeItem) {\n if ($callTypeItem['id'] === $type) {\n $result[] = $callTypeItem;\n\n break;\n }\n }\n }\n\n return $result;\n }\n\n private function transformMediaTypes(AutomatedReport $report): array\n {\n $values = [];\n\n foreach ($report->getMediaTypes() as $mediaType) {\n if (! in_array($mediaType, self::MEDIA_TYPES, true)) {\n continue;\n }\n\n $values[] = match ($mediaType) {\n self::MEDIA_TYPE_PDF => self::MEDIA_TYPE_OBJECT_PDF,\n self::MEDIA_TYPE_PODCAST => self::MEDIA_TYPE_OBJECT_PODCAST,\n };\n }\n\n return $values;\n }\n\n private function transformFrequency(string $frequency): array\n {\n foreach (self::ALL_FREQUENCIES as $frequencyItem) {\n if ($frequencyItem['id'] === $frequency) {\n return $frequencyItem;\n }\n }\n\n return [];\n }\n\n public function transformDurationToMinutes(?int $duration): ?int\n {\n if (! $duration) {\n return null;\n }\n\n return (int) ($duration / 60);\n }\n\n private function transformGroups(?Team $team, array $groupsIds): array\n {\n if (empty($groupsIds) || ! $team) {\n return [];\n }\n\n $data = [];\n foreach ($groupsIds as $groupId) {\n $group = $team->groups()->where('id', $groupId)->first();\n\n if ($group) {\n $data[] = [\n 'id' => $group->getUuid(),\n 'name' => $group->getName(),\n 'photoUrl' => $group->getPhotoUrl(),\n ];\n }\n }\n\n return $data;\n }\n\n private function transformStages(?Team $team, array $stagesIds): array\n {\n if (empty($stagesIds) || ! $team) {\n return [];\n }\n\n $data = [];\n foreach ($stagesIds as $stageId) {\n $stage = $team->stages()->where('id', $stageId)->first();\n\n if ($stage) {\n $data[] = [\n 'id' => $stage->getUuid(),\n 'name' => $stage->getName(),\n ];\n }\n }\n\n return $data;\n }\n\n private function transformRecipients(array $recipients): array\n {\n $users = [];\n foreach ($recipients['users'] ?? [] as $userId) {\n $users[] = $this->transformUser($userId);\n }\n\n return $users;\n }\n\n private function transformCreator(?User $user): ?array\n {\n if ($user === null) {\n return null;\n }\n\n return $this->transformUser($user->getId());\n }\n\n private function transformAskJiminnyPrompt(?AskAnythingPrompt $prompt): ?array\n {\n if ($prompt === null) {\n return null;\n }\n\n return [\n 'id' => $prompt->getUuid(),\n 'name' => $prompt->getTitle(),\n ];\n }\n\n private function transformSafeSearch(?Search $search): ?array\n {\n if ($search === null) {\n return null;\n }\n\n return [\n 'id' => $search->getUuid(),\n 'name' => $search->getName(),\n ];\n }\n\n private function transformUser(int $userId): array\n {\n /* @var ?User $user */\n $user = $this->userRepository->find($userId);\n\n return [\n 'id' => $user?->getUuid(),\n 'name' => $user?->getName(),\n 'email' => $user?->getEmailAddress(),\n 'photoUrl' => $user?->getPhotoUrl(),\n ];\n }\n\n public function create(array $data): array\n {\n $validatedData = $this->validateAndTransformData($data);\n $validatedData['created_by'] = auth()->id();\n\n $automatedReport = $this->automatedReportsRepository->create($validatedData);\n\n $this->generateOneOffReport($automatedReport);\n\n return $this->transformReportFullView($automatedReport);\n }\n\n public function update(string $uuid, array $data): array\n {\n $validatedData = $this->validateAndTransformData($data);\n $report = $this->automatedReportsRepository->findByUuid($uuid);\n\n if (! $report) {\n throw new InvalidArgumentException('Report not found');\n }\n\n $oldCustomName = $report->getCustomName();\n\n $automatedReport = $this->automatedReportsRepository->update($report, $validatedData);\n\n if ($oldCustomName !== $automatedReport->getCustomName()) {\n $this->updateResultNames($automatedReport);\n }\n\n $this->generateOneOffReport($automatedReport);\n\n return $this->transformReportFullView($automatedReport);\n }\n\n /**\n * Create an Ask Jiminny report.\n */\n public function createAskJiminnyReport(array $data, User $creator): array\n {\n $validatedData = $this->validateAskJiminnyReportData($data, $creator);\n $validatedData['created_by'] = $creator->getId();\n\n $automatedReport = $this->automatedReportsRepository->create($validatedData);\n\n return $this->transformReportFullView($automatedReport);\n }\n\n /**\n * Update an Ask Jiminny report.\n */\n public function updateAskJiminnyReport(AutomatedReport $report, array $data, User $user): array\n {\n if (! $report->isAskJiminnyReport()) {\n throw new InvalidArgumentException('Report is not an Ask Jiminny report');\n }\n\n $validatedData = $this->validateAskJiminnyReportData($data, $user);\n\n $oldCustomName = $report->getCustomName();\n\n $automatedReport = $this->automatedReportsRepository->update($report, $validatedData);\n\n if ($oldCustomName !== $automatedReport->getCustomName()) {\n $this->updateResultNames($automatedReport);\n }\n\n return $this->transformReportFullView($automatedReport);\n }\n\n public function updateAskJiminnyReportStatus(AutomatedReport $report, bool $status): array\n {\n $this->automatedReportsRepository->update($report, ['status' => $status]);\n\n return $this->transformReportFullView($report->fresh());\n }\n\n /**\n * Validate and transform data for Ask Jiminny reports.\n */\n private function validateAskJiminnyReportData(array $data, User $user): array\n {\n // Validate name\n $name = trim($data['report_name'] ?? '');\n if (empty($name)) {\n throw new InvalidArgumentException('Report name is required');\n }\n if (mb_strlen($name) > 50) {\n throw new InvalidArgumentException('Report name must be 50 characters or less');\n }\n\n // Validate frequency (only daily, weekly, monthly for Ask Jiminny)\n $frequency = $data['frequency'] ?? null;\n $askJiminnyFrequencies = [self::FREQUENCY_DAILY, self::FREQUENCY_WEEKLY, self::FREQUENCY_MONTHLY];\n if (! in_array($frequency, $askJiminnyFrequencies, true)) {\n throw new InvalidArgumentException('Frequency must be daily, weekly, or monthly');\n }\n\n // Validate expiration date\n $expiresAt = $data['expires_on'] ?? null;\n if (empty($expiresAt)) {\n throw new InvalidArgumentException('Expiration date is required');\n }\n\n try {\n $expiresAtDate = Carbon::parse($expiresAt);\n } catch (InvalidFormatException $e) {\n throw new InvalidArgumentException('Expiration date format is invalid');\n }\n $maxExpiration = Carbon::now()->addYear();\n if ($expiresAtDate->gt($maxExpiration)) {\n throw new InvalidArgumentException('Expiration date cannot be more than 1 year from now');\n }\n if ($expiresAtDate->isPast()) {\n throw new InvalidArgumentException('Expiration date cannot be in the past');\n }\n\n // Validate saved search\n $activitySearchId = $data['saved_search'] ?? null;\n if (empty($activitySearchId)) {\n throw new InvalidArgumentException('Saved search is required');\n }\n $savedSearch = $this->activitySearchRepository->findByUuidAndUser($activitySearchId, $user);\n if (! $savedSearch) {\n throw new InvalidArgumentException('Saved search not found or does not belong to you');\n }\n\n // Validate saved prompt\n $askAnythingPromptId = $data['ask_jiminny_prompt'] ?? null;\n if (empty($askAnythingPromptId)) {\n throw new InvalidArgumentException('Ask Jiminny prompt is required');\n }\n $prompt = $this->askAnythingRepository->getPromptByUuid($askAnythingPromptId);\n if (! $prompt) {\n throw new InvalidArgumentException('Ask Jiminny prompt not found');\n }\n\n // Validate status\n $status = $data['enabled'] ?? false;\n\n $recipientUserIds = [$user->getId()];\n\n if (! empty($data['share_users'])) {\n $sharedUserIds = $this->validateAndGetUserIdsByTeam(\n $user->team,\n (array) $data['share_users']\n );\n $recipientUserIds = array_merge($recipientUserIds, $sharedUserIds);\n }\n\n $sharedGroupIds = [];\n if (! empty($data['share_teams'])) {\n $sharedGroupIds = $this->validateAndGetGroupIds($user->team, (array) $data['share_teams']);\n }\n\n $recipientUserIds = array_values(array_unique($recipientUserIds));\n\n return [\n 'team_id' => $user->getTeamId(),\n 'type' => self::TYPE_ASK_JIMINNY,\n 'status' => (bool) $status,\n 'frequency' => $frequency,\n 'custom_name' => $name,\n 'activity_search_id' => $savedSearch->getId(),\n 'ask_anything_prompt_id' => $prompt->getId(),\n 'expires_at' => $expiresAtDate->toDateString(),\n 'media_types' => [self::MEDIA_TYPE_PDF],\n 'call_types' => [],\n 'recipients' => ['users' => $recipientUserIds],\n 'groups' => $sharedGroupIds,\n ];\n }\n\n public static function getAskJiminnyFrequencies(): array\n {\n return array_map(static function ($frequency) {\n return $frequency['id'];\n }, self::ASK_JIMINNY_FREQUENCIES);\n }\n\n public function getAskJiminnyReportFilters(User $user): array\n {\n $savedSearches = $this->activitySearchRepository->findByUserOrderedByName($user)\n ->map(fn (Search $search) => [\n 'id' => $search->getUuid(),\n 'name' => $search->getName(),\n ])\n ->values()->all();\n\n $prompts = collect(\n $this->askAnythingPromptService->get($user, AskAnythingPromptTarget::on_demand)\n )->map(fn (AskAnythingPromptDto $prompt) => [\n 'id' => $prompt->id,\n 'name' => $prompt->title,\n ])->values()->all();\n\n return [\n [\n 'id' => 'prompt',\n 'label' => 'Prompt',\n 'options' => $prompts,\n ],\n [\n 'id' => 'saved_search',\n 'label' => 'Saved Search',\n 'options' => $savedSearches,\n ],\n ];\n }\n\n public function getAskJiminnyReportFormData(User $user, ?AutomatedReport $report = null): array\n {\n $team = $user->getTeam();\n $userTimezone = $user->getTimezone();\n\n $savedSearches = $this->activitySearchRepository->findByUserOrderedByName($user)\n ->map(fn (Search $search) => [\n 'id' => $search->getUuid(),\n 'name' => $search->getName(),\n ])\n ->values()->all();\n\n $prompts = collect(\n $this->askAnythingPromptService->get($user, AskAnythingPromptTarget::on_demand)\n )->map(fn (AskAnythingPromptDto $prompt) => [\n 'id' => $prompt->id,\n 'name' => $prompt->title,\n ])->values()->all();\n\n $teamGroups = $this->groupRepository->getAllByTeam($team)->map(fn ($group) => [\n 'id' => $group->getUuid(),\n 'name' => $group->getName(),\n ])->values()->all();\n\n $shareUsers = $this->recipientsService->getRecipientsFieldData(team: $team)['options'] ?? [];\n\n $sharedTeamsValue = [];\n $sharedUsersValue = [];\n if ($report) {\n $sharedTeamsValue = $this->transformGroups($team, $report->getGroups());\n\n $recipientUserIds = $report->getRecipients()['users'] ?? [];\n $creatorId = $report->getAttribute('created_by');\n $sharedUserIds = array_values(array_filter(\n $recipientUserIds,\n static fn ($id) => $id !== $creatorId\n ));\n $sharedUsersValue = collect($sharedUserIds)\n ->map(fn ($id) => $this->userRepository->find((int) $id))\n ->filter()\n ->map(fn (User $u) => [\n 'id' => $u->getUuid(),\n 'name' => $u->getName(),\n ])\n ->values()\n ->all();\n }\n\n return [\n 'fields' => [\n [\n 'id' => 'enabled',\n 'inputType' => InputTypeEnum::TOGGLE,\n 'label' => '',\n 'value' => $report?->getStatus() ?? false,\n ],\n [\n 'id' => 'report_name',\n 'inputType' => InputTypeEnum::TEXT,\n 'label' => 'Name',\n 'placeholder' => 'Enter name',\n 'required' => true,\n 'validation' => ['maxLength' => 50],\n 'value' => $report?->getCustomName() ?? '',\n ],\n [\n 'id' => 'frequency',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'label' => 'Frequency',\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => self::ASK_JIMINNY_FREQUENCIES,\n 'value' => $report ? $this->transformFrequency($report->getFrequency()) : null,\n ],\n [\n 'id' => 'expires_on',\n 'inputType' => InputTypeEnum::DATE,\n 'label' => 'Expires on',\n 'required' => true,\n 'placeholder' => 'Select',\n 'validation' => [\n 'minDate' => now($userTimezone)->toDateString(),\n 'maxDate' => now($userTimezone)->addYear()->toDateString(),\n ],\n 'value' => $report?->getExpiresAt()?->toDateString(),\n ],\n [\n 'id' => 'share_teams',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'label' => 'Team',\n 'required' => false,\n 'placeholder' => 'Select',\n 'options' => $teamGroups,\n 'value' => $sharedTeamsValue,\n ],\n [\n 'id' => 'share_users',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'label' => 'Team member',\n 'required' => false,\n 'placeholder' => 'Select',\n 'groupLabelKey' => 'label',\n 'groupValuesKey' => 'users',\n 'optionLabelKey' => 'name',\n 'optionValueKey' => 'id',\n 'options' => $shareUsers,\n 'value' => $sharedUsersValue,\n ],\n [\n 'id' => 'saved_search',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'label' => 'Saved search',\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => $savedSearches,\n 'value' => $report && $report->getSavedSearch() ? [\n 'id' => $report->getSavedSearch()->getUuid(),\n 'name' => $report->getSavedSearch()->getName(),\n ] : null,\n ],\n [\n 'id' => 'ask_jiminny_prompt',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'label' => 'Ask Jiminny prompt',\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => $prompts,\n 'value' => $report && $report->getAskAnythingPrompt() ? [\n 'id' => $report->getAskAnythingPrompt()->getUuid(),\n 'name' => $report->getAskAnythingPrompt()->getTitle(),\n ] : null,\n ],\n ],\n ];\n }\n\n private function updateResultNames(AutomatedReport $automatedReport): void\n {\n $results = $this->automatedReportsRepository->getResultsByReport($automatedReport);\n\n foreach ($results as $result) {\n $result->update(['name' => $this->getReportFileName($result)]);\n }\n }\n\n public function updateStatus(string $uuid, array $data): array\n {\n $automatedReport = $this->automatedReportsRepository->findByUuid($uuid);\n\n if (! $automatedReport) {\n throw new ModelNotFoundException('Report not found');\n }\n\n $status = $this->validateReportStatus($data['report_enabled'] ?? null);\n $automatedReport->update([\n 'status' => $status,\n ]);\n\n $this->generateOneOffReport($automatedReport);\n\n return $this->transformReportFullView($automatedReport);\n }\n\n private function generateOneOffReport(AutomatedReport $automatedReport): void\n {\n // the scheduler handles all the other frequency types\n if ($automatedReport->getStatus() === false || $automatedReport->getFrequency() !== self::FREQUENCY_ONE_OFF) {\n return;\n }\n\n $this->dispatcher->dispatch(new RequestGenerateReportJob($automatedReport->getUuid()));\n }\n\n public function getReport(string $uuid): AutomatedReport\n {\n $automatedReport = $this->automatedReportsRepository->findByUuid($uuid);\n\n if (! $automatedReport) {\n throw new ModelNotFoundException('Report not found');\n }\n\n return $automatedReport;\n }\n\n public function get(string $uuid): array\n {\n $automatedReport = $this->getReport($uuid);\n\n return $this->transformReportFullView($automatedReport);\n }\n\n public function list(string $sortColumn = 'created_at', string $sortDirection = 'desc'): array\n {\n $results = [];\n $collection = $this->automatedReportsRepository->getAllStandardReports($sortColumn, $sortDirection);\n\n /** @var AutomatedReport $report */\n foreach ($collection as $report) {\n $results[] = $this->transformReportFullView($report);\n }\n\n return ['data' => $results];\n }\n\n public function listAskJiminnyReports(\n User $user,\n string $sortColumn = 'created_at',\n string $sortDirection = 'desc'\n ): array {\n $results = [];\n $collection = $this->automatedReportsRepository->getAskJiminnyReportsByUser($user, $sortColumn, $sortDirection);\n\n /** @var AutomatedReport $report */\n foreach ($collection as $report) {\n $results[] = $this->transformReportFullView($report);\n }\n\n return ['data' => $results];\n }\n\n public function delete(string $uuid): void\n {\n $automatedReport = $this->automatedReportsRepository->findByUuid($uuid);\n\n if (! $automatedReport) {\n throw new ModelNotFoundException('Report not found');\n }\n\n $automatedReport->delete();\n }\n\n public function createReportResult(AutomatedReport $automatedReport, array $data = []): AutomatedReportResult\n {\n return $this->automatedReportsRepository->createResult(\n array_merge(\n [\n 'report_id' => $automatedReport->getId(),\n 'status' => AutomatedReportResult::STATUS_DEFAULT,\n ],\n $data\n )\n );\n }\n\n public function getReportResult(string $resultUuid): AutomatedReportResult\n {\n $report = $this->automatedReportsRepository->findResultByUuid($resultUuid);\n\n if (! $report) {\n throw new ModelNotFoundException('Report Result not found');\n }\n\n return $report;\n }\n\n public function findChildResult(AutomatedReportResult $result, string $type): ?AutomatedReportResult\n {\n return $this->automatedReportsRepository->findChildResult($result, $type);\n }\n\n // prophet API calls\n /**\n * @throws ApplicationException\n */\n public function getGenerateReportPayload(AutomatedReport $automatedReport, string $reportResultUuid): array\n {\n $period = $this->calculateFromAndToDate($automatedReport);\n $fromDate = $period['fromDate'];\n $toDate = $period['toDate'];\n\n return [\n 'team_id' => $automatedReport->getTeamId(),\n 'request_id' => $reportResultUuid,\n 'report_type' => $automatedReport->getType(),\n 'media_types' => $automatedReport->getMediaTypes(),\n 'from_date' => $fromDate->startOfDay()->format(DateTimeInterface::RFC3339),\n 'to_date' => $toDate->endOfDay()->format(DateTimeInterface::RFC3339),\n 'group_ids' => $automatedReport->getGroups(),\n 'call_deal_stage' => $automatedReport->getDealAtCallStages(),\n 'current_deal_stage' => $automatedReport->getCurrentDealStages(),\n 'deal_min_value' => $automatedReport->getDealValueMin(),\n 'deal_max_value' => $automatedReport->getDealValueMax(),\n 'call_types' => $automatedReport->getCallTypes(),\n 'call_duration_min_seconds' => $automatedReport->getCallDurationMin(),\n 'call_duration_max_seconds' => $automatedReport->getCallDurationMax(),\n 'special_requirements' => $automatedReport->getAdditionalPromptInput(),\n 'callback_url' => $this->getCallbackUrl(),\n 'report_period' => $this->formatReportPeriodName(\n $automatedReport->getFrequency(),\n $fromDate,\n $toDate,\n ),\n 'playbook_categories' => $automatedReport->getPlaybookCategories(),\n 'custom_name' => $automatedReport->getCustomName(),\n ];\n }\n\n // $inputPayload - FE payload structure\n public function getActivitiesCountPayload(array $inputPayload): array\n {\n // Use validateAndTransformData to validate and normalize input\n $validatedData = $this->validateAndTransformData($inputPayload);\n $period = $this->calculateFromAndToDatePeriod(\n $validatedData['frequency'],\n Carbon::parse($validatedData['from']),\n Carbon::parse($validatedData['to']),\n );\n $fromDate = $period['fromDate'];\n $toDate = $period['toDate'];\n\n // Create payload similar to getGenerateReportPayload\n return [\n 'team_id' => $validatedData['team_id'],\n 'group_ids' => $validatedData['groups'] ?? [],\n 'report_type' => $validatedData['type'],\n 'from_date' => $fromDate->format(DateTimeInterface::RFC3339),\n 'to_date' => $toDate->format(DateTimeInterface::RFC3339),\n 'call_deal_stage' => $validatedData['deal_at_call_stages'] ?? [],\n 'current_deal_stage' => $validatedData['current_deal_stages'] ?? [],\n 'deal_min_value' => $validatedData['deal_value_min'] ?? null,\n 'deal_max_value' => $validatedData['deal_value_max'] ?? null,\n 'call_types' => $validatedData['call_types'],\n 'call_duration_min_seconds' => $validatedData['call_duration_min'] ?? null,\n 'call_duration_max_seconds' => $validatedData['call_duration_max'] ?? null,\n 'special_requirements' => $validatedData['additional_prompt_input'] ?? null,\n 'playbook_categories' => $validatedData['playbook_categories'] ?? [],\n 'request_id' => null,\n 'callback_url' => null,\n ];\n }\n\n public function shouldSendReport(array $users, ?CarbonInterface $generatedAt = null): bool\n {\n if (empty($users)) {\n return false;\n }\n\n $earliestTz = collect($users)\n ->mapWithKeys(function (array $user) {\n $tz = new DateTimeZone($user['timezone']);\n $nowUtc = new DateTime('now', new DateTimeZone('UTC'));\n $offset = $tz->getOffset($nowUtc);\n\n return [$user['timezone'] => $offset];\n })\n ->sortDesc()\n ->keys()\n ->first();\n\n $now = Carbon::now($earliestTz);\n $isScheduledTime = (int) $now->format('H') === self::SENT_REPORT_AT_HOURS;\n\n if ($isScheduledTime) {\n return true;\n }\n\n return $this->hasPassedScheduledTime($generatedAt, $earliestTz);\n }\n\n public function hasPassedScheduledTime(?CarbonInterface $generatedAt, string $timezone): bool\n {\n if ($generatedAt === null) {\n return false;\n }\n\n $now = Carbon::now($timezone);\n $scheduledTime = $now->copy()->setTime(self::SENT_REPORT_AT_HOURS, 0, 0);\n\n if ($now->hour < self::SENT_REPORT_AT_HOURS) {\n $scheduledTime = $scheduledTime->subDay();\n }\n\n $scheduledTimeUtc = $scheduledTime->copy()->utc();\n $generatedAtUtc = $generatedAt->copy()->utc();\n $nowUtc = $now->copy()->utc();\n\n return $generatedAtUtc->lt($scheduledTimeUtc) && $nowUtc->gt($scheduledTimeUtc);\n }\n\n public function calculateFromAndToDatePeriod(\n string $frequency,\n ?Carbon $fromDate = null,\n ?Carbon $toDate = null\n ): array {\n if ($frequency === self::FREQUENCY_ONE_OFF) {\n return [\n 'fromDate' => $fromDate,\n 'toDate' => $toDate,\n ];\n }\n\n $now = Carbon::now();\n\n return match ($frequency) {\n self::FREQUENCY_DAILY => [\n 'fromDate' => $now->copy()->subDay()->startOfDay(),\n 'toDate' => $now->copy()->subDay()->endOfDay(),\n ],\n self::FREQUENCY_WEEKLY => [\n 'fromDate' => $now->copy()->subWeeks(1)->startOfDay(),\n 'toDate' => $now->copy()->subDay()->endOfDay(),\n ],\n self::FREQUENCY_MONTHLY => [\n 'fromDate' => $now->copy()->subMonths(1)->startOfDay(),\n 'toDate' => $now->copy()->subDay()->endOfDay(),\n ],\n self::FREQUENCY_QUARTERLY => [\n 'fromDate' => $now->copy()->subMonths(3)->startOfDay(),\n 'toDate' => $now->copy()->subDay()->endOfDay(),\n ],\n default => throw new InvalidArgumentException(\"Unsupported frequency: {$frequency}\"),\n };\n }\n\n private function calculateFromAndToDate(AutomatedReport $automatedReport): array\n {\n return $this->calculateFromAndToDatePeriod(\n $automatedReport->getFrequency(),\n $automatedReport->getFrom(),\n $automatedReport->getTo()\n );\n }\n\n public function getAskJiminnyGenerateReportPayload(\n AutomatedReport $automatedReport,\n AutomatedReportResult $reportResult,\n array $activityIds,\n ): array {\n return [\n 'user_question' => $automatedReport->getAskAnythingPrompt()?->getContent(),\n 'call_ids' => array_map('strval', $activityIds),\n 'team_id' => $automatedReport->getTeamId(),\n 'request_id' => $reportResult->getUuid(),\n 'callback_url' => $this->getCallbackUrl(),\n 'report_period' => $this->getReportPeriodName($reportResult),\n 'report_name' => $automatedReport->getCustomName(),\n ];\n }\n\n private function getCallbackUrl(): string\n {\n return $this->webhookService->route('jiminny.webhook.reports.ready');\n }\n\n /**\n * Validate and transform payload data for automated reports\n *\n * @param array $data\n *\n * @throws InvalidArgumentException\n *\n * @return array\n */\n private function validateAndTransformData(array $data): array\n {\n // Validate organization (team) and check feature\n $team = $this->validateOrganization($data['organization'] ?? null);\n\n $status = $this->validateReportStatus($data['report_enabled'] ?? null);\n $type = $this->validateReportType($data['report_type'] ?? null);\n $frequency = $this->validateFrequency($data['frequency'] ?? null);\n $additionalPromptInput = $this->validateAdditionalPromptInput(\n $data['additional_prompt_input'] ?? null\n );\n $customReportName = $this->validateCustomReportName($data['custom_name'] ?? null);\n\n // Prepare data for the database\n $reportData = [\n 'team_id' => $team->getId(),\n 'type' => $type,\n 'status' => $status,\n 'frequency' => $frequency,\n 'additional_prompt_input' => $additionalPromptInput,\n 'custom_name' => $customReportName,\n ];\n\n // Validate deal values\n $reportData = $this->validateDealValues($data, $reportData);\n\n // Validate date range\n $reportData = $this->validateDateRange($data, $reportData, $frequency);\n\n // Validate call durations\n $reportData = $this->validateCallDurations($data, $reportData);\n\n // Validate call types\n $reportData = $this->validateCallTypes($data, $reportData);\n\n // Validate media types\n $reportData = $this->validateMediaTypes($data, $reportData);\n\n // Validate groups\n if (isset($data['teams'])) {\n $reportData['groups'] = $this->validateAndGetGroupIds($team, $data['teams']);\n }\n\n // Validate deal stages\n $reportData = $this->validateDealStages($data, $reportData, $team, $type);\n\n // Validate playbook categories\n $reportData = $this->validatePlaybookCategories($data, $reportData, $team);\n\n // Validate recipients\n $reportData['recipients'] = [\n 'users' => $this->validateAndGetUserIdsByTeam($team, $data['recipients'] ?? []),\n ];\n\n if (isset($data['jiminny_recipients'])) {\n // Validate Jiminny recipients\n $reportData['jiminny_recipients'] = [\n 'users' => $this->validateAndGetJiminnyUserIds((array) $data['jiminny_recipients']),\n ];\n }\n\n return $reportData;\n }\n\n private function validateDealValues(array $data, array $reportData): array\n {\n if (isset($data['min_deal_value'])) {\n $reportData['deal_value_min'] = (int) $data['min_deal_value'];\n\n if ($reportData['deal_value_min'] > 4294967295 || $reportData['deal_value_min'] < 0) {\n throw new InvalidArgumentException('Min deal value should be between 0 and 4294967295');\n }\n }\n\n if (isset($data['max_deal_value'])) {\n $reportData['deal_value_max'] = (int) $data['max_deal_value'];\n\n if ($reportData['deal_value_max'] > 4294967295 || $reportData['deal_value_max'] < 0) {\n throw new InvalidArgumentException('Max deal value should be between 0 and 4294967295');\n }\n }\n\n if (isset($data['min_deal_value'], $data['max_deal_value'])\n && $data['min_deal_value'] > $data['max_deal_value']\n ) {\n throw new InvalidArgumentException('Min deal value cannot be greater than max deal value');\n }\n\n return $reportData;\n }\n\n private function validateDateRange(array $data, array $reportData, string $frequency): array\n {\n // Set date range only for one_off frequency\n if ($frequency === 'one_off') {\n if (isset($data['start_date_period'])) {\n $reportData['from'] = $this->parseDate($data['start_date_period']);\n }\n\n if (isset($data['end_date_period'])) {\n $reportData['to'] = $this->parseDate($data['end_date_period']);\n }\n\n if (empty($reportData['from']) || empty($reportData['to'])) {\n throw new InvalidArgumentException(\n 'Start date and end date are required for one_off frequency'\n );\n }\n } else {\n $reportData['from'] = null;\n $reportData['to'] = null;\n }\n\n return $reportData;\n }\n\n private function validateCallDurations(array $data, array $reportData): array\n {\n // Convert call durations from minutes to seconds\n if (isset($data['min_call_duration'])) {\n $reportData['call_duration_min'] = (int) $data['min_call_duration'] * 60;\n\n if ($reportData['call_duration_min'] > 4294967295 || $reportData['call_duration_min'] < 0) {\n throw new InvalidArgumentException('Min call duration should be between 0 and 4294967295');\n }\n }\n\n if (isset($data['max_call_duration'])) {\n $reportData['call_duration_max'] = (int) $data['max_call_duration'] * 60;\n\n if ($reportData['call_duration_max'] > 4294967295 || $reportData['call_duration_max'] < 0) {\n throw new InvalidArgumentException('Max call duration should be between 0 and 4294967295');\n }\n }\n\n return $reportData;\n }\n\n private function validateCallTypes(array $data, array $reportData): array\n {\n // Set call types\n $reportData['call_types'] = $data['call_type'] ?? [];\n if (empty($reportData['call_types'])) {\n $reportData['call_types'] = self::getCallTypes();\n }\n\n foreach ($reportData['call_types'] as $callType) {\n if (! in_array($callType, self::getCallTypes(), true)) {\n throw new InvalidArgumentException(sprintf('Call type %s is invalid', $callType));\n }\n }\n\n return $reportData;\n }\n\n private function validateMediaTypes(array $data, array $reportData): array\n {\n // Set media types from input data\n $reportData['media_types'] = $data['media_types'] ?? [];\n\n if (empty($reportData['media_types'])) {\n throw new InvalidArgumentException('Media types are required');\n }\n\n foreach ($reportData['media_types'] as $mediaType) {\n if (! in_array($mediaType, self::MEDIA_TYPES, true)) {\n throw new InvalidArgumentException(sprintf('Media type %s is invalid', $mediaType));\n }\n }\n\n return $reportData;\n }\n\n private function validateDealStages(array $data, array $reportData, Team $team, string $reportType): array\n {\n // Validate and set deal stages\n if (isset($data['deal_stage_at_call'])) {\n $reportData['deal_at_call_stages'] =\n $this->validateAndGetDealStageIds($team, $data['deal_stage_at_call'], 'Deal stage at call');\n }\n\n if (isset($data['current_deal_stage'])) {\n $reportData['current_deal_stages'] =\n $this->validateAndGetDealStageIds($team, $data['current_deal_stage'], 'Current deal stage');\n }\n\n // Ensure current_deal_stage is not provided for loss_analysis report type\n if ($reportType === self::TYPE_LOSS_ANALYSIS && ! empty($data['current_deal_stage'])) {\n throw new InvalidArgumentException('Current deal stage is not applicable for Loss Analysis reports');\n }\n\n return $reportData;\n }\n\n // transform uuid to id\n private function validatePlaybookCategories(array $data, array $reportData, Team $team): array\n {\n $key = 'playbook_categories';\n\n if (isset($data[$key])) {\n $payloadIds = $data[$key];\n $ids = [];\n\n foreach ($payloadIds as $uuid) {\n $uuid = (string) $uuid;\n\n try {\n $playbookCategory = $this->playbookCategoryRepository->findByUuid($uuid);\n } catch (Throwable $throwable) {\n Log::error(__METHOD__ . ' ' . $throwable->getMessage());\n\n throw new InvalidArgumentException(sprintf('Playbook category %s not found', $uuid));\n }\n\n if (! $playbookCategory) {\n throw new InvalidArgumentException(sprintf('Playbook category %s not found', $uuid));\n }\n\n if (! $playbookCategory->hasPlaybook()) {\n throw new InvalidArgumentException(sprintf('Playbook category %s has no playbook', $uuid));\n }\n\n if ($playbookCategory->getPlaybook()->getTeamId() !== $team->getId()) {\n throw new InvalidArgumentException(\n sprintf('Playbook category %s not found for team %s', $uuid, $team->getUuid())\n );\n }\n\n $ids[] = $playbookCategory->getId();\n }\n\n $reportData[$key] = $ids;\n }\n\n return $reportData;\n }\n\n private function validateReportStatus($status): bool\n {\n if (! in_array($status, [true, false], true)) {\n throw new InvalidArgumentException('Report status is invalid');\n }\n\n return $status;\n }\n\n private function validateReportType($type): string\n {\n if (! in_array($type, self::getTypes(), true)) {\n throw new InvalidArgumentException(sprintf('Report type is invalid: %s', $type));\n }\n\n return $type;\n }\n\n private function validateFrequency($frequency): string\n {\n if (! in_array($frequency, self::getFrequencies(), true)) {\n throw new InvalidArgumentException('Frequency is invalid');\n }\n\n return $frequency;\n }\n\n private function validateAdditionalPromptInput(?string $additionalPromptInput): ?string\n {\n if ($additionalPromptInput && strlen($additionalPromptInput) > 5000) {\n throw new InvalidArgumentException('Additional Prompt Input should be less than 5000 characters');\n }\n\n return $additionalPromptInput;\n }\n\n private function validateCustomReportName(?string $customReportName): ?string\n {\n if ($customReportName === null || $customReportName === '') {\n return null;\n }\n\n if (strlen($customReportName) > 70) {\n throw new InvalidArgumentException('Custom report name should be less than 70 characters');\n }\n\n return $customReportName;\n }\n\n private function validateOrganization(?string $organizationUuid): Team\n {\n if (! $organizationUuid) {\n throw new InvalidArgumentException('Organization is required');\n }\n\n $team = $this->teamRepository->idOrUuid($organizationUuid);\n\n if (! $team) {\n throw new InvalidArgumentException('Organization not found');\n }\n\n if (! $team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {\n throw new InvalidArgumentException('Organization does not have the Automated Reports feature');\n }\n\n return $team;\n }\n\n private function validateAndGetGroupIds(Team $team, array $teamUuids): array\n {\n $groupIds = [];\n\n foreach ($teamUuids as $uuid) {\n $group = $this->groupRepository->findByUuid($uuid);\n\n if ($group === null || $group->getTeamId() !== $team->getId()) {\n throw new InvalidArgumentException(\n sprintf('Group %s not found for team %s', $uuid, $team->getUuid())\n );\n }\n\n $groupIds[] = $group->getId();\n\n }\n\n return $groupIds;\n }\n\n private function validateAndGetDealStageIds(Team $team, array $stageUuids, string $propertyLabel): array\n {\n $stageIds = [];\n\n foreach ($stageUuids as $uuid) {\n $stage = $this->stageRepository->findByUuid($uuid);\n\n if ($stage === null || $stage->getTeamId() !== $team->getId()) {\n throw new InvalidArgumentException(\n sprintf('Stage %s not found for team %s for %s', $uuid, $team->getUuid(), $propertyLabel)\n );\n }\n\n $stageIds[] = $stage->getId();\n }\n\n return $stageIds;\n }\n\n private function validateAndGetUserIds(array $userUuids, callable $teamCheck): array\n {\n if (empty($userUuids)) {\n return [];\n }\n\n $userIds = [];\n\n foreach ($userUuids as $uuid) {\n $user = $this->userRepository->findByUuid($uuid);\n\n if (! $user || ! $user->isStatusActive()) {\n throw new InvalidArgumentException(\n sprintf('User %s not found or is not active', $uuid)\n );\n }\n\n if (! $teamCheck($user)) {\n throw new InvalidArgumentException(\n sprintf('User %s does not belong to the allowed team(s)', $uuid)\n );\n }\n\n $userIds[] = $user->getId();\n }\n\n return $userIds;\n }\n\n private function validateAndGetUserIdsByTeam(Team $team, array $userUuids): array\n {\n return $this->validateAndGetUserIds($userUuids, fn ($user) => $user->getTeamId() === $team->getId());\n }\n\n private function validateAndGetJiminnyUserIds(array $userUuids): array\n {\n $allowedTeamIds = config('kiosk.teamIds', []);\n\n return $this->validateAndGetUserIds($userUuids, fn ($user) => in_array($user->getTeamId(), $allowedTeamIds, true));\n }\n\n private function parseDate(string $dateString): string\n {\n return date('Y-m-d H:i:s', strtotime($dateString));\n }\n\n private function generateReportResultViewUrl(AutomatedReportResult $result): string\n {\n $mediaResource = $this->getReportMediaRouteResource($result);\n\n return route('ai-reports.' . $mediaResource . '.view', ['uuid' => $result->getUuid()]);\n }\n\n private function generateReportResultDownloadUrl(AutomatedReportResult $result): string\n {\n $mediaResource = $this->getReportMediaRouteResource($result);\n\n return route('ai-reports.' . $mediaResource . '.download', ['uuid' => $result->getUuid()]);\n }\n\n private function getReportMediaRouteResource(AutomatedReportResult $result): string\n {\n if ($result->getMediaType() === self::MEDIA_TYPE_PDF) {\n return self::PDF_KEY;\n } elseif ($result->getMediaType() === self::MEDIA_TYPE_PODCAST) {\n return self::AUDIO_KEY;\n }\n\n throw new \\InvalidArgumentException('Unknown media type.');\n }\n\n public function getMediaPath(AutomatedReportResult $result): ?string\n {\n $url = match ($result->getMediaType()) {\n self::MEDIA_TYPE_PDF => $result->getPdfUrl(),\n self::MEDIA_TYPE_PODCAST => $result->getPodcastAudioUrl(),\n default => null,\n };\n\n if ($url === null) {\n return null;\n }\n\n $path = parse_url(trim($url, '\"\\''), PHP_URL_PATH);\n\n return $path ?: null;\n }\n\n public function getFilenameSuffix(AutomatedReportResult $result): ?string\n {\n return match ($result->getMediaType()) {\n self::MEDIA_TYPE_PODCAST => 'Podcast',\n default => null,\n };\n }\n\n public function getMailSubjectSuffix(AutomatedReportResult $result): string\n {\n return match ($result->getMediaType()) {\n self::MEDIA_TYPE_PDF => 'report',\n self::MEDIA_TYPE_PODCAST => 'podcast',\n default => '',\n };\n }\n\n public function getMediaTypeMetadata(AutomatedReportResult $result): array\n {\n return match ($result->getMediaType()) {\n self::MEDIA_TYPE_PODCAST => ['extension' => 'mp3', 'mime' => 'audio/mpeg'],\n self::MEDIA_TYPE_PDF => ['extension' => 'pdf', 'mime' => 'application/pdf'],\n default => ['extension' => null, 'mime' => null],\n };\n }\n\n public function deleteS3Files(AutomatedReportResult $result): void\n {\n $teamUuid = $result->getReport()->getTeam()->getUuid();\n $reportUuid = $result->getUuid();\n\n // delete all files for a report uuid no mather of pdf, podcast, or both\n // in case of both - the podcast files are linked to the pdf (parent) uuid\n // pdf and podcast date times should be close\n $path = sprintf('%s/%s/%s', $teamUuid, self::S3_DIR, $reportUuid);\n\n foreach (self::FILE_EXTENSIONS_VARIANTS as $extension) {\n $file = $path . '.' . $extension;\n\n if (Storage::exists($file)) {\n Storage::delete($file);\n Log::info('[Reports] Deleted S3 file', [\n 'path' => $file,\n ]);\n }\n }\n\n foreach (self::FILE_PODCAST_EXTENSIONS_VARIANTS as $extension) {\n $file = $path . '_podcast.' . $extension;\n\n if (Storage::exists($file)) {\n Storage::delete($file);\n Log::info('[Reports] Deleted Podcast S3 file', [\n 'path' => $file,\n ]);\n }\n }\n }\n\n /**\n *\n * @param int|null $teamId Optional team ID to filter results\n *\n * @return Collection<int, int> Collection of team IDs\n */\n public function getTeamIdsWithReportsResults(?int $teamId = null): Collection\n {\n return $this->automatedReportsRepository->getTeamIdsWithReportsResults($teamId);\n }\n\n /**\n * Core delete logic for report results using a query\n *\n * @param Builder $query\n * @param array $logContext\n *\n * @return int\n */\n private function deleteReportResultsByQuery(Builder $query, array $logContext = []): int\n {\n $deletedCount = 0;\n\n if ($query->exists()) {\n Log::info(\n 'Run delete report results',\n array_merge(\n $logContext,\n [\n 'service' => 'AutomatedReportsService',\n ]\n )\n );\n\n $query->chunkById(50, function ($results) use (&$deletedCount, $logContext) {\n foreach ($results as $result) {\n $this->deleteReportResult($result);\n $deletedCount++;\n\n Log::info(\n 'Deleted a report result',\n array_merge(\n $logContext,\n [\n 'result_id' => $result->getId(),\n 'report_id' => $result->getReportId(),\n ]\n )\n );\n }\n });\n }\n\n return $deletedCount;\n }\n\n /**\n * Delete report results for a team by retention period\n *\n * @param Team $team\n * @param CarbonImmutable $retentionDate\n *\n * @return int Number of deleted report results\n */\n public function deleteReportsResultsInRetentionPeriod(Team $team, CarbonImmutable $retentionDate): int\n {\n $reportIds = $this->automatedReportsRepository->getReportIdsByTeam($team);\n\n if ($reportIds->isEmpty()) {\n return 0;\n }\n\n $query = $this->automatedReportsRepository\n ->getReportResultsQueryForRetention($team, $retentionDate);\n\n return $this->deleteReportResultsByQuery($query, [\n 'team_id' => $team->getId(),\n 'retention_date' => $retentionDate->toDateTimeString(),\n ]);\n }\n\n /**\n * Delete ALL report results for a specific automated report\n *\n * @param string $uuid\n *\n * @return int\n */\n public function deleteReportResults(string $uuid): int\n {\n $report = $this->getReport($uuid);\n\n $query = $this->automatedReportsRepository->getResultsByReportQuery($report);\n\n return $this->deleteReportResultsByQuery($query, [\n 'report_uuid' => $uuid,\n 'report_id' => $report->getId(),\n ]);\n }\n\n public function deleteReportResult(AutomatedReportResult $result): void\n {\n $this->deleteS3Files($result);\n\n $result->delete();\n }\n\n /**\n * Get all reports for a specific team\n *\n * @param Team $team\n *\n * @return \\Illuminate\\Database\\Eloquent\\Collection\n */\n public function getTeamReports(Team $team): \\Illuminate\\Database\\Eloquent\\Collection\n {\n return $this->automatedReportsRepository->getReportsByTeam($team);\n }\n\n /**\n * Get all report results for a specific report\n *\n * @param AutomatedReport $report\n *\n * @return \\Illuminate\\Database\\Eloquent\\Collection\n */\n public function getReportResults(AutomatedReport $report): \\Illuminate\\Database\\Eloquent\\Collection\n {\n return $this->automatedReportsRepository->getResultsByReport($report);\n }\n\n public function deleteAllReportResults(AutomatedReport $report): void\n {\n $results = $this->getReportResults($report);\n\n /** @var AutomatedReportResult $result */\n foreach ($results as $result) {\n Log::info('Deleting result', [\n 'report' => $report->getId(),\n 'result' => $result->getId(),\n ]);\n\n $this->deleteReportResult($result);\n }\n }\n\n public function deleteAllData(Team $team): void\n {\n Log::info('Deleting automated report and results for team', [\n 'team' => $team->getId(),\n ]);\n\n $reports = $this->getTeamReports($team);\n\n /** @var AutomatedReport $report */\n foreach ($reports as $report) {\n Log::info('Deleting report', [\n 'team' => $team->getId(),\n 'report' => $report->getId(),\n ]);\n\n $this->deleteAllReportResults($report);\n\n $report->delete();\n }\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":true,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"Project","depth":3,"role_description":"text"},{"role":"AXButton","text":"Project","depth":3,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"New File or Directory…","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Expand Selected","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Collapse All","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Options","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false}]...
|
3397592283435315795
|
6686367547760219213
|
idle
|
accessibility
|
NULL
|
Project: faVsco.js, menu
#11894 on JY-18909-automa Project: faVsco.js, menu
#11894 on JY-18909-automated-reports-ask-jiminny, menu
Start Listening for PHP Debug Connections
AutomatedReportsCommandTest
Run 'AutomatedReportsCommandTest'
Debug 'AutomatedReportsCommandTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Execute
Explain Plan
Browse Query History
View Parameters
Open Query Execution Settings…
In-Editor Results
Tx: Auto
Cancel Running Statements
Playground
jiminny
Sync Changes
Hide This Notification
Code changed:
Hide
16
13
13
Previous Highlighted Error
Next Highlighted Error
SELECT * FROM teams WHERE id = 1;
select * from crm_layouts where crm_configuration_id = 39;
SELECT * FROM crm_layout_entities WHERE crm_layout_id = 283;
SELECT * FROM crm_fields WHERE id = 2234;
SELECT * FROM crm_field_values WHERE crm_field_id = 2234;
select * from crm_profiles where user_id = 143;
select * from record_types where crm_configuration_id = 39; # 0121K000001MHElQAO,0121K000001MHEqQAO
select * from business_processes where crm_configuration_id = 39;
# 01941000000H669AAC, 01941000000H66JAAS
select * from record_type_field_values
where record_type_id IN (24);
select * from crm_field_values where id IN (2730);
select * from crm_configurations where id = 39;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 1
and sa.provider = 'salesforce'; #1035
select * from users where team_id = 1; # 222 group 3
SELECT * FROM activities WHERE user_id = 222 order by id desc;
select * from sidekick_settings where team_id = 1;
select * from teams where id = 1;
select * from team_features where team_id = 1;
select * from activities where crm_configuration_id = 2
and provider = 'ms-teams' and id = 608765;
SELECT * FROM activities WHERE crm_configuration_id = 2 and crm_provider_id = '59523413338';
select * from sidekick_settings where team_id = 2;
SELECT * FROM activities WHERE id = 608660;
select * from activity_summary_logs where activity_id = 608660;
select * from ai_prompts where transcription_id = 11214;
# [PASSWORD_DOTS]
SELECT * FROM activities WHERE uuid_to_bin('ed78a437-2804-450e-ab2f-56ab1c641346') = uuid;
# id: 608818, crm: 59628809737
SELECT * FROM activities WHERE uuid_to_bin('36b06e55-afdd-4782-8dee-c624cd0af191') = uuid;
# id: 608821, crm: 59632069252
SELECT ce.start_time, ce.end_time, a.id, a.uuid, crm_provider_id, calendar_event_id, title,
playbook_category_id, user_id, lead_id, contact_id, account_id, opportunity_id,
scheduled_start_time, scheduled_end_time, actual_start_time, actual_end_time, a.created_at
FROM activities a
join calendar_events ce on a.calendar_event_id = ce.id
WHERE a.id IN (608818, 608821);
select * from users where team_id = 1;
select * from team_settings where team_id = 1;
select * from crm_profiles where crm_configuration_id = 39 order by user_id;
select * from team_features where team_id = 1;
select * from users where team_id = 2;
SELECT * FROM activities WHERE uuid_to_bin('ec7647e9-5225-458b-b475-f31aa2769204') = uuid; # 612639
# Preslava N. Ivanova, grou id 3
SELECT * FROM opportunities WHERE uuid_to_bin('a2928fe5-aec5-46cb-85d9-7654c89e46a6') = uuid;
select * from activities where opportunity_id = 344 and actual_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00';
select
a.id,
a.type,
a.scheduled_start_time,
a.actual_start_time,
a.created_at,
a.opportunity_id,
a.status
FROM activities a
WHERE opportunity_id = 344
and status IN ('completed', 'received', 'delivered')
and (
(a.actual_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00')
OR (a.created_at between '2024-10-11 00:00:00' and '2024-10-12 00:00:00')
OR (a.scheduled_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00'))
;
SELECT * FROM users WHERE id = 222;
SELECT * FROM crm_profiles WHERE user_id = 222;
select * from crm_layouts where crm_configuration_id = 39;
SELECT * FROM crm_layout_entities WHERE crm_layout_id = 281;
select * from group_deal_risk_types;
select * from opportunities where team_id = 1;
SELECT * FROM opportunities WHERE id = 315;
SELECT * FROM crm_field_data WHERE object_id = 315;
select * from crm_field_data where object_id = 260;
select * from generic_ai_prompts where subject_id = 315;
select * from teams; # 36, 21, 121, [EMAIL]
SELECT * FROM social_accounts WHERE sociable_id = 121 and provider = 'bullhorn';
# [PASSWORD_DOTS]
select * from teams where id = 1;
select * from crm_configurations where id = 39;
select * from users where team_id = 1;
select u.email, cp.* from users u
join crm_profiles cp on u.id = cp.user_id
where u.team_id = 1;
# 1 - 00541000004281rAAA
# 204 - 0052g000003freeAAA
# 429 - 0052g000003qGOiAAM
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 1
and sa.provider = 'salesforce';
select * from activities where type = 'softphone'
and created_at > '2024-12-11 15:24:36' order by id desc;
select * from activity_providers where team_id = 1;
select * from activity_provider_users where activity_provider_id = 328;
select * from opportunities where crm_configuration_id = 39
AND account_id = 178 AND is_closed = false
order by created_at DESC;
select * from contacts where id = 3952;
select * from accounts where id = 178;
# [PASSWORD_DOTS]
select * from teams where id = 36;
select * from crm_configurations where id = 21;
select * from users where team_id = 36;
select u.email, cp.* from users u
join crm_profiles cp on u.id = cp.user_id
where u.team_id = 36;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 36
and sa.provider = 'bullhorn';
select * from social_accounts where id = 348;
UPDATE social_accounts SET
provider_user_token = '21442_6802599_91:41179a58-21e7-4d7c-ad58-56bb666b2f65',
provider_refresh_token = '21442_6802599_91:01c6b335-3f2a-42e4-85ff-8a08fa65fceb',
expires = 1733998131,
state = 'connected'
WHERE id = 348;
# [PASSWORD_DOTS]
select * from teams where id = 31;
select * from crm_configurations where id = 18;
select * from users where team_id = 31; # 257
select u.email, cp.* from users u
join crm_profiles cp on u.id = cp.user_id
where u.team_id = 31;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 31
and sa.provider = 'close';
select * from contacts where crm_configuration_id = 18;
# [PASSWORD_DOTS] NEPTUNE [PASSWORD_DOTS]
select * from teams;
select * from users where id IN (1030, 1035, 1052);
select * from crm_configurations;
select * from users where team_id = 65; # 257
select * from team_settings where team_id = 65; # 257
select * from invitations where team_id = 65; # 257
select * from users where email = '[EMAIL]'; # 257
select u.email, cp.* from users u
join crm_profiles cp on u.id = cp.user_id
where u.team_id = 65;
select * from crm_configurations where id = 53;
select * from accounts where crm_configuration_id = 53 order by id desc;
select * from leads where crm_configuration_id = 53 order by id desc;
select * from contacts where crm_configuration_id = 53 order by id desc;
select * from opportunities where crm_configuration_id = 53 order by id desc;
select * from crm_profiles where crm_configuration_id = 53 order by id desc;
select * from crm_fields where crm_configuration_id = 53 order by id desc;
select * from crm_field_values where crm_field_id = 3341 order by id desc;
select * from crm_layouts where crm_configuration_id = 53 order by id desc;
select * from stages where crm_configuration_id = 53 order by id desc;
select * from crm_profiles where crm_configuration_id = 13;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 65
and sa.provider = 'integration-app';
select * from contacts where crm_configuration_id = 13;
select * from social_accounts where sociable_id = 283;
SELECT * FROM opportunities WHERE crm_provider_id = '006O400000E9bzeIAB';
select * from activity_providers where team_id = 65;
SELECT * FROM activities WHERE crm_configuration_id IN (51, 52, 53);
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 65
;
# [PASSWORD_DOTS] STAGING [PASSWORD_DOTS]
SELECT * FROM teams;
SELECT * FROM teams WHERE id = 88;
SELECT * FROM teams WHERE id = 89;
select * from team_settings where team_id = 89;
SELECT * FROM users WHERE team_id = 89;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 89;
select * from users;
SELECT * FROM social_accounts WHERE sociable_id = 1761;
SELECT * FROM crm_configurations WHERE id = 70;
select * from accounts where crm_configuration_id = 70 order by id desc;
select * from leads where crm_configuration_id = 70 order by id desc;
select * from contacts where crm_configuration_id = 70 order by id desc;
select * from opportunities where crm_configuration_id = 70 order by id desc;
select * from crm_profiles where crm_configuration_id = 70 order by id desc;
select * from crm_fields where crm_configuration_id = 70 order by id desc;
select * from crm_field_values where crm_field_id = 3536 order by id desc;
select * from crm_layouts where crm_configuration_id = 70 order by id desc;
select * from stages where crm_configuration_id = 70 order by id desc;
select * from business_processes where crm_configuration_id = 70 order by id desc;
select * from business_process_stages where business_process_id = 34;
select * from contacts where id = 10468;
select * from crm_layouts where crm_configuration_id = 70;
SELECT * FROM crm_layout_entities WHERE crm_layout_id = 388;
SELECT * FROM crm_fields WHERE id IN (3533,3534,3535);
select * from activities where crm_configuration_id = 70
and (account_id IS NOT NULL or lead_id IS NOT NULL or contact_id IS NOT NULL or opportunity_id IS NOT NULL) order by id desc;
SELECT * FROM activities WHERE uuid_to_bin('2e10b60f-8a61-41c5-a3d4-28835353dc65') = uuid;
SELECT * FROM activities where crm_configuration_id = 69 ;
SELECT * FROM users WHERE email LIKE '%[EMAIL]%';
SELECT * FROM activities WHERE uuid_to_bin('5a150c93-40fc-42ec-b3bd-c1d328e09f6e') = uuid;
SELECT * FROM opportunities WHERE id = 385;
select * from participants p
join activities a on p.activity_id = a.id
where a.crm_configuration_id = 70
and (p.lead_id IS NOT NULL or p.contact_id IS NOT NULL);
SELECT * FROM participants WHERE id = 1013638;
select * from teams where id = 90;
select * from users where team_id = 90;
select * from social_accounts where social_accounts.sociable_id IN (1960,1760);
SELECT * FROM crm_profiles WHERE crm_configuration_id = 71;
select * from invitations where team_id = 90;
select * from crm_configurations where id = 71;
select * from accounts where crm_configuration_id = 71 order by id desc;
select * from leads where crm_configuration_id = 71 order by id desc;
select * from contacts where crm_configuration_id = 71 order by id desc;
select * from opportunities where crm_configuration_id = 71 order by id desc;
select * from crm_profiles where crm_configuration_id = 71 order by id desc;
select * from crm_fields where crm_configuration_id = 71 order by id desc;
select * from crm_field_values where crm_field_id = 3341 order by id desc;
select * from crm_layouts where crm_configuration_id = 71 order by id desc;
select * from stages where crm_configuration_id = 71 order by id desc;
select * from users order by secondary_email desc;
select u.id, u.email, u.status, sa.id, sa.provider_user_id from social_accounts sa
join users u on sa.sociable_id = u.id
where sa.provider = 'google' and u.email LIKE 'aneliya%';
select * from failed_jobs order by id desc;
select * from users where email = '[EMAIL]' or secondary_email = '[EMAIL]';
select * from teams;
SELECT * FROM crm_profiles WHERE crm_configuration_id = 39;
SELECT * FROM crm_fields WHERE crm_configuration_id = 39 and object_type = 'task';
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 1
and sa.provider = 'salesforce';
# [PASSWORD_DOTS]
SELECT * FROM activities WHERE uuid_to_bin('c38b3895-fd0f-4b1f-9fb2-c170dba137c6') = uuid;
SELECT * FROM crm_configurations WHERE id = 70;
select * from teams where id = 1;
select * from groups where team_id = 1;
select * from users where team_id = 1;
select o.id, o.name,o.close_date, u.id, u.name, u.group_id, r.id, r.display_name, g.name, g.scope from opportunities o
join users u on o.user_id = u.id
join groups g on u.group_id = g.id
join role_user ru on u.id = ru.user_id
join roles r on ru.role_id = r.id
where o.crm_configuration_id = 39 and close_date > '2024-01-01 00:00:00';
select * from role_user where user_id = 143;
select * from roles;
select * from role_user;
select * from groups where id = 9;
select * from scope_groups where group_id = 9;
# [PASSWORD_DOTS]
select * from teams where id = 36;
select * from crm_configurations;
SELECT * FROM social_accounts WHERE sociable_id = 121;
[URL_WITH_CREDENTIALS] this will add filter, however if we need to control feature by FF we need conditional logic
public const array TYPES = [
['id' => 'exec_summary', 'name' => 'Exec Summary'],
['id' => 'coaching_profiles', 'name' => 'Coaching Profiles'],
['id' => 'product_feedback', 'name' => 'Product Feedback'],
['id' => self::TYPE_LOSS_ANALYSIS, 'name' => 'Loss Analysis'],
// ['id' => 'questions', 'name' => 'Questions'],
// ['id' => 'statistical_quant', 'name' => 'Statistical Quantitative'],
];
public const array ALL_TYPES = [
...self::TYPES,
['id' => self::TYPE_ASK_JIMINNY, 'name' => 'Ask Jiminny'],
];
public const string FREQUENCY_DAILY = 'daily';
public const string FREQUENCY_WEEKLY = 'weekly';
public const string FREQUENCY_MONTHLY = 'monthly';
public const string FREQUENCY_QUARTERLY = 'quarterly';
public const string FREQUENCY_ONE_OFF = 'one_off';
/**
* Frequencies for standard (non-Ask Jiminny) reports.
*/
public const array FREQUENCIES = [
['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],
['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],
['id' => self::FREQUENCY_QUARTERLY, 'name' => 'Quarterly'],
['id' => self::FREQUENCY_ONE_OFF, 'name' => 'One-off'],
];
/**
* Frequencies for Ask Jiminny reports.
*/
public const array ASK_JIMINNY_FREQUENCIES = [
['id' => self::FREQUENCY_DAILY, 'name' => 'Daily'],
['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],
['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],
];
public const string MEDIA_TYPE_PDF = 'pdf';
public const string MEDIA_TYPE_PODCAST = 'podcast';
public const array MEDIA_TYPES = [self::MEDIA_TYPE_PDF, self::MEDIA_TYPE_PODCAST];
public const array MEDIA_TYPE_OBJECT_PDF = ['id' => self::MEDIA_TYPE_PDF, 'name' => 'PDF'];
public const array MEDIA_TYPE_OBJECT_PODCAST = ['id' => self::MEDIA_TYPE_PODCAST, 'name' => 'Podcast'];
public const array MEDIA_TYPE_OBJECTS = [self::MEDIA_TYPE_OBJECT_PDF, self::MEDIA_TYPE_OBJECT_PODCAST];
public const array CALL_TYPE_CONFERENCE = ['id' => 'conference', 'name' => 'Conference'];
public const array CALL_TYPE_DIALER = ['id' => 'dialer', 'name' => 'Dialer'];
public const int SENT_REPORT_AT_HOURS = 5;
public const string PDF_KEY = 'pdf';
public const string AUDIO_KEY = 'audio';
private const array ALL_FREQUENCIES = [
['id' => self::FREQUENCY_DAILY, 'name' => 'Daily'],
['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],
['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],
['id' => self::FREQUENCY_QUARTERLY, 'name' => 'Quarterly'],
['id' => self::FREQUENCY_ONE_OFF, 'name' => 'One-off'],
];
private const string S3_DIR = 'reports';
private const array FILE_EXTENSIONS_VARIANTS = ['html', 'MD', 'pdf'];
private const array FILE_PODCAST_EXTENSIONS_VARIANTS = ['json', 'mp3', 'ssml'];
public function __construct(
private readonly TeamRepository $teamRepository,
private readonly GroupRepository $groupRepository,
private readonly UserRepository $userRepository,
private readonly StageRepository $stageRepository,
private readonly DealStagesService $dealStagesService,
private readonly RecipientsService $recipientsService,
private readonly AutomatedReportsRepository $automatedReportsRepository,
private readonly Webhook $webhookService,
private readonly BusDispatcher $dispatcher,
private readonly ActivityTypeService $activityTypeService,
private readonly PlaybookCategoryRepository $playbookCategoryRepository,
private readonly AskAnythingPromptService $askAnythingPromptService,
private readonly SearchRepository $activitySearchRepository,
private readonly AskAnythingRepository $askAnythingRepository,
) {
}
public static function getTypes(): array
{
$types = self::TYPES;
return array_map(static function ($type) {
return $type['id'];
}, $types);
}
public static function getCallTypes(): array
{
return array_map(static function ($callType) {
return $callType['id'];
}, [self::CALL_TYPE_CONFERENCE, self::CALL_TYPE_DIALER]);
}
public static function getFrequencies(): array
{
return array_map(static function ($frequency) {
return $frequency['id'];
}, self::FREQUENCIES);
}
// front-facing structure
public function getReportEnabledFieldData(bool $value = false): array
{
return [
'id' => 'report_enabled',
'label' => '',
'inputType' => InputTypeEnum::TOGGLE,
'value' => $value,
];
}
// Organizations = Teams
public function getOrganizationFieldData(?string $value = null, bool $shortVersion = false): array
{
$options = $this->getTeams();
if ($shortVersion) {
return [
'id' => 'organization',
'label' => 'Organization',
'options' => $options,
];
}
return [
'id' => 'organization',
'label' => 'Organization',
'inputType' => InputTypeEnum::DROPDOWN,
'required' => true,
'placeholder' => 'Select',
'options' => $options,
'value' => $value,
'dependencies' => [
'teams',
'deal_stage_at_call',
'current_deal_stage',
'recipients',
ActivityTypeService::PLAYBOOK_CATEGORIES_KEY,
],
'dependsOn' => [],
];
}
// Teams = Groups
public function getTeamFieldData(array $options = [], array $value = [], bool $shortVersion = false): array
{
if ($shortVersion) {
return [
'id' => 'teams',
'label' => 'Team',
'options' => $options,
];
}
return [
'id' => 'teams',
'label' => 'Team',
'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,
'required' => false,
'placeholder' => 'Select',
'options' => $options,
'value' => $value, // value should be an array of objects {id, name}
'dependencies' => [ActivityTypeService::PLAYBOOK_CATEGORIES_KEY],
'dependsOn' => [],
];
}
public function getReportTypeFieldData(?string $value = null, bool $shortVersion = false, ?Team $team = null): array
{
$types = [];
if ($team instanceof Team) {
if ($team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {
$types = self::TYPES;
}
if ($team->hasFeature(FeatureEnum::ASK_JIMINNY_REPORTS)) {
$types[] = ['id' => self::TYPE_ASK_JIMINNY, 'name' => 'Ask Jiminny'];
}
} else {
$types = self::TYPES;
}
if ($shortVersion) {
return [
'id' => 'report_type',
'label' => 'Report Type',
'options' => $types,
];
}
return [
'id' => 'report_type',
'label' => 'Report Type',
'inputType' => InputTypeEnum::DROPDOWN,
'required' => true,
'placeholder' => 'Select',
'options' => $types,
'value' => $value,
'dependencies' => [],
'dependsOn' => [],
];
}
public function getFrequencyFieldData(?string $value = null): array
{
return [
'id' => 'frequency',
'label' => 'Frequency',
'inputType' => InputTypeEnum::DROPDOWN,
'required' => true,
'placeholder' => 'Select',
'options' => self::FREQUENCIES,
'value' => $value,
'dependencies' => ['period'],
'dependsOn' => [],
];
}
public function getPeriodFieldData(?string $valueStartDate = null, ?string $valueEndDate = null): array
{
return [
'id' => 'period',
'label' => 'Select one-off period',
'inputType' => InputTypeEnum::DATE_RANGE,
'required' => true,
'placeholder' => 'Select',
'value' => ['startDate' => $valueStartDate, 'endDate' => $valueEndDate],
'queryParams' => [
'startDate' => 'start_date_period',
'endDate' => 'end_date_period',
],
'dependencies' => [],
'dependsOn' => ['frequency'],
];
}
public function getActivityTypesFieldData(?Team $team = null, array $value = [], array $teamsFilter = []): array
{
return $this->activityTypeService->getActivityTypeFieldData(team: $team, value: $value, groupIds: $teamsFilter);
}
public function getDealStageAtCallFieldData(?Team $team = null, array $value = []): array
{
return $this->dealStagesService->getDealStageAtCallFieldData(team: $team, value: $value);
}
public function getCurrentDealStageFieldData(?Team $team = null, array $value = []): array
{
return $this->dealStagesService->getCurrentDealStageFieldData(team: $team, value: $value);
}
public function getDealValueFieldData(?int $valueMin = null, ?int $valueMax = null): array
{
return [
'id' => 'deal_value',
'label' => 'Deal Value',
'inputType' => InputTypeEnum::INTEGER_RANGE,
'required' => false,
'value' => ['min' => $valueMin, 'max' => $valueMax],
'queryParams' => [
'min' => 'min_deal_value',
'max' => 'max_deal_value',
],
'dependencies' => [],
'dependsOn' => [],
];
}
public function getCallTypeFieldData(bool $conferenceOn = false, bool $dialerOn = false): array
{
$value = [];
$conferenceOn && $value[] = self::CALL_TYPE_CONFERENCE;
$dialerOn && $value[] = self::CALL_TYPE_DIALER;
return [
'id' => 'call_type',
'label' => 'Call Type',
'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,
'required' => true,
'options' => [
self::CALL_TYPE_CONFERENCE,
self::CALL_TYPE_DIALER,
],
'value' => $value,
'dependencies' => [],
'dependsOn' => [],
];
}
public function getMediaTypeFieldData(?AutomatedReport $report = null): array
{
$value = [];
if ($report) {
$value = $this->transformMediaTypes($report);
}
return [
'id' => 'media_types',
'label' => 'Export as',
'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,
'required' => true,
'options' => self::MEDIA_TYPE_OBJECTS,
'value' => $value,
'dependencies' => [],
'dependsOn' => [],
];
}
public function getCallDurationFieldData(?int $valueMin = null, ?int $valueMax = null): array
{
return [
'id' => 'call_duration',
'label' => 'Call Duration',
'inputType' => InputTypeEnum::INTEGER_RANGE,
'required' => false,
'value' => ['min' => $valueMin, 'max' => $valueMax],
'queryParams' => [
'min' => 'min_call_duration',
'max' => 'max_call_duration',
],
'dependencies' => [],
'dependsOn' => [],
];
}
public function getRecipientsFieldData(?Team $team = null, array $value = []): array
{
return $this->recipientsService->getRecipientsFieldData(team: $team, value: $value);
}
public function getJiminnyRecipientsFieldData(array $value = []): array
{
return $this->recipientsService->getJiminnyRecipientsFieldData($value);
}
public function getAdditionalPromptInputFieldData(?string $value = null): array
{
return [
'id' => 'additional_prompt_input',
'label' => 'Special requirements',
'inputType' => InputTypeEnum::TEXTAREA,
'required' => false,
'placeholder' => 'What should be the focus of the report?',
'value' => $value,
'dependencies' => [],
'dependsOn' => [],
];
}
public function getCustomReportNameFieldData(?string $value = null): array
{
return [
'id' => 'custom_name',
'label' => 'Custom report name',
'inputType' => InputTypeEnum::TEXT,
'required' => false,
'placeholder' => 'Enter custom name',
'value' => $value,
'dependencies' => [],
'dependsOn' => [],
];
}
// data providers
public function getTeams(): array
{
$teams = $this->teamRepository->getTeamsForKiosk(status: Team::STATUS_ACTIVE);
$teamData = [];
foreach ($teams as $team) {
if (! $team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {
continue;
}
$teamData[] = $this->transformTeam($team);
}
return $teamData;
}
public function getTeamGroups(string $teamUuid): array
{
$data = [];
$team = $this->getTeam($teamUuid);
if ($team !== null) {
$groups = $team->groups()->get();
foreach ($groups as $group) {
$data[] = [
'id' => $group->getUuid(),
'name' => $group->getName(),
];
}
}
return $data;
}
public function getTeamsGroupsOptions(array $filterTeamUuids = []): array
{
$data = [];
$teams = $this->getTeams();
foreach ($teams as $team) {
if (! empty($filterTeamUuids) && ! in_array($team['id'], $filterTeamUuids, true)) {
continue;
}
$data[] = [
'label' => $team['name'],
'groups' => $this->getTeamGroups($team['id']),
];
}
return $data;
}
public function getTeam(string $teamUuid): ?Team
{
return $this->teamRepository->idOrUuid($teamUuid);
}
public function getTeamById(int $teamId): ?Team
{
return $this->teamRepository->find($teamId);
}
public function getGroupsUuids(AutomatedReport $report): array
{
$uuids = [];
$reportGroups = $report->getGroups();
foreach ($reportGroups as $groupId) {
if ($group = $this->groupRepository->find($groupId)) {
$uuids[] = $group->getUuid();
}
}
return $uuids;
}
public function getPlaybookCategoriesUuids(AutomatedReport $report): array
{
$uuids = [];
$playbookCategories = $report->getPlaybookCategories();
foreach ($playbookCategories as $id) {
if ($category = $this->playbookCategoryRepository->find($id)) {
$uuids[] = $category->getUuid();
}
}
return $uuids;
}
public function getDealAtCallStagesUuids(AutomatedReport $report): array
{
$uuids = [];
$reportStages = $report->getDealAtCallStages();
foreach ($reportStages as $id) {
if ($stage = $this->stageRepository->find($id)) {
$uuids[] = $stage->getUuid();
}
}
return $uuids;
}
public function getCurrentDealStagesUuids(AutomatedReport $report): array
{
$uuids = [];
$reportStages = $report->getCurrentDealStages();
foreach ($reportStages as $id) {
if ($stage = $this->stageRepository->find($id)) {
$uuids[] = $stage->getUuid();
}
}
return $uuids;
}
public function getUsersUuids(AutomatedReport $report): array
{
return $this->extractUserUuids($report->getRecipients());
}
public function getJiminnyUsersUuids(AutomatedReport $report): array
{
return $this->extractUserUuids($report->getJiminnyRecipients());
}
/**
* @param array<string, mixed> $recipients
*/
private function extractUserUuids(array $recipients): array
{
$userIds = $recipients['users'] ?? [];
return collect($userIds)
->map(fn ($id) => $this->userRepository->find((int) $id))
->filter()
->map(fn (UserContract $user) => $user->getUuid())
->values()
->all();
}
// get mail data
public function getRecipientUsers(AutomatedReport $report): array
{
return $this->buildRecipientUsers($report->getRecipients());
}
private function getJiminnyRecipientUsers(AutomatedReport $report): array
{
return $this->buildRecipientUsers($report->getJiminnyRecipients());
}
/**
* @param array<string, mixed> $recipients
*/
private function buildRecipientUsers(array $recipients): array
{
$userIds = $recipients['users'] ?? [];
return collect($userIds)
->map(fn ($id) => $this->userRepository->find((int) $id))
->filter()
->map(fn (UserContract $user) => [
'email' => $user->getEmailAddress(),
'name' => $user->getName(),
'timezone' => $user->getTimezone()->getName(),
])
->values()
->all();
}
public function getValidRecipientUsers(AutomatedReport $report, bool $includeJiminny = false): array
{
if ($report->isAskJiminnyReport()) {
$recipients = $this->resolveAskJiminnyRecipients($report);
} else {
$recipients = $this->getRecipientUsers($report);
if ($includeJiminny) {
$recipients = array_merge($recipients, $this->getJiminnyRecipientUsers($report));
}
}
$emails = [];
return array_values(array_filter(
$recipients,
static function ($recipient) use (&$emails) {
if (empty($recipient['email']) || in_array($recipient['email'], $emails, true)) {
return false;
}
$emails[] = $recipient['email'];
return true;
}
));
}
private function resolveAskJiminnyRecipients(AutomatedReport $report): array
{
$recipients = [];
$creator = $report->getCreator();
if ($creator !== null) {
$recipients[] = [
'email' => $creator->getEmailAddress(),
'name' => $creator->getName(),
'timezone' => $creator->getTimezone()->getName(),
];
}
return array_merge(
$recipients,
$this->buildRecipientUsers($report->getRecipients()),
$this->getGroupRecipientUsers($report),
);
}
private function getGroupRecipientUsers(AutomatedReport $report): array
{
$users = [];
foreach ($report->getGroups() as $groupId) {
$group = $this->groupRepository->find($groupId);
if ($group === null) {
continue;
}
foreach ($group->getMembers() as $member) {
$users[] = [
'email' => $member->getEmailAddress(),
'name' => $member->getName(),
'timezone' => $member->getTimezone()->getName(),
];
}
}
return $users;
}
public function getReportTypeName(AutomatedReportResult $report): string
{
$type = $report->getReport()->getType();
$getType = $this->transformReportType($type);
return $getType['name'];
}
public function getReportPeriodName(AutomatedReportResult $report): string
{
$from = $report->getFromDate();
$to = $report->getToDate();
$frequency = $report->getReport()->getFrequency();
if ($from === null || $to === null) {
if (! $report->getReport()->isAskJiminnyReport()) {
$invalidPeriod = $from === null ? 'from' : 'to';
throw new ApplicationException('Report period is invalid: ' . $invalidPeriod);
}
$period = $this->calculateFromAndToDatePeriod($frequency);
$from = $period['fromDate'];
$to = $period['toDate'];
}
return $this->formatReportPeriodName($frequency, $from, $to);
}
private function formatReportPeriodName(string $frequency, Carbon $from, Carbon $to): string
{
$fromYear = $from->format('Y');
$toYear = $to->format('Y');
$differentYears = $fromYear !== $toYear;
switch ($frequency) {
case self::FREQUENCY_DAILY:
return $from->format('j M Y');
case self::FREQUENCY_QUARTERLY:
// 'Jan-Mar 2025' or 'Nov 2024-Jan 2025' if years differ
$startMonth = $from->format('M');
$endMonth = $to->copy()->subMonth();
$endMonthName = $endMonth->format('M');
$endMonthYear = $endMonth->format('Y');
if ($differentYears) {
return "{$startMonth} {$fromYear} - {$endMonthName} {$endMonthYear}";
}
return "{$startMonth} - {$endMonthName} {$toYear}";
case self::FREQUENCY_MONTHLY:
// 'May 2025' - monthly reports are always within the same year
return $from->format('M Y');
case self::FREQUENCY_WEEKLY:
// '4 - 8 Aug 2025', '27 Oct - 3 Nov 2025', or '28 Dec 2024 - 3 Jan 2025' if years differ
$startDay = $from->format('j');
$endDay = $to->format('j');
$startMonth = $from->format('M');
$endMonth = $to->format('M');
if ($differentYears) {
return "{$startDay} {$startMonth} {$fromYear} - {$endDay} {$endMonth} {$toYear}";
}
if ($startMonth !== $endMonth) {
return "{$startDay} {$startMonth} - {$endDay} {$endMonth} {$toYear}";
}
return "{$startDay} - {$endDay} {$endMonth} {$toYear}";
case self::FREQUENCY_ONE_OFF:
// '2 May-31 May 2025' or '15 Dec 2024-15 Jan 2025' if years differ
$startDay = $from->format('j');
$startMonth = $from->format('M');
$endDay = $to->format('j');
$endMonth = $to->format('M');
// If same month and year, use a format like '2-31 May 2025'
if ($startMonth === $endMonth && ! $differentYears) {
return "{$startDay} - {$endDay} {$startMonth} {$toYear}";
}
// If different years, include both years
if ($differentYears) {
return "{$startDay} {$startMonth} {$fromYear} - {$endDay} {$endMonth} {$toYear}";
}
// Same year but different months
return "{$startDay} {$startMonth} - {$endDay} {$endMonth} {$toYear}";
default:
// Default format for unknown frequencies
return $from->format('j M Y') . ' - ' . $to->format('j M Y');
}
}
public function getReportTeamsName(AutomatedReportResult $report): string
{
$groups = $report->getGroups();
if (empty($groups)) {
return 'All';
}
// Get group names from repository
$groupNames = [];
foreach ($groups as $groupId) {
$group = $this->groupRepository->find($groupId);
if ($group) {
$groupNames[] = $group->getName();
}
}
if (count($groupNames) === 1) {
// Single team format
$teamsName = $groupNames[0];
} else {
// Multiple teams format
$teamsName = implode(', ', $groupNames);
}
return $teamsName;
}
public function getReportFileName(AutomatedReportResult $report): string
...
|
12308
|
|
12323
|
262
|
0
|
2026-04-14T11:05:30.934588+00:00
|
/Users/lukas/.screenpipe/data/data/2026-04-14/1776 /Users/lukas/.screenpipe/data/data/2026-04-14/1776164730934_m1.jpg...
|
PhpStorm
|
faVsco.js – AutomatedReportsService.php
|
1
|
NULL
|
monitor_1
|
NULL
|
NULL
|
NULL
|
NULL
|
Project: faVsco.js, menu
#11894 on JY-18909-automa Project: faVsco.js, menu
#11894 on JY-18909-automated-reports-ask-jiminny, menu
Start Listening for PHP Debug Connections
AutomatedReportsCommandTest
Run 'AutomatedReportsCommandTest'
Debug 'AutomatedReportsCommandTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Execute
Explain Plan
Browse Query History
View Parameters
Open Query Execution Settings…
In-Editor Results
Tx: Auto
Cancel Running Statements
Playground
jiminny
Sync Changes
Hide This Notification
Code changed:
Hide
16
13
13
Previous Highlighted Error
Next Highlighted Error
SELECT * FROM teams WHERE id = 1;
select * from crm_layouts where crm_configuration_id = 39;
SELECT * FROM crm_layout_entities WHERE crm_layout_id = 283;
SELECT * FROM crm_fields WHERE id = 2234;
SELECT * FROM crm_field_values WHERE crm_field_id = 2234;
select * from crm_profiles where user_id = 143;
select * from record_types where crm_configuration_id = 39; # 0121K000001MHElQAO,0121K000001MHEqQAO
select * from business_processes where crm_configuration_id = 39;
# 01941000000H669AAC, 01941000000H66JAAS
select * from record_type_field_values
where record_type_id IN (24);
select * from crm_field_values where id IN (2730);
select * from crm_configurations where id = 39;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 1
and sa.provider = 'salesforce'; #1035
select * from users where team_id = 1; # 222 group 3
SELECT * FROM activities WHERE user_id = 222 order by id desc;
select * from sidekick_settings where team_id = 1;
select * from teams where id = 1;
select * from team_features where team_id = 1;
select * from activities where crm_configuration_id = 2
and provider = 'ms-teams' and id = 608765;
SELECT * FROM activities WHERE crm_configuration_id = 2 and crm_provider_id = '59523413338';
select * from sidekick_settings where team_id = 2;
SELECT * FROM activities WHERE id = 608660;
select * from activity_summary_logs where activity_id = 608660;
select * from ai_prompts where transcription_id = 11214;
# [PASSWORD_DOTS]
SELECT * FROM activities WHERE uuid_to_bin('ed78a437-2804-450e-ab2f-56ab1c641346') = uuid;
# id: 608818, crm: 59628809737
SELECT * FROM activities WHERE uuid_to_bin('36b06e55-afdd-4782-8dee-c624cd0af191') = uuid;
# id: 608821, crm: 59632069252
SELECT ce.start_time, ce.end_time, a.id, a.uuid, crm_provider_id, calendar_event_id, title,
playbook_category_id, user_id, lead_id, contact_id, account_id, opportunity_id,
scheduled_start_time, scheduled_end_time, actual_start_time, actual_end_time, a.created_at
FROM activities a
join calendar_events ce on a.calendar_event_id = ce.id
WHERE a.id IN (608818, 608821);
select * from users where team_id = 1;
select * from team_settings where team_id = 1;
select * from crm_profiles where crm_configuration_id = 39 order by user_id;
select * from team_features where team_id = 1;
select * from users where team_id = 2;
SELECT * FROM activities WHERE uuid_to_bin('ec7647e9-5225-458b-b475-f31aa2769204') = uuid; # 612639
# Preslava N. Ivanova, grou id 3
SELECT * FROM opportunities WHERE uuid_to_bin('a2928fe5-aec5-46cb-85d9-7654c89e46a6') = uuid;
select * from activities where opportunity_id = 344 and actual_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00';
select
a.id,
a.type,
a.scheduled_start_time,
a.actual_start_time,
a.created_at,
a.opportunity_id,
a.status
FROM activities a
WHERE opportunity_id = 344
and status IN ('completed', 'received', 'delivered')
and (
(a.actual_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00')
OR (a.created_at between '2024-10-11 00:00:00' and '2024-10-12 00:00:00')
OR (a.scheduled_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00'))
;
SELECT * FROM users WHERE id = 222;
SELECT * FROM crm_profiles WHERE user_id = 222;
select * from crm_layouts where crm_configuration_id = 39;
SELECT * FROM crm_layout_entities WHERE crm_layout_id = 281;
select * from group_deal_risk_types;
select * from opportunities where team_id = 1;
SELECT * FROM opportunities WHERE id = 315;
SELECT * FROM crm_field_data WHERE object_id = 315;
select * from crm_field_data where object_id = 260;
select * from generic_ai_prompts where subject_id = 315;
select * from teams; # 36, 21, 121, [EMAIL]
SELECT * FROM social_accounts WHERE sociable_id = 121 and provider = 'bullhorn';
# [PASSWORD_DOTS]
select * from teams where id = 1;
select * from crm_configurations where id = 39;
select * from users where team_id = 1;
select u.email, cp.* from users u
join crm_profiles cp on u.id = cp.user_id
where u.team_id = 1;
# 1 - 00541000004281rAAA
# 204 - 0052g000003freeAAA
# 429 - 0052g000003qGOiAAM
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 1
and sa.provider = 'salesforce';
select * from activities where type = 'softphone'
and created_at > '2024-12-11 15:24:36' order by id desc;
select * from activity_providers where team_id = 1;
select * from activity_provider_users where activity_provider_id = 328;
select * from opportunities where crm_configuration_id = 39
AND account_id = 178 AND is_closed = false
order by created_at DESC;
select * from contacts where id = 3952;
select * from accounts where id = 178;
# [PASSWORD_DOTS]
select * from teams where id = 36;
select * from crm_configurations where id = 21;
select * from users where team_id = 36;
select u.email, cp.* from users u
join crm_profiles cp on u.id = cp.user_id
where u.team_id = 36;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 36
and sa.provider = 'bullhorn';
select * from social_accounts where id = 348;
UPDATE social_accounts SET
provider_user_token = '21442_6802599_91:41179a58-21e7-4d7c-ad58-56bb666b2f65',
provider_refresh_token = '21442_6802599_91:01c6b335-3f2a-42e4-85ff-8a08fa65fceb',
expires = 1733998131,
state = 'connected'
WHERE id = 348;
# [PASSWORD_DOTS]
select * from teams where id = 31;
select * from crm_configurations where id = 18;
select * from users where team_id = 31; # 257
select u.email, cp.* from users u
join crm_profiles cp on u.id = cp.user_id
where u.team_id = 31;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 31
and sa.provider = 'close';
select * from contacts where crm_configuration_id = 18;
# [PASSWORD_DOTS] NEPTUNE [PASSWORD_DOTS]
select * from teams;
select * from users where id IN (1030, 1035, 1052);
select * from crm_configurations;
select * from users where team_id = 65; # 257
select * from team_settings where team_id = 65; # 257
select * from invitations where team_id = 65; # 257
select * from users where email = '[EMAIL]'; # 257
select u.email, cp.* from users u
join crm_profiles cp on u.id = cp.user_id
where u.team_id = 65;
select * from crm_configurations where id = 53;
select * from accounts where crm_configuration_id = 53 order by id desc;
select * from leads where crm_configuration_id = 53 order by id desc;
select * from contacts where crm_configuration_id = 53 order by id desc;
select * from opportunities where crm_configuration_id = 53 order by id desc;
select * from crm_profiles where crm_configuration_id = 53 order by id desc;
select * from crm_fields where crm_configuration_id = 53 order by id desc;
select * from crm_field_values where crm_field_id = 3341 order by id desc;
select * from crm_layouts where crm_configuration_id = 53 order by id desc;
select * from stages where crm_configuration_id = 53 order by id desc;
select * from crm_profiles where crm_configuration_id = 13;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 65
and sa.provider = 'integration-app';
select * from contacts where crm_configuration_id = 13;
select * from social_accounts where sociable_id = 283;
SELECT * FROM opportunities WHERE crm_provider_id = '006O400000E9bzeIAB';
select * from activity_providers where team_id = 65;
SELECT * FROM activities WHERE crm_configuration_id IN (51, 52, 53);
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 65
;
# [PASSWORD_DOTS] STAGING [PASSWORD_DOTS]
SELECT * FROM teams;
SELECT * FROM teams WHERE id = 88;
SELECT * FROM teams WHERE id = 89;
select * from team_settings where team_id = 89;
SELECT * FROM users WHERE team_id = 89;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 89;
select * from users;
SELECT * FROM social_accounts WHERE sociable_id = 1761;
SELECT * FROM crm_configurations WHERE id = 70;
select * from accounts where crm_configuration_id = 70 order by id desc;
select * from leads where crm_configuration_id = 70 order by id desc;
select * from contacts where crm_configuration_id = 70 order by id desc;
select * from opportunities where crm_configuration_id = 70 order by id desc;
select * from crm_profiles where crm_configuration_id = 70 order by id desc;
select * from crm_fields where crm_configuration_id = 70 order by id desc;
select * from crm_field_values where crm_field_id = 3536 order by id desc;
select * from crm_layouts where crm_configuration_id = 70 order by id desc;
select * from stages where crm_configuration_id = 70 order by id desc;
select * from business_processes where crm_configuration_id = 70 order by id desc;
select * from business_process_stages where business_process_id = 34;
select * from contacts where id = 10468;
select * from crm_layouts where crm_configuration_id = 70;
SELECT * FROM crm_layout_entities WHERE crm_layout_id = 388;
SELECT * FROM crm_fields WHERE id IN (3533,3534,3535);
select * from activities where crm_configuration_id = 70
and (account_id IS NOT NULL or lead_id IS NOT NULL or contact_id IS NOT NULL or opportunity_id IS NOT NULL) order by id desc;
SELECT * FROM activities WHERE uuid_to_bin('2e10b60f-8a61-41c5-a3d4-28835353dc65') = uuid;
SELECT * FROM activities where crm_configuration_id = 69 ;
SELECT * FROM users WHERE email LIKE '%[EMAIL]%';
SELECT * FROM activities WHERE uuid_to_bin('5a150c93-40fc-42ec-b3bd-c1d328e09f6e') = uuid;
SELECT * FROM opportunities WHERE id = 385;
select * from participants p
join activities a on p.activity_id = a.id
where a.crm_configuration_id = 70
and (p.lead_id IS NOT NULL or p.contact_id IS NOT NULL);
SELECT * FROM participants WHERE id = 1013638;
select * from teams where id = 90;
select * from users where team_id = 90;
select * from social_accounts where social_accounts.sociable_id IN (1960,1760);
SELECT * FROM crm_profiles WHERE crm_configuration_id = 71;
select * from invitations where team_id = 90;
select * from crm_configurations where id = 71;
select * from accounts where crm_configuration_id = 71 order by id desc;
select * from leads where crm_configuration_id = 71 order by id desc;
select * from contacts where crm_configuration_id = 71 order by id desc;
select * from opportunities where crm_configuration_id = 71 order by id desc;
select * from crm_profiles where crm_configuration_id = 71 order by id desc;
select * from crm_fields where crm_configuration_id = 71 order by id desc;
select * from crm_field_values where crm_field_id = 3341 order by id desc;
select * from crm_layouts where crm_configuration_id = 71 order by id desc;
select * from stages where crm_configuration_id = 71 order by id desc;
select * from users order by secondary_email desc;
select u.id, u.email, u.status, sa.id, sa.provider_user_id from social_accounts sa
join users u on sa.sociable_id = u.id
where sa.provider = 'google' and u.email LIKE 'aneliya%';
select * from failed_jobs order by id desc;
select * from users where email = '[EMAIL]' or secondary_email = '[EMAIL]';
select * from teams;
SELECT * FROM crm_profiles WHERE crm_configuration_id = 39;
SELECT * FROM crm_fields WHERE crm_configuration_id = 39 and object_type = 'task';
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 1
and sa.provider = 'salesforce';
# [PASSWORD_DOTS]
SELECT * FROM activities WHERE uuid_to_bin('c38b3895-fd0f-4b1f-9fb2-c170dba137c6') = uuid;
SELECT * FROM crm_configurations WHERE id = 70;
select * from teams where id = 1;
select * from groups where team_id = 1;
select * from users where team_id = 1;
select o.id, o.name,o.close_date, u.id, u.name, u.group_id, r.id, r.display_name, g.name, g.scope from opportunities o
join users u on o.user_id = u.id
join groups g on u.group_id = g.id
join role_user ru on u.id = ru.user_id
join roles r on ru.role_id = r.id
where o.crm_configuration_id = 39 and close_date > '2024-01-01 00:00:00';
select * from role_user where user_id = 143;
select * from roles;
select * from role_user;
select * from groups where id = 9;
select * from scope_groups where group_id = 9;
# [PASSWORD_DOTS]
select * from teams where id = 36;
select * from crm_configurations;
SELECT * FROM social_accounts WHERE sociable_id = 121;
[URL_WITH_CREDENTIALS] this will add filter, however if we need to control feature by FF we need conditional logic
public const array TYPES = [
['id' => 'exec_summary', 'name' => 'Exec Summary'],
['id' => 'coaching_profiles', 'name' => 'Coaching Profiles'],
['id' => 'product_feedback', 'name' => 'Product Feedback'],
['id' => self::TYPE_LOSS_ANALYSIS, 'name' => 'Loss Analysis'],
// ['id' => 'questions', 'name' => 'Questions'],
// ['id' => 'statistical_quant', 'name' => 'Statistical Quantitative'],
];
public const array ALL_TYPES = [
...self::TYPES,
['id' => self::TYPE_ASK_JIMINNY, 'name' => 'Ask Jiminny'],
];
public const string FREQUENCY_DAILY = 'daily';
public const string FREQUENCY_WEEKLY = 'weekly';
public const string FREQUENCY_MONTHLY = 'monthly';
public const string FREQUENCY_QUARTERLY = 'quarterly';
public const string FREQUENCY_ONE_OFF = 'one_off';
/**
* Frequencies for standard (non-Ask Jiminny) reports.
*/
public const array FREQUENCIES = [
['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],
['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],
['id' => self::FREQUENCY_QUARTERLY, 'name' => 'Quarterly'],
['id' => self::FREQUENCY_ONE_OFF, 'name' => 'One-off'],
];
/**
* Frequencies for Ask Jiminny reports.
*/
public const array ASK_JIMINNY_FREQUENCIES = [
['id' => self::FREQUENCY_DAILY, 'name' => 'Daily'],
['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],
['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],
];
public const string MEDIA_TYPE_PDF = 'pdf';
public const string MEDIA_TYPE_PODCAST = 'podcast';
public const array MEDIA_TYPES = [self::MEDIA_TYPE_PDF, self::MEDIA_TYPE_PODCAST];
public const array MEDIA_TYPE_OBJECT_PDF = ['id' => self::MEDIA_TYPE_PDF, 'name' => 'PDF'];
public const array MEDIA_TYPE_OBJECT_PODCAST = ['id' => self::MEDIA_TYPE_PODCAST, 'name' => 'Podcast'];
public const array MEDIA_TYPE_OBJECTS = [self::MEDIA_TYPE_OBJECT_PDF, self::MEDIA_TYPE_OBJECT_PODCAST];
public const array CALL_TYPE_CONFERENCE = ['id' => 'conference', 'name' => 'Conference'];
public const array CALL_TYPE_DIALER = ['id' => 'dialer', 'name' => 'Dialer'];
public const int SENT_REPORT_AT_HOURS = 5;
public const string PDF_KEY = 'pdf';
public const string AUDIO_KEY = 'audio';
private const array ALL_FREQUENCIES = [
['id' => self::FREQUENCY_DAILY, 'name' => 'Daily'],
['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],
['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],
['id' => self::FREQUENCY_QUARTERLY, 'name' => 'Quarterly'],
['id' => self::FREQUENCY_ONE_OFF, 'name' => 'One-off'],
];
private const string S3_DIR = 'reports';
private const array FILE_EXTENSIONS_VARIANTS = ['html', 'MD', 'pdf'];
private const array FILE_PODCAST_EXTENSIONS_VARIANTS = ['json', 'mp3', 'ssml'];
public function __construct(
private readonly TeamRepository $teamRepository,
private readonly GroupRepository $groupRepository,
private readonly UserRepository $userRepository,
private readonly StageRepository $stageRepository,
private readonly DealStagesService $dealStagesService,
private readonly RecipientsService $recipientsService,
private readonly AutomatedReportsRepository $automatedReportsRepository,
private readonly Webhook $webhookService,
private readonly BusDispatcher $dispatcher,
private readonly ActivityTypeService $activityTypeService,
private readonly PlaybookCategoryRepository $playbookCategoryRepository,
private readonly AskAnythingPromptService $askAnythingPromptService,
private readonly SearchRepository $activitySearchRepository,
private readonly AskAnythingRepository $askAnythingRepository,
) {
}
public static function getTypes(): array
{
$types = self::TYPES;
return array_map(static function ($type) {
return $type['id'];
}, $types);
}
public static function getCallTypes(): array
{
return array_map(static function ($callType) {
return $callType['id'];
}, [self::CALL_TYPE_CONFERENCE, self::CALL_TYPE_DIALER]);
}
public static function getFrequencies(): array
{
return array_map(static function ($frequency) {
return $frequency['id'];
}, self::FREQUENCIES);
}
// front-facing structure
public function getReportEnabledFieldData(bool $value = false): array
{
return [
'id' => 'report_enabled',
'label' => '',
'inputType' => InputTypeEnum::TOGGLE,
'value' => $value,
];
}
// Organizations = Teams
public function getOrganizationFieldData(?string $value = null, bool $shortVersion = false): array
{
$options = $this->getTeams();
if ($shortVersion) {
return [
'id' => 'organization',
'label' => 'Organization',
'options' => $options,
];
}
return [
'id' => 'organization',
'label' => 'Organization',
'inputType' => InputTypeEnum::DROPDOWN,
'required' => true,
'placeholder' => 'Select',
'options' => $options,
'value' => $value,
'dependencies' => [
'teams',
'deal_stage_at_call',
'current_deal_stage',
'recipients',
ActivityTypeService::PLAYBOOK_CATEGORIES_KEY,
],
'dependsOn' => [],
];
}
// Teams = Groups
public function getTeamFieldData(array $options = [], array $value = [], bool $shortVersion = false): array
{
if ($shortVersion) {
return [
'id' => 'teams',
'label' => 'Team',
'options' => $options,
];
}
return [
'id' => 'teams',
'label' => 'Team',
'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,
'required' => false,
'placeholder' => 'Select',
'options' => $options,
'value' => $value, // value should be an array of objects {id, name}
'dependencies' => [ActivityTypeService::PLAYBOOK_CATEGORIES_KEY],
'dependsOn' => [],
];
}
public function getReportTypeFieldData(?string $value = null, bool $shortVersion = false, ?Team $team = null): array
{
$types = [];
if ($team instanceof Team) {
if ($team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {
$types = self::TYPES;
}
if ($team->hasFeature(FeatureEnum::ASK_JIMINNY_REPORTS)) {
$types[] = ['id' => self::TYPE_ASK_JIMINNY, 'name' => 'Ask Jiminny'];
}
} else {
$types = self::TYPES;
}
if ($shortVersion) {
return [
'id' => 'report_type',
'label' => 'Report Type',
'options' => $types,
];
}
return [
'id' => 'report_type',
'label' => 'Report Type',
'inputType' => InputTypeEnum::DROPDOWN,
'required' => true,
'placeholder' => 'Select',
'options' => $types,
'value' => $value,
'dependencies' => [],
'dependsOn' => [],
];
}
public function getFrequencyFieldData(?string $value = null): array
{
return [
'id' => 'frequency',
'label' => 'Frequency',
'inputType' => InputTypeEnum::DROPDOWN,
'required' => true,
'placeholder' => 'Select',
'options' => self::FREQUENCIES,
'value' => $value,
'dependencies' => ['period'],
'dependsOn' => [],
];
}
public function getPeriodFieldData(?string $valueStartDate = null, ?string $valueEndDate = null): array
{
return [
'id' => 'period',
'label' => 'Select one-off period',
'inputType' => InputTypeEnum::DATE_RANGE,
'required' => true,
'placeholder' => 'Select',
'value' => ['startDate' => $valueStartDate, 'endDate' => $valueEndDate],
'queryParams' => [
'startDate' => 'start_date_period',
'endDate' => 'end_date_period',
],
'dependencies' => [],
'dependsOn' => ['frequency'],
];
}
public function getActivityTypesFieldData(?Team $team = null, array $value = [], array $teamsFilter = []): array
{
return $this->activityTypeService->getActivityTypeFieldData(team: $team, value: $value, groupIds: $teamsFilter);
}
public function getDealStageAtCallFieldData(?Team $team = null, array $value = []): array
{
return $this->dealStagesService->getDealStageAtCallFieldData(team: $team, value: $value);
}
public function getCurrentDealStageFieldData(?Team $team = null, array $value = []): array
{
return $this->dealStagesService->getCurrentDealStageFieldData(team: $team, value: $value);
}
public function getDealValueFieldData(?int $valueMin = null, ?int $valueMax = null): array
{
return [
'id' => 'deal_value',
'label' => 'Deal Value',
'inputType' => InputTypeEnum::INTEGER_RANGE,
'required' => false,
'value' => ['min' => $valueMin, 'max' => $valueMax],
'queryParams' => [
'min' => 'min_deal_value',
'max' => 'max_deal_value',
],
'dependencies' => [],
'dependsOn' => [],
];
}
public function getCallTypeFieldData(bool $conferenceOn = false, bool $dialerOn = false): array
{
$value = [];
$conferenceOn && $value[] = self::CALL_TYPE_CONFERENCE;
$dialerOn && $value[] = self::CALL_TYPE_DIALER;
return [
'id' => 'call_type',
'label' => 'Call Type',
'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,
'required' => true,
'options' => [
self::CALL_TYPE_CONFERENCE,
self::CALL_TYPE_DIALER,
],
'value' => $value,
'dependencies' => [],
'dependsOn' => [],
];
}
public function getMediaTypeFieldData(?AutomatedReport $report = null): array
{
$value = [];
if ($report) {
$value = $this->transformMediaTypes($report);
}
return [
'id' => 'media_types',
'label' => 'Export as',
'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,
'required' => true,
'options' => self::MEDIA_TYPE_OBJECTS,
'value' => $value,
'dependencies' => [],
'dependsOn' => [],
];
}
public function getCallDurationFieldData(?int $valueMin = null, ?int $valueMax = null): array
{
return [
'id' => 'call_duration',
'label' => 'Call Duration',
'inputType' => InputTypeEnum::INTEGER_RANGE,
'required' => false,
'value' => ['min' => $valueMin, 'max' => $valueMax],
'queryParams' => [
'min' => 'min_call_duration',
'max' => 'max_call_duration',
],
'dependencies' => [],
'dependsOn' => [],
];
}
public function getRecipientsFieldData(?Team $team = null, array $value = []): array
{
return $this->recipientsService->getRecipientsFieldData(team: $team, value: $value);
}
public function getJiminnyRecipientsFieldData(array $value = []): array
{
return $this->recipientsService->getJiminnyRecipientsFieldData($value);
}
public function getAdditionalPromptInputFieldData(?string $value = null): array
{
return [
'id' => 'additional_prompt_input',
'label' => 'Special requirements',
'inputType' => InputTypeEnum::TEXTAREA,
'required' => false,
'placeholder' => 'What should be the focus of the report?',
'value' => $value,
'dependencies' => [],
'dependsOn' => [],
];
}
public function getCustomReportNameFieldData(?string $value = null): array
{
return [
'id' => 'custom_name',
'label' => 'Custom report name',
'inputType' => InputTypeEnum::TEXT,
'required' => false,
'placeholder' => 'Enter custom name',
'value' => $value,
'dependencies' => [],
'dependsOn' => [],
];
}
// data providers
public function getTeams(): array
{
$teams = $this->teamRepository->getTeamsForKiosk(status: Team::STATUS_ACTIVE);
$teamData = [];
foreach ($teams as $team) {
if (! $team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {
continue;
}
$teamData[] = $this->transformTeam($team);
}
return $teamData;
}
public function getTeamGroups(string $teamUuid): array
{
$data = [];
$team = $this->getTeam($teamUuid);
if ($team !== null) {
$groups = $team->groups()->get();
foreach ($groups as $group) {
$data[] = [
'id' => $group->getUuid(),
'name' => $group->getName(),
];
}
}
return $data;
}
public function getTeamsGroupsOptions(array $filterTeamUuids = []): array
{
$data = [];
$teams = $this->getTeams();
foreach ($teams as $team) {
if (! empty($filterTeamUuids) && ! in_array($team['id'], $filterTeamUuids, true)) {
continue;
}
$data[] = [
'label' => $team['name'],
'groups' => $this->getTeamGroups($team['id']),
];
}
return $data;
}
public function getTeam(string $teamUuid): ?Team
{
return $this->teamRepository->idOrUuid($teamUuid);
}
public function getTeamById(int $teamId): ?Team
{
return $this->teamRepository->find($teamId);
}
public function getGroupsUuids(AutomatedReport $report): array
{
$uuids = [];
$reportGroups = $report->getGroups();
foreach ($reportGroups as $groupId) {
if ($group = $this->groupRepository->find($groupId)) {
$uuids[] = $group->getUuid();
}
}
return $uuids;
}
public function getPlaybookCategoriesUuids(AutomatedReport $report): array
{
$uuids = [];
$playbookCategories = $report->getPlaybookCategories();
foreach ($playbookCategories as $id) {
if ($category = $this->playbookCategoryRepository->find($id)) {
$uuids[] = $category->getUuid();
}
}
return $uuids;
}
public function getDealAtCallStagesUuids(AutomatedReport $report): array
{
$uuids = [];
$reportStages = $report->getDealAtCallStages();
foreach ($reportStages as $id) {
if ($stage = $this->stageRepository->find($id)) {
$uuids[] = $stage->getUuid();
}
}
return $uuids;
}
public function getCurrentDealStagesUuids(AutomatedReport $report): array
{
$uuids = [];
$reportStages = $report->getCurrentDealStages();
foreach ($reportStages as $id) {
if ($stage = $this->stageRepository->find($id)) {
$uuids[] = $stage->getUuid();
}
}
return $uuids;
}
public function getUsersUuids(AutomatedReport $report): array
{
return $this->extractUserUuids($report->getRecipients());
}
public function getJiminnyUsersUuids(AutomatedReport $report): array
{
return $this->extractUserUuids($report->getJiminnyRecipients());
}
/**
* @param array<string, mixed> $recipients
*/
private function extractUserUuids(array $recipients): array
{
$userIds = $recipients['users'] ?? [];
return collect($userIds)
->map(fn ($id) => $this->userRepository->find((int) $id))
->filter()
->map(fn (UserContract $user) => $user->getUuid())
->values()
->all();
}
// get mail data
public function getRecipientUsers(AutomatedReport $report): array
{
return $this->buildRecipientUsers($report->getRecipients());
}
private function getJiminnyRecipientUsers(AutomatedReport $report): array
{
return $this->buildRecipientUsers($report->getJiminnyRecipients());
}
/**
* @param array<string, mixed> $recipients
*/
private function buildRecipientUsers(array $recipients): array
{
$userIds = $recipients['users'] ?? [];
return collect($userIds)
->map(fn ($id) => $this->userRepository->find((int) $id))
->filter()
->map(fn (UserContract $user) => [
'email' => $user->getEmailAddress(),
'name' => $user->getName(),
'timezone' => $user->getTimezone()->getName(),
])
->values()
->all();
}
public function getValidRecipientUsers(AutomatedReport $report, bool $includeJiminny = false): array
{
if ($report->isAskJiminnyReport()) {
$recipients = $this->resolveAskJiminnyRecipients($report);
} else {
$recipients = $this->getRecipientUsers($report);
if ($includeJiminny) {
$recipients = array_merge($recipients, $this->getJiminnyRecipientUsers($report));
}
}
$emails = [];
return array_values(array_filter(
$recipients,
static function ($recipient) use (&$emails) {
if (empty($recipient['email']) || in_array($recipient['email'], $emails, true)) {
return false;
}
$emails[] = $recipient['email'];
return true;
}
));
}
private function resolveAskJiminnyRecipients(AutomatedReport $report): array
{
$recipients = [];
$creator = $report->getCreator();
if ($creator !== null) {
$recipients[] = [
'email' => $creator->getEmailAddress(),
'name' => $creator->getName(),
'timezone' => $creator->getTimezone()->getName(),
];
}
return array_merge(
$recipients,
$this->buildRecipientUsers($report->getRecipients()),
$this->getGroupRecipientUsers($report),
);
}
private function getGroupRecipientUsers(AutomatedReport $report): array
{
$users = [];
foreach ($report->getGroups() as $groupId) {
$group = $this->groupRepository->find($groupId);
if ($group === null) {
continue;
}
foreach ($group->getMembers() as $member) {
$users[] = [
'email' => $member->getEmailAddress(),
'name' => $member->getName(),
'timezone' => $member->getTimezone()->getName(),
];
}
}
return $users;
}
public function getReportTypeName(AutomatedReportResult $report): string
{
$type = $report->getReport()->getType();
$getType = $this->transformReportType($type);
return $getType['name'];
}
public function getReportPeriodName(AutomatedReportResult $report): string
{
$from = $report->getFromDate();
$to = $report->getToDate();
$frequency = $report->getReport()->getFrequency();
if ($from === null || $to === null) {
if (! $report->getReport()->isAskJiminnyReport()) {
$invalidPeriod = $from === null ? 'from' : 'to';
throw new ApplicationException('Report period is invalid: ' . $invalidPeriod);
}
$period = $this->calculateFromAndToDatePeriod($frequency);
$from = $period['fromDate'];
$to = $period['toDate'];
}
return $this->formatReportPeriodName($frequency, $from, $to);
}
private function formatReportPeriodName(string $frequency, Carbon $from, Carbon $to): string
{
$fromYear = $from->format('Y');
$toYear = $to->format('Y');
$differentYears = $fromYear !== $toYear;
switch ($frequency) {
case self::FREQUENCY_DAILY:
return $from->format('j M Y');
case self::FREQUENCY_QUARTERLY:
// 'Jan-Mar 2025' or 'Nov 2024-Jan 2025' if years differ
$startMonth = $from->format('M');
$endMonth = $to->copy()->subMonth();
$endMonthName = $endMonth->format('M');
$endMonthYear = $endMonth->format('Y');
if ($differentYears) {
return "{$startMonth} {$fromYear} - {$endMonthName} {$endMonthYear}";
}
return "{$startMonth} - {$endMonthName} {$toYear}";
case self::FREQUENCY_MONTHLY:
// 'May 2025' - monthly reports are always within the same year
return $from->format('M Y');
case self::FREQUENCY_WEEKLY:
// '4 - 8 Aug 2025', '27 Oct - 3 Nov 2025', or '28 Dec 2024 - 3 Jan 2025' if years differ
$startDay = $from->format('j');
$endDay = $to->format('j');
$startMonth = $from->format('M');
$endMonth = $to->format('M');
if ($differentYears) {
return "{$startDay} {$startMonth} {$fromYear} - {$endDay} {$endMonth} {$toYear}";
}
if ($startMonth !== $endMonth) {
return "{$startDay} {$startMonth} - {$endDay} {$endMonth} {$toYear}";
}
return "{$startDay} - {$endDay} {$endMonth} {$toYear}";
case self::FREQUENCY_ONE_OFF:
// '2 May-31 May 2025' or '15 Dec 2024-15 Jan 2025' if years differ
$startDay = $from->format('j');
$startMonth = $from->format('M');
$endDay = $to->format('j');
$endMonth = $to->format('M');
// If same month and year, use a format like '2-31 May 2025'
if ($startMonth === $endMonth && ! $differentYears) {
return "{$startDay} - {$endDay} {$startMonth} {$toYear}";
}
// If different years, include both years
if ($differentYears) {
return "{$startDay} {$startMonth} {$fromYear} - {$endDay} {$endMonth} {$toYear}";
}
// Same year but different months
return "{$startDay} {$startMonth} - {$endDay} {$endMonth} {$toYear}";
default:
// Default format for unknown frequencies
return $from->format('j M Y') . ' - ' . $to->format('j M Y');
}
}
public function getReportTeamsName(AutomatedReportResult $report): string
{
$groups = $report->getGroups();
if (empty($groups)) {
return 'All';
}
// Get group names from repository
$groupNames = [];
foreach ($groups as $groupId) {
$group = $this->groupRepository->find($groupId);
if ($group) {
$groupNames[] = $group->getName();
}
}
if (count($groupNames) === 1) {
// Single team format
$teamsName = $groupNames[0];
} else {
// Multiple teams format
$teamsName = implode(', ', $groupNames);
}
return $teamsName;
}
public function getReportFileName(AutomatedReportResult $report): string
...
|
[{"role":"AXButton","text" [{"role":"AXButton","text":"Project: faVsco.js, menu","depth":5,"help_text":"~/jiminny/app","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"#11894 on JY-18909-automated-reports-ask-jiminny, menu","depth":5,"help_text":"Pull request #11894 exists for current branch JY-18909-automated-reports-ask-jiminny","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Start Listening for PHP Debug Connections","depth":5,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"AutomatedReportsCommandTest","depth":6,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Run 'AutomatedReportsCommandTest'","depth":6,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Debug 'AutomatedReportsCommandTest'","depth":6,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"More Actions","depth":6,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JetBrains AI","depth":5,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Search Everywhere","depth":5,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"IDE and Project Settings","depth":5,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Execute","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Explain Plan","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Browse Query History","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"View Parameters","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Open Query Execution Settings…","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"In-Editor Results","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Tx: Auto","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Cancel Running Statements","depth":4,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Playground","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"jiminny","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.088194445,"height":0.027777778},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"16","depth":4,"role_description":"text"},{"role":"AXStaticText","text":"13","depth":4,"role_description":"text"},{"role":"AXStaticText","text":"13","depth":4,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"SELECT * FROM teams WHERE id = 1;\n\nselect * from crm_layouts where crm_configuration_id = 39;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 283;\nSELECT * FROM crm_fields WHERE id = 2234;\nSELECT * FROM crm_field_values WHERE crm_field_id = 2234;\n\nselect * from crm_profiles where user_id = 143;\n\nselect * from record_types where crm_configuration_id = 39; # 0121K000001MHElQAO,0121K000001MHEqQAO\nselect * from business_processes where crm_configuration_id = 39;\n# 01941000000H669AAC, 01941000000H66JAAS\n\nselect * from record_type_field_values\n where record_type_id IN (24);\n\nselect * from crm_field_values where id IN (2730);\n\nselect * from crm_configurations where id = 39;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 1\nand sa.provider = 'salesforce'; #1035\n\n\nselect * from users where team_id = 1; # 222 group 3\nSELECT * FROM activities WHERE user_id = 222 order by id desc;\nselect * from sidekick_settings where team_id = 1;\nselect * from teams where id = 1;\nselect * from team_features where team_id = 1;\n\nselect * from activities where crm_configuration_id = 2\nand provider = 'ms-teams' and id = 608765;\n\nSELECT * FROM activities WHERE crm_configuration_id = 2 and crm_provider_id = '59523413338';\n\nselect * from sidekick_settings where team_id = 2;\n\nSELECT * FROM activities WHERE id = 608660;\nselect * from activity_summary_logs where activity_id = 608660;\nselect * from ai_prompts where transcription_id = 11214;\n\n# ********************************************************************************************************\nSELECT * FROM activities WHERE uuid_to_bin('ed78a437-2804-450e-ab2f-56ab1c641346') = uuid;\n# id: 608818, crm: 59628809737\nSELECT * FROM activities WHERE uuid_to_bin('36b06e55-afdd-4782-8dee-c624cd0af191') = uuid;\n# id: 608821, crm: 59632069252\nSELECT ce.start_time, ce.end_time, a.id, a.uuid, crm_provider_id, calendar_event_id, title,\nplaybook_category_id, user_id, lead_id, contact_id, account_id, opportunity_id,\nscheduled_start_time, scheduled_end_time, actual_start_time, actual_end_time, a.created_at\nFROM activities a\njoin calendar_events ce on a.calendar_event_id = ce.id\nWHERE a.id IN (608818, 608821);\n\nselect * from users where team_id = 1;\nselect * from team_settings where team_id = 1;\nselect * from crm_profiles where crm_configuration_id = 39 order by user_id;\n\nselect * from team_features where team_id = 1;\n\nselect * from users where team_id = 2;\n\nSELECT * FROM activities WHERE uuid_to_bin('ec7647e9-5225-458b-b475-f31aa2769204') = uuid; # 612639\n# Preslava N. Ivanova, grou id 3\n\nSELECT * FROM opportunities WHERE uuid_to_bin('a2928fe5-aec5-46cb-85d9-7654c89e46a6') = uuid;\n\nselect * from activities where opportunity_id = 344 and actual_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00';\n\nselect\n a.id,\n a.type,\n a.scheduled_start_time,\n a.actual_start_time,\n a.created_at,\n a.opportunity_id,\n a.status\nFROM activities a\nWHERE opportunity_id = 344\nand status IN ('completed', 'received', 'delivered')\nand (\n (a.actual_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00')\nOR (a.created_at between '2024-10-11 00:00:00' and '2024-10-12 00:00:00')\nOR (a.scheduled_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00'))\n;\n\nSELECT * FROM users WHERE id = 222;\n\nSELECT * FROM crm_profiles WHERE user_id = 222;\nselect * from crm_layouts where crm_configuration_id = 39;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 281;\n\nselect * from group_deal_risk_types;\n\nselect * from opportunities where team_id = 1;\n\nSELECT * FROM opportunities WHERE id = 315;\nSELECT * FROM crm_field_data WHERE object_id = 315;\nselect * from crm_field_data where object_id = 260;\n\nselect * from generic_ai_prompts where subject_id = 315;\n\nselect * from teams; # 36, 21, 121, james.graham@bullhorn.jiminny.com\nSELECT * FROM social_accounts WHERE sociable_id = 121 and provider = 'bullhorn';\n\n# ************************************************************************************\nselect * from teams where id = 1;\nselect * from crm_configurations where id = 39;\nselect * from users where team_id = 1;\nselect u.email, cp.* from users u\njoin crm_profiles cp on u.id = cp.user_id\nwhere u.team_id = 1;\n# 1 - 00541000004281rAAA\n# 204 - 0052g000003freeAAA\n# 429 - 0052g000003qGOiAAM\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 1\nand sa.provider = 'salesforce';\n\nselect * from activities where type = 'softphone'\nand created_at > '2024-12-11 15:24:36' order by id desc;\n\nselect * from activity_providers where team_id = 1;\nselect * from activity_provider_users where activity_provider_id = 328;\n\nselect * from opportunities where crm_configuration_id = 39\nAND account_id = 178 AND is_closed = false\norder by created_at DESC;\n\nselect * from contacts where id = 3952;\nselect * from accounts where id = 178;\n\n# ************************************************************************************\nselect * from teams where id = 36;\nselect * from crm_configurations where id = 21;\nselect * from users where team_id = 36;\nselect u.email, cp.* from users u\njoin crm_profiles cp on u.id = cp.user_id\nwhere u.team_id = 36;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 36\nand sa.provider = 'bullhorn';\n\nselect * from social_accounts where id = 348;\nUPDATE social_accounts SET\nprovider_user_token = '21442_6802599_91:41179a58-21e7-4d7c-ad58-56bb666b2f65',\nprovider_refresh_token = '21442_6802599_91:01c6b335-3f2a-42e4-85ff-8a08fa65fceb',\nexpires = 1733998131,\nstate = 'connected'\nWHERE id = 348;\n\n# ************************************************************************************\nselect * from teams where id = 31;\nselect * from crm_configurations where id = 18;\n\nselect * from users where team_id = 31; # 257\nselect u.email, cp.* from users u\njoin crm_profiles cp on u.id = cp.user_id\nwhere u.team_id = 31;\n\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 31\nand sa.provider = 'close';\n\nselect * from contacts where crm_configuration_id = 18;\n\n# ********************** NEPTUNE **************************************************************\nselect * from teams;\nselect * from users where id IN (1030, 1035, 1052);\nselect * from crm_configurations;\n\nselect * from users where team_id = 65; # 257\nselect * from team_settings where team_id = 65; # 257\nselect * from invitations where team_id = 65; # 257\nselect * from users where email = 'integration-account@jiminny.com'; # 257\nselect u.email, cp.* from users u\njoin crm_profiles cp on u.id = cp.user_id\nwhere u.team_id = 65;\n\nselect * from crm_configurations where id = 53;\nselect * from accounts where crm_configuration_id = 53 order by id desc;\nselect * from leads where crm_configuration_id = 53 order by id desc;\nselect * from contacts where crm_configuration_id = 53 order by id desc;\nselect * from opportunities where crm_configuration_id = 53 order by id desc;\nselect * from crm_profiles where crm_configuration_id = 53 order by id desc;\nselect * from crm_fields where crm_configuration_id = 53 order by id desc;\nselect * from crm_field_values where crm_field_id = 3341 order by id desc;\nselect * from crm_layouts where crm_configuration_id = 53 order by id desc;\nselect * from stages where crm_configuration_id = 53 order by id desc;\n\n\nselect * from crm_profiles where crm_configuration_id = 13;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 65\nand sa.provider = 'integration-app';\n\nselect * from contacts where crm_configuration_id = 13;\n\nselect * from social_accounts where sociable_id = 283;\n\nSELECT * FROM opportunities WHERE crm_provider_id = '006O400000E9bzeIAB';\n\nselect * from activity_providers where team_id = 65;\nSELECT * FROM activities WHERE crm_configuration_id IN (51, 52, 53);\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 65\n;\n\n# ***************************** STAGING ********************************************\nSELECT * FROM teams;\nSELECT * FROM teams WHERE id = 88;\nSELECT * FROM teams WHERE id = 89;\nselect * from team_settings where team_id = 89;\nSELECT * FROM users WHERE team_id = 89;\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 89;\n\nselect * from users;\nSELECT * FROM social_accounts WHERE sociable_id = 1761;\nSELECT * FROM crm_configurations WHERE id = 70;\nselect * from accounts where crm_configuration_id = 70 order by id desc;\nselect * from leads where crm_configuration_id = 70 order by id desc;\nselect * from contacts where crm_configuration_id = 70 order by id desc;\nselect * from opportunities where crm_configuration_id = 70 order by id desc;\nselect * from crm_profiles where crm_configuration_id = 70 order by id desc;\nselect * from crm_fields where crm_configuration_id = 70 order by id desc;\nselect * from crm_field_values where crm_field_id = 3536 order by id desc;\nselect * from crm_layouts where crm_configuration_id = 70 order by id desc;\nselect * from stages where crm_configuration_id = 70 order by id desc;\nselect * from business_processes where crm_configuration_id = 70 order by id desc;\nselect * from business_process_stages where business_process_id = 34;\n\nselect * from contacts where id = 10468;\n\nselect * from crm_layouts where crm_configuration_id = 70;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 388;\nSELECT * FROM crm_fields WHERE id IN (3533,3534,3535);\n\nselect * from activities where crm_configuration_id = 70\nand (account_id IS NOT NULL or lead_id IS NOT NULL or contact_id IS NOT NULL or opportunity_id IS NOT NULL) order by id desc;\n\nSELECT * FROM activities WHERE uuid_to_bin('2e10b60f-8a61-41c5-a3d4-28835353dc65') = uuid;\nSELECT * FROM activities where crm_configuration_id = 69 ;\n\nSELECT * FROM users WHERE email LIKE '%jiminny_web_sa2@jiminny.com%';\nSELECT * FROM activities WHERE uuid_to_bin('5a150c93-40fc-42ec-b3bd-c1d328e09f6e') = uuid;\nSELECT * FROM opportunities WHERE id = 385;\n\nselect * from participants p\njoin activities a on p.activity_id = a.id\nwhere a.crm_configuration_id = 70\nand (p.lead_id IS NOT NULL or p.contact_id IS NOT NULL);\nSELECT * FROM participants WHERE id = 1013638;\n\nselect * from teams where id = 90;\nselect * from users where team_id = 90;\nselect * from social_accounts where social_accounts.sociable_id IN (1960,1760);\nSELECT * FROM crm_profiles WHERE crm_configuration_id = 71;\nselect * from invitations where team_id = 90;\n\nselect * from crm_configurations where id = 71;\nselect * from accounts where crm_configuration_id = 71 order by id desc;\nselect * from leads where crm_configuration_id = 71 order by id desc;\nselect * from contacts where crm_configuration_id = 71 order by id desc;\nselect * from opportunities where crm_configuration_id = 71 order by id desc;\nselect * from crm_profiles where crm_configuration_id = 71 order by id desc;\nselect * from crm_fields where crm_configuration_id = 71 order by id desc;\nselect * from crm_field_values where crm_field_id = 3341 order by id desc;\nselect * from crm_layouts where crm_configuration_id = 71 order by id desc;\nselect * from stages where crm_configuration_id = 71 order by id desc;\n\nselect * from users order by secondary_email desc;\nselect u.id, u.email, u.status, sa.id, sa.provider_user_id from social_accounts sa\n join users u on sa.sociable_id = u.id\nwhere sa.provider = 'google' and u.email LIKE 'aneliya%';\n\nselect * from failed_jobs order by id desc;\n\nselect * from users where email = 'ben.allwright@learningpeople.co.uk' or secondary_email = 'ben.allwright@learningpeople.co.uk';\n\nselect * from teams;\nSELECT * FROM crm_profiles WHERE crm_configuration_id = 39;\nSELECT * FROM crm_fields WHERE crm_configuration_id = 39 and object_type = 'task';\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 1\nand sa.provider = 'salesforce';\n\n# ************************************************************************************\nSELECT * FROM activities WHERE uuid_to_bin('c38b3895-fd0f-4b1f-9fb2-c170dba137c6') = uuid;\nSELECT * FROM crm_configurations WHERE id = 70;\n\nselect * from teams where id = 1;\nselect * from groups where team_id = 1;\nselect * from users where team_id = 1;\n\nselect o.id, o.name,o.close_date, u.id, u.name, u.group_id, r.id, r.display_name, g.name, g.scope from opportunities o\njoin users u on o.user_id = u.id\njoin groups g on u.group_id = g.id\njoin role_user ru on u.id = ru.user_id\njoin roles r on ru.role_id = r.id\nwhere o.crm_configuration_id = 39 and close_date > '2024-01-01 00:00:00';\n\nselect * from role_user where user_id = 143;\nselect * from roles;\n\nselect * from role_user;\nselect * from groups where id = 9;\nselect * from scope_groups where group_id = 9;\n\n# ************************************************************************************\nselect * from teams where id = 36;\nselect * from crm_configurations;\nSELECT * FROM social_accounts WHERE sociable_id = 121;\n\nhttps://crmsandbox.zoho.com/crm/jiminnyw4/tab/Leads/4776201000005049105\nhttps://crmsandbox.zoho.com/crm/\n\nhttps://crm.zoho.com/crm/org3469620/tab/Leads/230045000229559080\n https://crm.zoho.com/crm/\n org3469620\n\nSELECT * FROM activities WHERE uuid_to_bin('03382d20-c8bc-48e7-a3d4-90b52fa5ceab') = uuid;\n\nselect * from users where email LIKE \"%mobile_automation_%\";\nselect * from social_accounts where sociable_id IN (2228);\nselect * from crm_profiles where user_id IN (2222,2223,2226,2227);\n\nselect * from teams order by id desc;\nSELECT * FROM users WHERE id = 2229;\nSELECT * FROM crm_profiles WHERE user_id = 2229;\nselect * from opportunities where crm_configuration_id = 88;\nselect * from crm_fields where crm_configuration_id = 88;\nselect * from crm_profiles where crm_configuration_id = 88;\n\nSELECT * FROM teams WHERE id = 1;\n\nSELECT * FROM users WHERE id = 143;\nSELECT * FROM users WHERE uuid_to_bin('fde193d3-06a2-4e1a-8895-62b94039215d') = uuid;\nSELECT * FROM teams WHERE uuid_to_bin('73385071-a756-42ae-9c73-8b53f2309467') = uuid;\n\nhttps://app.staging.jiminny.com/ondemand?\n min_duration=1\n &\n only_recorded=1\n &\n user_id%5B%5D=641f1acb-16b8-42d1-8726-df52979dad0e\n &\n sequence_number=2\n\n select * from users where team_id = 1 and email like '%stoyan%'\n\nselect * from coaching_feedbacks;\n\nselect * from teams;\nSELECT * FROM users WHERE team_id = 36;\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 19\nand sa.provider = 'pipedrive';\n\nselect * from users where id = 143;\n\nSELECT * FROM users WHERE uuid_to_bin('73180eeb-33de-4065-977d-ccbe0e6c94fc') = uuid;\nSELECT * FROM teams WHERE uuid_to_bin('73180eeb-33de-4065-977d-ccbe0e6c94fc') = uuid;\nSELECT * FROM activity_shares WHERE uuid_to_bin('73180eeb-33de-4065-977d-ccbe0e6c94fc') = uuid;\n\nselect * from users where team_id = 2;\nselect * from activities where crm_configuration_id = 39\nand activities.scheduled_start_time BETWEEN '2025-04-09 00:00:00' AND '2025-04-09 23:59:59'\nAND user_id = 143\norder by id desc;\n\n# ************************************************************************************\nselect * from teams where id = 142; # 2312, 126\nselect * from team_settings;\nselect * from users where team_id = 142; # 21642\nSELECT * FROM social_accounts WHERE sociable_id = 21642;\nSELECT * FROM crm_profiles cp join users u ON u.id = cp.user_id WHERE team_id = 142;\nselect * from crm_profiles where id IN (93);\nselect * from invitations;\nselect * from team_features where team_id = 1;\n\nSELECT * FROM crm_configurations WHERE id = 126;\nselect * from accounts where crm_configuration_id = 126 order by id desc;\nselect * from leads where crm_configuration_id = 126 order by id desc;\nselect * from contacts where crm_configuration_id = 126 order by id desc;\nselect * from opportunities where crm_configuration_id = 126 order by id desc;\nselect * from crm_profiles where crm_configuration_id = 126 order by id desc;\nselect * from crm_fields where crm_configuration_id = 126 # 11060\n# and type IN ('picklist', 'status')\n# and object_type = 'task'\norder by id desc;\n# 5731,5732,5733\nselect DISTINCT crm_field_id from crm_field_values where crm_field_id IN (11151,12239,12215,12185,12175,12165,12144,12137,12127,12109,12107,12105,12103,12092,12037,12005,12003,11987,11969,11958,11951,11942,11931,11924,11921,11917,11915,11901,11893,11883,11872,11870,11868,11866,11839,11833,11821,11793,11780,11777,11769,11757,11737,11735,11656,11645,11638,11629,11618,11611,11602,11591,11584,11581,11558,11544,11543,11534,11532,11529,11527,11503,11497,11493,11488,11470,11468,11457,11455,11397,11387,11372,11363,11348,11323,11318,11309,11301,11300,11292,11290,11286,11284,11256,11252,11242,11237,11233,11219,11176,11160) order by id desc;\nselect * from crm_layouts where crm_configuration_id = 126 order by id desc;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id in (300,299,298);\nselect * from stages where crm_configuration_id = 126 order by id desc;\nselect * from business_processes where crm_configuration_id = 126 order by id desc;\nselect * from business_process_stages where business_process_id IN (76,75,74,73);\nselect * from playbooks where team_id = 142;\nselect * from playbook_layouts where playbook_id IN (108);\nSELECT * FROM playbook_categories WHERE playbook_id IN (108);\n\nselect * from teams where id = 130;\nSELECT * FROM social_accounts WHERE sociable_id = 2291;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 2\nand sa.provider = 'hubspot';\n\nSELECT * FROM activities\n WHERE crm_configuration_id = 110;\n\nselect * from teams;\nselect * from crm_configurations;\n\nSELECT * FROM activities WHERE id = 628773;\nSELECT * FROM crm_profiles WHERE user_id = 1460;\nSELECT * FROM social_accounts WHERE sociable_id = 2291;\n\nselect * from teams;\nselect ru.*, pr.*, p.* from users u join role_user ru on ru.user_id = u.id\njoin permission_role pr on pr.role_id = ru.role_id\n join permissions p on p.id = pr.permission_id\nwhere team_id = 495 and p.name IN ('dial');\n\nselect * from teams where id = 145;\nselect * from crm_configurations where id = 129;\nselect * from social_accounts where sociable_id = 2317;\nSELECT * FROM activities WHERE uuid_to_bin('8dbab184-a333-4268-ad57-fb41f8d53a9a') = uuid;\n\nselect * from teams where id = 1;\nSELECT * FROM crm_layouts WHERE crm_configuration_id = 39;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 280;\nSELECT * FROM crm_layout_entities WHERE id = 5507;\nSELECT * FROM crm_fields WHERE crm_configuration_id = 39 and object_type IN ('event');\n\nselect * from teams;\nselect * from activities where crm_configuration_id = 14;\n\nSELECT * FROM social_accounts where provider = 'copper';\n\nselect * from activities where id = 628467;\nselect * from participants where activity_id = 628467;\n\nSELECT * FROM contacts WHERE id = 3969;\nSELECT * FROM accounts WHERE id = 177;\n\nSELECT * FROM activities WHERE uuid_to_bin('4eb54c77-cfa3-2bd4-84a7-9ed46a21c988') = uuid;\n\n# ********************* BH\nselect * from teams where id = 36;\nSELECT * FROM crm_configurations WHERE id = 21;\nselect * from activities where crm_configuration_id = 21 and id = 607901;\nselect * from activities where crm_configuration_id = 21;\n\nselect * roles;\nselect * from permissions;\nselect * from permission_role where permission_id = 226;\n\nselect * from migrations order by id desc;\n\n# mercury\n# neptune\n# earth\n\nselect * from teams;\nselect * from teams where id = 19;\nselect * from teams where id = 27;\nselect * from users where team_id = 27;\nSELECT * FROM crm_configurations WHERE id = 42;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 19\nand sa.provider = 'pipedrive';\n\nselect * from activities where id = 631461;\nSELECT * FROM crm_field_values WHERE crm_field_id = 180;\n\nselect * from teams where id = 2;\nSELECT * FROM social_accounts WHERE sociable_id = 89;\n\nSELECT * FROM activities WHERE uuid_to_bin('ba0c029a-bc14-4e17-8603-64174acebcbb') = uuid; # 634273\nselect * from activity_summary_logs where activity_id = 634273;\n\nselect * from sidekick_settings where team_id = 2;\n\nselect * from teams; # 2, 2\nSELECT * FROM crm_configurations WHERE team_id = 2; # 2\nselect * from team_features where team_id = 2;\nselect * from features;\nSELECT * FROM opportunities WHERE crm_configuration_id = 2 and crm_provider_id = '51317301383';\nSELECT * FROM opportunities WHERE crm_configuration_id = 2 order by id desc;\n\nselect * from automated_reports order by id desc;\nselect * from automated_report_results order by id desc;\nselect * from users where team_id = 1 and id IN (7160, 3248);\nselect * from migrations order by id desc;\n\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 1 and sa.provider = 'salesforce';\n\nselect * from teams where id = 1;\nselect * from groups g JOIN playbooks p on g.playbook_id = p.id where g.team_id = 1;\nselect * from groups where id = 565;\nselect * from playbooks where team_id = 1;\nselect * from playbooks where id = 175;\nselect * from playbook_categories where playbook_id = 175;\nselect * from users where team_id = 1;\nselect * from users where id = 7160;\nselect * from crm_profiles where user_id = 7160;\nselect * from features;\nselect\n *\n# id, uuid, type, provider, playbook_category_id, user_id, lead_id, contact_id, account_id, opportunity_id, stage_id,\n# crm_configuration_id, crm_provider_id, transcription_id, status\nfrom activities where crm_configuration_id = 1 and type = 'conference'\n# and crm_provider_id IS NOT NULL\nand provider != 'uploader' and actual_start_time IS NOT NULL\nORDER by id desc;\nselect * from activities where id = 54747783; # 00UO400000pCzojMAC\n\nselect p.id, p.activity_type, pc.id, pc.name\nFROM playbooks p\njoin playbook_categories pc on p.id = pc.playbook_id\nwhere p.team_id = 1 and p.activity_type = 'event';\n\nSELECT * FROM crm_fields WHERE crm_configuration_id = 1 and object_type = 'event';\nSELECT * FROM crm_field_values WHERE crm_field_id = 4;\n\nselect * from crm_layouts cl join playbook_layouts pl on cl.id = pl.layout_id\nwhere crm_configuration_id = 1 and pl.playbook_id = 175;\n\nselect * from teams;\nSELECT r.* FROM automated_reports r\njoin teams t on r.team_id = t.id\nWHERE r.frequency = 'daily'\n and r.status = 1\nAND t.status = 'active'\nAND (r.expires_at >= now() OR r.expires_at IS NULL);\n\nselect * from automated_report_results where report_id IN (18, 33);\n\nselect * from activity_searches where id = 10932;\nselect * from activity_search_filters where activity_search_id = 10932;\nselect * from automated_reports;\nselect * from automated_report_results where report_id IN (34, 35);","depth":4,"value":"SELECT * FROM teams WHERE id = 1;\n\nselect * from crm_layouts where crm_configuration_id = 39;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 283;\nSELECT * FROM crm_fields WHERE id = 2234;\nSELECT * FROM crm_field_values WHERE crm_field_id = 2234;\n\nselect * from crm_profiles where user_id = 143;\n\nselect * from record_types where crm_configuration_id = 39; # 0121K000001MHElQAO,0121K000001MHEqQAO\nselect * from business_processes where crm_configuration_id = 39;\n# 01941000000H669AAC, 01941000000H66JAAS\n\nselect * from record_type_field_values\n where record_type_id IN (24);\n\nselect * from crm_field_values where id IN (2730);\n\nselect * from crm_configurations where id = 39;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 1\nand sa.provider = 'salesforce'; #1035\n\n\nselect * from users where team_id = 1; # 222 group 3\nSELECT * FROM activities WHERE user_id = 222 order by id desc;\nselect * from sidekick_settings where team_id = 1;\nselect * from teams where id = 1;\nselect * from team_features where team_id = 1;\n\nselect * from activities where crm_configuration_id = 2\nand provider = 'ms-teams' and id = 608765;\n\nSELECT * FROM activities WHERE crm_configuration_id = 2 and crm_provider_id = '59523413338';\n\nselect * from sidekick_settings where team_id = 2;\n\nSELECT * FROM activities WHERE id = 608660;\nselect * from activity_summary_logs where activity_id = 608660;\nselect * from ai_prompts where transcription_id = 11214;\n\n# ********************************************************************************************************\nSELECT * FROM activities WHERE uuid_to_bin('ed78a437-2804-450e-ab2f-56ab1c641346') = uuid;\n# id: 608818, crm: 59628809737\nSELECT * FROM activities WHERE uuid_to_bin('36b06e55-afdd-4782-8dee-c624cd0af191') = uuid;\n# id: 608821, crm: 59632069252\nSELECT ce.start_time, ce.end_time, a.id, a.uuid, crm_provider_id, calendar_event_id, title,\nplaybook_category_id, user_id, lead_id, contact_id, account_id, opportunity_id,\nscheduled_start_time, scheduled_end_time, actual_start_time, actual_end_time, a.created_at\nFROM activities a\njoin calendar_events ce on a.calendar_event_id = ce.id\nWHERE a.id IN (608818, 608821);\n\nselect * from users where team_id = 1;\nselect * from team_settings where team_id = 1;\nselect * from crm_profiles where crm_configuration_id = 39 order by user_id;\n\nselect * from team_features where team_id = 1;\n\nselect * from users where team_id = 2;\n\nSELECT * FROM activities WHERE uuid_to_bin('ec7647e9-5225-458b-b475-f31aa2769204') = uuid; # 612639\n# Preslava N. Ivanova, grou id 3\n\nSELECT * FROM opportunities WHERE uuid_to_bin('a2928fe5-aec5-46cb-85d9-7654c89e46a6') = uuid;\n\nselect * from activities where opportunity_id = 344 and actual_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00';\n\nselect\n a.id,\n a.type,\n a.scheduled_start_time,\n a.actual_start_time,\n a.created_at,\n a.opportunity_id,\n a.status\nFROM activities a\nWHERE opportunity_id = 344\nand status IN ('completed', 'received', 'delivered')\nand (\n (a.actual_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00')\nOR (a.created_at between '2024-10-11 00:00:00' and '2024-10-12 00:00:00')\nOR (a.scheduled_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00'))\n;\n\nSELECT * FROM users WHERE id = 222;\n\nSELECT * FROM crm_profiles WHERE user_id = 222;\nselect * from crm_layouts where crm_configuration_id = 39;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 281;\n\nselect * from group_deal_risk_types;\n\nselect * from opportunities where team_id = 1;\n\nSELECT * FROM opportunities WHERE id = 315;\nSELECT * FROM crm_field_data WHERE object_id = 315;\nselect * from crm_field_data where object_id = 260;\n\nselect * from generic_ai_prompts where subject_id = 315;\n\nselect * from teams; # 36, 21, 121, james.graham@bullhorn.jiminny.com\nSELECT * FROM social_accounts WHERE sociable_id = 121 and provider = 'bullhorn';\n\n# ************************************************************************************\nselect * from teams where id = 1;\nselect * from crm_configurations where id = 39;\nselect * from users where team_id = 1;\nselect u.email, cp.* from users u\njoin crm_profiles cp on u.id = cp.user_id\nwhere u.team_id = 1;\n# 1 - 00541000004281rAAA\n# 204 - 0052g000003freeAAA\n# 429 - 0052g000003qGOiAAM\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 1\nand sa.provider = 'salesforce';\n\nselect * from activities where type = 'softphone'\nand created_at > '2024-12-11 15:24:36' order by id desc;\n\nselect * from activity_providers where team_id = 1;\nselect * from activity_provider_users where activity_provider_id = 328;\n\nselect * from opportunities where crm_configuration_id = 39\nAND account_id = 178 AND is_closed = false\norder by created_at DESC;\n\nselect * from contacts where id = 3952;\nselect * from accounts where id = 178;\n\n# ************************************************************************************\nselect * from teams where id = 36;\nselect * from crm_configurations where id = 21;\nselect * from users where team_id = 36;\nselect u.email, cp.* from users u\njoin crm_profiles cp on u.id = cp.user_id\nwhere u.team_id = 36;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 36\nand sa.provider = 'bullhorn';\n\nselect * from social_accounts where id = 348;\nUPDATE social_accounts SET\nprovider_user_token = '21442_6802599_91:41179a58-21e7-4d7c-ad58-56bb666b2f65',\nprovider_refresh_token = '21442_6802599_91:01c6b335-3f2a-42e4-85ff-8a08fa65fceb',\nexpires = 1733998131,\nstate = 'connected'\nWHERE id = 348;\n\n# ************************************************************************************\nselect * from teams where id = 31;\nselect * from crm_configurations where id = 18;\n\nselect * from users where team_id = 31; # 257\nselect u.email, cp.* from users u\njoin crm_profiles cp on u.id = cp.user_id\nwhere u.team_id = 31;\n\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 31\nand sa.provider = 'close';\n\nselect * from contacts where crm_configuration_id = 18;\n\n# ********************** NEPTUNE **************************************************************\nselect * from teams;\nselect * from users where id IN (1030, 1035, 1052);\nselect * from crm_configurations;\n\nselect * from users where team_id = 65; # 257\nselect * from team_settings where team_id = 65; # 257\nselect * from invitations where team_id = 65; # 257\nselect * from users where email = 'integration-account@jiminny.com'; # 257\nselect u.email, cp.* from users u\njoin crm_profiles cp on u.id = cp.user_id\nwhere u.team_id = 65;\n\nselect * from crm_configurations where id = 53;\nselect * from accounts where crm_configuration_id = 53 order by id desc;\nselect * from leads where crm_configuration_id = 53 order by id desc;\nselect * from contacts where crm_configuration_id = 53 order by id desc;\nselect * from opportunities where crm_configuration_id = 53 order by id desc;\nselect * from crm_profiles where crm_configuration_id = 53 order by id desc;\nselect * from crm_fields where crm_configuration_id = 53 order by id desc;\nselect * from crm_field_values where crm_field_id = 3341 order by id desc;\nselect * from crm_layouts where crm_configuration_id = 53 order by id desc;\nselect * from stages where crm_configuration_id = 53 order by id desc;\n\n\nselect * from crm_profiles where crm_configuration_id = 13;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 65\nand sa.provider = 'integration-app';\n\nselect * from contacts where crm_configuration_id = 13;\n\nselect * from social_accounts where sociable_id = 283;\n\nSELECT * FROM opportunities WHERE crm_provider_id = '006O400000E9bzeIAB';\n\nselect * from activity_providers where team_id = 65;\nSELECT * FROM activities WHERE crm_configuration_id IN (51, 52, 53);\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 65\n;\n\n# ***************************** STAGING ********************************************\nSELECT * FROM teams;\nSELECT * FROM teams WHERE id = 88;\nSELECT * FROM teams WHERE id = 89;\nselect * from team_settings where team_id = 89;\nSELECT * FROM users WHERE team_id = 89;\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 89;\n\nselect * from users;\nSELECT * FROM social_accounts WHERE sociable_id = 1761;\nSELECT * FROM crm_configurations WHERE id = 70;\nselect * from accounts where crm_configuration_id = 70 order by id desc;\nselect * from leads where crm_configuration_id = 70 order by id desc;\nselect * from contacts where crm_configuration_id = 70 order by id desc;\nselect * from opportunities where crm_configuration_id = 70 order by id desc;\nselect * from crm_profiles where crm_configuration_id = 70 order by id desc;\nselect * from crm_fields where crm_configuration_id = 70 order by id desc;\nselect * from crm_field_values where crm_field_id = 3536 order by id desc;\nselect * from crm_layouts where crm_configuration_id = 70 order by id desc;\nselect * from stages where crm_configuration_id = 70 order by id desc;\nselect * from business_processes where crm_configuration_id = 70 order by id desc;\nselect * from business_process_stages where business_process_id = 34;\n\nselect * from contacts where id = 10468;\n\nselect * from crm_layouts where crm_configuration_id = 70;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 388;\nSELECT * FROM crm_fields WHERE id IN (3533,3534,3535);\n\nselect * from activities where crm_configuration_id = 70\nand (account_id IS NOT NULL or lead_id IS NOT NULL or contact_id IS NOT NULL or opportunity_id IS NOT NULL) order by id desc;\n\nSELECT * FROM activities WHERE uuid_to_bin('2e10b60f-8a61-41c5-a3d4-28835353dc65') = uuid;\nSELECT * FROM activities where crm_configuration_id = 69 ;\n\nSELECT * FROM users WHERE email LIKE '%jiminny_web_sa2@jiminny.com%';\nSELECT * FROM activities WHERE uuid_to_bin('5a150c93-40fc-42ec-b3bd-c1d328e09f6e') = uuid;\nSELECT * FROM opportunities WHERE id = 385;\n\nselect * from participants p\njoin activities a on p.activity_id = a.id\nwhere a.crm_configuration_id = 70\nand (p.lead_id IS NOT NULL or p.contact_id IS NOT NULL);\nSELECT * FROM participants WHERE id = 1013638;\n\nselect * from teams where id = 90;\nselect * from users where team_id = 90;\nselect * from social_accounts where social_accounts.sociable_id IN (1960,1760);\nSELECT * FROM crm_profiles WHERE crm_configuration_id = 71;\nselect * from invitations where team_id = 90;\n\nselect * from crm_configurations where id = 71;\nselect * from accounts where crm_configuration_id = 71 order by id desc;\nselect * from leads where crm_configuration_id = 71 order by id desc;\nselect * from contacts where crm_configuration_id = 71 order by id desc;\nselect * from opportunities where crm_configuration_id = 71 order by id desc;\nselect * from crm_profiles where crm_configuration_id = 71 order by id desc;\nselect * from crm_fields where crm_configuration_id = 71 order by id desc;\nselect * from crm_field_values where crm_field_id = 3341 order by id desc;\nselect * from crm_layouts where crm_configuration_id = 71 order by id desc;\nselect * from stages where crm_configuration_id = 71 order by id desc;\n\nselect * from users order by secondary_email desc;\nselect u.id, u.email, u.status, sa.id, sa.provider_user_id from social_accounts sa\n join users u on sa.sociable_id = u.id\nwhere sa.provider = 'google' and u.email LIKE 'aneliya%';\n\nselect * from failed_jobs order by id desc;\n\nselect * from users where email = 'ben.allwright@learningpeople.co.uk' or secondary_email = 'ben.allwright@learningpeople.co.uk';\n\nselect * from teams;\nSELECT * FROM crm_profiles WHERE crm_configuration_id = 39;\nSELECT * FROM crm_fields WHERE crm_configuration_id = 39 and object_type = 'task';\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 1\nand sa.provider = 'salesforce';\n\n# ************************************************************************************\nSELECT * FROM activities WHERE uuid_to_bin('c38b3895-fd0f-4b1f-9fb2-c170dba137c6') = uuid;\nSELECT * FROM crm_configurations WHERE id = 70;\n\nselect * from teams where id = 1;\nselect * from groups where team_id = 1;\nselect * from users where team_id = 1;\n\nselect o.id, o.name,o.close_date, u.id, u.name, u.group_id, r.id, r.display_name, g.name, g.scope from opportunities o\njoin users u on o.user_id = u.id\njoin groups g on u.group_id = g.id\njoin role_user ru on u.id = ru.user_id\njoin roles r on ru.role_id = r.id\nwhere o.crm_configuration_id = 39 and close_date > '2024-01-01 00:00:00';\n\nselect * from role_user where user_id = 143;\nselect * from roles;\n\nselect * from role_user;\nselect * from groups where id = 9;\nselect * from scope_groups where group_id = 9;\n\n# ************************************************************************************\nselect * from teams where id = 36;\nselect * from crm_configurations;\nSELECT * FROM social_accounts WHERE sociable_id = 121;\n\nhttps://crmsandbox.zoho.com/crm/jiminnyw4/tab/Leads/4776201000005049105\nhttps://crmsandbox.zoho.com/crm/\n\nhttps://crm.zoho.com/crm/org3469620/tab/Leads/230045000229559080\n https://crm.zoho.com/crm/\n org3469620\n\nSELECT * FROM activities WHERE uuid_to_bin('03382d20-c8bc-48e7-a3d4-90b52fa5ceab') = uuid;\n\nselect * from users where email LIKE \"%mobile_automation_%\";\nselect * from social_accounts where sociable_id IN (2228);\nselect * from crm_profiles where user_id IN (2222,2223,2226,2227);\n\nselect * from teams order by id desc;\nSELECT * FROM users WHERE id = 2229;\nSELECT * FROM crm_profiles WHERE user_id = 2229;\nselect * from opportunities where crm_configuration_id = 88;\nselect * from crm_fields where crm_configuration_id = 88;\nselect * from crm_profiles where crm_configuration_id = 88;\n\nSELECT * FROM teams WHERE id = 1;\n\nSELECT * FROM users WHERE id = 143;\nSELECT * FROM users WHERE uuid_to_bin('fde193d3-06a2-4e1a-8895-62b94039215d') = uuid;\nSELECT * FROM teams WHERE uuid_to_bin('73385071-a756-42ae-9c73-8b53f2309467') = uuid;\n\nhttps://app.staging.jiminny.com/ondemand?\n min_duration=1\n &\n only_recorded=1\n &\n user_id%5B%5D=641f1acb-16b8-42d1-8726-df52979dad0e\n &\n sequence_number=2\n\n select * from users where team_id = 1 and email like '%stoyan%'\n\nselect * from coaching_feedbacks;\n\nselect * from teams;\nSELECT * FROM users WHERE team_id = 36;\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 19\nand sa.provider = 'pipedrive';\n\nselect * from users where id = 143;\n\nSELECT * FROM users WHERE uuid_to_bin('73180eeb-33de-4065-977d-ccbe0e6c94fc') = uuid;\nSELECT * FROM teams WHERE uuid_to_bin('73180eeb-33de-4065-977d-ccbe0e6c94fc') = uuid;\nSELECT * FROM activity_shares WHERE uuid_to_bin('73180eeb-33de-4065-977d-ccbe0e6c94fc') = uuid;\n\nselect * from users where team_id = 2;\nselect * from activities where crm_configuration_id = 39\nand activities.scheduled_start_time BETWEEN '2025-04-09 00:00:00' AND '2025-04-09 23:59:59'\nAND user_id = 143\norder by id desc;\n\n# ************************************************************************************\nselect * from teams where id = 142; # 2312, 126\nselect * from team_settings;\nselect * from users where team_id = 142; # 21642\nSELECT * FROM social_accounts WHERE sociable_id = 21642;\nSELECT * FROM crm_profiles cp join users u ON u.id = cp.user_id WHERE team_id = 142;\nselect * from crm_profiles where id IN (93);\nselect * from invitations;\nselect * from team_features where team_id = 1;\n\nSELECT * FROM crm_configurations WHERE id = 126;\nselect * from accounts where crm_configuration_id = 126 order by id desc;\nselect * from leads where crm_configuration_id = 126 order by id desc;\nselect * from contacts where crm_configuration_id = 126 order by id desc;\nselect * from opportunities where crm_configuration_id = 126 order by id desc;\nselect * from crm_profiles where crm_configuration_id = 126 order by id desc;\nselect * from crm_fields where crm_configuration_id = 126 # 11060\n# and type IN ('picklist', 'status')\n# and object_type = 'task'\norder by id desc;\n# 5731,5732,5733\nselect DISTINCT crm_field_id from crm_field_values where crm_field_id IN (11151,12239,12215,12185,12175,12165,12144,12137,12127,12109,12107,12105,12103,12092,12037,12005,12003,11987,11969,11958,11951,11942,11931,11924,11921,11917,11915,11901,11893,11883,11872,11870,11868,11866,11839,11833,11821,11793,11780,11777,11769,11757,11737,11735,11656,11645,11638,11629,11618,11611,11602,11591,11584,11581,11558,11544,11543,11534,11532,11529,11527,11503,11497,11493,11488,11470,11468,11457,11455,11397,11387,11372,11363,11348,11323,11318,11309,11301,11300,11292,11290,11286,11284,11256,11252,11242,11237,11233,11219,11176,11160) order by id desc;\nselect * from crm_layouts where crm_configuration_id = 126 order by id desc;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id in (300,299,298);\nselect * from stages where crm_configuration_id = 126 order by id desc;\nselect * from business_processes where crm_configuration_id = 126 order by id desc;\nselect * from business_process_stages where business_process_id IN (76,75,74,73);\nselect * from playbooks where team_id = 142;\nselect * from playbook_layouts where playbook_id IN (108);\nSELECT * FROM playbook_categories WHERE playbook_id IN (108);\n\nselect * from teams where id = 130;\nSELECT * FROM social_accounts WHERE sociable_id = 2291;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 2\nand sa.provider = 'hubspot';\n\nSELECT * FROM activities\n WHERE crm_configuration_id = 110;\n\nselect * from teams;\nselect * from crm_configurations;\n\nSELECT * FROM activities WHERE id = 628773;\nSELECT * FROM crm_profiles WHERE user_id = 1460;\nSELECT * FROM social_accounts WHERE sociable_id = 2291;\n\nselect * from teams;\nselect ru.*, pr.*, p.* from users u join role_user ru on ru.user_id = u.id\njoin permission_role pr on pr.role_id = ru.role_id\n join permissions p on p.id = pr.permission_id\nwhere team_id = 495 and p.name IN ('dial');\n\nselect * from teams where id = 145;\nselect * from crm_configurations where id = 129;\nselect * from social_accounts where sociable_id = 2317;\nSELECT * FROM activities WHERE uuid_to_bin('8dbab184-a333-4268-ad57-fb41f8d53a9a') = uuid;\n\nselect * from teams where id = 1;\nSELECT * FROM crm_layouts WHERE crm_configuration_id = 39;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 280;\nSELECT * FROM crm_layout_entities WHERE id = 5507;\nSELECT * FROM crm_fields WHERE crm_configuration_id = 39 and object_type IN ('event');\n\nselect * from teams;\nselect * from activities where crm_configuration_id = 14;\n\nSELECT * FROM social_accounts where provider = 'copper';\n\nselect * from activities where id = 628467;\nselect * from participants where activity_id = 628467;\n\nSELECT * FROM contacts WHERE id = 3969;\nSELECT * FROM accounts WHERE id = 177;\n\nSELECT * FROM activities WHERE uuid_to_bin('4eb54c77-cfa3-2bd4-84a7-9ed46a21c988') = uuid;\n\n# ********************* BH\nselect * from teams where id = 36;\nSELECT * FROM crm_configurations WHERE id = 21;\nselect * from activities where crm_configuration_id = 21 and id = 607901;\nselect * from activities where crm_configuration_id = 21;\n\nselect * roles;\nselect * from permissions;\nselect * from permission_role where permission_id = 226;\n\nselect * from migrations order by id desc;\n\n# mercury\n# neptune\n# earth\n\nselect * from teams;\nselect * from teams where id = 19;\nselect * from teams where id = 27;\nselect * from users where team_id = 27;\nSELECT * FROM crm_configurations WHERE id = 42;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 19\nand sa.provider = 'pipedrive';\n\nselect * from activities where id = 631461;\nSELECT * FROM crm_field_values WHERE crm_field_id = 180;\n\nselect * from teams where id = 2;\nSELECT * FROM social_accounts WHERE sociable_id = 89;\n\nSELECT * FROM activities WHERE uuid_to_bin('ba0c029a-bc14-4e17-8603-64174acebcbb') = uuid; # 634273\nselect * from activity_summary_logs where activity_id = 634273;\n\nselect * from sidekick_settings where team_id = 2;\n\nselect * from teams; # 2, 2\nSELECT * FROM crm_configurations WHERE team_id = 2; # 2\nselect * from team_features where team_id = 2;\nselect * from features;\nSELECT * FROM opportunities WHERE crm_configuration_id = 2 and crm_provider_id = '51317301383';\nSELECT * FROM opportunities WHERE crm_configuration_id = 2 order by id desc;\n\nselect * from automated_reports order by id desc;\nselect * from automated_report_results order by id desc;\nselect * from users where team_id = 1 and id IN (7160, 3248);\nselect * from migrations order by id desc;\n\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 1 and sa.provider = 'salesforce';\n\nselect * from teams where id = 1;\nselect * from groups g JOIN playbooks p on g.playbook_id = p.id where g.team_id = 1;\nselect * from groups where id = 565;\nselect * from playbooks where team_id = 1;\nselect * from playbooks where id = 175;\nselect * from playbook_categories where playbook_id = 175;\nselect * from users where team_id = 1;\nselect * from users where id = 7160;\nselect * from crm_profiles where user_id = 7160;\nselect * from features;\nselect\n *\n# id, uuid, type, provider, playbook_category_id, user_id, lead_id, contact_id, account_id, opportunity_id, stage_id,\n# crm_configuration_id, crm_provider_id, transcription_id, status\nfrom activities where crm_configuration_id = 1 and type = 'conference'\n# and crm_provider_id IS NOT NULL\nand provider != 'uploader' and actual_start_time IS NOT NULL\nORDER by id desc;\nselect * from activities where id = 54747783; # 00UO400000pCzojMAC\n\nselect p.id, p.activity_type, pc.id, pc.name\nFROM playbooks p\njoin playbook_categories pc on p.id = pc.playbook_id\nwhere p.team_id = 1 and p.activity_type = 'event';\n\nSELECT * FROM crm_fields WHERE crm_configuration_id = 1 and object_type = 'event';\nSELECT * FROM crm_field_values WHERE crm_field_id = 4;\n\nselect * from crm_layouts cl join playbook_layouts pl on cl.id = pl.layout_id\nwhere crm_configuration_id = 1 and pl.playbook_id = 175;\n\nselect * from teams;\nSELECT r.* FROM automated_reports r\njoin teams t on r.team_id = t.id\nWHERE r.frequency = 'daily'\n and r.status = 1\nAND t.status = 'active'\nAND (r.expires_at >= now() OR r.expires_at IS NULL);\n\nselect * from automated_report_results where report_id IN (18, 33);\n\nselect * from activity_searches where id = 10932;\nselect * from activity_search_filters where activity_search_id = 10932;\nselect * from automated_reports;\nselect * from automated_report_results where report_id IN (34, 35);","role_description":"text entry area","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.088194445,"height":0.027777778},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"102","depth":4,"role_description":"text"},{"role":"AXStaticText","text":"3","depth":4,"role_description":"text"},{"role":"AXStaticText","text":"34","depth":4,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Services\\Kiosk\\AutomatedReports;\n\nuse Carbon\\CarbonImmutable;\nuse Carbon\\CarbonInterface;\nuse Carbon\\Exceptions\\InvalidFormatException;\nuse DateTime;\nuse DateTimeInterface;\nuse DateTimeZone;\nuse Illuminate\\Contracts\\Bus\\Dispatcher as BusDispatcher;\nuse Illuminate\\Database\\Eloquent\\Builder;\nuse Illuminate\\Support\\Carbon;\nuse Illuminate\\Support\\Collection;\nuse Illuminate\\Support\\Facades\\Log;\nuse Illuminate\\Support\\Facades\\Storage;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinition\\InputTypeEnum;\nuse Jiminny\\Component\\AskAnything\\AskAnythingPromptService;\nuse Jiminny\\Component\\AskAnything\\Dtos\\AskAnythingPromptDto;\nuse Jiminny\\Component\\UrlGenerator\\Webhook;\nuse Jiminny\\Contracts\\Repositories\\PlaybookCategoryRepository;\nuse Jiminny\\Contracts\\Repositories\\TeamRepository;\nuse Jiminny\\Contracts\\Repositories\\UserRepository;\nuse Jiminny\\Exceptions\\ApplicationException;\nuse Jiminny\\Exceptions\\InvalidArgumentException;\nuse Jiminny\\Exceptions\\ModelNotFoundException;\nuse Jiminny\\Jobs\\AutomatedReports\\RequestGenerateReportJob;\nuse Jiminny\\Models\\Activity\\Search;\nuse Jiminny\\Models\\AskAnything\\AskAnythingPrompt;\nuse Jiminny\\Models\\AskAnything\\AskAnythingPromptTarget;\nuse Jiminny\\Models\\AutomatedReport;\nuse Jiminny\\Models\\AutomatedReportResult;\nuse Jiminny\\Models\\Contracts\\UserContract;\nuse Jiminny\\Models\\Feature\\FeatureEnum;\nuse Jiminny\\Models\\Team;\nuse Jiminny\\Models\\User;\nuse Jiminny\\Repositories\\AskAnythingRepository;\nuse Jiminny\\Repositories\\AutomatedReportsRepository;\nuse Jiminny\\Repositories\\GroupRepository;\nuse Jiminny\\Repositories\\SearchRepository;\nuse Jiminny\\Repositories\\StageRepository;\nuse Throwable;\n\nclass AutomatedReportsService\n{\n public const string TYPE_LOSS_ANALYSIS = 'loss_analysis';\n public const string TYPE_ASK_JIMINNY = 'ask_jiminny';\n\n /**\n * Standard report types (used by kiosk for existing automated reports).\n */\n // @TODO this will add filter, however if we need to control feature by FF we need conditional logic\n public const array TYPES = [\n ['id' => 'exec_summary', 'name' => 'Exec Summary'],\n ['id' => 'coaching_profiles', 'name' => 'Coaching Profiles'],\n ['id' => 'product_feedback', 'name' => 'Product Feedback'],\n ['id' => self::TYPE_LOSS_ANALYSIS, 'name' => 'Loss Analysis'],\n// ['id' => 'questions', 'name' => 'Questions'],\n// ['id' => 'statistical_quant', 'name' => 'Statistical Quantitative'],\n ];\n\n public const array ALL_TYPES = [\n ...self::TYPES,\n ['id' => self::TYPE_ASK_JIMINNY, 'name' => 'Ask Jiminny'],\n ];\n\n public const string FREQUENCY_DAILY = 'daily';\n public const string FREQUENCY_WEEKLY = 'weekly';\n public const string FREQUENCY_MONTHLY = 'monthly';\n public const string FREQUENCY_QUARTERLY = 'quarterly';\n public const string FREQUENCY_ONE_OFF = 'one_off';\n\n /**\n * Frequencies for standard (non-Ask Jiminny) reports.\n */\n public const array FREQUENCIES = [\n ['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],\n ['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],\n ['id' => self::FREQUENCY_QUARTERLY, 'name' => 'Quarterly'],\n ['id' => self::FREQUENCY_ONE_OFF, 'name' => 'One-off'],\n ];\n\n /**\n * Frequencies for Ask Jiminny reports.\n */\n public const array ASK_JIMINNY_FREQUENCIES = [\n ['id' => self::FREQUENCY_DAILY, 'name' => 'Daily'],\n ['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],\n ['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],\n ];\n\n public const string MEDIA_TYPE_PDF = 'pdf';\n public const string MEDIA_TYPE_PODCAST = 'podcast';\n public const array MEDIA_TYPES = [self::MEDIA_TYPE_PDF, self::MEDIA_TYPE_PODCAST];\n public const array MEDIA_TYPE_OBJECT_PDF = ['id' => self::MEDIA_TYPE_PDF, 'name' => 'PDF'];\n public const array MEDIA_TYPE_OBJECT_PODCAST = ['id' => self::MEDIA_TYPE_PODCAST, 'name' => 'Podcast'];\n public const array MEDIA_TYPE_OBJECTS = [self::MEDIA_TYPE_OBJECT_PDF, self::MEDIA_TYPE_OBJECT_PODCAST];\n\n public const array CALL_TYPE_CONFERENCE = ['id' => 'conference', 'name' => 'Conference'];\n public const array CALL_TYPE_DIALER = ['id' => 'dialer', 'name' => 'Dialer'];\n public const int SENT_REPORT_AT_HOURS = 5;\n public const string PDF_KEY = 'pdf';\n public const string AUDIO_KEY = 'audio';\n\n private const array ALL_FREQUENCIES = [\n ['id' => self::FREQUENCY_DAILY, 'name' => 'Daily'],\n ['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],\n ['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],\n ['id' => self::FREQUENCY_QUARTERLY, 'name' => 'Quarterly'],\n ['id' => self::FREQUENCY_ONE_OFF, 'name' => 'One-off'],\n ];\n private const string S3_DIR = 'reports';\n private const array FILE_EXTENSIONS_VARIANTS = ['html', 'MD', 'pdf'];\n private const array FILE_PODCAST_EXTENSIONS_VARIANTS = ['json', 'mp3', 'ssml'];\n\n public function __construct(\n private readonly TeamRepository $teamRepository,\n private readonly GroupRepository $groupRepository,\n private readonly UserRepository $userRepository,\n private readonly StageRepository $stageRepository,\n private readonly DealStagesService $dealStagesService,\n private readonly RecipientsService $recipientsService,\n private readonly AutomatedReportsRepository $automatedReportsRepository,\n private readonly Webhook $webhookService,\n private readonly BusDispatcher $dispatcher,\n private readonly ActivityTypeService $activityTypeService,\n private readonly PlaybookCategoryRepository $playbookCategoryRepository,\n private readonly AskAnythingPromptService $askAnythingPromptService,\n private readonly SearchRepository $activitySearchRepository,\n private readonly AskAnythingRepository $askAnythingRepository,\n ) {\n }\n\n public static function getTypes(): array\n {\n $types = self::TYPES;\n\n return array_map(static function ($type) {\n return $type['id'];\n }, $types);\n }\n\n public static function getCallTypes(): array\n {\n return array_map(static function ($callType) {\n return $callType['id'];\n }, [self::CALL_TYPE_CONFERENCE, self::CALL_TYPE_DIALER]);\n }\n\n public static function getFrequencies(): array\n {\n return array_map(static function ($frequency) {\n return $frequency['id'];\n }, self::FREQUENCIES);\n }\n\n // front-facing structure\n public function getReportEnabledFieldData(bool $value = false): array\n {\n return [\n 'id' => 'report_enabled',\n 'label' => '',\n 'inputType' => InputTypeEnum::TOGGLE,\n 'value' => $value,\n ];\n }\n\n // Organizations = Teams\n public function getOrganizationFieldData(?string $value = null, bool $shortVersion = false): array\n {\n $options = $this->getTeams();\n\n if ($shortVersion) {\n return [\n 'id' => 'organization',\n 'label' => 'Organization',\n 'options' => $options,\n ];\n }\n\n return [\n 'id' => 'organization',\n 'label' => 'Organization',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => $options,\n 'value' => $value,\n 'dependencies' => [\n 'teams',\n 'deal_stage_at_call',\n 'current_deal_stage',\n 'recipients',\n ActivityTypeService::PLAYBOOK_CATEGORIES_KEY,\n ],\n 'dependsOn' => [],\n ];\n }\n\n // Teams = Groups\n public function getTeamFieldData(array $options = [], array $value = [], bool $shortVersion = false): array\n {\n if ($shortVersion) {\n return [\n 'id' => 'teams',\n 'label' => 'Team',\n 'options' => $options,\n ];\n }\n\n return [\n 'id' => 'teams',\n 'label' => 'Team',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'required' => false,\n 'placeholder' => 'Select',\n 'options' => $options,\n 'value' => $value, // value should be an array of objects {id, name}\n 'dependencies' => [ActivityTypeService::PLAYBOOK_CATEGORIES_KEY],\n 'dependsOn' => [],\n ];\n }\n\n public function getReportTypeFieldData(?string $value = null, bool $shortVersion = false, ?Team $team = null): array\n {\n $types = [];\n if ($team instanceof Team) {\n if ($team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {\n $types = self::TYPES;\n }\n if ($team->hasFeature(FeatureEnum::ASK_JIMINNY_REPORTS)) {\n $types[] = ['id' => self::TYPE_ASK_JIMINNY, 'name' => 'Ask Jiminny'];\n }\n } else {\n $types = self::TYPES;\n }\n\n if ($shortVersion) {\n return [\n 'id' => 'report_type',\n 'label' => 'Report Type',\n 'options' => $types,\n ];\n }\n\n return [\n 'id' => 'report_type',\n 'label' => 'Report Type',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => $types,\n 'value' => $value,\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getFrequencyFieldData(?string $value = null): array\n {\n return [\n 'id' => 'frequency',\n 'label' => 'Frequency',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => self::FREQUENCIES,\n 'value' => $value,\n 'dependencies' => ['period'],\n 'dependsOn' => [],\n ];\n }\n\n public function getPeriodFieldData(?string $valueStartDate = null, ?string $valueEndDate = null): array\n {\n return [\n 'id' => 'period',\n 'label' => 'Select one-off period',\n 'inputType' => InputTypeEnum::DATE_RANGE,\n 'required' => true,\n 'placeholder' => 'Select',\n 'value' => ['startDate' => $valueStartDate, 'endDate' => $valueEndDate],\n 'queryParams' => [\n 'startDate' => 'start_date_period',\n 'endDate' => 'end_date_period',\n ],\n 'dependencies' => [],\n 'dependsOn' => ['frequency'],\n ];\n }\n\n public function getActivityTypesFieldData(?Team $team = null, array $value = [], array $teamsFilter = []): array\n {\n return $this->activityTypeService->getActivityTypeFieldData(team: $team, value: $value, groupIds: $teamsFilter);\n }\n\n public function getDealStageAtCallFieldData(?Team $team = null, array $value = []): array\n {\n return $this->dealStagesService->getDealStageAtCallFieldData(team: $team, value: $value);\n }\n\n public function getCurrentDealStageFieldData(?Team $team = null, array $value = []): array\n {\n return $this->dealStagesService->getCurrentDealStageFieldData(team: $team, value: $value);\n }\n\n public function getDealValueFieldData(?int $valueMin = null, ?int $valueMax = null): array\n {\n return [\n 'id' => 'deal_value',\n 'label' => 'Deal Value',\n 'inputType' => InputTypeEnum::INTEGER_RANGE,\n 'required' => false,\n 'value' => ['min' => $valueMin, 'max' => $valueMax],\n 'queryParams' => [\n 'min' => 'min_deal_value',\n 'max' => 'max_deal_value',\n ],\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getCallTypeFieldData(bool $conferenceOn = false, bool $dialerOn = false): array\n {\n $value = [];\n $conferenceOn && $value[] = self::CALL_TYPE_CONFERENCE;\n $dialerOn && $value[] = self::CALL_TYPE_DIALER;\n\n return [\n 'id' => 'call_type',\n 'label' => 'Call Type',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'required' => true,\n 'options' => [\n self::CALL_TYPE_CONFERENCE,\n self::CALL_TYPE_DIALER,\n ],\n 'value' => $value,\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getMediaTypeFieldData(?AutomatedReport $report = null): array\n {\n $value = [];\n\n if ($report) {\n $value = $this->transformMediaTypes($report);\n }\n\n return [\n 'id' => 'media_types',\n 'label' => 'Export as',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'required' => true,\n 'options' => self::MEDIA_TYPE_OBJECTS,\n 'value' => $value,\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getCallDurationFieldData(?int $valueMin = null, ?int $valueMax = null): array\n {\n return [\n 'id' => 'call_duration',\n 'label' => 'Call Duration',\n 'inputType' => InputTypeEnum::INTEGER_RANGE,\n 'required' => false,\n 'value' => ['min' => $valueMin, 'max' => $valueMax],\n 'queryParams' => [\n 'min' => 'min_call_duration',\n 'max' => 'max_call_duration',\n ],\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getRecipientsFieldData(?Team $team = null, array $value = []): array\n {\n return $this->recipientsService->getRecipientsFieldData(team: $team, value: $value);\n }\n\n public function getJiminnyRecipientsFieldData(array $value = []): array\n {\n return $this->recipientsService->getJiminnyRecipientsFieldData($value);\n }\n\n public function getAdditionalPromptInputFieldData(?string $value = null): array\n {\n return [\n 'id' => 'additional_prompt_input',\n 'label' => 'Special requirements',\n 'inputType' => InputTypeEnum::TEXTAREA,\n 'required' => false,\n 'placeholder' => 'What should be the focus of the report?',\n 'value' => $value,\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getCustomReportNameFieldData(?string $value = null): array\n {\n return [\n 'id' => 'custom_name',\n 'label' => 'Custom report name',\n 'inputType' => InputTypeEnum::TEXT,\n 'required' => false,\n 'placeholder' => 'Enter custom name',\n 'value' => $value,\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n // data providers\n public function getTeams(): array\n {\n $teams = $this->teamRepository->getTeamsForKiosk(status: Team::STATUS_ACTIVE);\n\n $teamData = [];\n foreach ($teams as $team) {\n if (! $team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {\n continue;\n }\n\n $teamData[] = $this->transformTeam($team);\n }\n\n return $teamData;\n }\n\n public function getTeamGroups(string $teamUuid): array\n {\n $data = [];\n $team = $this->getTeam($teamUuid);\n\n if ($team !== null) {\n $groups = $team->groups()->get();\n\n foreach ($groups as $group) {\n $data[] = [\n 'id' => $group->getUuid(),\n 'name' => $group->getName(),\n ];\n }\n }\n\n return $data;\n }\n\n public function getTeamsGroupsOptions(array $filterTeamUuids = []): array\n {\n $data = [];\n $teams = $this->getTeams();\n\n foreach ($teams as $team) {\n if (! empty($filterTeamUuids) && ! in_array($team['id'], $filterTeamUuids, true)) {\n continue;\n }\n\n $data[] = [\n 'label' => $team['name'],\n 'groups' => $this->getTeamGroups($team['id']),\n ];\n }\n\n return $data;\n }\n\n public function getTeam(string $teamUuid): ?Team\n {\n return $this->teamRepository->idOrUuid($teamUuid);\n }\n\n public function getTeamById(int $teamId): ?Team\n {\n return $this->teamRepository->find($teamId);\n }\n\n public function getGroupsUuids(AutomatedReport $report): array\n {\n $uuids = [];\n $reportGroups = $report->getGroups();\n foreach ($reportGroups as $groupId) {\n if ($group = $this->groupRepository->find($groupId)) {\n $uuids[] = $group->getUuid();\n }\n }\n\n return $uuids;\n }\n\n public function getPlaybookCategoriesUuids(AutomatedReport $report): array\n {\n $uuids = [];\n $playbookCategories = $report->getPlaybookCategories();\n foreach ($playbookCategories as $id) {\n if ($category = $this->playbookCategoryRepository->find($id)) {\n $uuids[] = $category->getUuid();\n }\n }\n\n return $uuids;\n }\n\n public function getDealAtCallStagesUuids(AutomatedReport $report): array\n {\n $uuids = [];\n $reportStages = $report->getDealAtCallStages();\n foreach ($reportStages as $id) {\n if ($stage = $this->stageRepository->find($id)) {\n $uuids[] = $stage->getUuid();\n }\n }\n\n return $uuids;\n }\n\n public function getCurrentDealStagesUuids(AutomatedReport $report): array\n {\n $uuids = [];\n $reportStages = $report->getCurrentDealStages();\n foreach ($reportStages as $id) {\n if ($stage = $this->stageRepository->find($id)) {\n $uuids[] = $stage->getUuid();\n }\n }\n\n return $uuids;\n }\n\n public function getUsersUuids(AutomatedReport $report): array\n {\n return $this->extractUserUuids($report->getRecipients());\n }\n\n public function getJiminnyUsersUuids(AutomatedReport $report): array\n {\n return $this->extractUserUuids($report->getJiminnyRecipients());\n }\n\n /**\n * @param array<string, mixed> $recipients\n */\n private function extractUserUuids(array $recipients): array\n {\n $userIds = $recipients['users'] ?? [];\n\n return collect($userIds)\n ->map(fn ($id) => $this->userRepository->find((int) $id))\n ->filter()\n ->map(fn (UserContract $user) => $user->getUuid())\n ->values()\n ->all();\n }\n\n // get mail data\n public function getRecipientUsers(AutomatedReport $report): array\n {\n return $this->buildRecipientUsers($report->getRecipients());\n }\n\n private function getJiminnyRecipientUsers(AutomatedReport $report): array\n {\n return $this->buildRecipientUsers($report->getJiminnyRecipients());\n }\n\n /**\n * @param array<string, mixed> $recipients\n */\n private function buildRecipientUsers(array $recipients): array\n {\n $userIds = $recipients['users'] ?? [];\n\n return collect($userIds)\n ->map(fn ($id) => $this->userRepository->find((int) $id))\n ->filter()\n ->map(fn (UserContract $user) => [\n 'email' => $user->getEmailAddress(),\n 'name' => $user->getName(),\n 'timezone' => $user->getTimezone()->getName(),\n ])\n ->values()\n ->all();\n }\n\n public function getValidRecipientUsers(AutomatedReport $report, bool $includeJiminny = false): array\n {\n if ($report->isAskJiminnyReport()) {\n $recipients = $this->resolveAskJiminnyRecipients($report);\n } else {\n $recipients = $this->getRecipientUsers($report);\n if ($includeJiminny) {\n $recipients = array_merge($recipients, $this->getJiminnyRecipientUsers($report));\n }\n }\n\n $emails = [];\n\n return array_values(array_filter(\n $recipients,\n static function ($recipient) use (&$emails) {\n if (empty($recipient['email']) || in_array($recipient['email'], $emails, true)) {\n return false;\n }\n $emails[] = $recipient['email'];\n\n return true;\n }\n ));\n }\n\n private function resolveAskJiminnyRecipients(AutomatedReport $report): array\n {\n $recipients = [];\n\n $creator = $report->getCreator();\n if ($creator !== null) {\n $recipients[] = [\n 'email' => $creator->getEmailAddress(),\n 'name' => $creator->getName(),\n 'timezone' => $creator->getTimezone()->getName(),\n ];\n }\n\n return array_merge(\n $recipients,\n $this->buildRecipientUsers($report->getRecipients()),\n $this->getGroupRecipientUsers($report),\n );\n }\n\n private function getGroupRecipientUsers(AutomatedReport $report): array\n {\n $users = [];\n foreach ($report->getGroups() as $groupId) {\n $group = $this->groupRepository->find($groupId);\n if ($group === null) {\n continue;\n }\n foreach ($group->getMembers() as $member) {\n $users[] = [\n 'email' => $member->getEmailAddress(),\n 'name' => $member->getName(),\n 'timezone' => $member->getTimezone()->getName(),\n ];\n }\n }\n\n return $users;\n }\n\n public function getReportTypeName(AutomatedReportResult $report): string\n {\n $type = $report->getReport()->getType();\n\n $getType = $this->transformReportType($type);\n\n return $getType['name'];\n }\n\n public function getReportPeriodName(AutomatedReportResult $report): string\n {\n $from = $report->getFromDate();\n $to = $report->getToDate();\n $frequency = $report->getReport()->getFrequency();\n\n if ($from === null || $to === null) {\n if (! $report->getReport()->isAskJiminnyReport()) {\n $invalidPeriod = $from === null ? 'from' : 'to';\n\n throw new ApplicationException('Report period is invalid: ' . $invalidPeriod);\n }\n\n $period = $this->calculateFromAndToDatePeriod($frequency);\n $from = $period['fromDate'];\n $to = $period['toDate'];\n }\n\n return $this->formatReportPeriodName($frequency, $from, $to);\n }\n\n private function formatReportPeriodName(string $frequency, Carbon $from, Carbon $to): string\n {\n $fromYear = $from->format('Y');\n $toYear = $to->format('Y');\n $differentYears = $fromYear !== $toYear;\n\n switch ($frequency) {\n case self::FREQUENCY_DAILY:\n return $from->format('j M Y');\n\n case self::FREQUENCY_QUARTERLY:\n // 'Jan-Mar 2025' or 'Nov 2024-Jan 2025' if years differ\n $startMonth = $from->format('M');\n $endMonth = $to->copy()->subMonth();\n $endMonthName = $endMonth->format('M');\n $endMonthYear = $endMonth->format('Y');\n\n if ($differentYears) {\n return \"{$startMonth} {$fromYear} - {$endMonthName} {$endMonthYear}\";\n }\n\n return \"{$startMonth} - {$endMonthName} {$toYear}\";\n\n case self::FREQUENCY_MONTHLY:\n // 'May 2025' - monthly reports are always within the same year\n return $from->format('M Y');\n\n case self::FREQUENCY_WEEKLY:\n // '4 - 8 Aug 2025', '27 Oct - 3 Nov 2025', or '28 Dec 2024 - 3 Jan 2025' if years differ\n $startDay = $from->format('j');\n $endDay = $to->format('j');\n $startMonth = $from->format('M');\n $endMonth = $to->format('M');\n\n if ($differentYears) {\n return \"{$startDay} {$startMonth} {$fromYear} - {$endDay} {$endMonth} {$toYear}\";\n }\n\n if ($startMonth !== $endMonth) {\n return \"{$startDay} {$startMonth} - {$endDay} {$endMonth} {$toYear}\";\n }\n\n return \"{$startDay} - {$endDay} {$endMonth} {$toYear}\";\n\n case self::FREQUENCY_ONE_OFF:\n // '2 May-31 May 2025' or '15 Dec 2024-15 Jan 2025' if years differ\n $startDay = $from->format('j');\n $startMonth = $from->format('M');\n $endDay = $to->format('j');\n $endMonth = $to->format('M');\n\n // If same month and year, use a format like '2-31 May 2025'\n if ($startMonth === $endMonth && ! $differentYears) {\n return \"{$startDay} - {$endDay} {$startMonth} {$toYear}\";\n }\n\n // If different years, include both years\n if ($differentYears) {\n return \"{$startDay} {$startMonth} {$fromYear} - {$endDay} {$endMonth} {$toYear}\";\n }\n\n // Same year but different months\n return \"{$startDay} {$startMonth} - {$endDay} {$endMonth} {$toYear}\";\n\n default:\n // Default format for unknown frequencies\n return $from->format('j M Y') . ' - ' . $to->format('j M Y');\n }\n }\n\n public function getReportTeamsName(AutomatedReportResult $report): string\n {\n $groups = $report->getGroups();\n\n if (empty($groups)) {\n return 'All';\n }\n\n // Get group names from repository\n $groupNames = [];\n foreach ($groups as $groupId) {\n $group = $this->groupRepository->find($groupId);\n if ($group) {\n $groupNames[] = $group->getName();\n }\n }\n\n if (count($groupNames) === 1) {\n // Single team format\n $teamsName = $groupNames[0];\n } else {\n // Multiple teams format\n $teamsName = implode(', ', $groupNames);\n }\n\n return $teamsName;\n }\n\n public function getReportFileName(AutomatedReportResult $report): string\n {\n $customName = $report->getReport()->getCustomName();\n $periodName = $this->getReportPeriodName($report);\n $filenameSuffix = $this->getFilenameSuffix($report);\n\n if ($customName) {\n if ($filenameSuffix) {\n $customName .= \" {$filenameSuffix}\";\n }\n\n return $this->sanitizeFileName(\"{$customName} - {$periodName}\");\n }\n\n $baseName = $this->getReportTypeName($report);\n\n if ($filenameSuffix) {\n $baseName .= \" {$filenameSuffix}\";\n }\n\n return $this->sanitizeFileName(\"{$baseName} - {$periodName} - {$this->getReportTeamsName($report)}\");\n }\n\n public function getReportFileNameWithExtension(AutomatedReportResult $result): string\n {\n $extension = $this->getMediaTypeMetadata($result)['extension'];\n\n return $this->getReportFileName($result) . '.' . $extension;\n }\n\n public function sanitizeFileName(string $fileName): string\n {\n return str_replace(['/', '\\\\'], '-', $fileName);\n }\n\n public function isUserRecipientOfReport(User $user, AutomatedReport $report): bool\n {\n $recipients = array_map('intval', $report->getRecipients()['users'] ?? []);\n\n return in_array($user->getId(), $recipients);\n }\n\n public function transformReportResults(Collection $automatedReportResults): array\n {\n $data = [];\n foreach ($automatedReportResults as $automatedReportResult) {\n /** @var AutomatedReportResult $automatedReportResult */\n\n $report = $automatedReportResult->getReport();\n\n $createdBy = $report->getCreator();\n $creator = [\n 'id' => $createdBy?->getUuid(),\n 'name' => $createdBy?->getName(),\n 'email' => $createdBy?->getEmailAddress(),\n 'photoUrl' => $createdBy?->getPhotoUrl(),\n ];\n\n $data[] = [\n 'id' => $automatedReportResult->getUuid(),\n 'name' => $automatedReportResult->getName(),\n 'frequency' => $this->transformFrequency($report->getFrequency()),\n 'recipients' => [\n ...array_values($this->transformGroups(team: $report->getTeam(), groupsIds: $report->getGroups())),\n ...array_values($this->transformRecipients($report->getRecipients())),\n ],\n 'report_type' => $this->transformReportType($report->getType()),\n 'media_type' => $automatedReportResult->getMediaType(),\n 'downloadUrl' => $this->generateReportResultDownloadUrl($automatedReportResult),\n 'viewUrl' => $this->generateReportResultViewUrl($automatedReportResult),\n 'generated_at' => $automatedReportResult->getGeneratedAt()?->toIso8601String(),\n 'creator' => $creator,\n ];\n }\n\n return $data;\n }\n\n public function hasCallTypeConference(AutomatedReport $report): bool\n {\n return in_array(self::CALL_TYPE_CONFERENCE['id'], $report->getCallTypes(), true);\n }\n\n public function hasCallTypeDialer(AutomatedReport $report): bool\n {\n return in_array(self::CALL_TYPE_DIALER['id'], $report->getCallTypes(), true);\n }\n\n // transformers\n private function transformTeam(Team $team): array\n {\n if (! $team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {\n return [];\n }\n\n return [\n 'id' => $team->getUuid(),\n 'name' => $team->getName(),\n ];\n }\n\n private function transformReportFullView(AutomatedReport $report): array\n {\n $base = $this->transformReportBase($report);\n\n return $report->getType() === self::TYPE_ASK_JIMINNY\n ? $base + $this->transformAskJiminnyFields($report)\n : $base + $this->transformStandardReportFields($report);\n }\n\n private function transformReportBase(AutomatedReport $report): array\n {\n return [\n 'id' => $report->getUuid(),\n 'organization' => $this->transformOrganization(team: $report->getTeam()),\n 'report_type' => $this->transformReportType($report->getType()),\n 'frequency' => $this->transformFrequency($report->getFrequency()),\n ];\n }\n\n private function transformStandardReportFields(AutomatedReport $report): array\n {\n $team = $report->getTeam();\n\n return [\n 'report_enabled' => $report->getStatus(),\n 'start_date_period' => $report->getFrom()?->format('Y-m-d H:i:s'),\n 'end_date_period' => $report->getTo()?->format('Y-m-d H:i:s'),\n 'deal_value_min' => $report->getDealValueMin(),\n 'deal_value_max' => $report->getDealValueMax(),\n 'call_types' => $this->transformCallType($report->getCallTypes()),\n 'media_types' => $this->transformMediaTypes($report),\n 'call_duration_min' => $this->transformDurationToMinutes($report->getCallDurationMin()),\n 'call_duration_max' => $this->transformDurationToMinutes($report->getCallDurationMax()),\n 'teams' => $this->transformGroups(team: $team, groupsIds: $report->getGroups()),\n 'deal_at_call_stages' => $this->transformStages(team: $team, stagesIds: $report->getDealAtCallStages()),\n 'current_deal_stages' => $this->transformStages(team: $team, stagesIds: $report->getCurrentDealStages()),\n 'recipients' => $this->transformRecipients($report->getRecipients()),\n 'created_by' => $this->transformCreator($report->getCreator()),\n 'additional_prompt_input' => $report->getAdditionalPromptInput(),\n 'custom_name' => $report->getCustomName(),\n 'created_at' => $report->getCreatedAt()->format('Y-m-d H:i:s'),\n 'updated_at' => $report->getUpdatedAt()->format('Y-m-d H:i:s'),\n 'deleted_at' => $report->getDeletedAt()?->format('Y-m-d H:i:s'),\n ];\n }\n\n private function transformAskJiminnyFields(AutomatedReport $report): array\n {\n $team = $report->getTeam();\n $creatorId = $report->getAttribute('created_by');\n $explicitUserIds = array_values(array_filter(\n $report->getRecipients()['users'] ?? [],\n static fn ($id) => $id !== $creatorId\n ));\n\n return [\n 'report_name' => $report->getCustomName(),\n 'enabled' => $report->getStatus(),\n 'share_teams' => $this->transformGroups(team: $team, groupsIds: $report->getGroups()),\n 'share_users' => $this->transformRecipients(['users' => $explicitUserIds]),\n 'saved_search' => $this->transformSafeSearch($report->getSavedSearch()),\n 'ask_jiminny_prompt' => $this->transformAskJiminnyPrompt($report->getAskAnythingPrompt()),\n 'expires_on' => $report->getExpiresAt()?->format('Y-m-d'),\n ];\n }\n\n private function transformOrganization(?Team $team): array\n {\n return [\n 'id' => $team?->getUuid(),\n 'name' => $team?->getName(),\n ];\n }\n\n private function transformReportType(string $type): array\n {\n foreach (self::ALL_TYPES as $typeItem) {\n if ($typeItem['id'] === $type) {\n return $typeItem;\n }\n }\n\n return [];\n }\n\n private function transformCallType(array $types): array\n {\n $result = [];\n $callTypes = [self::CALL_TYPE_CONFERENCE, self::CALL_TYPE_DIALER];\n\n foreach ($types as $type) {\n foreach ($callTypes as $callTypeItem) {\n if ($callTypeItem['id'] === $type) {\n $result[] = $callTypeItem;\n\n break;\n }\n }\n }\n\n return $result;\n }\n\n private function transformMediaTypes(AutomatedReport $report): array\n {\n $values = [];\n\n foreach ($report->getMediaTypes() as $mediaType) {\n if (! in_array($mediaType, self::MEDIA_TYPES, true)) {\n continue;\n }\n\n $values[] = match ($mediaType) {\n self::MEDIA_TYPE_PDF => self::MEDIA_TYPE_OBJECT_PDF,\n self::MEDIA_TYPE_PODCAST => self::MEDIA_TYPE_OBJECT_PODCAST,\n };\n }\n\n return $values;\n }\n\n private function transformFrequency(string $frequency): array\n {\n foreach (self::ALL_FREQUENCIES as $frequencyItem) {\n if ($frequencyItem['id'] === $frequency) {\n return $frequencyItem;\n }\n }\n\n return [];\n }\n\n public function transformDurationToMinutes(?int $duration): ?int\n {\n if (! $duration) {\n return null;\n }\n\n return (int) ($duration / 60);\n }\n\n private function transformGroups(?Team $team, array $groupsIds): array\n {\n if (empty($groupsIds) || ! $team) {\n return [];\n }\n\n $data = [];\n foreach ($groupsIds as $groupId) {\n $group = $team->groups()->where('id', $groupId)->first();\n\n if ($group) {\n $data[] = [\n 'id' => $group->getUuid(),\n 'name' => $group->getName(),\n 'photoUrl' => $group->getPhotoUrl(),\n ];\n }\n }\n\n return $data;\n }\n\n private function transformStages(?Team $team, array $stagesIds): array\n {\n if (empty($stagesIds) || ! $team) {\n return [];\n }\n\n $data = [];\n foreach ($stagesIds as $stageId) {\n $stage = $team->stages()->where('id', $stageId)->first();\n\n if ($stage) {\n $data[] = [\n 'id' => $stage->getUuid(),\n 'name' => $stage->getName(),\n ];\n }\n }\n\n return $data;\n }\n\n private function transformRecipients(array $recipients): array\n {\n $users = [];\n foreach ($recipients['users'] ?? [] as $userId) {\n $users[] = $this->transformUser($userId);\n }\n\n return $users;\n }\n\n private function transformCreator(?User $user): ?array\n {\n if ($user === null) {\n return null;\n }\n\n return $this->transformUser($user->getId());\n }\n\n private function transformAskJiminnyPrompt(?AskAnythingPrompt $prompt): ?array\n {\n if ($prompt === null) {\n return null;\n }\n\n return [\n 'id' => $prompt->getUuid(),\n 'name' => $prompt->getTitle(),\n ];\n }\n\n private function transformSafeSearch(?Search $search): ?array\n {\n if ($search === null) {\n return null;\n }\n\n return [\n 'id' => $search->getUuid(),\n 'name' => $search->getName(),\n ];\n }\n\n private function transformUser(int $userId): array\n {\n /* @var ?User $user */\n $user = $this->userRepository->find($userId);\n\n return [\n 'id' => $user?->getUuid(),\n 'name' => $user?->getName(),\n 'email' => $user?->getEmailAddress(),\n 'photoUrl' => $user?->getPhotoUrl(),\n ];\n }\n\n public function create(array $data): array\n {\n $validatedData = $this->validateAndTransformData($data);\n $validatedData['created_by'] = auth()->id();\n\n $automatedReport = $this->automatedReportsRepository->create($validatedData);\n\n $this->generateOneOffReport($automatedReport);\n\n return $this->transformReportFullView($automatedReport);\n }\n\n public function update(string $uuid, array $data): array\n {\n $validatedData = $this->validateAndTransformData($data);\n $report = $this->automatedReportsRepository->findByUuid($uuid);\n\n if (! $report) {\n throw new InvalidArgumentException('Report not found');\n }\n\n $oldCustomName = $report->getCustomName();\n\n $automatedReport = $this->automatedReportsRepository->update($report, $validatedData);\n\n if ($oldCustomName !== $automatedReport->getCustomName()) {\n $this->updateResultNames($automatedReport);\n }\n\n $this->generateOneOffReport($automatedReport);\n\n return $this->transformReportFullView($automatedReport);\n }\n\n /**\n * Create an Ask Jiminny report.\n */\n public function createAskJiminnyReport(array $data, User $creator): array\n {\n $validatedData = $this->validateAskJiminnyReportData($data, $creator);\n $validatedData['created_by'] = $creator->getId();\n\n $automatedReport = $this->automatedReportsRepository->create($validatedData);\n\n return $this->transformReportFullView($automatedReport);\n }\n\n /**\n * Update an Ask Jiminny report.\n */\n public function updateAskJiminnyReport(AutomatedReport $report, array $data, User $user): array\n {\n if (! $report->isAskJiminnyReport()) {\n throw new InvalidArgumentException('Report is not an Ask Jiminny report');\n }\n\n $validatedData = $this->validateAskJiminnyReportData($data, $user);\n\n $oldCustomName = $report->getCustomName();\n\n $automatedReport = $this->automatedReportsRepository->update($report, $validatedData);\n\n if ($oldCustomName !== $automatedReport->getCustomName()) {\n $this->updateResultNames($automatedReport);\n }\n\n return $this->transformReportFullView($automatedReport);\n }\n\n public function updateAskJiminnyReportStatus(AutomatedReport $report, bool $status): array\n {\n $this->automatedReportsRepository->update($report, ['status' => $status]);\n\n return $this->transformReportFullView($report->fresh());\n }\n\n /**\n * Validate and transform data for Ask Jiminny reports.\n */\n private function validateAskJiminnyReportData(array $data, User $user): array\n {\n // Validate name\n $name = trim($data['report_name'] ?? '');\n if (empty($name)) {\n throw new InvalidArgumentException('Report name is required');\n }\n if (mb_strlen($name) > 50) {\n throw new InvalidArgumentException('Report name must be 50 characters or less');\n }\n\n // Validate frequency (only daily, weekly, monthly for Ask Jiminny)\n $frequency = $data['frequency'] ?? null;\n $askJiminnyFrequencies = [self::FREQUENCY_DAILY, self::FREQUENCY_WEEKLY, self::FREQUENCY_MONTHLY];\n if (! in_array($frequency, $askJiminnyFrequencies, true)) {\n throw new InvalidArgumentException('Frequency must be daily, weekly, or monthly');\n }\n\n // Validate expiration date\n $expiresAt = $data['expires_on'] ?? null;\n if (empty($expiresAt)) {\n throw new InvalidArgumentException('Expiration date is required');\n }\n\n try {\n $expiresAtDate = Carbon::parse($expiresAt);\n } catch (InvalidFormatException $e) {\n throw new InvalidArgumentException('Expiration date format is invalid');\n }\n $maxExpiration = Carbon::now()->addYear();\n if ($expiresAtDate->gt($maxExpiration)) {\n throw new InvalidArgumentException('Expiration date cannot be more than 1 year from now');\n }\n if ($expiresAtDate->isPast()) {\n throw new InvalidArgumentException('Expiration date cannot be in the past');\n }\n\n // Validate saved search\n $activitySearchId = $data['saved_search'] ?? null;\n if (empty($activitySearchId)) {\n throw new InvalidArgumentException('Saved search is required');\n }\n $savedSearch = $this->activitySearchRepository->findByUuidAndUser($activitySearchId, $user);\n if (! $savedSearch) {\n throw new InvalidArgumentException('Saved search not found or does not belong to you');\n }\n\n // Validate saved prompt\n $askAnythingPromptId = $data['ask_jiminny_prompt'] ?? null;\n if (empty($askAnythingPromptId)) {\n throw new InvalidArgumentException('Ask Jiminny prompt is required');\n }\n $prompt = $this->askAnythingRepository->getPromptByUuid($askAnythingPromptId);\n if (! $prompt) {\n throw new InvalidArgumentException('Ask Jiminny prompt not found');\n }\n\n // Validate status\n $status = $data['enabled'] ?? false;\n\n $recipientUserIds = [$user->getId()];\n\n if (! empty($data['share_users'])) {\n $sharedUserIds = $this->validateAndGetUserIdsByTeam(\n $user->team,\n (array) $data['share_users']\n );\n $recipientUserIds = array_merge($recipientUserIds, $sharedUserIds);\n }\n\n $sharedGroupIds = [];\n if (! empty($data['share_teams'])) {\n $sharedGroupIds = $this->validateAndGetGroupIds($user->team, (array) $data['share_teams']);\n }\n\n $recipientUserIds = array_values(array_unique($recipientUserIds));\n\n return [\n 'team_id' => $user->getTeamId(),\n 'type' => self::TYPE_ASK_JIMINNY,\n 'status' => (bool) $status,\n 'frequency' => $frequency,\n 'custom_name' => $name,\n 'activity_search_id' => $savedSearch->getId(),\n 'ask_anything_prompt_id' => $prompt->getId(),\n 'expires_at' => $expiresAtDate->toDateString(),\n 'media_types' => [self::MEDIA_TYPE_PDF],\n 'call_types' => [],\n 'recipients' => ['users' => $recipientUserIds],\n 'groups' => $sharedGroupIds,\n ];\n }\n\n public static function getAskJiminnyFrequencies(): array\n {\n return array_map(static function ($frequency) {\n return $frequency['id'];\n }, self::ASK_JIMINNY_FREQUENCIES);\n }\n\n public function getAskJiminnyReportFilters(User $user): array\n {\n $savedSearches = $this->activitySearchRepository->findByUserOrderedByName($user)\n ->map(fn (Search $search) => [\n 'id' => $search->getUuid(),\n 'name' => $search->getName(),\n ])\n ->values()->all();\n\n $prompts = collect(\n $this->askAnythingPromptService->get($user, AskAnythingPromptTarget::on_demand)\n )->map(fn (AskAnythingPromptDto $prompt) => [\n 'id' => $prompt->id,\n 'name' => $prompt->title,\n ])->values()->all();\n\n return [\n [\n 'id' => 'prompt',\n 'label' => 'Prompt',\n 'options' => $prompts,\n ],\n [\n 'id' => 'saved_search',\n 'label' => 'Saved Search',\n 'options' => $savedSearches,\n ],\n ];\n }\n\n public function getAskJiminnyReportFormData(User $user, ?AutomatedReport $report = null): array\n {\n $team = $user->getTeam();\n $userTimezone = $user->getTimezone();\n\n $savedSearches = $this->activitySearchRepository->findByUserOrderedByName($user)\n ->map(fn (Search $search) => [\n 'id' => $search->getUuid(),\n 'name' => $search->getName(),\n ])\n ->values()->all();\n\n $prompts = collect(\n $this->askAnythingPromptService->get($user, AskAnythingPromptTarget::on_demand)\n )->map(fn (AskAnythingPromptDto $prompt) => [\n 'id' => $prompt->id,\n 'name' => $prompt->title,\n ])->values()->all();\n\n $teamGroups = $this->groupRepository->getAllByTeam($team)->map(fn ($group) => [\n 'id' => $group->getUuid(),\n 'name' => $group->getName(),\n ])->values()->all();\n\n $shareUsers = $this->recipientsService->getRecipientsFieldData(team: $team)['options'] ?? [];\n\n $sharedTeamsValue = [];\n $sharedUsersValue = [];\n if ($report) {\n $sharedTeamsValue = $this->transformGroups($team, $report->getGroups());\n\n $recipientUserIds = $report->getRecipients()['users'] ?? [];\n $creatorId = $report->getAttribute('created_by');\n $sharedUserIds = array_values(array_filter(\n $recipientUserIds,\n static fn ($id) => $id !== $creatorId\n ));\n $sharedUsersValue = collect($sharedUserIds)\n ->map(fn ($id) => $this->userRepository->find((int) $id))\n ->filter()\n ->map(fn (User $u) => [\n 'id' => $u->getUuid(),\n 'name' => $u->getName(),\n ])\n ->values()\n ->all();\n }\n\n return [\n 'fields' => [\n [\n 'id' => 'enabled',\n 'inputType' => InputTypeEnum::TOGGLE,\n 'label' => '',\n 'value' => $report?->getStatus() ?? false,\n ],\n [\n 'id' => 'report_name',\n 'inputType' => InputTypeEnum::TEXT,\n 'label' => 'Name',\n 'placeholder' => 'Enter name',\n 'required' => true,\n 'validation' => ['maxLength' => 50],\n 'value' => $report?->getCustomName() ?? '',\n ],\n [\n 'id' => 'frequency',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'label' => 'Frequency',\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => self::ASK_JIMINNY_FREQUENCIES,\n 'value' => $report ? $this->transformFrequency($report->getFrequency()) : null,\n ],\n [\n 'id' => 'expires_on',\n 'inputType' => InputTypeEnum::DATE,\n 'label' => 'Expires on',\n 'required' => true,\n 'placeholder' => 'Select',\n 'validation' => [\n 'minDate' => now($userTimezone)->toDateString(),\n 'maxDate' => now($userTimezone)->addYear()->toDateString(),\n ],\n 'value' => $report?->getExpiresAt()?->toDateString(),\n ],\n [\n 'id' => 'share_teams',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'label' => 'Team',\n 'required' => false,\n 'placeholder' => 'Select',\n 'options' => $teamGroups,\n 'value' => $sharedTeamsValue,\n ],\n [\n 'id' => 'share_users',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'label' => 'Team member',\n 'required' => false,\n 'placeholder' => 'Select',\n 'groupLabelKey' => 'label',\n 'groupValuesKey' => 'users',\n 'optionLabelKey' => 'name',\n 'optionValueKey' => 'id',\n 'options' => $shareUsers,\n 'value' => $sharedUsersValue,\n ],\n [\n 'id' => 'saved_search',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'label' => 'Saved search',\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => $savedSearches,\n 'value' => $report && $report->getSavedSearch() ? [\n 'id' => $report->getSavedSearch()->getUuid(),\n 'name' => $report->getSavedSearch()->getName(),\n ] : null,\n ],\n [\n 'id' => 'ask_jiminny_prompt',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'label' => 'Ask Jiminny prompt',\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => $prompts,\n 'value' => $report && $report->getAskAnythingPrompt() ? [\n 'id' => $report->getAskAnythingPrompt()->getUuid(),\n 'name' => $report->getAskAnythingPrompt()->getTitle(),\n ] : null,\n ],\n ],\n ];\n }\n\n private function updateResultNames(AutomatedReport $automatedReport): void\n {\n $results = $this->automatedReportsRepository->getResultsByReport($automatedReport);\n\n foreach ($results as $result) {\n $result->update(['name' => $this->getReportFileName($result)]);\n }\n }\n\n public function updateStatus(string $uuid, array $data): array\n {\n $automatedReport = $this->automatedReportsRepository->findByUuid($uuid);\n\n if (! $automatedReport) {\n throw new ModelNotFoundException('Report not found');\n }\n\n $status = $this->validateReportStatus($data['report_enabled'] ?? null);\n $automatedReport->update([\n 'status' => $status,\n ]);\n\n $this->generateOneOffReport($automatedReport);\n\n return $this->transformReportFullView($automatedReport);\n }\n\n private function generateOneOffReport(AutomatedReport $automatedReport): void\n {\n // the scheduler handles all the other frequency types\n if ($automatedReport->getStatus() === false || $automatedReport->getFrequency() !== self::FREQUENCY_ONE_OFF) {\n return;\n }\n\n $this->dispatcher->dispatch(new RequestGenerateReportJob($automatedReport->getUuid()));\n }\n\n public function getReport(string $uuid): AutomatedReport\n {\n $automatedReport = $this->automatedReportsRepository->findByUuid($uuid);\n\n if (! $automatedReport) {\n throw new ModelNotFoundException('Report not found');\n }\n\n return $automatedReport;\n }\n\n public function get(string $uuid): array\n {\n $automatedReport = $this->getReport($uuid);\n\n return $this->transformReportFullView($automatedReport);\n }\n\n public function list(string $sortColumn = 'created_at', string $sortDirection = 'desc'): array\n {\n $results = [];\n $collection = $this->automatedReportsRepository->getAllStandardReports($sortColumn, $sortDirection);\n\n /** @var AutomatedReport $report */\n foreach ($collection as $report) {\n $results[] = $this->transformReportFullView($report);\n }\n\n return ['data' => $results];\n }\n\n public function listAskJiminnyReports(\n User $user,\n string $sortColumn = 'created_at',\n string $sortDirection = 'desc'\n ): array {\n $results = [];\n $collection = $this->automatedReportsRepository->getAskJiminnyReportsByUser($user, $sortColumn, $sortDirection);\n\n /** @var AutomatedReport $report */\n foreach ($collection as $report) {\n $results[] = $this->transformReportFullView($report);\n }\n\n return ['data' => $results];\n }\n\n public function delete(string $uuid): void\n {\n $automatedReport = $this->automatedReportsRepository->findByUuid($uuid);\n\n if (! $automatedReport) {\n throw new ModelNotFoundException('Report not found');\n }\n\n $automatedReport->delete();\n }\n\n public function createReportResult(AutomatedReport $automatedReport, array $data = []): AutomatedReportResult\n {\n return $this->automatedReportsRepository->createResult(\n array_merge(\n [\n 'report_id' => $automatedReport->getId(),\n 'status' => AutomatedReportResult::STATUS_DEFAULT,\n ],\n $data\n )\n );\n }\n\n public function getReportResult(string $resultUuid): AutomatedReportResult\n {\n $report = $this->automatedReportsRepository->findResultByUuid($resultUuid);\n\n if (! $report) {\n throw new ModelNotFoundException('Report Result not found');\n }\n\n return $report;\n }\n\n public function findChildResult(AutomatedReportResult $result, string $type): ?AutomatedReportResult\n {\n return $this->automatedReportsRepository->findChildResult($result, $type);\n }\n\n // prophet API calls\n /**\n * @throws ApplicationException\n */\n public function getGenerateReportPayload(AutomatedReport $automatedReport, string $reportResultUuid): array\n {\n $period = $this->calculateFromAndToDate($automatedReport);\n $fromDate = $period['fromDate'];\n $toDate = $period['toDate'];\n\n return [\n 'team_id' => $automatedReport->getTeamId(),\n 'request_id' => $reportResultUuid,\n 'report_type' => $automatedReport->getType(),\n 'media_types' => $automatedReport->getMediaTypes(),\n 'from_date' => $fromDate->startOfDay()->format(DateTimeInterface::RFC3339),\n 'to_date' => $toDate->endOfDay()->format(DateTimeInterface::RFC3339),\n 'group_ids' => $automatedReport->getGroups(),\n 'call_deal_stage' => $automatedReport->getDealAtCallStages(),\n 'current_deal_stage' => $automatedReport->getCurrentDealStages(),\n 'deal_min_value' => $automatedReport->getDealValueMin(),\n 'deal_max_value' => $automatedReport->getDealValueMax(),\n 'call_types' => $automatedReport->getCallTypes(),\n 'call_duration_min_seconds' => $automatedReport->getCallDurationMin(),\n 'call_duration_max_seconds' => $automatedReport->getCallDurationMax(),\n 'special_requirements' => $automatedReport->getAdditionalPromptInput(),\n 'callback_url' => $this->getCallbackUrl(),\n 'report_period' => $this->formatReportPeriodName(\n $automatedReport->getFrequency(),\n $fromDate,\n $toDate,\n ),\n 'playbook_categories' => $automatedReport->getPlaybookCategories(),\n 'custom_name' => $automatedReport->getCustomName(),\n ];\n }\n\n // $inputPayload - FE payload structure\n public function getActivitiesCountPayload(array $inputPayload): array\n {\n // Use validateAndTransformData to validate and normalize input\n $validatedData = $this->validateAndTransformData($inputPayload);\n $period = $this->calculateFromAndToDatePeriod(\n $validatedData['frequency'],\n Carbon::parse($validatedData['from']),\n Carbon::parse($validatedData['to']),\n );\n $fromDate = $period['fromDate'];\n $toDate = $period['toDate'];\n\n // Create payload similar to getGenerateReportPayload\n return [\n 'team_id' => $validatedData['team_id'],\n 'group_ids' => $validatedData['groups'] ?? [],\n 'report_type' => $validatedData['type'],\n 'from_date' => $fromDate->format(DateTimeInterface::RFC3339),\n 'to_date' => $toDate->format(DateTimeInterface::RFC3339),\n 'call_deal_stage' => $validatedData['deal_at_call_stages'] ?? [],\n 'current_deal_stage' => $validatedData['current_deal_stages'] ?? [],\n 'deal_min_value' => $validatedData['deal_value_min'] ?? null,\n 'deal_max_value' => $validatedData['deal_value_max'] ?? null,\n 'call_types' => $validatedData['call_types'],\n 'call_duration_min_seconds' => $validatedData['call_duration_min'] ?? null,\n 'call_duration_max_seconds' => $validatedData['call_duration_max'] ?? null,\n 'special_requirements' => $validatedData['additional_prompt_input'] ?? null,\n 'playbook_categories' => $validatedData['playbook_categories'] ?? [],\n 'request_id' => null,\n 'callback_url' => null,\n ];\n }\n\n public function shouldSendReport(array $users, ?CarbonInterface $generatedAt = null): bool\n {\n if (empty($users)) {\n return false;\n }\n\n $earliestTz = collect($users)\n ->mapWithKeys(function (array $user) {\n $tz = new DateTimeZone($user['timezone']);\n $nowUtc = new DateTime('now', new DateTimeZone('UTC'));\n $offset = $tz->getOffset($nowUtc);\n\n return [$user['timezone'] => $offset];\n })\n ->sortDesc()\n ->keys()\n ->first();\n\n $now = Carbon::now($earliestTz);\n $isScheduledTime = (int) $now->format('H') === self::SENT_REPORT_AT_HOURS;\n\n if ($isScheduledTime) {\n return true;\n }\n\n return $this->hasPassedScheduledTime($generatedAt, $earliestTz);\n }\n\n public function hasPassedScheduledTime(?CarbonInterface $generatedAt, string $timezone): bool\n {\n if ($generatedAt === null) {\n return false;\n }\n\n $now = Carbon::now($timezone);\n $scheduledTime = $now->copy()->setTime(self::SENT_REPORT_AT_HOURS, 0, 0);\n\n if ($now->hour < self::SENT_REPORT_AT_HOURS) {\n $scheduledTime = $scheduledTime->subDay();\n }\n\n $scheduledTimeUtc = $scheduledTime->copy()->utc();\n $generatedAtUtc = $generatedAt->copy()->utc();\n $nowUtc = $now->copy()->utc();\n\n return $generatedAtUtc->lt($scheduledTimeUtc) && $nowUtc->gt($scheduledTimeUtc);\n }\n\n public function calculateFromAndToDatePeriod(\n string $frequency,\n ?Carbon $fromDate = null,\n ?Carbon $toDate = null\n ): array {\n if ($frequency === self::FREQUENCY_ONE_OFF) {\n return [\n 'fromDate' => $fromDate,\n 'toDate' => $toDate,\n ];\n }\n\n $now = Carbon::now();\n\n return match ($frequency) {\n self::FREQUENCY_DAILY => [\n 'fromDate' => $now->copy()->subDay()->startOfDay(),\n 'toDate' => $now->copy()->subDay()->endOfDay(),\n ],\n self::FREQUENCY_WEEKLY => [\n 'fromDate' => $now->copy()->subWeeks(1)->startOfDay(),\n 'toDate' => $now->copy()->subDay()->endOfDay(),\n ],\n self::FREQUENCY_MONTHLY => [\n 'fromDate' => $now->copy()->subMonths(1)->startOfDay(),\n 'toDate' => $now->copy()->subDay()->endOfDay(),\n ],\n self::FREQUENCY_QUARTERLY => [\n 'fromDate' => $now->copy()->subMonths(3)->startOfDay(),\n 'toDate' => $now->copy()->subDay()->endOfDay(),\n ],\n default => throw new InvalidArgumentException(\"Unsupported frequency: {$frequency}\"),\n };\n }\n\n private function calculateFromAndToDate(AutomatedReport $automatedReport): array\n {\n return $this->calculateFromAndToDatePeriod(\n $automatedReport->getFrequency(),\n $automatedReport->getFrom(),\n $automatedReport->getTo()\n );\n }\n\n public function getAskJiminnyGenerateReportPayload(\n AutomatedReport $automatedReport,\n AutomatedReportResult $reportResult,\n array $activityIds,\n ): array {\n return [\n 'user_question' => $automatedReport->getAskAnythingPrompt()?->getContent(),\n 'call_ids' => array_map('strval', $activityIds),\n 'team_id' => $automatedReport->getTeamId(),\n 'request_id' => $reportResult->getUuid(),\n 'callback_url' => $this->getCallbackUrl(),\n 'report_period' => $this->getReportPeriodName($reportResult),\n 'report_name' => $automatedReport->getCustomName(),\n ];\n }\n\n private function getCallbackUrl(): string\n {\n return $this->webhookService->route('jiminny.webhook.reports.ready');\n }\n\n /**\n * Validate and transform payload data for automated reports\n *\n * @param array $data\n *\n * @throws InvalidArgumentException\n *\n * @return array\n */\n private function validateAndTransformData(array $data): array\n {\n // Validate organization (team) and check feature\n $team = $this->validateOrganization($data['organization'] ?? null);\n\n $status = $this->validateReportStatus($data['report_enabled'] ?? null);\n $type = $this->validateReportType($data['report_type'] ?? null);\n $frequency = $this->validateFrequency($data['frequency'] ?? null);\n $additionalPromptInput = $this->validateAdditionalPromptInput(\n $data['additional_prompt_input'] ?? null\n );\n $customReportName = $this->validateCustomReportName($data['custom_name'] ?? null);\n\n // Prepare data for the database\n $reportData = [\n 'team_id' => $team->getId(),\n 'type' => $type,\n 'status' => $status,\n 'frequency' => $frequency,\n 'additional_prompt_input' => $additionalPromptInput,\n 'custom_name' => $customReportName,\n ];\n\n // Validate deal values\n $reportData = $this->validateDealValues($data, $reportData);\n\n // Validate date range\n $reportData = $this->validateDateRange($data, $reportData, $frequency);\n\n // Validate call durations\n $reportData = $this->validateCallDurations($data, $reportData);\n\n // Validate call types\n $reportData = $this->validateCallTypes($data, $reportData);\n\n // Validate media types\n $reportData = $this->validateMediaTypes($data, $reportData);\n\n // Validate groups\n if (isset($data['teams'])) {\n $reportData['groups'] = $this->validateAndGetGroupIds($team, $data['teams']);\n }\n\n // Validate deal stages\n $reportData = $this->validateDealStages($data, $reportData, $team, $type);\n\n // Validate playbook categories\n $reportData = $this->validatePlaybookCategories($data, $reportData, $team);\n\n // Validate recipients\n $reportData['recipients'] = [\n 'users' => $this->validateAndGetUserIdsByTeam($team, $data['recipients'] ?? []),\n ];\n\n if (isset($data['jiminny_recipients'])) {\n // Validate Jiminny recipients\n $reportData['jiminny_recipients'] = [\n 'users' => $this->validateAndGetJiminnyUserIds((array) $data['jiminny_recipients']),\n ];\n }\n\n return $reportData;\n }\n\n private function validateDealValues(array $data, array $reportData): array\n {\n if (isset($data['min_deal_value'])) {\n $reportData['deal_value_min'] = (int) $data['min_deal_value'];\n\n if ($reportData['deal_value_min'] > 4294967295 || $reportData['deal_value_min'] < 0) {\n throw new InvalidArgumentException('Min deal value should be between 0 and 4294967295');\n }\n }\n\n if (isset($data['max_deal_value'])) {\n $reportData['deal_value_max'] = (int) $data['max_deal_value'];\n\n if ($reportData['deal_value_max'] > 4294967295 || $reportData['deal_value_max'] < 0) {\n throw new InvalidArgumentException('Max deal value should be between 0 and 4294967295');\n }\n }\n\n if (isset($data['min_deal_value'], $data['max_deal_value'])\n && $data['min_deal_value'] > $data['max_deal_value']\n ) {\n throw new InvalidArgumentException('Min deal value cannot be greater than max deal value');\n }\n\n return $reportData;\n }\n\n private function validateDateRange(array $data, array $reportData, string $frequency): array\n {\n // Set date range only for one_off frequency\n if ($frequency === 'one_off') {\n if (isset($data['start_date_period'])) {\n $reportData['from'] = $this->parseDate($data['start_date_period']);\n }\n\n if (isset($data['end_date_period'])) {\n $reportData['to'] = $this->parseDate($data['end_date_period']);\n }\n\n if (empty($reportData['from']) || empty($reportData['to'])) {\n throw new InvalidArgumentException(\n 'Start date and end date are required for one_off frequency'\n );\n }\n } else {\n $reportData['from'] = null;\n $reportData['to'] = null;\n }\n\n return $reportData;\n }\n\n private function validateCallDurations(array $data, array $reportData): array\n {\n // Convert call durations from minutes to seconds\n if (isset($data['min_call_duration'])) {\n $reportData['call_duration_min'] = (int) $data['min_call_duration'] * 60;\n\n if ($reportData['call_duration_min'] > 4294967295 || $reportData['call_duration_min'] < 0) {\n throw new InvalidArgumentException('Min call duration should be between 0 and 4294967295');\n }\n }\n\n if (isset($data['max_call_duration'])) {\n $reportData['call_duration_max'] = (int) $data['max_call_duration'] * 60;\n\n if ($reportData['call_duration_max'] > 4294967295 || $reportData['call_duration_max'] < 0) {\n throw new InvalidArgumentException('Max call duration should be between 0 and 4294967295');\n }\n }\n\n return $reportData;\n }\n\n private function validateCallTypes(array $data, array $reportData): array\n {\n // Set call types\n $reportData['call_types'] = $data['call_type'] ?? [];\n if (empty($reportData['call_types'])) {\n $reportData['call_types'] = self::getCallTypes();\n }\n\n foreach ($reportData['call_types'] as $callType) {\n if (! in_array($callType, self::getCallTypes(), true)) {\n throw new InvalidArgumentException(sprintf('Call type %s is invalid', $callType));\n }\n }\n\n return $reportData;\n }\n\n private function validateMediaTypes(array $data, array $reportData): array\n {\n // Set media types from input data\n $reportData['media_types'] = $data['media_types'] ?? [];\n\n if (empty($reportData['media_types'])) {\n throw new InvalidArgumentException('Media types are required');\n }\n\n foreach ($reportData['media_types'] as $mediaType) {\n if (! in_array($mediaType, self::MEDIA_TYPES, true)) {\n throw new InvalidArgumentException(sprintf('Media type %s is invalid', $mediaType));\n }\n }\n\n return $reportData;\n }\n\n private function validateDealStages(array $data, array $reportData, Team $team, string $reportType): array\n {\n // Validate and set deal stages\n if (isset($data['deal_stage_at_call'])) {\n $reportData['deal_at_call_stages'] =\n $this->validateAndGetDealStageIds($team, $data['deal_stage_at_call'], 'Deal stage at call');\n }\n\n if (isset($data['current_deal_stage'])) {\n $reportData['current_deal_stages'] =\n $this->validateAndGetDealStageIds($team, $data['current_deal_stage'], 'Current deal stage');\n }\n\n // Ensure current_deal_stage is not provided for loss_analysis report type\n if ($reportType === self::TYPE_LOSS_ANALYSIS && ! empty($data['current_deal_stage'])) {\n throw new InvalidArgumentException('Current deal stage is not applicable for Loss Analysis reports');\n }\n\n return $reportData;\n }\n\n // transform uuid to id\n private function validatePlaybookCategories(array $data, array $reportData, Team $team): array\n {\n $key = 'playbook_categories';\n\n if (isset($data[$key])) {\n $payloadIds = $data[$key];\n $ids = [];\n\n foreach ($payloadIds as $uuid) {\n $uuid = (string) $uuid;\n\n try {\n $playbookCategory = $this->playbookCategoryRepository->findByUuid($uuid);\n } catch (Throwable $throwable) {\n Log::error(__METHOD__ . ' ' . $throwable->getMessage());\n\n throw new InvalidArgumentException(sprintf('Playbook category %s not found', $uuid));\n }\n\n if (! $playbookCategory) {\n throw new InvalidArgumentException(sprintf('Playbook category %s not found', $uuid));\n }\n\n if (! $playbookCategory->hasPlaybook()) {\n throw new InvalidArgumentException(sprintf('Playbook category %s has no playbook', $uuid));\n }\n\n if ($playbookCategory->getPlaybook()->getTeamId() !== $team->getId()) {\n throw new InvalidArgumentException(\n sprintf('Playbook category %s not found for team %s', $uuid, $team->getUuid())\n );\n }\n\n $ids[] = $playbookCategory->getId();\n }\n\n $reportData[$key] = $ids;\n }\n\n return $reportData;\n }\n\n private function validateReportStatus($status): bool\n {\n if (! in_array($status, [true, false], true)) {\n throw new InvalidArgumentException('Report status is invalid');\n }\n\n return $status;\n }\n\n private function validateReportType($type): string\n {\n if (! in_array($type, self::getTypes(), true)) {\n throw new InvalidArgumentException(sprintf('Report type is invalid: %s', $type));\n }\n\n return $type;\n }\n\n private function validateFrequency($frequency): string\n {\n if (! in_array($frequency, self::getFrequencies(), true)) {\n throw new InvalidArgumentException('Frequency is invalid');\n }\n\n return $frequency;\n }\n\n private function validateAdditionalPromptInput(?string $additionalPromptInput): ?string\n {\n if ($additionalPromptInput && strlen($additionalPromptInput) > 5000) {\n throw new InvalidArgumentException('Additional Prompt Input should be less than 5000 characters');\n }\n\n return $additionalPromptInput;\n }\n\n private function validateCustomReportName(?string $customReportName): ?string\n {\n if ($customReportName === null || $customReportName === '') {\n return null;\n }\n\n if (strlen($customReportName) > 70) {\n throw new InvalidArgumentException('Custom report name should be less than 70 characters');\n }\n\n return $customReportName;\n }\n\n private function validateOrganization(?string $organizationUuid): Team\n {\n if (! $organizationUuid) {\n throw new InvalidArgumentException('Organization is required');\n }\n\n $team = $this->teamRepository->idOrUuid($organizationUuid);\n\n if (! $team) {\n throw new InvalidArgumentException('Organization not found');\n }\n\n if (! $team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {\n throw new InvalidArgumentException('Organization does not have the Automated Reports feature');\n }\n\n return $team;\n }\n\n private function validateAndGetGroupIds(Team $team, array $teamUuids): array\n {\n $groupIds = [];\n\n foreach ($teamUuids as $uuid) {\n $group = $this->groupRepository->findByUuid($uuid);\n\n if ($group === null || $group->getTeamId() !== $team->getId()) {\n throw new InvalidArgumentException(\n sprintf('Group %s not found for team %s', $uuid, $team->getUuid())\n );\n }\n\n $groupIds[] = $group->getId();\n\n }\n\n return $groupIds;\n }\n\n private function validateAndGetDealStageIds(Team $team, array $stageUuids, string $propertyLabel): array\n {\n $stageIds = [];\n\n foreach ($stageUuids as $uuid) {\n $stage = $this->stageRepository->findByUuid($uuid);\n\n if ($stage === null || $stage->getTeamId() !== $team->getId()) {\n throw new InvalidArgumentException(\n sprintf('Stage %s not found for team %s for %s', $uuid, $team->getUuid(), $propertyLabel)\n );\n }\n\n $stageIds[] = $stage->getId();\n }\n\n return $stageIds;\n }\n\n private function validateAndGetUserIds(array $userUuids, callable $teamCheck): array\n {\n if (empty($userUuids)) {\n return [];\n }\n\n $userIds = [];\n\n foreach ($userUuids as $uuid) {\n $user = $this->userRepository->findByUuid($uuid);\n\n if (! $user || ! $user->isStatusActive()) {\n throw new InvalidArgumentException(\n sprintf('User %s not found or is not active', $uuid)\n );\n }\n\n if (! $teamCheck($user)) {\n throw new InvalidArgumentException(\n sprintf('User %s does not belong to the allowed team(s)', $uuid)\n );\n }\n\n $userIds[] = $user->getId();\n }\n\n return $userIds;\n }\n\n private function validateAndGetUserIdsByTeam(Team $team, array $userUuids): array\n {\n return $this->validateAndGetUserIds($userUuids, fn ($user) => $user->getTeamId() === $team->getId());\n }\n\n private function validateAndGetJiminnyUserIds(array $userUuids): array\n {\n $allowedTeamIds = config('kiosk.teamIds', []);\n\n return $this->validateAndGetUserIds($userUuids, fn ($user) => in_array($user->getTeamId(), $allowedTeamIds, true));\n }\n\n private function parseDate(string $dateString): string\n {\n return date('Y-m-d H:i:s', strtotime($dateString));\n }\n\n private function generateReportResultViewUrl(AutomatedReportResult $result): string\n {\n $mediaResource = $this->getReportMediaRouteResource($result);\n\n return route('ai-reports.' . $mediaResource . '.view', ['uuid' => $result->getUuid()]);\n }\n\n private function generateReportResultDownloadUrl(AutomatedReportResult $result): string\n {\n $mediaResource = $this->getReportMediaRouteResource($result);\n\n return route('ai-reports.' . $mediaResource . '.download', ['uuid' => $result->getUuid()]);\n }\n\n private function getReportMediaRouteResource(AutomatedReportResult $result): string\n {\n if ($result->getMediaType() === self::MEDIA_TYPE_PDF) {\n return self::PDF_KEY;\n } elseif ($result->getMediaType() === self::MEDIA_TYPE_PODCAST) {\n return self::AUDIO_KEY;\n }\n\n throw new \\InvalidArgumentException('Unknown media type.');\n }\n\n public function getMediaPath(AutomatedReportResult $result): ?string\n {\n $url = match ($result->getMediaType()) {\n self::MEDIA_TYPE_PDF => $result->getPdfUrl(),\n self::MEDIA_TYPE_PODCAST => $result->getPodcastAudioUrl(),\n default => null,\n };\n\n if ($url === null) {\n return null;\n }\n\n $path = parse_url(trim($url, '\"\\''), PHP_URL_PATH);\n\n return $path ?: null;\n }\n\n public function getFilenameSuffix(AutomatedReportResult $result): ?string\n {\n return match ($result->getMediaType()) {\n self::MEDIA_TYPE_PODCAST => 'Podcast',\n default => null,\n };\n }\n\n public function getMailSubjectSuffix(AutomatedReportResult $result): string\n {\n return match ($result->getMediaType()) {\n self::MEDIA_TYPE_PDF => 'report',\n self::MEDIA_TYPE_PODCAST => 'podcast',\n default => '',\n };\n }\n\n public function getMediaTypeMetadata(AutomatedReportResult $result): array\n {\n return match ($result->getMediaType()) {\n self::MEDIA_TYPE_PODCAST => ['extension' => 'mp3', 'mime' => 'audio/mpeg'],\n self::MEDIA_TYPE_PDF => ['extension' => 'pdf', 'mime' => 'application/pdf'],\n default => ['extension' => null, 'mime' => null],\n };\n }\n\n public function deleteS3Files(AutomatedReportResult $result): void\n {\n $teamUuid = $result->getReport()->getTeam()->getUuid();\n $reportUuid = $result->getUuid();\n\n // delete all files for a report uuid no mather of pdf, podcast, or both\n // in case of both - the podcast files are linked to the pdf (parent) uuid\n // pdf and podcast date times should be close\n $path = sprintf('%s/%s/%s', $teamUuid, self::S3_DIR, $reportUuid);\n\n foreach (self::FILE_EXTENSIONS_VARIANTS as $extension) {\n $file = $path . '.' . $extension;\n\n if (Storage::exists($file)) {\n Storage::delete($file);\n Log::info('[Reports] Deleted S3 file', [\n 'path' => $file,\n ]);\n }\n }\n\n foreach (self::FILE_PODCAST_EXTENSIONS_VARIANTS as $extension) {\n $file = $path . '_podcast.' . $extension;\n\n if (Storage::exists($file)) {\n Storage::delete($file);\n Log::info('[Reports] Deleted Podcast S3 file', [\n 'path' => $file,\n ]);\n }\n }\n }\n\n /**\n *\n * @param int|null $teamId Optional team ID to filter results\n *\n * @return Collection<int, int> Collection of team IDs\n */\n public function getTeamIdsWithReportsResults(?int $teamId = null): Collection\n {\n return $this->automatedReportsRepository->getTeamIdsWithReportsResults($teamId);\n }\n\n /**\n * Core delete logic for report results using a query\n *\n * @param Builder $query\n * @param array $logContext\n *\n * @return int\n */\n private function deleteReportResultsByQuery(Builder $query, array $logContext = []): int\n {\n $deletedCount = 0;\n\n if ($query->exists()) {\n Log::info(\n 'Run delete report results',\n array_merge(\n $logContext,\n [\n 'service' => 'AutomatedReportsService',\n ]\n )\n );\n\n $query->chunkById(50, function ($results) use (&$deletedCount, $logContext) {\n foreach ($results as $result) {\n $this->deleteReportResult($result);\n $deletedCount++;\n\n Log::info(\n 'Deleted a report result',\n array_merge(\n $logContext,\n [\n 'result_id' => $result->getId(),\n 'report_id' => $result->getReportId(),\n ]\n )\n );\n }\n });\n }\n\n return $deletedCount;\n }\n\n /**\n * Delete report results for a team by retention period\n *\n * @param Team $team\n * @param CarbonImmutable $retentionDate\n *\n * @return int Number of deleted report results\n */\n public function deleteReportsResultsInRetentionPeriod(Team $team, CarbonImmutable $retentionDate): int\n {\n $reportIds = $this->automatedReportsRepository->getReportIdsByTeam($team);\n\n if ($reportIds->isEmpty()) {\n return 0;\n }\n\n $query = $this->automatedReportsRepository\n ->getReportResultsQueryForRetention($team, $retentionDate);\n\n return $this->deleteReportResultsByQuery($query, [\n 'team_id' => $team->getId(),\n 'retention_date' => $retentionDate->toDateTimeString(),\n ]);\n }\n\n /**\n * Delete ALL report results for a specific automated report\n *\n * @param string $uuid\n *\n * @return int\n */\n public function deleteReportResults(string $uuid): int\n {\n $report = $this->getReport($uuid);\n\n $query = $this->automatedReportsRepository->getResultsByReportQuery($report);\n\n return $this->deleteReportResultsByQuery($query, [\n 'report_uuid' => $uuid,\n 'report_id' => $report->getId(),\n ]);\n }\n\n public function deleteReportResult(AutomatedReportResult $result): void\n {\n $this->deleteS3Files($result);\n\n $result->delete();\n }\n\n /**\n * Get all reports for a specific team\n *\n * @param Team $team\n *\n * @return \\Illuminate\\Database\\Eloquent\\Collection\n */\n public function getTeamReports(Team $team): \\Illuminate\\Database\\Eloquent\\Collection\n {\n return $this->automatedReportsRepository->getReportsByTeam($team);\n }\n\n /**\n * Get all report results for a specific report\n *\n * @param AutomatedReport $report\n *\n * @return \\Illuminate\\Database\\Eloquent\\Collection\n */\n public function getReportResults(AutomatedReport $report): \\Illuminate\\Database\\Eloquent\\Collection\n {\n return $this->automatedReportsRepository->getResultsByReport($report);\n }\n\n public function deleteAllReportResults(AutomatedReport $report): void\n {\n $results = $this->getReportResults($report);\n\n /** @var AutomatedReportResult $result */\n foreach ($results as $result) {\n Log::info('Deleting result', [\n 'report' => $report->getId(),\n 'result' => $result->getId(),\n ]);\n\n $this->deleteReportResult($result);\n }\n }\n\n public function deleteAllData(Team $team): void\n {\n Log::info('Deleting automated report and results for team', [\n 'team' => $team->getId(),\n ]);\n\n $reports = $this->getTeamReports($team);\n\n /** @var AutomatedReport $report */\n foreach ($reports as $report) {\n Log::info('Deleting report', [\n 'team' => $team->getId(),\n 'report' => $report->getId(),\n ]);\n\n $this->deleteAllReportResults($report);\n\n $report->delete();\n }\n }\n}","depth":4,"value":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Services\\Kiosk\\AutomatedReports;\n\nuse Carbon\\CarbonImmutable;\nuse Carbon\\CarbonInterface;\nuse Carbon\\Exceptions\\InvalidFormatException;\nuse DateTime;\nuse DateTimeInterface;\nuse DateTimeZone;\nuse Illuminate\\Contracts\\Bus\\Dispatcher as BusDispatcher;\nuse Illuminate\\Database\\Eloquent\\Builder;\nuse Illuminate\\Support\\Carbon;\nuse Illuminate\\Support\\Collection;\nuse Illuminate\\Support\\Facades\\Log;\nuse Illuminate\\Support\\Facades\\Storage;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinition\\InputTypeEnum;\nuse Jiminny\\Component\\AskAnything\\AskAnythingPromptService;\nuse Jiminny\\Component\\AskAnything\\Dtos\\AskAnythingPromptDto;\nuse Jiminny\\Component\\UrlGenerator\\Webhook;\nuse Jiminny\\Contracts\\Repositories\\PlaybookCategoryRepository;\nuse Jiminny\\Contracts\\Repositories\\TeamRepository;\nuse Jiminny\\Contracts\\Repositories\\UserRepository;\nuse Jiminny\\Exceptions\\ApplicationException;\nuse Jiminny\\Exceptions\\InvalidArgumentException;\nuse Jiminny\\Exceptions\\ModelNotFoundException;\nuse Jiminny\\Jobs\\AutomatedReports\\RequestGenerateReportJob;\nuse Jiminny\\Models\\Activity\\Search;\nuse Jiminny\\Models\\AskAnything\\AskAnythingPrompt;\nuse Jiminny\\Models\\AskAnything\\AskAnythingPromptTarget;\nuse Jiminny\\Models\\AutomatedReport;\nuse Jiminny\\Models\\AutomatedReportResult;\nuse Jiminny\\Models\\Contracts\\UserContract;\nuse Jiminny\\Models\\Feature\\FeatureEnum;\nuse Jiminny\\Models\\Team;\nuse Jiminny\\Models\\User;\nuse Jiminny\\Repositories\\AskAnythingRepository;\nuse Jiminny\\Repositories\\AutomatedReportsRepository;\nuse Jiminny\\Repositories\\GroupRepository;\nuse Jiminny\\Repositories\\SearchRepository;\nuse Jiminny\\Repositories\\StageRepository;\nuse Throwable;\n\nclass AutomatedReportsService\n{\n public const string TYPE_LOSS_ANALYSIS = 'loss_analysis';\n public const string TYPE_ASK_JIMINNY = 'ask_jiminny';\n\n /**\n * Standard report types (used by kiosk for existing automated reports).\n */\n // @TODO this will add filter, however if we need to control feature by FF we need conditional logic\n public const array TYPES = [\n ['id' => 'exec_summary', 'name' => 'Exec Summary'],\n ['id' => 'coaching_profiles', 'name' => 'Coaching Profiles'],\n ['id' => 'product_feedback', 'name' => 'Product Feedback'],\n ['id' => self::TYPE_LOSS_ANALYSIS, 'name' => 'Loss Analysis'],\n// ['id' => 'questions', 'name' => 'Questions'],\n// ['id' => 'statistical_quant', 'name' => 'Statistical Quantitative'],\n ];\n\n public const array ALL_TYPES = [\n ...self::TYPES,\n ['id' => self::TYPE_ASK_JIMINNY, 'name' => 'Ask Jiminny'],\n ];\n\n public const string FREQUENCY_DAILY = 'daily';\n public const string FREQUENCY_WEEKLY = 'weekly';\n public const string FREQUENCY_MONTHLY = 'monthly';\n public const string FREQUENCY_QUARTERLY = 'quarterly';\n public const string FREQUENCY_ONE_OFF = 'one_off';\n\n /**\n * Frequencies for standard (non-Ask Jiminny) reports.\n */\n public const array FREQUENCIES = [\n ['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],\n ['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],\n ['id' => self::FREQUENCY_QUARTERLY, 'name' => 'Quarterly'],\n ['id' => self::FREQUENCY_ONE_OFF, 'name' => 'One-off'],\n ];\n\n /**\n * Frequencies for Ask Jiminny reports.\n */\n public const array ASK_JIMINNY_FREQUENCIES = [\n ['id' => self::FREQUENCY_DAILY, 'name' => 'Daily'],\n ['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],\n ['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],\n ];\n\n public const string MEDIA_TYPE_PDF = 'pdf';\n public const string MEDIA_TYPE_PODCAST = 'podcast';\n public const array MEDIA_TYPES = [self::MEDIA_TYPE_PDF, self::MEDIA_TYPE_PODCAST];\n public const array MEDIA_TYPE_OBJECT_PDF = ['id' => self::MEDIA_TYPE_PDF, 'name' => 'PDF'];\n public const array MEDIA_TYPE_OBJECT_PODCAST = ['id' => self::MEDIA_TYPE_PODCAST, 'name' => 'Podcast'];\n public const array MEDIA_TYPE_OBJECTS = [self::MEDIA_TYPE_OBJECT_PDF, self::MEDIA_TYPE_OBJECT_PODCAST];\n\n public const array CALL_TYPE_CONFERENCE = ['id' => 'conference', 'name' => 'Conference'];\n public const array CALL_TYPE_DIALER = ['id' => 'dialer', 'name' => 'Dialer'];\n public const int SENT_REPORT_AT_HOURS = 5;\n public const string PDF_KEY = 'pdf';\n public const string AUDIO_KEY = 'audio';\n\n private const array ALL_FREQUENCIES = [\n ['id' => self::FREQUENCY_DAILY, 'name' => 'Daily'],\n ['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],\n ['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],\n ['id' => self::FREQUENCY_QUARTERLY, 'name' => 'Quarterly'],\n ['id' => self::FREQUENCY_ONE_OFF, 'name' => 'One-off'],\n ];\n private const string S3_DIR = 'reports';\n private const array FILE_EXTENSIONS_VARIANTS = ['html', 'MD', 'pdf'];\n private const array FILE_PODCAST_EXTENSIONS_VARIANTS = ['json', 'mp3', 'ssml'];\n\n public function __construct(\n private readonly TeamRepository $teamRepository,\n private readonly GroupRepository $groupRepository,\n private readonly UserRepository $userRepository,\n private readonly StageRepository $stageRepository,\n private readonly DealStagesService $dealStagesService,\n private readonly RecipientsService $recipientsService,\n private readonly AutomatedReportsRepository $automatedReportsRepository,\n private readonly Webhook $webhookService,\n private readonly BusDispatcher $dispatcher,\n private readonly ActivityTypeService $activityTypeService,\n private readonly PlaybookCategoryRepository $playbookCategoryRepository,\n private readonly AskAnythingPromptService $askAnythingPromptService,\n private readonly SearchRepository $activitySearchRepository,\n private readonly AskAnythingRepository $askAnythingRepository,\n ) {\n }\n\n public static function getTypes(): array\n {\n $types = self::TYPES;\n\n return array_map(static function ($type) {\n return $type['id'];\n }, $types);\n }\n\n public static function getCallTypes(): array\n {\n return array_map(static function ($callType) {\n return $callType['id'];\n }, [self::CALL_TYPE_CONFERENCE, self::CALL_TYPE_DIALER]);\n }\n\n public static function getFrequencies(): array\n {\n return array_map(static function ($frequency) {\n return $frequency['id'];\n }, self::FREQUENCIES);\n }\n\n // front-facing structure\n public function getReportEnabledFieldData(bool $value = false): array\n {\n return [\n 'id' => 'report_enabled',\n 'label' => '',\n 'inputType' => InputTypeEnum::TOGGLE,\n 'value' => $value,\n ];\n }\n\n // Organizations = Teams\n public function getOrganizationFieldData(?string $value = null, bool $shortVersion = false): array\n {\n $options = $this->getTeams();\n\n if ($shortVersion) {\n return [\n 'id' => 'organization',\n 'label' => 'Organization',\n 'options' => $options,\n ];\n }\n\n return [\n 'id' => 'organization',\n 'label' => 'Organization',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => $options,\n 'value' => $value,\n 'dependencies' => [\n 'teams',\n 'deal_stage_at_call',\n 'current_deal_stage',\n 'recipients',\n ActivityTypeService::PLAYBOOK_CATEGORIES_KEY,\n ],\n 'dependsOn' => [],\n ];\n }\n\n // Teams = Groups\n public function getTeamFieldData(array $options = [], array $value = [], bool $shortVersion = false): array\n {\n if ($shortVersion) {\n return [\n 'id' => 'teams',\n 'label' => 'Team',\n 'options' => $options,\n ];\n }\n\n return [\n 'id' => 'teams',\n 'label' => 'Team',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'required' => false,\n 'placeholder' => 'Select',\n 'options' => $options,\n 'value' => $value, // value should be an array of objects {id, name}\n 'dependencies' => [ActivityTypeService::PLAYBOOK_CATEGORIES_KEY],\n 'dependsOn' => [],\n ];\n }\n\n public function getReportTypeFieldData(?string $value = null, bool $shortVersion = false, ?Team $team = null): array\n {\n $types = [];\n if ($team instanceof Team) {\n if ($team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {\n $types = self::TYPES;\n }\n if ($team->hasFeature(FeatureEnum::ASK_JIMINNY_REPORTS)) {\n $types[] = ['id' => self::TYPE_ASK_JIMINNY, 'name' => 'Ask Jiminny'];\n }\n } else {\n $types = self::TYPES;\n }\n\n if ($shortVersion) {\n return [\n 'id' => 'report_type',\n 'label' => 'Report Type',\n 'options' => $types,\n ];\n }\n\n return [\n 'id' => 'report_type',\n 'label' => 'Report Type',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => $types,\n 'value' => $value,\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getFrequencyFieldData(?string $value = null): array\n {\n return [\n 'id' => 'frequency',\n 'label' => 'Frequency',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => self::FREQUENCIES,\n 'value' => $value,\n 'dependencies' => ['period'],\n 'dependsOn' => [],\n ];\n }\n\n public function getPeriodFieldData(?string $valueStartDate = null, ?string $valueEndDate = null): array\n {\n return [\n 'id' => 'period',\n 'label' => 'Select one-off period',\n 'inputType' => InputTypeEnum::DATE_RANGE,\n 'required' => true,\n 'placeholder' => 'Select',\n 'value' => ['startDate' => $valueStartDate, 'endDate' => $valueEndDate],\n 'queryParams' => [\n 'startDate' => 'start_date_period',\n 'endDate' => 'end_date_period',\n ],\n 'dependencies' => [],\n 'dependsOn' => ['frequency'],\n ];\n }\n\n public function getActivityTypesFieldData(?Team $team = null, array $value = [], array $teamsFilter = []): array\n {\n return $this->activityTypeService->getActivityTypeFieldData(team: $team, value: $value, groupIds: $teamsFilter);\n }\n\n public function getDealStageAtCallFieldData(?Team $team = null, array $value = []): array\n {\n return $this->dealStagesService->getDealStageAtCallFieldData(team: $team, value: $value);\n }\n\n public function getCurrentDealStageFieldData(?Team $team = null, array $value = []): array\n {\n return $this->dealStagesService->getCurrentDealStageFieldData(team: $team, value: $value);\n }\n\n public function getDealValueFieldData(?int $valueMin = null, ?int $valueMax = null): array\n {\n return [\n 'id' => 'deal_value',\n 'label' => 'Deal Value',\n 'inputType' => InputTypeEnum::INTEGER_RANGE,\n 'required' => false,\n 'value' => ['min' => $valueMin, 'max' => $valueMax],\n 'queryParams' => [\n 'min' => 'min_deal_value',\n 'max' => 'max_deal_value',\n ],\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getCallTypeFieldData(bool $conferenceOn = false, bool $dialerOn = false): array\n {\n $value = [];\n $conferenceOn && $value[] = self::CALL_TYPE_CONFERENCE;\n $dialerOn && $value[] = self::CALL_TYPE_DIALER;\n\n return [\n 'id' => 'call_type',\n 'label' => 'Call Type',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'required' => true,\n 'options' => [\n self::CALL_TYPE_CONFERENCE,\n self::CALL_TYPE_DIALER,\n ],\n 'value' => $value,\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getMediaTypeFieldData(?AutomatedReport $report = null): array\n {\n $value = [];\n\n if ($report) {\n $value = $this->transformMediaTypes($report);\n }\n\n return [\n 'id' => 'media_types',\n 'label' => 'Export as',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'required' => true,\n 'options' => self::MEDIA_TYPE_OBJECTS,\n 'value' => $value,\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getCallDurationFieldData(?int $valueMin = null, ?int $valueMax = null): array\n {\n return [\n 'id' => 'call_duration',\n 'label' => 'Call Duration',\n 'inputType' => InputTypeEnum::INTEGER_RANGE,\n 'required' => false,\n 'value' => ['min' => $valueMin, 'max' => $valueMax],\n 'queryParams' => [\n 'min' => 'min_call_duration',\n 'max' => 'max_call_duration',\n ],\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getRecipientsFieldData(?Team $team = null, array $value = []): array\n {\n return $this->recipientsService->getRecipientsFieldData(team: $team, value: $value);\n }\n\n public function getJiminnyRecipientsFieldData(array $value = []): array\n {\n return $this->recipientsService->getJiminnyRecipientsFieldData($value);\n }\n\n public function getAdditionalPromptInputFieldData(?string $value = null): array\n {\n return [\n 'id' => 'additional_prompt_input',\n 'label' => 'Special requirements',\n 'inputType' => InputTypeEnum::TEXTAREA,\n 'required' => false,\n 'placeholder' => 'What should be the focus of the report?',\n 'value' => $value,\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getCustomReportNameFieldData(?string $value = null): array\n {\n return [\n 'id' => 'custom_name',\n 'label' => 'Custom report name',\n 'inputType' => InputTypeEnum::TEXT,\n 'required' => false,\n 'placeholder' => 'Enter custom name',\n 'value' => $value,\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n // data providers\n public function getTeams(): array\n {\n $teams = $this->teamRepository->getTeamsForKiosk(status: Team::STATUS_ACTIVE);\n\n $teamData = [];\n foreach ($teams as $team) {\n if (! $team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {\n continue;\n }\n\n $teamData[] = $this->transformTeam($team);\n }\n\n return $teamData;\n }\n\n public function getTeamGroups(string $teamUuid): array\n {\n $data = [];\n $team = $this->getTeam($teamUuid);\n\n if ($team !== null) {\n $groups = $team->groups()->get();\n\n foreach ($groups as $group) {\n $data[] = [\n 'id' => $group->getUuid(),\n 'name' => $group->getName(),\n ];\n }\n }\n\n return $data;\n }\n\n public function getTeamsGroupsOptions(array $filterTeamUuids = []): array\n {\n $data = [];\n $teams = $this->getTeams();\n\n foreach ($teams as $team) {\n if (! empty($filterTeamUuids) && ! in_array($team['id'], $filterTeamUuids, true)) {\n continue;\n }\n\n $data[] = [\n 'label' => $team['name'],\n 'groups' => $this->getTeamGroups($team['id']),\n ];\n }\n\n return $data;\n }\n\n public function getTeam(string $teamUuid): ?Team\n {\n return $this->teamRepository->idOrUuid($teamUuid);\n }\n\n public function getTeamById(int $teamId): ?Team\n {\n return $this->teamRepository->find($teamId);\n }\n\n public function getGroupsUuids(AutomatedReport $report): array\n {\n $uuids = [];\n $reportGroups = $report->getGroups();\n foreach ($reportGroups as $groupId) {\n if ($group = $this->groupRepository->find($groupId)) {\n $uuids[] = $group->getUuid();\n }\n }\n\n return $uuids;\n }\n\n public function getPlaybookCategoriesUuids(AutomatedReport $report): array\n {\n $uuids = [];\n $playbookCategories = $report->getPlaybookCategories();\n foreach ($playbookCategories as $id) {\n if ($category = $this->playbookCategoryRepository->find($id)) {\n $uuids[] = $category->getUuid();\n }\n }\n\n return $uuids;\n }\n\n public function getDealAtCallStagesUuids(AutomatedReport $report): array\n {\n $uuids = [];\n $reportStages = $report->getDealAtCallStages();\n foreach ($reportStages as $id) {\n if ($stage = $this->stageRepository->find($id)) {\n $uuids[] = $stage->getUuid();\n }\n }\n\n return $uuids;\n }\n\n public function getCurrentDealStagesUuids(AutomatedReport $report): array\n {\n $uuids = [];\n $reportStages = $report->getCurrentDealStages();\n foreach ($reportStages as $id) {\n if ($stage = $this->stageRepository->find($id)) {\n $uuids[] = $stage->getUuid();\n }\n }\n\n return $uuids;\n }\n\n public function getUsersUuids(AutomatedReport $report): array\n {\n return $this->extractUserUuids($report->getRecipients());\n }\n\n public function getJiminnyUsersUuids(AutomatedReport $report): array\n {\n return $this->extractUserUuids($report->getJiminnyRecipients());\n }\n\n /**\n * @param array<string, mixed> $recipients\n */\n private function extractUserUuids(array $recipients): array\n {\n $userIds = $recipients['users'] ?? [];\n\n return collect($userIds)\n ->map(fn ($id) => $this->userRepository->find((int) $id))\n ->filter()\n ->map(fn (UserContract $user) => $user->getUuid())\n ->values()\n ->all();\n }\n\n // get mail data\n public function getRecipientUsers(AutomatedReport $report): array\n {\n return $this->buildRecipientUsers($report->getRecipients());\n }\n\n private function getJiminnyRecipientUsers(AutomatedReport $report): array\n {\n return $this->buildRecipientUsers($report->getJiminnyRecipients());\n }\n\n /**\n * @param array<string, mixed> $recipients\n */\n private function buildRecipientUsers(array $recipients): array\n {\n $userIds = $recipients['users'] ?? [];\n\n return collect($userIds)\n ->map(fn ($id) => $this->userRepository->find((int) $id))\n ->filter()\n ->map(fn (UserContract $user) => [\n 'email' => $user->getEmailAddress(),\n 'name' => $user->getName(),\n 'timezone' => $user->getTimezone()->getName(),\n ])\n ->values()\n ->all();\n }\n\n public function getValidRecipientUsers(AutomatedReport $report, bool $includeJiminny = false): array\n {\n if ($report->isAskJiminnyReport()) {\n $recipients = $this->resolveAskJiminnyRecipients($report);\n } else {\n $recipients = $this->getRecipientUsers($report);\n if ($includeJiminny) {\n $recipients = array_merge($recipients, $this->getJiminnyRecipientUsers($report));\n }\n }\n\n $emails = [];\n\n return array_values(array_filter(\n $recipients,\n static function ($recipient) use (&$emails) {\n if (empty($recipient['email']) || in_array($recipient['email'], $emails, true)) {\n return false;\n }\n $emails[] = $recipient['email'];\n\n return true;\n }\n ));\n }\n\n private function resolveAskJiminnyRecipients(AutomatedReport $report): array\n {\n $recipients = [];\n\n $creator = $report->getCreator();\n if ($creator !== null) {\n $recipients[] = [\n 'email' => $creator->getEmailAddress(),\n 'name' => $creator->getName(),\n 'timezone' => $creator->getTimezone()->getName(),\n ];\n }\n\n return array_merge(\n $recipients,\n $this->buildRecipientUsers($report->getRecipients()),\n $this->getGroupRecipientUsers($report),\n );\n }\n\n private function getGroupRecipientUsers(AutomatedReport $report): array\n {\n $users = [];\n foreach ($report->getGroups() as $groupId) {\n $group = $this->groupRepository->find($groupId);\n if ($group === null) {\n continue;\n }\n foreach ($group->getMembers() as $member) {\n $users[] = [\n 'email' => $member->getEmailAddress(),\n 'name' => $member->getName(),\n 'timezone' => $member->getTimezone()->getName(),\n ];\n }\n }\n\n return $users;\n }\n\n public function getReportTypeName(AutomatedReportResult $report): string\n {\n $type = $report->getReport()->getType();\n\n $getType = $this->transformReportType($type);\n\n return $getType['name'];\n }\n\n public function getReportPeriodName(AutomatedReportResult $report): string\n {\n $from = $report->getFromDate();\n $to = $report->getToDate();\n $frequency = $report->getReport()->getFrequency();\n\n if ($from === null || $to === null) {\n if (! $report->getReport()->isAskJiminnyReport()) {\n $invalidPeriod = $from === null ? 'from' : 'to';\n\n throw new ApplicationException('Report period is invalid: ' . $invalidPeriod);\n }\n\n $period = $this->calculateFromAndToDatePeriod($frequency);\n $from = $period['fromDate'];\n $to = $period['toDate'];\n }\n\n return $this->formatReportPeriodName($frequency, $from, $to);\n }\n\n private function formatReportPeriodName(string $frequency, Carbon $from, Carbon $to): string\n {\n $fromYear = $from->format('Y');\n $toYear = $to->format('Y');\n $differentYears = $fromYear !== $toYear;\n\n switch ($frequency) {\n case self::FREQUENCY_DAILY:\n return $from->format('j M Y');\n\n case self::FREQUENCY_QUARTERLY:\n // 'Jan-Mar 2025' or 'Nov 2024-Jan 2025' if years differ\n $startMonth = $from->format('M');\n $endMonth = $to->copy()->subMonth();\n $endMonthName = $endMonth->format('M');\n $endMonthYear = $endMonth->format('Y');\n\n if ($differentYears) {\n return \"{$startMonth} {$fromYear} - {$endMonthName} {$endMonthYear}\";\n }\n\n return \"{$startMonth} - {$endMonthName} {$toYear}\";\n\n case self::FREQUENCY_MONTHLY:\n // 'May 2025' - monthly reports are always within the same year\n return $from->format('M Y');\n\n case self::FREQUENCY_WEEKLY:\n // '4 - 8 Aug 2025', '27 Oct - 3 Nov 2025', or '28 Dec 2024 - 3 Jan 2025' if years differ\n $startDay = $from->format('j');\n $endDay = $to->format('j');\n $startMonth = $from->format('M');\n $endMonth = $to->format('M');\n\n if ($differentYears) {\n return \"{$startDay} {$startMonth} {$fromYear} - {$endDay} {$endMonth} {$toYear}\";\n }\n\n if ($startMonth !== $endMonth) {\n return \"{$startDay} {$startMonth} - {$endDay} {$endMonth} {$toYear}\";\n }\n\n return \"{$startDay} - {$endDay} {$endMonth} {$toYear}\";\n\n case self::FREQUENCY_ONE_OFF:\n // '2 May-31 May 2025' or '15 Dec 2024-15 Jan 2025' if years differ\n $startDay = $from->format('j');\n $startMonth = $from->format('M');\n $endDay = $to->format('j');\n $endMonth = $to->format('M');\n\n // If same month and year, use a format like '2-31 May 2025'\n if ($startMonth === $endMonth && ! $differentYears) {\n return \"{$startDay} - {$endDay} {$startMonth} {$toYear}\";\n }\n\n // If different years, include both years\n if ($differentYears) {\n return \"{$startDay} {$startMonth} {$fromYear} - {$endDay} {$endMonth} {$toYear}\";\n }\n\n // Same year but different months\n return \"{$startDay} {$startMonth} - {$endDay} {$endMonth} {$toYear}\";\n\n default:\n // Default format for unknown frequencies\n return $from->format('j M Y') . ' - ' . $to->format('j M Y');\n }\n }\n\n public function getReportTeamsName(AutomatedReportResult $report): string\n {\n $groups = $report->getGroups();\n\n if (empty($groups)) {\n return 'All';\n }\n\n // Get group names from repository\n $groupNames = [];\n foreach ($groups as $groupId) {\n $group = $this->groupRepository->find($groupId);\n if ($group) {\n $groupNames[] = $group->getName();\n }\n }\n\n if (count($groupNames) === 1) {\n // Single team format\n $teamsName = $groupNames[0];\n } else {\n // Multiple teams format\n $teamsName = implode(', ', $groupNames);\n }\n\n return $teamsName;\n }\n\n public function getReportFileName(AutomatedReportResult $report): string\n {\n $customName = $report->getReport()->getCustomName();\n $periodName = $this->getReportPeriodName($report);\n $filenameSuffix = $this->getFilenameSuffix($report);\n\n if ($customName) {\n if ($filenameSuffix) {\n $customName .= \" {$filenameSuffix}\";\n }\n\n return $this->sanitizeFileName(\"{$customName} - {$periodName}\");\n }\n\n $baseName = $this->getReportTypeName($report);\n\n if ($filenameSuffix) {\n $baseName .= \" {$filenameSuffix}\";\n }\n\n return $this->sanitizeFileName(\"{$baseName} - {$periodName} - {$this->getReportTeamsName($report)}\");\n }\n\n public function getReportFileNameWithExtension(AutomatedReportResult $result): string\n {\n $extension = $this->getMediaTypeMetadata($result)['extension'];\n\n return $this->getReportFileName($result) . '.' . $extension;\n }\n\n public function sanitizeFileName(string $fileName): string\n {\n return str_replace(['/', '\\\\'], '-', $fileName);\n }\n\n public function isUserRecipientOfReport(User $user, AutomatedReport $report): bool\n {\n $recipients = array_map('intval', $report->getRecipients()['users'] ?? []);\n\n return in_array($user->getId(), $recipients);\n }\n\n public function transformReportResults(Collection $automatedReportResults): array\n {\n $data = [];\n foreach ($automatedReportResults as $automatedReportResult) {\n /** @var AutomatedReportResult $automatedReportResult */\n\n $report = $automatedReportResult->getReport();\n\n $createdBy = $report->getCreator();\n $creator = [\n 'id' => $createdBy?->getUuid(),\n 'name' => $createdBy?->getName(),\n 'email' => $createdBy?->getEmailAddress(),\n 'photoUrl' => $createdBy?->getPhotoUrl(),\n ];\n\n $data[] = [\n 'id' => $automatedReportResult->getUuid(),\n 'name' => $automatedReportResult->getName(),\n 'frequency' => $this->transformFrequency($report->getFrequency()),\n 'recipients' => [\n ...array_values($this->transformGroups(team: $report->getTeam(), groupsIds: $report->getGroups())),\n ...array_values($this->transformRecipients($report->getRecipients())),\n ],\n 'report_type' => $this->transformReportType($report->getType()),\n 'media_type' => $automatedReportResult->getMediaType(),\n 'downloadUrl' => $this->generateReportResultDownloadUrl($automatedReportResult),\n 'viewUrl' => $this->generateReportResultViewUrl($automatedReportResult),\n 'generated_at' => $automatedReportResult->getGeneratedAt()?->toIso8601String(),\n 'creator' => $creator,\n ];\n }\n\n return $data;\n }\n\n public function hasCallTypeConference(AutomatedReport $report): bool\n {\n return in_array(self::CALL_TYPE_CONFERENCE['id'], $report->getCallTypes(), true);\n }\n\n public function hasCallTypeDialer(AutomatedReport $report): bool\n {\n return in_array(self::CALL_TYPE_DIALER['id'], $report->getCallTypes(), true);\n }\n\n // transformers\n private function transformTeam(Team $team): array\n {\n if (! $team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {\n return [];\n }\n\n return [\n 'id' => $team->getUuid(),\n 'name' => $team->getName(),\n ];\n }\n\n private function transformReportFullView(AutomatedReport $report): array\n {\n $base = $this->transformReportBase($report);\n\n return $report->getType() === self::TYPE_ASK_JIMINNY\n ? $base + $this->transformAskJiminnyFields($report)\n : $base + $this->transformStandardReportFields($report);\n }\n\n private function transformReportBase(AutomatedReport $report): array\n {\n return [\n 'id' => $report->getUuid(),\n 'organization' => $this->transformOrganization(team: $report->getTeam()),\n 'report_type' => $this->transformReportType($report->getType()),\n 'frequency' => $this->transformFrequency($report->getFrequency()),\n ];\n }\n\n private function transformStandardReportFields(AutomatedReport $report): array\n {\n $team = $report->getTeam();\n\n return [\n 'report_enabled' => $report->getStatus(),\n 'start_date_period' => $report->getFrom()?->format('Y-m-d H:i:s'),\n 'end_date_period' => $report->getTo()?->format('Y-m-d H:i:s'),\n 'deal_value_min' => $report->getDealValueMin(),\n 'deal_value_max' => $report->getDealValueMax(),\n 'call_types' => $this->transformCallType($report->getCallTypes()),\n 'media_types' => $this->transformMediaTypes($report),\n 'call_duration_min' => $this->transformDurationToMinutes($report->getCallDurationMin()),\n 'call_duration_max' => $this->transformDurationToMinutes($report->getCallDurationMax()),\n 'teams' => $this->transformGroups(team: $team, groupsIds: $report->getGroups()),\n 'deal_at_call_stages' => $this->transformStages(team: $team, stagesIds: $report->getDealAtCallStages()),\n 'current_deal_stages' => $this->transformStages(team: $team, stagesIds: $report->getCurrentDealStages()),\n 'recipients' => $this->transformRecipients($report->getRecipients()),\n 'created_by' => $this->transformCreator($report->getCreator()),\n 'additional_prompt_input' => $report->getAdditionalPromptInput(),\n 'custom_name' => $report->getCustomName(),\n 'created_at' => $report->getCreatedAt()->format('Y-m-d H:i:s'),\n 'updated_at' => $report->getUpdatedAt()->format('Y-m-d H:i:s'),\n 'deleted_at' => $report->getDeletedAt()?->format('Y-m-d H:i:s'),\n ];\n }\n\n private function transformAskJiminnyFields(AutomatedReport $report): array\n {\n $team = $report->getTeam();\n $creatorId = $report->getAttribute('created_by');\n $explicitUserIds = array_values(array_filter(\n $report->getRecipients()['users'] ?? [],\n static fn ($id) => $id !== $creatorId\n ));\n\n return [\n 'report_name' => $report->getCustomName(),\n 'enabled' => $report->getStatus(),\n 'share_teams' => $this->transformGroups(team: $team, groupsIds: $report->getGroups()),\n 'share_users' => $this->transformRecipients(['users' => $explicitUserIds]),\n 'saved_search' => $this->transformSafeSearch($report->getSavedSearch()),\n 'ask_jiminny_prompt' => $this->transformAskJiminnyPrompt($report->getAskAnythingPrompt()),\n 'expires_on' => $report->getExpiresAt()?->format('Y-m-d'),\n ];\n }\n\n private function transformOrganization(?Team $team): array\n {\n return [\n 'id' => $team?->getUuid(),\n 'name' => $team?->getName(),\n ];\n }\n\n private function transformReportType(string $type): array\n {\n foreach (self::ALL_TYPES as $typeItem) {\n if ($typeItem['id'] === $type) {\n return $typeItem;\n }\n }\n\n return [];\n }\n\n private function transformCallType(array $types): array\n {\n $result = [];\n $callTypes = [self::CALL_TYPE_CONFERENCE, self::CALL_TYPE_DIALER];\n\n foreach ($types as $type) {\n foreach ($callTypes as $callTypeItem) {\n if ($callTypeItem['id'] === $type) {\n $result[] = $callTypeItem;\n\n break;\n }\n }\n }\n\n return $result;\n }\n\n private function transformMediaTypes(AutomatedReport $report): array\n {\n $values = [];\n\n foreach ($report->getMediaTypes() as $mediaType) {\n if (! in_array($mediaType, self::MEDIA_TYPES, true)) {\n continue;\n }\n\n $values[] = match ($mediaType) {\n self::MEDIA_TYPE_PDF => self::MEDIA_TYPE_OBJECT_PDF,\n self::MEDIA_TYPE_PODCAST => self::MEDIA_TYPE_OBJECT_PODCAST,\n };\n }\n\n return $values;\n }\n\n private function transformFrequency(string $frequency): array\n {\n foreach (self::ALL_FREQUENCIES as $frequencyItem) {\n if ($frequencyItem['id'] === $frequency) {\n return $frequencyItem;\n }\n }\n\n return [];\n }\n\n public function transformDurationToMinutes(?int $duration): ?int\n {\n if (! $duration) {\n return null;\n }\n\n return (int) ($duration / 60);\n }\n\n private function transformGroups(?Team $team, array $groupsIds): array\n {\n if (empty($groupsIds) || ! $team) {\n return [];\n }\n\n $data = [];\n foreach ($groupsIds as $groupId) {\n $group = $team->groups()->where('id', $groupId)->first();\n\n if ($group) {\n $data[] = [\n 'id' => $group->getUuid(),\n 'name' => $group->getName(),\n 'photoUrl' => $group->getPhotoUrl(),\n ];\n }\n }\n\n return $data;\n }\n\n private function transformStages(?Team $team, array $stagesIds): array\n {\n if (empty($stagesIds) || ! $team) {\n return [];\n }\n\n $data = [];\n foreach ($stagesIds as $stageId) {\n $stage = $team->stages()->where('id', $stageId)->first();\n\n if ($stage) {\n $data[] = [\n 'id' => $stage->getUuid(),\n 'name' => $stage->getName(),\n ];\n }\n }\n\n return $data;\n }\n\n private function transformRecipients(array $recipients): array\n {\n $users = [];\n foreach ($recipients['users'] ?? [] as $userId) {\n $users[] = $this->transformUser($userId);\n }\n\n return $users;\n }\n\n private function transformCreator(?User $user): ?array\n {\n if ($user === null) {\n return null;\n }\n\n return $this->transformUser($user->getId());\n }\n\n private function transformAskJiminnyPrompt(?AskAnythingPrompt $prompt): ?array\n {\n if ($prompt === null) {\n return null;\n }\n\n return [\n 'id' => $prompt->getUuid(),\n 'name' => $prompt->getTitle(),\n ];\n }\n\n private function transformSafeSearch(?Search $search): ?array\n {\n if ($search === null) {\n return null;\n }\n\n return [\n 'id' => $search->getUuid(),\n 'name' => $search->getName(),\n ];\n }\n\n private function transformUser(int $userId): array\n {\n /* @var ?User $user */\n $user = $this->userRepository->find($userId);\n\n return [\n 'id' => $user?->getUuid(),\n 'name' => $user?->getName(),\n 'email' => $user?->getEmailAddress(),\n 'photoUrl' => $user?->getPhotoUrl(),\n ];\n }\n\n public function create(array $data): array\n {\n $validatedData = $this->validateAndTransformData($data);\n $validatedData['created_by'] = auth()->id();\n\n $automatedReport = $this->automatedReportsRepository->create($validatedData);\n\n $this->generateOneOffReport($automatedReport);\n\n return $this->transformReportFullView($automatedReport);\n }\n\n public function update(string $uuid, array $data): array\n {\n $validatedData = $this->validateAndTransformData($data);\n $report = $this->automatedReportsRepository->findByUuid($uuid);\n\n if (! $report) {\n throw new InvalidArgumentException('Report not found');\n }\n\n $oldCustomName = $report->getCustomName();\n\n $automatedReport = $this->automatedReportsRepository->update($report, $validatedData);\n\n if ($oldCustomName !== $automatedReport->getCustomName()) {\n $this->updateResultNames($automatedReport);\n }\n\n $this->generateOneOffReport($automatedReport);\n\n return $this->transformReportFullView($automatedReport);\n }\n\n /**\n * Create an Ask Jiminny report.\n */\n public function createAskJiminnyReport(array $data, User $creator): array\n {\n $validatedData = $this->validateAskJiminnyReportData($data, $creator);\n $validatedData['created_by'] = $creator->getId();\n\n $automatedReport = $this->automatedReportsRepository->create($validatedData);\n\n return $this->transformReportFullView($automatedReport);\n }\n\n /**\n * Update an Ask Jiminny report.\n */\n public function updateAskJiminnyReport(AutomatedReport $report, array $data, User $user): array\n {\n if (! $report->isAskJiminnyReport()) {\n throw new InvalidArgumentException('Report is not an Ask Jiminny report');\n }\n\n $validatedData = $this->validateAskJiminnyReportData($data, $user);\n\n $oldCustomName = $report->getCustomName();\n\n $automatedReport = $this->automatedReportsRepository->update($report, $validatedData);\n\n if ($oldCustomName !== $automatedReport->getCustomName()) {\n $this->updateResultNames($automatedReport);\n }\n\n return $this->transformReportFullView($automatedReport);\n }\n\n public function updateAskJiminnyReportStatus(AutomatedReport $report, bool $status): array\n {\n $this->automatedReportsRepository->update($report, ['status' => $status]);\n\n return $this->transformReportFullView($report->fresh());\n }\n\n /**\n * Validate and transform data for Ask Jiminny reports.\n */\n private function validateAskJiminnyReportData(array $data, User $user): array\n {\n // Validate name\n $name = trim($data['report_name'] ?? '');\n if (empty($name)) {\n throw new InvalidArgumentException('Report name is required');\n }\n if (mb_strlen($name) > 50) {\n throw new InvalidArgumentException('Report name must be 50 characters or less');\n }\n\n // Validate frequency (only daily, weekly, monthly for Ask Jiminny)\n $frequency = $data['frequency'] ?? null;\n $askJiminnyFrequencies = [self::FREQUENCY_DAILY, self::FREQUENCY_WEEKLY, self::FREQUENCY_MONTHLY];\n if (! in_array($frequency, $askJiminnyFrequencies, true)) {\n throw new InvalidArgumentException('Frequency must be daily, weekly, or monthly');\n }\n\n // Validate expiration date\n $expiresAt = $data['expires_on'] ?? null;\n if (empty($expiresAt)) {\n throw new InvalidArgumentException('Expiration date is required');\n }\n\n try {\n $expiresAtDate = Carbon::parse($expiresAt);\n } catch (InvalidFormatException $e) {\n throw new InvalidArgumentException('Expiration date format is invalid');\n }\n $maxExpiration = Carbon::now()->addYear();\n if ($expiresAtDate->gt($maxExpiration)) {\n throw new InvalidArgumentException('Expiration date cannot be more than 1 year from now');\n }\n if ($expiresAtDate->isPast()) {\n throw new InvalidArgumentException('Expiration date cannot be in the past');\n }\n\n // Validate saved search\n $activitySearchId = $data['saved_search'] ?? null;\n if (empty($activitySearchId)) {\n throw new InvalidArgumentException('Saved search is required');\n }\n $savedSearch = $this->activitySearchRepository->findByUuidAndUser($activitySearchId, $user);\n if (! $savedSearch) {\n throw new InvalidArgumentException('Saved search not found or does not belong to you');\n }\n\n // Validate saved prompt\n $askAnythingPromptId = $data['ask_jiminny_prompt'] ?? null;\n if (empty($askAnythingPromptId)) {\n throw new InvalidArgumentException('Ask Jiminny prompt is required');\n }\n $prompt = $this->askAnythingRepository->getPromptByUuid($askAnythingPromptId);\n if (! $prompt) {\n throw new InvalidArgumentException('Ask Jiminny prompt not found');\n }\n\n // Validate status\n $status = $data['enabled'] ?? false;\n\n $recipientUserIds = [$user->getId()];\n\n if (! empty($data['share_users'])) {\n $sharedUserIds = $this->validateAndGetUserIdsByTeam(\n $user->team,\n (array) $data['share_users']\n );\n $recipientUserIds = array_merge($recipientUserIds, $sharedUserIds);\n }\n\n $sharedGroupIds = [];\n if (! empty($data['share_teams'])) {\n $sharedGroupIds = $this->validateAndGetGroupIds($user->team, (array) $data['share_teams']);\n }\n\n $recipientUserIds = array_values(array_unique($recipientUserIds));\n\n return [\n 'team_id' => $user->getTeamId(),\n 'type' => self::TYPE_ASK_JIMINNY,\n 'status' => (bool) $status,\n 'frequency' => $frequency,\n 'custom_name' => $name,\n 'activity_search_id' => $savedSearch->getId(),\n 'ask_anything_prompt_id' => $prompt->getId(),\n 'expires_at' => $expiresAtDate->toDateString(),\n 'media_types' => [self::MEDIA_TYPE_PDF],\n 'call_types' => [],\n 'recipients' => ['users' => $recipientUserIds],\n 'groups' => $sharedGroupIds,\n ];\n }\n\n public static function getAskJiminnyFrequencies(): array\n {\n return array_map(static function ($frequency) {\n return $frequency['id'];\n }, self::ASK_JIMINNY_FREQUENCIES);\n }\n\n public function getAskJiminnyReportFilters(User $user): array\n {\n $savedSearches = $this->activitySearchRepository->findByUserOrderedByName($user)\n ->map(fn (Search $search) => [\n 'id' => $search->getUuid(),\n 'name' => $search->getName(),\n ])\n ->values()->all();\n\n $prompts = collect(\n $this->askAnythingPromptService->get($user, AskAnythingPromptTarget::on_demand)\n )->map(fn (AskAnythingPromptDto $prompt) => [\n 'id' => $prompt->id,\n 'name' => $prompt->title,\n ])->values()->all();\n\n return [\n [\n 'id' => 'prompt',\n 'label' => 'Prompt',\n 'options' => $prompts,\n ],\n [\n 'id' => 'saved_search',\n 'label' => 'Saved Search',\n 'options' => $savedSearches,\n ],\n ];\n }\n\n public function getAskJiminnyReportFormData(User $user, ?AutomatedReport $report = null): array\n {\n $team = $user->getTeam();\n $userTimezone = $user->getTimezone();\n\n $savedSearches = $this->activitySearchRepository->findByUserOrderedByName($user)\n ->map(fn (Search $search) => [\n 'id' => $search->getUuid(),\n 'name' => $search->getName(),\n ])\n ->values()->all();\n\n $prompts = collect(\n $this->askAnythingPromptService->get($user, AskAnythingPromptTarget::on_demand)\n )->map(fn (AskAnythingPromptDto $prompt) => [\n 'id' => $prompt->id,\n 'name' => $prompt->title,\n ])->values()->all();\n\n $teamGroups = $this->groupRepository->getAllByTeam($team)->map(fn ($group) => [\n 'id' => $group->getUuid(),\n 'name' => $group->getName(),\n ])->values()->all();\n\n $shareUsers = $this->recipientsService->getRecipientsFieldData(team: $team)['options'] ?? [];\n\n $sharedTeamsValue = [];\n $sharedUsersValue = [];\n if ($report) {\n $sharedTeamsValue = $this->transformGroups($team, $report->getGroups());\n\n $recipientUserIds = $report->getRecipients()['users'] ?? [];\n $creatorId = $report->getAttribute('created_by');\n $sharedUserIds = array_values(array_filter(\n $recipientUserIds,\n static fn ($id) => $id !== $creatorId\n ));\n $sharedUsersValue = collect($sharedUserIds)\n ->map(fn ($id) => $this->userRepository->find((int) $id))\n ->filter()\n ->map(fn (User $u) => [\n 'id' => $u->getUuid(),\n 'name' => $u->getName(),\n ])\n ->values()\n ->all();\n }\n\n return [\n 'fields' => [\n [\n 'id' => 'enabled',\n 'inputType' => InputTypeEnum::TOGGLE,\n 'label' => '',\n 'value' => $report?->getStatus() ?? false,\n ],\n [\n 'id' => 'report_name',\n 'inputType' => InputTypeEnum::TEXT,\n 'label' => 'Name',\n 'placeholder' => 'Enter name',\n 'required' => true,\n 'validation' => ['maxLength' => 50],\n 'value' => $report?->getCustomName() ?? '',\n ],\n [\n 'id' => 'frequency',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'label' => 'Frequency',\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => self::ASK_JIMINNY_FREQUENCIES,\n 'value' => $report ? $this->transformFrequency($report->getFrequency()) : null,\n ],\n [\n 'id' => 'expires_on',\n 'inputType' => InputTypeEnum::DATE,\n 'label' => 'Expires on',\n 'required' => true,\n 'placeholder' => 'Select',\n 'validation' => [\n 'minDate' => now($userTimezone)->toDateString(),\n 'maxDate' => now($userTimezone)->addYear()->toDateString(),\n ],\n 'value' => $report?->getExpiresAt()?->toDateString(),\n ],\n [\n 'id' => 'share_teams',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'label' => 'Team',\n 'required' => false,\n 'placeholder' => 'Select',\n 'options' => $teamGroups,\n 'value' => $sharedTeamsValue,\n ],\n [\n 'id' => 'share_users',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'label' => 'Team member',\n 'required' => false,\n 'placeholder' => 'Select',\n 'groupLabelKey' => 'label',\n 'groupValuesKey' => 'users',\n 'optionLabelKey' => 'name',\n 'optionValueKey' => 'id',\n 'options' => $shareUsers,\n 'value' => $sharedUsersValue,\n ],\n [\n 'id' => 'saved_search',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'label' => 'Saved search',\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => $savedSearches,\n 'value' => $report && $report->getSavedSearch() ? [\n 'id' => $report->getSavedSearch()->getUuid(),\n 'name' => $report->getSavedSearch()->getName(),\n ] : null,\n ],\n [\n 'id' => 'ask_jiminny_prompt',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'label' => 'Ask Jiminny prompt',\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => $prompts,\n 'value' => $report && $report->getAskAnythingPrompt() ? [\n 'id' => $report->getAskAnythingPrompt()->getUuid(),\n 'name' => $report->getAskAnythingPrompt()->getTitle(),\n ] : null,\n ],\n ],\n ];\n }\n\n private function updateResultNames(AutomatedReport $automatedReport): void\n {\n $results = $this->automatedReportsRepository->getResultsByReport($automatedReport);\n\n foreach ($results as $result) {\n $result->update(['name' => $this->getReportFileName($result)]);\n }\n }\n\n public function updateStatus(string $uuid, array $data): array\n {\n $automatedReport = $this->automatedReportsRepository->findByUuid($uuid);\n\n if (! $automatedReport) {\n throw new ModelNotFoundException('Report not found');\n }\n\n $status = $this->validateReportStatus($data['report_enabled'] ?? null);\n $automatedReport->update([\n 'status' => $status,\n ]);\n\n $this->generateOneOffReport($automatedReport);\n\n return $this->transformReportFullView($automatedReport);\n }\n\n private function generateOneOffReport(AutomatedReport $automatedReport): void\n {\n // the scheduler handles all the other frequency types\n if ($automatedReport->getStatus() === false || $automatedReport->getFrequency() !== self::FREQUENCY_ONE_OFF) {\n return;\n }\n\n $this->dispatcher->dispatch(new RequestGenerateReportJob($automatedReport->getUuid()));\n }\n\n public function getReport(string $uuid): AutomatedReport\n {\n $automatedReport = $this->automatedReportsRepository->findByUuid($uuid);\n\n if (! $automatedReport) {\n throw new ModelNotFoundException('Report not found');\n }\n\n return $automatedReport;\n }\n\n public function get(string $uuid): array\n {\n $automatedReport = $this->getReport($uuid);\n\n return $this->transformReportFullView($automatedReport);\n }\n\n public function list(string $sortColumn = 'created_at', string $sortDirection = 'desc'): array\n {\n $results = [];\n $collection = $this->automatedReportsRepository->getAllStandardReports($sortColumn, $sortDirection);\n\n /** @var AutomatedReport $report */\n foreach ($collection as $report) {\n $results[] = $this->transformReportFullView($report);\n }\n\n return ['data' => $results];\n }\n\n public function listAskJiminnyReports(\n User $user,\n string $sortColumn = 'created_at',\n string $sortDirection = 'desc'\n ): array {\n $results = [];\n $collection = $this->automatedReportsRepository->getAskJiminnyReportsByUser($user, $sortColumn, $sortDirection);\n\n /** @var AutomatedReport $report */\n foreach ($collection as $report) {\n $results[] = $this->transformReportFullView($report);\n }\n\n return ['data' => $results];\n }\n\n public function delete(string $uuid): void\n {\n $automatedReport = $this->automatedReportsRepository->findByUuid($uuid);\n\n if (! $automatedReport) {\n throw new ModelNotFoundException('Report not found');\n }\n\n $automatedReport->delete();\n }\n\n public function createReportResult(AutomatedReport $automatedReport, array $data = []): AutomatedReportResult\n {\n return $this->automatedReportsRepository->createResult(\n array_merge(\n [\n 'report_id' => $automatedReport->getId(),\n 'status' => AutomatedReportResult::STATUS_DEFAULT,\n ],\n $data\n )\n );\n }\n\n public function getReportResult(string $resultUuid): AutomatedReportResult\n {\n $report = $this->automatedReportsRepository->findResultByUuid($resultUuid);\n\n if (! $report) {\n throw new ModelNotFoundException('Report Result not found');\n }\n\n return $report;\n }\n\n public function findChildResult(AutomatedReportResult $result, string $type): ?AutomatedReportResult\n {\n return $this->automatedReportsRepository->findChildResult($result, $type);\n }\n\n // prophet API calls\n /**\n * @throws ApplicationException\n */\n public function getGenerateReportPayload(AutomatedReport $automatedReport, string $reportResultUuid): array\n {\n $period = $this->calculateFromAndToDate($automatedReport);\n $fromDate = $period['fromDate'];\n $toDate = $period['toDate'];\n\n return [\n 'team_id' => $automatedReport->getTeamId(),\n 'request_id' => $reportResultUuid,\n 'report_type' => $automatedReport->getType(),\n 'media_types' => $automatedReport->getMediaTypes(),\n 'from_date' => $fromDate->startOfDay()->format(DateTimeInterface::RFC3339),\n 'to_date' => $toDate->endOfDay()->format(DateTimeInterface::RFC3339),\n 'group_ids' => $automatedReport->getGroups(),\n 'call_deal_stage' => $automatedReport->getDealAtCallStages(),\n 'current_deal_stage' => $automatedReport->getCurrentDealStages(),\n 'deal_min_value' => $automatedReport->getDealValueMin(),\n 'deal_max_value' => $automatedReport->getDealValueMax(),\n 'call_types' => $automatedReport->getCallTypes(),\n 'call_duration_min_seconds' => $automatedReport->getCallDurationMin(),\n 'call_duration_max_seconds' => $automatedReport->getCallDurationMax(),\n 'special_requirements' => $automatedReport->getAdditionalPromptInput(),\n 'callback_url' => $this->getCallbackUrl(),\n 'report_period' => $this->formatReportPeriodName(\n $automatedReport->getFrequency(),\n $fromDate,\n $toDate,\n ),\n 'playbook_categories' => $automatedReport->getPlaybookCategories(),\n 'custom_name' => $automatedReport->getCustomName(),\n ];\n }\n\n // $inputPayload - FE payload structure\n public function getActivitiesCountPayload(array $inputPayload): array\n {\n // Use validateAndTransformData to validate and normalize input\n $validatedData = $this->validateAndTransformData($inputPayload);\n $period = $this->calculateFromAndToDatePeriod(\n $validatedData['frequency'],\n Carbon::parse($validatedData['from']),\n Carbon::parse($validatedData['to']),\n );\n $fromDate = $period['fromDate'];\n $toDate = $period['toDate'];\n\n // Create payload similar to getGenerateReportPayload\n return [\n 'team_id' => $validatedData['team_id'],\n 'group_ids' => $validatedData['groups'] ?? [],\n 'report_type' => $validatedData['type'],\n 'from_date' => $fromDate->format(DateTimeInterface::RFC3339),\n 'to_date' => $toDate->format(DateTimeInterface::RFC3339),\n 'call_deal_stage' => $validatedData['deal_at_call_stages'] ?? [],\n 'current_deal_stage' => $validatedData['current_deal_stages'] ?? [],\n 'deal_min_value' => $validatedData['deal_value_min'] ?? null,\n 'deal_max_value' => $validatedData['deal_value_max'] ?? null,\n 'call_types' => $validatedData['call_types'],\n 'call_duration_min_seconds' => $validatedData['call_duration_min'] ?? null,\n 'call_duration_max_seconds' => $validatedData['call_duration_max'] ?? null,\n 'special_requirements' => $validatedData['additional_prompt_input'] ?? null,\n 'playbook_categories' => $validatedData['playbook_categories'] ?? [],\n 'request_id' => null,\n 'callback_url' => null,\n ];\n }\n\n public function shouldSendReport(array $users, ?CarbonInterface $generatedAt = null): bool\n {\n if (empty($users)) {\n return false;\n }\n\n $earliestTz = collect($users)\n ->mapWithKeys(function (array $user) {\n $tz = new DateTimeZone($user['timezone']);\n $nowUtc = new DateTime('now', new DateTimeZone('UTC'));\n $offset = $tz->getOffset($nowUtc);\n\n return [$user['timezone'] => $offset];\n })\n ->sortDesc()\n ->keys()\n ->first();\n\n $now = Carbon::now($earliestTz);\n $isScheduledTime = (int) $now->format('H') === self::SENT_REPORT_AT_HOURS;\n\n if ($isScheduledTime) {\n return true;\n }\n\n return $this->hasPassedScheduledTime($generatedAt, $earliestTz);\n }\n\n public function hasPassedScheduledTime(?CarbonInterface $generatedAt, string $timezone): bool\n {\n if ($generatedAt === null) {\n return false;\n }\n\n $now = Carbon::now($timezone);\n $scheduledTime = $now->copy()->setTime(self::SENT_REPORT_AT_HOURS, 0, 0);\n\n if ($now->hour < self::SENT_REPORT_AT_HOURS) {\n $scheduledTime = $scheduledTime->subDay();\n }\n\n $scheduledTimeUtc = $scheduledTime->copy()->utc();\n $generatedAtUtc = $generatedAt->copy()->utc();\n $nowUtc = $now->copy()->utc();\n\n return $generatedAtUtc->lt($scheduledTimeUtc) && $nowUtc->gt($scheduledTimeUtc);\n }\n\n public function calculateFromAndToDatePeriod(\n string $frequency,\n ?Carbon $fromDate = null,\n ?Carbon $toDate = null\n ): array {\n if ($frequency === self::FREQUENCY_ONE_OFF) {\n return [\n 'fromDate' => $fromDate,\n 'toDate' => $toDate,\n ];\n }\n\n $now = Carbon::now();\n\n return match ($frequency) {\n self::FREQUENCY_DAILY => [\n 'fromDate' => $now->copy()->subDay()->startOfDay(),\n 'toDate' => $now->copy()->subDay()->endOfDay(),\n ],\n self::FREQUENCY_WEEKLY => [\n 'fromDate' => $now->copy()->subWeeks(1)->startOfDay(),\n 'toDate' => $now->copy()->subDay()->endOfDay(),\n ],\n self::FREQUENCY_MONTHLY => [\n 'fromDate' => $now->copy()->subMonths(1)->startOfDay(),\n 'toDate' => $now->copy()->subDay()->endOfDay(),\n ],\n self::FREQUENCY_QUARTERLY => [\n 'fromDate' => $now->copy()->subMonths(3)->startOfDay(),\n 'toDate' => $now->copy()->subDay()->endOfDay(),\n ],\n default => throw new InvalidArgumentException(\"Unsupported frequency: {$frequency}\"),\n };\n }\n\n private function calculateFromAndToDate(AutomatedReport $automatedReport): array\n {\n return $this->calculateFromAndToDatePeriod(\n $automatedReport->getFrequency(),\n $automatedReport->getFrom(),\n $automatedReport->getTo()\n );\n }\n\n public function getAskJiminnyGenerateReportPayload(\n AutomatedReport $automatedReport,\n AutomatedReportResult $reportResult,\n array $activityIds,\n ): array {\n return [\n 'user_question' => $automatedReport->getAskAnythingPrompt()?->getContent(),\n 'call_ids' => array_map('strval', $activityIds),\n 'team_id' => $automatedReport->getTeamId(),\n 'request_id' => $reportResult->getUuid(),\n 'callback_url' => $this->getCallbackUrl(),\n 'report_period' => $this->getReportPeriodName($reportResult),\n 'report_name' => $automatedReport->getCustomName(),\n ];\n }\n\n private function getCallbackUrl(): string\n {\n return $this->webhookService->route('jiminny.webhook.reports.ready');\n }\n\n /**\n * Validate and transform payload data for automated reports\n *\n * @param array $data\n *\n * @throws InvalidArgumentException\n *\n * @return array\n */\n private function validateAndTransformData(array $data): array\n {\n // Validate organization (team) and check feature\n $team = $this->validateOrganization($data['organization'] ?? null);\n\n $status = $this->validateReportStatus($data['report_enabled'] ?? null);\n $type = $this->validateReportType($data['report_type'] ?? null);\n $frequency = $this->validateFrequency($data['frequency'] ?? null);\n $additionalPromptInput = $this->validateAdditionalPromptInput(\n $data['additional_prompt_input'] ?? null\n );\n $customReportName = $this->validateCustomReportName($data['custom_name'] ?? null);\n\n // Prepare data for the database\n $reportData = [\n 'team_id' => $team->getId(),\n 'type' => $type,\n 'status' => $status,\n 'frequency' => $frequency,\n 'additional_prompt_input' => $additionalPromptInput,\n 'custom_name' => $customReportName,\n ];\n\n // Validate deal values\n $reportData = $this->validateDealValues($data, $reportData);\n\n // Validate date range\n $reportData = $this->validateDateRange($data, $reportData, $frequency);\n\n // Validate call durations\n $reportData = $this->validateCallDurations($data, $reportData);\n\n // Validate call types\n $reportData = $this->validateCallTypes($data, $reportData);\n\n // Validate media types\n $reportData = $this->validateMediaTypes($data, $reportData);\n\n // Validate groups\n if (isset($data['teams'])) {\n $reportData['groups'] = $this->validateAndGetGroupIds($team, $data['teams']);\n }\n\n // Validate deal stages\n $reportData = $this->validateDealStages($data, $reportData, $team, $type);\n\n // Validate playbook categories\n $reportData = $this->validatePlaybookCategories($data, $reportData, $team);\n\n // Validate recipients\n $reportData['recipients'] = [\n 'users' => $this->validateAndGetUserIdsByTeam($team, $data['recipients'] ?? []),\n ];\n\n if (isset($data['jiminny_recipients'])) {\n // Validate Jiminny recipients\n $reportData['jiminny_recipients'] = [\n 'users' => $this->validateAndGetJiminnyUserIds((array) $data['jiminny_recipients']),\n ];\n }\n\n return $reportData;\n }\n\n private function validateDealValues(array $data, array $reportData): array\n {\n if (isset($data['min_deal_value'])) {\n $reportData['deal_value_min'] = (int) $data['min_deal_value'];\n\n if ($reportData['deal_value_min'] > 4294967295 || $reportData['deal_value_min'] < 0) {\n throw new InvalidArgumentException('Min deal value should be between 0 and 4294967295');\n }\n }\n\n if (isset($data['max_deal_value'])) {\n $reportData['deal_value_max'] = (int) $data['max_deal_value'];\n\n if ($reportData['deal_value_max'] > 4294967295 || $reportData['deal_value_max'] < 0) {\n throw new InvalidArgumentException('Max deal value should be between 0 and 4294967295');\n }\n }\n\n if (isset($data['min_deal_value'], $data['max_deal_value'])\n && $data['min_deal_value'] > $data['max_deal_value']\n ) {\n throw new InvalidArgumentException('Min deal value cannot be greater than max deal value');\n }\n\n return $reportData;\n }\n\n private function validateDateRange(array $data, array $reportData, string $frequency): array\n {\n // Set date range only for one_off frequency\n if ($frequency === 'one_off') {\n if (isset($data['start_date_period'])) {\n $reportData['from'] = $this->parseDate($data['start_date_period']);\n }\n\n if (isset($data['end_date_period'])) {\n $reportData['to'] = $this->parseDate($data['end_date_period']);\n }\n\n if (empty($reportData['from']) || empty($reportData['to'])) {\n throw new InvalidArgumentException(\n 'Start date and end date are required for one_off frequency'\n );\n }\n } else {\n $reportData['from'] = null;\n $reportData['to'] = null;\n }\n\n return $reportData;\n }\n\n private function validateCallDurations(array $data, array $reportData): array\n {\n // Convert call durations from minutes to seconds\n if (isset($data['min_call_duration'])) {\n $reportData['call_duration_min'] = (int) $data['min_call_duration'] * 60;\n\n if ($reportData['call_duration_min'] > 4294967295 || $reportData['call_duration_min'] < 0) {\n throw new InvalidArgumentException('Min call duration should be between 0 and 4294967295');\n }\n }\n\n if (isset($data['max_call_duration'])) {\n $reportData['call_duration_max'] = (int) $data['max_call_duration'] * 60;\n\n if ($reportData['call_duration_max'] > 4294967295 || $reportData['call_duration_max'] < 0) {\n throw new InvalidArgumentException('Max call duration should be between 0 and 4294967295');\n }\n }\n\n return $reportData;\n }\n\n private function validateCallTypes(array $data, array $reportData): array\n {\n // Set call types\n $reportData['call_types'] = $data['call_type'] ?? [];\n if (empty($reportData['call_types'])) {\n $reportData['call_types'] = self::getCallTypes();\n }\n\n foreach ($reportData['call_types'] as $callType) {\n if (! in_array($callType, self::getCallTypes(), true)) {\n throw new InvalidArgumentException(sprintf('Call type %s is invalid', $callType));\n }\n }\n\n return $reportData;\n }\n\n private function validateMediaTypes(array $data, array $reportData): array\n {\n // Set media types from input data\n $reportData['media_types'] = $data['media_types'] ?? [];\n\n if (empty($reportData['media_types'])) {\n throw new InvalidArgumentException('Media types are required');\n }\n\n foreach ($reportData['media_types'] as $mediaType) {\n if (! in_array($mediaType, self::MEDIA_TYPES, true)) {\n throw new InvalidArgumentException(sprintf('Media type %s is invalid', $mediaType));\n }\n }\n\n return $reportData;\n }\n\n private function validateDealStages(array $data, array $reportData, Team $team, string $reportType): array\n {\n // Validate and set deal stages\n if (isset($data['deal_stage_at_call'])) {\n $reportData['deal_at_call_stages'] =\n $this->validateAndGetDealStageIds($team, $data['deal_stage_at_call'], 'Deal stage at call');\n }\n\n if (isset($data['current_deal_stage'])) {\n $reportData['current_deal_stages'] =\n $this->validateAndGetDealStageIds($team, $data['current_deal_stage'], 'Current deal stage');\n }\n\n // Ensure current_deal_stage is not provided for loss_analysis report type\n if ($reportType === self::TYPE_LOSS_ANALYSIS && ! empty($data['current_deal_stage'])) {\n throw new InvalidArgumentException('Current deal stage is not applicable for Loss Analysis reports');\n }\n\n return $reportData;\n }\n\n // transform uuid to id\n private function validatePlaybookCategories(array $data, array $reportData, Team $team): array\n {\n $key = 'playbook_categories';\n\n if (isset($data[$key])) {\n $payloadIds = $data[$key];\n $ids = [];\n\n foreach ($payloadIds as $uuid) {\n $uuid = (string) $uuid;\n\n try {\n $playbookCategory = $this->playbookCategoryRepository->findByUuid($uuid);\n } catch (Throwable $throwable) {\n Log::error(__METHOD__ . ' ' . $throwable->getMessage());\n\n throw new InvalidArgumentException(sprintf('Playbook category %s not found', $uuid));\n }\n\n if (! $playbookCategory) {\n throw new InvalidArgumentException(sprintf('Playbook category %s not found', $uuid));\n }\n\n if (! $playbookCategory->hasPlaybook()) {\n throw new InvalidArgumentException(sprintf('Playbook category %s has no playbook', $uuid));\n }\n\n if ($playbookCategory->getPlaybook()->getTeamId() !== $team->getId()) {\n throw new InvalidArgumentException(\n sprintf('Playbook category %s not found for team %s', $uuid, $team->getUuid())\n );\n }\n\n $ids[] = $playbookCategory->getId();\n }\n\n $reportData[$key] = $ids;\n }\n\n return $reportData;\n }\n\n private function validateReportStatus($status): bool\n {\n if (! in_array($status, [true, false], true)) {\n throw new InvalidArgumentException('Report status is invalid');\n }\n\n return $status;\n }\n\n private function validateReportType($type): string\n {\n if (! in_array($type, self::getTypes(), true)) {\n throw new InvalidArgumentException(sprintf('Report type is invalid: %s', $type));\n }\n\n return $type;\n }\n\n private function validateFrequency($frequency): string\n {\n if (! in_array($frequency, self::getFrequencies(), true)) {\n throw new InvalidArgumentException('Frequency is invalid');\n }\n\n return $frequency;\n }\n\n private function validateAdditionalPromptInput(?string $additionalPromptInput): ?string\n {\n if ($additionalPromptInput && strlen($additionalPromptInput) > 5000) {\n throw new InvalidArgumentException('Additional Prompt Input should be less than 5000 characters');\n }\n\n return $additionalPromptInput;\n }\n\n private function validateCustomReportName(?string $customReportName): ?string\n {\n if ($customReportName === null || $customReportName === '') {\n return null;\n }\n\n if (strlen($customReportName) > 70) {\n throw new InvalidArgumentException('Custom report name should be less than 70 characters');\n }\n\n return $customReportName;\n }\n\n private function validateOrganization(?string $organizationUuid): Team\n {\n if (! $organizationUuid) {\n throw new InvalidArgumentException('Organization is required');\n }\n\n $team = $this->teamRepository->idOrUuid($organizationUuid);\n\n if (! $team) {\n throw new InvalidArgumentException('Organization not found');\n }\n\n if (! $team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {\n throw new InvalidArgumentException('Organization does not have the Automated Reports feature');\n }\n\n return $team;\n }\n\n private function validateAndGetGroupIds(Team $team, array $teamUuids): array\n {\n $groupIds = [];\n\n foreach ($teamUuids as $uuid) {\n $group = $this->groupRepository->findByUuid($uuid);\n\n if ($group === null || $group->getTeamId() !== $team->getId()) {\n throw new InvalidArgumentException(\n sprintf('Group %s not found for team %s', $uuid, $team->getUuid())\n );\n }\n\n $groupIds[] = $group->getId();\n\n }\n\n return $groupIds;\n }\n\n private function validateAndGetDealStageIds(Team $team, array $stageUuids, string $propertyLabel): array\n {\n $stageIds = [];\n\n foreach ($stageUuids as $uuid) {\n $stage = $this->stageRepository->findByUuid($uuid);\n\n if ($stage === null || $stage->getTeamId() !== $team->getId()) {\n throw new InvalidArgumentException(\n sprintf('Stage %s not found for team %s for %s', $uuid, $team->getUuid(), $propertyLabel)\n );\n }\n\n $stageIds[] = $stage->getId();\n }\n\n return $stageIds;\n }\n\n private function validateAndGetUserIds(array $userUuids, callable $teamCheck): array\n {\n if (empty($userUuids)) {\n return [];\n }\n\n $userIds = [];\n\n foreach ($userUuids as $uuid) {\n $user = $this->userRepository->findByUuid($uuid);\n\n if (! $user || ! $user->isStatusActive()) {\n throw new InvalidArgumentException(\n sprintf('User %s not found or is not active', $uuid)\n );\n }\n\n if (! $teamCheck($user)) {\n throw new InvalidArgumentException(\n sprintf('User %s does not belong to the allowed team(s)', $uuid)\n );\n }\n\n $userIds[] = $user->getId();\n }\n\n return $userIds;\n }\n\n private function validateAndGetUserIdsByTeam(Team $team, array $userUuids): array\n {\n return $this->validateAndGetUserIds($userUuids, fn ($user) => $user->getTeamId() === $team->getId());\n }\n\n private function validateAndGetJiminnyUserIds(array $userUuids): array\n {\n $allowedTeamIds = config('kiosk.teamIds', []);\n\n return $this->validateAndGetUserIds($userUuids, fn ($user) => in_array($user->getTeamId(), $allowedTeamIds, true));\n }\n\n private function parseDate(string $dateString): string\n {\n return date('Y-m-d H:i:s', strtotime($dateString));\n }\n\n private function generateReportResultViewUrl(AutomatedReportResult $result): string\n {\n $mediaResource = $this->getReportMediaRouteResource($result);\n\n return route('ai-reports.' . $mediaResource . '.view', ['uuid' => $result->getUuid()]);\n }\n\n private function generateReportResultDownloadUrl(AutomatedReportResult $result): string\n {\n $mediaResource = $this->getReportMediaRouteResource($result);\n\n return route('ai-reports.' . $mediaResource . '.download', ['uuid' => $result->getUuid()]);\n }\n\n private function getReportMediaRouteResource(AutomatedReportResult $result): string\n {\n if ($result->getMediaType() === self::MEDIA_TYPE_PDF) {\n return self::PDF_KEY;\n } elseif ($result->getMediaType() === self::MEDIA_TYPE_PODCAST) {\n return self::AUDIO_KEY;\n }\n\n throw new \\InvalidArgumentException('Unknown media type.');\n }\n\n public function getMediaPath(AutomatedReportResult $result): ?string\n {\n $url = match ($result->getMediaType()) {\n self::MEDIA_TYPE_PDF => $result->getPdfUrl(),\n self::MEDIA_TYPE_PODCAST => $result->getPodcastAudioUrl(),\n default => null,\n };\n\n if ($url === null) {\n return null;\n }\n\n $path = parse_url(trim($url, '\"\\''), PHP_URL_PATH);\n\n return $path ?: null;\n }\n\n public function getFilenameSuffix(AutomatedReportResult $result): ?string\n {\n return match ($result->getMediaType()) {\n self::MEDIA_TYPE_PODCAST => 'Podcast',\n default => null,\n };\n }\n\n public function getMailSubjectSuffix(AutomatedReportResult $result): string\n {\n return match ($result->getMediaType()) {\n self::MEDIA_TYPE_PDF => 'report',\n self::MEDIA_TYPE_PODCAST => 'podcast',\n default => '',\n };\n }\n\n public function getMediaTypeMetadata(AutomatedReportResult $result): array\n {\n return match ($result->getMediaType()) {\n self::MEDIA_TYPE_PODCAST => ['extension' => 'mp3', 'mime' => 'audio/mpeg'],\n self::MEDIA_TYPE_PDF => ['extension' => 'pdf', 'mime' => 'application/pdf'],\n default => ['extension' => null, 'mime' => null],\n };\n }\n\n public function deleteS3Files(AutomatedReportResult $result): void\n {\n $teamUuid = $result->getReport()->getTeam()->getUuid();\n $reportUuid = $result->getUuid();\n\n // delete all files for a report uuid no mather of pdf, podcast, or both\n // in case of both - the podcast files are linked to the pdf (parent) uuid\n // pdf and podcast date times should be close\n $path = sprintf('%s/%s/%s', $teamUuid, self::S3_DIR, $reportUuid);\n\n foreach (self::FILE_EXTENSIONS_VARIANTS as $extension) {\n $file = $path . '.' . $extension;\n\n if (Storage::exists($file)) {\n Storage::delete($file);\n Log::info('[Reports] Deleted S3 file', [\n 'path' => $file,\n ]);\n }\n }\n\n foreach (self::FILE_PODCAST_EXTENSIONS_VARIANTS as $extension) {\n $file = $path . '_podcast.' . $extension;\n\n if (Storage::exists($file)) {\n Storage::delete($file);\n Log::info('[Reports] Deleted Podcast S3 file', [\n 'path' => $file,\n ]);\n }\n }\n }\n\n /**\n *\n * @param int|null $teamId Optional team ID to filter results\n *\n * @return Collection<int, int> Collection of team IDs\n */\n public function getTeamIdsWithReportsResults(?int $teamId = null): Collection\n {\n return $this->automatedReportsRepository->getTeamIdsWithReportsResults($teamId);\n }\n\n /**\n * Core delete logic for report results using a query\n *\n * @param Builder $query\n * @param array $logContext\n *\n * @return int\n */\n private function deleteReportResultsByQuery(Builder $query, array $logContext = []): int\n {\n $deletedCount = 0;\n\n if ($query->exists()) {\n Log::info(\n 'Run delete report results',\n array_merge(\n $logContext,\n [\n 'service' => 'AutomatedReportsService',\n ]\n )\n );\n\n $query->chunkById(50, function ($results) use (&$deletedCount, $logContext) {\n foreach ($results as $result) {\n $this->deleteReportResult($result);\n $deletedCount++;\n\n Log::info(\n 'Deleted a report result',\n array_merge(\n $logContext,\n [\n 'result_id' => $result->getId(),\n 'report_id' => $result->getReportId(),\n ]\n )\n );\n }\n });\n }\n\n return $deletedCount;\n }\n\n /**\n * Delete report results for a team by retention period\n *\n * @param Team $team\n * @param CarbonImmutable $retentionDate\n *\n * @return int Number of deleted report results\n */\n public function deleteReportsResultsInRetentionPeriod(Team $team, CarbonImmutable $retentionDate): int\n {\n $reportIds = $this->automatedReportsRepository->getReportIdsByTeam($team);\n\n if ($reportIds->isEmpty()) {\n return 0;\n }\n\n $query = $this->automatedReportsRepository\n ->getReportResultsQueryForRetention($team, $retentionDate);\n\n return $this->deleteReportResultsByQuery($query, [\n 'team_id' => $team->getId(),\n 'retention_date' => $retentionDate->toDateTimeString(),\n ]);\n }\n\n /**\n * Delete ALL report results for a specific automated report\n *\n * @param string $uuid\n *\n * @return int\n */\n public function deleteReportResults(string $uuid): int\n {\n $report = $this->getReport($uuid);\n\n $query = $this->automatedReportsRepository->getResultsByReportQuery($report);\n\n return $this->deleteReportResultsByQuery($query, [\n 'report_uuid' => $uuid,\n 'report_id' => $report->getId(),\n ]);\n }\n\n public function deleteReportResult(AutomatedReportResult $result): void\n {\n $this->deleteS3Files($result);\n\n $result->delete();\n }\n\n /**\n * Get all reports for a specific team\n *\n * @param Team $team\n *\n * @return \\Illuminate\\Database\\Eloquent\\Collection\n */\n public function getTeamReports(Team $team): \\Illuminate\\Database\\Eloquent\\Collection\n {\n return $this->automatedReportsRepository->getReportsByTeam($team);\n }\n\n /**\n * Get all report results for a specific report\n *\n * @param AutomatedReport $report\n *\n * @return \\Illuminate\\Database\\Eloquent\\Collection\n */\n public function getReportResults(AutomatedReport $report): \\Illuminate\\Database\\Eloquent\\Collection\n {\n return $this->automatedReportsRepository->getResultsByReport($report);\n }\n\n public function deleteAllReportResults(AutomatedReport $report): void\n {\n $results = $this->getReportResults($report);\n\n /** @var AutomatedReportResult $result */\n foreach ($results as $result) {\n Log::info('Deleting result', [\n 'report' => $report->getId(),\n 'result' => $result->getId(),\n ]);\n\n $this->deleteReportResult($result);\n }\n }\n\n public function deleteAllData(Team $team): void\n {\n Log::info('Deleting automated report and results for team', [\n 'team' => $team->getId(),\n ]);\n\n $reports = $this->getTeamReports($team);\n\n /** @var AutomatedReport $report */\n foreach ($reports as $report) {\n Log::info('Deleting report', [\n 'team' => $team->getId(),\n 'report' => $report->getId(),\n ]);\n\n $this->deleteAllReportResults($report);\n\n $report->delete();\n }\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":true,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"Project","depth":3,"role_description":"text"},{"role":"AXButton","text":"Project","depth":3,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"New File or Directory…","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Expand Selected","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Collapse All","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Options","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false}]...
|
3397592283435315795
|
6686367547760219213
|
idle
|
accessibility
|
NULL
|
Project: faVsco.js, menu
#11894 on JY-18909-automa Project: faVsco.js, menu
#11894 on JY-18909-automated-reports-ask-jiminny, menu
Start Listening for PHP Debug Connections
AutomatedReportsCommandTest
Run 'AutomatedReportsCommandTest'
Debug 'AutomatedReportsCommandTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Execute
Explain Plan
Browse Query History
View Parameters
Open Query Execution Settings…
In-Editor Results
Tx: Auto
Cancel Running Statements
Playground
jiminny
Sync Changes
Hide This Notification
Code changed:
Hide
16
13
13
Previous Highlighted Error
Next Highlighted Error
SELECT * FROM teams WHERE id = 1;
select * from crm_layouts where crm_configuration_id = 39;
SELECT * FROM crm_layout_entities WHERE crm_layout_id = 283;
SELECT * FROM crm_fields WHERE id = 2234;
SELECT * FROM crm_field_values WHERE crm_field_id = 2234;
select * from crm_profiles where user_id = 143;
select * from record_types where crm_configuration_id = 39; # 0121K000001MHElQAO,0121K000001MHEqQAO
select * from business_processes where crm_configuration_id = 39;
# 01941000000H669AAC, 01941000000H66JAAS
select * from record_type_field_values
where record_type_id IN (24);
select * from crm_field_values where id IN (2730);
select * from crm_configurations where id = 39;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 1
and sa.provider = 'salesforce'; #1035
select * from users where team_id = 1; # 222 group 3
SELECT * FROM activities WHERE user_id = 222 order by id desc;
select * from sidekick_settings where team_id = 1;
select * from teams where id = 1;
select * from team_features where team_id = 1;
select * from activities where crm_configuration_id = 2
and provider = 'ms-teams' and id = 608765;
SELECT * FROM activities WHERE crm_configuration_id = 2 and crm_provider_id = '59523413338';
select * from sidekick_settings where team_id = 2;
SELECT * FROM activities WHERE id = 608660;
select * from activity_summary_logs where activity_id = 608660;
select * from ai_prompts where transcription_id = 11214;
# [PASSWORD_DOTS]
SELECT * FROM activities WHERE uuid_to_bin('ed78a437-2804-450e-ab2f-56ab1c641346') = uuid;
# id: 608818, crm: 59628809737
SELECT * FROM activities WHERE uuid_to_bin('36b06e55-afdd-4782-8dee-c624cd0af191') = uuid;
# id: 608821, crm: 59632069252
SELECT ce.start_time, ce.end_time, a.id, a.uuid, crm_provider_id, calendar_event_id, title,
playbook_category_id, user_id, lead_id, contact_id, account_id, opportunity_id,
scheduled_start_time, scheduled_end_time, actual_start_time, actual_end_time, a.created_at
FROM activities a
join calendar_events ce on a.calendar_event_id = ce.id
WHERE a.id IN (608818, 608821);
select * from users where team_id = 1;
select * from team_settings where team_id = 1;
select * from crm_profiles where crm_configuration_id = 39 order by user_id;
select * from team_features where team_id = 1;
select * from users where team_id = 2;
SELECT * FROM activities WHERE uuid_to_bin('ec7647e9-5225-458b-b475-f31aa2769204') = uuid; # 612639
# Preslava N. Ivanova, grou id 3
SELECT * FROM opportunities WHERE uuid_to_bin('a2928fe5-aec5-46cb-85d9-7654c89e46a6') = uuid;
select * from activities where opportunity_id = 344 and actual_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00';
select
a.id,
a.type,
a.scheduled_start_time,
a.actual_start_time,
a.created_at,
a.opportunity_id,
a.status
FROM activities a
WHERE opportunity_id = 344
and status IN ('completed', 'received', 'delivered')
and (
(a.actual_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00')
OR (a.created_at between '2024-10-11 00:00:00' and '2024-10-12 00:00:00')
OR (a.scheduled_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00'))
;
SELECT * FROM users WHERE id = 222;
SELECT * FROM crm_profiles WHERE user_id = 222;
select * from crm_layouts where crm_configuration_id = 39;
SELECT * FROM crm_layout_entities WHERE crm_layout_id = 281;
select * from group_deal_risk_types;
select * from opportunities where team_id = 1;
SELECT * FROM opportunities WHERE id = 315;
SELECT * FROM crm_field_data WHERE object_id = 315;
select * from crm_field_data where object_id = 260;
select * from generic_ai_prompts where subject_id = 315;
select * from teams; # 36, 21, 121, [EMAIL]
SELECT * FROM social_accounts WHERE sociable_id = 121 and provider = 'bullhorn';
# [PASSWORD_DOTS]
select * from teams where id = 1;
select * from crm_configurations where id = 39;
select * from users where team_id = 1;
select u.email, cp.* from users u
join crm_profiles cp on u.id = cp.user_id
where u.team_id = 1;
# 1 - 00541000004281rAAA
# 204 - 0052g000003freeAAA
# 429 - 0052g000003qGOiAAM
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 1
and sa.provider = 'salesforce';
select * from activities where type = 'softphone'
and created_at > '2024-12-11 15:24:36' order by id desc;
select * from activity_providers where team_id = 1;
select * from activity_provider_users where activity_provider_id = 328;
select * from opportunities where crm_configuration_id = 39
AND account_id = 178 AND is_closed = false
order by created_at DESC;
select * from contacts where id = 3952;
select * from accounts where id = 178;
# [PASSWORD_DOTS]
select * from teams where id = 36;
select * from crm_configurations where id = 21;
select * from users where team_id = 36;
select u.email, cp.* from users u
join crm_profiles cp on u.id = cp.user_id
where u.team_id = 36;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 36
and sa.provider = 'bullhorn';
select * from social_accounts where id = 348;
UPDATE social_accounts SET
provider_user_token = '21442_6802599_91:41179a58-21e7-4d7c-ad58-56bb666b2f65',
provider_refresh_token = '21442_6802599_91:01c6b335-3f2a-42e4-85ff-8a08fa65fceb',
expires = 1733998131,
state = 'connected'
WHERE id = 348;
# [PASSWORD_DOTS]
select * from teams where id = 31;
select * from crm_configurations where id = 18;
select * from users where team_id = 31; # 257
select u.email, cp.* from users u
join crm_profiles cp on u.id = cp.user_id
where u.team_id = 31;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 31
and sa.provider = 'close';
select * from contacts where crm_configuration_id = 18;
# [PASSWORD_DOTS] NEPTUNE [PASSWORD_DOTS]
select * from teams;
select * from users where id IN (1030, 1035, 1052);
select * from crm_configurations;
select * from users where team_id = 65; # 257
select * from team_settings where team_id = 65; # 257
select * from invitations where team_id = 65; # 257
select * from users where email = '[EMAIL]'; # 257
select u.email, cp.* from users u
join crm_profiles cp on u.id = cp.user_id
where u.team_id = 65;
select * from crm_configurations where id = 53;
select * from accounts where crm_configuration_id = 53 order by id desc;
select * from leads where crm_configuration_id = 53 order by id desc;
select * from contacts where crm_configuration_id = 53 order by id desc;
select * from opportunities where crm_configuration_id = 53 order by id desc;
select * from crm_profiles where crm_configuration_id = 53 order by id desc;
select * from crm_fields where crm_configuration_id = 53 order by id desc;
select * from crm_field_values where crm_field_id = 3341 order by id desc;
select * from crm_layouts where crm_configuration_id = 53 order by id desc;
select * from stages where crm_configuration_id = 53 order by id desc;
select * from crm_profiles where crm_configuration_id = 13;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 65
and sa.provider = 'integration-app';
select * from contacts where crm_configuration_id = 13;
select * from social_accounts where sociable_id = 283;
SELECT * FROM opportunities WHERE crm_provider_id = '006O400000E9bzeIAB';
select * from activity_providers where team_id = 65;
SELECT * FROM activities WHERE crm_configuration_id IN (51, 52, 53);
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 65
;
# [PASSWORD_DOTS] STAGING [PASSWORD_DOTS]
SELECT * FROM teams;
SELECT * FROM teams WHERE id = 88;
SELECT * FROM teams WHERE id = 89;
select * from team_settings where team_id = 89;
SELECT * FROM users WHERE team_id = 89;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 89;
select * from users;
SELECT * FROM social_accounts WHERE sociable_id = 1761;
SELECT * FROM crm_configurations WHERE id = 70;
select * from accounts where crm_configuration_id = 70 order by id desc;
select * from leads where crm_configuration_id = 70 order by id desc;
select * from contacts where crm_configuration_id = 70 order by id desc;
select * from opportunities where crm_configuration_id = 70 order by id desc;
select * from crm_profiles where crm_configuration_id = 70 order by id desc;
select * from crm_fields where crm_configuration_id = 70 order by id desc;
select * from crm_field_values where crm_field_id = 3536 order by id desc;
select * from crm_layouts where crm_configuration_id = 70 order by id desc;
select * from stages where crm_configuration_id = 70 order by id desc;
select * from business_processes where crm_configuration_id = 70 order by id desc;
select * from business_process_stages where business_process_id = 34;
select * from contacts where id = 10468;
select * from crm_layouts where crm_configuration_id = 70;
SELECT * FROM crm_layout_entities WHERE crm_layout_id = 388;
SELECT * FROM crm_fields WHERE id IN (3533,3534,3535);
select * from activities where crm_configuration_id = 70
and (account_id IS NOT NULL or lead_id IS NOT NULL or contact_id IS NOT NULL or opportunity_id IS NOT NULL) order by id desc;
SELECT * FROM activities WHERE uuid_to_bin('2e10b60f-8a61-41c5-a3d4-28835353dc65') = uuid;
SELECT * FROM activities where crm_configuration_id = 69 ;
SELECT * FROM users WHERE email LIKE '%[EMAIL]%';
SELECT * FROM activities WHERE uuid_to_bin('5a150c93-40fc-42ec-b3bd-c1d328e09f6e') = uuid;
SELECT * FROM opportunities WHERE id = 385;
select * from participants p
join activities a on p.activity_id = a.id
where a.crm_configuration_id = 70
and (p.lead_id IS NOT NULL or p.contact_id IS NOT NULL);
SELECT * FROM participants WHERE id = 1013638;
select * from teams where id = 90;
select * from users where team_id = 90;
select * from social_accounts where social_accounts.sociable_id IN (1960,1760);
SELECT * FROM crm_profiles WHERE crm_configuration_id = 71;
select * from invitations where team_id = 90;
select * from crm_configurations where id = 71;
select * from accounts where crm_configuration_id = 71 order by id desc;
select * from leads where crm_configuration_id = 71 order by id desc;
select * from contacts where crm_configuration_id = 71 order by id desc;
select * from opportunities where crm_configuration_id = 71 order by id desc;
select * from crm_profiles where crm_configuration_id = 71 order by id desc;
select * from crm_fields where crm_configuration_id = 71 order by id desc;
select * from crm_field_values where crm_field_id = 3341 order by id desc;
select * from crm_layouts where crm_configuration_id = 71 order by id desc;
select * from stages where crm_configuration_id = 71 order by id desc;
select * from users order by secondary_email desc;
select u.id, u.email, u.status, sa.id, sa.provider_user_id from social_accounts sa
join users u on sa.sociable_id = u.id
where sa.provider = 'google' and u.email LIKE 'aneliya%';
select * from failed_jobs order by id desc;
select * from users where email = '[EMAIL]' or secondary_email = '[EMAIL]';
select * from teams;
SELECT * FROM crm_profiles WHERE crm_configuration_id = 39;
SELECT * FROM crm_fields WHERE crm_configuration_id = 39 and object_type = 'task';
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 1
and sa.provider = 'salesforce';
# [PASSWORD_DOTS]
SELECT * FROM activities WHERE uuid_to_bin('c38b3895-fd0f-4b1f-9fb2-c170dba137c6') = uuid;
SELECT * FROM crm_configurations WHERE id = 70;
select * from teams where id = 1;
select * from groups where team_id = 1;
select * from users where team_id = 1;
select o.id, o.name,o.close_date, u.id, u.name, u.group_id, r.id, r.display_name, g.name, g.scope from opportunities o
join users u on o.user_id = u.id
join groups g on u.group_id = g.id
join role_user ru on u.id = ru.user_id
join roles r on ru.role_id = r.id
where o.crm_configuration_id = 39 and close_date > '2024-01-01 00:00:00';
select * from role_user where user_id = 143;
select * from roles;
select * from role_user;
select * from groups where id = 9;
select * from scope_groups where group_id = 9;
# [PASSWORD_DOTS]
select * from teams where id = 36;
select * from crm_configurations;
SELECT * FROM social_accounts WHERE sociable_id = 121;
[URL_WITH_CREDENTIALS] this will add filter, however if we need to control feature by FF we need conditional logic
public const array TYPES = [
['id' => 'exec_summary', 'name' => 'Exec Summary'],
['id' => 'coaching_profiles', 'name' => 'Coaching Profiles'],
['id' => 'product_feedback', 'name' => 'Product Feedback'],
['id' => self::TYPE_LOSS_ANALYSIS, 'name' => 'Loss Analysis'],
// ['id' => 'questions', 'name' => 'Questions'],
// ['id' => 'statistical_quant', 'name' => 'Statistical Quantitative'],
];
public const array ALL_TYPES = [
...self::TYPES,
['id' => self::TYPE_ASK_JIMINNY, 'name' => 'Ask Jiminny'],
];
public const string FREQUENCY_DAILY = 'daily';
public const string FREQUENCY_WEEKLY = 'weekly';
public const string FREQUENCY_MONTHLY = 'monthly';
public const string FREQUENCY_QUARTERLY = 'quarterly';
public const string FREQUENCY_ONE_OFF = 'one_off';
/**
* Frequencies for standard (non-Ask Jiminny) reports.
*/
public const array FREQUENCIES = [
['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],
['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],
['id' => self::FREQUENCY_QUARTERLY, 'name' => 'Quarterly'],
['id' => self::FREQUENCY_ONE_OFF, 'name' => 'One-off'],
];
/**
* Frequencies for Ask Jiminny reports.
*/
public const array ASK_JIMINNY_FREQUENCIES = [
['id' => self::FREQUENCY_DAILY, 'name' => 'Daily'],
['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],
['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],
];
public const string MEDIA_TYPE_PDF = 'pdf';
public const string MEDIA_TYPE_PODCAST = 'podcast';
public const array MEDIA_TYPES = [self::MEDIA_TYPE_PDF, self::MEDIA_TYPE_PODCAST];
public const array MEDIA_TYPE_OBJECT_PDF = ['id' => self::MEDIA_TYPE_PDF, 'name' => 'PDF'];
public const array MEDIA_TYPE_OBJECT_PODCAST = ['id' => self::MEDIA_TYPE_PODCAST, 'name' => 'Podcast'];
public const array MEDIA_TYPE_OBJECTS = [self::MEDIA_TYPE_OBJECT_PDF, self::MEDIA_TYPE_OBJECT_PODCAST];
public const array CALL_TYPE_CONFERENCE = ['id' => 'conference', 'name' => 'Conference'];
public const array CALL_TYPE_DIALER = ['id' => 'dialer', 'name' => 'Dialer'];
public const int SENT_REPORT_AT_HOURS = 5;
public const string PDF_KEY = 'pdf';
public const string AUDIO_KEY = 'audio';
private const array ALL_FREQUENCIES = [
['id' => self::FREQUENCY_DAILY, 'name' => 'Daily'],
['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],
['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],
['id' => self::FREQUENCY_QUARTERLY, 'name' => 'Quarterly'],
['id' => self::FREQUENCY_ONE_OFF, 'name' => 'One-off'],
];
private const string S3_DIR = 'reports';
private const array FILE_EXTENSIONS_VARIANTS = ['html', 'MD', 'pdf'];
private const array FILE_PODCAST_EXTENSIONS_VARIANTS = ['json', 'mp3', 'ssml'];
public function __construct(
private readonly TeamRepository $teamRepository,
private readonly GroupRepository $groupRepository,
private readonly UserRepository $userRepository,
private readonly StageRepository $stageRepository,
private readonly DealStagesService $dealStagesService,
private readonly RecipientsService $recipientsService,
private readonly AutomatedReportsRepository $automatedReportsRepository,
private readonly Webhook $webhookService,
private readonly BusDispatcher $dispatcher,
private readonly ActivityTypeService $activityTypeService,
private readonly PlaybookCategoryRepository $playbookCategoryRepository,
private readonly AskAnythingPromptService $askAnythingPromptService,
private readonly SearchRepository $activitySearchRepository,
private readonly AskAnythingRepository $askAnythingRepository,
) {
}
public static function getTypes(): array
{
$types = self::TYPES;
return array_map(static function ($type) {
return $type['id'];
}, $types);
}
public static function getCallTypes(): array
{
return array_map(static function ($callType) {
return $callType['id'];
}, [self::CALL_TYPE_CONFERENCE, self::CALL_TYPE_DIALER]);
}
public static function getFrequencies(): array
{
return array_map(static function ($frequency) {
return $frequency['id'];
}, self::FREQUENCIES);
}
// front-facing structure
public function getReportEnabledFieldData(bool $value = false): array
{
return [
'id' => 'report_enabled',
'label' => '',
'inputType' => InputTypeEnum::TOGGLE,
'value' => $value,
];
}
// Organizations = Teams
public function getOrganizationFieldData(?string $value = null, bool $shortVersion = false): array
{
$options = $this->getTeams();
if ($shortVersion) {
return [
'id' => 'organization',
'label' => 'Organization',
'options' => $options,
];
}
return [
'id' => 'organization',
'label' => 'Organization',
'inputType' => InputTypeEnum::DROPDOWN,
'required' => true,
'placeholder' => 'Select',
'options' => $options,
'value' => $value,
'dependencies' => [
'teams',
'deal_stage_at_call',
'current_deal_stage',
'recipients',
ActivityTypeService::PLAYBOOK_CATEGORIES_KEY,
],
'dependsOn' => [],
];
}
// Teams = Groups
public function getTeamFieldData(array $options = [], array $value = [], bool $shortVersion = false): array
{
if ($shortVersion) {
return [
'id' => 'teams',
'label' => 'Team',
'options' => $options,
];
}
return [
'id' => 'teams',
'label' => 'Team',
'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,
'required' => false,
'placeholder' => 'Select',
'options' => $options,
'value' => $value, // value should be an array of objects {id, name}
'dependencies' => [ActivityTypeService::PLAYBOOK_CATEGORIES_KEY],
'dependsOn' => [],
];
}
public function getReportTypeFieldData(?string $value = null, bool $shortVersion = false, ?Team $team = null): array
{
$types = [];
if ($team instanceof Team) {
if ($team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {
$types = self::TYPES;
}
if ($team->hasFeature(FeatureEnum::ASK_JIMINNY_REPORTS)) {
$types[] = ['id' => self::TYPE_ASK_JIMINNY, 'name' => 'Ask Jiminny'];
}
} else {
$types = self::TYPES;
}
if ($shortVersion) {
return [
'id' => 'report_type',
'label' => 'Report Type',
'options' => $types,
];
}
return [
'id' => 'report_type',
'label' => 'Report Type',
'inputType' => InputTypeEnum::DROPDOWN,
'required' => true,
'placeholder' => 'Select',
'options' => $types,
'value' => $value,
'dependencies' => [],
'dependsOn' => [],
];
}
public function getFrequencyFieldData(?string $value = null): array
{
return [
'id' => 'frequency',
'label' => 'Frequency',
'inputType' => InputTypeEnum::DROPDOWN,
'required' => true,
'placeholder' => 'Select',
'options' => self::FREQUENCIES,
'value' => $value,
'dependencies' => ['period'],
'dependsOn' => [],
];
}
public function getPeriodFieldData(?string $valueStartDate = null, ?string $valueEndDate = null): array
{
return [
'id' => 'period',
'label' => 'Select one-off period',
'inputType' => InputTypeEnum::DATE_RANGE,
'required' => true,
'placeholder' => 'Select',
'value' => ['startDate' => $valueStartDate, 'endDate' => $valueEndDate],
'queryParams' => [
'startDate' => 'start_date_period',
'endDate' => 'end_date_period',
],
'dependencies' => [],
'dependsOn' => ['frequency'],
];
}
public function getActivityTypesFieldData(?Team $team = null, array $value = [], array $teamsFilter = []): array
{
return $this->activityTypeService->getActivityTypeFieldData(team: $team, value: $value, groupIds: $teamsFilter);
}
public function getDealStageAtCallFieldData(?Team $team = null, array $value = []): array
{
return $this->dealStagesService->getDealStageAtCallFieldData(team: $team, value: $value);
}
public function getCurrentDealStageFieldData(?Team $team = null, array $value = []): array
{
return $this->dealStagesService->getCurrentDealStageFieldData(team: $team, value: $value);
}
public function getDealValueFieldData(?int $valueMin = null, ?int $valueMax = null): array
{
return [
'id' => 'deal_value',
'label' => 'Deal Value',
'inputType' => InputTypeEnum::INTEGER_RANGE,
'required' => false,
'value' => ['min' => $valueMin, 'max' => $valueMax],
'queryParams' => [
'min' => 'min_deal_value',
'max' => 'max_deal_value',
],
'dependencies' => [],
'dependsOn' => [],
];
}
public function getCallTypeFieldData(bool $conferenceOn = false, bool $dialerOn = false): array
{
$value = [];
$conferenceOn && $value[] = self::CALL_TYPE_CONFERENCE;
$dialerOn && $value[] = self::CALL_TYPE_DIALER;
return [
'id' => 'call_type',
'label' => 'Call Type',
'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,
'required' => true,
'options' => [
self::CALL_TYPE_CONFERENCE,
self::CALL_TYPE_DIALER,
],
'value' => $value,
'dependencies' => [],
'dependsOn' => [],
];
}
public function getMediaTypeFieldData(?AutomatedReport $report = null): array
{
$value = [];
if ($report) {
$value = $this->transformMediaTypes($report);
}
return [
'id' => 'media_types',
'label' => 'Export as',
'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,
'required' => true,
'options' => self::MEDIA_TYPE_OBJECTS,
'value' => $value,
'dependencies' => [],
'dependsOn' => [],
];
}
public function getCallDurationFieldData(?int $valueMin = null, ?int $valueMax = null): array
{
return [
'id' => 'call_duration',
'label' => 'Call Duration',
'inputType' => InputTypeEnum::INTEGER_RANGE,
'required' => false,
'value' => ['min' => $valueMin, 'max' => $valueMax],
'queryParams' => [
'min' => 'min_call_duration',
'max' => 'max_call_duration',
],
'dependencies' => [],
'dependsOn' => [],
];
}
public function getRecipientsFieldData(?Team $team = null, array $value = []): array
{
return $this->recipientsService->getRecipientsFieldData(team: $team, value: $value);
}
public function getJiminnyRecipientsFieldData(array $value = []): array
{
return $this->recipientsService->getJiminnyRecipientsFieldData($value);
}
public function getAdditionalPromptInputFieldData(?string $value = null): array
{
return [
'id' => 'additional_prompt_input',
'label' => 'Special requirements',
'inputType' => InputTypeEnum::TEXTAREA,
'required' => false,
'placeholder' => 'What should be the focus of the report?',
'value' => $value,
'dependencies' => [],
'dependsOn' => [],
];
}
public function getCustomReportNameFieldData(?string $value = null): array
{
return [
'id' => 'custom_name',
'label' => 'Custom report name',
'inputType' => InputTypeEnum::TEXT,
'required' => false,
'placeholder' => 'Enter custom name',
'value' => $value,
'dependencies' => [],
'dependsOn' => [],
];
}
// data providers
public function getTeams(): array
{
$teams = $this->teamRepository->getTeamsForKiosk(status: Team::STATUS_ACTIVE);
$teamData = [];
foreach ($teams as $team) {
if (! $team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {
continue;
}
$teamData[] = $this->transformTeam($team);
}
return $teamData;
}
public function getTeamGroups(string $teamUuid): array
{
$data = [];
$team = $this->getTeam($teamUuid);
if ($team !== null) {
$groups = $team->groups()->get();
foreach ($groups as $group) {
$data[] = [
'id' => $group->getUuid(),
'name' => $group->getName(),
];
}
}
return $data;
}
public function getTeamsGroupsOptions(array $filterTeamUuids = []): array
{
$data = [];
$teams = $this->getTeams();
foreach ($teams as $team) {
if (! empty($filterTeamUuids) && ! in_array($team['id'], $filterTeamUuids, true)) {
continue;
}
$data[] = [
'label' => $team['name'],
'groups' => $this->getTeamGroups($team['id']),
];
}
return $data;
}
public function getTeam(string $teamUuid): ?Team
{
return $this->teamRepository->idOrUuid($teamUuid);
}
public function getTeamById(int $teamId): ?Team
{
return $this->teamRepository->find($teamId);
}
public function getGroupsUuids(AutomatedReport $report): array
{
$uuids = [];
$reportGroups = $report->getGroups();
foreach ($reportGroups as $groupId) {
if ($group = $this->groupRepository->find($groupId)) {
$uuids[] = $group->getUuid();
}
}
return $uuids;
}
public function getPlaybookCategoriesUuids(AutomatedReport $report): array
{
$uuids = [];
$playbookCategories = $report->getPlaybookCategories();
foreach ($playbookCategories as $id) {
if ($category = $this->playbookCategoryRepository->find($id)) {
$uuids[] = $category->getUuid();
}
}
return $uuids;
}
public function getDealAtCallStagesUuids(AutomatedReport $report): array
{
$uuids = [];
$reportStages = $report->getDealAtCallStages();
foreach ($reportStages as $id) {
if ($stage = $this->stageRepository->find($id)) {
$uuids[] = $stage->getUuid();
}
}
return $uuids;
}
public function getCurrentDealStagesUuids(AutomatedReport $report): array
{
$uuids = [];
$reportStages = $report->getCurrentDealStages();
foreach ($reportStages as $id) {
if ($stage = $this->stageRepository->find($id)) {
$uuids[] = $stage->getUuid();
}
}
return $uuids;
}
public function getUsersUuids(AutomatedReport $report): array
{
return $this->extractUserUuids($report->getRecipients());
}
public function getJiminnyUsersUuids(AutomatedReport $report): array
{
return $this->extractUserUuids($report->getJiminnyRecipients());
}
/**
* @param array<string, mixed> $recipients
*/
private function extractUserUuids(array $recipients): array
{
$userIds = $recipients['users'] ?? [];
return collect($userIds)
->map(fn ($id) => $this->userRepository->find((int) $id))
->filter()
->map(fn (UserContract $user) => $user->getUuid())
->values()
->all();
}
// get mail data
public function getRecipientUsers(AutomatedReport $report): array
{
return $this->buildRecipientUsers($report->getRecipients());
}
private function getJiminnyRecipientUsers(AutomatedReport $report): array
{
return $this->buildRecipientUsers($report->getJiminnyRecipients());
}
/**
* @param array<string, mixed> $recipients
*/
private function buildRecipientUsers(array $recipients): array
{
$userIds = $recipients['users'] ?? [];
return collect($userIds)
->map(fn ($id) => $this->userRepository->find((int) $id))
->filter()
->map(fn (UserContract $user) => [
'email' => $user->getEmailAddress(),
'name' => $user->getName(),
'timezone' => $user->getTimezone()->getName(),
])
->values()
->all();
}
public function getValidRecipientUsers(AutomatedReport $report, bool $includeJiminny = false): array
{
if ($report->isAskJiminnyReport()) {
$recipients = $this->resolveAskJiminnyRecipients($report);
} else {
$recipients = $this->getRecipientUsers($report);
if ($includeJiminny) {
$recipients = array_merge($recipients, $this->getJiminnyRecipientUsers($report));
}
}
$emails = [];
return array_values(array_filter(
$recipients,
static function ($recipient) use (&$emails) {
if (empty($recipient['email']) || in_array($recipient['email'], $emails, true)) {
return false;
}
$emails[] = $recipient['email'];
return true;
}
));
}
private function resolveAskJiminnyRecipients(AutomatedReport $report): array
{
$recipients = [];
$creator = $report->getCreator();
if ($creator !== null) {
$recipients[] = [
'email' => $creator->getEmailAddress(),
'name' => $creator->getName(),
'timezone' => $creator->getTimezone()->getName(),
];
}
return array_merge(
$recipients,
$this->buildRecipientUsers($report->getRecipients()),
$this->getGroupRecipientUsers($report),
);
}
private function getGroupRecipientUsers(AutomatedReport $report): array
{
$users = [];
foreach ($report->getGroups() as $groupId) {
$group = $this->groupRepository->find($groupId);
if ($group === null) {
continue;
}
foreach ($group->getMembers() as $member) {
$users[] = [
'email' => $member->getEmailAddress(),
'name' => $member->getName(),
'timezone' => $member->getTimezone()->getName(),
];
}
}
return $users;
}
public function getReportTypeName(AutomatedReportResult $report): string
{
$type = $report->getReport()->getType();
$getType = $this->transformReportType($type);
return $getType['name'];
}
public function getReportPeriodName(AutomatedReportResult $report): string
{
$from = $report->getFromDate();
$to = $report->getToDate();
$frequency = $report->getReport()->getFrequency();
if ($from === null || $to === null) {
if (! $report->getReport()->isAskJiminnyReport()) {
$invalidPeriod = $from === null ? 'from' : 'to';
throw new ApplicationException('Report period is invalid: ' . $invalidPeriod);
}
$period = $this->calculateFromAndToDatePeriod($frequency);
$from = $period['fromDate'];
$to = $period['toDate'];
}
return $this->formatReportPeriodName($frequency, $from, $to);
}
private function formatReportPeriodName(string $frequency, Carbon $from, Carbon $to): string
{
$fromYear = $from->format('Y');
$toYear = $to->format('Y');
$differentYears = $fromYear !== $toYear;
switch ($frequency) {
case self::FREQUENCY_DAILY:
return $from->format('j M Y');
case self::FREQUENCY_QUARTERLY:
// 'Jan-Mar 2025' or 'Nov 2024-Jan 2025' if years differ
$startMonth = $from->format('M');
$endMonth = $to->copy()->subMonth();
$endMonthName = $endMonth->format('M');
$endMonthYear = $endMonth->format('Y');
if ($differentYears) {
return "{$startMonth} {$fromYear} - {$endMonthName} {$endMonthYear}";
}
return "{$startMonth} - {$endMonthName} {$toYear}";
case self::FREQUENCY_MONTHLY:
// 'May 2025' - monthly reports are always within the same year
return $from->format('M Y');
case self::FREQUENCY_WEEKLY:
// '4 - 8 Aug 2025', '27 Oct - 3 Nov 2025', or '28 Dec 2024 - 3 Jan 2025' if years differ
$startDay = $from->format('j');
$endDay = $to->format('j');
$startMonth = $from->format('M');
$endMonth = $to->format('M');
if ($differentYears) {
return "{$startDay} {$startMonth} {$fromYear} - {$endDay} {$endMonth} {$toYear}";
}
if ($startMonth !== $endMonth) {
return "{$startDay} {$startMonth} - {$endDay} {$endMonth} {$toYear}";
}
return "{$startDay} - {$endDay} {$endMonth} {$toYear}";
case self::FREQUENCY_ONE_OFF:
// '2 May-31 May 2025' or '15 Dec 2024-15 Jan 2025' if years differ
$startDay = $from->format('j');
$startMonth = $from->format('M');
$endDay = $to->format('j');
$endMonth = $to->format('M');
// If same month and year, use a format like '2-31 May 2025'
if ($startMonth === $endMonth && ! $differentYears) {
return "{$startDay} - {$endDay} {$startMonth} {$toYear}";
}
// If different years, include both years
if ($differentYears) {
return "{$startDay} {$startMonth} {$fromYear} - {$endDay} {$endMonth} {$toYear}";
}
// Same year but different months
return "{$startDay} {$startMonth} - {$endDay} {$endMonth} {$toYear}";
default:
// Default format for unknown frequencies
return $from->format('j M Y') . ' - ' . $to->format('j M Y');
}
}
public function getReportTeamsName(AutomatedReportResult $report): string
{
$groups = $report->getGroups();
if (empty($groups)) {
return 'All';
}
// Get group names from repository
$groupNames = [];
foreach ($groups as $groupId) {
$group = $this->groupRepository->find($groupId);
if ($group) {
$groupNames[] = $group->getName();
}
}
if (count($groupNames) === 1) {
// Single team format
$teamsName = $groupNames[0];
} else {
// Multiple teams format
$teamsName = implode(', ', $groupNames);
}
return $teamsName;
}
public function getReportFileName(AutomatedReportResult $report): string
...
|
12308
|
|
12325
|
262
|
1
|
2026-04-14T11:06:01.184948+00:00
|
/Users/lukas/.screenpipe/data/data/2026-04-14/1776 /Users/lukas/.screenpipe/data/data/2026-04-14/1776164761184_m1.jpg...
|
PhpStorm
|
faVsco.js – AutomatedReportsService.php
|
1
|
NULL
|
monitor_1
|
NULL
|
NULL
|
NULL
|
NULL
|
Project: faVsco.js, menu
#11894 on JY-18909-automa Project: faVsco.js, menu
#11894 on JY-18909-automated-reports-ask-jiminny, menu
Start Listening for PHP Debug Connections
AutomatedReportsCommandTest
Run 'AutomatedReportsCommandTest'
Debug 'AutomatedReportsCommandTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Execute
Explain Plan
Browse Query History
View Parameters
Open Query Execution Settings…
In-Editor Results
Tx: Auto
Cancel Running Statements
Playground
jiminny
Sync Changes
Hide This Notification
Code changed:
Hide
16
13
13
Previous Highlighted Error
Next Highlighted Error
SELECT * FROM teams WHERE id = 1;
select * from crm_layouts where crm_configuration_id = 39;
SELECT * FROM crm_layout_entities WHERE crm_layout_id = 283;
SELECT * FROM crm_fields WHERE id = 2234;
SELECT * FROM crm_field_values WHERE crm_field_id = 2234;
select * from crm_profiles where user_id = 143;
select * from record_types where crm_configuration_id = 39; # 0121K000001MHElQAO,0121K000001MHEqQAO
select * from business_processes where crm_configuration_id = 39;
# 01941000000H669AAC, 01941000000H66JAAS
select * from record_type_field_values
where record_type_id IN (24);
select * from crm_field_values where id IN (2730);
select * from crm_configurations where id = 39;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 1
and sa.provider = 'salesforce'; #1035
select * from users where team_id = 1; # 222 group 3
SELECT * FROM activities WHERE user_id = 222 order by id desc;
select * from sidekick_settings where team_id = 1;
select * from teams where id = 1;
select * from team_features where team_id = 1;
select * from activities where crm_configuration_id = 2
and provider = 'ms-teams' and id = 608765;
SELECT * FROM activities WHERE crm_configuration_id = 2 and crm_provider_id = '59523413338';
select * from sidekick_settings where team_id = 2;
SELECT * FROM activities WHERE id = 608660;
select * from activity_summary_logs where activity_id = 608660;
select * from ai_prompts where transcription_id = 11214;
# [PASSWORD_DOTS]
SELECT * FROM activities WHERE uuid_to_bin('ed78a437-2804-450e-ab2f-56ab1c641346') = uuid;
# id: 608818, crm: 59628809737
SELECT * FROM activities WHERE uuid_to_bin('36b06e55-afdd-4782-8dee-c624cd0af191') = uuid;
# id: 608821, crm: 59632069252
SELECT ce.start_time, ce.end_time, a.id, a.uuid, crm_provider_id, calendar_event_id, title,
playbook_category_id, user_id, lead_id, contact_id, account_id, opportunity_id,
scheduled_start_time, scheduled_end_time, actual_start_time, actual_end_time, a.created_at
FROM activities a
join calendar_events ce on a.calendar_event_id = ce.id
WHERE a.id IN (608818, 608821);
select * from users where team_id = 1;
select * from team_settings where team_id = 1;
select * from crm_profiles where crm_configuration_id = 39 order by user_id;
select * from team_features where team_id = 1;
select * from users where team_id = 2;
SELECT * FROM activities WHERE uuid_to_bin('ec7647e9-5225-458b-b475-f31aa2769204') = uuid; # 612639
# Preslava N. Ivanova, grou id 3
SELECT * FROM opportunities WHERE uuid_to_bin('a2928fe5-aec5-46cb-85d9-7654c89e46a6') = uuid;
select * from activities where opportunity_id = 344 and actual_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00';
select
a.id,
a.type,
a.scheduled_start_time,
a.actual_start_time,
a.created_at,
a.opportunity_id,
a.status
FROM activities a
WHERE opportunity_id = 344
and status IN ('completed', 'received', 'delivered')
and (
(a.actual_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00')
OR (a.created_at between '2024-10-11 00:00:00' and '2024-10-12 00:00:00')
OR (a.scheduled_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00'))
;
SELECT * FROM users WHERE id = 222;
SELECT * FROM crm_profiles WHERE user_id = 222;
select * from crm_layouts where crm_configuration_id = 39;
SELECT * FROM crm_layout_entities WHERE crm_layout_id = 281;
select * from group_deal_risk_types;
select * from opportunities where team_id = 1;
SELECT * FROM opportunities WHERE id = 315;
SELECT * FROM crm_field_data WHERE object_id = 315;
select * from crm_field_data where object_id = 260;
select * from generic_ai_prompts where subject_id = 315;
select * from teams; # 36, 21, 121, [EMAIL]
SELECT * FROM social_accounts WHERE sociable_id = 121 and provider = 'bullhorn';
# [PASSWORD_DOTS]
select * from teams where id = 1;
select * from crm_configurations where id = 39;
select * from users where team_id = 1;
select u.email, cp.* from users u
join crm_profiles cp on u.id = cp.user_id
where u.team_id = 1;
# 1 - 00541000004281rAAA
# 204 - 0052g000003freeAAA
# 429 - 0052g000003qGOiAAM
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 1
and sa.provider = 'salesforce';
select * from activities where type = 'softphone'
and created_at > '2024-12-11 15:24:36' order by id desc;
select * from activity_providers where team_id = 1;
select * from activity_provider_users where activity_provider_id = 328;
select * from opportunities where crm_configuration_id = 39
AND account_id = 178 AND is_closed = false
order by created_at DESC;
select * from contacts where id = 3952;
select * from accounts where id = 178;
# [PASSWORD_DOTS]
select * from teams where id = 36;
select * from crm_configurations where id = 21;
select * from users where team_id = 36;
select u.email, cp.* from users u
join crm_profiles cp on u.id = cp.user_id
where u.team_id = 36;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 36
and sa.provider = 'bullhorn';
select * from social_accounts where id = 348;
UPDATE social_accounts SET
provider_user_token = '21442_6802599_91:41179a58-21e7-4d7c-ad58-56bb666b2f65',
provider_refresh_token = '21442_6802599_91:01c6b335-3f2a-42e4-85ff-8a08fa65fceb',
expires = 1733998131,
state = 'connected'
WHERE id = 348;
# [PASSWORD_DOTS]
select * from teams where id = 31;
select * from crm_configurations where id = 18;
select * from users where team_id = 31; # 257
select u.email, cp.* from users u
join crm_profiles cp on u.id = cp.user_id
where u.team_id = 31;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 31
and sa.provider = 'close';
select * from contacts where crm_configuration_id = 18;
# [PASSWORD_DOTS] NEPTUNE [PASSWORD_DOTS]
select * from teams;
select * from users where id IN (1030, 1035, 1052);
select * from crm_configurations;
select * from users where team_id = 65; # 257
select * from team_settings where team_id = 65; # 257
select * from invitations where team_id = 65; # 257
select * from users where email = '[EMAIL]'; # 257
select u.email, cp.* from users u
join crm_profiles cp on u.id = cp.user_id
where u.team_id = 65;
select * from crm_configurations where id = 53;
select * from accounts where crm_configuration_id = 53 order by id desc;
select * from leads where crm_configuration_id = 53 order by id desc;
select * from contacts where crm_configuration_id = 53 order by id desc;
select * from opportunities where crm_configuration_id = 53 order by id desc;
select * from crm_profiles where crm_configuration_id = 53 order by id desc;
select * from crm_fields where crm_configuration_id = 53 order by id desc;
select * from crm_field_values where crm_field_id = 3341 order by id desc;
select * from crm_layouts where crm_configuration_id = 53 order by id desc;
select * from stages where crm_configuration_id = 53 order by id desc;
select * from crm_profiles where crm_configuration_id = 13;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 65
and sa.provider = 'integration-app';
select * from contacts where crm_configuration_id = 13;
select * from social_accounts where sociable_id = 283;
SELECT * FROM opportunities WHERE crm_provider_id = '006O400000E9bzeIAB';
select * from activity_providers where team_id = 65;
SELECT * FROM activities WHERE crm_configuration_id IN (51, 52, 53);
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 65
;
# [PASSWORD_DOTS] STAGING [PASSWORD_DOTS]
SELECT * FROM teams;
SELECT * FROM teams WHERE id = 88;
SELECT * FROM teams WHERE id = 89;
select * from team_settings where team_id = 89;
SELECT * FROM users WHERE team_id = 89;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 89;
select * from users;
SELECT * FROM social_accounts WHERE sociable_id = 1761;
SELECT * FROM crm_configurations WHERE id = 70;
select * from accounts where crm_configuration_id = 70 order by id desc;
select * from leads where crm_configuration_id = 70 order by id desc;
select * from contacts where crm_configuration_id = 70 order by id desc;
select * from opportunities where crm_configuration_id = 70 order by id desc;
select * from crm_profiles where crm_configuration_id = 70 order by id desc;
select * from crm_fields where crm_configuration_id = 70 order by id desc;
select * from crm_field_values where crm_field_id = 3536 order by id desc;
select * from crm_layouts where crm_configuration_id = 70 order by id desc;
select * from stages where crm_configuration_id = 70 order by id desc;
select * from business_processes where crm_configuration_id = 70 order by id desc;
select * from business_process_stages where business_process_id = 34;
select * from contacts where id = 10468;
select * from crm_layouts where crm_configuration_id = 70;
SELECT * FROM crm_layout_entities WHERE crm_layout_id = 388;
SELECT * FROM crm_fields WHERE id IN (3533,3534,3535);
select * from activities where crm_configuration_id = 70
and (account_id IS NOT NULL or lead_id IS NOT NULL or contact_id IS NOT NULL or opportunity_id IS NOT NULL) order by id desc;
SELECT * FROM activities WHERE uuid_to_bin('2e10b60f-8a61-41c5-a3d4-28835353dc65') = uuid;
SELECT * FROM activities where crm_configuration_id = 69 ;
SELECT * FROM users WHERE email LIKE '%[EMAIL]%';
SELECT * FROM activities WHERE uuid_to_bin('5a150c93-40fc-42ec-b3bd-c1d328e09f6e') = uuid;
SELECT * FROM opportunities WHERE id = 385;
select * from participants p
join activities a on p.activity_id = a.id
where a.crm_configuration_id = 70
and (p.lead_id IS NOT NULL or p.contact_id IS NOT NULL);
SELECT * FROM participants WHERE id = 1013638;
select * from teams where id = 90;
select * from users where team_id = 90;
select * from social_accounts where social_accounts.sociable_id IN (1960,1760);
SELECT * FROM crm_profiles WHERE crm_configuration_id = 71;
select * from invitations where team_id = 90;
select * from crm_configurations where id = 71;
select * from accounts where crm_configuration_id = 71 order by id desc;
select * from leads where crm_configuration_id = 71 order by id desc;
select * from contacts where crm_configuration_id = 71 order by id desc;
select * from opportunities where crm_configuration_id = 71 order by id desc;
select * from crm_profiles where crm_configuration_id = 71 order by id desc;
select * from crm_fields where crm_configuration_id = 71 order by id desc;
select * from crm_field_values where crm_field_id = 3341 order by id desc;
select * from crm_layouts where crm_configuration_id = 71 order by id desc;
select * from stages where crm_configuration_id = 71 order by id desc;
select * from users order by secondary_email desc;
select u.id, u.email, u.status, sa.id, sa.provider_user_id from social_accounts sa
join users u on sa.sociable_id = u.id
where sa.provider = 'google' and u.email LIKE 'aneliya%';
select * from failed_jobs order by id desc;
select * from users where email = '[EMAIL]' or secondary_email = '[EMAIL]';
select * from teams;
SELECT * FROM crm_profiles WHERE crm_configuration_id = 39;
SELECT * FROM crm_fields WHERE crm_configuration_id = 39 and object_type = 'task';
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 1
and sa.provider = 'salesforce';
# [PASSWORD_DOTS]
SELECT * FROM activities WHERE uuid_to_bin('c38b3895-fd0f-4b1f-9fb2-c170dba137c6') = uuid;
SELECT * FROM crm_configurations WHERE id = 70;
select * from teams where id = 1;
select * from groups where team_id = 1;
select * from users where team_id = 1;
select o.id, o.name,o.close_date, u.id, u.name, u.group_id, r.id, r.display_name, g.name, g.scope from opportunities o
join users u on o.user_id = u.id
join groups g on u.group_id = g.id
join role_user ru on u.id = ru.user_id
join roles r on ru.role_id = r.id
where o.crm_configuration_id = 39 and close_date > '2024-01-01 00:00:00';
select * from role_user where user_id = 143;
select * from roles;
select * from role_user;
select * from groups where id = 9;
select * from scope_groups where group_id = 9;
# [PASSWORD_DOTS]
select * from teams where id = 36;
select * from crm_configurations;
SELECT * FROM social_accounts WHERE sociable_id = 121;
[URL_WITH_CREDENTIALS] this will add filter, however if we need to control feature by FF we need conditional logic
public const array TYPES = [
['id' => 'exec_summary', 'name' => 'Exec Summary'],
['id' => 'coaching_profiles', 'name' => 'Coaching Profiles'],
['id' => 'product_feedback', 'name' => 'Product Feedback'],
['id' => self::TYPE_LOSS_ANALYSIS, 'name' => 'Loss Analysis'],
// ['id' => 'questions', 'name' => 'Questions'],
// ['id' => 'statistical_quant', 'name' => 'Statistical Quantitative'],
];
public const array ALL_TYPES = [
...self::TYPES,
['id' => self::TYPE_ASK_JIMINNY, 'name' => 'Ask Jiminny'],
];
public const string FREQUENCY_DAILY = 'daily';
public const string FREQUENCY_WEEKLY = 'weekly';
public const string FREQUENCY_MONTHLY = 'monthly';
public const string FREQUENCY_QUARTERLY = 'quarterly';
public const string FREQUENCY_ONE_OFF = 'one_off';
/**
* Frequencies for standard (non-Ask Jiminny) reports.
*/
public const array FREQUENCIES = [
['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],
['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],
['id' => self::FREQUENCY_QUARTERLY, 'name' => 'Quarterly'],
['id' => self::FREQUENCY_ONE_OFF, 'name' => 'One-off'],
];
/**
* Frequencies for Ask Jiminny reports.
*/
public const array ASK_JIMINNY_FREQUENCIES = [
['id' => self::FREQUENCY_DAILY, 'name' => 'Daily'],
['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],
['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],
];
public const string MEDIA_TYPE_PDF = 'pdf';
public const string MEDIA_TYPE_PODCAST = 'podcast';
public const array MEDIA_TYPES = [self::MEDIA_TYPE_PDF, self::MEDIA_TYPE_PODCAST];
public const array MEDIA_TYPE_OBJECT_PDF = ['id' => self::MEDIA_TYPE_PDF, 'name' => 'PDF'];
public const array MEDIA_TYPE_OBJECT_PODCAST = ['id' => self::MEDIA_TYPE_PODCAST, 'name' => 'Podcast'];
public const array MEDIA_TYPE_OBJECTS = [self::MEDIA_TYPE_OBJECT_PDF, self::MEDIA_TYPE_OBJECT_PODCAST];
public const array CALL_TYPE_CONFERENCE = ['id' => 'conference', 'name' => 'Conference'];
public const array CALL_TYPE_DIALER = ['id' => 'dialer', 'name' => 'Dialer'];
public const int SENT_REPORT_AT_HOURS = 5;
public const string PDF_KEY = 'pdf';
public const string AUDIO_KEY = 'audio';
private const array ALL_FREQUENCIES = [
['id' => self::FREQUENCY_DAILY, 'name' => 'Daily'],
['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],
['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],
['id' => self::FREQUENCY_QUARTERLY, 'name' => 'Quarterly'],
['id' => self::FREQUENCY_ONE_OFF, 'name' => 'One-off'],
];
private const string S3_DIR = 'reports';
private const array FILE_EXTENSIONS_VARIANTS = ['html', 'MD', 'pdf'];
private const array FILE_PODCAST_EXTENSIONS_VARIANTS = ['json', 'mp3', 'ssml'];
public function __construct(
private readonly TeamRepository $teamRepository,
private readonly GroupRepository $groupRepository,
private readonly UserRepository $userRepository,
private readonly StageRepository $stageRepository,
private readonly DealStagesService $dealStagesService,
private readonly RecipientsService $recipientsService,
private readonly AutomatedReportsRepository $automatedReportsRepository,
private readonly Webhook $webhookService,
private readonly BusDispatcher $dispatcher,
private readonly ActivityTypeService $activityTypeService,
private readonly PlaybookCategoryRepository $playbookCategoryRepository,
private readonly AskAnythingPromptService $askAnythingPromptService,
private readonly SearchRepository $activitySearchRepository,
private readonly AskAnythingRepository $askAnythingRepository,
) {
}
public static function getTypes(): array
{
$types = self::TYPES;
return array_map(static function ($type) {
return $type['id'];
}, $types);
}
public static function getCallTypes(): array
{
return array_map(static function ($callType) {
return $callType['id'];
}, [self::CALL_TYPE_CONFERENCE, self::CALL_TYPE_DIALER]);
}
public static function getFrequencies(): array
{
return array_map(static function ($frequency) {
return $frequency['id'];
}, self::FREQUENCIES);
}
// front-facing structure
public function getReportEnabledFieldData(bool $value = false): array
{
return [
'id' => 'report_enabled',
'label' => '',
'inputType' => InputTypeEnum::TOGGLE,
'value' => $value,
];
}
// Organizations = Teams
public function getOrganizationFieldData(?string $value = null, bool $shortVersion = false): array
{
$options = $this->getTeams();
if ($shortVersion) {
return [
'id' => 'organization',
'label' => 'Organization',
'options' => $options,
];
}
return [
'id' => 'organization',
'label' => 'Organization',
'inputType' => InputTypeEnum::DROPDOWN,
'required' => true,
'placeholder' => 'Select',
'options' => $options,
'value' => $value,
'dependencies' => [
'teams',
'deal_stage_at_call',
'current_deal_stage',
'recipients',
ActivityTypeService::PLAYBOOK_CATEGORIES_KEY,
],
'dependsOn' => [],
];
}
// Teams = Groups
public function getTeamFieldData(array $options = [], array $value = [], bool $shortVersion = false): array
{
if ($shortVersion) {
return [
'id' => 'teams',
'label' => 'Team',
'options' => $options,
];
}
return [
'id' => 'teams',
'label' => 'Team',
'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,
'required' => false,
'placeholder' => 'Select',
'options' => $options,
'value' => $value, // value should be an array of objects {id, name}
'dependencies' => [ActivityTypeService::PLAYBOOK_CATEGORIES_KEY],
'dependsOn' => [],
];
}
public function getReportTypeFieldData(?string $value = null, bool $shortVersion = false, ?Team $team = null): array
{
$types = [];
if ($team instanceof Team) {
if ($team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {
$types = self::TYPES;
}
if ($team->hasFeature(FeatureEnum::ASK_JIMINNY_REPORTS)) {
$types[] = ['id' => self::TYPE_ASK_JIMINNY, 'name' => 'Ask Jiminny'];
}
} else {
$types = self::TYPES;
}
if ($shortVersion) {
return [
'id' => 'report_type',
'label' => 'Report Type',
'options' => $types,
];
}
return [
'id' => 'report_type',
'label' => 'Report Type',
'inputType' => InputTypeEnum::DROPDOWN,
'required' => true,
'placeholder' => 'Select',
'options' => $types,
'value' => $value,
'dependencies' => [],
'dependsOn' => [],
];
}
public function getFrequencyFieldData(?string $value = null): array
{
return [
'id' => 'frequency',
'label' => 'Frequency',
'inputType' => InputTypeEnum::DROPDOWN,
'required' => true,
'placeholder' => 'Select',
'options' => self::FREQUENCIES,
'value' => $value,
'dependencies' => ['period'],
'dependsOn' => [],
];
}
public function getPeriodFieldData(?string $valueStartDate = null, ?string $valueEndDate = null): array
{
return [
'id' => 'period',
'label' => 'Select one-off period',
'inputType' => InputTypeEnum::DATE_RANGE,
'required' => true,
'placeholder' => 'Select',
'value' => ['startDate' => $valueStartDate, 'endDate' => $valueEndDate],
'queryParams' => [
'startDate' => 'start_date_period',
'endDate' => 'end_date_period',
],
'dependencies' => [],
'dependsOn' => ['frequency'],
];
}
public function getActivityTypesFieldData(?Team $team = null, array $value = [], array $teamsFilter = []): array
{
return $this->activityTypeService->getActivityTypeFieldData(team: $team, value: $value, groupIds: $teamsFilter);
}
public function getDealStageAtCallFieldData(?Team $team = null, array $value = []): array
{
return $this->dealStagesService->getDealStageAtCallFieldData(team: $team, value: $value);
}
public function getCurrentDealStageFieldData(?Team $team = null, array $value = []): array
{
return $this->dealStagesService->getCurrentDealStageFieldData(team: $team, value: $value);
}
public function getDealValueFieldData(?int $valueMin = null, ?int $valueMax = null): array
{
return [
'id' => 'deal_value',
'label' => 'Deal Value',
'inputType' => InputTypeEnum::INTEGER_RANGE,
'required' => false,
'value' => ['min' => $valueMin, 'max' => $valueMax],
'queryParams' => [
'min' => 'min_deal_value',
'max' => 'max_deal_value',
],
'dependencies' => [],
'dependsOn' => [],
];
}
public function getCallTypeFieldData(bool $conferenceOn = false, bool $dialerOn = false): array
{
$value = [];
$conferenceOn && $value[] = self::CALL_TYPE_CONFERENCE;
$dialerOn && $value[] = self::CALL_TYPE_DIALER;
return [
'id' => 'call_type',
'label' => 'Call Type',
'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,
'required' => true,
'options' => [
self::CALL_TYPE_CONFERENCE,
self::CALL_TYPE_DIALER,
],
'value' => $value,
'dependencies' => [],
'dependsOn' => [],
];
}
public function getMediaTypeFieldData(?AutomatedReport $report = null): array
{
$value = [];
if ($report) {
$value = $this->transformMediaTypes($report);
}
return [
'id' => 'media_types',
'label' => 'Export as',
'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,
'required' => true,
'options' => self::MEDIA_TYPE_OBJECTS,
'value' => $value,
'dependencies' => [],
'dependsOn' => [],
];
}
public function getCallDurationFieldData(?int $valueMin = null, ?int $valueMax = null): array
{
return [
'id' => 'call_duration',
'label' => 'Call Duration',
'inputType' => InputTypeEnum::INTEGER_RANGE,
'required' => false,
'value' => ['min' => $valueMin, 'max' => $valueMax],
'queryParams' => [
'min' => 'min_call_duration',
'max' => 'max_call_duration',
],
'dependencies' => [],
'dependsOn' => [],
];
}
public function getRecipientsFieldData(?Team $team = null, array $value = []): array
{
return $this->recipientsService->getRecipientsFieldData(team: $team, value: $value);
}
public function getJiminnyRecipientsFieldData(array $value = []): array
{
return $this->recipientsService->getJiminnyRecipientsFieldData($value);
}
public function getAdditionalPromptInputFieldData(?string $value = null): array
{
return [
'id' => 'additional_prompt_input',
'label' => 'Special requirements',
'inputType' => InputTypeEnum::TEXTAREA,
'required' => false,
'placeholder' => 'What should be the focus of the report?',
'value' => $value,
'dependencies' => [],
'dependsOn' => [],
];
}
public function getCustomReportNameFieldData(?string $value = null): array
{
return [
'id' => 'custom_name',
'label' => 'Custom report name',
'inputType' => InputTypeEnum::TEXT,
'required' => false,
'placeholder' => 'Enter custom name',
'value' => $value,
'dependencies' => [],
'dependsOn' => [],
];
}
// data providers
public function getTeams(): array
{
$teams = $this->teamRepository->getTeamsForKiosk(status: Team::STATUS_ACTIVE);
$teamData = [];
foreach ($teams as $team) {
if (! $team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {
continue;
}
$teamData[] = $this->transformTeam($team);
}
return $teamData;
}
public function getTeamGroups(string $teamUuid): array
{
$data = [];
$team = $this->getTeam($teamUuid);
if ($team !== null) {
$groups = $team->groups()->get();
foreach ($groups as $group) {
$data[] = [
'id' => $group->getUuid(),
'name' => $group->getName(),
];
}
}
return $data;
}
public function getTeamsGroupsOptions(array $filterTeamUuids = []): array
{
$data = [];
$teams = $this->getTeams();
foreach ($teams as $team) {
if (! empty($filterTeamUuids) && ! in_array($team['id'], $filterTeamUuids, true)) {
continue;
}
$data[] = [
'label' => $team['name'],
'groups' => $this->getTeamGroups($team['id']),
];
}
return $data;
}
public function getTeam(string $teamUuid): ?Team
{
return $this->teamRepository->idOrUuid($teamUuid);
}
public function getTeamById(int $teamId): ?Team
{
return $this->teamRepository->find($teamId);
}
public function getGroupsUuids(AutomatedReport $report): array
{
$uuids = [];
$reportGroups = $report->getGroups();
foreach ($reportGroups as $groupId) {
if ($group = $this->groupRepository->find($groupId)) {
$uuids[] = $group->getUuid();
}
}
return $uuids;
}
public function getPlaybookCategoriesUuids(AutomatedReport $report): array
{
$uuids = [];
$playbookCategories = $report->getPlaybookCategories();
foreach ($playbookCategories as $id) {
if ($category = $this->playbookCategoryRepository->find($id)) {
$uuids[] = $category->getUuid();
}
}
return $uuids;
}
public function getDealAtCallStagesUuids(AutomatedReport $report): array
{
$uuids = [];
$reportStages = $report->getDealAtCallStages();
foreach ($reportStages as $id) {
if ($stage = $this->stageRepository->find($id)) {
$uuids[] = $stage->getUuid();
}
}
return $uuids;
}
public function getCurrentDealStagesUuids(AutomatedReport $report): array
{
$uuids = [];
$reportStages = $report->getCurrentDealStages();
foreach ($reportStages as $id) {
if ($stage = $this->stageRepository->find($id)) {
$uuids[] = $stage->getUuid();
}
}
return $uuids;
}
public function getUsersUuids(AutomatedReport $report): array
{
return $this->extractUserUuids($report->getRecipients());
}
public function getJiminnyUsersUuids(AutomatedReport $report): array
{
return $this->extractUserUuids($report->getJiminnyRecipients());
}
/**
* @param array<string, mixed> $recipients
*/
private function extractUserUuids(array $recipients): array
{
$userIds = $recipients['users'] ?? [];
return collect($userIds)
->map(fn ($id) => $this->userRepository->find((int) $id))
->filter()
->map(fn (UserContract $user) => $user->getUuid())
->values()
->all();
}
// get mail data
public function getRecipientUsers(AutomatedReport $report): array
{
return $this->buildRecipientUsers($report->getRecipients());
}
private function getJiminnyRecipientUsers(AutomatedReport $report): array
{
return $this->buildRecipientUsers($report->getJiminnyRecipients());
}
/**
* @param array<string, mixed> $recipients
*/
private function buildRecipientUsers(array $recipients): array
{
$userIds = $recipients['users'] ?? [];
return collect($userIds)
->map(fn ($id) => $this->userRepository->find((int) $id))
->filter()
->map(fn (UserContract $user) => [
'email' => $user->getEmailAddress(),
'name' => $user->getName(),
'timezone' => $user->getTimezone()->getName(),
])
->values()
->all();
}
public function getValidRecipientUsers(AutomatedReport $report, bool $includeJiminny = false): array
{
if ($report->isAskJiminnyReport()) {
$recipients = $this->resolveAskJiminnyRecipients($report);
} else {
$recipients = $this->getRecipientUsers($report);
if ($includeJiminny) {
$recipients = array_merge($recipients, $this->getJiminnyRecipientUsers($report));
}
}
$emails = [];
return array_values(array_filter(
$recipients,
static function ($recipient) use (&$emails) {
if (empty($recipient['email']) || in_array($recipient['email'], $emails, true)) {
return false;
}
$emails[] = $recipient['email'];
return true;
}
));
}
private function resolveAskJiminnyRecipients(AutomatedReport $report): array
{
$recipients = [];
$creator = $report->getCreator();
if ($creator !== null) {
$recipients[] = [
'email' => $creator->getEmailAddress(),
'name' => $creator->getName(),
'timezone' => $creator->getTimezone()->getName(),
];
}
return array_merge(
$recipients,
$this->buildRecipientUsers($report->getRecipients()),
$this->getGroupRecipientUsers($report),
);
}
private function getGroupRecipientUsers(AutomatedReport $report): array
{
$users = [];
foreach ($report->getGroups() as $groupId) {
$group = $this->groupRepository->find($groupId);
if ($group === null) {
continue;
}
foreach ($group->getMembers() as $member) {
$users[] = [
'email' => $member->getEmailAddress(),
'name' => $member->getName(),
'timezone' => $member->getTimezone()->getName(),
];
}
}
return $users;
}
public function getReportTypeName(AutomatedReportResult $report): string
{
$type = $report->getReport()->getType();
$getType = $this->transformReportType($type);
return $getType['name'];
}
public function getReportPeriodName(AutomatedReportResult $report): string
{
$from = $report->getFromDate();
$to = $report->getToDate();
$frequency = $report->getReport()->getFrequency();
if ($from === null || $to === null) {
if (! $report->getReport()->isAskJiminnyReport()) {
$invalidPeriod = $from === null ? 'from' : 'to';
throw new ApplicationException('Report period is invalid: ' . $invalidPeriod);
}
$period = $this->calculateFromAndToDatePeriod($frequency);
$from = $period['fromDate'];
$to = $period['toDate'];
}
return $this->formatReportPeriodName($frequency, $from, $to);
}
private function formatReportPeriodName(string $frequency, Carbon $from, Carbon $to): string
{
$fromYear = $from->format('Y');
$toYear = $to->format('Y');
$differentYears = $fromYear !== $toYear;
switch ($frequency) {
case self::FREQUENCY_DAILY:
return $from->format('j M Y');
case self::FREQUENCY_QUARTERLY:
// 'Jan-Mar 2025' or 'Nov 2024-Jan 2025' if years differ
$startMonth = $from->format('M');
$endMonth = $to->copy()->subMonth();
$endMonthName = $endMonth->format('M');
$endMonthYear = $endMonth->format('Y');
if ($differentYears) {
return "{$startMonth} {$fromYear} - {$endMonthName} {$endMonthYear}";
}
return "{$startMonth} - {$endMonthName} {$toYear}";
case self::FREQUENCY_MONTHLY:
// 'May 2025' - monthly reports are always within the same year
return $from->format('M Y');
case self::FREQUENCY_WEEKLY:
// '4 - 8 Aug 2025', '27 Oct - 3 Nov 2025', or '28 Dec 2024 - 3 Jan 2025' if years differ
$startDay = $from->format('j');
$endDay = $to->format('j');
$startMonth = $from->format('M');
$endMonth = $to->format('M');
if ($differentYears) {
return "{$startDay} {$startMonth} {$fromYear} - {$endDay} {$endMonth} {$toYear}";
}
if ($startMonth !== $endMonth) {
return "{$startDay} {$startMonth} - {$endDay} {$endMonth} {$toYear}";
}
return "{$startDay} - {$endDay} {$endMonth} {$toYear}";
case self::FREQUENCY_ONE_OFF:
// '2 May-31 May 2025' or '15 Dec 2024-15 Jan 2025' if years differ
$startDay = $from->format('j');
$startMonth = $from->format('M');
$endDay = $to->format('j');
$endMonth = $to->format('M');
// If same month and year, use a format like '2-31 May 2025'
if ($startMonth === $endMonth && ! $differentYears) {
return "{$startDay} - {$endDay} {$startMonth} {$toYear}";
}
// If different years, include both years
if ($differentYears) {
return "{$startDay} {$startMonth} {$fromYear} - {$endDay} {$endMonth} {$toYear}";
}
// Same year but different months
return "{$startDay} {$startMonth} - {$endDay} {$endMonth} {$toYear}";
default:
// Default format for unknown frequencies
return $from->format('j M Y') . ' - ' . $to->format('j M Y');
}
}
public function getReportTeamsName(AutomatedReportResult $report): string
{
$groups = $report->getGroups();
if (empty($groups)) {
return 'All';
}
// Get group names from repository
$groupNames = [];
foreach ($groups as $groupId) {
$group = $this->groupRepository->find($groupId);
if ($group) {
$groupNames[] = $group->getName();
}
}
if (count($groupNames) === 1) {
// Single team format
$teamsName = $groupNames[0];
} else {
// Multiple teams format
$teamsName = implode(', ', $groupNames);
}
return $teamsName;
}
public function getReportFileName(AutomatedReportResult $report): string
...
|
[{"role":"AXButton","text" [{"role":"AXButton","text":"Project: faVsco.js, menu","depth":5,"help_text":"~/jiminny/app","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"#11894 on JY-18909-automated-reports-ask-jiminny, menu","depth":5,"help_text":"Pull request #11894 exists for current branch JY-18909-automated-reports-ask-jiminny","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Start Listening for PHP Debug Connections","depth":5,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"AutomatedReportsCommandTest","depth":6,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Run 'AutomatedReportsCommandTest'","depth":6,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Debug 'AutomatedReportsCommandTest'","depth":6,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"More Actions","depth":6,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JetBrains AI","depth":5,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Search Everywhere","depth":5,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"IDE and Project Settings","depth":5,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Execute","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Explain Plan","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Browse Query History","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"View Parameters","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Open Query Execution Settings…","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"In-Editor Results","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Tx: Auto","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Cancel Running Statements","depth":4,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Playground","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"jiminny","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.088194445,"height":0.027777778},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"16","depth":4,"role_description":"text"},{"role":"AXStaticText","text":"13","depth":4,"role_description":"text"},{"role":"AXStaticText","text":"13","depth":4,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"SELECT * FROM teams WHERE id = 1;\n\nselect * from crm_layouts where crm_configuration_id = 39;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 283;\nSELECT * FROM crm_fields WHERE id = 2234;\nSELECT * FROM crm_field_values WHERE crm_field_id = 2234;\n\nselect * from crm_profiles where user_id = 143;\n\nselect * from record_types where crm_configuration_id = 39; # 0121K000001MHElQAO,0121K000001MHEqQAO\nselect * from business_processes where crm_configuration_id = 39;\n# 01941000000H669AAC, 01941000000H66JAAS\n\nselect * from record_type_field_values\n where record_type_id IN (24);\n\nselect * from crm_field_values where id IN (2730);\n\nselect * from crm_configurations where id = 39;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 1\nand sa.provider = 'salesforce'; #1035\n\n\nselect * from users where team_id = 1; # 222 group 3\nSELECT * FROM activities WHERE user_id = 222 order by id desc;\nselect * from sidekick_settings where team_id = 1;\nselect * from teams where id = 1;\nselect * from team_features where team_id = 1;\n\nselect * from activities where crm_configuration_id = 2\nand provider = 'ms-teams' and id = 608765;\n\nSELECT * FROM activities WHERE crm_configuration_id = 2 and crm_provider_id = '59523413338';\n\nselect * from sidekick_settings where team_id = 2;\n\nSELECT * FROM activities WHERE id = 608660;\nselect * from activity_summary_logs where activity_id = 608660;\nselect * from ai_prompts where transcription_id = 11214;\n\n# ********************************************************************************************************\nSELECT * FROM activities WHERE uuid_to_bin('ed78a437-2804-450e-ab2f-56ab1c641346') = uuid;\n# id: 608818, crm: 59628809737\nSELECT * FROM activities WHERE uuid_to_bin('36b06e55-afdd-4782-8dee-c624cd0af191') = uuid;\n# id: 608821, crm: 59632069252\nSELECT ce.start_time, ce.end_time, a.id, a.uuid, crm_provider_id, calendar_event_id, title,\nplaybook_category_id, user_id, lead_id, contact_id, account_id, opportunity_id,\nscheduled_start_time, scheduled_end_time, actual_start_time, actual_end_time, a.created_at\nFROM activities a\njoin calendar_events ce on a.calendar_event_id = ce.id\nWHERE a.id IN (608818, 608821);\n\nselect * from users where team_id = 1;\nselect * from team_settings where team_id = 1;\nselect * from crm_profiles where crm_configuration_id = 39 order by user_id;\n\nselect * from team_features where team_id = 1;\n\nselect * from users where team_id = 2;\n\nSELECT * FROM activities WHERE uuid_to_bin('ec7647e9-5225-458b-b475-f31aa2769204') = uuid; # 612639\n# Preslava N. Ivanova, grou id 3\n\nSELECT * FROM opportunities WHERE uuid_to_bin('a2928fe5-aec5-46cb-85d9-7654c89e46a6') = uuid;\n\nselect * from activities where opportunity_id = 344 and actual_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00';\n\nselect\n a.id,\n a.type,\n a.scheduled_start_time,\n a.actual_start_time,\n a.created_at,\n a.opportunity_id,\n a.status\nFROM activities a\nWHERE opportunity_id = 344\nand status IN ('completed', 'received', 'delivered')\nand (\n (a.actual_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00')\nOR (a.created_at between '2024-10-11 00:00:00' and '2024-10-12 00:00:00')\nOR (a.scheduled_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00'))\n;\n\nSELECT * FROM users WHERE id = 222;\n\nSELECT * FROM crm_profiles WHERE user_id = 222;\nselect * from crm_layouts where crm_configuration_id = 39;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 281;\n\nselect * from group_deal_risk_types;\n\nselect * from opportunities where team_id = 1;\n\nSELECT * FROM opportunities WHERE id = 315;\nSELECT * FROM crm_field_data WHERE object_id = 315;\nselect * from crm_field_data where object_id = 260;\n\nselect * from generic_ai_prompts where subject_id = 315;\n\nselect * from teams; # 36, 21, 121, james.graham@bullhorn.jiminny.com\nSELECT * FROM social_accounts WHERE sociable_id = 121 and provider = 'bullhorn';\n\n# ************************************************************************************\nselect * from teams where id = 1;\nselect * from crm_configurations where id = 39;\nselect * from users where team_id = 1;\nselect u.email, cp.* from users u\njoin crm_profiles cp on u.id = cp.user_id\nwhere u.team_id = 1;\n# 1 - 00541000004281rAAA\n# 204 - 0052g000003freeAAA\n# 429 - 0052g000003qGOiAAM\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 1\nand sa.provider = 'salesforce';\n\nselect * from activities where type = 'softphone'\nand created_at > '2024-12-11 15:24:36' order by id desc;\n\nselect * from activity_providers where team_id = 1;\nselect * from activity_provider_users where activity_provider_id = 328;\n\nselect * from opportunities where crm_configuration_id = 39\nAND account_id = 178 AND is_closed = false\norder by created_at DESC;\n\nselect * from contacts where id = 3952;\nselect * from accounts where id = 178;\n\n# ************************************************************************************\nselect * from teams where id = 36;\nselect * from crm_configurations where id = 21;\nselect * from users where team_id = 36;\nselect u.email, cp.* from users u\njoin crm_profiles cp on u.id = cp.user_id\nwhere u.team_id = 36;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 36\nand sa.provider = 'bullhorn';\n\nselect * from social_accounts where id = 348;\nUPDATE social_accounts SET\nprovider_user_token = '21442_6802599_91:41179a58-21e7-4d7c-ad58-56bb666b2f65',\nprovider_refresh_token = '21442_6802599_91:01c6b335-3f2a-42e4-85ff-8a08fa65fceb',\nexpires = 1733998131,\nstate = 'connected'\nWHERE id = 348;\n\n# ************************************************************************************\nselect * from teams where id = 31;\nselect * from crm_configurations where id = 18;\n\nselect * from users where team_id = 31; # 257\nselect u.email, cp.* from users u\njoin crm_profiles cp on u.id = cp.user_id\nwhere u.team_id = 31;\n\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 31\nand sa.provider = 'close';\n\nselect * from contacts where crm_configuration_id = 18;\n\n# ********************** NEPTUNE **************************************************************\nselect * from teams;\nselect * from users where id IN (1030, 1035, 1052);\nselect * from crm_configurations;\n\nselect * from users where team_id = 65; # 257\nselect * from team_settings where team_id = 65; # 257\nselect * from invitations where team_id = 65; # 257\nselect * from users where email = 'integration-account@jiminny.com'; # 257\nselect u.email, cp.* from users u\njoin crm_profiles cp on u.id = cp.user_id\nwhere u.team_id = 65;\n\nselect * from crm_configurations where id = 53;\nselect * from accounts where crm_configuration_id = 53 order by id desc;\nselect * from leads where crm_configuration_id = 53 order by id desc;\nselect * from contacts where crm_configuration_id = 53 order by id desc;\nselect * from opportunities where crm_configuration_id = 53 order by id desc;\nselect * from crm_profiles where crm_configuration_id = 53 order by id desc;\nselect * from crm_fields where crm_configuration_id = 53 order by id desc;\nselect * from crm_field_values where crm_field_id = 3341 order by id desc;\nselect * from crm_layouts where crm_configuration_id = 53 order by id desc;\nselect * from stages where crm_configuration_id = 53 order by id desc;\n\n\nselect * from crm_profiles where crm_configuration_id = 13;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 65\nand sa.provider = 'integration-app';\n\nselect * from contacts where crm_configuration_id = 13;\n\nselect * from social_accounts where sociable_id = 283;\n\nSELECT * FROM opportunities WHERE crm_provider_id = '006O400000E9bzeIAB';\n\nselect * from activity_providers where team_id = 65;\nSELECT * FROM activities WHERE crm_configuration_id IN (51, 52, 53);\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 65\n;\n\n# ***************************** STAGING ********************************************\nSELECT * FROM teams;\nSELECT * FROM teams WHERE id = 88;\nSELECT * FROM teams WHERE id = 89;\nselect * from team_settings where team_id = 89;\nSELECT * FROM users WHERE team_id = 89;\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 89;\n\nselect * from users;\nSELECT * FROM social_accounts WHERE sociable_id = 1761;\nSELECT * FROM crm_configurations WHERE id = 70;\nselect * from accounts where crm_configuration_id = 70 order by id desc;\nselect * from leads where crm_configuration_id = 70 order by id desc;\nselect * from contacts where crm_configuration_id = 70 order by id desc;\nselect * from opportunities where crm_configuration_id = 70 order by id desc;\nselect * from crm_profiles where crm_configuration_id = 70 order by id desc;\nselect * from crm_fields where crm_configuration_id = 70 order by id desc;\nselect * from crm_field_values where crm_field_id = 3536 order by id desc;\nselect * from crm_layouts where crm_configuration_id = 70 order by id desc;\nselect * from stages where crm_configuration_id = 70 order by id desc;\nselect * from business_processes where crm_configuration_id = 70 order by id desc;\nselect * from business_process_stages where business_process_id = 34;\n\nselect * from contacts where id = 10468;\n\nselect * from crm_layouts where crm_configuration_id = 70;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 388;\nSELECT * FROM crm_fields WHERE id IN (3533,3534,3535);\n\nselect * from activities where crm_configuration_id = 70\nand (account_id IS NOT NULL or lead_id IS NOT NULL or contact_id IS NOT NULL or opportunity_id IS NOT NULL) order by id desc;\n\nSELECT * FROM activities WHERE uuid_to_bin('2e10b60f-8a61-41c5-a3d4-28835353dc65') = uuid;\nSELECT * FROM activities where crm_configuration_id = 69 ;\n\nSELECT * FROM users WHERE email LIKE '%jiminny_web_sa2@jiminny.com%';\nSELECT * FROM activities WHERE uuid_to_bin('5a150c93-40fc-42ec-b3bd-c1d328e09f6e') = uuid;\nSELECT * FROM opportunities WHERE id = 385;\n\nselect * from participants p\njoin activities a on p.activity_id = a.id\nwhere a.crm_configuration_id = 70\nand (p.lead_id IS NOT NULL or p.contact_id IS NOT NULL);\nSELECT * FROM participants WHERE id = 1013638;\n\nselect * from teams where id = 90;\nselect * from users where team_id = 90;\nselect * from social_accounts where social_accounts.sociable_id IN (1960,1760);\nSELECT * FROM crm_profiles WHERE crm_configuration_id = 71;\nselect * from invitations where team_id = 90;\n\nselect * from crm_configurations where id = 71;\nselect * from accounts where crm_configuration_id = 71 order by id desc;\nselect * from leads where crm_configuration_id = 71 order by id desc;\nselect * from contacts where crm_configuration_id = 71 order by id desc;\nselect * from opportunities where crm_configuration_id = 71 order by id desc;\nselect * from crm_profiles where crm_configuration_id = 71 order by id desc;\nselect * from crm_fields where crm_configuration_id = 71 order by id desc;\nselect * from crm_field_values where crm_field_id = 3341 order by id desc;\nselect * from crm_layouts where crm_configuration_id = 71 order by id desc;\nselect * from stages where crm_configuration_id = 71 order by id desc;\n\nselect * from users order by secondary_email desc;\nselect u.id, u.email, u.status, sa.id, sa.provider_user_id from social_accounts sa\n join users u on sa.sociable_id = u.id\nwhere sa.provider = 'google' and u.email LIKE 'aneliya%';\n\nselect * from failed_jobs order by id desc;\n\nselect * from users where email = 'ben.allwright@learningpeople.co.uk' or secondary_email = 'ben.allwright@learningpeople.co.uk';\n\nselect * from teams;\nSELECT * FROM crm_profiles WHERE crm_configuration_id = 39;\nSELECT * FROM crm_fields WHERE crm_configuration_id = 39 and object_type = 'task';\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 1\nand sa.provider = 'salesforce';\n\n# ************************************************************************************\nSELECT * FROM activities WHERE uuid_to_bin('c38b3895-fd0f-4b1f-9fb2-c170dba137c6') = uuid;\nSELECT * FROM crm_configurations WHERE id = 70;\n\nselect * from teams where id = 1;\nselect * from groups where team_id = 1;\nselect * from users where team_id = 1;\n\nselect o.id, o.name,o.close_date, u.id, u.name, u.group_id, r.id, r.display_name, g.name, g.scope from opportunities o\njoin users u on o.user_id = u.id\njoin groups g on u.group_id = g.id\njoin role_user ru on u.id = ru.user_id\njoin roles r on ru.role_id = r.id\nwhere o.crm_configuration_id = 39 and close_date > '2024-01-01 00:00:00';\n\nselect * from role_user where user_id = 143;\nselect * from roles;\n\nselect * from role_user;\nselect * from groups where id = 9;\nselect * from scope_groups where group_id = 9;\n\n# ************************************************************************************\nselect * from teams where id = 36;\nselect * from crm_configurations;\nSELECT * FROM social_accounts WHERE sociable_id = 121;\n\nhttps://crmsandbox.zoho.com/crm/jiminnyw4/tab/Leads/4776201000005049105\nhttps://crmsandbox.zoho.com/crm/\n\nhttps://crm.zoho.com/crm/org3469620/tab/Leads/230045000229559080\n https://crm.zoho.com/crm/\n org3469620\n\nSELECT * FROM activities WHERE uuid_to_bin('03382d20-c8bc-48e7-a3d4-90b52fa5ceab') = uuid;\n\nselect * from users where email LIKE \"%mobile_automation_%\";\nselect * from social_accounts where sociable_id IN (2228);\nselect * from crm_profiles where user_id IN (2222,2223,2226,2227);\n\nselect * from teams order by id desc;\nSELECT * FROM users WHERE id = 2229;\nSELECT * FROM crm_profiles WHERE user_id = 2229;\nselect * from opportunities where crm_configuration_id = 88;\nselect * from crm_fields where crm_configuration_id = 88;\nselect * from crm_profiles where crm_configuration_id = 88;\n\nSELECT * FROM teams WHERE id = 1;\n\nSELECT * FROM users WHERE id = 143;\nSELECT * FROM users WHERE uuid_to_bin('fde193d3-06a2-4e1a-8895-62b94039215d') = uuid;\nSELECT * FROM teams WHERE uuid_to_bin('73385071-a756-42ae-9c73-8b53f2309467') = uuid;\n\nhttps://app.staging.jiminny.com/ondemand?\n min_duration=1\n &\n only_recorded=1\n &\n user_id%5B%5D=641f1acb-16b8-42d1-8726-df52979dad0e\n &\n sequence_number=2\n\n select * from users where team_id = 1 and email like '%stoyan%'\n\nselect * from coaching_feedbacks;\n\nselect * from teams;\nSELECT * FROM users WHERE team_id = 36;\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 19\nand sa.provider = 'pipedrive';\n\nselect * from users where id = 143;\n\nSELECT * FROM users WHERE uuid_to_bin('73180eeb-33de-4065-977d-ccbe0e6c94fc') = uuid;\nSELECT * FROM teams WHERE uuid_to_bin('73180eeb-33de-4065-977d-ccbe0e6c94fc') = uuid;\nSELECT * FROM activity_shares WHERE uuid_to_bin('73180eeb-33de-4065-977d-ccbe0e6c94fc') = uuid;\n\nselect * from users where team_id = 2;\nselect * from activities where crm_configuration_id = 39\nand activities.scheduled_start_time BETWEEN '2025-04-09 00:00:00' AND '2025-04-09 23:59:59'\nAND user_id = 143\norder by id desc;\n\n# ************************************************************************************\nselect * from teams where id = 142; # 2312, 126\nselect * from team_settings;\nselect * from users where team_id = 142; # 21642\nSELECT * FROM social_accounts WHERE sociable_id = 21642;\nSELECT * FROM crm_profiles cp join users u ON u.id = cp.user_id WHERE team_id = 142;\nselect * from crm_profiles where id IN (93);\nselect * from invitations;\nselect * from team_features where team_id = 1;\n\nSELECT * FROM crm_configurations WHERE id = 126;\nselect * from accounts where crm_configuration_id = 126 order by id desc;\nselect * from leads where crm_configuration_id = 126 order by id desc;\nselect * from contacts where crm_configuration_id = 126 order by id desc;\nselect * from opportunities where crm_configuration_id = 126 order by id desc;\nselect * from crm_profiles where crm_configuration_id = 126 order by id desc;\nselect * from crm_fields where crm_configuration_id = 126 # 11060\n# and type IN ('picklist', 'status')\n# and object_type = 'task'\norder by id desc;\n# 5731,5732,5733\nselect DISTINCT crm_field_id from crm_field_values where crm_field_id IN (11151,12239,12215,12185,12175,12165,12144,12137,12127,12109,12107,12105,12103,12092,12037,12005,12003,11987,11969,11958,11951,11942,11931,11924,11921,11917,11915,11901,11893,11883,11872,11870,11868,11866,11839,11833,11821,11793,11780,11777,11769,11757,11737,11735,11656,11645,11638,11629,11618,11611,11602,11591,11584,11581,11558,11544,11543,11534,11532,11529,11527,11503,11497,11493,11488,11470,11468,11457,11455,11397,11387,11372,11363,11348,11323,11318,11309,11301,11300,11292,11290,11286,11284,11256,11252,11242,11237,11233,11219,11176,11160) order by id desc;\nselect * from crm_layouts where crm_configuration_id = 126 order by id desc;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id in (300,299,298);\nselect * from stages where crm_configuration_id = 126 order by id desc;\nselect * from business_processes where crm_configuration_id = 126 order by id desc;\nselect * from business_process_stages where business_process_id IN (76,75,74,73);\nselect * from playbooks where team_id = 142;\nselect * from playbook_layouts where playbook_id IN (108);\nSELECT * FROM playbook_categories WHERE playbook_id IN (108);\n\nselect * from teams where id = 130;\nSELECT * FROM social_accounts WHERE sociable_id = 2291;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 2\nand sa.provider = 'hubspot';\n\nSELECT * FROM activities\n WHERE crm_configuration_id = 110;\n\nselect * from teams;\nselect * from crm_configurations;\n\nSELECT * FROM activities WHERE id = 628773;\nSELECT * FROM crm_profiles WHERE user_id = 1460;\nSELECT * FROM social_accounts WHERE sociable_id = 2291;\n\nselect * from teams;\nselect ru.*, pr.*, p.* from users u join role_user ru on ru.user_id = u.id\njoin permission_role pr on pr.role_id = ru.role_id\n join permissions p on p.id = pr.permission_id\nwhere team_id = 495 and p.name IN ('dial');\n\nselect * from teams where id = 145;\nselect * from crm_configurations where id = 129;\nselect * from social_accounts where sociable_id = 2317;\nSELECT * FROM activities WHERE uuid_to_bin('8dbab184-a333-4268-ad57-fb41f8d53a9a') = uuid;\n\nselect * from teams where id = 1;\nSELECT * FROM crm_layouts WHERE crm_configuration_id = 39;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 280;\nSELECT * FROM crm_layout_entities WHERE id = 5507;\nSELECT * FROM crm_fields WHERE crm_configuration_id = 39 and object_type IN ('event');\n\nselect * from teams;\nselect * from activities where crm_configuration_id = 14;\n\nSELECT * FROM social_accounts where provider = 'copper';\n\nselect * from activities where id = 628467;\nselect * from participants where activity_id = 628467;\n\nSELECT * FROM contacts WHERE id = 3969;\nSELECT * FROM accounts WHERE id = 177;\n\nSELECT * FROM activities WHERE uuid_to_bin('4eb54c77-cfa3-2bd4-84a7-9ed46a21c988') = uuid;\n\n# ********************* BH\nselect * from teams where id = 36;\nSELECT * FROM crm_configurations WHERE id = 21;\nselect * from activities where crm_configuration_id = 21 and id = 607901;\nselect * from activities where crm_configuration_id = 21;\n\nselect * roles;\nselect * from permissions;\nselect * from permission_role where permission_id = 226;\n\nselect * from migrations order by id desc;\n\n# mercury\n# neptune\n# earth\n\nselect * from teams;\nselect * from teams where id = 19;\nselect * from teams where id = 27;\nselect * from users where team_id = 27;\nSELECT * FROM crm_configurations WHERE id = 42;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 19\nand sa.provider = 'pipedrive';\n\nselect * from activities where id = 631461;\nSELECT * FROM crm_field_values WHERE crm_field_id = 180;\n\nselect * from teams where id = 2;\nSELECT * FROM social_accounts WHERE sociable_id = 89;\n\nSELECT * FROM activities WHERE uuid_to_bin('ba0c029a-bc14-4e17-8603-64174acebcbb') = uuid; # 634273\nselect * from activity_summary_logs where activity_id = 634273;\n\nselect * from sidekick_settings where team_id = 2;\n\nselect * from teams; # 2, 2\nSELECT * FROM crm_configurations WHERE team_id = 2; # 2\nselect * from team_features where team_id = 2;\nselect * from features;\nSELECT * FROM opportunities WHERE crm_configuration_id = 2 and crm_provider_id = '51317301383';\nSELECT * FROM opportunities WHERE crm_configuration_id = 2 order by id desc;\n\nselect * from automated_reports order by id desc;\nselect * from automated_report_results order by id desc;\nselect * from users where team_id = 1 and id IN (7160, 3248);\nselect * from migrations order by id desc;\n\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 1 and sa.provider = 'salesforce';\n\nselect * from teams where id = 1;\nselect * from groups g JOIN playbooks p on g.playbook_id = p.id where g.team_id = 1;\nselect * from groups where id = 565;\nselect * from playbooks where team_id = 1;\nselect * from playbooks where id = 175;\nselect * from playbook_categories where playbook_id = 175;\nselect * from users where team_id = 1;\nselect * from users where id = 7160;\nselect * from crm_profiles where user_id = 7160;\nselect * from features;\nselect\n *\n# id, uuid, type, provider, playbook_category_id, user_id, lead_id, contact_id, account_id, opportunity_id, stage_id,\n# crm_configuration_id, crm_provider_id, transcription_id, status\nfrom activities where crm_configuration_id = 1 and type = 'conference'\n# and crm_provider_id IS NOT NULL\nand provider != 'uploader' and actual_start_time IS NOT NULL\nORDER by id desc;\nselect * from activities where id = 54747783; # 00UO400000pCzojMAC\n\nselect p.id, p.activity_type, pc.id, pc.name\nFROM playbooks p\njoin playbook_categories pc on p.id = pc.playbook_id\nwhere p.team_id = 1 and p.activity_type = 'event';\n\nSELECT * FROM crm_fields WHERE crm_configuration_id = 1 and object_type = 'event';\nSELECT * FROM crm_field_values WHERE crm_field_id = 4;\n\nselect * from crm_layouts cl join playbook_layouts pl on cl.id = pl.layout_id\nwhere crm_configuration_id = 1 and pl.playbook_id = 175;\n\nselect * from teams;\nSELECT r.* FROM automated_reports r\njoin teams t on r.team_id = t.id\nWHERE r.frequency = 'daily'\n and r.status = 1\nAND t.status = 'active'\nAND (r.expires_at >= now() OR r.expires_at IS NULL);\n\nselect * from automated_report_results where report_id IN (18, 33);\n\nselect * from activity_searches where id = 10932;\nselect * from activity_search_filters where activity_search_id = 10932;\nselect * from automated_reports;\nselect * from automated_report_results where report_id IN (34, 35);","depth":4,"value":"SELECT * FROM teams WHERE id = 1;\n\nselect * from crm_layouts where crm_configuration_id = 39;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 283;\nSELECT * FROM crm_fields WHERE id = 2234;\nSELECT * FROM crm_field_values WHERE crm_field_id = 2234;\n\nselect * from crm_profiles where user_id = 143;\n\nselect * from record_types where crm_configuration_id = 39; # 0121K000001MHElQAO,0121K000001MHEqQAO\nselect * from business_processes where crm_configuration_id = 39;\n# 01941000000H669AAC, 01941000000H66JAAS\n\nselect * from record_type_field_values\n where record_type_id IN (24);\n\nselect * from crm_field_values where id IN (2730);\n\nselect * from crm_configurations where id = 39;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 1\nand sa.provider = 'salesforce'; #1035\n\n\nselect * from users where team_id = 1; # 222 group 3\nSELECT * FROM activities WHERE user_id = 222 order by id desc;\nselect * from sidekick_settings where team_id = 1;\nselect * from teams where id = 1;\nselect * from team_features where team_id = 1;\n\nselect * from activities where crm_configuration_id = 2\nand provider = 'ms-teams' and id = 608765;\n\nSELECT * FROM activities WHERE crm_configuration_id = 2 and crm_provider_id = '59523413338';\n\nselect * from sidekick_settings where team_id = 2;\n\nSELECT * FROM activities WHERE id = 608660;\nselect * from activity_summary_logs where activity_id = 608660;\nselect * from ai_prompts where transcription_id = 11214;\n\n# ********************************************************************************************************\nSELECT * FROM activities WHERE uuid_to_bin('ed78a437-2804-450e-ab2f-56ab1c641346') = uuid;\n# id: 608818, crm: 59628809737\nSELECT * FROM activities WHERE uuid_to_bin('36b06e55-afdd-4782-8dee-c624cd0af191') = uuid;\n# id: 608821, crm: 59632069252\nSELECT ce.start_time, ce.end_time, a.id, a.uuid, crm_provider_id, calendar_event_id, title,\nplaybook_category_id, user_id, lead_id, contact_id, account_id, opportunity_id,\nscheduled_start_time, scheduled_end_time, actual_start_time, actual_end_time, a.created_at\nFROM activities a\njoin calendar_events ce on a.calendar_event_id = ce.id\nWHERE a.id IN (608818, 608821);\n\nselect * from users where team_id = 1;\nselect * from team_settings where team_id = 1;\nselect * from crm_profiles where crm_configuration_id = 39 order by user_id;\n\nselect * from team_features where team_id = 1;\n\nselect * from users where team_id = 2;\n\nSELECT * FROM activities WHERE uuid_to_bin('ec7647e9-5225-458b-b475-f31aa2769204') = uuid; # 612639\n# Preslava N. Ivanova, grou id 3\n\nSELECT * FROM opportunities WHERE uuid_to_bin('a2928fe5-aec5-46cb-85d9-7654c89e46a6') = uuid;\n\nselect * from activities where opportunity_id = 344 and actual_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00';\n\nselect\n a.id,\n a.type,\n a.scheduled_start_time,\n a.actual_start_time,\n a.created_at,\n a.opportunity_id,\n a.status\nFROM activities a\nWHERE opportunity_id = 344\nand status IN ('completed', 'received', 'delivered')\nand (\n (a.actual_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00')\nOR (a.created_at between '2024-10-11 00:00:00' and '2024-10-12 00:00:00')\nOR (a.scheduled_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00'))\n;\n\nSELECT * FROM users WHERE id = 222;\n\nSELECT * FROM crm_profiles WHERE user_id = 222;\nselect * from crm_layouts where crm_configuration_id = 39;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 281;\n\nselect * from group_deal_risk_types;\n\nselect * from opportunities where team_id = 1;\n\nSELECT * FROM opportunities WHERE id = 315;\nSELECT * FROM crm_field_data WHERE object_id = 315;\nselect * from crm_field_data where object_id = 260;\n\nselect * from generic_ai_prompts where subject_id = 315;\n\nselect * from teams; # 36, 21, 121, james.graham@bullhorn.jiminny.com\nSELECT * FROM social_accounts WHERE sociable_id = 121 and provider = 'bullhorn';\n\n# ************************************************************************************\nselect * from teams where id = 1;\nselect * from crm_configurations where id = 39;\nselect * from users where team_id = 1;\nselect u.email, cp.* from users u\njoin crm_profiles cp on u.id = cp.user_id\nwhere u.team_id = 1;\n# 1 - 00541000004281rAAA\n# 204 - 0052g000003freeAAA\n# 429 - 0052g000003qGOiAAM\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 1\nand sa.provider = 'salesforce';\n\nselect * from activities where type = 'softphone'\nand created_at > '2024-12-11 15:24:36' order by id desc;\n\nselect * from activity_providers where team_id = 1;\nselect * from activity_provider_users where activity_provider_id = 328;\n\nselect * from opportunities where crm_configuration_id = 39\nAND account_id = 178 AND is_closed = false\norder by created_at DESC;\n\nselect * from contacts where id = 3952;\nselect * from accounts where id = 178;\n\n# ************************************************************************************\nselect * from teams where id = 36;\nselect * from crm_configurations where id = 21;\nselect * from users where team_id = 36;\nselect u.email, cp.* from users u\njoin crm_profiles cp on u.id = cp.user_id\nwhere u.team_id = 36;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 36\nand sa.provider = 'bullhorn';\n\nselect * from social_accounts where id = 348;\nUPDATE social_accounts SET\nprovider_user_token = '21442_6802599_91:41179a58-21e7-4d7c-ad58-56bb666b2f65',\nprovider_refresh_token = '21442_6802599_91:01c6b335-3f2a-42e4-85ff-8a08fa65fceb',\nexpires = 1733998131,\nstate = 'connected'\nWHERE id = 348;\n\n# ************************************************************************************\nselect * from teams where id = 31;\nselect * from crm_configurations where id = 18;\n\nselect * from users where team_id = 31; # 257\nselect u.email, cp.* from users u\njoin crm_profiles cp on u.id = cp.user_id\nwhere u.team_id = 31;\n\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 31\nand sa.provider = 'close';\n\nselect * from contacts where crm_configuration_id = 18;\n\n# ********************** NEPTUNE **************************************************************\nselect * from teams;\nselect * from users where id IN (1030, 1035, 1052);\nselect * from crm_configurations;\n\nselect * from users where team_id = 65; # 257\nselect * from team_settings where team_id = 65; # 257\nselect * from invitations where team_id = 65; # 257\nselect * from users where email = 'integration-account@jiminny.com'; # 257\nselect u.email, cp.* from users u\njoin crm_profiles cp on u.id = cp.user_id\nwhere u.team_id = 65;\n\nselect * from crm_configurations where id = 53;\nselect * from accounts where crm_configuration_id = 53 order by id desc;\nselect * from leads where crm_configuration_id = 53 order by id desc;\nselect * from contacts where crm_configuration_id = 53 order by id desc;\nselect * from opportunities where crm_configuration_id = 53 order by id desc;\nselect * from crm_profiles where crm_configuration_id = 53 order by id desc;\nselect * from crm_fields where crm_configuration_id = 53 order by id desc;\nselect * from crm_field_values where crm_field_id = 3341 order by id desc;\nselect * from crm_layouts where crm_configuration_id = 53 order by id desc;\nselect * from stages where crm_configuration_id = 53 order by id desc;\n\n\nselect * from crm_profiles where crm_configuration_id = 13;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 65\nand sa.provider = 'integration-app';\n\nselect * from contacts where crm_configuration_id = 13;\n\nselect * from social_accounts where sociable_id = 283;\n\nSELECT * FROM opportunities WHERE crm_provider_id = '006O400000E9bzeIAB';\n\nselect * from activity_providers where team_id = 65;\nSELECT * FROM activities WHERE crm_configuration_id IN (51, 52, 53);\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 65\n;\n\n# ***************************** STAGING ********************************************\nSELECT * FROM teams;\nSELECT * FROM teams WHERE id = 88;\nSELECT * FROM teams WHERE id = 89;\nselect * from team_settings where team_id = 89;\nSELECT * FROM users WHERE team_id = 89;\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 89;\n\nselect * from users;\nSELECT * FROM social_accounts WHERE sociable_id = 1761;\nSELECT * FROM crm_configurations WHERE id = 70;\nselect * from accounts where crm_configuration_id = 70 order by id desc;\nselect * from leads where crm_configuration_id = 70 order by id desc;\nselect * from contacts where crm_configuration_id = 70 order by id desc;\nselect * from opportunities where crm_configuration_id = 70 order by id desc;\nselect * from crm_profiles where crm_configuration_id = 70 order by id desc;\nselect * from crm_fields where crm_configuration_id = 70 order by id desc;\nselect * from crm_field_values where crm_field_id = 3536 order by id desc;\nselect * from crm_layouts where crm_configuration_id = 70 order by id desc;\nselect * from stages where crm_configuration_id = 70 order by id desc;\nselect * from business_processes where crm_configuration_id = 70 order by id desc;\nselect * from business_process_stages where business_process_id = 34;\n\nselect * from contacts where id = 10468;\n\nselect * from crm_layouts where crm_configuration_id = 70;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 388;\nSELECT * FROM crm_fields WHERE id IN (3533,3534,3535);\n\nselect * from activities where crm_configuration_id = 70\nand (account_id IS NOT NULL or lead_id IS NOT NULL or contact_id IS NOT NULL or opportunity_id IS NOT NULL) order by id desc;\n\nSELECT * FROM activities WHERE uuid_to_bin('2e10b60f-8a61-41c5-a3d4-28835353dc65') = uuid;\nSELECT * FROM activities where crm_configuration_id = 69 ;\n\nSELECT * FROM users WHERE email LIKE '%jiminny_web_sa2@jiminny.com%';\nSELECT * FROM activities WHERE uuid_to_bin('5a150c93-40fc-42ec-b3bd-c1d328e09f6e') = uuid;\nSELECT * FROM opportunities WHERE id = 385;\n\nselect * from participants p\njoin activities a on p.activity_id = a.id\nwhere a.crm_configuration_id = 70\nand (p.lead_id IS NOT NULL or p.contact_id IS NOT NULL);\nSELECT * FROM participants WHERE id = 1013638;\n\nselect * from teams where id = 90;\nselect * from users where team_id = 90;\nselect * from social_accounts where social_accounts.sociable_id IN (1960,1760);\nSELECT * FROM crm_profiles WHERE crm_configuration_id = 71;\nselect * from invitations where team_id = 90;\n\nselect * from crm_configurations where id = 71;\nselect * from accounts where crm_configuration_id = 71 order by id desc;\nselect * from leads where crm_configuration_id = 71 order by id desc;\nselect * from contacts where crm_configuration_id = 71 order by id desc;\nselect * from opportunities where crm_configuration_id = 71 order by id desc;\nselect * from crm_profiles where crm_configuration_id = 71 order by id desc;\nselect * from crm_fields where crm_configuration_id = 71 order by id desc;\nselect * from crm_field_values where crm_field_id = 3341 order by id desc;\nselect * from crm_layouts where crm_configuration_id = 71 order by id desc;\nselect * from stages where crm_configuration_id = 71 order by id desc;\n\nselect * from users order by secondary_email desc;\nselect u.id, u.email, u.status, sa.id, sa.provider_user_id from social_accounts sa\n join users u on sa.sociable_id = u.id\nwhere sa.provider = 'google' and u.email LIKE 'aneliya%';\n\nselect * from failed_jobs order by id desc;\n\nselect * from users where email = 'ben.allwright@learningpeople.co.uk' or secondary_email = 'ben.allwright@learningpeople.co.uk';\n\nselect * from teams;\nSELECT * FROM crm_profiles WHERE crm_configuration_id = 39;\nSELECT * FROM crm_fields WHERE crm_configuration_id = 39 and object_type = 'task';\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 1\nand sa.provider = 'salesforce';\n\n# ************************************************************************************\nSELECT * FROM activities WHERE uuid_to_bin('c38b3895-fd0f-4b1f-9fb2-c170dba137c6') = uuid;\nSELECT * FROM crm_configurations WHERE id = 70;\n\nselect * from teams where id = 1;\nselect * from groups where team_id = 1;\nselect * from users where team_id = 1;\n\nselect o.id, o.name,o.close_date, u.id, u.name, u.group_id, r.id, r.display_name, g.name, g.scope from opportunities o\njoin users u on o.user_id = u.id\njoin groups g on u.group_id = g.id\njoin role_user ru on u.id = ru.user_id\njoin roles r on ru.role_id = r.id\nwhere o.crm_configuration_id = 39 and close_date > '2024-01-01 00:00:00';\n\nselect * from role_user where user_id = 143;\nselect * from roles;\n\nselect * from role_user;\nselect * from groups where id = 9;\nselect * from scope_groups where group_id = 9;\n\n# ************************************************************************************\nselect * from teams where id = 36;\nselect * from crm_configurations;\nSELECT * FROM social_accounts WHERE sociable_id = 121;\n\nhttps://crmsandbox.zoho.com/crm/jiminnyw4/tab/Leads/4776201000005049105\nhttps://crmsandbox.zoho.com/crm/\n\nhttps://crm.zoho.com/crm/org3469620/tab/Leads/230045000229559080\n https://crm.zoho.com/crm/\n org3469620\n\nSELECT * FROM activities WHERE uuid_to_bin('03382d20-c8bc-48e7-a3d4-90b52fa5ceab') = uuid;\n\nselect * from users where email LIKE \"%mobile_automation_%\";\nselect * from social_accounts where sociable_id IN (2228);\nselect * from crm_profiles where user_id IN (2222,2223,2226,2227);\n\nselect * from teams order by id desc;\nSELECT * FROM users WHERE id = 2229;\nSELECT * FROM crm_profiles WHERE user_id = 2229;\nselect * from opportunities where crm_configuration_id = 88;\nselect * from crm_fields where crm_configuration_id = 88;\nselect * from crm_profiles where crm_configuration_id = 88;\n\nSELECT * FROM teams WHERE id = 1;\n\nSELECT * FROM users WHERE id = 143;\nSELECT * FROM users WHERE uuid_to_bin('fde193d3-06a2-4e1a-8895-62b94039215d') = uuid;\nSELECT * FROM teams WHERE uuid_to_bin('73385071-a756-42ae-9c73-8b53f2309467') = uuid;\n\nhttps://app.staging.jiminny.com/ondemand?\n min_duration=1\n &\n only_recorded=1\n &\n user_id%5B%5D=641f1acb-16b8-42d1-8726-df52979dad0e\n &\n sequence_number=2\n\n select * from users where team_id = 1 and email like '%stoyan%'\n\nselect * from coaching_feedbacks;\n\nselect * from teams;\nSELECT * FROM users WHERE team_id = 36;\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 19\nand sa.provider = 'pipedrive';\n\nselect * from users where id = 143;\n\nSELECT * FROM users WHERE uuid_to_bin('73180eeb-33de-4065-977d-ccbe0e6c94fc') = uuid;\nSELECT * FROM teams WHERE uuid_to_bin('73180eeb-33de-4065-977d-ccbe0e6c94fc') = uuid;\nSELECT * FROM activity_shares WHERE uuid_to_bin('73180eeb-33de-4065-977d-ccbe0e6c94fc') = uuid;\n\nselect * from users where team_id = 2;\nselect * from activities where crm_configuration_id = 39\nand activities.scheduled_start_time BETWEEN '2025-04-09 00:00:00' AND '2025-04-09 23:59:59'\nAND user_id = 143\norder by id desc;\n\n# ************************************************************************************\nselect * from teams where id = 142; # 2312, 126\nselect * from team_settings;\nselect * from users where team_id = 142; # 21642\nSELECT * FROM social_accounts WHERE sociable_id = 21642;\nSELECT * FROM crm_profiles cp join users u ON u.id = cp.user_id WHERE team_id = 142;\nselect * from crm_profiles where id IN (93);\nselect * from invitations;\nselect * from team_features where team_id = 1;\n\nSELECT * FROM crm_configurations WHERE id = 126;\nselect * from accounts where crm_configuration_id = 126 order by id desc;\nselect * from leads where crm_configuration_id = 126 order by id desc;\nselect * from contacts where crm_configuration_id = 126 order by id desc;\nselect * from opportunities where crm_configuration_id = 126 order by id desc;\nselect * from crm_profiles where crm_configuration_id = 126 order by id desc;\nselect * from crm_fields where crm_configuration_id = 126 # 11060\n# and type IN ('picklist', 'status')\n# and object_type = 'task'\norder by id desc;\n# 5731,5732,5733\nselect DISTINCT crm_field_id from crm_field_values where crm_field_id IN (11151,12239,12215,12185,12175,12165,12144,12137,12127,12109,12107,12105,12103,12092,12037,12005,12003,11987,11969,11958,11951,11942,11931,11924,11921,11917,11915,11901,11893,11883,11872,11870,11868,11866,11839,11833,11821,11793,11780,11777,11769,11757,11737,11735,11656,11645,11638,11629,11618,11611,11602,11591,11584,11581,11558,11544,11543,11534,11532,11529,11527,11503,11497,11493,11488,11470,11468,11457,11455,11397,11387,11372,11363,11348,11323,11318,11309,11301,11300,11292,11290,11286,11284,11256,11252,11242,11237,11233,11219,11176,11160) order by id desc;\nselect * from crm_layouts where crm_configuration_id = 126 order by id desc;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id in (300,299,298);\nselect * from stages where crm_configuration_id = 126 order by id desc;\nselect * from business_processes where crm_configuration_id = 126 order by id desc;\nselect * from business_process_stages where business_process_id IN (76,75,74,73);\nselect * from playbooks where team_id = 142;\nselect * from playbook_layouts where playbook_id IN (108);\nSELECT * FROM playbook_categories WHERE playbook_id IN (108);\n\nselect * from teams where id = 130;\nSELECT * FROM social_accounts WHERE sociable_id = 2291;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 2\nand sa.provider = 'hubspot';\n\nSELECT * FROM activities\n WHERE crm_configuration_id = 110;\n\nselect * from teams;\nselect * from crm_configurations;\n\nSELECT * FROM activities WHERE id = 628773;\nSELECT * FROM crm_profiles WHERE user_id = 1460;\nSELECT * FROM social_accounts WHERE sociable_id = 2291;\n\nselect * from teams;\nselect ru.*, pr.*, p.* from users u join role_user ru on ru.user_id = u.id\njoin permission_role pr on pr.role_id = ru.role_id\n join permissions p on p.id = pr.permission_id\nwhere team_id = 495 and p.name IN ('dial');\n\nselect * from teams where id = 145;\nselect * from crm_configurations where id = 129;\nselect * from social_accounts where sociable_id = 2317;\nSELECT * FROM activities WHERE uuid_to_bin('8dbab184-a333-4268-ad57-fb41f8d53a9a') = uuid;\n\nselect * from teams where id = 1;\nSELECT * FROM crm_layouts WHERE crm_configuration_id = 39;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 280;\nSELECT * FROM crm_layout_entities WHERE id = 5507;\nSELECT * FROM crm_fields WHERE crm_configuration_id = 39 and object_type IN ('event');\n\nselect * from teams;\nselect * from activities where crm_configuration_id = 14;\n\nSELECT * FROM social_accounts where provider = 'copper';\n\nselect * from activities where id = 628467;\nselect * from participants where activity_id = 628467;\n\nSELECT * FROM contacts WHERE id = 3969;\nSELECT * FROM accounts WHERE id = 177;\n\nSELECT * FROM activities WHERE uuid_to_bin('4eb54c77-cfa3-2bd4-84a7-9ed46a21c988') = uuid;\n\n# ********************* BH\nselect * from teams where id = 36;\nSELECT * FROM crm_configurations WHERE id = 21;\nselect * from activities where crm_configuration_id = 21 and id = 607901;\nselect * from activities where crm_configuration_id = 21;\n\nselect * roles;\nselect * from permissions;\nselect * from permission_role where permission_id = 226;\n\nselect * from migrations order by id desc;\n\n# mercury\n# neptune\n# earth\n\nselect * from teams;\nselect * from teams where id = 19;\nselect * from teams where id = 27;\nselect * from users where team_id = 27;\nSELECT * FROM crm_configurations WHERE id = 42;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 19\nand sa.provider = 'pipedrive';\n\nselect * from activities where id = 631461;\nSELECT * FROM crm_field_values WHERE crm_field_id = 180;\n\nselect * from teams where id = 2;\nSELECT * FROM social_accounts WHERE sociable_id = 89;\n\nSELECT * FROM activities WHERE uuid_to_bin('ba0c029a-bc14-4e17-8603-64174acebcbb') = uuid; # 634273\nselect * from activity_summary_logs where activity_id = 634273;\n\nselect * from sidekick_settings where team_id = 2;\n\nselect * from teams; # 2, 2\nSELECT * FROM crm_configurations WHERE team_id = 2; # 2\nselect * from team_features where team_id = 2;\nselect * from features;\nSELECT * FROM opportunities WHERE crm_configuration_id = 2 and crm_provider_id = '51317301383';\nSELECT * FROM opportunities WHERE crm_configuration_id = 2 order by id desc;\n\nselect * from automated_reports order by id desc;\nselect * from automated_report_results order by id desc;\nselect * from users where team_id = 1 and id IN (7160, 3248);\nselect * from migrations order by id desc;\n\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 1 and sa.provider = 'salesforce';\n\nselect * from teams where id = 1;\nselect * from groups g JOIN playbooks p on g.playbook_id = p.id where g.team_id = 1;\nselect * from groups where id = 565;\nselect * from playbooks where team_id = 1;\nselect * from playbooks where id = 175;\nselect * from playbook_categories where playbook_id = 175;\nselect * from users where team_id = 1;\nselect * from users where id = 7160;\nselect * from crm_profiles where user_id = 7160;\nselect * from features;\nselect\n *\n# id, uuid, type, provider, playbook_category_id, user_id, lead_id, contact_id, account_id, opportunity_id, stage_id,\n# crm_configuration_id, crm_provider_id, transcription_id, status\nfrom activities where crm_configuration_id = 1 and type = 'conference'\n# and crm_provider_id IS NOT NULL\nand provider != 'uploader' and actual_start_time IS NOT NULL\nORDER by id desc;\nselect * from activities where id = 54747783; # 00UO400000pCzojMAC\n\nselect p.id, p.activity_type, pc.id, pc.name\nFROM playbooks p\njoin playbook_categories pc on p.id = pc.playbook_id\nwhere p.team_id = 1 and p.activity_type = 'event';\n\nSELECT * FROM crm_fields WHERE crm_configuration_id = 1 and object_type = 'event';\nSELECT * FROM crm_field_values WHERE crm_field_id = 4;\n\nselect * from crm_layouts cl join playbook_layouts pl on cl.id = pl.layout_id\nwhere crm_configuration_id = 1 and pl.playbook_id = 175;\n\nselect * from teams;\nSELECT r.* FROM automated_reports r\njoin teams t on r.team_id = t.id\nWHERE r.frequency = 'daily'\n and r.status = 1\nAND t.status = 'active'\nAND (r.expires_at >= now() OR r.expires_at IS NULL);\n\nselect * from automated_report_results where report_id IN (18, 33);\n\nselect * from activity_searches where id = 10932;\nselect * from activity_search_filters where activity_search_id = 10932;\nselect * from automated_reports;\nselect * from automated_report_results where report_id IN (34, 35);","role_description":"text entry area","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.088194445,"height":0.027777778},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"102","depth":4,"role_description":"text"},{"role":"AXStaticText","text":"3","depth":4,"role_description":"text"},{"role":"AXStaticText","text":"34","depth":4,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Services\\Kiosk\\AutomatedReports;\n\nuse Carbon\\CarbonImmutable;\nuse Carbon\\CarbonInterface;\nuse Carbon\\Exceptions\\InvalidFormatException;\nuse DateTime;\nuse DateTimeInterface;\nuse DateTimeZone;\nuse Illuminate\\Contracts\\Bus\\Dispatcher as BusDispatcher;\nuse Illuminate\\Database\\Eloquent\\Builder;\nuse Illuminate\\Support\\Carbon;\nuse Illuminate\\Support\\Collection;\nuse Illuminate\\Support\\Facades\\Log;\nuse Illuminate\\Support\\Facades\\Storage;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinition\\InputTypeEnum;\nuse Jiminny\\Component\\AskAnything\\AskAnythingPromptService;\nuse Jiminny\\Component\\AskAnything\\Dtos\\AskAnythingPromptDto;\nuse Jiminny\\Component\\UrlGenerator\\Webhook;\nuse Jiminny\\Contracts\\Repositories\\PlaybookCategoryRepository;\nuse Jiminny\\Contracts\\Repositories\\TeamRepository;\nuse Jiminny\\Contracts\\Repositories\\UserRepository;\nuse Jiminny\\Exceptions\\ApplicationException;\nuse Jiminny\\Exceptions\\InvalidArgumentException;\nuse Jiminny\\Exceptions\\ModelNotFoundException;\nuse Jiminny\\Jobs\\AutomatedReports\\RequestGenerateReportJob;\nuse Jiminny\\Models\\Activity\\Search;\nuse Jiminny\\Models\\AskAnything\\AskAnythingPrompt;\nuse Jiminny\\Models\\AskAnything\\AskAnythingPromptTarget;\nuse Jiminny\\Models\\AutomatedReport;\nuse Jiminny\\Models\\AutomatedReportResult;\nuse Jiminny\\Models\\Contracts\\UserContract;\nuse Jiminny\\Models\\Feature\\FeatureEnum;\nuse Jiminny\\Models\\Team;\nuse Jiminny\\Models\\User;\nuse Jiminny\\Repositories\\AskAnythingRepository;\nuse Jiminny\\Repositories\\AutomatedReportsRepository;\nuse Jiminny\\Repositories\\GroupRepository;\nuse Jiminny\\Repositories\\SearchRepository;\nuse Jiminny\\Repositories\\StageRepository;\nuse Throwable;\n\nclass AutomatedReportsService\n{\n public const string TYPE_LOSS_ANALYSIS = 'loss_analysis';\n public const string TYPE_ASK_JIMINNY = 'ask_jiminny';\n\n /**\n * Standard report types (used by kiosk for existing automated reports).\n */\n // @TODO this will add filter, however if we need to control feature by FF we need conditional logic\n public const array TYPES = [\n ['id' => 'exec_summary', 'name' => 'Exec Summary'],\n ['id' => 'coaching_profiles', 'name' => 'Coaching Profiles'],\n ['id' => 'product_feedback', 'name' => 'Product Feedback'],\n ['id' => self::TYPE_LOSS_ANALYSIS, 'name' => 'Loss Analysis'],\n// ['id' => 'questions', 'name' => 'Questions'],\n// ['id' => 'statistical_quant', 'name' => 'Statistical Quantitative'],\n ];\n\n public const array ALL_TYPES = [\n ...self::TYPES,\n ['id' => self::TYPE_ASK_JIMINNY, 'name' => 'Ask Jiminny'],\n ];\n\n public const string FREQUENCY_DAILY = 'daily';\n public const string FREQUENCY_WEEKLY = 'weekly';\n public const string FREQUENCY_MONTHLY = 'monthly';\n public const string FREQUENCY_QUARTERLY = 'quarterly';\n public const string FREQUENCY_ONE_OFF = 'one_off';\n\n /**\n * Frequencies for standard (non-Ask Jiminny) reports.\n */\n public const array FREQUENCIES = [\n ['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],\n ['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],\n ['id' => self::FREQUENCY_QUARTERLY, 'name' => 'Quarterly'],\n ['id' => self::FREQUENCY_ONE_OFF, 'name' => 'One-off'],\n ];\n\n /**\n * Frequencies for Ask Jiminny reports.\n */\n public const array ASK_JIMINNY_FREQUENCIES = [\n ['id' => self::FREQUENCY_DAILY, 'name' => 'Daily'],\n ['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],\n ['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],\n ];\n\n public const string MEDIA_TYPE_PDF = 'pdf';\n public const string MEDIA_TYPE_PODCAST = 'podcast';\n public const array MEDIA_TYPES = [self::MEDIA_TYPE_PDF, self::MEDIA_TYPE_PODCAST];\n public const array MEDIA_TYPE_OBJECT_PDF = ['id' => self::MEDIA_TYPE_PDF, 'name' => 'PDF'];\n public const array MEDIA_TYPE_OBJECT_PODCAST = ['id' => self::MEDIA_TYPE_PODCAST, 'name' => 'Podcast'];\n public const array MEDIA_TYPE_OBJECTS = [self::MEDIA_TYPE_OBJECT_PDF, self::MEDIA_TYPE_OBJECT_PODCAST];\n\n public const array CALL_TYPE_CONFERENCE = ['id' => 'conference', 'name' => 'Conference'];\n public const array CALL_TYPE_DIALER = ['id' => 'dialer', 'name' => 'Dialer'];\n public const int SENT_REPORT_AT_HOURS = 5;\n public const string PDF_KEY = 'pdf';\n public const string AUDIO_KEY = 'audio';\n\n private const array ALL_FREQUENCIES = [\n ['id' => self::FREQUENCY_DAILY, 'name' => 'Daily'],\n ['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],\n ['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],\n ['id' => self::FREQUENCY_QUARTERLY, 'name' => 'Quarterly'],\n ['id' => self::FREQUENCY_ONE_OFF, 'name' => 'One-off'],\n ];\n private const string S3_DIR = 'reports';\n private const array FILE_EXTENSIONS_VARIANTS = ['html', 'MD', 'pdf'];\n private const array FILE_PODCAST_EXTENSIONS_VARIANTS = ['json', 'mp3', 'ssml'];\n\n public function __construct(\n private readonly TeamRepository $teamRepository,\n private readonly GroupRepository $groupRepository,\n private readonly UserRepository $userRepository,\n private readonly StageRepository $stageRepository,\n private readonly DealStagesService $dealStagesService,\n private readonly RecipientsService $recipientsService,\n private readonly AutomatedReportsRepository $automatedReportsRepository,\n private readonly Webhook $webhookService,\n private readonly BusDispatcher $dispatcher,\n private readonly ActivityTypeService $activityTypeService,\n private readonly PlaybookCategoryRepository $playbookCategoryRepository,\n private readonly AskAnythingPromptService $askAnythingPromptService,\n private readonly SearchRepository $activitySearchRepository,\n private readonly AskAnythingRepository $askAnythingRepository,\n ) {\n }\n\n public static function getTypes(): array\n {\n $types = self::TYPES;\n\n return array_map(static function ($type) {\n return $type['id'];\n }, $types);\n }\n\n public static function getCallTypes(): array\n {\n return array_map(static function ($callType) {\n return $callType['id'];\n }, [self::CALL_TYPE_CONFERENCE, self::CALL_TYPE_DIALER]);\n }\n\n public static function getFrequencies(): array\n {\n return array_map(static function ($frequency) {\n return $frequency['id'];\n }, self::FREQUENCIES);\n }\n\n // front-facing structure\n public function getReportEnabledFieldData(bool $value = false): array\n {\n return [\n 'id' => 'report_enabled',\n 'label' => '',\n 'inputType' => InputTypeEnum::TOGGLE,\n 'value' => $value,\n ];\n }\n\n // Organizations = Teams\n public function getOrganizationFieldData(?string $value = null, bool $shortVersion = false): array\n {\n $options = $this->getTeams();\n\n if ($shortVersion) {\n return [\n 'id' => 'organization',\n 'label' => 'Organization',\n 'options' => $options,\n ];\n }\n\n return [\n 'id' => 'organization',\n 'label' => 'Organization',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => $options,\n 'value' => $value,\n 'dependencies' => [\n 'teams',\n 'deal_stage_at_call',\n 'current_deal_stage',\n 'recipients',\n ActivityTypeService::PLAYBOOK_CATEGORIES_KEY,\n ],\n 'dependsOn' => [],\n ];\n }\n\n // Teams = Groups\n public function getTeamFieldData(array $options = [], array $value = [], bool $shortVersion = false): array\n {\n if ($shortVersion) {\n return [\n 'id' => 'teams',\n 'label' => 'Team',\n 'options' => $options,\n ];\n }\n\n return [\n 'id' => 'teams',\n 'label' => 'Team',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'required' => false,\n 'placeholder' => 'Select',\n 'options' => $options,\n 'value' => $value, // value should be an array of objects {id, name}\n 'dependencies' => [ActivityTypeService::PLAYBOOK_CATEGORIES_KEY],\n 'dependsOn' => [],\n ];\n }\n\n public function getReportTypeFieldData(?string $value = null, bool $shortVersion = false, ?Team $team = null): array\n {\n $types = [];\n if ($team instanceof Team) {\n if ($team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {\n $types = self::TYPES;\n }\n if ($team->hasFeature(FeatureEnum::ASK_JIMINNY_REPORTS)) {\n $types[] = ['id' => self::TYPE_ASK_JIMINNY, 'name' => 'Ask Jiminny'];\n }\n } else {\n $types = self::TYPES;\n }\n\n if ($shortVersion) {\n return [\n 'id' => 'report_type',\n 'label' => 'Report Type',\n 'options' => $types,\n ];\n }\n\n return [\n 'id' => 'report_type',\n 'label' => 'Report Type',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => $types,\n 'value' => $value,\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getFrequencyFieldData(?string $value = null): array\n {\n return [\n 'id' => 'frequency',\n 'label' => 'Frequency',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => self::FREQUENCIES,\n 'value' => $value,\n 'dependencies' => ['period'],\n 'dependsOn' => [],\n ];\n }\n\n public function getPeriodFieldData(?string $valueStartDate = null, ?string $valueEndDate = null): array\n {\n return [\n 'id' => 'period',\n 'label' => 'Select one-off period',\n 'inputType' => InputTypeEnum::DATE_RANGE,\n 'required' => true,\n 'placeholder' => 'Select',\n 'value' => ['startDate' => $valueStartDate, 'endDate' => $valueEndDate],\n 'queryParams' => [\n 'startDate' => 'start_date_period',\n 'endDate' => 'end_date_period',\n ],\n 'dependencies' => [],\n 'dependsOn' => ['frequency'],\n ];\n }\n\n public function getActivityTypesFieldData(?Team $team = null, array $value = [], array $teamsFilter = []): array\n {\n return $this->activityTypeService->getActivityTypeFieldData(team: $team, value: $value, groupIds: $teamsFilter);\n }\n\n public function getDealStageAtCallFieldData(?Team $team = null, array $value = []): array\n {\n return $this->dealStagesService->getDealStageAtCallFieldData(team: $team, value: $value);\n }\n\n public function getCurrentDealStageFieldData(?Team $team = null, array $value = []): array\n {\n return $this->dealStagesService->getCurrentDealStageFieldData(team: $team, value: $value);\n }\n\n public function getDealValueFieldData(?int $valueMin = null, ?int $valueMax = null): array\n {\n return [\n 'id' => 'deal_value',\n 'label' => 'Deal Value',\n 'inputType' => InputTypeEnum::INTEGER_RANGE,\n 'required' => false,\n 'value' => ['min' => $valueMin, 'max' => $valueMax],\n 'queryParams' => [\n 'min' => 'min_deal_value',\n 'max' => 'max_deal_value',\n ],\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getCallTypeFieldData(bool $conferenceOn = false, bool $dialerOn = false): array\n {\n $value = [];\n $conferenceOn && $value[] = self::CALL_TYPE_CONFERENCE;\n $dialerOn && $value[] = self::CALL_TYPE_DIALER;\n\n return [\n 'id' => 'call_type',\n 'label' => 'Call Type',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'required' => true,\n 'options' => [\n self::CALL_TYPE_CONFERENCE,\n self::CALL_TYPE_DIALER,\n ],\n 'value' => $value,\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getMediaTypeFieldData(?AutomatedReport $report = null): array\n {\n $value = [];\n\n if ($report) {\n $value = $this->transformMediaTypes($report);\n }\n\n return [\n 'id' => 'media_types',\n 'label' => 'Export as',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'required' => true,\n 'options' => self::MEDIA_TYPE_OBJECTS,\n 'value' => $value,\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getCallDurationFieldData(?int $valueMin = null, ?int $valueMax = null): array\n {\n return [\n 'id' => 'call_duration',\n 'label' => 'Call Duration',\n 'inputType' => InputTypeEnum::INTEGER_RANGE,\n 'required' => false,\n 'value' => ['min' => $valueMin, 'max' => $valueMax],\n 'queryParams' => [\n 'min' => 'min_call_duration',\n 'max' => 'max_call_duration',\n ],\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getRecipientsFieldData(?Team $team = null, array $value = []): array\n {\n return $this->recipientsService->getRecipientsFieldData(team: $team, value: $value);\n }\n\n public function getJiminnyRecipientsFieldData(array $value = []): array\n {\n return $this->recipientsService->getJiminnyRecipientsFieldData($value);\n }\n\n public function getAdditionalPromptInputFieldData(?string $value = null): array\n {\n return [\n 'id' => 'additional_prompt_input',\n 'label' => 'Special requirements',\n 'inputType' => InputTypeEnum::TEXTAREA,\n 'required' => false,\n 'placeholder' => 'What should be the focus of the report?',\n 'value' => $value,\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getCustomReportNameFieldData(?string $value = null): array\n {\n return [\n 'id' => 'custom_name',\n 'label' => 'Custom report name',\n 'inputType' => InputTypeEnum::TEXT,\n 'required' => false,\n 'placeholder' => 'Enter custom name',\n 'value' => $value,\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n // data providers\n public function getTeams(): array\n {\n $teams = $this->teamRepository->getTeamsForKiosk(status: Team::STATUS_ACTIVE);\n\n $teamData = [];\n foreach ($teams as $team) {\n if (! $team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {\n continue;\n }\n\n $teamData[] = $this->transformTeam($team);\n }\n\n return $teamData;\n }\n\n public function getTeamGroups(string $teamUuid): array\n {\n $data = [];\n $team = $this->getTeam($teamUuid);\n\n if ($team !== null) {\n $groups = $team->groups()->get();\n\n foreach ($groups as $group) {\n $data[] = [\n 'id' => $group->getUuid(),\n 'name' => $group->getName(),\n ];\n }\n }\n\n return $data;\n }\n\n public function getTeamsGroupsOptions(array $filterTeamUuids = []): array\n {\n $data = [];\n $teams = $this->getTeams();\n\n foreach ($teams as $team) {\n if (! empty($filterTeamUuids) && ! in_array($team['id'], $filterTeamUuids, true)) {\n continue;\n }\n\n $data[] = [\n 'label' => $team['name'],\n 'groups' => $this->getTeamGroups($team['id']),\n ];\n }\n\n return $data;\n }\n\n public function getTeam(string $teamUuid): ?Team\n {\n return $this->teamRepository->idOrUuid($teamUuid);\n }\n\n public function getTeamById(int $teamId): ?Team\n {\n return $this->teamRepository->find($teamId);\n }\n\n public function getGroupsUuids(AutomatedReport $report): array\n {\n $uuids = [];\n $reportGroups = $report->getGroups();\n foreach ($reportGroups as $groupId) {\n if ($group = $this->groupRepository->find($groupId)) {\n $uuids[] = $group->getUuid();\n }\n }\n\n return $uuids;\n }\n\n public function getPlaybookCategoriesUuids(AutomatedReport $report): array\n {\n $uuids = [];\n $playbookCategories = $report->getPlaybookCategories();\n foreach ($playbookCategories as $id) {\n if ($category = $this->playbookCategoryRepository->find($id)) {\n $uuids[] = $category->getUuid();\n }\n }\n\n return $uuids;\n }\n\n public function getDealAtCallStagesUuids(AutomatedReport $report): array\n {\n $uuids = [];\n $reportStages = $report->getDealAtCallStages();\n foreach ($reportStages as $id) {\n if ($stage = $this->stageRepository->find($id)) {\n $uuids[] = $stage->getUuid();\n }\n }\n\n return $uuids;\n }\n\n public function getCurrentDealStagesUuids(AutomatedReport $report): array\n {\n $uuids = [];\n $reportStages = $report->getCurrentDealStages();\n foreach ($reportStages as $id) {\n if ($stage = $this->stageRepository->find($id)) {\n $uuids[] = $stage->getUuid();\n }\n }\n\n return $uuids;\n }\n\n public function getUsersUuids(AutomatedReport $report): array\n {\n return $this->extractUserUuids($report->getRecipients());\n }\n\n public function getJiminnyUsersUuids(AutomatedReport $report): array\n {\n return $this->extractUserUuids($report->getJiminnyRecipients());\n }\n\n /**\n * @param array<string, mixed> $recipients\n */\n private function extractUserUuids(array $recipients): array\n {\n $userIds = $recipients['users'] ?? [];\n\n return collect($userIds)\n ->map(fn ($id) => $this->userRepository->find((int) $id))\n ->filter()\n ->map(fn (UserContract $user) => $user->getUuid())\n ->values()\n ->all();\n }\n\n // get mail data\n public function getRecipientUsers(AutomatedReport $report): array\n {\n return $this->buildRecipientUsers($report->getRecipients());\n }\n\n private function getJiminnyRecipientUsers(AutomatedReport $report): array\n {\n return $this->buildRecipientUsers($report->getJiminnyRecipients());\n }\n\n /**\n * @param array<string, mixed> $recipients\n */\n private function buildRecipientUsers(array $recipients): array\n {\n $userIds = $recipients['users'] ?? [];\n\n return collect($userIds)\n ->map(fn ($id) => $this->userRepository->find((int) $id))\n ->filter()\n ->map(fn (UserContract $user) => [\n 'email' => $user->getEmailAddress(),\n 'name' => $user->getName(),\n 'timezone' => $user->getTimezone()->getName(),\n ])\n ->values()\n ->all();\n }\n\n public function getValidRecipientUsers(AutomatedReport $report, bool $includeJiminny = false): array\n {\n if ($report->isAskJiminnyReport()) {\n $recipients = $this->resolveAskJiminnyRecipients($report);\n } else {\n $recipients = $this->getRecipientUsers($report);\n if ($includeJiminny) {\n $recipients = array_merge($recipients, $this->getJiminnyRecipientUsers($report));\n }\n }\n\n $emails = [];\n\n return array_values(array_filter(\n $recipients,\n static function ($recipient) use (&$emails) {\n if (empty($recipient['email']) || in_array($recipient['email'], $emails, true)) {\n return false;\n }\n $emails[] = $recipient['email'];\n\n return true;\n }\n ));\n }\n\n private function resolveAskJiminnyRecipients(AutomatedReport $report): array\n {\n $recipients = [];\n\n $creator = $report->getCreator();\n if ($creator !== null) {\n $recipients[] = [\n 'email' => $creator->getEmailAddress(),\n 'name' => $creator->getName(),\n 'timezone' => $creator->getTimezone()->getName(),\n ];\n }\n\n return array_merge(\n $recipients,\n $this->buildRecipientUsers($report->getRecipients()),\n $this->getGroupRecipientUsers($report),\n );\n }\n\n private function getGroupRecipientUsers(AutomatedReport $report): array\n {\n $users = [];\n foreach ($report->getGroups() as $groupId) {\n $group = $this->groupRepository->find($groupId);\n if ($group === null) {\n continue;\n }\n foreach ($group->getMembers() as $member) {\n $users[] = [\n 'email' => $member->getEmailAddress(),\n 'name' => $member->getName(),\n 'timezone' => $member->getTimezone()->getName(),\n ];\n }\n }\n\n return $users;\n }\n\n public function getReportTypeName(AutomatedReportResult $report): string\n {\n $type = $report->getReport()->getType();\n\n $getType = $this->transformReportType($type);\n\n return $getType['name'];\n }\n\n public function getReportPeriodName(AutomatedReportResult $report): string\n {\n $from = $report->getFromDate();\n $to = $report->getToDate();\n $frequency = $report->getReport()->getFrequency();\n\n if ($from === null || $to === null) {\n if (! $report->getReport()->isAskJiminnyReport()) {\n $invalidPeriod = $from === null ? 'from' : 'to';\n\n throw new ApplicationException('Report period is invalid: ' . $invalidPeriod);\n }\n\n $period = $this->calculateFromAndToDatePeriod($frequency);\n $from = $period['fromDate'];\n $to = $period['toDate'];\n }\n\n return $this->formatReportPeriodName($frequency, $from, $to);\n }\n\n private function formatReportPeriodName(string $frequency, Carbon $from, Carbon $to): string\n {\n $fromYear = $from->format('Y');\n $toYear = $to->format('Y');\n $differentYears = $fromYear !== $toYear;\n\n switch ($frequency) {\n case self::FREQUENCY_DAILY:\n return $from->format('j M Y');\n\n case self::FREQUENCY_QUARTERLY:\n // 'Jan-Mar 2025' or 'Nov 2024-Jan 2025' if years differ\n $startMonth = $from->format('M');\n $endMonth = $to->copy()->subMonth();\n $endMonthName = $endMonth->format('M');\n $endMonthYear = $endMonth->format('Y');\n\n if ($differentYears) {\n return \"{$startMonth} {$fromYear} - {$endMonthName} {$endMonthYear}\";\n }\n\n return \"{$startMonth} - {$endMonthName} {$toYear}\";\n\n case self::FREQUENCY_MONTHLY:\n // 'May 2025' - monthly reports are always within the same year\n return $from->format('M Y');\n\n case self::FREQUENCY_WEEKLY:\n // '4 - 8 Aug 2025', '27 Oct - 3 Nov 2025', or '28 Dec 2024 - 3 Jan 2025' if years differ\n $startDay = $from->format('j');\n $endDay = $to->format('j');\n $startMonth = $from->format('M');\n $endMonth = $to->format('M');\n\n if ($differentYears) {\n return \"{$startDay} {$startMonth} {$fromYear} - {$endDay} {$endMonth} {$toYear}\";\n }\n\n if ($startMonth !== $endMonth) {\n return \"{$startDay} {$startMonth} - {$endDay} {$endMonth} {$toYear}\";\n }\n\n return \"{$startDay} - {$endDay} {$endMonth} {$toYear}\";\n\n case self::FREQUENCY_ONE_OFF:\n // '2 May-31 May 2025' or '15 Dec 2024-15 Jan 2025' if years differ\n $startDay = $from->format('j');\n $startMonth = $from->format('M');\n $endDay = $to->format('j');\n $endMonth = $to->format('M');\n\n // If same month and year, use a format like '2-31 May 2025'\n if ($startMonth === $endMonth && ! $differentYears) {\n return \"{$startDay} - {$endDay} {$startMonth} {$toYear}\";\n }\n\n // If different years, include both years\n if ($differentYears) {\n return \"{$startDay} {$startMonth} {$fromYear} - {$endDay} {$endMonth} {$toYear}\";\n }\n\n // Same year but different months\n return \"{$startDay} {$startMonth} - {$endDay} {$endMonth} {$toYear}\";\n\n default:\n // Default format for unknown frequencies\n return $from->format('j M Y') . ' - ' . $to->format('j M Y');\n }\n }\n\n public function getReportTeamsName(AutomatedReportResult $report): string\n {\n $groups = $report->getGroups();\n\n if (empty($groups)) {\n return 'All';\n }\n\n // Get group names from repository\n $groupNames = [];\n foreach ($groups as $groupId) {\n $group = $this->groupRepository->find($groupId);\n if ($group) {\n $groupNames[] = $group->getName();\n }\n }\n\n if (count($groupNames) === 1) {\n // Single team format\n $teamsName = $groupNames[0];\n } else {\n // Multiple teams format\n $teamsName = implode(', ', $groupNames);\n }\n\n return $teamsName;\n }\n\n public function getReportFileName(AutomatedReportResult $report): string\n {\n $customName = $report->getReport()->getCustomName();\n $periodName = $this->getReportPeriodName($report);\n $filenameSuffix = $this->getFilenameSuffix($report);\n\n if ($customName) {\n if ($filenameSuffix) {\n $customName .= \" {$filenameSuffix}\";\n }\n\n return $this->sanitizeFileName(\"{$customName} - {$periodName}\");\n }\n\n $baseName = $this->getReportTypeName($report);\n\n if ($filenameSuffix) {\n $baseName .= \" {$filenameSuffix}\";\n }\n\n return $this->sanitizeFileName(\"{$baseName} - {$periodName} - {$this->getReportTeamsName($report)}\");\n }\n\n public function getReportFileNameWithExtension(AutomatedReportResult $result): string\n {\n $extension = $this->getMediaTypeMetadata($result)['extension'];\n\n return $this->getReportFileName($result) . '.' . $extension;\n }\n\n public function sanitizeFileName(string $fileName): string\n {\n return str_replace(['/', '\\\\'], '-', $fileName);\n }\n\n public function isUserRecipientOfReport(User $user, AutomatedReport $report): bool\n {\n $recipients = array_map('intval', $report->getRecipients()['users'] ?? []);\n\n return in_array($user->getId(), $recipients);\n }\n\n public function transformReportResults(Collection $automatedReportResults): array\n {\n $data = [];\n foreach ($automatedReportResults as $automatedReportResult) {\n /** @var AutomatedReportResult $automatedReportResult */\n\n $report = $automatedReportResult->getReport();\n\n $createdBy = $report->getCreator();\n $creator = [\n 'id' => $createdBy?->getUuid(),\n 'name' => $createdBy?->getName(),\n 'email' => $createdBy?->getEmailAddress(),\n 'photoUrl' => $createdBy?->getPhotoUrl(),\n ];\n\n $data[] = [\n 'id' => $automatedReportResult->getUuid(),\n 'name' => $automatedReportResult->getName(),\n 'frequency' => $this->transformFrequency($report->getFrequency()),\n 'recipients' => [\n ...array_values($this->transformGroups(team: $report->getTeam(), groupsIds: $report->getGroups())),\n ...array_values($this->transformRecipients($report->getRecipients())),\n ],\n 'report_type' => $this->transformReportType($report->getType()),\n 'media_type' => $automatedReportResult->getMediaType(),\n 'downloadUrl' => $this->generateReportResultDownloadUrl($automatedReportResult),\n 'viewUrl' => $this->generateReportResultViewUrl($automatedReportResult),\n 'generated_at' => $automatedReportResult->getGeneratedAt()?->toIso8601String(),\n 'creator' => $creator,\n ];\n }\n\n return $data;\n }\n\n public function hasCallTypeConference(AutomatedReport $report): bool\n {\n return in_array(self::CALL_TYPE_CONFERENCE['id'], $report->getCallTypes(), true);\n }\n\n public function hasCallTypeDialer(AutomatedReport $report): bool\n {\n return in_array(self::CALL_TYPE_DIALER['id'], $report->getCallTypes(), true);\n }\n\n // transformers\n private function transformTeam(Team $team): array\n {\n if (! $team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {\n return [];\n }\n\n return [\n 'id' => $team->getUuid(),\n 'name' => $team->getName(),\n ];\n }\n\n private function transformReportFullView(AutomatedReport $report): array\n {\n $base = $this->transformReportBase($report);\n\n return $report->getType() === self::TYPE_ASK_JIMINNY\n ? $base + $this->transformAskJiminnyFields($report)\n : $base + $this->transformStandardReportFields($report);\n }\n\n private function transformReportBase(AutomatedReport $report): array\n {\n return [\n 'id' => $report->getUuid(),\n 'organization' => $this->transformOrganization(team: $report->getTeam()),\n 'report_type' => $this->transformReportType($report->getType()),\n 'frequency' => $this->transformFrequency($report->getFrequency()),\n ];\n }\n\n private function transformStandardReportFields(AutomatedReport $report): array\n {\n $team = $report->getTeam();\n\n return [\n 'report_enabled' => $report->getStatus(),\n 'start_date_period' => $report->getFrom()?->format('Y-m-d H:i:s'),\n 'end_date_period' => $report->getTo()?->format('Y-m-d H:i:s'),\n 'deal_value_min' => $report->getDealValueMin(),\n 'deal_value_max' => $report->getDealValueMax(),\n 'call_types' => $this->transformCallType($report->getCallTypes()),\n 'media_types' => $this->transformMediaTypes($report),\n 'call_duration_min' => $this->transformDurationToMinutes($report->getCallDurationMin()),\n 'call_duration_max' => $this->transformDurationToMinutes($report->getCallDurationMax()),\n 'teams' => $this->transformGroups(team: $team, groupsIds: $report->getGroups()),\n 'deal_at_call_stages' => $this->transformStages(team: $team, stagesIds: $report->getDealAtCallStages()),\n 'current_deal_stages' => $this->transformStages(team: $team, stagesIds: $report->getCurrentDealStages()),\n 'recipients' => $this->transformRecipients($report->getRecipients()),\n 'created_by' => $this->transformCreator($report->getCreator()),\n 'additional_prompt_input' => $report->getAdditionalPromptInput(),\n 'custom_name' => $report->getCustomName(),\n 'created_at' => $report->getCreatedAt()->format('Y-m-d H:i:s'),\n 'updated_at' => $report->getUpdatedAt()->format('Y-m-d H:i:s'),\n 'deleted_at' => $report->getDeletedAt()?->format('Y-m-d H:i:s'),\n ];\n }\n\n private function transformAskJiminnyFields(AutomatedReport $report): array\n {\n $team = $report->getTeam();\n $creatorId = $report->getAttribute('created_by');\n $explicitUserIds = array_values(array_filter(\n $report->getRecipients()['users'] ?? [],\n static fn ($id) => $id !== $creatorId\n ));\n\n return [\n 'report_name' => $report->getCustomName(),\n 'enabled' => $report->getStatus(),\n 'share_teams' => $this->transformGroups(team: $team, groupsIds: $report->getGroups()),\n 'share_users' => $this->transformRecipients(['users' => $explicitUserIds]),\n 'saved_search' => $this->transformSafeSearch($report->getSavedSearch()),\n 'ask_jiminny_prompt' => $this->transformAskJiminnyPrompt($report->getAskAnythingPrompt()),\n 'expires_on' => $report->getExpiresAt()?->format('Y-m-d'),\n ];\n }\n\n private function transformOrganization(?Team $team): array\n {\n return [\n 'id' => $team?->getUuid(),\n 'name' => $team?->getName(),\n ];\n }\n\n private function transformReportType(string $type): array\n {\n foreach (self::ALL_TYPES as $typeItem) {\n if ($typeItem['id'] === $type) {\n return $typeItem;\n }\n }\n\n return [];\n }\n\n private function transformCallType(array $types): array\n {\n $result = [];\n $callTypes = [self::CALL_TYPE_CONFERENCE, self::CALL_TYPE_DIALER];\n\n foreach ($types as $type) {\n foreach ($callTypes as $callTypeItem) {\n if ($callTypeItem['id'] === $type) {\n $result[] = $callTypeItem;\n\n break;\n }\n }\n }\n\n return $result;\n }\n\n private function transformMediaTypes(AutomatedReport $report): array\n {\n $values = [];\n\n foreach ($report->getMediaTypes() as $mediaType) {\n if (! in_array($mediaType, self::MEDIA_TYPES, true)) {\n continue;\n }\n\n $values[] = match ($mediaType) {\n self::MEDIA_TYPE_PDF => self::MEDIA_TYPE_OBJECT_PDF,\n self::MEDIA_TYPE_PODCAST => self::MEDIA_TYPE_OBJECT_PODCAST,\n };\n }\n\n return $values;\n }\n\n private function transformFrequency(string $frequency): array\n {\n foreach (self::ALL_FREQUENCIES as $frequencyItem) {\n if ($frequencyItem['id'] === $frequency) {\n return $frequencyItem;\n }\n }\n\n return [];\n }\n\n public function transformDurationToMinutes(?int $duration): ?int\n {\n if (! $duration) {\n return null;\n }\n\n return (int) ($duration / 60);\n }\n\n private function transformGroups(?Team $team, array $groupsIds): array\n {\n if (empty($groupsIds) || ! $team) {\n return [];\n }\n\n $data = [];\n foreach ($groupsIds as $groupId) {\n $group = $team->groups()->where('id', $groupId)->first();\n\n if ($group) {\n $data[] = [\n 'id' => $group->getUuid(),\n 'name' => $group->getName(),\n 'photoUrl' => $group->getPhotoUrl(),\n ];\n }\n }\n\n return $data;\n }\n\n private function transformStages(?Team $team, array $stagesIds): array\n {\n if (empty($stagesIds) || ! $team) {\n return [];\n }\n\n $data = [];\n foreach ($stagesIds as $stageId) {\n $stage = $team->stages()->where('id', $stageId)->first();\n\n if ($stage) {\n $data[] = [\n 'id' => $stage->getUuid(),\n 'name' => $stage->getName(),\n ];\n }\n }\n\n return $data;\n }\n\n private function transformRecipients(array $recipients): array\n {\n $users = [];\n foreach ($recipients['users'] ?? [] as $userId) {\n $users[] = $this->transformUser($userId);\n }\n\n return $users;\n }\n\n private function transformCreator(?User $user): ?array\n {\n if ($user === null) {\n return null;\n }\n\n return $this->transformUser($user->getId());\n }\n\n private function transformAskJiminnyPrompt(?AskAnythingPrompt $prompt): ?array\n {\n if ($prompt === null) {\n return null;\n }\n\n return [\n 'id' => $prompt->getUuid(),\n 'name' => $prompt->getTitle(),\n ];\n }\n\n private function transformSafeSearch(?Search $search): ?array\n {\n if ($search === null) {\n return null;\n }\n\n return [\n 'id' => $search->getUuid(),\n 'name' => $search->getName(),\n ];\n }\n\n private function transformUser(int $userId): array\n {\n /* @var ?User $user */\n $user = $this->userRepository->find($userId);\n\n return [\n 'id' => $user?->getUuid(),\n 'name' => $user?->getName(),\n 'email' => $user?->getEmailAddress(),\n 'photoUrl' => $user?->getPhotoUrl(),\n ];\n }\n\n public function create(array $data): array\n {\n $validatedData = $this->validateAndTransformData($data);\n $validatedData['created_by'] = auth()->id();\n\n $automatedReport = $this->automatedReportsRepository->create($validatedData);\n\n $this->generateOneOffReport($automatedReport);\n\n return $this->transformReportFullView($automatedReport);\n }\n\n public function update(string $uuid, array $data): array\n {\n $validatedData = $this->validateAndTransformData($data);\n $report = $this->automatedReportsRepository->findByUuid($uuid);\n\n if (! $report) {\n throw new InvalidArgumentException('Report not found');\n }\n\n $oldCustomName = $report->getCustomName();\n\n $automatedReport = $this->automatedReportsRepository->update($report, $validatedData);\n\n if ($oldCustomName !== $automatedReport->getCustomName()) {\n $this->updateResultNames($automatedReport);\n }\n\n $this->generateOneOffReport($automatedReport);\n\n return $this->transformReportFullView($automatedReport);\n }\n\n /**\n * Create an Ask Jiminny report.\n */\n public function createAskJiminnyReport(array $data, User $creator): array\n {\n $validatedData = $this->validateAskJiminnyReportData($data, $creator);\n $validatedData['created_by'] = $creator->getId();\n\n $automatedReport = $this->automatedReportsRepository->create($validatedData);\n\n return $this->transformReportFullView($automatedReport);\n }\n\n /**\n * Update an Ask Jiminny report.\n */\n public function updateAskJiminnyReport(AutomatedReport $report, array $data, User $user): array\n {\n if (! $report->isAskJiminnyReport()) {\n throw new InvalidArgumentException('Report is not an Ask Jiminny report');\n }\n\n $validatedData = $this->validateAskJiminnyReportData($data, $user);\n\n $oldCustomName = $report->getCustomName();\n\n $automatedReport = $this->automatedReportsRepository->update($report, $validatedData);\n\n if ($oldCustomName !== $automatedReport->getCustomName()) {\n $this->updateResultNames($automatedReport);\n }\n\n return $this->transformReportFullView($automatedReport);\n }\n\n public function updateAskJiminnyReportStatus(AutomatedReport $report, bool $status): array\n {\n $this->automatedReportsRepository->update($report, ['status' => $status]);\n\n return $this->transformReportFullView($report->fresh());\n }\n\n /**\n * Validate and transform data for Ask Jiminny reports.\n */\n private function validateAskJiminnyReportData(array $data, User $user): array\n {\n // Validate name\n $name = trim($data['report_name'] ?? '');\n if (empty($name)) {\n throw new InvalidArgumentException('Report name is required');\n }\n if (mb_strlen($name) > 50) {\n throw new InvalidArgumentException('Report name must be 50 characters or less');\n }\n\n // Validate frequency (only daily, weekly, monthly for Ask Jiminny)\n $frequency = $data['frequency'] ?? null;\n $askJiminnyFrequencies = [self::FREQUENCY_DAILY, self::FREQUENCY_WEEKLY, self::FREQUENCY_MONTHLY];\n if (! in_array($frequency, $askJiminnyFrequencies, true)) {\n throw new InvalidArgumentException('Frequency must be daily, weekly, or monthly');\n }\n\n // Validate expiration date\n $expiresAt = $data['expires_on'] ?? null;\n if (empty($expiresAt)) {\n throw new InvalidArgumentException('Expiration date is required');\n }\n\n try {\n $expiresAtDate = Carbon::parse($expiresAt);\n } catch (InvalidFormatException $e) {\n throw new InvalidArgumentException('Expiration date format is invalid');\n }\n $maxExpiration = Carbon::now()->addYear();\n if ($expiresAtDate->gt($maxExpiration)) {\n throw new InvalidArgumentException('Expiration date cannot be more than 1 year from now');\n }\n if ($expiresAtDate->isPast()) {\n throw new InvalidArgumentException('Expiration date cannot be in the past');\n }\n\n // Validate saved search\n $activitySearchId = $data['saved_search'] ?? null;\n if (empty($activitySearchId)) {\n throw new InvalidArgumentException('Saved search is required');\n }\n $savedSearch = $this->activitySearchRepository->findByUuidAndUser($activitySearchId, $user);\n if (! $savedSearch) {\n throw new InvalidArgumentException('Saved search not found or does not belong to you');\n }\n\n // Validate saved prompt\n $askAnythingPromptId = $data['ask_jiminny_prompt'] ?? null;\n if (empty($askAnythingPromptId)) {\n throw new InvalidArgumentException('Ask Jiminny prompt is required');\n }\n $prompt = $this->askAnythingRepository->getPromptByUuid($askAnythingPromptId);\n if (! $prompt) {\n throw new InvalidArgumentException('Ask Jiminny prompt not found');\n }\n\n // Validate status\n $status = $data['enabled'] ?? false;\n\n $recipientUserIds = [$user->getId()];\n\n if (! empty($data['share_users'])) {\n $sharedUserIds = $this->validateAndGetUserIdsByTeam(\n $user->team,\n (array) $data['share_users']\n );\n $recipientUserIds = array_merge($recipientUserIds, $sharedUserIds);\n }\n\n $sharedGroupIds = [];\n if (! empty($data['share_teams'])) {\n $sharedGroupIds = $this->validateAndGetGroupIds($user->team, (array) $data['share_teams']);\n }\n\n $recipientUserIds = array_values(array_unique($recipientUserIds));\n\n return [\n 'team_id' => $user->getTeamId(),\n 'type' => self::TYPE_ASK_JIMINNY,\n 'status' => (bool) $status,\n 'frequency' => $frequency,\n 'custom_name' => $name,\n 'activity_search_id' => $savedSearch->getId(),\n 'ask_anything_prompt_id' => $prompt->getId(),\n 'expires_at' => $expiresAtDate->toDateString(),\n 'media_types' => [self::MEDIA_TYPE_PDF],\n 'call_types' => [],\n 'recipients' => ['users' => $recipientUserIds],\n 'groups' => $sharedGroupIds,\n ];\n }\n\n public static function getAskJiminnyFrequencies(): array\n {\n return array_map(static function ($frequency) {\n return $frequency['id'];\n }, self::ASK_JIMINNY_FREQUENCIES);\n }\n\n public function getAskJiminnyReportFilters(User $user): array\n {\n $savedSearches = $this->activitySearchRepository->findByUserOrderedByName($user)\n ->map(fn (Search $search) => [\n 'id' => $search->getUuid(),\n 'name' => $search->getName(),\n ])\n ->values()->all();\n\n $prompts = collect(\n $this->askAnythingPromptService->get($user, AskAnythingPromptTarget::on_demand)\n )->map(fn (AskAnythingPromptDto $prompt) => [\n 'id' => $prompt->id,\n 'name' => $prompt->title,\n ])->values()->all();\n\n return [\n [\n 'id' => 'prompt',\n 'label' => 'Prompt',\n 'options' => $prompts,\n ],\n [\n 'id' => 'saved_search',\n 'label' => 'Saved Search',\n 'options' => $savedSearches,\n ],\n ];\n }\n\n public function getAskJiminnyReportFormData(User $user, ?AutomatedReport $report = null): array\n {\n $team = $user->getTeam();\n $userTimezone = $user->getTimezone();\n\n $savedSearches = $this->activitySearchRepository->findByUserOrderedByName($user)\n ->map(fn (Search $search) => [\n 'id' => $search->getUuid(),\n 'name' => $search->getName(),\n ])\n ->values()->all();\n\n $prompts = collect(\n $this->askAnythingPromptService->get($user, AskAnythingPromptTarget::on_demand)\n )->map(fn (AskAnythingPromptDto $prompt) => [\n 'id' => $prompt->id,\n 'name' => $prompt->title,\n ])->values()->all();\n\n $teamGroups = $this->groupRepository->getAllByTeam($team)->map(fn ($group) => [\n 'id' => $group->getUuid(),\n 'name' => $group->getName(),\n ])->values()->all();\n\n $shareUsers = $this->recipientsService->getRecipientsFieldData(team: $team)['options'] ?? [];\n\n $sharedTeamsValue = [];\n $sharedUsersValue = [];\n if ($report) {\n $sharedTeamsValue = $this->transformGroups($team, $report->getGroups());\n\n $recipientUserIds = $report->getRecipients()['users'] ?? [];\n $creatorId = $report->getAttribute('created_by');\n $sharedUserIds = array_values(array_filter(\n $recipientUserIds,\n static fn ($id) => $id !== $creatorId\n ));\n $sharedUsersValue = collect($sharedUserIds)\n ->map(fn ($id) => $this->userRepository->find((int) $id))\n ->filter()\n ->map(fn (User $u) => [\n 'id' => $u->getUuid(),\n 'name' => $u->getName(),\n ])\n ->values()\n ->all();\n }\n\n return [\n 'fields' => [\n [\n 'id' => 'enabled',\n 'inputType' => InputTypeEnum::TOGGLE,\n 'label' => '',\n 'value' => $report?->getStatus() ?? false,\n ],\n [\n 'id' => 'report_name',\n 'inputType' => InputTypeEnum::TEXT,\n 'label' => 'Name',\n 'placeholder' => 'Enter name',\n 'required' => true,\n 'validation' => ['maxLength' => 50],\n 'value' => $report?->getCustomName() ?? '',\n ],\n [\n 'id' => 'frequency',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'label' => 'Frequency',\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => self::ASK_JIMINNY_FREQUENCIES,\n 'value' => $report ? $this->transformFrequency($report->getFrequency()) : null,\n ],\n [\n 'id' => 'expires_on',\n 'inputType' => InputTypeEnum::DATE,\n 'label' => 'Expires on',\n 'required' => true,\n 'placeholder' => 'Select',\n 'validation' => [\n 'minDate' => now($userTimezone)->toDateString(),\n 'maxDate' => now($userTimezone)->addYear()->toDateString(),\n ],\n 'value' => $report?->getExpiresAt()?->toDateString(),\n ],\n [\n 'id' => 'share_teams',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'label' => 'Team',\n 'required' => false,\n 'placeholder' => 'Select',\n 'options' => $teamGroups,\n 'value' => $sharedTeamsValue,\n ],\n [\n 'id' => 'share_users',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'label' => 'Team member',\n 'required' => false,\n 'placeholder' => 'Select',\n 'groupLabelKey' => 'label',\n 'groupValuesKey' => 'users',\n 'optionLabelKey' => 'name',\n 'optionValueKey' => 'id',\n 'options' => $shareUsers,\n 'value' => $sharedUsersValue,\n ],\n [\n 'id' => 'saved_search',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'label' => 'Saved search',\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => $savedSearches,\n 'value' => $report && $report->getSavedSearch() ? [\n 'id' => $report->getSavedSearch()->getUuid(),\n 'name' => $report->getSavedSearch()->getName(),\n ] : null,\n ],\n [\n 'id' => 'ask_jiminny_prompt',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'label' => 'Ask Jiminny prompt',\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => $prompts,\n 'value' => $report && $report->getAskAnythingPrompt() ? [\n 'id' => $report->getAskAnythingPrompt()->getUuid(),\n 'name' => $report->getAskAnythingPrompt()->getTitle(),\n ] : null,\n ],\n ],\n ];\n }\n\n private function updateResultNames(AutomatedReport $automatedReport): void\n {\n $results = $this->automatedReportsRepository->getResultsByReport($automatedReport);\n\n foreach ($results as $result) {\n $result->update(['name' => $this->getReportFileName($result)]);\n }\n }\n\n public function updateStatus(string $uuid, array $data): array\n {\n $automatedReport = $this->automatedReportsRepository->findByUuid($uuid);\n\n if (! $automatedReport) {\n throw new ModelNotFoundException('Report not found');\n }\n\n $status = $this->validateReportStatus($data['report_enabled'] ?? null);\n $automatedReport->update([\n 'status' => $status,\n ]);\n\n $this->generateOneOffReport($automatedReport);\n\n return $this->transformReportFullView($automatedReport);\n }\n\n private function generateOneOffReport(AutomatedReport $automatedReport): void\n {\n // the scheduler handles all the other frequency types\n if ($automatedReport->getStatus() === false || $automatedReport->getFrequency() !== self::FREQUENCY_ONE_OFF) {\n return;\n }\n\n $this->dispatcher->dispatch(new RequestGenerateReportJob($automatedReport->getUuid()));\n }\n\n public function getReport(string $uuid): AutomatedReport\n {\n $automatedReport = $this->automatedReportsRepository->findByUuid($uuid);\n\n if (! $automatedReport) {\n throw new ModelNotFoundException('Report not found');\n }\n\n return $automatedReport;\n }\n\n public function get(string $uuid): array\n {\n $automatedReport = $this->getReport($uuid);\n\n return $this->transformReportFullView($automatedReport);\n }\n\n public function list(string $sortColumn = 'created_at', string $sortDirection = 'desc'): array\n {\n $results = [];\n $collection = $this->automatedReportsRepository->getAllStandardReports($sortColumn, $sortDirection);\n\n /** @var AutomatedReport $report */\n foreach ($collection as $report) {\n $results[] = $this->transformReportFullView($report);\n }\n\n return ['data' => $results];\n }\n\n public function listAskJiminnyReports(\n User $user,\n string $sortColumn = 'created_at',\n string $sortDirection = 'desc'\n ): array {\n $results = [];\n $collection = $this->automatedReportsRepository->getAskJiminnyReportsByUser($user, $sortColumn, $sortDirection);\n\n /** @var AutomatedReport $report */\n foreach ($collection as $report) {\n $results[] = $this->transformReportFullView($report);\n }\n\n return ['data' => $results];\n }\n\n public function delete(string $uuid): void\n {\n $automatedReport = $this->automatedReportsRepository->findByUuid($uuid);\n\n if (! $automatedReport) {\n throw new ModelNotFoundException('Report not found');\n }\n\n $automatedReport->delete();\n }\n\n public function createReportResult(AutomatedReport $automatedReport, array $data = []): AutomatedReportResult\n {\n return $this->automatedReportsRepository->createResult(\n array_merge(\n [\n 'report_id' => $automatedReport->getId(),\n 'status' => AutomatedReportResult::STATUS_DEFAULT,\n ],\n $data\n )\n );\n }\n\n public function getReportResult(string $resultUuid): AutomatedReportResult\n {\n $report = $this->automatedReportsRepository->findResultByUuid($resultUuid);\n\n if (! $report) {\n throw new ModelNotFoundException('Report Result not found');\n }\n\n return $report;\n }\n\n public function findChildResult(AutomatedReportResult $result, string $type): ?AutomatedReportResult\n {\n return $this->automatedReportsRepository->findChildResult($result, $type);\n }\n\n // prophet API calls\n /**\n * @throws ApplicationException\n */\n public function getGenerateReportPayload(AutomatedReport $automatedReport, string $reportResultUuid): array\n {\n $period = $this->calculateFromAndToDate($automatedReport);\n $fromDate = $period['fromDate'];\n $toDate = $period['toDate'];\n\n return [\n 'team_id' => $automatedReport->getTeamId(),\n 'request_id' => $reportResultUuid,\n 'report_type' => $automatedReport->getType(),\n 'media_types' => $automatedReport->getMediaTypes(),\n 'from_date' => $fromDate->startOfDay()->format(DateTimeInterface::RFC3339),\n 'to_date' => $toDate->endOfDay()->format(DateTimeInterface::RFC3339),\n 'group_ids' => $automatedReport->getGroups(),\n 'call_deal_stage' => $automatedReport->getDealAtCallStages(),\n 'current_deal_stage' => $automatedReport->getCurrentDealStages(),\n 'deal_min_value' => $automatedReport->getDealValueMin(),\n 'deal_max_value' => $automatedReport->getDealValueMax(),\n 'call_types' => $automatedReport->getCallTypes(),\n 'call_duration_min_seconds' => $automatedReport->getCallDurationMin(),\n 'call_duration_max_seconds' => $automatedReport->getCallDurationMax(),\n 'special_requirements' => $automatedReport->getAdditionalPromptInput(),\n 'callback_url' => $this->getCallbackUrl(),\n 'report_period' => $this->formatReportPeriodName(\n $automatedReport->getFrequency(),\n $fromDate,\n $toDate,\n ),\n 'playbook_categories' => $automatedReport->getPlaybookCategories(),\n 'custom_name' => $automatedReport->getCustomName(),\n ];\n }\n\n // $inputPayload - FE payload structure\n public function getActivitiesCountPayload(array $inputPayload): array\n {\n // Use validateAndTransformData to validate and normalize input\n $validatedData = $this->validateAndTransformData($inputPayload);\n $period = $this->calculateFromAndToDatePeriod(\n $validatedData['frequency'],\n Carbon::parse($validatedData['from']),\n Carbon::parse($validatedData['to']),\n );\n $fromDate = $period['fromDate'];\n $toDate = $period['toDate'];\n\n // Create payload similar to getGenerateReportPayload\n return [\n 'team_id' => $validatedData['team_id'],\n 'group_ids' => $validatedData['groups'] ?? [],\n 'report_type' => $validatedData['type'],\n 'from_date' => $fromDate->format(DateTimeInterface::RFC3339),\n 'to_date' => $toDate->format(DateTimeInterface::RFC3339),\n 'call_deal_stage' => $validatedData['deal_at_call_stages'] ?? [],\n 'current_deal_stage' => $validatedData['current_deal_stages'] ?? [],\n 'deal_min_value' => $validatedData['deal_value_min'] ?? null,\n 'deal_max_value' => $validatedData['deal_value_max'] ?? null,\n 'call_types' => $validatedData['call_types'],\n 'call_duration_min_seconds' => $validatedData['call_duration_min'] ?? null,\n 'call_duration_max_seconds' => $validatedData['call_duration_max'] ?? null,\n 'special_requirements' => $validatedData['additional_prompt_input'] ?? null,\n 'playbook_categories' => $validatedData['playbook_categories'] ?? [],\n 'request_id' => null,\n 'callback_url' => null,\n ];\n }\n\n public function shouldSendReport(array $users, ?CarbonInterface $generatedAt = null): bool\n {\n if (empty($users)) {\n return false;\n }\n\n $earliestTz = collect($users)\n ->mapWithKeys(function (array $user) {\n $tz = new DateTimeZone($user['timezone']);\n $nowUtc = new DateTime('now', new DateTimeZone('UTC'));\n $offset = $tz->getOffset($nowUtc);\n\n return [$user['timezone'] => $offset];\n })\n ->sortDesc()\n ->keys()\n ->first();\n\n $now = Carbon::now($earliestTz);\n $isScheduledTime = (int) $now->format('H') === self::SENT_REPORT_AT_HOURS;\n\n if ($isScheduledTime) {\n return true;\n }\n\n return $this->hasPassedScheduledTime($generatedAt, $earliestTz);\n }\n\n public function hasPassedScheduledTime(?CarbonInterface $generatedAt, string $timezone): bool\n {\n if ($generatedAt === null) {\n return false;\n }\n\n $now = Carbon::now($timezone);\n $scheduledTime = $now->copy()->setTime(self::SENT_REPORT_AT_HOURS, 0, 0);\n\n if ($now->hour < self::SENT_REPORT_AT_HOURS) {\n $scheduledTime = $scheduledTime->subDay();\n }\n\n $scheduledTimeUtc = $scheduledTime->copy()->utc();\n $generatedAtUtc = $generatedAt->copy()->utc();\n $nowUtc = $now->copy()->utc();\n\n return $generatedAtUtc->lt($scheduledTimeUtc) && $nowUtc->gt($scheduledTimeUtc);\n }\n\n public function calculateFromAndToDatePeriod(\n string $frequency,\n ?Carbon $fromDate = null,\n ?Carbon $toDate = null\n ): array {\n if ($frequency === self::FREQUENCY_ONE_OFF) {\n return [\n 'fromDate' => $fromDate,\n 'toDate' => $toDate,\n ];\n }\n\n $now = Carbon::now();\n\n return match ($frequency) {\n self::FREQUENCY_DAILY => [\n 'fromDate' => $now->copy()->subDay()->startOfDay(),\n 'toDate' => $now->copy()->subDay()->endOfDay(),\n ],\n self::FREQUENCY_WEEKLY => [\n 'fromDate' => $now->copy()->subWeeks(1)->startOfDay(),\n 'toDate' => $now->copy()->subDay()->endOfDay(),\n ],\n self::FREQUENCY_MONTHLY => [\n 'fromDate' => $now->copy()->subMonths(1)->startOfDay(),\n 'toDate' => $now->copy()->subDay()->endOfDay(),\n ],\n self::FREQUENCY_QUARTERLY => [\n 'fromDate' => $now->copy()->subMonths(3)->startOfDay(),\n 'toDate' => $now->copy()->subDay()->endOfDay(),\n ],\n default => throw new InvalidArgumentException(\"Unsupported frequency: {$frequency}\"),\n };\n }\n\n private function calculateFromAndToDate(AutomatedReport $automatedReport): array\n {\n return $this->calculateFromAndToDatePeriod(\n $automatedReport->getFrequency(),\n $automatedReport->getFrom(),\n $automatedReport->getTo()\n );\n }\n\n public function getAskJiminnyGenerateReportPayload(\n AutomatedReport $automatedReport,\n AutomatedReportResult $reportResult,\n array $activityIds,\n ): array {\n return [\n 'user_question' => $automatedReport->getAskAnythingPrompt()?->getContent(),\n 'call_ids' => array_map('strval', $activityIds),\n 'team_id' => $automatedReport->getTeamId(),\n 'request_id' => $reportResult->getUuid(),\n 'callback_url' => $this->getCallbackUrl(),\n 'report_period' => $this->getReportPeriodName($reportResult),\n 'report_name' => $automatedReport->getCustomName(),\n ];\n }\n\n private function getCallbackUrl(): string\n {\n return $this->webhookService->route('jiminny.webhook.reports.ready');\n }\n\n /**\n * Validate and transform payload data for automated reports\n *\n * @param array $data\n *\n * @throws InvalidArgumentException\n *\n * @return array\n */\n private function validateAndTransformData(array $data): array\n {\n // Validate organization (team) and check feature\n $team = $this->validateOrganization($data['organization'] ?? null);\n\n $status = $this->validateReportStatus($data['report_enabled'] ?? null);\n $type = $this->validateReportType($data['report_type'] ?? null);\n $frequency = $this->validateFrequency($data['frequency'] ?? null);\n $additionalPromptInput = $this->validateAdditionalPromptInput(\n $data['additional_prompt_input'] ?? null\n );\n $customReportName = $this->validateCustomReportName($data['custom_name'] ?? null);\n\n // Prepare data for the database\n $reportData = [\n 'team_id' => $team->getId(),\n 'type' => $type,\n 'status' => $status,\n 'frequency' => $frequency,\n 'additional_prompt_input' => $additionalPromptInput,\n 'custom_name' => $customReportName,\n ];\n\n // Validate deal values\n $reportData = $this->validateDealValues($data, $reportData);\n\n // Validate date range\n $reportData = $this->validateDateRange($data, $reportData, $frequency);\n\n // Validate call durations\n $reportData = $this->validateCallDurations($data, $reportData);\n\n // Validate call types\n $reportData = $this->validateCallTypes($data, $reportData);\n\n // Validate media types\n $reportData = $this->validateMediaTypes($data, $reportData);\n\n // Validate groups\n if (isset($data['teams'])) {\n $reportData['groups'] = $this->validateAndGetGroupIds($team, $data['teams']);\n }\n\n // Validate deal stages\n $reportData = $this->validateDealStages($data, $reportData, $team, $type);\n\n // Validate playbook categories\n $reportData = $this->validatePlaybookCategories($data, $reportData, $team);\n\n // Validate recipients\n $reportData['recipients'] = [\n 'users' => $this->validateAndGetUserIdsByTeam($team, $data['recipients'] ?? []),\n ];\n\n if (isset($data['jiminny_recipients'])) {\n // Validate Jiminny recipients\n $reportData['jiminny_recipients'] = [\n 'users' => $this->validateAndGetJiminnyUserIds((array) $data['jiminny_recipients']),\n ];\n }\n\n return $reportData;\n }\n\n private function validateDealValues(array $data, array $reportData): array\n {\n if (isset($data['min_deal_value'])) {\n $reportData['deal_value_min'] = (int) $data['min_deal_value'];\n\n if ($reportData['deal_value_min'] > 4294967295 || $reportData['deal_value_min'] < 0) {\n throw new InvalidArgumentException('Min deal value should be between 0 and 4294967295');\n }\n }\n\n if (isset($data['max_deal_value'])) {\n $reportData['deal_value_max'] = (int) $data['max_deal_value'];\n\n if ($reportData['deal_value_max'] > 4294967295 || $reportData['deal_value_max'] < 0) {\n throw new InvalidArgumentException('Max deal value should be between 0 and 4294967295');\n }\n }\n\n if (isset($data['min_deal_value'], $data['max_deal_value'])\n && $data['min_deal_value'] > $data['max_deal_value']\n ) {\n throw new InvalidArgumentException('Min deal value cannot be greater than max deal value');\n }\n\n return $reportData;\n }\n\n private function validateDateRange(array $data, array $reportData, string $frequency): array\n {\n // Set date range only for one_off frequency\n if ($frequency === 'one_off') {\n if (isset($data['start_date_period'])) {\n $reportData['from'] = $this->parseDate($data['start_date_period']);\n }\n\n if (isset($data['end_date_period'])) {\n $reportData['to'] = $this->parseDate($data['end_date_period']);\n }\n\n if (empty($reportData['from']) || empty($reportData['to'])) {\n throw new InvalidArgumentException(\n 'Start date and end date are required for one_off frequency'\n );\n }\n } else {\n $reportData['from'] = null;\n $reportData['to'] = null;\n }\n\n return $reportData;\n }\n\n private function validateCallDurations(array $data, array $reportData): array\n {\n // Convert call durations from minutes to seconds\n if (isset($data['min_call_duration'])) {\n $reportData['call_duration_min'] = (int) $data['min_call_duration'] * 60;\n\n if ($reportData['call_duration_min'] > 4294967295 || $reportData['call_duration_min'] < 0) {\n throw new InvalidArgumentException('Min call duration should be between 0 and 4294967295');\n }\n }\n\n if (isset($data['max_call_duration'])) {\n $reportData['call_duration_max'] = (int) $data['max_call_duration'] * 60;\n\n if ($reportData['call_duration_max'] > 4294967295 || $reportData['call_duration_max'] < 0) {\n throw new InvalidArgumentException('Max call duration should be between 0 and 4294967295');\n }\n }\n\n return $reportData;\n }\n\n private function validateCallTypes(array $data, array $reportData): array\n {\n // Set call types\n $reportData['call_types'] = $data['call_type'] ?? [];\n if (empty($reportData['call_types'])) {\n $reportData['call_types'] = self::getCallTypes();\n }\n\n foreach ($reportData['call_types'] as $callType) {\n if (! in_array($callType, self::getCallTypes(), true)) {\n throw new InvalidArgumentException(sprintf('Call type %s is invalid', $callType));\n }\n }\n\n return $reportData;\n }\n\n private function validateMediaTypes(array $data, array $reportData): array\n {\n // Set media types from input data\n $reportData['media_types'] = $data['media_types'] ?? [];\n\n if (empty($reportData['media_types'])) {\n throw new InvalidArgumentException('Media types are required');\n }\n\n foreach ($reportData['media_types'] as $mediaType) {\n if (! in_array($mediaType, self::MEDIA_TYPES, true)) {\n throw new InvalidArgumentException(sprintf('Media type %s is invalid', $mediaType));\n }\n }\n\n return $reportData;\n }\n\n private function validateDealStages(array $data, array $reportData, Team $team, string $reportType): array\n {\n // Validate and set deal stages\n if (isset($data['deal_stage_at_call'])) {\n $reportData['deal_at_call_stages'] =\n $this->validateAndGetDealStageIds($team, $data['deal_stage_at_call'], 'Deal stage at call');\n }\n\n if (isset($data['current_deal_stage'])) {\n $reportData['current_deal_stages'] =\n $this->validateAndGetDealStageIds($team, $data['current_deal_stage'], 'Current deal stage');\n }\n\n // Ensure current_deal_stage is not provided for loss_analysis report type\n if ($reportType === self::TYPE_LOSS_ANALYSIS && ! empty($data['current_deal_stage'])) {\n throw new InvalidArgumentException('Current deal stage is not applicable for Loss Analysis reports');\n }\n\n return $reportData;\n }\n\n // transform uuid to id\n private function validatePlaybookCategories(array $data, array $reportData, Team $team): array\n {\n $key = 'playbook_categories';\n\n if (isset($data[$key])) {\n $payloadIds = $data[$key];\n $ids = [];\n\n foreach ($payloadIds as $uuid) {\n $uuid = (string) $uuid;\n\n try {\n $playbookCategory = $this->playbookCategoryRepository->findByUuid($uuid);\n } catch (Throwable $throwable) {\n Log::error(__METHOD__ . ' ' . $throwable->getMessage());\n\n throw new InvalidArgumentException(sprintf('Playbook category %s not found', $uuid));\n }\n\n if (! $playbookCategory) {\n throw new InvalidArgumentException(sprintf('Playbook category %s not found', $uuid));\n }\n\n if (! $playbookCategory->hasPlaybook()) {\n throw new InvalidArgumentException(sprintf('Playbook category %s has no playbook', $uuid));\n }\n\n if ($playbookCategory->getPlaybook()->getTeamId() !== $team->getId()) {\n throw new InvalidArgumentException(\n sprintf('Playbook category %s not found for team %s', $uuid, $team->getUuid())\n );\n }\n\n $ids[] = $playbookCategory->getId();\n }\n\n $reportData[$key] = $ids;\n }\n\n return $reportData;\n }\n\n private function validateReportStatus($status): bool\n {\n if (! in_array($status, [true, false], true)) {\n throw new InvalidArgumentException('Report status is invalid');\n }\n\n return $status;\n }\n\n private function validateReportType($type): string\n {\n if (! in_array($type, self::getTypes(), true)) {\n throw new InvalidArgumentException(sprintf('Report type is invalid: %s', $type));\n }\n\n return $type;\n }\n\n private function validateFrequency($frequency): string\n {\n if (! in_array($frequency, self::getFrequencies(), true)) {\n throw new InvalidArgumentException('Frequency is invalid');\n }\n\n return $frequency;\n }\n\n private function validateAdditionalPromptInput(?string $additionalPromptInput): ?string\n {\n if ($additionalPromptInput && strlen($additionalPromptInput) > 5000) {\n throw new InvalidArgumentException('Additional Prompt Input should be less than 5000 characters');\n }\n\n return $additionalPromptInput;\n }\n\n private function validateCustomReportName(?string $customReportName): ?string\n {\n if ($customReportName === null || $customReportName === '') {\n return null;\n }\n\n if (strlen($customReportName) > 70) {\n throw new InvalidArgumentException('Custom report name should be less than 70 characters');\n }\n\n return $customReportName;\n }\n\n private function validateOrganization(?string $organizationUuid): Team\n {\n if (! $organizationUuid) {\n throw new InvalidArgumentException('Organization is required');\n }\n\n $team = $this->teamRepository->idOrUuid($organizationUuid);\n\n if (! $team) {\n throw new InvalidArgumentException('Organization not found');\n }\n\n if (! $team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {\n throw new InvalidArgumentException('Organization does not have the Automated Reports feature');\n }\n\n return $team;\n }\n\n private function validateAndGetGroupIds(Team $team, array $teamUuids): array\n {\n $groupIds = [];\n\n foreach ($teamUuids as $uuid) {\n $group = $this->groupRepository->findByUuid($uuid);\n\n if ($group === null || $group->getTeamId() !== $team->getId()) {\n throw new InvalidArgumentException(\n sprintf('Group %s not found for team %s', $uuid, $team->getUuid())\n );\n }\n\n $groupIds[] = $group->getId();\n\n }\n\n return $groupIds;\n }\n\n private function validateAndGetDealStageIds(Team $team, array $stageUuids, string $propertyLabel): array\n {\n $stageIds = [];\n\n foreach ($stageUuids as $uuid) {\n $stage = $this->stageRepository->findByUuid($uuid);\n\n if ($stage === null || $stage->getTeamId() !== $team->getId()) {\n throw new InvalidArgumentException(\n sprintf('Stage %s not found for team %s for %s', $uuid, $team->getUuid(), $propertyLabel)\n );\n }\n\n $stageIds[] = $stage->getId();\n }\n\n return $stageIds;\n }\n\n private function validateAndGetUserIds(array $userUuids, callable $teamCheck): array\n {\n if (empty($userUuids)) {\n return [];\n }\n\n $userIds = [];\n\n foreach ($userUuids as $uuid) {\n $user = $this->userRepository->findByUuid($uuid);\n\n if (! $user || ! $user->isStatusActive()) {\n throw new InvalidArgumentException(\n sprintf('User %s not found or is not active', $uuid)\n );\n }\n\n if (! $teamCheck($user)) {\n throw new InvalidArgumentException(\n sprintf('User %s does not belong to the allowed team(s)', $uuid)\n );\n }\n\n $userIds[] = $user->getId();\n }\n\n return $userIds;\n }\n\n private function validateAndGetUserIdsByTeam(Team $team, array $userUuids): array\n {\n return $this->validateAndGetUserIds($userUuids, fn ($user) => $user->getTeamId() === $team->getId());\n }\n\n private function validateAndGetJiminnyUserIds(array $userUuids): array\n {\n $allowedTeamIds = config('kiosk.teamIds', []);\n\n return $this->validateAndGetUserIds($userUuids, fn ($user) => in_array($user->getTeamId(), $allowedTeamIds, true));\n }\n\n private function parseDate(string $dateString): string\n {\n return date('Y-m-d H:i:s', strtotime($dateString));\n }\n\n private function generateReportResultViewUrl(AutomatedReportResult $result): string\n {\n $mediaResource = $this->getReportMediaRouteResource($result);\n\n return route('ai-reports.' . $mediaResource . '.view', ['uuid' => $result->getUuid()]);\n }\n\n private function generateReportResultDownloadUrl(AutomatedReportResult $result): string\n {\n $mediaResource = $this->getReportMediaRouteResource($result);\n\n return route('ai-reports.' . $mediaResource . '.download', ['uuid' => $result->getUuid()]);\n }\n\n private function getReportMediaRouteResource(AutomatedReportResult $result): string\n {\n if ($result->getMediaType() === self::MEDIA_TYPE_PDF) {\n return self::PDF_KEY;\n } elseif ($result->getMediaType() === self::MEDIA_TYPE_PODCAST) {\n return self::AUDIO_KEY;\n }\n\n throw new \\InvalidArgumentException('Unknown media type.');\n }\n\n public function getMediaPath(AutomatedReportResult $result): ?string\n {\n $url = match ($result->getMediaType()) {\n self::MEDIA_TYPE_PDF => $result->getPdfUrl(),\n self::MEDIA_TYPE_PODCAST => $result->getPodcastAudioUrl(),\n default => null,\n };\n\n if ($url === null) {\n return null;\n }\n\n $path = parse_url(trim($url, '\"\\''), PHP_URL_PATH);\n\n return $path ?: null;\n }\n\n public function getFilenameSuffix(AutomatedReportResult $result): ?string\n {\n return match ($result->getMediaType()) {\n self::MEDIA_TYPE_PODCAST => 'Podcast',\n default => null,\n };\n }\n\n public function getMailSubjectSuffix(AutomatedReportResult $result): string\n {\n return match ($result->getMediaType()) {\n self::MEDIA_TYPE_PDF => 'report',\n self::MEDIA_TYPE_PODCAST => 'podcast',\n default => '',\n };\n }\n\n public function getMediaTypeMetadata(AutomatedReportResult $result): array\n {\n return match ($result->getMediaType()) {\n self::MEDIA_TYPE_PODCAST => ['extension' => 'mp3', 'mime' => 'audio/mpeg'],\n self::MEDIA_TYPE_PDF => ['extension' => 'pdf', 'mime' => 'application/pdf'],\n default => ['extension' => null, 'mime' => null],\n };\n }\n\n public function deleteS3Files(AutomatedReportResult $result): void\n {\n $teamUuid = $result->getReport()->getTeam()->getUuid();\n $reportUuid = $result->getUuid();\n\n // delete all files for a report uuid no mather of pdf, podcast, or both\n // in case of both - the podcast files are linked to the pdf (parent) uuid\n // pdf and podcast date times should be close\n $path = sprintf('%s/%s/%s', $teamUuid, self::S3_DIR, $reportUuid);\n\n foreach (self::FILE_EXTENSIONS_VARIANTS as $extension) {\n $file = $path . '.' . $extension;\n\n if (Storage::exists($file)) {\n Storage::delete($file);\n Log::info('[Reports] Deleted S3 file', [\n 'path' => $file,\n ]);\n }\n }\n\n foreach (self::FILE_PODCAST_EXTENSIONS_VARIANTS as $extension) {\n $file = $path . '_podcast.' . $extension;\n\n if (Storage::exists($file)) {\n Storage::delete($file);\n Log::info('[Reports] Deleted Podcast S3 file', [\n 'path' => $file,\n ]);\n }\n }\n }\n\n /**\n *\n * @param int|null $teamId Optional team ID to filter results\n *\n * @return Collection<int, int> Collection of team IDs\n */\n public function getTeamIdsWithReportsResults(?int $teamId = null): Collection\n {\n return $this->automatedReportsRepository->getTeamIdsWithReportsResults($teamId);\n }\n\n /**\n * Core delete logic for report results using a query\n *\n * @param Builder $query\n * @param array $logContext\n *\n * @return int\n */\n private function deleteReportResultsByQuery(Builder $query, array $logContext = []): int\n {\n $deletedCount = 0;\n\n if ($query->exists()) {\n Log::info(\n 'Run delete report results',\n array_merge(\n $logContext,\n [\n 'service' => 'AutomatedReportsService',\n ]\n )\n );\n\n $query->chunkById(50, function ($results) use (&$deletedCount, $logContext) {\n foreach ($results as $result) {\n $this->deleteReportResult($result);\n $deletedCount++;\n\n Log::info(\n 'Deleted a report result',\n array_merge(\n $logContext,\n [\n 'result_id' => $result->getId(),\n 'report_id' => $result->getReportId(),\n ]\n )\n );\n }\n });\n }\n\n return $deletedCount;\n }\n\n /**\n * Delete report results for a team by retention period\n *\n * @param Team $team\n * @param CarbonImmutable $retentionDate\n *\n * @return int Number of deleted report results\n */\n public function deleteReportsResultsInRetentionPeriod(Team $team, CarbonImmutable $retentionDate): int\n {\n $reportIds = $this->automatedReportsRepository->getReportIdsByTeam($team);\n\n if ($reportIds->isEmpty()) {\n return 0;\n }\n\n $query = $this->automatedReportsRepository\n ->getReportResultsQueryForRetention($team, $retentionDate);\n\n return $this->deleteReportResultsByQuery($query, [\n 'team_id' => $team->getId(),\n 'retention_date' => $retentionDate->toDateTimeString(),\n ]);\n }\n\n /**\n * Delete ALL report results for a specific automated report\n *\n * @param string $uuid\n *\n * @return int\n */\n public function deleteReportResults(string $uuid): int\n {\n $report = $this->getReport($uuid);\n\n $query = $this->automatedReportsRepository->getResultsByReportQuery($report);\n\n return $this->deleteReportResultsByQuery($query, [\n 'report_uuid' => $uuid,\n 'report_id' => $report->getId(),\n ]);\n }\n\n public function deleteReportResult(AutomatedReportResult $result): void\n {\n $this->deleteS3Files($result);\n\n $result->delete();\n }\n\n /**\n * Get all reports for a specific team\n *\n * @param Team $team\n *\n * @return \\Illuminate\\Database\\Eloquent\\Collection\n */\n public function getTeamReports(Team $team): \\Illuminate\\Database\\Eloquent\\Collection\n {\n return $this->automatedReportsRepository->getReportsByTeam($team);\n }\n\n /**\n * Get all report results for a specific report\n *\n * @param AutomatedReport $report\n *\n * @return \\Illuminate\\Database\\Eloquent\\Collection\n */\n public function getReportResults(AutomatedReport $report): \\Illuminate\\Database\\Eloquent\\Collection\n {\n return $this->automatedReportsRepository->getResultsByReport($report);\n }\n\n public function deleteAllReportResults(AutomatedReport $report): void\n {\n $results = $this->getReportResults($report);\n\n /** @var AutomatedReportResult $result */\n foreach ($results as $result) {\n Log::info('Deleting result', [\n 'report' => $report->getId(),\n 'result' => $result->getId(),\n ]);\n\n $this->deleteReportResult($result);\n }\n }\n\n public function deleteAllData(Team $team): void\n {\n Log::info('Deleting automated report and results for team', [\n 'team' => $team->getId(),\n ]);\n\n $reports = $this->getTeamReports($team);\n\n /** @var AutomatedReport $report */\n foreach ($reports as $report) {\n Log::info('Deleting report', [\n 'team' => $team->getId(),\n 'report' => $report->getId(),\n ]);\n\n $this->deleteAllReportResults($report);\n\n $report->delete();\n }\n }\n}","depth":4,"value":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Services\\Kiosk\\AutomatedReports;\n\nuse Carbon\\CarbonImmutable;\nuse Carbon\\CarbonInterface;\nuse Carbon\\Exceptions\\InvalidFormatException;\nuse DateTime;\nuse DateTimeInterface;\nuse DateTimeZone;\nuse Illuminate\\Contracts\\Bus\\Dispatcher as BusDispatcher;\nuse Illuminate\\Database\\Eloquent\\Builder;\nuse Illuminate\\Support\\Carbon;\nuse Illuminate\\Support\\Collection;\nuse Illuminate\\Support\\Facades\\Log;\nuse Illuminate\\Support\\Facades\\Storage;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinition\\InputTypeEnum;\nuse Jiminny\\Component\\AskAnything\\AskAnythingPromptService;\nuse Jiminny\\Component\\AskAnything\\Dtos\\AskAnythingPromptDto;\nuse Jiminny\\Component\\UrlGenerator\\Webhook;\nuse Jiminny\\Contracts\\Repositories\\PlaybookCategoryRepository;\nuse Jiminny\\Contracts\\Repositories\\TeamRepository;\nuse Jiminny\\Contracts\\Repositories\\UserRepository;\nuse Jiminny\\Exceptions\\ApplicationException;\nuse Jiminny\\Exceptions\\InvalidArgumentException;\nuse Jiminny\\Exceptions\\ModelNotFoundException;\nuse Jiminny\\Jobs\\AutomatedReports\\RequestGenerateReportJob;\nuse Jiminny\\Models\\Activity\\Search;\nuse Jiminny\\Models\\AskAnything\\AskAnythingPrompt;\nuse Jiminny\\Models\\AskAnything\\AskAnythingPromptTarget;\nuse Jiminny\\Models\\AutomatedReport;\nuse Jiminny\\Models\\AutomatedReportResult;\nuse Jiminny\\Models\\Contracts\\UserContract;\nuse Jiminny\\Models\\Feature\\FeatureEnum;\nuse Jiminny\\Models\\Team;\nuse Jiminny\\Models\\User;\nuse Jiminny\\Repositories\\AskAnythingRepository;\nuse Jiminny\\Repositories\\AutomatedReportsRepository;\nuse Jiminny\\Repositories\\GroupRepository;\nuse Jiminny\\Repositories\\SearchRepository;\nuse Jiminny\\Repositories\\StageRepository;\nuse Throwable;\n\nclass AutomatedReportsService\n{\n public const string TYPE_LOSS_ANALYSIS = 'loss_analysis';\n public const string TYPE_ASK_JIMINNY = 'ask_jiminny';\n\n /**\n * Standard report types (used by kiosk for existing automated reports).\n */\n // @TODO this will add filter, however if we need to control feature by FF we need conditional logic\n public const array TYPES = [\n ['id' => 'exec_summary', 'name' => 'Exec Summary'],\n ['id' => 'coaching_profiles', 'name' => 'Coaching Profiles'],\n ['id' => 'product_feedback', 'name' => 'Product Feedback'],\n ['id' => self::TYPE_LOSS_ANALYSIS, 'name' => 'Loss Analysis'],\n// ['id' => 'questions', 'name' => 'Questions'],\n// ['id' => 'statistical_quant', 'name' => 'Statistical Quantitative'],\n ];\n\n public const array ALL_TYPES = [\n ...self::TYPES,\n ['id' => self::TYPE_ASK_JIMINNY, 'name' => 'Ask Jiminny'],\n ];\n\n public const string FREQUENCY_DAILY = 'daily';\n public const string FREQUENCY_WEEKLY = 'weekly';\n public const string FREQUENCY_MONTHLY = 'monthly';\n public const string FREQUENCY_QUARTERLY = 'quarterly';\n public const string FREQUENCY_ONE_OFF = 'one_off';\n\n /**\n * Frequencies for standard (non-Ask Jiminny) reports.\n */\n public const array FREQUENCIES = [\n ['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],\n ['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],\n ['id' => self::FREQUENCY_QUARTERLY, 'name' => 'Quarterly'],\n ['id' => self::FREQUENCY_ONE_OFF, 'name' => 'One-off'],\n ];\n\n /**\n * Frequencies for Ask Jiminny reports.\n */\n public const array ASK_JIMINNY_FREQUENCIES = [\n ['id' => self::FREQUENCY_DAILY, 'name' => 'Daily'],\n ['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],\n ['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],\n ];\n\n public const string MEDIA_TYPE_PDF = 'pdf';\n public const string MEDIA_TYPE_PODCAST = 'podcast';\n public const array MEDIA_TYPES = [self::MEDIA_TYPE_PDF, self::MEDIA_TYPE_PODCAST];\n public const array MEDIA_TYPE_OBJECT_PDF = ['id' => self::MEDIA_TYPE_PDF, 'name' => 'PDF'];\n public const array MEDIA_TYPE_OBJECT_PODCAST = ['id' => self::MEDIA_TYPE_PODCAST, 'name' => 'Podcast'];\n public const array MEDIA_TYPE_OBJECTS = [self::MEDIA_TYPE_OBJECT_PDF, self::MEDIA_TYPE_OBJECT_PODCAST];\n\n public const array CALL_TYPE_CONFERENCE = ['id' => 'conference', 'name' => 'Conference'];\n public const array CALL_TYPE_DIALER = ['id' => 'dialer', 'name' => 'Dialer'];\n public const int SENT_REPORT_AT_HOURS = 5;\n public const string PDF_KEY = 'pdf';\n public const string AUDIO_KEY = 'audio';\n\n private const array ALL_FREQUENCIES = [\n ['id' => self::FREQUENCY_DAILY, 'name' => 'Daily'],\n ['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],\n ['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],\n ['id' => self::FREQUENCY_QUARTERLY, 'name' => 'Quarterly'],\n ['id' => self::FREQUENCY_ONE_OFF, 'name' => 'One-off'],\n ];\n private const string S3_DIR = 'reports';\n private const array FILE_EXTENSIONS_VARIANTS = ['html', 'MD', 'pdf'];\n private const array FILE_PODCAST_EXTENSIONS_VARIANTS = ['json', 'mp3', 'ssml'];\n\n public function __construct(\n private readonly TeamRepository $teamRepository,\n private readonly GroupRepository $groupRepository,\n private readonly UserRepository $userRepository,\n private readonly StageRepository $stageRepository,\n private readonly DealStagesService $dealStagesService,\n private readonly RecipientsService $recipientsService,\n private readonly AutomatedReportsRepository $automatedReportsRepository,\n private readonly Webhook $webhookService,\n private readonly BusDispatcher $dispatcher,\n private readonly ActivityTypeService $activityTypeService,\n private readonly PlaybookCategoryRepository $playbookCategoryRepository,\n private readonly AskAnythingPromptService $askAnythingPromptService,\n private readonly SearchRepository $activitySearchRepository,\n private readonly AskAnythingRepository $askAnythingRepository,\n ) {\n }\n\n public static function getTypes(): array\n {\n $types = self::TYPES;\n\n return array_map(static function ($type) {\n return $type['id'];\n }, $types);\n }\n\n public static function getCallTypes(): array\n {\n return array_map(static function ($callType) {\n return $callType['id'];\n }, [self::CALL_TYPE_CONFERENCE, self::CALL_TYPE_DIALER]);\n }\n\n public static function getFrequencies(): array\n {\n return array_map(static function ($frequency) {\n return $frequency['id'];\n }, self::FREQUENCIES);\n }\n\n // front-facing structure\n public function getReportEnabledFieldData(bool $value = false): array\n {\n return [\n 'id' => 'report_enabled',\n 'label' => '',\n 'inputType' => InputTypeEnum::TOGGLE,\n 'value' => $value,\n ];\n }\n\n // Organizations = Teams\n public function getOrganizationFieldData(?string $value = null, bool $shortVersion = false): array\n {\n $options = $this->getTeams();\n\n if ($shortVersion) {\n return [\n 'id' => 'organization',\n 'label' => 'Organization',\n 'options' => $options,\n ];\n }\n\n return [\n 'id' => 'organization',\n 'label' => 'Organization',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => $options,\n 'value' => $value,\n 'dependencies' => [\n 'teams',\n 'deal_stage_at_call',\n 'current_deal_stage',\n 'recipients',\n ActivityTypeService::PLAYBOOK_CATEGORIES_KEY,\n ],\n 'dependsOn' => [],\n ];\n }\n\n // Teams = Groups\n public function getTeamFieldData(array $options = [], array $value = [], bool $shortVersion = false): array\n {\n if ($shortVersion) {\n return [\n 'id' => 'teams',\n 'label' => 'Team',\n 'options' => $options,\n ];\n }\n\n return [\n 'id' => 'teams',\n 'label' => 'Team',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'required' => false,\n 'placeholder' => 'Select',\n 'options' => $options,\n 'value' => $value, // value should be an array of objects {id, name}\n 'dependencies' => [ActivityTypeService::PLAYBOOK_CATEGORIES_KEY],\n 'dependsOn' => [],\n ];\n }\n\n public function getReportTypeFieldData(?string $value = null, bool $shortVersion = false, ?Team $team = null): array\n {\n $types = [];\n if ($team instanceof Team) {\n if ($team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {\n $types = self::TYPES;\n }\n if ($team->hasFeature(FeatureEnum::ASK_JIMINNY_REPORTS)) {\n $types[] = ['id' => self::TYPE_ASK_JIMINNY, 'name' => 'Ask Jiminny'];\n }\n } else {\n $types = self::TYPES;\n }\n\n if ($shortVersion) {\n return [\n 'id' => 'report_type',\n 'label' => 'Report Type',\n 'options' => $types,\n ];\n }\n\n return [\n 'id' => 'report_type',\n 'label' => 'Report Type',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => $types,\n 'value' => $value,\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getFrequencyFieldData(?string $value = null): array\n {\n return [\n 'id' => 'frequency',\n 'label' => 'Frequency',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => self::FREQUENCIES,\n 'value' => $value,\n 'dependencies' => ['period'],\n 'dependsOn' => [],\n ];\n }\n\n public function getPeriodFieldData(?string $valueStartDate = null, ?string $valueEndDate = null): array\n {\n return [\n 'id' => 'period',\n 'label' => 'Select one-off period',\n 'inputType' => InputTypeEnum::DATE_RANGE,\n 'required' => true,\n 'placeholder' => 'Select',\n 'value' => ['startDate' => $valueStartDate, 'endDate' => $valueEndDate],\n 'queryParams' => [\n 'startDate' => 'start_date_period',\n 'endDate' => 'end_date_period',\n ],\n 'dependencies' => [],\n 'dependsOn' => ['frequency'],\n ];\n }\n\n public function getActivityTypesFieldData(?Team $team = null, array $value = [], array $teamsFilter = []): array\n {\n return $this->activityTypeService->getActivityTypeFieldData(team: $team, value: $value, groupIds: $teamsFilter);\n }\n\n public function getDealStageAtCallFieldData(?Team $team = null, array $value = []): array\n {\n return $this->dealStagesService->getDealStageAtCallFieldData(team: $team, value: $value);\n }\n\n public function getCurrentDealStageFieldData(?Team $team = null, array $value = []): array\n {\n return $this->dealStagesService->getCurrentDealStageFieldData(team: $team, value: $value);\n }\n\n public function getDealValueFieldData(?int $valueMin = null, ?int $valueMax = null): array\n {\n return [\n 'id' => 'deal_value',\n 'label' => 'Deal Value',\n 'inputType' => InputTypeEnum::INTEGER_RANGE,\n 'required' => false,\n 'value' => ['min' => $valueMin, 'max' => $valueMax],\n 'queryParams' => [\n 'min' => 'min_deal_value',\n 'max' => 'max_deal_value',\n ],\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getCallTypeFieldData(bool $conferenceOn = false, bool $dialerOn = false): array\n {\n $value = [];\n $conferenceOn && $value[] = self::CALL_TYPE_CONFERENCE;\n $dialerOn && $value[] = self::CALL_TYPE_DIALER;\n\n return [\n 'id' => 'call_type',\n 'label' => 'Call Type',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'required' => true,\n 'options' => [\n self::CALL_TYPE_CONFERENCE,\n self::CALL_TYPE_DIALER,\n ],\n 'value' => $value,\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getMediaTypeFieldData(?AutomatedReport $report = null): array\n {\n $value = [];\n\n if ($report) {\n $value = $this->transformMediaTypes($report);\n }\n\n return [\n 'id' => 'media_types',\n 'label' => 'Export as',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'required' => true,\n 'options' => self::MEDIA_TYPE_OBJECTS,\n 'value' => $value,\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getCallDurationFieldData(?int $valueMin = null, ?int $valueMax = null): array\n {\n return [\n 'id' => 'call_duration',\n 'label' => 'Call Duration',\n 'inputType' => InputTypeEnum::INTEGER_RANGE,\n 'required' => false,\n 'value' => ['min' => $valueMin, 'max' => $valueMax],\n 'queryParams' => [\n 'min' => 'min_call_duration',\n 'max' => 'max_call_duration',\n ],\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getRecipientsFieldData(?Team $team = null, array $value = []): array\n {\n return $this->recipientsService->getRecipientsFieldData(team: $team, value: $value);\n }\n\n public function getJiminnyRecipientsFieldData(array $value = []): array\n {\n return $this->recipientsService->getJiminnyRecipientsFieldData($value);\n }\n\n public function getAdditionalPromptInputFieldData(?string $value = null): array\n {\n return [\n 'id' => 'additional_prompt_input',\n 'label' => 'Special requirements',\n 'inputType' => InputTypeEnum::TEXTAREA,\n 'required' => false,\n 'placeholder' => 'What should be the focus of the report?',\n 'value' => $value,\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getCustomReportNameFieldData(?string $value = null): array\n {\n return [\n 'id' => 'custom_name',\n 'label' => 'Custom report name',\n 'inputType' => InputTypeEnum::TEXT,\n 'required' => false,\n 'placeholder' => 'Enter custom name',\n 'value' => $value,\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n // data providers\n public function getTeams(): array\n {\n $teams = $this->teamRepository->getTeamsForKiosk(status: Team::STATUS_ACTIVE);\n\n $teamData = [];\n foreach ($teams as $team) {\n if (! $team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {\n continue;\n }\n\n $teamData[] = $this->transformTeam($team);\n }\n\n return $teamData;\n }\n\n public function getTeamGroups(string $teamUuid): array\n {\n $data = [];\n $team = $this->getTeam($teamUuid);\n\n if ($team !== null) {\n $groups = $team->groups()->get();\n\n foreach ($groups as $group) {\n $data[] = [\n 'id' => $group->getUuid(),\n 'name' => $group->getName(),\n ];\n }\n }\n\n return $data;\n }\n\n public function getTeamsGroupsOptions(array $filterTeamUuids = []): array\n {\n $data = [];\n $teams = $this->getTeams();\n\n foreach ($teams as $team) {\n if (! empty($filterTeamUuids) && ! in_array($team['id'], $filterTeamUuids, true)) {\n continue;\n }\n\n $data[] = [\n 'label' => $team['name'],\n 'groups' => $this->getTeamGroups($team['id']),\n ];\n }\n\n return $data;\n }\n\n public function getTeam(string $teamUuid): ?Team\n {\n return $this->teamRepository->idOrUuid($teamUuid);\n }\n\n public function getTeamById(int $teamId): ?Team\n {\n return $this->teamRepository->find($teamId);\n }\n\n public function getGroupsUuids(AutomatedReport $report): array\n {\n $uuids = [];\n $reportGroups = $report->getGroups();\n foreach ($reportGroups as $groupId) {\n if ($group = $this->groupRepository->find($groupId)) {\n $uuids[] = $group->getUuid();\n }\n }\n\n return $uuids;\n }\n\n public function getPlaybookCategoriesUuids(AutomatedReport $report): array\n {\n $uuids = [];\n $playbookCategories = $report->getPlaybookCategories();\n foreach ($playbookCategories as $id) {\n if ($category = $this->playbookCategoryRepository->find($id)) {\n $uuids[] = $category->getUuid();\n }\n }\n\n return $uuids;\n }\n\n public function getDealAtCallStagesUuids(AutomatedReport $report): array\n {\n $uuids = [];\n $reportStages = $report->getDealAtCallStages();\n foreach ($reportStages as $id) {\n if ($stage = $this->stageRepository->find($id)) {\n $uuids[] = $stage->getUuid();\n }\n }\n\n return $uuids;\n }\n\n public function getCurrentDealStagesUuids(AutomatedReport $report): array\n {\n $uuids = [];\n $reportStages = $report->getCurrentDealStages();\n foreach ($reportStages as $id) {\n if ($stage = $this->stageRepository->find($id)) {\n $uuids[] = $stage->getUuid();\n }\n }\n\n return $uuids;\n }\n\n public function getUsersUuids(AutomatedReport $report): array\n {\n return $this->extractUserUuids($report->getRecipients());\n }\n\n public function getJiminnyUsersUuids(AutomatedReport $report): array\n {\n return $this->extractUserUuids($report->getJiminnyRecipients());\n }\n\n /**\n * @param array<string, mixed> $recipients\n */\n private function extractUserUuids(array $recipients): array\n {\n $userIds = $recipients['users'] ?? [];\n\n return collect($userIds)\n ->map(fn ($id) => $this->userRepository->find((int) $id))\n ->filter()\n ->map(fn (UserContract $user) => $user->getUuid())\n ->values()\n ->all();\n }\n\n // get mail data\n public function getRecipientUsers(AutomatedReport $report): array\n {\n return $this->buildRecipientUsers($report->getRecipients());\n }\n\n private function getJiminnyRecipientUsers(AutomatedReport $report): array\n {\n return $this->buildRecipientUsers($report->getJiminnyRecipients());\n }\n\n /**\n * @param array<string, mixed> $recipients\n */\n private function buildRecipientUsers(array $recipients): array\n {\n $userIds = $recipients['users'] ?? [];\n\n return collect($userIds)\n ->map(fn ($id) => $this->userRepository->find((int) $id))\n ->filter()\n ->map(fn (UserContract $user) => [\n 'email' => $user->getEmailAddress(),\n 'name' => $user->getName(),\n 'timezone' => $user->getTimezone()->getName(),\n ])\n ->values()\n ->all();\n }\n\n public function getValidRecipientUsers(AutomatedReport $report, bool $includeJiminny = false): array\n {\n if ($report->isAskJiminnyReport()) {\n $recipients = $this->resolveAskJiminnyRecipients($report);\n } else {\n $recipients = $this->getRecipientUsers($report);\n if ($includeJiminny) {\n $recipients = array_merge($recipients, $this->getJiminnyRecipientUsers($report));\n }\n }\n\n $emails = [];\n\n return array_values(array_filter(\n $recipients,\n static function ($recipient) use (&$emails) {\n if (empty($recipient['email']) || in_array($recipient['email'], $emails, true)) {\n return false;\n }\n $emails[] = $recipient['email'];\n\n return true;\n }\n ));\n }\n\n private function resolveAskJiminnyRecipients(AutomatedReport $report): array\n {\n $recipients = [];\n\n $creator = $report->getCreator();\n if ($creator !== null) {\n $recipients[] = [\n 'email' => $creator->getEmailAddress(),\n 'name' => $creator->getName(),\n 'timezone' => $creator->getTimezone()->getName(),\n ];\n }\n\n return array_merge(\n $recipients,\n $this->buildRecipientUsers($report->getRecipients()),\n $this->getGroupRecipientUsers($report),\n );\n }\n\n private function getGroupRecipientUsers(AutomatedReport $report): array\n {\n $users = [];\n foreach ($report->getGroups() as $groupId) {\n $group = $this->groupRepository->find($groupId);\n if ($group === null) {\n continue;\n }\n foreach ($group->getMembers() as $member) {\n $users[] = [\n 'email' => $member->getEmailAddress(),\n 'name' => $member->getName(),\n 'timezone' => $member->getTimezone()->getName(),\n ];\n }\n }\n\n return $users;\n }\n\n public function getReportTypeName(AutomatedReportResult $report): string\n {\n $type = $report->getReport()->getType();\n\n $getType = $this->transformReportType($type);\n\n return $getType['name'];\n }\n\n public function getReportPeriodName(AutomatedReportResult $report): string\n {\n $from = $report->getFromDate();\n $to = $report->getToDate();\n $frequency = $report->getReport()->getFrequency();\n\n if ($from === null || $to === null) {\n if (! $report->getReport()->isAskJiminnyReport()) {\n $invalidPeriod = $from === null ? 'from' : 'to';\n\n throw new ApplicationException('Report period is invalid: ' . $invalidPeriod);\n }\n\n $period = $this->calculateFromAndToDatePeriod($frequency);\n $from = $period['fromDate'];\n $to = $period['toDate'];\n }\n\n return $this->formatReportPeriodName($frequency, $from, $to);\n }\n\n private function formatReportPeriodName(string $frequency, Carbon $from, Carbon $to): string\n {\n $fromYear = $from->format('Y');\n $toYear = $to->format('Y');\n $differentYears = $fromYear !== $toYear;\n\n switch ($frequency) {\n case self::FREQUENCY_DAILY:\n return $from->format('j M Y');\n\n case self::FREQUENCY_QUARTERLY:\n // 'Jan-Mar 2025' or 'Nov 2024-Jan 2025' if years differ\n $startMonth = $from->format('M');\n $endMonth = $to->copy()->subMonth();\n $endMonthName = $endMonth->format('M');\n $endMonthYear = $endMonth->format('Y');\n\n if ($differentYears) {\n return \"{$startMonth} {$fromYear} - {$endMonthName} {$endMonthYear}\";\n }\n\n return \"{$startMonth} - {$endMonthName} {$toYear}\";\n\n case self::FREQUENCY_MONTHLY:\n // 'May 2025' - monthly reports are always within the same year\n return $from->format('M Y');\n\n case self::FREQUENCY_WEEKLY:\n // '4 - 8 Aug 2025', '27 Oct - 3 Nov 2025', or '28 Dec 2024 - 3 Jan 2025' if years differ\n $startDay = $from->format('j');\n $endDay = $to->format('j');\n $startMonth = $from->format('M');\n $endMonth = $to->format('M');\n\n if ($differentYears) {\n return \"{$startDay} {$startMonth} {$fromYear} - {$endDay} {$endMonth} {$toYear}\";\n }\n\n if ($startMonth !== $endMonth) {\n return \"{$startDay} {$startMonth} - {$endDay} {$endMonth} {$toYear}\";\n }\n\n return \"{$startDay} - {$endDay} {$endMonth} {$toYear}\";\n\n case self::FREQUENCY_ONE_OFF:\n // '2 May-31 May 2025' or '15 Dec 2024-15 Jan 2025' if years differ\n $startDay = $from->format('j');\n $startMonth = $from->format('M');\n $endDay = $to->format('j');\n $endMonth = $to->format('M');\n\n // If same month and year, use a format like '2-31 May 2025'\n if ($startMonth === $endMonth && ! $differentYears) {\n return \"{$startDay} - {$endDay} {$startMonth} {$toYear}\";\n }\n\n // If different years, include both years\n if ($differentYears) {\n return \"{$startDay} {$startMonth} {$fromYear} - {$endDay} {$endMonth} {$toYear}\";\n }\n\n // Same year but different months\n return \"{$startDay} {$startMonth} - {$endDay} {$endMonth} {$toYear}\";\n\n default:\n // Default format for unknown frequencies\n return $from->format('j M Y') . ' - ' . $to->format('j M Y');\n }\n }\n\n public function getReportTeamsName(AutomatedReportResult $report): string\n {\n $groups = $report->getGroups();\n\n if (empty($groups)) {\n return 'All';\n }\n\n // Get group names from repository\n $groupNames = [];\n foreach ($groups as $groupId) {\n $group = $this->groupRepository->find($groupId);\n if ($group) {\n $groupNames[] = $group->getName();\n }\n }\n\n if (count($groupNames) === 1) {\n // Single team format\n $teamsName = $groupNames[0];\n } else {\n // Multiple teams format\n $teamsName = implode(', ', $groupNames);\n }\n\n return $teamsName;\n }\n\n public function getReportFileName(AutomatedReportResult $report): string\n {\n $customName = $report->getReport()->getCustomName();\n $periodName = $this->getReportPeriodName($report);\n $filenameSuffix = $this->getFilenameSuffix($report);\n\n if ($customName) {\n if ($filenameSuffix) {\n $customName .= \" {$filenameSuffix}\";\n }\n\n return $this->sanitizeFileName(\"{$customName} - {$periodName}\");\n }\n\n $baseName = $this->getReportTypeName($report);\n\n if ($filenameSuffix) {\n $baseName .= \" {$filenameSuffix}\";\n }\n\n return $this->sanitizeFileName(\"{$baseName} - {$periodName} - {$this->getReportTeamsName($report)}\");\n }\n\n public function getReportFileNameWithExtension(AutomatedReportResult $result): string\n {\n $extension = $this->getMediaTypeMetadata($result)['extension'];\n\n return $this->getReportFileName($result) . '.' . $extension;\n }\n\n public function sanitizeFileName(string $fileName): string\n {\n return str_replace(['/', '\\\\'], '-', $fileName);\n }\n\n public function isUserRecipientOfReport(User $user, AutomatedReport $report): bool\n {\n $recipients = array_map('intval', $report->getRecipients()['users'] ?? []);\n\n return in_array($user->getId(), $recipients);\n }\n\n public function transformReportResults(Collection $automatedReportResults): array\n {\n $data = [];\n foreach ($automatedReportResults as $automatedReportResult) {\n /** @var AutomatedReportResult $automatedReportResult */\n\n $report = $automatedReportResult->getReport();\n\n $createdBy = $report->getCreator();\n $creator = [\n 'id' => $createdBy?->getUuid(),\n 'name' => $createdBy?->getName(),\n 'email' => $createdBy?->getEmailAddress(),\n 'photoUrl' => $createdBy?->getPhotoUrl(),\n ];\n\n $data[] = [\n 'id' => $automatedReportResult->getUuid(),\n 'name' => $automatedReportResult->getName(),\n 'frequency' => $this->transformFrequency($report->getFrequency()),\n 'recipients' => [\n ...array_values($this->transformGroups(team: $report->getTeam(), groupsIds: $report->getGroups())),\n ...array_values($this->transformRecipients($report->getRecipients())),\n ],\n 'report_type' => $this->transformReportType($report->getType()),\n 'media_type' => $automatedReportResult->getMediaType(),\n 'downloadUrl' => $this->generateReportResultDownloadUrl($automatedReportResult),\n 'viewUrl' => $this->generateReportResultViewUrl($automatedReportResult),\n 'generated_at' => $automatedReportResult->getGeneratedAt()?->toIso8601String(),\n 'creator' => $creator,\n ];\n }\n\n return $data;\n }\n\n public function hasCallTypeConference(AutomatedReport $report): bool\n {\n return in_array(self::CALL_TYPE_CONFERENCE['id'], $report->getCallTypes(), true);\n }\n\n public function hasCallTypeDialer(AutomatedReport $report): bool\n {\n return in_array(self::CALL_TYPE_DIALER['id'], $report->getCallTypes(), true);\n }\n\n // transformers\n private function transformTeam(Team $team): array\n {\n if (! $team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {\n return [];\n }\n\n return [\n 'id' => $team->getUuid(),\n 'name' => $team->getName(),\n ];\n }\n\n private function transformReportFullView(AutomatedReport $report): array\n {\n $base = $this->transformReportBase($report);\n\n return $report->getType() === self::TYPE_ASK_JIMINNY\n ? $base + $this->transformAskJiminnyFields($report)\n : $base + $this->transformStandardReportFields($report);\n }\n\n private function transformReportBase(AutomatedReport $report): array\n {\n return [\n 'id' => $report->getUuid(),\n 'organization' => $this->transformOrganization(team: $report->getTeam()),\n 'report_type' => $this->transformReportType($report->getType()),\n 'frequency' => $this->transformFrequency($report->getFrequency()),\n ];\n }\n\n private function transformStandardReportFields(AutomatedReport $report): array\n {\n $team = $report->getTeam();\n\n return [\n 'report_enabled' => $report->getStatus(),\n 'start_date_period' => $report->getFrom()?->format('Y-m-d H:i:s'),\n 'end_date_period' => $report->getTo()?->format('Y-m-d H:i:s'),\n 'deal_value_min' => $report->getDealValueMin(),\n 'deal_value_max' => $report->getDealValueMax(),\n 'call_types' => $this->transformCallType($report->getCallTypes()),\n 'media_types' => $this->transformMediaTypes($report),\n 'call_duration_min' => $this->transformDurationToMinutes($report->getCallDurationMin()),\n 'call_duration_max' => $this->transformDurationToMinutes($report->getCallDurationMax()),\n 'teams' => $this->transformGroups(team: $team, groupsIds: $report->getGroups()),\n 'deal_at_call_stages' => $this->transformStages(team: $team, stagesIds: $report->getDealAtCallStages()),\n 'current_deal_stages' => $this->transformStages(team: $team, stagesIds: $report->getCurrentDealStages()),\n 'recipients' => $this->transformRecipients($report->getRecipients()),\n 'created_by' => $this->transformCreator($report->getCreator()),\n 'additional_prompt_input' => $report->getAdditionalPromptInput(),\n 'custom_name' => $report->getCustomName(),\n 'created_at' => $report->getCreatedAt()->format('Y-m-d H:i:s'),\n 'updated_at' => $report->getUpdatedAt()->format('Y-m-d H:i:s'),\n 'deleted_at' => $report->getDeletedAt()?->format('Y-m-d H:i:s'),\n ];\n }\n\n private function transformAskJiminnyFields(AutomatedReport $report): array\n {\n $team = $report->getTeam();\n $creatorId = $report->getAttribute('created_by');\n $explicitUserIds = array_values(array_filter(\n $report->getRecipients()['users'] ?? [],\n static fn ($id) => $id !== $creatorId\n ));\n\n return [\n 'report_name' => $report->getCustomName(),\n 'enabled' => $report->getStatus(),\n 'share_teams' => $this->transformGroups(team: $team, groupsIds: $report->getGroups()),\n 'share_users' => $this->transformRecipients(['users' => $explicitUserIds]),\n 'saved_search' => $this->transformSafeSearch($report->getSavedSearch()),\n 'ask_jiminny_prompt' => $this->transformAskJiminnyPrompt($report->getAskAnythingPrompt()),\n 'expires_on' => $report->getExpiresAt()?->format('Y-m-d'),\n ];\n }\n\n private function transformOrganization(?Team $team): array\n {\n return [\n 'id' => $team?->getUuid(),\n 'name' => $team?->getName(),\n ];\n }\n\n private function transformReportType(string $type): array\n {\n foreach (self::ALL_TYPES as $typeItem) {\n if ($typeItem['id'] === $type) {\n return $typeItem;\n }\n }\n\n return [];\n }\n\n private function transformCallType(array $types): array\n {\n $result = [];\n $callTypes = [self::CALL_TYPE_CONFERENCE, self::CALL_TYPE_DIALER];\n\n foreach ($types as $type) {\n foreach ($callTypes as $callTypeItem) {\n if ($callTypeItem['id'] === $type) {\n $result[] = $callTypeItem;\n\n break;\n }\n }\n }\n\n return $result;\n }\n\n private function transformMediaTypes(AutomatedReport $report): array\n {\n $values = [];\n\n foreach ($report->getMediaTypes() as $mediaType) {\n if (! in_array($mediaType, self::MEDIA_TYPES, true)) {\n continue;\n }\n\n $values[] = match ($mediaType) {\n self::MEDIA_TYPE_PDF => self::MEDIA_TYPE_OBJECT_PDF,\n self::MEDIA_TYPE_PODCAST => self::MEDIA_TYPE_OBJECT_PODCAST,\n };\n }\n\n return $values;\n }\n\n private function transformFrequency(string $frequency): array\n {\n foreach (self::ALL_FREQUENCIES as $frequencyItem) {\n if ($frequencyItem['id'] === $frequency) {\n return $frequencyItem;\n }\n }\n\n return [];\n }\n\n public function transformDurationToMinutes(?int $duration): ?int\n {\n if (! $duration) {\n return null;\n }\n\n return (int) ($duration / 60);\n }\n\n private function transformGroups(?Team $team, array $groupsIds): array\n {\n if (empty($groupsIds) || ! $team) {\n return [];\n }\n\n $data = [];\n foreach ($groupsIds as $groupId) {\n $group = $team->groups()->where('id', $groupId)->first();\n\n if ($group) {\n $data[] = [\n 'id' => $group->getUuid(),\n 'name' => $group->getName(),\n 'photoUrl' => $group->getPhotoUrl(),\n ];\n }\n }\n\n return $data;\n }\n\n private function transformStages(?Team $team, array $stagesIds): array\n {\n if (empty($stagesIds) || ! $team) {\n return [];\n }\n\n $data = [];\n foreach ($stagesIds as $stageId) {\n $stage = $team->stages()->where('id', $stageId)->first();\n\n if ($stage) {\n $data[] = [\n 'id' => $stage->getUuid(),\n 'name' => $stage->getName(),\n ];\n }\n }\n\n return $data;\n }\n\n private function transformRecipients(array $recipients): array\n {\n $users = [];\n foreach ($recipients['users'] ?? [] as $userId) {\n $users[] = $this->transformUser($userId);\n }\n\n return $users;\n }\n\n private function transformCreator(?User $user): ?array\n {\n if ($user === null) {\n return null;\n }\n\n return $this->transformUser($user->getId());\n }\n\n private function transformAskJiminnyPrompt(?AskAnythingPrompt $prompt): ?array\n {\n if ($prompt === null) {\n return null;\n }\n\n return [\n 'id' => $prompt->getUuid(),\n 'name' => $prompt->getTitle(),\n ];\n }\n\n private function transformSafeSearch(?Search $search): ?array\n {\n if ($search === null) {\n return null;\n }\n\n return [\n 'id' => $search->getUuid(),\n 'name' => $search->getName(),\n ];\n }\n\n private function transformUser(int $userId): array\n {\n /* @var ?User $user */\n $user = $this->userRepository->find($userId);\n\n return [\n 'id' => $user?->getUuid(),\n 'name' => $user?->getName(),\n 'email' => $user?->getEmailAddress(),\n 'photoUrl' => $user?->getPhotoUrl(),\n ];\n }\n\n public function create(array $data): array\n {\n $validatedData = $this->validateAndTransformData($data);\n $validatedData['created_by'] = auth()->id();\n\n $automatedReport = $this->automatedReportsRepository->create($validatedData);\n\n $this->generateOneOffReport($automatedReport);\n\n return $this->transformReportFullView($automatedReport);\n }\n\n public function update(string $uuid, array $data): array\n {\n $validatedData = $this->validateAndTransformData($data);\n $report = $this->automatedReportsRepository->findByUuid($uuid);\n\n if (! $report) {\n throw new InvalidArgumentException('Report not found');\n }\n\n $oldCustomName = $report->getCustomName();\n\n $automatedReport = $this->automatedReportsRepository->update($report, $validatedData);\n\n if ($oldCustomName !== $automatedReport->getCustomName()) {\n $this->updateResultNames($automatedReport);\n }\n\n $this->generateOneOffReport($automatedReport);\n\n return $this->transformReportFullView($automatedReport);\n }\n\n /**\n * Create an Ask Jiminny report.\n */\n public function createAskJiminnyReport(array $data, User $creator): array\n {\n $validatedData = $this->validateAskJiminnyReportData($data, $creator);\n $validatedData['created_by'] = $creator->getId();\n\n $automatedReport = $this->automatedReportsRepository->create($validatedData);\n\n return $this->transformReportFullView($automatedReport);\n }\n\n /**\n * Update an Ask Jiminny report.\n */\n public function updateAskJiminnyReport(AutomatedReport $report, array $data, User $user): array\n {\n if (! $report->isAskJiminnyReport()) {\n throw new InvalidArgumentException('Report is not an Ask Jiminny report');\n }\n\n $validatedData = $this->validateAskJiminnyReportData($data, $user);\n\n $oldCustomName = $report->getCustomName();\n\n $automatedReport = $this->automatedReportsRepository->update($report, $validatedData);\n\n if ($oldCustomName !== $automatedReport->getCustomName()) {\n $this->updateResultNames($automatedReport);\n }\n\n return $this->transformReportFullView($automatedReport);\n }\n\n public function updateAskJiminnyReportStatus(AutomatedReport $report, bool $status): array\n {\n $this->automatedReportsRepository->update($report, ['status' => $status]);\n\n return $this->transformReportFullView($report->fresh());\n }\n\n /**\n * Validate and transform data for Ask Jiminny reports.\n */\n private function validateAskJiminnyReportData(array $data, User $user): array\n {\n // Validate name\n $name = trim($data['report_name'] ?? '');\n if (empty($name)) {\n throw new InvalidArgumentException('Report name is required');\n }\n if (mb_strlen($name) > 50) {\n throw new InvalidArgumentException('Report name must be 50 characters or less');\n }\n\n // Validate frequency (only daily, weekly, monthly for Ask Jiminny)\n $frequency = $data['frequency'] ?? null;\n $askJiminnyFrequencies = [self::FREQUENCY_DAILY, self::FREQUENCY_WEEKLY, self::FREQUENCY_MONTHLY];\n if (! in_array($frequency, $askJiminnyFrequencies, true)) {\n throw new InvalidArgumentException('Frequency must be daily, weekly, or monthly');\n }\n\n // Validate expiration date\n $expiresAt = $data['expires_on'] ?? null;\n if (empty($expiresAt)) {\n throw new InvalidArgumentException('Expiration date is required');\n }\n\n try {\n $expiresAtDate = Carbon::parse($expiresAt);\n } catch (InvalidFormatException $e) {\n throw new InvalidArgumentException('Expiration date format is invalid');\n }\n $maxExpiration = Carbon::now()->addYear();\n if ($expiresAtDate->gt($maxExpiration)) {\n throw new InvalidArgumentException('Expiration date cannot be more than 1 year from now');\n }\n if ($expiresAtDate->isPast()) {\n throw new InvalidArgumentException('Expiration date cannot be in the past');\n }\n\n // Validate saved search\n $activitySearchId = $data['saved_search'] ?? null;\n if (empty($activitySearchId)) {\n throw new InvalidArgumentException('Saved search is required');\n }\n $savedSearch = $this->activitySearchRepository->findByUuidAndUser($activitySearchId, $user);\n if (! $savedSearch) {\n throw new InvalidArgumentException('Saved search not found or does not belong to you');\n }\n\n // Validate saved prompt\n $askAnythingPromptId = $data['ask_jiminny_prompt'] ?? null;\n if (empty($askAnythingPromptId)) {\n throw new InvalidArgumentException('Ask Jiminny prompt is required');\n }\n $prompt = $this->askAnythingRepository->getPromptByUuid($askAnythingPromptId);\n if (! $prompt) {\n throw new InvalidArgumentException('Ask Jiminny prompt not found');\n }\n\n // Validate status\n $status = $data['enabled'] ?? false;\n\n $recipientUserIds = [$user->getId()];\n\n if (! empty($data['share_users'])) {\n $sharedUserIds = $this->validateAndGetUserIdsByTeam(\n $user->team,\n (array) $data['share_users']\n );\n $recipientUserIds = array_merge($recipientUserIds, $sharedUserIds);\n }\n\n $sharedGroupIds = [];\n if (! empty($data['share_teams'])) {\n $sharedGroupIds = $this->validateAndGetGroupIds($user->team, (array) $data['share_teams']);\n }\n\n $recipientUserIds = array_values(array_unique($recipientUserIds));\n\n return [\n 'team_id' => $user->getTeamId(),\n 'type' => self::TYPE_ASK_JIMINNY,\n 'status' => (bool) $status,\n 'frequency' => $frequency,\n 'custom_name' => $name,\n 'activity_search_id' => $savedSearch->getId(),\n 'ask_anything_prompt_id' => $prompt->getId(),\n 'expires_at' => $expiresAtDate->toDateString(),\n 'media_types' => [self::MEDIA_TYPE_PDF],\n 'call_types' => [],\n 'recipients' => ['users' => $recipientUserIds],\n 'groups' => $sharedGroupIds,\n ];\n }\n\n public static function getAskJiminnyFrequencies(): array\n {\n return array_map(static function ($frequency) {\n return $frequency['id'];\n }, self::ASK_JIMINNY_FREQUENCIES);\n }\n\n public function getAskJiminnyReportFilters(User $user): array\n {\n $savedSearches = $this->activitySearchRepository->findByUserOrderedByName($user)\n ->map(fn (Search $search) => [\n 'id' => $search->getUuid(),\n 'name' => $search->getName(),\n ])\n ->values()->all();\n\n $prompts = collect(\n $this->askAnythingPromptService->get($user, AskAnythingPromptTarget::on_demand)\n )->map(fn (AskAnythingPromptDto $prompt) => [\n 'id' => $prompt->id,\n 'name' => $prompt->title,\n ])->values()->all();\n\n return [\n [\n 'id' => 'prompt',\n 'label' => 'Prompt',\n 'options' => $prompts,\n ],\n [\n 'id' => 'saved_search',\n 'label' => 'Saved Search',\n 'options' => $savedSearches,\n ],\n ];\n }\n\n public function getAskJiminnyReportFormData(User $user, ?AutomatedReport $report = null): array\n {\n $team = $user->getTeam();\n $userTimezone = $user->getTimezone();\n\n $savedSearches = $this->activitySearchRepository->findByUserOrderedByName($user)\n ->map(fn (Search $search) => [\n 'id' => $search->getUuid(),\n 'name' => $search->getName(),\n ])\n ->values()->all();\n\n $prompts = collect(\n $this->askAnythingPromptService->get($user, AskAnythingPromptTarget::on_demand)\n )->map(fn (AskAnythingPromptDto $prompt) => [\n 'id' => $prompt->id,\n 'name' => $prompt->title,\n ])->values()->all();\n\n $teamGroups = $this->groupRepository->getAllByTeam($team)->map(fn ($group) => [\n 'id' => $group->getUuid(),\n 'name' => $group->getName(),\n ])->values()->all();\n\n $shareUsers = $this->recipientsService->getRecipientsFieldData(team: $team)['options'] ?? [];\n\n $sharedTeamsValue = [];\n $sharedUsersValue = [];\n if ($report) {\n $sharedTeamsValue = $this->transformGroups($team, $report->getGroups());\n\n $recipientUserIds = $report->getRecipients()['users'] ?? [];\n $creatorId = $report->getAttribute('created_by');\n $sharedUserIds = array_values(array_filter(\n $recipientUserIds,\n static fn ($id) => $id !== $creatorId\n ));\n $sharedUsersValue = collect($sharedUserIds)\n ->map(fn ($id) => $this->userRepository->find((int) $id))\n ->filter()\n ->map(fn (User $u) => [\n 'id' => $u->getUuid(),\n 'name' => $u->getName(),\n ])\n ->values()\n ->all();\n }\n\n return [\n 'fields' => [\n [\n 'id' => 'enabled',\n 'inputType' => InputTypeEnum::TOGGLE,\n 'label' => '',\n 'value' => $report?->getStatus() ?? false,\n ],\n [\n 'id' => 'report_name',\n 'inputType' => InputTypeEnum::TEXT,\n 'label' => 'Name',\n 'placeholder' => 'Enter name',\n 'required' => true,\n 'validation' => ['maxLength' => 50],\n 'value' => $report?->getCustomName() ?? '',\n ],\n [\n 'id' => 'frequency',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'label' => 'Frequency',\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => self::ASK_JIMINNY_FREQUENCIES,\n 'value' => $report ? $this->transformFrequency($report->getFrequency()) : null,\n ],\n [\n 'id' => 'expires_on',\n 'inputType' => InputTypeEnum::DATE,\n 'label' => 'Expires on',\n 'required' => true,\n 'placeholder' => 'Select',\n 'validation' => [\n 'minDate' => now($userTimezone)->toDateString(),\n 'maxDate' => now($userTimezone)->addYear()->toDateString(),\n ],\n 'value' => $report?->getExpiresAt()?->toDateString(),\n ],\n [\n 'id' => 'share_teams',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'label' => 'Team',\n 'required' => false,\n 'placeholder' => 'Select',\n 'options' => $teamGroups,\n 'value' => $sharedTeamsValue,\n ],\n [\n 'id' => 'share_users',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'label' => 'Team member',\n 'required' => false,\n 'placeholder' => 'Select',\n 'groupLabelKey' => 'label',\n 'groupValuesKey' => 'users',\n 'optionLabelKey' => 'name',\n 'optionValueKey' => 'id',\n 'options' => $shareUsers,\n 'value' => $sharedUsersValue,\n ],\n [\n 'id' => 'saved_search',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'label' => 'Saved search',\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => $savedSearches,\n 'value' => $report && $report->getSavedSearch() ? [\n 'id' => $report->getSavedSearch()->getUuid(),\n 'name' => $report->getSavedSearch()->getName(),\n ] : null,\n ],\n [\n 'id' => 'ask_jiminny_prompt',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'label' => 'Ask Jiminny prompt',\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => $prompts,\n 'value' => $report && $report->getAskAnythingPrompt() ? [\n 'id' => $report->getAskAnythingPrompt()->getUuid(),\n 'name' => $report->getAskAnythingPrompt()->getTitle(),\n ] : null,\n ],\n ],\n ];\n }\n\n private function updateResultNames(AutomatedReport $automatedReport): void\n {\n $results = $this->automatedReportsRepository->getResultsByReport($automatedReport);\n\n foreach ($results as $result) {\n $result->update(['name' => $this->getReportFileName($result)]);\n }\n }\n\n public function updateStatus(string $uuid, array $data): array\n {\n $automatedReport = $this->automatedReportsRepository->findByUuid($uuid);\n\n if (! $automatedReport) {\n throw new ModelNotFoundException('Report not found');\n }\n\n $status = $this->validateReportStatus($data['report_enabled'] ?? null);\n $automatedReport->update([\n 'status' => $status,\n ]);\n\n $this->generateOneOffReport($automatedReport);\n\n return $this->transformReportFullView($automatedReport);\n }\n\n private function generateOneOffReport(AutomatedReport $automatedReport): void\n {\n // the scheduler handles all the other frequency types\n if ($automatedReport->getStatus() === false || $automatedReport->getFrequency() !== self::FREQUENCY_ONE_OFF) {\n return;\n }\n\n $this->dispatcher->dispatch(new RequestGenerateReportJob($automatedReport->getUuid()));\n }\n\n public function getReport(string $uuid): AutomatedReport\n {\n $automatedReport = $this->automatedReportsRepository->findByUuid($uuid);\n\n if (! $automatedReport) {\n throw new ModelNotFoundException('Report not found');\n }\n\n return $automatedReport;\n }\n\n public function get(string $uuid): array\n {\n $automatedReport = $this->getReport($uuid);\n\n return $this->transformReportFullView($automatedReport);\n }\n\n public function list(string $sortColumn = 'created_at', string $sortDirection = 'desc'): array\n {\n $results = [];\n $collection = $this->automatedReportsRepository->getAllStandardReports($sortColumn, $sortDirection);\n\n /** @var AutomatedReport $report */\n foreach ($collection as $report) {\n $results[] = $this->transformReportFullView($report);\n }\n\n return ['data' => $results];\n }\n\n public function listAskJiminnyReports(\n User $user,\n string $sortColumn = 'created_at',\n string $sortDirection = 'desc'\n ): array {\n $results = [];\n $collection = $this->automatedReportsRepository->getAskJiminnyReportsByUser($user, $sortColumn, $sortDirection);\n\n /** @var AutomatedReport $report */\n foreach ($collection as $report) {\n $results[] = $this->transformReportFullView($report);\n }\n\n return ['data' => $results];\n }\n\n public function delete(string $uuid): void\n {\n $automatedReport = $this->automatedReportsRepository->findByUuid($uuid);\n\n if (! $automatedReport) {\n throw new ModelNotFoundException('Report not found');\n }\n\n $automatedReport->delete();\n }\n\n public function createReportResult(AutomatedReport $automatedReport, array $data = []): AutomatedReportResult\n {\n return $this->automatedReportsRepository->createResult(\n array_merge(\n [\n 'report_id' => $automatedReport->getId(),\n 'status' => AutomatedReportResult::STATUS_DEFAULT,\n ],\n $data\n )\n );\n }\n\n public function getReportResult(string $resultUuid): AutomatedReportResult\n {\n $report = $this->automatedReportsRepository->findResultByUuid($resultUuid);\n\n if (! $report) {\n throw new ModelNotFoundException('Report Result not found');\n }\n\n return $report;\n }\n\n public function findChildResult(AutomatedReportResult $result, string $type): ?AutomatedReportResult\n {\n return $this->automatedReportsRepository->findChildResult($result, $type);\n }\n\n // prophet API calls\n /**\n * @throws ApplicationException\n */\n public function getGenerateReportPayload(AutomatedReport $automatedReport, string $reportResultUuid): array\n {\n $period = $this->calculateFromAndToDate($automatedReport);\n $fromDate = $period['fromDate'];\n $toDate = $period['toDate'];\n\n return [\n 'team_id' => $automatedReport->getTeamId(),\n 'request_id' => $reportResultUuid,\n 'report_type' => $automatedReport->getType(),\n 'media_types' => $automatedReport->getMediaTypes(),\n 'from_date' => $fromDate->startOfDay()->format(DateTimeInterface::RFC3339),\n 'to_date' => $toDate->endOfDay()->format(DateTimeInterface::RFC3339),\n 'group_ids' => $automatedReport->getGroups(),\n 'call_deal_stage' => $automatedReport->getDealAtCallStages(),\n 'current_deal_stage' => $automatedReport->getCurrentDealStages(),\n 'deal_min_value' => $automatedReport->getDealValueMin(),\n 'deal_max_value' => $automatedReport->getDealValueMax(),\n 'call_types' => $automatedReport->getCallTypes(),\n 'call_duration_min_seconds' => $automatedReport->getCallDurationMin(),\n 'call_duration_max_seconds' => $automatedReport->getCallDurationMax(),\n 'special_requirements' => $automatedReport->getAdditionalPromptInput(),\n 'callback_url' => $this->getCallbackUrl(),\n 'report_period' => $this->formatReportPeriodName(\n $automatedReport->getFrequency(),\n $fromDate,\n $toDate,\n ),\n 'playbook_categories' => $automatedReport->getPlaybookCategories(),\n 'custom_name' => $automatedReport->getCustomName(),\n ];\n }\n\n // $inputPayload - FE payload structure\n public function getActivitiesCountPayload(array $inputPayload): array\n {\n // Use validateAndTransformData to validate and normalize input\n $validatedData = $this->validateAndTransformData($inputPayload);\n $period = $this->calculateFromAndToDatePeriod(\n $validatedData['frequency'],\n Carbon::parse($validatedData['from']),\n Carbon::parse($validatedData['to']),\n );\n $fromDate = $period['fromDate'];\n $toDate = $period['toDate'];\n\n // Create payload similar to getGenerateReportPayload\n return [\n 'team_id' => $validatedData['team_id'],\n 'group_ids' => $validatedData['groups'] ?? [],\n 'report_type' => $validatedData['type'],\n 'from_date' => $fromDate->format(DateTimeInterface::RFC3339),\n 'to_date' => $toDate->format(DateTimeInterface::RFC3339),\n 'call_deal_stage' => $validatedData['deal_at_call_stages'] ?? [],\n 'current_deal_stage' => $validatedData['current_deal_stages'] ?? [],\n 'deal_min_value' => $validatedData['deal_value_min'] ?? null,\n 'deal_max_value' => $validatedData['deal_value_max'] ?? null,\n 'call_types' => $validatedData['call_types'],\n 'call_duration_min_seconds' => $validatedData['call_duration_min'] ?? null,\n 'call_duration_max_seconds' => $validatedData['call_duration_max'] ?? null,\n 'special_requirements' => $validatedData['additional_prompt_input'] ?? null,\n 'playbook_categories' => $validatedData['playbook_categories'] ?? [],\n 'request_id' => null,\n 'callback_url' => null,\n ];\n }\n\n public function shouldSendReport(array $users, ?CarbonInterface $generatedAt = null): bool\n {\n if (empty($users)) {\n return false;\n }\n\n $earliestTz = collect($users)\n ->mapWithKeys(function (array $user) {\n $tz = new DateTimeZone($user['timezone']);\n $nowUtc = new DateTime('now', new DateTimeZone('UTC'));\n $offset = $tz->getOffset($nowUtc);\n\n return [$user['timezone'] => $offset];\n })\n ->sortDesc()\n ->keys()\n ->first();\n\n $now = Carbon::now($earliestTz);\n $isScheduledTime = (int) $now->format('H') === self::SENT_REPORT_AT_HOURS;\n\n if ($isScheduledTime) {\n return true;\n }\n\n return $this->hasPassedScheduledTime($generatedAt, $earliestTz);\n }\n\n public function hasPassedScheduledTime(?CarbonInterface $generatedAt, string $timezone): bool\n {\n if ($generatedAt === null) {\n return false;\n }\n\n $now = Carbon::now($timezone);\n $scheduledTime = $now->copy()->setTime(self::SENT_REPORT_AT_HOURS, 0, 0);\n\n if ($now->hour < self::SENT_REPORT_AT_HOURS) {\n $scheduledTime = $scheduledTime->subDay();\n }\n\n $scheduledTimeUtc = $scheduledTime->copy()->utc();\n $generatedAtUtc = $generatedAt->copy()->utc();\n $nowUtc = $now->copy()->utc();\n\n return $generatedAtUtc->lt($scheduledTimeUtc) && $nowUtc->gt($scheduledTimeUtc);\n }\n\n public function calculateFromAndToDatePeriod(\n string $frequency,\n ?Carbon $fromDate = null,\n ?Carbon $toDate = null\n ): array {\n if ($frequency === self::FREQUENCY_ONE_OFF) {\n return [\n 'fromDate' => $fromDate,\n 'toDate' => $toDate,\n ];\n }\n\n $now = Carbon::now();\n\n return match ($frequency) {\n self::FREQUENCY_DAILY => [\n 'fromDate' => $now->copy()->subDay()->startOfDay(),\n 'toDate' => $now->copy()->subDay()->endOfDay(),\n ],\n self::FREQUENCY_WEEKLY => [\n 'fromDate' => $now->copy()->subWeeks(1)->startOfDay(),\n 'toDate' => $now->copy()->subDay()->endOfDay(),\n ],\n self::FREQUENCY_MONTHLY => [\n 'fromDate' => $now->copy()->subMonths(1)->startOfDay(),\n 'toDate' => $now->copy()->subDay()->endOfDay(),\n ],\n self::FREQUENCY_QUARTERLY => [\n 'fromDate' => $now->copy()->subMonths(3)->startOfDay(),\n 'toDate' => $now->copy()->subDay()->endOfDay(),\n ],\n default => throw new InvalidArgumentException(\"Unsupported frequency: {$frequency}\"),\n };\n }\n\n private function calculateFromAndToDate(AutomatedReport $automatedReport): array\n {\n return $this->calculateFromAndToDatePeriod(\n $automatedReport->getFrequency(),\n $automatedReport->getFrom(),\n $automatedReport->getTo()\n );\n }\n\n public function getAskJiminnyGenerateReportPayload(\n AutomatedReport $automatedReport,\n AutomatedReportResult $reportResult,\n array $activityIds,\n ): array {\n return [\n 'user_question' => $automatedReport->getAskAnythingPrompt()?->getContent(),\n 'call_ids' => array_map('strval', $activityIds),\n 'team_id' => $automatedReport->getTeamId(),\n 'request_id' => $reportResult->getUuid(),\n 'callback_url' => $this->getCallbackUrl(),\n 'report_period' => $this->getReportPeriodName($reportResult),\n 'report_name' => $automatedReport->getCustomName(),\n ];\n }\n\n private function getCallbackUrl(): string\n {\n return $this->webhookService->route('jiminny.webhook.reports.ready');\n }\n\n /**\n * Validate and transform payload data for automated reports\n *\n * @param array $data\n *\n * @throws InvalidArgumentException\n *\n * @return array\n */\n private function validateAndTransformData(array $data): array\n {\n // Validate organization (team) and check feature\n $team = $this->validateOrganization($data['organization'] ?? null);\n\n $status = $this->validateReportStatus($data['report_enabled'] ?? null);\n $type = $this->validateReportType($data['report_type'] ?? null);\n $frequency = $this->validateFrequency($data['frequency'] ?? null);\n $additionalPromptInput = $this->validateAdditionalPromptInput(\n $data['additional_prompt_input'] ?? null\n );\n $customReportName = $this->validateCustomReportName($data['custom_name'] ?? null);\n\n // Prepare data for the database\n $reportData = [\n 'team_id' => $team->getId(),\n 'type' => $type,\n 'status' => $status,\n 'frequency' => $frequency,\n 'additional_prompt_input' => $additionalPromptInput,\n 'custom_name' => $customReportName,\n ];\n\n // Validate deal values\n $reportData = $this->validateDealValues($data, $reportData);\n\n // Validate date range\n $reportData = $this->validateDateRange($data, $reportData, $frequency);\n\n // Validate call durations\n $reportData = $this->validateCallDurations($data, $reportData);\n\n // Validate call types\n $reportData = $this->validateCallTypes($data, $reportData);\n\n // Validate media types\n $reportData = $this->validateMediaTypes($data, $reportData);\n\n // Validate groups\n if (isset($data['teams'])) {\n $reportData['groups'] = $this->validateAndGetGroupIds($team, $data['teams']);\n }\n\n // Validate deal stages\n $reportData = $this->validateDealStages($data, $reportData, $team, $type);\n\n // Validate playbook categories\n $reportData = $this->validatePlaybookCategories($data, $reportData, $team);\n\n // Validate recipients\n $reportData['recipients'] = [\n 'users' => $this->validateAndGetUserIdsByTeam($team, $data['recipients'] ?? []),\n ];\n\n if (isset($data['jiminny_recipients'])) {\n // Validate Jiminny recipients\n $reportData['jiminny_recipients'] = [\n 'users' => $this->validateAndGetJiminnyUserIds((array) $data['jiminny_recipients']),\n ];\n }\n\n return $reportData;\n }\n\n private function validateDealValues(array $data, array $reportData): array\n {\n if (isset($data['min_deal_value'])) {\n $reportData['deal_value_min'] = (int) $data['min_deal_value'];\n\n if ($reportData['deal_value_min'] > 4294967295 || $reportData['deal_value_min'] < 0) {\n throw new InvalidArgumentException('Min deal value should be between 0 and 4294967295');\n }\n }\n\n if (isset($data['max_deal_value'])) {\n $reportData['deal_value_max'] = (int) $data['max_deal_value'];\n\n if ($reportData['deal_value_max'] > 4294967295 || $reportData['deal_value_max'] < 0) {\n throw new InvalidArgumentException('Max deal value should be between 0 and 4294967295');\n }\n }\n\n if (isset($data['min_deal_value'], $data['max_deal_value'])\n && $data['min_deal_value'] > $data['max_deal_value']\n ) {\n throw new InvalidArgumentException('Min deal value cannot be greater than max deal value');\n }\n\n return $reportData;\n }\n\n private function validateDateRange(array $data, array $reportData, string $frequency): array\n {\n // Set date range only for one_off frequency\n if ($frequency === 'one_off') {\n if (isset($data['start_date_period'])) {\n $reportData['from'] = $this->parseDate($data['start_date_period']);\n }\n\n if (isset($data['end_date_period'])) {\n $reportData['to'] = $this->parseDate($data['end_date_period']);\n }\n\n if (empty($reportData['from']) || empty($reportData['to'])) {\n throw new InvalidArgumentException(\n 'Start date and end date are required for one_off frequency'\n );\n }\n } else {\n $reportData['from'] = null;\n $reportData['to'] = null;\n }\n\n return $reportData;\n }\n\n private function validateCallDurations(array $data, array $reportData): array\n {\n // Convert call durations from minutes to seconds\n if (isset($data['min_call_duration'])) {\n $reportData['call_duration_min'] = (int) $data['min_call_duration'] * 60;\n\n if ($reportData['call_duration_min'] > 4294967295 || $reportData['call_duration_min'] < 0) {\n throw new InvalidArgumentException('Min call duration should be between 0 and 4294967295');\n }\n }\n\n if (isset($data['max_call_duration'])) {\n $reportData['call_duration_max'] = (int) $data['max_call_duration'] * 60;\n\n if ($reportData['call_duration_max'] > 4294967295 || $reportData['call_duration_max'] < 0) {\n throw new InvalidArgumentException('Max call duration should be between 0 and 4294967295');\n }\n }\n\n return $reportData;\n }\n\n private function validateCallTypes(array $data, array $reportData): array\n {\n // Set call types\n $reportData['call_types'] = $data['call_type'] ?? [];\n if (empty($reportData['call_types'])) {\n $reportData['call_types'] = self::getCallTypes();\n }\n\n foreach ($reportData['call_types'] as $callType) {\n if (! in_array($callType, self::getCallTypes(), true)) {\n throw new InvalidArgumentException(sprintf('Call type %s is invalid', $callType));\n }\n }\n\n return $reportData;\n }\n\n private function validateMediaTypes(array $data, array $reportData): array\n {\n // Set media types from input data\n $reportData['media_types'] = $data['media_types'] ?? [];\n\n if (empty($reportData['media_types'])) {\n throw new InvalidArgumentException('Media types are required');\n }\n\n foreach ($reportData['media_types'] as $mediaType) {\n if (! in_array($mediaType, self::MEDIA_TYPES, true)) {\n throw new InvalidArgumentException(sprintf('Media type %s is invalid', $mediaType));\n }\n }\n\n return $reportData;\n }\n\n private function validateDealStages(array $data, array $reportData, Team $team, string $reportType): array\n {\n // Validate and set deal stages\n if (isset($data['deal_stage_at_call'])) {\n $reportData['deal_at_call_stages'] =\n $this->validateAndGetDealStageIds($team, $data['deal_stage_at_call'], 'Deal stage at call');\n }\n\n if (isset($data['current_deal_stage'])) {\n $reportData['current_deal_stages'] =\n $this->validateAndGetDealStageIds($team, $data['current_deal_stage'], 'Current deal stage');\n }\n\n // Ensure current_deal_stage is not provided for loss_analysis report type\n if ($reportType === self::TYPE_LOSS_ANALYSIS && ! empty($data['current_deal_stage'])) {\n throw new InvalidArgumentException('Current deal stage is not applicable for Loss Analysis reports');\n }\n\n return $reportData;\n }\n\n // transform uuid to id\n private function validatePlaybookCategories(array $data, array $reportData, Team $team): array\n {\n $key = 'playbook_categories';\n\n if (isset($data[$key])) {\n $payloadIds = $data[$key];\n $ids = [];\n\n foreach ($payloadIds as $uuid) {\n $uuid = (string) $uuid;\n\n try {\n $playbookCategory = $this->playbookCategoryRepository->findByUuid($uuid);\n } catch (Throwable $throwable) {\n Log::error(__METHOD__ . ' ' . $throwable->getMessage());\n\n throw new InvalidArgumentException(sprintf('Playbook category %s not found', $uuid));\n }\n\n if (! $playbookCategory) {\n throw new InvalidArgumentException(sprintf('Playbook category %s not found', $uuid));\n }\n\n if (! $playbookCategory->hasPlaybook()) {\n throw new InvalidArgumentException(sprintf('Playbook category %s has no playbook', $uuid));\n }\n\n if ($playbookCategory->getPlaybook()->getTeamId() !== $team->getId()) {\n throw new InvalidArgumentException(\n sprintf('Playbook category %s not found for team %s', $uuid, $team->getUuid())\n );\n }\n\n $ids[] = $playbookCategory->getId();\n }\n\n $reportData[$key] = $ids;\n }\n\n return $reportData;\n }\n\n private function validateReportStatus($status): bool\n {\n if (! in_array($status, [true, false], true)) {\n throw new InvalidArgumentException('Report status is invalid');\n }\n\n return $status;\n }\n\n private function validateReportType($type): string\n {\n if (! in_array($type, self::getTypes(), true)) {\n throw new InvalidArgumentException(sprintf('Report type is invalid: %s', $type));\n }\n\n return $type;\n }\n\n private function validateFrequency($frequency): string\n {\n if (! in_array($frequency, self::getFrequencies(), true)) {\n throw new InvalidArgumentException('Frequency is invalid');\n }\n\n return $frequency;\n }\n\n private function validateAdditionalPromptInput(?string $additionalPromptInput): ?string\n {\n if ($additionalPromptInput && strlen($additionalPromptInput) > 5000) {\n throw new InvalidArgumentException('Additional Prompt Input should be less than 5000 characters');\n }\n\n return $additionalPromptInput;\n }\n\n private function validateCustomReportName(?string $customReportName): ?string\n {\n if ($customReportName === null || $customReportName === '') {\n return null;\n }\n\n if (strlen($customReportName) > 70) {\n throw new InvalidArgumentException('Custom report name should be less than 70 characters');\n }\n\n return $customReportName;\n }\n\n private function validateOrganization(?string $organizationUuid): Team\n {\n if (! $organizationUuid) {\n throw new InvalidArgumentException('Organization is required');\n }\n\n $team = $this->teamRepository->idOrUuid($organizationUuid);\n\n if (! $team) {\n throw new InvalidArgumentException('Organization not found');\n }\n\n if (! $team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {\n throw new InvalidArgumentException('Organization does not have the Automated Reports feature');\n }\n\n return $team;\n }\n\n private function validateAndGetGroupIds(Team $team, array $teamUuids): array\n {\n $groupIds = [];\n\n foreach ($teamUuids as $uuid) {\n $group = $this->groupRepository->findByUuid($uuid);\n\n if ($group === null || $group->getTeamId() !== $team->getId()) {\n throw new InvalidArgumentException(\n sprintf('Group %s not found for team %s', $uuid, $team->getUuid())\n );\n }\n\n $groupIds[] = $group->getId();\n\n }\n\n return $groupIds;\n }\n\n private function validateAndGetDealStageIds(Team $team, array $stageUuids, string $propertyLabel): array\n {\n $stageIds = [];\n\n foreach ($stageUuids as $uuid) {\n $stage = $this->stageRepository->findByUuid($uuid);\n\n if ($stage === null || $stage->getTeamId() !== $team->getId()) {\n throw new InvalidArgumentException(\n sprintf('Stage %s not found for team %s for %s', $uuid, $team->getUuid(), $propertyLabel)\n );\n }\n\n $stageIds[] = $stage->getId();\n }\n\n return $stageIds;\n }\n\n private function validateAndGetUserIds(array $userUuids, callable $teamCheck): array\n {\n if (empty($userUuids)) {\n return [];\n }\n\n $userIds = [];\n\n foreach ($userUuids as $uuid) {\n $user = $this->userRepository->findByUuid($uuid);\n\n if (! $user || ! $user->isStatusActive()) {\n throw new InvalidArgumentException(\n sprintf('User %s not found or is not active', $uuid)\n );\n }\n\n if (! $teamCheck($user)) {\n throw new InvalidArgumentException(\n sprintf('User %s does not belong to the allowed team(s)', $uuid)\n );\n }\n\n $userIds[] = $user->getId();\n }\n\n return $userIds;\n }\n\n private function validateAndGetUserIdsByTeam(Team $team, array $userUuids): array\n {\n return $this->validateAndGetUserIds($userUuids, fn ($user) => $user->getTeamId() === $team->getId());\n }\n\n private function validateAndGetJiminnyUserIds(array $userUuids): array\n {\n $allowedTeamIds = config('kiosk.teamIds', []);\n\n return $this->validateAndGetUserIds($userUuids, fn ($user) => in_array($user->getTeamId(), $allowedTeamIds, true));\n }\n\n private function parseDate(string $dateString): string\n {\n return date('Y-m-d H:i:s', strtotime($dateString));\n }\n\n private function generateReportResultViewUrl(AutomatedReportResult $result): string\n {\n $mediaResource = $this->getReportMediaRouteResource($result);\n\n return route('ai-reports.' . $mediaResource . '.view', ['uuid' => $result->getUuid()]);\n }\n\n private function generateReportResultDownloadUrl(AutomatedReportResult $result): string\n {\n $mediaResource = $this->getReportMediaRouteResource($result);\n\n return route('ai-reports.' . $mediaResource . '.download', ['uuid' => $result->getUuid()]);\n }\n\n private function getReportMediaRouteResource(AutomatedReportResult $result): string\n {\n if ($result->getMediaType() === self::MEDIA_TYPE_PDF) {\n return self::PDF_KEY;\n } elseif ($result->getMediaType() === self::MEDIA_TYPE_PODCAST) {\n return self::AUDIO_KEY;\n }\n\n throw new \\InvalidArgumentException('Unknown media type.');\n }\n\n public function getMediaPath(AutomatedReportResult $result): ?string\n {\n $url = match ($result->getMediaType()) {\n self::MEDIA_TYPE_PDF => $result->getPdfUrl(),\n self::MEDIA_TYPE_PODCAST => $result->getPodcastAudioUrl(),\n default => null,\n };\n\n if ($url === null) {\n return null;\n }\n\n $path = parse_url(trim($url, '\"\\''), PHP_URL_PATH);\n\n return $path ?: null;\n }\n\n public function getFilenameSuffix(AutomatedReportResult $result): ?string\n {\n return match ($result->getMediaType()) {\n self::MEDIA_TYPE_PODCAST => 'Podcast',\n default => null,\n };\n }\n\n public function getMailSubjectSuffix(AutomatedReportResult $result): string\n {\n return match ($result->getMediaType()) {\n self::MEDIA_TYPE_PDF => 'report',\n self::MEDIA_TYPE_PODCAST => 'podcast',\n default => '',\n };\n }\n\n public function getMediaTypeMetadata(AutomatedReportResult $result): array\n {\n return match ($result->getMediaType()) {\n self::MEDIA_TYPE_PODCAST => ['extension' => 'mp3', 'mime' => 'audio/mpeg'],\n self::MEDIA_TYPE_PDF => ['extension' => 'pdf', 'mime' => 'application/pdf'],\n default => ['extension' => null, 'mime' => null],\n };\n }\n\n public function deleteS3Files(AutomatedReportResult $result): void\n {\n $teamUuid = $result->getReport()->getTeam()->getUuid();\n $reportUuid = $result->getUuid();\n\n // delete all files for a report uuid no mather of pdf, podcast, or both\n // in case of both - the podcast files are linked to the pdf (parent) uuid\n // pdf and podcast date times should be close\n $path = sprintf('%s/%s/%s', $teamUuid, self::S3_DIR, $reportUuid);\n\n foreach (self::FILE_EXTENSIONS_VARIANTS as $extension) {\n $file = $path . '.' . $extension;\n\n if (Storage::exists($file)) {\n Storage::delete($file);\n Log::info('[Reports] Deleted S3 file', [\n 'path' => $file,\n ]);\n }\n }\n\n foreach (self::FILE_PODCAST_EXTENSIONS_VARIANTS as $extension) {\n $file = $path . '_podcast.' . $extension;\n\n if (Storage::exists($file)) {\n Storage::delete($file);\n Log::info('[Reports] Deleted Podcast S3 file', [\n 'path' => $file,\n ]);\n }\n }\n }\n\n /**\n *\n * @param int|null $teamId Optional team ID to filter results\n *\n * @return Collection<int, int> Collection of team IDs\n */\n public function getTeamIdsWithReportsResults(?int $teamId = null): Collection\n {\n return $this->automatedReportsRepository->getTeamIdsWithReportsResults($teamId);\n }\n\n /**\n * Core delete logic for report results using a query\n *\n * @param Builder $query\n * @param array $logContext\n *\n * @return int\n */\n private function deleteReportResultsByQuery(Builder $query, array $logContext = []): int\n {\n $deletedCount = 0;\n\n if ($query->exists()) {\n Log::info(\n 'Run delete report results',\n array_merge(\n $logContext,\n [\n 'service' => 'AutomatedReportsService',\n ]\n )\n );\n\n $query->chunkById(50, function ($results) use (&$deletedCount, $logContext) {\n foreach ($results as $result) {\n $this->deleteReportResult($result);\n $deletedCount++;\n\n Log::info(\n 'Deleted a report result',\n array_merge(\n $logContext,\n [\n 'result_id' => $result->getId(),\n 'report_id' => $result->getReportId(),\n ]\n )\n );\n }\n });\n }\n\n return $deletedCount;\n }\n\n /**\n * Delete report results for a team by retention period\n *\n * @param Team $team\n * @param CarbonImmutable $retentionDate\n *\n * @return int Number of deleted report results\n */\n public function deleteReportsResultsInRetentionPeriod(Team $team, CarbonImmutable $retentionDate): int\n {\n $reportIds = $this->automatedReportsRepository->getReportIdsByTeam($team);\n\n if ($reportIds->isEmpty()) {\n return 0;\n }\n\n $query = $this->automatedReportsRepository\n ->getReportResultsQueryForRetention($team, $retentionDate);\n\n return $this->deleteReportResultsByQuery($query, [\n 'team_id' => $team->getId(),\n 'retention_date' => $retentionDate->toDateTimeString(),\n ]);\n }\n\n /**\n * Delete ALL report results for a specific automated report\n *\n * @param string $uuid\n *\n * @return int\n */\n public function deleteReportResults(string $uuid): int\n {\n $report = $this->getReport($uuid);\n\n $query = $this->automatedReportsRepository->getResultsByReportQuery($report);\n\n return $this->deleteReportResultsByQuery($query, [\n 'report_uuid' => $uuid,\n 'report_id' => $report->getId(),\n ]);\n }\n\n public function deleteReportResult(AutomatedReportResult $result): void\n {\n $this->deleteS3Files($result);\n\n $result->delete();\n }\n\n /**\n * Get all reports for a specific team\n *\n * @param Team $team\n *\n * @return \\Illuminate\\Database\\Eloquent\\Collection\n */\n public function getTeamReports(Team $team): \\Illuminate\\Database\\Eloquent\\Collection\n {\n return $this->automatedReportsRepository->getReportsByTeam($team);\n }\n\n /**\n * Get all report results for a specific report\n *\n * @param AutomatedReport $report\n *\n * @return \\Illuminate\\Database\\Eloquent\\Collection\n */\n public function getReportResults(AutomatedReport $report): \\Illuminate\\Database\\Eloquent\\Collection\n {\n return $this->automatedReportsRepository->getResultsByReport($report);\n }\n\n public function deleteAllReportResults(AutomatedReport $report): void\n {\n $results = $this->getReportResults($report);\n\n /** @var AutomatedReportResult $result */\n foreach ($results as $result) {\n Log::info('Deleting result', [\n 'report' => $report->getId(),\n 'result' => $result->getId(),\n ]);\n\n $this->deleteReportResult($result);\n }\n }\n\n public function deleteAllData(Team $team): void\n {\n Log::info('Deleting automated report and results for team', [\n 'team' => $team->getId(),\n ]);\n\n $reports = $this->getTeamReports($team);\n\n /** @var AutomatedReport $report */\n foreach ($reports as $report) {\n Log::info('Deleting report', [\n 'team' => $team->getId(),\n 'report' => $report->getId(),\n ]);\n\n $this->deleteAllReportResults($report);\n\n $report->delete();\n }\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":true,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"Project","depth":3,"role_description":"text"},{"role":"AXButton","text":"Project","depth":3,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"New File or Directory…","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Expand Selected","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Collapse All","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Options","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false}]...
|
3397592283435315795
|
6686367547760219213
|
idle
|
accessibility
|
NULL
|
Project: faVsco.js, menu
#11894 on JY-18909-automa Project: faVsco.js, menu
#11894 on JY-18909-automated-reports-ask-jiminny, menu
Start Listening for PHP Debug Connections
AutomatedReportsCommandTest
Run 'AutomatedReportsCommandTest'
Debug 'AutomatedReportsCommandTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Execute
Explain Plan
Browse Query History
View Parameters
Open Query Execution Settings…
In-Editor Results
Tx: Auto
Cancel Running Statements
Playground
jiminny
Sync Changes
Hide This Notification
Code changed:
Hide
16
13
13
Previous Highlighted Error
Next Highlighted Error
SELECT * FROM teams WHERE id = 1;
select * from crm_layouts where crm_configuration_id = 39;
SELECT * FROM crm_layout_entities WHERE crm_layout_id = 283;
SELECT * FROM crm_fields WHERE id = 2234;
SELECT * FROM crm_field_values WHERE crm_field_id = 2234;
select * from crm_profiles where user_id = 143;
select * from record_types where crm_configuration_id = 39; # 0121K000001MHElQAO,0121K000001MHEqQAO
select * from business_processes where crm_configuration_id = 39;
# 01941000000H669AAC, 01941000000H66JAAS
select * from record_type_field_values
where record_type_id IN (24);
select * from crm_field_values where id IN (2730);
select * from crm_configurations where id = 39;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 1
and sa.provider = 'salesforce'; #1035
select * from users where team_id = 1; # 222 group 3
SELECT * FROM activities WHERE user_id = 222 order by id desc;
select * from sidekick_settings where team_id = 1;
select * from teams where id = 1;
select * from team_features where team_id = 1;
select * from activities where crm_configuration_id = 2
and provider = 'ms-teams' and id = 608765;
SELECT * FROM activities WHERE crm_configuration_id = 2 and crm_provider_id = '59523413338';
select * from sidekick_settings where team_id = 2;
SELECT * FROM activities WHERE id = 608660;
select * from activity_summary_logs where activity_id = 608660;
select * from ai_prompts where transcription_id = 11214;
# [PASSWORD_DOTS]
SELECT * FROM activities WHERE uuid_to_bin('ed78a437-2804-450e-ab2f-56ab1c641346') = uuid;
# id: 608818, crm: 59628809737
SELECT * FROM activities WHERE uuid_to_bin('36b06e55-afdd-4782-8dee-c624cd0af191') = uuid;
# id: 608821, crm: 59632069252
SELECT ce.start_time, ce.end_time, a.id, a.uuid, crm_provider_id, calendar_event_id, title,
playbook_category_id, user_id, lead_id, contact_id, account_id, opportunity_id,
scheduled_start_time, scheduled_end_time, actual_start_time, actual_end_time, a.created_at
FROM activities a
join calendar_events ce on a.calendar_event_id = ce.id
WHERE a.id IN (608818, 608821);
select * from users where team_id = 1;
select * from team_settings where team_id = 1;
select * from crm_profiles where crm_configuration_id = 39 order by user_id;
select * from team_features where team_id = 1;
select * from users where team_id = 2;
SELECT * FROM activities WHERE uuid_to_bin('ec7647e9-5225-458b-b475-f31aa2769204') = uuid; # 612639
# Preslava N. Ivanova, grou id 3
SELECT * FROM opportunities WHERE uuid_to_bin('a2928fe5-aec5-46cb-85d9-7654c89e46a6') = uuid;
select * from activities where opportunity_id = 344 and actual_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00';
select
a.id,
a.type,
a.scheduled_start_time,
a.actual_start_time,
a.created_at,
a.opportunity_id,
a.status
FROM activities a
WHERE opportunity_id = 344
and status IN ('completed', 'received', 'delivered')
and (
(a.actual_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00')
OR (a.created_at between '2024-10-11 00:00:00' and '2024-10-12 00:00:00')
OR (a.scheduled_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00'))
;
SELECT * FROM users WHERE id = 222;
SELECT * FROM crm_profiles WHERE user_id = 222;
select * from crm_layouts where crm_configuration_id = 39;
SELECT * FROM crm_layout_entities WHERE crm_layout_id = 281;
select * from group_deal_risk_types;
select * from opportunities where team_id = 1;
SELECT * FROM opportunities WHERE id = 315;
SELECT * FROM crm_field_data WHERE object_id = 315;
select * from crm_field_data where object_id = 260;
select * from generic_ai_prompts where subject_id = 315;
select * from teams; # 36, 21, 121, [EMAIL]
SELECT * FROM social_accounts WHERE sociable_id = 121 and provider = 'bullhorn';
# [PASSWORD_DOTS]
select * from teams where id = 1;
select * from crm_configurations where id = 39;
select * from users where team_id = 1;
select u.email, cp.* from users u
join crm_profiles cp on u.id = cp.user_id
where u.team_id = 1;
# 1 - 00541000004281rAAA
# 204 - 0052g000003freeAAA
# 429 - 0052g000003qGOiAAM
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 1
and sa.provider = 'salesforce';
select * from activities where type = 'softphone'
and created_at > '2024-12-11 15:24:36' order by id desc;
select * from activity_providers where team_id = 1;
select * from activity_provider_users where activity_provider_id = 328;
select * from opportunities where crm_configuration_id = 39
AND account_id = 178 AND is_closed = false
order by created_at DESC;
select * from contacts where id = 3952;
select * from accounts where id = 178;
# [PASSWORD_DOTS]
select * from teams where id = 36;
select * from crm_configurations where id = 21;
select * from users where team_id = 36;
select u.email, cp.* from users u
join crm_profiles cp on u.id = cp.user_id
where u.team_id = 36;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 36
and sa.provider = 'bullhorn';
select * from social_accounts where id = 348;
UPDATE social_accounts SET
provider_user_token = '21442_6802599_91:41179a58-21e7-4d7c-ad58-56bb666b2f65',
provider_refresh_token = '21442_6802599_91:01c6b335-3f2a-42e4-85ff-8a08fa65fceb',
expires = 1733998131,
state = 'connected'
WHERE id = 348;
# [PASSWORD_DOTS]
select * from teams where id = 31;
select * from crm_configurations where id = 18;
select * from users where team_id = 31; # 257
select u.email, cp.* from users u
join crm_profiles cp on u.id = cp.user_id
where u.team_id = 31;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 31
and sa.provider = 'close';
select * from contacts where crm_configuration_id = 18;
# [PASSWORD_DOTS] NEPTUNE [PASSWORD_DOTS]
select * from teams;
select * from users where id IN (1030, 1035, 1052);
select * from crm_configurations;
select * from users where team_id = 65; # 257
select * from team_settings where team_id = 65; # 257
select * from invitations where team_id = 65; # 257
select * from users where email = '[EMAIL]'; # 257
select u.email, cp.* from users u
join crm_profiles cp on u.id = cp.user_id
where u.team_id = 65;
select * from crm_configurations where id = 53;
select * from accounts where crm_configuration_id = 53 order by id desc;
select * from leads where crm_configuration_id = 53 order by id desc;
select * from contacts where crm_configuration_id = 53 order by id desc;
select * from opportunities where crm_configuration_id = 53 order by id desc;
select * from crm_profiles where crm_configuration_id = 53 order by id desc;
select * from crm_fields where crm_configuration_id = 53 order by id desc;
select * from crm_field_values where crm_field_id = 3341 order by id desc;
select * from crm_layouts where crm_configuration_id = 53 order by id desc;
select * from stages where crm_configuration_id = 53 order by id desc;
select * from crm_profiles where crm_configuration_id = 13;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 65
and sa.provider = 'integration-app';
select * from contacts where crm_configuration_id = 13;
select * from social_accounts where sociable_id = 283;
SELECT * FROM opportunities WHERE crm_provider_id = '006O400000E9bzeIAB';
select * from activity_providers where team_id = 65;
SELECT * FROM activities WHERE crm_configuration_id IN (51, 52, 53);
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 65
;
# [PASSWORD_DOTS] STAGING [PASSWORD_DOTS]
SELECT * FROM teams;
SELECT * FROM teams WHERE id = 88;
SELECT * FROM teams WHERE id = 89;
select * from team_settings where team_id = 89;
SELECT * FROM users WHERE team_id = 89;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 89;
select * from users;
SELECT * FROM social_accounts WHERE sociable_id = 1761;
SELECT * FROM crm_configurations WHERE id = 70;
select * from accounts where crm_configuration_id = 70 order by id desc;
select * from leads where crm_configuration_id = 70 order by id desc;
select * from contacts where crm_configuration_id = 70 order by id desc;
select * from opportunities where crm_configuration_id = 70 order by id desc;
select * from crm_profiles where crm_configuration_id = 70 order by id desc;
select * from crm_fields where crm_configuration_id = 70 order by id desc;
select * from crm_field_values where crm_field_id = 3536 order by id desc;
select * from crm_layouts where crm_configuration_id = 70 order by id desc;
select * from stages where crm_configuration_id = 70 order by id desc;
select * from business_processes where crm_configuration_id = 70 order by id desc;
select * from business_process_stages where business_process_id = 34;
select * from contacts where id = 10468;
select * from crm_layouts where crm_configuration_id = 70;
SELECT * FROM crm_layout_entities WHERE crm_layout_id = 388;
SELECT * FROM crm_fields WHERE id IN (3533,3534,3535);
select * from activities where crm_configuration_id = 70
and (account_id IS NOT NULL or lead_id IS NOT NULL or contact_id IS NOT NULL or opportunity_id IS NOT NULL) order by id desc;
SELECT * FROM activities WHERE uuid_to_bin('2e10b60f-8a61-41c5-a3d4-28835353dc65') = uuid;
SELECT * FROM activities where crm_configuration_id = 69 ;
SELECT * FROM users WHERE email LIKE '%[EMAIL]%';
SELECT * FROM activities WHERE uuid_to_bin('5a150c93-40fc-42ec-b3bd-c1d328e09f6e') = uuid;
SELECT * FROM opportunities WHERE id = 385;
select * from participants p
join activities a on p.activity_id = a.id
where a.crm_configuration_id = 70
and (p.lead_id IS NOT NULL or p.contact_id IS NOT NULL);
SELECT * FROM participants WHERE id = 1013638;
select * from teams where id = 90;
select * from users where team_id = 90;
select * from social_accounts where social_accounts.sociable_id IN (1960,1760);
SELECT * FROM crm_profiles WHERE crm_configuration_id = 71;
select * from invitations where team_id = 90;
select * from crm_configurations where id = 71;
select * from accounts where crm_configuration_id = 71 order by id desc;
select * from leads where crm_configuration_id = 71 order by id desc;
select * from contacts where crm_configuration_id = 71 order by id desc;
select * from opportunities where crm_configuration_id = 71 order by id desc;
select * from crm_profiles where crm_configuration_id = 71 order by id desc;
select * from crm_fields where crm_configuration_id = 71 order by id desc;
select * from crm_field_values where crm_field_id = 3341 order by id desc;
select * from crm_layouts where crm_configuration_id = 71 order by id desc;
select * from stages where crm_configuration_id = 71 order by id desc;
select * from users order by secondary_email desc;
select u.id, u.email, u.status, sa.id, sa.provider_user_id from social_accounts sa
join users u on sa.sociable_id = u.id
where sa.provider = 'google' and u.email LIKE 'aneliya%';
select * from failed_jobs order by id desc;
select * from users where email = '[EMAIL]' or secondary_email = '[EMAIL]';
select * from teams;
SELECT * FROM crm_profiles WHERE crm_configuration_id = 39;
SELECT * FROM crm_fields WHERE crm_configuration_id = 39 and object_type = 'task';
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 1
and sa.provider = 'salesforce';
# [PASSWORD_DOTS]
SELECT * FROM activities WHERE uuid_to_bin('c38b3895-fd0f-4b1f-9fb2-c170dba137c6') = uuid;
SELECT * FROM crm_configurations WHERE id = 70;
select * from teams where id = 1;
select * from groups where team_id = 1;
select * from users where team_id = 1;
select o.id, o.name,o.close_date, u.id, u.name, u.group_id, r.id, r.display_name, g.name, g.scope from opportunities o
join users u on o.user_id = u.id
join groups g on u.group_id = g.id
join role_user ru on u.id = ru.user_id
join roles r on ru.role_id = r.id
where o.crm_configuration_id = 39 and close_date > '2024-01-01 00:00:00';
select * from role_user where user_id = 143;
select * from roles;
select * from role_user;
select * from groups where id = 9;
select * from scope_groups where group_id = 9;
# [PASSWORD_DOTS]
select * from teams where id = 36;
select * from crm_configurations;
SELECT * FROM social_accounts WHERE sociable_id = 121;
[URL_WITH_CREDENTIALS] this will add filter, however if we need to control feature by FF we need conditional logic
public const array TYPES = [
['id' => 'exec_summary', 'name' => 'Exec Summary'],
['id' => 'coaching_profiles', 'name' => 'Coaching Profiles'],
['id' => 'product_feedback', 'name' => 'Product Feedback'],
['id' => self::TYPE_LOSS_ANALYSIS, 'name' => 'Loss Analysis'],
// ['id' => 'questions', 'name' => 'Questions'],
// ['id' => 'statistical_quant', 'name' => 'Statistical Quantitative'],
];
public const array ALL_TYPES = [
...self::TYPES,
['id' => self::TYPE_ASK_JIMINNY, 'name' => 'Ask Jiminny'],
];
public const string FREQUENCY_DAILY = 'daily';
public const string FREQUENCY_WEEKLY = 'weekly';
public const string FREQUENCY_MONTHLY = 'monthly';
public const string FREQUENCY_QUARTERLY = 'quarterly';
public const string FREQUENCY_ONE_OFF = 'one_off';
/**
* Frequencies for standard (non-Ask Jiminny) reports.
*/
public const array FREQUENCIES = [
['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],
['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],
['id' => self::FREQUENCY_QUARTERLY, 'name' => 'Quarterly'],
['id' => self::FREQUENCY_ONE_OFF, 'name' => 'One-off'],
];
/**
* Frequencies for Ask Jiminny reports.
*/
public const array ASK_JIMINNY_FREQUENCIES = [
['id' => self::FREQUENCY_DAILY, 'name' => 'Daily'],
['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],
['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],
];
public const string MEDIA_TYPE_PDF = 'pdf';
public const string MEDIA_TYPE_PODCAST = 'podcast';
public const array MEDIA_TYPES = [self::MEDIA_TYPE_PDF, self::MEDIA_TYPE_PODCAST];
public const array MEDIA_TYPE_OBJECT_PDF = ['id' => self::MEDIA_TYPE_PDF, 'name' => 'PDF'];
public const array MEDIA_TYPE_OBJECT_PODCAST = ['id' => self::MEDIA_TYPE_PODCAST, 'name' => 'Podcast'];
public const array MEDIA_TYPE_OBJECTS = [self::MEDIA_TYPE_OBJECT_PDF, self::MEDIA_TYPE_OBJECT_PODCAST];
public const array CALL_TYPE_CONFERENCE = ['id' => 'conference', 'name' => 'Conference'];
public const array CALL_TYPE_DIALER = ['id' => 'dialer', 'name' => 'Dialer'];
public const int SENT_REPORT_AT_HOURS = 5;
public const string PDF_KEY = 'pdf';
public const string AUDIO_KEY = 'audio';
private const array ALL_FREQUENCIES = [
['id' => self::FREQUENCY_DAILY, 'name' => 'Daily'],
['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],
['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],
['id' => self::FREQUENCY_QUARTERLY, 'name' => 'Quarterly'],
['id' => self::FREQUENCY_ONE_OFF, 'name' => 'One-off'],
];
private const string S3_DIR = 'reports';
private const array FILE_EXTENSIONS_VARIANTS = ['html', 'MD', 'pdf'];
private const array FILE_PODCAST_EXTENSIONS_VARIANTS = ['json', 'mp3', 'ssml'];
public function __construct(
private readonly TeamRepository $teamRepository,
private readonly GroupRepository $groupRepository,
private readonly UserRepository $userRepository,
private readonly StageRepository $stageRepository,
private readonly DealStagesService $dealStagesService,
private readonly RecipientsService $recipientsService,
private readonly AutomatedReportsRepository $automatedReportsRepository,
private readonly Webhook $webhookService,
private readonly BusDispatcher $dispatcher,
private readonly ActivityTypeService $activityTypeService,
private readonly PlaybookCategoryRepository $playbookCategoryRepository,
private readonly AskAnythingPromptService $askAnythingPromptService,
private readonly SearchRepository $activitySearchRepository,
private readonly AskAnythingRepository $askAnythingRepository,
) {
}
public static function getTypes(): array
{
$types = self::TYPES;
return array_map(static function ($type) {
return $type['id'];
}, $types);
}
public static function getCallTypes(): array
{
return array_map(static function ($callType) {
return $callType['id'];
}, [self::CALL_TYPE_CONFERENCE, self::CALL_TYPE_DIALER]);
}
public static function getFrequencies(): array
{
return array_map(static function ($frequency) {
return $frequency['id'];
}, self::FREQUENCIES);
}
// front-facing structure
public function getReportEnabledFieldData(bool $value = false): array
{
return [
'id' => 'report_enabled',
'label' => '',
'inputType' => InputTypeEnum::TOGGLE,
'value' => $value,
];
}
// Organizations = Teams
public function getOrganizationFieldData(?string $value = null, bool $shortVersion = false): array
{
$options = $this->getTeams();
if ($shortVersion) {
return [
'id' => 'organization',
'label' => 'Organization',
'options' => $options,
];
}
return [
'id' => 'organization',
'label' => 'Organization',
'inputType' => InputTypeEnum::DROPDOWN,
'required' => true,
'placeholder' => 'Select',
'options' => $options,
'value' => $value,
'dependencies' => [
'teams',
'deal_stage_at_call',
'current_deal_stage',
'recipients',
ActivityTypeService::PLAYBOOK_CATEGORIES_KEY,
],
'dependsOn' => [],
];
}
// Teams = Groups
public function getTeamFieldData(array $options = [], array $value = [], bool $shortVersion = false): array
{
if ($shortVersion) {
return [
'id' => 'teams',
'label' => 'Team',
'options' => $options,
];
}
return [
'id' => 'teams',
'label' => 'Team',
'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,
'required' => false,
'placeholder' => 'Select',
'options' => $options,
'value' => $value, // value should be an array of objects {id, name}
'dependencies' => [ActivityTypeService::PLAYBOOK_CATEGORIES_KEY],
'dependsOn' => [],
];
}
public function getReportTypeFieldData(?string $value = null, bool $shortVersion = false, ?Team $team = null): array
{
$types = [];
if ($team instanceof Team) {
if ($team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {
$types = self::TYPES;
}
if ($team->hasFeature(FeatureEnum::ASK_JIMINNY_REPORTS)) {
$types[] = ['id' => self::TYPE_ASK_JIMINNY, 'name' => 'Ask Jiminny'];
}
} else {
$types = self::TYPES;
}
if ($shortVersion) {
return [
'id' => 'report_type',
'label' => 'Report Type',
'options' => $types,
];
}
return [
'id' => 'report_type',
'label' => 'Report Type',
'inputType' => InputTypeEnum::DROPDOWN,
'required' => true,
'placeholder' => 'Select',
'options' => $types,
'value' => $value,
'dependencies' => [],
'dependsOn' => [],
];
}
public function getFrequencyFieldData(?string $value = null): array
{
return [
'id' => 'frequency',
'label' => 'Frequency',
'inputType' => InputTypeEnum::DROPDOWN,
'required' => true,
'placeholder' => 'Select',
'options' => self::FREQUENCIES,
'value' => $value,
'dependencies' => ['period'],
'dependsOn' => [],
];
}
public function getPeriodFieldData(?string $valueStartDate = null, ?string $valueEndDate = null): array
{
return [
'id' => 'period',
'label' => 'Select one-off period',
'inputType' => InputTypeEnum::DATE_RANGE,
'required' => true,
'placeholder' => 'Select',
'value' => ['startDate' => $valueStartDate, 'endDate' => $valueEndDate],
'queryParams' => [
'startDate' => 'start_date_period',
'endDate' => 'end_date_period',
],
'dependencies' => [],
'dependsOn' => ['frequency'],
];
}
public function getActivityTypesFieldData(?Team $team = null, array $value = [], array $teamsFilter = []): array
{
return $this->activityTypeService->getActivityTypeFieldData(team: $team, value: $value, groupIds: $teamsFilter);
}
public function getDealStageAtCallFieldData(?Team $team = null, array $value = []): array
{
return $this->dealStagesService->getDealStageAtCallFieldData(team: $team, value: $value);
}
public function getCurrentDealStageFieldData(?Team $team = null, array $value = []): array
{
return $this->dealStagesService->getCurrentDealStageFieldData(team: $team, value: $value);
}
public function getDealValueFieldData(?int $valueMin = null, ?int $valueMax = null): array
{
return [
'id' => 'deal_value',
'label' => 'Deal Value',
'inputType' => InputTypeEnum::INTEGER_RANGE,
'required' => false,
'value' => ['min' => $valueMin, 'max' => $valueMax],
'queryParams' => [
'min' => 'min_deal_value',
'max' => 'max_deal_value',
],
'dependencies' => [],
'dependsOn' => [],
];
}
public function getCallTypeFieldData(bool $conferenceOn = false, bool $dialerOn = false): array
{
$value = [];
$conferenceOn && $value[] = self::CALL_TYPE_CONFERENCE;
$dialerOn && $value[] = self::CALL_TYPE_DIALER;
return [
'id' => 'call_type',
'label' => 'Call Type',
'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,
'required' => true,
'options' => [
self::CALL_TYPE_CONFERENCE,
self::CALL_TYPE_DIALER,
],
'value' => $value,
'dependencies' => [],
'dependsOn' => [],
];
}
public function getMediaTypeFieldData(?AutomatedReport $report = null): array
{
$value = [];
if ($report) {
$value = $this->transformMediaTypes($report);
}
return [
'id' => 'media_types',
'label' => 'Export as',
'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,
'required' => true,
'options' => self::MEDIA_TYPE_OBJECTS,
'value' => $value,
'dependencies' => [],
'dependsOn' => [],
];
}
public function getCallDurationFieldData(?int $valueMin = null, ?int $valueMax = null): array
{
return [
'id' => 'call_duration',
'label' => 'Call Duration',
'inputType' => InputTypeEnum::INTEGER_RANGE,
'required' => false,
'value' => ['min' => $valueMin, 'max' => $valueMax],
'queryParams' => [
'min' => 'min_call_duration',
'max' => 'max_call_duration',
],
'dependencies' => [],
'dependsOn' => [],
];
}
public function getRecipientsFieldData(?Team $team = null, array $value = []): array
{
return $this->recipientsService->getRecipientsFieldData(team: $team, value: $value);
}
public function getJiminnyRecipientsFieldData(array $value = []): array
{
return $this->recipientsService->getJiminnyRecipientsFieldData($value);
}
public function getAdditionalPromptInputFieldData(?string $value = null): array
{
return [
'id' => 'additional_prompt_input',
'label' => 'Special requirements',
'inputType' => InputTypeEnum::TEXTAREA,
'required' => false,
'placeholder' => 'What should be the focus of the report?',
'value' => $value,
'dependencies' => [],
'dependsOn' => [],
];
}
public function getCustomReportNameFieldData(?string $value = null): array
{
return [
'id' => 'custom_name',
'label' => 'Custom report name',
'inputType' => InputTypeEnum::TEXT,
'required' => false,
'placeholder' => 'Enter custom name',
'value' => $value,
'dependencies' => [],
'dependsOn' => [],
];
}
// data providers
public function getTeams(): array
{
$teams = $this->teamRepository->getTeamsForKiosk(status: Team::STATUS_ACTIVE);
$teamData = [];
foreach ($teams as $team) {
if (! $team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {
continue;
}
$teamData[] = $this->transformTeam($team);
}
return $teamData;
}
public function getTeamGroups(string $teamUuid): array
{
$data = [];
$team = $this->getTeam($teamUuid);
if ($team !== null) {
$groups = $team->groups()->get();
foreach ($groups as $group) {
$data[] = [
'id' => $group->getUuid(),
'name' => $group->getName(),
];
}
}
return $data;
}
public function getTeamsGroupsOptions(array $filterTeamUuids = []): array
{
$data = [];
$teams = $this->getTeams();
foreach ($teams as $team) {
if (! empty($filterTeamUuids) && ! in_array($team['id'], $filterTeamUuids, true)) {
continue;
}
$data[] = [
'label' => $team['name'],
'groups' => $this->getTeamGroups($team['id']),
];
}
return $data;
}
public function getTeam(string $teamUuid): ?Team
{
return $this->teamRepository->idOrUuid($teamUuid);
}
public function getTeamById(int $teamId): ?Team
{
return $this->teamRepository->find($teamId);
}
public function getGroupsUuids(AutomatedReport $report): array
{
$uuids = [];
$reportGroups = $report->getGroups();
foreach ($reportGroups as $groupId) {
if ($group = $this->groupRepository->find($groupId)) {
$uuids[] = $group->getUuid();
}
}
return $uuids;
}
public function getPlaybookCategoriesUuids(AutomatedReport $report): array
{
$uuids = [];
$playbookCategories = $report->getPlaybookCategories();
foreach ($playbookCategories as $id) {
if ($category = $this->playbookCategoryRepository->find($id)) {
$uuids[] = $category->getUuid();
}
}
return $uuids;
}
public function getDealAtCallStagesUuids(AutomatedReport $report): array
{
$uuids = [];
$reportStages = $report->getDealAtCallStages();
foreach ($reportStages as $id) {
if ($stage = $this->stageRepository->find($id)) {
$uuids[] = $stage->getUuid();
}
}
return $uuids;
}
public function getCurrentDealStagesUuids(AutomatedReport $report): array
{
$uuids = [];
$reportStages = $report->getCurrentDealStages();
foreach ($reportStages as $id) {
if ($stage = $this->stageRepository->find($id)) {
$uuids[] = $stage->getUuid();
}
}
return $uuids;
}
public function getUsersUuids(AutomatedReport $report): array
{
return $this->extractUserUuids($report->getRecipients());
}
public function getJiminnyUsersUuids(AutomatedReport $report): array
{
return $this->extractUserUuids($report->getJiminnyRecipients());
}
/**
* @param array<string, mixed> $recipients
*/
private function extractUserUuids(array $recipients): array
{
$userIds = $recipients['users'] ?? [];
return collect($userIds)
->map(fn ($id) => $this->userRepository->find((int) $id))
->filter()
->map(fn (UserContract $user) => $user->getUuid())
->values()
->all();
}
// get mail data
public function getRecipientUsers(AutomatedReport $report): array
{
return $this->buildRecipientUsers($report->getRecipients());
}
private function getJiminnyRecipientUsers(AutomatedReport $report): array
{
return $this->buildRecipientUsers($report->getJiminnyRecipients());
}
/**
* @param array<string, mixed> $recipients
*/
private function buildRecipientUsers(array $recipients): array
{
$userIds = $recipients['users'] ?? [];
return collect($userIds)
->map(fn ($id) => $this->userRepository->find((int) $id))
->filter()
->map(fn (UserContract $user) => [
'email' => $user->getEmailAddress(),
'name' => $user->getName(),
'timezone' => $user->getTimezone()->getName(),
])
->values()
->all();
}
public function getValidRecipientUsers(AutomatedReport $report, bool $includeJiminny = false): array
{
if ($report->isAskJiminnyReport()) {
$recipients = $this->resolveAskJiminnyRecipients($report);
} else {
$recipients = $this->getRecipientUsers($report);
if ($includeJiminny) {
$recipients = array_merge($recipients, $this->getJiminnyRecipientUsers($report));
}
}
$emails = [];
return array_values(array_filter(
$recipients,
static function ($recipient) use (&$emails) {
if (empty($recipient['email']) || in_array($recipient['email'], $emails, true)) {
return false;
}
$emails[] = $recipient['email'];
return true;
}
));
}
private function resolveAskJiminnyRecipients(AutomatedReport $report): array
{
$recipients = [];
$creator = $report->getCreator();
if ($creator !== null) {
$recipients[] = [
'email' => $creator->getEmailAddress(),
'name' => $creator->getName(),
'timezone' => $creator->getTimezone()->getName(),
];
}
return array_merge(
$recipients,
$this->buildRecipientUsers($report->getRecipients()),
$this->getGroupRecipientUsers($report),
);
}
private function getGroupRecipientUsers(AutomatedReport $report): array
{
$users = [];
foreach ($report->getGroups() as $groupId) {
$group = $this->groupRepository->find($groupId);
if ($group === null) {
continue;
}
foreach ($group->getMembers() as $member) {
$users[] = [
'email' => $member->getEmailAddress(),
'name' => $member->getName(),
'timezone' => $member->getTimezone()->getName(),
];
}
}
return $users;
}
public function getReportTypeName(AutomatedReportResult $report): string
{
$type = $report->getReport()->getType();
$getType = $this->transformReportType($type);
return $getType['name'];
}
public function getReportPeriodName(AutomatedReportResult $report): string
{
$from = $report->getFromDate();
$to = $report->getToDate();
$frequency = $report->getReport()->getFrequency();
if ($from === null || $to === null) {
if (! $report->getReport()->isAskJiminnyReport()) {
$invalidPeriod = $from === null ? 'from' : 'to';
throw new ApplicationException('Report period is invalid: ' . $invalidPeriod);
}
$period = $this->calculateFromAndToDatePeriod($frequency);
$from = $period['fromDate'];
$to = $period['toDate'];
}
return $this->formatReportPeriodName($frequency, $from, $to);
}
private function formatReportPeriodName(string $frequency, Carbon $from, Carbon $to): string
{
$fromYear = $from->format('Y');
$toYear = $to->format('Y');
$differentYears = $fromYear !== $toYear;
switch ($frequency) {
case self::FREQUENCY_DAILY:
return $from->format('j M Y');
case self::FREQUENCY_QUARTERLY:
// 'Jan-Mar 2025' or 'Nov 2024-Jan 2025' if years differ
$startMonth = $from->format('M');
$endMonth = $to->copy()->subMonth();
$endMonthName = $endMonth->format('M');
$endMonthYear = $endMonth->format('Y');
if ($differentYears) {
return "{$startMonth} {$fromYear} - {$endMonthName} {$endMonthYear}";
}
return "{$startMonth} - {$endMonthName} {$toYear}";
case self::FREQUENCY_MONTHLY:
// 'May 2025' - monthly reports are always within the same year
return $from->format('M Y');
case self::FREQUENCY_WEEKLY:
// '4 - 8 Aug 2025', '27 Oct - 3 Nov 2025', or '28 Dec 2024 - 3 Jan 2025' if years differ
$startDay = $from->format('j');
$endDay = $to->format('j');
$startMonth = $from->format('M');
$endMonth = $to->format('M');
if ($differentYears) {
return "{$startDay} {$startMonth} {$fromYear} - {$endDay} {$endMonth} {$toYear}";
}
if ($startMonth !== $endMonth) {
return "{$startDay} {$startMonth} - {$endDay} {$endMonth} {$toYear}";
}
return "{$startDay} - {$endDay} {$endMonth} {$toYear}";
case self::FREQUENCY_ONE_OFF:
// '2 May-31 May 2025' or '15 Dec 2024-15 Jan 2025' if years differ
$startDay = $from->format('j');
$startMonth = $from->format('M');
$endDay = $to->format('j');
$endMonth = $to->format('M');
// If same month and year, use a format like '2-31 May 2025'
if ($startMonth === $endMonth && ! $differentYears) {
return "{$startDay} - {$endDay} {$startMonth} {$toYear}";
}
// If different years, include both years
if ($differentYears) {
return "{$startDay} {$startMonth} {$fromYear} - {$endDay} {$endMonth} {$toYear}";
}
// Same year but different months
return "{$startDay} {$startMonth} - {$endDay} {$endMonth} {$toYear}";
default:
// Default format for unknown frequencies
return $from->format('j M Y') . ' - ' . $to->format('j M Y');
}
}
public function getReportTeamsName(AutomatedReportResult $report): string
{
$groups = $report->getGroups();
if (empty($groups)) {
return 'All';
}
// Get group names from repository
$groupNames = [];
foreach ($groups as $groupId) {
$group = $this->groupRepository->find($groupId);
if ($group) {
$groupNames[] = $group->getName();
}
}
if (count($groupNames) === 1) {
// Single team format
$teamsName = $groupNames[0];
} else {
// Multiple teams format
$teamsName = implode(', ', $groupNames);
}
return $teamsName;
}
public function getReportFileName(AutomatedReportResult $report): string
...
|
12308
|
|
12327
|
262
|
2
|
2026-04-14T11:06:31.425856+00:00
|
/Users/lukas/.screenpipe/data/data/2026-04-14/1776 /Users/lukas/.screenpipe/data/data/2026-04-14/1776164791425_m1.jpg...
|
PhpStorm
|
faVsco.js – AutomatedReportsService.php
|
1
|
NULL
|
monitor_1
|
NULL
|
NULL
|
NULL
|
NULL
|
Project: faVsco.js, menu
#11894 on JY-18909-automa Project: faVsco.js, menu
#11894 on JY-18909-automated-reports-ask-jiminny, menu
Start Listening for PHP Debug Connections
AutomatedReportsCommandTest
Run 'AutomatedReportsCommandTest'
Debug 'AutomatedReportsCommandTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Execute
Explain Plan
Browse Query History
View Parameters
Open Query Execution Settings…
In-Editor Results
Tx: Auto
Cancel Running Statements
Playground
jiminny
Sync Changes
Hide This Notification
Code changed:
Hide
16
13
13
Previous Highlighted Error
Next Highlighted Error
SELECT * FROM teams WHERE id = 1;
select * from crm_layouts where crm_configuration_id = 39;
SELECT * FROM crm_layout_entities WHERE crm_layout_id = 283;
SELECT * FROM crm_fields WHERE id = 2234;
SELECT * FROM crm_field_values WHERE crm_field_id = 2234;
select * from crm_profiles where user_id = 143;
select * from record_types where crm_configuration_id = 39; # 0121K000001MHElQAO,0121K000001MHEqQAO
select * from business_processes where crm_configuration_id = 39;
# 01941000000H669AAC, 01941000000H66JAAS
select * from record_type_field_values
where record_type_id IN (24);
select * from crm_field_values where id IN (2730);
select * from crm_configurations where id = 39;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 1
and sa.provider = 'salesforce'; #1035
select * from users where team_id = 1; # 222 group 3
SELECT * FROM activities WHERE user_id = 222 order by id desc;
select * from sidekick_settings where team_id = 1;
select * from teams where id = 1;
select * from team_features where team_id = 1;
select * from activities where crm_configuration_id = 2
and provider = 'ms-teams' and id = 608765;
SELECT * FROM activities WHERE crm_configuration_id = 2 and crm_provider_id = '59523413338';
select * from sidekick_settings where team_id = 2;
SELECT * FROM activities WHERE id = 608660;
select * from activity_summary_logs where activity_id = 608660;
select * from ai_prompts where transcription_id = 11214;
# [PASSWORD_DOTS]
SELECT * FROM activities WHERE uuid_to_bin('ed78a437-2804-450e-ab2f-56ab1c641346') = uuid;
# id: 608818, crm: 59628809737
SELECT * FROM activities WHERE uuid_to_bin('36b06e55-afdd-4782-8dee-c624cd0af191') = uuid;
# id: 608821, crm: 59632069252
SELECT ce.start_time, ce.end_time, a.id, a.uuid, crm_provider_id, calendar_event_id, title,
playbook_category_id, user_id, lead_id, contact_id, account_id, opportunity_id,
scheduled_start_time, scheduled_end_time, actual_start_time, actual_end_time, a.created_at
FROM activities a
join calendar_events ce on a.calendar_event_id = ce.id
WHERE a.id IN (608818, 608821);
select * from users where team_id = 1;
select * from team_settings where team_id = 1;
select * from crm_profiles where crm_configuration_id = 39 order by user_id;
select * from team_features where team_id = 1;
select * from users where team_id = 2;
SELECT * FROM activities WHERE uuid_to_bin('ec7647e9-5225-458b-b475-f31aa2769204') = uuid; # 612639
# Preslava N. Ivanova, grou id 3
SELECT * FROM opportunities WHERE uuid_to_bin('a2928fe5-aec5-46cb-85d9-7654c89e46a6') = uuid;
select * from activities where opportunity_id = 344 and actual_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00';
select
a.id,
a.type,
a.scheduled_start_time,
a.actual_start_time,
a.created_at,
a.opportunity_id,
a.status
FROM activities a
WHERE opportunity_id = 344
and status IN ('completed', 'received', 'delivered')
and (
(a.actual_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00')
OR (a.created_at between '2024-10-11 00:00:00' and '2024-10-12 00:00:00')
OR (a.scheduled_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00'))
;
SELECT * FROM users WHERE id = 222;
SELECT * FROM crm_profiles WHERE user_id = 222;
select * from crm_layouts where crm_configuration_id = 39;
SELECT * FROM crm_layout_entities WHERE crm_layout_id = 281;
select * from group_deal_risk_types;
select * from opportunities where team_id = 1;
SELECT * FROM opportunities WHERE id = 315;
SELECT * FROM crm_field_data WHERE object_id = 315;
select * from crm_field_data where object_id = 260;
select * from generic_ai_prompts where subject_id = 315;
select * from teams; # 36, 21, 121, [EMAIL]
SELECT * FROM social_accounts WHERE sociable_id = 121 and provider = 'bullhorn';
# [PASSWORD_DOTS]
select * from teams where id = 1;
select * from crm_configurations where id = 39;
select * from users where team_id = 1;
select u.email, cp.* from users u
join crm_profiles cp on u.id = cp.user_id
where u.team_id = 1;
# 1 - 00541000004281rAAA
# 204 - 0052g000003freeAAA
# 429 - 0052g000003qGOiAAM
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 1
and sa.provider = 'salesforce';
select * from activities where type = 'softphone'
and created_at > '2024-12-11 15:24:36' order by id desc;
select * from activity_providers where team_id = 1;
select * from activity_provider_users where activity_provider_id = 328;
select * from opportunities where crm_configuration_id = 39
AND account_id = 178 AND is_closed = false
order by created_at DESC;
select * from contacts where id = 3952;
select * from accounts where id = 178;
# [PASSWORD_DOTS]
select * from teams where id = 36;
select * from crm_configurations where id = 21;
select * from users where team_id = 36;
select u.email, cp.* from users u
join crm_profiles cp on u.id = cp.user_id
where u.team_id = 36;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 36
and sa.provider = 'bullhorn';
select * from social_accounts where id = 348;
UPDATE social_accounts SET
provider_user_token = '21442_6802599_91:41179a58-21e7-4d7c-ad58-56bb666b2f65',
provider_refresh_token = '21442_6802599_91:01c6b335-3f2a-42e4-85ff-8a08fa65fceb',
expires = 1733998131,
state = 'connected'
WHERE id = 348;
# [PASSWORD_DOTS]
select * from teams where id = 31;
select * from crm_configurations where id = 18;
select * from users where team_id = 31; # 257
select u.email, cp.* from users u
join crm_profiles cp on u.id = cp.user_id
where u.team_id = 31;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 31
and sa.provider = 'close';
select * from contacts where crm_configuration_id = 18;
# [PASSWORD_DOTS] NEPTUNE [PASSWORD_DOTS]
select * from teams;
select * from users where id IN (1030, 1035, 1052);
select * from crm_configurations;
select * from users where team_id = 65; # 257
select * from team_settings where team_id = 65; # 257
select * from invitations where team_id = 65; # 257
select * from users where email = '[EMAIL]'; # 257
select u.email, cp.* from users u
join crm_profiles cp on u.id = cp.user_id
where u.team_id = 65;
select * from crm_configurations where id = 53;
select * from accounts where crm_configuration_id = 53 order by id desc;
select * from leads where crm_configuration_id = 53 order by id desc;
select * from contacts where crm_configuration_id = 53 order by id desc;
select * from opportunities where crm_configuration_id = 53 order by id desc;
select * from crm_profiles where crm_configuration_id = 53 order by id desc;
select * from crm_fields where crm_configuration_id = 53 order by id desc;
select * from crm_field_values where crm_field_id = 3341 order by id desc;
select * from crm_layouts where crm_configuration_id = 53 order by id desc;
select * from stages where crm_configuration_id = 53 order by id desc;
select * from crm_profiles where crm_configuration_id = 13;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 65
and sa.provider = 'integration-app';
select * from contacts where crm_configuration_id = 13;
select * from social_accounts where sociable_id = 283;
SELECT * FROM opportunities WHERE crm_provider_id = '006O400000E9bzeIAB';
select * from activity_providers where team_id = 65;
SELECT * FROM activities WHERE crm_configuration_id IN (51, 52, 53);
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 65
;
# [PASSWORD_DOTS] STAGING [PASSWORD_DOTS]
SELECT * FROM teams;
SELECT * FROM teams WHERE id = 88;
SELECT * FROM teams WHERE id = 89;
select * from team_settings where team_id = 89;
SELECT * FROM users WHERE team_id = 89;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 89;
select * from users;
SELECT * FROM social_accounts WHERE sociable_id = 1761;
SELECT * FROM crm_configurations WHERE id = 70;
select * from accounts where crm_configuration_id = 70 order by id desc;
select * from leads where crm_configuration_id = 70 order by id desc;
select * from contacts where crm_configuration_id = 70 order by id desc;
select * from opportunities where crm_configuration_id = 70 order by id desc;
select * from crm_profiles where crm_configuration_id = 70 order by id desc;
select * from crm_fields where crm_configuration_id = 70 order by id desc;
select * from crm_field_values where crm_field_id = 3536 order by id desc;
select * from crm_layouts where crm_configuration_id = 70 order by id desc;
select * from stages where crm_configuration_id = 70 order by id desc;
select * from business_processes where crm_configuration_id = 70 order by id desc;
select * from business_process_stages where business_process_id = 34;
select * from contacts where id = 10468;
select * from crm_layouts where crm_configuration_id = 70;
SELECT * FROM crm_layout_entities WHERE crm_layout_id = 388;
SELECT * FROM crm_fields WHERE id IN (3533,3534,3535);
select * from activities where crm_configuration_id = 70
and (account_id IS NOT NULL or lead_id IS NOT NULL or contact_id IS NOT NULL or opportunity_id IS NOT NULL) order by id desc;
SELECT * FROM activities WHERE uuid_to_bin('2e10b60f-8a61-41c5-a3d4-28835353dc65') = uuid;
SELECT * FROM activities where crm_configuration_id = 69 ;
SELECT * FROM users WHERE email LIKE '%[EMAIL]%';
SELECT * FROM activities WHERE uuid_to_bin('5a150c93-40fc-42ec-b3bd-c1d328e09f6e') = uuid;
SELECT * FROM opportunities WHERE id = 385;
select * from participants p
join activities a on p.activity_id = a.id
where a.crm_configuration_id = 70
and (p.lead_id IS NOT NULL or p.contact_id IS NOT NULL);
SELECT * FROM participants WHERE id = 1013638;
select * from teams where id = 90;
select * from users where team_id = 90;
select * from social_accounts where social_accounts.sociable_id IN (1960,1760);
SELECT * FROM crm_profiles WHERE crm_configuration_id = 71;
select * from invitations where team_id = 90;
select * from crm_configurations where id = 71;
select * from accounts where crm_configuration_id = 71 order by id desc;
select * from leads where crm_configuration_id = 71 order by id desc;
select * from contacts where crm_configuration_id = 71 order by id desc;
select * from opportunities where crm_configuration_id = 71 order by id desc;
select * from crm_profiles where crm_configuration_id = 71 order by id desc;
select * from crm_fields where crm_configuration_id = 71 order by id desc;
select * from crm_field_values where crm_field_id = 3341 order by id desc;
select * from crm_layouts where crm_configuration_id = 71 order by id desc;
select * from stages where crm_configuration_id = 71 order by id desc;
select * from users order by secondary_email desc;
select u.id, u.email, u.status, sa.id, sa.provider_user_id from social_accounts sa
join users u on sa.sociable_id = u.id
where sa.provider = 'google' and u.email LIKE 'aneliya%';
select * from failed_jobs order by id desc;
select * from users where email = '[EMAIL]' or secondary_email = '[EMAIL]';
select * from teams;
SELECT * FROM crm_profiles WHERE crm_configuration_id = 39;
SELECT * FROM crm_fields WHERE crm_configuration_id = 39 and object_type = 'task';
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 1
and sa.provider = 'salesforce';
# [PASSWORD_DOTS]
SELECT * FROM activities WHERE uuid_to_bin('c38b3895-fd0f-4b1f-9fb2-c170dba137c6') = uuid;
SELECT * FROM crm_configurations WHERE id = 70;
select * from teams where id = 1;
select * from groups where team_id = 1;
select * from users where team_id = 1;
select o.id, o.name,o.close_date, u.id, u.name, u.group_id, r.id, r.display_name, g.name, g.scope from opportunities o
join users u on o.user_id = u.id
join groups g on u.group_id = g.id
join role_user ru on u.id = ru.user_id
join roles r on ru.role_id = r.id
where o.crm_configuration_id = 39 and close_date > '2024-01-01 00:00:00';
select * from role_user where user_id = 143;
select * from roles;
select * from role_user;
select * from groups where id = 9;
select * from scope_groups where group_id = 9;
# [PASSWORD_DOTS]
select * from teams where id = 36;
select * from crm_configurations;
SELECT * FROM social_accounts WHERE sociable_id = 121;
[URL_WITH_CREDENTIALS] this will add filter, however if we need to control feature by FF we need conditional logic
public const array TYPES = [
['id' => 'exec_summary', 'name' => 'Exec Summary'],
['id' => 'coaching_profiles', 'name' => 'Coaching Profiles'],
['id' => 'product_feedback', 'name' => 'Product Feedback'],
['id' => self::TYPE_LOSS_ANALYSIS, 'name' => 'Loss Analysis'],
// ['id' => 'questions', 'name' => 'Questions'],
// ['id' => 'statistical_quant', 'name' => 'Statistical Quantitative'],
];
public const array ALL_TYPES = [
...self::TYPES,
['id' => self::TYPE_ASK_JIMINNY, 'name' => 'Ask Jiminny'],
];
public const string FREQUENCY_DAILY = 'daily';
public const string FREQUENCY_WEEKLY = 'weekly';
public const string FREQUENCY_MONTHLY = 'monthly';
public const string FREQUENCY_QUARTERLY = 'quarterly';
public const string FREQUENCY_ONE_OFF = 'one_off';
/**
* Frequencies for standard (non-Ask Jiminny) reports.
*/
public const array FREQUENCIES = [
['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],
['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],
['id' => self::FREQUENCY_QUARTERLY, 'name' => 'Quarterly'],
['id' => self::FREQUENCY_ONE_OFF, 'name' => 'One-off'],
];
/**
* Frequencies for Ask Jiminny reports.
*/
public const array ASK_JIMINNY_FREQUENCIES = [
['id' => self::FREQUENCY_DAILY, 'name' => 'Daily'],
['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],
['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],
];
public const string MEDIA_TYPE_PDF = 'pdf';
public const string MEDIA_TYPE_PODCAST = 'podcast';
public const array MEDIA_TYPES = [self::MEDIA_TYPE_PDF, self::MEDIA_TYPE_PODCAST];
public const array MEDIA_TYPE_OBJECT_PDF = ['id' => self::MEDIA_TYPE_PDF, 'name' => 'PDF'];
public const array MEDIA_TYPE_OBJECT_PODCAST = ['id' => self::MEDIA_TYPE_PODCAST, 'name' => 'Podcast'];
public const array MEDIA_TYPE_OBJECTS = [self::MEDIA_TYPE_OBJECT_PDF, self::MEDIA_TYPE_OBJECT_PODCAST];
public const array CALL_TYPE_CONFERENCE = ['id' => 'conference', 'name' => 'Conference'];
public const array CALL_TYPE_DIALER = ['id' => 'dialer', 'name' => 'Dialer'];
public const int SENT_REPORT_AT_HOURS = 5;
public const string PDF_KEY = 'pdf';
public const string AUDIO_KEY = 'audio';
private const array ALL_FREQUENCIES = [
['id' => self::FREQUENCY_DAILY, 'name' => 'Daily'],
['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],
['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],
['id' => self::FREQUENCY_QUARTERLY, 'name' => 'Quarterly'],
['id' => self::FREQUENCY_ONE_OFF, 'name' => 'One-off'],
];
private const string S3_DIR = 'reports';
private const array FILE_EXTENSIONS_VARIANTS = ['html', 'MD', 'pdf'];
private const array FILE_PODCAST_EXTENSIONS_VARIANTS = ['json', 'mp3', 'ssml'];
public function __construct(
private readonly TeamRepository $teamRepository,
private readonly GroupRepository $groupRepository,
private readonly UserRepository $userRepository,
private readonly StageRepository $stageRepository,
private readonly DealStagesService $dealStagesService,
private readonly RecipientsService $recipientsService,
private readonly AutomatedReportsRepository $automatedReportsRepository,
private readonly Webhook $webhookService,
private readonly BusDispatcher $dispatcher,
private readonly ActivityTypeService $activityTypeService,
private readonly PlaybookCategoryRepository $playbookCategoryRepository,
private readonly AskAnythingPromptService $askAnythingPromptService,
private readonly SearchRepository $activitySearchRepository,
private readonly AskAnythingRepository $askAnythingRepository,
) {
}
public static function getTypes(): array
{
$types = self::TYPES;
return array_map(static function ($type) {
return $type['id'];
}, $types);
}
public static function getCallTypes(): array
{
return array_map(static function ($callType) {
return $callType['id'];
}, [self::CALL_TYPE_CONFERENCE, self::CALL_TYPE_DIALER]);
}
public static function getFrequencies(): array
{
return array_map(static function ($frequency) {
return $frequency['id'];
}, self::FREQUENCIES);
}
// front-facing structure
public function getReportEnabledFieldData(bool $value = false): array
{
return [
'id' => 'report_enabled',
'label' => '',
'inputType' => InputTypeEnum::TOGGLE,
'value' => $value,
];
}
// Organizations = Teams
public function getOrganizationFieldData(?string $value = null, bool $shortVersion = false): array
{
$options = $this->getTeams();
if ($shortVersion) {
return [
'id' => 'organization',
'label' => 'Organization',
'options' => $options,
];
}
return [
'id' => 'organization',
'label' => 'Organization',
'inputType' => InputTypeEnum::DROPDOWN,
'required' => true,
'placeholder' => 'Select',
'options' => $options,
'value' => $value,
'dependencies' => [
'teams',
'deal_stage_at_call',
'current_deal_stage',
'recipients',
ActivityTypeService::PLAYBOOK_CATEGORIES_KEY,
],
'dependsOn' => [],
];
}
// Teams = Groups
public function getTeamFieldData(array $options = [], array $value = [], bool $shortVersion = false): array
{
if ($shortVersion) {
return [
'id' => 'teams',
'label' => 'Team',
'options' => $options,
];
}
return [
'id' => 'teams',
'label' => 'Team',
'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,
'required' => false,
'placeholder' => 'Select',
'options' => $options,
'value' => $value, // value should be an array of objects {id, name}
'dependencies' => [ActivityTypeService::PLAYBOOK_CATEGORIES_KEY],
'dependsOn' => [],
];
}
public function getReportTypeFieldData(?string $value = null, bool $shortVersion = false, ?Team $team = null): array
{
$types = [];
if ($team instanceof Team) {
if ($team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {
$types = self::TYPES;
}
if ($team->hasFeature(FeatureEnum::ASK_JIMINNY_REPORTS)) {
$types[] = ['id' => self::TYPE_ASK_JIMINNY, 'name' => 'Ask Jiminny'];
}
} else {
$types = self::TYPES;
}
if ($shortVersion) {
return [
'id' => 'report_type',
'label' => 'Report Type',
'options' => $types,
];
}
return [
'id' => 'report_type',
'label' => 'Report Type',
'inputType' => InputTypeEnum::DROPDOWN,
'required' => true,
'placeholder' => 'Select',
'options' => $types,
'value' => $value,
'dependencies' => [],
'dependsOn' => [],
];
}
public function getFrequencyFieldData(?string $value = null): array
{
return [
'id' => 'frequency',
'label' => 'Frequency',
'inputType' => InputTypeEnum::DROPDOWN,
'required' => true,
'placeholder' => 'Select',
'options' => self::FREQUENCIES,
'value' => $value,
'dependencies' => ['period'],
'dependsOn' => [],
];
}
public function getPeriodFieldData(?string $valueStartDate = null, ?string $valueEndDate = null): array
{
return [
'id' => 'period',
'label' => 'Select one-off period',
'inputType' => InputTypeEnum::DATE_RANGE,
'required' => true,
'placeholder' => 'Select',
'value' => ['startDate' => $valueStartDate, 'endDate' => $valueEndDate],
'queryParams' => [
'startDate' => 'start_date_period',
'endDate' => 'end_date_period',
],
'dependencies' => [],
'dependsOn' => ['frequency'],
];
}
public function getActivityTypesFieldData(?Team $team = null, array $value = [], array $teamsFilter = []): array
{
return $this->activityTypeService->getActivityTypeFieldData(team: $team, value: $value, groupIds: $teamsFilter);
}
public function getDealStageAtCallFieldData(?Team $team = null, array $value = []): array
{
return $this->dealStagesService->getDealStageAtCallFieldData(team: $team, value: $value);
}
public function getCurrentDealStageFieldData(?Team $team = null, array $value = []): array
{
return $this->dealStagesService->getCurrentDealStageFieldData(team: $team, value: $value);
}
public function getDealValueFieldData(?int $valueMin = null, ?int $valueMax = null): array
{
return [
'id' => 'deal_value',
'label' => 'Deal Value',
'inputType' => InputTypeEnum::INTEGER_RANGE,
'required' => false,
'value' => ['min' => $valueMin, 'max' => $valueMax],
'queryParams' => [
'min' => 'min_deal_value',
'max' => 'max_deal_value',
],
'dependencies' => [],
'dependsOn' => [],
];
}
public function getCallTypeFieldData(bool $conferenceOn = false, bool $dialerOn = false): array
{
$value = [];
$conferenceOn && $value[] = self::CALL_TYPE_CONFERENCE;
$dialerOn && $value[] = self::CALL_TYPE_DIALER;
return [
'id' => 'call_type',
'label' => 'Call Type',
'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,
'required' => true,
'options' => [
self::CALL_TYPE_CONFERENCE,
self::CALL_TYPE_DIALER,
],
'value' => $value,
'dependencies' => [],
'dependsOn' => [],
];
}
public function getMediaTypeFieldData(?AutomatedReport $report = null): array
{
$value = [];
if ($report) {
$value = $this->transformMediaTypes($report);
}
return [
'id' => 'media_types',
'label' => 'Export as',
'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,
'required' => true,
'options' => self::MEDIA_TYPE_OBJECTS,
'value' => $value,
'dependencies' => [],
'dependsOn' => [],
];
}
public function getCallDurationFieldData(?int $valueMin = null, ?int $valueMax = null): array
{
return [
'id' => 'call_duration',
'label' => 'Call Duration',
'inputType' => InputTypeEnum::INTEGER_RANGE,
'required' => false,
'value' => ['min' => $valueMin, 'max' => $valueMax],
'queryParams' => [
'min' => 'min_call_duration',
'max' => 'max_call_duration',
],
'dependencies' => [],
'dependsOn' => [],
];
}
public function getRecipientsFieldData(?Team $team = null, array $value = []): array
{
return $this->recipientsService->getRecipientsFieldData(team: $team, value: $value);
}
public function getJiminnyRecipientsFieldData(array $value = []): array
{
return $this->recipientsService->getJiminnyRecipientsFieldData($value);
}
public function getAdditionalPromptInputFieldData(?string $value = null): array
{
return [
'id' => 'additional_prompt_input',
'label' => 'Special requirements',
'inputType' => InputTypeEnum::TEXTAREA,
'required' => false,
'placeholder' => 'What should be the focus of the report?',
'value' => $value,
'dependencies' => [],
'dependsOn' => [],
];
}
public function getCustomReportNameFieldData(?string $value = null): array
{
return [
'id' => 'custom_name',
'label' => 'Custom report name',
'inputType' => InputTypeEnum::TEXT,
'required' => false,
'placeholder' => 'Enter custom name',
'value' => $value,
'dependencies' => [],
'dependsOn' => [],
];
}
// data providers
public function getTeams(): array
{
$teams = $this->teamRepository->getTeamsForKiosk(status: Team::STATUS_ACTIVE);
$teamData = [];
foreach ($teams as $team) {
if (! $team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {
continue;
}
$teamData[] = $this->transformTeam($team);
}
return $teamData;
}
public function getTeamGroups(string $teamUuid): array
{
$data = [];
$team = $this->getTeam($teamUuid);
if ($team !== null) {
$groups = $team->groups()->get();
foreach ($groups as $group) {
$data[] = [
'id' => $group->getUuid(),
'name' => $group->getName(),
];
}
}
return $data;
}
public function getTeamsGroupsOptions(array $filterTeamUuids = []): array
{
$data = [];
$teams = $this->getTeams();
foreach ($teams as $team) {
if (! empty($filterTeamUuids) && ! in_array($team['id'], $filterTeamUuids, true)) {
continue;
}
$data[] = [
'label' => $team['name'],
'groups' => $this->getTeamGroups($team['id']),
];
}
return $data;
}
public function getTeam(string $teamUuid): ?Team
{
return $this->teamRepository->idOrUuid($teamUuid);
}
public function getTeamById(int $teamId): ?Team
{
return $this->teamRepository->find($teamId);
}
public function getGroupsUuids(AutomatedReport $report): array
{
$uuids = [];
$reportGroups = $report->getGroups();
foreach ($reportGroups as $groupId) {
if ($group = $this->groupRepository->find($groupId)) {
$uuids[] = $group->getUuid();
}
}
return $uuids;
}
public function getPlaybookCategoriesUuids(AutomatedReport $report): array
{
$uuids = [];
$playbookCategories = $report->getPlaybookCategories();
foreach ($playbookCategories as $id) {
if ($category = $this->playbookCategoryRepository->find($id)) {
$uuids[] = $category->getUuid();
}
}
return $uuids;
}
public function getDealAtCallStagesUuids(AutomatedReport $report): array
{
$uuids = [];
$reportStages = $report->getDealAtCallStages();
foreach ($reportStages as $id) {
if ($stage = $this->stageRepository->find($id)) {
$uuids[] = $stage->getUuid();
}
}
return $uuids;
}
public function getCurrentDealStagesUuids(AutomatedReport $report): array
{
$uuids = [];
$reportStages = $report->getCurrentDealStages();
foreach ($reportStages as $id) {
if ($stage = $this->stageRepository->find($id)) {
$uuids[] = $stage->getUuid();
}
}
return $uuids;
}
public function getUsersUuids(AutomatedReport $report): array
{
return $this->extractUserUuids($report->getRecipients());
}
public function getJiminnyUsersUuids(AutomatedReport $report): array
{
return $this->extractUserUuids($report->getJiminnyRecipients());
}
/**
* @param array<string, mixed> $recipients
*/
private function extractUserUuids(array $recipients): array
{
$userIds = $recipients['users'] ?? [];
return collect($userIds)
->map(fn ($id) => $this->userRepository->find((int) $id))
->filter()
->map(fn (UserContract $user) => $user->getUuid())
->values()
->all();
}
// get mail data
public function getRecipientUsers(AutomatedReport $report): array
{
return $this->buildRecipientUsers($report->getRecipients());
}
private function getJiminnyRecipientUsers(AutomatedReport $report): array
{
return $this->buildRecipientUsers($report->getJiminnyRecipients());
}
/**
* @param array<string, mixed> $recipients
*/
private function buildRecipientUsers(array $recipients): array
{
$userIds = $recipients['users'] ?? [];
return collect($userIds)
->map(fn ($id) => $this->userRepository->find((int) $id))
->filter()
->map(fn (UserContract $user) => [
'email' => $user->getEmailAddress(),
'name' => $user->getName(),
'timezone' => $user->getTimezone()->getName(),
])
->values()
->all();
}
public function getValidRecipientUsers(AutomatedReport $report, bool $includeJiminny = false): array
{
if ($report->isAskJiminnyReport()) {
$recipients = $this->resolveAskJiminnyRecipients($report);
} else {
$recipients = $this->getRecipientUsers($report);
if ($includeJiminny) {
$recipients = array_merge($recipients, $this->getJiminnyRecipientUsers($report));
}
}
$emails = [];
return array_values(array_filter(
$recipients,
static function ($recipient) use (&$emails) {
if (empty($recipient['email']) || in_array($recipient['email'], $emails, true)) {
return false;
}
$emails[] = $recipient['email'];
return true;
}
));
}
private function resolveAskJiminnyRecipients(AutomatedReport $report): array
{
$recipients = [];
$creator = $report->getCreator();
if ($creator !== null) {
$recipients[] = [
'email' => $creator->getEmailAddress(),
'name' => $creator->getName(),
'timezone' => $creator->getTimezone()->getName(),
];
}
return array_merge(
$recipients,
$this->buildRecipientUsers($report->getRecipients()),
$this->getGroupRecipientUsers($report),
);
}
private function getGroupRecipientUsers(AutomatedReport $report): array
{
$users = [];
foreach ($report->getGroups() as $groupId) {
$group = $this->groupRepository->find($groupId);
if ($group === null) {
continue;
}
foreach ($group->getMembers() as $member) {
$users[] = [
'email' => $member->getEmailAddress(),
'name' => $member->getName(),
'timezone' => $member->getTimezone()->getName(),
];
}
}
return $users;
}
public function getReportTypeName(AutomatedReportResult $report): string
{
$type = $report->getReport()->getType();
$getType = $this->transformReportType($type);
return $getType['name'];
}
public function getReportPeriodName(AutomatedReportResult $report): string
{
$from = $report->getFromDate();
$to = $report->getToDate();
$frequency = $report->getReport()->getFrequency();
if ($from === null || $to === null) {
if (! $report->getReport()->isAskJiminnyReport()) {
$invalidPeriod = $from === null ? 'from' : 'to';
throw new ApplicationException('Report period is invalid: ' . $invalidPeriod);
}
$period = $this->calculateFromAndToDatePeriod($frequency);
$from = $period['fromDate'];
$to = $period['toDate'];
}
return $this->formatReportPeriodName($frequency, $from, $to);
}
private function formatReportPeriodName(string $frequency, Carbon $from, Carbon $to): string
{
$fromYear = $from->format('Y');
$toYear = $to->format('Y');
$differentYears = $fromYear !== $toYear;
switch ($frequency) {
case self::FREQUENCY_DAILY:
return $from->format('j M Y');
case self::FREQUENCY_QUARTERLY:
// 'Jan-Mar 2025' or 'Nov 2024-Jan 2025' if years differ
$startMonth = $from->format('M');
$endMonth = $to->copy()->subMonth();
$endMonthName = $endMonth->format('M');
$endMonthYear = $endMonth->format('Y');
if ($differentYears) {
return "{$startMonth} {$fromYear} - {$endMonthName} {$endMonthYear}";
}
return "{$startMonth} - {$endMonthName} {$toYear}";
case self::FREQUENCY_MONTHLY:
// 'May 2025' - monthly reports are always within the same year
return $from->format('M Y');
case self::FREQUENCY_WEEKLY:
// '4 - 8 Aug 2025', '27 Oct - 3 Nov 2025', or '28 Dec 2024 - 3 Jan 2025' if years differ
$startDay = $from->format('j');
$endDay = $to->format('j');
$startMonth = $from->format('M');
$endMonth = $to->format('M');
if ($differentYears) {
return "{$startDay} {$startMonth} {$fromYear} - {$endDay} {$endMonth} {$toYear}";
}
if ($startMonth !== $endMonth) {
return "{$startDay} {$startMonth} - {$endDay} {$endMonth} {$toYear}";
}
return "{$startDay} - {$endDay} {$endMonth} {$toYear}";
case self::FREQUENCY_ONE_OFF:
// '2 May-31 May 2025' or '15 Dec 2024-15 Jan 2025' if years differ
$startDay = $from->format('j');
$startMonth = $from->format('M');
$endDay = $to->format('j');
$endMonth = $to->format('M');
// If same month and year, use a format like '2-31 May 2025'
if ($startMonth === $endMonth && ! $differentYears) {
return "{$startDay} - {$endDay} {$startMonth} {$toYear}";
}
// If different years, include both years
if ($differentYears) {
return "{$startDay} {$startMonth} {$fromYear} - {$endDay} {$endMonth} {$toYear}";
}
// Same year but different months
return "{$startDay} {$startMonth} - {$endDay} {$endMonth} {$toYear}";
default:
// Default format for unknown frequencies
return $from->format('j M Y') . ' - ' . $to->format('j M Y');
}
}
public function getReportTeamsName(AutomatedReportResult $report): string
{
$groups = $report->getGroups();
if (empty($groups)) {
return 'All';
}
// Get group names from repository
$groupNames = [];
foreach ($groups as $groupId) {
$group = $this->groupRepository->find($groupId);
if ($group) {
$groupNames[] = $group->getName();
}
}
if (count($groupNames) === 1) {
// Single team format
$teamsName = $groupNames[0];
} else {
// Multiple teams format
$teamsName = implode(', ', $groupNames);
}
return $teamsName;
}
public function getReportFileName(AutomatedReportResult $report): string
...
|
[{"role":"AXButton","text" [{"role":"AXButton","text":"Project: faVsco.js, menu","depth":5,"help_text":"~/jiminny/app","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"#11894 on JY-18909-automated-reports-ask-jiminny, menu","depth":5,"help_text":"Pull request #11894 exists for current branch JY-18909-automated-reports-ask-jiminny","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Start Listening for PHP Debug Connections","depth":5,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"AutomatedReportsCommandTest","depth":6,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Run 'AutomatedReportsCommandTest'","depth":6,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Debug 'AutomatedReportsCommandTest'","depth":6,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"More Actions","depth":6,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JetBrains AI","depth":5,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Search Everywhere","depth":5,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"IDE and Project Settings","depth":5,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Execute","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Explain Plan","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Browse Query History","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"View Parameters","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Open Query Execution Settings…","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"In-Editor Results","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Tx: Auto","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Cancel Running Statements","depth":4,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Playground","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"jiminny","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.088194445,"height":0.027777778},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"16","depth":4,"role_description":"text"},{"role":"AXStaticText","text":"13","depth":4,"role_description":"text"},{"role":"AXStaticText","text":"13","depth":4,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"SELECT * FROM teams WHERE id = 1;\n\nselect * from crm_layouts where crm_configuration_id = 39;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 283;\nSELECT * FROM crm_fields WHERE id = 2234;\nSELECT * FROM crm_field_values WHERE crm_field_id = 2234;\n\nselect * from crm_profiles where user_id = 143;\n\nselect * from record_types where crm_configuration_id = 39; # 0121K000001MHElQAO,0121K000001MHEqQAO\nselect * from business_processes where crm_configuration_id = 39;\n# 01941000000H669AAC, 01941000000H66JAAS\n\nselect * from record_type_field_values\n where record_type_id IN (24);\n\nselect * from crm_field_values where id IN (2730);\n\nselect * from crm_configurations where id = 39;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 1\nand sa.provider = 'salesforce'; #1035\n\n\nselect * from users where team_id = 1; # 222 group 3\nSELECT * FROM activities WHERE user_id = 222 order by id desc;\nselect * from sidekick_settings where team_id = 1;\nselect * from teams where id = 1;\nselect * from team_features where team_id = 1;\n\nselect * from activities where crm_configuration_id = 2\nand provider = 'ms-teams' and id = 608765;\n\nSELECT * FROM activities WHERE crm_configuration_id = 2 and crm_provider_id = '59523413338';\n\nselect * from sidekick_settings where team_id = 2;\n\nSELECT * FROM activities WHERE id = 608660;\nselect * from activity_summary_logs where activity_id = 608660;\nselect * from ai_prompts where transcription_id = 11214;\n\n# ********************************************************************************************************\nSELECT * FROM activities WHERE uuid_to_bin('ed78a437-2804-450e-ab2f-56ab1c641346') = uuid;\n# id: 608818, crm: 59628809737\nSELECT * FROM activities WHERE uuid_to_bin('36b06e55-afdd-4782-8dee-c624cd0af191') = uuid;\n# id: 608821, crm: 59632069252\nSELECT ce.start_time, ce.end_time, a.id, a.uuid, crm_provider_id, calendar_event_id, title,\nplaybook_category_id, user_id, lead_id, contact_id, account_id, opportunity_id,\nscheduled_start_time, scheduled_end_time, actual_start_time, actual_end_time, a.created_at\nFROM activities a\njoin calendar_events ce on a.calendar_event_id = ce.id\nWHERE a.id IN (608818, 608821);\n\nselect * from users where team_id = 1;\nselect * from team_settings where team_id = 1;\nselect * from crm_profiles where crm_configuration_id = 39 order by user_id;\n\nselect * from team_features where team_id = 1;\n\nselect * from users where team_id = 2;\n\nSELECT * FROM activities WHERE uuid_to_bin('ec7647e9-5225-458b-b475-f31aa2769204') = uuid; # 612639\n# Preslava N. Ivanova, grou id 3\n\nSELECT * FROM opportunities WHERE uuid_to_bin('a2928fe5-aec5-46cb-85d9-7654c89e46a6') = uuid;\n\nselect * from activities where opportunity_id = 344 and actual_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00';\n\nselect\n a.id,\n a.type,\n a.scheduled_start_time,\n a.actual_start_time,\n a.created_at,\n a.opportunity_id,\n a.status\nFROM activities a\nWHERE opportunity_id = 344\nand status IN ('completed', 'received', 'delivered')\nand (\n (a.actual_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00')\nOR (a.created_at between '2024-10-11 00:00:00' and '2024-10-12 00:00:00')\nOR (a.scheduled_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00'))\n;\n\nSELECT * FROM users WHERE id = 222;\n\nSELECT * FROM crm_profiles WHERE user_id = 222;\nselect * from crm_layouts where crm_configuration_id = 39;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 281;\n\nselect * from group_deal_risk_types;\n\nselect * from opportunities where team_id = 1;\n\nSELECT * FROM opportunities WHERE id = 315;\nSELECT * FROM crm_field_data WHERE object_id = 315;\nselect * from crm_field_data where object_id = 260;\n\nselect * from generic_ai_prompts where subject_id = 315;\n\nselect * from teams; # 36, 21, 121, james.graham@bullhorn.jiminny.com\nSELECT * FROM social_accounts WHERE sociable_id = 121 and provider = 'bullhorn';\n\n# ************************************************************************************\nselect * from teams where id = 1;\nselect * from crm_configurations where id = 39;\nselect * from users where team_id = 1;\nselect u.email, cp.* from users u\njoin crm_profiles cp on u.id = cp.user_id\nwhere u.team_id = 1;\n# 1 - 00541000004281rAAA\n# 204 - 0052g000003freeAAA\n# 429 - 0052g000003qGOiAAM\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 1\nand sa.provider = 'salesforce';\n\nselect * from activities where type = 'softphone'\nand created_at > '2024-12-11 15:24:36' order by id desc;\n\nselect * from activity_providers where team_id = 1;\nselect * from activity_provider_users where activity_provider_id = 328;\n\nselect * from opportunities where crm_configuration_id = 39\nAND account_id = 178 AND is_closed = false\norder by created_at DESC;\n\nselect * from contacts where id = 3952;\nselect * from accounts where id = 178;\n\n# ************************************************************************************\nselect * from teams where id = 36;\nselect * from crm_configurations where id = 21;\nselect * from users where team_id = 36;\nselect u.email, cp.* from users u\njoin crm_profiles cp on u.id = cp.user_id\nwhere u.team_id = 36;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 36\nand sa.provider = 'bullhorn';\n\nselect * from social_accounts where id = 348;\nUPDATE social_accounts SET\nprovider_user_token = '21442_6802599_91:41179a58-21e7-4d7c-ad58-56bb666b2f65',\nprovider_refresh_token = '21442_6802599_91:01c6b335-3f2a-42e4-85ff-8a08fa65fceb',\nexpires = 1733998131,\nstate = 'connected'\nWHERE id = 348;\n\n# ************************************************************************************\nselect * from teams where id = 31;\nselect * from crm_configurations where id = 18;\n\nselect * from users where team_id = 31; # 257\nselect u.email, cp.* from users u\njoin crm_profiles cp on u.id = cp.user_id\nwhere u.team_id = 31;\n\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 31\nand sa.provider = 'close';\n\nselect * from contacts where crm_configuration_id = 18;\n\n# ********************** NEPTUNE **************************************************************\nselect * from teams;\nselect * from users where id IN (1030, 1035, 1052);\nselect * from crm_configurations;\n\nselect * from users where team_id = 65; # 257\nselect * from team_settings where team_id = 65; # 257\nselect * from invitations where team_id = 65; # 257\nselect * from users where email = 'integration-account@jiminny.com'; # 257\nselect u.email, cp.* from users u\njoin crm_profiles cp on u.id = cp.user_id\nwhere u.team_id = 65;\n\nselect * from crm_configurations where id = 53;\nselect * from accounts where crm_configuration_id = 53 order by id desc;\nselect * from leads where crm_configuration_id = 53 order by id desc;\nselect * from contacts where crm_configuration_id = 53 order by id desc;\nselect * from opportunities where crm_configuration_id = 53 order by id desc;\nselect * from crm_profiles where crm_configuration_id = 53 order by id desc;\nselect * from crm_fields where crm_configuration_id = 53 order by id desc;\nselect * from crm_field_values where crm_field_id = 3341 order by id desc;\nselect * from crm_layouts where crm_configuration_id = 53 order by id desc;\nselect * from stages where crm_configuration_id = 53 order by id desc;\n\n\nselect * from crm_profiles where crm_configuration_id = 13;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 65\nand sa.provider = 'integration-app';\n\nselect * from contacts where crm_configuration_id = 13;\n\nselect * from social_accounts where sociable_id = 283;\n\nSELECT * FROM opportunities WHERE crm_provider_id = '006O400000E9bzeIAB';\n\nselect * from activity_providers where team_id = 65;\nSELECT * FROM activities WHERE crm_configuration_id IN (51, 52, 53);\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 65\n;\n\n# ***************************** STAGING ********************************************\nSELECT * FROM teams;\nSELECT * FROM teams WHERE id = 88;\nSELECT * FROM teams WHERE id = 89;\nselect * from team_settings where team_id = 89;\nSELECT * FROM users WHERE team_id = 89;\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 89;\n\nselect * from users;\nSELECT * FROM social_accounts WHERE sociable_id = 1761;\nSELECT * FROM crm_configurations WHERE id = 70;\nselect * from accounts where crm_configuration_id = 70 order by id desc;\nselect * from leads where crm_configuration_id = 70 order by id desc;\nselect * from contacts where crm_configuration_id = 70 order by id desc;\nselect * from opportunities where crm_configuration_id = 70 order by id desc;\nselect * from crm_profiles where crm_configuration_id = 70 order by id desc;\nselect * from crm_fields where crm_configuration_id = 70 order by id desc;\nselect * from crm_field_values where crm_field_id = 3536 order by id desc;\nselect * from crm_layouts where crm_configuration_id = 70 order by id desc;\nselect * from stages where crm_configuration_id = 70 order by id desc;\nselect * from business_processes where crm_configuration_id = 70 order by id desc;\nselect * from business_process_stages where business_process_id = 34;\n\nselect * from contacts where id = 10468;\n\nselect * from crm_layouts where crm_configuration_id = 70;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 388;\nSELECT * FROM crm_fields WHERE id IN (3533,3534,3535);\n\nselect * from activities where crm_configuration_id = 70\nand (account_id IS NOT NULL or lead_id IS NOT NULL or contact_id IS NOT NULL or opportunity_id IS NOT NULL) order by id desc;\n\nSELECT * FROM activities WHERE uuid_to_bin('2e10b60f-8a61-41c5-a3d4-28835353dc65') = uuid;\nSELECT * FROM activities where crm_configuration_id = 69 ;\n\nSELECT * FROM users WHERE email LIKE '%jiminny_web_sa2@jiminny.com%';\nSELECT * FROM activities WHERE uuid_to_bin('5a150c93-40fc-42ec-b3bd-c1d328e09f6e') = uuid;\nSELECT * FROM opportunities WHERE id = 385;\n\nselect * from participants p\njoin activities a on p.activity_id = a.id\nwhere a.crm_configuration_id = 70\nand (p.lead_id IS NOT NULL or p.contact_id IS NOT NULL);\nSELECT * FROM participants WHERE id = 1013638;\n\nselect * from teams where id = 90;\nselect * from users where team_id = 90;\nselect * from social_accounts where social_accounts.sociable_id IN (1960,1760);\nSELECT * FROM crm_profiles WHERE crm_configuration_id = 71;\nselect * from invitations where team_id = 90;\n\nselect * from crm_configurations where id = 71;\nselect * from accounts where crm_configuration_id = 71 order by id desc;\nselect * from leads where crm_configuration_id = 71 order by id desc;\nselect * from contacts where crm_configuration_id = 71 order by id desc;\nselect * from opportunities where crm_configuration_id = 71 order by id desc;\nselect * from crm_profiles where crm_configuration_id = 71 order by id desc;\nselect * from crm_fields where crm_configuration_id = 71 order by id desc;\nselect * from crm_field_values where crm_field_id = 3341 order by id desc;\nselect * from crm_layouts where crm_configuration_id = 71 order by id desc;\nselect * from stages where crm_configuration_id = 71 order by id desc;\n\nselect * from users order by secondary_email desc;\nselect u.id, u.email, u.status, sa.id, sa.provider_user_id from social_accounts sa\n join users u on sa.sociable_id = u.id\nwhere sa.provider = 'google' and u.email LIKE 'aneliya%';\n\nselect * from failed_jobs order by id desc;\n\nselect * from users where email = 'ben.allwright@learningpeople.co.uk' or secondary_email = 'ben.allwright@learningpeople.co.uk';\n\nselect * from teams;\nSELECT * FROM crm_profiles WHERE crm_configuration_id = 39;\nSELECT * FROM crm_fields WHERE crm_configuration_id = 39 and object_type = 'task';\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 1\nand sa.provider = 'salesforce';\n\n# ************************************************************************************\nSELECT * FROM activities WHERE uuid_to_bin('c38b3895-fd0f-4b1f-9fb2-c170dba137c6') = uuid;\nSELECT * FROM crm_configurations WHERE id = 70;\n\nselect * from teams where id = 1;\nselect * from groups where team_id = 1;\nselect * from users where team_id = 1;\n\nselect o.id, o.name,o.close_date, u.id, u.name, u.group_id, r.id, r.display_name, g.name, g.scope from opportunities o\njoin users u on o.user_id = u.id\njoin groups g on u.group_id = g.id\njoin role_user ru on u.id = ru.user_id\njoin roles r on ru.role_id = r.id\nwhere o.crm_configuration_id = 39 and close_date > '2024-01-01 00:00:00';\n\nselect * from role_user where user_id = 143;\nselect * from roles;\n\nselect * from role_user;\nselect * from groups where id = 9;\nselect * from scope_groups where group_id = 9;\n\n# ************************************************************************************\nselect * from teams where id = 36;\nselect * from crm_configurations;\nSELECT * FROM social_accounts WHERE sociable_id = 121;\n\nhttps://crmsandbox.zoho.com/crm/jiminnyw4/tab/Leads/4776201000005049105\nhttps://crmsandbox.zoho.com/crm/\n\nhttps://crm.zoho.com/crm/org3469620/tab/Leads/230045000229559080\n https://crm.zoho.com/crm/\n org3469620\n\nSELECT * FROM activities WHERE uuid_to_bin('03382d20-c8bc-48e7-a3d4-90b52fa5ceab') = uuid;\n\nselect * from users where email LIKE \"%mobile_automation_%\";\nselect * from social_accounts where sociable_id IN (2228);\nselect * from crm_profiles where user_id IN (2222,2223,2226,2227);\n\nselect * from teams order by id desc;\nSELECT * FROM users WHERE id = 2229;\nSELECT * FROM crm_profiles WHERE user_id = 2229;\nselect * from opportunities where crm_configuration_id = 88;\nselect * from crm_fields where crm_configuration_id = 88;\nselect * from crm_profiles where crm_configuration_id = 88;\n\nSELECT * FROM teams WHERE id = 1;\n\nSELECT * FROM users WHERE id = 143;\nSELECT * FROM users WHERE uuid_to_bin('fde193d3-06a2-4e1a-8895-62b94039215d') = uuid;\nSELECT * FROM teams WHERE uuid_to_bin('73385071-a756-42ae-9c73-8b53f2309467') = uuid;\n\nhttps://app.staging.jiminny.com/ondemand?\n min_duration=1\n &\n only_recorded=1\n &\n user_id%5B%5D=641f1acb-16b8-42d1-8726-df52979dad0e\n &\n sequence_number=2\n\n select * from users where team_id = 1 and email like '%stoyan%'\n\nselect * from coaching_feedbacks;\n\nselect * from teams;\nSELECT * FROM users WHERE team_id = 36;\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 19\nand sa.provider = 'pipedrive';\n\nselect * from users where id = 143;\n\nSELECT * FROM users WHERE uuid_to_bin('73180eeb-33de-4065-977d-ccbe0e6c94fc') = uuid;\nSELECT * FROM teams WHERE uuid_to_bin('73180eeb-33de-4065-977d-ccbe0e6c94fc') = uuid;\nSELECT * FROM activity_shares WHERE uuid_to_bin('73180eeb-33de-4065-977d-ccbe0e6c94fc') = uuid;\n\nselect * from users where team_id = 2;\nselect * from activities where crm_configuration_id = 39\nand activities.scheduled_start_time BETWEEN '2025-04-09 00:00:00' AND '2025-04-09 23:59:59'\nAND user_id = 143\norder by id desc;\n\n# ************************************************************************************\nselect * from teams where id = 142; # 2312, 126\nselect * from team_settings;\nselect * from users where team_id = 142; # 21642\nSELECT * FROM social_accounts WHERE sociable_id = 21642;\nSELECT * FROM crm_profiles cp join users u ON u.id = cp.user_id WHERE team_id = 142;\nselect * from crm_profiles where id IN (93);\nselect * from invitations;\nselect * from team_features where team_id = 1;\n\nSELECT * FROM crm_configurations WHERE id = 126;\nselect * from accounts where crm_configuration_id = 126 order by id desc;\nselect * from leads where crm_configuration_id = 126 order by id desc;\nselect * from contacts where crm_configuration_id = 126 order by id desc;\nselect * from opportunities where crm_configuration_id = 126 order by id desc;\nselect * from crm_profiles where crm_configuration_id = 126 order by id desc;\nselect * from crm_fields where crm_configuration_id = 126 # 11060\n# and type IN ('picklist', 'status')\n# and object_type = 'task'\norder by id desc;\n# 5731,5732,5733\nselect DISTINCT crm_field_id from crm_field_values where crm_field_id IN (11151,12239,12215,12185,12175,12165,12144,12137,12127,12109,12107,12105,12103,12092,12037,12005,12003,11987,11969,11958,11951,11942,11931,11924,11921,11917,11915,11901,11893,11883,11872,11870,11868,11866,11839,11833,11821,11793,11780,11777,11769,11757,11737,11735,11656,11645,11638,11629,11618,11611,11602,11591,11584,11581,11558,11544,11543,11534,11532,11529,11527,11503,11497,11493,11488,11470,11468,11457,11455,11397,11387,11372,11363,11348,11323,11318,11309,11301,11300,11292,11290,11286,11284,11256,11252,11242,11237,11233,11219,11176,11160) order by id desc;\nselect * from crm_layouts where crm_configuration_id = 126 order by id desc;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id in (300,299,298);\nselect * from stages where crm_configuration_id = 126 order by id desc;\nselect * from business_processes where crm_configuration_id = 126 order by id desc;\nselect * from business_process_stages where business_process_id IN (76,75,74,73);\nselect * from playbooks where team_id = 142;\nselect * from playbook_layouts where playbook_id IN (108);\nSELECT * FROM playbook_categories WHERE playbook_id IN (108);\n\nselect * from teams where id = 130;\nSELECT * FROM social_accounts WHERE sociable_id = 2291;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 2\nand sa.provider = 'hubspot';\n\nSELECT * FROM activities\n WHERE crm_configuration_id = 110;\n\nselect * from teams;\nselect * from crm_configurations;\n\nSELECT * FROM activities WHERE id = 628773;\nSELECT * FROM crm_profiles WHERE user_id = 1460;\nSELECT * FROM social_accounts WHERE sociable_id = 2291;\n\nselect * from teams;\nselect ru.*, pr.*, p.* from users u join role_user ru on ru.user_id = u.id\njoin permission_role pr on pr.role_id = ru.role_id\n join permissions p on p.id = pr.permission_id\nwhere team_id = 495 and p.name IN ('dial');\n\nselect * from teams where id = 145;\nselect * from crm_configurations where id = 129;\nselect * from social_accounts where sociable_id = 2317;\nSELECT * FROM activities WHERE uuid_to_bin('8dbab184-a333-4268-ad57-fb41f8d53a9a') = uuid;\n\nselect * from teams where id = 1;\nSELECT * FROM crm_layouts WHERE crm_configuration_id = 39;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 280;\nSELECT * FROM crm_layout_entities WHERE id = 5507;\nSELECT * FROM crm_fields WHERE crm_configuration_id = 39 and object_type IN ('event');\n\nselect * from teams;\nselect * from activities where crm_configuration_id = 14;\n\nSELECT * FROM social_accounts where provider = 'copper';\n\nselect * from activities where id = 628467;\nselect * from participants where activity_id = 628467;\n\nSELECT * FROM contacts WHERE id = 3969;\nSELECT * FROM accounts WHERE id = 177;\n\nSELECT * FROM activities WHERE uuid_to_bin('4eb54c77-cfa3-2bd4-84a7-9ed46a21c988') = uuid;\n\n# ********************* BH\nselect * from teams where id = 36;\nSELECT * FROM crm_configurations WHERE id = 21;\nselect * from activities where crm_configuration_id = 21 and id = 607901;\nselect * from activities where crm_configuration_id = 21;\n\nselect * roles;\nselect * from permissions;\nselect * from permission_role where permission_id = 226;\n\nselect * from migrations order by id desc;\n\n# mercury\n# neptune\n# earth\n\nselect * from teams;\nselect * from teams where id = 19;\nselect * from teams where id = 27;\nselect * from users where team_id = 27;\nSELECT * FROM crm_configurations WHERE id = 42;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 19\nand sa.provider = 'pipedrive';\n\nselect * from activities where id = 631461;\nSELECT * FROM crm_field_values WHERE crm_field_id = 180;\n\nselect * from teams where id = 2;\nSELECT * FROM social_accounts WHERE sociable_id = 89;\n\nSELECT * FROM activities WHERE uuid_to_bin('ba0c029a-bc14-4e17-8603-64174acebcbb') = uuid; # 634273\nselect * from activity_summary_logs where activity_id = 634273;\n\nselect * from sidekick_settings where team_id = 2;\n\nselect * from teams; # 2, 2\nSELECT * FROM crm_configurations WHERE team_id = 2; # 2\nselect * from team_features where team_id = 2;\nselect * from features;\nSELECT * FROM opportunities WHERE crm_configuration_id = 2 and crm_provider_id = '51317301383';\nSELECT * FROM opportunities WHERE crm_configuration_id = 2 order by id desc;\n\nselect * from automated_reports order by id desc;\nselect * from automated_report_results order by id desc;\nselect * from users where team_id = 1 and id IN (7160, 3248);\nselect * from migrations order by id desc;\n\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 1 and sa.provider = 'salesforce';\n\nselect * from teams where id = 1;\nselect * from groups g JOIN playbooks p on g.playbook_id = p.id where g.team_id = 1;\nselect * from groups where id = 565;\nselect * from playbooks where team_id = 1;\nselect * from playbooks where id = 175;\nselect * from playbook_categories where playbook_id = 175;\nselect * from users where team_id = 1;\nselect * from users where id = 7160;\nselect * from crm_profiles where user_id = 7160;\nselect * from features;\nselect\n *\n# id, uuid, type, provider, playbook_category_id, user_id, lead_id, contact_id, account_id, opportunity_id, stage_id,\n# crm_configuration_id, crm_provider_id, transcription_id, status\nfrom activities where crm_configuration_id = 1 and type = 'conference'\n# and crm_provider_id IS NOT NULL\nand provider != 'uploader' and actual_start_time IS NOT NULL\nORDER by id desc;\nselect * from activities where id = 54747783; # 00UO400000pCzojMAC\n\nselect p.id, p.activity_type, pc.id, pc.name\nFROM playbooks p\njoin playbook_categories pc on p.id = pc.playbook_id\nwhere p.team_id = 1 and p.activity_type = 'event';\n\nSELECT * FROM crm_fields WHERE crm_configuration_id = 1 and object_type = 'event';\nSELECT * FROM crm_field_values WHERE crm_field_id = 4;\n\nselect * from crm_layouts cl join playbook_layouts pl on cl.id = pl.layout_id\nwhere crm_configuration_id = 1 and pl.playbook_id = 175;\n\nselect * from teams;\nSELECT r.* FROM automated_reports r\njoin teams t on r.team_id = t.id\nWHERE r.frequency = 'daily'\n and r.status = 1\nAND t.status = 'active'\nAND (r.expires_at >= now() OR r.expires_at IS NULL);\n\nselect * from automated_report_results where report_id IN (18, 33);\n\nselect * from activity_searches where id = 10932;\nselect * from activity_search_filters where activity_search_id = 10932;\nselect * from automated_reports;\nselect * from automated_report_results where report_id IN (34, 35);","depth":4,"value":"SELECT * FROM teams WHERE id = 1;\n\nselect * from crm_layouts where crm_configuration_id = 39;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 283;\nSELECT * FROM crm_fields WHERE id = 2234;\nSELECT * FROM crm_field_values WHERE crm_field_id = 2234;\n\nselect * from crm_profiles where user_id = 143;\n\nselect * from record_types where crm_configuration_id = 39; # 0121K000001MHElQAO,0121K000001MHEqQAO\nselect * from business_processes where crm_configuration_id = 39;\n# 01941000000H669AAC, 01941000000H66JAAS\n\nselect * from record_type_field_values\n where record_type_id IN (24);\n\nselect * from crm_field_values where id IN (2730);\n\nselect * from crm_configurations where id = 39;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 1\nand sa.provider = 'salesforce'; #1035\n\n\nselect * from users where team_id = 1; # 222 group 3\nSELECT * FROM activities WHERE user_id = 222 order by id desc;\nselect * from sidekick_settings where team_id = 1;\nselect * from teams where id = 1;\nselect * from team_features where team_id = 1;\n\nselect * from activities where crm_configuration_id = 2\nand provider = 'ms-teams' and id = 608765;\n\nSELECT * FROM activities WHERE crm_configuration_id = 2 and crm_provider_id = '59523413338';\n\nselect * from sidekick_settings where team_id = 2;\n\nSELECT * FROM activities WHERE id = 608660;\nselect * from activity_summary_logs where activity_id = 608660;\nselect * from ai_prompts where transcription_id = 11214;\n\n# ********************************************************************************************************\nSELECT * FROM activities WHERE uuid_to_bin('ed78a437-2804-450e-ab2f-56ab1c641346') = uuid;\n# id: 608818, crm: 59628809737\nSELECT * FROM activities WHERE uuid_to_bin('36b06e55-afdd-4782-8dee-c624cd0af191') = uuid;\n# id: 608821, crm: 59632069252\nSELECT ce.start_time, ce.end_time, a.id, a.uuid, crm_provider_id, calendar_event_id, title,\nplaybook_category_id, user_id, lead_id, contact_id, account_id, opportunity_id,\nscheduled_start_time, scheduled_end_time, actual_start_time, actual_end_time, a.created_at\nFROM activities a\njoin calendar_events ce on a.calendar_event_id = ce.id\nWHERE a.id IN (608818, 608821);\n\nselect * from users where team_id = 1;\nselect * from team_settings where team_id = 1;\nselect * from crm_profiles where crm_configuration_id = 39 order by user_id;\n\nselect * from team_features where team_id = 1;\n\nselect * from users where team_id = 2;\n\nSELECT * FROM activities WHERE uuid_to_bin('ec7647e9-5225-458b-b475-f31aa2769204') = uuid; # 612639\n# Preslava N. Ivanova, grou id 3\n\nSELECT * FROM opportunities WHERE uuid_to_bin('a2928fe5-aec5-46cb-85d9-7654c89e46a6') = uuid;\n\nselect * from activities where opportunity_id = 344 and actual_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00';\n\nselect\n a.id,\n a.type,\n a.scheduled_start_time,\n a.actual_start_time,\n a.created_at,\n a.opportunity_id,\n a.status\nFROM activities a\nWHERE opportunity_id = 344\nand status IN ('completed', 'received', 'delivered')\nand (\n (a.actual_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00')\nOR (a.created_at between '2024-10-11 00:00:00' and '2024-10-12 00:00:00')\nOR (a.scheduled_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00'))\n;\n\nSELECT * FROM users WHERE id = 222;\n\nSELECT * FROM crm_profiles WHERE user_id = 222;\nselect * from crm_layouts where crm_configuration_id = 39;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 281;\n\nselect * from group_deal_risk_types;\n\nselect * from opportunities where team_id = 1;\n\nSELECT * FROM opportunities WHERE id = 315;\nSELECT * FROM crm_field_data WHERE object_id = 315;\nselect * from crm_field_data where object_id = 260;\n\nselect * from generic_ai_prompts where subject_id = 315;\n\nselect * from teams; # 36, 21, 121, james.graham@bullhorn.jiminny.com\nSELECT * FROM social_accounts WHERE sociable_id = 121 and provider = 'bullhorn';\n\n# ************************************************************************************\nselect * from teams where id = 1;\nselect * from crm_configurations where id = 39;\nselect * from users where team_id = 1;\nselect u.email, cp.* from users u\njoin crm_profiles cp on u.id = cp.user_id\nwhere u.team_id = 1;\n# 1 - 00541000004281rAAA\n# 204 - 0052g000003freeAAA\n# 429 - 0052g000003qGOiAAM\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 1\nand sa.provider = 'salesforce';\n\nselect * from activities where type = 'softphone'\nand created_at > '2024-12-11 15:24:36' order by id desc;\n\nselect * from activity_providers where team_id = 1;\nselect * from activity_provider_users where activity_provider_id = 328;\n\nselect * from opportunities where crm_configuration_id = 39\nAND account_id = 178 AND is_closed = false\norder by created_at DESC;\n\nselect * from contacts where id = 3952;\nselect * from accounts where id = 178;\n\n# ************************************************************************************\nselect * from teams where id = 36;\nselect * from crm_configurations where id = 21;\nselect * from users where team_id = 36;\nselect u.email, cp.* from users u\njoin crm_profiles cp on u.id = cp.user_id\nwhere u.team_id = 36;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 36\nand sa.provider = 'bullhorn';\n\nselect * from social_accounts where id = 348;\nUPDATE social_accounts SET\nprovider_user_token = '21442_6802599_91:41179a58-21e7-4d7c-ad58-56bb666b2f65',\nprovider_refresh_token = '21442_6802599_91:01c6b335-3f2a-42e4-85ff-8a08fa65fceb',\nexpires = 1733998131,\nstate = 'connected'\nWHERE id = 348;\n\n# ************************************************************************************\nselect * from teams where id = 31;\nselect * from crm_configurations where id = 18;\n\nselect * from users where team_id = 31; # 257\nselect u.email, cp.* from users u\njoin crm_profiles cp on u.id = cp.user_id\nwhere u.team_id = 31;\n\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 31\nand sa.provider = 'close';\n\nselect * from contacts where crm_configuration_id = 18;\n\n# ********************** NEPTUNE **************************************************************\nselect * from teams;\nselect * from users where id IN (1030, 1035, 1052);\nselect * from crm_configurations;\n\nselect * from users where team_id = 65; # 257\nselect * from team_settings where team_id = 65; # 257\nselect * from invitations where team_id = 65; # 257\nselect * from users where email = 'integration-account@jiminny.com'; # 257\nselect u.email, cp.* from users u\njoin crm_profiles cp on u.id = cp.user_id\nwhere u.team_id = 65;\n\nselect * from crm_configurations where id = 53;\nselect * from accounts where crm_configuration_id = 53 order by id desc;\nselect * from leads where crm_configuration_id = 53 order by id desc;\nselect * from contacts where crm_configuration_id = 53 order by id desc;\nselect * from opportunities where crm_configuration_id = 53 order by id desc;\nselect * from crm_profiles where crm_configuration_id = 53 order by id desc;\nselect * from crm_fields where crm_configuration_id = 53 order by id desc;\nselect * from crm_field_values where crm_field_id = 3341 order by id desc;\nselect * from crm_layouts where crm_configuration_id = 53 order by id desc;\nselect * from stages where crm_configuration_id = 53 order by id desc;\n\n\nselect * from crm_profiles where crm_configuration_id = 13;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 65\nand sa.provider = 'integration-app';\n\nselect * from contacts where crm_configuration_id = 13;\n\nselect * from social_accounts where sociable_id = 283;\n\nSELECT * FROM opportunities WHERE crm_provider_id = '006O400000E9bzeIAB';\n\nselect * from activity_providers where team_id = 65;\nSELECT * FROM activities WHERE crm_configuration_id IN (51, 52, 53);\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 65\n;\n\n# ***************************** STAGING ********************************************\nSELECT * FROM teams;\nSELECT * FROM teams WHERE id = 88;\nSELECT * FROM teams WHERE id = 89;\nselect * from team_settings where team_id = 89;\nSELECT * FROM users WHERE team_id = 89;\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 89;\n\nselect * from users;\nSELECT * FROM social_accounts WHERE sociable_id = 1761;\nSELECT * FROM crm_configurations WHERE id = 70;\nselect * from accounts where crm_configuration_id = 70 order by id desc;\nselect * from leads where crm_configuration_id = 70 order by id desc;\nselect * from contacts where crm_configuration_id = 70 order by id desc;\nselect * from opportunities where crm_configuration_id = 70 order by id desc;\nselect * from crm_profiles where crm_configuration_id = 70 order by id desc;\nselect * from crm_fields where crm_configuration_id = 70 order by id desc;\nselect * from crm_field_values where crm_field_id = 3536 order by id desc;\nselect * from crm_layouts where crm_configuration_id = 70 order by id desc;\nselect * from stages where crm_configuration_id = 70 order by id desc;\nselect * from business_processes where crm_configuration_id = 70 order by id desc;\nselect * from business_process_stages where business_process_id = 34;\n\nselect * from contacts where id = 10468;\n\nselect * from crm_layouts where crm_configuration_id = 70;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 388;\nSELECT * FROM crm_fields WHERE id IN (3533,3534,3535);\n\nselect * from activities where crm_configuration_id = 70\nand (account_id IS NOT NULL or lead_id IS NOT NULL or contact_id IS NOT NULL or opportunity_id IS NOT NULL) order by id desc;\n\nSELECT * FROM activities WHERE uuid_to_bin('2e10b60f-8a61-41c5-a3d4-28835353dc65') = uuid;\nSELECT * FROM activities where crm_configuration_id = 69 ;\n\nSELECT * FROM users WHERE email LIKE '%jiminny_web_sa2@jiminny.com%';\nSELECT * FROM activities WHERE uuid_to_bin('5a150c93-40fc-42ec-b3bd-c1d328e09f6e') = uuid;\nSELECT * FROM opportunities WHERE id = 385;\n\nselect * from participants p\njoin activities a on p.activity_id = a.id\nwhere a.crm_configuration_id = 70\nand (p.lead_id IS NOT NULL or p.contact_id IS NOT NULL);\nSELECT * FROM participants WHERE id = 1013638;\n\nselect * from teams where id = 90;\nselect * from users where team_id = 90;\nselect * from social_accounts where social_accounts.sociable_id IN (1960,1760);\nSELECT * FROM crm_profiles WHERE crm_configuration_id = 71;\nselect * from invitations where team_id = 90;\n\nselect * from crm_configurations where id = 71;\nselect * from accounts where crm_configuration_id = 71 order by id desc;\nselect * from leads where crm_configuration_id = 71 order by id desc;\nselect * from contacts where crm_configuration_id = 71 order by id desc;\nselect * from opportunities where crm_configuration_id = 71 order by id desc;\nselect * from crm_profiles where crm_configuration_id = 71 order by id desc;\nselect * from crm_fields where crm_configuration_id = 71 order by id desc;\nselect * from crm_field_values where crm_field_id = 3341 order by id desc;\nselect * from crm_layouts where crm_configuration_id = 71 order by id desc;\nselect * from stages where crm_configuration_id = 71 order by id desc;\n\nselect * from users order by secondary_email desc;\nselect u.id, u.email, u.status, sa.id, sa.provider_user_id from social_accounts sa\n join users u on sa.sociable_id = u.id\nwhere sa.provider = 'google' and u.email LIKE 'aneliya%';\n\nselect * from failed_jobs order by id desc;\n\nselect * from users where email = 'ben.allwright@learningpeople.co.uk' or secondary_email = 'ben.allwright@learningpeople.co.uk';\n\nselect * from teams;\nSELECT * FROM crm_profiles WHERE crm_configuration_id = 39;\nSELECT * FROM crm_fields WHERE crm_configuration_id = 39 and object_type = 'task';\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 1\nand sa.provider = 'salesforce';\n\n# ************************************************************************************\nSELECT * FROM activities WHERE uuid_to_bin('c38b3895-fd0f-4b1f-9fb2-c170dba137c6') = uuid;\nSELECT * FROM crm_configurations WHERE id = 70;\n\nselect * from teams where id = 1;\nselect * from groups where team_id = 1;\nselect * from users where team_id = 1;\n\nselect o.id, o.name,o.close_date, u.id, u.name, u.group_id, r.id, r.display_name, g.name, g.scope from opportunities o\njoin users u on o.user_id = u.id\njoin groups g on u.group_id = g.id\njoin role_user ru on u.id = ru.user_id\njoin roles r on ru.role_id = r.id\nwhere o.crm_configuration_id = 39 and close_date > '2024-01-01 00:00:00';\n\nselect * from role_user where user_id = 143;\nselect * from roles;\n\nselect * from role_user;\nselect * from groups where id = 9;\nselect * from scope_groups where group_id = 9;\n\n# ************************************************************************************\nselect * from teams where id = 36;\nselect * from crm_configurations;\nSELECT * FROM social_accounts WHERE sociable_id = 121;\n\nhttps://crmsandbox.zoho.com/crm/jiminnyw4/tab/Leads/4776201000005049105\nhttps://crmsandbox.zoho.com/crm/\n\nhttps://crm.zoho.com/crm/org3469620/tab/Leads/230045000229559080\n https://crm.zoho.com/crm/\n org3469620\n\nSELECT * FROM activities WHERE uuid_to_bin('03382d20-c8bc-48e7-a3d4-90b52fa5ceab') = uuid;\n\nselect * from users where email LIKE \"%mobile_automation_%\";\nselect * from social_accounts where sociable_id IN (2228);\nselect * from crm_profiles where user_id IN (2222,2223,2226,2227);\n\nselect * from teams order by id desc;\nSELECT * FROM users WHERE id = 2229;\nSELECT * FROM crm_profiles WHERE user_id = 2229;\nselect * from opportunities where crm_configuration_id = 88;\nselect * from crm_fields where crm_configuration_id = 88;\nselect * from crm_profiles where crm_configuration_id = 88;\n\nSELECT * FROM teams WHERE id = 1;\n\nSELECT * FROM users WHERE id = 143;\nSELECT * FROM users WHERE uuid_to_bin('fde193d3-06a2-4e1a-8895-62b94039215d') = uuid;\nSELECT * FROM teams WHERE uuid_to_bin('73385071-a756-42ae-9c73-8b53f2309467') = uuid;\n\nhttps://app.staging.jiminny.com/ondemand?\n min_duration=1\n &\n only_recorded=1\n &\n user_id%5B%5D=641f1acb-16b8-42d1-8726-df52979dad0e\n &\n sequence_number=2\n\n select * from users where team_id = 1 and email like '%stoyan%'\n\nselect * from coaching_feedbacks;\n\nselect * from teams;\nSELECT * FROM users WHERE team_id = 36;\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 19\nand sa.provider = 'pipedrive';\n\nselect * from users where id = 143;\n\nSELECT * FROM users WHERE uuid_to_bin('73180eeb-33de-4065-977d-ccbe0e6c94fc') = uuid;\nSELECT * FROM teams WHERE uuid_to_bin('73180eeb-33de-4065-977d-ccbe0e6c94fc') = uuid;\nSELECT * FROM activity_shares WHERE uuid_to_bin('73180eeb-33de-4065-977d-ccbe0e6c94fc') = uuid;\n\nselect * from users where team_id = 2;\nselect * from activities where crm_configuration_id = 39\nand activities.scheduled_start_time BETWEEN '2025-04-09 00:00:00' AND '2025-04-09 23:59:59'\nAND user_id = 143\norder by id desc;\n\n# ************************************************************************************\nselect * from teams where id = 142; # 2312, 126\nselect * from team_settings;\nselect * from users where team_id = 142; # 21642\nSELECT * FROM social_accounts WHERE sociable_id = 21642;\nSELECT * FROM crm_profiles cp join users u ON u.id = cp.user_id WHERE team_id = 142;\nselect * from crm_profiles where id IN (93);\nselect * from invitations;\nselect * from team_features where team_id = 1;\n\nSELECT * FROM crm_configurations WHERE id = 126;\nselect * from accounts where crm_configuration_id = 126 order by id desc;\nselect * from leads where crm_configuration_id = 126 order by id desc;\nselect * from contacts where crm_configuration_id = 126 order by id desc;\nselect * from opportunities where crm_configuration_id = 126 order by id desc;\nselect * from crm_profiles where crm_configuration_id = 126 order by id desc;\nselect * from crm_fields where crm_configuration_id = 126 # 11060\n# and type IN ('picklist', 'status')\n# and object_type = 'task'\norder by id desc;\n# 5731,5732,5733\nselect DISTINCT crm_field_id from crm_field_values where crm_field_id IN (11151,12239,12215,12185,12175,12165,12144,12137,12127,12109,12107,12105,12103,12092,12037,12005,12003,11987,11969,11958,11951,11942,11931,11924,11921,11917,11915,11901,11893,11883,11872,11870,11868,11866,11839,11833,11821,11793,11780,11777,11769,11757,11737,11735,11656,11645,11638,11629,11618,11611,11602,11591,11584,11581,11558,11544,11543,11534,11532,11529,11527,11503,11497,11493,11488,11470,11468,11457,11455,11397,11387,11372,11363,11348,11323,11318,11309,11301,11300,11292,11290,11286,11284,11256,11252,11242,11237,11233,11219,11176,11160) order by id desc;\nselect * from crm_layouts where crm_configuration_id = 126 order by id desc;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id in (300,299,298);\nselect * from stages where crm_configuration_id = 126 order by id desc;\nselect * from business_processes where crm_configuration_id = 126 order by id desc;\nselect * from business_process_stages where business_process_id IN (76,75,74,73);\nselect * from playbooks where team_id = 142;\nselect * from playbook_layouts where playbook_id IN (108);\nSELECT * FROM playbook_categories WHERE playbook_id IN (108);\n\nselect * from teams where id = 130;\nSELECT * FROM social_accounts WHERE sociable_id = 2291;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 2\nand sa.provider = 'hubspot';\n\nSELECT * FROM activities\n WHERE crm_configuration_id = 110;\n\nselect * from teams;\nselect * from crm_configurations;\n\nSELECT * FROM activities WHERE id = 628773;\nSELECT * FROM crm_profiles WHERE user_id = 1460;\nSELECT * FROM social_accounts WHERE sociable_id = 2291;\n\nselect * from teams;\nselect ru.*, pr.*, p.* from users u join role_user ru on ru.user_id = u.id\njoin permission_role pr on pr.role_id = ru.role_id\n join permissions p on p.id = pr.permission_id\nwhere team_id = 495 and p.name IN ('dial');\n\nselect * from teams where id = 145;\nselect * from crm_configurations where id = 129;\nselect * from social_accounts where sociable_id = 2317;\nSELECT * FROM activities WHERE uuid_to_bin('8dbab184-a333-4268-ad57-fb41f8d53a9a') = uuid;\n\nselect * from teams where id = 1;\nSELECT * FROM crm_layouts WHERE crm_configuration_id = 39;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 280;\nSELECT * FROM crm_layout_entities WHERE id = 5507;\nSELECT * FROM crm_fields WHERE crm_configuration_id = 39 and object_type IN ('event');\n\nselect * from teams;\nselect * from activities where crm_configuration_id = 14;\n\nSELECT * FROM social_accounts where provider = 'copper';\n\nselect * from activities where id = 628467;\nselect * from participants where activity_id = 628467;\n\nSELECT * FROM contacts WHERE id = 3969;\nSELECT * FROM accounts WHERE id = 177;\n\nSELECT * FROM activities WHERE uuid_to_bin('4eb54c77-cfa3-2bd4-84a7-9ed46a21c988') = uuid;\n\n# ********************* BH\nselect * from teams where id = 36;\nSELECT * FROM crm_configurations WHERE id = 21;\nselect * from activities where crm_configuration_id = 21 and id = 607901;\nselect * from activities where crm_configuration_id = 21;\n\nselect * roles;\nselect * from permissions;\nselect * from permission_role where permission_id = 226;\n\nselect * from migrations order by id desc;\n\n# mercury\n# neptune\n# earth\n\nselect * from teams;\nselect * from teams where id = 19;\nselect * from teams where id = 27;\nselect * from users where team_id = 27;\nSELECT * FROM crm_configurations WHERE id = 42;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 19\nand sa.provider = 'pipedrive';\n\nselect * from activities where id = 631461;\nSELECT * FROM crm_field_values WHERE crm_field_id = 180;\n\nselect * from teams where id = 2;\nSELECT * FROM social_accounts WHERE sociable_id = 89;\n\nSELECT * FROM activities WHERE uuid_to_bin('ba0c029a-bc14-4e17-8603-64174acebcbb') = uuid; # 634273\nselect * from activity_summary_logs where activity_id = 634273;\n\nselect * from sidekick_settings where team_id = 2;\n\nselect * from teams; # 2, 2\nSELECT * FROM crm_configurations WHERE team_id = 2; # 2\nselect * from team_features where team_id = 2;\nselect * from features;\nSELECT * FROM opportunities WHERE crm_configuration_id = 2 and crm_provider_id = '51317301383';\nSELECT * FROM opportunities WHERE crm_configuration_id = 2 order by id desc;\n\nselect * from automated_reports order by id desc;\nselect * from automated_report_results order by id desc;\nselect * from users where team_id = 1 and id IN (7160, 3248);\nselect * from migrations order by id desc;\n\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 1 and sa.provider = 'salesforce';\n\nselect * from teams where id = 1;\nselect * from groups g JOIN playbooks p on g.playbook_id = p.id where g.team_id = 1;\nselect * from groups where id = 565;\nselect * from playbooks where team_id = 1;\nselect * from playbooks where id = 175;\nselect * from playbook_categories where playbook_id = 175;\nselect * from users where team_id = 1;\nselect * from users where id = 7160;\nselect * from crm_profiles where user_id = 7160;\nselect * from features;\nselect\n *\n# id, uuid, type, provider, playbook_category_id, user_id, lead_id, contact_id, account_id, opportunity_id, stage_id,\n# crm_configuration_id, crm_provider_id, transcription_id, status\nfrom activities where crm_configuration_id = 1 and type = 'conference'\n# and crm_provider_id IS NOT NULL\nand provider != 'uploader' and actual_start_time IS NOT NULL\nORDER by id desc;\nselect * from activities where id = 54747783; # 00UO400000pCzojMAC\n\nselect p.id, p.activity_type, pc.id, pc.name\nFROM playbooks p\njoin playbook_categories pc on p.id = pc.playbook_id\nwhere p.team_id = 1 and p.activity_type = 'event';\n\nSELECT * FROM crm_fields WHERE crm_configuration_id = 1 and object_type = 'event';\nSELECT * FROM crm_field_values WHERE crm_field_id = 4;\n\nselect * from crm_layouts cl join playbook_layouts pl on cl.id = pl.layout_id\nwhere crm_configuration_id = 1 and pl.playbook_id = 175;\n\nselect * from teams;\nSELECT r.* FROM automated_reports r\njoin teams t on r.team_id = t.id\nWHERE r.frequency = 'daily'\n and r.status = 1\nAND t.status = 'active'\nAND (r.expires_at >= now() OR r.expires_at IS NULL);\n\nselect * from automated_report_results where report_id IN (18, 33);\n\nselect * from activity_searches where id = 10932;\nselect * from activity_search_filters where activity_search_id = 10932;\nselect * from automated_reports;\nselect * from automated_report_results where report_id IN (34, 35);","role_description":"text entry area","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.088194445,"height":0.027777778},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"102","depth":4,"role_description":"text"},{"role":"AXStaticText","text":"3","depth":4,"role_description":"text"},{"role":"AXStaticText","text":"34","depth":4,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Services\\Kiosk\\AutomatedReports;\n\nuse Carbon\\CarbonImmutable;\nuse Carbon\\CarbonInterface;\nuse Carbon\\Exceptions\\InvalidFormatException;\nuse DateTime;\nuse DateTimeInterface;\nuse DateTimeZone;\nuse Illuminate\\Contracts\\Bus\\Dispatcher as BusDispatcher;\nuse Illuminate\\Database\\Eloquent\\Builder;\nuse Illuminate\\Support\\Carbon;\nuse Illuminate\\Support\\Collection;\nuse Illuminate\\Support\\Facades\\Log;\nuse Illuminate\\Support\\Facades\\Storage;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinition\\InputTypeEnum;\nuse Jiminny\\Component\\AskAnything\\AskAnythingPromptService;\nuse Jiminny\\Component\\AskAnything\\Dtos\\AskAnythingPromptDto;\nuse Jiminny\\Component\\UrlGenerator\\Webhook;\nuse Jiminny\\Contracts\\Repositories\\PlaybookCategoryRepository;\nuse Jiminny\\Contracts\\Repositories\\TeamRepository;\nuse Jiminny\\Contracts\\Repositories\\UserRepository;\nuse Jiminny\\Exceptions\\ApplicationException;\nuse Jiminny\\Exceptions\\InvalidArgumentException;\nuse Jiminny\\Exceptions\\ModelNotFoundException;\nuse Jiminny\\Jobs\\AutomatedReports\\RequestGenerateReportJob;\nuse Jiminny\\Models\\Activity\\Search;\nuse Jiminny\\Models\\AskAnything\\AskAnythingPrompt;\nuse Jiminny\\Models\\AskAnything\\AskAnythingPromptTarget;\nuse Jiminny\\Models\\AutomatedReport;\nuse Jiminny\\Models\\AutomatedReportResult;\nuse Jiminny\\Models\\Contracts\\UserContract;\nuse Jiminny\\Models\\Feature\\FeatureEnum;\nuse Jiminny\\Models\\Team;\nuse Jiminny\\Models\\User;\nuse Jiminny\\Repositories\\AskAnythingRepository;\nuse Jiminny\\Repositories\\AutomatedReportsRepository;\nuse Jiminny\\Repositories\\GroupRepository;\nuse Jiminny\\Repositories\\SearchRepository;\nuse Jiminny\\Repositories\\StageRepository;\nuse Throwable;\n\nclass AutomatedReportsService\n{\n public const string TYPE_LOSS_ANALYSIS = 'loss_analysis';\n public const string TYPE_ASK_JIMINNY = 'ask_jiminny';\n\n /**\n * Standard report types (used by kiosk for existing automated reports).\n */\n // @TODO this will add filter, however if we need to control feature by FF we need conditional logic\n public const array TYPES = [\n ['id' => 'exec_summary', 'name' => 'Exec Summary'],\n ['id' => 'coaching_profiles', 'name' => 'Coaching Profiles'],\n ['id' => 'product_feedback', 'name' => 'Product Feedback'],\n ['id' => self::TYPE_LOSS_ANALYSIS, 'name' => 'Loss Analysis'],\n// ['id' => 'questions', 'name' => 'Questions'],\n// ['id' => 'statistical_quant', 'name' => 'Statistical Quantitative'],\n ];\n\n public const array ALL_TYPES = [\n ...self::TYPES,\n ['id' => self::TYPE_ASK_JIMINNY, 'name' => 'Ask Jiminny'],\n ];\n\n public const string FREQUENCY_DAILY = 'daily';\n public const string FREQUENCY_WEEKLY = 'weekly';\n public const string FREQUENCY_MONTHLY = 'monthly';\n public const string FREQUENCY_QUARTERLY = 'quarterly';\n public const string FREQUENCY_ONE_OFF = 'one_off';\n\n /**\n * Frequencies for standard (non-Ask Jiminny) reports.\n */\n public const array FREQUENCIES = [\n ['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],\n ['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],\n ['id' => self::FREQUENCY_QUARTERLY, 'name' => 'Quarterly'],\n ['id' => self::FREQUENCY_ONE_OFF, 'name' => 'One-off'],\n ];\n\n /**\n * Frequencies for Ask Jiminny reports.\n */\n public const array ASK_JIMINNY_FREQUENCIES = [\n ['id' => self::FREQUENCY_DAILY, 'name' => 'Daily'],\n ['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],\n ['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],\n ];\n\n public const string MEDIA_TYPE_PDF = 'pdf';\n public const string MEDIA_TYPE_PODCAST = 'podcast';\n public const array MEDIA_TYPES = [self::MEDIA_TYPE_PDF, self::MEDIA_TYPE_PODCAST];\n public const array MEDIA_TYPE_OBJECT_PDF = ['id' => self::MEDIA_TYPE_PDF, 'name' => 'PDF'];\n public const array MEDIA_TYPE_OBJECT_PODCAST = ['id' => self::MEDIA_TYPE_PODCAST, 'name' => 'Podcast'];\n public const array MEDIA_TYPE_OBJECTS = [self::MEDIA_TYPE_OBJECT_PDF, self::MEDIA_TYPE_OBJECT_PODCAST];\n\n public const array CALL_TYPE_CONFERENCE = ['id' => 'conference', 'name' => 'Conference'];\n public const array CALL_TYPE_DIALER = ['id' => 'dialer', 'name' => 'Dialer'];\n public const int SENT_REPORT_AT_HOURS = 5;\n public const string PDF_KEY = 'pdf';\n public const string AUDIO_KEY = 'audio';\n\n private const array ALL_FREQUENCIES = [\n ['id' => self::FREQUENCY_DAILY, 'name' => 'Daily'],\n ['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],\n ['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],\n ['id' => self::FREQUENCY_QUARTERLY, 'name' => 'Quarterly'],\n ['id' => self::FREQUENCY_ONE_OFF, 'name' => 'One-off'],\n ];\n private const string S3_DIR = 'reports';\n private const array FILE_EXTENSIONS_VARIANTS = ['html', 'MD', 'pdf'];\n private const array FILE_PODCAST_EXTENSIONS_VARIANTS = ['json', 'mp3', 'ssml'];\n\n public function __construct(\n private readonly TeamRepository $teamRepository,\n private readonly GroupRepository $groupRepository,\n private readonly UserRepository $userRepository,\n private readonly StageRepository $stageRepository,\n private readonly DealStagesService $dealStagesService,\n private readonly RecipientsService $recipientsService,\n private readonly AutomatedReportsRepository $automatedReportsRepository,\n private readonly Webhook $webhookService,\n private readonly BusDispatcher $dispatcher,\n private readonly ActivityTypeService $activityTypeService,\n private readonly PlaybookCategoryRepository $playbookCategoryRepository,\n private readonly AskAnythingPromptService $askAnythingPromptService,\n private readonly SearchRepository $activitySearchRepository,\n private readonly AskAnythingRepository $askAnythingRepository,\n ) {\n }\n\n public static function getTypes(): array\n {\n $types = self::TYPES;\n\n return array_map(static function ($type) {\n return $type['id'];\n }, $types);\n }\n\n public static function getCallTypes(): array\n {\n return array_map(static function ($callType) {\n return $callType['id'];\n }, [self::CALL_TYPE_CONFERENCE, self::CALL_TYPE_DIALER]);\n }\n\n public static function getFrequencies(): array\n {\n return array_map(static function ($frequency) {\n return $frequency['id'];\n }, self::FREQUENCIES);\n }\n\n // front-facing structure\n public function getReportEnabledFieldData(bool $value = false): array\n {\n return [\n 'id' => 'report_enabled',\n 'label' => '',\n 'inputType' => InputTypeEnum::TOGGLE,\n 'value' => $value,\n ];\n }\n\n // Organizations = Teams\n public function getOrganizationFieldData(?string $value = null, bool $shortVersion = false): array\n {\n $options = $this->getTeams();\n\n if ($shortVersion) {\n return [\n 'id' => 'organization',\n 'label' => 'Organization',\n 'options' => $options,\n ];\n }\n\n return [\n 'id' => 'organization',\n 'label' => 'Organization',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => $options,\n 'value' => $value,\n 'dependencies' => [\n 'teams',\n 'deal_stage_at_call',\n 'current_deal_stage',\n 'recipients',\n ActivityTypeService::PLAYBOOK_CATEGORIES_KEY,\n ],\n 'dependsOn' => [],\n ];\n }\n\n // Teams = Groups\n public function getTeamFieldData(array $options = [], array $value = [], bool $shortVersion = false): array\n {\n if ($shortVersion) {\n return [\n 'id' => 'teams',\n 'label' => 'Team',\n 'options' => $options,\n ];\n }\n\n return [\n 'id' => 'teams',\n 'label' => 'Team',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'required' => false,\n 'placeholder' => 'Select',\n 'options' => $options,\n 'value' => $value, // value should be an array of objects {id, name}\n 'dependencies' => [ActivityTypeService::PLAYBOOK_CATEGORIES_KEY],\n 'dependsOn' => [],\n ];\n }\n\n public function getReportTypeFieldData(?string $value = null, bool $shortVersion = false, ?Team $team = null): array\n {\n $types = [];\n if ($team instanceof Team) {\n if ($team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {\n $types = self::TYPES;\n }\n if ($team->hasFeature(FeatureEnum::ASK_JIMINNY_REPORTS)) {\n $types[] = ['id' => self::TYPE_ASK_JIMINNY, 'name' => 'Ask Jiminny'];\n }\n } else {\n $types = self::TYPES;\n }\n\n if ($shortVersion) {\n return [\n 'id' => 'report_type',\n 'label' => 'Report Type',\n 'options' => $types,\n ];\n }\n\n return [\n 'id' => 'report_type',\n 'label' => 'Report Type',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => $types,\n 'value' => $value,\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getFrequencyFieldData(?string $value = null): array\n {\n return [\n 'id' => 'frequency',\n 'label' => 'Frequency',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => self::FREQUENCIES,\n 'value' => $value,\n 'dependencies' => ['period'],\n 'dependsOn' => [],\n ];\n }\n\n public function getPeriodFieldData(?string $valueStartDate = null, ?string $valueEndDate = null): array\n {\n return [\n 'id' => 'period',\n 'label' => 'Select one-off period',\n 'inputType' => InputTypeEnum::DATE_RANGE,\n 'required' => true,\n 'placeholder' => 'Select',\n 'value' => ['startDate' => $valueStartDate, 'endDate' => $valueEndDate],\n 'queryParams' => [\n 'startDate' => 'start_date_period',\n 'endDate' => 'end_date_period',\n ],\n 'dependencies' => [],\n 'dependsOn' => ['frequency'],\n ];\n }\n\n public function getActivityTypesFieldData(?Team $team = null, array $value = [], array $teamsFilter = []): array\n {\n return $this->activityTypeService->getActivityTypeFieldData(team: $team, value: $value, groupIds: $teamsFilter);\n }\n\n public function getDealStageAtCallFieldData(?Team $team = null, array $value = []): array\n {\n return $this->dealStagesService->getDealStageAtCallFieldData(team: $team, value: $value);\n }\n\n public function getCurrentDealStageFieldData(?Team $team = null, array $value = []): array\n {\n return $this->dealStagesService->getCurrentDealStageFieldData(team: $team, value: $value);\n }\n\n public function getDealValueFieldData(?int $valueMin = null, ?int $valueMax = null): array\n {\n return [\n 'id' => 'deal_value',\n 'label' => 'Deal Value',\n 'inputType' => InputTypeEnum::INTEGER_RANGE,\n 'required' => false,\n 'value' => ['min' => $valueMin, 'max' => $valueMax],\n 'queryParams' => [\n 'min' => 'min_deal_value',\n 'max' => 'max_deal_value',\n ],\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getCallTypeFieldData(bool $conferenceOn = false, bool $dialerOn = false): array\n {\n $value = [];\n $conferenceOn && $value[] = self::CALL_TYPE_CONFERENCE;\n $dialerOn && $value[] = self::CALL_TYPE_DIALER;\n\n return [\n 'id' => 'call_type',\n 'label' => 'Call Type',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'required' => true,\n 'options' => [\n self::CALL_TYPE_CONFERENCE,\n self::CALL_TYPE_DIALER,\n ],\n 'value' => $value,\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getMediaTypeFieldData(?AutomatedReport $report = null): array\n {\n $value = [];\n\n if ($report) {\n $value = $this->transformMediaTypes($report);\n }\n\n return [\n 'id' => 'media_types',\n 'label' => 'Export as',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'required' => true,\n 'options' => self::MEDIA_TYPE_OBJECTS,\n 'value' => $value,\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getCallDurationFieldData(?int $valueMin = null, ?int $valueMax = null): array\n {\n return [\n 'id' => 'call_duration',\n 'label' => 'Call Duration',\n 'inputType' => InputTypeEnum::INTEGER_RANGE,\n 'required' => false,\n 'value' => ['min' => $valueMin, 'max' => $valueMax],\n 'queryParams' => [\n 'min' => 'min_call_duration',\n 'max' => 'max_call_duration',\n ],\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getRecipientsFieldData(?Team $team = null, array $value = []): array\n {\n return $this->recipientsService->getRecipientsFieldData(team: $team, value: $value);\n }\n\n public function getJiminnyRecipientsFieldData(array $value = []): array\n {\n return $this->recipientsService->getJiminnyRecipientsFieldData($value);\n }\n\n public function getAdditionalPromptInputFieldData(?string $value = null): array\n {\n return [\n 'id' => 'additional_prompt_input',\n 'label' => 'Special requirements',\n 'inputType' => InputTypeEnum::TEXTAREA,\n 'required' => false,\n 'placeholder' => 'What should be the focus of the report?',\n 'value' => $value,\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getCustomReportNameFieldData(?string $value = null): array\n {\n return [\n 'id' => 'custom_name',\n 'label' => 'Custom report name',\n 'inputType' => InputTypeEnum::TEXT,\n 'required' => false,\n 'placeholder' => 'Enter custom name',\n 'value' => $value,\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n // data providers\n public function getTeams(): array\n {\n $teams = $this->teamRepository->getTeamsForKiosk(status: Team::STATUS_ACTIVE);\n\n $teamData = [];\n foreach ($teams as $team) {\n if (! $team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {\n continue;\n }\n\n $teamData[] = $this->transformTeam($team);\n }\n\n return $teamData;\n }\n\n public function getTeamGroups(string $teamUuid): array\n {\n $data = [];\n $team = $this->getTeam($teamUuid);\n\n if ($team !== null) {\n $groups = $team->groups()->get();\n\n foreach ($groups as $group) {\n $data[] = [\n 'id' => $group->getUuid(),\n 'name' => $group->getName(),\n ];\n }\n }\n\n return $data;\n }\n\n public function getTeamsGroupsOptions(array $filterTeamUuids = []): array\n {\n $data = [];\n $teams = $this->getTeams();\n\n foreach ($teams as $team) {\n if (! empty($filterTeamUuids) && ! in_array($team['id'], $filterTeamUuids, true)) {\n continue;\n }\n\n $data[] = [\n 'label' => $team['name'],\n 'groups' => $this->getTeamGroups($team['id']),\n ];\n }\n\n return $data;\n }\n\n public function getTeam(string $teamUuid): ?Team\n {\n return $this->teamRepository->idOrUuid($teamUuid);\n }\n\n public function getTeamById(int $teamId): ?Team\n {\n return $this->teamRepository->find($teamId);\n }\n\n public function getGroupsUuids(AutomatedReport $report): array\n {\n $uuids = [];\n $reportGroups = $report->getGroups();\n foreach ($reportGroups as $groupId) {\n if ($group = $this->groupRepository->find($groupId)) {\n $uuids[] = $group->getUuid();\n }\n }\n\n return $uuids;\n }\n\n public function getPlaybookCategoriesUuids(AutomatedReport $report): array\n {\n $uuids = [];\n $playbookCategories = $report->getPlaybookCategories();\n foreach ($playbookCategories as $id) {\n if ($category = $this->playbookCategoryRepository->find($id)) {\n $uuids[] = $category->getUuid();\n }\n }\n\n return $uuids;\n }\n\n public function getDealAtCallStagesUuids(AutomatedReport $report): array\n {\n $uuids = [];\n $reportStages = $report->getDealAtCallStages();\n foreach ($reportStages as $id) {\n if ($stage = $this->stageRepository->find($id)) {\n $uuids[] = $stage->getUuid();\n }\n }\n\n return $uuids;\n }\n\n public function getCurrentDealStagesUuids(AutomatedReport $report): array\n {\n $uuids = [];\n $reportStages = $report->getCurrentDealStages();\n foreach ($reportStages as $id) {\n if ($stage = $this->stageRepository->find($id)) {\n $uuids[] = $stage->getUuid();\n }\n }\n\n return $uuids;\n }\n\n public function getUsersUuids(AutomatedReport $report): array\n {\n return $this->extractUserUuids($report->getRecipients());\n }\n\n public function getJiminnyUsersUuids(AutomatedReport $report): array\n {\n return $this->extractUserUuids($report->getJiminnyRecipients());\n }\n\n /**\n * @param array<string, mixed> $recipients\n */\n private function extractUserUuids(array $recipients): array\n {\n $userIds = $recipients['users'] ?? [];\n\n return collect($userIds)\n ->map(fn ($id) => $this->userRepository->find((int) $id))\n ->filter()\n ->map(fn (UserContract $user) => $user->getUuid())\n ->values()\n ->all();\n }\n\n // get mail data\n public function getRecipientUsers(AutomatedReport $report): array\n {\n return $this->buildRecipientUsers($report->getRecipients());\n }\n\n private function getJiminnyRecipientUsers(AutomatedReport $report): array\n {\n return $this->buildRecipientUsers($report->getJiminnyRecipients());\n }\n\n /**\n * @param array<string, mixed> $recipients\n */\n private function buildRecipientUsers(array $recipients): array\n {\n $userIds = $recipients['users'] ?? [];\n\n return collect($userIds)\n ->map(fn ($id) => $this->userRepository->find((int) $id))\n ->filter()\n ->map(fn (UserContract $user) => [\n 'email' => $user->getEmailAddress(),\n 'name' => $user->getName(),\n 'timezone' => $user->getTimezone()->getName(),\n ])\n ->values()\n ->all();\n }\n\n public function getValidRecipientUsers(AutomatedReport $report, bool $includeJiminny = false): array\n {\n if ($report->isAskJiminnyReport()) {\n $recipients = $this->resolveAskJiminnyRecipients($report);\n } else {\n $recipients = $this->getRecipientUsers($report);\n if ($includeJiminny) {\n $recipients = array_merge($recipients, $this->getJiminnyRecipientUsers($report));\n }\n }\n\n $emails = [];\n\n return array_values(array_filter(\n $recipients,\n static function ($recipient) use (&$emails) {\n if (empty($recipient['email']) || in_array($recipient['email'], $emails, true)) {\n return false;\n }\n $emails[] = $recipient['email'];\n\n return true;\n }\n ));\n }\n\n private function resolveAskJiminnyRecipients(AutomatedReport $report): array\n {\n $recipients = [];\n\n $creator = $report->getCreator();\n if ($creator !== null) {\n $recipients[] = [\n 'email' => $creator->getEmailAddress(),\n 'name' => $creator->getName(),\n 'timezone' => $creator->getTimezone()->getName(),\n ];\n }\n\n return array_merge(\n $recipients,\n $this->buildRecipientUsers($report->getRecipients()),\n $this->getGroupRecipientUsers($report),\n );\n }\n\n private function getGroupRecipientUsers(AutomatedReport $report): array\n {\n $users = [];\n foreach ($report->getGroups() as $groupId) {\n $group = $this->groupRepository->find($groupId);\n if ($group === null) {\n continue;\n }\n foreach ($group->getMembers() as $member) {\n $users[] = [\n 'email' => $member->getEmailAddress(),\n 'name' => $member->getName(),\n 'timezone' => $member->getTimezone()->getName(),\n ];\n }\n }\n\n return $users;\n }\n\n public function getReportTypeName(AutomatedReportResult $report): string\n {\n $type = $report->getReport()->getType();\n\n $getType = $this->transformReportType($type);\n\n return $getType['name'];\n }\n\n public function getReportPeriodName(AutomatedReportResult $report): string\n {\n $from = $report->getFromDate();\n $to = $report->getToDate();\n $frequency = $report->getReport()->getFrequency();\n\n if ($from === null || $to === null) {\n if (! $report->getReport()->isAskJiminnyReport()) {\n $invalidPeriod = $from === null ? 'from' : 'to';\n\n throw new ApplicationException('Report period is invalid: ' . $invalidPeriod);\n }\n\n $period = $this->calculateFromAndToDatePeriod($frequency);\n $from = $period['fromDate'];\n $to = $period['toDate'];\n }\n\n return $this->formatReportPeriodName($frequency, $from, $to);\n }\n\n private function formatReportPeriodName(string $frequency, Carbon $from, Carbon $to): string\n {\n $fromYear = $from->format('Y');\n $toYear = $to->format('Y');\n $differentYears = $fromYear !== $toYear;\n\n switch ($frequency) {\n case self::FREQUENCY_DAILY:\n return $from->format('j M Y');\n\n case self::FREQUENCY_QUARTERLY:\n // 'Jan-Mar 2025' or 'Nov 2024-Jan 2025' if years differ\n $startMonth = $from->format('M');\n $endMonth = $to->copy()->subMonth();\n $endMonthName = $endMonth->format('M');\n $endMonthYear = $endMonth->format('Y');\n\n if ($differentYears) {\n return \"{$startMonth} {$fromYear} - {$endMonthName} {$endMonthYear}\";\n }\n\n return \"{$startMonth} - {$endMonthName} {$toYear}\";\n\n case self::FREQUENCY_MONTHLY:\n // 'May 2025' - monthly reports are always within the same year\n return $from->format('M Y');\n\n case self::FREQUENCY_WEEKLY:\n // '4 - 8 Aug 2025', '27 Oct - 3 Nov 2025', or '28 Dec 2024 - 3 Jan 2025' if years differ\n $startDay = $from->format('j');\n $endDay = $to->format('j');\n $startMonth = $from->format('M');\n $endMonth = $to->format('M');\n\n if ($differentYears) {\n return \"{$startDay} {$startMonth} {$fromYear} - {$endDay} {$endMonth} {$toYear}\";\n }\n\n if ($startMonth !== $endMonth) {\n return \"{$startDay} {$startMonth} - {$endDay} {$endMonth} {$toYear}\";\n }\n\n return \"{$startDay} - {$endDay} {$endMonth} {$toYear}\";\n\n case self::FREQUENCY_ONE_OFF:\n // '2 May-31 May 2025' or '15 Dec 2024-15 Jan 2025' if years differ\n $startDay = $from->format('j');\n $startMonth = $from->format('M');\n $endDay = $to->format('j');\n $endMonth = $to->format('M');\n\n // If same month and year, use a format like '2-31 May 2025'\n if ($startMonth === $endMonth && ! $differentYears) {\n return \"{$startDay} - {$endDay} {$startMonth} {$toYear}\";\n }\n\n // If different years, include both years\n if ($differentYears) {\n return \"{$startDay} {$startMonth} {$fromYear} - {$endDay} {$endMonth} {$toYear}\";\n }\n\n // Same year but different months\n return \"{$startDay} {$startMonth} - {$endDay} {$endMonth} {$toYear}\";\n\n default:\n // Default format for unknown frequencies\n return $from->format('j M Y') . ' - ' . $to->format('j M Y');\n }\n }\n\n public function getReportTeamsName(AutomatedReportResult $report): string\n {\n $groups = $report->getGroups();\n\n if (empty($groups)) {\n return 'All';\n }\n\n // Get group names from repository\n $groupNames = [];\n foreach ($groups as $groupId) {\n $group = $this->groupRepository->find($groupId);\n if ($group) {\n $groupNames[] = $group->getName();\n }\n }\n\n if (count($groupNames) === 1) {\n // Single team format\n $teamsName = $groupNames[0];\n } else {\n // Multiple teams format\n $teamsName = implode(', ', $groupNames);\n }\n\n return $teamsName;\n }\n\n public function getReportFileName(AutomatedReportResult $report): string\n {\n $customName = $report->getReport()->getCustomName();\n $periodName = $this->getReportPeriodName($report);\n $filenameSuffix = $this->getFilenameSuffix($report);\n\n if ($customName) {\n if ($filenameSuffix) {\n $customName .= \" {$filenameSuffix}\";\n }\n\n return $this->sanitizeFileName(\"{$customName} - {$periodName}\");\n }\n\n $baseName = $this->getReportTypeName($report);\n\n if ($filenameSuffix) {\n $baseName .= \" {$filenameSuffix}\";\n }\n\n return $this->sanitizeFileName(\"{$baseName} - {$periodName} - {$this->getReportTeamsName($report)}\");\n }\n\n public function getReportFileNameWithExtension(AutomatedReportResult $result): string\n {\n $extension = $this->getMediaTypeMetadata($result)['extension'];\n\n return $this->getReportFileName($result) . '.' . $extension;\n }\n\n public function sanitizeFileName(string $fileName): string\n {\n return str_replace(['/', '\\\\'], '-', $fileName);\n }\n\n public function isUserRecipientOfReport(User $user, AutomatedReport $report): bool\n {\n $recipients = array_map('intval', $report->getRecipients()['users'] ?? []);\n\n return in_array($user->getId(), $recipients);\n }\n\n public function transformReportResults(Collection $automatedReportResults): array\n {\n $data = [];\n foreach ($automatedReportResults as $automatedReportResult) {\n /** @var AutomatedReportResult $automatedReportResult */\n\n $report = $automatedReportResult->getReport();\n\n $createdBy = $report->getCreator();\n $creator = [\n 'id' => $createdBy?->getUuid(),\n 'name' => $createdBy?->getName(),\n 'email' => $createdBy?->getEmailAddress(),\n 'photoUrl' => $createdBy?->getPhotoUrl(),\n ];\n\n $data[] = [\n 'id' => $automatedReportResult->getUuid(),\n 'name' => $automatedReportResult->getName(),\n 'frequency' => $this->transformFrequency($report->getFrequency()),\n 'recipients' => [\n ...array_values($this->transformGroups(team: $report->getTeam(), groupsIds: $report->getGroups())),\n ...array_values($this->transformRecipients($report->getRecipients())),\n ],\n 'report_type' => $this->transformReportType($report->getType()),\n 'media_type' => $automatedReportResult->getMediaType(),\n 'downloadUrl' => $this->generateReportResultDownloadUrl($automatedReportResult),\n 'viewUrl' => $this->generateReportResultViewUrl($automatedReportResult),\n 'generated_at' => $automatedReportResult->getGeneratedAt()?->toIso8601String(),\n 'creator' => $creator,\n ];\n }\n\n return $data;\n }\n\n public function hasCallTypeConference(AutomatedReport $report): bool\n {\n return in_array(self::CALL_TYPE_CONFERENCE['id'], $report->getCallTypes(), true);\n }\n\n public function hasCallTypeDialer(AutomatedReport $report): bool\n {\n return in_array(self::CALL_TYPE_DIALER['id'], $report->getCallTypes(), true);\n }\n\n // transformers\n private function transformTeam(Team $team): array\n {\n if (! $team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {\n return [];\n }\n\n return [\n 'id' => $team->getUuid(),\n 'name' => $team->getName(),\n ];\n }\n\n private function transformReportFullView(AutomatedReport $report): array\n {\n $base = $this->transformReportBase($report);\n\n return $report->getType() === self::TYPE_ASK_JIMINNY\n ? $base + $this->transformAskJiminnyFields($report)\n : $base + $this->transformStandardReportFields($report);\n }\n\n private function transformReportBase(AutomatedReport $report): array\n {\n return [\n 'id' => $report->getUuid(),\n 'organization' => $this->transformOrganization(team: $report->getTeam()),\n 'report_type' => $this->transformReportType($report->getType()),\n 'frequency' => $this->transformFrequency($report->getFrequency()),\n ];\n }\n\n private function transformStandardReportFields(AutomatedReport $report): array\n {\n $team = $report->getTeam();\n\n return [\n 'report_enabled' => $report->getStatus(),\n 'start_date_period' => $report->getFrom()?->format('Y-m-d H:i:s'),\n 'end_date_period' => $report->getTo()?->format('Y-m-d H:i:s'),\n 'deal_value_min' => $report->getDealValueMin(),\n 'deal_value_max' => $report->getDealValueMax(),\n 'call_types' => $this->transformCallType($report->getCallTypes()),\n 'media_types' => $this->transformMediaTypes($report),\n 'call_duration_min' => $this->transformDurationToMinutes($report->getCallDurationMin()),\n 'call_duration_max' => $this->transformDurationToMinutes($report->getCallDurationMax()),\n 'teams' => $this->transformGroups(team: $team, groupsIds: $report->getGroups()),\n 'deal_at_call_stages' => $this->transformStages(team: $team, stagesIds: $report->getDealAtCallStages()),\n 'current_deal_stages' => $this->transformStages(team: $team, stagesIds: $report->getCurrentDealStages()),\n 'recipients' => $this->transformRecipients($report->getRecipients()),\n 'created_by' => $this->transformCreator($report->getCreator()),\n 'additional_prompt_input' => $report->getAdditionalPromptInput(),\n 'custom_name' => $report->getCustomName(),\n 'created_at' => $report->getCreatedAt()->format('Y-m-d H:i:s'),\n 'updated_at' => $report->getUpdatedAt()->format('Y-m-d H:i:s'),\n 'deleted_at' => $report->getDeletedAt()?->format('Y-m-d H:i:s'),\n ];\n }\n\n private function transformAskJiminnyFields(AutomatedReport $report): array\n {\n $team = $report->getTeam();\n $creatorId = $report->getAttribute('created_by');\n $explicitUserIds = array_values(array_filter(\n $report->getRecipients()['users'] ?? [],\n static fn ($id) => $id !== $creatorId\n ));\n\n return [\n 'report_name' => $report->getCustomName(),\n 'enabled' => $report->getStatus(),\n 'share_teams' => $this->transformGroups(team: $team, groupsIds: $report->getGroups()),\n 'share_users' => $this->transformRecipients(['users' => $explicitUserIds]),\n 'saved_search' => $this->transformSafeSearch($report->getSavedSearch()),\n 'ask_jiminny_prompt' => $this->transformAskJiminnyPrompt($report->getAskAnythingPrompt()),\n 'expires_on' => $report->getExpiresAt()?->format('Y-m-d'),\n ];\n }\n\n private function transformOrganization(?Team $team): array\n {\n return [\n 'id' => $team?->getUuid(),\n 'name' => $team?->getName(),\n ];\n }\n\n private function transformReportType(string $type): array\n {\n foreach (self::ALL_TYPES as $typeItem) {\n if ($typeItem['id'] === $type) {\n return $typeItem;\n }\n }\n\n return [];\n }\n\n private function transformCallType(array $types): array\n {\n $result = [];\n $callTypes = [self::CALL_TYPE_CONFERENCE, self::CALL_TYPE_DIALER];\n\n foreach ($types as $type) {\n foreach ($callTypes as $callTypeItem) {\n if ($callTypeItem['id'] === $type) {\n $result[] = $callTypeItem;\n\n break;\n }\n }\n }\n\n return $result;\n }\n\n private function transformMediaTypes(AutomatedReport $report): array\n {\n $values = [];\n\n foreach ($report->getMediaTypes() as $mediaType) {\n if (! in_array($mediaType, self::MEDIA_TYPES, true)) {\n continue;\n }\n\n $values[] = match ($mediaType) {\n self::MEDIA_TYPE_PDF => self::MEDIA_TYPE_OBJECT_PDF,\n self::MEDIA_TYPE_PODCAST => self::MEDIA_TYPE_OBJECT_PODCAST,\n };\n }\n\n return $values;\n }\n\n private function transformFrequency(string $frequency): array\n {\n foreach (self::ALL_FREQUENCIES as $frequencyItem) {\n if ($frequencyItem['id'] === $frequency) {\n return $frequencyItem;\n }\n }\n\n return [];\n }\n\n public function transformDurationToMinutes(?int $duration): ?int\n {\n if (! $duration) {\n return null;\n }\n\n return (int) ($duration / 60);\n }\n\n private function transformGroups(?Team $team, array $groupsIds): array\n {\n if (empty($groupsIds) || ! $team) {\n return [];\n }\n\n $data = [];\n foreach ($groupsIds as $groupId) {\n $group = $team->groups()->where('id', $groupId)->first();\n\n if ($group) {\n $data[] = [\n 'id' => $group->getUuid(),\n 'name' => $group->getName(),\n 'photoUrl' => $group->getPhotoUrl(),\n ];\n }\n }\n\n return $data;\n }\n\n private function transformStages(?Team $team, array $stagesIds): array\n {\n if (empty($stagesIds) || ! $team) {\n return [];\n }\n\n $data = [];\n foreach ($stagesIds as $stageId) {\n $stage = $team->stages()->where('id', $stageId)->first();\n\n if ($stage) {\n $data[] = [\n 'id' => $stage->getUuid(),\n 'name' => $stage->getName(),\n ];\n }\n }\n\n return $data;\n }\n\n private function transformRecipients(array $recipients): array\n {\n $users = [];\n foreach ($recipients['users'] ?? [] as $userId) {\n $users[] = $this->transformUser($userId);\n }\n\n return $users;\n }\n\n private function transformCreator(?User $user): ?array\n {\n if ($user === null) {\n return null;\n }\n\n return $this->transformUser($user->getId());\n }\n\n private function transformAskJiminnyPrompt(?AskAnythingPrompt $prompt): ?array\n {\n if ($prompt === null) {\n return null;\n }\n\n return [\n 'id' => $prompt->getUuid(),\n 'name' => $prompt->getTitle(),\n ];\n }\n\n private function transformSafeSearch(?Search $search): ?array\n {\n if ($search === null) {\n return null;\n }\n\n return [\n 'id' => $search->getUuid(),\n 'name' => $search->getName(),\n ];\n }\n\n private function transformUser(int $userId): array\n {\n /* @var ?User $user */\n $user = $this->userRepository->find($userId);\n\n return [\n 'id' => $user?->getUuid(),\n 'name' => $user?->getName(),\n 'email' => $user?->getEmailAddress(),\n 'photoUrl' => $user?->getPhotoUrl(),\n ];\n }\n\n public function create(array $data): array\n {\n $validatedData = $this->validateAndTransformData($data);\n $validatedData['created_by'] = auth()->id();\n\n $automatedReport = $this->automatedReportsRepository->create($validatedData);\n\n $this->generateOneOffReport($automatedReport);\n\n return $this->transformReportFullView($automatedReport);\n }\n\n public function update(string $uuid, array $data): array\n {\n $validatedData = $this->validateAndTransformData($data);\n $report = $this->automatedReportsRepository->findByUuid($uuid);\n\n if (! $report) {\n throw new InvalidArgumentException('Report not found');\n }\n\n $oldCustomName = $report->getCustomName();\n\n $automatedReport = $this->automatedReportsRepository->update($report, $validatedData);\n\n if ($oldCustomName !== $automatedReport->getCustomName()) {\n $this->updateResultNames($automatedReport);\n }\n\n $this->generateOneOffReport($automatedReport);\n\n return $this->transformReportFullView($automatedReport);\n }\n\n /**\n * Create an Ask Jiminny report.\n */\n public function createAskJiminnyReport(array $data, User $creator): array\n {\n $validatedData = $this->validateAskJiminnyReportData($data, $creator);\n $validatedData['created_by'] = $creator->getId();\n\n $automatedReport = $this->automatedReportsRepository->create($validatedData);\n\n return $this->transformReportFullView($automatedReport);\n }\n\n /**\n * Update an Ask Jiminny report.\n */\n public function updateAskJiminnyReport(AutomatedReport $report, array $data, User $user): array\n {\n if (! $report->isAskJiminnyReport()) {\n throw new InvalidArgumentException('Report is not an Ask Jiminny report');\n }\n\n $validatedData = $this->validateAskJiminnyReportData($data, $user);\n\n $oldCustomName = $report->getCustomName();\n\n $automatedReport = $this->automatedReportsRepository->update($report, $validatedData);\n\n if ($oldCustomName !== $automatedReport->getCustomName()) {\n $this->updateResultNames($automatedReport);\n }\n\n return $this->transformReportFullView($automatedReport);\n }\n\n public function updateAskJiminnyReportStatus(AutomatedReport $report, bool $status): array\n {\n $this->automatedReportsRepository->update($report, ['status' => $status]);\n\n return $this->transformReportFullView($report->fresh());\n }\n\n /**\n * Validate and transform data for Ask Jiminny reports.\n */\n private function validateAskJiminnyReportData(array $data, User $user): array\n {\n // Validate name\n $name = trim($data['report_name'] ?? '');\n if (empty($name)) {\n throw new InvalidArgumentException('Report name is required');\n }\n if (mb_strlen($name) > 50) {\n throw new InvalidArgumentException('Report name must be 50 characters or less');\n }\n\n // Validate frequency (only daily, weekly, monthly for Ask Jiminny)\n $frequency = $data['frequency'] ?? null;\n $askJiminnyFrequencies = [self::FREQUENCY_DAILY, self::FREQUENCY_WEEKLY, self::FREQUENCY_MONTHLY];\n if (! in_array($frequency, $askJiminnyFrequencies, true)) {\n throw new InvalidArgumentException('Frequency must be daily, weekly, or monthly');\n }\n\n // Validate expiration date\n $expiresAt = $data['expires_on'] ?? null;\n if (empty($expiresAt)) {\n throw new InvalidArgumentException('Expiration date is required');\n }\n\n try {\n $expiresAtDate = Carbon::parse($expiresAt);\n } catch (InvalidFormatException $e) {\n throw new InvalidArgumentException('Expiration date format is invalid');\n }\n $maxExpiration = Carbon::now()->addYear();\n if ($expiresAtDate->gt($maxExpiration)) {\n throw new InvalidArgumentException('Expiration date cannot be more than 1 year from now');\n }\n if ($expiresAtDate->isPast()) {\n throw new InvalidArgumentException('Expiration date cannot be in the past');\n }\n\n // Validate saved search\n $activitySearchId = $data['saved_search'] ?? null;\n if (empty($activitySearchId)) {\n throw new InvalidArgumentException('Saved search is required');\n }\n $savedSearch = $this->activitySearchRepository->findByUuidAndUser($activitySearchId, $user);\n if (! $savedSearch) {\n throw new InvalidArgumentException('Saved search not found or does not belong to you');\n }\n\n // Validate saved prompt\n $askAnythingPromptId = $data['ask_jiminny_prompt'] ?? null;\n if (empty($askAnythingPromptId)) {\n throw new InvalidArgumentException('Ask Jiminny prompt is required');\n }\n $prompt = $this->askAnythingRepository->getPromptByUuid($askAnythingPromptId);\n if (! $prompt) {\n throw new InvalidArgumentException('Ask Jiminny prompt not found');\n }\n\n // Validate status\n $status = $data['enabled'] ?? false;\n\n $recipientUserIds = [$user->getId()];\n\n if (! empty($data['share_users'])) {\n $sharedUserIds = $this->validateAndGetUserIdsByTeam(\n $user->team,\n (array) $data['share_users']\n );\n $recipientUserIds = array_merge($recipientUserIds, $sharedUserIds);\n }\n\n $sharedGroupIds = [];\n if (! empty($data['share_teams'])) {\n $sharedGroupIds = $this->validateAndGetGroupIds($user->team, (array) $data['share_teams']);\n }\n\n $recipientUserIds = array_values(array_unique($recipientUserIds));\n\n return [\n 'team_id' => $user->getTeamId(),\n 'type' => self::TYPE_ASK_JIMINNY,\n 'status' => (bool) $status,\n 'frequency' => $frequency,\n 'custom_name' => $name,\n 'activity_search_id' => $savedSearch->getId(),\n 'ask_anything_prompt_id' => $prompt->getId(),\n 'expires_at' => $expiresAtDate->toDateString(),\n 'media_types' => [self::MEDIA_TYPE_PDF],\n 'call_types' => [],\n 'recipients' => ['users' => $recipientUserIds],\n 'groups' => $sharedGroupIds,\n ];\n }\n\n public static function getAskJiminnyFrequencies(): array\n {\n return array_map(static function ($frequency) {\n return $frequency['id'];\n }, self::ASK_JIMINNY_FREQUENCIES);\n }\n\n public function getAskJiminnyReportFilters(User $user): array\n {\n $savedSearches = $this->activitySearchRepository->findByUserOrderedByName($user)\n ->map(fn (Search $search) => [\n 'id' => $search->getUuid(),\n 'name' => $search->getName(),\n ])\n ->values()->all();\n\n $prompts = collect(\n $this->askAnythingPromptService->get($user, AskAnythingPromptTarget::on_demand)\n )->map(fn (AskAnythingPromptDto $prompt) => [\n 'id' => $prompt->id,\n 'name' => $prompt->title,\n ])->values()->all();\n\n return [\n [\n 'id' => 'prompt',\n 'label' => 'Prompt',\n 'options' => $prompts,\n ],\n [\n 'id' => 'saved_search',\n 'label' => 'Saved Search',\n 'options' => $savedSearches,\n ],\n ];\n }\n\n public function getAskJiminnyReportFormData(User $user, ?AutomatedReport $report = null): array\n {\n $team = $user->getTeam();\n $userTimezone = $user->getTimezone();\n\n $savedSearches = $this->activitySearchRepository->findByUserOrderedByName($user)\n ->map(fn (Search $search) => [\n 'id' => $search->getUuid(),\n 'name' => $search->getName(),\n ])\n ->values()->all();\n\n $prompts = collect(\n $this->askAnythingPromptService->get($user, AskAnythingPromptTarget::on_demand)\n )->map(fn (AskAnythingPromptDto $prompt) => [\n 'id' => $prompt->id,\n 'name' => $prompt->title,\n ])->values()->all();\n\n $teamGroups = $this->groupRepository->getAllByTeam($team)->map(fn ($group) => [\n 'id' => $group->getUuid(),\n 'name' => $group->getName(),\n ])->values()->all();\n\n $shareUsers = $this->recipientsService->getRecipientsFieldData(team: $team)['options'] ?? [];\n\n $sharedTeamsValue = [];\n $sharedUsersValue = [];\n if ($report) {\n $sharedTeamsValue = $this->transformGroups($team, $report->getGroups());\n\n $recipientUserIds = $report->getRecipients()['users'] ?? [];\n $creatorId = $report->getAttribute('created_by');\n $sharedUserIds = array_values(array_filter(\n $recipientUserIds,\n static fn ($id) => $id !== $creatorId\n ));\n $sharedUsersValue = collect($sharedUserIds)\n ->map(fn ($id) => $this->userRepository->find((int) $id))\n ->filter()\n ->map(fn (User $u) => [\n 'id' => $u->getUuid(),\n 'name' => $u->getName(),\n ])\n ->values()\n ->all();\n }\n\n return [\n 'fields' => [\n [\n 'id' => 'enabled',\n 'inputType' => InputTypeEnum::TOGGLE,\n 'label' => '',\n 'value' => $report?->getStatus() ?? false,\n ],\n [\n 'id' => 'report_name',\n 'inputType' => InputTypeEnum::TEXT,\n 'label' => 'Name',\n 'placeholder' => 'Enter name',\n 'required' => true,\n 'validation' => ['maxLength' => 50],\n 'value' => $report?->getCustomName() ?? '',\n ],\n [\n 'id' => 'frequency',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'label' => 'Frequency',\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => self::ASK_JIMINNY_FREQUENCIES,\n 'value' => $report ? $this->transformFrequency($report->getFrequency()) : null,\n ],\n [\n 'id' => 'expires_on',\n 'inputType' => InputTypeEnum::DATE,\n 'label' => 'Expires on',\n 'required' => true,\n 'placeholder' => 'Select',\n 'validation' => [\n 'minDate' => now($userTimezone)->toDateString(),\n 'maxDate' => now($userTimezone)->addYear()->toDateString(),\n ],\n 'value' => $report?->getExpiresAt()?->toDateString(),\n ],\n [\n 'id' => 'share_teams',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'label' => 'Team',\n 'required' => false,\n 'placeholder' => 'Select',\n 'options' => $teamGroups,\n 'value' => $sharedTeamsValue,\n ],\n [\n 'id' => 'share_users',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'label' => 'Team member',\n 'required' => false,\n 'placeholder' => 'Select',\n 'groupLabelKey' => 'label',\n 'groupValuesKey' => 'users',\n 'optionLabelKey' => 'name',\n 'optionValueKey' => 'id',\n 'options' => $shareUsers,\n 'value' => $sharedUsersValue,\n ],\n [\n 'id' => 'saved_search',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'label' => 'Saved search',\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => $savedSearches,\n 'value' => $report && $report->getSavedSearch() ? [\n 'id' => $report->getSavedSearch()->getUuid(),\n 'name' => $report->getSavedSearch()->getName(),\n ] : null,\n ],\n [\n 'id' => 'ask_jiminny_prompt',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'label' => 'Ask Jiminny prompt',\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => $prompts,\n 'value' => $report && $report->getAskAnythingPrompt() ? [\n 'id' => $report->getAskAnythingPrompt()->getUuid(),\n 'name' => $report->getAskAnythingPrompt()->getTitle(),\n ] : null,\n ],\n ],\n ];\n }\n\n private function updateResultNames(AutomatedReport $automatedReport): void\n {\n $results = $this->automatedReportsRepository->getResultsByReport($automatedReport);\n\n foreach ($results as $result) {\n $result->update(['name' => $this->getReportFileName($result)]);\n }\n }\n\n public function updateStatus(string $uuid, array $data): array\n {\n $automatedReport = $this->automatedReportsRepository->findByUuid($uuid);\n\n if (! $automatedReport) {\n throw new ModelNotFoundException('Report not found');\n }\n\n $status = $this->validateReportStatus($data['report_enabled'] ?? null);\n $automatedReport->update([\n 'status' => $status,\n ]);\n\n $this->generateOneOffReport($automatedReport);\n\n return $this->transformReportFullView($automatedReport);\n }\n\n private function generateOneOffReport(AutomatedReport $automatedReport): void\n {\n // the scheduler handles all the other frequency types\n if ($automatedReport->getStatus() === false || $automatedReport->getFrequency() !== self::FREQUENCY_ONE_OFF) {\n return;\n }\n\n $this->dispatcher->dispatch(new RequestGenerateReportJob($automatedReport->getUuid()));\n }\n\n public function getReport(string $uuid): AutomatedReport\n {\n $automatedReport = $this->automatedReportsRepository->findByUuid($uuid);\n\n if (! $automatedReport) {\n throw new ModelNotFoundException('Report not found');\n }\n\n return $automatedReport;\n }\n\n public function get(string $uuid): array\n {\n $automatedReport = $this->getReport($uuid);\n\n return $this->transformReportFullView($automatedReport);\n }\n\n public function list(string $sortColumn = 'created_at', string $sortDirection = 'desc'): array\n {\n $results = [];\n $collection = $this->automatedReportsRepository->getAllStandardReports($sortColumn, $sortDirection);\n\n /** @var AutomatedReport $report */\n foreach ($collection as $report) {\n $results[] = $this->transformReportFullView($report);\n }\n\n return ['data' => $results];\n }\n\n public function listAskJiminnyReports(\n User $user,\n string $sortColumn = 'created_at',\n string $sortDirection = 'desc'\n ): array {\n $results = [];\n $collection = $this->automatedReportsRepository->getAskJiminnyReportsByUser($user, $sortColumn, $sortDirection);\n\n /** @var AutomatedReport $report */\n foreach ($collection as $report) {\n $results[] = $this->transformReportFullView($report);\n }\n\n return ['data' => $results];\n }\n\n public function delete(string $uuid): void\n {\n $automatedReport = $this->automatedReportsRepository->findByUuid($uuid);\n\n if (! $automatedReport) {\n throw new ModelNotFoundException('Report not found');\n }\n\n $automatedReport->delete();\n }\n\n public function createReportResult(AutomatedReport $automatedReport, array $data = []): AutomatedReportResult\n {\n return $this->automatedReportsRepository->createResult(\n array_merge(\n [\n 'report_id' => $automatedReport->getId(),\n 'status' => AutomatedReportResult::STATUS_DEFAULT,\n ],\n $data\n )\n );\n }\n\n public function getReportResult(string $resultUuid): AutomatedReportResult\n {\n $report = $this->automatedReportsRepository->findResultByUuid($resultUuid);\n\n if (! $report) {\n throw new ModelNotFoundException('Report Result not found');\n }\n\n return $report;\n }\n\n public function findChildResult(AutomatedReportResult $result, string $type): ?AutomatedReportResult\n {\n return $this->automatedReportsRepository->findChildResult($result, $type);\n }\n\n // prophet API calls\n /**\n * @throws ApplicationException\n */\n public function getGenerateReportPayload(AutomatedReport $automatedReport, string $reportResultUuid): array\n {\n $period = $this->calculateFromAndToDate($automatedReport);\n $fromDate = $period['fromDate'];\n $toDate = $period['toDate'];\n\n return [\n 'team_id' => $automatedReport->getTeamId(),\n 'request_id' => $reportResultUuid,\n 'report_type' => $automatedReport->getType(),\n 'media_types' => $automatedReport->getMediaTypes(),\n 'from_date' => $fromDate->startOfDay()->format(DateTimeInterface::RFC3339),\n 'to_date' => $toDate->endOfDay()->format(DateTimeInterface::RFC3339),\n 'group_ids' => $automatedReport->getGroups(),\n 'call_deal_stage' => $automatedReport->getDealAtCallStages(),\n 'current_deal_stage' => $automatedReport->getCurrentDealStages(),\n 'deal_min_value' => $automatedReport->getDealValueMin(),\n 'deal_max_value' => $automatedReport->getDealValueMax(),\n 'call_types' => $automatedReport->getCallTypes(),\n 'call_duration_min_seconds' => $automatedReport->getCallDurationMin(),\n 'call_duration_max_seconds' => $automatedReport->getCallDurationMax(),\n 'special_requirements' => $automatedReport->getAdditionalPromptInput(),\n 'callback_url' => $this->getCallbackUrl(),\n 'report_period' => $this->formatReportPeriodName(\n $automatedReport->getFrequency(),\n $fromDate,\n $toDate,\n ),\n 'playbook_categories' => $automatedReport->getPlaybookCategories(),\n 'custom_name' => $automatedReport->getCustomName(),\n ];\n }\n\n // $inputPayload - FE payload structure\n public function getActivitiesCountPayload(array $inputPayload): array\n {\n // Use validateAndTransformData to validate and normalize input\n $validatedData = $this->validateAndTransformData($inputPayload);\n $period = $this->calculateFromAndToDatePeriod(\n $validatedData['frequency'],\n Carbon::parse($validatedData['from']),\n Carbon::parse($validatedData['to']),\n );\n $fromDate = $period['fromDate'];\n $toDate = $period['toDate'];\n\n // Create payload similar to getGenerateReportPayload\n return [\n 'team_id' => $validatedData['team_id'],\n 'group_ids' => $validatedData['groups'] ?? [],\n 'report_type' => $validatedData['type'],\n 'from_date' => $fromDate->format(DateTimeInterface::RFC3339),\n 'to_date' => $toDate->format(DateTimeInterface::RFC3339),\n 'call_deal_stage' => $validatedData['deal_at_call_stages'] ?? [],\n 'current_deal_stage' => $validatedData['current_deal_stages'] ?? [],\n 'deal_min_value' => $validatedData['deal_value_min'] ?? null,\n 'deal_max_value' => $validatedData['deal_value_max'] ?? null,\n 'call_types' => $validatedData['call_types'],\n 'call_duration_min_seconds' => $validatedData['call_duration_min'] ?? null,\n 'call_duration_max_seconds' => $validatedData['call_duration_max'] ?? null,\n 'special_requirements' => $validatedData['additional_prompt_input'] ?? null,\n 'playbook_categories' => $validatedData['playbook_categories'] ?? [],\n 'request_id' => null,\n 'callback_url' => null,\n ];\n }\n\n public function shouldSendReport(array $users, ?CarbonInterface $generatedAt = null): bool\n {\n if (empty($users)) {\n return false;\n }\n\n $earliestTz = collect($users)\n ->mapWithKeys(function (array $user) {\n $tz = new DateTimeZone($user['timezone']);\n $nowUtc = new DateTime('now', new DateTimeZone('UTC'));\n $offset = $tz->getOffset($nowUtc);\n\n return [$user['timezone'] => $offset];\n })\n ->sortDesc()\n ->keys()\n ->first();\n\n $now = Carbon::now($earliestTz);\n $isScheduledTime = (int) $now->format('H') === self::SENT_REPORT_AT_HOURS;\n\n if ($isScheduledTime) {\n return true;\n }\n\n return $this->hasPassedScheduledTime($generatedAt, $earliestTz);\n }\n\n public function hasPassedScheduledTime(?CarbonInterface $generatedAt, string $timezone): bool\n {\n if ($generatedAt === null) {\n return false;\n }\n\n $now = Carbon::now($timezone);\n $scheduledTime = $now->copy()->setTime(self::SENT_REPORT_AT_HOURS, 0, 0);\n\n if ($now->hour < self::SENT_REPORT_AT_HOURS) {\n $scheduledTime = $scheduledTime->subDay();\n }\n\n $scheduledTimeUtc = $scheduledTime->copy()->utc();\n $generatedAtUtc = $generatedAt->copy()->utc();\n $nowUtc = $now->copy()->utc();\n\n return $generatedAtUtc->lt($scheduledTimeUtc) && $nowUtc->gt($scheduledTimeUtc);\n }\n\n public function calculateFromAndToDatePeriod(\n string $frequency,\n ?Carbon $fromDate = null,\n ?Carbon $toDate = null\n ): array {\n if ($frequency === self::FREQUENCY_ONE_OFF) {\n return [\n 'fromDate' => $fromDate,\n 'toDate' => $toDate,\n ];\n }\n\n $now = Carbon::now();\n\n return match ($frequency) {\n self::FREQUENCY_DAILY => [\n 'fromDate' => $now->copy()->subDay()->startOfDay(),\n 'toDate' => $now->copy()->subDay()->endOfDay(),\n ],\n self::FREQUENCY_WEEKLY => [\n 'fromDate' => $now->copy()->subWeeks(1)->startOfDay(),\n 'toDate' => $now->copy()->subDay()->endOfDay(),\n ],\n self::FREQUENCY_MONTHLY => [\n 'fromDate' => $now->copy()->subMonths(1)->startOfDay(),\n 'toDate' => $now->copy()->subDay()->endOfDay(),\n ],\n self::FREQUENCY_QUARTERLY => [\n 'fromDate' => $now->copy()->subMonths(3)->startOfDay(),\n 'toDate' => $now->copy()->subDay()->endOfDay(),\n ],\n default => throw new InvalidArgumentException(\"Unsupported frequency: {$frequency}\"),\n };\n }\n\n private function calculateFromAndToDate(AutomatedReport $automatedReport): array\n {\n return $this->calculateFromAndToDatePeriod(\n $automatedReport->getFrequency(),\n $automatedReport->getFrom(),\n $automatedReport->getTo()\n );\n }\n\n public function getAskJiminnyGenerateReportPayload(\n AutomatedReport $automatedReport,\n AutomatedReportResult $reportResult,\n array $activityIds,\n ): array {\n return [\n 'user_question' => $automatedReport->getAskAnythingPrompt()?->getContent(),\n 'call_ids' => array_map('strval', $activityIds),\n 'team_id' => $automatedReport->getTeamId(),\n 'request_id' => $reportResult->getUuid(),\n 'callback_url' => $this->getCallbackUrl(),\n 'report_period' => $this->getReportPeriodName($reportResult),\n 'report_name' => $automatedReport->getCustomName(),\n ];\n }\n\n private function getCallbackUrl(): string\n {\n return $this->webhookService->route('jiminny.webhook.reports.ready');\n }\n\n /**\n * Validate and transform payload data for automated reports\n *\n * @param array $data\n *\n * @throws InvalidArgumentException\n *\n * @return array\n */\n private function validateAndTransformData(array $data): array\n {\n // Validate organization (team) and check feature\n $team = $this->validateOrganization($data['organization'] ?? null);\n\n $status = $this->validateReportStatus($data['report_enabled'] ?? null);\n $type = $this->validateReportType($data['report_type'] ?? null);\n $frequency = $this->validateFrequency($data['frequency'] ?? null);\n $additionalPromptInput = $this->validateAdditionalPromptInput(\n $data['additional_prompt_input'] ?? null\n );\n $customReportName = $this->validateCustomReportName($data['custom_name'] ?? null);\n\n // Prepare data for the database\n $reportData = [\n 'team_id' => $team->getId(),\n 'type' => $type,\n 'status' => $status,\n 'frequency' => $frequency,\n 'additional_prompt_input' => $additionalPromptInput,\n 'custom_name' => $customReportName,\n ];\n\n // Validate deal values\n $reportData = $this->validateDealValues($data, $reportData);\n\n // Validate date range\n $reportData = $this->validateDateRange($data, $reportData, $frequency);\n\n // Validate call durations\n $reportData = $this->validateCallDurations($data, $reportData);\n\n // Validate call types\n $reportData = $this->validateCallTypes($data, $reportData);\n\n // Validate media types\n $reportData = $this->validateMediaTypes($data, $reportData);\n\n // Validate groups\n if (isset($data['teams'])) {\n $reportData['groups'] = $this->validateAndGetGroupIds($team, $data['teams']);\n }\n\n // Validate deal stages\n $reportData = $this->validateDealStages($data, $reportData, $team, $type);\n\n // Validate playbook categories\n $reportData = $this->validatePlaybookCategories($data, $reportData, $team);\n\n // Validate recipients\n $reportData['recipients'] = [\n 'users' => $this->validateAndGetUserIdsByTeam($team, $data['recipients'] ?? []),\n ];\n\n if (isset($data['jiminny_recipients'])) {\n // Validate Jiminny recipients\n $reportData['jiminny_recipients'] = [\n 'users' => $this->validateAndGetJiminnyUserIds((array) $data['jiminny_recipients']),\n ];\n }\n\n return $reportData;\n }\n\n private function validateDealValues(array $data, array $reportData): array\n {\n if (isset($data['min_deal_value'])) {\n $reportData['deal_value_min'] = (int) $data['min_deal_value'];\n\n if ($reportData['deal_value_min'] > 4294967295 || $reportData['deal_value_min'] < 0) {\n throw new InvalidArgumentException('Min deal value should be between 0 and 4294967295');\n }\n }\n\n if (isset($data['max_deal_value'])) {\n $reportData['deal_value_max'] = (int) $data['max_deal_value'];\n\n if ($reportData['deal_value_max'] > 4294967295 || $reportData['deal_value_max'] < 0) {\n throw new InvalidArgumentException('Max deal value should be between 0 and 4294967295');\n }\n }\n\n if (isset($data['min_deal_value'], $data['max_deal_value'])\n && $data['min_deal_value'] > $data['max_deal_value']\n ) {\n throw new InvalidArgumentException('Min deal value cannot be greater than max deal value');\n }\n\n return $reportData;\n }\n\n private function validateDateRange(array $data, array $reportData, string $frequency): array\n {\n // Set date range only for one_off frequency\n if ($frequency === 'one_off') {\n if (isset($data['start_date_period'])) {\n $reportData['from'] = $this->parseDate($data['start_date_period']);\n }\n\n if (isset($data['end_date_period'])) {\n $reportData['to'] = $this->parseDate($data['end_date_period']);\n }\n\n if (empty($reportData['from']) || empty($reportData['to'])) {\n throw new InvalidArgumentException(\n 'Start date and end date are required for one_off frequency'\n );\n }\n } else {\n $reportData['from'] = null;\n $reportData['to'] = null;\n }\n\n return $reportData;\n }\n\n private function validateCallDurations(array $data, array $reportData): array\n {\n // Convert call durations from minutes to seconds\n if (isset($data['min_call_duration'])) {\n $reportData['call_duration_min'] = (int) $data['min_call_duration'] * 60;\n\n if ($reportData['call_duration_min'] > 4294967295 || $reportData['call_duration_min'] < 0) {\n throw new InvalidArgumentException('Min call duration should be between 0 and 4294967295');\n }\n }\n\n if (isset($data['max_call_duration'])) {\n $reportData['call_duration_max'] = (int) $data['max_call_duration'] * 60;\n\n if ($reportData['call_duration_max'] > 4294967295 || $reportData['call_duration_max'] < 0) {\n throw new InvalidArgumentException('Max call duration should be between 0 and 4294967295');\n }\n }\n\n return $reportData;\n }\n\n private function validateCallTypes(array $data, array $reportData): array\n {\n // Set call types\n $reportData['call_types'] = $data['call_type'] ?? [];\n if (empty($reportData['call_types'])) {\n $reportData['call_types'] = self::getCallTypes();\n }\n\n foreach ($reportData['call_types'] as $callType) {\n if (! in_array($callType, self::getCallTypes(), true)) {\n throw new InvalidArgumentException(sprintf('Call type %s is invalid', $callType));\n }\n }\n\n return $reportData;\n }\n\n private function validateMediaTypes(array $data, array $reportData): array\n {\n // Set media types from input data\n $reportData['media_types'] = $data['media_types'] ?? [];\n\n if (empty($reportData['media_types'])) {\n throw new InvalidArgumentException('Media types are required');\n }\n\n foreach ($reportData['media_types'] as $mediaType) {\n if (! in_array($mediaType, self::MEDIA_TYPES, true)) {\n throw new InvalidArgumentException(sprintf('Media type %s is invalid', $mediaType));\n }\n }\n\n return $reportData;\n }\n\n private function validateDealStages(array $data, array $reportData, Team $team, string $reportType): array\n {\n // Validate and set deal stages\n if (isset($data['deal_stage_at_call'])) {\n $reportData['deal_at_call_stages'] =\n $this->validateAndGetDealStageIds($team, $data['deal_stage_at_call'], 'Deal stage at call');\n }\n\n if (isset($data['current_deal_stage'])) {\n $reportData['current_deal_stages'] =\n $this->validateAndGetDealStageIds($team, $data['current_deal_stage'], 'Current deal stage');\n }\n\n // Ensure current_deal_stage is not provided for loss_analysis report type\n if ($reportType === self::TYPE_LOSS_ANALYSIS && ! empty($data['current_deal_stage'])) {\n throw new InvalidArgumentException('Current deal stage is not applicable for Loss Analysis reports');\n }\n\n return $reportData;\n }\n\n // transform uuid to id\n private function validatePlaybookCategories(array $data, array $reportData, Team $team): array\n {\n $key = 'playbook_categories';\n\n if (isset($data[$key])) {\n $payloadIds = $data[$key];\n $ids = [];\n\n foreach ($payloadIds as $uuid) {\n $uuid = (string) $uuid;\n\n try {\n $playbookCategory = $this->playbookCategoryRepository->findByUuid($uuid);\n } catch (Throwable $throwable) {\n Log::error(__METHOD__ . ' ' . $throwable->getMessage());\n\n throw new InvalidArgumentException(sprintf('Playbook category %s not found', $uuid));\n }\n\n if (! $playbookCategory) {\n throw new InvalidArgumentException(sprintf('Playbook category %s not found', $uuid));\n }\n\n if (! $playbookCategory->hasPlaybook()) {\n throw new InvalidArgumentException(sprintf('Playbook category %s has no playbook', $uuid));\n }\n\n if ($playbookCategory->getPlaybook()->getTeamId() !== $team->getId()) {\n throw new InvalidArgumentException(\n sprintf('Playbook category %s not found for team %s', $uuid, $team->getUuid())\n );\n }\n\n $ids[] = $playbookCategory->getId();\n }\n\n $reportData[$key] = $ids;\n }\n\n return $reportData;\n }\n\n private function validateReportStatus($status): bool\n {\n if (! in_array($status, [true, false], true)) {\n throw new InvalidArgumentException('Report status is invalid');\n }\n\n return $status;\n }\n\n private function validateReportType($type): string\n {\n if (! in_array($type, self::getTypes(), true)) {\n throw new InvalidArgumentException(sprintf('Report type is invalid: %s', $type));\n }\n\n return $type;\n }\n\n private function validateFrequency($frequency): string\n {\n if (! in_array($frequency, self::getFrequencies(), true)) {\n throw new InvalidArgumentException('Frequency is invalid');\n }\n\n return $frequency;\n }\n\n private function validateAdditionalPromptInput(?string $additionalPromptInput): ?string\n {\n if ($additionalPromptInput && strlen($additionalPromptInput) > 5000) {\n throw new InvalidArgumentException('Additional Prompt Input should be less than 5000 characters');\n }\n\n return $additionalPromptInput;\n }\n\n private function validateCustomReportName(?string $customReportName): ?string\n {\n if ($customReportName === null || $customReportName === '') {\n return null;\n }\n\n if (strlen($customReportName) > 70) {\n throw new InvalidArgumentException('Custom report name should be less than 70 characters');\n }\n\n return $customReportName;\n }\n\n private function validateOrganization(?string $organizationUuid): Team\n {\n if (! $organizationUuid) {\n throw new InvalidArgumentException('Organization is required');\n }\n\n $team = $this->teamRepository->idOrUuid($organizationUuid);\n\n if (! $team) {\n throw new InvalidArgumentException('Organization not found');\n }\n\n if (! $team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {\n throw new InvalidArgumentException('Organization does not have the Automated Reports feature');\n }\n\n return $team;\n }\n\n private function validateAndGetGroupIds(Team $team, array $teamUuids): array\n {\n $groupIds = [];\n\n foreach ($teamUuids as $uuid) {\n $group = $this->groupRepository->findByUuid($uuid);\n\n if ($group === null || $group->getTeamId() !== $team->getId()) {\n throw new InvalidArgumentException(\n sprintf('Group %s not found for team %s', $uuid, $team->getUuid())\n );\n }\n\n $groupIds[] = $group->getId();\n\n }\n\n return $groupIds;\n }\n\n private function validateAndGetDealStageIds(Team $team, array $stageUuids, string $propertyLabel): array\n {\n $stageIds = [];\n\n foreach ($stageUuids as $uuid) {\n $stage = $this->stageRepository->findByUuid($uuid);\n\n if ($stage === null || $stage->getTeamId() !== $team->getId()) {\n throw new InvalidArgumentException(\n sprintf('Stage %s not found for team %s for %s', $uuid, $team->getUuid(), $propertyLabel)\n );\n }\n\n $stageIds[] = $stage->getId();\n }\n\n return $stageIds;\n }\n\n private function validateAndGetUserIds(array $userUuids, callable $teamCheck): array\n {\n if (empty($userUuids)) {\n return [];\n }\n\n $userIds = [];\n\n foreach ($userUuids as $uuid) {\n $user = $this->userRepository->findByUuid($uuid);\n\n if (! $user || ! $user->isStatusActive()) {\n throw new InvalidArgumentException(\n sprintf('User %s not found or is not active', $uuid)\n );\n }\n\n if (! $teamCheck($user)) {\n throw new InvalidArgumentException(\n sprintf('User %s does not belong to the allowed team(s)', $uuid)\n );\n }\n\n $userIds[] = $user->getId();\n }\n\n return $userIds;\n }\n\n private function validateAndGetUserIdsByTeam(Team $team, array $userUuids): array\n {\n return $this->validateAndGetUserIds($userUuids, fn ($user) => $user->getTeamId() === $team->getId());\n }\n\n private function validateAndGetJiminnyUserIds(array $userUuids): array\n {\n $allowedTeamIds = config('kiosk.teamIds', []);\n\n return $this->validateAndGetUserIds($userUuids, fn ($user) => in_array($user->getTeamId(), $allowedTeamIds, true));\n }\n\n private function parseDate(string $dateString): string\n {\n return date('Y-m-d H:i:s', strtotime($dateString));\n }\n\n private function generateReportResultViewUrl(AutomatedReportResult $result): string\n {\n $mediaResource = $this->getReportMediaRouteResource($result);\n\n return route('ai-reports.' . $mediaResource . '.view', ['uuid' => $result->getUuid()]);\n }\n\n private function generateReportResultDownloadUrl(AutomatedReportResult $result): string\n {\n $mediaResource = $this->getReportMediaRouteResource($result);\n\n return route('ai-reports.' . $mediaResource . '.download', ['uuid' => $result->getUuid()]);\n }\n\n private function getReportMediaRouteResource(AutomatedReportResult $result): string\n {\n if ($result->getMediaType() === self::MEDIA_TYPE_PDF) {\n return self::PDF_KEY;\n } elseif ($result->getMediaType() === self::MEDIA_TYPE_PODCAST) {\n return self::AUDIO_KEY;\n }\n\n throw new \\InvalidArgumentException('Unknown media type.');\n }\n\n public function getMediaPath(AutomatedReportResult $result): ?string\n {\n $url = match ($result->getMediaType()) {\n self::MEDIA_TYPE_PDF => $result->getPdfUrl(),\n self::MEDIA_TYPE_PODCAST => $result->getPodcastAudioUrl(),\n default => null,\n };\n\n if ($url === null) {\n return null;\n }\n\n $path = parse_url(trim($url, '\"\\''), PHP_URL_PATH);\n\n return $path ?: null;\n }\n\n public function getFilenameSuffix(AutomatedReportResult $result): ?string\n {\n return match ($result->getMediaType()) {\n self::MEDIA_TYPE_PODCAST => 'Podcast',\n default => null,\n };\n }\n\n public function getMailSubjectSuffix(AutomatedReportResult $result): string\n {\n return match ($result->getMediaType()) {\n self::MEDIA_TYPE_PDF => 'report',\n self::MEDIA_TYPE_PODCAST => 'podcast',\n default => '',\n };\n }\n\n public function getMediaTypeMetadata(AutomatedReportResult $result): array\n {\n return match ($result->getMediaType()) {\n self::MEDIA_TYPE_PODCAST => ['extension' => 'mp3', 'mime' => 'audio/mpeg'],\n self::MEDIA_TYPE_PDF => ['extension' => 'pdf', 'mime' => 'application/pdf'],\n default => ['extension' => null, 'mime' => null],\n };\n }\n\n public function deleteS3Files(AutomatedReportResult $result): void\n {\n $teamUuid = $result->getReport()->getTeam()->getUuid();\n $reportUuid = $result->getUuid();\n\n // delete all files for a report uuid no mather of pdf, podcast, or both\n // in case of both - the podcast files are linked to the pdf (parent) uuid\n // pdf and podcast date times should be close\n $path = sprintf('%s/%s/%s', $teamUuid, self::S3_DIR, $reportUuid);\n\n foreach (self::FILE_EXTENSIONS_VARIANTS as $extension) {\n $file = $path . '.' . $extension;\n\n if (Storage::exists($file)) {\n Storage::delete($file);\n Log::info('[Reports] Deleted S3 file', [\n 'path' => $file,\n ]);\n }\n }\n\n foreach (self::FILE_PODCAST_EXTENSIONS_VARIANTS as $extension) {\n $file = $path . '_podcast.' . $extension;\n\n if (Storage::exists($file)) {\n Storage::delete($file);\n Log::info('[Reports] Deleted Podcast S3 file', [\n 'path' => $file,\n ]);\n }\n }\n }\n\n /**\n *\n * @param int|null $teamId Optional team ID to filter results\n *\n * @return Collection<int, int> Collection of team IDs\n */\n public function getTeamIdsWithReportsResults(?int $teamId = null): Collection\n {\n return $this->automatedReportsRepository->getTeamIdsWithReportsResults($teamId);\n }\n\n /**\n * Core delete logic for report results using a query\n *\n * @param Builder $query\n * @param array $logContext\n *\n * @return int\n */\n private function deleteReportResultsByQuery(Builder $query, array $logContext = []): int\n {\n $deletedCount = 0;\n\n if ($query->exists()) {\n Log::info(\n 'Run delete report results',\n array_merge(\n $logContext,\n [\n 'service' => 'AutomatedReportsService',\n ]\n )\n );\n\n $query->chunkById(50, function ($results) use (&$deletedCount, $logContext) {\n foreach ($results as $result) {\n $this->deleteReportResult($result);\n $deletedCount++;\n\n Log::info(\n 'Deleted a report result',\n array_merge(\n $logContext,\n [\n 'result_id' => $result->getId(),\n 'report_id' => $result->getReportId(),\n ]\n )\n );\n }\n });\n }\n\n return $deletedCount;\n }\n\n /**\n * Delete report results for a team by retention period\n *\n * @param Team $team\n * @param CarbonImmutable $retentionDate\n *\n * @return int Number of deleted report results\n */\n public function deleteReportsResultsInRetentionPeriod(Team $team, CarbonImmutable $retentionDate): int\n {\n $reportIds = $this->automatedReportsRepository->getReportIdsByTeam($team);\n\n if ($reportIds->isEmpty()) {\n return 0;\n }\n\n $query = $this->automatedReportsRepository\n ->getReportResultsQueryForRetention($team, $retentionDate);\n\n return $this->deleteReportResultsByQuery($query, [\n 'team_id' => $team->getId(),\n 'retention_date' => $retentionDate->toDateTimeString(),\n ]);\n }\n\n /**\n * Delete ALL report results for a specific automated report\n *\n * @param string $uuid\n *\n * @return int\n */\n public function deleteReportResults(string $uuid): int\n {\n $report = $this->getReport($uuid);\n\n $query = $this->automatedReportsRepository->getResultsByReportQuery($report);\n\n return $this->deleteReportResultsByQuery($query, [\n 'report_uuid' => $uuid,\n 'report_id' => $report->getId(),\n ]);\n }\n\n public function deleteReportResult(AutomatedReportResult $result): void\n {\n $this->deleteS3Files($result);\n\n $result->delete();\n }\n\n /**\n * Get all reports for a specific team\n *\n * @param Team $team\n *\n * @return \\Illuminate\\Database\\Eloquent\\Collection\n */\n public function getTeamReports(Team $team): \\Illuminate\\Database\\Eloquent\\Collection\n {\n return $this->automatedReportsRepository->getReportsByTeam($team);\n }\n\n /**\n * Get all report results for a specific report\n *\n * @param AutomatedReport $report\n *\n * @return \\Illuminate\\Database\\Eloquent\\Collection\n */\n public function getReportResults(AutomatedReport $report): \\Illuminate\\Database\\Eloquent\\Collection\n {\n return $this->automatedReportsRepository->getResultsByReport($report);\n }\n\n public function deleteAllReportResults(AutomatedReport $report): void\n {\n $results = $this->getReportResults($report);\n\n /** @var AutomatedReportResult $result */\n foreach ($results as $result) {\n Log::info('Deleting result', [\n 'report' => $report->getId(),\n 'result' => $result->getId(),\n ]);\n\n $this->deleteReportResult($result);\n }\n }\n\n public function deleteAllData(Team $team): void\n {\n Log::info('Deleting automated report and results for team', [\n 'team' => $team->getId(),\n ]);\n\n $reports = $this->getTeamReports($team);\n\n /** @var AutomatedReport $report */\n foreach ($reports as $report) {\n Log::info('Deleting report', [\n 'team' => $team->getId(),\n 'report' => $report->getId(),\n ]);\n\n $this->deleteAllReportResults($report);\n\n $report->delete();\n }\n }\n}","depth":4,"value":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Services\\Kiosk\\AutomatedReports;\n\nuse Carbon\\CarbonImmutable;\nuse Carbon\\CarbonInterface;\nuse Carbon\\Exceptions\\InvalidFormatException;\nuse DateTime;\nuse DateTimeInterface;\nuse DateTimeZone;\nuse Illuminate\\Contracts\\Bus\\Dispatcher as BusDispatcher;\nuse Illuminate\\Database\\Eloquent\\Builder;\nuse Illuminate\\Support\\Carbon;\nuse Illuminate\\Support\\Collection;\nuse Illuminate\\Support\\Facades\\Log;\nuse Illuminate\\Support\\Facades\\Storage;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinition\\InputTypeEnum;\nuse Jiminny\\Component\\AskAnything\\AskAnythingPromptService;\nuse Jiminny\\Component\\AskAnything\\Dtos\\AskAnythingPromptDto;\nuse Jiminny\\Component\\UrlGenerator\\Webhook;\nuse Jiminny\\Contracts\\Repositories\\PlaybookCategoryRepository;\nuse Jiminny\\Contracts\\Repositories\\TeamRepository;\nuse Jiminny\\Contracts\\Repositories\\UserRepository;\nuse Jiminny\\Exceptions\\ApplicationException;\nuse Jiminny\\Exceptions\\InvalidArgumentException;\nuse Jiminny\\Exceptions\\ModelNotFoundException;\nuse Jiminny\\Jobs\\AutomatedReports\\RequestGenerateReportJob;\nuse Jiminny\\Models\\Activity\\Search;\nuse Jiminny\\Models\\AskAnything\\AskAnythingPrompt;\nuse Jiminny\\Models\\AskAnything\\AskAnythingPromptTarget;\nuse Jiminny\\Models\\AutomatedReport;\nuse Jiminny\\Models\\AutomatedReportResult;\nuse Jiminny\\Models\\Contracts\\UserContract;\nuse Jiminny\\Models\\Feature\\FeatureEnum;\nuse Jiminny\\Models\\Team;\nuse Jiminny\\Models\\User;\nuse Jiminny\\Repositories\\AskAnythingRepository;\nuse Jiminny\\Repositories\\AutomatedReportsRepository;\nuse Jiminny\\Repositories\\GroupRepository;\nuse Jiminny\\Repositories\\SearchRepository;\nuse Jiminny\\Repositories\\StageRepository;\nuse Throwable;\n\nclass AutomatedReportsService\n{\n public const string TYPE_LOSS_ANALYSIS = 'loss_analysis';\n public const string TYPE_ASK_JIMINNY = 'ask_jiminny';\n\n /**\n * Standard report types (used by kiosk for existing automated reports).\n */\n // @TODO this will add filter, however if we need to control feature by FF we need conditional logic\n public const array TYPES = [\n ['id' => 'exec_summary', 'name' => 'Exec Summary'],\n ['id' => 'coaching_profiles', 'name' => 'Coaching Profiles'],\n ['id' => 'product_feedback', 'name' => 'Product Feedback'],\n ['id' => self::TYPE_LOSS_ANALYSIS, 'name' => 'Loss Analysis'],\n// ['id' => 'questions', 'name' => 'Questions'],\n// ['id' => 'statistical_quant', 'name' => 'Statistical Quantitative'],\n ];\n\n public const array ALL_TYPES = [\n ...self::TYPES,\n ['id' => self::TYPE_ASK_JIMINNY, 'name' => 'Ask Jiminny'],\n ];\n\n public const string FREQUENCY_DAILY = 'daily';\n public const string FREQUENCY_WEEKLY = 'weekly';\n public const string FREQUENCY_MONTHLY = 'monthly';\n public const string FREQUENCY_QUARTERLY = 'quarterly';\n public const string FREQUENCY_ONE_OFF = 'one_off';\n\n /**\n * Frequencies for standard (non-Ask Jiminny) reports.\n */\n public const array FREQUENCIES = [\n ['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],\n ['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],\n ['id' => self::FREQUENCY_QUARTERLY, 'name' => 'Quarterly'],\n ['id' => self::FREQUENCY_ONE_OFF, 'name' => 'One-off'],\n ];\n\n /**\n * Frequencies for Ask Jiminny reports.\n */\n public const array ASK_JIMINNY_FREQUENCIES = [\n ['id' => self::FREQUENCY_DAILY, 'name' => 'Daily'],\n ['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],\n ['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],\n ];\n\n public const string MEDIA_TYPE_PDF = 'pdf';\n public const string MEDIA_TYPE_PODCAST = 'podcast';\n public const array MEDIA_TYPES = [self::MEDIA_TYPE_PDF, self::MEDIA_TYPE_PODCAST];\n public const array MEDIA_TYPE_OBJECT_PDF = ['id' => self::MEDIA_TYPE_PDF, 'name' => 'PDF'];\n public const array MEDIA_TYPE_OBJECT_PODCAST = ['id' => self::MEDIA_TYPE_PODCAST, 'name' => 'Podcast'];\n public const array MEDIA_TYPE_OBJECTS = [self::MEDIA_TYPE_OBJECT_PDF, self::MEDIA_TYPE_OBJECT_PODCAST];\n\n public const array CALL_TYPE_CONFERENCE = ['id' => 'conference', 'name' => 'Conference'];\n public const array CALL_TYPE_DIALER = ['id' => 'dialer', 'name' => 'Dialer'];\n public const int SENT_REPORT_AT_HOURS = 5;\n public const string PDF_KEY = 'pdf';\n public const string AUDIO_KEY = 'audio';\n\n private const array ALL_FREQUENCIES = [\n ['id' => self::FREQUENCY_DAILY, 'name' => 'Daily'],\n ['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],\n ['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],\n ['id' => self::FREQUENCY_QUARTERLY, 'name' => 'Quarterly'],\n ['id' => self::FREQUENCY_ONE_OFF, 'name' => 'One-off'],\n ];\n private const string S3_DIR = 'reports';\n private const array FILE_EXTENSIONS_VARIANTS = ['html', 'MD', 'pdf'];\n private const array FILE_PODCAST_EXTENSIONS_VARIANTS = ['json', 'mp3', 'ssml'];\n\n public function __construct(\n private readonly TeamRepository $teamRepository,\n private readonly GroupRepository $groupRepository,\n private readonly UserRepository $userRepository,\n private readonly StageRepository $stageRepository,\n private readonly DealStagesService $dealStagesService,\n private readonly RecipientsService $recipientsService,\n private readonly AutomatedReportsRepository $automatedReportsRepository,\n private readonly Webhook $webhookService,\n private readonly BusDispatcher $dispatcher,\n private readonly ActivityTypeService $activityTypeService,\n private readonly PlaybookCategoryRepository $playbookCategoryRepository,\n private readonly AskAnythingPromptService $askAnythingPromptService,\n private readonly SearchRepository $activitySearchRepository,\n private readonly AskAnythingRepository $askAnythingRepository,\n ) {\n }\n\n public static function getTypes(): array\n {\n $types = self::TYPES;\n\n return array_map(static function ($type) {\n return $type['id'];\n }, $types);\n }\n\n public static function getCallTypes(): array\n {\n return array_map(static function ($callType) {\n return $callType['id'];\n }, [self::CALL_TYPE_CONFERENCE, self::CALL_TYPE_DIALER]);\n }\n\n public static function getFrequencies(): array\n {\n return array_map(static function ($frequency) {\n return $frequency['id'];\n }, self::FREQUENCIES);\n }\n\n // front-facing structure\n public function getReportEnabledFieldData(bool $value = false): array\n {\n return [\n 'id' => 'report_enabled',\n 'label' => '',\n 'inputType' => InputTypeEnum::TOGGLE,\n 'value' => $value,\n ];\n }\n\n // Organizations = Teams\n public function getOrganizationFieldData(?string $value = null, bool $shortVersion = false): array\n {\n $options = $this->getTeams();\n\n if ($shortVersion) {\n return [\n 'id' => 'organization',\n 'label' => 'Organization',\n 'options' => $options,\n ];\n }\n\n return [\n 'id' => 'organization',\n 'label' => 'Organization',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => $options,\n 'value' => $value,\n 'dependencies' => [\n 'teams',\n 'deal_stage_at_call',\n 'current_deal_stage',\n 'recipients',\n ActivityTypeService::PLAYBOOK_CATEGORIES_KEY,\n ],\n 'dependsOn' => [],\n ];\n }\n\n // Teams = Groups\n public function getTeamFieldData(array $options = [], array $value = [], bool $shortVersion = false): array\n {\n if ($shortVersion) {\n return [\n 'id' => 'teams',\n 'label' => 'Team',\n 'options' => $options,\n ];\n }\n\n return [\n 'id' => 'teams',\n 'label' => 'Team',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'required' => false,\n 'placeholder' => 'Select',\n 'options' => $options,\n 'value' => $value, // value should be an array of objects {id, name}\n 'dependencies' => [ActivityTypeService::PLAYBOOK_CATEGORIES_KEY],\n 'dependsOn' => [],\n ];\n }\n\n public function getReportTypeFieldData(?string $value = null, bool $shortVersion = false, ?Team $team = null): array\n {\n $types = [];\n if ($team instanceof Team) {\n if ($team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {\n $types = self::TYPES;\n }\n if ($team->hasFeature(FeatureEnum::ASK_JIMINNY_REPORTS)) {\n $types[] = ['id' => self::TYPE_ASK_JIMINNY, 'name' => 'Ask Jiminny'];\n }\n } else {\n $types = self::TYPES;\n }\n\n if ($shortVersion) {\n return [\n 'id' => 'report_type',\n 'label' => 'Report Type',\n 'options' => $types,\n ];\n }\n\n return [\n 'id' => 'report_type',\n 'label' => 'Report Type',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => $types,\n 'value' => $value,\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getFrequencyFieldData(?string $value = null): array\n {\n return [\n 'id' => 'frequency',\n 'label' => 'Frequency',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => self::FREQUENCIES,\n 'value' => $value,\n 'dependencies' => ['period'],\n 'dependsOn' => [],\n ];\n }\n\n public function getPeriodFieldData(?string $valueStartDate = null, ?string $valueEndDate = null): array\n {\n return [\n 'id' => 'period',\n 'label' => 'Select one-off period',\n 'inputType' => InputTypeEnum::DATE_RANGE,\n 'required' => true,\n 'placeholder' => 'Select',\n 'value' => ['startDate' => $valueStartDate, 'endDate' => $valueEndDate],\n 'queryParams' => [\n 'startDate' => 'start_date_period',\n 'endDate' => 'end_date_period',\n ],\n 'dependencies' => [],\n 'dependsOn' => ['frequency'],\n ];\n }\n\n public function getActivityTypesFieldData(?Team $team = null, array $value = [], array $teamsFilter = []): array\n {\n return $this->activityTypeService->getActivityTypeFieldData(team: $team, value: $value, groupIds: $teamsFilter);\n }\n\n public function getDealStageAtCallFieldData(?Team $team = null, array $value = []): array\n {\n return $this->dealStagesService->getDealStageAtCallFieldData(team: $team, value: $value);\n }\n\n public function getCurrentDealStageFieldData(?Team $team = null, array $value = []): array\n {\n return $this->dealStagesService->getCurrentDealStageFieldData(team: $team, value: $value);\n }\n\n public function getDealValueFieldData(?int $valueMin = null, ?int $valueMax = null): array\n {\n return [\n 'id' => 'deal_value',\n 'label' => 'Deal Value',\n 'inputType' => InputTypeEnum::INTEGER_RANGE,\n 'required' => false,\n 'value' => ['min' => $valueMin, 'max' => $valueMax],\n 'queryParams' => [\n 'min' => 'min_deal_value',\n 'max' => 'max_deal_value',\n ],\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getCallTypeFieldData(bool $conferenceOn = false, bool $dialerOn = false): array\n {\n $value = [];\n $conferenceOn && $value[] = self::CALL_TYPE_CONFERENCE;\n $dialerOn && $value[] = self::CALL_TYPE_DIALER;\n\n return [\n 'id' => 'call_type',\n 'label' => 'Call Type',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'required' => true,\n 'options' => [\n self::CALL_TYPE_CONFERENCE,\n self::CALL_TYPE_DIALER,\n ],\n 'value' => $value,\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getMediaTypeFieldData(?AutomatedReport $report = null): array\n {\n $value = [];\n\n if ($report) {\n $value = $this->transformMediaTypes($report);\n }\n\n return [\n 'id' => 'media_types',\n 'label' => 'Export as',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'required' => true,\n 'options' => self::MEDIA_TYPE_OBJECTS,\n 'value' => $value,\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getCallDurationFieldData(?int $valueMin = null, ?int $valueMax = null): array\n {\n return [\n 'id' => 'call_duration',\n 'label' => 'Call Duration',\n 'inputType' => InputTypeEnum::INTEGER_RANGE,\n 'required' => false,\n 'value' => ['min' => $valueMin, 'max' => $valueMax],\n 'queryParams' => [\n 'min' => 'min_call_duration',\n 'max' => 'max_call_duration',\n ],\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getRecipientsFieldData(?Team $team = null, array $value = []): array\n {\n return $this->recipientsService->getRecipientsFieldData(team: $team, value: $value);\n }\n\n public function getJiminnyRecipientsFieldData(array $value = []): array\n {\n return $this->recipientsService->getJiminnyRecipientsFieldData($value);\n }\n\n public function getAdditionalPromptInputFieldData(?string $value = null): array\n {\n return [\n 'id' => 'additional_prompt_input',\n 'label' => 'Special requirements',\n 'inputType' => InputTypeEnum::TEXTAREA,\n 'required' => false,\n 'placeholder' => 'What should be the focus of the report?',\n 'value' => $value,\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getCustomReportNameFieldData(?string $value = null): array\n {\n return [\n 'id' => 'custom_name',\n 'label' => 'Custom report name',\n 'inputType' => InputTypeEnum::TEXT,\n 'required' => false,\n 'placeholder' => 'Enter custom name',\n 'value' => $value,\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n // data providers\n public function getTeams(): array\n {\n $teams = $this->teamRepository->getTeamsForKiosk(status: Team::STATUS_ACTIVE);\n\n $teamData = [];\n foreach ($teams as $team) {\n if (! $team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {\n continue;\n }\n\n $teamData[] = $this->transformTeam($team);\n }\n\n return $teamData;\n }\n\n public function getTeamGroups(string $teamUuid): array\n {\n $data = [];\n $team = $this->getTeam($teamUuid);\n\n if ($team !== null) {\n $groups = $team->groups()->get();\n\n foreach ($groups as $group) {\n $data[] = [\n 'id' => $group->getUuid(),\n 'name' => $group->getName(),\n ];\n }\n }\n\n return $data;\n }\n\n public function getTeamsGroupsOptions(array $filterTeamUuids = []): array\n {\n $data = [];\n $teams = $this->getTeams();\n\n foreach ($teams as $team) {\n if (! empty($filterTeamUuids) && ! in_array($team['id'], $filterTeamUuids, true)) {\n continue;\n }\n\n $data[] = [\n 'label' => $team['name'],\n 'groups' => $this->getTeamGroups($team['id']),\n ];\n }\n\n return $data;\n }\n\n public function getTeam(string $teamUuid): ?Team\n {\n return $this->teamRepository->idOrUuid($teamUuid);\n }\n\n public function getTeamById(int $teamId): ?Team\n {\n return $this->teamRepository->find($teamId);\n }\n\n public function getGroupsUuids(AutomatedReport $report): array\n {\n $uuids = [];\n $reportGroups = $report->getGroups();\n foreach ($reportGroups as $groupId) {\n if ($group = $this->groupRepository->find($groupId)) {\n $uuids[] = $group->getUuid();\n }\n }\n\n return $uuids;\n }\n\n public function getPlaybookCategoriesUuids(AutomatedReport $report): array\n {\n $uuids = [];\n $playbookCategories = $report->getPlaybookCategories();\n foreach ($playbookCategories as $id) {\n if ($category = $this->playbookCategoryRepository->find($id)) {\n $uuids[] = $category->getUuid();\n }\n }\n\n return $uuids;\n }\n\n public function getDealAtCallStagesUuids(AutomatedReport $report): array\n {\n $uuids = [];\n $reportStages = $report->getDealAtCallStages();\n foreach ($reportStages as $id) {\n if ($stage = $this->stageRepository->find($id)) {\n $uuids[] = $stage->getUuid();\n }\n }\n\n return $uuids;\n }\n\n public function getCurrentDealStagesUuids(AutomatedReport $report): array\n {\n $uuids = [];\n $reportStages = $report->getCurrentDealStages();\n foreach ($reportStages as $id) {\n if ($stage = $this->stageRepository->find($id)) {\n $uuids[] = $stage->getUuid();\n }\n }\n\n return $uuids;\n }\n\n public function getUsersUuids(AutomatedReport $report): array\n {\n return $this->extractUserUuids($report->getRecipients());\n }\n\n public function getJiminnyUsersUuids(AutomatedReport $report): array\n {\n return $this->extractUserUuids($report->getJiminnyRecipients());\n }\n\n /**\n * @param array<string, mixed> $recipients\n */\n private function extractUserUuids(array $recipients): array\n {\n $userIds = $recipients['users'] ?? [];\n\n return collect($userIds)\n ->map(fn ($id) => $this->userRepository->find((int) $id))\n ->filter()\n ->map(fn (UserContract $user) => $user->getUuid())\n ->values()\n ->all();\n }\n\n // get mail data\n public function getRecipientUsers(AutomatedReport $report): array\n {\n return $this->buildRecipientUsers($report->getRecipients());\n }\n\n private function getJiminnyRecipientUsers(AutomatedReport $report): array\n {\n return $this->buildRecipientUsers($report->getJiminnyRecipients());\n }\n\n /**\n * @param array<string, mixed> $recipients\n */\n private function buildRecipientUsers(array $recipients): array\n {\n $userIds = $recipients['users'] ?? [];\n\n return collect($userIds)\n ->map(fn ($id) => $this->userRepository->find((int) $id))\n ->filter()\n ->map(fn (UserContract $user) => [\n 'email' => $user->getEmailAddress(),\n 'name' => $user->getName(),\n 'timezone' => $user->getTimezone()->getName(),\n ])\n ->values()\n ->all();\n }\n\n public function getValidRecipientUsers(AutomatedReport $report, bool $includeJiminny = false): array\n {\n if ($report->isAskJiminnyReport()) {\n $recipients = $this->resolveAskJiminnyRecipients($report);\n } else {\n $recipients = $this->getRecipientUsers($report);\n if ($includeJiminny) {\n $recipients = array_merge($recipients, $this->getJiminnyRecipientUsers($report));\n }\n }\n\n $emails = [];\n\n return array_values(array_filter(\n $recipients,\n static function ($recipient) use (&$emails) {\n if (empty($recipient['email']) || in_array($recipient['email'], $emails, true)) {\n return false;\n }\n $emails[] = $recipient['email'];\n\n return true;\n }\n ));\n }\n\n private function resolveAskJiminnyRecipients(AutomatedReport $report): array\n {\n $recipients = [];\n\n $creator = $report->getCreator();\n if ($creator !== null) {\n $recipients[] = [\n 'email' => $creator->getEmailAddress(),\n 'name' => $creator->getName(),\n 'timezone' => $creator->getTimezone()->getName(),\n ];\n }\n\n return array_merge(\n $recipients,\n $this->buildRecipientUsers($report->getRecipients()),\n $this->getGroupRecipientUsers($report),\n );\n }\n\n private function getGroupRecipientUsers(AutomatedReport $report): array\n {\n $users = [];\n foreach ($report->getGroups() as $groupId) {\n $group = $this->groupRepository->find($groupId);\n if ($group === null) {\n continue;\n }\n foreach ($group->getMembers() as $member) {\n $users[] = [\n 'email' => $member->getEmailAddress(),\n 'name' => $member->getName(),\n 'timezone' => $member->getTimezone()->getName(),\n ];\n }\n }\n\n return $users;\n }\n\n public function getReportTypeName(AutomatedReportResult $report): string\n {\n $type = $report->getReport()->getType();\n\n $getType = $this->transformReportType($type);\n\n return $getType['name'];\n }\n\n public function getReportPeriodName(AutomatedReportResult $report): string\n {\n $from = $report->getFromDate();\n $to = $report->getToDate();\n $frequency = $report->getReport()->getFrequency();\n\n if ($from === null || $to === null) {\n if (! $report->getReport()->isAskJiminnyReport()) {\n $invalidPeriod = $from === null ? 'from' : 'to';\n\n throw new ApplicationException('Report period is invalid: ' . $invalidPeriod);\n }\n\n $period = $this->calculateFromAndToDatePeriod($frequency);\n $from = $period['fromDate'];\n $to = $period['toDate'];\n }\n\n return $this->formatReportPeriodName($frequency, $from, $to);\n }\n\n private function formatReportPeriodName(string $frequency, Carbon $from, Carbon $to): string\n {\n $fromYear = $from->format('Y');\n $toYear = $to->format('Y');\n $differentYears = $fromYear !== $toYear;\n\n switch ($frequency) {\n case self::FREQUENCY_DAILY:\n return $from->format('j M Y');\n\n case self::FREQUENCY_QUARTERLY:\n // 'Jan-Mar 2025' or 'Nov 2024-Jan 2025' if years differ\n $startMonth = $from->format('M');\n $endMonth = $to->copy()->subMonth();\n $endMonthName = $endMonth->format('M');\n $endMonthYear = $endMonth->format('Y');\n\n if ($differentYears) {\n return \"{$startMonth} {$fromYear} - {$endMonthName} {$endMonthYear}\";\n }\n\n return \"{$startMonth} - {$endMonthName} {$toYear}\";\n\n case self::FREQUENCY_MONTHLY:\n // 'May 2025' - monthly reports are always within the same year\n return $from->format('M Y');\n\n case self::FREQUENCY_WEEKLY:\n // '4 - 8 Aug 2025', '27 Oct - 3 Nov 2025', or '28 Dec 2024 - 3 Jan 2025' if years differ\n $startDay = $from->format('j');\n $endDay = $to->format('j');\n $startMonth = $from->format('M');\n $endMonth = $to->format('M');\n\n if ($differentYears) {\n return \"{$startDay} {$startMonth} {$fromYear} - {$endDay} {$endMonth} {$toYear}\";\n }\n\n if ($startMonth !== $endMonth) {\n return \"{$startDay} {$startMonth} - {$endDay} {$endMonth} {$toYear}\";\n }\n\n return \"{$startDay} - {$endDay} {$endMonth} {$toYear}\";\n\n case self::FREQUENCY_ONE_OFF:\n // '2 May-31 May 2025' or '15 Dec 2024-15 Jan 2025' if years differ\n $startDay = $from->format('j');\n $startMonth = $from->format('M');\n $endDay = $to->format('j');\n $endMonth = $to->format('M');\n\n // If same month and year, use a format like '2-31 May 2025'\n if ($startMonth === $endMonth && ! $differentYears) {\n return \"{$startDay} - {$endDay} {$startMonth} {$toYear}\";\n }\n\n // If different years, include both years\n if ($differentYears) {\n return \"{$startDay} {$startMonth} {$fromYear} - {$endDay} {$endMonth} {$toYear}\";\n }\n\n // Same year but different months\n return \"{$startDay} {$startMonth} - {$endDay} {$endMonth} {$toYear}\";\n\n default:\n // Default format for unknown frequencies\n return $from->format('j M Y') . ' - ' . $to->format('j M Y');\n }\n }\n\n public function getReportTeamsName(AutomatedReportResult $report): string\n {\n $groups = $report->getGroups();\n\n if (empty($groups)) {\n return 'All';\n }\n\n // Get group names from repository\n $groupNames = [];\n foreach ($groups as $groupId) {\n $group = $this->groupRepository->find($groupId);\n if ($group) {\n $groupNames[] = $group->getName();\n }\n }\n\n if (count($groupNames) === 1) {\n // Single team format\n $teamsName = $groupNames[0];\n } else {\n // Multiple teams format\n $teamsName = implode(', ', $groupNames);\n }\n\n return $teamsName;\n }\n\n public function getReportFileName(AutomatedReportResult $report): string\n {\n $customName = $report->getReport()->getCustomName();\n $periodName = $this->getReportPeriodName($report);\n $filenameSuffix = $this->getFilenameSuffix($report);\n\n if ($customName) {\n if ($filenameSuffix) {\n $customName .= \" {$filenameSuffix}\";\n }\n\n return $this->sanitizeFileName(\"{$customName} - {$periodName}\");\n }\n\n $baseName = $this->getReportTypeName($report);\n\n if ($filenameSuffix) {\n $baseName .= \" {$filenameSuffix}\";\n }\n\n return $this->sanitizeFileName(\"{$baseName} - {$periodName} - {$this->getReportTeamsName($report)}\");\n }\n\n public function getReportFileNameWithExtension(AutomatedReportResult $result): string\n {\n $extension = $this->getMediaTypeMetadata($result)['extension'];\n\n return $this->getReportFileName($result) . '.' . $extension;\n }\n\n public function sanitizeFileName(string $fileName): string\n {\n return str_replace(['/', '\\\\'], '-', $fileName);\n }\n\n public function isUserRecipientOfReport(User $user, AutomatedReport $report): bool\n {\n $recipients = array_map('intval', $report->getRecipients()['users'] ?? []);\n\n return in_array($user->getId(), $recipients);\n }\n\n public function transformReportResults(Collection $automatedReportResults): array\n {\n $data = [];\n foreach ($automatedReportResults as $automatedReportResult) {\n /** @var AutomatedReportResult $automatedReportResult */\n\n $report = $automatedReportResult->getReport();\n\n $createdBy = $report->getCreator();\n $creator = [\n 'id' => $createdBy?->getUuid(),\n 'name' => $createdBy?->getName(),\n 'email' => $createdBy?->getEmailAddress(),\n 'photoUrl' => $createdBy?->getPhotoUrl(),\n ];\n\n $data[] = [\n 'id' => $automatedReportResult->getUuid(),\n 'name' => $automatedReportResult->getName(),\n 'frequency' => $this->transformFrequency($report->getFrequency()),\n 'recipients' => [\n ...array_values($this->transformGroups(team: $report->getTeam(), groupsIds: $report->getGroups())),\n ...array_values($this->transformRecipients($report->getRecipients())),\n ],\n 'report_type' => $this->transformReportType($report->getType()),\n 'media_type' => $automatedReportResult->getMediaType(),\n 'downloadUrl' => $this->generateReportResultDownloadUrl($automatedReportResult),\n 'viewUrl' => $this->generateReportResultViewUrl($automatedReportResult),\n 'generated_at' => $automatedReportResult->getGeneratedAt()?->toIso8601String(),\n 'creator' => $creator,\n ];\n }\n\n return $data;\n }\n\n public function hasCallTypeConference(AutomatedReport $report): bool\n {\n return in_array(self::CALL_TYPE_CONFERENCE['id'], $report->getCallTypes(), true);\n }\n\n public function hasCallTypeDialer(AutomatedReport $report): bool\n {\n return in_array(self::CALL_TYPE_DIALER['id'], $report->getCallTypes(), true);\n }\n\n // transformers\n private function transformTeam(Team $team): array\n {\n if (! $team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {\n return [];\n }\n\n return [\n 'id' => $team->getUuid(),\n 'name' => $team->getName(),\n ];\n }\n\n private function transformReportFullView(AutomatedReport $report): array\n {\n $base = $this->transformReportBase($report);\n\n return $report->getType() === self::TYPE_ASK_JIMINNY\n ? $base + $this->transformAskJiminnyFields($report)\n : $base + $this->transformStandardReportFields($report);\n }\n\n private function transformReportBase(AutomatedReport $report): array\n {\n return [\n 'id' => $report->getUuid(),\n 'organization' => $this->transformOrganization(team: $report->getTeam()),\n 'report_type' => $this->transformReportType($report->getType()),\n 'frequency' => $this->transformFrequency($report->getFrequency()),\n ];\n }\n\n private function transformStandardReportFields(AutomatedReport $report): array\n {\n $team = $report->getTeam();\n\n return [\n 'report_enabled' => $report->getStatus(),\n 'start_date_period' => $report->getFrom()?->format('Y-m-d H:i:s'),\n 'end_date_period' => $report->getTo()?->format('Y-m-d H:i:s'),\n 'deal_value_min' => $report->getDealValueMin(),\n 'deal_value_max' => $report->getDealValueMax(),\n 'call_types' => $this->transformCallType($report->getCallTypes()),\n 'media_types' => $this->transformMediaTypes($report),\n 'call_duration_min' => $this->transformDurationToMinutes($report->getCallDurationMin()),\n 'call_duration_max' => $this->transformDurationToMinutes($report->getCallDurationMax()),\n 'teams' => $this->transformGroups(team: $team, groupsIds: $report->getGroups()),\n 'deal_at_call_stages' => $this->transformStages(team: $team, stagesIds: $report->getDealAtCallStages()),\n 'current_deal_stages' => $this->transformStages(team: $team, stagesIds: $report->getCurrentDealStages()),\n 'recipients' => $this->transformRecipients($report->getRecipients()),\n 'created_by' => $this->transformCreator($report->getCreator()),\n 'additional_prompt_input' => $report->getAdditionalPromptInput(),\n 'custom_name' => $report->getCustomName(),\n 'created_at' => $report->getCreatedAt()->format('Y-m-d H:i:s'),\n 'updated_at' => $report->getUpdatedAt()->format('Y-m-d H:i:s'),\n 'deleted_at' => $report->getDeletedAt()?->format('Y-m-d H:i:s'),\n ];\n }\n\n private function transformAskJiminnyFields(AutomatedReport $report): array\n {\n $team = $report->getTeam();\n $creatorId = $report->getAttribute('created_by');\n $explicitUserIds = array_values(array_filter(\n $report->getRecipients()['users'] ?? [],\n static fn ($id) => $id !== $creatorId\n ));\n\n return [\n 'report_name' => $report->getCustomName(),\n 'enabled' => $report->getStatus(),\n 'share_teams' => $this->transformGroups(team: $team, groupsIds: $report->getGroups()),\n 'share_users' => $this->transformRecipients(['users' => $explicitUserIds]),\n 'saved_search' => $this->transformSafeSearch($report->getSavedSearch()),\n 'ask_jiminny_prompt' => $this->transformAskJiminnyPrompt($report->getAskAnythingPrompt()),\n 'expires_on' => $report->getExpiresAt()?->format('Y-m-d'),\n ];\n }\n\n private function transformOrganization(?Team $team): array\n {\n return [\n 'id' => $team?->getUuid(),\n 'name' => $team?->getName(),\n ];\n }\n\n private function transformReportType(string $type): array\n {\n foreach (self::ALL_TYPES as $typeItem) {\n if ($typeItem['id'] === $type) {\n return $typeItem;\n }\n }\n\n return [];\n }\n\n private function transformCallType(array $types): array\n {\n $result = [];\n $callTypes = [self::CALL_TYPE_CONFERENCE, self::CALL_TYPE_DIALER];\n\n foreach ($types as $type) {\n foreach ($callTypes as $callTypeItem) {\n if ($callTypeItem['id'] === $type) {\n $result[] = $callTypeItem;\n\n break;\n }\n }\n }\n\n return $result;\n }\n\n private function transformMediaTypes(AutomatedReport $report): array\n {\n $values = [];\n\n foreach ($report->getMediaTypes() as $mediaType) {\n if (! in_array($mediaType, self::MEDIA_TYPES, true)) {\n continue;\n }\n\n $values[] = match ($mediaType) {\n self::MEDIA_TYPE_PDF => self::MEDIA_TYPE_OBJECT_PDF,\n self::MEDIA_TYPE_PODCAST => self::MEDIA_TYPE_OBJECT_PODCAST,\n };\n }\n\n return $values;\n }\n\n private function transformFrequency(string $frequency): array\n {\n foreach (self::ALL_FREQUENCIES as $frequencyItem) {\n if ($frequencyItem['id'] === $frequency) {\n return $frequencyItem;\n }\n }\n\n return [];\n }\n\n public function transformDurationToMinutes(?int $duration): ?int\n {\n if (! $duration) {\n return null;\n }\n\n return (int) ($duration / 60);\n }\n\n private function transformGroups(?Team $team, array $groupsIds): array\n {\n if (empty($groupsIds) || ! $team) {\n return [];\n }\n\n $data = [];\n foreach ($groupsIds as $groupId) {\n $group = $team->groups()->where('id', $groupId)->first();\n\n if ($group) {\n $data[] = [\n 'id' => $group->getUuid(),\n 'name' => $group->getName(),\n 'photoUrl' => $group->getPhotoUrl(),\n ];\n }\n }\n\n return $data;\n }\n\n private function transformStages(?Team $team, array $stagesIds): array\n {\n if (empty($stagesIds) || ! $team) {\n return [];\n }\n\n $data = [];\n foreach ($stagesIds as $stageId) {\n $stage = $team->stages()->where('id', $stageId)->first();\n\n if ($stage) {\n $data[] = [\n 'id' => $stage->getUuid(),\n 'name' => $stage->getName(),\n ];\n }\n }\n\n return $data;\n }\n\n private function transformRecipients(array $recipients): array\n {\n $users = [];\n foreach ($recipients['users'] ?? [] as $userId) {\n $users[] = $this->transformUser($userId);\n }\n\n return $users;\n }\n\n private function transformCreator(?User $user): ?array\n {\n if ($user === null) {\n return null;\n }\n\n return $this->transformUser($user->getId());\n }\n\n private function transformAskJiminnyPrompt(?AskAnythingPrompt $prompt): ?array\n {\n if ($prompt === null) {\n return null;\n }\n\n return [\n 'id' => $prompt->getUuid(),\n 'name' => $prompt->getTitle(),\n ];\n }\n\n private function transformSafeSearch(?Search $search): ?array\n {\n if ($search === null) {\n return null;\n }\n\n return [\n 'id' => $search->getUuid(),\n 'name' => $search->getName(),\n ];\n }\n\n private function transformUser(int $userId): array\n {\n /* @var ?User $user */\n $user = $this->userRepository->find($userId);\n\n return [\n 'id' => $user?->getUuid(),\n 'name' => $user?->getName(),\n 'email' => $user?->getEmailAddress(),\n 'photoUrl' => $user?->getPhotoUrl(),\n ];\n }\n\n public function create(array $data): array\n {\n $validatedData = $this->validateAndTransformData($data);\n $validatedData['created_by'] = auth()->id();\n\n $automatedReport = $this->automatedReportsRepository->create($validatedData);\n\n $this->generateOneOffReport($automatedReport);\n\n return $this->transformReportFullView($automatedReport);\n }\n\n public function update(string $uuid, array $data): array\n {\n $validatedData = $this->validateAndTransformData($data);\n $report = $this->automatedReportsRepository->findByUuid($uuid);\n\n if (! $report) {\n throw new InvalidArgumentException('Report not found');\n }\n\n $oldCustomName = $report->getCustomName();\n\n $automatedReport = $this->automatedReportsRepository->update($report, $validatedData);\n\n if ($oldCustomName !== $automatedReport->getCustomName()) {\n $this->updateResultNames($automatedReport);\n }\n\n $this->generateOneOffReport($automatedReport);\n\n return $this->transformReportFullView($automatedReport);\n }\n\n /**\n * Create an Ask Jiminny report.\n */\n public function createAskJiminnyReport(array $data, User $creator): array\n {\n $validatedData = $this->validateAskJiminnyReportData($data, $creator);\n $validatedData['created_by'] = $creator->getId();\n\n $automatedReport = $this->automatedReportsRepository->create($validatedData);\n\n return $this->transformReportFullView($automatedReport);\n }\n\n /**\n * Update an Ask Jiminny report.\n */\n public function updateAskJiminnyReport(AutomatedReport $report, array $data, User $user): array\n {\n if (! $report->isAskJiminnyReport()) {\n throw new InvalidArgumentException('Report is not an Ask Jiminny report');\n }\n\n $validatedData = $this->validateAskJiminnyReportData($data, $user);\n\n $oldCustomName = $report->getCustomName();\n\n $automatedReport = $this->automatedReportsRepository->update($report, $validatedData);\n\n if ($oldCustomName !== $automatedReport->getCustomName()) {\n $this->updateResultNames($automatedReport);\n }\n\n return $this->transformReportFullView($automatedReport);\n }\n\n public function updateAskJiminnyReportStatus(AutomatedReport $report, bool $status): array\n {\n $this->automatedReportsRepository->update($report, ['status' => $status]);\n\n return $this->transformReportFullView($report->fresh());\n }\n\n /**\n * Validate and transform data for Ask Jiminny reports.\n */\n private function validateAskJiminnyReportData(array $data, User $user): array\n {\n // Validate name\n $name = trim($data['report_name'] ?? '');\n if (empty($name)) {\n throw new InvalidArgumentException('Report name is required');\n }\n if (mb_strlen($name) > 50) {\n throw new InvalidArgumentException('Report name must be 50 characters or less');\n }\n\n // Validate frequency (only daily, weekly, monthly for Ask Jiminny)\n $frequency = $data['frequency'] ?? null;\n $askJiminnyFrequencies = [self::FREQUENCY_DAILY, self::FREQUENCY_WEEKLY, self::FREQUENCY_MONTHLY];\n if (! in_array($frequency, $askJiminnyFrequencies, true)) {\n throw new InvalidArgumentException('Frequency must be daily, weekly, or monthly');\n }\n\n // Validate expiration date\n $expiresAt = $data['expires_on'] ?? null;\n if (empty($expiresAt)) {\n throw new InvalidArgumentException('Expiration date is required');\n }\n\n try {\n $expiresAtDate = Carbon::parse($expiresAt);\n } catch (InvalidFormatException $e) {\n throw new InvalidArgumentException('Expiration date format is invalid');\n }\n $maxExpiration = Carbon::now()->addYear();\n if ($expiresAtDate->gt($maxExpiration)) {\n throw new InvalidArgumentException('Expiration date cannot be more than 1 year from now');\n }\n if ($expiresAtDate->isPast()) {\n throw new InvalidArgumentException('Expiration date cannot be in the past');\n }\n\n // Validate saved search\n $activitySearchId = $data['saved_search'] ?? null;\n if (empty($activitySearchId)) {\n throw new InvalidArgumentException('Saved search is required');\n }\n $savedSearch = $this->activitySearchRepository->findByUuidAndUser($activitySearchId, $user);\n if (! $savedSearch) {\n throw new InvalidArgumentException('Saved search not found or does not belong to you');\n }\n\n // Validate saved prompt\n $askAnythingPromptId = $data['ask_jiminny_prompt'] ?? null;\n if (empty($askAnythingPromptId)) {\n throw new InvalidArgumentException('Ask Jiminny prompt is required');\n }\n $prompt = $this->askAnythingRepository->getPromptByUuid($askAnythingPromptId);\n if (! $prompt) {\n throw new InvalidArgumentException('Ask Jiminny prompt not found');\n }\n\n // Validate status\n $status = $data['enabled'] ?? false;\n\n $recipientUserIds = [$user->getId()];\n\n if (! empty($data['share_users'])) {\n $sharedUserIds = $this->validateAndGetUserIdsByTeam(\n $user->team,\n (array) $data['share_users']\n );\n $recipientUserIds = array_merge($recipientUserIds, $sharedUserIds);\n }\n\n $sharedGroupIds = [];\n if (! empty($data['share_teams'])) {\n $sharedGroupIds = $this->validateAndGetGroupIds($user->team, (array) $data['share_teams']);\n }\n\n $recipientUserIds = array_values(array_unique($recipientUserIds));\n\n return [\n 'team_id' => $user->getTeamId(),\n 'type' => self::TYPE_ASK_JIMINNY,\n 'status' => (bool) $status,\n 'frequency' => $frequency,\n 'custom_name' => $name,\n 'activity_search_id' => $savedSearch->getId(),\n 'ask_anything_prompt_id' => $prompt->getId(),\n 'expires_at' => $expiresAtDate->toDateString(),\n 'media_types' => [self::MEDIA_TYPE_PDF],\n 'call_types' => [],\n 'recipients' => ['users' => $recipientUserIds],\n 'groups' => $sharedGroupIds,\n ];\n }\n\n public static function getAskJiminnyFrequencies(): array\n {\n return array_map(static function ($frequency) {\n return $frequency['id'];\n }, self::ASK_JIMINNY_FREQUENCIES);\n }\n\n public function getAskJiminnyReportFilters(User $user): array\n {\n $savedSearches = $this->activitySearchRepository->findByUserOrderedByName($user)\n ->map(fn (Search $search) => [\n 'id' => $search->getUuid(),\n 'name' => $search->getName(),\n ])\n ->values()->all();\n\n $prompts = collect(\n $this->askAnythingPromptService->get($user, AskAnythingPromptTarget::on_demand)\n )->map(fn (AskAnythingPromptDto $prompt) => [\n 'id' => $prompt->id,\n 'name' => $prompt->title,\n ])->values()->all();\n\n return [\n [\n 'id' => 'prompt',\n 'label' => 'Prompt',\n 'options' => $prompts,\n ],\n [\n 'id' => 'saved_search',\n 'label' => 'Saved Search',\n 'options' => $savedSearches,\n ],\n ];\n }\n\n public function getAskJiminnyReportFormData(User $user, ?AutomatedReport $report = null): array\n {\n $team = $user->getTeam();\n $userTimezone = $user->getTimezone();\n\n $savedSearches = $this->activitySearchRepository->findByUserOrderedByName($user)\n ->map(fn (Search $search) => [\n 'id' => $search->getUuid(),\n 'name' => $search->getName(),\n ])\n ->values()->all();\n\n $prompts = collect(\n $this->askAnythingPromptService->get($user, AskAnythingPromptTarget::on_demand)\n )->map(fn (AskAnythingPromptDto $prompt) => [\n 'id' => $prompt->id,\n 'name' => $prompt->title,\n ])->values()->all();\n\n $teamGroups = $this->groupRepository->getAllByTeam($team)->map(fn ($group) => [\n 'id' => $group->getUuid(),\n 'name' => $group->getName(),\n ])->values()->all();\n\n $shareUsers = $this->recipientsService->getRecipientsFieldData(team: $team)['options'] ?? [];\n\n $sharedTeamsValue = [];\n $sharedUsersValue = [];\n if ($report) {\n $sharedTeamsValue = $this->transformGroups($team, $report->getGroups());\n\n $recipientUserIds = $report->getRecipients()['users'] ?? [];\n $creatorId = $report->getAttribute('created_by');\n $sharedUserIds = array_values(array_filter(\n $recipientUserIds,\n static fn ($id) => $id !== $creatorId\n ));\n $sharedUsersValue = collect($sharedUserIds)\n ->map(fn ($id) => $this->userRepository->find((int) $id))\n ->filter()\n ->map(fn (User $u) => [\n 'id' => $u->getUuid(),\n 'name' => $u->getName(),\n ])\n ->values()\n ->all();\n }\n\n return [\n 'fields' => [\n [\n 'id' => 'enabled',\n 'inputType' => InputTypeEnum::TOGGLE,\n 'label' => '',\n 'value' => $report?->getStatus() ?? false,\n ],\n [\n 'id' => 'report_name',\n 'inputType' => InputTypeEnum::TEXT,\n 'label' => 'Name',\n 'placeholder' => 'Enter name',\n 'required' => true,\n 'validation' => ['maxLength' => 50],\n 'value' => $report?->getCustomName() ?? '',\n ],\n [\n 'id' => 'frequency',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'label' => 'Frequency',\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => self::ASK_JIMINNY_FREQUENCIES,\n 'value' => $report ? $this->transformFrequency($report->getFrequency()) : null,\n ],\n [\n 'id' => 'expires_on',\n 'inputType' => InputTypeEnum::DATE,\n 'label' => 'Expires on',\n 'required' => true,\n 'placeholder' => 'Select',\n 'validation' => [\n 'minDate' => now($userTimezone)->toDateString(),\n 'maxDate' => now($userTimezone)->addYear()->toDateString(),\n ],\n 'value' => $report?->getExpiresAt()?->toDateString(),\n ],\n [\n 'id' => 'share_teams',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'label' => 'Team',\n 'required' => false,\n 'placeholder' => 'Select',\n 'options' => $teamGroups,\n 'value' => $sharedTeamsValue,\n ],\n [\n 'id' => 'share_users',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'label' => 'Team member',\n 'required' => false,\n 'placeholder' => 'Select',\n 'groupLabelKey' => 'label',\n 'groupValuesKey' => 'users',\n 'optionLabelKey' => 'name',\n 'optionValueKey' => 'id',\n 'options' => $shareUsers,\n 'value' => $sharedUsersValue,\n ],\n [\n 'id' => 'saved_search',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'label' => 'Saved search',\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => $savedSearches,\n 'value' => $report && $report->getSavedSearch() ? [\n 'id' => $report->getSavedSearch()->getUuid(),\n 'name' => $report->getSavedSearch()->getName(),\n ] : null,\n ],\n [\n 'id' => 'ask_jiminny_prompt',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'label' => 'Ask Jiminny prompt',\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => $prompts,\n 'value' => $report && $report->getAskAnythingPrompt() ? [\n 'id' => $report->getAskAnythingPrompt()->getUuid(),\n 'name' => $report->getAskAnythingPrompt()->getTitle(),\n ] : null,\n ],\n ],\n ];\n }\n\n private function updateResultNames(AutomatedReport $automatedReport): void\n {\n $results = $this->automatedReportsRepository->getResultsByReport($automatedReport);\n\n foreach ($results as $result) {\n $result->update(['name' => $this->getReportFileName($result)]);\n }\n }\n\n public function updateStatus(string $uuid, array $data): array\n {\n $automatedReport = $this->automatedReportsRepository->findByUuid($uuid);\n\n if (! $automatedReport) {\n throw new ModelNotFoundException('Report not found');\n }\n\n $status = $this->validateReportStatus($data['report_enabled'] ?? null);\n $automatedReport->update([\n 'status' => $status,\n ]);\n\n $this->generateOneOffReport($automatedReport);\n\n return $this->transformReportFullView($automatedReport);\n }\n\n private function generateOneOffReport(AutomatedReport $automatedReport): void\n {\n // the scheduler handles all the other frequency types\n if ($automatedReport->getStatus() === false || $automatedReport->getFrequency() !== self::FREQUENCY_ONE_OFF) {\n return;\n }\n\n $this->dispatcher->dispatch(new RequestGenerateReportJob($automatedReport->getUuid()));\n }\n\n public function getReport(string $uuid): AutomatedReport\n {\n $automatedReport = $this->automatedReportsRepository->findByUuid($uuid);\n\n if (! $automatedReport) {\n throw new ModelNotFoundException('Report not found');\n }\n\n return $automatedReport;\n }\n\n public function get(string $uuid): array\n {\n $automatedReport = $this->getReport($uuid);\n\n return $this->transformReportFullView($automatedReport);\n }\n\n public function list(string $sortColumn = 'created_at', string $sortDirection = 'desc'): array\n {\n $results = [];\n $collection = $this->automatedReportsRepository->getAllStandardReports($sortColumn, $sortDirection);\n\n /** @var AutomatedReport $report */\n foreach ($collection as $report) {\n $results[] = $this->transformReportFullView($report);\n }\n\n return ['data' => $results];\n }\n\n public function listAskJiminnyReports(\n User $user,\n string $sortColumn = 'created_at',\n string $sortDirection = 'desc'\n ): array {\n $results = [];\n $collection = $this->automatedReportsRepository->getAskJiminnyReportsByUser($user, $sortColumn, $sortDirection);\n\n /** @var AutomatedReport $report */\n foreach ($collection as $report) {\n $results[] = $this->transformReportFullView($report);\n }\n\n return ['data' => $results];\n }\n\n public function delete(string $uuid): void\n {\n $automatedReport = $this->automatedReportsRepository->findByUuid($uuid);\n\n if (! $automatedReport) {\n throw new ModelNotFoundException('Report not found');\n }\n\n $automatedReport->delete();\n }\n\n public function createReportResult(AutomatedReport $automatedReport, array $data = []): AutomatedReportResult\n {\n return $this->automatedReportsRepository->createResult(\n array_merge(\n [\n 'report_id' => $automatedReport->getId(),\n 'status' => AutomatedReportResult::STATUS_DEFAULT,\n ],\n $data\n )\n );\n }\n\n public function getReportResult(string $resultUuid): AutomatedReportResult\n {\n $report = $this->automatedReportsRepository->findResultByUuid($resultUuid);\n\n if (! $report) {\n throw new ModelNotFoundException('Report Result not found');\n }\n\n return $report;\n }\n\n public function findChildResult(AutomatedReportResult $result, string $type): ?AutomatedReportResult\n {\n return $this->automatedReportsRepository->findChildResult($result, $type);\n }\n\n // prophet API calls\n /**\n * @throws ApplicationException\n */\n public function getGenerateReportPayload(AutomatedReport $automatedReport, string $reportResultUuid): array\n {\n $period = $this->calculateFromAndToDate($automatedReport);\n $fromDate = $period['fromDate'];\n $toDate = $period['toDate'];\n\n return [\n 'team_id' => $automatedReport->getTeamId(),\n 'request_id' => $reportResultUuid,\n 'report_type' => $automatedReport->getType(),\n 'media_types' => $automatedReport->getMediaTypes(),\n 'from_date' => $fromDate->startOfDay()->format(DateTimeInterface::RFC3339),\n 'to_date' => $toDate->endOfDay()->format(DateTimeInterface::RFC3339),\n 'group_ids' => $automatedReport->getGroups(),\n 'call_deal_stage' => $automatedReport->getDealAtCallStages(),\n 'current_deal_stage' => $automatedReport->getCurrentDealStages(),\n 'deal_min_value' => $automatedReport->getDealValueMin(),\n 'deal_max_value' => $automatedReport->getDealValueMax(),\n 'call_types' => $automatedReport->getCallTypes(),\n 'call_duration_min_seconds' => $automatedReport->getCallDurationMin(),\n 'call_duration_max_seconds' => $automatedReport->getCallDurationMax(),\n 'special_requirements' => $automatedReport->getAdditionalPromptInput(),\n 'callback_url' => $this->getCallbackUrl(),\n 'report_period' => $this->formatReportPeriodName(\n $automatedReport->getFrequency(),\n $fromDate,\n $toDate,\n ),\n 'playbook_categories' => $automatedReport->getPlaybookCategories(),\n 'custom_name' => $automatedReport->getCustomName(),\n ];\n }\n\n // $inputPayload - FE payload structure\n public function getActivitiesCountPayload(array $inputPayload): array\n {\n // Use validateAndTransformData to validate and normalize input\n $validatedData = $this->validateAndTransformData($inputPayload);\n $period = $this->calculateFromAndToDatePeriod(\n $validatedData['frequency'],\n Carbon::parse($validatedData['from']),\n Carbon::parse($validatedData['to']),\n );\n $fromDate = $period['fromDate'];\n $toDate = $period['toDate'];\n\n // Create payload similar to getGenerateReportPayload\n return [\n 'team_id' => $validatedData['team_id'],\n 'group_ids' => $validatedData['groups'] ?? [],\n 'report_type' => $validatedData['type'],\n 'from_date' => $fromDate->format(DateTimeInterface::RFC3339),\n 'to_date' => $toDate->format(DateTimeInterface::RFC3339),\n 'call_deal_stage' => $validatedData['deal_at_call_stages'] ?? [],\n 'current_deal_stage' => $validatedData['current_deal_stages'] ?? [],\n 'deal_min_value' => $validatedData['deal_value_min'] ?? null,\n 'deal_max_value' => $validatedData['deal_value_max'] ?? null,\n 'call_types' => $validatedData['call_types'],\n 'call_duration_min_seconds' => $validatedData['call_duration_min'] ?? null,\n 'call_duration_max_seconds' => $validatedData['call_duration_max'] ?? null,\n 'special_requirements' => $validatedData['additional_prompt_input'] ?? null,\n 'playbook_categories' => $validatedData['playbook_categories'] ?? [],\n 'request_id' => null,\n 'callback_url' => null,\n ];\n }\n\n public function shouldSendReport(array $users, ?CarbonInterface $generatedAt = null): bool\n {\n if (empty($users)) {\n return false;\n }\n\n $earliestTz = collect($users)\n ->mapWithKeys(function (array $user) {\n $tz = new DateTimeZone($user['timezone']);\n $nowUtc = new DateTime('now', new DateTimeZone('UTC'));\n $offset = $tz->getOffset($nowUtc);\n\n return [$user['timezone'] => $offset];\n })\n ->sortDesc()\n ->keys()\n ->first();\n\n $now = Carbon::now($earliestTz);\n $isScheduledTime = (int) $now->format('H') === self::SENT_REPORT_AT_HOURS;\n\n if ($isScheduledTime) {\n return true;\n }\n\n return $this->hasPassedScheduledTime($generatedAt, $earliestTz);\n }\n\n public function hasPassedScheduledTime(?CarbonInterface $generatedAt, string $timezone): bool\n {\n if ($generatedAt === null) {\n return false;\n }\n\n $now = Carbon::now($timezone);\n $scheduledTime = $now->copy()->setTime(self::SENT_REPORT_AT_HOURS, 0, 0);\n\n if ($now->hour < self::SENT_REPORT_AT_HOURS) {\n $scheduledTime = $scheduledTime->subDay();\n }\n\n $scheduledTimeUtc = $scheduledTime->copy()->utc();\n $generatedAtUtc = $generatedAt->copy()->utc();\n $nowUtc = $now->copy()->utc();\n\n return $generatedAtUtc->lt($scheduledTimeUtc) && $nowUtc->gt($scheduledTimeUtc);\n }\n\n public function calculateFromAndToDatePeriod(\n string $frequency,\n ?Carbon $fromDate = null,\n ?Carbon $toDate = null\n ): array {\n if ($frequency === self::FREQUENCY_ONE_OFF) {\n return [\n 'fromDate' => $fromDate,\n 'toDate' => $toDate,\n ];\n }\n\n $now = Carbon::now();\n\n return match ($frequency) {\n self::FREQUENCY_DAILY => [\n 'fromDate' => $now->copy()->subDay()->startOfDay(),\n 'toDate' => $now->copy()->subDay()->endOfDay(),\n ],\n self::FREQUENCY_WEEKLY => [\n 'fromDate' => $now->copy()->subWeeks(1)->startOfDay(),\n 'toDate' => $now->copy()->subDay()->endOfDay(),\n ],\n self::FREQUENCY_MONTHLY => [\n 'fromDate' => $now->copy()->subMonths(1)->startOfDay(),\n 'toDate' => $now->copy()->subDay()->endOfDay(),\n ],\n self::FREQUENCY_QUARTERLY => [\n 'fromDate' => $now->copy()->subMonths(3)->startOfDay(),\n 'toDate' => $now->copy()->subDay()->endOfDay(),\n ],\n default => throw new InvalidArgumentException(\"Unsupported frequency: {$frequency}\"),\n };\n }\n\n private function calculateFromAndToDate(AutomatedReport $automatedReport): array\n {\n return $this->calculateFromAndToDatePeriod(\n $automatedReport->getFrequency(),\n $automatedReport->getFrom(),\n $automatedReport->getTo()\n );\n }\n\n public function getAskJiminnyGenerateReportPayload(\n AutomatedReport $automatedReport,\n AutomatedReportResult $reportResult,\n array $activityIds,\n ): array {\n return [\n 'user_question' => $automatedReport->getAskAnythingPrompt()?->getContent(),\n 'call_ids' => array_map('strval', $activityIds),\n 'team_id' => $automatedReport->getTeamId(),\n 'request_id' => $reportResult->getUuid(),\n 'callback_url' => $this->getCallbackUrl(),\n 'report_period' => $this->getReportPeriodName($reportResult),\n 'report_name' => $automatedReport->getCustomName(),\n ];\n }\n\n private function getCallbackUrl(): string\n {\n return $this->webhookService->route('jiminny.webhook.reports.ready');\n }\n\n /**\n * Validate and transform payload data for automated reports\n *\n * @param array $data\n *\n * @throws InvalidArgumentException\n *\n * @return array\n */\n private function validateAndTransformData(array $data): array\n {\n // Validate organization (team) and check feature\n $team = $this->validateOrganization($data['organization'] ?? null);\n\n $status = $this->validateReportStatus($data['report_enabled'] ?? null);\n $type = $this->validateReportType($data['report_type'] ?? null);\n $frequency = $this->validateFrequency($data['frequency'] ?? null);\n $additionalPromptInput = $this->validateAdditionalPromptInput(\n $data['additional_prompt_input'] ?? null\n );\n $customReportName = $this->validateCustomReportName($data['custom_name'] ?? null);\n\n // Prepare data for the database\n $reportData = [\n 'team_id' => $team->getId(),\n 'type' => $type,\n 'status' => $status,\n 'frequency' => $frequency,\n 'additional_prompt_input' => $additionalPromptInput,\n 'custom_name' => $customReportName,\n ];\n\n // Validate deal values\n $reportData = $this->validateDealValues($data, $reportData);\n\n // Validate date range\n $reportData = $this->validateDateRange($data, $reportData, $frequency);\n\n // Validate call durations\n $reportData = $this->validateCallDurations($data, $reportData);\n\n // Validate call types\n $reportData = $this->validateCallTypes($data, $reportData);\n\n // Validate media types\n $reportData = $this->validateMediaTypes($data, $reportData);\n\n // Validate groups\n if (isset($data['teams'])) {\n $reportData['groups'] = $this->validateAndGetGroupIds($team, $data['teams']);\n }\n\n // Validate deal stages\n $reportData = $this->validateDealStages($data, $reportData, $team, $type);\n\n // Validate playbook categories\n $reportData = $this->validatePlaybookCategories($data, $reportData, $team);\n\n // Validate recipients\n $reportData['recipients'] = [\n 'users' => $this->validateAndGetUserIdsByTeam($team, $data['recipients'] ?? []),\n ];\n\n if (isset($data['jiminny_recipients'])) {\n // Validate Jiminny recipients\n $reportData['jiminny_recipients'] = [\n 'users' => $this->validateAndGetJiminnyUserIds((array) $data['jiminny_recipients']),\n ];\n }\n\n return $reportData;\n }\n\n private function validateDealValues(array $data, array $reportData): array\n {\n if (isset($data['min_deal_value'])) {\n $reportData['deal_value_min'] = (int) $data['min_deal_value'];\n\n if ($reportData['deal_value_min'] > 4294967295 || $reportData['deal_value_min'] < 0) {\n throw new InvalidArgumentException('Min deal value should be between 0 and 4294967295');\n }\n }\n\n if (isset($data['max_deal_value'])) {\n $reportData['deal_value_max'] = (int) $data['max_deal_value'];\n\n if ($reportData['deal_value_max'] > 4294967295 || $reportData['deal_value_max'] < 0) {\n throw new InvalidArgumentException('Max deal value should be between 0 and 4294967295');\n }\n }\n\n if (isset($data['min_deal_value'], $data['max_deal_value'])\n && $data['min_deal_value'] > $data['max_deal_value']\n ) {\n throw new InvalidArgumentException('Min deal value cannot be greater than max deal value');\n }\n\n return $reportData;\n }\n\n private function validateDateRange(array $data, array $reportData, string $frequency): array\n {\n // Set date range only for one_off frequency\n if ($frequency === 'one_off') {\n if (isset($data['start_date_period'])) {\n $reportData['from'] = $this->parseDate($data['start_date_period']);\n }\n\n if (isset($data['end_date_period'])) {\n $reportData['to'] = $this->parseDate($data['end_date_period']);\n }\n\n if (empty($reportData['from']) || empty($reportData['to'])) {\n throw new InvalidArgumentException(\n 'Start date and end date are required for one_off frequency'\n );\n }\n } else {\n $reportData['from'] = null;\n $reportData['to'] = null;\n }\n\n return $reportData;\n }\n\n private function validateCallDurations(array $data, array $reportData): array\n {\n // Convert call durations from minutes to seconds\n if (isset($data['min_call_duration'])) {\n $reportData['call_duration_min'] = (int) $data['min_call_duration'] * 60;\n\n if ($reportData['call_duration_min'] > 4294967295 || $reportData['call_duration_min'] < 0) {\n throw new InvalidArgumentException('Min call duration should be between 0 and 4294967295');\n }\n }\n\n if (isset($data['max_call_duration'])) {\n $reportData['call_duration_max'] = (int) $data['max_call_duration'] * 60;\n\n if ($reportData['call_duration_max'] > 4294967295 || $reportData['call_duration_max'] < 0) {\n throw new InvalidArgumentException('Max call duration should be between 0 and 4294967295');\n }\n }\n\n return $reportData;\n }\n\n private function validateCallTypes(array $data, array $reportData): array\n {\n // Set call types\n $reportData['call_types'] = $data['call_type'] ?? [];\n if (empty($reportData['call_types'])) {\n $reportData['call_types'] = self::getCallTypes();\n }\n\n foreach ($reportData['call_types'] as $callType) {\n if (! in_array($callType, self::getCallTypes(), true)) {\n throw new InvalidArgumentException(sprintf('Call type %s is invalid', $callType));\n }\n }\n\n return $reportData;\n }\n\n private function validateMediaTypes(array $data, array $reportData): array\n {\n // Set media types from input data\n $reportData['media_types'] = $data['media_types'] ?? [];\n\n if (empty($reportData['media_types'])) {\n throw new InvalidArgumentException('Media types are required');\n }\n\n foreach ($reportData['media_types'] as $mediaType) {\n if (! in_array($mediaType, self::MEDIA_TYPES, true)) {\n throw new InvalidArgumentException(sprintf('Media type %s is invalid', $mediaType));\n }\n }\n\n return $reportData;\n }\n\n private function validateDealStages(array $data, array $reportData, Team $team, string $reportType): array\n {\n // Validate and set deal stages\n if (isset($data['deal_stage_at_call'])) {\n $reportData['deal_at_call_stages'] =\n $this->validateAndGetDealStageIds($team, $data['deal_stage_at_call'], 'Deal stage at call');\n }\n\n if (isset($data['current_deal_stage'])) {\n $reportData['current_deal_stages'] =\n $this->validateAndGetDealStageIds($team, $data['current_deal_stage'], 'Current deal stage');\n }\n\n // Ensure current_deal_stage is not provided for loss_analysis report type\n if ($reportType === self::TYPE_LOSS_ANALYSIS && ! empty($data['current_deal_stage'])) {\n throw new InvalidArgumentException('Current deal stage is not applicable for Loss Analysis reports');\n }\n\n return $reportData;\n }\n\n // transform uuid to id\n private function validatePlaybookCategories(array $data, array $reportData, Team $team): array\n {\n $key = 'playbook_categories';\n\n if (isset($data[$key])) {\n $payloadIds = $data[$key];\n $ids = [];\n\n foreach ($payloadIds as $uuid) {\n $uuid = (string) $uuid;\n\n try {\n $playbookCategory = $this->playbookCategoryRepository->findByUuid($uuid);\n } catch (Throwable $throwable) {\n Log::error(__METHOD__ . ' ' . $throwable->getMessage());\n\n throw new InvalidArgumentException(sprintf('Playbook category %s not found', $uuid));\n }\n\n if (! $playbookCategory) {\n throw new InvalidArgumentException(sprintf('Playbook category %s not found', $uuid));\n }\n\n if (! $playbookCategory->hasPlaybook()) {\n throw new InvalidArgumentException(sprintf('Playbook category %s has no playbook', $uuid));\n }\n\n if ($playbookCategory->getPlaybook()->getTeamId() !== $team->getId()) {\n throw new InvalidArgumentException(\n sprintf('Playbook category %s not found for team %s', $uuid, $team->getUuid())\n );\n }\n\n $ids[] = $playbookCategory->getId();\n }\n\n $reportData[$key] = $ids;\n }\n\n return $reportData;\n }\n\n private function validateReportStatus($status): bool\n {\n if (! in_array($status, [true, false], true)) {\n throw new InvalidArgumentException('Report status is invalid');\n }\n\n return $status;\n }\n\n private function validateReportType($type): string\n {\n if (! in_array($type, self::getTypes(), true)) {\n throw new InvalidArgumentException(sprintf('Report type is invalid: %s', $type));\n }\n\n return $type;\n }\n\n private function validateFrequency($frequency): string\n {\n if (! in_array($frequency, self::getFrequencies(), true)) {\n throw new InvalidArgumentException('Frequency is invalid');\n }\n\n return $frequency;\n }\n\n private function validateAdditionalPromptInput(?string $additionalPromptInput): ?string\n {\n if ($additionalPromptInput && strlen($additionalPromptInput) > 5000) {\n throw new InvalidArgumentException('Additional Prompt Input should be less than 5000 characters');\n }\n\n return $additionalPromptInput;\n }\n\n private function validateCustomReportName(?string $customReportName): ?string\n {\n if ($customReportName === null || $customReportName === '') {\n return null;\n }\n\n if (strlen($customReportName) > 70) {\n throw new InvalidArgumentException('Custom report name should be less than 70 characters');\n }\n\n return $customReportName;\n }\n\n private function validateOrganization(?string $organizationUuid): Team\n {\n if (! $organizationUuid) {\n throw new InvalidArgumentException('Organization is required');\n }\n\n $team = $this->teamRepository->idOrUuid($organizationUuid);\n\n if (! $team) {\n throw new InvalidArgumentException('Organization not found');\n }\n\n if (! $team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {\n throw new InvalidArgumentException('Organization does not have the Automated Reports feature');\n }\n\n return $team;\n }\n\n private function validateAndGetGroupIds(Team $team, array $teamUuids): array\n {\n $groupIds = [];\n\n foreach ($teamUuids as $uuid) {\n $group = $this->groupRepository->findByUuid($uuid);\n\n if ($group === null || $group->getTeamId() !== $team->getId()) {\n throw new InvalidArgumentException(\n sprintf('Group %s not found for team %s', $uuid, $team->getUuid())\n );\n }\n\n $groupIds[] = $group->getId();\n\n }\n\n return $groupIds;\n }\n\n private function validateAndGetDealStageIds(Team $team, array $stageUuids, string $propertyLabel): array\n {\n $stageIds = [];\n\n foreach ($stageUuids as $uuid) {\n $stage = $this->stageRepository->findByUuid($uuid);\n\n if ($stage === null || $stage->getTeamId() !== $team->getId()) {\n throw new InvalidArgumentException(\n sprintf('Stage %s not found for team %s for %s', $uuid, $team->getUuid(), $propertyLabel)\n );\n }\n\n $stageIds[] = $stage->getId();\n }\n\n return $stageIds;\n }\n\n private function validateAndGetUserIds(array $userUuids, callable $teamCheck): array\n {\n if (empty($userUuids)) {\n return [];\n }\n\n $userIds = [];\n\n foreach ($userUuids as $uuid) {\n $user = $this->userRepository->findByUuid($uuid);\n\n if (! $user || ! $user->isStatusActive()) {\n throw new InvalidArgumentException(\n sprintf('User %s not found or is not active', $uuid)\n );\n }\n\n if (! $teamCheck($user)) {\n throw new InvalidArgumentException(\n sprintf('User %s does not belong to the allowed team(s)', $uuid)\n );\n }\n\n $userIds[] = $user->getId();\n }\n\n return $userIds;\n }\n\n private function validateAndGetUserIdsByTeam(Team $team, array $userUuids): array\n {\n return $this->validateAndGetUserIds($userUuids, fn ($user) => $user->getTeamId() === $team->getId());\n }\n\n private function validateAndGetJiminnyUserIds(array $userUuids): array\n {\n $allowedTeamIds = config('kiosk.teamIds', []);\n\n return $this->validateAndGetUserIds($userUuids, fn ($user) => in_array($user->getTeamId(), $allowedTeamIds, true));\n }\n\n private function parseDate(string $dateString): string\n {\n return date('Y-m-d H:i:s', strtotime($dateString));\n }\n\n private function generateReportResultViewUrl(AutomatedReportResult $result): string\n {\n $mediaResource = $this->getReportMediaRouteResource($result);\n\n return route('ai-reports.' . $mediaResource . '.view', ['uuid' => $result->getUuid()]);\n }\n\n private function generateReportResultDownloadUrl(AutomatedReportResult $result): string\n {\n $mediaResource = $this->getReportMediaRouteResource($result);\n\n return route('ai-reports.' . $mediaResource . '.download', ['uuid' => $result->getUuid()]);\n }\n\n private function getReportMediaRouteResource(AutomatedReportResult $result): string\n {\n if ($result->getMediaType() === self::MEDIA_TYPE_PDF) {\n return self::PDF_KEY;\n } elseif ($result->getMediaType() === self::MEDIA_TYPE_PODCAST) {\n return self::AUDIO_KEY;\n }\n\n throw new \\InvalidArgumentException('Unknown media type.');\n }\n\n public function getMediaPath(AutomatedReportResult $result): ?string\n {\n $url = match ($result->getMediaType()) {\n self::MEDIA_TYPE_PDF => $result->getPdfUrl(),\n self::MEDIA_TYPE_PODCAST => $result->getPodcastAudioUrl(),\n default => null,\n };\n\n if ($url === null) {\n return null;\n }\n\n $path = parse_url(trim($url, '\"\\''), PHP_URL_PATH);\n\n return $path ?: null;\n }\n\n public function getFilenameSuffix(AutomatedReportResult $result): ?string\n {\n return match ($result->getMediaType()) {\n self::MEDIA_TYPE_PODCAST => 'Podcast',\n default => null,\n };\n }\n\n public function getMailSubjectSuffix(AutomatedReportResult $result): string\n {\n return match ($result->getMediaType()) {\n self::MEDIA_TYPE_PDF => 'report',\n self::MEDIA_TYPE_PODCAST => 'podcast',\n default => '',\n };\n }\n\n public function getMediaTypeMetadata(AutomatedReportResult $result): array\n {\n return match ($result->getMediaType()) {\n self::MEDIA_TYPE_PODCAST => ['extension' => 'mp3', 'mime' => 'audio/mpeg'],\n self::MEDIA_TYPE_PDF => ['extension' => 'pdf', 'mime' => 'application/pdf'],\n default => ['extension' => null, 'mime' => null],\n };\n }\n\n public function deleteS3Files(AutomatedReportResult $result): void\n {\n $teamUuid = $result->getReport()->getTeam()->getUuid();\n $reportUuid = $result->getUuid();\n\n // delete all files for a report uuid no mather of pdf, podcast, or both\n // in case of both - the podcast files are linked to the pdf (parent) uuid\n // pdf and podcast date times should be close\n $path = sprintf('%s/%s/%s', $teamUuid, self::S3_DIR, $reportUuid);\n\n foreach (self::FILE_EXTENSIONS_VARIANTS as $extension) {\n $file = $path . '.' . $extension;\n\n if (Storage::exists($file)) {\n Storage::delete($file);\n Log::info('[Reports] Deleted S3 file', [\n 'path' => $file,\n ]);\n }\n }\n\n foreach (self::FILE_PODCAST_EXTENSIONS_VARIANTS as $extension) {\n $file = $path . '_podcast.' . $extension;\n\n if (Storage::exists($file)) {\n Storage::delete($file);\n Log::info('[Reports] Deleted Podcast S3 file', [\n 'path' => $file,\n ]);\n }\n }\n }\n\n /**\n *\n * @param int|null $teamId Optional team ID to filter results\n *\n * @return Collection<int, int> Collection of team IDs\n */\n public function getTeamIdsWithReportsResults(?int $teamId = null): Collection\n {\n return $this->automatedReportsRepository->getTeamIdsWithReportsResults($teamId);\n }\n\n /**\n * Core delete logic for report results using a query\n *\n * @param Builder $query\n * @param array $logContext\n *\n * @return int\n */\n private function deleteReportResultsByQuery(Builder $query, array $logContext = []): int\n {\n $deletedCount = 0;\n\n if ($query->exists()) {\n Log::info(\n 'Run delete report results',\n array_merge(\n $logContext,\n [\n 'service' => 'AutomatedReportsService',\n ]\n )\n );\n\n $query->chunkById(50, function ($results) use (&$deletedCount, $logContext) {\n foreach ($results as $result) {\n $this->deleteReportResult($result);\n $deletedCount++;\n\n Log::info(\n 'Deleted a report result',\n array_merge(\n $logContext,\n [\n 'result_id' => $result->getId(),\n 'report_id' => $result->getReportId(),\n ]\n )\n );\n }\n });\n }\n\n return $deletedCount;\n }\n\n /**\n * Delete report results for a team by retention period\n *\n * @param Team $team\n * @param CarbonImmutable $retentionDate\n *\n * @return int Number of deleted report results\n */\n public function deleteReportsResultsInRetentionPeriod(Team $team, CarbonImmutable $retentionDate): int\n {\n $reportIds = $this->automatedReportsRepository->getReportIdsByTeam($team);\n\n if ($reportIds->isEmpty()) {\n return 0;\n }\n\n $query = $this->automatedReportsRepository\n ->getReportResultsQueryForRetention($team, $retentionDate);\n\n return $this->deleteReportResultsByQuery($query, [\n 'team_id' => $team->getId(),\n 'retention_date' => $retentionDate->toDateTimeString(),\n ]);\n }\n\n /**\n * Delete ALL report results for a specific automated report\n *\n * @param string $uuid\n *\n * @return int\n */\n public function deleteReportResults(string $uuid): int\n {\n $report = $this->getReport($uuid);\n\n $query = $this->automatedReportsRepository->getResultsByReportQuery($report);\n\n return $this->deleteReportResultsByQuery($query, [\n 'report_uuid' => $uuid,\n 'report_id' => $report->getId(),\n ]);\n }\n\n public function deleteReportResult(AutomatedReportResult $result): void\n {\n $this->deleteS3Files($result);\n\n $result->delete();\n }\n\n /**\n * Get all reports for a specific team\n *\n * @param Team $team\n *\n * @return \\Illuminate\\Database\\Eloquent\\Collection\n */\n public function getTeamReports(Team $team): \\Illuminate\\Database\\Eloquent\\Collection\n {\n return $this->automatedReportsRepository->getReportsByTeam($team);\n }\n\n /**\n * Get all report results for a specific report\n *\n * @param AutomatedReport $report\n *\n * @return \\Illuminate\\Database\\Eloquent\\Collection\n */\n public function getReportResults(AutomatedReport $report): \\Illuminate\\Database\\Eloquent\\Collection\n {\n return $this->automatedReportsRepository->getResultsByReport($report);\n }\n\n public function deleteAllReportResults(AutomatedReport $report): void\n {\n $results = $this->getReportResults($report);\n\n /** @var AutomatedReportResult $result */\n foreach ($results as $result) {\n Log::info('Deleting result', [\n 'report' => $report->getId(),\n 'result' => $result->getId(),\n ]);\n\n $this->deleteReportResult($result);\n }\n }\n\n public function deleteAllData(Team $team): void\n {\n Log::info('Deleting automated report and results for team', [\n 'team' => $team->getId(),\n ]);\n\n $reports = $this->getTeamReports($team);\n\n /** @var AutomatedReport $report */\n foreach ($reports as $report) {\n Log::info('Deleting report', [\n 'team' => $team->getId(),\n 'report' => $report->getId(),\n ]);\n\n $this->deleteAllReportResults($report);\n\n $report->delete();\n }\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":true,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"Project","depth":3,"role_description":"text"},{"role":"AXButton","text":"Project","depth":3,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"New File or Directory…","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Expand Selected","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Collapse All","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Options","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false}]...
|
3397592283435315795
|
6686367547760219213
|
idle
|
accessibility
|
NULL
|
Project: faVsco.js, menu
#11894 on JY-18909-automa Project: faVsco.js, menu
#11894 on JY-18909-automated-reports-ask-jiminny, menu
Start Listening for PHP Debug Connections
AutomatedReportsCommandTest
Run 'AutomatedReportsCommandTest'
Debug 'AutomatedReportsCommandTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Execute
Explain Plan
Browse Query History
View Parameters
Open Query Execution Settings…
In-Editor Results
Tx: Auto
Cancel Running Statements
Playground
jiminny
Sync Changes
Hide This Notification
Code changed:
Hide
16
13
13
Previous Highlighted Error
Next Highlighted Error
SELECT * FROM teams WHERE id = 1;
select * from crm_layouts where crm_configuration_id = 39;
SELECT * FROM crm_layout_entities WHERE crm_layout_id = 283;
SELECT * FROM crm_fields WHERE id = 2234;
SELECT * FROM crm_field_values WHERE crm_field_id = 2234;
select * from crm_profiles where user_id = 143;
select * from record_types where crm_configuration_id = 39; # 0121K000001MHElQAO,0121K000001MHEqQAO
select * from business_processes where crm_configuration_id = 39;
# 01941000000H669AAC, 01941000000H66JAAS
select * from record_type_field_values
where record_type_id IN (24);
select * from crm_field_values where id IN (2730);
select * from crm_configurations where id = 39;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 1
and sa.provider = 'salesforce'; #1035
select * from users where team_id = 1; # 222 group 3
SELECT * FROM activities WHERE user_id = 222 order by id desc;
select * from sidekick_settings where team_id = 1;
select * from teams where id = 1;
select * from team_features where team_id = 1;
select * from activities where crm_configuration_id = 2
and provider = 'ms-teams' and id = 608765;
SELECT * FROM activities WHERE crm_configuration_id = 2 and crm_provider_id = '59523413338';
select * from sidekick_settings where team_id = 2;
SELECT * FROM activities WHERE id = 608660;
select * from activity_summary_logs where activity_id = 608660;
select * from ai_prompts where transcription_id = 11214;
# [PASSWORD_DOTS]
SELECT * FROM activities WHERE uuid_to_bin('ed78a437-2804-450e-ab2f-56ab1c641346') = uuid;
# id: 608818, crm: 59628809737
SELECT * FROM activities WHERE uuid_to_bin('36b06e55-afdd-4782-8dee-c624cd0af191') = uuid;
# id: 608821, crm: 59632069252
SELECT ce.start_time, ce.end_time, a.id, a.uuid, crm_provider_id, calendar_event_id, title,
playbook_category_id, user_id, lead_id, contact_id, account_id, opportunity_id,
scheduled_start_time, scheduled_end_time, actual_start_time, actual_end_time, a.created_at
FROM activities a
join calendar_events ce on a.calendar_event_id = ce.id
WHERE a.id IN (608818, 608821);
select * from users where team_id = 1;
select * from team_settings where team_id = 1;
select * from crm_profiles where crm_configuration_id = 39 order by user_id;
select * from team_features where team_id = 1;
select * from users where team_id = 2;
SELECT * FROM activities WHERE uuid_to_bin('ec7647e9-5225-458b-b475-f31aa2769204') = uuid; # 612639
# Preslava N. Ivanova, grou id 3
SELECT * FROM opportunities WHERE uuid_to_bin('a2928fe5-aec5-46cb-85d9-7654c89e46a6') = uuid;
select * from activities where opportunity_id = 344 and actual_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00';
select
a.id,
a.type,
a.scheduled_start_time,
a.actual_start_time,
a.created_at,
a.opportunity_id,
a.status
FROM activities a
WHERE opportunity_id = 344
and status IN ('completed', 'received', 'delivered')
and (
(a.actual_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00')
OR (a.created_at between '2024-10-11 00:00:00' and '2024-10-12 00:00:00')
OR (a.scheduled_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00'))
;
SELECT * FROM users WHERE id = 222;
SELECT * FROM crm_profiles WHERE user_id = 222;
select * from crm_layouts where crm_configuration_id = 39;
SELECT * FROM crm_layout_entities WHERE crm_layout_id = 281;
select * from group_deal_risk_types;
select * from opportunities where team_id = 1;
SELECT * FROM opportunities WHERE id = 315;
SELECT * FROM crm_field_data WHERE object_id = 315;
select * from crm_field_data where object_id = 260;
select * from generic_ai_prompts where subject_id = 315;
select * from teams; # 36, 21, 121, [EMAIL]
SELECT * FROM social_accounts WHERE sociable_id = 121 and provider = 'bullhorn';
# [PASSWORD_DOTS]
select * from teams where id = 1;
select * from crm_configurations where id = 39;
select * from users where team_id = 1;
select u.email, cp.* from users u
join crm_profiles cp on u.id = cp.user_id
where u.team_id = 1;
# 1 - 00541000004281rAAA
# 204 - 0052g000003freeAAA
# 429 - 0052g000003qGOiAAM
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 1
and sa.provider = 'salesforce';
select * from activities where type = 'softphone'
and created_at > '2024-12-11 15:24:36' order by id desc;
select * from activity_providers where team_id = 1;
select * from activity_provider_users where activity_provider_id = 328;
select * from opportunities where crm_configuration_id = 39
AND account_id = 178 AND is_closed = false
order by created_at DESC;
select * from contacts where id = 3952;
select * from accounts where id = 178;
# [PASSWORD_DOTS]
select * from teams where id = 36;
select * from crm_configurations where id = 21;
select * from users where team_id = 36;
select u.email, cp.* from users u
join crm_profiles cp on u.id = cp.user_id
where u.team_id = 36;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 36
and sa.provider = 'bullhorn';
select * from social_accounts where id = 348;
UPDATE social_accounts SET
provider_user_token = '21442_6802599_91:41179a58-21e7-4d7c-ad58-56bb666b2f65',
provider_refresh_token = '21442_6802599_91:01c6b335-3f2a-42e4-85ff-8a08fa65fceb',
expires = 1733998131,
state = 'connected'
WHERE id = 348;
# [PASSWORD_DOTS]
select * from teams where id = 31;
select * from crm_configurations where id = 18;
select * from users where team_id = 31; # 257
select u.email, cp.* from users u
join crm_profiles cp on u.id = cp.user_id
where u.team_id = 31;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 31
and sa.provider = 'close';
select * from contacts where crm_configuration_id = 18;
# [PASSWORD_DOTS] NEPTUNE [PASSWORD_DOTS]
select * from teams;
select * from users where id IN (1030, 1035, 1052);
select * from crm_configurations;
select * from users where team_id = 65; # 257
select * from team_settings where team_id = 65; # 257
select * from invitations where team_id = 65; # 257
select * from users where email = '[EMAIL]'; # 257
select u.email, cp.* from users u
join crm_profiles cp on u.id = cp.user_id
where u.team_id = 65;
select * from crm_configurations where id = 53;
select * from accounts where crm_configuration_id = 53 order by id desc;
select * from leads where crm_configuration_id = 53 order by id desc;
select * from contacts where crm_configuration_id = 53 order by id desc;
select * from opportunities where crm_configuration_id = 53 order by id desc;
select * from crm_profiles where crm_configuration_id = 53 order by id desc;
select * from crm_fields where crm_configuration_id = 53 order by id desc;
select * from crm_field_values where crm_field_id = 3341 order by id desc;
select * from crm_layouts where crm_configuration_id = 53 order by id desc;
select * from stages where crm_configuration_id = 53 order by id desc;
select * from crm_profiles where crm_configuration_id = 13;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 65
and sa.provider = 'integration-app';
select * from contacts where crm_configuration_id = 13;
select * from social_accounts where sociable_id = 283;
SELECT * FROM opportunities WHERE crm_provider_id = '006O400000E9bzeIAB';
select * from activity_providers where team_id = 65;
SELECT * FROM activities WHERE crm_configuration_id IN (51, 52, 53);
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 65
;
# [PASSWORD_DOTS] STAGING [PASSWORD_DOTS]
SELECT * FROM teams;
SELECT * FROM teams WHERE id = 88;
SELECT * FROM teams WHERE id = 89;
select * from team_settings where team_id = 89;
SELECT * FROM users WHERE team_id = 89;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 89;
select * from users;
SELECT * FROM social_accounts WHERE sociable_id = 1761;
SELECT * FROM crm_configurations WHERE id = 70;
select * from accounts where crm_configuration_id = 70 order by id desc;
select * from leads where crm_configuration_id = 70 order by id desc;
select * from contacts where crm_configuration_id = 70 order by id desc;
select * from opportunities where crm_configuration_id = 70 order by id desc;
select * from crm_profiles where crm_configuration_id = 70 order by id desc;
select * from crm_fields where crm_configuration_id = 70 order by id desc;
select * from crm_field_values where crm_field_id = 3536 order by id desc;
select * from crm_layouts where crm_configuration_id = 70 order by id desc;
select * from stages where crm_configuration_id = 70 order by id desc;
select * from business_processes where crm_configuration_id = 70 order by id desc;
select * from business_process_stages where business_process_id = 34;
select * from contacts where id = 10468;
select * from crm_layouts where crm_configuration_id = 70;
SELECT * FROM crm_layout_entities WHERE crm_layout_id = 388;
SELECT * FROM crm_fields WHERE id IN (3533,3534,3535);
select * from activities where crm_configuration_id = 70
and (account_id IS NOT NULL or lead_id IS NOT NULL or contact_id IS NOT NULL or opportunity_id IS NOT NULL) order by id desc;
SELECT * FROM activities WHERE uuid_to_bin('2e10b60f-8a61-41c5-a3d4-28835353dc65') = uuid;
SELECT * FROM activities where crm_configuration_id = 69 ;
SELECT * FROM users WHERE email LIKE '%[EMAIL]%';
SELECT * FROM activities WHERE uuid_to_bin('5a150c93-40fc-42ec-b3bd-c1d328e09f6e') = uuid;
SELECT * FROM opportunities WHERE id = 385;
select * from participants p
join activities a on p.activity_id = a.id
where a.crm_configuration_id = 70
and (p.lead_id IS NOT NULL or p.contact_id IS NOT NULL);
SELECT * FROM participants WHERE id = 1013638;
select * from teams where id = 90;
select * from users where team_id = 90;
select * from social_accounts where social_accounts.sociable_id IN (1960,1760);
SELECT * FROM crm_profiles WHERE crm_configuration_id = 71;
select * from invitations where team_id = 90;
select * from crm_configurations where id = 71;
select * from accounts where crm_configuration_id = 71 order by id desc;
select * from leads where crm_configuration_id = 71 order by id desc;
select * from contacts where crm_configuration_id = 71 order by id desc;
select * from opportunities where crm_configuration_id = 71 order by id desc;
select * from crm_profiles where crm_configuration_id = 71 order by id desc;
select * from crm_fields where crm_configuration_id = 71 order by id desc;
select * from crm_field_values where crm_field_id = 3341 order by id desc;
select * from crm_layouts where crm_configuration_id = 71 order by id desc;
select * from stages where crm_configuration_id = 71 order by id desc;
select * from users order by secondary_email desc;
select u.id, u.email, u.status, sa.id, sa.provider_user_id from social_accounts sa
join users u on sa.sociable_id = u.id
where sa.provider = 'google' and u.email LIKE 'aneliya%';
select * from failed_jobs order by id desc;
select * from users where email = '[EMAIL]' or secondary_email = '[EMAIL]';
select * from teams;
SELECT * FROM crm_profiles WHERE crm_configuration_id = 39;
SELECT * FROM crm_fields WHERE crm_configuration_id = 39 and object_type = 'task';
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 1
and sa.provider = 'salesforce';
# [PASSWORD_DOTS]
SELECT * FROM activities WHERE uuid_to_bin('c38b3895-fd0f-4b1f-9fb2-c170dba137c6') = uuid;
SELECT * FROM crm_configurations WHERE id = 70;
select * from teams where id = 1;
select * from groups where team_id = 1;
select * from users where team_id = 1;
select o.id, o.name,o.close_date, u.id, u.name, u.group_id, r.id, r.display_name, g.name, g.scope from opportunities o
join users u on o.user_id = u.id
join groups g on u.group_id = g.id
join role_user ru on u.id = ru.user_id
join roles r on ru.role_id = r.id
where o.crm_configuration_id = 39 and close_date > '2024-01-01 00:00:00';
select * from role_user where user_id = 143;
select * from roles;
select * from role_user;
select * from groups where id = 9;
select * from scope_groups where group_id = 9;
# [PASSWORD_DOTS]
select * from teams where id = 36;
select * from crm_configurations;
SELECT * FROM social_accounts WHERE sociable_id = 121;
[URL_WITH_CREDENTIALS] this will add filter, however if we need to control feature by FF we need conditional logic
public const array TYPES = [
['id' => 'exec_summary', 'name' => 'Exec Summary'],
['id' => 'coaching_profiles', 'name' => 'Coaching Profiles'],
['id' => 'product_feedback', 'name' => 'Product Feedback'],
['id' => self::TYPE_LOSS_ANALYSIS, 'name' => 'Loss Analysis'],
// ['id' => 'questions', 'name' => 'Questions'],
// ['id' => 'statistical_quant', 'name' => 'Statistical Quantitative'],
];
public const array ALL_TYPES = [
...self::TYPES,
['id' => self::TYPE_ASK_JIMINNY, 'name' => 'Ask Jiminny'],
];
public const string FREQUENCY_DAILY = 'daily';
public const string FREQUENCY_WEEKLY = 'weekly';
public const string FREQUENCY_MONTHLY = 'monthly';
public const string FREQUENCY_QUARTERLY = 'quarterly';
public const string FREQUENCY_ONE_OFF = 'one_off';
/**
* Frequencies for standard (non-Ask Jiminny) reports.
*/
public const array FREQUENCIES = [
['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],
['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],
['id' => self::FREQUENCY_QUARTERLY, 'name' => 'Quarterly'],
['id' => self::FREQUENCY_ONE_OFF, 'name' => 'One-off'],
];
/**
* Frequencies for Ask Jiminny reports.
*/
public const array ASK_JIMINNY_FREQUENCIES = [
['id' => self::FREQUENCY_DAILY, 'name' => 'Daily'],
['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],
['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],
];
public const string MEDIA_TYPE_PDF = 'pdf';
public const string MEDIA_TYPE_PODCAST = 'podcast';
public const array MEDIA_TYPES = [self::MEDIA_TYPE_PDF, self::MEDIA_TYPE_PODCAST];
public const array MEDIA_TYPE_OBJECT_PDF = ['id' => self::MEDIA_TYPE_PDF, 'name' => 'PDF'];
public const array MEDIA_TYPE_OBJECT_PODCAST = ['id' => self::MEDIA_TYPE_PODCAST, 'name' => 'Podcast'];
public const array MEDIA_TYPE_OBJECTS = [self::MEDIA_TYPE_OBJECT_PDF, self::MEDIA_TYPE_OBJECT_PODCAST];
public const array CALL_TYPE_CONFERENCE = ['id' => 'conference', 'name' => 'Conference'];
public const array CALL_TYPE_DIALER = ['id' => 'dialer', 'name' => 'Dialer'];
public const int SENT_REPORT_AT_HOURS = 5;
public const string PDF_KEY = 'pdf';
public const string AUDIO_KEY = 'audio';
private const array ALL_FREQUENCIES = [
['id' => self::FREQUENCY_DAILY, 'name' => 'Daily'],
['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],
['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],
['id' => self::FREQUENCY_QUARTERLY, 'name' => 'Quarterly'],
['id' => self::FREQUENCY_ONE_OFF, 'name' => 'One-off'],
];
private const string S3_DIR = 'reports';
private const array FILE_EXTENSIONS_VARIANTS = ['html', 'MD', 'pdf'];
private const array FILE_PODCAST_EXTENSIONS_VARIANTS = ['json', 'mp3', 'ssml'];
public function __construct(
private readonly TeamRepository $teamRepository,
private readonly GroupRepository $groupRepository,
private readonly UserRepository $userRepository,
private readonly StageRepository $stageRepository,
private readonly DealStagesService $dealStagesService,
private readonly RecipientsService $recipientsService,
private readonly AutomatedReportsRepository $automatedReportsRepository,
private readonly Webhook $webhookService,
private readonly BusDispatcher $dispatcher,
private readonly ActivityTypeService $activityTypeService,
private readonly PlaybookCategoryRepository $playbookCategoryRepository,
private readonly AskAnythingPromptService $askAnythingPromptService,
private readonly SearchRepository $activitySearchRepository,
private readonly AskAnythingRepository $askAnythingRepository,
) {
}
public static function getTypes(): array
{
$types = self::TYPES;
return array_map(static function ($type) {
return $type['id'];
}, $types);
}
public static function getCallTypes(): array
{
return array_map(static function ($callType) {
return $callType['id'];
}, [self::CALL_TYPE_CONFERENCE, self::CALL_TYPE_DIALER]);
}
public static function getFrequencies(): array
{
return array_map(static function ($frequency) {
return $frequency['id'];
}, self::FREQUENCIES);
}
// front-facing structure
public function getReportEnabledFieldData(bool $value = false): array
{
return [
'id' => 'report_enabled',
'label' => '',
'inputType' => InputTypeEnum::TOGGLE,
'value' => $value,
];
}
// Organizations = Teams
public function getOrganizationFieldData(?string $value = null, bool $shortVersion = false): array
{
$options = $this->getTeams();
if ($shortVersion) {
return [
'id' => 'organization',
'label' => 'Organization',
'options' => $options,
];
}
return [
'id' => 'organization',
'label' => 'Organization',
'inputType' => InputTypeEnum::DROPDOWN,
'required' => true,
'placeholder' => 'Select',
'options' => $options,
'value' => $value,
'dependencies' => [
'teams',
'deal_stage_at_call',
'current_deal_stage',
'recipients',
ActivityTypeService::PLAYBOOK_CATEGORIES_KEY,
],
'dependsOn' => [],
];
}
// Teams = Groups
public function getTeamFieldData(array $options = [], array $value = [], bool $shortVersion = false): array
{
if ($shortVersion) {
return [
'id' => 'teams',
'label' => 'Team',
'options' => $options,
];
}
return [
'id' => 'teams',
'label' => 'Team',
'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,
'required' => false,
'placeholder' => 'Select',
'options' => $options,
'value' => $value, // value should be an array of objects {id, name}
'dependencies' => [ActivityTypeService::PLAYBOOK_CATEGORIES_KEY],
'dependsOn' => [],
];
}
public function getReportTypeFieldData(?string $value = null, bool $shortVersion = false, ?Team $team = null): array
{
$types = [];
if ($team instanceof Team) {
if ($team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {
$types = self::TYPES;
}
if ($team->hasFeature(FeatureEnum::ASK_JIMINNY_REPORTS)) {
$types[] = ['id' => self::TYPE_ASK_JIMINNY, 'name' => 'Ask Jiminny'];
}
} else {
$types = self::TYPES;
}
if ($shortVersion) {
return [
'id' => 'report_type',
'label' => 'Report Type',
'options' => $types,
];
}
return [
'id' => 'report_type',
'label' => 'Report Type',
'inputType' => InputTypeEnum::DROPDOWN,
'required' => true,
'placeholder' => 'Select',
'options' => $types,
'value' => $value,
'dependencies' => [],
'dependsOn' => [],
];
}
public function getFrequencyFieldData(?string $value = null): array
{
return [
'id' => 'frequency',
'label' => 'Frequency',
'inputType' => InputTypeEnum::DROPDOWN,
'required' => true,
'placeholder' => 'Select',
'options' => self::FREQUENCIES,
'value' => $value,
'dependencies' => ['period'],
'dependsOn' => [],
];
}
public function getPeriodFieldData(?string $valueStartDate = null, ?string $valueEndDate = null): array
{
return [
'id' => 'period',
'label' => 'Select one-off period',
'inputType' => InputTypeEnum::DATE_RANGE,
'required' => true,
'placeholder' => 'Select',
'value' => ['startDate' => $valueStartDate, 'endDate' => $valueEndDate],
'queryParams' => [
'startDate' => 'start_date_period',
'endDate' => 'end_date_period',
],
'dependencies' => [],
'dependsOn' => ['frequency'],
];
}
public function getActivityTypesFieldData(?Team $team = null, array $value = [], array $teamsFilter = []): array
{
return $this->activityTypeService->getActivityTypeFieldData(team: $team, value: $value, groupIds: $teamsFilter);
}
public function getDealStageAtCallFieldData(?Team $team = null, array $value = []): array
{
return $this->dealStagesService->getDealStageAtCallFieldData(team: $team, value: $value);
}
public function getCurrentDealStageFieldData(?Team $team = null, array $value = []): array
{
return $this->dealStagesService->getCurrentDealStageFieldData(team: $team, value: $value);
}
public function getDealValueFieldData(?int $valueMin = null, ?int $valueMax = null): array
{
return [
'id' => 'deal_value',
'label' => 'Deal Value',
'inputType' => InputTypeEnum::INTEGER_RANGE,
'required' => false,
'value' => ['min' => $valueMin, 'max' => $valueMax],
'queryParams' => [
'min' => 'min_deal_value',
'max' => 'max_deal_value',
],
'dependencies' => [],
'dependsOn' => [],
];
}
public function getCallTypeFieldData(bool $conferenceOn = false, bool $dialerOn = false): array
{
$value = [];
$conferenceOn && $value[] = self::CALL_TYPE_CONFERENCE;
$dialerOn && $value[] = self::CALL_TYPE_DIALER;
return [
'id' => 'call_type',
'label' => 'Call Type',
'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,
'required' => true,
'options' => [
self::CALL_TYPE_CONFERENCE,
self::CALL_TYPE_DIALER,
],
'value' => $value,
'dependencies' => [],
'dependsOn' => [],
];
}
public function getMediaTypeFieldData(?AutomatedReport $report = null): array
{
$value = [];
if ($report) {
$value = $this->transformMediaTypes($report);
}
return [
'id' => 'media_types',
'label' => 'Export as',
'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,
'required' => true,
'options' => self::MEDIA_TYPE_OBJECTS,
'value' => $value,
'dependencies' => [],
'dependsOn' => [],
];
}
public function getCallDurationFieldData(?int $valueMin = null, ?int $valueMax = null): array
{
return [
'id' => 'call_duration',
'label' => 'Call Duration',
'inputType' => InputTypeEnum::INTEGER_RANGE,
'required' => false,
'value' => ['min' => $valueMin, 'max' => $valueMax],
'queryParams' => [
'min' => 'min_call_duration',
'max' => 'max_call_duration',
],
'dependencies' => [],
'dependsOn' => [],
];
}
public function getRecipientsFieldData(?Team $team = null, array $value = []): array
{
return $this->recipientsService->getRecipientsFieldData(team: $team, value: $value);
}
public function getJiminnyRecipientsFieldData(array $value = []): array
{
return $this->recipientsService->getJiminnyRecipientsFieldData($value);
}
public function getAdditionalPromptInputFieldData(?string $value = null): array
{
return [
'id' => 'additional_prompt_input',
'label' => 'Special requirements',
'inputType' => InputTypeEnum::TEXTAREA,
'required' => false,
'placeholder' => 'What should be the focus of the report?',
'value' => $value,
'dependencies' => [],
'dependsOn' => [],
];
}
public function getCustomReportNameFieldData(?string $value = null): array
{
return [
'id' => 'custom_name',
'label' => 'Custom report name',
'inputType' => InputTypeEnum::TEXT,
'required' => false,
'placeholder' => 'Enter custom name',
'value' => $value,
'dependencies' => [],
'dependsOn' => [],
];
}
// data providers
public function getTeams(): array
{
$teams = $this->teamRepository->getTeamsForKiosk(status: Team::STATUS_ACTIVE);
$teamData = [];
foreach ($teams as $team) {
if (! $team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {
continue;
}
$teamData[] = $this->transformTeam($team);
}
return $teamData;
}
public function getTeamGroups(string $teamUuid): array
{
$data = [];
$team = $this->getTeam($teamUuid);
if ($team !== null) {
$groups = $team->groups()->get();
foreach ($groups as $group) {
$data[] = [
'id' => $group->getUuid(),
'name' => $group->getName(),
];
}
}
return $data;
}
public function getTeamsGroupsOptions(array $filterTeamUuids = []): array
{
$data = [];
$teams = $this->getTeams();
foreach ($teams as $team) {
if (! empty($filterTeamUuids) && ! in_array($team['id'], $filterTeamUuids, true)) {
continue;
}
$data[] = [
'label' => $team['name'],
'groups' => $this->getTeamGroups($team['id']),
];
}
return $data;
}
public function getTeam(string $teamUuid): ?Team
{
return $this->teamRepository->idOrUuid($teamUuid);
}
public function getTeamById(int $teamId): ?Team
{
return $this->teamRepository->find($teamId);
}
public function getGroupsUuids(AutomatedReport $report): array
{
$uuids = [];
$reportGroups = $report->getGroups();
foreach ($reportGroups as $groupId) {
if ($group = $this->groupRepository->find($groupId)) {
$uuids[] = $group->getUuid();
}
}
return $uuids;
}
public function getPlaybookCategoriesUuids(AutomatedReport $report): array
{
$uuids = [];
$playbookCategories = $report->getPlaybookCategories();
foreach ($playbookCategories as $id) {
if ($category = $this->playbookCategoryRepository->find($id)) {
$uuids[] = $category->getUuid();
}
}
return $uuids;
}
public function getDealAtCallStagesUuids(AutomatedReport $report): array
{
$uuids = [];
$reportStages = $report->getDealAtCallStages();
foreach ($reportStages as $id) {
if ($stage = $this->stageRepository->find($id)) {
$uuids[] = $stage->getUuid();
}
}
return $uuids;
}
public function getCurrentDealStagesUuids(AutomatedReport $report): array
{
$uuids = [];
$reportStages = $report->getCurrentDealStages();
foreach ($reportStages as $id) {
if ($stage = $this->stageRepository->find($id)) {
$uuids[] = $stage->getUuid();
}
}
return $uuids;
}
public function getUsersUuids(AutomatedReport $report): array
{
return $this->extractUserUuids($report->getRecipients());
}
public function getJiminnyUsersUuids(AutomatedReport $report): array
{
return $this->extractUserUuids($report->getJiminnyRecipients());
}
/**
* @param array<string, mixed> $recipients
*/
private function extractUserUuids(array $recipients): array
{
$userIds = $recipients['users'] ?? [];
return collect($userIds)
->map(fn ($id) => $this->userRepository->find((int) $id))
->filter()
->map(fn (UserContract $user) => $user->getUuid())
->values()
->all();
}
// get mail data
public function getRecipientUsers(AutomatedReport $report): array
{
return $this->buildRecipientUsers($report->getRecipients());
}
private function getJiminnyRecipientUsers(AutomatedReport $report): array
{
return $this->buildRecipientUsers($report->getJiminnyRecipients());
}
/**
* @param array<string, mixed> $recipients
*/
private function buildRecipientUsers(array $recipients): array
{
$userIds = $recipients['users'] ?? [];
return collect($userIds)
->map(fn ($id) => $this->userRepository->find((int) $id))
->filter()
->map(fn (UserContract $user) => [
'email' => $user->getEmailAddress(),
'name' => $user->getName(),
'timezone' => $user->getTimezone()->getName(),
])
->values()
->all();
}
public function getValidRecipientUsers(AutomatedReport $report, bool $includeJiminny = false): array
{
if ($report->isAskJiminnyReport()) {
$recipients = $this->resolveAskJiminnyRecipients($report);
} else {
$recipients = $this->getRecipientUsers($report);
if ($includeJiminny) {
$recipients = array_merge($recipients, $this->getJiminnyRecipientUsers($report));
}
}
$emails = [];
return array_values(array_filter(
$recipients,
static function ($recipient) use (&$emails) {
if (empty($recipient['email']) || in_array($recipient['email'], $emails, true)) {
return false;
}
$emails[] = $recipient['email'];
return true;
}
));
}
private function resolveAskJiminnyRecipients(AutomatedReport $report): array
{
$recipients = [];
$creator = $report->getCreator();
if ($creator !== null) {
$recipients[] = [
'email' => $creator->getEmailAddress(),
'name' => $creator->getName(),
'timezone' => $creator->getTimezone()->getName(),
];
}
return array_merge(
$recipients,
$this->buildRecipientUsers($report->getRecipients()),
$this->getGroupRecipientUsers($report),
);
}
private function getGroupRecipientUsers(AutomatedReport $report): array
{
$users = [];
foreach ($report->getGroups() as $groupId) {
$group = $this->groupRepository->find($groupId);
if ($group === null) {
continue;
}
foreach ($group->getMembers() as $member) {
$users[] = [
'email' => $member->getEmailAddress(),
'name' => $member->getName(),
'timezone' => $member->getTimezone()->getName(),
];
}
}
return $users;
}
public function getReportTypeName(AutomatedReportResult $report): string
{
$type = $report->getReport()->getType();
$getType = $this->transformReportType($type);
return $getType['name'];
}
public function getReportPeriodName(AutomatedReportResult $report): string
{
$from = $report->getFromDate();
$to = $report->getToDate();
$frequency = $report->getReport()->getFrequency();
if ($from === null || $to === null) {
if (! $report->getReport()->isAskJiminnyReport()) {
$invalidPeriod = $from === null ? 'from' : 'to';
throw new ApplicationException('Report period is invalid: ' . $invalidPeriod);
}
$period = $this->calculateFromAndToDatePeriod($frequency);
$from = $period['fromDate'];
$to = $period['toDate'];
}
return $this->formatReportPeriodName($frequency, $from, $to);
}
private function formatReportPeriodName(string $frequency, Carbon $from, Carbon $to): string
{
$fromYear = $from->format('Y');
$toYear = $to->format('Y');
$differentYears = $fromYear !== $toYear;
switch ($frequency) {
case self::FREQUENCY_DAILY:
return $from->format('j M Y');
case self::FREQUENCY_QUARTERLY:
// 'Jan-Mar 2025' or 'Nov 2024-Jan 2025' if years differ
$startMonth = $from->format('M');
$endMonth = $to->copy()->subMonth();
$endMonthName = $endMonth->format('M');
$endMonthYear = $endMonth->format('Y');
if ($differentYears) {
return "{$startMonth} {$fromYear} - {$endMonthName} {$endMonthYear}";
}
return "{$startMonth} - {$endMonthName} {$toYear}";
case self::FREQUENCY_MONTHLY:
// 'May 2025' - monthly reports are always within the same year
return $from->format('M Y');
case self::FREQUENCY_WEEKLY:
// '4 - 8 Aug 2025', '27 Oct - 3 Nov 2025', or '28 Dec 2024 - 3 Jan 2025' if years differ
$startDay = $from->format('j');
$endDay = $to->format('j');
$startMonth = $from->format('M');
$endMonth = $to->format('M');
if ($differentYears) {
return "{$startDay} {$startMonth} {$fromYear} - {$endDay} {$endMonth} {$toYear}";
}
if ($startMonth !== $endMonth) {
return "{$startDay} {$startMonth} - {$endDay} {$endMonth} {$toYear}";
}
return "{$startDay} - {$endDay} {$endMonth} {$toYear}";
case self::FREQUENCY_ONE_OFF:
// '2 May-31 May 2025' or '15 Dec 2024-15 Jan 2025' if years differ
$startDay = $from->format('j');
$startMonth = $from->format('M');
$endDay = $to->format('j');
$endMonth = $to->format('M');
// If same month and year, use a format like '2-31 May 2025'
if ($startMonth === $endMonth && ! $differentYears) {
return "{$startDay} - {$endDay} {$startMonth} {$toYear}";
}
// If different years, include both years
if ($differentYears) {
return "{$startDay} {$startMonth} {$fromYear} - {$endDay} {$endMonth} {$toYear}";
}
// Same year but different months
return "{$startDay} {$startMonth} - {$endDay} {$endMonth} {$toYear}";
default:
// Default format for unknown frequencies
return $from->format('j M Y') . ' - ' . $to->format('j M Y');
}
}
public function getReportTeamsName(AutomatedReportResult $report): string
{
$groups = $report->getGroups();
if (empty($groups)) {
return 'All';
}
// Get group names from repository
$groupNames = [];
foreach ($groups as $groupId) {
$group = $this->groupRepository->find($groupId);
if ($group) {
$groupNames[] = $group->getName();
}
}
if (count($groupNames) === 1) {
// Single team format
$teamsName = $groupNames[0];
} else {
// Multiple teams format
$teamsName = implode(', ', $groupNames);
}
return $teamsName;
}
public function getReportFileName(AutomatedReportResult $report): string
...
|
12308
|
|
12329
|
262
|
3
|
2026-04-14T11:07:01.691045+00:00
|
/Users/lukas/.screenpipe/data/data/2026-04-14/1776 /Users/lukas/.screenpipe/data/data/2026-04-14/1776164821691_m1.jpg...
|
PhpStorm
|
faVsco.js – AutomatedReportsService.php
|
1
|
NULL
|
monitor_1
|
NULL
|
NULL
|
NULL
|
NULL
|
Project: faVsco.js, menu
#11894 on JY-18909-automa Project: faVsco.js, menu
#11894 on JY-18909-automated-reports-ask-jiminny, menu
Start Listening for PHP Debug Connections
AutomatedReportsCommandTest
Run 'AutomatedReportsCommandTest'
Debug 'AutomatedReportsCommandTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Execute
Explain Plan
Browse Query History
View Parameters
Open Query Execution Settings…
In-Editor Results
Tx: Auto
Cancel Running Statements
Playground
jiminny
Sync Changes
Hide This Notification
Code changed:
Hide
16
13
13
Previous Highlighted Error
Next Highlighted Error
SELECT * FROM teams WHERE id = 1;
select * from crm_layouts where crm_configuration_id = 39;
SELECT * FROM crm_layout_entities WHERE crm_layout_id = 283;
SELECT * FROM crm_fields WHERE id = 2234;
SELECT * FROM crm_field_values WHERE crm_field_id = 2234;
select * from crm_profiles where user_id = 143;
select * from record_types where crm_configuration_id = 39; # 0121K000001MHElQAO,0121K000001MHEqQAO
select * from business_processes where crm_configuration_id = 39;
# 01941000000H669AAC, 01941000000H66JAAS
select * from record_type_field_values
where record_type_id IN (24);
select * from crm_field_values where id IN (2730);
select * from crm_configurations where id = 39;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 1
and sa.provider = 'salesforce'; #1035
select * from users where team_id = 1; # 222 group 3
SELECT * FROM activities WHERE user_id = 222 order by id desc;
select * from sidekick_settings where team_id = 1;
select * from teams where id = 1;
select * from team_features where team_id = 1;
select * from activities where crm_configuration_id = 2
and provider = 'ms-teams' and id = 608765;
SELECT * FROM activities WHERE crm_configuration_id = 2 and crm_provider_id = '59523413338';
select * from sidekick_settings where team_id = 2;
SELECT * FROM activities WHERE id = 608660;
select * from activity_summary_logs where activity_id = 608660;
select * from ai_prompts where transcription_id = 11214;
# [PASSWORD_DOTS]
SELECT * FROM activities WHERE uuid_to_bin('ed78a437-2804-450e-ab2f-56ab1c641346') = uuid;
# id: 608818, crm: 59628809737
SELECT * FROM activities WHERE uuid_to_bin('36b06e55-afdd-4782-8dee-c624cd0af191') = uuid;
# id: 608821, crm: 59632069252
SELECT ce.start_time, ce.end_time, a.id, a.uuid, crm_provider_id, calendar_event_id, title,
playbook_category_id, user_id, lead_id, contact_id, account_id, opportunity_id,
scheduled_start_time, scheduled_end_time, actual_start_time, actual_end_time, a.created_at
FROM activities a
join calendar_events ce on a.calendar_event_id = ce.id
WHERE a.id IN (608818, 608821);
select * from users where team_id = 1;
select * from team_settings where team_id = 1;
select * from crm_profiles where crm_configuration_id = 39 order by user_id;
select * from team_features where team_id = 1;
select * from users where team_id = 2;
SELECT * FROM activities WHERE uuid_to_bin('ec7647e9-5225-458b-b475-f31aa2769204') = uuid; # 612639
# Preslava N. Ivanova, grou id 3
SELECT * FROM opportunities WHERE uuid_to_bin('a2928fe5-aec5-46cb-85d9-7654c89e46a6') = uuid;
select * from activities where opportunity_id = 344 and actual_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00';
select
a.id,
a.type,
a.scheduled_start_time,
a.actual_start_time,
a.created_at,
a.opportunity_id,
a.status
FROM activities a
WHERE opportunity_id = 344
and status IN ('completed', 'received', 'delivered')
and (
(a.actual_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00')
OR (a.created_at between '2024-10-11 00:00:00' and '2024-10-12 00:00:00')
OR (a.scheduled_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00'))
;
SELECT * FROM users WHERE id = 222;
SELECT * FROM crm_profiles WHERE user_id = 222;
select * from crm_layouts where crm_configuration_id = 39;
SELECT * FROM crm_layout_entities WHERE crm_layout_id = 281;
select * from group_deal_risk_types;
select * from opportunities where team_id = 1;
SELECT * FROM opportunities WHERE id = 315;
SELECT * FROM crm_field_data WHERE object_id = 315;
select * from crm_field_data where object_id = 260;
select * from generic_ai_prompts where subject_id = 315;
select * from teams; # 36, 21, 121, [EMAIL]
SELECT * FROM social_accounts WHERE sociable_id = 121 and provider = 'bullhorn';
# [PASSWORD_DOTS]
select * from teams where id = 1;
select * from crm_configurations where id = 39;
select * from users where team_id = 1;
select u.email, cp.* from users u
join crm_profiles cp on u.id = cp.user_id
where u.team_id = 1;
# 1 - 00541000004281rAAA
# 204 - 0052g000003freeAAA
# 429 - 0052g000003qGOiAAM
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 1
and sa.provider = 'salesforce';
select * from activities where type = 'softphone'
and created_at > '2024-12-11 15:24:36' order by id desc;
select * from activity_providers where team_id = 1;
select * from activity_provider_users where activity_provider_id = 328;
select * from opportunities where crm_configuration_id = 39
AND account_id = 178 AND is_closed = false
order by created_at DESC;
select * from contacts where id = 3952;
select * from accounts where id = 178;
# [PASSWORD_DOTS]
select * from teams where id = 36;
select * from crm_configurations where id = 21;
select * from users where team_id = 36;
select u.email, cp.* from users u
join crm_profiles cp on u.id = cp.user_id
where u.team_id = 36;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 36
and sa.provider = 'bullhorn';
select * from social_accounts where id = 348;
UPDATE social_accounts SET
provider_user_token = '21442_6802599_91:41179a58-21e7-4d7c-ad58-56bb666b2f65',
provider_refresh_token = '21442_6802599_91:01c6b335-3f2a-42e4-85ff-8a08fa65fceb',
expires = 1733998131,
state = 'connected'
WHERE id = 348;
# [PASSWORD_DOTS]
select * from teams where id = 31;
select * from crm_configurations where id = 18;
select * from users where team_id = 31; # 257
select u.email, cp.* from users u
join crm_profiles cp on u.id = cp.user_id
where u.team_id = 31;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 31
and sa.provider = 'close';
select * from contacts where crm_configuration_id = 18;
# [PASSWORD_DOTS] NEPTUNE [PASSWORD_DOTS]
select * from teams;
select * from users where id IN (1030, 1035, 1052);
select * from crm_configurations;
select * from users where team_id = 65; # 257
select * from team_settings where team_id = 65; # 257
select * from invitations where team_id = 65; # 257
select * from users where email = '[EMAIL]'; # 257
select u.email, cp.* from users u
join crm_profiles cp on u.id = cp.user_id
where u.team_id = 65;
select * from crm_configurations where id = 53;
select * from accounts where crm_configuration_id = 53 order by id desc;
select * from leads where crm_configuration_id = 53 order by id desc;
select * from contacts where crm_configuration_id = 53 order by id desc;
select * from opportunities where crm_configuration_id = 53 order by id desc;
select * from crm_profiles where crm_configuration_id = 53 order by id desc;
select * from crm_fields where crm_configuration_id = 53 order by id desc;
select * from crm_field_values where crm_field_id = 3341 order by id desc;
select * from crm_layouts where crm_configuration_id = 53 order by id desc;
select * from stages where crm_configuration_id = 53 order by id desc;
select * from crm_profiles where crm_configuration_id = 13;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 65
and sa.provider = 'integration-app';
select * from contacts where crm_configuration_id = 13;
select * from social_accounts where sociable_id = 283;
SELECT * FROM opportunities WHERE crm_provider_id = '006O400000E9bzeIAB';
select * from activity_providers where team_id = 65;
SELECT * FROM activities WHERE crm_configuration_id IN (51, 52, 53);
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 65
;
# [PASSWORD_DOTS] STAGING [PASSWORD_DOTS]
SELECT * FROM teams;
SELECT * FROM teams WHERE id = 88;
SELECT * FROM teams WHERE id = 89;
select * from team_settings where team_id = 89;
SELECT * FROM users WHERE team_id = 89;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 89;
select * from users;
SELECT * FROM social_accounts WHERE sociable_id = 1761;
SELECT * FROM crm_configurations WHERE id = 70;
select * from accounts where crm_configuration_id = 70 order by id desc;
select * from leads where crm_configuration_id = 70 order by id desc;
select * from contacts where crm_configuration_id = 70 order by id desc;
select * from opportunities where crm_configuration_id = 70 order by id desc;
select * from crm_profiles where crm_configuration_id = 70 order by id desc;
select * from crm_fields where crm_configuration_id = 70 order by id desc;
select * from crm_field_values where crm_field_id = 3536 order by id desc;
select * from crm_layouts where crm_configuration_id = 70 order by id desc;
select * from stages where crm_configuration_id = 70 order by id desc;
select * from business_processes where crm_configuration_id = 70 order by id desc;
select * from business_process_stages where business_process_id = 34;
select * from contacts where id = 10468;
select * from crm_layouts where crm_configuration_id = 70;
SELECT * FROM crm_layout_entities WHERE crm_layout_id = 388;
SELECT * FROM crm_fields WHERE id IN (3533,3534,3535);
select * from activities where crm_configuration_id = 70
and (account_id IS NOT NULL or lead_id IS NOT NULL or contact_id IS NOT NULL or opportunity_id IS NOT NULL) order by id desc;
SELECT * FROM activities WHERE uuid_to_bin('2e10b60f-8a61-41c5-a3d4-28835353dc65') = uuid;
SELECT * FROM activities where crm_configuration_id = 69 ;
SELECT * FROM users WHERE email LIKE '%[EMAIL]%';
SELECT * FROM activities WHERE uuid_to_bin('5a150c93-40fc-42ec-b3bd-c1d328e09f6e') = uuid;
SELECT * FROM opportunities WHERE id = 385;
select * from participants p
join activities a on p.activity_id = a.id
where a.crm_configuration_id = 70
and (p.lead_id IS NOT NULL or p.contact_id IS NOT NULL);
SELECT * FROM participants WHERE id = 1013638;
select * from teams where id = 90;
select * from users where team_id = 90;
select * from social_accounts where social_accounts.sociable_id IN (1960,1760);
SELECT * FROM crm_profiles WHERE crm_configuration_id = 71;
select * from invitations where team_id = 90;
select * from crm_configurations where id = 71;
select * from accounts where crm_configuration_id = 71 order by id desc;
select * from leads where crm_configuration_id = 71 order by id desc;
select * from contacts where crm_configuration_id = 71 order by id desc;
select * from opportunities where crm_configuration_id = 71 order by id desc;
select * from crm_profiles where crm_configuration_id = 71 order by id desc;
select * from crm_fields where crm_configuration_id = 71 order by id desc;
select * from crm_field_values where crm_field_id = 3341 order by id desc;
select * from crm_layouts where crm_configuration_id = 71 order by id desc;
select * from stages where crm_configuration_id = 71 order by id desc;
select * from users order by secondary_email desc;
select u.id, u.email, u.status, sa.id, sa.provider_user_id from social_accounts sa
join users u on sa.sociable_id = u.id
where sa.provider = 'google' and u.email LIKE 'aneliya%';
select * from failed_jobs order by id desc;
select * from users where email = '[EMAIL]' or secondary_email = '[EMAIL]';
select * from teams;
SELECT * FROM crm_profiles WHERE crm_configuration_id = 39;
SELECT * FROM crm_fields WHERE crm_configuration_id = 39 and object_type = 'task';
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 1
and sa.provider = 'salesforce';
# [PASSWORD_DOTS]
SELECT * FROM activities WHERE uuid_to_bin('c38b3895-fd0f-4b1f-9fb2-c170dba137c6') = uuid;
SELECT * FROM crm_configurations WHERE id = 70;
select * from teams where id = 1;
select * from groups where team_id = 1;
select * from users where team_id = 1;
select o.id, o.name,o.close_date, u.id, u.name, u.group_id, r.id, r.display_name, g.name, g.scope from opportunities o
join users u on o.user_id = u.id
join groups g on u.group_id = g.id
join role_user ru on u.id = ru.user_id
join roles r on ru.role_id = r.id
where o.crm_configuration_id = 39 and close_date > '2024-01-01 00:00:00';
select * from role_user where user_id = 143;
select * from roles;
select * from role_user;
select * from groups where id = 9;
select * from scope_groups where group_id = 9;
# [PASSWORD_DOTS]
select * from teams where id = 36;
select * from crm_configurations;
SELECT * FROM social_accounts WHERE sociable_id = 121;
https://crmsandbox.zoho.com/crm/jiminnyw4/tab/Leads/4776201000005049105
https://crmsandbox.zoho.com/crm/
https://crm.zoho.com/crm/org3469620/tab/Leads/230045000229559080
https://crm.zoho.com/crm/
org3469620
SELECT * FROM activities WHERE uuid_to_bin('03382d20-c8bc-48e7-a3d4-90b52fa5ceab') = uuid;
select * from users where email LIKE "%mobile_automation_%";
select * from social_accounts where sociable_id IN (2228);
select * from crm_profiles where user_id IN (2222,2223,2226,2227);
select * from teams order by id desc;
SELECT * FROM users WHERE id = 2229;
SELECT * FROM crm_profiles WHERE user_id = 2229;
select * from opportunities where crm_configuration_id = 88;
select * from crm_fields where crm_configuration_id = 88;
select * from crm_profiles where crm_configuration_id = 88;
SELECT * FROM teams WHERE id = 1;
SELECT * FROM users WHERE id = 143;
SELECT * FROM users WHERE uuid_to_bin('fde193d3-06a2-4e1a-8895-62b94039215d') = uuid;
SELECT * FROM teams WHERE uuid_to_bin('73385071-a756-42ae-9c73-8b53f2309467') = uuid;
https://app.staging.jiminny.com/ondemand?
min_duration=1
&
only_recorded=1
&
user_id%5B%5D=641f1acb-16b8-42d1-8726-df52979dad0e
&
sequence_number=2
select * from users where team_id = 1 and email like '%stoyan%'
select * from coaching_feedbacks;
select * from teams;
SELECT * FROM users WHERE team_id = 36;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 19
and sa.provider = 'pipedrive';
select * from users where id = 143;
SELECT * FROM users WHERE uuid_to_bin('73180eeb-33de-4065-977d-ccbe0e6c94fc') = uuid;
SELECT * FROM teams WHERE uuid_to_bin('73180eeb-33de-4065-977d-ccbe0e6c94fc') = uuid;
SELECT * FROM activity_shares WHERE uuid_to_bin('73180eeb-33de-4065-977d-ccbe0e6c94fc') = uuid;
select * from users where team_id = 2;
select * from activities where crm_configuration_id = 39
and activities.scheduled_start_time BETWEEN '2025-04-09 00:00:00' AND '2025-04-09 23:59:59'
AND user_id = 143
order by id desc;
# [PASSWORD_DOTS]
select * from teams where id = 142; # 2312, 126
select * from team_settings;
select * from users where team_id = 142; # 21642
SELECT * FROM social_accounts WHERE sociable_id = 21642;
SELECT * FROM crm_profiles cp join users u ON u.id = cp.user_id WHERE team_id = 142;
select * from crm_profiles where id IN (93);
select * from invitations;
select * from team_features where team_id = 1;
SELECT * FROM crm_configurations WHERE id = 126;
select * from accounts where crm_configuration_id = 126 order by id desc;
select * from leads where crm_configuration_id = 126 order by id desc;
select * from contacts where crm_configuration_id = 126 order by id desc;
select * from opportunities where crm_configuration_id = 126 order by id desc;
select * from crm_profiles where crm_configuration_id = 126 order by id desc;
select * from crm_fields where crm_configuration_id = 126 # 11060
# and type IN ('picklist', 'status')
# and object_type = 'task'
order by id desc;
# 5731,5732,5733
select DISTINCT crm_field_id from crm_field_values where crm_field_id IN (11151,12239,12215,12185,12175,12165,12144,12137,12127,12109,12107,12105,12103,12092,12037,12005,12003,11987,11969,11958,11951,11942,11931,11924,11921,11917,11915,11901,11893,11883,11872,11870,11868,11866,11839,11833,11821,11793,11780,11777,11769,11757,11737,11735,11656,11645,11638,11629,11618,11611,11602,11591,11584,11581,11558,11544,11543,11534,11532,11529,11527,11503,11497,11493,11488,11470,11468,11457,11455,11397,11387,11372,11363,11348,11323,11318,11309,11301,11300,11292,11290,11286,11284,11256,11252,11242,11237,11233,11219,11176,11160) order by id desc;
select * from crm_layouts where crm_configuration_id = 126 order by id desc;
SELECT * FROM crm_layout_entities WHERE crm_layout_id in (300,299,298);
select * from stages where crm_configuration_id = 126 order by id desc;
select * from business_processes where crm_configuration_id = 126 order by id desc;
select * from business_process_stages where business_process_id IN (76,75,74,73);
select * from playbooks where team_id = 142;
select * from playbook_layouts where playbook_id IN (108);
SELECT * FROM playbook_categories WHERE playbook_id IN (108);
select * from teams where id = 130;
SELECT * FROM social_accounts WHERE sociable_id = 2291;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 2
and sa.provider = 'hubspot';
SELECT * FROM activities
WHERE crm_configuration_id = 110;
select * from teams;
select * from crm_configurations;
SELECT * FROM activities WHERE id = 628773;
SELECT * FROM crm_profiles WHERE user_id = 1460;
SELECT * FROM social_accounts WHERE sociable_id = 2291;
select * from teams;
select ru.*, pr.*, p.* from users u join role_user ru on ru.user_id = u.id
join permission_role pr on pr.role_id = ru.role_id
join permissions p on p.id = pr.permission_id
where team_id = 495 and p.name IN ('dial');
select * from teams where id = 145;
select * from crm_configurations where id = 129;
select * from social_accounts where sociable_id = 2317;
SELECT * FROM activities WHERE uuid_to_bin('8dbab184-a333-4268-ad57-fb41f8d53a9a') = uuid;
select * from teams where id = 1;
SELECT * FROM crm_layouts WHERE crm_configuration_id = 39;
SELECT * FROM crm_layout_entities WHERE crm_layout_id = 280;
SELECT * FROM crm_layout_entities WHERE id = 5507;
SELECT * FROM crm_fields WHERE crm_configuration_id = 39 and object_type IN ('event');
select * from teams;
select * from activities where crm_configuration_id = 14;
SELECT * FROM social_accounts where provider = 'copper';
select * from activities where id = 628467;
select * from participants where activity_id = 628467;
SELECT * FROM contacts WHERE id = 3969;
SELECT * FROM accounts WHERE id = 177;
SELECT * FROM activities WHERE uuid_to_bin('4eb54c77-cfa3-2bd4-84a7-9ed46a21c988') = uuid;
# [PASSWORD_DOTS] BH
select * from teams where id = 36;
SELECT * FROM crm_configurations WHERE id = 21;
select * from activities where crm_configuration_id = 21 and id = 607901;
select * from activities where crm_configuration_id = 21;
select * roles;
select * from permissions;
select * from permission_role where permission_id = 226;
select * from migrations order by id desc;
# mercury
# neptune
# earth
select * from teams;
select * from teams where id = 19;
select * from teams where id = 27;
select * from users where team_id = 27;
SELECT * FROM crm_configurations WHERE id = 42;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 19
and sa.provider = 'pipedrive';
select * from activities where id = 631461;
SELECT * FROM crm_field_values WHERE crm_field_id = 180;
select * from teams where id = 2;
SELECT * FROM social_accounts WHERE sociable_id = 89;
SELECT * FROM activities WHERE uuid_to_bin('ba0c029a-bc14-4e17-8603-64174acebcbb') = uuid; # 634273
select * from activity_summary_logs where activity_id = 634273;
select * from sidekick_settings where team_id = 2;
select * from teams; # 2, 2
SELECT * FROM crm_configurations WHERE team_id = 2; # 2
select * from team_features where team_id = 2;
select * from features;
SELECT * FROM opportunities WHERE crm_configuration_id = 2 and crm_provider_id = '51317301383';
SELECT * FROM opportunities WHERE crm_configuration_id = 2 order by id desc;
select * from automated_reports order by id desc;
select * from automated_report_results order by id desc;
select * from users where team_id = 1 and id IN (7160, 3248);
select * from migrations order by id desc;
SELECT
CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,
u.email,
sa.*,
t.owner_id FROM social_accounts sa
JOIN users u on u.id = sa.sociable_id
JOIN teams t on t.id = u.team_id
WHERE u.team_id = 1 and sa.provider = 'salesforce';
select * from teams where id = 1;
select * from groups g JOIN playbooks p on g.playbook_id = p.id where g.team_id = 1;
select * from groups where id = 565;
select * from playbooks where team_id = 1;
select * from playbooks where id = 175;
select * from playbook_categories where playbook_id = 175;
select * from users where team_id = 1;
select * from users where id = 7160;
select * from crm_profiles where user_id = 7160;
select * from features;
select
*
# id, uuid, type, provider, playbook_category_id, user_id, lead_id, contact_id, account_id, opportunity_id, stage_id,
# crm_configuration_id, crm_provider_id, transcription_id, status
from activities where crm_configuration_id = 1 and type = 'conference'
# and crm_provider_id IS NOT NULL
and provider != 'uploader' and actual_start_time IS NOT NULL
ORDER by id desc;
select * from activities where id = 54747783; # 00UO400000pCzojMAC
select p.id, p.activity_type, pc.id, pc.name
FROM playbooks p
join playbook_categories pc on p.id = pc.playbook_id
where p.team_id = 1 and p.activity_type = 'event';
SELECT * FROM crm_fields WHERE crm_configuration_id = 1 and object_type = 'event';
SELECT * FROM crm_field_values WHERE crm_field_id = 4;
select * from crm_layouts cl join playbook_layouts pl on cl.id = pl.layout_id
where crm_configuration_id = 1 and pl.playbook_id = 175;
select * from teams;
SELECT r.* FROM automated_reports r
join teams t on r.team_id = t.id
WHERE r.frequency = 'daily'
and r.status = 1
AND t.status = 'active'
AND (r.expires_at >= now() OR r.expires_at IS NULL);
select * from automated_report_results where report_id IN (18, 33);
select * from activity_searches where id = 10932;
select * from activity_search_filters where activity_search_id = 10932;
select * from automated_reports;
select * from automated_report_results where report_id IN (34, 35);
Sync Changes
Hide This Notification
Code changed:
Hide...
|
[{"role":"AXButton","text" [{"role":"AXButton","text":"Project: faVsco.js, menu","depth":5,"help_text":"~/jiminny/app","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"#11894 on JY-18909-automated-reports-ask-jiminny, menu","depth":5,"help_text":"Pull request #11894 exists for current branch JY-18909-automated-reports-ask-jiminny","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Start Listening for PHP Debug Connections","depth":5,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"AutomatedReportsCommandTest","depth":6,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Run 'AutomatedReportsCommandTest'","depth":6,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Debug 'AutomatedReportsCommandTest'","depth":6,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"More Actions","depth":6,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JetBrains AI","depth":5,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Search Everywhere","depth":5,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"IDE and Project Settings","depth":5,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Execute","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Explain Plan","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Browse Query History","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"View Parameters","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Open Query Execution Settings…","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"In-Editor Results","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Tx: Auto","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Cancel Running Statements","depth":4,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Playground","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"jiminny","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.088194445,"height":0.027777778},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"16","depth":4,"role_description":"text"},{"role":"AXStaticText","text":"13","depth":4,"role_description":"text"},{"role":"AXStaticText","text":"13","depth":4,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"SELECT * FROM teams WHERE id = 1;\n\nselect * from crm_layouts where crm_configuration_id = 39;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 283;\nSELECT * FROM crm_fields WHERE id = 2234;\nSELECT * FROM crm_field_values WHERE crm_field_id = 2234;\n\nselect * from crm_profiles where user_id = 143;\n\nselect * from record_types where crm_configuration_id = 39; # 0121K000001MHElQAO,0121K000001MHEqQAO\nselect * from business_processes where crm_configuration_id = 39;\n# 01941000000H669AAC, 01941000000H66JAAS\n\nselect * from record_type_field_values\n where record_type_id IN (24);\n\nselect * from crm_field_values where id IN (2730);\n\nselect * from crm_configurations where id = 39;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 1\nand sa.provider = 'salesforce'; #1035\n\n\nselect * from users where team_id = 1; # 222 group 3\nSELECT * FROM activities WHERE user_id = 222 order by id desc;\nselect * from sidekick_settings where team_id = 1;\nselect * from teams where id = 1;\nselect * from team_features where team_id = 1;\n\nselect * from activities where crm_configuration_id = 2\nand provider = 'ms-teams' and id = 608765;\n\nSELECT * FROM activities WHERE crm_configuration_id = 2 and crm_provider_id = '59523413338';\n\nselect * from sidekick_settings where team_id = 2;\n\nSELECT * FROM activities WHERE id = 608660;\nselect * from activity_summary_logs where activity_id = 608660;\nselect * from ai_prompts where transcription_id = 11214;\n\n# ********************************************************************************************************\nSELECT * FROM activities WHERE uuid_to_bin('ed78a437-2804-450e-ab2f-56ab1c641346') = uuid;\n# id: 608818, crm: 59628809737\nSELECT * FROM activities WHERE uuid_to_bin('36b06e55-afdd-4782-8dee-c624cd0af191') = uuid;\n# id: 608821, crm: 59632069252\nSELECT ce.start_time, ce.end_time, a.id, a.uuid, crm_provider_id, calendar_event_id, title,\nplaybook_category_id, user_id, lead_id, contact_id, account_id, opportunity_id,\nscheduled_start_time, scheduled_end_time, actual_start_time, actual_end_time, a.created_at\nFROM activities a\njoin calendar_events ce on a.calendar_event_id = ce.id\nWHERE a.id IN (608818, 608821);\n\nselect * from users where team_id = 1;\nselect * from team_settings where team_id = 1;\nselect * from crm_profiles where crm_configuration_id = 39 order by user_id;\n\nselect * from team_features where team_id = 1;\n\nselect * from users where team_id = 2;\n\nSELECT * FROM activities WHERE uuid_to_bin('ec7647e9-5225-458b-b475-f31aa2769204') = uuid; # 612639\n# Preslava N. Ivanova, grou id 3\n\nSELECT * FROM opportunities WHERE uuid_to_bin('a2928fe5-aec5-46cb-85d9-7654c89e46a6') = uuid;\n\nselect * from activities where opportunity_id = 344 and actual_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00';\n\nselect\n a.id,\n a.type,\n a.scheduled_start_time,\n a.actual_start_time,\n a.created_at,\n a.opportunity_id,\n a.status\nFROM activities a\nWHERE opportunity_id = 344\nand status IN ('completed', 'received', 'delivered')\nand (\n (a.actual_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00')\nOR (a.created_at between '2024-10-11 00:00:00' and '2024-10-12 00:00:00')\nOR (a.scheduled_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00'))\n;\n\nSELECT * FROM users WHERE id = 222;\n\nSELECT * FROM crm_profiles WHERE user_id = 222;\nselect * from crm_layouts where crm_configuration_id = 39;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 281;\n\nselect * from group_deal_risk_types;\n\nselect * from opportunities where team_id = 1;\n\nSELECT * FROM opportunities WHERE id = 315;\nSELECT * FROM crm_field_data WHERE object_id = 315;\nselect * from crm_field_data where object_id = 260;\n\nselect * from generic_ai_prompts where subject_id = 315;\n\nselect * from teams; # 36, 21, 121, james.graham@bullhorn.jiminny.com\nSELECT * FROM social_accounts WHERE sociable_id = 121 and provider = 'bullhorn';\n\n# ************************************************************************************\nselect * from teams where id = 1;\nselect * from crm_configurations where id = 39;\nselect * from users where team_id = 1;\nselect u.email, cp.* from users u\njoin crm_profiles cp on u.id = cp.user_id\nwhere u.team_id = 1;\n# 1 - 00541000004281rAAA\n# 204 - 0052g000003freeAAA\n# 429 - 0052g000003qGOiAAM\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 1\nand sa.provider = 'salesforce';\n\nselect * from activities where type = 'softphone'\nand created_at > '2024-12-11 15:24:36' order by id desc;\n\nselect * from activity_providers where team_id = 1;\nselect * from activity_provider_users where activity_provider_id = 328;\n\nselect * from opportunities where crm_configuration_id = 39\nAND account_id = 178 AND is_closed = false\norder by created_at DESC;\n\nselect * from contacts where id = 3952;\nselect * from accounts where id = 178;\n\n# ************************************************************************************\nselect * from teams where id = 36;\nselect * from crm_configurations where id = 21;\nselect * from users where team_id = 36;\nselect u.email, cp.* from users u\njoin crm_profiles cp on u.id = cp.user_id\nwhere u.team_id = 36;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 36\nand sa.provider = 'bullhorn';\n\nselect * from social_accounts where id = 348;\nUPDATE social_accounts SET\nprovider_user_token = '21442_6802599_91:41179a58-21e7-4d7c-ad58-56bb666b2f65',\nprovider_refresh_token = '21442_6802599_91:01c6b335-3f2a-42e4-85ff-8a08fa65fceb',\nexpires = 1733998131,\nstate = 'connected'\nWHERE id = 348;\n\n# ************************************************************************************\nselect * from teams where id = 31;\nselect * from crm_configurations where id = 18;\n\nselect * from users where team_id = 31; # 257\nselect u.email, cp.* from users u\njoin crm_profiles cp on u.id = cp.user_id\nwhere u.team_id = 31;\n\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 31\nand sa.provider = 'close';\n\nselect * from contacts where crm_configuration_id = 18;\n\n# ********************** NEPTUNE **************************************************************\nselect * from teams;\nselect * from users where id IN (1030, 1035, 1052);\nselect * from crm_configurations;\n\nselect * from users where team_id = 65; # 257\nselect * from team_settings where team_id = 65; # 257\nselect * from invitations where team_id = 65; # 257\nselect * from users where email = 'integration-account@jiminny.com'; # 257\nselect u.email, cp.* from users u\njoin crm_profiles cp on u.id = cp.user_id\nwhere u.team_id = 65;\n\nselect * from crm_configurations where id = 53;\nselect * from accounts where crm_configuration_id = 53 order by id desc;\nselect * from leads where crm_configuration_id = 53 order by id desc;\nselect * from contacts where crm_configuration_id = 53 order by id desc;\nselect * from opportunities where crm_configuration_id = 53 order by id desc;\nselect * from crm_profiles where crm_configuration_id = 53 order by id desc;\nselect * from crm_fields where crm_configuration_id = 53 order by id desc;\nselect * from crm_field_values where crm_field_id = 3341 order by id desc;\nselect * from crm_layouts where crm_configuration_id = 53 order by id desc;\nselect * from stages where crm_configuration_id = 53 order by id desc;\n\n\nselect * from crm_profiles where crm_configuration_id = 13;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 65\nand sa.provider = 'integration-app';\n\nselect * from contacts where crm_configuration_id = 13;\n\nselect * from social_accounts where sociable_id = 283;\n\nSELECT * FROM opportunities WHERE crm_provider_id = '006O400000E9bzeIAB';\n\nselect * from activity_providers where team_id = 65;\nSELECT * FROM activities WHERE crm_configuration_id IN (51, 52, 53);\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 65\n;\n\n# ***************************** STAGING ********************************************\nSELECT * FROM teams;\nSELECT * FROM teams WHERE id = 88;\nSELECT * FROM teams WHERE id = 89;\nselect * from team_settings where team_id = 89;\nSELECT * FROM users WHERE team_id = 89;\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 89;\n\nselect * from users;\nSELECT * FROM social_accounts WHERE sociable_id = 1761;\nSELECT * FROM crm_configurations WHERE id = 70;\nselect * from accounts where crm_configuration_id = 70 order by id desc;\nselect * from leads where crm_configuration_id = 70 order by id desc;\nselect * from contacts where crm_configuration_id = 70 order by id desc;\nselect * from opportunities where crm_configuration_id = 70 order by id desc;\nselect * from crm_profiles where crm_configuration_id = 70 order by id desc;\nselect * from crm_fields where crm_configuration_id = 70 order by id desc;\nselect * from crm_field_values where crm_field_id = 3536 order by id desc;\nselect * from crm_layouts where crm_configuration_id = 70 order by id desc;\nselect * from stages where crm_configuration_id = 70 order by id desc;\nselect * from business_processes where crm_configuration_id = 70 order by id desc;\nselect * from business_process_stages where business_process_id = 34;\n\nselect * from contacts where id = 10468;\n\nselect * from crm_layouts where crm_configuration_id = 70;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 388;\nSELECT * FROM crm_fields WHERE id IN (3533,3534,3535);\n\nselect * from activities where crm_configuration_id = 70\nand (account_id IS NOT NULL or lead_id IS NOT NULL or contact_id IS NOT NULL or opportunity_id IS NOT NULL) order by id desc;\n\nSELECT * FROM activities WHERE uuid_to_bin('2e10b60f-8a61-41c5-a3d4-28835353dc65') = uuid;\nSELECT * FROM activities where crm_configuration_id = 69 ;\n\nSELECT * FROM users WHERE email LIKE '%jiminny_web_sa2@jiminny.com%';\nSELECT * FROM activities WHERE uuid_to_bin('5a150c93-40fc-42ec-b3bd-c1d328e09f6e') = uuid;\nSELECT * FROM opportunities WHERE id = 385;\n\nselect * from participants p\njoin activities a on p.activity_id = a.id\nwhere a.crm_configuration_id = 70\nand (p.lead_id IS NOT NULL or p.contact_id IS NOT NULL);\nSELECT * FROM participants WHERE id = 1013638;\n\nselect * from teams where id = 90;\nselect * from users where team_id = 90;\nselect * from social_accounts where social_accounts.sociable_id IN (1960,1760);\nSELECT * FROM crm_profiles WHERE crm_configuration_id = 71;\nselect * from invitations where team_id = 90;\n\nselect * from crm_configurations where id = 71;\nselect * from accounts where crm_configuration_id = 71 order by id desc;\nselect * from leads where crm_configuration_id = 71 order by id desc;\nselect * from contacts where crm_configuration_id = 71 order by id desc;\nselect * from opportunities where crm_configuration_id = 71 order by id desc;\nselect * from crm_profiles where crm_configuration_id = 71 order by id desc;\nselect * from crm_fields where crm_configuration_id = 71 order by id desc;\nselect * from crm_field_values where crm_field_id = 3341 order by id desc;\nselect * from crm_layouts where crm_configuration_id = 71 order by id desc;\nselect * from stages where crm_configuration_id = 71 order by id desc;\n\nselect * from users order by secondary_email desc;\nselect u.id, u.email, u.status, sa.id, sa.provider_user_id from social_accounts sa\n join users u on sa.sociable_id = u.id\nwhere sa.provider = 'google' and u.email LIKE 'aneliya%';\n\nselect * from failed_jobs order by id desc;\n\nselect * from users where email = 'ben.allwright@learningpeople.co.uk' or secondary_email = 'ben.allwright@learningpeople.co.uk';\n\nselect * from teams;\nSELECT * FROM crm_profiles WHERE crm_configuration_id = 39;\nSELECT * FROM crm_fields WHERE crm_configuration_id = 39 and object_type = 'task';\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 1\nand sa.provider = 'salesforce';\n\n# ************************************************************************************\nSELECT * FROM activities WHERE uuid_to_bin('c38b3895-fd0f-4b1f-9fb2-c170dba137c6') = uuid;\nSELECT * FROM crm_configurations WHERE id = 70;\n\nselect * from teams where id = 1;\nselect * from groups where team_id = 1;\nselect * from users where team_id = 1;\n\nselect o.id, o.name,o.close_date, u.id, u.name, u.group_id, r.id, r.display_name, g.name, g.scope from opportunities o\njoin users u on o.user_id = u.id\njoin groups g on u.group_id = g.id\njoin role_user ru on u.id = ru.user_id\njoin roles r on ru.role_id = r.id\nwhere o.crm_configuration_id = 39 and close_date > '2024-01-01 00:00:00';\n\nselect * from role_user where user_id = 143;\nselect * from roles;\n\nselect * from role_user;\nselect * from groups where id = 9;\nselect * from scope_groups where group_id = 9;\n\n# ************************************************************************************\nselect * from teams where id = 36;\nselect * from crm_configurations;\nSELECT * FROM social_accounts WHERE sociable_id = 121;\n\nhttps://crmsandbox.zoho.com/crm/jiminnyw4/tab/Leads/4776201000005049105\nhttps://crmsandbox.zoho.com/crm/\n\nhttps://crm.zoho.com/crm/org3469620/tab/Leads/230045000229559080\n https://crm.zoho.com/crm/\n org3469620\n\nSELECT * FROM activities WHERE uuid_to_bin('03382d20-c8bc-48e7-a3d4-90b52fa5ceab') = uuid;\n\nselect * from users where email LIKE \"%mobile_automation_%\";\nselect * from social_accounts where sociable_id IN (2228);\nselect * from crm_profiles where user_id IN (2222,2223,2226,2227);\n\nselect * from teams order by id desc;\nSELECT * FROM users WHERE id = 2229;\nSELECT * FROM crm_profiles WHERE user_id = 2229;\nselect * from opportunities where crm_configuration_id = 88;\nselect * from crm_fields where crm_configuration_id = 88;\nselect * from crm_profiles where crm_configuration_id = 88;\n\nSELECT * FROM teams WHERE id = 1;\n\nSELECT * FROM users WHERE id = 143;\nSELECT * FROM users WHERE uuid_to_bin('fde193d3-06a2-4e1a-8895-62b94039215d') = uuid;\nSELECT * FROM teams WHERE uuid_to_bin('73385071-a756-42ae-9c73-8b53f2309467') = uuid;\n\nhttps://app.staging.jiminny.com/ondemand?\n min_duration=1\n &\n only_recorded=1\n &\n user_id%5B%5D=641f1acb-16b8-42d1-8726-df52979dad0e\n &\n sequence_number=2\n\n select * from users where team_id = 1 and email like '%stoyan%'\n\nselect * from coaching_feedbacks;\n\nselect * from teams;\nSELECT * FROM users WHERE team_id = 36;\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 19\nand sa.provider = 'pipedrive';\n\nselect * from users where id = 143;\n\nSELECT * FROM users WHERE uuid_to_bin('73180eeb-33de-4065-977d-ccbe0e6c94fc') = uuid;\nSELECT * FROM teams WHERE uuid_to_bin('73180eeb-33de-4065-977d-ccbe0e6c94fc') = uuid;\nSELECT * FROM activity_shares WHERE uuid_to_bin('73180eeb-33de-4065-977d-ccbe0e6c94fc') = uuid;\n\nselect * from users where team_id = 2;\nselect * from activities where crm_configuration_id = 39\nand activities.scheduled_start_time BETWEEN '2025-04-09 00:00:00' AND '2025-04-09 23:59:59'\nAND user_id = 143\norder by id desc;\n\n# ************************************************************************************\nselect * from teams where id = 142; # 2312, 126\nselect * from team_settings;\nselect * from users where team_id = 142; # 21642\nSELECT * FROM social_accounts WHERE sociable_id = 21642;\nSELECT * FROM crm_profiles cp join users u ON u.id = cp.user_id WHERE team_id = 142;\nselect * from crm_profiles where id IN (93);\nselect * from invitations;\nselect * from team_features where team_id = 1;\n\nSELECT * FROM crm_configurations WHERE id = 126;\nselect * from accounts where crm_configuration_id = 126 order by id desc;\nselect * from leads where crm_configuration_id = 126 order by id desc;\nselect * from contacts where crm_configuration_id = 126 order by id desc;\nselect * from opportunities where crm_configuration_id = 126 order by id desc;\nselect * from crm_profiles where crm_configuration_id = 126 order by id desc;\nselect * from crm_fields where crm_configuration_id = 126 # 11060\n# and type IN ('picklist', 'status')\n# and object_type = 'task'\norder by id desc;\n# 5731,5732,5733\nselect DISTINCT crm_field_id from crm_field_values where crm_field_id IN (11151,12239,12215,12185,12175,12165,12144,12137,12127,12109,12107,12105,12103,12092,12037,12005,12003,11987,11969,11958,11951,11942,11931,11924,11921,11917,11915,11901,11893,11883,11872,11870,11868,11866,11839,11833,11821,11793,11780,11777,11769,11757,11737,11735,11656,11645,11638,11629,11618,11611,11602,11591,11584,11581,11558,11544,11543,11534,11532,11529,11527,11503,11497,11493,11488,11470,11468,11457,11455,11397,11387,11372,11363,11348,11323,11318,11309,11301,11300,11292,11290,11286,11284,11256,11252,11242,11237,11233,11219,11176,11160) order by id desc;\nselect * from crm_layouts where crm_configuration_id = 126 order by id desc;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id in (300,299,298);\nselect * from stages where crm_configuration_id = 126 order by id desc;\nselect * from business_processes where crm_configuration_id = 126 order by id desc;\nselect * from business_process_stages where business_process_id IN (76,75,74,73);\nselect * from playbooks where team_id = 142;\nselect * from playbook_layouts where playbook_id IN (108);\nSELECT * FROM playbook_categories WHERE playbook_id IN (108);\n\nselect * from teams where id = 130;\nSELECT * FROM social_accounts WHERE sociable_id = 2291;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 2\nand sa.provider = 'hubspot';\n\nSELECT * FROM activities\n WHERE crm_configuration_id = 110;\n\nselect * from teams;\nselect * from crm_configurations;\n\nSELECT * FROM activities WHERE id = 628773;\nSELECT * FROM crm_profiles WHERE user_id = 1460;\nSELECT * FROM social_accounts WHERE sociable_id = 2291;\n\nselect * from teams;\nselect ru.*, pr.*, p.* from users u join role_user ru on ru.user_id = u.id\njoin permission_role pr on pr.role_id = ru.role_id\n join permissions p on p.id = pr.permission_id\nwhere team_id = 495 and p.name IN ('dial');\n\nselect * from teams where id = 145;\nselect * from crm_configurations where id = 129;\nselect * from social_accounts where sociable_id = 2317;\nSELECT * FROM activities WHERE uuid_to_bin('8dbab184-a333-4268-ad57-fb41f8d53a9a') = uuid;\n\nselect * from teams where id = 1;\nSELECT * FROM crm_layouts WHERE crm_configuration_id = 39;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 280;\nSELECT * FROM crm_layout_entities WHERE id = 5507;\nSELECT * FROM crm_fields WHERE crm_configuration_id = 39 and object_type IN ('event');\n\nselect * from teams;\nselect * from activities where crm_configuration_id = 14;\n\nSELECT * FROM social_accounts where provider = 'copper';\n\nselect * from activities where id = 628467;\nselect * from participants where activity_id = 628467;\n\nSELECT * FROM contacts WHERE id = 3969;\nSELECT * FROM accounts WHERE id = 177;\n\nSELECT * FROM activities WHERE uuid_to_bin('4eb54c77-cfa3-2bd4-84a7-9ed46a21c988') = uuid;\n\n# ********************* BH\nselect * from teams where id = 36;\nSELECT * FROM crm_configurations WHERE id = 21;\nselect * from activities where crm_configuration_id = 21 and id = 607901;\nselect * from activities where crm_configuration_id = 21;\n\nselect * roles;\nselect * from permissions;\nselect * from permission_role where permission_id = 226;\n\nselect * from migrations order by id desc;\n\n# mercury\n# neptune\n# earth\n\nselect * from teams;\nselect * from teams where id = 19;\nselect * from teams where id = 27;\nselect * from users where team_id = 27;\nSELECT * FROM crm_configurations WHERE id = 42;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 19\nand sa.provider = 'pipedrive';\n\nselect * from activities where id = 631461;\nSELECT * FROM crm_field_values WHERE crm_field_id = 180;\n\nselect * from teams where id = 2;\nSELECT * FROM social_accounts WHERE sociable_id = 89;\n\nSELECT * FROM activities WHERE uuid_to_bin('ba0c029a-bc14-4e17-8603-64174acebcbb') = uuid; # 634273\nselect * from activity_summary_logs where activity_id = 634273;\n\nselect * from sidekick_settings where team_id = 2;\n\nselect * from teams; # 2, 2\nSELECT * FROM crm_configurations WHERE team_id = 2; # 2\nselect * from team_features where team_id = 2;\nselect * from features;\nSELECT * FROM opportunities WHERE crm_configuration_id = 2 and crm_provider_id = '51317301383';\nSELECT * FROM opportunities WHERE crm_configuration_id = 2 order by id desc;\n\nselect * from automated_reports order by id desc;\nselect * from automated_report_results order by id desc;\nselect * from users where team_id = 1 and id IN (7160, 3248);\nselect * from migrations order by id desc;\n\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 1 and sa.provider = 'salesforce';\n\nselect * from teams where id = 1;\nselect * from groups g JOIN playbooks p on g.playbook_id = p.id where g.team_id = 1;\nselect * from groups where id = 565;\nselect * from playbooks where team_id = 1;\nselect * from playbooks where id = 175;\nselect * from playbook_categories where playbook_id = 175;\nselect * from users where team_id = 1;\nselect * from users where id = 7160;\nselect * from crm_profiles where user_id = 7160;\nselect * from features;\nselect\n *\n# id, uuid, type, provider, playbook_category_id, user_id, lead_id, contact_id, account_id, opportunity_id, stage_id,\n# crm_configuration_id, crm_provider_id, transcription_id, status\nfrom activities where crm_configuration_id = 1 and type = 'conference'\n# and crm_provider_id IS NOT NULL\nand provider != 'uploader' and actual_start_time IS NOT NULL\nORDER by id desc;\nselect * from activities where id = 54747783; # 00UO400000pCzojMAC\n\nselect p.id, p.activity_type, pc.id, pc.name\nFROM playbooks p\njoin playbook_categories pc on p.id = pc.playbook_id\nwhere p.team_id = 1 and p.activity_type = 'event';\n\nSELECT * FROM crm_fields WHERE crm_configuration_id = 1 and object_type = 'event';\nSELECT * FROM crm_field_values WHERE crm_field_id = 4;\n\nselect * from crm_layouts cl join playbook_layouts pl on cl.id = pl.layout_id\nwhere crm_configuration_id = 1 and pl.playbook_id = 175;\n\nselect * from teams;\nSELECT r.* FROM automated_reports r\njoin teams t on r.team_id = t.id\nWHERE r.frequency = 'daily'\n and r.status = 1\nAND t.status = 'active'\nAND (r.expires_at >= now() OR r.expires_at IS NULL);\n\nselect * from automated_report_results where report_id IN (18, 33);\n\nselect * from activity_searches where id = 10932;\nselect * from activity_search_filters where activity_search_id = 10932;\nselect * from automated_reports;\nselect * from automated_report_results where report_id IN (34, 35);","depth":4,"value":"SELECT * FROM teams WHERE id = 1;\n\nselect * from crm_layouts where crm_configuration_id = 39;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 283;\nSELECT * FROM crm_fields WHERE id = 2234;\nSELECT * FROM crm_field_values WHERE crm_field_id = 2234;\n\nselect * from crm_profiles where user_id = 143;\n\nselect * from record_types where crm_configuration_id = 39; # 0121K000001MHElQAO,0121K000001MHEqQAO\nselect * from business_processes where crm_configuration_id = 39;\n# 01941000000H669AAC, 01941000000H66JAAS\n\nselect * from record_type_field_values\n where record_type_id IN (24);\n\nselect * from crm_field_values where id IN (2730);\n\nselect * from crm_configurations where id = 39;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 1\nand sa.provider = 'salesforce'; #1035\n\n\nselect * from users where team_id = 1; # 222 group 3\nSELECT * FROM activities WHERE user_id = 222 order by id desc;\nselect * from sidekick_settings where team_id = 1;\nselect * from teams where id = 1;\nselect * from team_features where team_id = 1;\n\nselect * from activities where crm_configuration_id = 2\nand provider = 'ms-teams' and id = 608765;\n\nSELECT * FROM activities WHERE crm_configuration_id = 2 and crm_provider_id = '59523413338';\n\nselect * from sidekick_settings where team_id = 2;\n\nSELECT * FROM activities WHERE id = 608660;\nselect * from activity_summary_logs where activity_id = 608660;\nselect * from ai_prompts where transcription_id = 11214;\n\n# ********************************************************************************************************\nSELECT * FROM activities WHERE uuid_to_bin('ed78a437-2804-450e-ab2f-56ab1c641346') = uuid;\n# id: 608818, crm: 59628809737\nSELECT * FROM activities WHERE uuid_to_bin('36b06e55-afdd-4782-8dee-c624cd0af191') = uuid;\n# id: 608821, crm: 59632069252\nSELECT ce.start_time, ce.end_time, a.id, a.uuid, crm_provider_id, calendar_event_id, title,\nplaybook_category_id, user_id, lead_id, contact_id, account_id, opportunity_id,\nscheduled_start_time, scheduled_end_time, actual_start_time, actual_end_time, a.created_at\nFROM activities a\njoin calendar_events ce on a.calendar_event_id = ce.id\nWHERE a.id IN (608818, 608821);\n\nselect * from users where team_id = 1;\nselect * from team_settings where team_id = 1;\nselect * from crm_profiles where crm_configuration_id = 39 order by user_id;\n\nselect * from team_features where team_id = 1;\n\nselect * from users where team_id = 2;\n\nSELECT * FROM activities WHERE uuid_to_bin('ec7647e9-5225-458b-b475-f31aa2769204') = uuid; # 612639\n# Preslava N. Ivanova, grou id 3\n\nSELECT * FROM opportunities WHERE uuid_to_bin('a2928fe5-aec5-46cb-85d9-7654c89e46a6') = uuid;\n\nselect * from activities where opportunity_id = 344 and actual_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00';\n\nselect\n a.id,\n a.type,\n a.scheduled_start_time,\n a.actual_start_time,\n a.created_at,\n a.opportunity_id,\n a.status\nFROM activities a\nWHERE opportunity_id = 344\nand status IN ('completed', 'received', 'delivered')\nand (\n (a.actual_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00')\nOR (a.created_at between '2024-10-11 00:00:00' and '2024-10-12 00:00:00')\nOR (a.scheduled_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00'))\n;\n\nSELECT * FROM users WHERE id = 222;\n\nSELECT * FROM crm_profiles WHERE user_id = 222;\nselect * from crm_layouts where crm_configuration_id = 39;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 281;\n\nselect * from group_deal_risk_types;\n\nselect * from opportunities where team_id = 1;\n\nSELECT * FROM opportunities WHERE id = 315;\nSELECT * FROM crm_field_data WHERE object_id = 315;\nselect * from crm_field_data where object_id = 260;\n\nselect * from generic_ai_prompts where subject_id = 315;\n\nselect * from teams; # 36, 21, 121, james.graham@bullhorn.jiminny.com\nSELECT * FROM social_accounts WHERE sociable_id = 121 and provider = 'bullhorn';\n\n# ************************************************************************************\nselect * from teams where id = 1;\nselect * from crm_configurations where id = 39;\nselect * from users where team_id = 1;\nselect u.email, cp.* from users u\njoin crm_profiles cp on u.id = cp.user_id\nwhere u.team_id = 1;\n# 1 - 00541000004281rAAA\n# 204 - 0052g000003freeAAA\n# 429 - 0052g000003qGOiAAM\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 1\nand sa.provider = 'salesforce';\n\nselect * from activities where type = 'softphone'\nand created_at > '2024-12-11 15:24:36' order by id desc;\n\nselect * from activity_providers where team_id = 1;\nselect * from activity_provider_users where activity_provider_id = 328;\n\nselect * from opportunities where crm_configuration_id = 39\nAND account_id = 178 AND is_closed = false\norder by created_at DESC;\n\nselect * from contacts where id = 3952;\nselect * from accounts where id = 178;\n\n# ************************************************************************************\nselect * from teams where id = 36;\nselect * from crm_configurations where id = 21;\nselect * from users where team_id = 36;\nselect u.email, cp.* from users u\njoin crm_profiles cp on u.id = cp.user_id\nwhere u.team_id = 36;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 36\nand sa.provider = 'bullhorn';\n\nselect * from social_accounts where id = 348;\nUPDATE social_accounts SET\nprovider_user_token = '21442_6802599_91:41179a58-21e7-4d7c-ad58-56bb666b2f65',\nprovider_refresh_token = '21442_6802599_91:01c6b335-3f2a-42e4-85ff-8a08fa65fceb',\nexpires = 1733998131,\nstate = 'connected'\nWHERE id = 348;\n\n# ************************************************************************************\nselect * from teams where id = 31;\nselect * from crm_configurations where id = 18;\n\nselect * from users where team_id = 31; # 257\nselect u.email, cp.* from users u\njoin crm_profiles cp on u.id = cp.user_id\nwhere u.team_id = 31;\n\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 31\nand sa.provider = 'close';\n\nselect * from contacts where crm_configuration_id = 18;\n\n# ********************** NEPTUNE **************************************************************\nselect * from teams;\nselect * from users where id IN (1030, 1035, 1052);\nselect * from crm_configurations;\n\nselect * from users where team_id = 65; # 257\nselect * from team_settings where team_id = 65; # 257\nselect * from invitations where team_id = 65; # 257\nselect * from users where email = 'integration-account@jiminny.com'; # 257\nselect u.email, cp.* from users u\njoin crm_profiles cp on u.id = cp.user_id\nwhere u.team_id = 65;\n\nselect * from crm_configurations where id = 53;\nselect * from accounts where crm_configuration_id = 53 order by id desc;\nselect * from leads where crm_configuration_id = 53 order by id desc;\nselect * from contacts where crm_configuration_id = 53 order by id desc;\nselect * from opportunities where crm_configuration_id = 53 order by id desc;\nselect * from crm_profiles where crm_configuration_id = 53 order by id desc;\nselect * from crm_fields where crm_configuration_id = 53 order by id desc;\nselect * from crm_field_values where crm_field_id = 3341 order by id desc;\nselect * from crm_layouts where crm_configuration_id = 53 order by id desc;\nselect * from stages where crm_configuration_id = 53 order by id desc;\n\n\nselect * from crm_profiles where crm_configuration_id = 13;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 65\nand sa.provider = 'integration-app';\n\nselect * from contacts where crm_configuration_id = 13;\n\nselect * from social_accounts where sociable_id = 283;\n\nSELECT * FROM opportunities WHERE crm_provider_id = '006O400000E9bzeIAB';\n\nselect * from activity_providers where team_id = 65;\nSELECT * FROM activities WHERE crm_configuration_id IN (51, 52, 53);\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 65\n;\n\n# ***************************** STAGING ********************************************\nSELECT * FROM teams;\nSELECT * FROM teams WHERE id = 88;\nSELECT * FROM teams WHERE id = 89;\nselect * from team_settings where team_id = 89;\nSELECT * FROM users WHERE team_id = 89;\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 89;\n\nselect * from users;\nSELECT * FROM social_accounts WHERE sociable_id = 1761;\nSELECT * FROM crm_configurations WHERE id = 70;\nselect * from accounts where crm_configuration_id = 70 order by id desc;\nselect * from leads where crm_configuration_id = 70 order by id desc;\nselect * from contacts where crm_configuration_id = 70 order by id desc;\nselect * from opportunities where crm_configuration_id = 70 order by id desc;\nselect * from crm_profiles where crm_configuration_id = 70 order by id desc;\nselect * from crm_fields where crm_configuration_id = 70 order by id desc;\nselect * from crm_field_values where crm_field_id = 3536 order by id desc;\nselect * from crm_layouts where crm_configuration_id = 70 order by id desc;\nselect * from stages where crm_configuration_id = 70 order by id desc;\nselect * from business_processes where crm_configuration_id = 70 order by id desc;\nselect * from business_process_stages where business_process_id = 34;\n\nselect * from contacts where id = 10468;\n\nselect * from crm_layouts where crm_configuration_id = 70;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 388;\nSELECT * FROM crm_fields WHERE id IN (3533,3534,3535);\n\nselect * from activities where crm_configuration_id = 70\nand (account_id IS NOT NULL or lead_id IS NOT NULL or contact_id IS NOT NULL or opportunity_id IS NOT NULL) order by id desc;\n\nSELECT * FROM activities WHERE uuid_to_bin('2e10b60f-8a61-41c5-a3d4-28835353dc65') = uuid;\nSELECT * FROM activities where crm_configuration_id = 69 ;\n\nSELECT * FROM users WHERE email LIKE '%jiminny_web_sa2@jiminny.com%';\nSELECT * FROM activities WHERE uuid_to_bin('5a150c93-40fc-42ec-b3bd-c1d328e09f6e') = uuid;\nSELECT * FROM opportunities WHERE id = 385;\n\nselect * from participants p\njoin activities a on p.activity_id = a.id\nwhere a.crm_configuration_id = 70\nand (p.lead_id IS NOT NULL or p.contact_id IS NOT NULL);\nSELECT * FROM participants WHERE id = 1013638;\n\nselect * from teams where id = 90;\nselect * from users where team_id = 90;\nselect * from social_accounts where social_accounts.sociable_id IN (1960,1760);\nSELECT * FROM crm_profiles WHERE crm_configuration_id = 71;\nselect * from invitations where team_id = 90;\n\nselect * from crm_configurations where id = 71;\nselect * from accounts where crm_configuration_id = 71 order by id desc;\nselect * from leads where crm_configuration_id = 71 order by id desc;\nselect * from contacts where crm_configuration_id = 71 order by id desc;\nselect * from opportunities where crm_configuration_id = 71 order by id desc;\nselect * from crm_profiles where crm_configuration_id = 71 order by id desc;\nselect * from crm_fields where crm_configuration_id = 71 order by id desc;\nselect * from crm_field_values where crm_field_id = 3341 order by id desc;\nselect * from crm_layouts where crm_configuration_id = 71 order by id desc;\nselect * from stages where crm_configuration_id = 71 order by id desc;\n\nselect * from users order by secondary_email desc;\nselect u.id, u.email, u.status, sa.id, sa.provider_user_id from social_accounts sa\n join users u on sa.sociable_id = u.id\nwhere sa.provider = 'google' and u.email LIKE 'aneliya%';\n\nselect * from failed_jobs order by id desc;\n\nselect * from users where email = 'ben.allwright@learningpeople.co.uk' or secondary_email = 'ben.allwright@learningpeople.co.uk';\n\nselect * from teams;\nSELECT * FROM crm_profiles WHERE crm_configuration_id = 39;\nSELECT * FROM crm_fields WHERE crm_configuration_id = 39 and object_type = 'task';\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 1\nand sa.provider = 'salesforce';\n\n# ************************************************************************************\nSELECT * FROM activities WHERE uuid_to_bin('c38b3895-fd0f-4b1f-9fb2-c170dba137c6') = uuid;\nSELECT * FROM crm_configurations WHERE id = 70;\n\nselect * from teams where id = 1;\nselect * from groups where team_id = 1;\nselect * from users where team_id = 1;\n\nselect o.id, o.name,o.close_date, u.id, u.name, u.group_id, r.id, r.display_name, g.name, g.scope from opportunities o\njoin users u on o.user_id = u.id\njoin groups g on u.group_id = g.id\njoin role_user ru on u.id = ru.user_id\njoin roles r on ru.role_id = r.id\nwhere o.crm_configuration_id = 39 and close_date > '2024-01-01 00:00:00';\n\nselect * from role_user where user_id = 143;\nselect * from roles;\n\nselect * from role_user;\nselect * from groups where id = 9;\nselect * from scope_groups where group_id = 9;\n\n# ************************************************************************************\nselect * from teams where id = 36;\nselect * from crm_configurations;\nSELECT * FROM social_accounts WHERE sociable_id = 121;\n\nhttps://crmsandbox.zoho.com/crm/jiminnyw4/tab/Leads/4776201000005049105\nhttps://crmsandbox.zoho.com/crm/\n\nhttps://crm.zoho.com/crm/org3469620/tab/Leads/230045000229559080\n https://crm.zoho.com/crm/\n org3469620\n\nSELECT * FROM activities WHERE uuid_to_bin('03382d20-c8bc-48e7-a3d4-90b52fa5ceab') = uuid;\n\nselect * from users where email LIKE \"%mobile_automation_%\";\nselect * from social_accounts where sociable_id IN (2228);\nselect * from crm_profiles where user_id IN (2222,2223,2226,2227);\n\nselect * from teams order by id desc;\nSELECT * FROM users WHERE id = 2229;\nSELECT * FROM crm_profiles WHERE user_id = 2229;\nselect * from opportunities where crm_configuration_id = 88;\nselect * from crm_fields where crm_configuration_id = 88;\nselect * from crm_profiles where crm_configuration_id = 88;\n\nSELECT * FROM teams WHERE id = 1;\n\nSELECT * FROM users WHERE id = 143;\nSELECT * FROM users WHERE uuid_to_bin('fde193d3-06a2-4e1a-8895-62b94039215d') = uuid;\nSELECT * FROM teams WHERE uuid_to_bin('73385071-a756-42ae-9c73-8b53f2309467') = uuid;\n\nhttps://app.staging.jiminny.com/ondemand?\n min_duration=1\n &\n only_recorded=1\n &\n user_id%5B%5D=641f1acb-16b8-42d1-8726-df52979dad0e\n &\n sequence_number=2\n\n select * from users where team_id = 1 and email like '%stoyan%'\n\nselect * from coaching_feedbacks;\n\nselect * from teams;\nSELECT * FROM users WHERE team_id = 36;\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 19\nand sa.provider = 'pipedrive';\n\nselect * from users where id = 143;\n\nSELECT * FROM users WHERE uuid_to_bin('73180eeb-33de-4065-977d-ccbe0e6c94fc') = uuid;\nSELECT * FROM teams WHERE uuid_to_bin('73180eeb-33de-4065-977d-ccbe0e6c94fc') = uuid;\nSELECT * FROM activity_shares WHERE uuid_to_bin('73180eeb-33de-4065-977d-ccbe0e6c94fc') = uuid;\n\nselect * from users where team_id = 2;\nselect * from activities where crm_configuration_id = 39\nand activities.scheduled_start_time BETWEEN '2025-04-09 00:00:00' AND '2025-04-09 23:59:59'\nAND user_id = 143\norder by id desc;\n\n# ************************************************************************************\nselect * from teams where id = 142; # 2312, 126\nselect * from team_settings;\nselect * from users where team_id = 142; # 21642\nSELECT * FROM social_accounts WHERE sociable_id = 21642;\nSELECT * FROM crm_profiles cp join users u ON u.id = cp.user_id WHERE team_id = 142;\nselect * from crm_profiles where id IN (93);\nselect * from invitations;\nselect * from team_features where team_id = 1;\n\nSELECT * FROM crm_configurations WHERE id = 126;\nselect * from accounts where crm_configuration_id = 126 order by id desc;\nselect * from leads where crm_configuration_id = 126 order by id desc;\nselect * from contacts where crm_configuration_id = 126 order by id desc;\nselect * from opportunities where crm_configuration_id = 126 order by id desc;\nselect * from crm_profiles where crm_configuration_id = 126 order by id desc;\nselect * from crm_fields where crm_configuration_id = 126 # 11060\n# and type IN ('picklist', 'status')\n# and object_type = 'task'\norder by id desc;\n# 5731,5732,5733\nselect DISTINCT crm_field_id from crm_field_values where crm_field_id IN (11151,12239,12215,12185,12175,12165,12144,12137,12127,12109,12107,12105,12103,12092,12037,12005,12003,11987,11969,11958,11951,11942,11931,11924,11921,11917,11915,11901,11893,11883,11872,11870,11868,11866,11839,11833,11821,11793,11780,11777,11769,11757,11737,11735,11656,11645,11638,11629,11618,11611,11602,11591,11584,11581,11558,11544,11543,11534,11532,11529,11527,11503,11497,11493,11488,11470,11468,11457,11455,11397,11387,11372,11363,11348,11323,11318,11309,11301,11300,11292,11290,11286,11284,11256,11252,11242,11237,11233,11219,11176,11160) order by id desc;\nselect * from crm_layouts where crm_configuration_id = 126 order by id desc;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id in (300,299,298);\nselect * from stages where crm_configuration_id = 126 order by id desc;\nselect * from business_processes where crm_configuration_id = 126 order by id desc;\nselect * from business_process_stages where business_process_id IN (76,75,74,73);\nselect * from playbooks where team_id = 142;\nselect * from playbook_layouts where playbook_id IN (108);\nSELECT * FROM playbook_categories WHERE playbook_id IN (108);\n\nselect * from teams where id = 130;\nSELECT * FROM social_accounts WHERE sociable_id = 2291;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 2\nand sa.provider = 'hubspot';\n\nSELECT * FROM activities\n WHERE crm_configuration_id = 110;\n\nselect * from teams;\nselect * from crm_configurations;\n\nSELECT * FROM activities WHERE id = 628773;\nSELECT * FROM crm_profiles WHERE user_id = 1460;\nSELECT * FROM social_accounts WHERE sociable_id = 2291;\n\nselect * from teams;\nselect ru.*, pr.*, p.* from users u join role_user ru on ru.user_id = u.id\njoin permission_role pr on pr.role_id = ru.role_id\n join permissions p on p.id = pr.permission_id\nwhere team_id = 495 and p.name IN ('dial');\n\nselect * from teams where id = 145;\nselect * from crm_configurations where id = 129;\nselect * from social_accounts where sociable_id = 2317;\nSELECT * FROM activities WHERE uuid_to_bin('8dbab184-a333-4268-ad57-fb41f8d53a9a') = uuid;\n\nselect * from teams where id = 1;\nSELECT * FROM crm_layouts WHERE crm_configuration_id = 39;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 280;\nSELECT * FROM crm_layout_entities WHERE id = 5507;\nSELECT * FROM crm_fields WHERE crm_configuration_id = 39 and object_type IN ('event');\n\nselect * from teams;\nselect * from activities where crm_configuration_id = 14;\n\nSELECT * FROM social_accounts where provider = 'copper';\n\nselect * from activities where id = 628467;\nselect * from participants where activity_id = 628467;\n\nSELECT * FROM contacts WHERE id = 3969;\nSELECT * FROM accounts WHERE id = 177;\n\nSELECT * FROM activities WHERE uuid_to_bin('4eb54c77-cfa3-2bd4-84a7-9ed46a21c988') = uuid;\n\n# ********************* BH\nselect * from teams where id = 36;\nSELECT * FROM crm_configurations WHERE id = 21;\nselect * from activities where crm_configuration_id = 21 and id = 607901;\nselect * from activities where crm_configuration_id = 21;\n\nselect * roles;\nselect * from permissions;\nselect * from permission_role where permission_id = 226;\n\nselect * from migrations order by id desc;\n\n# mercury\n# neptune\n# earth\n\nselect * from teams;\nselect * from teams where id = 19;\nselect * from teams where id = 27;\nselect * from users where team_id = 27;\nSELECT * FROM crm_configurations WHERE id = 42;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 19\nand sa.provider = 'pipedrive';\n\nselect * from activities where id = 631461;\nSELECT * FROM crm_field_values WHERE crm_field_id = 180;\n\nselect * from teams where id = 2;\nSELECT * FROM social_accounts WHERE sociable_id = 89;\n\nSELECT * FROM activities WHERE uuid_to_bin('ba0c029a-bc14-4e17-8603-64174acebcbb') = uuid; # 634273\nselect * from activity_summary_logs where activity_id = 634273;\n\nselect * from sidekick_settings where team_id = 2;\n\nselect * from teams; # 2, 2\nSELECT * FROM crm_configurations WHERE team_id = 2; # 2\nselect * from team_features where team_id = 2;\nselect * from features;\nSELECT * FROM opportunities WHERE crm_configuration_id = 2 and crm_provider_id = '51317301383';\nSELECT * FROM opportunities WHERE crm_configuration_id = 2 order by id desc;\n\nselect * from automated_reports order by id desc;\nselect * from automated_report_results order by id desc;\nselect * from users where team_id = 1 and id IN (7160, 3248);\nselect * from migrations order by id desc;\n\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 1 and sa.provider = 'salesforce';\n\nselect * from teams where id = 1;\nselect * from groups g JOIN playbooks p on g.playbook_id = p.id where g.team_id = 1;\nselect * from groups where id = 565;\nselect * from playbooks where team_id = 1;\nselect * from playbooks where id = 175;\nselect * from playbook_categories where playbook_id = 175;\nselect * from users where team_id = 1;\nselect * from users where id = 7160;\nselect * from crm_profiles where user_id = 7160;\nselect * from features;\nselect\n *\n# id, uuid, type, provider, playbook_category_id, user_id, lead_id, contact_id, account_id, opportunity_id, stage_id,\n# crm_configuration_id, crm_provider_id, transcription_id, status\nfrom activities where crm_configuration_id = 1 and type = 'conference'\n# and crm_provider_id IS NOT NULL\nand provider != 'uploader' and actual_start_time IS NOT NULL\nORDER by id desc;\nselect * from activities where id = 54747783; # 00UO400000pCzojMAC\n\nselect p.id, p.activity_type, pc.id, pc.name\nFROM playbooks p\njoin playbook_categories pc on p.id = pc.playbook_id\nwhere p.team_id = 1 and p.activity_type = 'event';\n\nSELECT * FROM crm_fields WHERE crm_configuration_id = 1 and object_type = 'event';\nSELECT * FROM crm_field_values WHERE crm_field_id = 4;\n\nselect * from crm_layouts cl join playbook_layouts pl on cl.id = pl.layout_id\nwhere crm_configuration_id = 1 and pl.playbook_id = 175;\n\nselect * from teams;\nSELECT r.* FROM automated_reports r\njoin teams t on r.team_id = t.id\nWHERE r.frequency = 'daily'\n and r.status = 1\nAND t.status = 'active'\nAND (r.expires_at >= now() OR r.expires_at IS NULL);\n\nselect * from automated_report_results where report_id IN (18, 33);\n\nselect * from activity_searches where id = 10932;\nselect * from activity_search_filters where activity_search_id = 10932;\nselect * from automated_reports;\nselect * from automated_report_results where report_id IN (34, 35);","role_description":"text entry area","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.088194445,"height":0.027777778},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false}]...
|
-8397015556662170072
|
6686649022737200205
|
idle
|
accessibility
|
NULL
|
Project: faVsco.js, menu
#11894 on JY-18909-automa Project: faVsco.js, menu
#11894 on JY-18909-automated-reports-ask-jiminny, menu
Start Listening for PHP Debug Connections
AutomatedReportsCommandTest
Run 'AutomatedReportsCommandTest'
Debug 'AutomatedReportsCommandTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Execute
Explain Plan
Browse Query History
View Parameters
Open Query Execution Settings…
In-Editor Results
Tx: Auto
Cancel Running Statements
Playground
jiminny
Sync Changes
Hide This Notification
Code changed:
Hide
16
13
13
Previous Highlighted Error
Next Highlighted Error
SELECT * FROM teams WHERE id = 1;
select * from crm_layouts where crm_configuration_id = 39;
SELECT * FROM crm_layout_entities WHERE crm_layout_id = 283;
SELECT * FROM crm_fields WHERE id = 2234;
SELECT * FROM crm_field_values WHERE crm_field_id = 2234;
select * from crm_profiles where user_id = 143;
select * from record_types where crm_configuration_id = 39; # 0121K000001MHElQAO,0121K000001MHEqQAO
select * from business_processes where crm_configuration_id = 39;
# 01941000000H669AAC, 01941000000H66JAAS
select * from record_type_field_values
where record_type_id IN (24);
select * from crm_field_values where id IN (2730);
select * from crm_configurations where id = 39;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 1
and sa.provider = 'salesforce'; #1035
select * from users where team_id = 1; # 222 group 3
SELECT * FROM activities WHERE user_id = 222 order by id desc;
select * from sidekick_settings where team_id = 1;
select * from teams where id = 1;
select * from team_features where team_id = 1;
select * from activities where crm_configuration_id = 2
and provider = 'ms-teams' and id = 608765;
SELECT * FROM activities WHERE crm_configuration_id = 2 and crm_provider_id = '59523413338';
select * from sidekick_settings where team_id = 2;
SELECT * FROM activities WHERE id = 608660;
select * from activity_summary_logs where activity_id = 608660;
select * from ai_prompts where transcription_id = 11214;
# [PASSWORD_DOTS]
SELECT * FROM activities WHERE uuid_to_bin('ed78a437-2804-450e-ab2f-56ab1c641346') = uuid;
# id: 608818, crm: 59628809737
SELECT * FROM activities WHERE uuid_to_bin('36b06e55-afdd-4782-8dee-c624cd0af191') = uuid;
# id: 608821, crm: 59632069252
SELECT ce.start_time, ce.end_time, a.id, a.uuid, crm_provider_id, calendar_event_id, title,
playbook_category_id, user_id, lead_id, contact_id, account_id, opportunity_id,
scheduled_start_time, scheduled_end_time, actual_start_time, actual_end_time, a.created_at
FROM activities a
join calendar_events ce on a.calendar_event_id = ce.id
WHERE a.id IN (608818, 608821);
select * from users where team_id = 1;
select * from team_settings where team_id = 1;
select * from crm_profiles where crm_configuration_id = 39 order by user_id;
select * from team_features where team_id = 1;
select * from users where team_id = 2;
SELECT * FROM activities WHERE uuid_to_bin('ec7647e9-5225-458b-b475-f31aa2769204') = uuid; # 612639
# Preslava N. Ivanova, grou id 3
SELECT * FROM opportunities WHERE uuid_to_bin('a2928fe5-aec5-46cb-85d9-7654c89e46a6') = uuid;
select * from activities where opportunity_id = 344 and actual_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00';
select
a.id,
a.type,
a.scheduled_start_time,
a.actual_start_time,
a.created_at,
a.opportunity_id,
a.status
FROM activities a
WHERE opportunity_id = 344
and status IN ('completed', 'received', 'delivered')
and (
(a.actual_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00')
OR (a.created_at between '2024-10-11 00:00:00' and '2024-10-12 00:00:00')
OR (a.scheduled_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00'))
;
SELECT * FROM users WHERE id = 222;
SELECT * FROM crm_profiles WHERE user_id = 222;
select * from crm_layouts where crm_configuration_id = 39;
SELECT * FROM crm_layout_entities WHERE crm_layout_id = 281;
select * from group_deal_risk_types;
select * from opportunities where team_id = 1;
SELECT * FROM opportunities WHERE id = 315;
SELECT * FROM crm_field_data WHERE object_id = 315;
select * from crm_field_data where object_id = 260;
select * from generic_ai_prompts where subject_id = 315;
select * from teams; # 36, 21, 121, [EMAIL]
SELECT * FROM social_accounts WHERE sociable_id = 121 and provider = 'bullhorn';
# [PASSWORD_DOTS]
select * from teams where id = 1;
select * from crm_configurations where id = 39;
select * from users where team_id = 1;
select u.email, cp.* from users u
join crm_profiles cp on u.id = cp.user_id
where u.team_id = 1;
# 1 - 00541000004281rAAA
# 204 - 0052g000003freeAAA
# 429 - 0052g000003qGOiAAM
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 1
and sa.provider = 'salesforce';
select * from activities where type = 'softphone'
and created_at > '2024-12-11 15:24:36' order by id desc;
select * from activity_providers where team_id = 1;
select * from activity_provider_users where activity_provider_id = 328;
select * from opportunities where crm_configuration_id = 39
AND account_id = 178 AND is_closed = false
order by created_at DESC;
select * from contacts where id = 3952;
select * from accounts where id = 178;
# [PASSWORD_DOTS]
select * from teams where id = 36;
select * from crm_configurations where id = 21;
select * from users where team_id = 36;
select u.email, cp.* from users u
join crm_profiles cp on u.id = cp.user_id
where u.team_id = 36;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 36
and sa.provider = 'bullhorn';
select * from social_accounts where id = 348;
UPDATE social_accounts SET
provider_user_token = '21442_6802599_91:41179a58-21e7-4d7c-ad58-56bb666b2f65',
provider_refresh_token = '21442_6802599_91:01c6b335-3f2a-42e4-85ff-8a08fa65fceb',
expires = 1733998131,
state = 'connected'
WHERE id = 348;
# [PASSWORD_DOTS]
select * from teams where id = 31;
select * from crm_configurations where id = 18;
select * from users where team_id = 31; # 257
select u.email, cp.* from users u
join crm_profiles cp on u.id = cp.user_id
where u.team_id = 31;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 31
and sa.provider = 'close';
select * from contacts where crm_configuration_id = 18;
# [PASSWORD_DOTS] NEPTUNE [PASSWORD_DOTS]
select * from teams;
select * from users where id IN (1030, 1035, 1052);
select * from crm_configurations;
select * from users where team_id = 65; # 257
select * from team_settings where team_id = 65; # 257
select * from invitations where team_id = 65; # 257
select * from users where email = '[EMAIL]'; # 257
select u.email, cp.* from users u
join crm_profiles cp on u.id = cp.user_id
where u.team_id = 65;
select * from crm_configurations where id = 53;
select * from accounts where crm_configuration_id = 53 order by id desc;
select * from leads where crm_configuration_id = 53 order by id desc;
select * from contacts where crm_configuration_id = 53 order by id desc;
select * from opportunities where crm_configuration_id = 53 order by id desc;
select * from crm_profiles where crm_configuration_id = 53 order by id desc;
select * from crm_fields where crm_configuration_id = 53 order by id desc;
select * from crm_field_values where crm_field_id = 3341 order by id desc;
select * from crm_layouts where crm_configuration_id = 53 order by id desc;
select * from stages where crm_configuration_id = 53 order by id desc;
select * from crm_profiles where crm_configuration_id = 13;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 65
and sa.provider = 'integration-app';
select * from contacts where crm_configuration_id = 13;
select * from social_accounts where sociable_id = 283;
SELECT * FROM opportunities WHERE crm_provider_id = '006O400000E9bzeIAB';
select * from activity_providers where team_id = 65;
SELECT * FROM activities WHERE crm_configuration_id IN (51, 52, 53);
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 65
;
# [PASSWORD_DOTS] STAGING [PASSWORD_DOTS]
SELECT * FROM teams;
SELECT * FROM teams WHERE id = 88;
SELECT * FROM teams WHERE id = 89;
select * from team_settings where team_id = 89;
SELECT * FROM users WHERE team_id = 89;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 89;
select * from users;
SELECT * FROM social_accounts WHERE sociable_id = 1761;
SELECT * FROM crm_configurations WHERE id = 70;
select * from accounts where crm_configuration_id = 70 order by id desc;
select * from leads where crm_configuration_id = 70 order by id desc;
select * from contacts where crm_configuration_id = 70 order by id desc;
select * from opportunities where crm_configuration_id = 70 order by id desc;
select * from crm_profiles where crm_configuration_id = 70 order by id desc;
select * from crm_fields where crm_configuration_id = 70 order by id desc;
select * from crm_field_values where crm_field_id = 3536 order by id desc;
select * from crm_layouts where crm_configuration_id = 70 order by id desc;
select * from stages where crm_configuration_id = 70 order by id desc;
select * from business_processes where crm_configuration_id = 70 order by id desc;
select * from business_process_stages where business_process_id = 34;
select * from contacts where id = 10468;
select * from crm_layouts where crm_configuration_id = 70;
SELECT * FROM crm_layout_entities WHERE crm_layout_id = 388;
SELECT * FROM crm_fields WHERE id IN (3533,3534,3535);
select * from activities where crm_configuration_id = 70
and (account_id IS NOT NULL or lead_id IS NOT NULL or contact_id IS NOT NULL or opportunity_id IS NOT NULL) order by id desc;
SELECT * FROM activities WHERE uuid_to_bin('2e10b60f-8a61-41c5-a3d4-28835353dc65') = uuid;
SELECT * FROM activities where crm_configuration_id = 69 ;
SELECT * FROM users WHERE email LIKE '%[EMAIL]%';
SELECT * FROM activities WHERE uuid_to_bin('5a150c93-40fc-42ec-b3bd-c1d328e09f6e') = uuid;
SELECT * FROM opportunities WHERE id = 385;
select * from participants p
join activities a on p.activity_id = a.id
where a.crm_configuration_id = 70
and (p.lead_id IS NOT NULL or p.contact_id IS NOT NULL);
SELECT * FROM participants WHERE id = 1013638;
select * from teams where id = 90;
select * from users where team_id = 90;
select * from social_accounts where social_accounts.sociable_id IN (1960,1760);
SELECT * FROM crm_profiles WHERE crm_configuration_id = 71;
select * from invitations where team_id = 90;
select * from crm_configurations where id = 71;
select * from accounts where crm_configuration_id = 71 order by id desc;
select * from leads where crm_configuration_id = 71 order by id desc;
select * from contacts where crm_configuration_id = 71 order by id desc;
select * from opportunities where crm_configuration_id = 71 order by id desc;
select * from crm_profiles where crm_configuration_id = 71 order by id desc;
select * from crm_fields where crm_configuration_id = 71 order by id desc;
select * from crm_field_values where crm_field_id = 3341 order by id desc;
select * from crm_layouts where crm_configuration_id = 71 order by id desc;
select * from stages where crm_configuration_id = 71 order by id desc;
select * from users order by secondary_email desc;
select u.id, u.email, u.status, sa.id, sa.provider_user_id from social_accounts sa
join users u on sa.sociable_id = u.id
where sa.provider = 'google' and u.email LIKE 'aneliya%';
select * from failed_jobs order by id desc;
select * from users where email = '[EMAIL]' or secondary_email = '[EMAIL]';
select * from teams;
SELECT * FROM crm_profiles WHERE crm_configuration_id = 39;
SELECT * FROM crm_fields WHERE crm_configuration_id = 39 and object_type = 'task';
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 1
and sa.provider = 'salesforce';
# [PASSWORD_DOTS]
SELECT * FROM activities WHERE uuid_to_bin('c38b3895-fd0f-4b1f-9fb2-c170dba137c6') = uuid;
SELECT * FROM crm_configurations WHERE id = 70;
select * from teams where id = 1;
select * from groups where team_id = 1;
select * from users where team_id = 1;
select o.id, o.name,o.close_date, u.id, u.name, u.group_id, r.id, r.display_name, g.name, g.scope from opportunities o
join users u on o.user_id = u.id
join groups g on u.group_id = g.id
join role_user ru on u.id = ru.user_id
join roles r on ru.role_id = r.id
where o.crm_configuration_id = 39 and close_date > '2024-01-01 00:00:00';
select * from role_user where user_id = 143;
select * from roles;
select * from role_user;
select * from groups where id = 9;
select * from scope_groups where group_id = 9;
# [PASSWORD_DOTS]
select * from teams where id = 36;
select * from crm_configurations;
SELECT * FROM social_accounts WHERE sociable_id = 121;
https://crmsandbox.zoho.com/crm/jiminnyw4/tab/Leads/4776201000005049105
https://crmsandbox.zoho.com/crm/
https://crm.zoho.com/crm/org3469620/tab/Leads/230045000229559080
https://crm.zoho.com/crm/
org3469620
SELECT * FROM activities WHERE uuid_to_bin('03382d20-c8bc-48e7-a3d4-90b52fa5ceab') = uuid;
select * from users where email LIKE "%mobile_automation_%";
select * from social_accounts where sociable_id IN (2228);
select * from crm_profiles where user_id IN (2222,2223,2226,2227);
select * from teams order by id desc;
SELECT * FROM users WHERE id = 2229;
SELECT * FROM crm_profiles WHERE user_id = 2229;
select * from opportunities where crm_configuration_id = 88;
select * from crm_fields where crm_configuration_id = 88;
select * from crm_profiles where crm_configuration_id = 88;
SELECT * FROM teams WHERE id = 1;
SELECT * FROM users WHERE id = 143;
SELECT * FROM users WHERE uuid_to_bin('fde193d3-06a2-4e1a-8895-62b94039215d') = uuid;
SELECT * FROM teams WHERE uuid_to_bin('73385071-a756-42ae-9c73-8b53f2309467') = uuid;
https://app.staging.jiminny.com/ondemand?
min_duration=1
&
only_recorded=1
&
user_id%5B%5D=641f1acb-16b8-42d1-8726-df52979dad0e
&
sequence_number=2
select * from users where team_id = 1 and email like '%stoyan%'
select * from coaching_feedbacks;
select * from teams;
SELECT * FROM users WHERE team_id = 36;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 19
and sa.provider = 'pipedrive';
select * from users where id = 143;
SELECT * FROM users WHERE uuid_to_bin('73180eeb-33de-4065-977d-ccbe0e6c94fc') = uuid;
SELECT * FROM teams WHERE uuid_to_bin('73180eeb-33de-4065-977d-ccbe0e6c94fc') = uuid;
SELECT * FROM activity_shares WHERE uuid_to_bin('73180eeb-33de-4065-977d-ccbe0e6c94fc') = uuid;
select * from users where team_id = 2;
select * from activities where crm_configuration_id = 39
and activities.scheduled_start_time BETWEEN '2025-04-09 00:00:00' AND '2025-04-09 23:59:59'
AND user_id = 143
order by id desc;
# [PASSWORD_DOTS]
select * from teams where id = 142; # 2312, 126
select * from team_settings;
select * from users where team_id = 142; # 21642
SELECT * FROM social_accounts WHERE sociable_id = 21642;
SELECT * FROM crm_profiles cp join users u ON u.id = cp.user_id WHERE team_id = 142;
select * from crm_profiles where id IN (93);
select * from invitations;
select * from team_features where team_id = 1;
SELECT * FROM crm_configurations WHERE id = 126;
select * from accounts where crm_configuration_id = 126 order by id desc;
select * from leads where crm_configuration_id = 126 order by id desc;
select * from contacts where crm_configuration_id = 126 order by id desc;
select * from opportunities where crm_configuration_id = 126 order by id desc;
select * from crm_profiles where crm_configuration_id = 126 order by id desc;
select * from crm_fields where crm_configuration_id = 126 # 11060
# and type IN ('picklist', 'status')
# and object_type = 'task'
order by id desc;
# 5731,5732,5733
select DISTINCT crm_field_id from crm_field_values where crm_field_id IN (11151,12239,12215,12185,12175,12165,12144,12137,12127,12109,12107,12105,12103,12092,12037,12005,12003,11987,11969,11958,11951,11942,11931,11924,11921,11917,11915,11901,11893,11883,11872,11870,11868,11866,11839,11833,11821,11793,11780,11777,11769,11757,11737,11735,11656,11645,11638,11629,11618,11611,11602,11591,11584,11581,11558,11544,11543,11534,11532,11529,11527,11503,11497,11493,11488,11470,11468,11457,11455,11397,11387,11372,11363,11348,11323,11318,11309,11301,11300,11292,11290,11286,11284,11256,11252,11242,11237,11233,11219,11176,11160) order by id desc;
select * from crm_layouts where crm_configuration_id = 126 order by id desc;
SELECT * FROM crm_layout_entities WHERE crm_layout_id in (300,299,298);
select * from stages where crm_configuration_id = 126 order by id desc;
select * from business_processes where crm_configuration_id = 126 order by id desc;
select * from business_process_stages where business_process_id IN (76,75,74,73);
select * from playbooks where team_id = 142;
select * from playbook_layouts where playbook_id IN (108);
SELECT * FROM playbook_categories WHERE playbook_id IN (108);
select * from teams where id = 130;
SELECT * FROM social_accounts WHERE sociable_id = 2291;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 2
and sa.provider = 'hubspot';
SELECT * FROM activities
WHERE crm_configuration_id = 110;
select * from teams;
select * from crm_configurations;
SELECT * FROM activities WHERE id = 628773;
SELECT * FROM crm_profiles WHERE user_id = 1460;
SELECT * FROM social_accounts WHERE sociable_id = 2291;
select * from teams;
select ru.*, pr.*, p.* from users u join role_user ru on ru.user_id = u.id
join permission_role pr on pr.role_id = ru.role_id
join permissions p on p.id = pr.permission_id
where team_id = 495 and p.name IN ('dial');
select * from teams where id = 145;
select * from crm_configurations where id = 129;
select * from social_accounts where sociable_id = 2317;
SELECT * FROM activities WHERE uuid_to_bin('8dbab184-a333-4268-ad57-fb41f8d53a9a') = uuid;
select * from teams where id = 1;
SELECT * FROM crm_layouts WHERE crm_configuration_id = 39;
SELECT * FROM crm_layout_entities WHERE crm_layout_id = 280;
SELECT * FROM crm_layout_entities WHERE id = 5507;
SELECT * FROM crm_fields WHERE crm_configuration_id = 39 and object_type IN ('event');
select * from teams;
select * from activities where crm_configuration_id = 14;
SELECT * FROM social_accounts where provider = 'copper';
select * from activities where id = 628467;
select * from participants where activity_id = 628467;
SELECT * FROM contacts WHERE id = 3969;
SELECT * FROM accounts WHERE id = 177;
SELECT * FROM activities WHERE uuid_to_bin('4eb54c77-cfa3-2bd4-84a7-9ed46a21c988') = uuid;
# [PASSWORD_DOTS] BH
select * from teams where id = 36;
SELECT * FROM crm_configurations WHERE id = 21;
select * from activities where crm_configuration_id = 21 and id = 607901;
select * from activities where crm_configuration_id = 21;
select * roles;
select * from permissions;
select * from permission_role where permission_id = 226;
select * from migrations order by id desc;
# mercury
# neptune
# earth
select * from teams;
select * from teams where id = 19;
select * from teams where id = 27;
select * from users where team_id = 27;
SELECT * FROM crm_configurations WHERE id = 42;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 19
and sa.provider = 'pipedrive';
select * from activities where id = 631461;
SELECT * FROM crm_field_values WHERE crm_field_id = 180;
select * from teams where id = 2;
SELECT * FROM social_accounts WHERE sociable_id = 89;
SELECT * FROM activities WHERE uuid_to_bin('ba0c029a-bc14-4e17-8603-64174acebcbb') = uuid; # 634273
select * from activity_summary_logs where activity_id = 634273;
select * from sidekick_settings where team_id = 2;
select * from teams; # 2, 2
SELECT * FROM crm_configurations WHERE team_id = 2; # 2
select * from team_features where team_id = 2;
select * from features;
SELECT * FROM opportunities WHERE crm_configuration_id = 2 and crm_provider_id = '51317301383';
SELECT * FROM opportunities WHERE crm_configuration_id = 2 order by id desc;
select * from automated_reports order by id desc;
select * from automated_report_results order by id desc;
select * from users where team_id = 1 and id IN (7160, 3248);
select * from migrations order by id desc;
SELECT
CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,
u.email,
sa.*,
t.owner_id FROM social_accounts sa
JOIN users u on u.id = sa.sociable_id
JOIN teams t on t.id = u.team_id
WHERE u.team_id = 1 and sa.provider = 'salesforce';
select * from teams where id = 1;
select * from groups g JOIN playbooks p on g.playbook_id = p.id where g.team_id = 1;
select * from groups where id = 565;
select * from playbooks where team_id = 1;
select * from playbooks where id = 175;
select * from playbook_categories where playbook_id = 175;
select * from users where team_id = 1;
select * from users where id = 7160;
select * from crm_profiles where user_id = 7160;
select * from features;
select
*
# id, uuid, type, provider, playbook_category_id, user_id, lead_id, contact_id, account_id, opportunity_id, stage_id,
# crm_configuration_id, crm_provider_id, transcription_id, status
from activities where crm_configuration_id = 1 and type = 'conference'
# and crm_provider_id IS NOT NULL
and provider != 'uploader' and actual_start_time IS NOT NULL
ORDER by id desc;
select * from activities where id = 54747783; # 00UO400000pCzojMAC
select p.id, p.activity_type, pc.id, pc.name
FROM playbooks p
join playbook_categories pc on p.id = pc.playbook_id
where p.team_id = 1 and p.activity_type = 'event';
SELECT * FROM crm_fields WHERE crm_configuration_id = 1 and object_type = 'event';
SELECT * FROM crm_field_values WHERE crm_field_id = 4;
select * from crm_layouts cl join playbook_layouts pl on cl.id = pl.layout_id
where crm_configuration_id = 1 and pl.playbook_id = 175;
select * from teams;
SELECT r.* FROM automated_reports r
join teams t on r.team_id = t.id
WHERE r.frequency = 'daily'
and r.status = 1
AND t.status = 'active'
AND (r.expires_at >= now() OR r.expires_at IS NULL);
select * from automated_report_results where report_id IN (18, 33);
select * from activity_searches where id = 10932;
select * from activity_search_filters where activity_search_id = 10932;
select * from automated_reports;
select * from automated_report_results where report_id IN (34, 35);
Sync Changes
Hide This Notification
Code changed:
Hide...
|
12308
|
|
12331
|
262
|
4
|
2026-04-14T11:07:31.947119+00:00
|
/Users/lukas/.screenpipe/data/data/2026-04-14/1776 /Users/lukas/.screenpipe/data/data/2026-04-14/1776164851947_m1.jpg...
|
PhpStorm
|
faVsco.js – AutomatedReportsService.php
|
1
|
NULL
|
monitor_1
|
NULL
|
NULL
|
NULL
|
NULL
|
Project: faVsco.js, menu
#11894 on JY-18909-automa Project: faVsco.js, menu
#11894 on JY-18909-automated-reports-ask-jiminny, menu
Start Listening for PHP Debug Connections
AutomatedReportsCommandTest
Run 'AutomatedReportsCommandTest'
Debug 'AutomatedReportsCommandTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Execute
Explain Plan
Browse Query History
View Parameters
Open Query Execution Settings…
In-Editor Results
Tx: Auto
Cancel Running Statements
Playground
jiminny
Sync Changes
Hide This Notification
Code changed:
Hide
16
13
13
Previous Highlighted Error
Next Highlighted Error
SELECT * FROM teams WHERE id = 1;
select * from crm_layouts where crm_configuration_id = 39;
SELECT * FROM crm_layout_entities WHERE crm_layout_id = 283;
SELECT * FROM crm_fields WHERE id = 2234;
SELECT * FROM crm_field_values WHERE crm_field_id = 2234;
select * from crm_profiles where user_id = 143;
select * from record_types where crm_configuration_id = 39; # 0121K000001MHElQAO,0121K000001MHEqQAO
select * from business_processes where crm_configuration_id = 39;
# 01941000000H669AAC, 01941000000H66JAAS
select * from record_type_field_values
where record_type_id IN (24);
select * from crm_field_values where id IN (2730);
select * from crm_configurations where id = 39;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 1
and sa.provider = 'salesforce'; #1035
select * from users where team_id = 1; # 222 group 3
SELECT * FROM activities WHERE user_id = 222 order by id desc;
select * from sidekick_settings where team_id = 1;
select * from teams where id = 1;
select * from team_features where team_id = 1;
select * from activities where crm_configuration_id = 2
and provider = 'ms-teams' and id = 608765;
SELECT * FROM activities WHERE crm_configuration_id = 2 and crm_provider_id = '59523413338';
select * from sidekick_settings where team_id = 2;
SELECT * FROM activities WHERE id = 608660;
select * from activity_summary_logs where activity_id = 608660;
select * from ai_prompts where transcription_id = 11214;
# [PASSWORD_DOTS]
SELECT * FROM activities WHERE uuid_to_bin('ed78a437-2804-450e-ab2f-56ab1c641346') = uuid;
# id: 608818, crm: 59628809737
SELECT * FROM activities WHERE uuid_to_bin('36b06e55-afdd-4782-8dee-c624cd0af191') = uuid;
# id: 608821, crm: 59632069252
SELECT ce.start_time, ce.end_time, a.id, a.uuid, crm_provider_id, calendar_event_id, title,
playbook_category_id, user_id, lead_id, contact_id, account_id, opportunity_id,
scheduled_start_time, scheduled_end_time, actual_start_time, actual_end_time, a.created_at
FROM activities a
join calendar_events ce on a.calendar_event_id = ce.id
WHERE a.id IN (608818, 608821);
select * from users where team_id = 1;
select * from team_settings where team_id = 1;
select * from crm_profiles where crm_configuration_id = 39 order by user_id;
select * from team_features where team_id = 1;
select * from users where team_id = 2;
SELECT * FROM activities WHERE uuid_to_bin('ec7647e9-5225-458b-b475-f31aa2769204') = uuid; # 612639
# Preslava N. Ivanova, grou id 3
SELECT * FROM opportunities WHERE uuid_to_bin('a2928fe5-aec5-46cb-85d9-7654c89e46a6') = uuid;
select * from activities where opportunity_id = 344 and actual_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00';
select
a.id,
a.type,
a.scheduled_start_time,
a.actual_start_time,
a.created_at,
a.opportunity_id,
a.status
FROM activities a
WHERE opportunity_id = 344
and status IN ('completed', 'received', 'delivered')
and (
(a.actual_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00')
OR (a.created_at between '2024-10-11 00:00:00' and '2024-10-12 00:00:00')
OR (a.scheduled_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00'))
;
SELECT * FROM users WHERE id = 222;
SELECT * FROM crm_profiles WHERE user_id = 222;
select * from crm_layouts where crm_configuration_id = 39;
SELECT * FROM crm_layout_entities WHERE crm_layout_id = 281;
select * from group_deal_risk_types;
select * from opportunities where team_id = 1;
SELECT * FROM opportunities WHERE id = 315;
SELECT * FROM crm_field_data WHERE object_id = 315;
select * from crm_field_data where object_id = 260;
select * from generic_ai_prompts where subject_id = 315;
select * from teams; # 36, 21, 121, [EMAIL]
SELECT * FROM social_accounts WHERE sociable_id = 121 and provider = 'bullhorn';
# [PASSWORD_DOTS]
select * from teams where id = 1;
select * from crm_configurations where id = 39;
select * from users where team_id = 1;
select u.email, cp.* from users u
join crm_profiles cp on u.id = cp.user_id
where u.team_id = 1;
# 1 - 00541000004281rAAA
# 204 - 0052g000003freeAAA
# 429 - 0052g000003qGOiAAM
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 1
and sa.provider = 'salesforce';
select * from activities where type = 'softphone'
and created_at > '2024-12-11 15:24:36' order by id desc;
select * from activity_providers where team_id = 1;
select * from activity_provider_users where activity_provider_id = 328;
select * from opportunities where crm_configuration_id = 39
AND account_id = 178 AND is_closed = false
order by created_at DESC;
select * from contacts where id = 3952;
select * from accounts where id = 178;
# [PASSWORD_DOTS]
select * from teams where id = 36;
select * from crm_configurations where id = 21;
select * from users where team_id = 36;
select u.email, cp.* from users u
join crm_profiles cp on u.id = cp.user_id
where u.team_id = 36;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 36
and sa.provider = 'bullhorn';
select * from social_accounts where id = 348;
UPDATE social_accounts SET
provider_user_token = '21442_6802599_91:41179a58-21e7-4d7c-ad58-56bb666b2f65',
provider_refresh_token = '21442_6802599_91:01c6b335-3f2a-42e4-85ff-8a08fa65fceb',
expires = 1733998131,
state = 'connected'
WHERE id = 348;
# [PASSWORD_DOTS]
select * from teams where id = 31;
select * from crm_configurations where id = 18;
select * from users where team_id = 31; # 257
select u.email, cp.* from users u
join crm_profiles cp on u.id = cp.user_id
where u.team_id = 31;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 31
and sa.provider = 'close';
select * from contacts where crm_configuration_id = 18;
# [PASSWORD_DOTS] NEPTUNE [PASSWORD_DOTS]
select * from teams;
select * from users where id IN (1030, 1035, 1052);
select * from crm_configurations;
select * from users where team_id = 65; # 257
select * from team_settings where team_id = 65; # 257
select * from invitations where team_id = 65; # 257
select * from users where email = '[EMAIL]'; # 257
select u.email, cp.* from users u
join crm_profiles cp on u.id = cp.user_id
where u.team_id = 65;
select * from crm_configurations where id = 53;
select * from accounts where crm_configuration_id = 53 order by id desc;
select * from leads where crm_configuration_id = 53 order by id desc;
select * from contacts where crm_configuration_id = 53 order by id desc;
select * from opportunities where crm_configuration_id = 53 order by id desc;
select * from crm_profiles where crm_configuration_id = 53 order by id desc;
select * from crm_fields where crm_configuration_id = 53 order by id desc;
select * from crm_field_values where crm_field_id = 3341 order by id desc;
select * from crm_layouts where crm_configuration_id = 53 order by id desc;
select * from stages where crm_configuration_id = 53 order by id desc;
select * from crm_profiles where crm_configuration_id = 13;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 65
and sa.provider = 'integration-app';
select * from contacts where crm_configuration_id = 13;
select * from social_accounts where sociable_id = 283;
SELECT * FROM opportunities WHERE crm_provider_id = '006O400000E9bzeIAB';
select * from activity_providers where team_id = 65;
SELECT * FROM activities WHERE crm_configuration_id IN (51, 52, 53);
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 65
;
# [PASSWORD_DOTS] STAGING [PASSWORD_DOTS]
SELECT * FROM teams;
SELECT * FROM teams WHERE id = 88;
SELECT * FROM teams WHERE id = 89;
select * from team_settings where team_id = 89;
SELECT * FROM users WHERE team_id = 89;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 89;
select * from users;
SELECT * FROM social_accounts WHERE sociable_id = 1761;
SELECT * FROM crm_configurations WHERE id = 70;
select * from accounts where crm_configuration_id = 70 order by id desc;
select * from leads where crm_configuration_id = 70 order by id desc;
select * from contacts where crm_configuration_id = 70 order by id desc;
select * from opportunities where crm_configuration_id = 70 order by id desc;
select * from crm_profiles where crm_configuration_id = 70 order by id desc;
select * from crm_fields where crm_configuration_id = 70 order by id desc;
select * from crm_field_values where crm_field_id = 3536 order by id desc;
select * from crm_layouts where crm_configuration_id = 70 order by id desc;
select * from stages where crm_configuration_id = 70 order by id desc;
select * from business_processes where crm_configuration_id = 70 order by id desc;
select * from business_process_stages where business_process_id = 34;
select * from contacts where id = 10468;
select * from crm_layouts where crm_configuration_id = 70;
SELECT * FROM crm_layout_entities WHERE crm_layout_id = 388;
SELECT * FROM crm_fields WHERE id IN (3533,3534,3535);
select * from activities where crm_configuration_id = 70
and (account_id IS NOT NULL or lead_id IS NOT NULL or contact_id IS NOT NULL or opportunity_id IS NOT NULL) order by id desc;
SELECT * FROM activities WHERE uuid_to_bin('2e10b60f-8a61-41c5-a3d4-28835353dc65') = uuid;
SELECT * FROM activities where crm_configuration_id = 69 ;
SELECT * FROM users WHERE email LIKE '%[EMAIL]%';
SELECT * FROM activities WHERE uuid_to_bin('5a150c93-40fc-42ec-b3bd-c1d328e09f6e') = uuid;
SELECT * FROM opportunities WHERE id = 385;
select * from participants p
join activities a on p.activity_id = a.id
where a.crm_configuration_id = 70
and (p.lead_id IS NOT NULL or p.contact_id IS NOT NULL);
SELECT * FROM participants WHERE id = 1013638;
select * from teams where id = 90;
select * from users where team_id = 90;
select * from social_accounts where social_accounts.sociable_id IN (1960,1760);
SELECT * FROM crm_profiles WHERE crm_configuration_id = 71;
select * from invitations where team_id = 90;
select * from crm_configurations where id = 71;
select * from accounts where crm_configuration_id = 71 order by id desc;
select * from leads where crm_configuration_id = 71 order by id desc;
select * from contacts where crm_configuration_id = 71 order by id desc;
select * from opportunities where crm_configuration_id = 71 order by id desc;
select * from crm_profiles where crm_configuration_id = 71 order by id desc;
select * from crm_fields where crm_configuration_id = 71 order by id desc;
select * from crm_field_values where crm_field_id = 3341 order by id desc;
select * from crm_layouts where crm_configuration_id = 71 order by id desc;
select * from stages where crm_configuration_id = 71 order by id desc;
select * from users order by secondary_email desc;
select u.id, u.email, u.status, sa.id, sa.provider_user_id from social_accounts sa
join users u on sa.sociable_id = u.id
where sa.provider = 'google' and u.email LIKE 'aneliya%';
select * from failed_jobs order by id desc;
select * from users where email = '[EMAIL]' or secondary_email = '[EMAIL]';
select * from teams;
SELECT * FROM crm_profiles WHERE crm_configuration_id = 39;
SELECT * FROM crm_fields WHERE crm_configuration_id = 39 and object_type = 'task';
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 1
and sa.provider = 'salesforce';
# [PASSWORD_DOTS]
SELECT * FROM activities WHERE uuid_to_bin('c38b3895-fd0f-4b1f-9fb2-c170dba137c6') = uuid;
SELECT * FROM crm_configurations WHERE id = 70;
select * from teams where id = 1;
select * from groups where team_id = 1;
select * from users where team_id = 1;
select o.id, o.name,o.close_date, u.id, u.name, u.group_id, r.id, r.display_name, g.name, g.scope from opportunities o
join users u on o.user_id = u.id
join groups g on u.group_id = g.id
join role_user ru on u.id = ru.user_id
join roles r on ru.role_id = r.id
where o.crm_configuration_id = 39 and close_date > '2024-01-01 00:00:00';
select * from role_user where user_id = 143;
select * from roles;
select * from role_user;
select * from groups where id = 9;
select * from scope_groups where group_id = 9;
# [PASSWORD_DOTS]
select * from teams where id = 36;
select * from crm_configurations;
SELECT * FROM social_accounts WHERE sociable_id = 121;
[URL_WITH_CREDENTIALS] this will add filter, however if we need to control feature by FF we need conditional logic
public const array TYPES = [
['id' => 'exec_summary', 'name' => 'Exec Summary'],
['id' => 'coaching_profiles', 'name' => 'Coaching Profiles'],
['id' => 'product_feedback', 'name' => 'Product Feedback'],
['id' => self::TYPE_LOSS_ANALYSIS, 'name' => 'Loss Analysis'],
// ['id' => 'questions', 'name' => 'Questions'],
// ['id' => 'statistical_quant', 'name' => 'Statistical Quantitative'],
];
public const array ALL_TYPES = [
...self::TYPES,
['id' => self::TYPE_ASK_JIMINNY, 'name' => 'Ask Jiminny'],
];
public const string FREQUENCY_DAILY = 'daily';
public const string FREQUENCY_WEEKLY = 'weekly';
public const string FREQUENCY_MONTHLY = 'monthly';
public const string FREQUENCY_QUARTERLY = 'quarterly';
public const string FREQUENCY_ONE_OFF = 'one_off';
/**
* Frequencies for standard (non-Ask Jiminny) reports.
*/
public const array FREQUENCIES = [
['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],
['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],
['id' => self::FREQUENCY_QUARTERLY, 'name' => 'Quarterly'],
['id' => self::FREQUENCY_ONE_OFF, 'name' => 'One-off'],
];
/**
* Frequencies for Ask Jiminny reports.
*/
public const array ASK_JIMINNY_FREQUENCIES = [
['id' => self::FREQUENCY_DAILY, 'name' => 'Daily'],
['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],
['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],
];
public const string MEDIA_TYPE_PDF = 'pdf';
public const string MEDIA_TYPE_PODCAST = 'podcast';
public const array MEDIA_TYPES = [self::MEDIA_TYPE_PDF, self::MEDIA_TYPE_PODCAST];
public const array MEDIA_TYPE_OBJECT_PDF = ['id' => self::MEDIA_TYPE_PDF, 'name' => 'PDF'];
public const array MEDIA_TYPE_OBJECT_PODCAST = ['id' => self::MEDIA_TYPE_PODCAST, 'name' => 'Podcast'];
public const array MEDIA_TYPE_OBJECTS = [self::MEDIA_TYPE_OBJECT_PDF, self::MEDIA_TYPE_OBJECT_PODCAST];
public const array CALL_TYPE_CONFERENCE = ['id' => 'conference', 'name' => 'Conference'];
public const array CALL_TYPE_DIALER = ['id' => 'dialer', 'name' => 'Dialer'];
public const int SENT_REPORT_AT_HOURS = 5;
public const string PDF_KEY = 'pdf';
public const string AUDIO_KEY = 'audio';
private const array ALL_FREQUENCIES = [
['id' => self::FREQUENCY_DAILY, 'name' => 'Daily'],
['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],
['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],
['id' => self::FREQUENCY_QUARTERLY, 'name' => 'Quarterly'],
['id' => self::FREQUENCY_ONE_OFF, 'name' => 'One-off'],
];
private const string S3_DIR = 'reports';
private const array FILE_EXTENSIONS_VARIANTS = ['html', 'MD', 'pdf'];
private const array FILE_PODCAST_EXTENSIONS_VARIANTS = ['json', 'mp3', 'ssml'];
public function __construct(
private readonly TeamRepository $teamRepository,
private readonly GroupRepository $groupRepository,
private readonly UserRepository $userRepository,
private readonly StageRepository $stageRepository,
private readonly DealStagesService $dealStagesService,
private readonly RecipientsService $recipientsService,
private readonly AutomatedReportsRepository $automatedReportsRepository,
private readonly Webhook $webhookService,
private readonly BusDispatcher $dispatcher,
private readonly ActivityTypeService $activityTypeService,
private readonly PlaybookCategoryRepository $playbookCategoryRepository,
private readonly AskAnythingPromptService $askAnythingPromptService,
private readonly SearchRepository $activitySearchRepository,
private readonly AskAnythingRepository $askAnythingRepository,
) {
}
public static function getTypes(): array
{
$types = self::TYPES;
return array_map(static function ($type) {
return $type['id'];
}, $types);
}
public static function getCallTypes(): array
{
return array_map(static function ($callType) {
return $callType['id'];
}, [self::CALL_TYPE_CONFERENCE, self::CALL_TYPE_DIALER]);
}
public static function getFrequencies(): array
{
return array_map(static function ($frequency) {
return $frequency['id'];
}, self::FREQUENCIES);
}
// front-facing structure
public function getReportEnabledFieldData(bool $value = false): array
{
return [
'id' => 'report_enabled',
'label' => '',
'inputType' => InputTypeEnum::TOGGLE,
'value' => $value,
];
}
// Organizations = Teams
public function getOrganizationFieldData(?string $value = null, bool $shortVersion = false): array
{
$options = $this->getTeams();
if ($shortVersion) {
return [
'id' => 'organization',
'label' => 'Organization',
'options' => $options,
];
}
return [
'id' => 'organization',
'label' => 'Organization',
'inputType' => InputTypeEnum::DROPDOWN,
'required' => true,
'placeholder' => 'Select',
'options' => $options,
'value' => $value,
'dependencies' => [
'teams',
'deal_stage_at_call',
'current_deal_stage',
'recipients',
ActivityTypeService::PLAYBOOK_CATEGORIES_KEY,
],
'dependsOn' => [],
];
}
// Teams = Groups
public function getTeamFieldData(array $options = [], array $value = [], bool $shortVersion = false): array
{
if ($shortVersion) {
return [
'id' => 'teams',
'label' => 'Team',
'options' => $options,
];
}
return [
'id' => 'teams',
'label' => 'Team',
'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,
'required' => false,
'placeholder' => 'Select',
'options' => $options,
'value' => $value, // value should be an array of objects {id, name}
'dependencies' => [ActivityTypeService::PLAYBOOK_CATEGORIES_KEY],
'dependsOn' => [],
];
}
public function getReportTypeFieldData(?string $value = null, bool $shortVersion = false, ?Team $team = null): array
{
$types = [];
if ($team instanceof Team) {
if ($team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {
$types = self::TYPES;
}
if ($team->hasFeature(FeatureEnum::ASK_JIMINNY_REPORTS)) {
$types[] = ['id' => self::TYPE_ASK_JIMINNY, 'name' => 'Ask Jiminny'];
}
} else {
$types = self::TYPES;
}
if ($shortVersion) {
return [
'id' => 'report_type',
'label' => 'Report Type',
'options' => $types,
];
}
return [
'id' => 'report_type',
'label' => 'Report Type',
'inputType' => InputTypeEnum::DROPDOWN,
'required' => true,
'placeholder' => 'Select',
'options' => $types,
'value' => $value,
'dependencies' => [],
'dependsOn' => [],
];
}
public function getFrequencyFieldData(?string $value = null): array
{
return [
'id' => 'frequency',
'label' => 'Frequency',
'inputType' => InputTypeEnum::DROPDOWN,
'required' => true,
'placeholder' => 'Select',
'options' => self::FREQUENCIES,
'value' => $value,
'dependencies' => ['period'],
'dependsOn' => [],
];
}
public function getPeriodFieldData(?string $valueStartDate = null, ?string $valueEndDate = null): array
{
return [
'id' => 'period',
'label' => 'Select one-off period',
'inputType' => InputTypeEnum::DATE_RANGE,
'required' => true,
'placeholder' => 'Select',
'value' => ['startDate' => $valueStartDate, 'endDate' => $valueEndDate],
'queryParams' => [
'startDate' => 'start_date_period',
'endDate' => 'end_date_period',
],
'dependencies' => [],
'dependsOn' => ['frequency'],
];
}
public function getActivityTypesFieldData(?Team $team = null, array $value = [], array $teamsFilter = []): array
{
return $this->activityTypeService->getActivityTypeFieldData(team: $team, value: $value, groupIds: $teamsFilter);
}
public function getDealStageAtCallFieldData(?Team $team = null, array $value = []): array
{
return $this->dealStagesService->getDealStageAtCallFieldData(team: $team, value: $value);
}
public function getCurrentDealStageFieldData(?Team $team = null, array $value = []): array
{
return $this->dealStagesService->getCurrentDealStageFieldData(team: $team, value: $value);
}
public function getDealValueFieldData(?int $valueMin = null, ?int $valueMax = null): array
{
return [
'id' => 'deal_value',
'label' => 'Deal Value',
'inputType' => InputTypeEnum::INTEGER_RANGE,
'required' => false,
'value' => ['min' => $valueMin, 'max' => $valueMax],
'queryParams' => [
'min' => 'min_deal_value',
'max' => 'max_deal_value',
],
'dependencies' => [],
'dependsOn' => [],
];
}
public function getCallTypeFieldData(bool $conferenceOn = false, bool $dialerOn = false): array
{
$value = [];
$conferenceOn && $value[] = self::CALL_TYPE_CONFERENCE;
$dialerOn && $value[] = self::CALL_TYPE_DIALER;
return [
'id' => 'call_type',
'label' => 'Call Type',
'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,
'required' => true,
'options' => [
self::CALL_TYPE_CONFERENCE,
self::CALL_TYPE_DIALER,
],
'value' => $value,
'dependencies' => [],
'dependsOn' => [],
];
}
public function getMediaTypeFieldData(?AutomatedReport $report = null): array
{
$value = [];
if ($report) {
$value = $this->transformMediaTypes($report);
}
return [
'id' => 'media_types',
'label' => 'Export as',
'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,
'required' => true,
'options' => self::MEDIA_TYPE_OBJECTS,
'value' => $value,
'dependencies' => [],
'dependsOn' => [],
];
}
public function getCallDurationFieldData(?int $valueMin = null, ?int $valueMax = null): array
{
return [
'id' => 'call_duration',
'label' => 'Call Duration',
'inputType' => InputTypeEnum::INTEGER_RANGE,
'required' => false,
'value' => ['min' => $valueMin, 'max' => $valueMax],
'queryParams' => [
'min' => 'min_call_duration',
'max' => 'max_call_duration',
],
'dependencies' => [],
'dependsOn' => [],
];
}
public function getRecipientsFieldData(?Team $team = null, array $value = []): array
{
return $this->recipientsService->getRecipientsFieldData(team: $team, value: $value);
}
public function getJiminnyRecipientsFieldData(array $value = []): array
{
return $this->recipientsService->getJiminnyRecipientsFieldData($value);
}
public function getAdditionalPromptInputFieldData(?string $value = null): array
{
return [
'id' => 'additional_prompt_input',
'label' => 'Special requirements',
'inputType' => InputTypeEnum::TEXTAREA,
'required' => false,
'placeholder' => 'What should be the focus of the report?',
'value' => $value,
'dependencies' => [],
'dependsOn' => [],
];
}
public function getCustomReportNameFieldData(?string $value = null): array
{
return [
'id' => 'custom_name',
'label' => 'Custom report name',
'inputType' => InputTypeEnum::TEXT,
'required' => false,
'placeholder' => 'Enter custom name',
'value' => $value,
'dependencies' => [],
'dependsOn' => [],
];
}
// data providers
public function getTeams(): array
{
$teams = $this->teamRepository->getTeamsForKiosk(status: Team::STATUS_ACTIVE);
$teamData = [];
foreach ($teams as $team) {
if (! $team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {
continue;
}
$teamData[] = $this->transformTeam($team);
}
return $teamData;
}
public function getTeamGroups(string $teamUuid): array
{
$data = [];
$team = $this->getTeam($teamUuid);
if ($team !== null) {
$groups = $team->groups()->get();
foreach ($groups as $group) {
$data[] = [
'id' => $group->getUuid(),
'name' => $group->getName(),
];
}
}
return $data;
}
public function getTeamsGroupsOptions(array $filterTeamUuids = []): array
{
$data = [];
$teams = $this->getTeams();
foreach ($teams as $team) {
if (! empty($filterTeamUuids) && ! in_array($team['id'], $filterTeamUuids, true)) {
continue;
}
$data[] = [
'label' => $team['name'],
'groups' => $this->getTeamGroups($team['id']),
];
}
return $data;
}
public function getTeam(string $teamUuid): ?Team
{
return $this->teamRepository->idOrUuid($teamUuid);
}
public function getTeamById(int $teamId): ?Team
{
return $this->teamRepository->find($teamId);
}
public function getGroupsUuids(AutomatedReport $report): array
{
$uuids = [];
$reportGroups = $report->getGroups();
foreach ($reportGroups as $groupId) {
if ($group = $this->groupRepository->find($groupId)) {
$uuids[] = $group->getUuid();
}
}
return $uuids;
}
public function getPlaybookCategoriesUuids(AutomatedReport $report): array
{
$uuids = [];
$playbookCategories = $report->getPlaybookCategories();
foreach ($playbookCategories as $id) {
if ($category = $this->playbookCategoryRepository->find($id)) {
$uuids[] = $category->getUuid();
}
}
return $uuids;
}
public function getDealAtCallStagesUuids(AutomatedReport $report): array
{
$uuids = [];
$reportStages = $report->getDealAtCallStages();
foreach ($reportStages as $id) {
if ($stage = $this->stageRepository->find($id)) {
$uuids[] = $stage->getUuid();
}
}
return $uuids;
}
public function getCurrentDealStagesUuids(AutomatedReport $report): array
{
$uuids = [];
$reportStages = $report->getCurrentDealStages();
foreach ($reportStages as $id) {
if ($stage = $this->stageRepository->find($id)) {
$uuids[] = $stage->getUuid();
}
}
return $uuids;
}
public function getUsersUuids(AutomatedReport $report): array
{
return $this->extractUserUuids($report->getRecipients());
}
public function getJiminnyUsersUuids(AutomatedReport $report): array
{
return $this->extractUserUuids($report->getJiminnyRecipients());
}
/**
* @param array<string, mixed> $recipients
*/
private function extractUserUuids(array $recipients): array
{
$userIds = $recipients['users'] ?? [];
return collect($userIds)
->map(fn ($id) => $this->userRepository->find((int) $id))
->filter()
->map(fn (UserContract $user) => $user->getUuid())
->values()
->all();
}
// get mail data
public function getRecipientUsers(AutomatedReport $report): array
{
return $this->buildRecipientUsers($report->getRecipients());
}
private function getJiminnyRecipientUsers(AutomatedReport $report): array
{
return $this->buildRecipientUsers($report->getJiminnyRecipients());
}
/**
* @param array<string, mixed> $recipients
*/
private function buildRecipientUsers(array $recipients): array
{
$userIds = $recipients['users'] ?? [];
return collect($userIds)
->map(fn ($id) => $this->userRepository->find((int) $id))
->filter()
->map(fn (UserContract $user) => [
'email' => $user->getEmailAddress(),
'name' => $user->getName(),
'timezone' => $user->getTimezone()->getName(),
])
->values()
->all();
}
public function getValidRecipientUsers(AutomatedReport $report, bool $includeJiminny = false): array
{
if ($report->isAskJiminnyReport()) {
$recipients = $this->resolveAskJiminnyRecipients($report);
} else {
$recipients = $this->getRecipientUsers($report);
if ($includeJiminny) {
$recipients = array_merge($recipients, $this->getJiminnyRecipientUsers($report));
}
}
$emails = [];
return array_values(array_filter(
$recipients,
static function ($recipient) use (&$emails) {
if (empty($recipient['email']) || in_array($recipient['email'], $emails, true)) {
return false;
}
$emails[] = $recipient['email'];
return true;
}
));
}
private function resolveAskJiminnyRecipients(AutomatedReport $report): array
{
$recipients = [];
$creator = $report->getCreator();
if ($creator !== null) {
$recipients[] = [
'email' => $creator->getEmailAddress(),
'name' => $creator->getName(),
'timezone' => $creator->getTimezone()->getName(),
];
}
return array_merge(
$recipients,
$this->buildRecipientUsers($report->getRecipients()),
$this->getGroupRecipientUsers($report),
);
}
private function getGroupRecipientUsers(AutomatedReport $report): array
{
$users = [];
foreach ($report->getGroups() as $groupId) {
$group = $this->groupRepository->find($groupId);
if ($group === null) {
continue;
}
foreach ($group->getMembers() as $member) {
$users[] = [
'email' => $member->getEmailAddress(),
'name' => $member->getName(),
'timezone' => $member->getTimezone()->getName(),
];
}
}
return $users;
}
public function getReportTypeName(AutomatedReportResult $report): string
{
$type = $report->getReport()->getType();
$getType = $this->transformReportType($type);
return $getType['name'];
}
public function getReportPeriodName(AutomatedReportResult $report): string
{
$from = $report->getFromDate();
$to = $report->getToDate();
$frequency = $report->getReport()->getFrequency();
if ($from === null || $to === null) {
if (! $report->getReport()->isAskJiminnyReport()) {
$invalidPeriod = $from === null ? 'from' : 'to';
throw new ApplicationException('Report period is invalid: ' . $invalidPeriod);
}
$period = $this->calculateFromAndToDatePeriod($frequency);
$from = $period['fromDate'];
$to = $period['toDate'];
}
return $this->formatReportPeriodName($frequency, $from, $to);
}
private function formatReportPeriodName(string $frequency, Carbon $from, Carbon $to): string
{
$fromYear = $from->format('Y');
$toYear = $to->format('Y');
$differentYears = $fromYear !== $toYear;
switch ($frequency) {
case self::FREQUENCY_DAILY:
return $from->format('j M Y');
case self::FREQUENCY_QUARTERLY:
// 'Jan-Mar 2025' or 'Nov 2024-Jan 2025' if years differ
$startMonth = $from->format('M');
$endMonth = $to->copy()->subMonth();
$endMonthName = $endMonth->format('M');
$endMonthYear = $endMonth->format('Y');
if ($differentYears) {
return "{$startMonth} {$fromYear} - {$endMonthName} {$endMonthYear}";
}
return "{$startMonth} - {$endMonthName} {$toYear}";
case self::FREQUENCY_MONTHLY:
// 'May 2025' - monthly reports are always within the same year
return $from->format('M Y');
case self::FREQUENCY_WEEKLY:
// '4 - 8 Aug 2025', '27 Oct - 3 Nov 2025', or '28 Dec 2024 - 3 Jan 2025' if years differ
$startDay = $from->format('j');
$endDay = $to->format('j');
$startMonth = $from->format('M');
$endMonth = $to->format('M');
if ($differentYears) {
return "{$startDay} {$startMonth} {$fromYear} - {$endDay} {$endMonth} {$toYear}";
}
if ($startMonth !== $endMonth) {
return "{$startDay} {$startMonth} - {$endDay} {$endMonth} {$toYear}";
}
return "{$startDay} - {$endDay} {$endMonth} {$toYear}";
case self::FREQUENCY_ONE_OFF:
// '2 May-31 May 2025' or '15 Dec 2024-15 Jan 2025' if years differ
$startDay = $from->format('j');
$startMonth = $from->format('M');
$endDay = $to->format('j');
$endMonth = $to->format('M');
// If same month and year, use a format like '2-31 May 2025'
if ($startMonth === $endMonth && ! $differentYears) {
return "{$startDay} - {$endDay} {$startMonth} {$toYear}";
}
// If different years, include both years
if ($differentYears) {
return "{$startDay} {$startMonth} {$fromYear} - {$endDay} {$endMonth} {$toYear}";
}
// Same year but different months
return "{$startDay} {$startMonth} - {$endDay} {$endMonth} {$toYear}";
default:
// Default format for unknown frequencies
return $from->format('j M Y') . ' - ' . $to->format('j M Y');
}
}
public function getReportTeamsName(AutomatedReportResult $report): string
{
$groups = $report->getGroups();
if (empty($groups)) {
return 'All';
}
// Get group names from repository
$groupNames = [];
foreach ($groups as $groupId) {
$group = $this->groupRepository->find($groupId);
if ($group) {
$groupNames[] = $group->getName();
}
}
if (count($groupNames) === 1) {
// Single team format
$teamsName = $groupNames[0];
} else {
// Multiple teams format
$teamsName = implode(', ', $groupNames);
}
return $teamsName;
}
public function getReportFileName(AutomatedReportResult $report): string
...
|
[{"role":"AXButton","text" [{"role":"AXButton","text":"Project: faVsco.js, menu","depth":5,"help_text":"~/jiminny/app","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"#11894 on JY-18909-automated-reports-ask-jiminny, menu","depth":5,"help_text":"Pull request #11894 exists for current branch JY-18909-automated-reports-ask-jiminny","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Start Listening for PHP Debug Connections","depth":5,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"AutomatedReportsCommandTest","depth":6,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Run 'AutomatedReportsCommandTest'","depth":6,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Debug 'AutomatedReportsCommandTest'","depth":6,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"More Actions","depth":6,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JetBrains AI","depth":5,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Search Everywhere","depth":5,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"IDE and Project Settings","depth":5,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Execute","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Explain Plan","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Browse Query History","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"View Parameters","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Open Query Execution Settings…","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"In-Editor Results","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Tx: Auto","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Cancel Running Statements","depth":4,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Playground","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"jiminny","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.088194445,"height":0.027777778},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"16","depth":4,"role_description":"text"},{"role":"AXStaticText","text":"13","depth":4,"role_description":"text"},{"role":"AXStaticText","text":"13","depth":4,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"SELECT * FROM teams WHERE id = 1;\n\nselect * from crm_layouts where crm_configuration_id = 39;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 283;\nSELECT * FROM crm_fields WHERE id = 2234;\nSELECT * FROM crm_field_values WHERE crm_field_id = 2234;\n\nselect * from crm_profiles where user_id = 143;\n\nselect * from record_types where crm_configuration_id = 39; # 0121K000001MHElQAO,0121K000001MHEqQAO\nselect * from business_processes where crm_configuration_id = 39;\n# 01941000000H669AAC, 01941000000H66JAAS\n\nselect * from record_type_field_values\n where record_type_id IN (24);\n\nselect * from crm_field_values where id IN (2730);\n\nselect * from crm_configurations where id = 39;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 1\nand sa.provider = 'salesforce'; #1035\n\n\nselect * from users where team_id = 1; # 222 group 3\nSELECT * FROM activities WHERE user_id = 222 order by id desc;\nselect * from sidekick_settings where team_id = 1;\nselect * from teams where id = 1;\nselect * from team_features where team_id = 1;\n\nselect * from activities where crm_configuration_id = 2\nand provider = 'ms-teams' and id = 608765;\n\nSELECT * FROM activities WHERE crm_configuration_id = 2 and crm_provider_id = '59523413338';\n\nselect * from sidekick_settings where team_id = 2;\n\nSELECT * FROM activities WHERE id = 608660;\nselect * from activity_summary_logs where activity_id = 608660;\nselect * from ai_prompts where transcription_id = 11214;\n\n# ********************************************************************************************************\nSELECT * FROM activities WHERE uuid_to_bin('ed78a437-2804-450e-ab2f-56ab1c641346') = uuid;\n# id: 608818, crm: 59628809737\nSELECT * FROM activities WHERE uuid_to_bin('36b06e55-afdd-4782-8dee-c624cd0af191') = uuid;\n# id: 608821, crm: 59632069252\nSELECT ce.start_time, ce.end_time, a.id, a.uuid, crm_provider_id, calendar_event_id, title,\nplaybook_category_id, user_id, lead_id, contact_id, account_id, opportunity_id,\nscheduled_start_time, scheduled_end_time, actual_start_time, actual_end_time, a.created_at\nFROM activities a\njoin calendar_events ce on a.calendar_event_id = ce.id\nWHERE a.id IN (608818, 608821);\n\nselect * from users where team_id = 1;\nselect * from team_settings where team_id = 1;\nselect * from crm_profiles where crm_configuration_id = 39 order by user_id;\n\nselect * from team_features where team_id = 1;\n\nselect * from users where team_id = 2;\n\nSELECT * FROM activities WHERE uuid_to_bin('ec7647e9-5225-458b-b475-f31aa2769204') = uuid; # 612639\n# Preslava N. Ivanova, grou id 3\n\nSELECT * FROM opportunities WHERE uuid_to_bin('a2928fe5-aec5-46cb-85d9-7654c89e46a6') = uuid;\n\nselect * from activities where opportunity_id = 344 and actual_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00';\n\nselect\n a.id,\n a.type,\n a.scheduled_start_time,\n a.actual_start_time,\n a.created_at,\n a.opportunity_id,\n a.status\nFROM activities a\nWHERE opportunity_id = 344\nand status IN ('completed', 'received', 'delivered')\nand (\n (a.actual_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00')\nOR (a.created_at between '2024-10-11 00:00:00' and '2024-10-12 00:00:00')\nOR (a.scheduled_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00'))\n;\n\nSELECT * FROM users WHERE id = 222;\n\nSELECT * FROM crm_profiles WHERE user_id = 222;\nselect * from crm_layouts where crm_configuration_id = 39;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 281;\n\nselect * from group_deal_risk_types;\n\nselect * from opportunities where team_id = 1;\n\nSELECT * FROM opportunities WHERE id = 315;\nSELECT * FROM crm_field_data WHERE object_id = 315;\nselect * from crm_field_data where object_id = 260;\n\nselect * from generic_ai_prompts where subject_id = 315;\n\nselect * from teams; # 36, 21, 121, james.graham@bullhorn.jiminny.com\nSELECT * FROM social_accounts WHERE sociable_id = 121 and provider = 'bullhorn';\n\n# ************************************************************************************\nselect * from teams where id = 1;\nselect * from crm_configurations where id = 39;\nselect * from users where team_id = 1;\nselect u.email, cp.* from users u\njoin crm_profiles cp on u.id = cp.user_id\nwhere u.team_id = 1;\n# 1 - 00541000004281rAAA\n# 204 - 0052g000003freeAAA\n# 429 - 0052g000003qGOiAAM\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 1\nand sa.provider = 'salesforce';\n\nselect * from activities where type = 'softphone'\nand created_at > '2024-12-11 15:24:36' order by id desc;\n\nselect * from activity_providers where team_id = 1;\nselect * from activity_provider_users where activity_provider_id = 328;\n\nselect * from opportunities where crm_configuration_id = 39\nAND account_id = 178 AND is_closed = false\norder by created_at DESC;\n\nselect * from contacts where id = 3952;\nselect * from accounts where id = 178;\n\n# ************************************************************************************\nselect * from teams where id = 36;\nselect * from crm_configurations where id = 21;\nselect * from users where team_id = 36;\nselect u.email, cp.* from users u\njoin crm_profiles cp on u.id = cp.user_id\nwhere u.team_id = 36;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 36\nand sa.provider = 'bullhorn';\n\nselect * from social_accounts where id = 348;\nUPDATE social_accounts SET\nprovider_user_token = '21442_6802599_91:41179a58-21e7-4d7c-ad58-56bb666b2f65',\nprovider_refresh_token = '21442_6802599_91:01c6b335-3f2a-42e4-85ff-8a08fa65fceb',\nexpires = 1733998131,\nstate = 'connected'\nWHERE id = 348;\n\n# ************************************************************************************\nselect * from teams where id = 31;\nselect * from crm_configurations where id = 18;\n\nselect * from users where team_id = 31; # 257\nselect u.email, cp.* from users u\njoin crm_profiles cp on u.id = cp.user_id\nwhere u.team_id = 31;\n\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 31\nand sa.provider = 'close';\n\nselect * from contacts where crm_configuration_id = 18;\n\n# ********************** NEPTUNE **************************************************************\nselect * from teams;\nselect * from users where id IN (1030, 1035, 1052);\nselect * from crm_configurations;\n\nselect * from users where team_id = 65; # 257\nselect * from team_settings where team_id = 65; # 257\nselect * from invitations where team_id = 65; # 257\nselect * from users where email = 'integration-account@jiminny.com'; # 257\nselect u.email, cp.* from users u\njoin crm_profiles cp on u.id = cp.user_id\nwhere u.team_id = 65;\n\nselect * from crm_configurations where id = 53;\nselect * from accounts where crm_configuration_id = 53 order by id desc;\nselect * from leads where crm_configuration_id = 53 order by id desc;\nselect * from contacts where crm_configuration_id = 53 order by id desc;\nselect * from opportunities where crm_configuration_id = 53 order by id desc;\nselect * from crm_profiles where crm_configuration_id = 53 order by id desc;\nselect * from crm_fields where crm_configuration_id = 53 order by id desc;\nselect * from crm_field_values where crm_field_id = 3341 order by id desc;\nselect * from crm_layouts where crm_configuration_id = 53 order by id desc;\nselect * from stages where crm_configuration_id = 53 order by id desc;\n\n\nselect * from crm_profiles where crm_configuration_id = 13;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 65\nand sa.provider = 'integration-app';\n\nselect * from contacts where crm_configuration_id = 13;\n\nselect * from social_accounts where sociable_id = 283;\n\nSELECT * FROM opportunities WHERE crm_provider_id = '006O400000E9bzeIAB';\n\nselect * from activity_providers where team_id = 65;\nSELECT * FROM activities WHERE crm_configuration_id IN (51, 52, 53);\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 65\n;\n\n# ***************************** STAGING ********************************************\nSELECT * FROM teams;\nSELECT * FROM teams WHERE id = 88;\nSELECT * FROM teams WHERE id = 89;\nselect * from team_settings where team_id = 89;\nSELECT * FROM users WHERE team_id = 89;\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 89;\n\nselect * from users;\nSELECT * FROM social_accounts WHERE sociable_id = 1761;\nSELECT * FROM crm_configurations WHERE id = 70;\nselect * from accounts where crm_configuration_id = 70 order by id desc;\nselect * from leads where crm_configuration_id = 70 order by id desc;\nselect * from contacts where crm_configuration_id = 70 order by id desc;\nselect * from opportunities where crm_configuration_id = 70 order by id desc;\nselect * from crm_profiles where crm_configuration_id = 70 order by id desc;\nselect * from crm_fields where crm_configuration_id = 70 order by id desc;\nselect * from crm_field_values where crm_field_id = 3536 order by id desc;\nselect * from crm_layouts where crm_configuration_id = 70 order by id desc;\nselect * from stages where crm_configuration_id = 70 order by id desc;\nselect * from business_processes where crm_configuration_id = 70 order by id desc;\nselect * from business_process_stages where business_process_id = 34;\n\nselect * from contacts where id = 10468;\n\nselect * from crm_layouts where crm_configuration_id = 70;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 388;\nSELECT * FROM crm_fields WHERE id IN (3533,3534,3535);\n\nselect * from activities where crm_configuration_id = 70\nand (account_id IS NOT NULL or lead_id IS NOT NULL or contact_id IS NOT NULL or opportunity_id IS NOT NULL) order by id desc;\n\nSELECT * FROM activities WHERE uuid_to_bin('2e10b60f-8a61-41c5-a3d4-28835353dc65') = uuid;\nSELECT * FROM activities where crm_configuration_id = 69 ;\n\nSELECT * FROM users WHERE email LIKE '%jiminny_web_sa2@jiminny.com%';\nSELECT * FROM activities WHERE uuid_to_bin('5a150c93-40fc-42ec-b3bd-c1d328e09f6e') = uuid;\nSELECT * FROM opportunities WHERE id = 385;\n\nselect * from participants p\njoin activities a on p.activity_id = a.id\nwhere a.crm_configuration_id = 70\nand (p.lead_id IS NOT NULL or p.contact_id IS NOT NULL);\nSELECT * FROM participants WHERE id = 1013638;\n\nselect * from teams where id = 90;\nselect * from users where team_id = 90;\nselect * from social_accounts where social_accounts.sociable_id IN (1960,1760);\nSELECT * FROM crm_profiles WHERE crm_configuration_id = 71;\nselect * from invitations where team_id = 90;\n\nselect * from crm_configurations where id = 71;\nselect * from accounts where crm_configuration_id = 71 order by id desc;\nselect * from leads where crm_configuration_id = 71 order by id desc;\nselect * from contacts where crm_configuration_id = 71 order by id desc;\nselect * from opportunities where crm_configuration_id = 71 order by id desc;\nselect * from crm_profiles where crm_configuration_id = 71 order by id desc;\nselect * from crm_fields where crm_configuration_id = 71 order by id desc;\nselect * from crm_field_values where crm_field_id = 3341 order by id desc;\nselect * from crm_layouts where crm_configuration_id = 71 order by id desc;\nselect * from stages where crm_configuration_id = 71 order by id desc;\n\nselect * from users order by secondary_email desc;\nselect u.id, u.email, u.status, sa.id, sa.provider_user_id from social_accounts sa\n join users u on sa.sociable_id = u.id\nwhere sa.provider = 'google' and u.email LIKE 'aneliya%';\n\nselect * from failed_jobs order by id desc;\n\nselect * from users where email = 'ben.allwright@learningpeople.co.uk' or secondary_email = 'ben.allwright@learningpeople.co.uk';\n\nselect * from teams;\nSELECT * FROM crm_profiles WHERE crm_configuration_id = 39;\nSELECT * FROM crm_fields WHERE crm_configuration_id = 39 and object_type = 'task';\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 1\nand sa.provider = 'salesforce';\n\n# ************************************************************************************\nSELECT * FROM activities WHERE uuid_to_bin('c38b3895-fd0f-4b1f-9fb2-c170dba137c6') = uuid;\nSELECT * FROM crm_configurations WHERE id = 70;\n\nselect * from teams where id = 1;\nselect * from groups where team_id = 1;\nselect * from users where team_id = 1;\n\nselect o.id, o.name,o.close_date, u.id, u.name, u.group_id, r.id, r.display_name, g.name, g.scope from opportunities o\njoin users u on o.user_id = u.id\njoin groups g on u.group_id = g.id\njoin role_user ru on u.id = ru.user_id\njoin roles r on ru.role_id = r.id\nwhere o.crm_configuration_id = 39 and close_date > '2024-01-01 00:00:00';\n\nselect * from role_user where user_id = 143;\nselect * from roles;\n\nselect * from role_user;\nselect * from groups where id = 9;\nselect * from scope_groups where group_id = 9;\n\n# ************************************************************************************\nselect * from teams where id = 36;\nselect * from crm_configurations;\nSELECT * FROM social_accounts WHERE sociable_id = 121;\n\nhttps://crmsandbox.zoho.com/crm/jiminnyw4/tab/Leads/4776201000005049105\nhttps://crmsandbox.zoho.com/crm/\n\nhttps://crm.zoho.com/crm/org3469620/tab/Leads/230045000229559080\n https://crm.zoho.com/crm/\n org3469620\n\nSELECT * FROM activities WHERE uuid_to_bin('03382d20-c8bc-48e7-a3d4-90b52fa5ceab') = uuid;\n\nselect * from users where email LIKE \"%mobile_automation_%\";\nselect * from social_accounts where sociable_id IN (2228);\nselect * from crm_profiles where user_id IN (2222,2223,2226,2227);\n\nselect * from teams order by id desc;\nSELECT * FROM users WHERE id = 2229;\nSELECT * FROM crm_profiles WHERE user_id = 2229;\nselect * from opportunities where crm_configuration_id = 88;\nselect * from crm_fields where crm_configuration_id = 88;\nselect * from crm_profiles where crm_configuration_id = 88;\n\nSELECT * FROM teams WHERE id = 1;\n\nSELECT * FROM users WHERE id = 143;\nSELECT * FROM users WHERE uuid_to_bin('fde193d3-06a2-4e1a-8895-62b94039215d') = uuid;\nSELECT * FROM teams WHERE uuid_to_bin('73385071-a756-42ae-9c73-8b53f2309467') = uuid;\n\nhttps://app.staging.jiminny.com/ondemand?\n min_duration=1\n &\n only_recorded=1\n &\n user_id%5B%5D=641f1acb-16b8-42d1-8726-df52979dad0e\n &\n sequence_number=2\n\n select * from users where team_id = 1 and email like '%stoyan%'\n\nselect * from coaching_feedbacks;\n\nselect * from teams;\nSELECT * FROM users WHERE team_id = 36;\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 19\nand sa.provider = 'pipedrive';\n\nselect * from users where id = 143;\n\nSELECT * FROM users WHERE uuid_to_bin('73180eeb-33de-4065-977d-ccbe0e6c94fc') = uuid;\nSELECT * FROM teams WHERE uuid_to_bin('73180eeb-33de-4065-977d-ccbe0e6c94fc') = uuid;\nSELECT * FROM activity_shares WHERE uuid_to_bin('73180eeb-33de-4065-977d-ccbe0e6c94fc') = uuid;\n\nselect * from users where team_id = 2;\nselect * from activities where crm_configuration_id = 39\nand activities.scheduled_start_time BETWEEN '2025-04-09 00:00:00' AND '2025-04-09 23:59:59'\nAND user_id = 143\norder by id desc;\n\n# ************************************************************************************\nselect * from teams where id = 142; # 2312, 126\nselect * from team_settings;\nselect * from users where team_id = 142; # 21642\nSELECT * FROM social_accounts WHERE sociable_id = 21642;\nSELECT * FROM crm_profiles cp join users u ON u.id = cp.user_id WHERE team_id = 142;\nselect * from crm_profiles where id IN (93);\nselect * from invitations;\nselect * from team_features where team_id = 1;\n\nSELECT * FROM crm_configurations WHERE id = 126;\nselect * from accounts where crm_configuration_id = 126 order by id desc;\nselect * from leads where crm_configuration_id = 126 order by id desc;\nselect * from contacts where crm_configuration_id = 126 order by id desc;\nselect * from opportunities where crm_configuration_id = 126 order by id desc;\nselect * from crm_profiles where crm_configuration_id = 126 order by id desc;\nselect * from crm_fields where crm_configuration_id = 126 # 11060\n# and type IN ('picklist', 'status')\n# and object_type = 'task'\norder by id desc;\n# 5731,5732,5733\nselect DISTINCT crm_field_id from crm_field_values where crm_field_id IN (11151,12239,12215,12185,12175,12165,12144,12137,12127,12109,12107,12105,12103,12092,12037,12005,12003,11987,11969,11958,11951,11942,11931,11924,11921,11917,11915,11901,11893,11883,11872,11870,11868,11866,11839,11833,11821,11793,11780,11777,11769,11757,11737,11735,11656,11645,11638,11629,11618,11611,11602,11591,11584,11581,11558,11544,11543,11534,11532,11529,11527,11503,11497,11493,11488,11470,11468,11457,11455,11397,11387,11372,11363,11348,11323,11318,11309,11301,11300,11292,11290,11286,11284,11256,11252,11242,11237,11233,11219,11176,11160) order by id desc;\nselect * from crm_layouts where crm_configuration_id = 126 order by id desc;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id in (300,299,298);\nselect * from stages where crm_configuration_id = 126 order by id desc;\nselect * from business_processes where crm_configuration_id = 126 order by id desc;\nselect * from business_process_stages where business_process_id IN (76,75,74,73);\nselect * from playbooks where team_id = 142;\nselect * from playbook_layouts where playbook_id IN (108);\nSELECT * FROM playbook_categories WHERE playbook_id IN (108);\n\nselect * from teams where id = 130;\nSELECT * FROM social_accounts WHERE sociable_id = 2291;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 2\nand sa.provider = 'hubspot';\n\nSELECT * FROM activities\n WHERE crm_configuration_id = 110;\n\nselect * from teams;\nselect * from crm_configurations;\n\nSELECT * FROM activities WHERE id = 628773;\nSELECT * FROM crm_profiles WHERE user_id = 1460;\nSELECT * FROM social_accounts WHERE sociable_id = 2291;\n\nselect * from teams;\nselect ru.*, pr.*, p.* from users u join role_user ru on ru.user_id = u.id\njoin permission_role pr on pr.role_id = ru.role_id\n join permissions p on p.id = pr.permission_id\nwhere team_id = 495 and p.name IN ('dial');\n\nselect * from teams where id = 145;\nselect * from crm_configurations where id = 129;\nselect * from social_accounts where sociable_id = 2317;\nSELECT * FROM activities WHERE uuid_to_bin('8dbab184-a333-4268-ad57-fb41f8d53a9a') = uuid;\n\nselect * from teams where id = 1;\nSELECT * FROM crm_layouts WHERE crm_configuration_id = 39;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 280;\nSELECT * FROM crm_layout_entities WHERE id = 5507;\nSELECT * FROM crm_fields WHERE crm_configuration_id = 39 and object_type IN ('event');\n\nselect * from teams;\nselect * from activities where crm_configuration_id = 14;\n\nSELECT * FROM social_accounts where provider = 'copper';\n\nselect * from activities where id = 628467;\nselect * from participants where activity_id = 628467;\n\nSELECT * FROM contacts WHERE id = 3969;\nSELECT * FROM accounts WHERE id = 177;\n\nSELECT * FROM activities WHERE uuid_to_bin('4eb54c77-cfa3-2bd4-84a7-9ed46a21c988') = uuid;\n\n# ********************* BH\nselect * from teams where id = 36;\nSELECT * FROM crm_configurations WHERE id = 21;\nselect * from activities where crm_configuration_id = 21 and id = 607901;\nselect * from activities where crm_configuration_id = 21;\n\nselect * roles;\nselect * from permissions;\nselect * from permission_role where permission_id = 226;\n\nselect * from migrations order by id desc;\n\n# mercury\n# neptune\n# earth\n\nselect * from teams;\nselect * from teams where id = 19;\nselect * from teams where id = 27;\nselect * from users where team_id = 27;\nSELECT * FROM crm_configurations WHERE id = 42;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 19\nand sa.provider = 'pipedrive';\n\nselect * from activities where id = 631461;\nSELECT * FROM crm_field_values WHERE crm_field_id = 180;\n\nselect * from teams where id = 2;\nSELECT * FROM social_accounts WHERE sociable_id = 89;\n\nSELECT * FROM activities WHERE uuid_to_bin('ba0c029a-bc14-4e17-8603-64174acebcbb') = uuid; # 634273\nselect * from activity_summary_logs where activity_id = 634273;\n\nselect * from sidekick_settings where team_id = 2;\n\nselect * from teams; # 2, 2\nSELECT * FROM crm_configurations WHERE team_id = 2; # 2\nselect * from team_features where team_id = 2;\nselect * from features;\nSELECT * FROM opportunities WHERE crm_configuration_id = 2 and crm_provider_id = '51317301383';\nSELECT * FROM opportunities WHERE crm_configuration_id = 2 order by id desc;\n\nselect * from automated_reports order by id desc;\nselect * from automated_report_results order by id desc;\nselect * from users where team_id = 1 and id IN (7160, 3248);\nselect * from migrations order by id desc;\n\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 1 and sa.provider = 'salesforce';\n\nselect * from teams where id = 1;\nselect * from groups g JOIN playbooks p on g.playbook_id = p.id where g.team_id = 1;\nselect * from groups where id = 565;\nselect * from playbooks where team_id = 1;\nselect * from playbooks where id = 175;\nselect * from playbook_categories where playbook_id = 175;\nselect * from users where team_id = 1;\nselect * from users where id = 7160;\nselect * from crm_profiles where user_id = 7160;\nselect * from features;\nselect\n *\n# id, uuid, type, provider, playbook_category_id, user_id, lead_id, contact_id, account_id, opportunity_id, stage_id,\n# crm_configuration_id, crm_provider_id, transcription_id, status\nfrom activities where crm_configuration_id = 1 and type = 'conference'\n# and crm_provider_id IS NOT NULL\nand provider != 'uploader' and actual_start_time IS NOT NULL\nORDER by id desc;\nselect * from activities where id = 54747783; # 00UO400000pCzojMAC\n\nselect p.id, p.activity_type, pc.id, pc.name\nFROM playbooks p\njoin playbook_categories pc on p.id = pc.playbook_id\nwhere p.team_id = 1 and p.activity_type = 'event';\n\nSELECT * FROM crm_fields WHERE crm_configuration_id = 1 and object_type = 'event';\nSELECT * FROM crm_field_values WHERE crm_field_id = 4;\n\nselect * from crm_layouts cl join playbook_layouts pl on cl.id = pl.layout_id\nwhere crm_configuration_id = 1 and pl.playbook_id = 175;\n\nselect * from teams;\nSELECT r.* FROM automated_reports r\njoin teams t on r.team_id = t.id\nWHERE r.frequency = 'daily'\n and r.status = 1\nAND t.status = 'active'\nAND (r.expires_at >= now() OR r.expires_at IS NULL);\n\nselect * from automated_report_results where report_id IN (18, 33);\n\nselect * from activity_searches where id = 10932;\nselect * from activity_search_filters where activity_search_id = 10932;\nselect * from automated_reports;\nselect * from automated_report_results where report_id IN (34, 35);","depth":4,"value":"SELECT * FROM teams WHERE id = 1;\n\nselect * from crm_layouts where crm_configuration_id = 39;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 283;\nSELECT * FROM crm_fields WHERE id = 2234;\nSELECT * FROM crm_field_values WHERE crm_field_id = 2234;\n\nselect * from crm_profiles where user_id = 143;\n\nselect * from record_types where crm_configuration_id = 39; # 0121K000001MHElQAO,0121K000001MHEqQAO\nselect * from business_processes where crm_configuration_id = 39;\n# 01941000000H669AAC, 01941000000H66JAAS\n\nselect * from record_type_field_values\n where record_type_id IN (24);\n\nselect * from crm_field_values where id IN (2730);\n\nselect * from crm_configurations where id = 39;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 1\nand sa.provider = 'salesforce'; #1035\n\n\nselect * from users where team_id = 1; # 222 group 3\nSELECT * FROM activities WHERE user_id = 222 order by id desc;\nselect * from sidekick_settings where team_id = 1;\nselect * from teams where id = 1;\nselect * from team_features where team_id = 1;\n\nselect * from activities where crm_configuration_id = 2\nand provider = 'ms-teams' and id = 608765;\n\nSELECT * FROM activities WHERE crm_configuration_id = 2 and crm_provider_id = '59523413338';\n\nselect * from sidekick_settings where team_id = 2;\n\nSELECT * FROM activities WHERE id = 608660;\nselect * from activity_summary_logs where activity_id = 608660;\nselect * from ai_prompts where transcription_id = 11214;\n\n# ********************************************************************************************************\nSELECT * FROM activities WHERE uuid_to_bin('ed78a437-2804-450e-ab2f-56ab1c641346') = uuid;\n# id: 608818, crm: 59628809737\nSELECT * FROM activities WHERE uuid_to_bin('36b06e55-afdd-4782-8dee-c624cd0af191') = uuid;\n# id: 608821, crm: 59632069252\nSELECT ce.start_time, ce.end_time, a.id, a.uuid, crm_provider_id, calendar_event_id, title,\nplaybook_category_id, user_id, lead_id, contact_id, account_id, opportunity_id,\nscheduled_start_time, scheduled_end_time, actual_start_time, actual_end_time, a.created_at\nFROM activities a\njoin calendar_events ce on a.calendar_event_id = ce.id\nWHERE a.id IN (608818, 608821);\n\nselect * from users where team_id = 1;\nselect * from team_settings where team_id = 1;\nselect * from crm_profiles where crm_configuration_id = 39 order by user_id;\n\nselect * from team_features where team_id = 1;\n\nselect * from users where team_id = 2;\n\nSELECT * FROM activities WHERE uuid_to_bin('ec7647e9-5225-458b-b475-f31aa2769204') = uuid; # 612639\n# Preslava N. Ivanova, grou id 3\n\nSELECT * FROM opportunities WHERE uuid_to_bin('a2928fe5-aec5-46cb-85d9-7654c89e46a6') = uuid;\n\nselect * from activities where opportunity_id = 344 and actual_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00';\n\nselect\n a.id,\n a.type,\n a.scheduled_start_time,\n a.actual_start_time,\n a.created_at,\n a.opportunity_id,\n a.status\nFROM activities a\nWHERE opportunity_id = 344\nand status IN ('completed', 'received', 'delivered')\nand (\n (a.actual_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00')\nOR (a.created_at between '2024-10-11 00:00:00' and '2024-10-12 00:00:00')\nOR (a.scheduled_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00'))\n;\n\nSELECT * FROM users WHERE id = 222;\n\nSELECT * FROM crm_profiles WHERE user_id = 222;\nselect * from crm_layouts where crm_configuration_id = 39;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 281;\n\nselect * from group_deal_risk_types;\n\nselect * from opportunities where team_id = 1;\n\nSELECT * FROM opportunities WHERE id = 315;\nSELECT * FROM crm_field_data WHERE object_id = 315;\nselect * from crm_field_data where object_id = 260;\n\nselect * from generic_ai_prompts where subject_id = 315;\n\nselect * from teams; # 36, 21, 121, james.graham@bullhorn.jiminny.com\nSELECT * FROM social_accounts WHERE sociable_id = 121 and provider = 'bullhorn';\n\n# ************************************************************************************\nselect * from teams where id = 1;\nselect * from crm_configurations where id = 39;\nselect * from users where team_id = 1;\nselect u.email, cp.* from users u\njoin crm_profiles cp on u.id = cp.user_id\nwhere u.team_id = 1;\n# 1 - 00541000004281rAAA\n# 204 - 0052g000003freeAAA\n# 429 - 0052g000003qGOiAAM\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 1\nand sa.provider = 'salesforce';\n\nselect * from activities where type = 'softphone'\nand created_at > '2024-12-11 15:24:36' order by id desc;\n\nselect * from activity_providers where team_id = 1;\nselect * from activity_provider_users where activity_provider_id = 328;\n\nselect * from opportunities where crm_configuration_id = 39\nAND account_id = 178 AND is_closed = false\norder by created_at DESC;\n\nselect * from contacts where id = 3952;\nselect * from accounts where id = 178;\n\n# ************************************************************************************\nselect * from teams where id = 36;\nselect * from crm_configurations where id = 21;\nselect * from users where team_id = 36;\nselect u.email, cp.* from users u\njoin crm_profiles cp on u.id = cp.user_id\nwhere u.team_id = 36;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 36\nand sa.provider = 'bullhorn';\n\nselect * from social_accounts where id = 348;\nUPDATE social_accounts SET\nprovider_user_token = '21442_6802599_91:41179a58-21e7-4d7c-ad58-56bb666b2f65',\nprovider_refresh_token = '21442_6802599_91:01c6b335-3f2a-42e4-85ff-8a08fa65fceb',\nexpires = 1733998131,\nstate = 'connected'\nWHERE id = 348;\n\n# ************************************************************************************\nselect * from teams where id = 31;\nselect * from crm_configurations where id = 18;\n\nselect * from users where team_id = 31; # 257\nselect u.email, cp.* from users u\njoin crm_profiles cp on u.id = cp.user_id\nwhere u.team_id = 31;\n\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 31\nand sa.provider = 'close';\n\nselect * from contacts where crm_configuration_id = 18;\n\n# ********************** NEPTUNE **************************************************************\nselect * from teams;\nselect * from users where id IN (1030, 1035, 1052);\nselect * from crm_configurations;\n\nselect * from users where team_id = 65; # 257\nselect * from team_settings where team_id = 65; # 257\nselect * from invitations where team_id = 65; # 257\nselect * from users where email = 'integration-account@jiminny.com'; # 257\nselect u.email, cp.* from users u\njoin crm_profiles cp on u.id = cp.user_id\nwhere u.team_id = 65;\n\nselect * from crm_configurations where id = 53;\nselect * from accounts where crm_configuration_id = 53 order by id desc;\nselect * from leads where crm_configuration_id = 53 order by id desc;\nselect * from contacts where crm_configuration_id = 53 order by id desc;\nselect * from opportunities where crm_configuration_id = 53 order by id desc;\nselect * from crm_profiles where crm_configuration_id = 53 order by id desc;\nselect * from crm_fields where crm_configuration_id = 53 order by id desc;\nselect * from crm_field_values where crm_field_id = 3341 order by id desc;\nselect * from crm_layouts where crm_configuration_id = 53 order by id desc;\nselect * from stages where crm_configuration_id = 53 order by id desc;\n\n\nselect * from crm_profiles where crm_configuration_id = 13;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 65\nand sa.provider = 'integration-app';\n\nselect * from contacts where crm_configuration_id = 13;\n\nselect * from social_accounts where sociable_id = 283;\n\nSELECT * FROM opportunities WHERE crm_provider_id = '006O400000E9bzeIAB';\n\nselect * from activity_providers where team_id = 65;\nSELECT * FROM activities WHERE crm_configuration_id IN (51, 52, 53);\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 65\n;\n\n# ***************************** STAGING ********************************************\nSELECT * FROM teams;\nSELECT * FROM teams WHERE id = 88;\nSELECT * FROM teams WHERE id = 89;\nselect * from team_settings where team_id = 89;\nSELECT * FROM users WHERE team_id = 89;\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 89;\n\nselect * from users;\nSELECT * FROM social_accounts WHERE sociable_id = 1761;\nSELECT * FROM crm_configurations WHERE id = 70;\nselect * from accounts where crm_configuration_id = 70 order by id desc;\nselect * from leads where crm_configuration_id = 70 order by id desc;\nselect * from contacts where crm_configuration_id = 70 order by id desc;\nselect * from opportunities where crm_configuration_id = 70 order by id desc;\nselect * from crm_profiles where crm_configuration_id = 70 order by id desc;\nselect * from crm_fields where crm_configuration_id = 70 order by id desc;\nselect * from crm_field_values where crm_field_id = 3536 order by id desc;\nselect * from crm_layouts where crm_configuration_id = 70 order by id desc;\nselect * from stages where crm_configuration_id = 70 order by id desc;\nselect * from business_processes where crm_configuration_id = 70 order by id desc;\nselect * from business_process_stages where business_process_id = 34;\n\nselect * from contacts where id = 10468;\n\nselect * from crm_layouts where crm_configuration_id = 70;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 388;\nSELECT * FROM crm_fields WHERE id IN (3533,3534,3535);\n\nselect * from activities where crm_configuration_id = 70\nand (account_id IS NOT NULL or lead_id IS NOT NULL or contact_id IS NOT NULL or opportunity_id IS NOT NULL) order by id desc;\n\nSELECT * FROM activities WHERE uuid_to_bin('2e10b60f-8a61-41c5-a3d4-28835353dc65') = uuid;\nSELECT * FROM activities where crm_configuration_id = 69 ;\n\nSELECT * FROM users WHERE email LIKE '%jiminny_web_sa2@jiminny.com%';\nSELECT * FROM activities WHERE uuid_to_bin('5a150c93-40fc-42ec-b3bd-c1d328e09f6e') = uuid;\nSELECT * FROM opportunities WHERE id = 385;\n\nselect * from participants p\njoin activities a on p.activity_id = a.id\nwhere a.crm_configuration_id = 70\nand (p.lead_id IS NOT NULL or p.contact_id IS NOT NULL);\nSELECT * FROM participants WHERE id = 1013638;\n\nselect * from teams where id = 90;\nselect * from users where team_id = 90;\nselect * from social_accounts where social_accounts.sociable_id IN (1960,1760);\nSELECT * FROM crm_profiles WHERE crm_configuration_id = 71;\nselect * from invitations where team_id = 90;\n\nselect * from crm_configurations where id = 71;\nselect * from accounts where crm_configuration_id = 71 order by id desc;\nselect * from leads where crm_configuration_id = 71 order by id desc;\nselect * from contacts where crm_configuration_id = 71 order by id desc;\nselect * from opportunities where crm_configuration_id = 71 order by id desc;\nselect * from crm_profiles where crm_configuration_id = 71 order by id desc;\nselect * from crm_fields where crm_configuration_id = 71 order by id desc;\nselect * from crm_field_values where crm_field_id = 3341 order by id desc;\nselect * from crm_layouts where crm_configuration_id = 71 order by id desc;\nselect * from stages where crm_configuration_id = 71 order by id desc;\n\nselect * from users order by secondary_email desc;\nselect u.id, u.email, u.status, sa.id, sa.provider_user_id from social_accounts sa\n join users u on sa.sociable_id = u.id\nwhere sa.provider = 'google' and u.email LIKE 'aneliya%';\n\nselect * from failed_jobs order by id desc;\n\nselect * from users where email = 'ben.allwright@learningpeople.co.uk' or secondary_email = 'ben.allwright@learningpeople.co.uk';\n\nselect * from teams;\nSELECT * FROM crm_profiles WHERE crm_configuration_id = 39;\nSELECT * FROM crm_fields WHERE crm_configuration_id = 39 and object_type = 'task';\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 1\nand sa.provider = 'salesforce';\n\n# ************************************************************************************\nSELECT * FROM activities WHERE uuid_to_bin('c38b3895-fd0f-4b1f-9fb2-c170dba137c6') = uuid;\nSELECT * FROM crm_configurations WHERE id = 70;\n\nselect * from teams where id = 1;\nselect * from groups where team_id = 1;\nselect * from users where team_id = 1;\n\nselect o.id, o.name,o.close_date, u.id, u.name, u.group_id, r.id, r.display_name, g.name, g.scope from opportunities o\njoin users u on o.user_id = u.id\njoin groups g on u.group_id = g.id\njoin role_user ru on u.id = ru.user_id\njoin roles r on ru.role_id = r.id\nwhere o.crm_configuration_id = 39 and close_date > '2024-01-01 00:00:00';\n\nselect * from role_user where user_id = 143;\nselect * from roles;\n\nselect * from role_user;\nselect * from groups where id = 9;\nselect * from scope_groups where group_id = 9;\n\n# ************************************************************************************\nselect * from teams where id = 36;\nselect * from crm_configurations;\nSELECT * FROM social_accounts WHERE sociable_id = 121;\n\nhttps://crmsandbox.zoho.com/crm/jiminnyw4/tab/Leads/4776201000005049105\nhttps://crmsandbox.zoho.com/crm/\n\nhttps://crm.zoho.com/crm/org3469620/tab/Leads/230045000229559080\n https://crm.zoho.com/crm/\n org3469620\n\nSELECT * FROM activities WHERE uuid_to_bin('03382d20-c8bc-48e7-a3d4-90b52fa5ceab') = uuid;\n\nselect * from users where email LIKE \"%mobile_automation_%\";\nselect * from social_accounts where sociable_id IN (2228);\nselect * from crm_profiles where user_id IN (2222,2223,2226,2227);\n\nselect * from teams order by id desc;\nSELECT * FROM users WHERE id = 2229;\nSELECT * FROM crm_profiles WHERE user_id = 2229;\nselect * from opportunities where crm_configuration_id = 88;\nselect * from crm_fields where crm_configuration_id = 88;\nselect * from crm_profiles where crm_configuration_id = 88;\n\nSELECT * FROM teams WHERE id = 1;\n\nSELECT * FROM users WHERE id = 143;\nSELECT * FROM users WHERE uuid_to_bin('fde193d3-06a2-4e1a-8895-62b94039215d') = uuid;\nSELECT * FROM teams WHERE uuid_to_bin('73385071-a756-42ae-9c73-8b53f2309467') = uuid;\n\nhttps://app.staging.jiminny.com/ondemand?\n min_duration=1\n &\n only_recorded=1\n &\n user_id%5B%5D=641f1acb-16b8-42d1-8726-df52979dad0e\n &\n sequence_number=2\n\n select * from users where team_id = 1 and email like '%stoyan%'\n\nselect * from coaching_feedbacks;\n\nselect * from teams;\nSELECT * FROM users WHERE team_id = 36;\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 19\nand sa.provider = 'pipedrive';\n\nselect * from users where id = 143;\n\nSELECT * FROM users WHERE uuid_to_bin('73180eeb-33de-4065-977d-ccbe0e6c94fc') = uuid;\nSELECT * FROM teams WHERE uuid_to_bin('73180eeb-33de-4065-977d-ccbe0e6c94fc') = uuid;\nSELECT * FROM activity_shares WHERE uuid_to_bin('73180eeb-33de-4065-977d-ccbe0e6c94fc') = uuid;\n\nselect * from users where team_id = 2;\nselect * from activities where crm_configuration_id = 39\nand activities.scheduled_start_time BETWEEN '2025-04-09 00:00:00' AND '2025-04-09 23:59:59'\nAND user_id = 143\norder by id desc;\n\n# ************************************************************************************\nselect * from teams where id = 142; # 2312, 126\nselect * from team_settings;\nselect * from users where team_id = 142; # 21642\nSELECT * FROM social_accounts WHERE sociable_id = 21642;\nSELECT * FROM crm_profiles cp join users u ON u.id = cp.user_id WHERE team_id = 142;\nselect * from crm_profiles where id IN (93);\nselect * from invitations;\nselect * from team_features where team_id = 1;\n\nSELECT * FROM crm_configurations WHERE id = 126;\nselect * from accounts where crm_configuration_id = 126 order by id desc;\nselect * from leads where crm_configuration_id = 126 order by id desc;\nselect * from contacts where crm_configuration_id = 126 order by id desc;\nselect * from opportunities where crm_configuration_id = 126 order by id desc;\nselect * from crm_profiles where crm_configuration_id = 126 order by id desc;\nselect * from crm_fields where crm_configuration_id = 126 # 11060\n# and type IN ('picklist', 'status')\n# and object_type = 'task'\norder by id desc;\n# 5731,5732,5733\nselect DISTINCT crm_field_id from crm_field_values where crm_field_id IN (11151,12239,12215,12185,12175,12165,12144,12137,12127,12109,12107,12105,12103,12092,12037,12005,12003,11987,11969,11958,11951,11942,11931,11924,11921,11917,11915,11901,11893,11883,11872,11870,11868,11866,11839,11833,11821,11793,11780,11777,11769,11757,11737,11735,11656,11645,11638,11629,11618,11611,11602,11591,11584,11581,11558,11544,11543,11534,11532,11529,11527,11503,11497,11493,11488,11470,11468,11457,11455,11397,11387,11372,11363,11348,11323,11318,11309,11301,11300,11292,11290,11286,11284,11256,11252,11242,11237,11233,11219,11176,11160) order by id desc;\nselect * from crm_layouts where crm_configuration_id = 126 order by id desc;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id in (300,299,298);\nselect * from stages where crm_configuration_id = 126 order by id desc;\nselect * from business_processes where crm_configuration_id = 126 order by id desc;\nselect * from business_process_stages where business_process_id IN (76,75,74,73);\nselect * from playbooks where team_id = 142;\nselect * from playbook_layouts where playbook_id IN (108);\nSELECT * FROM playbook_categories WHERE playbook_id IN (108);\n\nselect * from teams where id = 130;\nSELECT * FROM social_accounts WHERE sociable_id = 2291;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 2\nand sa.provider = 'hubspot';\n\nSELECT * FROM activities\n WHERE crm_configuration_id = 110;\n\nselect * from teams;\nselect * from crm_configurations;\n\nSELECT * FROM activities WHERE id = 628773;\nSELECT * FROM crm_profiles WHERE user_id = 1460;\nSELECT * FROM social_accounts WHERE sociable_id = 2291;\n\nselect * from teams;\nselect ru.*, pr.*, p.* from users u join role_user ru on ru.user_id = u.id\njoin permission_role pr on pr.role_id = ru.role_id\n join permissions p on p.id = pr.permission_id\nwhere team_id = 495 and p.name IN ('dial');\n\nselect * from teams where id = 145;\nselect * from crm_configurations where id = 129;\nselect * from social_accounts where sociable_id = 2317;\nSELECT * FROM activities WHERE uuid_to_bin('8dbab184-a333-4268-ad57-fb41f8d53a9a') = uuid;\n\nselect * from teams where id = 1;\nSELECT * FROM crm_layouts WHERE crm_configuration_id = 39;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 280;\nSELECT * FROM crm_layout_entities WHERE id = 5507;\nSELECT * FROM crm_fields WHERE crm_configuration_id = 39 and object_type IN ('event');\n\nselect * from teams;\nselect * from activities where crm_configuration_id = 14;\n\nSELECT * FROM social_accounts where provider = 'copper';\n\nselect * from activities where id = 628467;\nselect * from participants where activity_id = 628467;\n\nSELECT * FROM contacts WHERE id = 3969;\nSELECT * FROM accounts WHERE id = 177;\n\nSELECT * FROM activities WHERE uuid_to_bin('4eb54c77-cfa3-2bd4-84a7-9ed46a21c988') = uuid;\n\n# ********************* BH\nselect * from teams where id = 36;\nSELECT * FROM crm_configurations WHERE id = 21;\nselect * from activities where crm_configuration_id = 21 and id = 607901;\nselect * from activities where crm_configuration_id = 21;\n\nselect * roles;\nselect * from permissions;\nselect * from permission_role where permission_id = 226;\n\nselect * from migrations order by id desc;\n\n# mercury\n# neptune\n# earth\n\nselect * from teams;\nselect * from teams where id = 19;\nselect * from teams where id = 27;\nselect * from users where team_id = 27;\nSELECT * FROM crm_configurations WHERE id = 42;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 19\nand sa.provider = 'pipedrive';\n\nselect * from activities where id = 631461;\nSELECT * FROM crm_field_values WHERE crm_field_id = 180;\n\nselect * from teams where id = 2;\nSELECT * FROM social_accounts WHERE sociable_id = 89;\n\nSELECT * FROM activities WHERE uuid_to_bin('ba0c029a-bc14-4e17-8603-64174acebcbb') = uuid; # 634273\nselect * from activity_summary_logs where activity_id = 634273;\n\nselect * from sidekick_settings where team_id = 2;\n\nselect * from teams; # 2, 2\nSELECT * FROM crm_configurations WHERE team_id = 2; # 2\nselect * from team_features where team_id = 2;\nselect * from features;\nSELECT * FROM opportunities WHERE crm_configuration_id = 2 and crm_provider_id = '51317301383';\nSELECT * FROM opportunities WHERE crm_configuration_id = 2 order by id desc;\n\nselect * from automated_reports order by id desc;\nselect * from automated_report_results order by id desc;\nselect * from users where team_id = 1 and id IN (7160, 3248);\nselect * from migrations order by id desc;\n\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 1 and sa.provider = 'salesforce';\n\nselect * from teams where id = 1;\nselect * from groups g JOIN playbooks p on g.playbook_id = p.id where g.team_id = 1;\nselect * from groups where id = 565;\nselect * from playbooks where team_id = 1;\nselect * from playbooks where id = 175;\nselect * from playbook_categories where playbook_id = 175;\nselect * from users where team_id = 1;\nselect * from users where id = 7160;\nselect * from crm_profiles where user_id = 7160;\nselect * from features;\nselect\n *\n# id, uuid, type, provider, playbook_category_id, user_id, lead_id, contact_id, account_id, opportunity_id, stage_id,\n# crm_configuration_id, crm_provider_id, transcription_id, status\nfrom activities where crm_configuration_id = 1 and type = 'conference'\n# and crm_provider_id IS NOT NULL\nand provider != 'uploader' and actual_start_time IS NOT NULL\nORDER by id desc;\nselect * from activities where id = 54747783; # 00UO400000pCzojMAC\n\nselect p.id, p.activity_type, pc.id, pc.name\nFROM playbooks p\njoin playbook_categories pc on p.id = pc.playbook_id\nwhere p.team_id = 1 and p.activity_type = 'event';\n\nSELECT * FROM crm_fields WHERE crm_configuration_id = 1 and object_type = 'event';\nSELECT * FROM crm_field_values WHERE crm_field_id = 4;\n\nselect * from crm_layouts cl join playbook_layouts pl on cl.id = pl.layout_id\nwhere crm_configuration_id = 1 and pl.playbook_id = 175;\n\nselect * from teams;\nSELECT r.* FROM automated_reports r\njoin teams t on r.team_id = t.id\nWHERE r.frequency = 'daily'\n and r.status = 1\nAND t.status = 'active'\nAND (r.expires_at >= now() OR r.expires_at IS NULL);\n\nselect * from automated_report_results where report_id IN (18, 33);\n\nselect * from activity_searches where id = 10932;\nselect * from activity_search_filters where activity_search_id = 10932;\nselect * from automated_reports;\nselect * from automated_report_results where report_id IN (34, 35);","role_description":"text entry area","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.088194445,"height":0.027777778},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"102","depth":4,"role_description":"text"},{"role":"AXStaticText","text":"3","depth":4,"role_description":"text"},{"role":"AXStaticText","text":"34","depth":4,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Services\\Kiosk\\AutomatedReports;\n\nuse Carbon\\CarbonImmutable;\nuse Carbon\\CarbonInterface;\nuse Carbon\\Exceptions\\InvalidFormatException;\nuse DateTime;\nuse DateTimeInterface;\nuse DateTimeZone;\nuse Illuminate\\Contracts\\Bus\\Dispatcher as BusDispatcher;\nuse Illuminate\\Database\\Eloquent\\Builder;\nuse Illuminate\\Support\\Carbon;\nuse Illuminate\\Support\\Collection;\nuse Illuminate\\Support\\Facades\\Log;\nuse Illuminate\\Support\\Facades\\Storage;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinition\\InputTypeEnum;\nuse Jiminny\\Component\\AskAnything\\AskAnythingPromptService;\nuse Jiminny\\Component\\AskAnything\\Dtos\\AskAnythingPromptDto;\nuse Jiminny\\Component\\UrlGenerator\\Webhook;\nuse Jiminny\\Contracts\\Repositories\\PlaybookCategoryRepository;\nuse Jiminny\\Contracts\\Repositories\\TeamRepository;\nuse Jiminny\\Contracts\\Repositories\\UserRepository;\nuse Jiminny\\Exceptions\\ApplicationException;\nuse Jiminny\\Exceptions\\InvalidArgumentException;\nuse Jiminny\\Exceptions\\ModelNotFoundException;\nuse Jiminny\\Jobs\\AutomatedReports\\RequestGenerateReportJob;\nuse Jiminny\\Models\\Activity\\Search;\nuse Jiminny\\Models\\AskAnything\\AskAnythingPrompt;\nuse Jiminny\\Models\\AskAnything\\AskAnythingPromptTarget;\nuse Jiminny\\Models\\AutomatedReport;\nuse Jiminny\\Models\\AutomatedReportResult;\nuse Jiminny\\Models\\Contracts\\UserContract;\nuse Jiminny\\Models\\Feature\\FeatureEnum;\nuse Jiminny\\Models\\Team;\nuse Jiminny\\Models\\User;\nuse Jiminny\\Repositories\\AskAnythingRepository;\nuse Jiminny\\Repositories\\AutomatedReportsRepository;\nuse Jiminny\\Repositories\\GroupRepository;\nuse Jiminny\\Repositories\\SearchRepository;\nuse Jiminny\\Repositories\\StageRepository;\nuse Throwable;\n\nclass AutomatedReportsService\n{\n public const string TYPE_LOSS_ANALYSIS = 'loss_analysis';\n public const string TYPE_ASK_JIMINNY = 'ask_jiminny';\n\n /**\n * Standard report types (used by kiosk for existing automated reports).\n */\n // @TODO this will add filter, however if we need to control feature by FF we need conditional logic\n public const array TYPES = [\n ['id' => 'exec_summary', 'name' => 'Exec Summary'],\n ['id' => 'coaching_profiles', 'name' => 'Coaching Profiles'],\n ['id' => 'product_feedback', 'name' => 'Product Feedback'],\n ['id' => self::TYPE_LOSS_ANALYSIS, 'name' => 'Loss Analysis'],\n// ['id' => 'questions', 'name' => 'Questions'],\n// ['id' => 'statistical_quant', 'name' => 'Statistical Quantitative'],\n ];\n\n public const array ALL_TYPES = [\n ...self::TYPES,\n ['id' => self::TYPE_ASK_JIMINNY, 'name' => 'Ask Jiminny'],\n ];\n\n public const string FREQUENCY_DAILY = 'daily';\n public const string FREQUENCY_WEEKLY = 'weekly';\n public const string FREQUENCY_MONTHLY = 'monthly';\n public const string FREQUENCY_QUARTERLY = 'quarterly';\n public const string FREQUENCY_ONE_OFF = 'one_off';\n\n /**\n * Frequencies for standard (non-Ask Jiminny) reports.\n */\n public const array FREQUENCIES = [\n ['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],\n ['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],\n ['id' => self::FREQUENCY_QUARTERLY, 'name' => 'Quarterly'],\n ['id' => self::FREQUENCY_ONE_OFF, 'name' => 'One-off'],\n ];\n\n /**\n * Frequencies for Ask Jiminny reports.\n */\n public const array ASK_JIMINNY_FREQUENCIES = [\n ['id' => self::FREQUENCY_DAILY, 'name' => 'Daily'],\n ['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],\n ['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],\n ];\n\n public const string MEDIA_TYPE_PDF = 'pdf';\n public const string MEDIA_TYPE_PODCAST = 'podcast';\n public const array MEDIA_TYPES = [self::MEDIA_TYPE_PDF, self::MEDIA_TYPE_PODCAST];\n public const array MEDIA_TYPE_OBJECT_PDF = ['id' => self::MEDIA_TYPE_PDF, 'name' => 'PDF'];\n public const array MEDIA_TYPE_OBJECT_PODCAST = ['id' => self::MEDIA_TYPE_PODCAST, 'name' => 'Podcast'];\n public const array MEDIA_TYPE_OBJECTS = [self::MEDIA_TYPE_OBJECT_PDF, self::MEDIA_TYPE_OBJECT_PODCAST];\n\n public const array CALL_TYPE_CONFERENCE = ['id' => 'conference', 'name' => 'Conference'];\n public const array CALL_TYPE_DIALER = ['id' => 'dialer', 'name' => 'Dialer'];\n public const int SENT_REPORT_AT_HOURS = 5;\n public const string PDF_KEY = 'pdf';\n public const string AUDIO_KEY = 'audio';\n\n private const array ALL_FREQUENCIES = [\n ['id' => self::FREQUENCY_DAILY, 'name' => 'Daily'],\n ['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],\n ['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],\n ['id' => self::FREQUENCY_QUARTERLY, 'name' => 'Quarterly'],\n ['id' => self::FREQUENCY_ONE_OFF, 'name' => 'One-off'],\n ];\n private const string S3_DIR = 'reports';\n private const array FILE_EXTENSIONS_VARIANTS = ['html', 'MD', 'pdf'];\n private const array FILE_PODCAST_EXTENSIONS_VARIANTS = ['json', 'mp3', 'ssml'];\n\n public function __construct(\n private readonly TeamRepository $teamRepository,\n private readonly GroupRepository $groupRepository,\n private readonly UserRepository $userRepository,\n private readonly StageRepository $stageRepository,\n private readonly DealStagesService $dealStagesService,\n private readonly RecipientsService $recipientsService,\n private readonly AutomatedReportsRepository $automatedReportsRepository,\n private readonly Webhook $webhookService,\n private readonly BusDispatcher $dispatcher,\n private readonly ActivityTypeService $activityTypeService,\n private readonly PlaybookCategoryRepository $playbookCategoryRepository,\n private readonly AskAnythingPromptService $askAnythingPromptService,\n private readonly SearchRepository $activitySearchRepository,\n private readonly AskAnythingRepository $askAnythingRepository,\n ) {\n }\n\n public static function getTypes(): array\n {\n $types = self::TYPES;\n\n return array_map(static function ($type) {\n return $type['id'];\n }, $types);\n }\n\n public static function getCallTypes(): array\n {\n return array_map(static function ($callType) {\n return $callType['id'];\n }, [self::CALL_TYPE_CONFERENCE, self::CALL_TYPE_DIALER]);\n }\n\n public static function getFrequencies(): array\n {\n return array_map(static function ($frequency) {\n return $frequency['id'];\n }, self::FREQUENCIES);\n }\n\n // front-facing structure\n public function getReportEnabledFieldData(bool $value = false): array\n {\n return [\n 'id' => 'report_enabled',\n 'label' => '',\n 'inputType' => InputTypeEnum::TOGGLE,\n 'value' => $value,\n ];\n }\n\n // Organizations = Teams\n public function getOrganizationFieldData(?string $value = null, bool $shortVersion = false): array\n {\n $options = $this->getTeams();\n\n if ($shortVersion) {\n return [\n 'id' => 'organization',\n 'label' => 'Organization',\n 'options' => $options,\n ];\n }\n\n return [\n 'id' => 'organization',\n 'label' => 'Organization',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => $options,\n 'value' => $value,\n 'dependencies' => [\n 'teams',\n 'deal_stage_at_call',\n 'current_deal_stage',\n 'recipients',\n ActivityTypeService::PLAYBOOK_CATEGORIES_KEY,\n ],\n 'dependsOn' => [],\n ];\n }\n\n // Teams = Groups\n public function getTeamFieldData(array $options = [], array $value = [], bool $shortVersion = false): array\n {\n if ($shortVersion) {\n return [\n 'id' => 'teams',\n 'label' => 'Team',\n 'options' => $options,\n ];\n }\n\n return [\n 'id' => 'teams',\n 'label' => 'Team',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'required' => false,\n 'placeholder' => 'Select',\n 'options' => $options,\n 'value' => $value, // value should be an array of objects {id, name}\n 'dependencies' => [ActivityTypeService::PLAYBOOK_CATEGORIES_KEY],\n 'dependsOn' => [],\n ];\n }\n\n public function getReportTypeFieldData(?string $value = null, bool $shortVersion = false, ?Team $team = null): array\n {\n $types = [];\n if ($team instanceof Team) {\n if ($team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {\n $types = self::TYPES;\n }\n if ($team->hasFeature(FeatureEnum::ASK_JIMINNY_REPORTS)) {\n $types[] = ['id' => self::TYPE_ASK_JIMINNY, 'name' => 'Ask Jiminny'];\n }\n } else {\n $types = self::TYPES;\n }\n\n if ($shortVersion) {\n return [\n 'id' => 'report_type',\n 'label' => 'Report Type',\n 'options' => $types,\n ];\n }\n\n return [\n 'id' => 'report_type',\n 'label' => 'Report Type',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => $types,\n 'value' => $value,\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getFrequencyFieldData(?string $value = null): array\n {\n return [\n 'id' => 'frequency',\n 'label' => 'Frequency',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => self::FREQUENCIES,\n 'value' => $value,\n 'dependencies' => ['period'],\n 'dependsOn' => [],\n ];\n }\n\n public function getPeriodFieldData(?string $valueStartDate = null, ?string $valueEndDate = null): array\n {\n return [\n 'id' => 'period',\n 'label' => 'Select one-off period',\n 'inputType' => InputTypeEnum::DATE_RANGE,\n 'required' => true,\n 'placeholder' => 'Select',\n 'value' => ['startDate' => $valueStartDate, 'endDate' => $valueEndDate],\n 'queryParams' => [\n 'startDate' => 'start_date_period',\n 'endDate' => 'end_date_period',\n ],\n 'dependencies' => [],\n 'dependsOn' => ['frequency'],\n ];\n }\n\n public function getActivityTypesFieldData(?Team $team = null, array $value = [], array $teamsFilter = []): array\n {\n return $this->activityTypeService->getActivityTypeFieldData(team: $team, value: $value, groupIds: $teamsFilter);\n }\n\n public function getDealStageAtCallFieldData(?Team $team = null, array $value = []): array\n {\n return $this->dealStagesService->getDealStageAtCallFieldData(team: $team, value: $value);\n }\n\n public function getCurrentDealStageFieldData(?Team $team = null, array $value = []): array\n {\n return $this->dealStagesService->getCurrentDealStageFieldData(team: $team, value: $value);\n }\n\n public function getDealValueFieldData(?int $valueMin = null, ?int $valueMax = null): array\n {\n return [\n 'id' => 'deal_value',\n 'label' => 'Deal Value',\n 'inputType' => InputTypeEnum::INTEGER_RANGE,\n 'required' => false,\n 'value' => ['min' => $valueMin, 'max' => $valueMax],\n 'queryParams' => [\n 'min' => 'min_deal_value',\n 'max' => 'max_deal_value',\n ],\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getCallTypeFieldData(bool $conferenceOn = false, bool $dialerOn = false): array\n {\n $value = [];\n $conferenceOn && $value[] = self::CALL_TYPE_CONFERENCE;\n $dialerOn && $value[] = self::CALL_TYPE_DIALER;\n\n return [\n 'id' => 'call_type',\n 'label' => 'Call Type',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'required' => true,\n 'options' => [\n self::CALL_TYPE_CONFERENCE,\n self::CALL_TYPE_DIALER,\n ],\n 'value' => $value,\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getMediaTypeFieldData(?AutomatedReport $report = null): array\n {\n $value = [];\n\n if ($report) {\n $value = $this->transformMediaTypes($report);\n }\n\n return [\n 'id' => 'media_types',\n 'label' => 'Export as',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'required' => true,\n 'options' => self::MEDIA_TYPE_OBJECTS,\n 'value' => $value,\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getCallDurationFieldData(?int $valueMin = null, ?int $valueMax = null): array\n {\n return [\n 'id' => 'call_duration',\n 'label' => 'Call Duration',\n 'inputType' => InputTypeEnum::INTEGER_RANGE,\n 'required' => false,\n 'value' => ['min' => $valueMin, 'max' => $valueMax],\n 'queryParams' => [\n 'min' => 'min_call_duration',\n 'max' => 'max_call_duration',\n ],\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getRecipientsFieldData(?Team $team = null, array $value = []): array\n {\n return $this->recipientsService->getRecipientsFieldData(team: $team, value: $value);\n }\n\n public function getJiminnyRecipientsFieldData(array $value = []): array\n {\n return $this->recipientsService->getJiminnyRecipientsFieldData($value);\n }\n\n public function getAdditionalPromptInputFieldData(?string $value = null): array\n {\n return [\n 'id' => 'additional_prompt_input',\n 'label' => 'Special requirements',\n 'inputType' => InputTypeEnum::TEXTAREA,\n 'required' => false,\n 'placeholder' => 'What should be the focus of the report?',\n 'value' => $value,\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getCustomReportNameFieldData(?string $value = null): array\n {\n return [\n 'id' => 'custom_name',\n 'label' => 'Custom report name',\n 'inputType' => InputTypeEnum::TEXT,\n 'required' => false,\n 'placeholder' => 'Enter custom name',\n 'value' => $value,\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n // data providers\n public function getTeams(): array\n {\n $teams = $this->teamRepository->getTeamsForKiosk(status: Team::STATUS_ACTIVE);\n\n $teamData = [];\n foreach ($teams as $team) {\n if (! $team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {\n continue;\n }\n\n $teamData[] = $this->transformTeam($team);\n }\n\n return $teamData;\n }\n\n public function getTeamGroups(string $teamUuid): array\n {\n $data = [];\n $team = $this->getTeam($teamUuid);\n\n if ($team !== null) {\n $groups = $team->groups()->get();\n\n foreach ($groups as $group) {\n $data[] = [\n 'id' => $group->getUuid(),\n 'name' => $group->getName(),\n ];\n }\n }\n\n return $data;\n }\n\n public function getTeamsGroupsOptions(array $filterTeamUuids = []): array\n {\n $data = [];\n $teams = $this->getTeams();\n\n foreach ($teams as $team) {\n if (! empty($filterTeamUuids) && ! in_array($team['id'], $filterTeamUuids, true)) {\n continue;\n }\n\n $data[] = [\n 'label' => $team['name'],\n 'groups' => $this->getTeamGroups($team['id']),\n ];\n }\n\n return $data;\n }\n\n public function getTeam(string $teamUuid): ?Team\n {\n return $this->teamRepository->idOrUuid($teamUuid);\n }\n\n public function getTeamById(int $teamId): ?Team\n {\n return $this->teamRepository->find($teamId);\n }\n\n public function getGroupsUuids(AutomatedReport $report): array\n {\n $uuids = [];\n $reportGroups = $report->getGroups();\n foreach ($reportGroups as $groupId) {\n if ($group = $this->groupRepository->find($groupId)) {\n $uuids[] = $group->getUuid();\n }\n }\n\n return $uuids;\n }\n\n public function getPlaybookCategoriesUuids(AutomatedReport $report): array\n {\n $uuids = [];\n $playbookCategories = $report->getPlaybookCategories();\n foreach ($playbookCategories as $id) {\n if ($category = $this->playbookCategoryRepository->find($id)) {\n $uuids[] = $category->getUuid();\n }\n }\n\n return $uuids;\n }\n\n public function getDealAtCallStagesUuids(AutomatedReport $report): array\n {\n $uuids = [];\n $reportStages = $report->getDealAtCallStages();\n foreach ($reportStages as $id) {\n if ($stage = $this->stageRepository->find($id)) {\n $uuids[] = $stage->getUuid();\n }\n }\n\n return $uuids;\n }\n\n public function getCurrentDealStagesUuids(AutomatedReport $report): array\n {\n $uuids = [];\n $reportStages = $report->getCurrentDealStages();\n foreach ($reportStages as $id) {\n if ($stage = $this->stageRepository->find($id)) {\n $uuids[] = $stage->getUuid();\n }\n }\n\n return $uuids;\n }\n\n public function getUsersUuids(AutomatedReport $report): array\n {\n return $this->extractUserUuids($report->getRecipients());\n }\n\n public function getJiminnyUsersUuids(AutomatedReport $report): array\n {\n return $this->extractUserUuids($report->getJiminnyRecipients());\n }\n\n /**\n * @param array<string, mixed> $recipients\n */\n private function extractUserUuids(array $recipients): array\n {\n $userIds = $recipients['users'] ?? [];\n\n return collect($userIds)\n ->map(fn ($id) => $this->userRepository->find((int) $id))\n ->filter()\n ->map(fn (UserContract $user) => $user->getUuid())\n ->values()\n ->all();\n }\n\n // get mail data\n public function getRecipientUsers(AutomatedReport $report): array\n {\n return $this->buildRecipientUsers($report->getRecipients());\n }\n\n private function getJiminnyRecipientUsers(AutomatedReport $report): array\n {\n return $this->buildRecipientUsers($report->getJiminnyRecipients());\n }\n\n /**\n * @param array<string, mixed> $recipients\n */\n private function buildRecipientUsers(array $recipients): array\n {\n $userIds = $recipients['users'] ?? [];\n\n return collect($userIds)\n ->map(fn ($id) => $this->userRepository->find((int) $id))\n ->filter()\n ->map(fn (UserContract $user) => [\n 'email' => $user->getEmailAddress(),\n 'name' => $user->getName(),\n 'timezone' => $user->getTimezone()->getName(),\n ])\n ->values()\n ->all();\n }\n\n public function getValidRecipientUsers(AutomatedReport $report, bool $includeJiminny = false): array\n {\n if ($report->isAskJiminnyReport()) {\n $recipients = $this->resolveAskJiminnyRecipients($report);\n } else {\n $recipients = $this->getRecipientUsers($report);\n if ($includeJiminny) {\n $recipients = array_merge($recipients, $this->getJiminnyRecipientUsers($report));\n }\n }\n\n $emails = [];\n\n return array_values(array_filter(\n $recipients,\n static function ($recipient) use (&$emails) {\n if (empty($recipient['email']) || in_array($recipient['email'], $emails, true)) {\n return false;\n }\n $emails[] = $recipient['email'];\n\n return true;\n }\n ));\n }\n\n private function resolveAskJiminnyRecipients(AutomatedReport $report): array\n {\n $recipients = [];\n\n $creator = $report->getCreator();\n if ($creator !== null) {\n $recipients[] = [\n 'email' => $creator->getEmailAddress(),\n 'name' => $creator->getName(),\n 'timezone' => $creator->getTimezone()->getName(),\n ];\n }\n\n return array_merge(\n $recipients,\n $this->buildRecipientUsers($report->getRecipients()),\n $this->getGroupRecipientUsers($report),\n );\n }\n\n private function getGroupRecipientUsers(AutomatedReport $report): array\n {\n $users = [];\n foreach ($report->getGroups() as $groupId) {\n $group = $this->groupRepository->find($groupId);\n if ($group === null) {\n continue;\n }\n foreach ($group->getMembers() as $member) {\n $users[] = [\n 'email' => $member->getEmailAddress(),\n 'name' => $member->getName(),\n 'timezone' => $member->getTimezone()->getName(),\n ];\n }\n }\n\n return $users;\n }\n\n public function getReportTypeName(AutomatedReportResult $report): string\n {\n $type = $report->getReport()->getType();\n\n $getType = $this->transformReportType($type);\n\n return $getType['name'];\n }\n\n public function getReportPeriodName(AutomatedReportResult $report): string\n {\n $from = $report->getFromDate();\n $to = $report->getToDate();\n $frequency = $report->getReport()->getFrequency();\n\n if ($from === null || $to === null) {\n if (! $report->getReport()->isAskJiminnyReport()) {\n $invalidPeriod = $from === null ? 'from' : 'to';\n\n throw new ApplicationException('Report period is invalid: ' . $invalidPeriod);\n }\n\n $period = $this->calculateFromAndToDatePeriod($frequency);\n $from = $period['fromDate'];\n $to = $period['toDate'];\n }\n\n return $this->formatReportPeriodName($frequency, $from, $to);\n }\n\n private function formatReportPeriodName(string $frequency, Carbon $from, Carbon $to): string\n {\n $fromYear = $from->format('Y');\n $toYear = $to->format('Y');\n $differentYears = $fromYear !== $toYear;\n\n switch ($frequency) {\n case self::FREQUENCY_DAILY:\n return $from->format('j M Y');\n\n case self::FREQUENCY_QUARTERLY:\n // 'Jan-Mar 2025' or 'Nov 2024-Jan 2025' if years differ\n $startMonth = $from->format('M');\n $endMonth = $to->copy()->subMonth();\n $endMonthName = $endMonth->format('M');\n $endMonthYear = $endMonth->format('Y');\n\n if ($differentYears) {\n return \"{$startMonth} {$fromYear} - {$endMonthName} {$endMonthYear}\";\n }\n\n return \"{$startMonth} - {$endMonthName} {$toYear}\";\n\n case self::FREQUENCY_MONTHLY:\n // 'May 2025' - monthly reports are always within the same year\n return $from->format('M Y');\n\n case self::FREQUENCY_WEEKLY:\n // '4 - 8 Aug 2025', '27 Oct - 3 Nov 2025', or '28 Dec 2024 - 3 Jan 2025' if years differ\n $startDay = $from->format('j');\n $endDay = $to->format('j');\n $startMonth = $from->format('M');\n $endMonth = $to->format('M');\n\n if ($differentYears) {\n return \"{$startDay} {$startMonth} {$fromYear} - {$endDay} {$endMonth} {$toYear}\";\n }\n\n if ($startMonth !== $endMonth) {\n return \"{$startDay} {$startMonth} - {$endDay} {$endMonth} {$toYear}\";\n }\n\n return \"{$startDay} - {$endDay} {$endMonth} {$toYear}\";\n\n case self::FREQUENCY_ONE_OFF:\n // '2 May-31 May 2025' or '15 Dec 2024-15 Jan 2025' if years differ\n $startDay = $from->format('j');\n $startMonth = $from->format('M');\n $endDay = $to->format('j');\n $endMonth = $to->format('M');\n\n // If same month and year, use a format like '2-31 May 2025'\n if ($startMonth === $endMonth && ! $differentYears) {\n return \"{$startDay} - {$endDay} {$startMonth} {$toYear}\";\n }\n\n // If different years, include both years\n if ($differentYears) {\n return \"{$startDay} {$startMonth} {$fromYear} - {$endDay} {$endMonth} {$toYear}\";\n }\n\n // Same year but different months\n return \"{$startDay} {$startMonth} - {$endDay} {$endMonth} {$toYear}\";\n\n default:\n // Default format for unknown frequencies\n return $from->format('j M Y') . ' - ' . $to->format('j M Y');\n }\n }\n\n public function getReportTeamsName(AutomatedReportResult $report): string\n {\n $groups = $report->getGroups();\n\n if (empty($groups)) {\n return 'All';\n }\n\n // Get group names from repository\n $groupNames = [];\n foreach ($groups as $groupId) {\n $group = $this->groupRepository->find($groupId);\n if ($group) {\n $groupNames[] = $group->getName();\n }\n }\n\n if (count($groupNames) === 1) {\n // Single team format\n $teamsName = $groupNames[0];\n } else {\n // Multiple teams format\n $teamsName = implode(', ', $groupNames);\n }\n\n return $teamsName;\n }\n\n public function getReportFileName(AutomatedReportResult $report): string\n {\n $customName = $report->getReport()->getCustomName();\n $periodName = $this->getReportPeriodName($report);\n $filenameSuffix = $this->getFilenameSuffix($report);\n\n if ($customName) {\n if ($filenameSuffix) {\n $customName .= \" {$filenameSuffix}\";\n }\n\n return $this->sanitizeFileName(\"{$customName} - {$periodName}\");\n }\n\n $baseName = $this->getReportTypeName($report);\n\n if ($filenameSuffix) {\n $baseName .= \" {$filenameSuffix}\";\n }\n\n return $this->sanitizeFileName(\"{$baseName} - {$periodName} - {$this->getReportTeamsName($report)}\");\n }\n\n public function getReportFileNameWithExtension(AutomatedReportResult $result): string\n {\n $extension = $this->getMediaTypeMetadata($result)['extension'];\n\n return $this->getReportFileName($result) . '.' . $extension;\n }\n\n public function sanitizeFileName(string $fileName): string\n {\n return str_replace(['/', '\\\\'], '-', $fileName);\n }\n\n public function isUserRecipientOfReport(User $user, AutomatedReport $report): bool\n {\n $recipients = array_map('intval', $report->getRecipients()['users'] ?? []);\n\n return in_array($user->getId(), $recipients);\n }\n\n public function transformReportResults(Collection $automatedReportResults): array\n {\n $data = [];\n foreach ($automatedReportResults as $automatedReportResult) {\n /** @var AutomatedReportResult $automatedReportResult */\n\n $report = $automatedReportResult->getReport();\n\n $createdBy = $report->getCreator();\n $creator = [\n 'id' => $createdBy?->getUuid(),\n 'name' => $createdBy?->getName(),\n 'email' => $createdBy?->getEmailAddress(),\n 'photoUrl' => $createdBy?->getPhotoUrl(),\n ];\n\n $data[] = [\n 'id' => $automatedReportResult->getUuid(),\n 'name' => $automatedReportResult->getName(),\n 'frequency' => $this->transformFrequency($report->getFrequency()),\n 'recipients' => [\n ...array_values($this->transformGroups(team: $report->getTeam(), groupsIds: $report->getGroups())),\n ...array_values($this->transformRecipients($report->getRecipients())),\n ],\n 'report_type' => $this->transformReportType($report->getType()),\n 'media_type' => $automatedReportResult->getMediaType(),\n 'downloadUrl' => $this->generateReportResultDownloadUrl($automatedReportResult),\n 'viewUrl' => $this->generateReportResultViewUrl($automatedReportResult),\n 'generated_at' => $automatedReportResult->getGeneratedAt()?->toIso8601String(),\n 'creator' => $creator,\n ];\n }\n\n return $data;\n }\n\n public function hasCallTypeConference(AutomatedReport $report): bool\n {\n return in_array(self::CALL_TYPE_CONFERENCE['id'], $report->getCallTypes(), true);\n }\n\n public function hasCallTypeDialer(AutomatedReport $report): bool\n {\n return in_array(self::CALL_TYPE_DIALER['id'], $report->getCallTypes(), true);\n }\n\n // transformers\n private function transformTeam(Team $team): array\n {\n if (! $team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {\n return [];\n }\n\n return [\n 'id' => $team->getUuid(),\n 'name' => $team->getName(),\n ];\n }\n\n private function transformReportFullView(AutomatedReport $report): array\n {\n $base = $this->transformReportBase($report);\n\n return $report->getType() === self::TYPE_ASK_JIMINNY\n ? $base + $this->transformAskJiminnyFields($report)\n : $base + $this->transformStandardReportFields($report);\n }\n\n private function transformReportBase(AutomatedReport $report): array\n {\n return [\n 'id' => $report->getUuid(),\n 'organization' => $this->transformOrganization(team: $report->getTeam()),\n 'report_type' => $this->transformReportType($report->getType()),\n 'frequency' => $this->transformFrequency($report->getFrequency()),\n ];\n }\n\n private function transformStandardReportFields(AutomatedReport $report): array\n {\n $team = $report->getTeam();\n\n return [\n 'report_enabled' => $report->getStatus(),\n 'start_date_period' => $report->getFrom()?->format('Y-m-d H:i:s'),\n 'end_date_period' => $report->getTo()?->format('Y-m-d H:i:s'),\n 'deal_value_min' => $report->getDealValueMin(),\n 'deal_value_max' => $report->getDealValueMax(),\n 'call_types' => $this->transformCallType($report->getCallTypes()),\n 'media_types' => $this->transformMediaTypes($report),\n 'call_duration_min' => $this->transformDurationToMinutes($report->getCallDurationMin()),\n 'call_duration_max' => $this->transformDurationToMinutes($report->getCallDurationMax()),\n 'teams' => $this->transformGroups(team: $team, groupsIds: $report->getGroups()),\n 'deal_at_call_stages' => $this->transformStages(team: $team, stagesIds: $report->getDealAtCallStages()),\n 'current_deal_stages' => $this->transformStages(team: $team, stagesIds: $report->getCurrentDealStages()),\n 'recipients' => $this->transformRecipients($report->getRecipients()),\n 'created_by' => $this->transformCreator($report->getCreator()),\n 'additional_prompt_input' => $report->getAdditionalPromptInput(),\n 'custom_name' => $report->getCustomName(),\n 'created_at' => $report->getCreatedAt()->format('Y-m-d H:i:s'),\n 'updated_at' => $report->getUpdatedAt()->format('Y-m-d H:i:s'),\n 'deleted_at' => $report->getDeletedAt()?->format('Y-m-d H:i:s'),\n ];\n }\n\n private function transformAskJiminnyFields(AutomatedReport $report): array\n {\n $team = $report->getTeam();\n $creatorId = $report->getAttribute('created_by');\n $explicitUserIds = array_values(array_filter(\n $report->getRecipients()['users'] ?? [],\n static fn ($id) => $id !== $creatorId\n ));\n\n return [\n 'report_name' => $report->getCustomName(),\n 'enabled' => $report->getStatus(),\n 'share_teams' => $this->transformGroups(team: $team, groupsIds: $report->getGroups()),\n 'share_users' => $this->transformRecipients(['users' => $explicitUserIds]),\n 'saved_search' => $this->transformSafeSearch($report->getSavedSearch()),\n 'ask_jiminny_prompt' => $this->transformAskJiminnyPrompt($report->getAskAnythingPrompt()),\n 'expires_on' => $report->getExpiresAt()?->format('Y-m-d'),\n ];\n }\n\n private function transformOrganization(?Team $team): array\n {\n return [\n 'id' => $team?->getUuid(),\n 'name' => $team?->getName(),\n ];\n }\n\n private function transformReportType(string $type): array\n {\n foreach (self::ALL_TYPES as $typeItem) {\n if ($typeItem['id'] === $type) {\n return $typeItem;\n }\n }\n\n return [];\n }\n\n private function transformCallType(array $types): array\n {\n $result = [];\n $callTypes = [self::CALL_TYPE_CONFERENCE, self::CALL_TYPE_DIALER];\n\n foreach ($types as $type) {\n foreach ($callTypes as $callTypeItem) {\n if ($callTypeItem['id'] === $type) {\n $result[] = $callTypeItem;\n\n break;\n }\n }\n }\n\n return $result;\n }\n\n private function transformMediaTypes(AutomatedReport $report): array\n {\n $values = [];\n\n foreach ($report->getMediaTypes() as $mediaType) {\n if (! in_array($mediaType, self::MEDIA_TYPES, true)) {\n continue;\n }\n\n $values[] = match ($mediaType) {\n self::MEDIA_TYPE_PDF => self::MEDIA_TYPE_OBJECT_PDF,\n self::MEDIA_TYPE_PODCAST => self::MEDIA_TYPE_OBJECT_PODCAST,\n };\n }\n\n return $values;\n }\n\n private function transformFrequency(string $frequency): array\n {\n foreach (self::ALL_FREQUENCIES as $frequencyItem) {\n if ($frequencyItem['id'] === $frequency) {\n return $frequencyItem;\n }\n }\n\n return [];\n }\n\n public function transformDurationToMinutes(?int $duration): ?int\n {\n if (! $duration) {\n return null;\n }\n\n return (int) ($duration / 60);\n }\n\n private function transformGroups(?Team $team, array $groupsIds): array\n {\n if (empty($groupsIds) || ! $team) {\n return [];\n }\n\n $data = [];\n foreach ($groupsIds as $groupId) {\n $group = $team->groups()->where('id', $groupId)->first();\n\n if ($group) {\n $data[] = [\n 'id' => $group->getUuid(),\n 'name' => $group->getName(),\n 'photoUrl' => $group->getPhotoUrl(),\n ];\n }\n }\n\n return $data;\n }\n\n private function transformStages(?Team $team, array $stagesIds): array\n {\n if (empty($stagesIds) || ! $team) {\n return [];\n }\n\n $data = [];\n foreach ($stagesIds as $stageId) {\n $stage = $team->stages()->where('id', $stageId)->first();\n\n if ($stage) {\n $data[] = [\n 'id' => $stage->getUuid(),\n 'name' => $stage->getName(),\n ];\n }\n }\n\n return $data;\n }\n\n private function transformRecipients(array $recipients): array\n {\n $users = [];\n foreach ($recipients['users'] ?? [] as $userId) {\n $users[] = $this->transformUser($userId);\n }\n\n return $users;\n }\n\n private function transformCreator(?User $user): ?array\n {\n if ($user === null) {\n return null;\n }\n\n return $this->transformUser($user->getId());\n }\n\n private function transformAskJiminnyPrompt(?AskAnythingPrompt $prompt): ?array\n {\n if ($prompt === null) {\n return null;\n }\n\n return [\n 'id' => $prompt->getUuid(),\n 'name' => $prompt->getTitle(),\n ];\n }\n\n private function transformSafeSearch(?Search $search): ?array\n {\n if ($search === null) {\n return null;\n }\n\n return [\n 'id' => $search->getUuid(),\n 'name' => $search->getName(),\n ];\n }\n\n private function transformUser(int $userId): array\n {\n /* @var ?User $user */\n $user = $this->userRepository->find($userId);\n\n return [\n 'id' => $user?->getUuid(),\n 'name' => $user?->getName(),\n 'email' => $user?->getEmailAddress(),\n 'photoUrl' => $user?->getPhotoUrl(),\n ];\n }\n\n public function create(array $data): array\n {\n $validatedData = $this->validateAndTransformData($data);\n $validatedData['created_by'] = auth()->id();\n\n $automatedReport = $this->automatedReportsRepository->create($validatedData);\n\n $this->generateOneOffReport($automatedReport);\n\n return $this->transformReportFullView($automatedReport);\n }\n\n public function update(string $uuid, array $data): array\n {\n $validatedData = $this->validateAndTransformData($data);\n $report = $this->automatedReportsRepository->findByUuid($uuid);\n\n if (! $report) {\n throw new InvalidArgumentException('Report not found');\n }\n\n $oldCustomName = $report->getCustomName();\n\n $automatedReport = $this->automatedReportsRepository->update($report, $validatedData);\n\n if ($oldCustomName !== $automatedReport->getCustomName()) {\n $this->updateResultNames($automatedReport);\n }\n\n $this->generateOneOffReport($automatedReport);\n\n return $this->transformReportFullView($automatedReport);\n }\n\n /**\n * Create an Ask Jiminny report.\n */\n public function createAskJiminnyReport(array $data, User $creator): array\n {\n $validatedData = $this->validateAskJiminnyReportData($data, $creator);\n $validatedData['created_by'] = $creator->getId();\n\n $automatedReport = $this->automatedReportsRepository->create($validatedData);\n\n return $this->transformReportFullView($automatedReport);\n }\n\n /**\n * Update an Ask Jiminny report.\n */\n public function updateAskJiminnyReport(AutomatedReport $report, array $data, User $user): array\n {\n if (! $report->isAskJiminnyReport()) {\n throw new InvalidArgumentException('Report is not an Ask Jiminny report');\n }\n\n $validatedData = $this->validateAskJiminnyReportData($data, $user);\n\n $oldCustomName = $report->getCustomName();\n\n $automatedReport = $this->automatedReportsRepository->update($report, $validatedData);\n\n if ($oldCustomName !== $automatedReport->getCustomName()) {\n $this->updateResultNames($automatedReport);\n }\n\n return $this->transformReportFullView($automatedReport);\n }\n\n public function updateAskJiminnyReportStatus(AutomatedReport $report, bool $status): array\n {\n $this->automatedReportsRepository->update($report, ['status' => $status]);\n\n return $this->transformReportFullView($report->fresh());\n }\n\n /**\n * Validate and transform data for Ask Jiminny reports.\n */\n private function validateAskJiminnyReportData(array $data, User $user): array\n {\n // Validate name\n $name = trim($data['report_name'] ?? '');\n if (empty($name)) {\n throw new InvalidArgumentException('Report name is required');\n }\n if (mb_strlen($name) > 50) {\n throw new InvalidArgumentException('Report name must be 50 characters or less');\n }\n\n // Validate frequency (only daily, weekly, monthly for Ask Jiminny)\n $frequency = $data['frequency'] ?? null;\n $askJiminnyFrequencies = [self::FREQUENCY_DAILY, self::FREQUENCY_WEEKLY, self::FREQUENCY_MONTHLY];\n if (! in_array($frequency, $askJiminnyFrequencies, true)) {\n throw new InvalidArgumentException('Frequency must be daily, weekly, or monthly');\n }\n\n // Validate expiration date\n $expiresAt = $data['expires_on'] ?? null;\n if (empty($expiresAt)) {\n throw new InvalidArgumentException('Expiration date is required');\n }\n\n try {\n $expiresAtDate = Carbon::parse($expiresAt);\n } catch (InvalidFormatException $e) {\n throw new InvalidArgumentException('Expiration date format is invalid');\n }\n $maxExpiration = Carbon::now()->addYear();\n if ($expiresAtDate->gt($maxExpiration)) {\n throw new InvalidArgumentException('Expiration date cannot be more than 1 year from now');\n }\n if ($expiresAtDate->isPast()) {\n throw new InvalidArgumentException('Expiration date cannot be in the past');\n }\n\n // Validate saved search\n $activitySearchId = $data['saved_search'] ?? null;\n if (empty($activitySearchId)) {\n throw new InvalidArgumentException('Saved search is required');\n }\n $savedSearch = $this->activitySearchRepository->findByUuidAndUser($activitySearchId, $user);\n if (! $savedSearch) {\n throw new InvalidArgumentException('Saved search not found or does not belong to you');\n }\n\n // Validate saved prompt\n $askAnythingPromptId = $data['ask_jiminny_prompt'] ?? null;\n if (empty($askAnythingPromptId)) {\n throw new InvalidArgumentException('Ask Jiminny prompt is required');\n }\n $prompt = $this->askAnythingRepository->getPromptByUuid($askAnythingPromptId);\n if (! $prompt) {\n throw new InvalidArgumentException('Ask Jiminny prompt not found');\n }\n\n // Validate status\n $status = $data['enabled'] ?? false;\n\n $recipientUserIds = [$user->getId()];\n\n if (! empty($data['share_users'])) {\n $sharedUserIds = $this->validateAndGetUserIdsByTeam(\n $user->team,\n (array) $data['share_users']\n );\n $recipientUserIds = array_merge($recipientUserIds, $sharedUserIds);\n }\n\n $sharedGroupIds = [];\n if (! empty($data['share_teams'])) {\n $sharedGroupIds = $this->validateAndGetGroupIds($user->team, (array) $data['share_teams']);\n }\n\n $recipientUserIds = array_values(array_unique($recipientUserIds));\n\n return [\n 'team_id' => $user->getTeamId(),\n 'type' => self::TYPE_ASK_JIMINNY,\n 'status' => (bool) $status,\n 'frequency' => $frequency,\n 'custom_name' => $name,\n 'activity_search_id' => $savedSearch->getId(),\n 'ask_anything_prompt_id' => $prompt->getId(),\n 'expires_at' => $expiresAtDate->toDateString(),\n 'media_types' => [self::MEDIA_TYPE_PDF],\n 'call_types' => [],\n 'recipients' => ['users' => $recipientUserIds],\n 'groups' => $sharedGroupIds,\n ];\n }\n\n public static function getAskJiminnyFrequencies(): array\n {\n return array_map(static function ($frequency) {\n return $frequency['id'];\n }, self::ASK_JIMINNY_FREQUENCIES);\n }\n\n public function getAskJiminnyReportFilters(User $user): array\n {\n $savedSearches = $this->activitySearchRepository->findByUserOrderedByName($user)\n ->map(fn (Search $search) => [\n 'id' => $search->getUuid(),\n 'name' => $search->getName(),\n ])\n ->values()->all();\n\n $prompts = collect(\n $this->askAnythingPromptService->get($user, AskAnythingPromptTarget::on_demand)\n )->map(fn (AskAnythingPromptDto $prompt) => [\n 'id' => $prompt->id,\n 'name' => $prompt->title,\n ])->values()->all();\n\n return [\n [\n 'id' => 'prompt',\n 'label' => 'Prompt',\n 'options' => $prompts,\n ],\n [\n 'id' => 'saved_search',\n 'label' => 'Saved Search',\n 'options' => $savedSearches,\n ],\n ];\n }\n\n public function getAskJiminnyReportFormData(User $user, ?AutomatedReport $report = null): array\n {\n $team = $user->getTeam();\n $userTimezone = $user->getTimezone();\n\n $savedSearches = $this->activitySearchRepository->findByUserOrderedByName($user)\n ->map(fn (Search $search) => [\n 'id' => $search->getUuid(),\n 'name' => $search->getName(),\n ])\n ->values()->all();\n\n $prompts = collect(\n $this->askAnythingPromptService->get($user, AskAnythingPromptTarget::on_demand)\n )->map(fn (AskAnythingPromptDto $prompt) => [\n 'id' => $prompt->id,\n 'name' => $prompt->title,\n ])->values()->all();\n\n $teamGroups = $this->groupRepository->getAllByTeam($team)->map(fn ($group) => [\n 'id' => $group->getUuid(),\n 'name' => $group->getName(),\n ])->values()->all();\n\n $shareUsers = $this->recipientsService->getRecipientsFieldData(team: $team)['options'] ?? [];\n\n $sharedTeamsValue = [];\n $sharedUsersValue = [];\n if ($report) {\n $sharedTeamsValue = $this->transformGroups($team, $report->getGroups());\n\n $recipientUserIds = $report->getRecipients()['users'] ?? [];\n $creatorId = $report->getAttribute('created_by');\n $sharedUserIds = array_values(array_filter(\n $recipientUserIds,\n static fn ($id) => $id !== $creatorId\n ));\n $sharedUsersValue = collect($sharedUserIds)\n ->map(fn ($id) => $this->userRepository->find((int) $id))\n ->filter()\n ->map(fn (User $u) => [\n 'id' => $u->getUuid(),\n 'name' => $u->getName(),\n ])\n ->values()\n ->all();\n }\n\n return [\n 'fields' => [\n [\n 'id' => 'enabled',\n 'inputType' => InputTypeEnum::TOGGLE,\n 'label' => '',\n 'value' => $report?->getStatus() ?? false,\n ],\n [\n 'id' => 'report_name',\n 'inputType' => InputTypeEnum::TEXT,\n 'label' => 'Name',\n 'placeholder' => 'Enter name',\n 'required' => true,\n 'validation' => ['maxLength' => 50],\n 'value' => $report?->getCustomName() ?? '',\n ],\n [\n 'id' => 'frequency',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'label' => 'Frequency',\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => self::ASK_JIMINNY_FREQUENCIES,\n 'value' => $report ? $this->transformFrequency($report->getFrequency()) : null,\n ],\n [\n 'id' => 'expires_on',\n 'inputType' => InputTypeEnum::DATE,\n 'label' => 'Expires on',\n 'required' => true,\n 'placeholder' => 'Select',\n 'validation' => [\n 'minDate' => now($userTimezone)->toDateString(),\n 'maxDate' => now($userTimezone)->addYear()->toDateString(),\n ],\n 'value' => $report?->getExpiresAt()?->toDateString(),\n ],\n [\n 'id' => 'share_teams',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'label' => 'Team',\n 'required' => false,\n 'placeholder' => 'Select',\n 'options' => $teamGroups,\n 'value' => $sharedTeamsValue,\n ],\n [\n 'id' => 'share_users',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'label' => 'Team member',\n 'required' => false,\n 'placeholder' => 'Select',\n 'groupLabelKey' => 'label',\n 'groupValuesKey' => 'users',\n 'optionLabelKey' => 'name',\n 'optionValueKey' => 'id',\n 'options' => $shareUsers,\n 'value' => $sharedUsersValue,\n ],\n [\n 'id' => 'saved_search',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'label' => 'Saved search',\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => $savedSearches,\n 'value' => $report && $report->getSavedSearch() ? [\n 'id' => $report->getSavedSearch()->getUuid(),\n 'name' => $report->getSavedSearch()->getName(),\n ] : null,\n ],\n [\n 'id' => 'ask_jiminny_prompt',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'label' => 'Ask Jiminny prompt',\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => $prompts,\n 'value' => $report && $report->getAskAnythingPrompt() ? [\n 'id' => $report->getAskAnythingPrompt()->getUuid(),\n 'name' => $report->getAskAnythingPrompt()->getTitle(),\n ] : null,\n ],\n ],\n ];\n }\n\n private function updateResultNames(AutomatedReport $automatedReport): void\n {\n $results = $this->automatedReportsRepository->getResultsByReport($automatedReport);\n\n foreach ($results as $result) {\n $result->update(['name' => $this->getReportFileName($result)]);\n }\n }\n\n public function updateStatus(string $uuid, array $data): array\n {\n $automatedReport = $this->automatedReportsRepository->findByUuid($uuid);\n\n if (! $automatedReport) {\n throw new ModelNotFoundException('Report not found');\n }\n\n $status = $this->validateReportStatus($data['report_enabled'] ?? null);\n $automatedReport->update([\n 'status' => $status,\n ]);\n\n $this->generateOneOffReport($automatedReport);\n\n return $this->transformReportFullView($automatedReport);\n }\n\n private function generateOneOffReport(AutomatedReport $automatedReport): void\n {\n // the scheduler handles all the other frequency types\n if ($automatedReport->getStatus() === false || $automatedReport->getFrequency() !== self::FREQUENCY_ONE_OFF) {\n return;\n }\n\n $this->dispatcher->dispatch(new RequestGenerateReportJob($automatedReport->getUuid()));\n }\n\n public function getReport(string $uuid): AutomatedReport\n {\n $automatedReport = $this->automatedReportsRepository->findByUuid($uuid);\n\n if (! $automatedReport) {\n throw new ModelNotFoundException('Report not found');\n }\n\n return $automatedReport;\n }\n\n public function get(string $uuid): array\n {\n $automatedReport = $this->getReport($uuid);\n\n return $this->transformReportFullView($automatedReport);\n }\n\n public function list(string $sortColumn = 'created_at', string $sortDirection = 'desc'): array\n {\n $results = [];\n $collection = $this->automatedReportsRepository->getAllStandardReports($sortColumn, $sortDirection);\n\n /** @var AutomatedReport $report */\n foreach ($collection as $report) {\n $results[] = $this->transformReportFullView($report);\n }\n\n return ['data' => $results];\n }\n\n public function listAskJiminnyReports(\n User $user,\n string $sortColumn = 'created_at',\n string $sortDirection = 'desc'\n ): array {\n $results = [];\n $collection = $this->automatedReportsRepository->getAskJiminnyReportsByUser($user, $sortColumn, $sortDirection);\n\n /** @var AutomatedReport $report */\n foreach ($collection as $report) {\n $results[] = $this->transformReportFullView($report);\n }\n\n return ['data' => $results];\n }\n\n public function delete(string $uuid): void\n {\n $automatedReport = $this->automatedReportsRepository->findByUuid($uuid);\n\n if (! $automatedReport) {\n throw new ModelNotFoundException('Report not found');\n }\n\n $automatedReport->delete();\n }\n\n public function createReportResult(AutomatedReport $automatedReport, array $data = []): AutomatedReportResult\n {\n return $this->automatedReportsRepository->createResult(\n array_merge(\n [\n 'report_id' => $automatedReport->getId(),\n 'status' => AutomatedReportResult::STATUS_DEFAULT,\n ],\n $data\n )\n );\n }\n\n public function getReportResult(string $resultUuid): AutomatedReportResult\n {\n $report = $this->automatedReportsRepository->findResultByUuid($resultUuid);\n\n if (! $report) {\n throw new ModelNotFoundException('Report Result not found');\n }\n\n return $report;\n }\n\n public function findChildResult(AutomatedReportResult $result, string $type): ?AutomatedReportResult\n {\n return $this->automatedReportsRepository->findChildResult($result, $type);\n }\n\n // prophet API calls\n /**\n * @throws ApplicationException\n */\n public function getGenerateReportPayload(AutomatedReport $automatedReport, string $reportResultUuid): array\n {\n $period = $this->calculateFromAndToDate($automatedReport);\n $fromDate = $period['fromDate'];\n $toDate = $period['toDate'];\n\n return [\n 'team_id' => $automatedReport->getTeamId(),\n 'request_id' => $reportResultUuid,\n 'report_type' => $automatedReport->getType(),\n 'media_types' => $automatedReport->getMediaTypes(),\n 'from_date' => $fromDate->startOfDay()->format(DateTimeInterface::RFC3339),\n 'to_date' => $toDate->endOfDay()->format(DateTimeInterface::RFC3339),\n 'group_ids' => $automatedReport->getGroups(),\n 'call_deal_stage' => $automatedReport->getDealAtCallStages(),\n 'current_deal_stage' => $automatedReport->getCurrentDealStages(),\n 'deal_min_value' => $automatedReport->getDealValueMin(),\n 'deal_max_value' => $automatedReport->getDealValueMax(),\n 'call_types' => $automatedReport->getCallTypes(),\n 'call_duration_min_seconds' => $automatedReport->getCallDurationMin(),\n 'call_duration_max_seconds' => $automatedReport->getCallDurationMax(),\n 'special_requirements' => $automatedReport->getAdditionalPromptInput(),\n 'callback_url' => $this->getCallbackUrl(),\n 'report_period' => $this->formatReportPeriodName(\n $automatedReport->getFrequency(),\n $fromDate,\n $toDate,\n ),\n 'playbook_categories' => $automatedReport->getPlaybookCategories(),\n 'custom_name' => $automatedReport->getCustomName(),\n ];\n }\n\n // $inputPayload - FE payload structure\n public function getActivitiesCountPayload(array $inputPayload): array\n {\n // Use validateAndTransformData to validate and normalize input\n $validatedData = $this->validateAndTransformData($inputPayload);\n $period = $this->calculateFromAndToDatePeriod(\n $validatedData['frequency'],\n Carbon::parse($validatedData['from']),\n Carbon::parse($validatedData['to']),\n );\n $fromDate = $period['fromDate'];\n $toDate = $period['toDate'];\n\n // Create payload similar to getGenerateReportPayload\n return [\n 'team_id' => $validatedData['team_id'],\n 'group_ids' => $validatedData['groups'] ?? [],\n 'report_type' => $validatedData['type'],\n 'from_date' => $fromDate->format(DateTimeInterface::RFC3339),\n 'to_date' => $toDate->format(DateTimeInterface::RFC3339),\n 'call_deal_stage' => $validatedData['deal_at_call_stages'] ?? [],\n 'current_deal_stage' => $validatedData['current_deal_stages'] ?? [],\n 'deal_min_value' => $validatedData['deal_value_min'] ?? null,\n 'deal_max_value' => $validatedData['deal_value_max'] ?? null,\n 'call_types' => $validatedData['call_types'],\n 'call_duration_min_seconds' => $validatedData['call_duration_min'] ?? null,\n 'call_duration_max_seconds' => $validatedData['call_duration_max'] ?? null,\n 'special_requirements' => $validatedData['additional_prompt_input'] ?? null,\n 'playbook_categories' => $validatedData['playbook_categories'] ?? [],\n 'request_id' => null,\n 'callback_url' => null,\n ];\n }\n\n public function shouldSendReport(array $users, ?CarbonInterface $generatedAt = null): bool\n {\n if (empty($users)) {\n return false;\n }\n\n $earliestTz = collect($users)\n ->mapWithKeys(function (array $user) {\n $tz = new DateTimeZone($user['timezone']);\n $nowUtc = new DateTime('now', new DateTimeZone('UTC'));\n $offset = $tz->getOffset($nowUtc);\n\n return [$user['timezone'] => $offset];\n })\n ->sortDesc()\n ->keys()\n ->first();\n\n $now = Carbon::now($earliestTz);\n $isScheduledTime = (int) $now->format('H') === self::SENT_REPORT_AT_HOURS;\n\n if ($isScheduledTime) {\n return true;\n }\n\n return $this->hasPassedScheduledTime($generatedAt, $earliestTz);\n }\n\n public function hasPassedScheduledTime(?CarbonInterface $generatedAt, string $timezone): bool\n {\n if ($generatedAt === null) {\n return false;\n }\n\n $now = Carbon::now($timezone);\n $scheduledTime = $now->copy()->setTime(self::SENT_REPORT_AT_HOURS, 0, 0);\n\n if ($now->hour < self::SENT_REPORT_AT_HOURS) {\n $scheduledTime = $scheduledTime->subDay();\n }\n\n $scheduledTimeUtc = $scheduledTime->copy()->utc();\n $generatedAtUtc = $generatedAt->copy()->utc();\n $nowUtc = $now->copy()->utc();\n\n return $generatedAtUtc->lt($scheduledTimeUtc) && $nowUtc->gt($scheduledTimeUtc);\n }\n\n public function calculateFromAndToDatePeriod(\n string $frequency,\n ?Carbon $fromDate = null,\n ?Carbon $toDate = null\n ): array {\n if ($frequency === self::FREQUENCY_ONE_OFF) {\n return [\n 'fromDate' => $fromDate,\n 'toDate' => $toDate,\n ];\n }\n\n $now = Carbon::now();\n\n return match ($frequency) {\n self::FREQUENCY_DAILY => [\n 'fromDate' => $now->copy()->subDay()->startOfDay(),\n 'toDate' => $now->copy()->subDay()->endOfDay(),\n ],\n self::FREQUENCY_WEEKLY => [\n 'fromDate' => $now->copy()->subWeeks(1)->startOfDay(),\n 'toDate' => $now->copy()->subDay()->endOfDay(),\n ],\n self::FREQUENCY_MONTHLY => [\n 'fromDate' => $now->copy()->subMonths(1)->startOfDay(),\n 'toDate' => $now->copy()->subDay()->endOfDay(),\n ],\n self::FREQUENCY_QUARTERLY => [\n 'fromDate' => $now->copy()->subMonths(3)->startOfDay(),\n 'toDate' => $now->copy()->subDay()->endOfDay(),\n ],\n default => throw new InvalidArgumentException(\"Unsupported frequency: {$frequency}\"),\n };\n }\n\n private function calculateFromAndToDate(AutomatedReport $automatedReport): array\n {\n return $this->calculateFromAndToDatePeriod(\n $automatedReport->getFrequency(),\n $automatedReport->getFrom(),\n $automatedReport->getTo()\n );\n }\n\n public function getAskJiminnyGenerateReportPayload(\n AutomatedReport $automatedReport,\n AutomatedReportResult $reportResult,\n array $activityIds,\n ): array {\n return [\n 'user_question' => $automatedReport->getAskAnythingPrompt()?->getContent(),\n 'call_ids' => array_map('strval', $activityIds),\n 'team_id' => $automatedReport->getTeamId(),\n 'request_id' => $reportResult->getUuid(),\n 'callback_url' => $this->getCallbackUrl(),\n 'report_period' => $this->getReportPeriodName($reportResult),\n 'report_name' => $automatedReport->getCustomName(),\n ];\n }\n\n private function getCallbackUrl(): string\n {\n return $this->webhookService->route('jiminny.webhook.reports.ready');\n }\n\n /**\n * Validate and transform payload data for automated reports\n *\n * @param array $data\n *\n * @throws InvalidArgumentException\n *\n * @return array\n */\n private function validateAndTransformData(array $data): array\n {\n // Validate organization (team) and check feature\n $team = $this->validateOrganization($data['organization'] ?? null);\n\n $status = $this->validateReportStatus($data['report_enabled'] ?? null);\n $type = $this->validateReportType($data['report_type'] ?? null);\n $frequency = $this->validateFrequency($data['frequency'] ?? null);\n $additionalPromptInput = $this->validateAdditionalPromptInput(\n $data['additional_prompt_input'] ?? null\n );\n $customReportName = $this->validateCustomReportName($data['custom_name'] ?? null);\n\n // Prepare data for the database\n $reportData = [\n 'team_id' => $team->getId(),\n 'type' => $type,\n 'status' => $status,\n 'frequency' => $frequency,\n 'additional_prompt_input' => $additionalPromptInput,\n 'custom_name' => $customReportName,\n ];\n\n // Validate deal values\n $reportData = $this->validateDealValues($data, $reportData);\n\n // Validate date range\n $reportData = $this->validateDateRange($data, $reportData, $frequency);\n\n // Validate call durations\n $reportData = $this->validateCallDurations($data, $reportData);\n\n // Validate call types\n $reportData = $this->validateCallTypes($data, $reportData);\n\n // Validate media types\n $reportData = $this->validateMediaTypes($data, $reportData);\n\n // Validate groups\n if (isset($data['teams'])) {\n $reportData['groups'] = $this->validateAndGetGroupIds($team, $data['teams']);\n }\n\n // Validate deal stages\n $reportData = $this->validateDealStages($data, $reportData, $team, $type);\n\n // Validate playbook categories\n $reportData = $this->validatePlaybookCategories($data, $reportData, $team);\n\n // Validate recipients\n $reportData['recipients'] = [\n 'users' => $this->validateAndGetUserIdsByTeam($team, $data['recipients'] ?? []),\n ];\n\n if (isset($data['jiminny_recipients'])) {\n // Validate Jiminny recipients\n $reportData['jiminny_recipients'] = [\n 'users' => $this->validateAndGetJiminnyUserIds((array) $data['jiminny_recipients']),\n ];\n }\n\n return $reportData;\n }\n\n private function validateDealValues(array $data, array $reportData): array\n {\n if (isset($data['min_deal_value'])) {\n $reportData['deal_value_min'] = (int) $data['min_deal_value'];\n\n if ($reportData['deal_value_min'] > 4294967295 || $reportData['deal_value_min'] < 0) {\n throw new InvalidArgumentException('Min deal value should be between 0 and 4294967295');\n }\n }\n\n if (isset($data['max_deal_value'])) {\n $reportData['deal_value_max'] = (int) $data['max_deal_value'];\n\n if ($reportData['deal_value_max'] > 4294967295 || $reportData['deal_value_max'] < 0) {\n throw new InvalidArgumentException('Max deal value should be between 0 and 4294967295');\n }\n }\n\n if (isset($data['min_deal_value'], $data['max_deal_value'])\n && $data['min_deal_value'] > $data['max_deal_value']\n ) {\n throw new InvalidArgumentException('Min deal value cannot be greater than max deal value');\n }\n\n return $reportData;\n }\n\n private function validateDateRange(array $data, array $reportData, string $frequency): array\n {\n // Set date range only for one_off frequency\n if ($frequency === 'one_off') {\n if (isset($data['start_date_period'])) {\n $reportData['from'] = $this->parseDate($data['start_date_period']);\n }\n\n if (isset($data['end_date_period'])) {\n $reportData['to'] = $this->parseDate($data['end_date_period']);\n }\n\n if (empty($reportData['from']) || empty($reportData['to'])) {\n throw new InvalidArgumentException(\n 'Start date and end date are required for one_off frequency'\n );\n }\n } else {\n $reportData['from'] = null;\n $reportData['to'] = null;\n }\n\n return $reportData;\n }\n\n private function validateCallDurations(array $data, array $reportData): array\n {\n // Convert call durations from minutes to seconds\n if (isset($data['min_call_duration'])) {\n $reportData['call_duration_min'] = (int) $data['min_call_duration'] * 60;\n\n if ($reportData['call_duration_min'] > 4294967295 || $reportData['call_duration_min'] < 0) {\n throw new InvalidArgumentException('Min call duration should be between 0 and 4294967295');\n }\n }\n\n if (isset($data['max_call_duration'])) {\n $reportData['call_duration_max'] = (int) $data['max_call_duration'] * 60;\n\n if ($reportData['call_duration_max'] > 4294967295 || $reportData['call_duration_max'] < 0) {\n throw new InvalidArgumentException('Max call duration should be between 0 and 4294967295');\n }\n }\n\n return $reportData;\n }\n\n private function validateCallTypes(array $data, array $reportData): array\n {\n // Set call types\n $reportData['call_types'] = $data['call_type'] ?? [];\n if (empty($reportData['call_types'])) {\n $reportData['call_types'] = self::getCallTypes();\n }\n\n foreach ($reportData['call_types'] as $callType) {\n if (! in_array($callType, self::getCallTypes(), true)) {\n throw new InvalidArgumentException(sprintf('Call type %s is invalid', $callType));\n }\n }\n\n return $reportData;\n }\n\n private function validateMediaTypes(array $data, array $reportData): array\n {\n // Set media types from input data\n $reportData['media_types'] = $data['media_types'] ?? [];\n\n if (empty($reportData['media_types'])) {\n throw new InvalidArgumentException('Media types are required');\n }\n\n foreach ($reportData['media_types'] as $mediaType) {\n if (! in_array($mediaType, self::MEDIA_TYPES, true)) {\n throw new InvalidArgumentException(sprintf('Media type %s is invalid', $mediaType));\n }\n }\n\n return $reportData;\n }\n\n private function validateDealStages(array $data, array $reportData, Team $team, string $reportType): array\n {\n // Validate and set deal stages\n if (isset($data['deal_stage_at_call'])) {\n $reportData['deal_at_call_stages'] =\n $this->validateAndGetDealStageIds($team, $data['deal_stage_at_call'], 'Deal stage at call');\n }\n\n if (isset($data['current_deal_stage'])) {\n $reportData['current_deal_stages'] =\n $this->validateAndGetDealStageIds($team, $data['current_deal_stage'], 'Current deal stage');\n }\n\n // Ensure current_deal_stage is not provided for loss_analysis report type\n if ($reportType === self::TYPE_LOSS_ANALYSIS && ! empty($data['current_deal_stage'])) {\n throw new InvalidArgumentException('Current deal stage is not applicable for Loss Analysis reports');\n }\n\n return $reportData;\n }\n\n // transform uuid to id\n private function validatePlaybookCategories(array $data, array $reportData, Team $team): array\n {\n $key = 'playbook_categories';\n\n if (isset($data[$key])) {\n $payloadIds = $data[$key];\n $ids = [];\n\n foreach ($payloadIds as $uuid) {\n $uuid = (string) $uuid;\n\n try {\n $playbookCategory = $this->playbookCategoryRepository->findByUuid($uuid);\n } catch (Throwable $throwable) {\n Log::error(__METHOD__ . ' ' . $throwable->getMessage());\n\n throw new InvalidArgumentException(sprintf('Playbook category %s not found', $uuid));\n }\n\n if (! $playbookCategory) {\n throw new InvalidArgumentException(sprintf('Playbook category %s not found', $uuid));\n }\n\n if (! $playbookCategory->hasPlaybook()) {\n throw new InvalidArgumentException(sprintf('Playbook category %s has no playbook', $uuid));\n }\n\n if ($playbookCategory->getPlaybook()->getTeamId() !== $team->getId()) {\n throw new InvalidArgumentException(\n sprintf('Playbook category %s not found for team %s', $uuid, $team->getUuid())\n );\n }\n\n $ids[] = $playbookCategory->getId();\n }\n\n $reportData[$key] = $ids;\n }\n\n return $reportData;\n }\n\n private function validateReportStatus($status): bool\n {\n if (! in_array($status, [true, false], true)) {\n throw new InvalidArgumentException('Report status is invalid');\n }\n\n return $status;\n }\n\n private function validateReportType($type): string\n {\n if (! in_array($type, self::getTypes(), true)) {\n throw new InvalidArgumentException(sprintf('Report type is invalid: %s', $type));\n }\n\n return $type;\n }\n\n private function validateFrequency($frequency): string\n {\n if (! in_array($frequency, self::getFrequencies(), true)) {\n throw new InvalidArgumentException('Frequency is invalid');\n }\n\n return $frequency;\n }\n\n private function validateAdditionalPromptInput(?string $additionalPromptInput): ?string\n {\n if ($additionalPromptInput && strlen($additionalPromptInput) > 5000) {\n throw new InvalidArgumentException('Additional Prompt Input should be less than 5000 characters');\n }\n\n return $additionalPromptInput;\n }\n\n private function validateCustomReportName(?string $customReportName): ?string\n {\n if ($customReportName === null || $customReportName === '') {\n return null;\n }\n\n if (strlen($customReportName) > 70) {\n throw new InvalidArgumentException('Custom report name should be less than 70 characters');\n }\n\n return $customReportName;\n }\n\n private function validateOrganization(?string $organizationUuid): Team\n {\n if (! $organizationUuid) {\n throw new InvalidArgumentException('Organization is required');\n }\n\n $team = $this->teamRepository->idOrUuid($organizationUuid);\n\n if (! $team) {\n throw new InvalidArgumentException('Organization not found');\n }\n\n if (! $team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {\n throw new InvalidArgumentException('Organization does not have the Automated Reports feature');\n }\n\n return $team;\n }\n\n private function validateAndGetGroupIds(Team $team, array $teamUuids): array\n {\n $groupIds = [];\n\n foreach ($teamUuids as $uuid) {\n $group = $this->groupRepository->findByUuid($uuid);\n\n if ($group === null || $group->getTeamId() !== $team->getId()) {\n throw new InvalidArgumentException(\n sprintf('Group %s not found for team %s', $uuid, $team->getUuid())\n );\n }\n\n $groupIds[] = $group->getId();\n\n }\n\n return $groupIds;\n }\n\n private function validateAndGetDealStageIds(Team $team, array $stageUuids, string $propertyLabel): array\n {\n $stageIds = [];\n\n foreach ($stageUuids as $uuid) {\n $stage = $this->stageRepository->findByUuid($uuid);\n\n if ($stage === null || $stage->getTeamId() !== $team->getId()) {\n throw new InvalidArgumentException(\n sprintf('Stage %s not found for team %s for %s', $uuid, $team->getUuid(), $propertyLabel)\n );\n }\n\n $stageIds[] = $stage->getId();\n }\n\n return $stageIds;\n }\n\n private function validateAndGetUserIds(array $userUuids, callable $teamCheck): array\n {\n if (empty($userUuids)) {\n return [];\n }\n\n $userIds = [];\n\n foreach ($userUuids as $uuid) {\n $user = $this->userRepository->findByUuid($uuid);\n\n if (! $user || ! $user->isStatusActive()) {\n throw new InvalidArgumentException(\n sprintf('User %s not found or is not active', $uuid)\n );\n }\n\n if (! $teamCheck($user)) {\n throw new InvalidArgumentException(\n sprintf('User %s does not belong to the allowed team(s)', $uuid)\n );\n }\n\n $userIds[] = $user->getId();\n }\n\n return $userIds;\n }\n\n private function validateAndGetUserIdsByTeam(Team $team, array $userUuids): array\n {\n return $this->validateAndGetUserIds($userUuids, fn ($user) => $user->getTeamId() === $team->getId());\n }\n\n private function validateAndGetJiminnyUserIds(array $userUuids): array\n {\n $allowedTeamIds = config('kiosk.teamIds', []);\n\n return $this->validateAndGetUserIds($userUuids, fn ($user) => in_array($user->getTeamId(), $allowedTeamIds, true));\n }\n\n private function parseDate(string $dateString): string\n {\n return date('Y-m-d H:i:s', strtotime($dateString));\n }\n\n private function generateReportResultViewUrl(AutomatedReportResult $result): string\n {\n $mediaResource = $this->getReportMediaRouteResource($result);\n\n return route('ai-reports.' . $mediaResource . '.view', ['uuid' => $result->getUuid()]);\n }\n\n private function generateReportResultDownloadUrl(AutomatedReportResult $result): string\n {\n $mediaResource = $this->getReportMediaRouteResource($result);\n\n return route('ai-reports.' . $mediaResource . '.download', ['uuid' => $result->getUuid()]);\n }\n\n private function getReportMediaRouteResource(AutomatedReportResult $result): string\n {\n if ($result->getMediaType() === self::MEDIA_TYPE_PDF) {\n return self::PDF_KEY;\n } elseif ($result->getMediaType() === self::MEDIA_TYPE_PODCAST) {\n return self::AUDIO_KEY;\n }\n\n throw new \\InvalidArgumentException('Unknown media type.');\n }\n\n public function getMediaPath(AutomatedReportResult $result): ?string\n {\n $url = match ($result->getMediaType()) {\n self::MEDIA_TYPE_PDF => $result->getPdfUrl(),\n self::MEDIA_TYPE_PODCAST => $result->getPodcastAudioUrl(),\n default => null,\n };\n\n if ($url === null) {\n return null;\n }\n\n $path = parse_url(trim($url, '\"\\''), PHP_URL_PATH);\n\n return $path ?: null;\n }\n\n public function getFilenameSuffix(AutomatedReportResult $result): ?string\n {\n return match ($result->getMediaType()) {\n self::MEDIA_TYPE_PODCAST => 'Podcast',\n default => null,\n };\n }\n\n public function getMailSubjectSuffix(AutomatedReportResult $result): string\n {\n return match ($result->getMediaType()) {\n self::MEDIA_TYPE_PDF => 'report',\n self::MEDIA_TYPE_PODCAST => 'podcast',\n default => '',\n };\n }\n\n public function getMediaTypeMetadata(AutomatedReportResult $result): array\n {\n return match ($result->getMediaType()) {\n self::MEDIA_TYPE_PODCAST => ['extension' => 'mp3', 'mime' => 'audio/mpeg'],\n self::MEDIA_TYPE_PDF => ['extension' => 'pdf', 'mime' => 'application/pdf'],\n default => ['extension' => null, 'mime' => null],\n };\n }\n\n public function deleteS3Files(AutomatedReportResult $result): void\n {\n $teamUuid = $result->getReport()->getTeam()->getUuid();\n $reportUuid = $result->getUuid();\n\n // delete all files for a report uuid no mather of pdf, podcast, or both\n // in case of both - the podcast files are linked to the pdf (parent) uuid\n // pdf and podcast date times should be close\n $path = sprintf('%s/%s/%s', $teamUuid, self::S3_DIR, $reportUuid);\n\n foreach (self::FILE_EXTENSIONS_VARIANTS as $extension) {\n $file = $path . '.' . $extension;\n\n if (Storage::exists($file)) {\n Storage::delete($file);\n Log::info('[Reports] Deleted S3 file', [\n 'path' => $file,\n ]);\n }\n }\n\n foreach (self::FILE_PODCAST_EXTENSIONS_VARIANTS as $extension) {\n $file = $path . '_podcast.' . $extension;\n\n if (Storage::exists($file)) {\n Storage::delete($file);\n Log::info('[Reports] Deleted Podcast S3 file', [\n 'path' => $file,\n ]);\n }\n }\n }\n\n /**\n *\n * @param int|null $teamId Optional team ID to filter results\n *\n * @return Collection<int, int> Collection of team IDs\n */\n public function getTeamIdsWithReportsResults(?int $teamId = null): Collection\n {\n return $this->automatedReportsRepository->getTeamIdsWithReportsResults($teamId);\n }\n\n /**\n * Core delete logic for report results using a query\n *\n * @param Builder $query\n * @param array $logContext\n *\n * @return int\n */\n private function deleteReportResultsByQuery(Builder $query, array $logContext = []): int\n {\n $deletedCount = 0;\n\n if ($query->exists()) {\n Log::info(\n 'Run delete report results',\n array_merge(\n $logContext,\n [\n 'service' => 'AutomatedReportsService',\n ]\n )\n );\n\n $query->chunkById(50, function ($results) use (&$deletedCount, $logContext) {\n foreach ($results as $result) {\n $this->deleteReportResult($result);\n $deletedCount++;\n\n Log::info(\n 'Deleted a report result',\n array_merge(\n $logContext,\n [\n 'result_id' => $result->getId(),\n 'report_id' => $result->getReportId(),\n ]\n )\n );\n }\n });\n }\n\n return $deletedCount;\n }\n\n /**\n * Delete report results for a team by retention period\n *\n * @param Team $team\n * @param CarbonImmutable $retentionDate\n *\n * @return int Number of deleted report results\n */\n public function deleteReportsResultsInRetentionPeriod(Team $team, CarbonImmutable $retentionDate): int\n {\n $reportIds = $this->automatedReportsRepository->getReportIdsByTeam($team);\n\n if ($reportIds->isEmpty()) {\n return 0;\n }\n\n $query = $this->automatedReportsRepository\n ->getReportResultsQueryForRetention($team, $retentionDate);\n\n return $this->deleteReportResultsByQuery($query, [\n 'team_id' => $team->getId(),\n 'retention_date' => $retentionDate->toDateTimeString(),\n ]);\n }\n\n /**\n * Delete ALL report results for a specific automated report\n *\n * @param string $uuid\n *\n * @return int\n */\n public function deleteReportResults(string $uuid): int\n {\n $report = $this->getReport($uuid);\n\n $query = $this->automatedReportsRepository->getResultsByReportQuery($report);\n\n return $this->deleteReportResultsByQuery($query, [\n 'report_uuid' => $uuid,\n 'report_id' => $report->getId(),\n ]);\n }\n\n public function deleteReportResult(AutomatedReportResult $result): void\n {\n $this->deleteS3Files($result);\n\n $result->delete();\n }\n\n /**\n * Get all reports for a specific team\n *\n * @param Team $team\n *\n * @return \\Illuminate\\Database\\Eloquent\\Collection\n */\n public function getTeamReports(Team $team): \\Illuminate\\Database\\Eloquent\\Collection\n {\n return $this->automatedReportsRepository->getReportsByTeam($team);\n }\n\n /**\n * Get all report results for a specific report\n *\n * @param AutomatedReport $report\n *\n * @return \\Illuminate\\Database\\Eloquent\\Collection\n */\n public function getReportResults(AutomatedReport $report): \\Illuminate\\Database\\Eloquent\\Collection\n {\n return $this->automatedReportsRepository->getResultsByReport($report);\n }\n\n public function deleteAllReportResults(AutomatedReport $report): void\n {\n $results = $this->getReportResults($report);\n\n /** @var AutomatedReportResult $result */\n foreach ($results as $result) {\n Log::info('Deleting result', [\n 'report' => $report->getId(),\n 'result' => $result->getId(),\n ]);\n\n $this->deleteReportResult($result);\n }\n }\n\n public function deleteAllData(Team $team): void\n {\n Log::info('Deleting automated report and results for team', [\n 'team' => $team->getId(),\n ]);\n\n $reports = $this->getTeamReports($team);\n\n /** @var AutomatedReport $report */\n foreach ($reports as $report) {\n Log::info('Deleting report', [\n 'team' => $team->getId(),\n 'report' => $report->getId(),\n ]);\n\n $this->deleteAllReportResults($report);\n\n $report->delete();\n }\n }\n}","depth":4,"value":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Services\\Kiosk\\AutomatedReports;\n\nuse Carbon\\CarbonImmutable;\nuse Carbon\\CarbonInterface;\nuse Carbon\\Exceptions\\InvalidFormatException;\nuse DateTime;\nuse DateTimeInterface;\nuse DateTimeZone;\nuse Illuminate\\Contracts\\Bus\\Dispatcher as BusDispatcher;\nuse Illuminate\\Database\\Eloquent\\Builder;\nuse Illuminate\\Support\\Carbon;\nuse Illuminate\\Support\\Collection;\nuse Illuminate\\Support\\Facades\\Log;\nuse Illuminate\\Support\\Facades\\Storage;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinition\\InputTypeEnum;\nuse Jiminny\\Component\\AskAnything\\AskAnythingPromptService;\nuse Jiminny\\Component\\AskAnything\\Dtos\\AskAnythingPromptDto;\nuse Jiminny\\Component\\UrlGenerator\\Webhook;\nuse Jiminny\\Contracts\\Repositories\\PlaybookCategoryRepository;\nuse Jiminny\\Contracts\\Repositories\\TeamRepository;\nuse Jiminny\\Contracts\\Repositories\\UserRepository;\nuse Jiminny\\Exceptions\\ApplicationException;\nuse Jiminny\\Exceptions\\InvalidArgumentException;\nuse Jiminny\\Exceptions\\ModelNotFoundException;\nuse Jiminny\\Jobs\\AutomatedReports\\RequestGenerateReportJob;\nuse Jiminny\\Models\\Activity\\Search;\nuse Jiminny\\Models\\AskAnything\\AskAnythingPrompt;\nuse Jiminny\\Models\\AskAnything\\AskAnythingPromptTarget;\nuse Jiminny\\Models\\AutomatedReport;\nuse Jiminny\\Models\\AutomatedReportResult;\nuse Jiminny\\Models\\Contracts\\UserContract;\nuse Jiminny\\Models\\Feature\\FeatureEnum;\nuse Jiminny\\Models\\Team;\nuse Jiminny\\Models\\User;\nuse Jiminny\\Repositories\\AskAnythingRepository;\nuse Jiminny\\Repositories\\AutomatedReportsRepository;\nuse Jiminny\\Repositories\\GroupRepository;\nuse Jiminny\\Repositories\\SearchRepository;\nuse Jiminny\\Repositories\\StageRepository;\nuse Throwable;\n\nclass AutomatedReportsService\n{\n public const string TYPE_LOSS_ANALYSIS = 'loss_analysis';\n public const string TYPE_ASK_JIMINNY = 'ask_jiminny';\n\n /**\n * Standard report types (used by kiosk for existing automated reports).\n */\n // @TODO this will add filter, however if we need to control feature by FF we need conditional logic\n public const array TYPES = [\n ['id' => 'exec_summary', 'name' => 'Exec Summary'],\n ['id' => 'coaching_profiles', 'name' => 'Coaching Profiles'],\n ['id' => 'product_feedback', 'name' => 'Product Feedback'],\n ['id' => self::TYPE_LOSS_ANALYSIS, 'name' => 'Loss Analysis'],\n// ['id' => 'questions', 'name' => 'Questions'],\n// ['id' => 'statistical_quant', 'name' => 'Statistical Quantitative'],\n ];\n\n public const array ALL_TYPES = [\n ...self::TYPES,\n ['id' => self::TYPE_ASK_JIMINNY, 'name' => 'Ask Jiminny'],\n ];\n\n public const string FREQUENCY_DAILY = 'daily';\n public const string FREQUENCY_WEEKLY = 'weekly';\n public const string FREQUENCY_MONTHLY = 'monthly';\n public const string FREQUENCY_QUARTERLY = 'quarterly';\n public const string FREQUENCY_ONE_OFF = 'one_off';\n\n /**\n * Frequencies for standard (non-Ask Jiminny) reports.\n */\n public const array FREQUENCIES = [\n ['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],\n ['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],\n ['id' => self::FREQUENCY_QUARTERLY, 'name' => 'Quarterly'],\n ['id' => self::FREQUENCY_ONE_OFF, 'name' => 'One-off'],\n ];\n\n /**\n * Frequencies for Ask Jiminny reports.\n */\n public const array ASK_JIMINNY_FREQUENCIES = [\n ['id' => self::FREQUENCY_DAILY, 'name' => 'Daily'],\n ['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],\n ['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],\n ];\n\n public const string MEDIA_TYPE_PDF = 'pdf';\n public const string MEDIA_TYPE_PODCAST = 'podcast';\n public const array MEDIA_TYPES = [self::MEDIA_TYPE_PDF, self::MEDIA_TYPE_PODCAST];\n public const array MEDIA_TYPE_OBJECT_PDF = ['id' => self::MEDIA_TYPE_PDF, 'name' => 'PDF'];\n public const array MEDIA_TYPE_OBJECT_PODCAST = ['id' => self::MEDIA_TYPE_PODCAST, 'name' => 'Podcast'];\n public const array MEDIA_TYPE_OBJECTS = [self::MEDIA_TYPE_OBJECT_PDF, self::MEDIA_TYPE_OBJECT_PODCAST];\n\n public const array CALL_TYPE_CONFERENCE = ['id' => 'conference', 'name' => 'Conference'];\n public const array CALL_TYPE_DIALER = ['id' => 'dialer', 'name' => 'Dialer'];\n public const int SENT_REPORT_AT_HOURS = 5;\n public const string PDF_KEY = 'pdf';\n public const string AUDIO_KEY = 'audio';\n\n private const array ALL_FREQUENCIES = [\n ['id' => self::FREQUENCY_DAILY, 'name' => 'Daily'],\n ['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],\n ['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],\n ['id' => self::FREQUENCY_QUARTERLY, 'name' => 'Quarterly'],\n ['id' => self::FREQUENCY_ONE_OFF, 'name' => 'One-off'],\n ];\n private const string S3_DIR = 'reports';\n private const array FILE_EXTENSIONS_VARIANTS = ['html', 'MD', 'pdf'];\n private const array FILE_PODCAST_EXTENSIONS_VARIANTS = ['json', 'mp3', 'ssml'];\n\n public function __construct(\n private readonly TeamRepository $teamRepository,\n private readonly GroupRepository $groupRepository,\n private readonly UserRepository $userRepository,\n private readonly StageRepository $stageRepository,\n private readonly DealStagesService $dealStagesService,\n private readonly RecipientsService $recipientsService,\n private readonly AutomatedReportsRepository $automatedReportsRepository,\n private readonly Webhook $webhookService,\n private readonly BusDispatcher $dispatcher,\n private readonly ActivityTypeService $activityTypeService,\n private readonly PlaybookCategoryRepository $playbookCategoryRepository,\n private readonly AskAnythingPromptService $askAnythingPromptService,\n private readonly SearchRepository $activitySearchRepository,\n private readonly AskAnythingRepository $askAnythingRepository,\n ) {\n }\n\n public static function getTypes(): array\n {\n $types = self::TYPES;\n\n return array_map(static function ($type) {\n return $type['id'];\n }, $types);\n }\n\n public static function getCallTypes(): array\n {\n return array_map(static function ($callType) {\n return $callType['id'];\n }, [self::CALL_TYPE_CONFERENCE, self::CALL_TYPE_DIALER]);\n }\n\n public static function getFrequencies(): array\n {\n return array_map(static function ($frequency) {\n return $frequency['id'];\n }, self::FREQUENCIES);\n }\n\n // front-facing structure\n public function getReportEnabledFieldData(bool $value = false): array\n {\n return [\n 'id' => 'report_enabled',\n 'label' => '',\n 'inputType' => InputTypeEnum::TOGGLE,\n 'value' => $value,\n ];\n }\n\n // Organizations = Teams\n public function getOrganizationFieldData(?string $value = null, bool $shortVersion = false): array\n {\n $options = $this->getTeams();\n\n if ($shortVersion) {\n return [\n 'id' => 'organization',\n 'label' => 'Organization',\n 'options' => $options,\n ];\n }\n\n return [\n 'id' => 'organization',\n 'label' => 'Organization',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => $options,\n 'value' => $value,\n 'dependencies' => [\n 'teams',\n 'deal_stage_at_call',\n 'current_deal_stage',\n 'recipients',\n ActivityTypeService::PLAYBOOK_CATEGORIES_KEY,\n ],\n 'dependsOn' => [],\n ];\n }\n\n // Teams = Groups\n public function getTeamFieldData(array $options = [], array $value = [], bool $shortVersion = false): array\n {\n if ($shortVersion) {\n return [\n 'id' => 'teams',\n 'label' => 'Team',\n 'options' => $options,\n ];\n }\n\n return [\n 'id' => 'teams',\n 'label' => 'Team',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'required' => false,\n 'placeholder' => 'Select',\n 'options' => $options,\n 'value' => $value, // value should be an array of objects {id, name}\n 'dependencies' => [ActivityTypeService::PLAYBOOK_CATEGORIES_KEY],\n 'dependsOn' => [],\n ];\n }\n\n public function getReportTypeFieldData(?string $value = null, bool $shortVersion = false, ?Team $team = null): array\n {\n $types = [];\n if ($team instanceof Team) {\n if ($team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {\n $types = self::TYPES;\n }\n if ($team->hasFeature(FeatureEnum::ASK_JIMINNY_REPORTS)) {\n $types[] = ['id' => self::TYPE_ASK_JIMINNY, 'name' => 'Ask Jiminny'];\n }\n } else {\n $types = self::TYPES;\n }\n\n if ($shortVersion) {\n return [\n 'id' => 'report_type',\n 'label' => 'Report Type',\n 'options' => $types,\n ];\n }\n\n return [\n 'id' => 'report_type',\n 'label' => 'Report Type',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => $types,\n 'value' => $value,\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getFrequencyFieldData(?string $value = null): array\n {\n return [\n 'id' => 'frequency',\n 'label' => 'Frequency',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => self::FREQUENCIES,\n 'value' => $value,\n 'dependencies' => ['period'],\n 'dependsOn' => [],\n ];\n }\n\n public function getPeriodFieldData(?string $valueStartDate = null, ?string $valueEndDate = null): array\n {\n return [\n 'id' => 'period',\n 'label' => 'Select one-off period',\n 'inputType' => InputTypeEnum::DATE_RANGE,\n 'required' => true,\n 'placeholder' => 'Select',\n 'value' => ['startDate' => $valueStartDate, 'endDate' => $valueEndDate],\n 'queryParams' => [\n 'startDate' => 'start_date_period',\n 'endDate' => 'end_date_period',\n ],\n 'dependencies' => [],\n 'dependsOn' => ['frequency'],\n ];\n }\n\n public function getActivityTypesFieldData(?Team $team = null, array $value = [], array $teamsFilter = []): array\n {\n return $this->activityTypeService->getActivityTypeFieldData(team: $team, value: $value, groupIds: $teamsFilter);\n }\n\n public function getDealStageAtCallFieldData(?Team $team = null, array $value = []): array\n {\n return $this->dealStagesService->getDealStageAtCallFieldData(team: $team, value: $value);\n }\n\n public function getCurrentDealStageFieldData(?Team $team = null, array $value = []): array\n {\n return $this->dealStagesService->getCurrentDealStageFieldData(team: $team, value: $value);\n }\n\n public function getDealValueFieldData(?int $valueMin = null, ?int $valueMax = null): array\n {\n return [\n 'id' => 'deal_value',\n 'label' => 'Deal Value',\n 'inputType' => InputTypeEnum::INTEGER_RANGE,\n 'required' => false,\n 'value' => ['min' => $valueMin, 'max' => $valueMax],\n 'queryParams' => [\n 'min' => 'min_deal_value',\n 'max' => 'max_deal_value',\n ],\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getCallTypeFieldData(bool $conferenceOn = false, bool $dialerOn = false): array\n {\n $value = [];\n $conferenceOn && $value[] = self::CALL_TYPE_CONFERENCE;\n $dialerOn && $value[] = self::CALL_TYPE_DIALER;\n\n return [\n 'id' => 'call_type',\n 'label' => 'Call Type',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'required' => true,\n 'options' => [\n self::CALL_TYPE_CONFERENCE,\n self::CALL_TYPE_DIALER,\n ],\n 'value' => $value,\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getMediaTypeFieldData(?AutomatedReport $report = null): array\n {\n $value = [];\n\n if ($report) {\n $value = $this->transformMediaTypes($report);\n }\n\n return [\n 'id' => 'media_types',\n 'label' => 'Export as',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'required' => true,\n 'options' => self::MEDIA_TYPE_OBJECTS,\n 'value' => $value,\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getCallDurationFieldData(?int $valueMin = null, ?int $valueMax = null): array\n {\n return [\n 'id' => 'call_duration',\n 'label' => 'Call Duration',\n 'inputType' => InputTypeEnum::INTEGER_RANGE,\n 'required' => false,\n 'value' => ['min' => $valueMin, 'max' => $valueMax],\n 'queryParams' => [\n 'min' => 'min_call_duration',\n 'max' => 'max_call_duration',\n ],\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getRecipientsFieldData(?Team $team = null, array $value = []): array\n {\n return $this->recipientsService->getRecipientsFieldData(team: $team, value: $value);\n }\n\n public function getJiminnyRecipientsFieldData(array $value = []): array\n {\n return $this->recipientsService->getJiminnyRecipientsFieldData($value);\n }\n\n public function getAdditionalPromptInputFieldData(?string $value = null): array\n {\n return [\n 'id' => 'additional_prompt_input',\n 'label' => 'Special requirements',\n 'inputType' => InputTypeEnum::TEXTAREA,\n 'required' => false,\n 'placeholder' => 'What should be the focus of the report?',\n 'value' => $value,\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getCustomReportNameFieldData(?string $value = null): array\n {\n return [\n 'id' => 'custom_name',\n 'label' => 'Custom report name',\n 'inputType' => InputTypeEnum::TEXT,\n 'required' => false,\n 'placeholder' => 'Enter custom name',\n 'value' => $value,\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n // data providers\n public function getTeams(): array\n {\n $teams = $this->teamRepository->getTeamsForKiosk(status: Team::STATUS_ACTIVE);\n\n $teamData = [];\n foreach ($teams as $team) {\n if (! $team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {\n continue;\n }\n\n $teamData[] = $this->transformTeam($team);\n }\n\n return $teamData;\n }\n\n public function getTeamGroups(string $teamUuid): array\n {\n $data = [];\n $team = $this->getTeam($teamUuid);\n\n if ($team !== null) {\n $groups = $team->groups()->get();\n\n foreach ($groups as $group) {\n $data[] = [\n 'id' => $group->getUuid(),\n 'name' => $group->getName(),\n ];\n }\n }\n\n return $data;\n }\n\n public function getTeamsGroupsOptions(array $filterTeamUuids = []): array\n {\n $data = [];\n $teams = $this->getTeams();\n\n foreach ($teams as $team) {\n if (! empty($filterTeamUuids) && ! in_array($team['id'], $filterTeamUuids, true)) {\n continue;\n }\n\n $data[] = [\n 'label' => $team['name'],\n 'groups' => $this->getTeamGroups($team['id']),\n ];\n }\n\n return $data;\n }\n\n public function getTeam(string $teamUuid): ?Team\n {\n return $this->teamRepository->idOrUuid($teamUuid);\n }\n\n public function getTeamById(int $teamId): ?Team\n {\n return $this->teamRepository->find($teamId);\n }\n\n public function getGroupsUuids(AutomatedReport $report): array\n {\n $uuids = [];\n $reportGroups = $report->getGroups();\n foreach ($reportGroups as $groupId) {\n if ($group = $this->groupRepository->find($groupId)) {\n $uuids[] = $group->getUuid();\n }\n }\n\n return $uuids;\n }\n\n public function getPlaybookCategoriesUuids(AutomatedReport $report): array\n {\n $uuids = [];\n $playbookCategories = $report->getPlaybookCategories();\n foreach ($playbookCategories as $id) {\n if ($category = $this->playbookCategoryRepository->find($id)) {\n $uuids[] = $category->getUuid();\n }\n }\n\n return $uuids;\n }\n\n public function getDealAtCallStagesUuids(AutomatedReport $report): array\n {\n $uuids = [];\n $reportStages = $report->getDealAtCallStages();\n foreach ($reportStages as $id) {\n if ($stage = $this->stageRepository->find($id)) {\n $uuids[] = $stage->getUuid();\n }\n }\n\n return $uuids;\n }\n\n public function getCurrentDealStagesUuids(AutomatedReport $report): array\n {\n $uuids = [];\n $reportStages = $report->getCurrentDealStages();\n foreach ($reportStages as $id) {\n if ($stage = $this->stageRepository->find($id)) {\n $uuids[] = $stage->getUuid();\n }\n }\n\n return $uuids;\n }\n\n public function getUsersUuids(AutomatedReport $report): array\n {\n return $this->extractUserUuids($report->getRecipients());\n }\n\n public function getJiminnyUsersUuids(AutomatedReport $report): array\n {\n return $this->extractUserUuids($report->getJiminnyRecipients());\n }\n\n /**\n * @param array<string, mixed> $recipients\n */\n private function extractUserUuids(array $recipients): array\n {\n $userIds = $recipients['users'] ?? [];\n\n return collect($userIds)\n ->map(fn ($id) => $this->userRepository->find((int) $id))\n ->filter()\n ->map(fn (UserContract $user) => $user->getUuid())\n ->values()\n ->all();\n }\n\n // get mail data\n public function getRecipientUsers(AutomatedReport $report): array\n {\n return $this->buildRecipientUsers($report->getRecipients());\n }\n\n private function getJiminnyRecipientUsers(AutomatedReport $report): array\n {\n return $this->buildRecipientUsers($report->getJiminnyRecipients());\n }\n\n /**\n * @param array<string, mixed> $recipients\n */\n private function buildRecipientUsers(array $recipients): array\n {\n $userIds = $recipients['users'] ?? [];\n\n return collect($userIds)\n ->map(fn ($id) => $this->userRepository->find((int) $id))\n ->filter()\n ->map(fn (UserContract $user) => [\n 'email' => $user->getEmailAddress(),\n 'name' => $user->getName(),\n 'timezone' => $user->getTimezone()->getName(),\n ])\n ->values()\n ->all();\n }\n\n public function getValidRecipientUsers(AutomatedReport $report, bool $includeJiminny = false): array\n {\n if ($report->isAskJiminnyReport()) {\n $recipients = $this->resolveAskJiminnyRecipients($report);\n } else {\n $recipients = $this->getRecipientUsers($report);\n if ($includeJiminny) {\n $recipients = array_merge($recipients, $this->getJiminnyRecipientUsers($report));\n }\n }\n\n $emails = [];\n\n return array_values(array_filter(\n $recipients,\n static function ($recipient) use (&$emails) {\n if (empty($recipient['email']) || in_array($recipient['email'], $emails, true)) {\n return false;\n }\n $emails[] = $recipient['email'];\n\n return true;\n }\n ));\n }\n\n private function resolveAskJiminnyRecipients(AutomatedReport $report): array\n {\n $recipients = [];\n\n $creator = $report->getCreator();\n if ($creator !== null) {\n $recipients[] = [\n 'email' => $creator->getEmailAddress(),\n 'name' => $creator->getName(),\n 'timezone' => $creator->getTimezone()->getName(),\n ];\n }\n\n return array_merge(\n $recipients,\n $this->buildRecipientUsers($report->getRecipients()),\n $this->getGroupRecipientUsers($report),\n );\n }\n\n private function getGroupRecipientUsers(AutomatedReport $report): array\n {\n $users = [];\n foreach ($report->getGroups() as $groupId) {\n $group = $this->groupRepository->find($groupId);\n if ($group === null) {\n continue;\n }\n foreach ($group->getMembers() as $member) {\n $users[] = [\n 'email' => $member->getEmailAddress(),\n 'name' => $member->getName(),\n 'timezone' => $member->getTimezone()->getName(),\n ];\n }\n }\n\n return $users;\n }\n\n public function getReportTypeName(AutomatedReportResult $report): string\n {\n $type = $report->getReport()->getType();\n\n $getType = $this->transformReportType($type);\n\n return $getType['name'];\n }\n\n public function getReportPeriodName(AutomatedReportResult $report): string\n {\n $from = $report->getFromDate();\n $to = $report->getToDate();\n $frequency = $report->getReport()->getFrequency();\n\n if ($from === null || $to === null) {\n if (! $report->getReport()->isAskJiminnyReport()) {\n $invalidPeriod = $from === null ? 'from' : 'to';\n\n throw new ApplicationException('Report period is invalid: ' . $invalidPeriod);\n }\n\n $period = $this->calculateFromAndToDatePeriod($frequency);\n $from = $period['fromDate'];\n $to = $period['toDate'];\n }\n\n return $this->formatReportPeriodName($frequency, $from, $to);\n }\n\n private function formatReportPeriodName(string $frequency, Carbon $from, Carbon $to): string\n {\n $fromYear = $from->format('Y');\n $toYear = $to->format('Y');\n $differentYears = $fromYear !== $toYear;\n\n switch ($frequency) {\n case self::FREQUENCY_DAILY:\n return $from->format('j M Y');\n\n case self::FREQUENCY_QUARTERLY:\n // 'Jan-Mar 2025' or 'Nov 2024-Jan 2025' if years differ\n $startMonth = $from->format('M');\n $endMonth = $to->copy()->subMonth();\n $endMonthName = $endMonth->format('M');\n $endMonthYear = $endMonth->format('Y');\n\n if ($differentYears) {\n return \"{$startMonth} {$fromYear} - {$endMonthName} {$endMonthYear}\";\n }\n\n return \"{$startMonth} - {$endMonthName} {$toYear}\";\n\n case self::FREQUENCY_MONTHLY:\n // 'May 2025' - monthly reports are always within the same year\n return $from->format('M Y');\n\n case self::FREQUENCY_WEEKLY:\n // '4 - 8 Aug 2025', '27 Oct - 3 Nov 2025', or '28 Dec 2024 - 3 Jan 2025' if years differ\n $startDay = $from->format('j');\n $endDay = $to->format('j');\n $startMonth = $from->format('M');\n $endMonth = $to->format('M');\n\n if ($differentYears) {\n return \"{$startDay} {$startMonth} {$fromYear} - {$endDay} {$endMonth} {$toYear}\";\n }\n\n if ($startMonth !== $endMonth) {\n return \"{$startDay} {$startMonth} - {$endDay} {$endMonth} {$toYear}\";\n }\n\n return \"{$startDay} - {$endDay} {$endMonth} {$toYear}\";\n\n case self::FREQUENCY_ONE_OFF:\n // '2 May-31 May 2025' or '15 Dec 2024-15 Jan 2025' if years differ\n $startDay = $from->format('j');\n $startMonth = $from->format('M');\n $endDay = $to->format('j');\n $endMonth = $to->format('M');\n\n // If same month and year, use a format like '2-31 May 2025'\n if ($startMonth === $endMonth && ! $differentYears) {\n return \"{$startDay} - {$endDay} {$startMonth} {$toYear}\";\n }\n\n // If different years, include both years\n if ($differentYears) {\n return \"{$startDay} {$startMonth} {$fromYear} - {$endDay} {$endMonth} {$toYear}\";\n }\n\n // Same year but different months\n return \"{$startDay} {$startMonth} - {$endDay} {$endMonth} {$toYear}\";\n\n default:\n // Default format for unknown frequencies\n return $from->format('j M Y') . ' - ' . $to->format('j M Y');\n }\n }\n\n public function getReportTeamsName(AutomatedReportResult $report): string\n {\n $groups = $report->getGroups();\n\n if (empty($groups)) {\n return 'All';\n }\n\n // Get group names from repository\n $groupNames = [];\n foreach ($groups as $groupId) {\n $group = $this->groupRepository->find($groupId);\n if ($group) {\n $groupNames[] = $group->getName();\n }\n }\n\n if (count($groupNames) === 1) {\n // Single team format\n $teamsName = $groupNames[0];\n } else {\n // Multiple teams format\n $teamsName = implode(', ', $groupNames);\n }\n\n return $teamsName;\n }\n\n public function getReportFileName(AutomatedReportResult $report): string\n {\n $customName = $report->getReport()->getCustomName();\n $periodName = $this->getReportPeriodName($report);\n $filenameSuffix = $this->getFilenameSuffix($report);\n\n if ($customName) {\n if ($filenameSuffix) {\n $customName .= \" {$filenameSuffix}\";\n }\n\n return $this->sanitizeFileName(\"{$customName} - {$periodName}\");\n }\n\n $baseName = $this->getReportTypeName($report);\n\n if ($filenameSuffix) {\n $baseName .= \" {$filenameSuffix}\";\n }\n\n return $this->sanitizeFileName(\"{$baseName} - {$periodName} - {$this->getReportTeamsName($report)}\");\n }\n\n public function getReportFileNameWithExtension(AutomatedReportResult $result): string\n {\n $extension = $this->getMediaTypeMetadata($result)['extension'];\n\n return $this->getReportFileName($result) . '.' . $extension;\n }\n\n public function sanitizeFileName(string $fileName): string\n {\n return str_replace(['/', '\\\\'], '-', $fileName);\n }\n\n public function isUserRecipientOfReport(User $user, AutomatedReport $report): bool\n {\n $recipients = array_map('intval', $report->getRecipients()['users'] ?? []);\n\n return in_array($user->getId(), $recipients);\n }\n\n public function transformReportResults(Collection $automatedReportResults): array\n {\n $data = [];\n foreach ($automatedReportResults as $automatedReportResult) {\n /** @var AutomatedReportResult $automatedReportResult */\n\n $report = $automatedReportResult->getReport();\n\n $createdBy = $report->getCreator();\n $creator = [\n 'id' => $createdBy?->getUuid(),\n 'name' => $createdBy?->getName(),\n 'email' => $createdBy?->getEmailAddress(),\n 'photoUrl' => $createdBy?->getPhotoUrl(),\n ];\n\n $data[] = [\n 'id' => $automatedReportResult->getUuid(),\n 'name' => $automatedReportResult->getName(),\n 'frequency' => $this->transformFrequency($report->getFrequency()),\n 'recipients' => [\n ...array_values($this->transformGroups(team: $report->getTeam(), groupsIds: $report->getGroups())),\n ...array_values($this->transformRecipients($report->getRecipients())),\n ],\n 'report_type' => $this->transformReportType($report->getType()),\n 'media_type' => $automatedReportResult->getMediaType(),\n 'downloadUrl' => $this->generateReportResultDownloadUrl($automatedReportResult),\n 'viewUrl' => $this->generateReportResultViewUrl($automatedReportResult),\n 'generated_at' => $automatedReportResult->getGeneratedAt()?->toIso8601String(),\n 'creator' => $creator,\n ];\n }\n\n return $data;\n }\n\n public function hasCallTypeConference(AutomatedReport $report): bool\n {\n return in_array(self::CALL_TYPE_CONFERENCE['id'], $report->getCallTypes(), true);\n }\n\n public function hasCallTypeDialer(AutomatedReport $report): bool\n {\n return in_array(self::CALL_TYPE_DIALER['id'], $report->getCallTypes(), true);\n }\n\n // transformers\n private function transformTeam(Team $team): array\n {\n if (! $team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {\n return [];\n }\n\n return [\n 'id' => $team->getUuid(),\n 'name' => $team->getName(),\n ];\n }\n\n private function transformReportFullView(AutomatedReport $report): array\n {\n $base = $this->transformReportBase($report);\n\n return $report->getType() === self::TYPE_ASK_JIMINNY\n ? $base + $this->transformAskJiminnyFields($report)\n : $base + $this->transformStandardReportFields($report);\n }\n\n private function transformReportBase(AutomatedReport $report): array\n {\n return [\n 'id' => $report->getUuid(),\n 'organization' => $this->transformOrganization(team: $report->getTeam()),\n 'report_type' => $this->transformReportType($report->getType()),\n 'frequency' => $this->transformFrequency($report->getFrequency()),\n ];\n }\n\n private function transformStandardReportFields(AutomatedReport $report): array\n {\n $team = $report->getTeam();\n\n return [\n 'report_enabled' => $report->getStatus(),\n 'start_date_period' => $report->getFrom()?->format('Y-m-d H:i:s'),\n 'end_date_period' => $report->getTo()?->format('Y-m-d H:i:s'),\n 'deal_value_min' => $report->getDealValueMin(),\n 'deal_value_max' => $report->getDealValueMax(),\n 'call_types' => $this->transformCallType($report->getCallTypes()),\n 'media_types' => $this->transformMediaTypes($report),\n 'call_duration_min' => $this->transformDurationToMinutes($report->getCallDurationMin()),\n 'call_duration_max' => $this->transformDurationToMinutes($report->getCallDurationMax()),\n 'teams' => $this->transformGroups(team: $team, groupsIds: $report->getGroups()),\n 'deal_at_call_stages' => $this->transformStages(team: $team, stagesIds: $report->getDealAtCallStages()),\n 'current_deal_stages' => $this->transformStages(team: $team, stagesIds: $report->getCurrentDealStages()),\n 'recipients' => $this->transformRecipients($report->getRecipients()),\n 'created_by' => $this->transformCreator($report->getCreator()),\n 'additional_prompt_input' => $report->getAdditionalPromptInput(),\n 'custom_name' => $report->getCustomName(),\n 'created_at' => $report->getCreatedAt()->format('Y-m-d H:i:s'),\n 'updated_at' => $report->getUpdatedAt()->format('Y-m-d H:i:s'),\n 'deleted_at' => $report->getDeletedAt()?->format('Y-m-d H:i:s'),\n ];\n }\n\n private function transformAskJiminnyFields(AutomatedReport $report): array\n {\n $team = $report->getTeam();\n $creatorId = $report->getAttribute('created_by');\n $explicitUserIds = array_values(array_filter(\n $report->getRecipients()['users'] ?? [],\n static fn ($id) => $id !== $creatorId\n ));\n\n return [\n 'report_name' => $report->getCustomName(),\n 'enabled' => $report->getStatus(),\n 'share_teams' => $this->transformGroups(team: $team, groupsIds: $report->getGroups()),\n 'share_users' => $this->transformRecipients(['users' => $explicitUserIds]),\n 'saved_search' => $this->transformSafeSearch($report->getSavedSearch()),\n 'ask_jiminny_prompt' => $this->transformAskJiminnyPrompt($report->getAskAnythingPrompt()),\n 'expires_on' => $report->getExpiresAt()?->format('Y-m-d'),\n ];\n }\n\n private function transformOrganization(?Team $team): array\n {\n return [\n 'id' => $team?->getUuid(),\n 'name' => $team?->getName(),\n ];\n }\n\n private function transformReportType(string $type): array\n {\n foreach (self::ALL_TYPES as $typeItem) {\n if ($typeItem['id'] === $type) {\n return $typeItem;\n }\n }\n\n return [];\n }\n\n private function transformCallType(array $types): array\n {\n $result = [];\n $callTypes = [self::CALL_TYPE_CONFERENCE, self::CALL_TYPE_DIALER];\n\n foreach ($types as $type) {\n foreach ($callTypes as $callTypeItem) {\n if ($callTypeItem['id'] === $type) {\n $result[] = $callTypeItem;\n\n break;\n }\n }\n }\n\n return $result;\n }\n\n private function transformMediaTypes(AutomatedReport $report): array\n {\n $values = [];\n\n foreach ($report->getMediaTypes() as $mediaType) {\n if (! in_array($mediaType, self::MEDIA_TYPES, true)) {\n continue;\n }\n\n $values[] = match ($mediaType) {\n self::MEDIA_TYPE_PDF => self::MEDIA_TYPE_OBJECT_PDF,\n self::MEDIA_TYPE_PODCAST => self::MEDIA_TYPE_OBJECT_PODCAST,\n };\n }\n\n return $values;\n }\n\n private function transformFrequency(string $frequency): array\n {\n foreach (self::ALL_FREQUENCIES as $frequencyItem) {\n if ($frequencyItem['id'] === $frequency) {\n return $frequencyItem;\n }\n }\n\n return [];\n }\n\n public function transformDurationToMinutes(?int $duration): ?int\n {\n if (! $duration) {\n return null;\n }\n\n return (int) ($duration / 60);\n }\n\n private function transformGroups(?Team $team, array $groupsIds): array\n {\n if (empty($groupsIds) || ! $team) {\n return [];\n }\n\n $data = [];\n foreach ($groupsIds as $groupId) {\n $group = $team->groups()->where('id', $groupId)->first();\n\n if ($group) {\n $data[] = [\n 'id' => $group->getUuid(),\n 'name' => $group->getName(),\n 'photoUrl' => $group->getPhotoUrl(),\n ];\n }\n }\n\n return $data;\n }\n\n private function transformStages(?Team $team, array $stagesIds): array\n {\n if (empty($stagesIds) || ! $team) {\n return [];\n }\n\n $data = [];\n foreach ($stagesIds as $stageId) {\n $stage = $team->stages()->where('id', $stageId)->first();\n\n if ($stage) {\n $data[] = [\n 'id' => $stage->getUuid(),\n 'name' => $stage->getName(),\n ];\n }\n }\n\n return $data;\n }\n\n private function transformRecipients(array $recipients): array\n {\n $users = [];\n foreach ($recipients['users'] ?? [] as $userId) {\n $users[] = $this->transformUser($userId);\n }\n\n return $users;\n }\n\n private function transformCreator(?User $user): ?array\n {\n if ($user === null) {\n return null;\n }\n\n return $this->transformUser($user->getId());\n }\n\n private function transformAskJiminnyPrompt(?AskAnythingPrompt $prompt): ?array\n {\n if ($prompt === null) {\n return null;\n }\n\n return [\n 'id' => $prompt->getUuid(),\n 'name' => $prompt->getTitle(),\n ];\n }\n\n private function transformSafeSearch(?Search $search): ?array\n {\n if ($search === null) {\n return null;\n }\n\n return [\n 'id' => $search->getUuid(),\n 'name' => $search->getName(),\n ];\n }\n\n private function transformUser(int $userId): array\n {\n /* @var ?User $user */\n $user = $this->userRepository->find($userId);\n\n return [\n 'id' => $user?->getUuid(),\n 'name' => $user?->getName(),\n 'email' => $user?->getEmailAddress(),\n 'photoUrl' => $user?->getPhotoUrl(),\n ];\n }\n\n public function create(array $data): array\n {\n $validatedData = $this->validateAndTransformData($data);\n $validatedData['created_by'] = auth()->id();\n\n $automatedReport = $this->automatedReportsRepository->create($validatedData);\n\n $this->generateOneOffReport($automatedReport);\n\n return $this->transformReportFullView($automatedReport);\n }\n\n public function update(string $uuid, array $data): array\n {\n $validatedData = $this->validateAndTransformData($data);\n $report = $this->automatedReportsRepository->findByUuid($uuid);\n\n if (! $report) {\n throw new InvalidArgumentException('Report not found');\n }\n\n $oldCustomName = $report->getCustomName();\n\n $automatedReport = $this->automatedReportsRepository->update($report, $validatedData);\n\n if ($oldCustomName !== $automatedReport->getCustomName()) {\n $this->updateResultNames($automatedReport);\n }\n\n $this->generateOneOffReport($automatedReport);\n\n return $this->transformReportFullView($automatedReport);\n }\n\n /**\n * Create an Ask Jiminny report.\n */\n public function createAskJiminnyReport(array $data, User $creator): array\n {\n $validatedData = $this->validateAskJiminnyReportData($data, $creator);\n $validatedData['created_by'] = $creator->getId();\n\n $automatedReport = $this->automatedReportsRepository->create($validatedData);\n\n return $this->transformReportFullView($automatedReport);\n }\n\n /**\n * Update an Ask Jiminny report.\n */\n public function updateAskJiminnyReport(AutomatedReport $report, array $data, User $user): array\n {\n if (! $report->isAskJiminnyReport()) {\n throw new InvalidArgumentException('Report is not an Ask Jiminny report');\n }\n\n $validatedData = $this->validateAskJiminnyReportData($data, $user);\n\n $oldCustomName = $report->getCustomName();\n\n $automatedReport = $this->automatedReportsRepository->update($report, $validatedData);\n\n if ($oldCustomName !== $automatedReport->getCustomName()) {\n $this->updateResultNames($automatedReport);\n }\n\n return $this->transformReportFullView($automatedReport);\n }\n\n public function updateAskJiminnyReportStatus(AutomatedReport $report, bool $status): array\n {\n $this->automatedReportsRepository->update($report, ['status' => $status]);\n\n return $this->transformReportFullView($report->fresh());\n }\n\n /**\n * Validate and transform data for Ask Jiminny reports.\n */\n private function validateAskJiminnyReportData(array $data, User $user): array\n {\n // Validate name\n $name = trim($data['report_name'] ?? '');\n if (empty($name)) {\n throw new InvalidArgumentException('Report name is required');\n }\n if (mb_strlen($name) > 50) {\n throw new InvalidArgumentException('Report name must be 50 characters or less');\n }\n\n // Validate frequency (only daily, weekly, monthly for Ask Jiminny)\n $frequency = $data['frequency'] ?? null;\n $askJiminnyFrequencies = [self::FREQUENCY_DAILY, self::FREQUENCY_WEEKLY, self::FREQUENCY_MONTHLY];\n if (! in_array($frequency, $askJiminnyFrequencies, true)) {\n throw new InvalidArgumentException('Frequency must be daily, weekly, or monthly');\n }\n\n // Validate expiration date\n $expiresAt = $data['expires_on'] ?? null;\n if (empty($expiresAt)) {\n throw new InvalidArgumentException('Expiration date is required');\n }\n\n try {\n $expiresAtDate = Carbon::parse($expiresAt);\n } catch (InvalidFormatException $e) {\n throw new InvalidArgumentException('Expiration date format is invalid');\n }\n $maxExpiration = Carbon::now()->addYear();\n if ($expiresAtDate->gt($maxExpiration)) {\n throw new InvalidArgumentException('Expiration date cannot be more than 1 year from now');\n }\n if ($expiresAtDate->isPast()) {\n throw new InvalidArgumentException('Expiration date cannot be in the past');\n }\n\n // Validate saved search\n $activitySearchId = $data['saved_search'] ?? null;\n if (empty($activitySearchId)) {\n throw new InvalidArgumentException('Saved search is required');\n }\n $savedSearch = $this->activitySearchRepository->findByUuidAndUser($activitySearchId, $user);\n if (! $savedSearch) {\n throw new InvalidArgumentException('Saved search not found or does not belong to you');\n }\n\n // Validate saved prompt\n $askAnythingPromptId = $data['ask_jiminny_prompt'] ?? null;\n if (empty($askAnythingPromptId)) {\n throw new InvalidArgumentException('Ask Jiminny prompt is required');\n }\n $prompt = $this->askAnythingRepository->getPromptByUuid($askAnythingPromptId);\n if (! $prompt) {\n throw new InvalidArgumentException('Ask Jiminny prompt not found');\n }\n\n // Validate status\n $status = $data['enabled'] ?? false;\n\n $recipientUserIds = [$user->getId()];\n\n if (! empty($data['share_users'])) {\n $sharedUserIds = $this->validateAndGetUserIdsByTeam(\n $user->team,\n (array) $data['share_users']\n );\n $recipientUserIds = array_merge($recipientUserIds, $sharedUserIds);\n }\n\n $sharedGroupIds = [];\n if (! empty($data['share_teams'])) {\n $sharedGroupIds = $this->validateAndGetGroupIds($user->team, (array) $data['share_teams']);\n }\n\n $recipientUserIds = array_values(array_unique($recipientUserIds));\n\n return [\n 'team_id' => $user->getTeamId(),\n 'type' => self::TYPE_ASK_JIMINNY,\n 'status' => (bool) $status,\n 'frequency' => $frequency,\n 'custom_name' => $name,\n 'activity_search_id' => $savedSearch->getId(),\n 'ask_anything_prompt_id' => $prompt->getId(),\n 'expires_at' => $expiresAtDate->toDateString(),\n 'media_types' => [self::MEDIA_TYPE_PDF],\n 'call_types' => [],\n 'recipients' => ['users' => $recipientUserIds],\n 'groups' => $sharedGroupIds,\n ];\n }\n\n public static function getAskJiminnyFrequencies(): array\n {\n return array_map(static function ($frequency) {\n return $frequency['id'];\n }, self::ASK_JIMINNY_FREQUENCIES);\n }\n\n public function getAskJiminnyReportFilters(User $user): array\n {\n $savedSearches = $this->activitySearchRepository->findByUserOrderedByName($user)\n ->map(fn (Search $search) => [\n 'id' => $search->getUuid(),\n 'name' => $search->getName(),\n ])\n ->values()->all();\n\n $prompts = collect(\n $this->askAnythingPromptService->get($user, AskAnythingPromptTarget::on_demand)\n )->map(fn (AskAnythingPromptDto $prompt) => [\n 'id' => $prompt->id,\n 'name' => $prompt->title,\n ])->values()->all();\n\n return [\n [\n 'id' => 'prompt',\n 'label' => 'Prompt',\n 'options' => $prompts,\n ],\n [\n 'id' => 'saved_search',\n 'label' => 'Saved Search',\n 'options' => $savedSearches,\n ],\n ];\n }\n\n public function getAskJiminnyReportFormData(User $user, ?AutomatedReport $report = null): array\n {\n $team = $user->getTeam();\n $userTimezone = $user->getTimezone();\n\n $savedSearches = $this->activitySearchRepository->findByUserOrderedByName($user)\n ->map(fn (Search $search) => [\n 'id' => $search->getUuid(),\n 'name' => $search->getName(),\n ])\n ->values()->all();\n\n $prompts = collect(\n $this->askAnythingPromptService->get($user, AskAnythingPromptTarget::on_demand)\n )->map(fn (AskAnythingPromptDto $prompt) => [\n 'id' => $prompt->id,\n 'name' => $prompt->title,\n ])->values()->all();\n\n $teamGroups = $this->groupRepository->getAllByTeam($team)->map(fn ($group) => [\n 'id' => $group->getUuid(),\n 'name' => $group->getName(),\n ])->values()->all();\n\n $shareUsers = $this->recipientsService->getRecipientsFieldData(team: $team)['options'] ?? [];\n\n $sharedTeamsValue = [];\n $sharedUsersValue = [];\n if ($report) {\n $sharedTeamsValue = $this->transformGroups($team, $report->getGroups());\n\n $recipientUserIds = $report->getRecipients()['users'] ?? [];\n $creatorId = $report->getAttribute('created_by');\n $sharedUserIds = array_values(array_filter(\n $recipientUserIds,\n static fn ($id) => $id !== $creatorId\n ));\n $sharedUsersValue = collect($sharedUserIds)\n ->map(fn ($id) => $this->userRepository->find((int) $id))\n ->filter()\n ->map(fn (User $u) => [\n 'id' => $u->getUuid(),\n 'name' => $u->getName(),\n ])\n ->values()\n ->all();\n }\n\n return [\n 'fields' => [\n [\n 'id' => 'enabled',\n 'inputType' => InputTypeEnum::TOGGLE,\n 'label' => '',\n 'value' => $report?->getStatus() ?? false,\n ],\n [\n 'id' => 'report_name',\n 'inputType' => InputTypeEnum::TEXT,\n 'label' => 'Name',\n 'placeholder' => 'Enter name',\n 'required' => true,\n 'validation' => ['maxLength' => 50],\n 'value' => $report?->getCustomName() ?? '',\n ],\n [\n 'id' => 'frequency',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'label' => 'Frequency',\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => self::ASK_JIMINNY_FREQUENCIES,\n 'value' => $report ? $this->transformFrequency($report->getFrequency()) : null,\n ],\n [\n 'id' => 'expires_on',\n 'inputType' => InputTypeEnum::DATE,\n 'label' => 'Expires on',\n 'required' => true,\n 'placeholder' => 'Select',\n 'validation' => [\n 'minDate' => now($userTimezone)->toDateString(),\n 'maxDate' => now($userTimezone)->addYear()->toDateString(),\n ],\n 'value' => $report?->getExpiresAt()?->toDateString(),\n ],\n [\n 'id' => 'share_teams',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'label' => 'Team',\n 'required' => false,\n 'placeholder' => 'Select',\n 'options' => $teamGroups,\n 'value' => $sharedTeamsValue,\n ],\n [\n 'id' => 'share_users',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'label' => 'Team member',\n 'required' => false,\n 'placeholder' => 'Select',\n 'groupLabelKey' => 'label',\n 'groupValuesKey' => 'users',\n 'optionLabelKey' => 'name',\n 'optionValueKey' => 'id',\n 'options' => $shareUsers,\n 'value' => $sharedUsersValue,\n ],\n [\n 'id' => 'saved_search',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'label' => 'Saved search',\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => $savedSearches,\n 'value' => $report && $report->getSavedSearch() ? [\n 'id' => $report->getSavedSearch()->getUuid(),\n 'name' => $report->getSavedSearch()->getName(),\n ] : null,\n ],\n [\n 'id' => 'ask_jiminny_prompt',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'label' => 'Ask Jiminny prompt',\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => $prompts,\n 'value' => $report && $report->getAskAnythingPrompt() ? [\n 'id' => $report->getAskAnythingPrompt()->getUuid(),\n 'name' => $report->getAskAnythingPrompt()->getTitle(),\n ] : null,\n ],\n ],\n ];\n }\n\n private function updateResultNames(AutomatedReport $automatedReport): void\n {\n $results = $this->automatedReportsRepository->getResultsByReport($automatedReport);\n\n foreach ($results as $result) {\n $result->update(['name' => $this->getReportFileName($result)]);\n }\n }\n\n public function updateStatus(string $uuid, array $data): array\n {\n $automatedReport = $this->automatedReportsRepository->findByUuid($uuid);\n\n if (! $automatedReport) {\n throw new ModelNotFoundException('Report not found');\n }\n\n $status = $this->validateReportStatus($data['report_enabled'] ?? null);\n $automatedReport->update([\n 'status' => $status,\n ]);\n\n $this->generateOneOffReport($automatedReport);\n\n return $this->transformReportFullView($automatedReport);\n }\n\n private function generateOneOffReport(AutomatedReport $automatedReport): void\n {\n // the scheduler handles all the other frequency types\n if ($automatedReport->getStatus() === false || $automatedReport->getFrequency() !== self::FREQUENCY_ONE_OFF) {\n return;\n }\n\n $this->dispatcher->dispatch(new RequestGenerateReportJob($automatedReport->getUuid()));\n }\n\n public function getReport(string $uuid): AutomatedReport\n {\n $automatedReport = $this->automatedReportsRepository->findByUuid($uuid);\n\n if (! $automatedReport) {\n throw new ModelNotFoundException('Report not found');\n }\n\n return $automatedReport;\n }\n\n public function get(string $uuid): array\n {\n $automatedReport = $this->getReport($uuid);\n\n return $this->transformReportFullView($automatedReport);\n }\n\n public function list(string $sortColumn = 'created_at', string $sortDirection = 'desc'): array\n {\n $results = [];\n $collection = $this->automatedReportsRepository->getAllStandardReports($sortColumn, $sortDirection);\n\n /** @var AutomatedReport $report */\n foreach ($collection as $report) {\n $results[] = $this->transformReportFullView($report);\n }\n\n return ['data' => $results];\n }\n\n public function listAskJiminnyReports(\n User $user,\n string $sortColumn = 'created_at',\n string $sortDirection = 'desc'\n ): array {\n $results = [];\n $collection = $this->automatedReportsRepository->getAskJiminnyReportsByUser($user, $sortColumn, $sortDirection);\n\n /** @var AutomatedReport $report */\n foreach ($collection as $report) {\n $results[] = $this->transformReportFullView($report);\n }\n\n return ['data' => $results];\n }\n\n public function delete(string $uuid): void\n {\n $automatedReport = $this->automatedReportsRepository->findByUuid($uuid);\n\n if (! $automatedReport) {\n throw new ModelNotFoundException('Report not found');\n }\n\n $automatedReport->delete();\n }\n\n public function createReportResult(AutomatedReport $automatedReport, array $data = []): AutomatedReportResult\n {\n return $this->automatedReportsRepository->createResult(\n array_merge(\n [\n 'report_id' => $automatedReport->getId(),\n 'status' => AutomatedReportResult::STATUS_DEFAULT,\n ],\n $data\n )\n );\n }\n\n public function getReportResult(string $resultUuid): AutomatedReportResult\n {\n $report = $this->automatedReportsRepository->findResultByUuid($resultUuid);\n\n if (! $report) {\n throw new ModelNotFoundException('Report Result not found');\n }\n\n return $report;\n }\n\n public function findChildResult(AutomatedReportResult $result, string $type): ?AutomatedReportResult\n {\n return $this->automatedReportsRepository->findChildResult($result, $type);\n }\n\n // prophet API calls\n /**\n * @throws ApplicationException\n */\n public function getGenerateReportPayload(AutomatedReport $automatedReport, string $reportResultUuid): array\n {\n $period = $this->calculateFromAndToDate($automatedReport);\n $fromDate = $period['fromDate'];\n $toDate = $period['toDate'];\n\n return [\n 'team_id' => $automatedReport->getTeamId(),\n 'request_id' => $reportResultUuid,\n 'report_type' => $automatedReport->getType(),\n 'media_types' => $automatedReport->getMediaTypes(),\n 'from_date' => $fromDate->startOfDay()->format(DateTimeInterface::RFC3339),\n 'to_date' => $toDate->endOfDay()->format(DateTimeInterface::RFC3339),\n 'group_ids' => $automatedReport->getGroups(),\n 'call_deal_stage' => $automatedReport->getDealAtCallStages(),\n 'current_deal_stage' => $automatedReport->getCurrentDealStages(),\n 'deal_min_value' => $automatedReport->getDealValueMin(),\n 'deal_max_value' => $automatedReport->getDealValueMax(),\n 'call_types' => $automatedReport->getCallTypes(),\n 'call_duration_min_seconds' => $automatedReport->getCallDurationMin(),\n 'call_duration_max_seconds' => $automatedReport->getCallDurationMax(),\n 'special_requirements' => $automatedReport->getAdditionalPromptInput(),\n 'callback_url' => $this->getCallbackUrl(),\n 'report_period' => $this->formatReportPeriodName(\n $automatedReport->getFrequency(),\n $fromDate,\n $toDate,\n ),\n 'playbook_categories' => $automatedReport->getPlaybookCategories(),\n 'custom_name' => $automatedReport->getCustomName(),\n ];\n }\n\n // $inputPayload - FE payload structure\n public function getActivitiesCountPayload(array $inputPayload): array\n {\n // Use validateAndTransformData to validate and normalize input\n $validatedData = $this->validateAndTransformData($inputPayload);\n $period = $this->calculateFromAndToDatePeriod(\n $validatedData['frequency'],\n Carbon::parse($validatedData['from']),\n Carbon::parse($validatedData['to']),\n );\n $fromDate = $period['fromDate'];\n $toDate = $period['toDate'];\n\n // Create payload similar to getGenerateReportPayload\n return [\n 'team_id' => $validatedData['team_id'],\n 'group_ids' => $validatedData['groups'] ?? [],\n 'report_type' => $validatedData['type'],\n 'from_date' => $fromDate->format(DateTimeInterface::RFC3339),\n 'to_date' => $toDate->format(DateTimeInterface::RFC3339),\n 'call_deal_stage' => $validatedData['deal_at_call_stages'] ?? [],\n 'current_deal_stage' => $validatedData['current_deal_stages'] ?? [],\n 'deal_min_value' => $validatedData['deal_value_min'] ?? null,\n 'deal_max_value' => $validatedData['deal_value_max'] ?? null,\n 'call_types' => $validatedData['call_types'],\n 'call_duration_min_seconds' => $validatedData['call_duration_min'] ?? null,\n 'call_duration_max_seconds' => $validatedData['call_duration_max'] ?? null,\n 'special_requirements' => $validatedData['additional_prompt_input'] ?? null,\n 'playbook_categories' => $validatedData['playbook_categories'] ?? [],\n 'request_id' => null,\n 'callback_url' => null,\n ];\n }\n\n public function shouldSendReport(array $users, ?CarbonInterface $generatedAt = null): bool\n {\n if (empty($users)) {\n return false;\n }\n\n $earliestTz = collect($users)\n ->mapWithKeys(function (array $user) {\n $tz = new DateTimeZone($user['timezone']);\n $nowUtc = new DateTime('now', new DateTimeZone('UTC'));\n $offset = $tz->getOffset($nowUtc);\n\n return [$user['timezone'] => $offset];\n })\n ->sortDesc()\n ->keys()\n ->first();\n\n $now = Carbon::now($earliestTz);\n $isScheduledTime = (int) $now->format('H') === self::SENT_REPORT_AT_HOURS;\n\n if ($isScheduledTime) {\n return true;\n }\n\n return $this->hasPassedScheduledTime($generatedAt, $earliestTz);\n }\n\n public function hasPassedScheduledTime(?CarbonInterface $generatedAt, string $timezone): bool\n {\n if ($generatedAt === null) {\n return false;\n }\n\n $now = Carbon::now($timezone);\n $scheduledTime = $now->copy()->setTime(self::SENT_REPORT_AT_HOURS, 0, 0);\n\n if ($now->hour < self::SENT_REPORT_AT_HOURS) {\n $scheduledTime = $scheduledTime->subDay();\n }\n\n $scheduledTimeUtc = $scheduledTime->copy()->utc();\n $generatedAtUtc = $generatedAt->copy()->utc();\n $nowUtc = $now->copy()->utc();\n\n return $generatedAtUtc->lt($scheduledTimeUtc) && $nowUtc->gt($scheduledTimeUtc);\n }\n\n public function calculateFromAndToDatePeriod(\n string $frequency,\n ?Carbon $fromDate = null,\n ?Carbon $toDate = null\n ): array {\n if ($frequency === self::FREQUENCY_ONE_OFF) {\n return [\n 'fromDate' => $fromDate,\n 'toDate' => $toDate,\n ];\n }\n\n $now = Carbon::now();\n\n return match ($frequency) {\n self::FREQUENCY_DAILY => [\n 'fromDate' => $now->copy()->subDay()->startOfDay(),\n 'toDate' => $now->copy()->subDay()->endOfDay(),\n ],\n self::FREQUENCY_WEEKLY => [\n 'fromDate' => $now->copy()->subWeeks(1)->startOfDay(),\n 'toDate' => $now->copy()->subDay()->endOfDay(),\n ],\n self::FREQUENCY_MONTHLY => [\n 'fromDate' => $now->copy()->subMonths(1)->startOfDay(),\n 'toDate' => $now->copy()->subDay()->endOfDay(),\n ],\n self::FREQUENCY_QUARTERLY => [\n 'fromDate' => $now->copy()->subMonths(3)->startOfDay(),\n 'toDate' => $now->copy()->subDay()->endOfDay(),\n ],\n default => throw new InvalidArgumentException(\"Unsupported frequency: {$frequency}\"),\n };\n }\n\n private function calculateFromAndToDate(AutomatedReport $automatedReport): array\n {\n return $this->calculateFromAndToDatePeriod(\n $automatedReport->getFrequency(),\n $automatedReport->getFrom(),\n $automatedReport->getTo()\n );\n }\n\n public function getAskJiminnyGenerateReportPayload(\n AutomatedReport $automatedReport,\n AutomatedReportResult $reportResult,\n array $activityIds,\n ): array {\n return [\n 'user_question' => $automatedReport->getAskAnythingPrompt()?->getContent(),\n 'call_ids' => array_map('strval', $activityIds),\n 'team_id' => $automatedReport->getTeamId(),\n 'request_id' => $reportResult->getUuid(),\n 'callback_url' => $this->getCallbackUrl(),\n 'report_period' => $this->getReportPeriodName($reportResult),\n 'report_name' => $automatedReport->getCustomName(),\n ];\n }\n\n private function getCallbackUrl(): string\n {\n return $this->webhookService->route('jiminny.webhook.reports.ready');\n }\n\n /**\n * Validate and transform payload data for automated reports\n *\n * @param array $data\n *\n * @throws InvalidArgumentException\n *\n * @return array\n */\n private function validateAndTransformData(array $data): array\n {\n // Validate organization (team) and check feature\n $team = $this->validateOrganization($data['organization'] ?? null);\n\n $status = $this->validateReportStatus($data['report_enabled'] ?? null);\n $type = $this->validateReportType($data['report_type'] ?? null);\n $frequency = $this->validateFrequency($data['frequency'] ?? null);\n $additionalPromptInput = $this->validateAdditionalPromptInput(\n $data['additional_prompt_input'] ?? null\n );\n $customReportName = $this->validateCustomReportName($data['custom_name'] ?? null);\n\n // Prepare data for the database\n $reportData = [\n 'team_id' => $team->getId(),\n 'type' => $type,\n 'status' => $status,\n 'frequency' => $frequency,\n 'additional_prompt_input' => $additionalPromptInput,\n 'custom_name' => $customReportName,\n ];\n\n // Validate deal values\n $reportData = $this->validateDealValues($data, $reportData);\n\n // Validate date range\n $reportData = $this->validateDateRange($data, $reportData, $frequency);\n\n // Validate call durations\n $reportData = $this->validateCallDurations($data, $reportData);\n\n // Validate call types\n $reportData = $this->validateCallTypes($data, $reportData);\n\n // Validate media types\n $reportData = $this->validateMediaTypes($data, $reportData);\n\n // Validate groups\n if (isset($data['teams'])) {\n $reportData['groups'] = $this->validateAndGetGroupIds($team, $data['teams']);\n }\n\n // Validate deal stages\n $reportData = $this->validateDealStages($data, $reportData, $team, $type);\n\n // Validate playbook categories\n $reportData = $this->validatePlaybookCategories($data, $reportData, $team);\n\n // Validate recipients\n $reportData['recipients'] = [\n 'users' => $this->validateAndGetUserIdsByTeam($team, $data['recipients'] ?? []),\n ];\n\n if (isset($data['jiminny_recipients'])) {\n // Validate Jiminny recipients\n $reportData['jiminny_recipients'] = [\n 'users' => $this->validateAndGetJiminnyUserIds((array) $data['jiminny_recipients']),\n ];\n }\n\n return $reportData;\n }\n\n private function validateDealValues(array $data, array $reportData): array\n {\n if (isset($data['min_deal_value'])) {\n $reportData['deal_value_min'] = (int) $data['min_deal_value'];\n\n if ($reportData['deal_value_min'] > 4294967295 || $reportData['deal_value_min'] < 0) {\n throw new InvalidArgumentException('Min deal value should be between 0 and 4294967295');\n }\n }\n\n if (isset($data['max_deal_value'])) {\n $reportData['deal_value_max'] = (int) $data['max_deal_value'];\n\n if ($reportData['deal_value_max'] > 4294967295 || $reportData['deal_value_max'] < 0) {\n throw new InvalidArgumentException('Max deal value should be between 0 and 4294967295');\n }\n }\n\n if (isset($data['min_deal_value'], $data['max_deal_value'])\n && $data['min_deal_value'] > $data['max_deal_value']\n ) {\n throw new InvalidArgumentException('Min deal value cannot be greater than max deal value');\n }\n\n return $reportData;\n }\n\n private function validateDateRange(array $data, array $reportData, string $frequency): array\n {\n // Set date range only for one_off frequency\n if ($frequency === 'one_off') {\n if (isset($data['start_date_period'])) {\n $reportData['from'] = $this->parseDate($data['start_date_period']);\n }\n\n if (isset($data['end_date_period'])) {\n $reportData['to'] = $this->parseDate($data['end_date_period']);\n }\n\n if (empty($reportData['from']) || empty($reportData['to'])) {\n throw new InvalidArgumentException(\n 'Start date and end date are required for one_off frequency'\n );\n }\n } else {\n $reportData['from'] = null;\n $reportData['to'] = null;\n }\n\n return $reportData;\n }\n\n private function validateCallDurations(array $data, array $reportData): array\n {\n // Convert call durations from minutes to seconds\n if (isset($data['min_call_duration'])) {\n $reportData['call_duration_min'] = (int) $data['min_call_duration'] * 60;\n\n if ($reportData['call_duration_min'] > 4294967295 || $reportData['call_duration_min'] < 0) {\n throw new InvalidArgumentException('Min call duration should be between 0 and 4294967295');\n }\n }\n\n if (isset($data['max_call_duration'])) {\n $reportData['call_duration_max'] = (int) $data['max_call_duration'] * 60;\n\n if ($reportData['call_duration_max'] > 4294967295 || $reportData['call_duration_max'] < 0) {\n throw new InvalidArgumentException('Max call duration should be between 0 and 4294967295');\n }\n }\n\n return $reportData;\n }\n\n private function validateCallTypes(array $data, array $reportData): array\n {\n // Set call types\n $reportData['call_types'] = $data['call_type'] ?? [];\n if (empty($reportData['call_types'])) {\n $reportData['call_types'] = self::getCallTypes();\n }\n\n foreach ($reportData['call_types'] as $callType) {\n if (! in_array($callType, self::getCallTypes(), true)) {\n throw new InvalidArgumentException(sprintf('Call type %s is invalid', $callType));\n }\n }\n\n return $reportData;\n }\n\n private function validateMediaTypes(array $data, array $reportData): array\n {\n // Set media types from input data\n $reportData['media_types'] = $data['media_types'] ?? [];\n\n if (empty($reportData['media_types'])) {\n throw new InvalidArgumentException('Media types are required');\n }\n\n foreach ($reportData['media_types'] as $mediaType) {\n if (! in_array($mediaType, self::MEDIA_TYPES, true)) {\n throw new InvalidArgumentException(sprintf('Media type %s is invalid', $mediaType));\n }\n }\n\n return $reportData;\n }\n\n private function validateDealStages(array $data, array $reportData, Team $team, string $reportType): array\n {\n // Validate and set deal stages\n if (isset($data['deal_stage_at_call'])) {\n $reportData['deal_at_call_stages'] =\n $this->validateAndGetDealStageIds($team, $data['deal_stage_at_call'], 'Deal stage at call');\n }\n\n if (isset($data['current_deal_stage'])) {\n $reportData['current_deal_stages'] =\n $this->validateAndGetDealStageIds($team, $data['current_deal_stage'], 'Current deal stage');\n }\n\n // Ensure current_deal_stage is not provided for loss_analysis report type\n if ($reportType === self::TYPE_LOSS_ANALYSIS && ! empty($data['current_deal_stage'])) {\n throw new InvalidArgumentException('Current deal stage is not applicable for Loss Analysis reports');\n }\n\n return $reportData;\n }\n\n // transform uuid to id\n private function validatePlaybookCategories(array $data, array $reportData, Team $team): array\n {\n $key = 'playbook_categories';\n\n if (isset($data[$key])) {\n $payloadIds = $data[$key];\n $ids = [];\n\n foreach ($payloadIds as $uuid) {\n $uuid = (string) $uuid;\n\n try {\n $playbookCategory = $this->playbookCategoryRepository->findByUuid($uuid);\n } catch (Throwable $throwable) {\n Log::error(__METHOD__ . ' ' . $throwable->getMessage());\n\n throw new InvalidArgumentException(sprintf('Playbook category %s not found', $uuid));\n }\n\n if (! $playbookCategory) {\n throw new InvalidArgumentException(sprintf('Playbook category %s not found', $uuid));\n }\n\n if (! $playbookCategory->hasPlaybook()) {\n throw new InvalidArgumentException(sprintf('Playbook category %s has no playbook', $uuid));\n }\n\n if ($playbookCategory->getPlaybook()->getTeamId() !== $team->getId()) {\n throw new InvalidArgumentException(\n sprintf('Playbook category %s not found for team %s', $uuid, $team->getUuid())\n );\n }\n\n $ids[] = $playbookCategory->getId();\n }\n\n $reportData[$key] = $ids;\n }\n\n return $reportData;\n }\n\n private function validateReportStatus($status): bool\n {\n if (! in_array($status, [true, false], true)) {\n throw new InvalidArgumentException('Report status is invalid');\n }\n\n return $status;\n }\n\n private function validateReportType($type): string\n {\n if (! in_array($type, self::getTypes(), true)) {\n throw new InvalidArgumentException(sprintf('Report type is invalid: %s', $type));\n }\n\n return $type;\n }\n\n private function validateFrequency($frequency): string\n {\n if (! in_array($frequency, self::getFrequencies(), true)) {\n throw new InvalidArgumentException('Frequency is invalid');\n }\n\n return $frequency;\n }\n\n private function validateAdditionalPromptInput(?string $additionalPromptInput): ?string\n {\n if ($additionalPromptInput && strlen($additionalPromptInput) > 5000) {\n throw new InvalidArgumentException('Additional Prompt Input should be less than 5000 characters');\n }\n\n return $additionalPromptInput;\n }\n\n private function validateCustomReportName(?string $customReportName): ?string\n {\n if ($customReportName === null || $customReportName === '') {\n return null;\n }\n\n if (strlen($customReportName) > 70) {\n throw new InvalidArgumentException('Custom report name should be less than 70 characters');\n }\n\n return $customReportName;\n }\n\n private function validateOrganization(?string $organizationUuid): Team\n {\n if (! $organizationUuid) {\n throw new InvalidArgumentException('Organization is required');\n }\n\n $team = $this->teamRepository->idOrUuid($organizationUuid);\n\n if (! $team) {\n throw new InvalidArgumentException('Organization not found');\n }\n\n if (! $team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {\n throw new InvalidArgumentException('Organization does not have the Automated Reports feature');\n }\n\n return $team;\n }\n\n private function validateAndGetGroupIds(Team $team, array $teamUuids): array\n {\n $groupIds = [];\n\n foreach ($teamUuids as $uuid) {\n $group = $this->groupRepository->findByUuid($uuid);\n\n if ($group === null || $group->getTeamId() !== $team->getId()) {\n throw new InvalidArgumentException(\n sprintf('Group %s not found for team %s', $uuid, $team->getUuid())\n );\n }\n\n $groupIds[] = $group->getId();\n\n }\n\n return $groupIds;\n }\n\n private function validateAndGetDealStageIds(Team $team, array $stageUuids, string $propertyLabel): array\n {\n $stageIds = [];\n\n foreach ($stageUuids as $uuid) {\n $stage = $this->stageRepository->findByUuid($uuid);\n\n if ($stage === null || $stage->getTeamId() !== $team->getId()) {\n throw new InvalidArgumentException(\n sprintf('Stage %s not found for team %s for %s', $uuid, $team->getUuid(), $propertyLabel)\n );\n }\n\n $stageIds[] = $stage->getId();\n }\n\n return $stageIds;\n }\n\n private function validateAndGetUserIds(array $userUuids, callable $teamCheck): array\n {\n if (empty($userUuids)) {\n return [];\n }\n\n $userIds = [];\n\n foreach ($userUuids as $uuid) {\n $user = $this->userRepository->findByUuid($uuid);\n\n if (! $user || ! $user->isStatusActive()) {\n throw new InvalidArgumentException(\n sprintf('User %s not found or is not active', $uuid)\n );\n }\n\n if (! $teamCheck($user)) {\n throw new InvalidArgumentException(\n sprintf('User %s does not belong to the allowed team(s)', $uuid)\n );\n }\n\n $userIds[] = $user->getId();\n }\n\n return $userIds;\n }\n\n private function validateAndGetUserIdsByTeam(Team $team, array $userUuids): array\n {\n return $this->validateAndGetUserIds($userUuids, fn ($user) => $user->getTeamId() === $team->getId());\n }\n\n private function validateAndGetJiminnyUserIds(array $userUuids): array\n {\n $allowedTeamIds = config('kiosk.teamIds', []);\n\n return $this->validateAndGetUserIds($userUuids, fn ($user) => in_array($user->getTeamId(), $allowedTeamIds, true));\n }\n\n private function parseDate(string $dateString): string\n {\n return date('Y-m-d H:i:s', strtotime($dateString));\n }\n\n private function generateReportResultViewUrl(AutomatedReportResult $result): string\n {\n $mediaResource = $this->getReportMediaRouteResource($result);\n\n return route('ai-reports.' . $mediaResource . '.view', ['uuid' => $result->getUuid()]);\n }\n\n private function generateReportResultDownloadUrl(AutomatedReportResult $result): string\n {\n $mediaResource = $this->getReportMediaRouteResource($result);\n\n return route('ai-reports.' . $mediaResource . '.download', ['uuid' => $result->getUuid()]);\n }\n\n private function getReportMediaRouteResource(AutomatedReportResult $result): string\n {\n if ($result->getMediaType() === self::MEDIA_TYPE_PDF) {\n return self::PDF_KEY;\n } elseif ($result->getMediaType() === self::MEDIA_TYPE_PODCAST) {\n return self::AUDIO_KEY;\n }\n\n throw new \\InvalidArgumentException('Unknown media type.');\n }\n\n public function getMediaPath(AutomatedReportResult $result): ?string\n {\n $url = match ($result->getMediaType()) {\n self::MEDIA_TYPE_PDF => $result->getPdfUrl(),\n self::MEDIA_TYPE_PODCAST => $result->getPodcastAudioUrl(),\n default => null,\n };\n\n if ($url === null) {\n return null;\n }\n\n $path = parse_url(trim($url, '\"\\''), PHP_URL_PATH);\n\n return $path ?: null;\n }\n\n public function getFilenameSuffix(AutomatedReportResult $result): ?string\n {\n return match ($result->getMediaType()) {\n self::MEDIA_TYPE_PODCAST => 'Podcast',\n default => null,\n };\n }\n\n public function getMailSubjectSuffix(AutomatedReportResult $result): string\n {\n return match ($result->getMediaType()) {\n self::MEDIA_TYPE_PDF => 'report',\n self::MEDIA_TYPE_PODCAST => 'podcast',\n default => '',\n };\n }\n\n public function getMediaTypeMetadata(AutomatedReportResult $result): array\n {\n return match ($result->getMediaType()) {\n self::MEDIA_TYPE_PODCAST => ['extension' => 'mp3', 'mime' => 'audio/mpeg'],\n self::MEDIA_TYPE_PDF => ['extension' => 'pdf', 'mime' => 'application/pdf'],\n default => ['extension' => null, 'mime' => null],\n };\n }\n\n public function deleteS3Files(AutomatedReportResult $result): void\n {\n $teamUuid = $result->getReport()->getTeam()->getUuid();\n $reportUuid = $result->getUuid();\n\n // delete all files for a report uuid no mather of pdf, podcast, or both\n // in case of both - the podcast files are linked to the pdf (parent) uuid\n // pdf and podcast date times should be close\n $path = sprintf('%s/%s/%s', $teamUuid, self::S3_DIR, $reportUuid);\n\n foreach (self::FILE_EXTENSIONS_VARIANTS as $extension) {\n $file = $path . '.' . $extension;\n\n if (Storage::exists($file)) {\n Storage::delete($file);\n Log::info('[Reports] Deleted S3 file', [\n 'path' => $file,\n ]);\n }\n }\n\n foreach (self::FILE_PODCAST_EXTENSIONS_VARIANTS as $extension) {\n $file = $path . '_podcast.' . $extension;\n\n if (Storage::exists($file)) {\n Storage::delete($file);\n Log::info('[Reports] Deleted Podcast S3 file', [\n 'path' => $file,\n ]);\n }\n }\n }\n\n /**\n *\n * @param int|null $teamId Optional team ID to filter results\n *\n * @return Collection<int, int> Collection of team IDs\n */\n public function getTeamIdsWithReportsResults(?int $teamId = null): Collection\n {\n return $this->automatedReportsRepository->getTeamIdsWithReportsResults($teamId);\n }\n\n /**\n * Core delete logic for report results using a query\n *\n * @param Builder $query\n * @param array $logContext\n *\n * @return int\n */\n private function deleteReportResultsByQuery(Builder $query, array $logContext = []): int\n {\n $deletedCount = 0;\n\n if ($query->exists()) {\n Log::info(\n 'Run delete report results',\n array_merge(\n $logContext,\n [\n 'service' => 'AutomatedReportsService',\n ]\n )\n );\n\n $query->chunkById(50, function ($results) use (&$deletedCount, $logContext) {\n foreach ($results as $result) {\n $this->deleteReportResult($result);\n $deletedCount++;\n\n Log::info(\n 'Deleted a report result',\n array_merge(\n $logContext,\n [\n 'result_id' => $result->getId(),\n 'report_id' => $result->getReportId(),\n ]\n )\n );\n }\n });\n }\n\n return $deletedCount;\n }\n\n /**\n * Delete report results for a team by retention period\n *\n * @param Team $team\n * @param CarbonImmutable $retentionDate\n *\n * @return int Number of deleted report results\n */\n public function deleteReportsResultsInRetentionPeriod(Team $team, CarbonImmutable $retentionDate): int\n {\n $reportIds = $this->automatedReportsRepository->getReportIdsByTeam($team);\n\n if ($reportIds->isEmpty()) {\n return 0;\n }\n\n $query = $this->automatedReportsRepository\n ->getReportResultsQueryForRetention($team, $retentionDate);\n\n return $this->deleteReportResultsByQuery($query, [\n 'team_id' => $team->getId(),\n 'retention_date' => $retentionDate->toDateTimeString(),\n ]);\n }\n\n /**\n * Delete ALL report results for a specific automated report\n *\n * @param string $uuid\n *\n * @return int\n */\n public function deleteReportResults(string $uuid): int\n {\n $report = $this->getReport($uuid);\n\n $query = $this->automatedReportsRepository->getResultsByReportQuery($report);\n\n return $this->deleteReportResultsByQuery($query, [\n 'report_uuid' => $uuid,\n 'report_id' => $report->getId(),\n ]);\n }\n\n public function deleteReportResult(AutomatedReportResult $result): void\n {\n $this->deleteS3Files($result);\n\n $result->delete();\n }\n\n /**\n * Get all reports for a specific team\n *\n * @param Team $team\n *\n * @return \\Illuminate\\Database\\Eloquent\\Collection\n */\n public function getTeamReports(Team $team): \\Illuminate\\Database\\Eloquent\\Collection\n {\n return $this->automatedReportsRepository->getReportsByTeam($team);\n }\n\n /**\n * Get all report results for a specific report\n *\n * @param AutomatedReport $report\n *\n * @return \\Illuminate\\Database\\Eloquent\\Collection\n */\n public function getReportResults(AutomatedReport $report): \\Illuminate\\Database\\Eloquent\\Collection\n {\n return $this->automatedReportsRepository->getResultsByReport($report);\n }\n\n public function deleteAllReportResults(AutomatedReport $report): void\n {\n $results = $this->getReportResults($report);\n\n /** @var AutomatedReportResult $result */\n foreach ($results as $result) {\n Log::info('Deleting result', [\n 'report' => $report->getId(),\n 'result' => $result->getId(),\n ]);\n\n $this->deleteReportResult($result);\n }\n }\n\n public function deleteAllData(Team $team): void\n {\n Log::info('Deleting automated report and results for team', [\n 'team' => $team->getId(),\n ]);\n\n $reports = $this->getTeamReports($team);\n\n /** @var AutomatedReport $report */\n foreach ($reports as $report) {\n Log::info('Deleting report', [\n 'team' => $team->getId(),\n 'report' => $report->getId(),\n ]);\n\n $this->deleteAllReportResults($report);\n\n $report->delete();\n }\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":true,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"Project","depth":3,"role_description":"text"},{"role":"AXButton","text":"Project","depth":3,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"New File or Directory…","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Expand Selected","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Collapse All","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Options","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false}]...
|
3397592283435315795
|
6686367547760219213
|
idle
|
accessibility
|
NULL
|
Project: faVsco.js, menu
#11894 on JY-18909-automa Project: faVsco.js, menu
#11894 on JY-18909-automated-reports-ask-jiminny, menu
Start Listening for PHP Debug Connections
AutomatedReportsCommandTest
Run 'AutomatedReportsCommandTest'
Debug 'AutomatedReportsCommandTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Execute
Explain Plan
Browse Query History
View Parameters
Open Query Execution Settings…
In-Editor Results
Tx: Auto
Cancel Running Statements
Playground
jiminny
Sync Changes
Hide This Notification
Code changed:
Hide
16
13
13
Previous Highlighted Error
Next Highlighted Error
SELECT * FROM teams WHERE id = 1;
select * from crm_layouts where crm_configuration_id = 39;
SELECT * FROM crm_layout_entities WHERE crm_layout_id = 283;
SELECT * FROM crm_fields WHERE id = 2234;
SELECT * FROM crm_field_values WHERE crm_field_id = 2234;
select * from crm_profiles where user_id = 143;
select * from record_types where crm_configuration_id = 39; # 0121K000001MHElQAO,0121K000001MHEqQAO
select * from business_processes where crm_configuration_id = 39;
# 01941000000H669AAC, 01941000000H66JAAS
select * from record_type_field_values
where record_type_id IN (24);
select * from crm_field_values where id IN (2730);
select * from crm_configurations where id = 39;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 1
and sa.provider = 'salesforce'; #1035
select * from users where team_id = 1; # 222 group 3
SELECT * FROM activities WHERE user_id = 222 order by id desc;
select * from sidekick_settings where team_id = 1;
select * from teams where id = 1;
select * from team_features where team_id = 1;
select * from activities where crm_configuration_id = 2
and provider = 'ms-teams' and id = 608765;
SELECT * FROM activities WHERE crm_configuration_id = 2 and crm_provider_id = '59523413338';
select * from sidekick_settings where team_id = 2;
SELECT * FROM activities WHERE id = 608660;
select * from activity_summary_logs where activity_id = 608660;
select * from ai_prompts where transcription_id = 11214;
# [PASSWORD_DOTS]
SELECT * FROM activities WHERE uuid_to_bin('ed78a437-2804-450e-ab2f-56ab1c641346') = uuid;
# id: 608818, crm: 59628809737
SELECT * FROM activities WHERE uuid_to_bin('36b06e55-afdd-4782-8dee-c624cd0af191') = uuid;
# id: 608821, crm: 59632069252
SELECT ce.start_time, ce.end_time, a.id, a.uuid, crm_provider_id, calendar_event_id, title,
playbook_category_id, user_id, lead_id, contact_id, account_id, opportunity_id,
scheduled_start_time, scheduled_end_time, actual_start_time, actual_end_time, a.created_at
FROM activities a
join calendar_events ce on a.calendar_event_id = ce.id
WHERE a.id IN (608818, 608821);
select * from users where team_id = 1;
select * from team_settings where team_id = 1;
select * from crm_profiles where crm_configuration_id = 39 order by user_id;
select * from team_features where team_id = 1;
select * from users where team_id = 2;
SELECT * FROM activities WHERE uuid_to_bin('ec7647e9-5225-458b-b475-f31aa2769204') = uuid; # 612639
# Preslava N. Ivanova, grou id 3
SELECT * FROM opportunities WHERE uuid_to_bin('a2928fe5-aec5-46cb-85d9-7654c89e46a6') = uuid;
select * from activities where opportunity_id = 344 and actual_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00';
select
a.id,
a.type,
a.scheduled_start_time,
a.actual_start_time,
a.created_at,
a.opportunity_id,
a.status
FROM activities a
WHERE opportunity_id = 344
and status IN ('completed', 'received', 'delivered')
and (
(a.actual_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00')
OR (a.created_at between '2024-10-11 00:00:00' and '2024-10-12 00:00:00')
OR (a.scheduled_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00'))
;
SELECT * FROM users WHERE id = 222;
SELECT * FROM crm_profiles WHERE user_id = 222;
select * from crm_layouts where crm_configuration_id = 39;
SELECT * FROM crm_layout_entities WHERE crm_layout_id = 281;
select * from group_deal_risk_types;
select * from opportunities where team_id = 1;
SELECT * FROM opportunities WHERE id = 315;
SELECT * FROM crm_field_data WHERE object_id = 315;
select * from crm_field_data where object_id = 260;
select * from generic_ai_prompts where subject_id = 315;
select * from teams; # 36, 21, 121, [EMAIL]
SELECT * FROM social_accounts WHERE sociable_id = 121 and provider = 'bullhorn';
# [PASSWORD_DOTS]
select * from teams where id = 1;
select * from crm_configurations where id = 39;
select * from users where team_id = 1;
select u.email, cp.* from users u
join crm_profiles cp on u.id = cp.user_id
where u.team_id = 1;
# 1 - 00541000004281rAAA
# 204 - 0052g000003freeAAA
# 429 - 0052g000003qGOiAAM
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 1
and sa.provider = 'salesforce';
select * from activities where type = 'softphone'
and created_at > '2024-12-11 15:24:36' order by id desc;
select * from activity_providers where team_id = 1;
select * from activity_provider_users where activity_provider_id = 328;
select * from opportunities where crm_configuration_id = 39
AND account_id = 178 AND is_closed = false
order by created_at DESC;
select * from contacts where id = 3952;
select * from accounts where id = 178;
# [PASSWORD_DOTS]
select * from teams where id = 36;
select * from crm_configurations where id = 21;
select * from users where team_id = 36;
select u.email, cp.* from users u
join crm_profiles cp on u.id = cp.user_id
where u.team_id = 36;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 36
and sa.provider = 'bullhorn';
select * from social_accounts where id = 348;
UPDATE social_accounts SET
provider_user_token = '21442_6802599_91:41179a58-21e7-4d7c-ad58-56bb666b2f65',
provider_refresh_token = '21442_6802599_91:01c6b335-3f2a-42e4-85ff-8a08fa65fceb',
expires = 1733998131,
state = 'connected'
WHERE id = 348;
# [PASSWORD_DOTS]
select * from teams where id = 31;
select * from crm_configurations where id = 18;
select * from users where team_id = 31; # 257
select u.email, cp.* from users u
join crm_profiles cp on u.id = cp.user_id
where u.team_id = 31;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 31
and sa.provider = 'close';
select * from contacts where crm_configuration_id = 18;
# [PASSWORD_DOTS] NEPTUNE [PASSWORD_DOTS]
select * from teams;
select * from users where id IN (1030, 1035, 1052);
select * from crm_configurations;
select * from users where team_id = 65; # 257
select * from team_settings where team_id = 65; # 257
select * from invitations where team_id = 65; # 257
select * from users where email = '[EMAIL]'; # 257
select u.email, cp.* from users u
join crm_profiles cp on u.id = cp.user_id
where u.team_id = 65;
select * from crm_configurations where id = 53;
select * from accounts where crm_configuration_id = 53 order by id desc;
select * from leads where crm_configuration_id = 53 order by id desc;
select * from contacts where crm_configuration_id = 53 order by id desc;
select * from opportunities where crm_configuration_id = 53 order by id desc;
select * from crm_profiles where crm_configuration_id = 53 order by id desc;
select * from crm_fields where crm_configuration_id = 53 order by id desc;
select * from crm_field_values where crm_field_id = 3341 order by id desc;
select * from crm_layouts where crm_configuration_id = 53 order by id desc;
select * from stages where crm_configuration_id = 53 order by id desc;
select * from crm_profiles where crm_configuration_id = 13;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 65
and sa.provider = 'integration-app';
select * from contacts where crm_configuration_id = 13;
select * from social_accounts where sociable_id = 283;
SELECT * FROM opportunities WHERE crm_provider_id = '006O400000E9bzeIAB';
select * from activity_providers where team_id = 65;
SELECT * FROM activities WHERE crm_configuration_id IN (51, 52, 53);
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 65
;
# [PASSWORD_DOTS] STAGING [PASSWORD_DOTS]
SELECT * FROM teams;
SELECT * FROM teams WHERE id = 88;
SELECT * FROM teams WHERE id = 89;
select * from team_settings where team_id = 89;
SELECT * FROM users WHERE team_id = 89;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 89;
select * from users;
SELECT * FROM social_accounts WHERE sociable_id = 1761;
SELECT * FROM crm_configurations WHERE id = 70;
select * from accounts where crm_configuration_id = 70 order by id desc;
select * from leads where crm_configuration_id = 70 order by id desc;
select * from contacts where crm_configuration_id = 70 order by id desc;
select * from opportunities where crm_configuration_id = 70 order by id desc;
select * from crm_profiles where crm_configuration_id = 70 order by id desc;
select * from crm_fields where crm_configuration_id = 70 order by id desc;
select * from crm_field_values where crm_field_id = 3536 order by id desc;
select * from crm_layouts where crm_configuration_id = 70 order by id desc;
select * from stages where crm_configuration_id = 70 order by id desc;
select * from business_processes where crm_configuration_id = 70 order by id desc;
select * from business_process_stages where business_process_id = 34;
select * from contacts where id = 10468;
select * from crm_layouts where crm_configuration_id = 70;
SELECT * FROM crm_layout_entities WHERE crm_layout_id = 388;
SELECT * FROM crm_fields WHERE id IN (3533,3534,3535);
select * from activities where crm_configuration_id = 70
and (account_id IS NOT NULL or lead_id IS NOT NULL or contact_id IS NOT NULL or opportunity_id IS NOT NULL) order by id desc;
SELECT * FROM activities WHERE uuid_to_bin('2e10b60f-8a61-41c5-a3d4-28835353dc65') = uuid;
SELECT * FROM activities where crm_configuration_id = 69 ;
SELECT * FROM users WHERE email LIKE '%[EMAIL]%';
SELECT * FROM activities WHERE uuid_to_bin('5a150c93-40fc-42ec-b3bd-c1d328e09f6e') = uuid;
SELECT * FROM opportunities WHERE id = 385;
select * from participants p
join activities a on p.activity_id = a.id
where a.crm_configuration_id = 70
and (p.lead_id IS NOT NULL or p.contact_id IS NOT NULL);
SELECT * FROM participants WHERE id = 1013638;
select * from teams where id = 90;
select * from users where team_id = 90;
select * from social_accounts where social_accounts.sociable_id IN (1960,1760);
SELECT * FROM crm_profiles WHERE crm_configuration_id = 71;
select * from invitations where team_id = 90;
select * from crm_configurations where id = 71;
select * from accounts where crm_configuration_id = 71 order by id desc;
select * from leads where crm_configuration_id = 71 order by id desc;
select * from contacts where crm_configuration_id = 71 order by id desc;
select * from opportunities where crm_configuration_id = 71 order by id desc;
select * from crm_profiles where crm_configuration_id = 71 order by id desc;
select * from crm_fields where crm_configuration_id = 71 order by id desc;
select * from crm_field_values where crm_field_id = 3341 order by id desc;
select * from crm_layouts where crm_configuration_id = 71 order by id desc;
select * from stages where crm_configuration_id = 71 order by id desc;
select * from users order by secondary_email desc;
select u.id, u.email, u.status, sa.id, sa.provider_user_id from social_accounts sa
join users u on sa.sociable_id = u.id
where sa.provider = 'google' and u.email LIKE 'aneliya%';
select * from failed_jobs order by id desc;
select * from users where email = '[EMAIL]' or secondary_email = '[EMAIL]';
select * from teams;
SELECT * FROM crm_profiles WHERE crm_configuration_id = 39;
SELECT * FROM crm_fields WHERE crm_configuration_id = 39 and object_type = 'task';
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 1
and sa.provider = 'salesforce';
# [PASSWORD_DOTS]
SELECT * FROM activities WHERE uuid_to_bin('c38b3895-fd0f-4b1f-9fb2-c170dba137c6') = uuid;
SELECT * FROM crm_configurations WHERE id = 70;
select * from teams where id = 1;
select * from groups where team_id = 1;
select * from users where team_id = 1;
select o.id, o.name,o.close_date, u.id, u.name, u.group_id, r.id, r.display_name, g.name, g.scope from opportunities o
join users u on o.user_id = u.id
join groups g on u.group_id = g.id
join role_user ru on u.id = ru.user_id
join roles r on ru.role_id = r.id
where o.crm_configuration_id = 39 and close_date > '2024-01-01 00:00:00';
select * from role_user where user_id = 143;
select * from roles;
select * from role_user;
select * from groups where id = 9;
select * from scope_groups where group_id = 9;
# [PASSWORD_DOTS]
select * from teams where id = 36;
select * from crm_configurations;
SELECT * FROM social_accounts WHERE sociable_id = 121;
[URL_WITH_CREDENTIALS] this will add filter, however if we need to control feature by FF we need conditional logic
public const array TYPES = [
['id' => 'exec_summary', 'name' => 'Exec Summary'],
['id' => 'coaching_profiles', 'name' => 'Coaching Profiles'],
['id' => 'product_feedback', 'name' => 'Product Feedback'],
['id' => self::TYPE_LOSS_ANALYSIS, 'name' => 'Loss Analysis'],
// ['id' => 'questions', 'name' => 'Questions'],
// ['id' => 'statistical_quant', 'name' => 'Statistical Quantitative'],
];
public const array ALL_TYPES = [
...self::TYPES,
['id' => self::TYPE_ASK_JIMINNY, 'name' => 'Ask Jiminny'],
];
public const string FREQUENCY_DAILY = 'daily';
public const string FREQUENCY_WEEKLY = 'weekly';
public const string FREQUENCY_MONTHLY = 'monthly';
public const string FREQUENCY_QUARTERLY = 'quarterly';
public const string FREQUENCY_ONE_OFF = 'one_off';
/**
* Frequencies for standard (non-Ask Jiminny) reports.
*/
public const array FREQUENCIES = [
['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],
['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],
['id' => self::FREQUENCY_QUARTERLY, 'name' => 'Quarterly'],
['id' => self::FREQUENCY_ONE_OFF, 'name' => 'One-off'],
];
/**
* Frequencies for Ask Jiminny reports.
*/
public const array ASK_JIMINNY_FREQUENCIES = [
['id' => self::FREQUENCY_DAILY, 'name' => 'Daily'],
['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],
['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],
];
public const string MEDIA_TYPE_PDF = 'pdf';
public const string MEDIA_TYPE_PODCAST = 'podcast';
public const array MEDIA_TYPES = [self::MEDIA_TYPE_PDF, self::MEDIA_TYPE_PODCAST];
public const array MEDIA_TYPE_OBJECT_PDF = ['id' => self::MEDIA_TYPE_PDF, 'name' => 'PDF'];
public const array MEDIA_TYPE_OBJECT_PODCAST = ['id' => self::MEDIA_TYPE_PODCAST, 'name' => 'Podcast'];
public const array MEDIA_TYPE_OBJECTS = [self::MEDIA_TYPE_OBJECT_PDF, self::MEDIA_TYPE_OBJECT_PODCAST];
public const array CALL_TYPE_CONFERENCE = ['id' => 'conference', 'name' => 'Conference'];
public const array CALL_TYPE_DIALER = ['id' => 'dialer', 'name' => 'Dialer'];
public const int SENT_REPORT_AT_HOURS = 5;
public const string PDF_KEY = 'pdf';
public const string AUDIO_KEY = 'audio';
private const array ALL_FREQUENCIES = [
['id' => self::FREQUENCY_DAILY, 'name' => 'Daily'],
['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],
['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],
['id' => self::FREQUENCY_QUARTERLY, 'name' => 'Quarterly'],
['id' => self::FREQUENCY_ONE_OFF, 'name' => 'One-off'],
];
private const string S3_DIR = 'reports';
private const array FILE_EXTENSIONS_VARIANTS = ['html', 'MD', 'pdf'];
private const array FILE_PODCAST_EXTENSIONS_VARIANTS = ['json', 'mp3', 'ssml'];
public function __construct(
private readonly TeamRepository $teamRepository,
private readonly GroupRepository $groupRepository,
private readonly UserRepository $userRepository,
private readonly StageRepository $stageRepository,
private readonly DealStagesService $dealStagesService,
private readonly RecipientsService $recipientsService,
private readonly AutomatedReportsRepository $automatedReportsRepository,
private readonly Webhook $webhookService,
private readonly BusDispatcher $dispatcher,
private readonly ActivityTypeService $activityTypeService,
private readonly PlaybookCategoryRepository $playbookCategoryRepository,
private readonly AskAnythingPromptService $askAnythingPromptService,
private readonly SearchRepository $activitySearchRepository,
private readonly AskAnythingRepository $askAnythingRepository,
) {
}
public static function getTypes(): array
{
$types = self::TYPES;
return array_map(static function ($type) {
return $type['id'];
}, $types);
}
public static function getCallTypes(): array
{
return array_map(static function ($callType) {
return $callType['id'];
}, [self::CALL_TYPE_CONFERENCE, self::CALL_TYPE_DIALER]);
}
public static function getFrequencies(): array
{
return array_map(static function ($frequency) {
return $frequency['id'];
}, self::FREQUENCIES);
}
// front-facing structure
public function getReportEnabledFieldData(bool $value = false): array
{
return [
'id' => 'report_enabled',
'label' => '',
'inputType' => InputTypeEnum::TOGGLE,
'value' => $value,
];
}
// Organizations = Teams
public function getOrganizationFieldData(?string $value = null, bool $shortVersion = false): array
{
$options = $this->getTeams();
if ($shortVersion) {
return [
'id' => 'organization',
'label' => 'Organization',
'options' => $options,
];
}
return [
'id' => 'organization',
'label' => 'Organization',
'inputType' => InputTypeEnum::DROPDOWN,
'required' => true,
'placeholder' => 'Select',
'options' => $options,
'value' => $value,
'dependencies' => [
'teams',
'deal_stage_at_call',
'current_deal_stage',
'recipients',
ActivityTypeService::PLAYBOOK_CATEGORIES_KEY,
],
'dependsOn' => [],
];
}
// Teams = Groups
public function getTeamFieldData(array $options = [], array $value = [], bool $shortVersion = false): array
{
if ($shortVersion) {
return [
'id' => 'teams',
'label' => 'Team',
'options' => $options,
];
}
return [
'id' => 'teams',
'label' => 'Team',
'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,
'required' => false,
'placeholder' => 'Select',
'options' => $options,
'value' => $value, // value should be an array of objects {id, name}
'dependencies' => [ActivityTypeService::PLAYBOOK_CATEGORIES_KEY],
'dependsOn' => [],
];
}
public function getReportTypeFieldData(?string $value = null, bool $shortVersion = false, ?Team $team = null): array
{
$types = [];
if ($team instanceof Team) {
if ($team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {
$types = self::TYPES;
}
if ($team->hasFeature(FeatureEnum::ASK_JIMINNY_REPORTS)) {
$types[] = ['id' => self::TYPE_ASK_JIMINNY, 'name' => 'Ask Jiminny'];
}
} else {
$types = self::TYPES;
}
if ($shortVersion) {
return [
'id' => 'report_type',
'label' => 'Report Type',
'options' => $types,
];
}
return [
'id' => 'report_type',
'label' => 'Report Type',
'inputType' => InputTypeEnum::DROPDOWN,
'required' => true,
'placeholder' => 'Select',
'options' => $types,
'value' => $value,
'dependencies' => [],
'dependsOn' => [],
];
}
public function getFrequencyFieldData(?string $value = null): array
{
return [
'id' => 'frequency',
'label' => 'Frequency',
'inputType' => InputTypeEnum::DROPDOWN,
'required' => true,
'placeholder' => 'Select',
'options' => self::FREQUENCIES,
'value' => $value,
'dependencies' => ['period'],
'dependsOn' => [],
];
}
public function getPeriodFieldData(?string $valueStartDate = null, ?string $valueEndDate = null): array
{
return [
'id' => 'period',
'label' => 'Select one-off period',
'inputType' => InputTypeEnum::DATE_RANGE,
'required' => true,
'placeholder' => 'Select',
'value' => ['startDate' => $valueStartDate, 'endDate' => $valueEndDate],
'queryParams' => [
'startDate' => 'start_date_period',
'endDate' => 'end_date_period',
],
'dependencies' => [],
'dependsOn' => ['frequency'],
];
}
public function getActivityTypesFieldData(?Team $team = null, array $value = [], array $teamsFilter = []): array
{
return $this->activityTypeService->getActivityTypeFieldData(team: $team, value: $value, groupIds: $teamsFilter);
}
public function getDealStageAtCallFieldData(?Team $team = null, array $value = []): array
{
return $this->dealStagesService->getDealStageAtCallFieldData(team: $team, value: $value);
}
public function getCurrentDealStageFieldData(?Team $team = null, array $value = []): array
{
return $this->dealStagesService->getCurrentDealStageFieldData(team: $team, value: $value);
}
public function getDealValueFieldData(?int $valueMin = null, ?int $valueMax = null): array
{
return [
'id' => 'deal_value',
'label' => 'Deal Value',
'inputType' => InputTypeEnum::INTEGER_RANGE,
'required' => false,
'value' => ['min' => $valueMin, 'max' => $valueMax],
'queryParams' => [
'min' => 'min_deal_value',
'max' => 'max_deal_value',
],
'dependencies' => [],
'dependsOn' => [],
];
}
public function getCallTypeFieldData(bool $conferenceOn = false, bool $dialerOn = false): array
{
$value = [];
$conferenceOn && $value[] = self::CALL_TYPE_CONFERENCE;
$dialerOn && $value[] = self::CALL_TYPE_DIALER;
return [
'id' => 'call_type',
'label' => 'Call Type',
'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,
'required' => true,
'options' => [
self::CALL_TYPE_CONFERENCE,
self::CALL_TYPE_DIALER,
],
'value' => $value,
'dependencies' => [],
'dependsOn' => [],
];
}
public function getMediaTypeFieldData(?AutomatedReport $report = null): array
{
$value = [];
if ($report) {
$value = $this->transformMediaTypes($report);
}
return [
'id' => 'media_types',
'label' => 'Export as',
'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,
'required' => true,
'options' => self::MEDIA_TYPE_OBJECTS,
'value' => $value,
'dependencies' => [],
'dependsOn' => [],
];
}
public function getCallDurationFieldData(?int $valueMin = null, ?int $valueMax = null): array
{
return [
'id' => 'call_duration',
'label' => 'Call Duration',
'inputType' => InputTypeEnum::INTEGER_RANGE,
'required' => false,
'value' => ['min' => $valueMin, 'max' => $valueMax],
'queryParams' => [
'min' => 'min_call_duration',
'max' => 'max_call_duration',
],
'dependencies' => [],
'dependsOn' => [],
];
}
public function getRecipientsFieldData(?Team $team = null, array $value = []): array
{
return $this->recipientsService->getRecipientsFieldData(team: $team, value: $value);
}
public function getJiminnyRecipientsFieldData(array $value = []): array
{
return $this->recipientsService->getJiminnyRecipientsFieldData($value);
}
public function getAdditionalPromptInputFieldData(?string $value = null): array
{
return [
'id' => 'additional_prompt_input',
'label' => 'Special requirements',
'inputType' => InputTypeEnum::TEXTAREA,
'required' => false,
'placeholder' => 'What should be the focus of the report?',
'value' => $value,
'dependencies' => [],
'dependsOn' => [],
];
}
public function getCustomReportNameFieldData(?string $value = null): array
{
return [
'id' => 'custom_name',
'label' => 'Custom report name',
'inputType' => InputTypeEnum::TEXT,
'required' => false,
'placeholder' => 'Enter custom name',
'value' => $value,
'dependencies' => [],
'dependsOn' => [],
];
}
// data providers
public function getTeams(): array
{
$teams = $this->teamRepository->getTeamsForKiosk(status: Team::STATUS_ACTIVE);
$teamData = [];
foreach ($teams as $team) {
if (! $team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {
continue;
}
$teamData[] = $this->transformTeam($team);
}
return $teamData;
}
public function getTeamGroups(string $teamUuid): array
{
$data = [];
$team = $this->getTeam($teamUuid);
if ($team !== null) {
$groups = $team->groups()->get();
foreach ($groups as $group) {
$data[] = [
'id' => $group->getUuid(),
'name' => $group->getName(),
];
}
}
return $data;
}
public function getTeamsGroupsOptions(array $filterTeamUuids = []): array
{
$data = [];
$teams = $this->getTeams();
foreach ($teams as $team) {
if (! empty($filterTeamUuids) && ! in_array($team['id'], $filterTeamUuids, true)) {
continue;
}
$data[] = [
'label' => $team['name'],
'groups' => $this->getTeamGroups($team['id']),
];
}
return $data;
}
public function getTeam(string $teamUuid): ?Team
{
return $this->teamRepository->idOrUuid($teamUuid);
}
public function getTeamById(int $teamId): ?Team
{
return $this->teamRepository->find($teamId);
}
public function getGroupsUuids(AutomatedReport $report): array
{
$uuids = [];
$reportGroups = $report->getGroups();
foreach ($reportGroups as $groupId) {
if ($group = $this->groupRepository->find($groupId)) {
$uuids[] = $group->getUuid();
}
}
return $uuids;
}
public function getPlaybookCategoriesUuids(AutomatedReport $report): array
{
$uuids = [];
$playbookCategories = $report->getPlaybookCategories();
foreach ($playbookCategories as $id) {
if ($category = $this->playbookCategoryRepository->find($id)) {
$uuids[] = $category->getUuid();
}
}
return $uuids;
}
public function getDealAtCallStagesUuids(AutomatedReport $report): array
{
$uuids = [];
$reportStages = $report->getDealAtCallStages();
foreach ($reportStages as $id) {
if ($stage = $this->stageRepository->find($id)) {
$uuids[] = $stage->getUuid();
}
}
return $uuids;
}
public function getCurrentDealStagesUuids(AutomatedReport $report): array
{
$uuids = [];
$reportStages = $report->getCurrentDealStages();
foreach ($reportStages as $id) {
if ($stage = $this->stageRepository->find($id)) {
$uuids[] = $stage->getUuid();
}
}
return $uuids;
}
public function getUsersUuids(AutomatedReport $report): array
{
return $this->extractUserUuids($report->getRecipients());
}
public function getJiminnyUsersUuids(AutomatedReport $report): array
{
return $this->extractUserUuids($report->getJiminnyRecipients());
}
/**
* @param array<string, mixed> $recipients
*/
private function extractUserUuids(array $recipients): array
{
$userIds = $recipients['users'] ?? [];
return collect($userIds)
->map(fn ($id) => $this->userRepository->find((int) $id))
->filter()
->map(fn (UserContract $user) => $user->getUuid())
->values()
->all();
}
// get mail data
public function getRecipientUsers(AutomatedReport $report): array
{
return $this->buildRecipientUsers($report->getRecipients());
}
private function getJiminnyRecipientUsers(AutomatedReport $report): array
{
return $this->buildRecipientUsers($report->getJiminnyRecipients());
}
/**
* @param array<string, mixed> $recipients
*/
private function buildRecipientUsers(array $recipients): array
{
$userIds = $recipients['users'] ?? [];
return collect($userIds)
->map(fn ($id) => $this->userRepository->find((int) $id))
->filter()
->map(fn (UserContract $user) => [
'email' => $user->getEmailAddress(),
'name' => $user->getName(),
'timezone' => $user->getTimezone()->getName(),
])
->values()
->all();
}
public function getValidRecipientUsers(AutomatedReport $report, bool $includeJiminny = false): array
{
if ($report->isAskJiminnyReport()) {
$recipients = $this->resolveAskJiminnyRecipients($report);
} else {
$recipients = $this->getRecipientUsers($report);
if ($includeJiminny) {
$recipients = array_merge($recipients, $this->getJiminnyRecipientUsers($report));
}
}
$emails = [];
return array_values(array_filter(
$recipients,
static function ($recipient) use (&$emails) {
if (empty($recipient['email']) || in_array($recipient['email'], $emails, true)) {
return false;
}
$emails[] = $recipient['email'];
return true;
}
));
}
private function resolveAskJiminnyRecipients(AutomatedReport $report): array
{
$recipients = [];
$creator = $report->getCreator();
if ($creator !== null) {
$recipients[] = [
'email' => $creator->getEmailAddress(),
'name' => $creator->getName(),
'timezone' => $creator->getTimezone()->getName(),
];
}
return array_merge(
$recipients,
$this->buildRecipientUsers($report->getRecipients()),
$this->getGroupRecipientUsers($report),
);
}
private function getGroupRecipientUsers(AutomatedReport $report): array
{
$users = [];
foreach ($report->getGroups() as $groupId) {
$group = $this->groupRepository->find($groupId);
if ($group === null) {
continue;
}
foreach ($group->getMembers() as $member) {
$users[] = [
'email' => $member->getEmailAddress(),
'name' => $member->getName(),
'timezone' => $member->getTimezone()->getName(),
];
}
}
return $users;
}
public function getReportTypeName(AutomatedReportResult $report): string
{
$type = $report->getReport()->getType();
$getType = $this->transformReportType($type);
return $getType['name'];
}
public function getReportPeriodName(AutomatedReportResult $report): string
{
$from = $report->getFromDate();
$to = $report->getToDate();
$frequency = $report->getReport()->getFrequency();
if ($from === null || $to === null) {
if (! $report->getReport()->isAskJiminnyReport()) {
$invalidPeriod = $from === null ? 'from' : 'to';
throw new ApplicationException('Report period is invalid: ' . $invalidPeriod);
}
$period = $this->calculateFromAndToDatePeriod($frequency);
$from = $period['fromDate'];
$to = $period['toDate'];
}
return $this->formatReportPeriodName($frequency, $from, $to);
}
private function formatReportPeriodName(string $frequency, Carbon $from, Carbon $to): string
{
$fromYear = $from->format('Y');
$toYear = $to->format('Y');
$differentYears = $fromYear !== $toYear;
switch ($frequency) {
case self::FREQUENCY_DAILY:
return $from->format('j M Y');
case self::FREQUENCY_QUARTERLY:
// 'Jan-Mar 2025' or 'Nov 2024-Jan 2025' if years differ
$startMonth = $from->format('M');
$endMonth = $to->copy()->subMonth();
$endMonthName = $endMonth->format('M');
$endMonthYear = $endMonth->format('Y');
if ($differentYears) {
return "{$startMonth} {$fromYear} - {$endMonthName} {$endMonthYear}";
}
return "{$startMonth} - {$endMonthName} {$toYear}";
case self::FREQUENCY_MONTHLY:
// 'May 2025' - monthly reports are always within the same year
return $from->format('M Y');
case self::FREQUENCY_WEEKLY:
// '4 - 8 Aug 2025', '27 Oct - 3 Nov 2025', or '28 Dec 2024 - 3 Jan 2025' if years differ
$startDay = $from->format('j');
$endDay = $to->format('j');
$startMonth = $from->format('M');
$endMonth = $to->format('M');
if ($differentYears) {
return "{$startDay} {$startMonth} {$fromYear} - {$endDay} {$endMonth} {$toYear}";
}
if ($startMonth !== $endMonth) {
return "{$startDay} {$startMonth} - {$endDay} {$endMonth} {$toYear}";
}
return "{$startDay} - {$endDay} {$endMonth} {$toYear}";
case self::FREQUENCY_ONE_OFF:
// '2 May-31 May 2025' or '15 Dec 2024-15 Jan 2025' if years differ
$startDay = $from->format('j');
$startMonth = $from->format('M');
$endDay = $to->format('j');
$endMonth = $to->format('M');
// If same month and year, use a format like '2-31 May 2025'
if ($startMonth === $endMonth && ! $differentYears) {
return "{$startDay} - {$endDay} {$startMonth} {$toYear}";
}
// If different years, include both years
if ($differentYears) {
return "{$startDay} {$startMonth} {$fromYear} - {$endDay} {$endMonth} {$toYear}";
}
// Same year but different months
return "{$startDay} {$startMonth} - {$endDay} {$endMonth} {$toYear}";
default:
// Default format for unknown frequencies
return $from->format('j M Y') . ' - ' . $to->format('j M Y');
}
}
public function getReportTeamsName(AutomatedReportResult $report): string
{
$groups = $report->getGroups();
if (empty($groups)) {
return 'All';
}
// Get group names from repository
$groupNames = [];
foreach ($groups as $groupId) {
$group = $this->groupRepository->find($groupId);
if ($group) {
$groupNames[] = $group->getName();
}
}
if (count($groupNames) === 1) {
// Single team format
$teamsName = $groupNames[0];
} else {
// Multiple teams format
$teamsName = implode(', ', $groupNames);
}
return $teamsName;
}
public function getReportFileName(AutomatedReportResult $report): string
...
|
NULL
|
|
12333
|
262
|
5
|
2026-04-14T11:08:02.196727+00:00
|
/Users/lukas/.screenpipe/data/data/2026-04-14/1776 /Users/lukas/.screenpipe/data/data/2026-04-14/1776164882196_m1.jpg...
|
PhpStorm
|
faVsco.js – AutomatedReportsService.php
|
1
|
NULL
|
monitor_1
|
NULL
|
NULL
|
NULL
|
NULL
|
Project: faVsco.js, menu
#11894 on JY-18909-automa Project: faVsco.js, menu
#11894 on JY-18909-automated-reports-ask-jiminny, menu
Start Listening for PHP Debug Connections
AutomatedReportsCommandTest
Run 'AutomatedReportsCommandTest'
Debug 'AutomatedReportsCommandTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Execute
Explain Plan
Browse Query History
View Parameters
Open Query Execution Settings…
In-Editor Results
Tx: Auto
Cancel Running Statements
Playground
jiminny
Sync Changes
Hide This Notification
Code changed:
Hide
16
13
13
Previous Highlighted Error
Next Highlighted Error
SELECT * FROM teams WHERE id = 1;
select * from crm_layouts where crm_configuration_id = 39;
SELECT * FROM crm_layout_entities WHERE crm_layout_id = 283;
SELECT * FROM crm_fields WHERE id = 2234;
SELECT * FROM crm_field_values WHERE crm_field_id = 2234;
select * from crm_profiles where user_id = 143;
select * from record_types where crm_configuration_id = 39; # 0121K000001MHElQAO,0121K000001MHEqQAO
select * from business_processes where crm_configuration_id = 39;
# 01941000000H669AAC, 01941000000H66JAAS
select * from record_type_field_values
where record_type_id IN (24);
select * from crm_field_values where id IN (2730);
select * from crm_configurations where id = 39;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 1
and sa.provider = 'salesforce'; #1035
select * from users where team_id = 1; # 222 group 3
SELECT * FROM activities WHERE user_id = 222 order by id desc;
select * from sidekick_settings where team_id = 1;
select * from teams where id = 1;
select * from team_features where team_id = 1;
select * from activities where crm_configuration_id = 2
and provider = 'ms-teams' and id = 608765;
SELECT * FROM activities WHERE crm_configuration_id = 2 and crm_provider_id = '59523413338';
select * from sidekick_settings where team_id = 2;
SELECT * FROM activities WHERE id = 608660;
select * from activity_summary_logs where activity_id = 608660;
select * from ai_prompts where transcription_id = 11214;
# [PASSWORD_DOTS]
SELECT * FROM activities WHERE uuid_to_bin('ed78a437-2804-450e-ab2f-56ab1c641346') = uuid;
# id: 608818, crm: 59628809737
SELECT * FROM activities WHERE uuid_to_bin('36b06e55-afdd-4782-8dee-c624cd0af191') = uuid;
# id: 608821, crm: 59632069252
SELECT ce.start_time, ce.end_time, a.id, a.uuid, crm_provider_id, calendar_event_id, title,
playbook_category_id, user_id, lead_id, contact_id, account_id, opportunity_id,
scheduled_start_time, scheduled_end_time, actual_start_time, actual_end_time, a.created_at
FROM activities a
join calendar_events ce on a.calendar_event_id = ce.id
WHERE a.id IN (608818, 608821);
select * from users where team_id = 1;
select * from team_settings where team_id = 1;
select * from crm_profiles where crm_configuration_id = 39 order by user_id;
select * from team_features where team_id = 1;
select * from users where team_id = 2;
SELECT * FROM activities WHERE uuid_to_bin('ec7647e9-5225-458b-b475-f31aa2769204') = uuid; # 612639
# Preslava N. Ivanova, grou id 3
SELECT * FROM opportunities WHERE uuid_to_bin('a2928fe5-aec5-46cb-85d9-7654c89e46a6') = uuid;
select * from activities where opportunity_id = 344 and actual_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00';
select
a.id,
a.type,
a.scheduled_start_time,
a.actual_start_time,
a.created_at,
a.opportunity_id,
a.status
FROM activities a
WHERE opportunity_id = 344
and status IN ('completed', 'received', 'delivered')
and (
(a.actual_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00')
OR (a.created_at between '2024-10-11 00:00:00' and '2024-10-12 00:00:00')
OR (a.scheduled_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00'))
;
SELECT * FROM users WHERE id = 222;
SELECT * FROM crm_profiles WHERE user_id = 222;
select * from crm_layouts where crm_configuration_id = 39;
SELECT * FROM crm_layout_entities WHERE crm_layout_id = 281;
select * from group_deal_risk_types;
select * from opportunities where team_id = 1;
SELECT * FROM opportunities WHERE id = 315;
SELECT * FROM crm_field_data WHERE object_id = 315;
select * from crm_field_data where object_id = 260;
select * from generic_ai_prompts where subject_id = 315;
select * from teams; # 36, 21, 121, [EMAIL]
SELECT * FROM social_accounts WHERE sociable_id = 121 and provider = 'bullhorn';
# [PASSWORD_DOTS]
select * from teams where id = 1;
select * from crm_configurations where id = 39;
select * from users where team_id = 1;
select u.email, cp.* from users u
join crm_profiles cp on u.id = cp.user_id
where u.team_id = 1;
# 1 - 00541000004281rAAA
# 204 - 0052g000003freeAAA
# 429 - 0052g000003qGOiAAM
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 1
and sa.provider = 'salesforce';
select * from activities where type = 'softphone'
and created_at > '2024-12-11 15:24:36' order by id desc;
select * from activity_providers where team_id = 1;
select * from activity_provider_users where activity_provider_id = 328;
select * from opportunities where crm_configuration_id = 39
AND account_id = 178 AND is_closed = false
order by created_at DESC;
select * from contacts where id = 3952;
select * from accounts where id = 178;
# [PASSWORD_DOTS]
select * from teams where id = 36;
select * from crm_configurations where id = 21;
select * from users where team_id = 36;
select u.email, cp.* from users u
join crm_profiles cp on u.id = cp.user_id
where u.team_id = 36;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 36
and sa.provider = 'bullhorn';
select * from social_accounts where id = 348;
UPDATE social_accounts SET
provider_user_token = '21442_6802599_91:41179a58-21e7-4d7c-ad58-56bb666b2f65',
provider_refresh_token = '21442_6802599_91:01c6b335-3f2a-42e4-85ff-8a08fa65fceb',
expires = 1733998131,
state = 'connected'
WHERE id = 348;
# [PASSWORD_DOTS]
select * from teams where id = 31;
select * from crm_configurations where id = 18;
select * from users where team_id = 31; # 257
select u.email, cp.* from users u
join crm_profiles cp on u.id = cp.user_id
where u.team_id = 31;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 31
and sa.provider = 'close';
select * from contacts where crm_configuration_id = 18;
# [PASSWORD_DOTS] NEPTUNE [PASSWORD_DOTS]
select * from teams;
select * from users where id IN (1030, 1035, 1052);
select * from crm_configurations;
select * from users where team_id = 65; # 257
select * from team_settings where team_id = 65; # 257
select * from invitations where team_id = 65; # 257
select * from users where email = '[EMAIL]'; # 257
select u.email, cp.* from users u
join crm_profiles cp on u.id = cp.user_id
where u.team_id = 65;
select * from crm_configurations where id = 53;
select * from accounts where crm_configuration_id = 53 order by id desc;
select * from leads where crm_configuration_id = 53 order by id desc;
select * from contacts where crm_configuration_id = 53 order by id desc;
select * from opportunities where crm_configuration_id = 53 order by id desc;
select * from crm_profiles where crm_configuration_id = 53 order by id desc;
select * from crm_fields where crm_configuration_id = 53 order by id desc;
select * from crm_field_values where crm_field_id = 3341 order by id desc;
select * from crm_layouts where crm_configuration_id = 53 order by id desc;
select * from stages where crm_configuration_id = 53 order by id desc;
select * from crm_profiles where crm_configuration_id = 13;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 65
and sa.provider = 'integration-app';
select * from contacts where crm_configuration_id = 13;
select * from social_accounts where sociable_id = 283;
SELECT * FROM opportunities WHERE crm_provider_id = '006O400000E9bzeIAB';
select * from activity_providers where team_id = 65;
SELECT * FROM activities WHERE crm_configuration_id IN (51, 52, 53);
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 65
;
# [PASSWORD_DOTS] STAGING [PASSWORD_DOTS]
SELECT * FROM teams;
SELECT * FROM teams WHERE id = 88;
SELECT * FROM teams WHERE id = 89;
select * from team_settings where team_id = 89;
SELECT * FROM users WHERE team_id = 89;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 89;
select * from users;
SELECT * FROM social_accounts WHERE sociable_id = 1761;
SELECT * FROM crm_configurations WHERE id = 70;
select * from accounts where crm_configuration_id = 70 order by id desc;
select * from leads where crm_configuration_id = 70 order by id desc;
select * from contacts where crm_configuration_id = 70 order by id desc;
select * from opportunities where crm_configuration_id = 70 order by id desc;
select * from crm_profiles where crm_configuration_id = 70 order by id desc;
select * from crm_fields where crm_configuration_id = 70 order by id desc;
select * from crm_field_values where crm_field_id = 3536 order by id desc;
select * from crm_layouts where crm_configuration_id = 70 order by id desc;
select * from stages where crm_configuration_id = 70 order by id desc;
select * from business_processes where crm_configuration_id = 70 order by id desc;
select * from business_process_stages where business_process_id = 34;
select * from contacts where id = 10468;
select * from crm_layouts where crm_configuration_id = 70;
SELECT * FROM crm_layout_entities WHERE crm_layout_id = 388;
SELECT * FROM crm_fields WHERE id IN (3533,3534,3535);
select * from activities where crm_configuration_id = 70
and (account_id IS NOT NULL or lead_id IS NOT NULL or contact_id IS NOT NULL or opportunity_id IS NOT NULL) order by id desc;
SELECT * FROM activities WHERE uuid_to_bin('2e10b60f-8a61-41c5-a3d4-28835353dc65') = uuid;
SELECT * FROM activities where crm_configuration_id = 69 ;
SELECT * FROM users WHERE email LIKE '%[EMAIL]%';
SELECT * FROM activities WHERE uuid_to_bin('5a150c93-40fc-42ec-b3bd-c1d328e09f6e') = uuid;
SELECT * FROM opportunities WHERE id = 385;
select * from participants p
join activities a on p.activity_id = a.id
where a.crm_configuration_id = 70
and (p.lead_id IS NOT NULL or p.contact_id IS NOT NULL);
SELECT * FROM participants WHERE id = 1013638;
select * from teams where id = 90;
select * from users where team_id = 90;
select * from social_accounts where social_accounts.sociable_id IN (1960,1760);
SELECT * FROM crm_profiles WHERE crm_configuration_id = 71;
select * from invitations where team_id = 90;
select * from crm_configurations where id = 71;
select * from accounts where crm_configuration_id = 71 order by id desc;
select * from leads where crm_configuration_id = 71 order by id desc;
select * from contacts where crm_configuration_id = 71 order by id desc;
select * from opportunities where crm_configuration_id = 71 order by id desc;
select * from crm_profiles where crm_configuration_id = 71 order by id desc;
select * from crm_fields where crm_configuration_id = 71 order by id desc;
select * from crm_field_values where crm_field_id = 3341 order by id desc;
select * from crm_layouts where crm_configuration_id = 71 order by id desc;
select * from stages where crm_configuration_id = 71 order by id desc;
select * from users order by secondary_email desc;
select u.id, u.email, u.status, sa.id, sa.provider_user_id from social_accounts sa
join users u on sa.sociable_id = u.id
where sa.provider = 'google' and u.email LIKE 'aneliya%';
select * from failed_jobs order by id desc;
select * from users where email = '[EMAIL]' or secondary_email = '[EMAIL]';
select * from teams;
SELECT * FROM crm_profiles WHERE crm_configuration_id = 39;
SELECT * FROM crm_fields WHERE crm_configuration_id = 39 and object_type = 'task';
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 1
and sa.provider = 'salesforce';
# [PASSWORD_DOTS]
SELECT * FROM activities WHERE uuid_to_bin('c38b3895-fd0f-4b1f-9fb2-c170dba137c6') = uuid;
SELECT * FROM crm_configurations WHERE id = 70;
select * from teams where id = 1;
select * from groups where team_id = 1;
select * from users where team_id = 1;
select o.id, o.name,o.close_date, u.id, u.name, u.group_id, r.id, r.display_name, g.name, g.scope from opportunities o
join users u on o.user_id = u.id
join groups g on u.group_id = g.id
join role_user ru on u.id = ru.user_id
join roles r on ru.role_id = r.id
where o.crm_configuration_id = 39 and close_date > '2024-01-01 00:00:00';
select * from role_user where user_id = 143;
select * from roles;
select * from role_user;
select * from groups where id = 9;
select * from scope_groups where group_id = 9;
# [PASSWORD_DOTS]
select * from teams where id = 36;
select * from crm_configurations;
SELECT * FROM social_accounts WHERE sociable_id = 121;
[URL_WITH_CREDENTIALS] this will add filter, however if we need to control feature by FF we need conditional logic
public const array TYPES = [
['id' => 'exec_summary', 'name' => 'Exec Summary'],
['id' => 'coaching_profiles', 'name' => 'Coaching Profiles'],
['id' => 'product_feedback', 'name' => 'Product Feedback'],
['id' => self::TYPE_LOSS_ANALYSIS, 'name' => 'Loss Analysis'],
// ['id' => 'questions', 'name' => 'Questions'],
// ['id' => 'statistical_quant', 'name' => 'Statistical Quantitative'],
];
public const array ALL_TYPES = [
...self::TYPES,
['id' => self::TYPE_ASK_JIMINNY, 'name' => 'Ask Jiminny'],
];
public const string FREQUENCY_DAILY = 'daily';
public const string FREQUENCY_WEEKLY = 'weekly';
public const string FREQUENCY_MONTHLY = 'monthly';
public const string FREQUENCY_QUARTERLY = 'quarterly';
public const string FREQUENCY_ONE_OFF = 'one_off';
/**
* Frequencies for standard (non-Ask Jiminny) reports.
*/
public const array FREQUENCIES = [
['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],
['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],
['id' => self::FREQUENCY_QUARTERLY, 'name' => 'Quarterly'],
['id' => self::FREQUENCY_ONE_OFF, 'name' => 'One-off'],
];
/**
* Frequencies for Ask Jiminny reports.
*/
public const array ASK_JIMINNY_FREQUENCIES = [
['id' => self::FREQUENCY_DAILY, 'name' => 'Daily'],
['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],
['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],
];
public const string MEDIA_TYPE_PDF = 'pdf';
public const string MEDIA_TYPE_PODCAST = 'podcast';
public const array MEDIA_TYPES = [self::MEDIA_TYPE_PDF, self::MEDIA_TYPE_PODCAST];
public const array MEDIA_TYPE_OBJECT_PDF = ['id' => self::MEDIA_TYPE_PDF, 'name' => 'PDF'];
public const array MEDIA_TYPE_OBJECT_PODCAST = ['id' => self::MEDIA_TYPE_PODCAST, 'name' => 'Podcast'];
public const array MEDIA_TYPE_OBJECTS = [self::MEDIA_TYPE_OBJECT_PDF, self::MEDIA_TYPE_OBJECT_PODCAST];
public const array CALL_TYPE_CONFERENCE = ['id' => 'conference', 'name' => 'Conference'];
public const array CALL_TYPE_DIALER = ['id' => 'dialer', 'name' => 'Dialer'];
public const int SENT_REPORT_AT_HOURS = 5;
public const string PDF_KEY = 'pdf';
public const string AUDIO_KEY = 'audio';
private const array ALL_FREQUENCIES = [
['id' => self::FREQUENCY_DAILY, 'name' => 'Daily'],
['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],
['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],
['id' => self::FREQUENCY_QUARTERLY, 'name' => 'Quarterly'],
['id' => self::FREQUENCY_ONE_OFF, 'name' => 'One-off'],
];
private const string S3_DIR = 'reports';
private const array FILE_EXTENSIONS_VARIANTS = ['html', 'MD', 'pdf'];
private const array FILE_PODCAST_EXTENSIONS_VARIANTS = ['json', 'mp3', 'ssml'];
public function __construct(
private readonly TeamRepository $teamRepository,
private readonly GroupRepository $groupRepository,
private readonly UserRepository $userRepository,
private readonly StageRepository $stageRepository,
private readonly DealStagesService $dealStagesService,
private readonly RecipientsService $recipientsService,
private readonly AutomatedReportsRepository $automatedReportsRepository,
private readonly Webhook $webhookService,
private readonly BusDispatcher $dispatcher,
private readonly ActivityTypeService $activityTypeService,
private readonly PlaybookCategoryRepository $playbookCategoryRepository,
private readonly AskAnythingPromptService $askAnythingPromptService,
private readonly SearchRepository $activitySearchRepository,
private readonly AskAnythingRepository $askAnythingRepository,
) {
}
public static function getTypes(): array
{
$types = self::TYPES;
return array_map(static function ($type) {
return $type['id'];
}, $types);
}
public static function getCallTypes(): array
{
return array_map(static function ($callType) {
return $callType['id'];
}, [self::CALL_TYPE_CONFERENCE, self::CALL_TYPE_DIALER]);
}
public static function getFrequencies(): array
{
return array_map(static function ($frequency) {
return $frequency['id'];
}, self::FREQUENCIES);
}
// front-facing structure
public function getReportEnabledFieldData(bool $value = false): array
{
return [
'id' => 'report_enabled',
'label' => '',
'inputType' => InputTypeEnum::TOGGLE,
'value' => $value,
];
}
// Organizations = Teams
public function getOrganizationFieldData(?string $value = null, bool $shortVersion = false): array
{
$options = $this->getTeams();
if ($shortVersion) {
return [
'id' => 'organization',
'label' => 'Organization',
'options' => $options,
];
}
return [
'id' => 'organization',
'label' => 'Organization',
'inputType' => InputTypeEnum::DROPDOWN,
'required' => true,
'placeholder' => 'Select',
'options' => $options,
'value' => $value,
'dependencies' => [
'teams',
'deal_stage_at_call',
'current_deal_stage',
'recipients',
ActivityTypeService::PLAYBOOK_CATEGORIES_KEY,
],
'dependsOn' => [],
];
}
// Teams = Groups
public function getTeamFieldData(array $options = [], array $value = [], bool $shortVersion = false): array
{
if ($shortVersion) {
return [
'id' => 'teams',
'label' => 'Team',
'options' => $options,
];
}
return [
'id' => 'teams',
'label' => 'Team',
'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,
'required' => false,
'placeholder' => 'Select',
'options' => $options,
'value' => $value, // value should be an array of objects {id, name}
'dependencies' => [ActivityTypeService::PLAYBOOK_CATEGORIES_KEY],
'dependsOn' => [],
];
}
public function getReportTypeFieldData(?string $value = null, bool $shortVersion = false, ?Team $team = null): array
{
$types = [];
if ($team instanceof Team) {
if ($team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {
$types = self::TYPES;
}
if ($team->hasFeature(FeatureEnum::ASK_JIMINNY_REPORTS)) {
$types[] = ['id' => self::TYPE_ASK_JIMINNY, 'name' => 'Ask Jiminny'];
}
} else {
$types = self::TYPES;
}
if ($shortVersion) {
return [
'id' => 'report_type',
'label' => 'Report Type',
'options' => $types,
];
}
return [
'id' => 'report_type',
'label' => 'Report Type',
'inputType' => InputTypeEnum::DROPDOWN,
'required' => true,
'placeholder' => 'Select',
'options' => $types,
'value' => $value,
'dependencies' => [],
'dependsOn' => [],
];
}
public function getFrequencyFieldData(?string $value = null): array
{
return [
'id' => 'frequency',
'label' => 'Frequency',
'inputType' => InputTypeEnum::DROPDOWN,
'required' => true,
'placeholder' => 'Select',
'options' => self::FREQUENCIES,
'value' => $value,
'dependencies' => ['period'],
'dependsOn' => [],
];
}
public function getPeriodFieldData(?string $valueStartDate = null, ?string $valueEndDate = null): array
{
return [
'id' => 'period',
'label' => 'Select one-off period',
'inputType' => InputTypeEnum::DATE_RANGE,
'required' => true,
'placeholder' => 'Select',
'value' => ['startDate' => $valueStartDate, 'endDate' => $valueEndDate],
'queryParams' => [
'startDate' => 'start_date_period',
'endDate' => 'end_date_period',
],
'dependencies' => [],
'dependsOn' => ['frequency'],
];
}
public function getActivityTypesFieldData(?Team $team = null, array $value = [], array $teamsFilter = []): array
{
return $this->activityTypeService->getActivityTypeFieldData(team: $team, value: $value, groupIds: $teamsFilter);
}
public function getDealStageAtCallFieldData(?Team $team = null, array $value = []): array
{
return $this->dealStagesService->getDealStageAtCallFieldData(team: $team, value: $value);
}
public function getCurrentDealStageFieldData(?Team $team = null, array $value = []): array
{
return $this->dealStagesService->getCurrentDealStageFieldData(team: $team, value: $value);
}
public function getDealValueFieldData(?int $valueMin = null, ?int $valueMax = null): array
{
return [
'id' => 'deal_value',
'label' => 'Deal Value',
'inputType' => InputTypeEnum::INTEGER_RANGE,
'required' => false,
'value' => ['min' => $valueMin, 'max' => $valueMax],
'queryParams' => [
'min' => 'min_deal_value',
'max' => 'max_deal_value',
],
'dependencies' => [],
'dependsOn' => [],
];
}
public function getCallTypeFieldData(bool $conferenceOn = false, bool $dialerOn = false): array
{
$value = [];
$conferenceOn && $value[] = self::CALL_TYPE_CONFERENCE;
$dialerOn && $value[] = self::CALL_TYPE_DIALER;
return [
'id' => 'call_type',
'label' => 'Call Type',
'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,
'required' => true,
'options' => [
self::CALL_TYPE_CONFERENCE,
self::CALL_TYPE_DIALER,
],
'value' => $value,
'dependencies' => [],
'dependsOn' => [],
];
}
public function getMediaTypeFieldData(?AutomatedReport $report = null): array
{
$value = [];
if ($report) {
$value = $this->transformMediaTypes($report);
}
return [
'id' => 'media_types',
'label' => 'Export as',
'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,
'required' => true,
'options' => self::MEDIA_TYPE_OBJECTS,
'value' => $value,
'dependencies' => [],
'dependsOn' => [],
];
}
public function getCallDurationFieldData(?int $valueMin = null, ?int $valueMax = null): array
{
return [
'id' => 'call_duration',
'label' => 'Call Duration',
'inputType' => InputTypeEnum::INTEGER_RANGE,
'required' => false,
'value' => ['min' => $valueMin, 'max' => $valueMax],
'queryParams' => [
'min' => 'min_call_duration',
'max' => 'max_call_duration',
],
'dependencies' => [],
'dependsOn' => [],
];
}
public function getRecipientsFieldData(?Team $team = null, array $value = []): array
{
return $this->recipientsService->getRecipientsFieldData(team: $team, value: $value);
}
public function getJiminnyRecipientsFieldData(array $value = []): array
{
return $this->recipientsService->getJiminnyRecipientsFieldData($value);
}
public function getAdditionalPromptInputFieldData(?string $value = null): array
{
return [
'id' => 'additional_prompt_input',
'label' => 'Special requirements',
'inputType' => InputTypeEnum::TEXTAREA,
'required' => false,
'placeholder' => 'What should be the focus of the report?',
'value' => $value,
'dependencies' => [],
'dependsOn' => [],
];
}
public function getCustomReportNameFieldData(?string $value = null): array
{
return [
'id' => 'custom_name',
'label' => 'Custom report name',
'inputType' => InputTypeEnum::TEXT,
'required' => false,
'placeholder' => 'Enter custom name',
'value' => $value,
'dependencies' => [],
'dependsOn' => [],
];
}
// data providers
public function getTeams(): array
{
$teams = $this->teamRepository->getTeamsForKiosk(status: Team::STATUS_ACTIVE);
$teamData = [];
foreach ($teams as $team) {
if (! $team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {
continue;
}
$teamData[] = $this->transformTeam($team);
}
return $teamData;
}
public function getTeamGroups(string $teamUuid): array
{
$data = [];
$team = $this->getTeam($teamUuid);
if ($team !== null) {
$groups = $team->groups()->get();
foreach ($groups as $group) {
$data[] = [
'id' => $group->getUuid(),
'name' => $group->getName(),
];
}
}
return $data;
}
public function getTeamsGroupsOptions(array $filterTeamUuids = []): array
{
$data = [];
$teams = $this->getTeams();
foreach ($teams as $team) {
if (! empty($filterTeamUuids) && ! in_array($team['id'], $filterTeamUuids, true)) {
continue;
}
$data[] = [
'label' => $team['name'],
'groups' => $this->getTeamGroups($team['id']),
];
}
return $data;
}
public function getTeam(string $teamUuid): ?Team
{
return $this->teamRepository->idOrUuid($teamUuid);
}
public function getTeamById(int $teamId): ?Team
{
return $this->teamRepository->find($teamId);
}
public function getGroupsUuids(AutomatedReport $report): array
{
$uuids = [];
$reportGroups = $report->getGroups();
foreach ($reportGroups as $groupId) {
if ($group = $this->groupRepository->find($groupId)) {
$uuids[] = $group->getUuid();
}
}
return $uuids;
}
public function getPlaybookCategoriesUuids(AutomatedReport $report): array
{
$uuids = [];
$playbookCategories = $report->getPlaybookCategories();
foreach ($playbookCategories as $id) {
if ($category = $this->playbookCategoryRepository->find($id)) {
$uuids[] = $category->getUuid();
}
}
return $uuids;
}
public function getDealAtCallStagesUuids(AutomatedReport $report): array
{
$uuids = [];
$reportStages = $report->getDealAtCallStages();
foreach ($reportStages as $id) {
if ($stage = $this->stageRepository->find($id)) {
$uuids[] = $stage->getUuid();
}
}
return $uuids;
}
public function getCurrentDealStagesUuids(AutomatedReport $report): array
{
$uuids = [];
$reportStages = $report->getCurrentDealStages();
foreach ($reportStages as $id) {
if ($stage = $this->stageRepository->find($id)) {
$uuids[] = $stage->getUuid();
}
}
return $uuids;
}
public function getUsersUuids(AutomatedReport $report): array
{
return $this->extractUserUuids($report->getRecipients());
}
public function getJiminnyUsersUuids(AutomatedReport $report): array
{
return $this->extractUserUuids($report->getJiminnyRecipients());
}
/**
* @param array<string, mixed> $recipients
*/
private function extractUserUuids(array $recipients): array
{
$userIds = $recipients['users'] ?? [];
return collect($userIds)
->map(fn ($id) => $this->userRepository->find((int) $id))
->filter()
->map(fn (UserContract $user) => $user->getUuid())
->values()
->all();
}
// get mail data
public function getRecipientUsers(AutomatedReport $report): array
{
return $this->buildRecipientUsers($report->getRecipients());
}
private function getJiminnyRecipientUsers(AutomatedReport $report): array
{
return $this->buildRecipientUsers($report->getJiminnyRecipients());
}
/**
* @param array<string, mixed> $recipients
*/
private function buildRecipientUsers(array $recipients): array
{
$userIds = $recipients['users'] ?? [];
return collect($userIds)
->map(fn ($id) => $this->userRepository->find((int) $id))
->filter()
->map(fn (UserContract $user) => [
'email' => $user->getEmailAddress(),
'name' => $user->getName(),
'timezone' => $user->getTimezone()->getName(),
])
->values()
->all();
}
public function getValidRecipientUsers(AutomatedReport $report, bool $includeJiminny = false): array
{
if ($report->isAskJiminnyReport()) {
$recipients = $this->resolveAskJiminnyRecipients($report);
} else {
$recipients = $this->getRecipientUsers($report);
if ($includeJiminny) {
$recipients = array_merge($recipients, $this->getJiminnyRecipientUsers($report));
}
}
$emails = [];
return array_values(array_filter(
$recipients,
static function ($recipient) use (&$emails) {
if (empty($recipient['email']) || in_array($recipient['email'], $emails, true)) {
return false;
}
$emails[] = $recipient['email'];
return true;
}
));
}
private function resolveAskJiminnyRecipients(AutomatedReport $report): array
{
$recipients = [];
$creator = $report->getCreator();
if ($creator !== null) {
$recipients[] = [
'email' => $creator->getEmailAddress(),
'name' => $creator->getName(),
'timezone' => $creator->getTimezone()->getName(),
];
}
return array_merge(
$recipients,
$this->buildRecipientUsers($report->getRecipients()),
$this->getGroupRecipientUsers($report),
);
}
private function getGroupRecipientUsers(AutomatedReport $report): array
{
$users = [];
foreach ($report->getGroups() as $groupId) {
$group = $this->groupRepository->find($groupId);
if ($group === null) {
continue;
}
foreach ($group->getMembers() as $member) {
$users[] = [
'email' => $member->getEmailAddress(),
'name' => $member->getName(),
'timezone' => $member->getTimezone()->getName(),
];
}
}
return $users;
}
public function getReportTypeName(AutomatedReportResult $report): string
{
$type = $report->getReport()->getType();
$getType = $this->transformReportType($type);
return $getType['name'];
}
public function getReportPeriodName(AutomatedReportResult $report): string
{
$from = $report->getFromDate();
$to = $report->getToDate();
$frequency = $report->getReport()->getFrequency();
if ($from === null || $to === null) {
if (! $report->getReport()->isAskJiminnyReport()) {
$invalidPeriod = $from === null ? 'from' : 'to';
throw new ApplicationException('Report period is invalid: ' . $invalidPeriod);
}
$period = $this->calculateFromAndToDatePeriod($frequency);
$from = $period['fromDate'];
$to = $period['toDate'];
}
return $this->formatReportPeriodName($frequency, $from, $to);
}
private function formatReportPeriodName(string $frequency, Carbon $from, Carbon $to): string
{
$fromYear = $from->format('Y');
$toYear = $to->format('Y');
$differentYears = $fromYear !== $toYear;
switch ($frequency) {
case self::FREQUENCY_DAILY:
return $from->format('j M Y');
case self::FREQUENCY_QUARTERLY:
// 'Jan-Mar 2025' or 'Nov 2024-Jan 2025' if years differ
$startMonth = $from->format('M');
$endMonth = $to->copy()->subMonth();
$endMonthName = $endMonth->format('M');
$endMonthYear = $endMonth->format('Y');
if ($differentYears) {
return "{$startMonth} {$fromYear} - {$endMonthName} {$endMonthYear}";
}
return "{$startMonth} - {$endMonthName} {$toYear}";
case self::FREQUENCY_MONTHLY:
// 'May 2025' - monthly reports are always within the same year
return $from->format('M Y');
case self::FREQUENCY_WEEKLY:
// '4 - 8 Aug 2025', '27 Oct - 3 Nov 2025', or '28 Dec 2024 - 3 Jan 2025' if years differ
$startDay = $from->format('j');
$endDay = $to->format('j');
$startMonth = $from->format('M');
$endMonth = $to->format('M');
if ($differentYears) {
return "{$startDay} {$startMonth} {$fromYear} - {$endDay} {$endMonth} {$toYear}";
}
if ($startMonth !== $endMonth) {
return "{$startDay} {$startMonth} - {$endDay} {$endMonth} {$toYear}";
}
return "{$startDay} - {$endDay} {$endMonth} {$toYear}";
case self::FREQUENCY_ONE_OFF:
// '2 May-31 May 2025' or '15 Dec 2024-15 Jan 2025' if years differ
$startDay = $from->format('j');
$startMonth = $from->format('M');
$endDay = $to->format('j');
$endMonth = $to->format('M');
// If same month and year, use a format like '2-31 May 2025'
if ($startMonth === $endMonth && ! $differentYears) {
return "{$startDay} - {$endDay} {$startMonth} {$toYear}";
}
// If different years, include both years
if ($differentYears) {
return "{$startDay} {$startMonth} {$fromYear} - {$endDay} {$endMonth} {$toYear}";
}
// Same year but different months
return "{$startDay} {$startMonth} - {$endDay} {$endMonth} {$toYear}";
default:
// Default format for unknown frequencies
return $from->format('j M Y') . ' - ' . $to->format('j M Y');
}
}
public function getReportTeamsName(AutomatedReportResult $report): string
{
$groups = $report->getGroups();
if (empty($groups)) {
return 'All';
}
// Get group names from repository
$groupNames = [];
foreach ($groups as $groupId) {
$group = $this->groupRepository->find($groupId);
if ($group) {
$groupNames[] = $group->getName();
}
}
if (count($groupNames) === 1) {
// Single team format
$teamsName = $groupNames[0];
} else {
// Multiple teams format
$teamsName = implode(', ', $groupNames);
}
return $teamsName;
}
public function getReportFileName(AutomatedReportResult $report): string
...
|
[{"role":"AXButton","text" [{"role":"AXButton","text":"Project: faVsco.js, menu","depth":5,"help_text":"~/jiminny/app","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"#11894 on JY-18909-automated-reports-ask-jiminny, menu","depth":5,"help_text":"Pull request #11894 exists for current branch JY-18909-automated-reports-ask-jiminny","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Start Listening for PHP Debug Connections","depth":5,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"AutomatedReportsCommandTest","depth":6,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Run 'AutomatedReportsCommandTest'","depth":6,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Debug 'AutomatedReportsCommandTest'","depth":6,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"More Actions","depth":6,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JetBrains AI","depth":5,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Search Everywhere","depth":5,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"IDE and Project Settings","depth":5,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Execute","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Explain Plan","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Browse Query History","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"View Parameters","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Open Query Execution Settings…","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"In-Editor Results","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Tx: Auto","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Cancel Running Statements","depth":4,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Playground","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"jiminny","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.088194445,"height":0.027777778},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"16","depth":4,"role_description":"text"},{"role":"AXStaticText","text":"13","depth":4,"role_description":"text"},{"role":"AXStaticText","text":"13","depth":4,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"SELECT * FROM teams WHERE id = 1;\n\nselect * from crm_layouts where crm_configuration_id = 39;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 283;\nSELECT * FROM crm_fields WHERE id = 2234;\nSELECT * FROM crm_field_values WHERE crm_field_id = 2234;\n\nselect * from crm_profiles where user_id = 143;\n\nselect * from record_types where crm_configuration_id = 39; # 0121K000001MHElQAO,0121K000001MHEqQAO\nselect * from business_processes where crm_configuration_id = 39;\n# 01941000000H669AAC, 01941000000H66JAAS\n\nselect * from record_type_field_values\n where record_type_id IN (24);\n\nselect * from crm_field_values where id IN (2730);\n\nselect * from crm_configurations where id = 39;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 1\nand sa.provider = 'salesforce'; #1035\n\n\nselect * from users where team_id = 1; # 222 group 3\nSELECT * FROM activities WHERE user_id = 222 order by id desc;\nselect * from sidekick_settings where team_id = 1;\nselect * from teams where id = 1;\nselect * from team_features where team_id = 1;\n\nselect * from activities where crm_configuration_id = 2\nand provider = 'ms-teams' and id = 608765;\n\nSELECT * FROM activities WHERE crm_configuration_id = 2 and crm_provider_id = '59523413338';\n\nselect * from sidekick_settings where team_id = 2;\n\nSELECT * FROM activities WHERE id = 608660;\nselect * from activity_summary_logs where activity_id = 608660;\nselect * from ai_prompts where transcription_id = 11214;\n\n# ********************************************************************************************************\nSELECT * FROM activities WHERE uuid_to_bin('ed78a437-2804-450e-ab2f-56ab1c641346') = uuid;\n# id: 608818, crm: 59628809737\nSELECT * FROM activities WHERE uuid_to_bin('36b06e55-afdd-4782-8dee-c624cd0af191') = uuid;\n# id: 608821, crm: 59632069252\nSELECT ce.start_time, ce.end_time, a.id, a.uuid, crm_provider_id, calendar_event_id, title,\nplaybook_category_id, user_id, lead_id, contact_id, account_id, opportunity_id,\nscheduled_start_time, scheduled_end_time, actual_start_time, actual_end_time, a.created_at\nFROM activities a\njoin calendar_events ce on a.calendar_event_id = ce.id\nWHERE a.id IN (608818, 608821);\n\nselect * from users where team_id = 1;\nselect * from team_settings where team_id = 1;\nselect * from crm_profiles where crm_configuration_id = 39 order by user_id;\n\nselect * from team_features where team_id = 1;\n\nselect * from users where team_id = 2;\n\nSELECT * FROM activities WHERE uuid_to_bin('ec7647e9-5225-458b-b475-f31aa2769204') = uuid; # 612639\n# Preslava N. Ivanova, grou id 3\n\nSELECT * FROM opportunities WHERE uuid_to_bin('a2928fe5-aec5-46cb-85d9-7654c89e46a6') = uuid;\n\nselect * from activities where opportunity_id = 344 and actual_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00';\n\nselect\n a.id,\n a.type,\n a.scheduled_start_time,\n a.actual_start_time,\n a.created_at,\n a.opportunity_id,\n a.status\nFROM activities a\nWHERE opportunity_id = 344\nand status IN ('completed', 'received', 'delivered')\nand (\n (a.actual_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00')\nOR (a.created_at between '2024-10-11 00:00:00' and '2024-10-12 00:00:00')\nOR (a.scheduled_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00'))\n;\n\nSELECT * FROM users WHERE id = 222;\n\nSELECT * FROM crm_profiles WHERE user_id = 222;\nselect * from crm_layouts where crm_configuration_id = 39;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 281;\n\nselect * from group_deal_risk_types;\n\nselect * from opportunities where team_id = 1;\n\nSELECT * FROM opportunities WHERE id = 315;\nSELECT * FROM crm_field_data WHERE object_id = 315;\nselect * from crm_field_data where object_id = 260;\n\nselect * from generic_ai_prompts where subject_id = 315;\n\nselect * from teams; # 36, 21, 121, james.graham@bullhorn.jiminny.com\nSELECT * FROM social_accounts WHERE sociable_id = 121 and provider = 'bullhorn';\n\n# ************************************************************************************\nselect * from teams where id = 1;\nselect * from crm_configurations where id = 39;\nselect * from users where team_id = 1;\nselect u.email, cp.* from users u\njoin crm_profiles cp on u.id = cp.user_id\nwhere u.team_id = 1;\n# 1 - 00541000004281rAAA\n# 204 - 0052g000003freeAAA\n# 429 - 0052g000003qGOiAAM\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 1\nand sa.provider = 'salesforce';\n\nselect * from activities where type = 'softphone'\nand created_at > '2024-12-11 15:24:36' order by id desc;\n\nselect * from activity_providers where team_id = 1;\nselect * from activity_provider_users where activity_provider_id = 328;\n\nselect * from opportunities where crm_configuration_id = 39\nAND account_id = 178 AND is_closed = false\norder by created_at DESC;\n\nselect * from contacts where id = 3952;\nselect * from accounts where id = 178;\n\n# ************************************************************************************\nselect * from teams where id = 36;\nselect * from crm_configurations where id = 21;\nselect * from users where team_id = 36;\nselect u.email, cp.* from users u\njoin crm_profiles cp on u.id = cp.user_id\nwhere u.team_id = 36;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 36\nand sa.provider = 'bullhorn';\n\nselect * from social_accounts where id = 348;\nUPDATE social_accounts SET\nprovider_user_token = '21442_6802599_91:41179a58-21e7-4d7c-ad58-56bb666b2f65',\nprovider_refresh_token = '21442_6802599_91:01c6b335-3f2a-42e4-85ff-8a08fa65fceb',\nexpires = 1733998131,\nstate = 'connected'\nWHERE id = 348;\n\n# ************************************************************************************\nselect * from teams where id = 31;\nselect * from crm_configurations where id = 18;\n\nselect * from users where team_id = 31; # 257\nselect u.email, cp.* from users u\njoin crm_profiles cp on u.id = cp.user_id\nwhere u.team_id = 31;\n\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 31\nand sa.provider = 'close';\n\nselect * from contacts where crm_configuration_id = 18;\n\n# ********************** NEPTUNE **************************************************************\nselect * from teams;\nselect * from users where id IN (1030, 1035, 1052);\nselect * from crm_configurations;\n\nselect * from users where team_id = 65; # 257\nselect * from team_settings where team_id = 65; # 257\nselect * from invitations where team_id = 65; # 257\nselect * from users where email = 'integration-account@jiminny.com'; # 257\nselect u.email, cp.* from users u\njoin crm_profiles cp on u.id = cp.user_id\nwhere u.team_id = 65;\n\nselect * from crm_configurations where id = 53;\nselect * from accounts where crm_configuration_id = 53 order by id desc;\nselect * from leads where crm_configuration_id = 53 order by id desc;\nselect * from contacts where crm_configuration_id = 53 order by id desc;\nselect * from opportunities where crm_configuration_id = 53 order by id desc;\nselect * from crm_profiles where crm_configuration_id = 53 order by id desc;\nselect * from crm_fields where crm_configuration_id = 53 order by id desc;\nselect * from crm_field_values where crm_field_id = 3341 order by id desc;\nselect * from crm_layouts where crm_configuration_id = 53 order by id desc;\nselect * from stages where crm_configuration_id = 53 order by id desc;\n\n\nselect * from crm_profiles where crm_configuration_id = 13;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 65\nand sa.provider = 'integration-app';\n\nselect * from contacts where crm_configuration_id = 13;\n\nselect * from social_accounts where sociable_id = 283;\n\nSELECT * FROM opportunities WHERE crm_provider_id = '006O400000E9bzeIAB';\n\nselect * from activity_providers where team_id = 65;\nSELECT * FROM activities WHERE crm_configuration_id IN (51, 52, 53);\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 65\n;\n\n# ***************************** STAGING ********************************************\nSELECT * FROM teams;\nSELECT * FROM teams WHERE id = 88;\nSELECT * FROM teams WHERE id = 89;\nselect * from team_settings where team_id = 89;\nSELECT * FROM users WHERE team_id = 89;\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 89;\n\nselect * from users;\nSELECT * FROM social_accounts WHERE sociable_id = 1761;\nSELECT * FROM crm_configurations WHERE id = 70;\nselect * from accounts where crm_configuration_id = 70 order by id desc;\nselect * from leads where crm_configuration_id = 70 order by id desc;\nselect * from contacts where crm_configuration_id = 70 order by id desc;\nselect * from opportunities where crm_configuration_id = 70 order by id desc;\nselect * from crm_profiles where crm_configuration_id = 70 order by id desc;\nselect * from crm_fields where crm_configuration_id = 70 order by id desc;\nselect * from crm_field_values where crm_field_id = 3536 order by id desc;\nselect * from crm_layouts where crm_configuration_id = 70 order by id desc;\nselect * from stages where crm_configuration_id = 70 order by id desc;\nselect * from business_processes where crm_configuration_id = 70 order by id desc;\nselect * from business_process_stages where business_process_id = 34;\n\nselect * from contacts where id = 10468;\n\nselect * from crm_layouts where crm_configuration_id = 70;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 388;\nSELECT * FROM crm_fields WHERE id IN (3533,3534,3535);\n\nselect * from activities where crm_configuration_id = 70\nand (account_id IS NOT NULL or lead_id IS NOT NULL or contact_id IS NOT NULL or opportunity_id IS NOT NULL) order by id desc;\n\nSELECT * FROM activities WHERE uuid_to_bin('2e10b60f-8a61-41c5-a3d4-28835353dc65') = uuid;\nSELECT * FROM activities where crm_configuration_id = 69 ;\n\nSELECT * FROM users WHERE email LIKE '%jiminny_web_sa2@jiminny.com%';\nSELECT * FROM activities WHERE uuid_to_bin('5a150c93-40fc-42ec-b3bd-c1d328e09f6e') = uuid;\nSELECT * FROM opportunities WHERE id = 385;\n\nselect * from participants p\njoin activities a on p.activity_id = a.id\nwhere a.crm_configuration_id = 70\nand (p.lead_id IS NOT NULL or p.contact_id IS NOT NULL);\nSELECT * FROM participants WHERE id = 1013638;\n\nselect * from teams where id = 90;\nselect * from users where team_id = 90;\nselect * from social_accounts where social_accounts.sociable_id IN (1960,1760);\nSELECT * FROM crm_profiles WHERE crm_configuration_id = 71;\nselect * from invitations where team_id = 90;\n\nselect * from crm_configurations where id = 71;\nselect * from accounts where crm_configuration_id = 71 order by id desc;\nselect * from leads where crm_configuration_id = 71 order by id desc;\nselect * from contacts where crm_configuration_id = 71 order by id desc;\nselect * from opportunities where crm_configuration_id = 71 order by id desc;\nselect * from crm_profiles where crm_configuration_id = 71 order by id desc;\nselect * from crm_fields where crm_configuration_id = 71 order by id desc;\nselect * from crm_field_values where crm_field_id = 3341 order by id desc;\nselect * from crm_layouts where crm_configuration_id = 71 order by id desc;\nselect * from stages where crm_configuration_id = 71 order by id desc;\n\nselect * from users order by secondary_email desc;\nselect u.id, u.email, u.status, sa.id, sa.provider_user_id from social_accounts sa\n join users u on sa.sociable_id = u.id\nwhere sa.provider = 'google' and u.email LIKE 'aneliya%';\n\nselect * from failed_jobs order by id desc;\n\nselect * from users where email = 'ben.allwright@learningpeople.co.uk' or secondary_email = 'ben.allwright@learningpeople.co.uk';\n\nselect * from teams;\nSELECT * FROM crm_profiles WHERE crm_configuration_id = 39;\nSELECT * FROM crm_fields WHERE crm_configuration_id = 39 and object_type = 'task';\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 1\nand sa.provider = 'salesforce';\n\n# ************************************************************************************\nSELECT * FROM activities WHERE uuid_to_bin('c38b3895-fd0f-4b1f-9fb2-c170dba137c6') = uuid;\nSELECT * FROM crm_configurations WHERE id = 70;\n\nselect * from teams where id = 1;\nselect * from groups where team_id = 1;\nselect * from users where team_id = 1;\n\nselect o.id, o.name,o.close_date, u.id, u.name, u.group_id, r.id, r.display_name, g.name, g.scope from opportunities o\njoin users u on o.user_id = u.id\njoin groups g on u.group_id = g.id\njoin role_user ru on u.id = ru.user_id\njoin roles r on ru.role_id = r.id\nwhere o.crm_configuration_id = 39 and close_date > '2024-01-01 00:00:00';\n\nselect * from role_user where user_id = 143;\nselect * from roles;\n\nselect * from role_user;\nselect * from groups where id = 9;\nselect * from scope_groups where group_id = 9;\n\n# ************************************************************************************\nselect * from teams where id = 36;\nselect * from crm_configurations;\nSELECT * FROM social_accounts WHERE sociable_id = 121;\n\nhttps://crmsandbox.zoho.com/crm/jiminnyw4/tab/Leads/4776201000005049105\nhttps://crmsandbox.zoho.com/crm/\n\nhttps://crm.zoho.com/crm/org3469620/tab/Leads/230045000229559080\n https://crm.zoho.com/crm/\n org3469620\n\nSELECT * FROM activities WHERE uuid_to_bin('03382d20-c8bc-48e7-a3d4-90b52fa5ceab') = uuid;\n\nselect * from users where email LIKE \"%mobile_automation_%\";\nselect * from social_accounts where sociable_id IN (2228);\nselect * from crm_profiles where user_id IN (2222,2223,2226,2227);\n\nselect * from teams order by id desc;\nSELECT * FROM users WHERE id = 2229;\nSELECT * FROM crm_profiles WHERE user_id = 2229;\nselect * from opportunities where crm_configuration_id = 88;\nselect * from crm_fields where crm_configuration_id = 88;\nselect * from crm_profiles where crm_configuration_id = 88;\n\nSELECT * FROM teams WHERE id = 1;\n\nSELECT * FROM users WHERE id = 143;\nSELECT * FROM users WHERE uuid_to_bin('fde193d3-06a2-4e1a-8895-62b94039215d') = uuid;\nSELECT * FROM teams WHERE uuid_to_bin('73385071-a756-42ae-9c73-8b53f2309467') = uuid;\n\nhttps://app.staging.jiminny.com/ondemand?\n min_duration=1\n &\n only_recorded=1\n &\n user_id%5B%5D=641f1acb-16b8-42d1-8726-df52979dad0e\n &\n sequence_number=2\n\n select * from users where team_id = 1 and email like '%stoyan%'\n\nselect * from coaching_feedbacks;\n\nselect * from teams;\nSELECT * FROM users WHERE team_id = 36;\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 19\nand sa.provider = 'pipedrive';\n\nselect * from users where id = 143;\n\nSELECT * FROM users WHERE uuid_to_bin('73180eeb-33de-4065-977d-ccbe0e6c94fc') = uuid;\nSELECT * FROM teams WHERE uuid_to_bin('73180eeb-33de-4065-977d-ccbe0e6c94fc') = uuid;\nSELECT * FROM activity_shares WHERE uuid_to_bin('73180eeb-33de-4065-977d-ccbe0e6c94fc') = uuid;\n\nselect * from users where team_id = 2;\nselect * from activities where crm_configuration_id = 39\nand activities.scheduled_start_time BETWEEN '2025-04-09 00:00:00' AND '2025-04-09 23:59:59'\nAND user_id = 143\norder by id desc;\n\n# ************************************************************************************\nselect * from teams where id = 142; # 2312, 126\nselect * from team_settings;\nselect * from users where team_id = 142; # 21642\nSELECT * FROM social_accounts WHERE sociable_id = 21642;\nSELECT * FROM crm_profiles cp join users u ON u.id = cp.user_id WHERE team_id = 142;\nselect * from crm_profiles where id IN (93);\nselect * from invitations;\nselect * from team_features where team_id = 1;\n\nSELECT * FROM crm_configurations WHERE id = 126;\nselect * from accounts where crm_configuration_id = 126 order by id desc;\nselect * from leads where crm_configuration_id = 126 order by id desc;\nselect * from contacts where crm_configuration_id = 126 order by id desc;\nselect * from opportunities where crm_configuration_id = 126 order by id desc;\nselect * from crm_profiles where crm_configuration_id = 126 order by id desc;\nselect * from crm_fields where crm_configuration_id = 126 # 11060\n# and type IN ('picklist', 'status')\n# and object_type = 'task'\norder by id desc;\n# 5731,5732,5733\nselect DISTINCT crm_field_id from crm_field_values where crm_field_id IN (11151,12239,12215,12185,12175,12165,12144,12137,12127,12109,12107,12105,12103,12092,12037,12005,12003,11987,11969,11958,11951,11942,11931,11924,11921,11917,11915,11901,11893,11883,11872,11870,11868,11866,11839,11833,11821,11793,11780,11777,11769,11757,11737,11735,11656,11645,11638,11629,11618,11611,11602,11591,11584,11581,11558,11544,11543,11534,11532,11529,11527,11503,11497,11493,11488,11470,11468,11457,11455,11397,11387,11372,11363,11348,11323,11318,11309,11301,11300,11292,11290,11286,11284,11256,11252,11242,11237,11233,11219,11176,11160) order by id desc;\nselect * from crm_layouts where crm_configuration_id = 126 order by id desc;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id in (300,299,298);\nselect * from stages where crm_configuration_id = 126 order by id desc;\nselect * from business_processes where crm_configuration_id = 126 order by id desc;\nselect * from business_process_stages where business_process_id IN (76,75,74,73);\nselect * from playbooks where team_id = 142;\nselect * from playbook_layouts where playbook_id IN (108);\nSELECT * FROM playbook_categories WHERE playbook_id IN (108);\n\nselect * from teams where id = 130;\nSELECT * FROM social_accounts WHERE sociable_id = 2291;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 2\nand sa.provider = 'hubspot';\n\nSELECT * FROM activities\n WHERE crm_configuration_id = 110;\n\nselect * from teams;\nselect * from crm_configurations;\n\nSELECT * FROM activities WHERE id = 628773;\nSELECT * FROM crm_profiles WHERE user_id = 1460;\nSELECT * FROM social_accounts WHERE sociable_id = 2291;\n\nselect * from teams;\nselect ru.*, pr.*, p.* from users u join role_user ru on ru.user_id = u.id\njoin permission_role pr on pr.role_id = ru.role_id\n join permissions p on p.id = pr.permission_id\nwhere team_id = 495 and p.name IN ('dial');\n\nselect * from teams where id = 145;\nselect * from crm_configurations where id = 129;\nselect * from social_accounts where sociable_id = 2317;\nSELECT * FROM activities WHERE uuid_to_bin('8dbab184-a333-4268-ad57-fb41f8d53a9a') = uuid;\n\nselect * from teams where id = 1;\nSELECT * FROM crm_layouts WHERE crm_configuration_id = 39;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 280;\nSELECT * FROM crm_layout_entities WHERE id = 5507;\nSELECT * FROM crm_fields WHERE crm_configuration_id = 39 and object_type IN ('event');\n\nselect * from teams;\nselect * from activities where crm_configuration_id = 14;\n\nSELECT * FROM social_accounts where provider = 'copper';\n\nselect * from activities where id = 628467;\nselect * from participants where activity_id = 628467;\n\nSELECT * FROM contacts WHERE id = 3969;\nSELECT * FROM accounts WHERE id = 177;\n\nSELECT * FROM activities WHERE uuid_to_bin('4eb54c77-cfa3-2bd4-84a7-9ed46a21c988') = uuid;\n\n# ********************* BH\nselect * from teams where id = 36;\nSELECT * FROM crm_configurations WHERE id = 21;\nselect * from activities where crm_configuration_id = 21 and id = 607901;\nselect * from activities where crm_configuration_id = 21;\n\nselect * roles;\nselect * from permissions;\nselect * from permission_role where permission_id = 226;\n\nselect * from migrations order by id desc;\n\n# mercury\n# neptune\n# earth\n\nselect * from teams;\nselect * from teams where id = 19;\nselect * from teams where id = 27;\nselect * from users where team_id = 27;\nSELECT * FROM crm_configurations WHERE id = 42;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 19\nand sa.provider = 'pipedrive';\n\nselect * from activities where id = 631461;\nSELECT * FROM crm_field_values WHERE crm_field_id = 180;\n\nselect * from teams where id = 2;\nSELECT * FROM social_accounts WHERE sociable_id = 89;\n\nSELECT * FROM activities WHERE uuid_to_bin('ba0c029a-bc14-4e17-8603-64174acebcbb') = uuid; # 634273\nselect * from activity_summary_logs where activity_id = 634273;\n\nselect * from sidekick_settings where team_id = 2;\n\nselect * from teams; # 2, 2\nSELECT * FROM crm_configurations WHERE team_id = 2; # 2\nselect * from team_features where team_id = 2;\nselect * from features;\nSELECT * FROM opportunities WHERE crm_configuration_id = 2 and crm_provider_id = '51317301383';\nSELECT * FROM opportunities WHERE crm_configuration_id = 2 order by id desc;\n\nselect * from automated_reports order by id desc;\nselect * from automated_report_results order by id desc;\nselect * from users where team_id = 1 and id IN (7160, 3248);\nselect * from migrations order by id desc;\n\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 1 and sa.provider = 'salesforce';\n\nselect * from teams where id = 1;\nselect * from groups g JOIN playbooks p on g.playbook_id = p.id where g.team_id = 1;\nselect * from groups where id = 565;\nselect * from playbooks where team_id = 1;\nselect * from playbooks where id = 175;\nselect * from playbook_categories where playbook_id = 175;\nselect * from users where team_id = 1;\nselect * from users where id = 7160;\nselect * from crm_profiles where user_id = 7160;\nselect * from features;\nselect\n *\n# id, uuid, type, provider, playbook_category_id, user_id, lead_id, contact_id, account_id, opportunity_id, stage_id,\n# crm_configuration_id, crm_provider_id, transcription_id, status\nfrom activities where crm_configuration_id = 1 and type = 'conference'\n# and crm_provider_id IS NOT NULL\nand provider != 'uploader' and actual_start_time IS NOT NULL\nORDER by id desc;\nselect * from activities where id = 54747783; # 00UO400000pCzojMAC\n\nselect p.id, p.activity_type, pc.id, pc.name\nFROM playbooks p\njoin playbook_categories pc on p.id = pc.playbook_id\nwhere p.team_id = 1 and p.activity_type = 'event';\n\nSELECT * FROM crm_fields WHERE crm_configuration_id = 1 and object_type = 'event';\nSELECT * FROM crm_field_values WHERE crm_field_id = 4;\n\nselect * from crm_layouts cl join playbook_layouts pl on cl.id = pl.layout_id\nwhere crm_configuration_id = 1 and pl.playbook_id = 175;\n\nselect * from teams;\nSELECT r.* FROM automated_reports r\njoin teams t on r.team_id = t.id\nWHERE r.frequency = 'daily'\n and r.status = 1\nAND t.status = 'active'\nAND (r.expires_at >= now() OR r.expires_at IS NULL);\n\nselect * from automated_report_results where report_id IN (18, 33);\n\nselect * from activity_searches where id = 10932;\nselect * from activity_search_filters where activity_search_id = 10932;\nselect * from automated_reports;\nselect * from automated_report_results where report_id IN (34, 35);","depth":4,"value":"SELECT * FROM teams WHERE id = 1;\n\nselect * from crm_layouts where crm_configuration_id = 39;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 283;\nSELECT * FROM crm_fields WHERE id = 2234;\nSELECT * FROM crm_field_values WHERE crm_field_id = 2234;\n\nselect * from crm_profiles where user_id = 143;\n\nselect * from record_types where crm_configuration_id = 39; # 0121K000001MHElQAO,0121K000001MHEqQAO\nselect * from business_processes where crm_configuration_id = 39;\n# 01941000000H669AAC, 01941000000H66JAAS\n\nselect * from record_type_field_values\n where record_type_id IN (24);\n\nselect * from crm_field_values where id IN (2730);\n\nselect * from crm_configurations where id = 39;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 1\nand sa.provider = 'salesforce'; #1035\n\n\nselect * from users where team_id = 1; # 222 group 3\nSELECT * FROM activities WHERE user_id = 222 order by id desc;\nselect * from sidekick_settings where team_id = 1;\nselect * from teams where id = 1;\nselect * from team_features where team_id = 1;\n\nselect * from activities where crm_configuration_id = 2\nand provider = 'ms-teams' and id = 608765;\n\nSELECT * FROM activities WHERE crm_configuration_id = 2 and crm_provider_id = '59523413338';\n\nselect * from sidekick_settings where team_id = 2;\n\nSELECT * FROM activities WHERE id = 608660;\nselect * from activity_summary_logs where activity_id = 608660;\nselect * from ai_prompts where transcription_id = 11214;\n\n# ********************************************************************************************************\nSELECT * FROM activities WHERE uuid_to_bin('ed78a437-2804-450e-ab2f-56ab1c641346') = uuid;\n# id: 608818, crm: 59628809737\nSELECT * FROM activities WHERE uuid_to_bin('36b06e55-afdd-4782-8dee-c624cd0af191') = uuid;\n# id: 608821, crm: 59632069252\nSELECT ce.start_time, ce.end_time, a.id, a.uuid, crm_provider_id, calendar_event_id, title,\nplaybook_category_id, user_id, lead_id, contact_id, account_id, opportunity_id,\nscheduled_start_time, scheduled_end_time, actual_start_time, actual_end_time, a.created_at\nFROM activities a\njoin calendar_events ce on a.calendar_event_id = ce.id\nWHERE a.id IN (608818, 608821);\n\nselect * from users where team_id = 1;\nselect * from team_settings where team_id = 1;\nselect * from crm_profiles where crm_configuration_id = 39 order by user_id;\n\nselect * from team_features where team_id = 1;\n\nselect * from users where team_id = 2;\n\nSELECT * FROM activities WHERE uuid_to_bin('ec7647e9-5225-458b-b475-f31aa2769204') = uuid; # 612639\n# Preslava N. Ivanova, grou id 3\n\nSELECT * FROM opportunities WHERE uuid_to_bin('a2928fe5-aec5-46cb-85d9-7654c89e46a6') = uuid;\n\nselect * from activities where opportunity_id = 344 and actual_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00';\n\nselect\n a.id,\n a.type,\n a.scheduled_start_time,\n a.actual_start_time,\n a.created_at,\n a.opportunity_id,\n a.status\nFROM activities a\nWHERE opportunity_id = 344\nand status IN ('completed', 'received', 'delivered')\nand (\n (a.actual_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00')\nOR (a.created_at between '2024-10-11 00:00:00' and '2024-10-12 00:00:00')\nOR (a.scheduled_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00'))\n;\n\nSELECT * FROM users WHERE id = 222;\n\nSELECT * FROM crm_profiles WHERE user_id = 222;\nselect * from crm_layouts where crm_configuration_id = 39;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 281;\n\nselect * from group_deal_risk_types;\n\nselect * from opportunities where team_id = 1;\n\nSELECT * FROM opportunities WHERE id = 315;\nSELECT * FROM crm_field_data WHERE object_id = 315;\nselect * from crm_field_data where object_id = 260;\n\nselect * from generic_ai_prompts where subject_id = 315;\n\nselect * from teams; # 36, 21, 121, james.graham@bullhorn.jiminny.com\nSELECT * FROM social_accounts WHERE sociable_id = 121 and provider = 'bullhorn';\n\n# ************************************************************************************\nselect * from teams where id = 1;\nselect * from crm_configurations where id = 39;\nselect * from users where team_id = 1;\nselect u.email, cp.* from users u\njoin crm_profiles cp on u.id = cp.user_id\nwhere u.team_id = 1;\n# 1 - 00541000004281rAAA\n# 204 - 0052g000003freeAAA\n# 429 - 0052g000003qGOiAAM\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 1\nand sa.provider = 'salesforce';\n\nselect * from activities where type = 'softphone'\nand created_at > '2024-12-11 15:24:36' order by id desc;\n\nselect * from activity_providers where team_id = 1;\nselect * from activity_provider_users where activity_provider_id = 328;\n\nselect * from opportunities where crm_configuration_id = 39\nAND account_id = 178 AND is_closed = false\norder by created_at DESC;\n\nselect * from contacts where id = 3952;\nselect * from accounts where id = 178;\n\n# ************************************************************************************\nselect * from teams where id = 36;\nselect * from crm_configurations where id = 21;\nselect * from users where team_id = 36;\nselect u.email, cp.* from users u\njoin crm_profiles cp on u.id = cp.user_id\nwhere u.team_id = 36;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 36\nand sa.provider = 'bullhorn';\n\nselect * from social_accounts where id = 348;\nUPDATE social_accounts SET\nprovider_user_token = '21442_6802599_91:41179a58-21e7-4d7c-ad58-56bb666b2f65',\nprovider_refresh_token = '21442_6802599_91:01c6b335-3f2a-42e4-85ff-8a08fa65fceb',\nexpires = 1733998131,\nstate = 'connected'\nWHERE id = 348;\n\n# ************************************************************************************\nselect * from teams where id = 31;\nselect * from crm_configurations where id = 18;\n\nselect * from users where team_id = 31; # 257\nselect u.email, cp.* from users u\njoin crm_profiles cp on u.id = cp.user_id\nwhere u.team_id = 31;\n\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 31\nand sa.provider = 'close';\n\nselect * from contacts where crm_configuration_id = 18;\n\n# ********************** NEPTUNE **************************************************************\nselect * from teams;\nselect * from users where id IN (1030, 1035, 1052);\nselect * from crm_configurations;\n\nselect * from users where team_id = 65; # 257\nselect * from team_settings where team_id = 65; # 257\nselect * from invitations where team_id = 65; # 257\nselect * from users where email = 'integration-account@jiminny.com'; # 257\nselect u.email, cp.* from users u\njoin crm_profiles cp on u.id = cp.user_id\nwhere u.team_id = 65;\n\nselect * from crm_configurations where id = 53;\nselect * from accounts where crm_configuration_id = 53 order by id desc;\nselect * from leads where crm_configuration_id = 53 order by id desc;\nselect * from contacts where crm_configuration_id = 53 order by id desc;\nselect * from opportunities where crm_configuration_id = 53 order by id desc;\nselect * from crm_profiles where crm_configuration_id = 53 order by id desc;\nselect * from crm_fields where crm_configuration_id = 53 order by id desc;\nselect * from crm_field_values where crm_field_id = 3341 order by id desc;\nselect * from crm_layouts where crm_configuration_id = 53 order by id desc;\nselect * from stages where crm_configuration_id = 53 order by id desc;\n\n\nselect * from crm_profiles where crm_configuration_id = 13;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 65\nand sa.provider = 'integration-app';\n\nselect * from contacts where crm_configuration_id = 13;\n\nselect * from social_accounts where sociable_id = 283;\n\nSELECT * FROM opportunities WHERE crm_provider_id = '006O400000E9bzeIAB';\n\nselect * from activity_providers where team_id = 65;\nSELECT * FROM activities WHERE crm_configuration_id IN (51, 52, 53);\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 65\n;\n\n# ***************************** STAGING ********************************************\nSELECT * FROM teams;\nSELECT * FROM teams WHERE id = 88;\nSELECT * FROM teams WHERE id = 89;\nselect * from team_settings where team_id = 89;\nSELECT * FROM users WHERE team_id = 89;\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 89;\n\nselect * from users;\nSELECT * FROM social_accounts WHERE sociable_id = 1761;\nSELECT * FROM crm_configurations WHERE id = 70;\nselect * from accounts where crm_configuration_id = 70 order by id desc;\nselect * from leads where crm_configuration_id = 70 order by id desc;\nselect * from contacts where crm_configuration_id = 70 order by id desc;\nselect * from opportunities where crm_configuration_id = 70 order by id desc;\nselect * from crm_profiles where crm_configuration_id = 70 order by id desc;\nselect * from crm_fields where crm_configuration_id = 70 order by id desc;\nselect * from crm_field_values where crm_field_id = 3536 order by id desc;\nselect * from crm_layouts where crm_configuration_id = 70 order by id desc;\nselect * from stages where crm_configuration_id = 70 order by id desc;\nselect * from business_processes where crm_configuration_id = 70 order by id desc;\nselect * from business_process_stages where business_process_id = 34;\n\nselect * from contacts where id = 10468;\n\nselect * from crm_layouts where crm_configuration_id = 70;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 388;\nSELECT * FROM crm_fields WHERE id IN (3533,3534,3535);\n\nselect * from activities where crm_configuration_id = 70\nand (account_id IS NOT NULL or lead_id IS NOT NULL or contact_id IS NOT NULL or opportunity_id IS NOT NULL) order by id desc;\n\nSELECT * FROM activities WHERE uuid_to_bin('2e10b60f-8a61-41c5-a3d4-28835353dc65') = uuid;\nSELECT * FROM activities where crm_configuration_id = 69 ;\n\nSELECT * FROM users WHERE email LIKE '%jiminny_web_sa2@jiminny.com%';\nSELECT * FROM activities WHERE uuid_to_bin('5a150c93-40fc-42ec-b3bd-c1d328e09f6e') = uuid;\nSELECT * FROM opportunities WHERE id = 385;\n\nselect * from participants p\njoin activities a on p.activity_id = a.id\nwhere a.crm_configuration_id = 70\nand (p.lead_id IS NOT NULL or p.contact_id IS NOT NULL);\nSELECT * FROM participants WHERE id = 1013638;\n\nselect * from teams where id = 90;\nselect * from users where team_id = 90;\nselect * from social_accounts where social_accounts.sociable_id IN (1960,1760);\nSELECT * FROM crm_profiles WHERE crm_configuration_id = 71;\nselect * from invitations where team_id = 90;\n\nselect * from crm_configurations where id = 71;\nselect * from accounts where crm_configuration_id = 71 order by id desc;\nselect * from leads where crm_configuration_id = 71 order by id desc;\nselect * from contacts where crm_configuration_id = 71 order by id desc;\nselect * from opportunities where crm_configuration_id = 71 order by id desc;\nselect * from crm_profiles where crm_configuration_id = 71 order by id desc;\nselect * from crm_fields where crm_configuration_id = 71 order by id desc;\nselect * from crm_field_values where crm_field_id = 3341 order by id desc;\nselect * from crm_layouts where crm_configuration_id = 71 order by id desc;\nselect * from stages where crm_configuration_id = 71 order by id desc;\n\nselect * from users order by secondary_email desc;\nselect u.id, u.email, u.status, sa.id, sa.provider_user_id from social_accounts sa\n join users u on sa.sociable_id = u.id\nwhere sa.provider = 'google' and u.email LIKE 'aneliya%';\n\nselect * from failed_jobs order by id desc;\n\nselect * from users where email = 'ben.allwright@learningpeople.co.uk' or secondary_email = 'ben.allwright@learningpeople.co.uk';\n\nselect * from teams;\nSELECT * FROM crm_profiles WHERE crm_configuration_id = 39;\nSELECT * FROM crm_fields WHERE crm_configuration_id = 39 and object_type = 'task';\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 1\nand sa.provider = 'salesforce';\n\n# ************************************************************************************\nSELECT * FROM activities WHERE uuid_to_bin('c38b3895-fd0f-4b1f-9fb2-c170dba137c6') = uuid;\nSELECT * FROM crm_configurations WHERE id = 70;\n\nselect * from teams where id = 1;\nselect * from groups where team_id = 1;\nselect * from users where team_id = 1;\n\nselect o.id, o.name,o.close_date, u.id, u.name, u.group_id, r.id, r.display_name, g.name, g.scope from opportunities o\njoin users u on o.user_id = u.id\njoin groups g on u.group_id = g.id\njoin role_user ru on u.id = ru.user_id\njoin roles r on ru.role_id = r.id\nwhere o.crm_configuration_id = 39 and close_date > '2024-01-01 00:00:00';\n\nselect * from role_user where user_id = 143;\nselect * from roles;\n\nselect * from role_user;\nselect * from groups where id = 9;\nselect * from scope_groups where group_id = 9;\n\n# ************************************************************************************\nselect * from teams where id = 36;\nselect * from crm_configurations;\nSELECT * FROM social_accounts WHERE sociable_id = 121;\n\nhttps://crmsandbox.zoho.com/crm/jiminnyw4/tab/Leads/4776201000005049105\nhttps://crmsandbox.zoho.com/crm/\n\nhttps://crm.zoho.com/crm/org3469620/tab/Leads/230045000229559080\n https://crm.zoho.com/crm/\n org3469620\n\nSELECT * FROM activities WHERE uuid_to_bin('03382d20-c8bc-48e7-a3d4-90b52fa5ceab') = uuid;\n\nselect * from users where email LIKE \"%mobile_automation_%\";\nselect * from social_accounts where sociable_id IN (2228);\nselect * from crm_profiles where user_id IN (2222,2223,2226,2227);\n\nselect * from teams order by id desc;\nSELECT * FROM users WHERE id = 2229;\nSELECT * FROM crm_profiles WHERE user_id = 2229;\nselect * from opportunities where crm_configuration_id = 88;\nselect * from crm_fields where crm_configuration_id = 88;\nselect * from crm_profiles where crm_configuration_id = 88;\n\nSELECT * FROM teams WHERE id = 1;\n\nSELECT * FROM users WHERE id = 143;\nSELECT * FROM users WHERE uuid_to_bin('fde193d3-06a2-4e1a-8895-62b94039215d') = uuid;\nSELECT * FROM teams WHERE uuid_to_bin('73385071-a756-42ae-9c73-8b53f2309467') = uuid;\n\nhttps://app.staging.jiminny.com/ondemand?\n min_duration=1\n &\n only_recorded=1\n &\n user_id%5B%5D=641f1acb-16b8-42d1-8726-df52979dad0e\n &\n sequence_number=2\n\n select * from users where team_id = 1 and email like '%stoyan%'\n\nselect * from coaching_feedbacks;\n\nselect * from teams;\nSELECT * FROM users WHERE team_id = 36;\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 19\nand sa.provider = 'pipedrive';\n\nselect * from users where id = 143;\n\nSELECT * FROM users WHERE uuid_to_bin('73180eeb-33de-4065-977d-ccbe0e6c94fc') = uuid;\nSELECT * FROM teams WHERE uuid_to_bin('73180eeb-33de-4065-977d-ccbe0e6c94fc') = uuid;\nSELECT * FROM activity_shares WHERE uuid_to_bin('73180eeb-33de-4065-977d-ccbe0e6c94fc') = uuid;\n\nselect * from users where team_id = 2;\nselect * from activities where crm_configuration_id = 39\nand activities.scheduled_start_time BETWEEN '2025-04-09 00:00:00' AND '2025-04-09 23:59:59'\nAND user_id = 143\norder by id desc;\n\n# ************************************************************************************\nselect * from teams where id = 142; # 2312, 126\nselect * from team_settings;\nselect * from users where team_id = 142; # 21642\nSELECT * FROM social_accounts WHERE sociable_id = 21642;\nSELECT * FROM crm_profiles cp join users u ON u.id = cp.user_id WHERE team_id = 142;\nselect * from crm_profiles where id IN (93);\nselect * from invitations;\nselect * from team_features where team_id = 1;\n\nSELECT * FROM crm_configurations WHERE id = 126;\nselect * from accounts where crm_configuration_id = 126 order by id desc;\nselect * from leads where crm_configuration_id = 126 order by id desc;\nselect * from contacts where crm_configuration_id = 126 order by id desc;\nselect * from opportunities where crm_configuration_id = 126 order by id desc;\nselect * from crm_profiles where crm_configuration_id = 126 order by id desc;\nselect * from crm_fields where crm_configuration_id = 126 # 11060\n# and type IN ('picklist', 'status')\n# and object_type = 'task'\norder by id desc;\n# 5731,5732,5733\nselect DISTINCT crm_field_id from crm_field_values where crm_field_id IN (11151,12239,12215,12185,12175,12165,12144,12137,12127,12109,12107,12105,12103,12092,12037,12005,12003,11987,11969,11958,11951,11942,11931,11924,11921,11917,11915,11901,11893,11883,11872,11870,11868,11866,11839,11833,11821,11793,11780,11777,11769,11757,11737,11735,11656,11645,11638,11629,11618,11611,11602,11591,11584,11581,11558,11544,11543,11534,11532,11529,11527,11503,11497,11493,11488,11470,11468,11457,11455,11397,11387,11372,11363,11348,11323,11318,11309,11301,11300,11292,11290,11286,11284,11256,11252,11242,11237,11233,11219,11176,11160) order by id desc;\nselect * from crm_layouts where crm_configuration_id = 126 order by id desc;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id in (300,299,298);\nselect * from stages where crm_configuration_id = 126 order by id desc;\nselect * from business_processes where crm_configuration_id = 126 order by id desc;\nselect * from business_process_stages where business_process_id IN (76,75,74,73);\nselect * from playbooks where team_id = 142;\nselect * from playbook_layouts where playbook_id IN (108);\nSELECT * FROM playbook_categories WHERE playbook_id IN (108);\n\nselect * from teams where id = 130;\nSELECT * FROM social_accounts WHERE sociable_id = 2291;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 2\nand sa.provider = 'hubspot';\n\nSELECT * FROM activities\n WHERE crm_configuration_id = 110;\n\nselect * from teams;\nselect * from crm_configurations;\n\nSELECT * FROM activities WHERE id = 628773;\nSELECT * FROM crm_profiles WHERE user_id = 1460;\nSELECT * FROM social_accounts WHERE sociable_id = 2291;\n\nselect * from teams;\nselect ru.*, pr.*, p.* from users u join role_user ru on ru.user_id = u.id\njoin permission_role pr on pr.role_id = ru.role_id\n join permissions p on p.id = pr.permission_id\nwhere team_id = 495 and p.name IN ('dial');\n\nselect * from teams where id = 145;\nselect * from crm_configurations where id = 129;\nselect * from social_accounts where sociable_id = 2317;\nSELECT * FROM activities WHERE uuid_to_bin('8dbab184-a333-4268-ad57-fb41f8d53a9a') = uuid;\n\nselect * from teams where id = 1;\nSELECT * FROM crm_layouts WHERE crm_configuration_id = 39;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 280;\nSELECT * FROM crm_layout_entities WHERE id = 5507;\nSELECT * FROM crm_fields WHERE crm_configuration_id = 39 and object_type IN ('event');\n\nselect * from teams;\nselect * from activities where crm_configuration_id = 14;\n\nSELECT * FROM social_accounts where provider = 'copper';\n\nselect * from activities where id = 628467;\nselect * from participants where activity_id = 628467;\n\nSELECT * FROM contacts WHERE id = 3969;\nSELECT * FROM accounts WHERE id = 177;\n\nSELECT * FROM activities WHERE uuid_to_bin('4eb54c77-cfa3-2bd4-84a7-9ed46a21c988') = uuid;\n\n# ********************* BH\nselect * from teams where id = 36;\nSELECT * FROM crm_configurations WHERE id = 21;\nselect * from activities where crm_configuration_id = 21 and id = 607901;\nselect * from activities where crm_configuration_id = 21;\n\nselect * roles;\nselect * from permissions;\nselect * from permission_role where permission_id = 226;\n\nselect * from migrations order by id desc;\n\n# mercury\n# neptune\n# earth\n\nselect * from teams;\nselect * from teams where id = 19;\nselect * from teams where id = 27;\nselect * from users where team_id = 27;\nSELECT * FROM crm_configurations WHERE id = 42;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 19\nand sa.provider = 'pipedrive';\n\nselect * from activities where id = 631461;\nSELECT * FROM crm_field_values WHERE crm_field_id = 180;\n\nselect * from teams where id = 2;\nSELECT * FROM social_accounts WHERE sociable_id = 89;\n\nSELECT * FROM activities WHERE uuid_to_bin('ba0c029a-bc14-4e17-8603-64174acebcbb') = uuid; # 634273\nselect * from activity_summary_logs where activity_id = 634273;\n\nselect * from sidekick_settings where team_id = 2;\n\nselect * from teams; # 2, 2\nSELECT * FROM crm_configurations WHERE team_id = 2; # 2\nselect * from team_features where team_id = 2;\nselect * from features;\nSELECT * FROM opportunities WHERE crm_configuration_id = 2 and crm_provider_id = '51317301383';\nSELECT * FROM opportunities WHERE crm_configuration_id = 2 order by id desc;\n\nselect * from automated_reports order by id desc;\nselect * from automated_report_results order by id desc;\nselect * from users where team_id = 1 and id IN (7160, 3248);\nselect * from migrations order by id desc;\n\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 1 and sa.provider = 'salesforce';\n\nselect * from teams where id = 1;\nselect * from groups g JOIN playbooks p on g.playbook_id = p.id where g.team_id = 1;\nselect * from groups where id = 565;\nselect * from playbooks where team_id = 1;\nselect * from playbooks where id = 175;\nselect * from playbook_categories where playbook_id = 175;\nselect * from users where team_id = 1;\nselect * from users where id = 7160;\nselect * from crm_profiles where user_id = 7160;\nselect * from features;\nselect\n *\n# id, uuid, type, provider, playbook_category_id, user_id, lead_id, contact_id, account_id, opportunity_id, stage_id,\n# crm_configuration_id, crm_provider_id, transcription_id, status\nfrom activities where crm_configuration_id = 1 and type = 'conference'\n# and crm_provider_id IS NOT NULL\nand provider != 'uploader' and actual_start_time IS NOT NULL\nORDER by id desc;\nselect * from activities where id = 54747783; # 00UO400000pCzojMAC\n\nselect p.id, p.activity_type, pc.id, pc.name\nFROM playbooks p\njoin playbook_categories pc on p.id = pc.playbook_id\nwhere p.team_id = 1 and p.activity_type = 'event';\n\nSELECT * FROM crm_fields WHERE crm_configuration_id = 1 and object_type = 'event';\nSELECT * FROM crm_field_values WHERE crm_field_id = 4;\n\nselect * from crm_layouts cl join playbook_layouts pl on cl.id = pl.layout_id\nwhere crm_configuration_id = 1 and pl.playbook_id = 175;\n\nselect * from teams;\nSELECT r.* FROM automated_reports r\njoin teams t on r.team_id = t.id\nWHERE r.frequency = 'daily'\n and r.status = 1\nAND t.status = 'active'\nAND (r.expires_at >= now() OR r.expires_at IS NULL);\n\nselect * from automated_report_results where report_id IN (18, 33);\n\nselect * from activity_searches where id = 10932;\nselect * from activity_search_filters where activity_search_id = 10932;\nselect * from automated_reports;\nselect * from automated_report_results where report_id IN (34, 35);","role_description":"text entry area","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.088194445,"height":0.027777778},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"102","depth":4,"role_description":"text"},{"role":"AXStaticText","text":"3","depth":4,"role_description":"text"},{"role":"AXStaticText","text":"34","depth":4,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Services\\Kiosk\\AutomatedReports;\n\nuse Carbon\\CarbonImmutable;\nuse Carbon\\CarbonInterface;\nuse Carbon\\Exceptions\\InvalidFormatException;\nuse DateTime;\nuse DateTimeInterface;\nuse DateTimeZone;\nuse Illuminate\\Contracts\\Bus\\Dispatcher as BusDispatcher;\nuse Illuminate\\Database\\Eloquent\\Builder;\nuse Illuminate\\Support\\Carbon;\nuse Illuminate\\Support\\Collection;\nuse Illuminate\\Support\\Facades\\Log;\nuse Illuminate\\Support\\Facades\\Storage;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinition\\InputTypeEnum;\nuse Jiminny\\Component\\AskAnything\\AskAnythingPromptService;\nuse Jiminny\\Component\\AskAnything\\Dtos\\AskAnythingPromptDto;\nuse Jiminny\\Component\\UrlGenerator\\Webhook;\nuse Jiminny\\Contracts\\Repositories\\PlaybookCategoryRepository;\nuse Jiminny\\Contracts\\Repositories\\TeamRepository;\nuse Jiminny\\Contracts\\Repositories\\UserRepository;\nuse Jiminny\\Exceptions\\ApplicationException;\nuse Jiminny\\Exceptions\\InvalidArgumentException;\nuse Jiminny\\Exceptions\\ModelNotFoundException;\nuse Jiminny\\Jobs\\AutomatedReports\\RequestGenerateReportJob;\nuse Jiminny\\Models\\Activity\\Search;\nuse Jiminny\\Models\\AskAnything\\AskAnythingPrompt;\nuse Jiminny\\Models\\AskAnything\\AskAnythingPromptTarget;\nuse Jiminny\\Models\\AutomatedReport;\nuse Jiminny\\Models\\AutomatedReportResult;\nuse Jiminny\\Models\\Contracts\\UserContract;\nuse Jiminny\\Models\\Feature\\FeatureEnum;\nuse Jiminny\\Models\\Team;\nuse Jiminny\\Models\\User;\nuse Jiminny\\Repositories\\AskAnythingRepository;\nuse Jiminny\\Repositories\\AutomatedReportsRepository;\nuse Jiminny\\Repositories\\GroupRepository;\nuse Jiminny\\Repositories\\SearchRepository;\nuse Jiminny\\Repositories\\StageRepository;\nuse Throwable;\n\nclass AutomatedReportsService\n{\n public const string TYPE_LOSS_ANALYSIS = 'loss_analysis';\n public const string TYPE_ASK_JIMINNY = 'ask_jiminny';\n\n /**\n * Standard report types (used by kiosk for existing automated reports).\n */\n // @TODO this will add filter, however if we need to control feature by FF we need conditional logic\n public const array TYPES = [\n ['id' => 'exec_summary', 'name' => 'Exec Summary'],\n ['id' => 'coaching_profiles', 'name' => 'Coaching Profiles'],\n ['id' => 'product_feedback', 'name' => 'Product Feedback'],\n ['id' => self::TYPE_LOSS_ANALYSIS, 'name' => 'Loss Analysis'],\n// ['id' => 'questions', 'name' => 'Questions'],\n// ['id' => 'statistical_quant', 'name' => 'Statistical Quantitative'],\n ];\n\n public const array ALL_TYPES = [\n ...self::TYPES,\n ['id' => self::TYPE_ASK_JIMINNY, 'name' => 'Ask Jiminny'],\n ];\n\n public const string FREQUENCY_DAILY = 'daily';\n public const string FREQUENCY_WEEKLY = 'weekly';\n public const string FREQUENCY_MONTHLY = 'monthly';\n public const string FREQUENCY_QUARTERLY = 'quarterly';\n public const string FREQUENCY_ONE_OFF = 'one_off';\n\n /**\n * Frequencies for standard (non-Ask Jiminny) reports.\n */\n public const array FREQUENCIES = [\n ['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],\n ['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],\n ['id' => self::FREQUENCY_QUARTERLY, 'name' => 'Quarterly'],\n ['id' => self::FREQUENCY_ONE_OFF, 'name' => 'One-off'],\n ];\n\n /**\n * Frequencies for Ask Jiminny reports.\n */\n public const array ASK_JIMINNY_FREQUENCIES = [\n ['id' => self::FREQUENCY_DAILY, 'name' => 'Daily'],\n ['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],\n ['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],\n ];\n\n public const string MEDIA_TYPE_PDF = 'pdf';\n public const string MEDIA_TYPE_PODCAST = 'podcast';\n public const array MEDIA_TYPES = [self::MEDIA_TYPE_PDF, self::MEDIA_TYPE_PODCAST];\n public const array MEDIA_TYPE_OBJECT_PDF = ['id' => self::MEDIA_TYPE_PDF, 'name' => 'PDF'];\n public const array MEDIA_TYPE_OBJECT_PODCAST = ['id' => self::MEDIA_TYPE_PODCAST, 'name' => 'Podcast'];\n public const array MEDIA_TYPE_OBJECTS = [self::MEDIA_TYPE_OBJECT_PDF, self::MEDIA_TYPE_OBJECT_PODCAST];\n\n public const array CALL_TYPE_CONFERENCE = ['id' => 'conference', 'name' => 'Conference'];\n public const array CALL_TYPE_DIALER = ['id' => 'dialer', 'name' => 'Dialer'];\n public const int SENT_REPORT_AT_HOURS = 5;\n public const string PDF_KEY = 'pdf';\n public const string AUDIO_KEY = 'audio';\n\n private const array ALL_FREQUENCIES = [\n ['id' => self::FREQUENCY_DAILY, 'name' => 'Daily'],\n ['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],\n ['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],\n ['id' => self::FREQUENCY_QUARTERLY, 'name' => 'Quarterly'],\n ['id' => self::FREQUENCY_ONE_OFF, 'name' => 'One-off'],\n ];\n private const string S3_DIR = 'reports';\n private const array FILE_EXTENSIONS_VARIANTS = ['html', 'MD', 'pdf'];\n private const array FILE_PODCAST_EXTENSIONS_VARIANTS = ['json', 'mp3', 'ssml'];\n\n public function __construct(\n private readonly TeamRepository $teamRepository,\n private readonly GroupRepository $groupRepository,\n private readonly UserRepository $userRepository,\n private readonly StageRepository $stageRepository,\n private readonly DealStagesService $dealStagesService,\n private readonly RecipientsService $recipientsService,\n private readonly AutomatedReportsRepository $automatedReportsRepository,\n private readonly Webhook $webhookService,\n private readonly BusDispatcher $dispatcher,\n private readonly ActivityTypeService $activityTypeService,\n private readonly PlaybookCategoryRepository $playbookCategoryRepository,\n private readonly AskAnythingPromptService $askAnythingPromptService,\n private readonly SearchRepository $activitySearchRepository,\n private readonly AskAnythingRepository $askAnythingRepository,\n ) {\n }\n\n public static function getTypes(): array\n {\n $types = self::TYPES;\n\n return array_map(static function ($type) {\n return $type['id'];\n }, $types);\n }\n\n public static function getCallTypes(): array\n {\n return array_map(static function ($callType) {\n return $callType['id'];\n }, [self::CALL_TYPE_CONFERENCE, self::CALL_TYPE_DIALER]);\n }\n\n public static function getFrequencies(): array\n {\n return array_map(static function ($frequency) {\n return $frequency['id'];\n }, self::FREQUENCIES);\n }\n\n // front-facing structure\n public function getReportEnabledFieldData(bool $value = false): array\n {\n return [\n 'id' => 'report_enabled',\n 'label' => '',\n 'inputType' => InputTypeEnum::TOGGLE,\n 'value' => $value,\n ];\n }\n\n // Organizations = Teams\n public function getOrganizationFieldData(?string $value = null, bool $shortVersion = false): array\n {\n $options = $this->getTeams();\n\n if ($shortVersion) {\n return [\n 'id' => 'organization',\n 'label' => 'Organization',\n 'options' => $options,\n ];\n }\n\n return [\n 'id' => 'organization',\n 'label' => 'Organization',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => $options,\n 'value' => $value,\n 'dependencies' => [\n 'teams',\n 'deal_stage_at_call',\n 'current_deal_stage',\n 'recipients',\n ActivityTypeService::PLAYBOOK_CATEGORIES_KEY,\n ],\n 'dependsOn' => [],\n ];\n }\n\n // Teams = Groups\n public function getTeamFieldData(array $options = [], array $value = [], bool $shortVersion = false): array\n {\n if ($shortVersion) {\n return [\n 'id' => 'teams',\n 'label' => 'Team',\n 'options' => $options,\n ];\n }\n\n return [\n 'id' => 'teams',\n 'label' => 'Team',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'required' => false,\n 'placeholder' => 'Select',\n 'options' => $options,\n 'value' => $value, // value should be an array of objects {id, name}\n 'dependencies' => [ActivityTypeService::PLAYBOOK_CATEGORIES_KEY],\n 'dependsOn' => [],\n ];\n }\n\n public function getReportTypeFieldData(?string $value = null, bool $shortVersion = false, ?Team $team = null): array\n {\n $types = [];\n if ($team instanceof Team) {\n if ($team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {\n $types = self::TYPES;\n }\n if ($team->hasFeature(FeatureEnum::ASK_JIMINNY_REPORTS)) {\n $types[] = ['id' => self::TYPE_ASK_JIMINNY, 'name' => 'Ask Jiminny'];\n }\n } else {\n $types = self::TYPES;\n }\n\n if ($shortVersion) {\n return [\n 'id' => 'report_type',\n 'label' => 'Report Type',\n 'options' => $types,\n ];\n }\n\n return [\n 'id' => 'report_type',\n 'label' => 'Report Type',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => $types,\n 'value' => $value,\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getFrequencyFieldData(?string $value = null): array\n {\n return [\n 'id' => 'frequency',\n 'label' => 'Frequency',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => self::FREQUENCIES,\n 'value' => $value,\n 'dependencies' => ['period'],\n 'dependsOn' => [],\n ];\n }\n\n public function getPeriodFieldData(?string $valueStartDate = null, ?string $valueEndDate = null): array\n {\n return [\n 'id' => 'period',\n 'label' => 'Select one-off period',\n 'inputType' => InputTypeEnum::DATE_RANGE,\n 'required' => true,\n 'placeholder' => 'Select',\n 'value' => ['startDate' => $valueStartDate, 'endDate' => $valueEndDate],\n 'queryParams' => [\n 'startDate' => 'start_date_period',\n 'endDate' => 'end_date_period',\n ],\n 'dependencies' => [],\n 'dependsOn' => ['frequency'],\n ];\n }\n\n public function getActivityTypesFieldData(?Team $team = null, array $value = [], array $teamsFilter = []): array\n {\n return $this->activityTypeService->getActivityTypeFieldData(team: $team, value: $value, groupIds: $teamsFilter);\n }\n\n public function getDealStageAtCallFieldData(?Team $team = null, array $value = []): array\n {\n return $this->dealStagesService->getDealStageAtCallFieldData(team: $team, value: $value);\n }\n\n public function getCurrentDealStageFieldData(?Team $team = null, array $value = []): array\n {\n return $this->dealStagesService->getCurrentDealStageFieldData(team: $team, value: $value);\n }\n\n public function getDealValueFieldData(?int $valueMin = null, ?int $valueMax = null): array\n {\n return [\n 'id' => 'deal_value',\n 'label' => 'Deal Value',\n 'inputType' => InputTypeEnum::INTEGER_RANGE,\n 'required' => false,\n 'value' => ['min' => $valueMin, 'max' => $valueMax],\n 'queryParams' => [\n 'min' => 'min_deal_value',\n 'max' => 'max_deal_value',\n ],\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getCallTypeFieldData(bool $conferenceOn = false, bool $dialerOn = false): array\n {\n $value = [];\n $conferenceOn && $value[] = self::CALL_TYPE_CONFERENCE;\n $dialerOn && $value[] = self::CALL_TYPE_DIALER;\n\n return [\n 'id' => 'call_type',\n 'label' => 'Call Type',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'required' => true,\n 'options' => [\n self::CALL_TYPE_CONFERENCE,\n self::CALL_TYPE_DIALER,\n ],\n 'value' => $value,\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getMediaTypeFieldData(?AutomatedReport $report = null): array\n {\n $value = [];\n\n if ($report) {\n $value = $this->transformMediaTypes($report);\n }\n\n return [\n 'id' => 'media_types',\n 'label' => 'Export as',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'required' => true,\n 'options' => self::MEDIA_TYPE_OBJECTS,\n 'value' => $value,\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getCallDurationFieldData(?int $valueMin = null, ?int $valueMax = null): array\n {\n return [\n 'id' => 'call_duration',\n 'label' => 'Call Duration',\n 'inputType' => InputTypeEnum::INTEGER_RANGE,\n 'required' => false,\n 'value' => ['min' => $valueMin, 'max' => $valueMax],\n 'queryParams' => [\n 'min' => 'min_call_duration',\n 'max' => 'max_call_duration',\n ],\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getRecipientsFieldData(?Team $team = null, array $value = []): array\n {\n return $this->recipientsService->getRecipientsFieldData(team: $team, value: $value);\n }\n\n public function getJiminnyRecipientsFieldData(array $value = []): array\n {\n return $this->recipientsService->getJiminnyRecipientsFieldData($value);\n }\n\n public function getAdditionalPromptInputFieldData(?string $value = null): array\n {\n return [\n 'id' => 'additional_prompt_input',\n 'label' => 'Special requirements',\n 'inputType' => InputTypeEnum::TEXTAREA,\n 'required' => false,\n 'placeholder' => 'What should be the focus of the report?',\n 'value' => $value,\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getCustomReportNameFieldData(?string $value = null): array\n {\n return [\n 'id' => 'custom_name',\n 'label' => 'Custom report name',\n 'inputType' => InputTypeEnum::TEXT,\n 'required' => false,\n 'placeholder' => 'Enter custom name',\n 'value' => $value,\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n // data providers\n public function getTeams(): array\n {\n $teams = $this->teamRepository->getTeamsForKiosk(status: Team::STATUS_ACTIVE);\n\n $teamData = [];\n foreach ($teams as $team) {\n if (! $team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {\n continue;\n }\n\n $teamData[] = $this->transformTeam($team);\n }\n\n return $teamData;\n }\n\n public function getTeamGroups(string $teamUuid): array\n {\n $data = [];\n $team = $this->getTeam($teamUuid);\n\n if ($team !== null) {\n $groups = $team->groups()->get();\n\n foreach ($groups as $group) {\n $data[] = [\n 'id' => $group->getUuid(),\n 'name' => $group->getName(),\n ];\n }\n }\n\n return $data;\n }\n\n public function getTeamsGroupsOptions(array $filterTeamUuids = []): array\n {\n $data = [];\n $teams = $this->getTeams();\n\n foreach ($teams as $team) {\n if (! empty($filterTeamUuids) && ! in_array($team['id'], $filterTeamUuids, true)) {\n continue;\n }\n\n $data[] = [\n 'label' => $team['name'],\n 'groups' => $this->getTeamGroups($team['id']),\n ];\n }\n\n return $data;\n }\n\n public function getTeam(string $teamUuid): ?Team\n {\n return $this->teamRepository->idOrUuid($teamUuid);\n }\n\n public function getTeamById(int $teamId): ?Team\n {\n return $this->teamRepository->find($teamId);\n }\n\n public function getGroupsUuids(AutomatedReport $report): array\n {\n $uuids = [];\n $reportGroups = $report->getGroups();\n foreach ($reportGroups as $groupId) {\n if ($group = $this->groupRepository->find($groupId)) {\n $uuids[] = $group->getUuid();\n }\n }\n\n return $uuids;\n }\n\n public function getPlaybookCategoriesUuids(AutomatedReport $report): array\n {\n $uuids = [];\n $playbookCategories = $report->getPlaybookCategories();\n foreach ($playbookCategories as $id) {\n if ($category = $this->playbookCategoryRepository->find($id)) {\n $uuids[] = $category->getUuid();\n }\n }\n\n return $uuids;\n }\n\n public function getDealAtCallStagesUuids(AutomatedReport $report): array\n {\n $uuids = [];\n $reportStages = $report->getDealAtCallStages();\n foreach ($reportStages as $id) {\n if ($stage = $this->stageRepository->find($id)) {\n $uuids[] = $stage->getUuid();\n }\n }\n\n return $uuids;\n }\n\n public function getCurrentDealStagesUuids(AutomatedReport $report): array\n {\n $uuids = [];\n $reportStages = $report->getCurrentDealStages();\n foreach ($reportStages as $id) {\n if ($stage = $this->stageRepository->find($id)) {\n $uuids[] = $stage->getUuid();\n }\n }\n\n return $uuids;\n }\n\n public function getUsersUuids(AutomatedReport $report): array\n {\n return $this->extractUserUuids($report->getRecipients());\n }\n\n public function getJiminnyUsersUuids(AutomatedReport $report): array\n {\n return $this->extractUserUuids($report->getJiminnyRecipients());\n }\n\n /**\n * @param array<string, mixed> $recipients\n */\n private function extractUserUuids(array $recipients): array\n {\n $userIds = $recipients['users'] ?? [];\n\n return collect($userIds)\n ->map(fn ($id) => $this->userRepository->find((int) $id))\n ->filter()\n ->map(fn (UserContract $user) => $user->getUuid())\n ->values()\n ->all();\n }\n\n // get mail data\n public function getRecipientUsers(AutomatedReport $report): array\n {\n return $this->buildRecipientUsers($report->getRecipients());\n }\n\n private function getJiminnyRecipientUsers(AutomatedReport $report): array\n {\n return $this->buildRecipientUsers($report->getJiminnyRecipients());\n }\n\n /**\n * @param array<string, mixed> $recipients\n */\n private function buildRecipientUsers(array $recipients): array\n {\n $userIds = $recipients['users'] ?? [];\n\n return collect($userIds)\n ->map(fn ($id) => $this->userRepository->find((int) $id))\n ->filter()\n ->map(fn (UserContract $user) => [\n 'email' => $user->getEmailAddress(),\n 'name' => $user->getName(),\n 'timezone' => $user->getTimezone()->getName(),\n ])\n ->values()\n ->all();\n }\n\n public function getValidRecipientUsers(AutomatedReport $report, bool $includeJiminny = false): array\n {\n if ($report->isAskJiminnyReport()) {\n $recipients = $this->resolveAskJiminnyRecipients($report);\n } else {\n $recipients = $this->getRecipientUsers($report);\n if ($includeJiminny) {\n $recipients = array_merge($recipients, $this->getJiminnyRecipientUsers($report));\n }\n }\n\n $emails = [];\n\n return array_values(array_filter(\n $recipients,\n static function ($recipient) use (&$emails) {\n if (empty($recipient['email']) || in_array($recipient['email'], $emails, true)) {\n return false;\n }\n $emails[] = $recipient['email'];\n\n return true;\n }\n ));\n }\n\n private function resolveAskJiminnyRecipients(AutomatedReport $report): array\n {\n $recipients = [];\n\n $creator = $report->getCreator();\n if ($creator !== null) {\n $recipients[] = [\n 'email' => $creator->getEmailAddress(),\n 'name' => $creator->getName(),\n 'timezone' => $creator->getTimezone()->getName(),\n ];\n }\n\n return array_merge(\n $recipients,\n $this->buildRecipientUsers($report->getRecipients()),\n $this->getGroupRecipientUsers($report),\n );\n }\n\n private function getGroupRecipientUsers(AutomatedReport $report): array\n {\n $users = [];\n foreach ($report->getGroups() as $groupId) {\n $group = $this->groupRepository->find($groupId);\n if ($group === null) {\n continue;\n }\n foreach ($group->getMembers() as $member) {\n $users[] = [\n 'email' => $member->getEmailAddress(),\n 'name' => $member->getName(),\n 'timezone' => $member->getTimezone()->getName(),\n ];\n }\n }\n\n return $users;\n }\n\n public function getReportTypeName(AutomatedReportResult $report): string\n {\n $type = $report->getReport()->getType();\n\n $getType = $this->transformReportType($type);\n\n return $getType['name'];\n }\n\n public function getReportPeriodName(AutomatedReportResult $report): string\n {\n $from = $report->getFromDate();\n $to = $report->getToDate();\n $frequency = $report->getReport()->getFrequency();\n\n if ($from === null || $to === null) {\n if (! $report->getReport()->isAskJiminnyReport()) {\n $invalidPeriod = $from === null ? 'from' : 'to';\n\n throw new ApplicationException('Report period is invalid: ' . $invalidPeriod);\n }\n\n $period = $this->calculateFromAndToDatePeriod($frequency);\n $from = $period['fromDate'];\n $to = $period['toDate'];\n }\n\n return $this->formatReportPeriodName($frequency, $from, $to);\n }\n\n private function formatReportPeriodName(string $frequency, Carbon $from, Carbon $to): string\n {\n $fromYear = $from->format('Y');\n $toYear = $to->format('Y');\n $differentYears = $fromYear !== $toYear;\n\n switch ($frequency) {\n case self::FREQUENCY_DAILY:\n return $from->format('j M Y');\n\n case self::FREQUENCY_QUARTERLY:\n // 'Jan-Mar 2025' or 'Nov 2024-Jan 2025' if years differ\n $startMonth = $from->format('M');\n $endMonth = $to->copy()->subMonth();\n $endMonthName = $endMonth->format('M');\n $endMonthYear = $endMonth->format('Y');\n\n if ($differentYears) {\n return \"{$startMonth} {$fromYear} - {$endMonthName} {$endMonthYear}\";\n }\n\n return \"{$startMonth} - {$endMonthName} {$toYear}\";\n\n case self::FREQUENCY_MONTHLY:\n // 'May 2025' - monthly reports are always within the same year\n return $from->format('M Y');\n\n case self::FREQUENCY_WEEKLY:\n // '4 - 8 Aug 2025', '27 Oct - 3 Nov 2025', or '28 Dec 2024 - 3 Jan 2025' if years differ\n $startDay = $from->format('j');\n $endDay = $to->format('j');\n $startMonth = $from->format('M');\n $endMonth = $to->format('M');\n\n if ($differentYears) {\n return \"{$startDay} {$startMonth} {$fromYear} - {$endDay} {$endMonth} {$toYear}\";\n }\n\n if ($startMonth !== $endMonth) {\n return \"{$startDay} {$startMonth} - {$endDay} {$endMonth} {$toYear}\";\n }\n\n return \"{$startDay} - {$endDay} {$endMonth} {$toYear}\";\n\n case self::FREQUENCY_ONE_OFF:\n // '2 May-31 May 2025' or '15 Dec 2024-15 Jan 2025' if years differ\n $startDay = $from->format('j');\n $startMonth = $from->format('M');\n $endDay = $to->format('j');\n $endMonth = $to->format('M');\n\n // If same month and year, use a format like '2-31 May 2025'\n if ($startMonth === $endMonth && ! $differentYears) {\n return \"{$startDay} - {$endDay} {$startMonth} {$toYear}\";\n }\n\n // If different years, include both years\n if ($differentYears) {\n return \"{$startDay} {$startMonth} {$fromYear} - {$endDay} {$endMonth} {$toYear}\";\n }\n\n // Same year but different months\n return \"{$startDay} {$startMonth} - {$endDay} {$endMonth} {$toYear}\";\n\n default:\n // Default format for unknown frequencies\n return $from->format('j M Y') . ' - ' . $to->format('j M Y');\n }\n }\n\n public function getReportTeamsName(AutomatedReportResult $report): string\n {\n $groups = $report->getGroups();\n\n if (empty($groups)) {\n return 'All';\n }\n\n // Get group names from repository\n $groupNames = [];\n foreach ($groups as $groupId) {\n $group = $this->groupRepository->find($groupId);\n if ($group) {\n $groupNames[] = $group->getName();\n }\n }\n\n if (count($groupNames) === 1) {\n // Single team format\n $teamsName = $groupNames[0];\n } else {\n // Multiple teams format\n $teamsName = implode(', ', $groupNames);\n }\n\n return $teamsName;\n }\n\n public function getReportFileName(AutomatedReportResult $report): string\n {\n $customName = $report->getReport()->getCustomName();\n $periodName = $this->getReportPeriodName($report);\n $filenameSuffix = $this->getFilenameSuffix($report);\n\n if ($customName) {\n if ($filenameSuffix) {\n $customName .= \" {$filenameSuffix}\";\n }\n\n return $this->sanitizeFileName(\"{$customName} - {$periodName}\");\n }\n\n $baseName = $this->getReportTypeName($report);\n\n if ($filenameSuffix) {\n $baseName .= \" {$filenameSuffix}\";\n }\n\n return $this->sanitizeFileName(\"{$baseName} - {$periodName} - {$this->getReportTeamsName($report)}\");\n }\n\n public function getReportFileNameWithExtension(AutomatedReportResult $result): string\n {\n $extension = $this->getMediaTypeMetadata($result)['extension'];\n\n return $this->getReportFileName($result) . '.' . $extension;\n }\n\n public function sanitizeFileName(string $fileName): string\n {\n return str_replace(['/', '\\\\'], '-', $fileName);\n }\n\n public function isUserRecipientOfReport(User $user, AutomatedReport $report): bool\n {\n $recipients = array_map('intval', $report->getRecipients()['users'] ?? []);\n\n return in_array($user->getId(), $recipients);\n }\n\n public function transformReportResults(Collection $automatedReportResults): array\n {\n $data = [];\n foreach ($automatedReportResults as $automatedReportResult) {\n /** @var AutomatedReportResult $automatedReportResult */\n\n $report = $automatedReportResult->getReport();\n\n $createdBy = $report->getCreator();\n $creator = [\n 'id' => $createdBy?->getUuid(),\n 'name' => $createdBy?->getName(),\n 'email' => $createdBy?->getEmailAddress(),\n 'photoUrl' => $createdBy?->getPhotoUrl(),\n ];\n\n $data[] = [\n 'id' => $automatedReportResult->getUuid(),\n 'name' => $automatedReportResult->getName(),\n 'frequency' => $this->transformFrequency($report->getFrequency()),\n 'recipients' => [\n ...array_values($this->transformGroups(team: $report->getTeam(), groupsIds: $report->getGroups())),\n ...array_values($this->transformRecipients($report->getRecipients())),\n ],\n 'report_type' => $this->transformReportType($report->getType()),\n 'media_type' => $automatedReportResult->getMediaType(),\n 'downloadUrl' => $this->generateReportResultDownloadUrl($automatedReportResult),\n 'viewUrl' => $this->generateReportResultViewUrl($automatedReportResult),\n 'generated_at' => $automatedReportResult->getGeneratedAt()?->toIso8601String(),\n 'creator' => $creator,\n ];\n }\n\n return $data;\n }\n\n public function hasCallTypeConference(AutomatedReport $report): bool\n {\n return in_array(self::CALL_TYPE_CONFERENCE['id'], $report->getCallTypes(), true);\n }\n\n public function hasCallTypeDialer(AutomatedReport $report): bool\n {\n return in_array(self::CALL_TYPE_DIALER['id'], $report->getCallTypes(), true);\n }\n\n // transformers\n private function transformTeam(Team $team): array\n {\n if (! $team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {\n return [];\n }\n\n return [\n 'id' => $team->getUuid(),\n 'name' => $team->getName(),\n ];\n }\n\n private function transformReportFullView(AutomatedReport $report): array\n {\n $base = $this->transformReportBase($report);\n\n return $report->getType() === self::TYPE_ASK_JIMINNY\n ? $base + $this->transformAskJiminnyFields($report)\n : $base + $this->transformStandardReportFields($report);\n }\n\n private function transformReportBase(AutomatedReport $report): array\n {\n return [\n 'id' => $report->getUuid(),\n 'organization' => $this->transformOrganization(team: $report->getTeam()),\n 'report_type' => $this->transformReportType($report->getType()),\n 'frequency' => $this->transformFrequency($report->getFrequency()),\n ];\n }\n\n private function transformStandardReportFields(AutomatedReport $report): array\n {\n $team = $report->getTeam();\n\n return [\n 'report_enabled' => $report->getStatus(),\n 'start_date_period' => $report->getFrom()?->format('Y-m-d H:i:s'),\n 'end_date_period' => $report->getTo()?->format('Y-m-d H:i:s'),\n 'deal_value_min' => $report->getDealValueMin(),\n 'deal_value_max' => $report->getDealValueMax(),\n 'call_types' => $this->transformCallType($report->getCallTypes()),\n 'media_types' => $this->transformMediaTypes($report),\n 'call_duration_min' => $this->transformDurationToMinutes($report->getCallDurationMin()),\n 'call_duration_max' => $this->transformDurationToMinutes($report->getCallDurationMax()),\n 'teams' => $this->transformGroups(team: $team, groupsIds: $report->getGroups()),\n 'deal_at_call_stages' => $this->transformStages(team: $team, stagesIds: $report->getDealAtCallStages()),\n 'current_deal_stages' => $this->transformStages(team: $team, stagesIds: $report->getCurrentDealStages()),\n 'recipients' => $this->transformRecipients($report->getRecipients()),\n 'created_by' => $this->transformCreator($report->getCreator()),\n 'additional_prompt_input' => $report->getAdditionalPromptInput(),\n 'custom_name' => $report->getCustomName(),\n 'created_at' => $report->getCreatedAt()->format('Y-m-d H:i:s'),\n 'updated_at' => $report->getUpdatedAt()->format('Y-m-d H:i:s'),\n 'deleted_at' => $report->getDeletedAt()?->format('Y-m-d H:i:s'),\n ];\n }\n\n private function transformAskJiminnyFields(AutomatedReport $report): array\n {\n $team = $report->getTeam();\n $creatorId = $report->getAttribute('created_by');\n $explicitUserIds = array_values(array_filter(\n $report->getRecipients()['users'] ?? [],\n static fn ($id) => $id !== $creatorId\n ));\n\n return [\n 'report_name' => $report->getCustomName(),\n 'enabled' => $report->getStatus(),\n 'share_teams' => $this->transformGroups(team: $team, groupsIds: $report->getGroups()),\n 'share_users' => $this->transformRecipients(['users' => $explicitUserIds]),\n 'saved_search' => $this->transformSafeSearch($report->getSavedSearch()),\n 'ask_jiminny_prompt' => $this->transformAskJiminnyPrompt($report->getAskAnythingPrompt()),\n 'expires_on' => $report->getExpiresAt()?->format('Y-m-d'),\n ];\n }\n\n private function transformOrganization(?Team $team): array\n {\n return [\n 'id' => $team?->getUuid(),\n 'name' => $team?->getName(),\n ];\n }\n\n private function transformReportType(string $type): array\n {\n foreach (self::ALL_TYPES as $typeItem) {\n if ($typeItem['id'] === $type) {\n return $typeItem;\n }\n }\n\n return [];\n }\n\n private function transformCallType(array $types): array\n {\n $result = [];\n $callTypes = [self::CALL_TYPE_CONFERENCE, self::CALL_TYPE_DIALER];\n\n foreach ($types as $type) {\n foreach ($callTypes as $callTypeItem) {\n if ($callTypeItem['id'] === $type) {\n $result[] = $callTypeItem;\n\n break;\n }\n }\n }\n\n return $result;\n }\n\n private function transformMediaTypes(AutomatedReport $report): array\n {\n $values = [];\n\n foreach ($report->getMediaTypes() as $mediaType) {\n if (! in_array($mediaType, self::MEDIA_TYPES, true)) {\n continue;\n }\n\n $values[] = match ($mediaType) {\n self::MEDIA_TYPE_PDF => self::MEDIA_TYPE_OBJECT_PDF,\n self::MEDIA_TYPE_PODCAST => self::MEDIA_TYPE_OBJECT_PODCAST,\n };\n }\n\n return $values;\n }\n\n private function transformFrequency(string $frequency): array\n {\n foreach (self::ALL_FREQUENCIES as $frequencyItem) {\n if ($frequencyItem['id'] === $frequency) {\n return $frequencyItem;\n }\n }\n\n return [];\n }\n\n public function transformDurationToMinutes(?int $duration): ?int\n {\n if (! $duration) {\n return null;\n }\n\n return (int) ($duration / 60);\n }\n\n private function transformGroups(?Team $team, array $groupsIds): array\n {\n if (empty($groupsIds) || ! $team) {\n return [];\n }\n\n $data = [];\n foreach ($groupsIds as $groupId) {\n $group = $team->groups()->where('id', $groupId)->first();\n\n if ($group) {\n $data[] = [\n 'id' => $group->getUuid(),\n 'name' => $group->getName(),\n 'photoUrl' => $group->getPhotoUrl(),\n ];\n }\n }\n\n return $data;\n }\n\n private function transformStages(?Team $team, array $stagesIds): array\n {\n if (empty($stagesIds) || ! $team) {\n return [];\n }\n\n $data = [];\n foreach ($stagesIds as $stageId) {\n $stage = $team->stages()->where('id', $stageId)->first();\n\n if ($stage) {\n $data[] = [\n 'id' => $stage->getUuid(),\n 'name' => $stage->getName(),\n ];\n }\n }\n\n return $data;\n }\n\n private function transformRecipients(array $recipients): array\n {\n $users = [];\n foreach ($recipients['users'] ?? [] as $userId) {\n $users[] = $this->transformUser($userId);\n }\n\n return $users;\n }\n\n private function transformCreator(?User $user): ?array\n {\n if ($user === null) {\n return null;\n }\n\n return $this->transformUser($user->getId());\n }\n\n private function transformAskJiminnyPrompt(?AskAnythingPrompt $prompt): ?array\n {\n if ($prompt === null) {\n return null;\n }\n\n return [\n 'id' => $prompt->getUuid(),\n 'name' => $prompt->getTitle(),\n ];\n }\n\n private function transformSafeSearch(?Search $search): ?array\n {\n if ($search === null) {\n return null;\n }\n\n return [\n 'id' => $search->getUuid(),\n 'name' => $search->getName(),\n ];\n }\n\n private function transformUser(int $userId): array\n {\n /* @var ?User $user */\n $user = $this->userRepository->find($userId);\n\n return [\n 'id' => $user?->getUuid(),\n 'name' => $user?->getName(),\n 'email' => $user?->getEmailAddress(),\n 'photoUrl' => $user?->getPhotoUrl(),\n ];\n }\n\n public function create(array $data): array\n {\n $validatedData = $this->validateAndTransformData($data);\n $validatedData['created_by'] = auth()->id();\n\n $automatedReport = $this->automatedReportsRepository->create($validatedData);\n\n $this->generateOneOffReport($automatedReport);\n\n return $this->transformReportFullView($automatedReport);\n }\n\n public function update(string $uuid, array $data): array\n {\n $validatedData = $this->validateAndTransformData($data);\n $report = $this->automatedReportsRepository->findByUuid($uuid);\n\n if (! $report) {\n throw new InvalidArgumentException('Report not found');\n }\n\n $oldCustomName = $report->getCustomName();\n\n $automatedReport = $this->automatedReportsRepository->update($report, $validatedData);\n\n if ($oldCustomName !== $automatedReport->getCustomName()) {\n $this->updateResultNames($automatedReport);\n }\n\n $this->generateOneOffReport($automatedReport);\n\n return $this->transformReportFullView($automatedReport);\n }\n\n /**\n * Create an Ask Jiminny report.\n */\n public function createAskJiminnyReport(array $data, User $creator): array\n {\n $validatedData = $this->validateAskJiminnyReportData($data, $creator);\n $validatedData['created_by'] = $creator->getId();\n\n $automatedReport = $this->automatedReportsRepository->create($validatedData);\n\n return $this->transformReportFullView($automatedReport);\n }\n\n /**\n * Update an Ask Jiminny report.\n */\n public function updateAskJiminnyReport(AutomatedReport $report, array $data, User $user): array\n {\n if (! $report->isAskJiminnyReport()) {\n throw new InvalidArgumentException('Report is not an Ask Jiminny report');\n }\n\n $validatedData = $this->validateAskJiminnyReportData($data, $user);\n\n $oldCustomName = $report->getCustomName();\n\n $automatedReport = $this->automatedReportsRepository->update($report, $validatedData);\n\n if ($oldCustomName !== $automatedReport->getCustomName()) {\n $this->updateResultNames($automatedReport);\n }\n\n return $this->transformReportFullView($automatedReport);\n }\n\n public function updateAskJiminnyReportStatus(AutomatedReport $report, bool $status): array\n {\n $this->automatedReportsRepository->update($report, ['status' => $status]);\n\n return $this->transformReportFullView($report->fresh());\n }\n\n /**\n * Validate and transform data for Ask Jiminny reports.\n */\n private function validateAskJiminnyReportData(array $data, User $user): array\n {\n // Validate name\n $name = trim($data['report_name'] ?? '');\n if (empty($name)) {\n throw new InvalidArgumentException('Report name is required');\n }\n if (mb_strlen($name) > 50) {\n throw new InvalidArgumentException('Report name must be 50 characters or less');\n }\n\n // Validate frequency (only daily, weekly, monthly for Ask Jiminny)\n $frequency = $data['frequency'] ?? null;\n $askJiminnyFrequencies = [self::FREQUENCY_DAILY, self::FREQUENCY_WEEKLY, self::FREQUENCY_MONTHLY];\n if (! in_array($frequency, $askJiminnyFrequencies, true)) {\n throw new InvalidArgumentException('Frequency must be daily, weekly, or monthly');\n }\n\n // Validate expiration date\n $expiresAt = $data['expires_on'] ?? null;\n if (empty($expiresAt)) {\n throw new InvalidArgumentException('Expiration date is required');\n }\n\n try {\n $expiresAtDate = Carbon::parse($expiresAt);\n } catch (InvalidFormatException $e) {\n throw new InvalidArgumentException('Expiration date format is invalid');\n }\n $maxExpiration = Carbon::now()->addYear();\n if ($expiresAtDate->gt($maxExpiration)) {\n throw new InvalidArgumentException('Expiration date cannot be more than 1 year from now');\n }\n if ($expiresAtDate->isPast()) {\n throw new InvalidArgumentException('Expiration date cannot be in the past');\n }\n\n // Validate saved search\n $activitySearchId = $data['saved_search'] ?? null;\n if (empty($activitySearchId)) {\n throw new InvalidArgumentException('Saved search is required');\n }\n $savedSearch = $this->activitySearchRepository->findByUuidAndUser($activitySearchId, $user);\n if (! $savedSearch) {\n throw new InvalidArgumentException('Saved search not found or does not belong to you');\n }\n\n // Validate saved prompt\n $askAnythingPromptId = $data['ask_jiminny_prompt'] ?? null;\n if (empty($askAnythingPromptId)) {\n throw new InvalidArgumentException('Ask Jiminny prompt is required');\n }\n $prompt = $this->askAnythingRepository->getPromptByUuid($askAnythingPromptId);\n if (! $prompt) {\n throw new InvalidArgumentException('Ask Jiminny prompt not found');\n }\n\n // Validate status\n $status = $data['enabled'] ?? false;\n\n $recipientUserIds = [$user->getId()];\n\n if (! empty($data['share_users'])) {\n $sharedUserIds = $this->validateAndGetUserIdsByTeam(\n $user->team,\n (array) $data['share_users']\n );\n $recipientUserIds = array_merge($recipientUserIds, $sharedUserIds);\n }\n\n $sharedGroupIds = [];\n if (! empty($data['share_teams'])) {\n $sharedGroupIds = $this->validateAndGetGroupIds($user->team, (array) $data['share_teams']);\n }\n\n $recipientUserIds = array_values(array_unique($recipientUserIds));\n\n return [\n 'team_id' => $user->getTeamId(),\n 'type' => self::TYPE_ASK_JIMINNY,\n 'status' => (bool) $status,\n 'frequency' => $frequency,\n 'custom_name' => $name,\n 'activity_search_id' => $savedSearch->getId(),\n 'ask_anything_prompt_id' => $prompt->getId(),\n 'expires_at' => $expiresAtDate->toDateString(),\n 'media_types' => [self::MEDIA_TYPE_PDF],\n 'call_types' => [],\n 'recipients' => ['users' => $recipientUserIds],\n 'groups' => $sharedGroupIds,\n ];\n }\n\n public static function getAskJiminnyFrequencies(): array\n {\n return array_map(static function ($frequency) {\n return $frequency['id'];\n }, self::ASK_JIMINNY_FREQUENCIES);\n }\n\n public function getAskJiminnyReportFilters(User $user): array\n {\n $savedSearches = $this->activitySearchRepository->findByUserOrderedByName($user)\n ->map(fn (Search $search) => [\n 'id' => $search->getUuid(),\n 'name' => $search->getName(),\n ])\n ->values()->all();\n\n $prompts = collect(\n $this->askAnythingPromptService->get($user, AskAnythingPromptTarget::on_demand)\n )->map(fn (AskAnythingPromptDto $prompt) => [\n 'id' => $prompt->id,\n 'name' => $prompt->title,\n ])->values()->all();\n\n return [\n [\n 'id' => 'prompt',\n 'label' => 'Prompt',\n 'options' => $prompts,\n ],\n [\n 'id' => 'saved_search',\n 'label' => 'Saved Search',\n 'options' => $savedSearches,\n ],\n ];\n }\n\n public function getAskJiminnyReportFormData(User $user, ?AutomatedReport $report = null): array\n {\n $team = $user->getTeam();\n $userTimezone = $user->getTimezone();\n\n $savedSearches = $this->activitySearchRepository->findByUserOrderedByName($user)\n ->map(fn (Search $search) => [\n 'id' => $search->getUuid(),\n 'name' => $search->getName(),\n ])\n ->values()->all();\n\n $prompts = collect(\n $this->askAnythingPromptService->get($user, AskAnythingPromptTarget::on_demand)\n )->map(fn (AskAnythingPromptDto $prompt) => [\n 'id' => $prompt->id,\n 'name' => $prompt->title,\n ])->values()->all();\n\n $teamGroups = $this->groupRepository->getAllByTeam($team)->map(fn ($group) => [\n 'id' => $group->getUuid(),\n 'name' => $group->getName(),\n ])->values()->all();\n\n $shareUsers = $this->recipientsService->getRecipientsFieldData(team: $team)['options'] ?? [];\n\n $sharedTeamsValue = [];\n $sharedUsersValue = [];\n if ($report) {\n $sharedTeamsValue = $this->transformGroups($team, $report->getGroups());\n\n $recipientUserIds = $report->getRecipients()['users'] ?? [];\n $creatorId = $report->getAttribute('created_by');\n $sharedUserIds = array_values(array_filter(\n $recipientUserIds,\n static fn ($id) => $id !== $creatorId\n ));\n $sharedUsersValue = collect($sharedUserIds)\n ->map(fn ($id) => $this->userRepository->find((int) $id))\n ->filter()\n ->map(fn (User $u) => [\n 'id' => $u->getUuid(),\n 'name' => $u->getName(),\n ])\n ->values()\n ->all();\n }\n\n return [\n 'fields' => [\n [\n 'id' => 'enabled',\n 'inputType' => InputTypeEnum::TOGGLE,\n 'label' => '',\n 'value' => $report?->getStatus() ?? false,\n ],\n [\n 'id' => 'report_name',\n 'inputType' => InputTypeEnum::TEXT,\n 'label' => 'Name',\n 'placeholder' => 'Enter name',\n 'required' => true,\n 'validation' => ['maxLength' => 50],\n 'value' => $report?->getCustomName() ?? '',\n ],\n [\n 'id' => 'frequency',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'label' => 'Frequency',\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => self::ASK_JIMINNY_FREQUENCIES,\n 'value' => $report ? $this->transformFrequency($report->getFrequency()) : null,\n ],\n [\n 'id' => 'expires_on',\n 'inputType' => InputTypeEnum::DATE,\n 'label' => 'Expires on',\n 'required' => true,\n 'placeholder' => 'Select',\n 'validation' => [\n 'minDate' => now($userTimezone)->toDateString(),\n 'maxDate' => now($userTimezone)->addYear()->toDateString(),\n ],\n 'value' => $report?->getExpiresAt()?->toDateString(),\n ],\n [\n 'id' => 'share_teams',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'label' => 'Team',\n 'required' => false,\n 'placeholder' => 'Select',\n 'options' => $teamGroups,\n 'value' => $sharedTeamsValue,\n ],\n [\n 'id' => 'share_users',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'label' => 'Team member',\n 'required' => false,\n 'placeholder' => 'Select',\n 'groupLabelKey' => 'label',\n 'groupValuesKey' => 'users',\n 'optionLabelKey' => 'name',\n 'optionValueKey' => 'id',\n 'options' => $shareUsers,\n 'value' => $sharedUsersValue,\n ],\n [\n 'id' => 'saved_search',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'label' => 'Saved search',\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => $savedSearches,\n 'value' => $report && $report->getSavedSearch() ? [\n 'id' => $report->getSavedSearch()->getUuid(),\n 'name' => $report->getSavedSearch()->getName(),\n ] : null,\n ],\n [\n 'id' => 'ask_jiminny_prompt',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'label' => 'Ask Jiminny prompt',\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => $prompts,\n 'value' => $report && $report->getAskAnythingPrompt() ? [\n 'id' => $report->getAskAnythingPrompt()->getUuid(),\n 'name' => $report->getAskAnythingPrompt()->getTitle(),\n ] : null,\n ],\n ],\n ];\n }\n\n private function updateResultNames(AutomatedReport $automatedReport): void\n {\n $results = $this->automatedReportsRepository->getResultsByReport($automatedReport);\n\n foreach ($results as $result) {\n $result->update(['name' => $this->getReportFileName($result)]);\n }\n }\n\n public function updateStatus(string $uuid, array $data): array\n {\n $automatedReport = $this->automatedReportsRepository->findByUuid($uuid);\n\n if (! $automatedReport) {\n throw new ModelNotFoundException('Report not found');\n }\n\n $status = $this->validateReportStatus($data['report_enabled'] ?? null);\n $automatedReport->update([\n 'status' => $status,\n ]);\n\n $this->generateOneOffReport($automatedReport);\n\n return $this->transformReportFullView($automatedReport);\n }\n\n private function generateOneOffReport(AutomatedReport $automatedReport): void\n {\n // the scheduler handles all the other frequency types\n if ($automatedReport->getStatus() === false || $automatedReport->getFrequency() !== self::FREQUENCY_ONE_OFF) {\n return;\n }\n\n $this->dispatcher->dispatch(new RequestGenerateReportJob($automatedReport->getUuid()));\n }\n\n public function getReport(string $uuid): AutomatedReport\n {\n $automatedReport = $this->automatedReportsRepository->findByUuid($uuid);\n\n if (! $automatedReport) {\n throw new ModelNotFoundException('Report not found');\n }\n\n return $automatedReport;\n }\n\n public function get(string $uuid): array\n {\n $automatedReport = $this->getReport($uuid);\n\n return $this->transformReportFullView($automatedReport);\n }\n\n public function list(string $sortColumn = 'created_at', string $sortDirection = 'desc'): array\n {\n $results = [];\n $collection = $this->automatedReportsRepository->getAllStandardReports($sortColumn, $sortDirection);\n\n /** @var AutomatedReport $report */\n foreach ($collection as $report) {\n $results[] = $this->transformReportFullView($report);\n }\n\n return ['data' => $results];\n }\n\n public function listAskJiminnyReports(\n User $user,\n string $sortColumn = 'created_at',\n string $sortDirection = 'desc'\n ): array {\n $results = [];\n $collection = $this->automatedReportsRepository->getAskJiminnyReportsByUser($user, $sortColumn, $sortDirection);\n\n /** @var AutomatedReport $report */\n foreach ($collection as $report) {\n $results[] = $this->transformReportFullView($report);\n }\n\n return ['data' => $results];\n }\n\n public function delete(string $uuid): void\n {\n $automatedReport = $this->automatedReportsRepository->findByUuid($uuid);\n\n if (! $automatedReport) {\n throw new ModelNotFoundException('Report not found');\n }\n\n $automatedReport->delete();\n }\n\n public function createReportResult(AutomatedReport $automatedReport, array $data = []): AutomatedReportResult\n {\n return $this->automatedReportsRepository->createResult(\n array_merge(\n [\n 'report_id' => $automatedReport->getId(),\n 'status' => AutomatedReportResult::STATUS_DEFAULT,\n ],\n $data\n )\n );\n }\n\n public function getReportResult(string $resultUuid): AutomatedReportResult\n {\n $report = $this->automatedReportsRepository->findResultByUuid($resultUuid);\n\n if (! $report) {\n throw new ModelNotFoundException('Report Result not found');\n }\n\n return $report;\n }\n\n public function findChildResult(AutomatedReportResult $result, string $type): ?AutomatedReportResult\n {\n return $this->automatedReportsRepository->findChildResult($result, $type);\n }\n\n // prophet API calls\n /**\n * @throws ApplicationException\n */\n public function getGenerateReportPayload(AutomatedReport $automatedReport, string $reportResultUuid): array\n {\n $period = $this->calculateFromAndToDate($automatedReport);\n $fromDate = $period['fromDate'];\n $toDate = $period['toDate'];\n\n return [\n 'team_id' => $automatedReport->getTeamId(),\n 'request_id' => $reportResultUuid,\n 'report_type' => $automatedReport->getType(),\n 'media_types' => $automatedReport->getMediaTypes(),\n 'from_date' => $fromDate->startOfDay()->format(DateTimeInterface::RFC3339),\n 'to_date' => $toDate->endOfDay()->format(DateTimeInterface::RFC3339),\n 'group_ids' => $automatedReport->getGroups(),\n 'call_deal_stage' => $automatedReport->getDealAtCallStages(),\n 'current_deal_stage' => $automatedReport->getCurrentDealStages(),\n 'deal_min_value' => $automatedReport->getDealValueMin(),\n 'deal_max_value' => $automatedReport->getDealValueMax(),\n 'call_types' => $automatedReport->getCallTypes(),\n 'call_duration_min_seconds' => $automatedReport->getCallDurationMin(),\n 'call_duration_max_seconds' => $automatedReport->getCallDurationMax(),\n 'special_requirements' => $automatedReport->getAdditionalPromptInput(),\n 'callback_url' => $this->getCallbackUrl(),\n 'report_period' => $this->formatReportPeriodName(\n $automatedReport->getFrequency(),\n $fromDate,\n $toDate,\n ),\n 'playbook_categories' => $automatedReport->getPlaybookCategories(),\n 'custom_name' => $automatedReport->getCustomName(),\n ];\n }\n\n // $inputPayload - FE payload structure\n public function getActivitiesCountPayload(array $inputPayload): array\n {\n // Use validateAndTransformData to validate and normalize input\n $validatedData = $this->validateAndTransformData($inputPayload);\n $period = $this->calculateFromAndToDatePeriod(\n $validatedData['frequency'],\n Carbon::parse($validatedData['from']),\n Carbon::parse($validatedData['to']),\n );\n $fromDate = $period['fromDate'];\n $toDate = $period['toDate'];\n\n // Create payload similar to getGenerateReportPayload\n return [\n 'team_id' => $validatedData['team_id'],\n 'group_ids' => $validatedData['groups'] ?? [],\n 'report_type' => $validatedData['type'],\n 'from_date' => $fromDate->format(DateTimeInterface::RFC3339),\n 'to_date' => $toDate->format(DateTimeInterface::RFC3339),\n 'call_deal_stage' => $validatedData['deal_at_call_stages'] ?? [],\n 'current_deal_stage' => $validatedData['current_deal_stages'] ?? [],\n 'deal_min_value' => $validatedData['deal_value_min'] ?? null,\n 'deal_max_value' => $validatedData['deal_value_max'] ?? null,\n 'call_types' => $validatedData['call_types'],\n 'call_duration_min_seconds' => $validatedData['call_duration_min'] ?? null,\n 'call_duration_max_seconds' => $validatedData['call_duration_max'] ?? null,\n 'special_requirements' => $validatedData['additional_prompt_input'] ?? null,\n 'playbook_categories' => $validatedData['playbook_categories'] ?? [],\n 'request_id' => null,\n 'callback_url' => null,\n ];\n }\n\n public function shouldSendReport(array $users, ?CarbonInterface $generatedAt = null): bool\n {\n if (empty($users)) {\n return false;\n }\n\n $earliestTz = collect($users)\n ->mapWithKeys(function (array $user) {\n $tz = new DateTimeZone($user['timezone']);\n $nowUtc = new DateTime('now', new DateTimeZone('UTC'));\n $offset = $tz->getOffset($nowUtc);\n\n return [$user['timezone'] => $offset];\n })\n ->sortDesc()\n ->keys()\n ->first();\n\n $now = Carbon::now($earliestTz);\n $isScheduledTime = (int) $now->format('H') === self::SENT_REPORT_AT_HOURS;\n\n if ($isScheduledTime) {\n return true;\n }\n\n return $this->hasPassedScheduledTime($generatedAt, $earliestTz);\n }\n\n public function hasPassedScheduledTime(?CarbonInterface $generatedAt, string $timezone): bool\n {\n if ($generatedAt === null) {\n return false;\n }\n\n $now = Carbon::now($timezone);\n $scheduledTime = $now->copy()->setTime(self::SENT_REPORT_AT_HOURS, 0, 0);\n\n if ($now->hour < self::SENT_REPORT_AT_HOURS) {\n $scheduledTime = $scheduledTime->subDay();\n }\n\n $scheduledTimeUtc = $scheduledTime->copy()->utc();\n $generatedAtUtc = $generatedAt->copy()->utc();\n $nowUtc = $now->copy()->utc();\n\n return $generatedAtUtc->lt($scheduledTimeUtc) && $nowUtc->gt($scheduledTimeUtc);\n }\n\n public function calculateFromAndToDatePeriod(\n string $frequency,\n ?Carbon $fromDate = null,\n ?Carbon $toDate = null\n ): array {\n if ($frequency === self::FREQUENCY_ONE_OFF) {\n return [\n 'fromDate' => $fromDate,\n 'toDate' => $toDate,\n ];\n }\n\n $now = Carbon::now();\n\n return match ($frequency) {\n self::FREQUENCY_DAILY => [\n 'fromDate' => $now->copy()->subDay()->startOfDay(),\n 'toDate' => $now->copy()->subDay()->endOfDay(),\n ],\n self::FREQUENCY_WEEKLY => [\n 'fromDate' => $now->copy()->subWeeks(1)->startOfDay(),\n 'toDate' => $now->copy()->subDay()->endOfDay(),\n ],\n self::FREQUENCY_MONTHLY => [\n 'fromDate' => $now->copy()->subMonths(1)->startOfDay(),\n 'toDate' => $now->copy()->subDay()->endOfDay(),\n ],\n self::FREQUENCY_QUARTERLY => [\n 'fromDate' => $now->copy()->subMonths(3)->startOfDay(),\n 'toDate' => $now->copy()->subDay()->endOfDay(),\n ],\n default => throw new InvalidArgumentException(\"Unsupported frequency: {$frequency}\"),\n };\n }\n\n private function calculateFromAndToDate(AutomatedReport $automatedReport): array\n {\n return $this->calculateFromAndToDatePeriod(\n $automatedReport->getFrequency(),\n $automatedReport->getFrom(),\n $automatedReport->getTo()\n );\n }\n\n public function getAskJiminnyGenerateReportPayload(\n AutomatedReport $automatedReport,\n AutomatedReportResult $reportResult,\n array $activityIds,\n ): array {\n return [\n 'user_question' => $automatedReport->getAskAnythingPrompt()?->getContent(),\n 'call_ids' => array_map('strval', $activityIds),\n 'team_id' => $automatedReport->getTeamId(),\n 'request_id' => $reportResult->getUuid(),\n 'callback_url' => $this->getCallbackUrl(),\n 'report_period' => $this->getReportPeriodName($reportResult),\n 'report_name' => $automatedReport->getCustomName(),\n ];\n }\n\n private function getCallbackUrl(): string\n {\n return $this->webhookService->route('jiminny.webhook.reports.ready');\n }\n\n /**\n * Validate and transform payload data for automated reports\n *\n * @param array $data\n *\n * @throws InvalidArgumentException\n *\n * @return array\n */\n private function validateAndTransformData(array $data): array\n {\n // Validate organization (team) and check feature\n $team = $this->validateOrganization($data['organization'] ?? null);\n\n $status = $this->validateReportStatus($data['report_enabled'] ?? null);\n $type = $this->validateReportType($data['report_type'] ?? null);\n $frequency = $this->validateFrequency($data['frequency'] ?? null);\n $additionalPromptInput = $this->validateAdditionalPromptInput(\n $data['additional_prompt_input'] ?? null\n );\n $customReportName = $this->validateCustomReportName($data['custom_name'] ?? null);\n\n // Prepare data for the database\n $reportData = [\n 'team_id' => $team->getId(),\n 'type' => $type,\n 'status' => $status,\n 'frequency' => $frequency,\n 'additional_prompt_input' => $additionalPromptInput,\n 'custom_name' => $customReportName,\n ];\n\n // Validate deal values\n $reportData = $this->validateDealValues($data, $reportData);\n\n // Validate date range\n $reportData = $this->validateDateRange($data, $reportData, $frequency);\n\n // Validate call durations\n $reportData = $this->validateCallDurations($data, $reportData);\n\n // Validate call types\n $reportData = $this->validateCallTypes($data, $reportData);\n\n // Validate media types\n $reportData = $this->validateMediaTypes($data, $reportData);\n\n // Validate groups\n if (isset($data['teams'])) {\n $reportData['groups'] = $this->validateAndGetGroupIds($team, $data['teams']);\n }\n\n // Validate deal stages\n $reportData = $this->validateDealStages($data, $reportData, $team, $type);\n\n // Validate playbook categories\n $reportData = $this->validatePlaybookCategories($data, $reportData, $team);\n\n // Validate recipients\n $reportData['recipients'] = [\n 'users' => $this->validateAndGetUserIdsByTeam($team, $data['recipients'] ?? []),\n ];\n\n if (isset($data['jiminny_recipients'])) {\n // Validate Jiminny recipients\n $reportData['jiminny_recipients'] = [\n 'users' => $this->validateAndGetJiminnyUserIds((array) $data['jiminny_recipients']),\n ];\n }\n\n return $reportData;\n }\n\n private function validateDealValues(array $data, array $reportData): array\n {\n if (isset($data['min_deal_value'])) {\n $reportData['deal_value_min'] = (int) $data['min_deal_value'];\n\n if ($reportData['deal_value_min'] > 4294967295 || $reportData['deal_value_min'] < 0) {\n throw new InvalidArgumentException('Min deal value should be between 0 and 4294967295');\n }\n }\n\n if (isset($data['max_deal_value'])) {\n $reportData['deal_value_max'] = (int) $data['max_deal_value'];\n\n if ($reportData['deal_value_max'] > 4294967295 || $reportData['deal_value_max'] < 0) {\n throw new InvalidArgumentException('Max deal value should be between 0 and 4294967295');\n }\n }\n\n if (isset($data['min_deal_value'], $data['max_deal_value'])\n && $data['min_deal_value'] > $data['max_deal_value']\n ) {\n throw new InvalidArgumentException('Min deal value cannot be greater than max deal value');\n }\n\n return $reportData;\n }\n\n private function validateDateRange(array $data, array $reportData, string $frequency): array\n {\n // Set date range only for one_off frequency\n if ($frequency === 'one_off') {\n if (isset($data['start_date_period'])) {\n $reportData['from'] = $this->parseDate($data['start_date_period']);\n }\n\n if (isset($data['end_date_period'])) {\n $reportData['to'] = $this->parseDate($data['end_date_period']);\n }\n\n if (empty($reportData['from']) || empty($reportData['to'])) {\n throw new InvalidArgumentException(\n 'Start date and end date are required for one_off frequency'\n );\n }\n } else {\n $reportData['from'] = null;\n $reportData['to'] = null;\n }\n\n return $reportData;\n }\n\n private function validateCallDurations(array $data, array $reportData): array\n {\n // Convert call durations from minutes to seconds\n if (isset($data['min_call_duration'])) {\n $reportData['call_duration_min'] = (int) $data['min_call_duration'] * 60;\n\n if ($reportData['call_duration_min'] > 4294967295 || $reportData['call_duration_min'] < 0) {\n throw new InvalidArgumentException('Min call duration should be between 0 and 4294967295');\n }\n }\n\n if (isset($data['max_call_duration'])) {\n $reportData['call_duration_max'] = (int) $data['max_call_duration'] * 60;\n\n if ($reportData['call_duration_max'] > 4294967295 || $reportData['call_duration_max'] < 0) {\n throw new InvalidArgumentException('Max call duration should be between 0 and 4294967295');\n }\n }\n\n return $reportData;\n }\n\n private function validateCallTypes(array $data, array $reportData): array\n {\n // Set call types\n $reportData['call_types'] = $data['call_type'] ?? [];\n if (empty($reportData['call_types'])) {\n $reportData['call_types'] = self::getCallTypes();\n }\n\n foreach ($reportData['call_types'] as $callType) {\n if (! in_array($callType, self::getCallTypes(), true)) {\n throw new InvalidArgumentException(sprintf('Call type %s is invalid', $callType));\n }\n }\n\n return $reportData;\n }\n\n private function validateMediaTypes(array $data, array $reportData): array\n {\n // Set media types from input data\n $reportData['media_types'] = $data['media_types'] ?? [];\n\n if (empty($reportData['media_types'])) {\n throw new InvalidArgumentException('Media types are required');\n }\n\n foreach ($reportData['media_types'] as $mediaType) {\n if (! in_array($mediaType, self::MEDIA_TYPES, true)) {\n throw new InvalidArgumentException(sprintf('Media type %s is invalid', $mediaType));\n }\n }\n\n return $reportData;\n }\n\n private function validateDealStages(array $data, array $reportData, Team $team, string $reportType): array\n {\n // Validate and set deal stages\n if (isset($data['deal_stage_at_call'])) {\n $reportData['deal_at_call_stages'] =\n $this->validateAndGetDealStageIds($team, $data['deal_stage_at_call'], 'Deal stage at call');\n }\n\n if (isset($data['current_deal_stage'])) {\n $reportData['current_deal_stages'] =\n $this->validateAndGetDealStageIds($team, $data['current_deal_stage'], 'Current deal stage');\n }\n\n // Ensure current_deal_stage is not provided for loss_analysis report type\n if ($reportType === self::TYPE_LOSS_ANALYSIS && ! empty($data['current_deal_stage'])) {\n throw new InvalidArgumentException('Current deal stage is not applicable for Loss Analysis reports');\n }\n\n return $reportData;\n }\n\n // transform uuid to id\n private function validatePlaybookCategories(array $data, array $reportData, Team $team): array\n {\n $key = 'playbook_categories';\n\n if (isset($data[$key])) {\n $payloadIds = $data[$key];\n $ids = [];\n\n foreach ($payloadIds as $uuid) {\n $uuid = (string) $uuid;\n\n try {\n $playbookCategory = $this->playbookCategoryRepository->findByUuid($uuid);\n } catch (Throwable $throwable) {\n Log::error(__METHOD__ . ' ' . $throwable->getMessage());\n\n throw new InvalidArgumentException(sprintf('Playbook category %s not found', $uuid));\n }\n\n if (! $playbookCategory) {\n throw new InvalidArgumentException(sprintf('Playbook category %s not found', $uuid));\n }\n\n if (! $playbookCategory->hasPlaybook()) {\n throw new InvalidArgumentException(sprintf('Playbook category %s has no playbook', $uuid));\n }\n\n if ($playbookCategory->getPlaybook()->getTeamId() !== $team->getId()) {\n throw new InvalidArgumentException(\n sprintf('Playbook category %s not found for team %s', $uuid, $team->getUuid())\n );\n }\n\n $ids[] = $playbookCategory->getId();\n }\n\n $reportData[$key] = $ids;\n }\n\n return $reportData;\n }\n\n private function validateReportStatus($status): bool\n {\n if (! in_array($status, [true, false], true)) {\n throw new InvalidArgumentException('Report status is invalid');\n }\n\n return $status;\n }\n\n private function validateReportType($type): string\n {\n if (! in_array($type, self::getTypes(), true)) {\n throw new InvalidArgumentException(sprintf('Report type is invalid: %s', $type));\n }\n\n return $type;\n }\n\n private function validateFrequency($frequency): string\n {\n if (! in_array($frequency, self::getFrequencies(), true)) {\n throw new InvalidArgumentException('Frequency is invalid');\n }\n\n return $frequency;\n }\n\n private function validateAdditionalPromptInput(?string $additionalPromptInput): ?string\n {\n if ($additionalPromptInput && strlen($additionalPromptInput) > 5000) {\n throw new InvalidArgumentException('Additional Prompt Input should be less than 5000 characters');\n }\n\n return $additionalPromptInput;\n }\n\n private function validateCustomReportName(?string $customReportName): ?string\n {\n if ($customReportName === null || $customReportName === '') {\n return null;\n }\n\n if (strlen($customReportName) > 70) {\n throw new InvalidArgumentException('Custom report name should be less than 70 characters');\n }\n\n return $customReportName;\n }\n\n private function validateOrganization(?string $organizationUuid): Team\n {\n if (! $organizationUuid) {\n throw new InvalidArgumentException('Organization is required');\n }\n\n $team = $this->teamRepository->idOrUuid($organizationUuid);\n\n if (! $team) {\n throw new InvalidArgumentException('Organization not found');\n }\n\n if (! $team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {\n throw new InvalidArgumentException('Organization does not have the Automated Reports feature');\n }\n\n return $team;\n }\n\n private function validateAndGetGroupIds(Team $team, array $teamUuids): array\n {\n $groupIds = [];\n\n foreach ($teamUuids as $uuid) {\n $group = $this->groupRepository->findByUuid($uuid);\n\n if ($group === null || $group->getTeamId() !== $team->getId()) {\n throw new InvalidArgumentException(\n sprintf('Group %s not found for team %s', $uuid, $team->getUuid())\n );\n }\n\n $groupIds[] = $group->getId();\n\n }\n\n return $groupIds;\n }\n\n private function validateAndGetDealStageIds(Team $team, array $stageUuids, string $propertyLabel): array\n {\n $stageIds = [];\n\n foreach ($stageUuids as $uuid) {\n $stage = $this->stageRepository->findByUuid($uuid);\n\n if ($stage === null || $stage->getTeamId() !== $team->getId()) {\n throw new InvalidArgumentException(\n sprintf('Stage %s not found for team %s for %s', $uuid, $team->getUuid(), $propertyLabel)\n );\n }\n\n $stageIds[] = $stage->getId();\n }\n\n return $stageIds;\n }\n\n private function validateAndGetUserIds(array $userUuids, callable $teamCheck): array\n {\n if (empty($userUuids)) {\n return [];\n }\n\n $userIds = [];\n\n foreach ($userUuids as $uuid) {\n $user = $this->userRepository->findByUuid($uuid);\n\n if (! $user || ! $user->isStatusActive()) {\n throw new InvalidArgumentException(\n sprintf('User %s not found or is not active', $uuid)\n );\n }\n\n if (! $teamCheck($user)) {\n throw new InvalidArgumentException(\n sprintf('User %s does not belong to the allowed team(s)', $uuid)\n );\n }\n\n $userIds[] = $user->getId();\n }\n\n return $userIds;\n }\n\n private function validateAndGetUserIdsByTeam(Team $team, array $userUuids): array\n {\n return $this->validateAndGetUserIds($userUuids, fn ($user) => $user->getTeamId() === $team->getId());\n }\n\n private function validateAndGetJiminnyUserIds(array $userUuids): array\n {\n $allowedTeamIds = config('kiosk.teamIds', []);\n\n return $this->validateAndGetUserIds($userUuids, fn ($user) => in_array($user->getTeamId(), $allowedTeamIds, true));\n }\n\n private function parseDate(string $dateString): string\n {\n return date('Y-m-d H:i:s', strtotime($dateString));\n }\n\n private function generateReportResultViewUrl(AutomatedReportResult $result): string\n {\n $mediaResource = $this->getReportMediaRouteResource($result);\n\n return route('ai-reports.' . $mediaResource . '.view', ['uuid' => $result->getUuid()]);\n }\n\n private function generateReportResultDownloadUrl(AutomatedReportResult $result): string\n {\n $mediaResource = $this->getReportMediaRouteResource($result);\n\n return route('ai-reports.' . $mediaResource . '.download', ['uuid' => $result->getUuid()]);\n }\n\n private function getReportMediaRouteResource(AutomatedReportResult $result): string\n {\n if ($result->getMediaType() === self::MEDIA_TYPE_PDF) {\n return self::PDF_KEY;\n } elseif ($result->getMediaType() === self::MEDIA_TYPE_PODCAST) {\n return self::AUDIO_KEY;\n }\n\n throw new \\InvalidArgumentException('Unknown media type.');\n }\n\n public function getMediaPath(AutomatedReportResult $result): ?string\n {\n $url = match ($result->getMediaType()) {\n self::MEDIA_TYPE_PDF => $result->getPdfUrl(),\n self::MEDIA_TYPE_PODCAST => $result->getPodcastAudioUrl(),\n default => null,\n };\n\n if ($url === null) {\n return null;\n }\n\n $path = parse_url(trim($url, '\"\\''), PHP_URL_PATH);\n\n return $path ?: null;\n }\n\n public function getFilenameSuffix(AutomatedReportResult $result): ?string\n {\n return match ($result->getMediaType()) {\n self::MEDIA_TYPE_PODCAST => 'Podcast',\n default => null,\n };\n }\n\n public function getMailSubjectSuffix(AutomatedReportResult $result): string\n {\n return match ($result->getMediaType()) {\n self::MEDIA_TYPE_PDF => 'report',\n self::MEDIA_TYPE_PODCAST => 'podcast',\n default => '',\n };\n }\n\n public function getMediaTypeMetadata(AutomatedReportResult $result): array\n {\n return match ($result->getMediaType()) {\n self::MEDIA_TYPE_PODCAST => ['extension' => 'mp3', 'mime' => 'audio/mpeg'],\n self::MEDIA_TYPE_PDF => ['extension' => 'pdf', 'mime' => 'application/pdf'],\n default => ['extension' => null, 'mime' => null],\n };\n }\n\n public function deleteS3Files(AutomatedReportResult $result): void\n {\n $teamUuid = $result->getReport()->getTeam()->getUuid();\n $reportUuid = $result->getUuid();\n\n // delete all files for a report uuid no mather of pdf, podcast, or both\n // in case of both - the podcast files are linked to the pdf (parent) uuid\n // pdf and podcast date times should be close\n $path = sprintf('%s/%s/%s', $teamUuid, self::S3_DIR, $reportUuid);\n\n foreach (self::FILE_EXTENSIONS_VARIANTS as $extension) {\n $file = $path . '.' . $extension;\n\n if (Storage::exists($file)) {\n Storage::delete($file);\n Log::info('[Reports] Deleted S3 file', [\n 'path' => $file,\n ]);\n }\n }\n\n foreach (self::FILE_PODCAST_EXTENSIONS_VARIANTS as $extension) {\n $file = $path . '_podcast.' . $extension;\n\n if (Storage::exists($file)) {\n Storage::delete($file);\n Log::info('[Reports] Deleted Podcast S3 file', [\n 'path' => $file,\n ]);\n }\n }\n }\n\n /**\n *\n * @param int|null $teamId Optional team ID to filter results\n *\n * @return Collection<int, int> Collection of team IDs\n */\n public function getTeamIdsWithReportsResults(?int $teamId = null): Collection\n {\n return $this->automatedReportsRepository->getTeamIdsWithReportsResults($teamId);\n }\n\n /**\n * Core delete logic for report results using a query\n *\n * @param Builder $query\n * @param array $logContext\n *\n * @return int\n */\n private function deleteReportResultsByQuery(Builder $query, array $logContext = []): int\n {\n $deletedCount = 0;\n\n if ($query->exists()) {\n Log::info(\n 'Run delete report results',\n array_merge(\n $logContext,\n [\n 'service' => 'AutomatedReportsService',\n ]\n )\n );\n\n $query->chunkById(50, function ($results) use (&$deletedCount, $logContext) {\n foreach ($results as $result) {\n $this->deleteReportResult($result);\n $deletedCount++;\n\n Log::info(\n 'Deleted a report result',\n array_merge(\n $logContext,\n [\n 'result_id' => $result->getId(),\n 'report_id' => $result->getReportId(),\n ]\n )\n );\n }\n });\n }\n\n return $deletedCount;\n }\n\n /**\n * Delete report results for a team by retention period\n *\n * @param Team $team\n * @param CarbonImmutable $retentionDate\n *\n * @return int Number of deleted report results\n */\n public function deleteReportsResultsInRetentionPeriod(Team $team, CarbonImmutable $retentionDate): int\n {\n $reportIds = $this->automatedReportsRepository->getReportIdsByTeam($team);\n\n if ($reportIds->isEmpty()) {\n return 0;\n }\n\n $query = $this->automatedReportsRepository\n ->getReportResultsQueryForRetention($team, $retentionDate);\n\n return $this->deleteReportResultsByQuery($query, [\n 'team_id' => $team->getId(),\n 'retention_date' => $retentionDate->toDateTimeString(),\n ]);\n }\n\n /**\n * Delete ALL report results for a specific automated report\n *\n * @param string $uuid\n *\n * @return int\n */\n public function deleteReportResults(string $uuid): int\n {\n $report = $this->getReport($uuid);\n\n $query = $this->automatedReportsRepository->getResultsByReportQuery($report);\n\n return $this->deleteReportResultsByQuery($query, [\n 'report_uuid' => $uuid,\n 'report_id' => $report->getId(),\n ]);\n }\n\n public function deleteReportResult(AutomatedReportResult $result): void\n {\n $this->deleteS3Files($result);\n\n $result->delete();\n }\n\n /**\n * Get all reports for a specific team\n *\n * @param Team $team\n *\n * @return \\Illuminate\\Database\\Eloquent\\Collection\n */\n public function getTeamReports(Team $team): \\Illuminate\\Database\\Eloquent\\Collection\n {\n return $this->automatedReportsRepository->getReportsByTeam($team);\n }\n\n /**\n * Get all report results for a specific report\n *\n * @param AutomatedReport $report\n *\n * @return \\Illuminate\\Database\\Eloquent\\Collection\n */\n public function getReportResults(AutomatedReport $report): \\Illuminate\\Database\\Eloquent\\Collection\n {\n return $this->automatedReportsRepository->getResultsByReport($report);\n }\n\n public function deleteAllReportResults(AutomatedReport $report): void\n {\n $results = $this->getReportResults($report);\n\n /** @var AutomatedReportResult $result */\n foreach ($results as $result) {\n Log::info('Deleting result', [\n 'report' => $report->getId(),\n 'result' => $result->getId(),\n ]);\n\n $this->deleteReportResult($result);\n }\n }\n\n public function deleteAllData(Team $team): void\n {\n Log::info('Deleting automated report and results for team', [\n 'team' => $team->getId(),\n ]);\n\n $reports = $this->getTeamReports($team);\n\n /** @var AutomatedReport $report */\n foreach ($reports as $report) {\n Log::info('Deleting report', [\n 'team' => $team->getId(),\n 'report' => $report->getId(),\n ]);\n\n $this->deleteAllReportResults($report);\n\n $report->delete();\n }\n }\n}","depth":4,"value":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Services\\Kiosk\\AutomatedReports;\n\nuse Carbon\\CarbonImmutable;\nuse Carbon\\CarbonInterface;\nuse Carbon\\Exceptions\\InvalidFormatException;\nuse DateTime;\nuse DateTimeInterface;\nuse DateTimeZone;\nuse Illuminate\\Contracts\\Bus\\Dispatcher as BusDispatcher;\nuse Illuminate\\Database\\Eloquent\\Builder;\nuse Illuminate\\Support\\Carbon;\nuse Illuminate\\Support\\Collection;\nuse Illuminate\\Support\\Facades\\Log;\nuse Illuminate\\Support\\Facades\\Storage;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinition\\InputTypeEnum;\nuse Jiminny\\Component\\AskAnything\\AskAnythingPromptService;\nuse Jiminny\\Component\\AskAnything\\Dtos\\AskAnythingPromptDto;\nuse Jiminny\\Component\\UrlGenerator\\Webhook;\nuse Jiminny\\Contracts\\Repositories\\PlaybookCategoryRepository;\nuse Jiminny\\Contracts\\Repositories\\TeamRepository;\nuse Jiminny\\Contracts\\Repositories\\UserRepository;\nuse Jiminny\\Exceptions\\ApplicationException;\nuse Jiminny\\Exceptions\\InvalidArgumentException;\nuse Jiminny\\Exceptions\\ModelNotFoundException;\nuse Jiminny\\Jobs\\AutomatedReports\\RequestGenerateReportJob;\nuse Jiminny\\Models\\Activity\\Search;\nuse Jiminny\\Models\\AskAnything\\AskAnythingPrompt;\nuse Jiminny\\Models\\AskAnything\\AskAnythingPromptTarget;\nuse Jiminny\\Models\\AutomatedReport;\nuse Jiminny\\Models\\AutomatedReportResult;\nuse Jiminny\\Models\\Contracts\\UserContract;\nuse Jiminny\\Models\\Feature\\FeatureEnum;\nuse Jiminny\\Models\\Team;\nuse Jiminny\\Models\\User;\nuse Jiminny\\Repositories\\AskAnythingRepository;\nuse Jiminny\\Repositories\\AutomatedReportsRepository;\nuse Jiminny\\Repositories\\GroupRepository;\nuse Jiminny\\Repositories\\SearchRepository;\nuse Jiminny\\Repositories\\StageRepository;\nuse Throwable;\n\nclass AutomatedReportsService\n{\n public const string TYPE_LOSS_ANALYSIS = 'loss_analysis';\n public const string TYPE_ASK_JIMINNY = 'ask_jiminny';\n\n /**\n * Standard report types (used by kiosk for existing automated reports).\n */\n // @TODO this will add filter, however if we need to control feature by FF we need conditional logic\n public const array TYPES = [\n ['id' => 'exec_summary', 'name' => 'Exec Summary'],\n ['id' => 'coaching_profiles', 'name' => 'Coaching Profiles'],\n ['id' => 'product_feedback', 'name' => 'Product Feedback'],\n ['id' => self::TYPE_LOSS_ANALYSIS, 'name' => 'Loss Analysis'],\n// ['id' => 'questions', 'name' => 'Questions'],\n// ['id' => 'statistical_quant', 'name' => 'Statistical Quantitative'],\n ];\n\n public const array ALL_TYPES = [\n ...self::TYPES,\n ['id' => self::TYPE_ASK_JIMINNY, 'name' => 'Ask Jiminny'],\n ];\n\n public const string FREQUENCY_DAILY = 'daily';\n public const string FREQUENCY_WEEKLY = 'weekly';\n public const string FREQUENCY_MONTHLY = 'monthly';\n public const string FREQUENCY_QUARTERLY = 'quarterly';\n public const string FREQUENCY_ONE_OFF = 'one_off';\n\n /**\n * Frequencies for standard (non-Ask Jiminny) reports.\n */\n public const array FREQUENCIES = [\n ['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],\n ['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],\n ['id' => self::FREQUENCY_QUARTERLY, 'name' => 'Quarterly'],\n ['id' => self::FREQUENCY_ONE_OFF, 'name' => 'One-off'],\n ];\n\n /**\n * Frequencies for Ask Jiminny reports.\n */\n public const array ASK_JIMINNY_FREQUENCIES = [\n ['id' => self::FREQUENCY_DAILY, 'name' => 'Daily'],\n ['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],\n ['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],\n ];\n\n public const string MEDIA_TYPE_PDF = 'pdf';\n public const string MEDIA_TYPE_PODCAST = 'podcast';\n public const array MEDIA_TYPES = [self::MEDIA_TYPE_PDF, self::MEDIA_TYPE_PODCAST];\n public const array MEDIA_TYPE_OBJECT_PDF = ['id' => self::MEDIA_TYPE_PDF, 'name' => 'PDF'];\n public const array MEDIA_TYPE_OBJECT_PODCAST = ['id' => self::MEDIA_TYPE_PODCAST, 'name' => 'Podcast'];\n public const array MEDIA_TYPE_OBJECTS = [self::MEDIA_TYPE_OBJECT_PDF, self::MEDIA_TYPE_OBJECT_PODCAST];\n\n public const array CALL_TYPE_CONFERENCE = ['id' => 'conference', 'name' => 'Conference'];\n public const array CALL_TYPE_DIALER = ['id' => 'dialer', 'name' => 'Dialer'];\n public const int SENT_REPORT_AT_HOURS = 5;\n public const string PDF_KEY = 'pdf';\n public const string AUDIO_KEY = 'audio';\n\n private const array ALL_FREQUENCIES = [\n ['id' => self::FREQUENCY_DAILY, 'name' => 'Daily'],\n ['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],\n ['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],\n ['id' => self::FREQUENCY_QUARTERLY, 'name' => 'Quarterly'],\n ['id' => self::FREQUENCY_ONE_OFF, 'name' => 'One-off'],\n ];\n private const string S3_DIR = 'reports';\n private const array FILE_EXTENSIONS_VARIANTS = ['html', 'MD', 'pdf'];\n private const array FILE_PODCAST_EXTENSIONS_VARIANTS = ['json', 'mp3', 'ssml'];\n\n public function __construct(\n private readonly TeamRepository $teamRepository,\n private readonly GroupRepository $groupRepository,\n private readonly UserRepository $userRepository,\n private readonly StageRepository $stageRepository,\n private readonly DealStagesService $dealStagesService,\n private readonly RecipientsService $recipientsService,\n private readonly AutomatedReportsRepository $automatedReportsRepository,\n private readonly Webhook $webhookService,\n private readonly BusDispatcher $dispatcher,\n private readonly ActivityTypeService $activityTypeService,\n private readonly PlaybookCategoryRepository $playbookCategoryRepository,\n private readonly AskAnythingPromptService $askAnythingPromptService,\n private readonly SearchRepository $activitySearchRepository,\n private readonly AskAnythingRepository $askAnythingRepository,\n ) {\n }\n\n public static function getTypes(): array\n {\n $types = self::TYPES;\n\n return array_map(static function ($type) {\n return $type['id'];\n }, $types);\n }\n\n public static function getCallTypes(): array\n {\n return array_map(static function ($callType) {\n return $callType['id'];\n }, [self::CALL_TYPE_CONFERENCE, self::CALL_TYPE_DIALER]);\n }\n\n public static function getFrequencies(): array\n {\n return array_map(static function ($frequency) {\n return $frequency['id'];\n }, self::FREQUENCIES);\n }\n\n // front-facing structure\n public function getReportEnabledFieldData(bool $value = false): array\n {\n return [\n 'id' => 'report_enabled',\n 'label' => '',\n 'inputType' => InputTypeEnum::TOGGLE,\n 'value' => $value,\n ];\n }\n\n // Organizations = Teams\n public function getOrganizationFieldData(?string $value = null, bool $shortVersion = false): array\n {\n $options = $this->getTeams();\n\n if ($shortVersion) {\n return [\n 'id' => 'organization',\n 'label' => 'Organization',\n 'options' => $options,\n ];\n }\n\n return [\n 'id' => 'organization',\n 'label' => 'Organization',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => $options,\n 'value' => $value,\n 'dependencies' => [\n 'teams',\n 'deal_stage_at_call',\n 'current_deal_stage',\n 'recipients',\n ActivityTypeService::PLAYBOOK_CATEGORIES_KEY,\n ],\n 'dependsOn' => [],\n ];\n }\n\n // Teams = Groups\n public function getTeamFieldData(array $options = [], array $value = [], bool $shortVersion = false): array\n {\n if ($shortVersion) {\n return [\n 'id' => 'teams',\n 'label' => 'Team',\n 'options' => $options,\n ];\n }\n\n return [\n 'id' => 'teams',\n 'label' => 'Team',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'required' => false,\n 'placeholder' => 'Select',\n 'options' => $options,\n 'value' => $value, // value should be an array of objects {id, name}\n 'dependencies' => [ActivityTypeService::PLAYBOOK_CATEGORIES_KEY],\n 'dependsOn' => [],\n ];\n }\n\n public function getReportTypeFieldData(?string $value = null, bool $shortVersion = false, ?Team $team = null): array\n {\n $types = [];\n if ($team instanceof Team) {\n if ($team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {\n $types = self::TYPES;\n }\n if ($team->hasFeature(FeatureEnum::ASK_JIMINNY_REPORTS)) {\n $types[] = ['id' => self::TYPE_ASK_JIMINNY, 'name' => 'Ask Jiminny'];\n }\n } else {\n $types = self::TYPES;\n }\n\n if ($shortVersion) {\n return [\n 'id' => 'report_type',\n 'label' => 'Report Type',\n 'options' => $types,\n ];\n }\n\n return [\n 'id' => 'report_type',\n 'label' => 'Report Type',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => $types,\n 'value' => $value,\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getFrequencyFieldData(?string $value = null): array\n {\n return [\n 'id' => 'frequency',\n 'label' => 'Frequency',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => self::FREQUENCIES,\n 'value' => $value,\n 'dependencies' => ['period'],\n 'dependsOn' => [],\n ];\n }\n\n public function getPeriodFieldData(?string $valueStartDate = null, ?string $valueEndDate = null): array\n {\n return [\n 'id' => 'period',\n 'label' => 'Select one-off period',\n 'inputType' => InputTypeEnum::DATE_RANGE,\n 'required' => true,\n 'placeholder' => 'Select',\n 'value' => ['startDate' => $valueStartDate, 'endDate' => $valueEndDate],\n 'queryParams' => [\n 'startDate' => 'start_date_period',\n 'endDate' => 'end_date_period',\n ],\n 'dependencies' => [],\n 'dependsOn' => ['frequency'],\n ];\n }\n\n public function getActivityTypesFieldData(?Team $team = null, array $value = [], array $teamsFilter = []): array\n {\n return $this->activityTypeService->getActivityTypeFieldData(team: $team, value: $value, groupIds: $teamsFilter);\n }\n\n public function getDealStageAtCallFieldData(?Team $team = null, array $value = []): array\n {\n return $this->dealStagesService->getDealStageAtCallFieldData(team: $team, value: $value);\n }\n\n public function getCurrentDealStageFieldData(?Team $team = null, array $value = []): array\n {\n return $this->dealStagesService->getCurrentDealStageFieldData(team: $team, value: $value);\n }\n\n public function getDealValueFieldData(?int $valueMin = null, ?int $valueMax = null): array\n {\n return [\n 'id' => 'deal_value',\n 'label' => 'Deal Value',\n 'inputType' => InputTypeEnum::INTEGER_RANGE,\n 'required' => false,\n 'value' => ['min' => $valueMin, 'max' => $valueMax],\n 'queryParams' => [\n 'min' => 'min_deal_value',\n 'max' => 'max_deal_value',\n ],\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getCallTypeFieldData(bool $conferenceOn = false, bool $dialerOn = false): array\n {\n $value = [];\n $conferenceOn && $value[] = self::CALL_TYPE_CONFERENCE;\n $dialerOn && $value[] = self::CALL_TYPE_DIALER;\n\n return [\n 'id' => 'call_type',\n 'label' => 'Call Type',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'required' => true,\n 'options' => [\n self::CALL_TYPE_CONFERENCE,\n self::CALL_TYPE_DIALER,\n ],\n 'value' => $value,\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getMediaTypeFieldData(?AutomatedReport $report = null): array\n {\n $value = [];\n\n if ($report) {\n $value = $this->transformMediaTypes($report);\n }\n\n return [\n 'id' => 'media_types',\n 'label' => 'Export as',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'required' => true,\n 'options' => self::MEDIA_TYPE_OBJECTS,\n 'value' => $value,\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getCallDurationFieldData(?int $valueMin = null, ?int $valueMax = null): array\n {\n return [\n 'id' => 'call_duration',\n 'label' => 'Call Duration',\n 'inputType' => InputTypeEnum::INTEGER_RANGE,\n 'required' => false,\n 'value' => ['min' => $valueMin, 'max' => $valueMax],\n 'queryParams' => [\n 'min' => 'min_call_duration',\n 'max' => 'max_call_duration',\n ],\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getRecipientsFieldData(?Team $team = null, array $value = []): array\n {\n return $this->recipientsService->getRecipientsFieldData(team: $team, value: $value);\n }\n\n public function getJiminnyRecipientsFieldData(array $value = []): array\n {\n return $this->recipientsService->getJiminnyRecipientsFieldData($value);\n }\n\n public function getAdditionalPromptInputFieldData(?string $value = null): array\n {\n return [\n 'id' => 'additional_prompt_input',\n 'label' => 'Special requirements',\n 'inputType' => InputTypeEnum::TEXTAREA,\n 'required' => false,\n 'placeholder' => 'What should be the focus of the report?',\n 'value' => $value,\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getCustomReportNameFieldData(?string $value = null): array\n {\n return [\n 'id' => 'custom_name',\n 'label' => 'Custom report name',\n 'inputType' => InputTypeEnum::TEXT,\n 'required' => false,\n 'placeholder' => 'Enter custom name',\n 'value' => $value,\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n // data providers\n public function getTeams(): array\n {\n $teams = $this->teamRepository->getTeamsForKiosk(status: Team::STATUS_ACTIVE);\n\n $teamData = [];\n foreach ($teams as $team) {\n if (! $team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {\n continue;\n }\n\n $teamData[] = $this->transformTeam($team);\n }\n\n return $teamData;\n }\n\n public function getTeamGroups(string $teamUuid): array\n {\n $data = [];\n $team = $this->getTeam($teamUuid);\n\n if ($team !== null) {\n $groups = $team->groups()->get();\n\n foreach ($groups as $group) {\n $data[] = [\n 'id' => $group->getUuid(),\n 'name' => $group->getName(),\n ];\n }\n }\n\n return $data;\n }\n\n public function getTeamsGroupsOptions(array $filterTeamUuids = []): array\n {\n $data = [];\n $teams = $this->getTeams();\n\n foreach ($teams as $team) {\n if (! empty($filterTeamUuids) && ! in_array($team['id'], $filterTeamUuids, true)) {\n continue;\n }\n\n $data[] = [\n 'label' => $team['name'],\n 'groups' => $this->getTeamGroups($team['id']),\n ];\n }\n\n return $data;\n }\n\n public function getTeam(string $teamUuid): ?Team\n {\n return $this->teamRepository->idOrUuid($teamUuid);\n }\n\n public function getTeamById(int $teamId): ?Team\n {\n return $this->teamRepository->find($teamId);\n }\n\n public function getGroupsUuids(AutomatedReport $report): array\n {\n $uuids = [];\n $reportGroups = $report->getGroups();\n foreach ($reportGroups as $groupId) {\n if ($group = $this->groupRepository->find($groupId)) {\n $uuids[] = $group->getUuid();\n }\n }\n\n return $uuids;\n }\n\n public function getPlaybookCategoriesUuids(AutomatedReport $report): array\n {\n $uuids = [];\n $playbookCategories = $report->getPlaybookCategories();\n foreach ($playbookCategories as $id) {\n if ($category = $this->playbookCategoryRepository->find($id)) {\n $uuids[] = $category->getUuid();\n }\n }\n\n return $uuids;\n }\n\n public function getDealAtCallStagesUuids(AutomatedReport $report): array\n {\n $uuids = [];\n $reportStages = $report->getDealAtCallStages();\n foreach ($reportStages as $id) {\n if ($stage = $this->stageRepository->find($id)) {\n $uuids[] = $stage->getUuid();\n }\n }\n\n return $uuids;\n }\n\n public function getCurrentDealStagesUuids(AutomatedReport $report): array\n {\n $uuids = [];\n $reportStages = $report->getCurrentDealStages();\n foreach ($reportStages as $id) {\n if ($stage = $this->stageRepository->find($id)) {\n $uuids[] = $stage->getUuid();\n }\n }\n\n return $uuids;\n }\n\n public function getUsersUuids(AutomatedReport $report): array\n {\n return $this->extractUserUuids($report->getRecipients());\n }\n\n public function getJiminnyUsersUuids(AutomatedReport $report): array\n {\n return $this->extractUserUuids($report->getJiminnyRecipients());\n }\n\n /**\n * @param array<string, mixed> $recipients\n */\n private function extractUserUuids(array $recipients): array\n {\n $userIds = $recipients['users'] ?? [];\n\n return collect($userIds)\n ->map(fn ($id) => $this->userRepository->find((int) $id))\n ->filter()\n ->map(fn (UserContract $user) => $user->getUuid())\n ->values()\n ->all();\n }\n\n // get mail data\n public function getRecipientUsers(AutomatedReport $report): array\n {\n return $this->buildRecipientUsers($report->getRecipients());\n }\n\n private function getJiminnyRecipientUsers(AutomatedReport $report): array\n {\n return $this->buildRecipientUsers($report->getJiminnyRecipients());\n }\n\n /**\n * @param array<string, mixed> $recipients\n */\n private function buildRecipientUsers(array $recipients): array\n {\n $userIds = $recipients['users'] ?? [];\n\n return collect($userIds)\n ->map(fn ($id) => $this->userRepository->find((int) $id))\n ->filter()\n ->map(fn (UserContract $user) => [\n 'email' => $user->getEmailAddress(),\n 'name' => $user->getName(),\n 'timezone' => $user->getTimezone()->getName(),\n ])\n ->values()\n ->all();\n }\n\n public function getValidRecipientUsers(AutomatedReport $report, bool $includeJiminny = false): array\n {\n if ($report->isAskJiminnyReport()) {\n $recipients = $this->resolveAskJiminnyRecipients($report);\n } else {\n $recipients = $this->getRecipientUsers($report);\n if ($includeJiminny) {\n $recipients = array_merge($recipients, $this->getJiminnyRecipientUsers($report));\n }\n }\n\n $emails = [];\n\n return array_values(array_filter(\n $recipients,\n static function ($recipient) use (&$emails) {\n if (empty($recipient['email']) || in_array($recipient['email'], $emails, true)) {\n return false;\n }\n $emails[] = $recipient['email'];\n\n return true;\n }\n ));\n }\n\n private function resolveAskJiminnyRecipients(AutomatedReport $report): array\n {\n $recipients = [];\n\n $creator = $report->getCreator();\n if ($creator !== null) {\n $recipients[] = [\n 'email' => $creator->getEmailAddress(),\n 'name' => $creator->getName(),\n 'timezone' => $creator->getTimezone()->getName(),\n ];\n }\n\n return array_merge(\n $recipients,\n $this->buildRecipientUsers($report->getRecipients()),\n $this->getGroupRecipientUsers($report),\n );\n }\n\n private function getGroupRecipientUsers(AutomatedReport $report): array\n {\n $users = [];\n foreach ($report->getGroups() as $groupId) {\n $group = $this->groupRepository->find($groupId);\n if ($group === null) {\n continue;\n }\n foreach ($group->getMembers() as $member) {\n $users[] = [\n 'email' => $member->getEmailAddress(),\n 'name' => $member->getName(),\n 'timezone' => $member->getTimezone()->getName(),\n ];\n }\n }\n\n return $users;\n }\n\n public function getReportTypeName(AutomatedReportResult $report): string\n {\n $type = $report->getReport()->getType();\n\n $getType = $this->transformReportType($type);\n\n return $getType['name'];\n }\n\n public function getReportPeriodName(AutomatedReportResult $report): string\n {\n $from = $report->getFromDate();\n $to = $report->getToDate();\n $frequency = $report->getReport()->getFrequency();\n\n if ($from === null || $to === null) {\n if (! $report->getReport()->isAskJiminnyReport()) {\n $invalidPeriod = $from === null ? 'from' : 'to';\n\n throw new ApplicationException('Report period is invalid: ' . $invalidPeriod);\n }\n\n $period = $this->calculateFromAndToDatePeriod($frequency);\n $from = $period['fromDate'];\n $to = $period['toDate'];\n }\n\n return $this->formatReportPeriodName($frequency, $from, $to);\n }\n\n private function formatReportPeriodName(string $frequency, Carbon $from, Carbon $to): string\n {\n $fromYear = $from->format('Y');\n $toYear = $to->format('Y');\n $differentYears = $fromYear !== $toYear;\n\n switch ($frequency) {\n case self::FREQUENCY_DAILY:\n return $from->format('j M Y');\n\n case self::FREQUENCY_QUARTERLY:\n // 'Jan-Mar 2025' or 'Nov 2024-Jan 2025' if years differ\n $startMonth = $from->format('M');\n $endMonth = $to->copy()->subMonth();\n $endMonthName = $endMonth->format('M');\n $endMonthYear = $endMonth->format('Y');\n\n if ($differentYears) {\n return \"{$startMonth} {$fromYear} - {$endMonthName} {$endMonthYear}\";\n }\n\n return \"{$startMonth} - {$endMonthName} {$toYear}\";\n\n case self::FREQUENCY_MONTHLY:\n // 'May 2025' - monthly reports are always within the same year\n return $from->format('M Y');\n\n case self::FREQUENCY_WEEKLY:\n // '4 - 8 Aug 2025', '27 Oct - 3 Nov 2025', or '28 Dec 2024 - 3 Jan 2025' if years differ\n $startDay = $from->format('j');\n $endDay = $to->format('j');\n $startMonth = $from->format('M');\n $endMonth = $to->format('M');\n\n if ($differentYears) {\n return \"{$startDay} {$startMonth} {$fromYear} - {$endDay} {$endMonth} {$toYear}\";\n }\n\n if ($startMonth !== $endMonth) {\n return \"{$startDay} {$startMonth} - {$endDay} {$endMonth} {$toYear}\";\n }\n\n return \"{$startDay} - {$endDay} {$endMonth} {$toYear}\";\n\n case self::FREQUENCY_ONE_OFF:\n // '2 May-31 May 2025' or '15 Dec 2024-15 Jan 2025' if years differ\n $startDay = $from->format('j');\n $startMonth = $from->format('M');\n $endDay = $to->format('j');\n $endMonth = $to->format('M');\n\n // If same month and year, use a format like '2-31 May 2025'\n if ($startMonth === $endMonth && ! $differentYears) {\n return \"{$startDay} - {$endDay} {$startMonth} {$toYear}\";\n }\n\n // If different years, include both years\n if ($differentYears) {\n return \"{$startDay} {$startMonth} {$fromYear} - {$endDay} {$endMonth} {$toYear}\";\n }\n\n // Same year but different months\n return \"{$startDay} {$startMonth} - {$endDay} {$endMonth} {$toYear}\";\n\n default:\n // Default format for unknown frequencies\n return $from->format('j M Y') . ' - ' . $to->format('j M Y');\n }\n }\n\n public function getReportTeamsName(AutomatedReportResult $report): string\n {\n $groups = $report->getGroups();\n\n if (empty($groups)) {\n return 'All';\n }\n\n // Get group names from repository\n $groupNames = [];\n foreach ($groups as $groupId) {\n $group = $this->groupRepository->find($groupId);\n if ($group) {\n $groupNames[] = $group->getName();\n }\n }\n\n if (count($groupNames) === 1) {\n // Single team format\n $teamsName = $groupNames[0];\n } else {\n // Multiple teams format\n $teamsName = implode(', ', $groupNames);\n }\n\n return $teamsName;\n }\n\n public function getReportFileName(AutomatedReportResult $report): string\n {\n $customName = $report->getReport()->getCustomName();\n $periodName = $this->getReportPeriodName($report);\n $filenameSuffix = $this->getFilenameSuffix($report);\n\n if ($customName) {\n if ($filenameSuffix) {\n $customName .= \" {$filenameSuffix}\";\n }\n\n return $this->sanitizeFileName(\"{$customName} - {$periodName}\");\n }\n\n $baseName = $this->getReportTypeName($report);\n\n if ($filenameSuffix) {\n $baseName .= \" {$filenameSuffix}\";\n }\n\n return $this->sanitizeFileName(\"{$baseName} - {$periodName} - {$this->getReportTeamsName($report)}\");\n }\n\n public function getReportFileNameWithExtension(AutomatedReportResult $result): string\n {\n $extension = $this->getMediaTypeMetadata($result)['extension'];\n\n return $this->getReportFileName($result) . '.' . $extension;\n }\n\n public function sanitizeFileName(string $fileName): string\n {\n return str_replace(['/', '\\\\'], '-', $fileName);\n }\n\n public function isUserRecipientOfReport(User $user, AutomatedReport $report): bool\n {\n $recipients = array_map('intval', $report->getRecipients()['users'] ?? []);\n\n return in_array($user->getId(), $recipients);\n }\n\n public function transformReportResults(Collection $automatedReportResults): array\n {\n $data = [];\n foreach ($automatedReportResults as $automatedReportResult) {\n /** @var AutomatedReportResult $automatedReportResult */\n\n $report = $automatedReportResult->getReport();\n\n $createdBy = $report->getCreator();\n $creator = [\n 'id' => $createdBy?->getUuid(),\n 'name' => $createdBy?->getName(),\n 'email' => $createdBy?->getEmailAddress(),\n 'photoUrl' => $createdBy?->getPhotoUrl(),\n ];\n\n $data[] = [\n 'id' => $automatedReportResult->getUuid(),\n 'name' => $automatedReportResult->getName(),\n 'frequency' => $this->transformFrequency($report->getFrequency()),\n 'recipients' => [\n ...array_values($this->transformGroups(team: $report->getTeam(), groupsIds: $report->getGroups())),\n ...array_values($this->transformRecipients($report->getRecipients())),\n ],\n 'report_type' => $this->transformReportType($report->getType()),\n 'media_type' => $automatedReportResult->getMediaType(),\n 'downloadUrl' => $this->generateReportResultDownloadUrl($automatedReportResult),\n 'viewUrl' => $this->generateReportResultViewUrl($automatedReportResult),\n 'generated_at' => $automatedReportResult->getGeneratedAt()?->toIso8601String(),\n 'creator' => $creator,\n ];\n }\n\n return $data;\n }\n\n public function hasCallTypeConference(AutomatedReport $report): bool\n {\n return in_array(self::CALL_TYPE_CONFERENCE['id'], $report->getCallTypes(), true);\n }\n\n public function hasCallTypeDialer(AutomatedReport $report): bool\n {\n return in_array(self::CALL_TYPE_DIALER['id'], $report->getCallTypes(), true);\n }\n\n // transformers\n private function transformTeam(Team $team): array\n {\n if (! $team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {\n return [];\n }\n\n return [\n 'id' => $team->getUuid(),\n 'name' => $team->getName(),\n ];\n }\n\n private function transformReportFullView(AutomatedReport $report): array\n {\n $base = $this->transformReportBase($report);\n\n return $report->getType() === self::TYPE_ASK_JIMINNY\n ? $base + $this->transformAskJiminnyFields($report)\n : $base + $this->transformStandardReportFields($report);\n }\n\n private function transformReportBase(AutomatedReport $report): array\n {\n return [\n 'id' => $report->getUuid(),\n 'organization' => $this->transformOrganization(team: $report->getTeam()),\n 'report_type' => $this->transformReportType($report->getType()),\n 'frequency' => $this->transformFrequency($report->getFrequency()),\n ];\n }\n\n private function transformStandardReportFields(AutomatedReport $report): array\n {\n $team = $report->getTeam();\n\n return [\n 'report_enabled' => $report->getStatus(),\n 'start_date_period' => $report->getFrom()?->format('Y-m-d H:i:s'),\n 'end_date_period' => $report->getTo()?->format('Y-m-d H:i:s'),\n 'deal_value_min' => $report->getDealValueMin(),\n 'deal_value_max' => $report->getDealValueMax(),\n 'call_types' => $this->transformCallType($report->getCallTypes()),\n 'media_types' => $this->transformMediaTypes($report),\n 'call_duration_min' => $this->transformDurationToMinutes($report->getCallDurationMin()),\n 'call_duration_max' => $this->transformDurationToMinutes($report->getCallDurationMax()),\n 'teams' => $this->transformGroups(team: $team, groupsIds: $report->getGroups()),\n 'deal_at_call_stages' => $this->transformStages(team: $team, stagesIds: $report->getDealAtCallStages()),\n 'current_deal_stages' => $this->transformStages(team: $team, stagesIds: $report->getCurrentDealStages()),\n 'recipients' => $this->transformRecipients($report->getRecipients()),\n 'created_by' => $this->transformCreator($report->getCreator()),\n 'additional_prompt_input' => $report->getAdditionalPromptInput(),\n 'custom_name' => $report->getCustomName(),\n 'created_at' => $report->getCreatedAt()->format('Y-m-d H:i:s'),\n 'updated_at' => $report->getUpdatedAt()->format('Y-m-d H:i:s'),\n 'deleted_at' => $report->getDeletedAt()?->format('Y-m-d H:i:s'),\n ];\n }\n\n private function transformAskJiminnyFields(AutomatedReport $report): array\n {\n $team = $report->getTeam();\n $creatorId = $report->getAttribute('created_by');\n $explicitUserIds = array_values(array_filter(\n $report->getRecipients()['users'] ?? [],\n static fn ($id) => $id !== $creatorId\n ));\n\n return [\n 'report_name' => $report->getCustomName(),\n 'enabled' => $report->getStatus(),\n 'share_teams' => $this->transformGroups(team: $team, groupsIds: $report->getGroups()),\n 'share_users' => $this->transformRecipients(['users' => $explicitUserIds]),\n 'saved_search' => $this->transformSafeSearch($report->getSavedSearch()),\n 'ask_jiminny_prompt' => $this->transformAskJiminnyPrompt($report->getAskAnythingPrompt()),\n 'expires_on' => $report->getExpiresAt()?->format('Y-m-d'),\n ];\n }\n\n private function transformOrganization(?Team $team): array\n {\n return [\n 'id' => $team?->getUuid(),\n 'name' => $team?->getName(),\n ];\n }\n\n private function transformReportType(string $type): array\n {\n foreach (self::ALL_TYPES as $typeItem) {\n if ($typeItem['id'] === $type) {\n return $typeItem;\n }\n }\n\n return [];\n }\n\n private function transformCallType(array $types): array\n {\n $result = [];\n $callTypes = [self::CALL_TYPE_CONFERENCE, self::CALL_TYPE_DIALER];\n\n foreach ($types as $type) {\n foreach ($callTypes as $callTypeItem) {\n if ($callTypeItem['id'] === $type) {\n $result[] = $callTypeItem;\n\n break;\n }\n }\n }\n\n return $result;\n }\n\n private function transformMediaTypes(AutomatedReport $report): array\n {\n $values = [];\n\n foreach ($report->getMediaTypes() as $mediaType) {\n if (! in_array($mediaType, self::MEDIA_TYPES, true)) {\n continue;\n }\n\n $values[] = match ($mediaType) {\n self::MEDIA_TYPE_PDF => self::MEDIA_TYPE_OBJECT_PDF,\n self::MEDIA_TYPE_PODCAST => self::MEDIA_TYPE_OBJECT_PODCAST,\n };\n }\n\n return $values;\n }\n\n private function transformFrequency(string $frequency): array\n {\n foreach (self::ALL_FREQUENCIES as $frequencyItem) {\n if ($frequencyItem['id'] === $frequency) {\n return $frequencyItem;\n }\n }\n\n return [];\n }\n\n public function transformDurationToMinutes(?int $duration): ?int\n {\n if (! $duration) {\n return null;\n }\n\n return (int) ($duration / 60);\n }\n\n private function transformGroups(?Team $team, array $groupsIds): array\n {\n if (empty($groupsIds) || ! $team) {\n return [];\n }\n\n $data = [];\n foreach ($groupsIds as $groupId) {\n $group = $team->groups()->where('id', $groupId)->first();\n\n if ($group) {\n $data[] = [\n 'id' => $group->getUuid(),\n 'name' => $group->getName(),\n 'photoUrl' => $group->getPhotoUrl(),\n ];\n }\n }\n\n return $data;\n }\n\n private function transformStages(?Team $team, array $stagesIds): array\n {\n if (empty($stagesIds) || ! $team) {\n return [];\n }\n\n $data = [];\n foreach ($stagesIds as $stageId) {\n $stage = $team->stages()->where('id', $stageId)->first();\n\n if ($stage) {\n $data[] = [\n 'id' => $stage->getUuid(),\n 'name' => $stage->getName(),\n ];\n }\n }\n\n return $data;\n }\n\n private function transformRecipients(array $recipients): array\n {\n $users = [];\n foreach ($recipients['users'] ?? [] as $userId) {\n $users[] = $this->transformUser($userId);\n }\n\n return $users;\n }\n\n private function transformCreator(?User $user): ?array\n {\n if ($user === null) {\n return null;\n }\n\n return $this->transformUser($user->getId());\n }\n\n private function transformAskJiminnyPrompt(?AskAnythingPrompt $prompt): ?array\n {\n if ($prompt === null) {\n return null;\n }\n\n return [\n 'id' => $prompt->getUuid(),\n 'name' => $prompt->getTitle(),\n ];\n }\n\n private function transformSafeSearch(?Search $search): ?array\n {\n if ($search === null) {\n return null;\n }\n\n return [\n 'id' => $search->getUuid(),\n 'name' => $search->getName(),\n ];\n }\n\n private function transformUser(int $userId): array\n {\n /* @var ?User $user */\n $user = $this->userRepository->find($userId);\n\n return [\n 'id' => $user?->getUuid(),\n 'name' => $user?->getName(),\n 'email' => $user?->getEmailAddress(),\n 'photoUrl' => $user?->getPhotoUrl(),\n ];\n }\n\n public function create(array $data): array\n {\n $validatedData = $this->validateAndTransformData($data);\n $validatedData['created_by'] = auth()->id();\n\n $automatedReport = $this->automatedReportsRepository->create($validatedData);\n\n $this->generateOneOffReport($automatedReport);\n\n return $this->transformReportFullView($automatedReport);\n }\n\n public function update(string $uuid, array $data): array\n {\n $validatedData = $this->validateAndTransformData($data);\n $report = $this->automatedReportsRepository->findByUuid($uuid);\n\n if (! $report) {\n throw new InvalidArgumentException('Report not found');\n }\n\n $oldCustomName = $report->getCustomName();\n\n $automatedReport = $this->automatedReportsRepository->update($report, $validatedData);\n\n if ($oldCustomName !== $automatedReport->getCustomName()) {\n $this->updateResultNames($automatedReport);\n }\n\n $this->generateOneOffReport($automatedReport);\n\n return $this->transformReportFullView($automatedReport);\n }\n\n /**\n * Create an Ask Jiminny report.\n */\n public function createAskJiminnyReport(array $data, User $creator): array\n {\n $validatedData = $this->validateAskJiminnyReportData($data, $creator);\n $validatedData['created_by'] = $creator->getId();\n\n $automatedReport = $this->automatedReportsRepository->create($validatedData);\n\n return $this->transformReportFullView($automatedReport);\n }\n\n /**\n * Update an Ask Jiminny report.\n */\n public function updateAskJiminnyReport(AutomatedReport $report, array $data, User $user): array\n {\n if (! $report->isAskJiminnyReport()) {\n throw new InvalidArgumentException('Report is not an Ask Jiminny report');\n }\n\n $validatedData = $this->validateAskJiminnyReportData($data, $user);\n\n $oldCustomName = $report->getCustomName();\n\n $automatedReport = $this->automatedReportsRepository->update($report, $validatedData);\n\n if ($oldCustomName !== $automatedReport->getCustomName()) {\n $this->updateResultNames($automatedReport);\n }\n\n return $this->transformReportFullView($automatedReport);\n }\n\n public function updateAskJiminnyReportStatus(AutomatedReport $report, bool $status): array\n {\n $this->automatedReportsRepository->update($report, ['status' => $status]);\n\n return $this->transformReportFullView($report->fresh());\n }\n\n /**\n * Validate and transform data for Ask Jiminny reports.\n */\n private function validateAskJiminnyReportData(array $data, User $user): array\n {\n // Validate name\n $name = trim($data['report_name'] ?? '');\n if (empty($name)) {\n throw new InvalidArgumentException('Report name is required');\n }\n if (mb_strlen($name) > 50) {\n throw new InvalidArgumentException('Report name must be 50 characters or less');\n }\n\n // Validate frequency (only daily, weekly, monthly for Ask Jiminny)\n $frequency = $data['frequency'] ?? null;\n $askJiminnyFrequencies = [self::FREQUENCY_DAILY, self::FREQUENCY_WEEKLY, self::FREQUENCY_MONTHLY];\n if (! in_array($frequency, $askJiminnyFrequencies, true)) {\n throw new InvalidArgumentException('Frequency must be daily, weekly, or monthly');\n }\n\n // Validate expiration date\n $expiresAt = $data['expires_on'] ?? null;\n if (empty($expiresAt)) {\n throw new InvalidArgumentException('Expiration date is required');\n }\n\n try {\n $expiresAtDate = Carbon::parse($expiresAt);\n } catch (InvalidFormatException $e) {\n throw new InvalidArgumentException('Expiration date format is invalid');\n }\n $maxExpiration = Carbon::now()->addYear();\n if ($expiresAtDate->gt($maxExpiration)) {\n throw new InvalidArgumentException('Expiration date cannot be more than 1 year from now');\n }\n if ($expiresAtDate->isPast()) {\n throw new InvalidArgumentException('Expiration date cannot be in the past');\n }\n\n // Validate saved search\n $activitySearchId = $data['saved_search'] ?? null;\n if (empty($activitySearchId)) {\n throw new InvalidArgumentException('Saved search is required');\n }\n $savedSearch = $this->activitySearchRepository->findByUuidAndUser($activitySearchId, $user);\n if (! $savedSearch) {\n throw new InvalidArgumentException('Saved search not found or does not belong to you');\n }\n\n // Validate saved prompt\n $askAnythingPromptId = $data['ask_jiminny_prompt'] ?? null;\n if (empty($askAnythingPromptId)) {\n throw new InvalidArgumentException('Ask Jiminny prompt is required');\n }\n $prompt = $this->askAnythingRepository->getPromptByUuid($askAnythingPromptId);\n if (! $prompt) {\n throw new InvalidArgumentException('Ask Jiminny prompt not found');\n }\n\n // Validate status\n $status = $data['enabled'] ?? false;\n\n $recipientUserIds = [$user->getId()];\n\n if (! empty($data['share_users'])) {\n $sharedUserIds = $this->validateAndGetUserIdsByTeam(\n $user->team,\n (array) $data['share_users']\n );\n $recipientUserIds = array_merge($recipientUserIds, $sharedUserIds);\n }\n\n $sharedGroupIds = [];\n if (! empty($data['share_teams'])) {\n $sharedGroupIds = $this->validateAndGetGroupIds($user->team, (array) $data['share_teams']);\n }\n\n $recipientUserIds = array_values(array_unique($recipientUserIds));\n\n return [\n 'team_id' => $user->getTeamId(),\n 'type' => self::TYPE_ASK_JIMINNY,\n 'status' => (bool) $status,\n 'frequency' => $frequency,\n 'custom_name' => $name,\n 'activity_search_id' => $savedSearch->getId(),\n 'ask_anything_prompt_id' => $prompt->getId(),\n 'expires_at' => $expiresAtDate->toDateString(),\n 'media_types' => [self::MEDIA_TYPE_PDF],\n 'call_types' => [],\n 'recipients' => ['users' => $recipientUserIds],\n 'groups' => $sharedGroupIds,\n ];\n }\n\n public static function getAskJiminnyFrequencies(): array\n {\n return array_map(static function ($frequency) {\n return $frequency['id'];\n }, self::ASK_JIMINNY_FREQUENCIES);\n }\n\n public function getAskJiminnyReportFilters(User $user): array\n {\n $savedSearches = $this->activitySearchRepository->findByUserOrderedByName($user)\n ->map(fn (Search $search) => [\n 'id' => $search->getUuid(),\n 'name' => $search->getName(),\n ])\n ->values()->all();\n\n $prompts = collect(\n $this->askAnythingPromptService->get($user, AskAnythingPromptTarget::on_demand)\n )->map(fn (AskAnythingPromptDto $prompt) => [\n 'id' => $prompt->id,\n 'name' => $prompt->title,\n ])->values()->all();\n\n return [\n [\n 'id' => 'prompt',\n 'label' => 'Prompt',\n 'options' => $prompts,\n ],\n [\n 'id' => 'saved_search',\n 'label' => 'Saved Search',\n 'options' => $savedSearches,\n ],\n ];\n }\n\n public function getAskJiminnyReportFormData(User $user, ?AutomatedReport $report = null): array\n {\n $team = $user->getTeam();\n $userTimezone = $user->getTimezone();\n\n $savedSearches = $this->activitySearchRepository->findByUserOrderedByName($user)\n ->map(fn (Search $search) => [\n 'id' => $search->getUuid(),\n 'name' => $search->getName(),\n ])\n ->values()->all();\n\n $prompts = collect(\n $this->askAnythingPromptService->get($user, AskAnythingPromptTarget::on_demand)\n )->map(fn (AskAnythingPromptDto $prompt) => [\n 'id' => $prompt->id,\n 'name' => $prompt->title,\n ])->values()->all();\n\n $teamGroups = $this->groupRepository->getAllByTeam($team)->map(fn ($group) => [\n 'id' => $group->getUuid(),\n 'name' => $group->getName(),\n ])->values()->all();\n\n $shareUsers = $this->recipientsService->getRecipientsFieldData(team: $team)['options'] ?? [];\n\n $sharedTeamsValue = [];\n $sharedUsersValue = [];\n if ($report) {\n $sharedTeamsValue = $this->transformGroups($team, $report->getGroups());\n\n $recipientUserIds = $report->getRecipients()['users'] ?? [];\n $creatorId = $report->getAttribute('created_by');\n $sharedUserIds = array_values(array_filter(\n $recipientUserIds,\n static fn ($id) => $id !== $creatorId\n ));\n $sharedUsersValue = collect($sharedUserIds)\n ->map(fn ($id) => $this->userRepository->find((int) $id))\n ->filter()\n ->map(fn (User $u) => [\n 'id' => $u->getUuid(),\n 'name' => $u->getName(),\n ])\n ->values()\n ->all();\n }\n\n return [\n 'fields' => [\n [\n 'id' => 'enabled',\n 'inputType' => InputTypeEnum::TOGGLE,\n 'label' => '',\n 'value' => $report?->getStatus() ?? false,\n ],\n [\n 'id' => 'report_name',\n 'inputType' => InputTypeEnum::TEXT,\n 'label' => 'Name',\n 'placeholder' => 'Enter name',\n 'required' => true,\n 'validation' => ['maxLength' => 50],\n 'value' => $report?->getCustomName() ?? '',\n ],\n [\n 'id' => 'frequency',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'label' => 'Frequency',\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => self::ASK_JIMINNY_FREQUENCIES,\n 'value' => $report ? $this->transformFrequency($report->getFrequency()) : null,\n ],\n [\n 'id' => 'expires_on',\n 'inputType' => InputTypeEnum::DATE,\n 'label' => 'Expires on',\n 'required' => true,\n 'placeholder' => 'Select',\n 'validation' => [\n 'minDate' => now($userTimezone)->toDateString(),\n 'maxDate' => now($userTimezone)->addYear()->toDateString(),\n ],\n 'value' => $report?->getExpiresAt()?->toDateString(),\n ],\n [\n 'id' => 'share_teams',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'label' => 'Team',\n 'required' => false,\n 'placeholder' => 'Select',\n 'options' => $teamGroups,\n 'value' => $sharedTeamsValue,\n ],\n [\n 'id' => 'share_users',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'label' => 'Team member',\n 'required' => false,\n 'placeholder' => 'Select',\n 'groupLabelKey' => 'label',\n 'groupValuesKey' => 'users',\n 'optionLabelKey' => 'name',\n 'optionValueKey' => 'id',\n 'options' => $shareUsers,\n 'value' => $sharedUsersValue,\n ],\n [\n 'id' => 'saved_search',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'label' => 'Saved search',\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => $savedSearches,\n 'value' => $report && $report->getSavedSearch() ? [\n 'id' => $report->getSavedSearch()->getUuid(),\n 'name' => $report->getSavedSearch()->getName(),\n ] : null,\n ],\n [\n 'id' => 'ask_jiminny_prompt',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'label' => 'Ask Jiminny prompt',\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => $prompts,\n 'value' => $report && $report->getAskAnythingPrompt() ? [\n 'id' => $report->getAskAnythingPrompt()->getUuid(),\n 'name' => $report->getAskAnythingPrompt()->getTitle(),\n ] : null,\n ],\n ],\n ];\n }\n\n private function updateResultNames(AutomatedReport $automatedReport): void\n {\n $results = $this->automatedReportsRepository->getResultsByReport($automatedReport);\n\n foreach ($results as $result) {\n $result->update(['name' => $this->getReportFileName($result)]);\n }\n }\n\n public function updateStatus(string $uuid, array $data): array\n {\n $automatedReport = $this->automatedReportsRepository->findByUuid($uuid);\n\n if (! $automatedReport) {\n throw new ModelNotFoundException('Report not found');\n }\n\n $status = $this->validateReportStatus($data['report_enabled'] ?? null);\n $automatedReport->update([\n 'status' => $status,\n ]);\n\n $this->generateOneOffReport($automatedReport);\n\n return $this->transformReportFullView($automatedReport);\n }\n\n private function generateOneOffReport(AutomatedReport $automatedReport): void\n {\n // the scheduler handles all the other frequency types\n if ($automatedReport->getStatus() === false || $automatedReport->getFrequency() !== self::FREQUENCY_ONE_OFF) {\n return;\n }\n\n $this->dispatcher->dispatch(new RequestGenerateReportJob($automatedReport->getUuid()));\n }\n\n public function getReport(string $uuid): AutomatedReport\n {\n $automatedReport = $this->automatedReportsRepository->findByUuid($uuid);\n\n if (! $automatedReport) {\n throw new ModelNotFoundException('Report not found');\n }\n\n return $automatedReport;\n }\n\n public function get(string $uuid): array\n {\n $automatedReport = $this->getReport($uuid);\n\n return $this->transformReportFullView($automatedReport);\n }\n\n public function list(string $sortColumn = 'created_at', string $sortDirection = 'desc'): array\n {\n $results = [];\n $collection = $this->automatedReportsRepository->getAllStandardReports($sortColumn, $sortDirection);\n\n /** @var AutomatedReport $report */\n foreach ($collection as $report) {\n $results[] = $this->transformReportFullView($report);\n }\n\n return ['data' => $results];\n }\n\n public function listAskJiminnyReports(\n User $user,\n string $sortColumn = 'created_at',\n string $sortDirection = 'desc'\n ): array {\n $results = [];\n $collection = $this->automatedReportsRepository->getAskJiminnyReportsByUser($user, $sortColumn, $sortDirection);\n\n /** @var AutomatedReport $report */\n foreach ($collection as $report) {\n $results[] = $this->transformReportFullView($report);\n }\n\n return ['data' => $results];\n }\n\n public function delete(string $uuid): void\n {\n $automatedReport = $this->automatedReportsRepository->findByUuid($uuid);\n\n if (! $automatedReport) {\n throw new ModelNotFoundException('Report not found');\n }\n\n $automatedReport->delete();\n }\n\n public function createReportResult(AutomatedReport $automatedReport, array $data = []): AutomatedReportResult\n {\n return $this->automatedReportsRepository->createResult(\n array_merge(\n [\n 'report_id' => $automatedReport->getId(),\n 'status' => AutomatedReportResult::STATUS_DEFAULT,\n ],\n $data\n )\n );\n }\n\n public function getReportResult(string $resultUuid): AutomatedReportResult\n {\n $report = $this->automatedReportsRepository->findResultByUuid($resultUuid);\n\n if (! $report) {\n throw new ModelNotFoundException('Report Result not found');\n }\n\n return $report;\n }\n\n public function findChildResult(AutomatedReportResult $result, string $type): ?AutomatedReportResult\n {\n return $this->automatedReportsRepository->findChildResult($result, $type);\n }\n\n // prophet API calls\n /**\n * @throws ApplicationException\n */\n public function getGenerateReportPayload(AutomatedReport $automatedReport, string $reportResultUuid): array\n {\n $period = $this->calculateFromAndToDate($automatedReport);\n $fromDate = $period['fromDate'];\n $toDate = $period['toDate'];\n\n return [\n 'team_id' => $automatedReport->getTeamId(),\n 'request_id' => $reportResultUuid,\n 'report_type' => $automatedReport->getType(),\n 'media_types' => $automatedReport->getMediaTypes(),\n 'from_date' => $fromDate->startOfDay()->format(DateTimeInterface::RFC3339),\n 'to_date' => $toDate->endOfDay()->format(DateTimeInterface::RFC3339),\n 'group_ids' => $automatedReport->getGroups(),\n 'call_deal_stage' => $automatedReport->getDealAtCallStages(),\n 'current_deal_stage' => $automatedReport->getCurrentDealStages(),\n 'deal_min_value' => $automatedReport->getDealValueMin(),\n 'deal_max_value' => $automatedReport->getDealValueMax(),\n 'call_types' => $automatedReport->getCallTypes(),\n 'call_duration_min_seconds' => $automatedReport->getCallDurationMin(),\n 'call_duration_max_seconds' => $automatedReport->getCallDurationMax(),\n 'special_requirements' => $automatedReport->getAdditionalPromptInput(),\n 'callback_url' => $this->getCallbackUrl(),\n 'report_period' => $this->formatReportPeriodName(\n $automatedReport->getFrequency(),\n $fromDate,\n $toDate,\n ),\n 'playbook_categories' => $automatedReport->getPlaybookCategories(),\n 'custom_name' => $automatedReport->getCustomName(),\n ];\n }\n\n // $inputPayload - FE payload structure\n public function getActivitiesCountPayload(array $inputPayload): array\n {\n // Use validateAndTransformData to validate and normalize input\n $validatedData = $this->validateAndTransformData($inputPayload);\n $period = $this->calculateFromAndToDatePeriod(\n $validatedData['frequency'],\n Carbon::parse($validatedData['from']),\n Carbon::parse($validatedData['to']),\n );\n $fromDate = $period['fromDate'];\n $toDate = $period['toDate'];\n\n // Create payload similar to getGenerateReportPayload\n return [\n 'team_id' => $validatedData['team_id'],\n 'group_ids' => $validatedData['groups'] ?? [],\n 'report_type' => $validatedData['type'],\n 'from_date' => $fromDate->format(DateTimeInterface::RFC3339),\n 'to_date' => $toDate->format(DateTimeInterface::RFC3339),\n 'call_deal_stage' => $validatedData['deal_at_call_stages'] ?? [],\n 'current_deal_stage' => $validatedData['current_deal_stages'] ?? [],\n 'deal_min_value' => $validatedData['deal_value_min'] ?? null,\n 'deal_max_value' => $validatedData['deal_value_max'] ?? null,\n 'call_types' => $validatedData['call_types'],\n 'call_duration_min_seconds' => $validatedData['call_duration_min'] ?? null,\n 'call_duration_max_seconds' => $validatedData['call_duration_max'] ?? null,\n 'special_requirements' => $validatedData['additional_prompt_input'] ?? null,\n 'playbook_categories' => $validatedData['playbook_categories'] ?? [],\n 'request_id' => null,\n 'callback_url' => null,\n ];\n }\n\n public function shouldSendReport(array $users, ?CarbonInterface $generatedAt = null): bool\n {\n if (empty($users)) {\n return false;\n }\n\n $earliestTz = collect($users)\n ->mapWithKeys(function (array $user) {\n $tz = new DateTimeZone($user['timezone']);\n $nowUtc = new DateTime('now', new DateTimeZone('UTC'));\n $offset = $tz->getOffset($nowUtc);\n\n return [$user['timezone'] => $offset];\n })\n ->sortDesc()\n ->keys()\n ->first();\n\n $now = Carbon::now($earliestTz);\n $isScheduledTime = (int) $now->format('H') === self::SENT_REPORT_AT_HOURS;\n\n if ($isScheduledTime) {\n return true;\n }\n\n return $this->hasPassedScheduledTime($generatedAt, $earliestTz);\n }\n\n public function hasPassedScheduledTime(?CarbonInterface $generatedAt, string $timezone): bool\n {\n if ($generatedAt === null) {\n return false;\n }\n\n $now = Carbon::now($timezone);\n $scheduledTime = $now->copy()->setTime(self::SENT_REPORT_AT_HOURS, 0, 0);\n\n if ($now->hour < self::SENT_REPORT_AT_HOURS) {\n $scheduledTime = $scheduledTime->subDay();\n }\n\n $scheduledTimeUtc = $scheduledTime->copy()->utc();\n $generatedAtUtc = $generatedAt->copy()->utc();\n $nowUtc = $now->copy()->utc();\n\n return $generatedAtUtc->lt($scheduledTimeUtc) && $nowUtc->gt($scheduledTimeUtc);\n }\n\n public function calculateFromAndToDatePeriod(\n string $frequency,\n ?Carbon $fromDate = null,\n ?Carbon $toDate = null\n ): array {\n if ($frequency === self::FREQUENCY_ONE_OFF) {\n return [\n 'fromDate' => $fromDate,\n 'toDate' => $toDate,\n ];\n }\n\n $now = Carbon::now();\n\n return match ($frequency) {\n self::FREQUENCY_DAILY => [\n 'fromDate' => $now->copy()->subDay()->startOfDay(),\n 'toDate' => $now->copy()->subDay()->endOfDay(),\n ],\n self::FREQUENCY_WEEKLY => [\n 'fromDate' => $now->copy()->subWeeks(1)->startOfDay(),\n 'toDate' => $now->copy()->subDay()->endOfDay(),\n ],\n self::FREQUENCY_MONTHLY => [\n 'fromDate' => $now->copy()->subMonths(1)->startOfDay(),\n 'toDate' => $now->copy()->subDay()->endOfDay(),\n ],\n self::FREQUENCY_QUARTERLY => [\n 'fromDate' => $now->copy()->subMonths(3)->startOfDay(),\n 'toDate' => $now->copy()->subDay()->endOfDay(),\n ],\n default => throw new InvalidArgumentException(\"Unsupported frequency: {$frequency}\"),\n };\n }\n\n private function calculateFromAndToDate(AutomatedReport $automatedReport): array\n {\n return $this->calculateFromAndToDatePeriod(\n $automatedReport->getFrequency(),\n $automatedReport->getFrom(),\n $automatedReport->getTo()\n );\n }\n\n public function getAskJiminnyGenerateReportPayload(\n AutomatedReport $automatedReport,\n AutomatedReportResult $reportResult,\n array $activityIds,\n ): array {\n return [\n 'user_question' => $automatedReport->getAskAnythingPrompt()?->getContent(),\n 'call_ids' => array_map('strval', $activityIds),\n 'team_id' => $automatedReport->getTeamId(),\n 'request_id' => $reportResult->getUuid(),\n 'callback_url' => $this->getCallbackUrl(),\n 'report_period' => $this->getReportPeriodName($reportResult),\n 'report_name' => $automatedReport->getCustomName(),\n ];\n }\n\n private function getCallbackUrl(): string\n {\n return $this->webhookService->route('jiminny.webhook.reports.ready');\n }\n\n /**\n * Validate and transform payload data for automated reports\n *\n * @param array $data\n *\n * @throws InvalidArgumentException\n *\n * @return array\n */\n private function validateAndTransformData(array $data): array\n {\n // Validate organization (team) and check feature\n $team = $this->validateOrganization($data['organization'] ?? null);\n\n $status = $this->validateReportStatus($data['report_enabled'] ?? null);\n $type = $this->validateReportType($data['report_type'] ?? null);\n $frequency = $this->validateFrequency($data['frequency'] ?? null);\n $additionalPromptInput = $this->validateAdditionalPromptInput(\n $data['additional_prompt_input'] ?? null\n );\n $customReportName = $this->validateCustomReportName($data['custom_name'] ?? null);\n\n // Prepare data for the database\n $reportData = [\n 'team_id' => $team->getId(),\n 'type' => $type,\n 'status' => $status,\n 'frequency' => $frequency,\n 'additional_prompt_input' => $additionalPromptInput,\n 'custom_name' => $customReportName,\n ];\n\n // Validate deal values\n $reportData = $this->validateDealValues($data, $reportData);\n\n // Validate date range\n $reportData = $this->validateDateRange($data, $reportData, $frequency);\n\n // Validate call durations\n $reportData = $this->validateCallDurations($data, $reportData);\n\n // Validate call types\n $reportData = $this->validateCallTypes($data, $reportData);\n\n // Validate media types\n $reportData = $this->validateMediaTypes($data, $reportData);\n\n // Validate groups\n if (isset($data['teams'])) {\n $reportData['groups'] = $this->validateAndGetGroupIds($team, $data['teams']);\n }\n\n // Validate deal stages\n $reportData = $this->validateDealStages($data, $reportData, $team, $type);\n\n // Validate playbook categories\n $reportData = $this->validatePlaybookCategories($data, $reportData, $team);\n\n // Validate recipients\n $reportData['recipients'] = [\n 'users' => $this->validateAndGetUserIdsByTeam($team, $data['recipients'] ?? []),\n ];\n\n if (isset($data['jiminny_recipients'])) {\n // Validate Jiminny recipients\n $reportData['jiminny_recipients'] = [\n 'users' => $this->validateAndGetJiminnyUserIds((array) $data['jiminny_recipients']),\n ];\n }\n\n return $reportData;\n }\n\n private function validateDealValues(array $data, array $reportData): array\n {\n if (isset($data['min_deal_value'])) {\n $reportData['deal_value_min'] = (int) $data['min_deal_value'];\n\n if ($reportData['deal_value_min'] > 4294967295 || $reportData['deal_value_min'] < 0) {\n throw new InvalidArgumentException('Min deal value should be between 0 and 4294967295');\n }\n }\n\n if (isset($data['max_deal_value'])) {\n $reportData['deal_value_max'] = (int) $data['max_deal_value'];\n\n if ($reportData['deal_value_max'] > 4294967295 || $reportData['deal_value_max'] < 0) {\n throw new InvalidArgumentException('Max deal value should be between 0 and 4294967295');\n }\n }\n\n if (isset($data['min_deal_value'], $data['max_deal_value'])\n && $data['min_deal_value'] > $data['max_deal_value']\n ) {\n throw new InvalidArgumentException('Min deal value cannot be greater than max deal value');\n }\n\n return $reportData;\n }\n\n private function validateDateRange(array $data, array $reportData, string $frequency): array\n {\n // Set date range only for one_off frequency\n if ($frequency === 'one_off') {\n if (isset($data['start_date_period'])) {\n $reportData['from'] = $this->parseDate($data['start_date_period']);\n }\n\n if (isset($data['end_date_period'])) {\n $reportData['to'] = $this->parseDate($data['end_date_period']);\n }\n\n if (empty($reportData['from']) || empty($reportData['to'])) {\n throw new InvalidArgumentException(\n 'Start date and end date are required for one_off frequency'\n );\n }\n } else {\n $reportData['from'] = null;\n $reportData['to'] = null;\n }\n\n return $reportData;\n }\n\n private function validateCallDurations(array $data, array $reportData): array\n {\n // Convert call durations from minutes to seconds\n if (isset($data['min_call_duration'])) {\n $reportData['call_duration_min'] = (int) $data['min_call_duration'] * 60;\n\n if ($reportData['call_duration_min'] > 4294967295 || $reportData['call_duration_min'] < 0) {\n throw new InvalidArgumentException('Min call duration should be between 0 and 4294967295');\n }\n }\n\n if (isset($data['max_call_duration'])) {\n $reportData['call_duration_max'] = (int) $data['max_call_duration'] * 60;\n\n if ($reportData['call_duration_max'] > 4294967295 || $reportData['call_duration_max'] < 0) {\n throw new InvalidArgumentException('Max call duration should be between 0 and 4294967295');\n }\n }\n\n return $reportData;\n }\n\n private function validateCallTypes(array $data, array $reportData): array\n {\n // Set call types\n $reportData['call_types'] = $data['call_type'] ?? [];\n if (empty($reportData['call_types'])) {\n $reportData['call_types'] = self::getCallTypes();\n }\n\n foreach ($reportData['call_types'] as $callType) {\n if (! in_array($callType, self::getCallTypes(), true)) {\n throw new InvalidArgumentException(sprintf('Call type %s is invalid', $callType));\n }\n }\n\n return $reportData;\n }\n\n private function validateMediaTypes(array $data, array $reportData): array\n {\n // Set media types from input data\n $reportData['media_types'] = $data['media_types'] ?? [];\n\n if (empty($reportData['media_types'])) {\n throw new InvalidArgumentException('Media types are required');\n }\n\n foreach ($reportData['media_types'] as $mediaType) {\n if (! in_array($mediaType, self::MEDIA_TYPES, true)) {\n throw new InvalidArgumentException(sprintf('Media type %s is invalid', $mediaType));\n }\n }\n\n return $reportData;\n }\n\n private function validateDealStages(array $data, array $reportData, Team $team, string $reportType): array\n {\n // Validate and set deal stages\n if (isset($data['deal_stage_at_call'])) {\n $reportData['deal_at_call_stages'] =\n $this->validateAndGetDealStageIds($team, $data['deal_stage_at_call'], 'Deal stage at call');\n }\n\n if (isset($data['current_deal_stage'])) {\n $reportData['current_deal_stages'] =\n $this->validateAndGetDealStageIds($team, $data['current_deal_stage'], 'Current deal stage');\n }\n\n // Ensure current_deal_stage is not provided for loss_analysis report type\n if ($reportType === self::TYPE_LOSS_ANALYSIS && ! empty($data['current_deal_stage'])) {\n throw new InvalidArgumentException('Current deal stage is not applicable for Loss Analysis reports');\n }\n\n return $reportData;\n }\n\n // transform uuid to id\n private function validatePlaybookCategories(array $data, array $reportData, Team $team): array\n {\n $key = 'playbook_categories';\n\n if (isset($data[$key])) {\n $payloadIds = $data[$key];\n $ids = [];\n\n foreach ($payloadIds as $uuid) {\n $uuid = (string) $uuid;\n\n try {\n $playbookCategory = $this->playbookCategoryRepository->findByUuid($uuid);\n } catch (Throwable $throwable) {\n Log::error(__METHOD__ . ' ' . $throwable->getMessage());\n\n throw new InvalidArgumentException(sprintf('Playbook category %s not found', $uuid));\n }\n\n if (! $playbookCategory) {\n throw new InvalidArgumentException(sprintf('Playbook category %s not found', $uuid));\n }\n\n if (! $playbookCategory->hasPlaybook()) {\n throw new InvalidArgumentException(sprintf('Playbook category %s has no playbook', $uuid));\n }\n\n if ($playbookCategory->getPlaybook()->getTeamId() !== $team->getId()) {\n throw new InvalidArgumentException(\n sprintf('Playbook category %s not found for team %s', $uuid, $team->getUuid())\n );\n }\n\n $ids[] = $playbookCategory->getId();\n }\n\n $reportData[$key] = $ids;\n }\n\n return $reportData;\n }\n\n private function validateReportStatus($status): bool\n {\n if (! in_array($status, [true, false], true)) {\n throw new InvalidArgumentException('Report status is invalid');\n }\n\n return $status;\n }\n\n private function validateReportType($type): string\n {\n if (! in_array($type, self::getTypes(), true)) {\n throw new InvalidArgumentException(sprintf('Report type is invalid: %s', $type));\n }\n\n return $type;\n }\n\n private function validateFrequency($frequency): string\n {\n if (! in_array($frequency, self::getFrequencies(), true)) {\n throw new InvalidArgumentException('Frequency is invalid');\n }\n\n return $frequency;\n }\n\n private function validateAdditionalPromptInput(?string $additionalPromptInput): ?string\n {\n if ($additionalPromptInput && strlen($additionalPromptInput) > 5000) {\n throw new InvalidArgumentException('Additional Prompt Input should be less than 5000 characters');\n }\n\n return $additionalPromptInput;\n }\n\n private function validateCustomReportName(?string $customReportName): ?string\n {\n if ($customReportName === null || $customReportName === '') {\n return null;\n }\n\n if (strlen($customReportName) > 70) {\n throw new InvalidArgumentException('Custom report name should be less than 70 characters');\n }\n\n return $customReportName;\n }\n\n private function validateOrganization(?string $organizationUuid): Team\n {\n if (! $organizationUuid) {\n throw new InvalidArgumentException('Organization is required');\n }\n\n $team = $this->teamRepository->idOrUuid($organizationUuid);\n\n if (! $team) {\n throw new InvalidArgumentException('Organization not found');\n }\n\n if (! $team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {\n throw new InvalidArgumentException('Organization does not have the Automated Reports feature');\n }\n\n return $team;\n }\n\n private function validateAndGetGroupIds(Team $team, array $teamUuids): array\n {\n $groupIds = [];\n\n foreach ($teamUuids as $uuid) {\n $group = $this->groupRepository->findByUuid($uuid);\n\n if ($group === null || $group->getTeamId() !== $team->getId()) {\n throw new InvalidArgumentException(\n sprintf('Group %s not found for team %s', $uuid, $team->getUuid())\n );\n }\n\n $groupIds[] = $group->getId();\n\n }\n\n return $groupIds;\n }\n\n private function validateAndGetDealStageIds(Team $team, array $stageUuids, string $propertyLabel): array\n {\n $stageIds = [];\n\n foreach ($stageUuids as $uuid) {\n $stage = $this->stageRepository->findByUuid($uuid);\n\n if ($stage === null || $stage->getTeamId() !== $team->getId()) {\n throw new InvalidArgumentException(\n sprintf('Stage %s not found for team %s for %s', $uuid, $team->getUuid(), $propertyLabel)\n );\n }\n\n $stageIds[] = $stage->getId();\n }\n\n return $stageIds;\n }\n\n private function validateAndGetUserIds(array $userUuids, callable $teamCheck): array\n {\n if (empty($userUuids)) {\n return [];\n }\n\n $userIds = [];\n\n foreach ($userUuids as $uuid) {\n $user = $this->userRepository->findByUuid($uuid);\n\n if (! $user || ! $user->isStatusActive()) {\n throw new InvalidArgumentException(\n sprintf('User %s not found or is not active', $uuid)\n );\n }\n\n if (! $teamCheck($user)) {\n throw new InvalidArgumentException(\n sprintf('User %s does not belong to the allowed team(s)', $uuid)\n );\n }\n\n $userIds[] = $user->getId();\n }\n\n return $userIds;\n }\n\n private function validateAndGetUserIdsByTeam(Team $team, array $userUuids): array\n {\n return $this->validateAndGetUserIds($userUuids, fn ($user) => $user->getTeamId() === $team->getId());\n }\n\n private function validateAndGetJiminnyUserIds(array $userUuids): array\n {\n $allowedTeamIds = config('kiosk.teamIds', []);\n\n return $this->validateAndGetUserIds($userUuids, fn ($user) => in_array($user->getTeamId(), $allowedTeamIds, true));\n }\n\n private function parseDate(string $dateString): string\n {\n return date('Y-m-d H:i:s', strtotime($dateString));\n }\n\n private function generateReportResultViewUrl(AutomatedReportResult $result): string\n {\n $mediaResource = $this->getReportMediaRouteResource($result);\n\n return route('ai-reports.' . $mediaResource . '.view', ['uuid' => $result->getUuid()]);\n }\n\n private function generateReportResultDownloadUrl(AutomatedReportResult $result): string\n {\n $mediaResource = $this->getReportMediaRouteResource($result);\n\n return route('ai-reports.' . $mediaResource . '.download', ['uuid' => $result->getUuid()]);\n }\n\n private function getReportMediaRouteResource(AutomatedReportResult $result): string\n {\n if ($result->getMediaType() === self::MEDIA_TYPE_PDF) {\n return self::PDF_KEY;\n } elseif ($result->getMediaType() === self::MEDIA_TYPE_PODCAST) {\n return self::AUDIO_KEY;\n }\n\n throw new \\InvalidArgumentException('Unknown media type.');\n }\n\n public function getMediaPath(AutomatedReportResult $result): ?string\n {\n $url = match ($result->getMediaType()) {\n self::MEDIA_TYPE_PDF => $result->getPdfUrl(),\n self::MEDIA_TYPE_PODCAST => $result->getPodcastAudioUrl(),\n default => null,\n };\n\n if ($url === null) {\n return null;\n }\n\n $path = parse_url(trim($url, '\"\\''), PHP_URL_PATH);\n\n return $path ?: null;\n }\n\n public function getFilenameSuffix(AutomatedReportResult $result): ?string\n {\n return match ($result->getMediaType()) {\n self::MEDIA_TYPE_PODCAST => 'Podcast',\n default => null,\n };\n }\n\n public function getMailSubjectSuffix(AutomatedReportResult $result): string\n {\n return match ($result->getMediaType()) {\n self::MEDIA_TYPE_PDF => 'report',\n self::MEDIA_TYPE_PODCAST => 'podcast',\n default => '',\n };\n }\n\n public function getMediaTypeMetadata(AutomatedReportResult $result): array\n {\n return match ($result->getMediaType()) {\n self::MEDIA_TYPE_PODCAST => ['extension' => 'mp3', 'mime' => 'audio/mpeg'],\n self::MEDIA_TYPE_PDF => ['extension' => 'pdf', 'mime' => 'application/pdf'],\n default => ['extension' => null, 'mime' => null],\n };\n }\n\n public function deleteS3Files(AutomatedReportResult $result): void\n {\n $teamUuid = $result->getReport()->getTeam()->getUuid();\n $reportUuid = $result->getUuid();\n\n // delete all files for a report uuid no mather of pdf, podcast, or both\n // in case of both - the podcast files are linked to the pdf (parent) uuid\n // pdf and podcast date times should be close\n $path = sprintf('%s/%s/%s', $teamUuid, self::S3_DIR, $reportUuid);\n\n foreach (self::FILE_EXTENSIONS_VARIANTS as $extension) {\n $file = $path . '.' . $extension;\n\n if (Storage::exists($file)) {\n Storage::delete($file);\n Log::info('[Reports] Deleted S3 file', [\n 'path' => $file,\n ]);\n }\n }\n\n foreach (self::FILE_PODCAST_EXTENSIONS_VARIANTS as $extension) {\n $file = $path . '_podcast.' . $extension;\n\n if (Storage::exists($file)) {\n Storage::delete($file);\n Log::info('[Reports] Deleted Podcast S3 file', [\n 'path' => $file,\n ]);\n }\n }\n }\n\n /**\n *\n * @param int|null $teamId Optional team ID to filter results\n *\n * @return Collection<int, int> Collection of team IDs\n */\n public function getTeamIdsWithReportsResults(?int $teamId = null): Collection\n {\n return $this->automatedReportsRepository->getTeamIdsWithReportsResults($teamId);\n }\n\n /**\n * Core delete logic for report results using a query\n *\n * @param Builder $query\n * @param array $logContext\n *\n * @return int\n */\n private function deleteReportResultsByQuery(Builder $query, array $logContext = []): int\n {\n $deletedCount = 0;\n\n if ($query->exists()) {\n Log::info(\n 'Run delete report results',\n array_merge(\n $logContext,\n [\n 'service' => 'AutomatedReportsService',\n ]\n )\n );\n\n $query->chunkById(50, function ($results) use (&$deletedCount, $logContext) {\n foreach ($results as $result) {\n $this->deleteReportResult($result);\n $deletedCount++;\n\n Log::info(\n 'Deleted a report result',\n array_merge(\n $logContext,\n [\n 'result_id' => $result->getId(),\n 'report_id' => $result->getReportId(),\n ]\n )\n );\n }\n });\n }\n\n return $deletedCount;\n }\n\n /**\n * Delete report results for a team by retention period\n *\n * @param Team $team\n * @param CarbonImmutable $retentionDate\n *\n * @return int Number of deleted report results\n */\n public function deleteReportsResultsInRetentionPeriod(Team $team, CarbonImmutable $retentionDate): int\n {\n $reportIds = $this->automatedReportsRepository->getReportIdsByTeam($team);\n\n if ($reportIds->isEmpty()) {\n return 0;\n }\n\n $query = $this->automatedReportsRepository\n ->getReportResultsQueryForRetention($team, $retentionDate);\n\n return $this->deleteReportResultsByQuery($query, [\n 'team_id' => $team->getId(),\n 'retention_date' => $retentionDate->toDateTimeString(),\n ]);\n }\n\n /**\n * Delete ALL report results for a specific automated report\n *\n * @param string $uuid\n *\n * @return int\n */\n public function deleteReportResults(string $uuid): int\n {\n $report = $this->getReport($uuid);\n\n $query = $this->automatedReportsRepository->getResultsByReportQuery($report);\n\n return $this->deleteReportResultsByQuery($query, [\n 'report_uuid' => $uuid,\n 'report_id' => $report->getId(),\n ]);\n }\n\n public function deleteReportResult(AutomatedReportResult $result): void\n {\n $this->deleteS3Files($result);\n\n $result->delete();\n }\n\n /**\n * Get all reports for a specific team\n *\n * @param Team $team\n *\n * @return \\Illuminate\\Database\\Eloquent\\Collection\n */\n public function getTeamReports(Team $team): \\Illuminate\\Database\\Eloquent\\Collection\n {\n return $this->automatedReportsRepository->getReportsByTeam($team);\n }\n\n /**\n * Get all report results for a specific report\n *\n * @param AutomatedReport $report\n *\n * @return \\Illuminate\\Database\\Eloquent\\Collection\n */\n public function getReportResults(AutomatedReport $report): \\Illuminate\\Database\\Eloquent\\Collection\n {\n return $this->automatedReportsRepository->getResultsByReport($report);\n }\n\n public function deleteAllReportResults(AutomatedReport $report): void\n {\n $results = $this->getReportResults($report);\n\n /** @var AutomatedReportResult $result */\n foreach ($results as $result) {\n Log::info('Deleting result', [\n 'report' => $report->getId(),\n 'result' => $result->getId(),\n ]);\n\n $this->deleteReportResult($result);\n }\n }\n\n public function deleteAllData(Team $team): void\n {\n Log::info('Deleting automated report and results for team', [\n 'team' => $team->getId(),\n ]);\n\n $reports = $this->getTeamReports($team);\n\n /** @var AutomatedReport $report */\n foreach ($reports as $report) {\n Log::info('Deleting report', [\n 'team' => $team->getId(),\n 'report' => $report->getId(),\n ]);\n\n $this->deleteAllReportResults($report);\n\n $report->delete();\n }\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":true,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"Project","depth":3,"role_description":"text"},{"role":"AXButton","text":"Project","depth":3,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"New File or Directory…","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Expand Selected","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Collapse All","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Options","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false}]...
|
3397592283435315795
|
6686367547760219213
|
idle
|
accessibility
|
NULL
|
Project: faVsco.js, menu
#11894 on JY-18909-automa Project: faVsco.js, menu
#11894 on JY-18909-automated-reports-ask-jiminny, menu
Start Listening for PHP Debug Connections
AutomatedReportsCommandTest
Run 'AutomatedReportsCommandTest'
Debug 'AutomatedReportsCommandTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Execute
Explain Plan
Browse Query History
View Parameters
Open Query Execution Settings…
In-Editor Results
Tx: Auto
Cancel Running Statements
Playground
jiminny
Sync Changes
Hide This Notification
Code changed:
Hide
16
13
13
Previous Highlighted Error
Next Highlighted Error
SELECT * FROM teams WHERE id = 1;
select * from crm_layouts where crm_configuration_id = 39;
SELECT * FROM crm_layout_entities WHERE crm_layout_id = 283;
SELECT * FROM crm_fields WHERE id = 2234;
SELECT * FROM crm_field_values WHERE crm_field_id = 2234;
select * from crm_profiles where user_id = 143;
select * from record_types where crm_configuration_id = 39; # 0121K000001MHElQAO,0121K000001MHEqQAO
select * from business_processes where crm_configuration_id = 39;
# 01941000000H669AAC, 01941000000H66JAAS
select * from record_type_field_values
where record_type_id IN (24);
select * from crm_field_values where id IN (2730);
select * from crm_configurations where id = 39;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 1
and sa.provider = 'salesforce'; #1035
select * from users where team_id = 1; # 222 group 3
SELECT * FROM activities WHERE user_id = 222 order by id desc;
select * from sidekick_settings where team_id = 1;
select * from teams where id = 1;
select * from team_features where team_id = 1;
select * from activities where crm_configuration_id = 2
and provider = 'ms-teams' and id = 608765;
SELECT * FROM activities WHERE crm_configuration_id = 2 and crm_provider_id = '59523413338';
select * from sidekick_settings where team_id = 2;
SELECT * FROM activities WHERE id = 608660;
select * from activity_summary_logs where activity_id = 608660;
select * from ai_prompts where transcription_id = 11214;
# [PASSWORD_DOTS]
SELECT * FROM activities WHERE uuid_to_bin('ed78a437-2804-450e-ab2f-56ab1c641346') = uuid;
# id: 608818, crm: 59628809737
SELECT * FROM activities WHERE uuid_to_bin('36b06e55-afdd-4782-8dee-c624cd0af191') = uuid;
# id: 608821, crm: 59632069252
SELECT ce.start_time, ce.end_time, a.id, a.uuid, crm_provider_id, calendar_event_id, title,
playbook_category_id, user_id, lead_id, contact_id, account_id, opportunity_id,
scheduled_start_time, scheduled_end_time, actual_start_time, actual_end_time, a.created_at
FROM activities a
join calendar_events ce on a.calendar_event_id = ce.id
WHERE a.id IN (608818, 608821);
select * from users where team_id = 1;
select * from team_settings where team_id = 1;
select * from crm_profiles where crm_configuration_id = 39 order by user_id;
select * from team_features where team_id = 1;
select * from users where team_id = 2;
SELECT * FROM activities WHERE uuid_to_bin('ec7647e9-5225-458b-b475-f31aa2769204') = uuid; # 612639
# Preslava N. Ivanova, grou id 3
SELECT * FROM opportunities WHERE uuid_to_bin('a2928fe5-aec5-46cb-85d9-7654c89e46a6') = uuid;
select * from activities where opportunity_id = 344 and actual_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00';
select
a.id,
a.type,
a.scheduled_start_time,
a.actual_start_time,
a.created_at,
a.opportunity_id,
a.status
FROM activities a
WHERE opportunity_id = 344
and status IN ('completed', 'received', 'delivered')
and (
(a.actual_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00')
OR (a.created_at between '2024-10-11 00:00:00' and '2024-10-12 00:00:00')
OR (a.scheduled_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00'))
;
SELECT * FROM users WHERE id = 222;
SELECT * FROM crm_profiles WHERE user_id = 222;
select * from crm_layouts where crm_configuration_id = 39;
SELECT * FROM crm_layout_entities WHERE crm_layout_id = 281;
select * from group_deal_risk_types;
select * from opportunities where team_id = 1;
SELECT * FROM opportunities WHERE id = 315;
SELECT * FROM crm_field_data WHERE object_id = 315;
select * from crm_field_data where object_id = 260;
select * from generic_ai_prompts where subject_id = 315;
select * from teams; # 36, 21, 121, [EMAIL]
SELECT * FROM social_accounts WHERE sociable_id = 121 and provider = 'bullhorn';
# [PASSWORD_DOTS]
select * from teams where id = 1;
select * from crm_configurations where id = 39;
select * from users where team_id = 1;
select u.email, cp.* from users u
join crm_profiles cp on u.id = cp.user_id
where u.team_id = 1;
# 1 - 00541000004281rAAA
# 204 - 0052g000003freeAAA
# 429 - 0052g000003qGOiAAM
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 1
and sa.provider = 'salesforce';
select * from activities where type = 'softphone'
and created_at > '2024-12-11 15:24:36' order by id desc;
select * from activity_providers where team_id = 1;
select * from activity_provider_users where activity_provider_id = 328;
select * from opportunities where crm_configuration_id = 39
AND account_id = 178 AND is_closed = false
order by created_at DESC;
select * from contacts where id = 3952;
select * from accounts where id = 178;
# [PASSWORD_DOTS]
select * from teams where id = 36;
select * from crm_configurations where id = 21;
select * from users where team_id = 36;
select u.email, cp.* from users u
join crm_profiles cp on u.id = cp.user_id
where u.team_id = 36;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 36
and sa.provider = 'bullhorn';
select * from social_accounts where id = 348;
UPDATE social_accounts SET
provider_user_token = '21442_6802599_91:41179a58-21e7-4d7c-ad58-56bb666b2f65',
provider_refresh_token = '21442_6802599_91:01c6b335-3f2a-42e4-85ff-8a08fa65fceb',
expires = 1733998131,
state = 'connected'
WHERE id = 348;
# [PASSWORD_DOTS]
select * from teams where id = 31;
select * from crm_configurations where id = 18;
select * from users where team_id = 31; # 257
select u.email, cp.* from users u
join crm_profiles cp on u.id = cp.user_id
where u.team_id = 31;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 31
and sa.provider = 'close';
select * from contacts where crm_configuration_id = 18;
# [PASSWORD_DOTS] NEPTUNE [PASSWORD_DOTS]
select * from teams;
select * from users where id IN (1030, 1035, 1052);
select * from crm_configurations;
select * from users where team_id = 65; # 257
select * from team_settings where team_id = 65; # 257
select * from invitations where team_id = 65; # 257
select * from users where email = '[EMAIL]'; # 257
select u.email, cp.* from users u
join crm_profiles cp on u.id = cp.user_id
where u.team_id = 65;
select * from crm_configurations where id = 53;
select * from accounts where crm_configuration_id = 53 order by id desc;
select * from leads where crm_configuration_id = 53 order by id desc;
select * from contacts where crm_configuration_id = 53 order by id desc;
select * from opportunities where crm_configuration_id = 53 order by id desc;
select * from crm_profiles where crm_configuration_id = 53 order by id desc;
select * from crm_fields where crm_configuration_id = 53 order by id desc;
select * from crm_field_values where crm_field_id = 3341 order by id desc;
select * from crm_layouts where crm_configuration_id = 53 order by id desc;
select * from stages where crm_configuration_id = 53 order by id desc;
select * from crm_profiles where crm_configuration_id = 13;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 65
and sa.provider = 'integration-app';
select * from contacts where crm_configuration_id = 13;
select * from social_accounts where sociable_id = 283;
SELECT * FROM opportunities WHERE crm_provider_id = '006O400000E9bzeIAB';
select * from activity_providers where team_id = 65;
SELECT * FROM activities WHERE crm_configuration_id IN (51, 52, 53);
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 65
;
# [PASSWORD_DOTS] STAGING [PASSWORD_DOTS]
SELECT * FROM teams;
SELECT * FROM teams WHERE id = 88;
SELECT * FROM teams WHERE id = 89;
select * from team_settings where team_id = 89;
SELECT * FROM users WHERE team_id = 89;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 89;
select * from users;
SELECT * FROM social_accounts WHERE sociable_id = 1761;
SELECT * FROM crm_configurations WHERE id = 70;
select * from accounts where crm_configuration_id = 70 order by id desc;
select * from leads where crm_configuration_id = 70 order by id desc;
select * from contacts where crm_configuration_id = 70 order by id desc;
select * from opportunities where crm_configuration_id = 70 order by id desc;
select * from crm_profiles where crm_configuration_id = 70 order by id desc;
select * from crm_fields where crm_configuration_id = 70 order by id desc;
select * from crm_field_values where crm_field_id = 3536 order by id desc;
select * from crm_layouts where crm_configuration_id = 70 order by id desc;
select * from stages where crm_configuration_id = 70 order by id desc;
select * from business_processes where crm_configuration_id = 70 order by id desc;
select * from business_process_stages where business_process_id = 34;
select * from contacts where id = 10468;
select * from crm_layouts where crm_configuration_id = 70;
SELECT * FROM crm_layout_entities WHERE crm_layout_id = 388;
SELECT * FROM crm_fields WHERE id IN (3533,3534,3535);
select * from activities where crm_configuration_id = 70
and (account_id IS NOT NULL or lead_id IS NOT NULL or contact_id IS NOT NULL or opportunity_id IS NOT NULL) order by id desc;
SELECT * FROM activities WHERE uuid_to_bin('2e10b60f-8a61-41c5-a3d4-28835353dc65') = uuid;
SELECT * FROM activities where crm_configuration_id = 69 ;
SELECT * FROM users WHERE email LIKE '%[EMAIL]%';
SELECT * FROM activities WHERE uuid_to_bin('5a150c93-40fc-42ec-b3bd-c1d328e09f6e') = uuid;
SELECT * FROM opportunities WHERE id = 385;
select * from participants p
join activities a on p.activity_id = a.id
where a.crm_configuration_id = 70
and (p.lead_id IS NOT NULL or p.contact_id IS NOT NULL);
SELECT * FROM participants WHERE id = 1013638;
select * from teams where id = 90;
select * from users where team_id = 90;
select * from social_accounts where social_accounts.sociable_id IN (1960,1760);
SELECT * FROM crm_profiles WHERE crm_configuration_id = 71;
select * from invitations where team_id = 90;
select * from crm_configurations where id = 71;
select * from accounts where crm_configuration_id = 71 order by id desc;
select * from leads where crm_configuration_id = 71 order by id desc;
select * from contacts where crm_configuration_id = 71 order by id desc;
select * from opportunities where crm_configuration_id = 71 order by id desc;
select * from crm_profiles where crm_configuration_id = 71 order by id desc;
select * from crm_fields where crm_configuration_id = 71 order by id desc;
select * from crm_field_values where crm_field_id = 3341 order by id desc;
select * from crm_layouts where crm_configuration_id = 71 order by id desc;
select * from stages where crm_configuration_id = 71 order by id desc;
select * from users order by secondary_email desc;
select u.id, u.email, u.status, sa.id, sa.provider_user_id from social_accounts sa
join users u on sa.sociable_id = u.id
where sa.provider = 'google' and u.email LIKE 'aneliya%';
select * from failed_jobs order by id desc;
select * from users where email = '[EMAIL]' or secondary_email = '[EMAIL]';
select * from teams;
SELECT * FROM crm_profiles WHERE crm_configuration_id = 39;
SELECT * FROM crm_fields WHERE crm_configuration_id = 39 and object_type = 'task';
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 1
and sa.provider = 'salesforce';
# [PASSWORD_DOTS]
SELECT * FROM activities WHERE uuid_to_bin('c38b3895-fd0f-4b1f-9fb2-c170dba137c6') = uuid;
SELECT * FROM crm_configurations WHERE id = 70;
select * from teams where id = 1;
select * from groups where team_id = 1;
select * from users where team_id = 1;
select o.id, o.name,o.close_date, u.id, u.name, u.group_id, r.id, r.display_name, g.name, g.scope from opportunities o
join users u on o.user_id = u.id
join groups g on u.group_id = g.id
join role_user ru on u.id = ru.user_id
join roles r on ru.role_id = r.id
where o.crm_configuration_id = 39 and close_date > '2024-01-01 00:00:00';
select * from role_user where user_id = 143;
select * from roles;
select * from role_user;
select * from groups where id = 9;
select * from scope_groups where group_id = 9;
# [PASSWORD_DOTS]
select * from teams where id = 36;
select * from crm_configurations;
SELECT * FROM social_accounts WHERE sociable_id = 121;
[URL_WITH_CREDENTIALS] this will add filter, however if we need to control feature by FF we need conditional logic
public const array TYPES = [
['id' => 'exec_summary', 'name' => 'Exec Summary'],
['id' => 'coaching_profiles', 'name' => 'Coaching Profiles'],
['id' => 'product_feedback', 'name' => 'Product Feedback'],
['id' => self::TYPE_LOSS_ANALYSIS, 'name' => 'Loss Analysis'],
// ['id' => 'questions', 'name' => 'Questions'],
// ['id' => 'statistical_quant', 'name' => 'Statistical Quantitative'],
];
public const array ALL_TYPES = [
...self::TYPES,
['id' => self::TYPE_ASK_JIMINNY, 'name' => 'Ask Jiminny'],
];
public const string FREQUENCY_DAILY = 'daily';
public const string FREQUENCY_WEEKLY = 'weekly';
public const string FREQUENCY_MONTHLY = 'monthly';
public const string FREQUENCY_QUARTERLY = 'quarterly';
public const string FREQUENCY_ONE_OFF = 'one_off';
/**
* Frequencies for standard (non-Ask Jiminny) reports.
*/
public const array FREQUENCIES = [
['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],
['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],
['id' => self::FREQUENCY_QUARTERLY, 'name' => 'Quarterly'],
['id' => self::FREQUENCY_ONE_OFF, 'name' => 'One-off'],
];
/**
* Frequencies for Ask Jiminny reports.
*/
public const array ASK_JIMINNY_FREQUENCIES = [
['id' => self::FREQUENCY_DAILY, 'name' => 'Daily'],
['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],
['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],
];
public const string MEDIA_TYPE_PDF = 'pdf';
public const string MEDIA_TYPE_PODCAST = 'podcast';
public const array MEDIA_TYPES = [self::MEDIA_TYPE_PDF, self::MEDIA_TYPE_PODCAST];
public const array MEDIA_TYPE_OBJECT_PDF = ['id' => self::MEDIA_TYPE_PDF, 'name' => 'PDF'];
public const array MEDIA_TYPE_OBJECT_PODCAST = ['id' => self::MEDIA_TYPE_PODCAST, 'name' => 'Podcast'];
public const array MEDIA_TYPE_OBJECTS = [self::MEDIA_TYPE_OBJECT_PDF, self::MEDIA_TYPE_OBJECT_PODCAST];
public const array CALL_TYPE_CONFERENCE = ['id' => 'conference', 'name' => 'Conference'];
public const array CALL_TYPE_DIALER = ['id' => 'dialer', 'name' => 'Dialer'];
public const int SENT_REPORT_AT_HOURS = 5;
public const string PDF_KEY = 'pdf';
public const string AUDIO_KEY = 'audio';
private const array ALL_FREQUENCIES = [
['id' => self::FREQUENCY_DAILY, 'name' => 'Daily'],
['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],
['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],
['id' => self::FREQUENCY_QUARTERLY, 'name' => 'Quarterly'],
['id' => self::FREQUENCY_ONE_OFF, 'name' => 'One-off'],
];
private const string S3_DIR = 'reports';
private const array FILE_EXTENSIONS_VARIANTS = ['html', 'MD', 'pdf'];
private const array FILE_PODCAST_EXTENSIONS_VARIANTS = ['json', 'mp3', 'ssml'];
public function __construct(
private readonly TeamRepository $teamRepository,
private readonly GroupRepository $groupRepository,
private readonly UserRepository $userRepository,
private readonly StageRepository $stageRepository,
private readonly DealStagesService $dealStagesService,
private readonly RecipientsService $recipientsService,
private readonly AutomatedReportsRepository $automatedReportsRepository,
private readonly Webhook $webhookService,
private readonly BusDispatcher $dispatcher,
private readonly ActivityTypeService $activityTypeService,
private readonly PlaybookCategoryRepository $playbookCategoryRepository,
private readonly AskAnythingPromptService $askAnythingPromptService,
private readonly SearchRepository $activitySearchRepository,
private readonly AskAnythingRepository $askAnythingRepository,
) {
}
public static function getTypes(): array
{
$types = self::TYPES;
return array_map(static function ($type) {
return $type['id'];
}, $types);
}
public static function getCallTypes(): array
{
return array_map(static function ($callType) {
return $callType['id'];
}, [self::CALL_TYPE_CONFERENCE, self::CALL_TYPE_DIALER]);
}
public static function getFrequencies(): array
{
return array_map(static function ($frequency) {
return $frequency['id'];
}, self::FREQUENCIES);
}
// front-facing structure
public function getReportEnabledFieldData(bool $value = false): array
{
return [
'id' => 'report_enabled',
'label' => '',
'inputType' => InputTypeEnum::TOGGLE,
'value' => $value,
];
}
// Organizations = Teams
public function getOrganizationFieldData(?string $value = null, bool $shortVersion = false): array
{
$options = $this->getTeams();
if ($shortVersion) {
return [
'id' => 'organization',
'label' => 'Organization',
'options' => $options,
];
}
return [
'id' => 'organization',
'label' => 'Organization',
'inputType' => InputTypeEnum::DROPDOWN,
'required' => true,
'placeholder' => 'Select',
'options' => $options,
'value' => $value,
'dependencies' => [
'teams',
'deal_stage_at_call',
'current_deal_stage',
'recipients',
ActivityTypeService::PLAYBOOK_CATEGORIES_KEY,
],
'dependsOn' => [],
];
}
// Teams = Groups
public function getTeamFieldData(array $options = [], array $value = [], bool $shortVersion = false): array
{
if ($shortVersion) {
return [
'id' => 'teams',
'label' => 'Team',
'options' => $options,
];
}
return [
'id' => 'teams',
'label' => 'Team',
'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,
'required' => false,
'placeholder' => 'Select',
'options' => $options,
'value' => $value, // value should be an array of objects {id, name}
'dependencies' => [ActivityTypeService::PLAYBOOK_CATEGORIES_KEY],
'dependsOn' => [],
];
}
public function getReportTypeFieldData(?string $value = null, bool $shortVersion = false, ?Team $team = null): array
{
$types = [];
if ($team instanceof Team) {
if ($team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {
$types = self::TYPES;
}
if ($team->hasFeature(FeatureEnum::ASK_JIMINNY_REPORTS)) {
$types[] = ['id' => self::TYPE_ASK_JIMINNY, 'name' => 'Ask Jiminny'];
}
} else {
$types = self::TYPES;
}
if ($shortVersion) {
return [
'id' => 'report_type',
'label' => 'Report Type',
'options' => $types,
];
}
return [
'id' => 'report_type',
'label' => 'Report Type',
'inputType' => InputTypeEnum::DROPDOWN,
'required' => true,
'placeholder' => 'Select',
'options' => $types,
'value' => $value,
'dependencies' => [],
'dependsOn' => [],
];
}
public function getFrequencyFieldData(?string $value = null): array
{
return [
'id' => 'frequency',
'label' => 'Frequency',
'inputType' => InputTypeEnum::DROPDOWN,
'required' => true,
'placeholder' => 'Select',
'options' => self::FREQUENCIES,
'value' => $value,
'dependencies' => ['period'],
'dependsOn' => [],
];
}
public function getPeriodFieldData(?string $valueStartDate = null, ?string $valueEndDate = null): array
{
return [
'id' => 'period',
'label' => 'Select one-off period',
'inputType' => InputTypeEnum::DATE_RANGE,
'required' => true,
'placeholder' => 'Select',
'value' => ['startDate' => $valueStartDate, 'endDate' => $valueEndDate],
'queryParams' => [
'startDate' => 'start_date_period',
'endDate' => 'end_date_period',
],
'dependencies' => [],
'dependsOn' => ['frequency'],
];
}
public function getActivityTypesFieldData(?Team $team = null, array $value = [], array $teamsFilter = []): array
{
return $this->activityTypeService->getActivityTypeFieldData(team: $team, value: $value, groupIds: $teamsFilter);
}
public function getDealStageAtCallFieldData(?Team $team = null, array $value = []): array
{
return $this->dealStagesService->getDealStageAtCallFieldData(team: $team, value: $value);
}
public function getCurrentDealStageFieldData(?Team $team = null, array $value = []): array
{
return $this->dealStagesService->getCurrentDealStageFieldData(team: $team, value: $value);
}
public function getDealValueFieldData(?int $valueMin = null, ?int $valueMax = null): array
{
return [
'id' => 'deal_value',
'label' => 'Deal Value',
'inputType' => InputTypeEnum::INTEGER_RANGE,
'required' => false,
'value' => ['min' => $valueMin, 'max' => $valueMax],
'queryParams' => [
'min' => 'min_deal_value',
'max' => 'max_deal_value',
],
'dependencies' => [],
'dependsOn' => [],
];
}
public function getCallTypeFieldData(bool $conferenceOn = false, bool $dialerOn = false): array
{
$value = [];
$conferenceOn && $value[] = self::CALL_TYPE_CONFERENCE;
$dialerOn && $value[] = self::CALL_TYPE_DIALER;
return [
'id' => 'call_type',
'label' => 'Call Type',
'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,
'required' => true,
'options' => [
self::CALL_TYPE_CONFERENCE,
self::CALL_TYPE_DIALER,
],
'value' => $value,
'dependencies' => [],
'dependsOn' => [],
];
}
public function getMediaTypeFieldData(?AutomatedReport $report = null): array
{
$value = [];
if ($report) {
$value = $this->transformMediaTypes($report);
}
return [
'id' => 'media_types',
'label' => 'Export as',
'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,
'required' => true,
'options' => self::MEDIA_TYPE_OBJECTS,
'value' => $value,
'dependencies' => [],
'dependsOn' => [],
];
}
public function getCallDurationFieldData(?int $valueMin = null, ?int $valueMax = null): array
{
return [
'id' => 'call_duration',
'label' => 'Call Duration',
'inputType' => InputTypeEnum::INTEGER_RANGE,
'required' => false,
'value' => ['min' => $valueMin, 'max' => $valueMax],
'queryParams' => [
'min' => 'min_call_duration',
'max' => 'max_call_duration',
],
'dependencies' => [],
'dependsOn' => [],
];
}
public function getRecipientsFieldData(?Team $team = null, array $value = []): array
{
return $this->recipientsService->getRecipientsFieldData(team: $team, value: $value);
}
public function getJiminnyRecipientsFieldData(array $value = []): array
{
return $this->recipientsService->getJiminnyRecipientsFieldData($value);
}
public function getAdditionalPromptInputFieldData(?string $value = null): array
{
return [
'id' => 'additional_prompt_input',
'label' => 'Special requirements',
'inputType' => InputTypeEnum::TEXTAREA,
'required' => false,
'placeholder' => 'What should be the focus of the report?',
'value' => $value,
'dependencies' => [],
'dependsOn' => [],
];
}
public function getCustomReportNameFieldData(?string $value = null): array
{
return [
'id' => 'custom_name',
'label' => 'Custom report name',
'inputType' => InputTypeEnum::TEXT,
'required' => false,
'placeholder' => 'Enter custom name',
'value' => $value,
'dependencies' => [],
'dependsOn' => [],
];
}
// data providers
public function getTeams(): array
{
$teams = $this->teamRepository->getTeamsForKiosk(status: Team::STATUS_ACTIVE);
$teamData = [];
foreach ($teams as $team) {
if (! $team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {
continue;
}
$teamData[] = $this->transformTeam($team);
}
return $teamData;
}
public function getTeamGroups(string $teamUuid): array
{
$data = [];
$team = $this->getTeam($teamUuid);
if ($team !== null) {
$groups = $team->groups()->get();
foreach ($groups as $group) {
$data[] = [
'id' => $group->getUuid(),
'name' => $group->getName(),
];
}
}
return $data;
}
public function getTeamsGroupsOptions(array $filterTeamUuids = []): array
{
$data = [];
$teams = $this->getTeams();
foreach ($teams as $team) {
if (! empty($filterTeamUuids) && ! in_array($team['id'], $filterTeamUuids, true)) {
continue;
}
$data[] = [
'label' => $team['name'],
'groups' => $this->getTeamGroups($team['id']),
];
}
return $data;
}
public function getTeam(string $teamUuid): ?Team
{
return $this->teamRepository->idOrUuid($teamUuid);
}
public function getTeamById(int $teamId): ?Team
{
return $this->teamRepository->find($teamId);
}
public function getGroupsUuids(AutomatedReport $report): array
{
$uuids = [];
$reportGroups = $report->getGroups();
foreach ($reportGroups as $groupId) {
if ($group = $this->groupRepository->find($groupId)) {
$uuids[] = $group->getUuid();
}
}
return $uuids;
}
public function getPlaybookCategoriesUuids(AutomatedReport $report): array
{
$uuids = [];
$playbookCategories = $report->getPlaybookCategories();
foreach ($playbookCategories as $id) {
if ($category = $this->playbookCategoryRepository->find($id)) {
$uuids[] = $category->getUuid();
}
}
return $uuids;
}
public function getDealAtCallStagesUuids(AutomatedReport $report): array
{
$uuids = [];
$reportStages = $report->getDealAtCallStages();
foreach ($reportStages as $id) {
if ($stage = $this->stageRepository->find($id)) {
$uuids[] = $stage->getUuid();
}
}
return $uuids;
}
public function getCurrentDealStagesUuids(AutomatedReport $report): array
{
$uuids = [];
$reportStages = $report->getCurrentDealStages();
foreach ($reportStages as $id) {
if ($stage = $this->stageRepository->find($id)) {
$uuids[] = $stage->getUuid();
}
}
return $uuids;
}
public function getUsersUuids(AutomatedReport $report): array
{
return $this->extractUserUuids($report->getRecipients());
}
public function getJiminnyUsersUuids(AutomatedReport $report): array
{
return $this->extractUserUuids($report->getJiminnyRecipients());
}
/**
* @param array<string, mixed> $recipients
*/
private function extractUserUuids(array $recipients): array
{
$userIds = $recipients['users'] ?? [];
return collect($userIds)
->map(fn ($id) => $this->userRepository->find((int) $id))
->filter()
->map(fn (UserContract $user) => $user->getUuid())
->values()
->all();
}
// get mail data
public function getRecipientUsers(AutomatedReport $report): array
{
return $this->buildRecipientUsers($report->getRecipients());
}
private function getJiminnyRecipientUsers(AutomatedReport $report): array
{
return $this->buildRecipientUsers($report->getJiminnyRecipients());
}
/**
* @param array<string, mixed> $recipients
*/
private function buildRecipientUsers(array $recipients): array
{
$userIds = $recipients['users'] ?? [];
return collect($userIds)
->map(fn ($id) => $this->userRepository->find((int) $id))
->filter()
->map(fn (UserContract $user) => [
'email' => $user->getEmailAddress(),
'name' => $user->getName(),
'timezone' => $user->getTimezone()->getName(),
])
->values()
->all();
}
public function getValidRecipientUsers(AutomatedReport $report, bool $includeJiminny = false): array
{
if ($report->isAskJiminnyReport()) {
$recipients = $this->resolveAskJiminnyRecipients($report);
} else {
$recipients = $this->getRecipientUsers($report);
if ($includeJiminny) {
$recipients = array_merge($recipients, $this->getJiminnyRecipientUsers($report));
}
}
$emails = [];
return array_values(array_filter(
$recipients,
static function ($recipient) use (&$emails) {
if (empty($recipient['email']) || in_array($recipient['email'], $emails, true)) {
return false;
}
$emails[] = $recipient['email'];
return true;
}
));
}
private function resolveAskJiminnyRecipients(AutomatedReport $report): array
{
$recipients = [];
$creator = $report->getCreator();
if ($creator !== null) {
$recipients[] = [
'email' => $creator->getEmailAddress(),
'name' => $creator->getName(),
'timezone' => $creator->getTimezone()->getName(),
];
}
return array_merge(
$recipients,
$this->buildRecipientUsers($report->getRecipients()),
$this->getGroupRecipientUsers($report),
);
}
private function getGroupRecipientUsers(AutomatedReport $report): array
{
$users = [];
foreach ($report->getGroups() as $groupId) {
$group = $this->groupRepository->find($groupId);
if ($group === null) {
continue;
}
foreach ($group->getMembers() as $member) {
$users[] = [
'email' => $member->getEmailAddress(),
'name' => $member->getName(),
'timezone' => $member->getTimezone()->getName(),
];
}
}
return $users;
}
public function getReportTypeName(AutomatedReportResult $report): string
{
$type = $report->getReport()->getType();
$getType = $this->transformReportType($type);
return $getType['name'];
}
public function getReportPeriodName(AutomatedReportResult $report): string
{
$from = $report->getFromDate();
$to = $report->getToDate();
$frequency = $report->getReport()->getFrequency();
if ($from === null || $to === null) {
if (! $report->getReport()->isAskJiminnyReport()) {
$invalidPeriod = $from === null ? 'from' : 'to';
throw new ApplicationException('Report period is invalid: ' . $invalidPeriod);
}
$period = $this->calculateFromAndToDatePeriod($frequency);
$from = $period['fromDate'];
$to = $period['toDate'];
}
return $this->formatReportPeriodName($frequency, $from, $to);
}
private function formatReportPeriodName(string $frequency, Carbon $from, Carbon $to): string
{
$fromYear = $from->format('Y');
$toYear = $to->format('Y');
$differentYears = $fromYear !== $toYear;
switch ($frequency) {
case self::FREQUENCY_DAILY:
return $from->format('j M Y');
case self::FREQUENCY_QUARTERLY:
// 'Jan-Mar 2025' or 'Nov 2024-Jan 2025' if years differ
$startMonth = $from->format('M');
$endMonth = $to->copy()->subMonth();
$endMonthName = $endMonth->format('M');
$endMonthYear = $endMonth->format('Y');
if ($differentYears) {
return "{$startMonth} {$fromYear} - {$endMonthName} {$endMonthYear}";
}
return "{$startMonth} - {$endMonthName} {$toYear}";
case self::FREQUENCY_MONTHLY:
// 'May 2025' - monthly reports are always within the same year
return $from->format('M Y');
case self::FREQUENCY_WEEKLY:
// '4 - 8 Aug 2025', '27 Oct - 3 Nov 2025', or '28 Dec 2024 - 3 Jan 2025' if years differ
$startDay = $from->format('j');
$endDay = $to->format('j');
$startMonth = $from->format('M');
$endMonth = $to->format('M');
if ($differentYears) {
return "{$startDay} {$startMonth} {$fromYear} - {$endDay} {$endMonth} {$toYear}";
}
if ($startMonth !== $endMonth) {
return "{$startDay} {$startMonth} - {$endDay} {$endMonth} {$toYear}";
}
return "{$startDay} - {$endDay} {$endMonth} {$toYear}";
case self::FREQUENCY_ONE_OFF:
// '2 May-31 May 2025' or '15 Dec 2024-15 Jan 2025' if years differ
$startDay = $from->format('j');
$startMonth = $from->format('M');
$endDay = $to->format('j');
$endMonth = $to->format('M');
// If same month and year, use a format like '2-31 May 2025'
if ($startMonth === $endMonth && ! $differentYears) {
return "{$startDay} - {$endDay} {$startMonth} {$toYear}";
}
// If different years, include both years
if ($differentYears) {
return "{$startDay} {$startMonth} {$fromYear} - {$endDay} {$endMonth} {$toYear}";
}
// Same year but different months
return "{$startDay} {$startMonth} - {$endDay} {$endMonth} {$toYear}";
default:
// Default format for unknown frequencies
return $from->format('j M Y') . ' - ' . $to->format('j M Y');
}
}
public function getReportTeamsName(AutomatedReportResult $report): string
{
$groups = $report->getGroups();
if (empty($groups)) {
return 'All';
}
// Get group names from repository
$groupNames = [];
foreach ($groups as $groupId) {
$group = $this->groupRepository->find($groupId);
if ($group) {
$groupNames[] = $group->getName();
}
}
if (count($groupNames) === 1) {
// Single team format
$teamsName = $groupNames[0];
} else {
// Multiple teams format
$teamsName = implode(', ', $groupNames);
}
return $teamsName;
}
public function getReportFileName(AutomatedReportResult $report): string
...
|
12331
|
|
12335
|
262
|
6
|
2026-04-14T11:08:32.432262+00:00
|
/Users/lukas/.screenpipe/data/data/2026-04-14/1776 /Users/lukas/.screenpipe/data/data/2026-04-14/1776164912432_m1.jpg...
|
PhpStorm
|
faVsco.js – AutomatedReportsService.php
|
1
|
NULL
|
monitor_1
|
NULL
|
NULL
|
NULL
|
NULL
|
Project: faVsco.js, menu
#11894 on JY-18909-automa Project: faVsco.js, menu
#11894 on JY-18909-automated-reports-ask-jiminny, menu
Start Listening for PHP Debug Connections
AutomatedReportsCommandTest
Run 'AutomatedReportsCommandTest'
Debug 'AutomatedReportsCommandTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Execute
Explain Plan
Browse Query History
View Parameters
Open Query Execution Settings…
In-Editor Results
Tx: Auto
Cancel Running Statements
Playground
jiminny
Sync Changes
Hide This Notification
Code changed:
Hide
16
13
13
Previous Highlighted Error
Next Highlighted Error
SELECT * FROM teams WHERE id = 1;
select * from crm_layouts where crm_configuration_id = 39;
SELECT * FROM crm_layout_entities WHERE crm_layout_id = 283;
SELECT * FROM crm_fields WHERE id = 2234;
SELECT * FROM crm_field_values WHERE crm_field_id = 2234;
select * from crm_profiles where user_id = 143;
select * from record_types where crm_configuration_id = 39; # 0121K000001MHElQAO,0121K000001MHEqQAO
select * from business_processes where crm_configuration_id = 39;
# 01941000000H669AAC, 01941000000H66JAAS
select * from record_type_field_values
where record_type_id IN (24);
select * from crm_field_values where id IN (2730);
select * from crm_configurations where id = 39;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 1
and sa.provider = 'salesforce'; #1035
select * from users where team_id = 1; # 222 group 3
SELECT * FROM activities WHERE user_id = 222 order by id desc;
select * from sidekick_settings where team_id = 1;
select * from teams where id = 1;
select * from team_features where team_id = 1;
select * from activities where crm_configuration_id = 2
and provider = 'ms-teams' and id = 608765;
SELECT * FROM activities WHERE crm_configuration_id = 2 and crm_provider_id = '59523413338';
select * from sidekick_settings where team_id = 2;
SELECT * FROM activities WHERE id = 608660;
select * from activity_summary_logs where activity_id = 608660;
select * from ai_prompts where transcription_id = 11214;
# [PASSWORD_DOTS]
SELECT * FROM activities WHERE uuid_to_bin('ed78a437-2804-450e-ab2f-56ab1c641346') = uuid;
# id: 608818, crm: 59628809737
SELECT * FROM activities WHERE uuid_to_bin('36b06e55-afdd-4782-8dee-c624cd0af191') = uuid;
# id: 608821, crm: 59632069252
SELECT ce.start_time, ce.end_time, a.id, a.uuid, crm_provider_id, calendar_event_id, title,
playbook_category_id, user_id, lead_id, contact_id, account_id, opportunity_id,
scheduled_start_time, scheduled_end_time, actual_start_time, actual_end_time, a.created_at
FROM activities a
join calendar_events ce on a.calendar_event_id = ce.id
WHERE a.id IN (608818, 608821);
select * from users where team_id = 1;
select * from team_settings where team_id = 1;
select * from crm_profiles where crm_configuration_id = 39 order by user_id;
select * from team_features where team_id = 1;
select * from users where team_id = 2;
SELECT * FROM activities WHERE uuid_to_bin('ec7647e9-5225-458b-b475-f31aa2769204') = uuid; # 612639
# Preslava N. Ivanova, grou id 3
SELECT * FROM opportunities WHERE uuid_to_bin('a2928fe5-aec5-46cb-85d9-7654c89e46a6') = uuid;
select * from activities where opportunity_id = 344 and actual_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00';
select
a.id,
a.type,
a.scheduled_start_time,
a.actual_start_time,
a.created_at,
a.opportunity_id,
a.status
FROM activities a
WHERE opportunity_id = 344
and status IN ('completed', 'received', 'delivered')
and (
(a.actual_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00')
OR (a.created_at between '2024-10-11 00:00:00' and '2024-10-12 00:00:00')
OR (a.scheduled_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00'))
;
SELECT * FROM users WHERE id = 222;
SELECT * FROM crm_profiles WHERE user_id = 222;
select * from crm_layouts where crm_configuration_id = 39;
SELECT * FROM crm_layout_entities WHERE crm_layout_id = 281;
select * from group_deal_risk_types;
select * from opportunities where team_id = 1;
SELECT * FROM opportunities WHERE id = 315;
SELECT * FROM crm_field_data WHERE object_id = 315;
select * from crm_field_data where object_id = 260;
select * from generic_ai_prompts where subject_id = 315;
select * from teams; # 36, 21, 121, [EMAIL]
SELECT * FROM social_accounts WHERE sociable_id = 121 and provider = 'bullhorn';
# [PASSWORD_DOTS]
select * from teams where id = 1;
select * from crm_configurations where id = 39;
select * from users where team_id = 1;
select u.email, cp.* from users u
join crm_profiles cp on u.id = cp.user_id
where u.team_id = 1;
# 1 - 00541000004281rAAA
# 204 - 0052g000003freeAAA
# 429 - 0052g000003qGOiAAM
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 1
and sa.provider = 'salesforce';
select * from activities where type = 'softphone'
and created_at > '2024-12-11 15:24:36' order by id desc;
select * from activity_providers where team_id = 1;
select * from activity_provider_users where activity_provider_id = 328;
select * from opportunities where crm_configuration_id = 39
AND account_id = 178 AND is_closed = false
order by created_at DESC;
select * from contacts where id = 3952;
select * from accounts where id = 178;
# [PASSWORD_DOTS]
select * from teams where id = 36;
select * from crm_configurations where id = 21;
select * from users where team_id = 36;
select u.email, cp.* from users u
join crm_profiles cp on u.id = cp.user_id
where u.team_id = 36;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 36
and sa.provider = 'bullhorn';
select * from social_accounts where id = 348;
UPDATE social_accounts SET
provider_user_token = '21442_6802599_91:41179a58-21e7-4d7c-ad58-56bb666b2f65',
provider_refresh_token = '21442_6802599_91:01c6b335-3f2a-42e4-85ff-8a08fa65fceb',
expires = 1733998131,
state = 'connected'
WHERE id = 348;
# [PASSWORD_DOTS]
select * from teams where id = 31;
select * from crm_configurations where id = 18;
select * from users where team_id = 31; # 257
select u.email, cp.* from users u
join crm_profiles cp on u.id = cp.user_id
where u.team_id = 31;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 31
and sa.provider = 'close';
select * from contacts where crm_configuration_id = 18;
# [PASSWORD_DOTS] NEPTUNE [PASSWORD_DOTS]
select * from teams;
select * from users where id IN (1030, 1035, 1052);
select * from crm_configurations;
select * from users where team_id = 65; # 257
select * from team_settings where team_id = 65; # 257
select * from invitations where team_id = 65; # 257
select * from users where email = '[EMAIL]'; # 257
select u.email, cp.* from users u
join crm_profiles cp on u.id = cp.user_id
where u.team_id = 65;
select * from crm_configurations where id = 53;
select * from accounts where crm_configuration_id = 53 order by id desc;
select * from leads where crm_configuration_id = 53 order by id desc;
select * from contacts where crm_configuration_id = 53 order by id desc;
select * from opportunities where crm_configuration_id = 53 order by id desc;
select * from crm_profiles where crm_configuration_id = 53 order by id desc;
select * from crm_fields where crm_configuration_id = 53 order by id desc;
select * from crm_field_values where crm_field_id = 3341 order by id desc;
select * from crm_layouts where crm_configuration_id = 53 order by id desc;
select * from stages where crm_configuration_id = 53 order by id desc;
select * from crm_profiles where crm_configuration_id = 13;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 65
and sa.provider = 'integration-app';
select * from contacts where crm_configuration_id = 13;
select * from social_accounts where sociable_id = 283;
SELECT * FROM opportunities WHERE crm_provider_id = '006O400000E9bzeIAB';
select * from activity_providers where team_id = 65;
SELECT * FROM activities WHERE crm_configuration_id IN (51, 52, 53);
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 65
;
# [PASSWORD_DOTS] STAGING [PASSWORD_DOTS]
SELECT * FROM teams;
SELECT * FROM teams WHERE id = 88;
SELECT * FROM teams WHERE id = 89;
select * from team_settings where team_id = 89;
SELECT * FROM users WHERE team_id = 89;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 89;
select * from users;
SELECT * FROM social_accounts WHERE sociable_id = 1761;
SELECT * FROM crm_configurations WHERE id = 70;
select * from accounts where crm_configuration_id = 70 order by id desc;
select * from leads where crm_configuration_id = 70 order by id desc;
select * from contacts where crm_configuration_id = 70 order by id desc;
select * from opportunities where crm_configuration_id = 70 order by id desc;
select * from crm_profiles where crm_configuration_id = 70 order by id desc;
select * from crm_fields where crm_configuration_id = 70 order by id desc;
select * from crm_field_values where crm_field_id = 3536 order by id desc;
select * from crm_layouts where crm_configuration_id = 70 order by id desc;
select * from stages where crm_configuration_id = 70 order by id desc;
select * from business_processes where crm_configuration_id = 70 order by id desc;
select * from business_process_stages where business_process_id = 34;
select * from contacts where id = 10468;
select * from crm_layouts where crm_configuration_id = 70;
SELECT * FROM crm_layout_entities WHERE crm_layout_id = 388;
SELECT * FROM crm_fields WHERE id IN (3533,3534,3535);
select * from activities where crm_configuration_id = 70
and (account_id IS NOT NULL or lead_id IS NOT NULL or contact_id IS NOT NULL or opportunity_id IS NOT NULL) order by id desc;
SELECT * FROM activities WHERE uuid_to_bin('2e10b60f-8a61-41c5-a3d4-28835353dc65') = uuid;
SELECT * FROM activities where crm_configuration_id = 69 ;
SELECT * FROM users WHERE email LIKE '%[EMAIL]%';
SELECT * FROM activities WHERE uuid_to_bin('5a150c93-40fc-42ec-b3bd-c1d328e09f6e') = uuid;
SELECT * FROM opportunities WHERE id = 385;
select * from participants p
join activities a on p.activity_id = a.id
where a.crm_configuration_id = 70
and (p.lead_id IS NOT NULL or p.contact_id IS NOT NULL);
SELECT * FROM participants WHERE id = 1013638;
select * from teams where id = 90;
select * from users where team_id = 90;
select * from social_accounts where social_accounts.sociable_id IN (1960,1760);
SELECT * FROM crm_profiles WHERE crm_configuration_id = 71;
select * from invitations where team_id = 90;
select * from crm_configurations where id = 71;
select * from accounts where crm_configuration_id = 71 order by id desc;
select * from leads where crm_configuration_id = 71 order by id desc;
select * from contacts where crm_configuration_id = 71 order by id desc;
select * from opportunities where crm_configuration_id = 71 order by id desc;
select * from crm_profiles where crm_configuration_id = 71 order by id desc;
select * from crm_fields where crm_configuration_id = 71 order by id desc;
select * from crm_field_values where crm_field_id = 3341 order by id desc;
select * from crm_layouts where crm_configuration_id = 71 order by id desc;
select * from stages where crm_configuration_id = 71 order by id desc;
select * from users order by secondary_email desc;
select u.id, u.email, u.status, sa.id, sa.provider_user_id from social_accounts sa
join users u on sa.sociable_id = u.id
where sa.provider = 'google' and u.email LIKE 'aneliya%';
select * from failed_jobs order by id desc;
select * from users where email = '[EMAIL]' or secondary_email = '[EMAIL]';
select * from teams;
SELECT * FROM crm_profiles WHERE crm_configuration_id = 39;
SELECT * FROM crm_fields WHERE crm_configuration_id = 39 and object_type = 'task';
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 1
and sa.provider = 'salesforce';
# [PASSWORD_DOTS]
SELECT * FROM activities WHERE uuid_to_bin('c38b3895-fd0f-4b1f-9fb2-c170dba137c6') = uuid;
SELECT * FROM crm_configurations WHERE id = 70;
select * from teams where id = 1;
select * from groups where team_id = 1;
select * from users where team_id = 1;
select o.id, o.name,o.close_date, u.id, u.name, u.group_id, r.id, r.display_name, g.name, g.scope from opportunities o
join users u on o.user_id = u.id
join groups g on u.group_id = g.id
join role_user ru on u.id = ru.user_id
join roles r on ru.role_id = r.id
where o.crm_configuration_id = 39 and close_date > '2024-01-01 00:00:00';
select * from role_user where user_id = 143;
select * from roles;
select * from role_user;
select * from groups where id = 9;
select * from scope_groups where group_id = 9;
# [PASSWORD_DOTS]
select * from teams where id = 36;
select * from crm_configurations;
SELECT * FROM social_accounts WHERE sociable_id = 121;
[URL_WITH_CREDENTIALS] this will add filter, however if we need to control feature by FF we need conditional logic
public const array TYPES = [
['id' => 'exec_summary', 'name' => 'Exec Summary'],
['id' => 'coaching_profiles', 'name' => 'Coaching Profiles'],
['id' => 'product_feedback', 'name' => 'Product Feedback'],
['id' => self::TYPE_LOSS_ANALYSIS, 'name' => 'Loss Analysis'],
// ['id' => 'questions', 'name' => 'Questions'],
// ['id' => 'statistical_quant', 'name' => 'Statistical Quantitative'],
];
public const array ALL_TYPES = [
...self::TYPES,
['id' => self::TYPE_ASK_JIMINNY, 'name' => 'Ask Jiminny'],
];
public const string FREQUENCY_DAILY = 'daily';
public const string FREQUENCY_WEEKLY = 'weekly';
public const string FREQUENCY_MONTHLY = 'monthly';
public const string FREQUENCY_QUARTERLY = 'quarterly';
public const string FREQUENCY_ONE_OFF = 'one_off';
/**
* Frequencies for standard (non-Ask Jiminny) reports.
*/
public const array FREQUENCIES = [
['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],
['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],
['id' => self::FREQUENCY_QUARTERLY, 'name' => 'Quarterly'],
['id' => self::FREQUENCY_ONE_OFF, 'name' => 'One-off'],
];
/**
* Frequencies for Ask Jiminny reports.
*/
public const array ASK_JIMINNY_FREQUENCIES = [
['id' => self::FREQUENCY_DAILY, 'name' => 'Daily'],
['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],
['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],
];
public const string MEDIA_TYPE_PDF = 'pdf';
public const string MEDIA_TYPE_PODCAST = 'podcast';
public const array MEDIA_TYPES = [self::MEDIA_TYPE_PDF, self::MEDIA_TYPE_PODCAST];
public const array MEDIA_TYPE_OBJECT_PDF = ['id' => self::MEDIA_TYPE_PDF, 'name' => 'PDF'];
public const array MEDIA_TYPE_OBJECT_PODCAST = ['id' => self::MEDIA_TYPE_PODCAST, 'name' => 'Podcast'];
public const array MEDIA_TYPE_OBJECTS = [self::MEDIA_TYPE_OBJECT_PDF, self::MEDIA_TYPE_OBJECT_PODCAST];
public const array CALL_TYPE_CONFERENCE = ['id' => 'conference', 'name' => 'Conference'];
public const array CALL_TYPE_DIALER = ['id' => 'dialer', 'name' => 'Dialer'];
public const int SENT_REPORT_AT_HOURS = 5;
public const string PDF_KEY = 'pdf';
public const string AUDIO_KEY = 'audio';
private const array ALL_FREQUENCIES = [
['id' => self::FREQUENCY_DAILY, 'name' => 'Daily'],
['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],
['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],
['id' => self::FREQUENCY_QUARTERLY, 'name' => 'Quarterly'],
['id' => self::FREQUENCY_ONE_OFF, 'name' => 'One-off'],
];
private const string S3_DIR = 'reports';
private const array FILE_EXTENSIONS_VARIANTS = ['html', 'MD', 'pdf'];
private const array FILE_PODCAST_EXTENSIONS_VARIANTS = ['json', 'mp3', 'ssml'];
public function __construct(
private readonly TeamRepository $teamRepository,
private readonly GroupRepository $groupRepository,
private readonly UserRepository $userRepository,
private readonly StageRepository $stageRepository,
private readonly DealStagesService $dealStagesService,
private readonly RecipientsService $recipientsService,
private readonly AutomatedReportsRepository $automatedReportsRepository,
private readonly Webhook $webhookService,
private readonly BusDispatcher $dispatcher,
private readonly ActivityTypeService $activityTypeService,
private readonly PlaybookCategoryRepository $playbookCategoryRepository,
private readonly AskAnythingPromptService $askAnythingPromptService,
private readonly SearchRepository $activitySearchRepository,
private readonly AskAnythingRepository $askAnythingRepository,
) {
}
public static function getTypes(): array
{
$types = self::TYPES;
return array_map(static function ($type) {
return $type['id'];
}, $types);
}
public static function getCallTypes(): array
{
return array_map(static function ($callType) {
return $callType['id'];
}, [self::CALL_TYPE_CONFERENCE, self::CALL_TYPE_DIALER]);
}
public static function getFrequencies(): array
{
return array_map(static function ($frequency) {
return $frequency['id'];
}, self::FREQUENCIES);
}
// front-facing structure
public function getReportEnabledFieldData(bool $value = false): array
{
return [
'id' => 'report_enabled',
'label' => '',
'inputType' => InputTypeEnum::TOGGLE,
'value' => $value,
];
}
// Organizations = Teams
public function getOrganizationFieldData(?string $value = null, bool $shortVersion = false): array
{
$options = $this->getTeams();
if ($shortVersion) {
return [
'id' => 'organization',
'label' => 'Organization',
'options' => $options,
];
}
return [
'id' => 'organization',
'label' => 'Organization',
'inputType' => InputTypeEnum::DROPDOWN,
'required' => true,
'placeholder' => 'Select',
'options' => $options,
'value' => $value,
'dependencies' => [
'teams',
'deal_stage_at_call',
'current_deal_stage',
'recipients',
ActivityTypeService::PLAYBOOK_CATEGORIES_KEY,
],
'dependsOn' => [],
];
}
// Teams = Groups
public function getTeamFieldData(array $options = [], array $value = [], bool $shortVersion = false): array
{
if ($shortVersion) {
return [
'id' => 'teams',
'label' => 'Team',
'options' => $options,
];
}
return [
'id' => 'teams',
'label' => 'Team',
'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,
'required' => false,
'placeholder' => 'Select',
'options' => $options,
'value' => $value, // value should be an array of objects {id, name}
'dependencies' => [ActivityTypeService::PLAYBOOK_CATEGORIES_KEY],
'dependsOn' => [],
];
}
public function getReportTypeFieldData(?string $value = null, bool $shortVersion = false, ?Team $team = null): array
{
$types = [];
if ($team instanceof Team) {
if ($team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {
$types = self::TYPES;
}
if ($team->hasFeature(FeatureEnum::ASK_JIMINNY_REPORTS)) {
$types[] = ['id' => self::TYPE_ASK_JIMINNY, 'name' => 'Ask Jiminny'];
}
} else {
$types = self::TYPES;
}
if ($shortVersion) {
return [
'id' => 'report_type',
'label' => 'Report Type',
'options' => $types,
];
}
return [
'id' => 'report_type',
'label' => 'Report Type',
'inputType' => InputTypeEnum::DROPDOWN,
'required' => true,
'placeholder' => 'Select',
'options' => $types,
'value' => $value,
'dependencies' => [],
'dependsOn' => [],
];
}
public function getFrequencyFieldData(?string $value = null): array
{
return [
'id' => 'frequency',
'label' => 'Frequency',
'inputType' => InputTypeEnum::DROPDOWN,
'required' => true,
'placeholder' => 'Select',
'options' => self::FREQUENCIES,
'value' => $value,
'dependencies' => ['period'],
'dependsOn' => [],
];
}
public function getPeriodFieldData(?string $valueStartDate = null, ?string $valueEndDate = null): array
{
return [
'id' => 'period',
'label' => 'Select one-off period',
'inputType' => InputTypeEnum::DATE_RANGE,
'required' => true,
'placeholder' => 'Select',
'value' => ['startDate' => $valueStartDate, 'endDate' => $valueEndDate],
'queryParams' => [
'startDate' => 'start_date_period',
'endDate' => 'end_date_period',
],
'dependencies' => [],
'dependsOn' => ['frequency'],
];
}
public function getActivityTypesFieldData(?Team $team = null, array $value = [], array $teamsFilter = []): array
{
return $this->activityTypeService->getActivityTypeFieldData(team: $team, value: $value, groupIds: $teamsFilter);
}
public function getDealStageAtCallFieldData(?Team $team = null, array $value = []): array
{
return $this->dealStagesService->getDealStageAtCallFieldData(team: $team, value: $value);
}
public function getCurrentDealStageFieldData(?Team $team = null, array $value = []): array
{
return $this->dealStagesService->getCurrentDealStageFieldData(team: $team, value: $value);
}
public function getDealValueFieldData(?int $valueMin = null, ?int $valueMax = null): array
{
return [
'id' => 'deal_value',
'label' => 'Deal Value',
'inputType' => InputTypeEnum::INTEGER_RANGE,
'required' => false,
'value' => ['min' => $valueMin, 'max' => $valueMax],
'queryParams' => [
'min' => 'min_deal_value',
'max' => 'max_deal_value',
],
'dependencies' => [],
'dependsOn' => [],
];
}
public function getCallTypeFieldData(bool $conferenceOn = false, bool $dialerOn = false): array
{
$value = [];
$conferenceOn && $value[] = self::CALL_TYPE_CONFERENCE;
$dialerOn && $value[] = self::CALL_TYPE_DIALER;
return [
'id' => 'call_type',
'label' => 'Call Type',
'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,
'required' => true,
'options' => [
self::CALL_TYPE_CONFERENCE,
self::CALL_TYPE_DIALER,
],
'value' => $value,
'dependencies' => [],
'dependsOn' => [],
];
}
public function getMediaTypeFieldData(?AutomatedReport $report = null): array
{
$value = [];
if ($report) {
$value = $this->transformMediaTypes($report);
}
return [
'id' => 'media_types',
'label' => 'Export as',
'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,
'required' => true,
'options' => self::MEDIA_TYPE_OBJECTS,
'value' => $value,
'dependencies' => [],
'dependsOn' => [],
];
}
public function getCallDurationFieldData(?int $valueMin = null, ?int $valueMax = null): array
{
return [
'id' => 'call_duration',
'label' => 'Call Duration',
'inputType' => InputTypeEnum::INTEGER_RANGE,
'required' => false,
'value' => ['min' => $valueMin, 'max' => $valueMax],
'queryParams' => [
'min' => 'min_call_duration',
'max' => 'max_call_duration',
],
'dependencies' => [],
'dependsOn' => [],
];
}
public function getRecipientsFieldData(?Team $team = null, array $value = []): array
{
return $this->recipientsService->getRecipientsFieldData(team: $team, value: $value);
}
public function getJiminnyRecipientsFieldData(array $value = []): array
{
return $this->recipientsService->getJiminnyRecipientsFieldData($value);
}
public function getAdditionalPromptInputFieldData(?string $value = null): array
{
return [
'id' => 'additional_prompt_input',
'label' => 'Special requirements',
'inputType' => InputTypeEnum::TEXTAREA,
'required' => false,
'placeholder' => 'What should be the focus of the report?',
'value' => $value,
'dependencies' => [],
'dependsOn' => [],
];
}
public function getCustomReportNameFieldData(?string $value = null): array
{
return [
'id' => 'custom_name',
'label' => 'Custom report name',
'inputType' => InputTypeEnum::TEXT,
'required' => false,
'placeholder' => 'Enter custom name',
'value' => $value,
'dependencies' => [],
'dependsOn' => [],
];
}
// data providers
public function getTeams(): array
{
$teams = $this->teamRepository->getTeamsForKiosk(status: Team::STATUS_ACTIVE);
$teamData = [];
foreach ($teams as $team) {
if (! $team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {
continue;
}
$teamData[] = $this->transformTeam($team);
}
return $teamData;
}
public function getTeamGroups(string $teamUuid): array
{
$data = [];
$team = $this->getTeam($teamUuid);
if ($team !== null) {
$groups = $team->groups()->get();
foreach ($groups as $group) {
$data[] = [
'id' => $group->getUuid(),
'name' => $group->getName(),
];
}
}
return $data;
}
public function getTeamsGroupsOptions(array $filterTeamUuids = []): array
{
$data = [];
$teams = $this->getTeams();
foreach ($teams as $team) {
if (! empty($filterTeamUuids) && ! in_array($team['id'], $filterTeamUuids, true)) {
continue;
}
$data[] = [
'label' => $team['name'],
'groups' => $this->getTeamGroups($team['id']),
];
}
return $data;
}
public function getTeam(string $teamUuid): ?Team
{
return $this->teamRepository->idOrUuid($teamUuid);
}
public function getTeamById(int $teamId): ?Team
{
return $this->teamRepository->find($teamId);
}
public function getGroupsUuids(AutomatedReport $report): array
{
$uuids = [];
$reportGroups = $report->getGroups();
foreach ($reportGroups as $groupId) {
if ($group = $this->groupRepository->find($groupId)) {
$uuids[] = $group->getUuid();
}
}
return $uuids;
}
public function getPlaybookCategoriesUuids(AutomatedReport $report): array
{
$uuids = [];
$playbookCategories = $report->getPlaybookCategories();
foreach ($playbookCategories as $id) {
if ($category = $this->playbookCategoryRepository->find($id)) {
$uuids[] = $category->getUuid();
}
}
return $uuids;
}
public function getDealAtCallStagesUuids(AutomatedReport $report): array
{
$uuids = [];
$reportStages = $report->getDealAtCallStages();
foreach ($reportStages as $id) {
if ($stage = $this->stageRepository->find($id)) {
$uuids[] = $stage->getUuid();
}
}
return $uuids;
}
public function getCurrentDealStagesUuids(AutomatedReport $report): array
{
$uuids = [];
$reportStages = $report->getCurrentDealStages();
foreach ($reportStages as $id) {
if ($stage = $this->stageRepository->find($id)) {
$uuids[] = $stage->getUuid();
}
}
return $uuids;
}
public function getUsersUuids(AutomatedReport $report): array
{
return $this->extractUserUuids($report->getRecipients());
}
public function getJiminnyUsersUuids(AutomatedReport $report): array
{
return $this->extractUserUuids($report->getJiminnyRecipients());
}
/**
* @param array<string, mixed> $recipients
*/
private function extractUserUuids(array $recipients): array
{
$userIds = $recipients['users'] ?? [];
return collect($userIds)
->map(fn ($id) => $this->userRepository->find((int) $id))
->filter()
->map(fn (UserContract $user) => $user->getUuid())
->values()
->all();
}
// get mail data
public function getRecipientUsers(AutomatedReport $report): array
{
return $this->buildRecipientUsers($report->getRecipients());
}
private function getJiminnyRecipientUsers(AutomatedReport $report): array
{
return $this->buildRecipientUsers($report->getJiminnyRecipients());
}
/**
* @param array<string, mixed> $recipients
*/
private function buildRecipientUsers(array $recipients): array
{
$userIds = $recipients['users'] ?? [];
return collect($userIds)
->map(fn ($id) => $this->userRepository->find((int) $id))
->filter()
->map(fn (UserContract $user) => [
'email' => $user->getEmailAddress(),
'name' => $user->getName(),
'timezone' => $user->getTimezone()->getName(),
])
->values()
->all();
}
public function getValidRecipientUsers(AutomatedReport $report, bool $includeJiminny = false): array
{
if ($report->isAskJiminnyReport()) {
$recipients = $this->resolveAskJiminnyRecipients($report);
} else {
$recipients = $this->getRecipientUsers($report);
if ($includeJiminny) {
$recipients = array_merge($recipients, $this->getJiminnyRecipientUsers($report));
}
}
$emails = [];
return array_values(array_filter(
$recipients,
static function ($recipient) use (&$emails) {
if (empty($recipient['email']) || in_array($recipient['email'], $emails, true)) {
return false;
}
$emails[] = $recipient['email'];
return true;
}
));
}
private function resolveAskJiminnyRecipients(AutomatedReport $report): array
{
$recipients = [];
$creator = $report->getCreator();
if ($creator !== null) {
$recipients[] = [
'email' => $creator->getEmailAddress(),
'name' => $creator->getName(),
'timezone' => $creator->getTimezone()->getName(),
];
}
return array_merge(
$recipients,
$this->buildRecipientUsers($report->getRecipients()),
$this->getGroupRecipientUsers($report),
);
}
private function getGroupRecipientUsers(AutomatedReport $report): array
{
$users = [];
foreach ($report->getGroups() as $groupId) {
$group = $this->groupRepository->find($groupId);
if ($group === null) {
continue;
}
foreach ($group->getMembers() as $member) {
$users[] = [
'email' => $member->getEmailAddress(),
'name' => $member->getName(),
'timezone' => $member->getTimezone()->getName(),
];
}
}
return $users;
}
public function getReportTypeName(AutomatedReportResult $report): string
{
$type = $report->getReport()->getType();
$getType = $this->transformReportType($type);
return $getType['name'];
}
public function getReportPeriodName(AutomatedReportResult $report): string
{
$from = $report->getFromDate();
$to = $report->getToDate();
$frequency = $report->getReport()->getFrequency();
if ($from === null || $to === null) {
if (! $report->getReport()->isAskJiminnyReport()) {
$invalidPeriod = $from === null ? 'from' : 'to';
throw new ApplicationException('Report period is invalid: ' . $invalidPeriod);
}
$period = $this->calculateFromAndToDatePeriod($frequency);
$from = $period['fromDate'];
$to = $period['toDate'];
}
return $this->formatReportPeriodName($frequency, $from, $to);
}
private function formatReportPeriodName(string $frequency, Carbon $from, Carbon $to): string
{
$fromYear = $from->format('Y');
$toYear = $to->format('Y');
$differentYears = $fromYear !== $toYear;
switch ($frequency) {
case self::FREQUENCY_DAILY:
return $from->format('j M Y');
case self::FREQUENCY_QUARTERLY:
// 'Jan-Mar 2025' or 'Nov 2024-Jan 2025' if years differ
$startMonth = $from->format('M');
$endMonth = $to->copy()->subMonth();
$endMonthName = $endMonth->format('M');
$endMonthYear = $endMonth->format('Y');
if ($differentYears) {
return "{$startMonth} {$fromYear} - {$endMonthName} {$endMonthYear}";
}
return "{$startMonth} - {$endMonthName} {$toYear}";
case self::FREQUENCY_MONTHLY:
// 'May 2025' - monthly reports are always within the same year
return $from->format('M Y');
case self::FREQUENCY_WEEKLY:
// '4 - 8 Aug 2025', '27 Oct - 3 Nov 2025', or '28 Dec 2024 - 3 Jan 2025' if years differ
$startDay = $from->format('j');
$endDay = $to->format('j');
$startMonth = $from->format('M');
$endMonth = $to->format('M');
if ($differentYears) {
return "{$startDay} {$startMonth} {$fromYear} - {$endDay} {$endMonth} {$toYear}";
}
if ($startMonth !== $endMonth) {
return "{$startDay} {$startMonth} - {$endDay} {$endMonth} {$toYear}";
}
return "{$startDay} - {$endDay} {$endMonth} {$toYear}";
case self::FREQUENCY_ONE_OFF:
// '2 May-31 May 2025' or '15 Dec 2024-15 Jan 2025' if years differ
$startDay = $from->format('j');
$startMonth = $from->format('M');
$endDay = $to->format('j');
$endMonth = $to->format('M');
// If same month and year, use a format like '2-31 May 2025'
if ($startMonth === $endMonth && ! $differentYears) {
return "{$startDay} - {$endDay} {$startMonth} {$toYear}";
}
// If different years, include both years
if ($differentYears) {
return "{$startDay} {$startMonth} {$fromYear} - {$endDay} {$endMonth} {$toYear}";
}
// Same year but different months
return "{$startDay} {$startMonth} - {$endDay} {$endMonth} {$toYear}";
default:
// Default format for unknown frequencies
return $from->format('j M Y') . ' - ' . $to->format('j M Y');
}
}
public function getReportTeamsName(AutomatedReportResult $report): string
{
$groups = $report->getGroups();
if (empty($groups)) {
return 'All';
}
// Get group names from repository
$groupNames = [];
foreach ($groups as $groupId) {
$group = $this->groupRepository->find($groupId);
if ($group) {
$groupNames[] = $group->getName();
}
}
if (count($groupNames) === 1) {
// Single team format
$teamsName = $groupNames[0];
} else {
// Multiple teams format
$teamsName = implode(', ', $groupNames);
}
return $teamsName;
}
public function getReportFileName(AutomatedReportResult $report): string
...
|
[{"role":"AXButton","text" [{"role":"AXButton","text":"Project: faVsco.js, menu","depth":5,"help_text":"~/jiminny/app","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"#11894 on JY-18909-automated-reports-ask-jiminny, menu","depth":5,"help_text":"Pull request #11894 exists for current branch JY-18909-automated-reports-ask-jiminny","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Start Listening for PHP Debug Connections","depth":5,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"AutomatedReportsCommandTest","depth":6,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Run 'AutomatedReportsCommandTest'","depth":6,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Debug 'AutomatedReportsCommandTest'","depth":6,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"More Actions","depth":6,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JetBrains AI","depth":5,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Search Everywhere","depth":5,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"IDE and Project Settings","depth":5,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Execute","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Explain Plan","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Browse Query History","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"View Parameters","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Open Query Execution Settings…","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"In-Editor Results","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Tx: Auto","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Cancel Running Statements","depth":4,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Playground","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"jiminny","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.088194445,"height":0.027777778},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"16","depth":4,"role_description":"text"},{"role":"AXStaticText","text":"13","depth":4,"role_description":"text"},{"role":"AXStaticText","text":"13","depth":4,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"SELECT * FROM teams WHERE id = 1;\n\nselect * from crm_layouts where crm_configuration_id = 39;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 283;\nSELECT * FROM crm_fields WHERE id = 2234;\nSELECT * FROM crm_field_values WHERE crm_field_id = 2234;\n\nselect * from crm_profiles where user_id = 143;\n\nselect * from record_types where crm_configuration_id = 39; # 0121K000001MHElQAO,0121K000001MHEqQAO\nselect * from business_processes where crm_configuration_id = 39;\n# 01941000000H669AAC, 01941000000H66JAAS\n\nselect * from record_type_field_values\n where record_type_id IN (24);\n\nselect * from crm_field_values where id IN (2730);\n\nselect * from crm_configurations where id = 39;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 1\nand sa.provider = 'salesforce'; #1035\n\n\nselect * from users where team_id = 1; # 222 group 3\nSELECT * FROM activities WHERE user_id = 222 order by id desc;\nselect * from sidekick_settings where team_id = 1;\nselect * from teams where id = 1;\nselect * from team_features where team_id = 1;\n\nselect * from activities where crm_configuration_id = 2\nand provider = 'ms-teams' and id = 608765;\n\nSELECT * FROM activities WHERE crm_configuration_id = 2 and crm_provider_id = '59523413338';\n\nselect * from sidekick_settings where team_id = 2;\n\nSELECT * FROM activities WHERE id = 608660;\nselect * from activity_summary_logs where activity_id = 608660;\nselect * from ai_prompts where transcription_id = 11214;\n\n# ********************************************************************************************************\nSELECT * FROM activities WHERE uuid_to_bin('ed78a437-2804-450e-ab2f-56ab1c641346') = uuid;\n# id: 608818, crm: 59628809737\nSELECT * FROM activities WHERE uuid_to_bin('36b06e55-afdd-4782-8dee-c624cd0af191') = uuid;\n# id: 608821, crm: 59632069252\nSELECT ce.start_time, ce.end_time, a.id, a.uuid, crm_provider_id, calendar_event_id, title,\nplaybook_category_id, user_id, lead_id, contact_id, account_id, opportunity_id,\nscheduled_start_time, scheduled_end_time, actual_start_time, actual_end_time, a.created_at\nFROM activities a\njoin calendar_events ce on a.calendar_event_id = ce.id\nWHERE a.id IN (608818, 608821);\n\nselect * from users where team_id = 1;\nselect * from team_settings where team_id = 1;\nselect * from crm_profiles where crm_configuration_id = 39 order by user_id;\n\nselect * from team_features where team_id = 1;\n\nselect * from users where team_id = 2;\n\nSELECT * FROM activities WHERE uuid_to_bin('ec7647e9-5225-458b-b475-f31aa2769204') = uuid; # 612639\n# Preslava N. Ivanova, grou id 3\n\nSELECT * FROM opportunities WHERE uuid_to_bin('a2928fe5-aec5-46cb-85d9-7654c89e46a6') = uuid;\n\nselect * from activities where opportunity_id = 344 and actual_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00';\n\nselect\n a.id,\n a.type,\n a.scheduled_start_time,\n a.actual_start_time,\n a.created_at,\n a.opportunity_id,\n a.status\nFROM activities a\nWHERE opportunity_id = 344\nand status IN ('completed', 'received', 'delivered')\nand (\n (a.actual_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00')\nOR (a.created_at between '2024-10-11 00:00:00' and '2024-10-12 00:00:00')\nOR (a.scheduled_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00'))\n;\n\nSELECT * FROM users WHERE id = 222;\n\nSELECT * FROM crm_profiles WHERE user_id = 222;\nselect * from crm_layouts where crm_configuration_id = 39;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 281;\n\nselect * from group_deal_risk_types;\n\nselect * from opportunities where team_id = 1;\n\nSELECT * FROM opportunities WHERE id = 315;\nSELECT * FROM crm_field_data WHERE object_id = 315;\nselect * from crm_field_data where object_id = 260;\n\nselect * from generic_ai_prompts where subject_id = 315;\n\nselect * from teams; # 36, 21, 121, james.graham@bullhorn.jiminny.com\nSELECT * FROM social_accounts WHERE sociable_id = 121 and provider = 'bullhorn';\n\n# ************************************************************************************\nselect * from teams where id = 1;\nselect * from crm_configurations where id = 39;\nselect * from users where team_id = 1;\nselect u.email, cp.* from users u\njoin crm_profiles cp on u.id = cp.user_id\nwhere u.team_id = 1;\n# 1 - 00541000004281rAAA\n# 204 - 0052g000003freeAAA\n# 429 - 0052g000003qGOiAAM\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 1\nand sa.provider = 'salesforce';\n\nselect * from activities where type = 'softphone'\nand created_at > '2024-12-11 15:24:36' order by id desc;\n\nselect * from activity_providers where team_id = 1;\nselect * from activity_provider_users where activity_provider_id = 328;\n\nselect * from opportunities where crm_configuration_id = 39\nAND account_id = 178 AND is_closed = false\norder by created_at DESC;\n\nselect * from contacts where id = 3952;\nselect * from accounts where id = 178;\n\n# ************************************************************************************\nselect * from teams where id = 36;\nselect * from crm_configurations where id = 21;\nselect * from users where team_id = 36;\nselect u.email, cp.* from users u\njoin crm_profiles cp on u.id = cp.user_id\nwhere u.team_id = 36;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 36\nand sa.provider = 'bullhorn';\n\nselect * from social_accounts where id = 348;\nUPDATE social_accounts SET\nprovider_user_token = '21442_6802599_91:41179a58-21e7-4d7c-ad58-56bb666b2f65',\nprovider_refresh_token = '21442_6802599_91:01c6b335-3f2a-42e4-85ff-8a08fa65fceb',\nexpires = 1733998131,\nstate = 'connected'\nWHERE id = 348;\n\n# ************************************************************************************\nselect * from teams where id = 31;\nselect * from crm_configurations where id = 18;\n\nselect * from users where team_id = 31; # 257\nselect u.email, cp.* from users u\njoin crm_profiles cp on u.id = cp.user_id\nwhere u.team_id = 31;\n\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 31\nand sa.provider = 'close';\n\nselect * from contacts where crm_configuration_id = 18;\n\n# ********************** NEPTUNE **************************************************************\nselect * from teams;\nselect * from users where id IN (1030, 1035, 1052);\nselect * from crm_configurations;\n\nselect * from users where team_id = 65; # 257\nselect * from team_settings where team_id = 65; # 257\nselect * from invitations where team_id = 65; # 257\nselect * from users where email = 'integration-account@jiminny.com'; # 257\nselect u.email, cp.* from users u\njoin crm_profiles cp on u.id = cp.user_id\nwhere u.team_id = 65;\n\nselect * from crm_configurations where id = 53;\nselect * from accounts where crm_configuration_id = 53 order by id desc;\nselect * from leads where crm_configuration_id = 53 order by id desc;\nselect * from contacts where crm_configuration_id = 53 order by id desc;\nselect * from opportunities where crm_configuration_id = 53 order by id desc;\nselect * from crm_profiles where crm_configuration_id = 53 order by id desc;\nselect * from crm_fields where crm_configuration_id = 53 order by id desc;\nselect * from crm_field_values where crm_field_id = 3341 order by id desc;\nselect * from crm_layouts where crm_configuration_id = 53 order by id desc;\nselect * from stages where crm_configuration_id = 53 order by id desc;\n\n\nselect * from crm_profiles where crm_configuration_id = 13;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 65\nand sa.provider = 'integration-app';\n\nselect * from contacts where crm_configuration_id = 13;\n\nselect * from social_accounts where sociable_id = 283;\n\nSELECT * FROM opportunities WHERE crm_provider_id = '006O400000E9bzeIAB';\n\nselect * from activity_providers where team_id = 65;\nSELECT * FROM activities WHERE crm_configuration_id IN (51, 52, 53);\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 65\n;\n\n# ***************************** STAGING ********************************************\nSELECT * FROM teams;\nSELECT * FROM teams WHERE id = 88;\nSELECT * FROM teams WHERE id = 89;\nselect * from team_settings where team_id = 89;\nSELECT * FROM users WHERE team_id = 89;\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 89;\n\nselect * from users;\nSELECT * FROM social_accounts WHERE sociable_id = 1761;\nSELECT * FROM crm_configurations WHERE id = 70;\nselect * from accounts where crm_configuration_id = 70 order by id desc;\nselect * from leads where crm_configuration_id = 70 order by id desc;\nselect * from contacts where crm_configuration_id = 70 order by id desc;\nselect * from opportunities where crm_configuration_id = 70 order by id desc;\nselect * from crm_profiles where crm_configuration_id = 70 order by id desc;\nselect * from crm_fields where crm_configuration_id = 70 order by id desc;\nselect * from crm_field_values where crm_field_id = 3536 order by id desc;\nselect * from crm_layouts where crm_configuration_id = 70 order by id desc;\nselect * from stages where crm_configuration_id = 70 order by id desc;\nselect * from business_processes where crm_configuration_id = 70 order by id desc;\nselect * from business_process_stages where business_process_id = 34;\n\nselect * from contacts where id = 10468;\n\nselect * from crm_layouts where crm_configuration_id = 70;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 388;\nSELECT * FROM crm_fields WHERE id IN (3533,3534,3535);\n\nselect * from activities where crm_configuration_id = 70\nand (account_id IS NOT NULL or lead_id IS NOT NULL or contact_id IS NOT NULL or opportunity_id IS NOT NULL) order by id desc;\n\nSELECT * FROM activities WHERE uuid_to_bin('2e10b60f-8a61-41c5-a3d4-28835353dc65') = uuid;\nSELECT * FROM activities where crm_configuration_id = 69 ;\n\nSELECT * FROM users WHERE email LIKE '%jiminny_web_sa2@jiminny.com%';\nSELECT * FROM activities WHERE uuid_to_bin('5a150c93-40fc-42ec-b3bd-c1d328e09f6e') = uuid;\nSELECT * FROM opportunities WHERE id = 385;\n\nselect * from participants p\njoin activities a on p.activity_id = a.id\nwhere a.crm_configuration_id = 70\nand (p.lead_id IS NOT NULL or p.contact_id IS NOT NULL);\nSELECT * FROM participants WHERE id = 1013638;\n\nselect * from teams where id = 90;\nselect * from users where team_id = 90;\nselect * from social_accounts where social_accounts.sociable_id IN (1960,1760);\nSELECT * FROM crm_profiles WHERE crm_configuration_id = 71;\nselect * from invitations where team_id = 90;\n\nselect * from crm_configurations where id = 71;\nselect * from accounts where crm_configuration_id = 71 order by id desc;\nselect * from leads where crm_configuration_id = 71 order by id desc;\nselect * from contacts where crm_configuration_id = 71 order by id desc;\nselect * from opportunities where crm_configuration_id = 71 order by id desc;\nselect * from crm_profiles where crm_configuration_id = 71 order by id desc;\nselect * from crm_fields where crm_configuration_id = 71 order by id desc;\nselect * from crm_field_values where crm_field_id = 3341 order by id desc;\nselect * from crm_layouts where crm_configuration_id = 71 order by id desc;\nselect * from stages where crm_configuration_id = 71 order by id desc;\n\nselect * from users order by secondary_email desc;\nselect u.id, u.email, u.status, sa.id, sa.provider_user_id from social_accounts sa\n join users u on sa.sociable_id = u.id\nwhere sa.provider = 'google' and u.email LIKE 'aneliya%';\n\nselect * from failed_jobs order by id desc;\n\nselect * from users where email = 'ben.allwright@learningpeople.co.uk' or secondary_email = 'ben.allwright@learningpeople.co.uk';\n\nselect * from teams;\nSELECT * FROM crm_profiles WHERE crm_configuration_id = 39;\nSELECT * FROM crm_fields WHERE crm_configuration_id = 39 and object_type = 'task';\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 1\nand sa.provider = 'salesforce';\n\n# ************************************************************************************\nSELECT * FROM activities WHERE uuid_to_bin('c38b3895-fd0f-4b1f-9fb2-c170dba137c6') = uuid;\nSELECT * FROM crm_configurations WHERE id = 70;\n\nselect * from teams where id = 1;\nselect * from groups where team_id = 1;\nselect * from users where team_id = 1;\n\nselect o.id, o.name,o.close_date, u.id, u.name, u.group_id, r.id, r.display_name, g.name, g.scope from opportunities o\njoin users u on o.user_id = u.id\njoin groups g on u.group_id = g.id\njoin role_user ru on u.id = ru.user_id\njoin roles r on ru.role_id = r.id\nwhere o.crm_configuration_id = 39 and close_date > '2024-01-01 00:00:00';\n\nselect * from role_user where user_id = 143;\nselect * from roles;\n\nselect * from role_user;\nselect * from groups where id = 9;\nselect * from scope_groups where group_id = 9;\n\n# ************************************************************************************\nselect * from teams where id = 36;\nselect * from crm_configurations;\nSELECT * FROM social_accounts WHERE sociable_id = 121;\n\nhttps://crmsandbox.zoho.com/crm/jiminnyw4/tab/Leads/4776201000005049105\nhttps://crmsandbox.zoho.com/crm/\n\nhttps://crm.zoho.com/crm/org3469620/tab/Leads/230045000229559080\n https://crm.zoho.com/crm/\n org3469620\n\nSELECT * FROM activities WHERE uuid_to_bin('03382d20-c8bc-48e7-a3d4-90b52fa5ceab') = uuid;\n\nselect * from users where email LIKE \"%mobile_automation_%\";\nselect * from social_accounts where sociable_id IN (2228);\nselect * from crm_profiles where user_id IN (2222,2223,2226,2227);\n\nselect * from teams order by id desc;\nSELECT * FROM users WHERE id = 2229;\nSELECT * FROM crm_profiles WHERE user_id = 2229;\nselect * from opportunities where crm_configuration_id = 88;\nselect * from crm_fields where crm_configuration_id = 88;\nselect * from crm_profiles where crm_configuration_id = 88;\n\nSELECT * FROM teams WHERE id = 1;\n\nSELECT * FROM users WHERE id = 143;\nSELECT * FROM users WHERE uuid_to_bin('fde193d3-06a2-4e1a-8895-62b94039215d') = uuid;\nSELECT * FROM teams WHERE uuid_to_bin('73385071-a756-42ae-9c73-8b53f2309467') = uuid;\n\nhttps://app.staging.jiminny.com/ondemand?\n min_duration=1\n &\n only_recorded=1\n &\n user_id%5B%5D=641f1acb-16b8-42d1-8726-df52979dad0e\n &\n sequence_number=2\n\n select * from users where team_id = 1 and email like '%stoyan%'\n\nselect * from coaching_feedbacks;\n\nselect * from teams;\nSELECT * FROM users WHERE team_id = 36;\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 19\nand sa.provider = 'pipedrive';\n\nselect * from users where id = 143;\n\nSELECT * FROM users WHERE uuid_to_bin('73180eeb-33de-4065-977d-ccbe0e6c94fc') = uuid;\nSELECT * FROM teams WHERE uuid_to_bin('73180eeb-33de-4065-977d-ccbe0e6c94fc') = uuid;\nSELECT * FROM activity_shares WHERE uuid_to_bin('73180eeb-33de-4065-977d-ccbe0e6c94fc') = uuid;\n\nselect * from users where team_id = 2;\nselect * from activities where crm_configuration_id = 39\nand activities.scheduled_start_time BETWEEN '2025-04-09 00:00:00' AND '2025-04-09 23:59:59'\nAND user_id = 143\norder by id desc;\n\n# ************************************************************************************\nselect * from teams where id = 142; # 2312, 126\nselect * from team_settings;\nselect * from users where team_id = 142; # 21642\nSELECT * FROM social_accounts WHERE sociable_id = 21642;\nSELECT * FROM crm_profiles cp join users u ON u.id = cp.user_id WHERE team_id = 142;\nselect * from crm_profiles where id IN (93);\nselect * from invitations;\nselect * from team_features where team_id = 1;\n\nSELECT * FROM crm_configurations WHERE id = 126;\nselect * from accounts where crm_configuration_id = 126 order by id desc;\nselect * from leads where crm_configuration_id = 126 order by id desc;\nselect * from contacts where crm_configuration_id = 126 order by id desc;\nselect * from opportunities where crm_configuration_id = 126 order by id desc;\nselect * from crm_profiles where crm_configuration_id = 126 order by id desc;\nselect * from crm_fields where crm_configuration_id = 126 # 11060\n# and type IN ('picklist', 'status')\n# and object_type = 'task'\norder by id desc;\n# 5731,5732,5733\nselect DISTINCT crm_field_id from crm_field_values where crm_field_id IN (11151,12239,12215,12185,12175,12165,12144,12137,12127,12109,12107,12105,12103,12092,12037,12005,12003,11987,11969,11958,11951,11942,11931,11924,11921,11917,11915,11901,11893,11883,11872,11870,11868,11866,11839,11833,11821,11793,11780,11777,11769,11757,11737,11735,11656,11645,11638,11629,11618,11611,11602,11591,11584,11581,11558,11544,11543,11534,11532,11529,11527,11503,11497,11493,11488,11470,11468,11457,11455,11397,11387,11372,11363,11348,11323,11318,11309,11301,11300,11292,11290,11286,11284,11256,11252,11242,11237,11233,11219,11176,11160) order by id desc;\nselect * from crm_layouts where crm_configuration_id = 126 order by id desc;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id in (300,299,298);\nselect * from stages where crm_configuration_id = 126 order by id desc;\nselect * from business_processes where crm_configuration_id = 126 order by id desc;\nselect * from business_process_stages where business_process_id IN (76,75,74,73);\nselect * from playbooks where team_id = 142;\nselect * from playbook_layouts where playbook_id IN (108);\nSELECT * FROM playbook_categories WHERE playbook_id IN (108);\n\nselect * from teams where id = 130;\nSELECT * FROM social_accounts WHERE sociable_id = 2291;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 2\nand sa.provider = 'hubspot';\n\nSELECT * FROM activities\n WHERE crm_configuration_id = 110;\n\nselect * from teams;\nselect * from crm_configurations;\n\nSELECT * FROM activities WHERE id = 628773;\nSELECT * FROM crm_profiles WHERE user_id = 1460;\nSELECT * FROM social_accounts WHERE sociable_id = 2291;\n\nselect * from teams;\nselect ru.*, pr.*, p.* from users u join role_user ru on ru.user_id = u.id\njoin permission_role pr on pr.role_id = ru.role_id\n join permissions p on p.id = pr.permission_id\nwhere team_id = 495 and p.name IN ('dial');\n\nselect * from teams where id = 145;\nselect * from crm_configurations where id = 129;\nselect * from social_accounts where sociable_id = 2317;\nSELECT * FROM activities WHERE uuid_to_bin('8dbab184-a333-4268-ad57-fb41f8d53a9a') = uuid;\n\nselect * from teams where id = 1;\nSELECT * FROM crm_layouts WHERE crm_configuration_id = 39;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 280;\nSELECT * FROM crm_layout_entities WHERE id = 5507;\nSELECT * FROM crm_fields WHERE crm_configuration_id = 39 and object_type IN ('event');\n\nselect * from teams;\nselect * from activities where crm_configuration_id = 14;\n\nSELECT * FROM social_accounts where provider = 'copper';\n\nselect * from activities where id = 628467;\nselect * from participants where activity_id = 628467;\n\nSELECT * FROM contacts WHERE id = 3969;\nSELECT * FROM accounts WHERE id = 177;\n\nSELECT * FROM activities WHERE uuid_to_bin('4eb54c77-cfa3-2bd4-84a7-9ed46a21c988') = uuid;\n\n# ********************* BH\nselect * from teams where id = 36;\nSELECT * FROM crm_configurations WHERE id = 21;\nselect * from activities where crm_configuration_id = 21 and id = 607901;\nselect * from activities where crm_configuration_id = 21;\n\nselect * roles;\nselect * from permissions;\nselect * from permission_role where permission_id = 226;\n\nselect * from migrations order by id desc;\n\n# mercury\n# neptune\n# earth\n\nselect * from teams;\nselect * from teams where id = 19;\nselect * from teams where id = 27;\nselect * from users where team_id = 27;\nSELECT * FROM crm_configurations WHERE id = 42;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 19\nand sa.provider = 'pipedrive';\n\nselect * from activities where id = 631461;\nSELECT * FROM crm_field_values WHERE crm_field_id = 180;\n\nselect * from teams where id = 2;\nSELECT * FROM social_accounts WHERE sociable_id = 89;\n\nSELECT * FROM activities WHERE uuid_to_bin('ba0c029a-bc14-4e17-8603-64174acebcbb') = uuid; # 634273\nselect * from activity_summary_logs where activity_id = 634273;\n\nselect * from sidekick_settings where team_id = 2;\n\nselect * from teams; # 2, 2\nSELECT * FROM crm_configurations WHERE team_id = 2; # 2\nselect * from team_features where team_id = 2;\nselect * from features;\nSELECT * FROM opportunities WHERE crm_configuration_id = 2 and crm_provider_id = '51317301383';\nSELECT * FROM opportunities WHERE crm_configuration_id = 2 order by id desc;\n\nselect * from automated_reports order by id desc;\nselect * from automated_report_results order by id desc;\nselect * from users where team_id = 1 and id IN (7160, 3248);\nselect * from migrations order by id desc;\n\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 1 and sa.provider = 'salesforce';\n\nselect * from teams where id = 1;\nselect * from groups g JOIN playbooks p on g.playbook_id = p.id where g.team_id = 1;\nselect * from groups where id = 565;\nselect * from playbooks where team_id = 1;\nselect * from playbooks where id = 175;\nselect * from playbook_categories where playbook_id = 175;\nselect * from users where team_id = 1;\nselect * from users where id = 7160;\nselect * from crm_profiles where user_id = 7160;\nselect * from features;\nselect\n *\n# id, uuid, type, provider, playbook_category_id, user_id, lead_id, contact_id, account_id, opportunity_id, stage_id,\n# crm_configuration_id, crm_provider_id, transcription_id, status\nfrom activities where crm_configuration_id = 1 and type = 'conference'\n# and crm_provider_id IS NOT NULL\nand provider != 'uploader' and actual_start_time IS NOT NULL\nORDER by id desc;\nselect * from activities where id = 54747783; # 00UO400000pCzojMAC\n\nselect p.id, p.activity_type, pc.id, pc.name\nFROM playbooks p\njoin playbook_categories pc on p.id = pc.playbook_id\nwhere p.team_id = 1 and p.activity_type = 'event';\n\nSELECT * FROM crm_fields WHERE crm_configuration_id = 1 and object_type = 'event';\nSELECT * FROM crm_field_values WHERE crm_field_id = 4;\n\nselect * from crm_layouts cl join playbook_layouts pl on cl.id = pl.layout_id\nwhere crm_configuration_id = 1 and pl.playbook_id = 175;\n\nselect * from teams;\nSELECT r.* FROM automated_reports r\njoin teams t on r.team_id = t.id\nWHERE r.frequency = 'daily'\n and r.status = 1\nAND t.status = 'active'\nAND (r.expires_at >= now() OR r.expires_at IS NULL);\n\nselect * from automated_report_results where report_id IN (18, 33);\n\nselect * from activity_searches where id = 10932;\nselect * from activity_search_filters where activity_search_id = 10932;\nselect * from automated_reports;\nselect * from automated_report_results where report_id IN (34, 35);","depth":4,"value":"SELECT * FROM teams WHERE id = 1;\n\nselect * from crm_layouts where crm_configuration_id = 39;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 283;\nSELECT * FROM crm_fields WHERE id = 2234;\nSELECT * FROM crm_field_values WHERE crm_field_id = 2234;\n\nselect * from crm_profiles where user_id = 143;\n\nselect * from record_types where crm_configuration_id = 39; # 0121K000001MHElQAO,0121K000001MHEqQAO\nselect * from business_processes where crm_configuration_id = 39;\n# 01941000000H669AAC, 01941000000H66JAAS\n\nselect * from record_type_field_values\n where record_type_id IN (24);\n\nselect * from crm_field_values where id IN (2730);\n\nselect * from crm_configurations where id = 39;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 1\nand sa.provider = 'salesforce'; #1035\n\n\nselect * from users where team_id = 1; # 222 group 3\nSELECT * FROM activities WHERE user_id = 222 order by id desc;\nselect * from sidekick_settings where team_id = 1;\nselect * from teams where id = 1;\nselect * from team_features where team_id = 1;\n\nselect * from activities where crm_configuration_id = 2\nand provider = 'ms-teams' and id = 608765;\n\nSELECT * FROM activities WHERE crm_configuration_id = 2 and crm_provider_id = '59523413338';\n\nselect * from sidekick_settings where team_id = 2;\n\nSELECT * FROM activities WHERE id = 608660;\nselect * from activity_summary_logs where activity_id = 608660;\nselect * from ai_prompts where transcription_id = 11214;\n\n# ********************************************************************************************************\nSELECT * FROM activities WHERE uuid_to_bin('ed78a437-2804-450e-ab2f-56ab1c641346') = uuid;\n# id: 608818, crm: 59628809737\nSELECT * FROM activities WHERE uuid_to_bin('36b06e55-afdd-4782-8dee-c624cd0af191') = uuid;\n# id: 608821, crm: 59632069252\nSELECT ce.start_time, ce.end_time, a.id, a.uuid, crm_provider_id, calendar_event_id, title,\nplaybook_category_id, user_id, lead_id, contact_id, account_id, opportunity_id,\nscheduled_start_time, scheduled_end_time, actual_start_time, actual_end_time, a.created_at\nFROM activities a\njoin calendar_events ce on a.calendar_event_id = ce.id\nWHERE a.id IN (608818, 608821);\n\nselect * from users where team_id = 1;\nselect * from team_settings where team_id = 1;\nselect * from crm_profiles where crm_configuration_id = 39 order by user_id;\n\nselect * from team_features where team_id = 1;\n\nselect * from users where team_id = 2;\n\nSELECT * FROM activities WHERE uuid_to_bin('ec7647e9-5225-458b-b475-f31aa2769204') = uuid; # 612639\n# Preslava N. Ivanova, grou id 3\n\nSELECT * FROM opportunities WHERE uuid_to_bin('a2928fe5-aec5-46cb-85d9-7654c89e46a6') = uuid;\n\nselect * from activities where opportunity_id = 344 and actual_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00';\n\nselect\n a.id,\n a.type,\n a.scheduled_start_time,\n a.actual_start_time,\n a.created_at,\n a.opportunity_id,\n a.status\nFROM activities a\nWHERE opportunity_id = 344\nand status IN ('completed', 'received', 'delivered')\nand (\n (a.actual_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00')\nOR (a.created_at between '2024-10-11 00:00:00' and '2024-10-12 00:00:00')\nOR (a.scheduled_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00'))\n;\n\nSELECT * FROM users WHERE id = 222;\n\nSELECT * FROM crm_profiles WHERE user_id = 222;\nselect * from crm_layouts where crm_configuration_id = 39;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 281;\n\nselect * from group_deal_risk_types;\n\nselect * from opportunities where team_id = 1;\n\nSELECT * FROM opportunities WHERE id = 315;\nSELECT * FROM crm_field_data WHERE object_id = 315;\nselect * from crm_field_data where object_id = 260;\n\nselect * from generic_ai_prompts where subject_id = 315;\n\nselect * from teams; # 36, 21, 121, james.graham@bullhorn.jiminny.com\nSELECT * FROM social_accounts WHERE sociable_id = 121 and provider = 'bullhorn';\n\n# ************************************************************************************\nselect * from teams where id = 1;\nselect * from crm_configurations where id = 39;\nselect * from users where team_id = 1;\nselect u.email, cp.* from users u\njoin crm_profiles cp on u.id = cp.user_id\nwhere u.team_id = 1;\n# 1 - 00541000004281rAAA\n# 204 - 0052g000003freeAAA\n# 429 - 0052g000003qGOiAAM\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 1\nand sa.provider = 'salesforce';\n\nselect * from activities where type = 'softphone'\nand created_at > '2024-12-11 15:24:36' order by id desc;\n\nselect * from activity_providers where team_id = 1;\nselect * from activity_provider_users where activity_provider_id = 328;\n\nselect * from opportunities where crm_configuration_id = 39\nAND account_id = 178 AND is_closed = false\norder by created_at DESC;\n\nselect * from contacts where id = 3952;\nselect * from accounts where id = 178;\n\n# ************************************************************************************\nselect * from teams where id = 36;\nselect * from crm_configurations where id = 21;\nselect * from users where team_id = 36;\nselect u.email, cp.* from users u\njoin crm_profiles cp on u.id = cp.user_id\nwhere u.team_id = 36;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 36\nand sa.provider = 'bullhorn';\n\nselect * from social_accounts where id = 348;\nUPDATE social_accounts SET\nprovider_user_token = '21442_6802599_91:41179a58-21e7-4d7c-ad58-56bb666b2f65',\nprovider_refresh_token = '21442_6802599_91:01c6b335-3f2a-42e4-85ff-8a08fa65fceb',\nexpires = 1733998131,\nstate = 'connected'\nWHERE id = 348;\n\n# ************************************************************************************\nselect * from teams where id = 31;\nselect * from crm_configurations where id = 18;\n\nselect * from users where team_id = 31; # 257\nselect u.email, cp.* from users u\njoin crm_profiles cp on u.id = cp.user_id\nwhere u.team_id = 31;\n\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 31\nand sa.provider = 'close';\n\nselect * from contacts where crm_configuration_id = 18;\n\n# ********************** NEPTUNE **************************************************************\nselect * from teams;\nselect * from users where id IN (1030, 1035, 1052);\nselect * from crm_configurations;\n\nselect * from users where team_id = 65; # 257\nselect * from team_settings where team_id = 65; # 257\nselect * from invitations where team_id = 65; # 257\nselect * from users where email = 'integration-account@jiminny.com'; # 257\nselect u.email, cp.* from users u\njoin crm_profiles cp on u.id = cp.user_id\nwhere u.team_id = 65;\n\nselect * from crm_configurations where id = 53;\nselect * from accounts where crm_configuration_id = 53 order by id desc;\nselect * from leads where crm_configuration_id = 53 order by id desc;\nselect * from contacts where crm_configuration_id = 53 order by id desc;\nselect * from opportunities where crm_configuration_id = 53 order by id desc;\nselect * from crm_profiles where crm_configuration_id = 53 order by id desc;\nselect * from crm_fields where crm_configuration_id = 53 order by id desc;\nselect * from crm_field_values where crm_field_id = 3341 order by id desc;\nselect * from crm_layouts where crm_configuration_id = 53 order by id desc;\nselect * from stages where crm_configuration_id = 53 order by id desc;\n\n\nselect * from crm_profiles where crm_configuration_id = 13;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 65\nand sa.provider = 'integration-app';\n\nselect * from contacts where crm_configuration_id = 13;\n\nselect * from social_accounts where sociable_id = 283;\n\nSELECT * FROM opportunities WHERE crm_provider_id = '006O400000E9bzeIAB';\n\nselect * from activity_providers where team_id = 65;\nSELECT * FROM activities WHERE crm_configuration_id IN (51, 52, 53);\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 65\n;\n\n# ***************************** STAGING ********************************************\nSELECT * FROM teams;\nSELECT * FROM teams WHERE id = 88;\nSELECT * FROM teams WHERE id = 89;\nselect * from team_settings where team_id = 89;\nSELECT * FROM users WHERE team_id = 89;\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 89;\n\nselect * from users;\nSELECT * FROM social_accounts WHERE sociable_id = 1761;\nSELECT * FROM crm_configurations WHERE id = 70;\nselect * from accounts where crm_configuration_id = 70 order by id desc;\nselect * from leads where crm_configuration_id = 70 order by id desc;\nselect * from contacts where crm_configuration_id = 70 order by id desc;\nselect * from opportunities where crm_configuration_id = 70 order by id desc;\nselect * from crm_profiles where crm_configuration_id = 70 order by id desc;\nselect * from crm_fields where crm_configuration_id = 70 order by id desc;\nselect * from crm_field_values where crm_field_id = 3536 order by id desc;\nselect * from crm_layouts where crm_configuration_id = 70 order by id desc;\nselect * from stages where crm_configuration_id = 70 order by id desc;\nselect * from business_processes where crm_configuration_id = 70 order by id desc;\nselect * from business_process_stages where business_process_id = 34;\n\nselect * from contacts where id = 10468;\n\nselect * from crm_layouts where crm_configuration_id = 70;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 388;\nSELECT * FROM crm_fields WHERE id IN (3533,3534,3535);\n\nselect * from activities where crm_configuration_id = 70\nand (account_id IS NOT NULL or lead_id IS NOT NULL or contact_id IS NOT NULL or opportunity_id IS NOT NULL) order by id desc;\n\nSELECT * FROM activities WHERE uuid_to_bin('2e10b60f-8a61-41c5-a3d4-28835353dc65') = uuid;\nSELECT * FROM activities where crm_configuration_id = 69 ;\n\nSELECT * FROM users WHERE email LIKE '%jiminny_web_sa2@jiminny.com%';\nSELECT * FROM activities WHERE uuid_to_bin('5a150c93-40fc-42ec-b3bd-c1d328e09f6e') = uuid;\nSELECT * FROM opportunities WHERE id = 385;\n\nselect * from participants p\njoin activities a on p.activity_id = a.id\nwhere a.crm_configuration_id = 70\nand (p.lead_id IS NOT NULL or p.contact_id IS NOT NULL);\nSELECT * FROM participants WHERE id = 1013638;\n\nselect * from teams where id = 90;\nselect * from users where team_id = 90;\nselect * from social_accounts where social_accounts.sociable_id IN (1960,1760);\nSELECT * FROM crm_profiles WHERE crm_configuration_id = 71;\nselect * from invitations where team_id = 90;\n\nselect * from crm_configurations where id = 71;\nselect * from accounts where crm_configuration_id = 71 order by id desc;\nselect * from leads where crm_configuration_id = 71 order by id desc;\nselect * from contacts where crm_configuration_id = 71 order by id desc;\nselect * from opportunities where crm_configuration_id = 71 order by id desc;\nselect * from crm_profiles where crm_configuration_id = 71 order by id desc;\nselect * from crm_fields where crm_configuration_id = 71 order by id desc;\nselect * from crm_field_values where crm_field_id = 3341 order by id desc;\nselect * from crm_layouts where crm_configuration_id = 71 order by id desc;\nselect * from stages where crm_configuration_id = 71 order by id desc;\n\nselect * from users order by secondary_email desc;\nselect u.id, u.email, u.status, sa.id, sa.provider_user_id from social_accounts sa\n join users u on sa.sociable_id = u.id\nwhere sa.provider = 'google' and u.email LIKE 'aneliya%';\n\nselect * from failed_jobs order by id desc;\n\nselect * from users where email = 'ben.allwright@learningpeople.co.uk' or secondary_email = 'ben.allwright@learningpeople.co.uk';\n\nselect * from teams;\nSELECT * FROM crm_profiles WHERE crm_configuration_id = 39;\nSELECT * FROM crm_fields WHERE crm_configuration_id = 39 and object_type = 'task';\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 1\nand sa.provider = 'salesforce';\n\n# ************************************************************************************\nSELECT * FROM activities WHERE uuid_to_bin('c38b3895-fd0f-4b1f-9fb2-c170dba137c6') = uuid;\nSELECT * FROM crm_configurations WHERE id = 70;\n\nselect * from teams where id = 1;\nselect * from groups where team_id = 1;\nselect * from users where team_id = 1;\n\nselect o.id, o.name,o.close_date, u.id, u.name, u.group_id, r.id, r.display_name, g.name, g.scope from opportunities o\njoin users u on o.user_id = u.id\njoin groups g on u.group_id = g.id\njoin role_user ru on u.id = ru.user_id\njoin roles r on ru.role_id = r.id\nwhere o.crm_configuration_id = 39 and close_date > '2024-01-01 00:00:00';\n\nselect * from role_user where user_id = 143;\nselect * from roles;\n\nselect * from role_user;\nselect * from groups where id = 9;\nselect * from scope_groups where group_id = 9;\n\n# ************************************************************************************\nselect * from teams where id = 36;\nselect * from crm_configurations;\nSELECT * FROM social_accounts WHERE sociable_id = 121;\n\nhttps://crmsandbox.zoho.com/crm/jiminnyw4/tab/Leads/4776201000005049105\nhttps://crmsandbox.zoho.com/crm/\n\nhttps://crm.zoho.com/crm/org3469620/tab/Leads/230045000229559080\n https://crm.zoho.com/crm/\n org3469620\n\nSELECT * FROM activities WHERE uuid_to_bin('03382d20-c8bc-48e7-a3d4-90b52fa5ceab') = uuid;\n\nselect * from users where email LIKE \"%mobile_automation_%\";\nselect * from social_accounts where sociable_id IN (2228);\nselect * from crm_profiles where user_id IN (2222,2223,2226,2227);\n\nselect * from teams order by id desc;\nSELECT * FROM users WHERE id = 2229;\nSELECT * FROM crm_profiles WHERE user_id = 2229;\nselect * from opportunities where crm_configuration_id = 88;\nselect * from crm_fields where crm_configuration_id = 88;\nselect * from crm_profiles where crm_configuration_id = 88;\n\nSELECT * FROM teams WHERE id = 1;\n\nSELECT * FROM users WHERE id = 143;\nSELECT * FROM users WHERE uuid_to_bin('fde193d3-06a2-4e1a-8895-62b94039215d') = uuid;\nSELECT * FROM teams WHERE uuid_to_bin('73385071-a756-42ae-9c73-8b53f2309467') = uuid;\n\nhttps://app.staging.jiminny.com/ondemand?\n min_duration=1\n &\n only_recorded=1\n &\n user_id%5B%5D=641f1acb-16b8-42d1-8726-df52979dad0e\n &\n sequence_number=2\n\n select * from users where team_id = 1 and email like '%stoyan%'\n\nselect * from coaching_feedbacks;\n\nselect * from teams;\nSELECT * FROM users WHERE team_id = 36;\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 19\nand sa.provider = 'pipedrive';\n\nselect * from users where id = 143;\n\nSELECT * FROM users WHERE uuid_to_bin('73180eeb-33de-4065-977d-ccbe0e6c94fc') = uuid;\nSELECT * FROM teams WHERE uuid_to_bin('73180eeb-33de-4065-977d-ccbe0e6c94fc') = uuid;\nSELECT * FROM activity_shares WHERE uuid_to_bin('73180eeb-33de-4065-977d-ccbe0e6c94fc') = uuid;\n\nselect * from users where team_id = 2;\nselect * from activities where crm_configuration_id = 39\nand activities.scheduled_start_time BETWEEN '2025-04-09 00:00:00' AND '2025-04-09 23:59:59'\nAND user_id = 143\norder by id desc;\n\n# ************************************************************************************\nselect * from teams where id = 142; # 2312, 126\nselect * from team_settings;\nselect * from users where team_id = 142; # 21642\nSELECT * FROM social_accounts WHERE sociable_id = 21642;\nSELECT * FROM crm_profiles cp join users u ON u.id = cp.user_id WHERE team_id = 142;\nselect * from crm_profiles where id IN (93);\nselect * from invitations;\nselect * from team_features where team_id = 1;\n\nSELECT * FROM crm_configurations WHERE id = 126;\nselect * from accounts where crm_configuration_id = 126 order by id desc;\nselect * from leads where crm_configuration_id = 126 order by id desc;\nselect * from contacts where crm_configuration_id = 126 order by id desc;\nselect * from opportunities where crm_configuration_id = 126 order by id desc;\nselect * from crm_profiles where crm_configuration_id = 126 order by id desc;\nselect * from crm_fields where crm_configuration_id = 126 # 11060\n# and type IN ('picklist', 'status')\n# and object_type = 'task'\norder by id desc;\n# 5731,5732,5733\nselect DISTINCT crm_field_id from crm_field_values where crm_field_id IN (11151,12239,12215,12185,12175,12165,12144,12137,12127,12109,12107,12105,12103,12092,12037,12005,12003,11987,11969,11958,11951,11942,11931,11924,11921,11917,11915,11901,11893,11883,11872,11870,11868,11866,11839,11833,11821,11793,11780,11777,11769,11757,11737,11735,11656,11645,11638,11629,11618,11611,11602,11591,11584,11581,11558,11544,11543,11534,11532,11529,11527,11503,11497,11493,11488,11470,11468,11457,11455,11397,11387,11372,11363,11348,11323,11318,11309,11301,11300,11292,11290,11286,11284,11256,11252,11242,11237,11233,11219,11176,11160) order by id desc;\nselect * from crm_layouts where crm_configuration_id = 126 order by id desc;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id in (300,299,298);\nselect * from stages where crm_configuration_id = 126 order by id desc;\nselect * from business_processes where crm_configuration_id = 126 order by id desc;\nselect * from business_process_stages where business_process_id IN (76,75,74,73);\nselect * from playbooks where team_id = 142;\nselect * from playbook_layouts where playbook_id IN (108);\nSELECT * FROM playbook_categories WHERE playbook_id IN (108);\n\nselect * from teams where id = 130;\nSELECT * FROM social_accounts WHERE sociable_id = 2291;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 2\nand sa.provider = 'hubspot';\n\nSELECT * FROM activities\n WHERE crm_configuration_id = 110;\n\nselect * from teams;\nselect * from crm_configurations;\n\nSELECT * FROM activities WHERE id = 628773;\nSELECT * FROM crm_profiles WHERE user_id = 1460;\nSELECT * FROM social_accounts WHERE sociable_id = 2291;\n\nselect * from teams;\nselect ru.*, pr.*, p.* from users u join role_user ru on ru.user_id = u.id\njoin permission_role pr on pr.role_id = ru.role_id\n join permissions p on p.id = pr.permission_id\nwhere team_id = 495 and p.name IN ('dial');\n\nselect * from teams where id = 145;\nselect * from crm_configurations where id = 129;\nselect * from social_accounts where sociable_id = 2317;\nSELECT * FROM activities WHERE uuid_to_bin('8dbab184-a333-4268-ad57-fb41f8d53a9a') = uuid;\n\nselect * from teams where id = 1;\nSELECT * FROM crm_layouts WHERE crm_configuration_id = 39;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 280;\nSELECT * FROM crm_layout_entities WHERE id = 5507;\nSELECT * FROM crm_fields WHERE crm_configuration_id = 39 and object_type IN ('event');\n\nselect * from teams;\nselect * from activities where crm_configuration_id = 14;\n\nSELECT * FROM social_accounts where provider = 'copper';\n\nselect * from activities where id = 628467;\nselect * from participants where activity_id = 628467;\n\nSELECT * FROM contacts WHERE id = 3969;\nSELECT * FROM accounts WHERE id = 177;\n\nSELECT * FROM activities WHERE uuid_to_bin('4eb54c77-cfa3-2bd4-84a7-9ed46a21c988') = uuid;\n\n# ********************* BH\nselect * from teams where id = 36;\nSELECT * FROM crm_configurations WHERE id = 21;\nselect * from activities where crm_configuration_id = 21 and id = 607901;\nselect * from activities where crm_configuration_id = 21;\n\nselect * roles;\nselect * from permissions;\nselect * from permission_role where permission_id = 226;\n\nselect * from migrations order by id desc;\n\n# mercury\n# neptune\n# earth\n\nselect * from teams;\nselect * from teams where id = 19;\nselect * from teams where id = 27;\nselect * from users where team_id = 27;\nSELECT * FROM crm_configurations WHERE id = 42;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 19\nand sa.provider = 'pipedrive';\n\nselect * from activities where id = 631461;\nSELECT * FROM crm_field_values WHERE crm_field_id = 180;\n\nselect * from teams where id = 2;\nSELECT * FROM social_accounts WHERE sociable_id = 89;\n\nSELECT * FROM activities WHERE uuid_to_bin('ba0c029a-bc14-4e17-8603-64174acebcbb') = uuid; # 634273\nselect * from activity_summary_logs where activity_id = 634273;\n\nselect * from sidekick_settings where team_id = 2;\n\nselect * from teams; # 2, 2\nSELECT * FROM crm_configurations WHERE team_id = 2; # 2\nselect * from team_features where team_id = 2;\nselect * from features;\nSELECT * FROM opportunities WHERE crm_configuration_id = 2 and crm_provider_id = '51317301383';\nSELECT * FROM opportunities WHERE crm_configuration_id = 2 order by id desc;\n\nselect * from automated_reports order by id desc;\nselect * from automated_report_results order by id desc;\nselect * from users where team_id = 1 and id IN (7160, 3248);\nselect * from migrations order by id desc;\n\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 1 and sa.provider = 'salesforce';\n\nselect * from teams where id = 1;\nselect * from groups g JOIN playbooks p on g.playbook_id = p.id where g.team_id = 1;\nselect * from groups where id = 565;\nselect * from playbooks where team_id = 1;\nselect * from playbooks where id = 175;\nselect * from playbook_categories where playbook_id = 175;\nselect * from users where team_id = 1;\nselect * from users where id = 7160;\nselect * from crm_profiles where user_id = 7160;\nselect * from features;\nselect\n *\n# id, uuid, type, provider, playbook_category_id, user_id, lead_id, contact_id, account_id, opportunity_id, stage_id,\n# crm_configuration_id, crm_provider_id, transcription_id, status\nfrom activities where crm_configuration_id = 1 and type = 'conference'\n# and crm_provider_id IS NOT NULL\nand provider != 'uploader' and actual_start_time IS NOT NULL\nORDER by id desc;\nselect * from activities where id = 54747783; # 00UO400000pCzojMAC\n\nselect p.id, p.activity_type, pc.id, pc.name\nFROM playbooks p\njoin playbook_categories pc on p.id = pc.playbook_id\nwhere p.team_id = 1 and p.activity_type = 'event';\n\nSELECT * FROM crm_fields WHERE crm_configuration_id = 1 and object_type = 'event';\nSELECT * FROM crm_field_values WHERE crm_field_id = 4;\n\nselect * from crm_layouts cl join playbook_layouts pl on cl.id = pl.layout_id\nwhere crm_configuration_id = 1 and pl.playbook_id = 175;\n\nselect * from teams;\nSELECT r.* FROM automated_reports r\njoin teams t on r.team_id = t.id\nWHERE r.frequency = 'daily'\n and r.status = 1\nAND t.status = 'active'\nAND (r.expires_at >= now() OR r.expires_at IS NULL);\n\nselect * from automated_report_results where report_id IN (18, 33);\n\nselect * from activity_searches where id = 10932;\nselect * from activity_search_filters where activity_search_id = 10932;\nselect * from automated_reports;\nselect * from automated_report_results where report_id IN (34, 35);","role_description":"text entry area","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.088194445,"height":0.027777778},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"102","depth":4,"role_description":"text"},{"role":"AXStaticText","text":"3","depth":4,"role_description":"text"},{"role":"AXStaticText","text":"34","depth":4,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Services\\Kiosk\\AutomatedReports;\n\nuse Carbon\\CarbonImmutable;\nuse Carbon\\CarbonInterface;\nuse Carbon\\Exceptions\\InvalidFormatException;\nuse DateTime;\nuse DateTimeInterface;\nuse DateTimeZone;\nuse Illuminate\\Contracts\\Bus\\Dispatcher as BusDispatcher;\nuse Illuminate\\Database\\Eloquent\\Builder;\nuse Illuminate\\Support\\Carbon;\nuse Illuminate\\Support\\Collection;\nuse Illuminate\\Support\\Facades\\Log;\nuse Illuminate\\Support\\Facades\\Storage;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinition\\InputTypeEnum;\nuse Jiminny\\Component\\AskAnything\\AskAnythingPromptService;\nuse Jiminny\\Component\\AskAnything\\Dtos\\AskAnythingPromptDto;\nuse Jiminny\\Component\\UrlGenerator\\Webhook;\nuse Jiminny\\Contracts\\Repositories\\PlaybookCategoryRepository;\nuse Jiminny\\Contracts\\Repositories\\TeamRepository;\nuse Jiminny\\Contracts\\Repositories\\UserRepository;\nuse Jiminny\\Exceptions\\ApplicationException;\nuse Jiminny\\Exceptions\\InvalidArgumentException;\nuse Jiminny\\Exceptions\\ModelNotFoundException;\nuse Jiminny\\Jobs\\AutomatedReports\\RequestGenerateReportJob;\nuse Jiminny\\Models\\Activity\\Search;\nuse Jiminny\\Models\\AskAnything\\AskAnythingPrompt;\nuse Jiminny\\Models\\AskAnything\\AskAnythingPromptTarget;\nuse Jiminny\\Models\\AutomatedReport;\nuse Jiminny\\Models\\AutomatedReportResult;\nuse Jiminny\\Models\\Contracts\\UserContract;\nuse Jiminny\\Models\\Feature\\FeatureEnum;\nuse Jiminny\\Models\\Team;\nuse Jiminny\\Models\\User;\nuse Jiminny\\Repositories\\AskAnythingRepository;\nuse Jiminny\\Repositories\\AutomatedReportsRepository;\nuse Jiminny\\Repositories\\GroupRepository;\nuse Jiminny\\Repositories\\SearchRepository;\nuse Jiminny\\Repositories\\StageRepository;\nuse Throwable;\n\nclass AutomatedReportsService\n{\n public const string TYPE_LOSS_ANALYSIS = 'loss_analysis';\n public const string TYPE_ASK_JIMINNY = 'ask_jiminny';\n\n /**\n * Standard report types (used by kiosk for existing automated reports).\n */\n // @TODO this will add filter, however if we need to control feature by FF we need conditional logic\n public const array TYPES = [\n ['id' => 'exec_summary', 'name' => 'Exec Summary'],\n ['id' => 'coaching_profiles', 'name' => 'Coaching Profiles'],\n ['id' => 'product_feedback', 'name' => 'Product Feedback'],\n ['id' => self::TYPE_LOSS_ANALYSIS, 'name' => 'Loss Analysis'],\n// ['id' => 'questions', 'name' => 'Questions'],\n// ['id' => 'statistical_quant', 'name' => 'Statistical Quantitative'],\n ];\n\n public const array ALL_TYPES = [\n ...self::TYPES,\n ['id' => self::TYPE_ASK_JIMINNY, 'name' => 'Ask Jiminny'],\n ];\n\n public const string FREQUENCY_DAILY = 'daily';\n public const string FREQUENCY_WEEKLY = 'weekly';\n public const string FREQUENCY_MONTHLY = 'monthly';\n public const string FREQUENCY_QUARTERLY = 'quarterly';\n public const string FREQUENCY_ONE_OFF = 'one_off';\n\n /**\n * Frequencies for standard (non-Ask Jiminny) reports.\n */\n public const array FREQUENCIES = [\n ['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],\n ['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],\n ['id' => self::FREQUENCY_QUARTERLY, 'name' => 'Quarterly'],\n ['id' => self::FREQUENCY_ONE_OFF, 'name' => 'One-off'],\n ];\n\n /**\n * Frequencies for Ask Jiminny reports.\n */\n public const array ASK_JIMINNY_FREQUENCIES = [\n ['id' => self::FREQUENCY_DAILY, 'name' => 'Daily'],\n ['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],\n ['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],\n ];\n\n public const string MEDIA_TYPE_PDF = 'pdf';\n public const string MEDIA_TYPE_PODCAST = 'podcast';\n public const array MEDIA_TYPES = [self::MEDIA_TYPE_PDF, self::MEDIA_TYPE_PODCAST];\n public const array MEDIA_TYPE_OBJECT_PDF = ['id' => self::MEDIA_TYPE_PDF, 'name' => 'PDF'];\n public const array MEDIA_TYPE_OBJECT_PODCAST = ['id' => self::MEDIA_TYPE_PODCAST, 'name' => 'Podcast'];\n public const array MEDIA_TYPE_OBJECTS = [self::MEDIA_TYPE_OBJECT_PDF, self::MEDIA_TYPE_OBJECT_PODCAST];\n\n public const array CALL_TYPE_CONFERENCE = ['id' => 'conference', 'name' => 'Conference'];\n public const array CALL_TYPE_DIALER = ['id' => 'dialer', 'name' => 'Dialer'];\n public const int SENT_REPORT_AT_HOURS = 5;\n public const string PDF_KEY = 'pdf';\n public const string AUDIO_KEY = 'audio';\n\n private const array ALL_FREQUENCIES = [\n ['id' => self::FREQUENCY_DAILY, 'name' => 'Daily'],\n ['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],\n ['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],\n ['id' => self::FREQUENCY_QUARTERLY, 'name' => 'Quarterly'],\n ['id' => self::FREQUENCY_ONE_OFF, 'name' => 'One-off'],\n ];\n private const string S3_DIR = 'reports';\n private const array FILE_EXTENSIONS_VARIANTS = ['html', 'MD', 'pdf'];\n private const array FILE_PODCAST_EXTENSIONS_VARIANTS = ['json', 'mp3', 'ssml'];\n\n public function __construct(\n private readonly TeamRepository $teamRepository,\n private readonly GroupRepository $groupRepository,\n private readonly UserRepository $userRepository,\n private readonly StageRepository $stageRepository,\n private readonly DealStagesService $dealStagesService,\n private readonly RecipientsService $recipientsService,\n private readonly AutomatedReportsRepository $automatedReportsRepository,\n private readonly Webhook $webhookService,\n private readonly BusDispatcher $dispatcher,\n private readonly ActivityTypeService $activityTypeService,\n private readonly PlaybookCategoryRepository $playbookCategoryRepository,\n private readonly AskAnythingPromptService $askAnythingPromptService,\n private readonly SearchRepository $activitySearchRepository,\n private readonly AskAnythingRepository $askAnythingRepository,\n ) {\n }\n\n public static function getTypes(): array\n {\n $types = self::TYPES;\n\n return array_map(static function ($type) {\n return $type['id'];\n }, $types);\n }\n\n public static function getCallTypes(): array\n {\n return array_map(static function ($callType) {\n return $callType['id'];\n }, [self::CALL_TYPE_CONFERENCE, self::CALL_TYPE_DIALER]);\n }\n\n public static function getFrequencies(): array\n {\n return array_map(static function ($frequency) {\n return $frequency['id'];\n }, self::FREQUENCIES);\n }\n\n // front-facing structure\n public function getReportEnabledFieldData(bool $value = false): array\n {\n return [\n 'id' => 'report_enabled',\n 'label' => '',\n 'inputType' => InputTypeEnum::TOGGLE,\n 'value' => $value,\n ];\n }\n\n // Organizations = Teams\n public function getOrganizationFieldData(?string $value = null, bool $shortVersion = false): array\n {\n $options = $this->getTeams();\n\n if ($shortVersion) {\n return [\n 'id' => 'organization',\n 'label' => 'Organization',\n 'options' => $options,\n ];\n }\n\n return [\n 'id' => 'organization',\n 'label' => 'Organization',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => $options,\n 'value' => $value,\n 'dependencies' => [\n 'teams',\n 'deal_stage_at_call',\n 'current_deal_stage',\n 'recipients',\n ActivityTypeService::PLAYBOOK_CATEGORIES_KEY,\n ],\n 'dependsOn' => [],\n ];\n }\n\n // Teams = Groups\n public function getTeamFieldData(array $options = [], array $value = [], bool $shortVersion = false): array\n {\n if ($shortVersion) {\n return [\n 'id' => 'teams',\n 'label' => 'Team',\n 'options' => $options,\n ];\n }\n\n return [\n 'id' => 'teams',\n 'label' => 'Team',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'required' => false,\n 'placeholder' => 'Select',\n 'options' => $options,\n 'value' => $value, // value should be an array of objects {id, name}\n 'dependencies' => [ActivityTypeService::PLAYBOOK_CATEGORIES_KEY],\n 'dependsOn' => [],\n ];\n }\n\n public function getReportTypeFieldData(?string $value = null, bool $shortVersion = false, ?Team $team = null): array\n {\n $types = [];\n if ($team instanceof Team) {\n if ($team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {\n $types = self::TYPES;\n }\n if ($team->hasFeature(FeatureEnum::ASK_JIMINNY_REPORTS)) {\n $types[] = ['id' => self::TYPE_ASK_JIMINNY, 'name' => 'Ask Jiminny'];\n }\n } else {\n $types = self::TYPES;\n }\n\n if ($shortVersion) {\n return [\n 'id' => 'report_type',\n 'label' => 'Report Type',\n 'options' => $types,\n ];\n }\n\n return [\n 'id' => 'report_type',\n 'label' => 'Report Type',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => $types,\n 'value' => $value,\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getFrequencyFieldData(?string $value = null): array\n {\n return [\n 'id' => 'frequency',\n 'label' => 'Frequency',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => self::FREQUENCIES,\n 'value' => $value,\n 'dependencies' => ['period'],\n 'dependsOn' => [],\n ];\n }\n\n public function getPeriodFieldData(?string $valueStartDate = null, ?string $valueEndDate = null): array\n {\n return [\n 'id' => 'period',\n 'label' => 'Select one-off period',\n 'inputType' => InputTypeEnum::DATE_RANGE,\n 'required' => true,\n 'placeholder' => 'Select',\n 'value' => ['startDate' => $valueStartDate, 'endDate' => $valueEndDate],\n 'queryParams' => [\n 'startDate' => 'start_date_period',\n 'endDate' => 'end_date_period',\n ],\n 'dependencies' => [],\n 'dependsOn' => ['frequency'],\n ];\n }\n\n public function getActivityTypesFieldData(?Team $team = null, array $value = [], array $teamsFilter = []): array\n {\n return $this->activityTypeService->getActivityTypeFieldData(team: $team, value: $value, groupIds: $teamsFilter);\n }\n\n public function getDealStageAtCallFieldData(?Team $team = null, array $value = []): array\n {\n return $this->dealStagesService->getDealStageAtCallFieldData(team: $team, value: $value);\n }\n\n public function getCurrentDealStageFieldData(?Team $team = null, array $value = []): array\n {\n return $this->dealStagesService->getCurrentDealStageFieldData(team: $team, value: $value);\n }\n\n public function getDealValueFieldData(?int $valueMin = null, ?int $valueMax = null): array\n {\n return [\n 'id' => 'deal_value',\n 'label' => 'Deal Value',\n 'inputType' => InputTypeEnum::INTEGER_RANGE,\n 'required' => false,\n 'value' => ['min' => $valueMin, 'max' => $valueMax],\n 'queryParams' => [\n 'min' => 'min_deal_value',\n 'max' => 'max_deal_value',\n ],\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getCallTypeFieldData(bool $conferenceOn = false, bool $dialerOn = false): array\n {\n $value = [];\n $conferenceOn && $value[] = self::CALL_TYPE_CONFERENCE;\n $dialerOn && $value[] = self::CALL_TYPE_DIALER;\n\n return [\n 'id' => 'call_type',\n 'label' => 'Call Type',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'required' => true,\n 'options' => [\n self::CALL_TYPE_CONFERENCE,\n self::CALL_TYPE_DIALER,\n ],\n 'value' => $value,\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getMediaTypeFieldData(?AutomatedReport $report = null): array\n {\n $value = [];\n\n if ($report) {\n $value = $this->transformMediaTypes($report);\n }\n\n return [\n 'id' => 'media_types',\n 'label' => 'Export as',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'required' => true,\n 'options' => self::MEDIA_TYPE_OBJECTS,\n 'value' => $value,\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getCallDurationFieldData(?int $valueMin = null, ?int $valueMax = null): array\n {\n return [\n 'id' => 'call_duration',\n 'label' => 'Call Duration',\n 'inputType' => InputTypeEnum::INTEGER_RANGE,\n 'required' => false,\n 'value' => ['min' => $valueMin, 'max' => $valueMax],\n 'queryParams' => [\n 'min' => 'min_call_duration',\n 'max' => 'max_call_duration',\n ],\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getRecipientsFieldData(?Team $team = null, array $value = []): array\n {\n return $this->recipientsService->getRecipientsFieldData(team: $team, value: $value);\n }\n\n public function getJiminnyRecipientsFieldData(array $value = []): array\n {\n return $this->recipientsService->getJiminnyRecipientsFieldData($value);\n }\n\n public function getAdditionalPromptInputFieldData(?string $value = null): array\n {\n return [\n 'id' => 'additional_prompt_input',\n 'label' => 'Special requirements',\n 'inputType' => InputTypeEnum::TEXTAREA,\n 'required' => false,\n 'placeholder' => 'What should be the focus of the report?',\n 'value' => $value,\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getCustomReportNameFieldData(?string $value = null): array\n {\n return [\n 'id' => 'custom_name',\n 'label' => 'Custom report name',\n 'inputType' => InputTypeEnum::TEXT,\n 'required' => false,\n 'placeholder' => 'Enter custom name',\n 'value' => $value,\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n // data providers\n public function getTeams(): array\n {\n $teams = $this->teamRepository->getTeamsForKiosk(status: Team::STATUS_ACTIVE);\n\n $teamData = [];\n foreach ($teams as $team) {\n if (! $team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {\n continue;\n }\n\n $teamData[] = $this->transformTeam($team);\n }\n\n return $teamData;\n }\n\n public function getTeamGroups(string $teamUuid): array\n {\n $data = [];\n $team = $this->getTeam($teamUuid);\n\n if ($team !== null) {\n $groups = $team->groups()->get();\n\n foreach ($groups as $group) {\n $data[] = [\n 'id' => $group->getUuid(),\n 'name' => $group->getName(),\n ];\n }\n }\n\n return $data;\n }\n\n public function getTeamsGroupsOptions(array $filterTeamUuids = []): array\n {\n $data = [];\n $teams = $this->getTeams();\n\n foreach ($teams as $team) {\n if (! empty($filterTeamUuids) && ! in_array($team['id'], $filterTeamUuids, true)) {\n continue;\n }\n\n $data[] = [\n 'label' => $team['name'],\n 'groups' => $this->getTeamGroups($team['id']),\n ];\n }\n\n return $data;\n }\n\n public function getTeam(string $teamUuid): ?Team\n {\n return $this->teamRepository->idOrUuid($teamUuid);\n }\n\n public function getTeamById(int $teamId): ?Team\n {\n return $this->teamRepository->find($teamId);\n }\n\n public function getGroupsUuids(AutomatedReport $report): array\n {\n $uuids = [];\n $reportGroups = $report->getGroups();\n foreach ($reportGroups as $groupId) {\n if ($group = $this->groupRepository->find($groupId)) {\n $uuids[] = $group->getUuid();\n }\n }\n\n return $uuids;\n }\n\n public function getPlaybookCategoriesUuids(AutomatedReport $report): array\n {\n $uuids = [];\n $playbookCategories = $report->getPlaybookCategories();\n foreach ($playbookCategories as $id) {\n if ($category = $this->playbookCategoryRepository->find($id)) {\n $uuids[] = $category->getUuid();\n }\n }\n\n return $uuids;\n }\n\n public function getDealAtCallStagesUuids(AutomatedReport $report): array\n {\n $uuids = [];\n $reportStages = $report->getDealAtCallStages();\n foreach ($reportStages as $id) {\n if ($stage = $this->stageRepository->find($id)) {\n $uuids[] = $stage->getUuid();\n }\n }\n\n return $uuids;\n }\n\n public function getCurrentDealStagesUuids(AutomatedReport $report): array\n {\n $uuids = [];\n $reportStages = $report->getCurrentDealStages();\n foreach ($reportStages as $id) {\n if ($stage = $this->stageRepository->find($id)) {\n $uuids[] = $stage->getUuid();\n }\n }\n\n return $uuids;\n }\n\n public function getUsersUuids(AutomatedReport $report): array\n {\n return $this->extractUserUuids($report->getRecipients());\n }\n\n public function getJiminnyUsersUuids(AutomatedReport $report): array\n {\n return $this->extractUserUuids($report->getJiminnyRecipients());\n }\n\n /**\n * @param array<string, mixed> $recipients\n */\n private function extractUserUuids(array $recipients): array\n {\n $userIds = $recipients['users'] ?? [];\n\n return collect($userIds)\n ->map(fn ($id) => $this->userRepository->find((int) $id))\n ->filter()\n ->map(fn (UserContract $user) => $user->getUuid())\n ->values()\n ->all();\n }\n\n // get mail data\n public function getRecipientUsers(AutomatedReport $report): array\n {\n return $this->buildRecipientUsers($report->getRecipients());\n }\n\n private function getJiminnyRecipientUsers(AutomatedReport $report): array\n {\n return $this->buildRecipientUsers($report->getJiminnyRecipients());\n }\n\n /**\n * @param array<string, mixed> $recipients\n */\n private function buildRecipientUsers(array $recipients): array\n {\n $userIds = $recipients['users'] ?? [];\n\n return collect($userIds)\n ->map(fn ($id) => $this->userRepository->find((int) $id))\n ->filter()\n ->map(fn (UserContract $user) => [\n 'email' => $user->getEmailAddress(),\n 'name' => $user->getName(),\n 'timezone' => $user->getTimezone()->getName(),\n ])\n ->values()\n ->all();\n }\n\n public function getValidRecipientUsers(AutomatedReport $report, bool $includeJiminny = false): array\n {\n if ($report->isAskJiminnyReport()) {\n $recipients = $this->resolveAskJiminnyRecipients($report);\n } else {\n $recipients = $this->getRecipientUsers($report);\n if ($includeJiminny) {\n $recipients = array_merge($recipients, $this->getJiminnyRecipientUsers($report));\n }\n }\n\n $emails = [];\n\n return array_values(array_filter(\n $recipients,\n static function ($recipient) use (&$emails) {\n if (empty($recipient['email']) || in_array($recipient['email'], $emails, true)) {\n return false;\n }\n $emails[] = $recipient['email'];\n\n return true;\n }\n ));\n }\n\n private function resolveAskJiminnyRecipients(AutomatedReport $report): array\n {\n $recipients = [];\n\n $creator = $report->getCreator();\n if ($creator !== null) {\n $recipients[] = [\n 'email' => $creator->getEmailAddress(),\n 'name' => $creator->getName(),\n 'timezone' => $creator->getTimezone()->getName(),\n ];\n }\n\n return array_merge(\n $recipients,\n $this->buildRecipientUsers($report->getRecipients()),\n $this->getGroupRecipientUsers($report),\n );\n }\n\n private function getGroupRecipientUsers(AutomatedReport $report): array\n {\n $users = [];\n foreach ($report->getGroups() as $groupId) {\n $group = $this->groupRepository->find($groupId);\n if ($group === null) {\n continue;\n }\n foreach ($group->getMembers() as $member) {\n $users[] = [\n 'email' => $member->getEmailAddress(),\n 'name' => $member->getName(),\n 'timezone' => $member->getTimezone()->getName(),\n ];\n }\n }\n\n return $users;\n }\n\n public function getReportTypeName(AutomatedReportResult $report): string\n {\n $type = $report->getReport()->getType();\n\n $getType = $this->transformReportType($type);\n\n return $getType['name'];\n }\n\n public function getReportPeriodName(AutomatedReportResult $report): string\n {\n $from = $report->getFromDate();\n $to = $report->getToDate();\n $frequency = $report->getReport()->getFrequency();\n\n if ($from === null || $to === null) {\n if (! $report->getReport()->isAskJiminnyReport()) {\n $invalidPeriod = $from === null ? 'from' : 'to';\n\n throw new ApplicationException('Report period is invalid: ' . $invalidPeriod);\n }\n\n $period = $this->calculateFromAndToDatePeriod($frequency);\n $from = $period['fromDate'];\n $to = $period['toDate'];\n }\n\n return $this->formatReportPeriodName($frequency, $from, $to);\n }\n\n private function formatReportPeriodName(string $frequency, Carbon $from, Carbon $to): string\n {\n $fromYear = $from->format('Y');\n $toYear = $to->format('Y');\n $differentYears = $fromYear !== $toYear;\n\n switch ($frequency) {\n case self::FREQUENCY_DAILY:\n return $from->format('j M Y');\n\n case self::FREQUENCY_QUARTERLY:\n // 'Jan-Mar 2025' or 'Nov 2024-Jan 2025' if years differ\n $startMonth = $from->format('M');\n $endMonth = $to->copy()->subMonth();\n $endMonthName = $endMonth->format('M');\n $endMonthYear = $endMonth->format('Y');\n\n if ($differentYears) {\n return \"{$startMonth} {$fromYear} - {$endMonthName} {$endMonthYear}\";\n }\n\n return \"{$startMonth} - {$endMonthName} {$toYear}\";\n\n case self::FREQUENCY_MONTHLY:\n // 'May 2025' - monthly reports are always within the same year\n return $from->format('M Y');\n\n case self::FREQUENCY_WEEKLY:\n // '4 - 8 Aug 2025', '27 Oct - 3 Nov 2025', or '28 Dec 2024 - 3 Jan 2025' if years differ\n $startDay = $from->format('j');\n $endDay = $to->format('j');\n $startMonth = $from->format('M');\n $endMonth = $to->format('M');\n\n if ($differentYears) {\n return \"{$startDay} {$startMonth} {$fromYear} - {$endDay} {$endMonth} {$toYear}\";\n }\n\n if ($startMonth !== $endMonth) {\n return \"{$startDay} {$startMonth} - {$endDay} {$endMonth} {$toYear}\";\n }\n\n return \"{$startDay} - {$endDay} {$endMonth} {$toYear}\";\n\n case self::FREQUENCY_ONE_OFF:\n // '2 May-31 May 2025' or '15 Dec 2024-15 Jan 2025' if years differ\n $startDay = $from->format('j');\n $startMonth = $from->format('M');\n $endDay = $to->format('j');\n $endMonth = $to->format('M');\n\n // If same month and year, use a format like '2-31 May 2025'\n if ($startMonth === $endMonth && ! $differentYears) {\n return \"{$startDay} - {$endDay} {$startMonth} {$toYear}\";\n }\n\n // If different years, include both years\n if ($differentYears) {\n return \"{$startDay} {$startMonth} {$fromYear} - {$endDay} {$endMonth} {$toYear}\";\n }\n\n // Same year but different months\n return \"{$startDay} {$startMonth} - {$endDay} {$endMonth} {$toYear}\";\n\n default:\n // Default format for unknown frequencies\n return $from->format('j M Y') . ' - ' . $to->format('j M Y');\n }\n }\n\n public function getReportTeamsName(AutomatedReportResult $report): string\n {\n $groups = $report->getGroups();\n\n if (empty($groups)) {\n return 'All';\n }\n\n // Get group names from repository\n $groupNames = [];\n foreach ($groups as $groupId) {\n $group = $this->groupRepository->find($groupId);\n if ($group) {\n $groupNames[] = $group->getName();\n }\n }\n\n if (count($groupNames) === 1) {\n // Single team format\n $teamsName = $groupNames[0];\n } else {\n // Multiple teams format\n $teamsName = implode(', ', $groupNames);\n }\n\n return $teamsName;\n }\n\n public function getReportFileName(AutomatedReportResult $report): string\n {\n $customName = $report->getReport()->getCustomName();\n $periodName = $this->getReportPeriodName($report);\n $filenameSuffix = $this->getFilenameSuffix($report);\n\n if ($customName) {\n if ($filenameSuffix) {\n $customName .= \" {$filenameSuffix}\";\n }\n\n return $this->sanitizeFileName(\"{$customName} - {$periodName}\");\n }\n\n $baseName = $this->getReportTypeName($report);\n\n if ($filenameSuffix) {\n $baseName .= \" {$filenameSuffix}\";\n }\n\n return $this->sanitizeFileName(\"{$baseName} - {$periodName} - {$this->getReportTeamsName($report)}\");\n }\n\n public function getReportFileNameWithExtension(AutomatedReportResult $result): string\n {\n $extension = $this->getMediaTypeMetadata($result)['extension'];\n\n return $this->getReportFileName($result) . '.' . $extension;\n }\n\n public function sanitizeFileName(string $fileName): string\n {\n return str_replace(['/', '\\\\'], '-', $fileName);\n }\n\n public function isUserRecipientOfReport(User $user, AutomatedReport $report): bool\n {\n $recipients = array_map('intval', $report->getRecipients()['users'] ?? []);\n\n return in_array($user->getId(), $recipients);\n }\n\n public function transformReportResults(Collection $automatedReportResults): array\n {\n $data = [];\n foreach ($automatedReportResults as $automatedReportResult) {\n /** @var AutomatedReportResult $automatedReportResult */\n\n $report = $automatedReportResult->getReport();\n\n $createdBy = $report->getCreator();\n $creator = [\n 'id' => $createdBy?->getUuid(),\n 'name' => $createdBy?->getName(),\n 'email' => $createdBy?->getEmailAddress(),\n 'photoUrl' => $createdBy?->getPhotoUrl(),\n ];\n\n $data[] = [\n 'id' => $automatedReportResult->getUuid(),\n 'name' => $automatedReportResult->getName(),\n 'frequency' => $this->transformFrequency($report->getFrequency()),\n 'recipients' => [\n ...array_values($this->transformGroups(team: $report->getTeam(), groupsIds: $report->getGroups())),\n ...array_values($this->transformRecipients($report->getRecipients())),\n ],\n 'report_type' => $this->transformReportType($report->getType()),\n 'media_type' => $automatedReportResult->getMediaType(),\n 'downloadUrl' => $this->generateReportResultDownloadUrl($automatedReportResult),\n 'viewUrl' => $this->generateReportResultViewUrl($automatedReportResult),\n 'generated_at' => $automatedReportResult->getGeneratedAt()?->toIso8601String(),\n 'creator' => $creator,\n ];\n }\n\n return $data;\n }\n\n public function hasCallTypeConference(AutomatedReport $report): bool\n {\n return in_array(self::CALL_TYPE_CONFERENCE['id'], $report->getCallTypes(), true);\n }\n\n public function hasCallTypeDialer(AutomatedReport $report): bool\n {\n return in_array(self::CALL_TYPE_DIALER['id'], $report->getCallTypes(), true);\n }\n\n // transformers\n private function transformTeam(Team $team): array\n {\n if (! $team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {\n return [];\n }\n\n return [\n 'id' => $team->getUuid(),\n 'name' => $team->getName(),\n ];\n }\n\n private function transformReportFullView(AutomatedReport $report): array\n {\n $base = $this->transformReportBase($report);\n\n return $report->getType() === self::TYPE_ASK_JIMINNY\n ? $base + $this->transformAskJiminnyFields($report)\n : $base + $this->transformStandardReportFields($report);\n }\n\n private function transformReportBase(AutomatedReport $report): array\n {\n return [\n 'id' => $report->getUuid(),\n 'organization' => $this->transformOrganization(team: $report->getTeam()),\n 'report_type' => $this->transformReportType($report->getType()),\n 'frequency' => $this->transformFrequency($report->getFrequency()),\n ];\n }\n\n private function transformStandardReportFields(AutomatedReport $report): array\n {\n $team = $report->getTeam();\n\n return [\n 'report_enabled' => $report->getStatus(),\n 'start_date_period' => $report->getFrom()?->format('Y-m-d H:i:s'),\n 'end_date_period' => $report->getTo()?->format('Y-m-d H:i:s'),\n 'deal_value_min' => $report->getDealValueMin(),\n 'deal_value_max' => $report->getDealValueMax(),\n 'call_types' => $this->transformCallType($report->getCallTypes()),\n 'media_types' => $this->transformMediaTypes($report),\n 'call_duration_min' => $this->transformDurationToMinutes($report->getCallDurationMin()),\n 'call_duration_max' => $this->transformDurationToMinutes($report->getCallDurationMax()),\n 'teams' => $this->transformGroups(team: $team, groupsIds: $report->getGroups()),\n 'deal_at_call_stages' => $this->transformStages(team: $team, stagesIds: $report->getDealAtCallStages()),\n 'current_deal_stages' => $this->transformStages(team: $team, stagesIds: $report->getCurrentDealStages()),\n 'recipients' => $this->transformRecipients($report->getRecipients()),\n 'created_by' => $this->transformCreator($report->getCreator()),\n 'additional_prompt_input' => $report->getAdditionalPromptInput(),\n 'custom_name' => $report->getCustomName(),\n 'created_at' => $report->getCreatedAt()->format('Y-m-d H:i:s'),\n 'updated_at' => $report->getUpdatedAt()->format('Y-m-d H:i:s'),\n 'deleted_at' => $report->getDeletedAt()?->format('Y-m-d H:i:s'),\n ];\n }\n\n private function transformAskJiminnyFields(AutomatedReport $report): array\n {\n $team = $report->getTeam();\n $creatorId = $report->getAttribute('created_by');\n $explicitUserIds = array_values(array_filter(\n $report->getRecipients()['users'] ?? [],\n static fn ($id) => $id !== $creatorId\n ));\n\n return [\n 'report_name' => $report->getCustomName(),\n 'enabled' => $report->getStatus(),\n 'share_teams' => $this->transformGroups(team: $team, groupsIds: $report->getGroups()),\n 'share_users' => $this->transformRecipients(['users' => $explicitUserIds]),\n 'saved_search' => $this->transformSafeSearch($report->getSavedSearch()),\n 'ask_jiminny_prompt' => $this->transformAskJiminnyPrompt($report->getAskAnythingPrompt()),\n 'expires_on' => $report->getExpiresAt()?->format('Y-m-d'),\n ];\n }\n\n private function transformOrganization(?Team $team): array\n {\n return [\n 'id' => $team?->getUuid(),\n 'name' => $team?->getName(),\n ];\n }\n\n private function transformReportType(string $type): array\n {\n foreach (self::ALL_TYPES as $typeItem) {\n if ($typeItem['id'] === $type) {\n return $typeItem;\n }\n }\n\n return [];\n }\n\n private function transformCallType(array $types): array\n {\n $result = [];\n $callTypes = [self::CALL_TYPE_CONFERENCE, self::CALL_TYPE_DIALER];\n\n foreach ($types as $type) {\n foreach ($callTypes as $callTypeItem) {\n if ($callTypeItem['id'] === $type) {\n $result[] = $callTypeItem;\n\n break;\n }\n }\n }\n\n return $result;\n }\n\n private function transformMediaTypes(AutomatedReport $report): array\n {\n $values = [];\n\n foreach ($report->getMediaTypes() as $mediaType) {\n if (! in_array($mediaType, self::MEDIA_TYPES, true)) {\n continue;\n }\n\n $values[] = match ($mediaType) {\n self::MEDIA_TYPE_PDF => self::MEDIA_TYPE_OBJECT_PDF,\n self::MEDIA_TYPE_PODCAST => self::MEDIA_TYPE_OBJECT_PODCAST,\n };\n }\n\n return $values;\n }\n\n private function transformFrequency(string $frequency): array\n {\n foreach (self::ALL_FREQUENCIES as $frequencyItem) {\n if ($frequencyItem['id'] === $frequency) {\n return $frequencyItem;\n }\n }\n\n return [];\n }\n\n public function transformDurationToMinutes(?int $duration): ?int\n {\n if (! $duration) {\n return null;\n }\n\n return (int) ($duration / 60);\n }\n\n private function transformGroups(?Team $team, array $groupsIds): array\n {\n if (empty($groupsIds) || ! $team) {\n return [];\n }\n\n $data = [];\n foreach ($groupsIds as $groupId) {\n $group = $team->groups()->where('id', $groupId)->first();\n\n if ($group) {\n $data[] = [\n 'id' => $group->getUuid(),\n 'name' => $group->getName(),\n 'photoUrl' => $group->getPhotoUrl(),\n ];\n }\n }\n\n return $data;\n }\n\n private function transformStages(?Team $team, array $stagesIds): array\n {\n if (empty($stagesIds) || ! $team) {\n return [];\n }\n\n $data = [];\n foreach ($stagesIds as $stageId) {\n $stage = $team->stages()->where('id', $stageId)->first();\n\n if ($stage) {\n $data[] = [\n 'id' => $stage->getUuid(),\n 'name' => $stage->getName(),\n ];\n }\n }\n\n return $data;\n }\n\n private function transformRecipients(array $recipients): array\n {\n $users = [];\n foreach ($recipients['users'] ?? [] as $userId) {\n $users[] = $this->transformUser($userId);\n }\n\n return $users;\n }\n\n private function transformCreator(?User $user): ?array\n {\n if ($user === null) {\n return null;\n }\n\n return $this->transformUser($user->getId());\n }\n\n private function transformAskJiminnyPrompt(?AskAnythingPrompt $prompt): ?array\n {\n if ($prompt === null) {\n return null;\n }\n\n return [\n 'id' => $prompt->getUuid(),\n 'name' => $prompt->getTitle(),\n ];\n }\n\n private function transformSafeSearch(?Search $search): ?array\n {\n if ($search === null) {\n return null;\n }\n\n return [\n 'id' => $search->getUuid(),\n 'name' => $search->getName(),\n ];\n }\n\n private function transformUser(int $userId): array\n {\n /* @var ?User $user */\n $user = $this->userRepository->find($userId);\n\n return [\n 'id' => $user?->getUuid(),\n 'name' => $user?->getName(),\n 'email' => $user?->getEmailAddress(),\n 'photoUrl' => $user?->getPhotoUrl(),\n ];\n }\n\n public function create(array $data): array\n {\n $validatedData = $this->validateAndTransformData($data);\n $validatedData['created_by'] = auth()->id();\n\n $automatedReport = $this->automatedReportsRepository->create($validatedData);\n\n $this->generateOneOffReport($automatedReport);\n\n return $this->transformReportFullView($automatedReport);\n }\n\n public function update(string $uuid, array $data): array\n {\n $validatedData = $this->validateAndTransformData($data);\n $report = $this->automatedReportsRepository->findByUuid($uuid);\n\n if (! $report) {\n throw new InvalidArgumentException('Report not found');\n }\n\n $oldCustomName = $report->getCustomName();\n\n $automatedReport = $this->automatedReportsRepository->update($report, $validatedData);\n\n if ($oldCustomName !== $automatedReport->getCustomName()) {\n $this->updateResultNames($automatedReport);\n }\n\n $this->generateOneOffReport($automatedReport);\n\n return $this->transformReportFullView($automatedReport);\n }\n\n /**\n * Create an Ask Jiminny report.\n */\n public function createAskJiminnyReport(array $data, User $creator): array\n {\n $validatedData = $this->validateAskJiminnyReportData($data, $creator);\n $validatedData['created_by'] = $creator->getId();\n\n $automatedReport = $this->automatedReportsRepository->create($validatedData);\n\n return $this->transformReportFullView($automatedReport);\n }\n\n /**\n * Update an Ask Jiminny report.\n */\n public function updateAskJiminnyReport(AutomatedReport $report, array $data, User $user): array\n {\n if (! $report->isAskJiminnyReport()) {\n throw new InvalidArgumentException('Report is not an Ask Jiminny report');\n }\n\n $validatedData = $this->validateAskJiminnyReportData($data, $user);\n\n $oldCustomName = $report->getCustomName();\n\n $automatedReport = $this->automatedReportsRepository->update($report, $validatedData);\n\n if ($oldCustomName !== $automatedReport->getCustomName()) {\n $this->updateResultNames($automatedReport);\n }\n\n return $this->transformReportFullView($automatedReport);\n }\n\n public function updateAskJiminnyReportStatus(AutomatedReport $report, bool $status): array\n {\n $this->automatedReportsRepository->update($report, ['status' => $status]);\n\n return $this->transformReportFullView($report->fresh());\n }\n\n /**\n * Validate and transform data for Ask Jiminny reports.\n */\n private function validateAskJiminnyReportData(array $data, User $user): array\n {\n // Validate name\n $name = trim($data['report_name'] ?? '');\n if (empty($name)) {\n throw new InvalidArgumentException('Report name is required');\n }\n if (mb_strlen($name) > 50) {\n throw new InvalidArgumentException('Report name must be 50 characters or less');\n }\n\n // Validate frequency (only daily, weekly, monthly for Ask Jiminny)\n $frequency = $data['frequency'] ?? null;\n $askJiminnyFrequencies = [self::FREQUENCY_DAILY, self::FREQUENCY_WEEKLY, self::FREQUENCY_MONTHLY];\n if (! in_array($frequency, $askJiminnyFrequencies, true)) {\n throw new InvalidArgumentException('Frequency must be daily, weekly, or monthly');\n }\n\n // Validate expiration date\n $expiresAt = $data['expires_on'] ?? null;\n if (empty($expiresAt)) {\n throw new InvalidArgumentException('Expiration date is required');\n }\n\n try {\n $expiresAtDate = Carbon::parse($expiresAt);\n } catch (InvalidFormatException $e) {\n throw new InvalidArgumentException('Expiration date format is invalid');\n }\n $maxExpiration = Carbon::now()->addYear();\n if ($expiresAtDate->gt($maxExpiration)) {\n throw new InvalidArgumentException('Expiration date cannot be more than 1 year from now');\n }\n if ($expiresAtDate->isPast()) {\n throw new InvalidArgumentException('Expiration date cannot be in the past');\n }\n\n // Validate saved search\n $activitySearchId = $data['saved_search'] ?? null;\n if (empty($activitySearchId)) {\n throw new InvalidArgumentException('Saved search is required');\n }\n $savedSearch = $this->activitySearchRepository->findByUuidAndUser($activitySearchId, $user);\n if (! $savedSearch) {\n throw new InvalidArgumentException('Saved search not found or does not belong to you');\n }\n\n // Validate saved prompt\n $askAnythingPromptId = $data['ask_jiminny_prompt'] ?? null;\n if (empty($askAnythingPromptId)) {\n throw new InvalidArgumentException('Ask Jiminny prompt is required');\n }\n $prompt = $this->askAnythingRepository->getPromptByUuid($askAnythingPromptId);\n if (! $prompt) {\n throw new InvalidArgumentException('Ask Jiminny prompt not found');\n }\n\n // Validate status\n $status = $data['enabled'] ?? false;\n\n $recipientUserIds = [$user->getId()];\n\n if (! empty($data['share_users'])) {\n $sharedUserIds = $this->validateAndGetUserIdsByTeam(\n $user->team,\n (array) $data['share_users']\n );\n $recipientUserIds = array_merge($recipientUserIds, $sharedUserIds);\n }\n\n $sharedGroupIds = [];\n if (! empty($data['share_teams'])) {\n $sharedGroupIds = $this->validateAndGetGroupIds($user->team, (array) $data['share_teams']);\n }\n\n $recipientUserIds = array_values(array_unique($recipientUserIds));\n\n return [\n 'team_id' => $user->getTeamId(),\n 'type' => self::TYPE_ASK_JIMINNY,\n 'status' => (bool) $status,\n 'frequency' => $frequency,\n 'custom_name' => $name,\n 'activity_search_id' => $savedSearch->getId(),\n 'ask_anything_prompt_id' => $prompt->getId(),\n 'expires_at' => $expiresAtDate->toDateString(),\n 'media_types' => [self::MEDIA_TYPE_PDF],\n 'call_types' => [],\n 'recipients' => ['users' => $recipientUserIds],\n 'groups' => $sharedGroupIds,\n ];\n }\n\n public static function getAskJiminnyFrequencies(): array\n {\n return array_map(static function ($frequency) {\n return $frequency['id'];\n }, self::ASK_JIMINNY_FREQUENCIES);\n }\n\n public function getAskJiminnyReportFilters(User $user): array\n {\n $savedSearches = $this->activitySearchRepository->findByUserOrderedByName($user)\n ->map(fn (Search $search) => [\n 'id' => $search->getUuid(),\n 'name' => $search->getName(),\n ])\n ->values()->all();\n\n $prompts = collect(\n $this->askAnythingPromptService->get($user, AskAnythingPromptTarget::on_demand)\n )->map(fn (AskAnythingPromptDto $prompt) => [\n 'id' => $prompt->id,\n 'name' => $prompt->title,\n ])->values()->all();\n\n return [\n [\n 'id' => 'prompt',\n 'label' => 'Prompt',\n 'options' => $prompts,\n ],\n [\n 'id' => 'saved_search',\n 'label' => 'Saved Search',\n 'options' => $savedSearches,\n ],\n ];\n }\n\n public function getAskJiminnyReportFormData(User $user, ?AutomatedReport $report = null): array\n {\n $team = $user->getTeam();\n $userTimezone = $user->getTimezone();\n\n $savedSearches = $this->activitySearchRepository->findByUserOrderedByName($user)\n ->map(fn (Search $search) => [\n 'id' => $search->getUuid(),\n 'name' => $search->getName(),\n ])\n ->values()->all();\n\n $prompts = collect(\n $this->askAnythingPromptService->get($user, AskAnythingPromptTarget::on_demand)\n )->map(fn (AskAnythingPromptDto $prompt) => [\n 'id' => $prompt->id,\n 'name' => $prompt->title,\n ])->values()->all();\n\n $teamGroups = $this->groupRepository->getAllByTeam($team)->map(fn ($group) => [\n 'id' => $group->getUuid(),\n 'name' => $group->getName(),\n ])->values()->all();\n\n $shareUsers = $this->recipientsService->getRecipientsFieldData(team: $team)['options'] ?? [];\n\n $sharedTeamsValue = [];\n $sharedUsersValue = [];\n if ($report) {\n $sharedTeamsValue = $this->transformGroups($team, $report->getGroups());\n\n $recipientUserIds = $report->getRecipients()['users'] ?? [];\n $creatorId = $report->getAttribute('created_by');\n $sharedUserIds = array_values(array_filter(\n $recipientUserIds,\n static fn ($id) => $id !== $creatorId\n ));\n $sharedUsersValue = collect($sharedUserIds)\n ->map(fn ($id) => $this->userRepository->find((int) $id))\n ->filter()\n ->map(fn (User $u) => [\n 'id' => $u->getUuid(),\n 'name' => $u->getName(),\n ])\n ->values()\n ->all();\n }\n\n return [\n 'fields' => [\n [\n 'id' => 'enabled',\n 'inputType' => InputTypeEnum::TOGGLE,\n 'label' => '',\n 'value' => $report?->getStatus() ?? false,\n ],\n [\n 'id' => 'report_name',\n 'inputType' => InputTypeEnum::TEXT,\n 'label' => 'Name',\n 'placeholder' => 'Enter name',\n 'required' => true,\n 'validation' => ['maxLength' => 50],\n 'value' => $report?->getCustomName() ?? '',\n ],\n [\n 'id' => 'frequency',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'label' => 'Frequency',\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => self::ASK_JIMINNY_FREQUENCIES,\n 'value' => $report ? $this->transformFrequency($report->getFrequency()) : null,\n ],\n [\n 'id' => 'expires_on',\n 'inputType' => InputTypeEnum::DATE,\n 'label' => 'Expires on',\n 'required' => true,\n 'placeholder' => 'Select',\n 'validation' => [\n 'minDate' => now($userTimezone)->toDateString(),\n 'maxDate' => now($userTimezone)->addYear()->toDateString(),\n ],\n 'value' => $report?->getExpiresAt()?->toDateString(),\n ],\n [\n 'id' => 'share_teams',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'label' => 'Team',\n 'required' => false,\n 'placeholder' => 'Select',\n 'options' => $teamGroups,\n 'value' => $sharedTeamsValue,\n ],\n [\n 'id' => 'share_users',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'label' => 'Team member',\n 'required' => false,\n 'placeholder' => 'Select',\n 'groupLabelKey' => 'label',\n 'groupValuesKey' => 'users',\n 'optionLabelKey' => 'name',\n 'optionValueKey' => 'id',\n 'options' => $shareUsers,\n 'value' => $sharedUsersValue,\n ],\n [\n 'id' => 'saved_search',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'label' => 'Saved search',\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => $savedSearches,\n 'value' => $report && $report->getSavedSearch() ? [\n 'id' => $report->getSavedSearch()->getUuid(),\n 'name' => $report->getSavedSearch()->getName(),\n ] : null,\n ],\n [\n 'id' => 'ask_jiminny_prompt',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'label' => 'Ask Jiminny prompt',\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => $prompts,\n 'value' => $report && $report->getAskAnythingPrompt() ? [\n 'id' => $report->getAskAnythingPrompt()->getUuid(),\n 'name' => $report->getAskAnythingPrompt()->getTitle(),\n ] : null,\n ],\n ],\n ];\n }\n\n private function updateResultNames(AutomatedReport $automatedReport): void\n {\n $results = $this->automatedReportsRepository->getResultsByReport($automatedReport);\n\n foreach ($results as $result) {\n $result->update(['name' => $this->getReportFileName($result)]);\n }\n }\n\n public function updateStatus(string $uuid, array $data): array\n {\n $automatedReport = $this->automatedReportsRepository->findByUuid($uuid);\n\n if (! $automatedReport) {\n throw new ModelNotFoundException('Report not found');\n }\n\n $status = $this->validateReportStatus($data['report_enabled'] ?? null);\n $automatedReport->update([\n 'status' => $status,\n ]);\n\n $this->generateOneOffReport($automatedReport);\n\n return $this->transformReportFullView($automatedReport);\n }\n\n private function generateOneOffReport(AutomatedReport $automatedReport): void\n {\n // the scheduler handles all the other frequency types\n if ($automatedReport->getStatus() === false || $automatedReport->getFrequency() !== self::FREQUENCY_ONE_OFF) {\n return;\n }\n\n $this->dispatcher->dispatch(new RequestGenerateReportJob($automatedReport->getUuid()));\n }\n\n public function getReport(string $uuid): AutomatedReport\n {\n $automatedReport = $this->automatedReportsRepository->findByUuid($uuid);\n\n if (! $automatedReport) {\n throw new ModelNotFoundException('Report not found');\n }\n\n return $automatedReport;\n }\n\n public function get(string $uuid): array\n {\n $automatedReport = $this->getReport($uuid);\n\n return $this->transformReportFullView($automatedReport);\n }\n\n public function list(string $sortColumn = 'created_at', string $sortDirection = 'desc'): array\n {\n $results = [];\n $collection = $this->automatedReportsRepository->getAllStandardReports($sortColumn, $sortDirection);\n\n /** @var AutomatedReport $report */\n foreach ($collection as $report) {\n $results[] = $this->transformReportFullView($report);\n }\n\n return ['data' => $results];\n }\n\n public function listAskJiminnyReports(\n User $user,\n string $sortColumn = 'created_at',\n string $sortDirection = 'desc'\n ): array {\n $results = [];\n $collection = $this->automatedReportsRepository->getAskJiminnyReportsByUser($user, $sortColumn, $sortDirection);\n\n /** @var AutomatedReport $report */\n foreach ($collection as $report) {\n $results[] = $this->transformReportFullView($report);\n }\n\n return ['data' => $results];\n }\n\n public function delete(string $uuid): void\n {\n $automatedReport = $this->automatedReportsRepository->findByUuid($uuid);\n\n if (! $automatedReport) {\n throw new ModelNotFoundException('Report not found');\n }\n\n $automatedReport->delete();\n }\n\n public function createReportResult(AutomatedReport $automatedReport, array $data = []): AutomatedReportResult\n {\n return $this->automatedReportsRepository->createResult(\n array_merge(\n [\n 'report_id' => $automatedReport->getId(),\n 'status' => AutomatedReportResult::STATUS_DEFAULT,\n ],\n $data\n )\n );\n }\n\n public function getReportResult(string $resultUuid): AutomatedReportResult\n {\n $report = $this->automatedReportsRepository->findResultByUuid($resultUuid);\n\n if (! $report) {\n throw new ModelNotFoundException('Report Result not found');\n }\n\n return $report;\n }\n\n public function findChildResult(AutomatedReportResult $result, string $type): ?AutomatedReportResult\n {\n return $this->automatedReportsRepository->findChildResult($result, $type);\n }\n\n // prophet API calls\n /**\n * @throws ApplicationException\n */\n public function getGenerateReportPayload(AutomatedReport $automatedReport, string $reportResultUuid): array\n {\n $period = $this->calculateFromAndToDate($automatedReport);\n $fromDate = $period['fromDate'];\n $toDate = $period['toDate'];\n\n return [\n 'team_id' => $automatedReport->getTeamId(),\n 'request_id' => $reportResultUuid,\n 'report_type' => $automatedReport->getType(),\n 'media_types' => $automatedReport->getMediaTypes(),\n 'from_date' => $fromDate->startOfDay()->format(DateTimeInterface::RFC3339),\n 'to_date' => $toDate->endOfDay()->format(DateTimeInterface::RFC3339),\n 'group_ids' => $automatedReport->getGroups(),\n 'call_deal_stage' => $automatedReport->getDealAtCallStages(),\n 'current_deal_stage' => $automatedReport->getCurrentDealStages(),\n 'deal_min_value' => $automatedReport->getDealValueMin(),\n 'deal_max_value' => $automatedReport->getDealValueMax(),\n 'call_types' => $automatedReport->getCallTypes(),\n 'call_duration_min_seconds' => $automatedReport->getCallDurationMin(),\n 'call_duration_max_seconds' => $automatedReport->getCallDurationMax(),\n 'special_requirements' => $automatedReport->getAdditionalPromptInput(),\n 'callback_url' => $this->getCallbackUrl(),\n 'report_period' => $this->formatReportPeriodName(\n $automatedReport->getFrequency(),\n $fromDate,\n $toDate,\n ),\n 'playbook_categories' => $automatedReport->getPlaybookCategories(),\n 'custom_name' => $automatedReport->getCustomName(),\n ];\n }\n\n // $inputPayload - FE payload structure\n public function getActivitiesCountPayload(array $inputPayload): array\n {\n // Use validateAndTransformData to validate and normalize input\n $validatedData = $this->validateAndTransformData($inputPayload);\n $period = $this->calculateFromAndToDatePeriod(\n $validatedData['frequency'],\n Carbon::parse($validatedData['from']),\n Carbon::parse($validatedData['to']),\n );\n $fromDate = $period['fromDate'];\n $toDate = $period['toDate'];\n\n // Create payload similar to getGenerateReportPayload\n return [\n 'team_id' => $validatedData['team_id'],\n 'group_ids' => $validatedData['groups'] ?? [],\n 'report_type' => $validatedData['type'],\n 'from_date' => $fromDate->format(DateTimeInterface::RFC3339),\n 'to_date' => $toDate->format(DateTimeInterface::RFC3339),\n 'call_deal_stage' => $validatedData['deal_at_call_stages'] ?? [],\n 'current_deal_stage' => $validatedData['current_deal_stages'] ?? [],\n 'deal_min_value' => $validatedData['deal_value_min'] ?? null,\n 'deal_max_value' => $validatedData['deal_value_max'] ?? null,\n 'call_types' => $validatedData['call_types'],\n 'call_duration_min_seconds' => $validatedData['call_duration_min'] ?? null,\n 'call_duration_max_seconds' => $validatedData['call_duration_max'] ?? null,\n 'special_requirements' => $validatedData['additional_prompt_input'] ?? null,\n 'playbook_categories' => $validatedData['playbook_categories'] ?? [],\n 'request_id' => null,\n 'callback_url' => null,\n ];\n }\n\n public function shouldSendReport(array $users, ?CarbonInterface $generatedAt = null): bool\n {\n if (empty($users)) {\n return false;\n }\n\n $earliestTz = collect($users)\n ->mapWithKeys(function (array $user) {\n $tz = new DateTimeZone($user['timezone']);\n $nowUtc = new DateTime('now', new DateTimeZone('UTC'));\n $offset = $tz->getOffset($nowUtc);\n\n return [$user['timezone'] => $offset];\n })\n ->sortDesc()\n ->keys()\n ->first();\n\n $now = Carbon::now($earliestTz);\n $isScheduledTime = (int) $now->format('H') === self::SENT_REPORT_AT_HOURS;\n\n if ($isScheduledTime) {\n return true;\n }\n\n return $this->hasPassedScheduledTime($generatedAt, $earliestTz);\n }\n\n public function hasPassedScheduledTime(?CarbonInterface $generatedAt, string $timezone): bool\n {\n if ($generatedAt === null) {\n return false;\n }\n\n $now = Carbon::now($timezone);\n $scheduledTime = $now->copy()->setTime(self::SENT_REPORT_AT_HOURS, 0, 0);\n\n if ($now->hour < self::SENT_REPORT_AT_HOURS) {\n $scheduledTime = $scheduledTime->subDay();\n }\n\n $scheduledTimeUtc = $scheduledTime->copy()->utc();\n $generatedAtUtc = $generatedAt->copy()->utc();\n $nowUtc = $now->copy()->utc();\n\n return $generatedAtUtc->lt($scheduledTimeUtc) && $nowUtc->gt($scheduledTimeUtc);\n }\n\n public function calculateFromAndToDatePeriod(\n string $frequency,\n ?Carbon $fromDate = null,\n ?Carbon $toDate = null\n ): array {\n if ($frequency === self::FREQUENCY_ONE_OFF) {\n return [\n 'fromDate' => $fromDate,\n 'toDate' => $toDate,\n ];\n }\n\n $now = Carbon::now();\n\n return match ($frequency) {\n self::FREQUENCY_DAILY => [\n 'fromDate' => $now->copy()->subDay()->startOfDay(),\n 'toDate' => $now->copy()->subDay()->endOfDay(),\n ],\n self::FREQUENCY_WEEKLY => [\n 'fromDate' => $now->copy()->subWeeks(1)->startOfDay(),\n 'toDate' => $now->copy()->subDay()->endOfDay(),\n ],\n self::FREQUENCY_MONTHLY => [\n 'fromDate' => $now->copy()->subMonths(1)->startOfDay(),\n 'toDate' => $now->copy()->subDay()->endOfDay(),\n ],\n self::FREQUENCY_QUARTERLY => [\n 'fromDate' => $now->copy()->subMonths(3)->startOfDay(),\n 'toDate' => $now->copy()->subDay()->endOfDay(),\n ],\n default => throw new InvalidArgumentException(\"Unsupported frequency: {$frequency}\"),\n };\n }\n\n private function calculateFromAndToDate(AutomatedReport $automatedReport): array\n {\n return $this->calculateFromAndToDatePeriod(\n $automatedReport->getFrequency(),\n $automatedReport->getFrom(),\n $automatedReport->getTo()\n );\n }\n\n public function getAskJiminnyGenerateReportPayload(\n AutomatedReport $automatedReport,\n AutomatedReportResult $reportResult,\n array $activityIds,\n ): array {\n return [\n 'user_question' => $automatedReport->getAskAnythingPrompt()?->getContent(),\n 'call_ids' => array_map('strval', $activityIds),\n 'team_id' => $automatedReport->getTeamId(),\n 'request_id' => $reportResult->getUuid(),\n 'callback_url' => $this->getCallbackUrl(),\n 'report_period' => $this->getReportPeriodName($reportResult),\n 'report_name' => $automatedReport->getCustomName(),\n ];\n }\n\n private function getCallbackUrl(): string\n {\n return $this->webhookService->route('jiminny.webhook.reports.ready');\n }\n\n /**\n * Validate and transform payload data for automated reports\n *\n * @param array $data\n *\n * @throws InvalidArgumentException\n *\n * @return array\n */\n private function validateAndTransformData(array $data): array\n {\n // Validate organization (team) and check feature\n $team = $this->validateOrganization($data['organization'] ?? null);\n\n $status = $this->validateReportStatus($data['report_enabled'] ?? null);\n $type = $this->validateReportType($data['report_type'] ?? null);\n $frequency = $this->validateFrequency($data['frequency'] ?? null);\n $additionalPromptInput = $this->validateAdditionalPromptInput(\n $data['additional_prompt_input'] ?? null\n );\n $customReportName = $this->validateCustomReportName($data['custom_name'] ?? null);\n\n // Prepare data for the database\n $reportData = [\n 'team_id' => $team->getId(),\n 'type' => $type,\n 'status' => $status,\n 'frequency' => $frequency,\n 'additional_prompt_input' => $additionalPromptInput,\n 'custom_name' => $customReportName,\n ];\n\n // Validate deal values\n $reportData = $this->validateDealValues($data, $reportData);\n\n // Validate date range\n $reportData = $this->validateDateRange($data, $reportData, $frequency);\n\n // Validate call durations\n $reportData = $this->validateCallDurations($data, $reportData);\n\n // Validate call types\n $reportData = $this->validateCallTypes($data, $reportData);\n\n // Validate media types\n $reportData = $this->validateMediaTypes($data, $reportData);\n\n // Validate groups\n if (isset($data['teams'])) {\n $reportData['groups'] = $this->validateAndGetGroupIds($team, $data['teams']);\n }\n\n // Validate deal stages\n $reportData = $this->validateDealStages($data, $reportData, $team, $type);\n\n // Validate playbook categories\n $reportData = $this->validatePlaybookCategories($data, $reportData, $team);\n\n // Validate recipients\n $reportData['recipients'] = [\n 'users' => $this->validateAndGetUserIdsByTeam($team, $data['recipients'] ?? []),\n ];\n\n if (isset($data['jiminny_recipients'])) {\n // Validate Jiminny recipients\n $reportData['jiminny_recipients'] = [\n 'users' => $this->validateAndGetJiminnyUserIds((array) $data['jiminny_recipients']),\n ];\n }\n\n return $reportData;\n }\n\n private function validateDealValues(array $data, array $reportData): array\n {\n if (isset($data['min_deal_value'])) {\n $reportData['deal_value_min'] = (int) $data['min_deal_value'];\n\n if ($reportData['deal_value_min'] > 4294967295 || $reportData['deal_value_min'] < 0) {\n throw new InvalidArgumentException('Min deal value should be between 0 and 4294967295');\n }\n }\n\n if (isset($data['max_deal_value'])) {\n $reportData['deal_value_max'] = (int) $data['max_deal_value'];\n\n if ($reportData['deal_value_max'] > 4294967295 || $reportData['deal_value_max'] < 0) {\n throw new InvalidArgumentException('Max deal value should be between 0 and 4294967295');\n }\n }\n\n if (isset($data['min_deal_value'], $data['max_deal_value'])\n && $data['min_deal_value'] > $data['max_deal_value']\n ) {\n throw new InvalidArgumentException('Min deal value cannot be greater than max deal value');\n }\n\n return $reportData;\n }\n\n private function validateDateRange(array $data, array $reportData, string $frequency): array\n {\n // Set date range only for one_off frequency\n if ($frequency === 'one_off') {\n if (isset($data['start_date_period'])) {\n $reportData['from'] = $this->parseDate($data['start_date_period']);\n }\n\n if (isset($data['end_date_period'])) {\n $reportData['to'] = $this->parseDate($data['end_date_period']);\n }\n\n if (empty($reportData['from']) || empty($reportData['to'])) {\n throw new InvalidArgumentException(\n 'Start date and end date are required for one_off frequency'\n );\n }\n } else {\n $reportData['from'] = null;\n $reportData['to'] = null;\n }\n\n return $reportData;\n }\n\n private function validateCallDurations(array $data, array $reportData): array\n {\n // Convert call durations from minutes to seconds\n if (isset($data['min_call_duration'])) {\n $reportData['call_duration_min'] = (int) $data['min_call_duration'] * 60;\n\n if ($reportData['call_duration_min'] > 4294967295 || $reportData['call_duration_min'] < 0) {\n throw new InvalidArgumentException('Min call duration should be between 0 and 4294967295');\n }\n }\n\n if (isset($data['max_call_duration'])) {\n $reportData['call_duration_max'] = (int) $data['max_call_duration'] * 60;\n\n if ($reportData['call_duration_max'] > 4294967295 || $reportData['call_duration_max'] < 0) {\n throw new InvalidArgumentException('Max call duration should be between 0 and 4294967295');\n }\n }\n\n return $reportData;\n }\n\n private function validateCallTypes(array $data, array $reportData): array\n {\n // Set call types\n $reportData['call_types'] = $data['call_type'] ?? [];\n if (empty($reportData['call_types'])) {\n $reportData['call_types'] = self::getCallTypes();\n }\n\n foreach ($reportData['call_types'] as $callType) {\n if (! in_array($callType, self::getCallTypes(), true)) {\n throw new InvalidArgumentException(sprintf('Call type %s is invalid', $callType));\n }\n }\n\n return $reportData;\n }\n\n private function validateMediaTypes(array $data, array $reportData): array\n {\n // Set media types from input data\n $reportData['media_types'] = $data['media_types'] ?? [];\n\n if (empty($reportData['media_types'])) {\n throw new InvalidArgumentException('Media types are required');\n }\n\n foreach ($reportData['media_types'] as $mediaType) {\n if (! in_array($mediaType, self::MEDIA_TYPES, true)) {\n throw new InvalidArgumentException(sprintf('Media type %s is invalid', $mediaType));\n }\n }\n\n return $reportData;\n }\n\n private function validateDealStages(array $data, array $reportData, Team $team, string $reportType): array\n {\n // Validate and set deal stages\n if (isset($data['deal_stage_at_call'])) {\n $reportData['deal_at_call_stages'] =\n $this->validateAndGetDealStageIds($team, $data['deal_stage_at_call'], 'Deal stage at call');\n }\n\n if (isset($data['current_deal_stage'])) {\n $reportData['current_deal_stages'] =\n $this->validateAndGetDealStageIds($team, $data['current_deal_stage'], 'Current deal stage');\n }\n\n // Ensure current_deal_stage is not provided for loss_analysis report type\n if ($reportType === self::TYPE_LOSS_ANALYSIS && ! empty($data['current_deal_stage'])) {\n throw new InvalidArgumentException('Current deal stage is not applicable for Loss Analysis reports');\n }\n\n return $reportData;\n }\n\n // transform uuid to id\n private function validatePlaybookCategories(array $data, array $reportData, Team $team): array\n {\n $key = 'playbook_categories';\n\n if (isset($data[$key])) {\n $payloadIds = $data[$key];\n $ids = [];\n\n foreach ($payloadIds as $uuid) {\n $uuid = (string) $uuid;\n\n try {\n $playbookCategory = $this->playbookCategoryRepository->findByUuid($uuid);\n } catch (Throwable $throwable) {\n Log::error(__METHOD__ . ' ' . $throwable->getMessage());\n\n throw new InvalidArgumentException(sprintf('Playbook category %s not found', $uuid));\n }\n\n if (! $playbookCategory) {\n throw new InvalidArgumentException(sprintf('Playbook category %s not found', $uuid));\n }\n\n if (! $playbookCategory->hasPlaybook()) {\n throw new InvalidArgumentException(sprintf('Playbook category %s has no playbook', $uuid));\n }\n\n if ($playbookCategory->getPlaybook()->getTeamId() !== $team->getId()) {\n throw new InvalidArgumentException(\n sprintf('Playbook category %s not found for team %s', $uuid, $team->getUuid())\n );\n }\n\n $ids[] = $playbookCategory->getId();\n }\n\n $reportData[$key] = $ids;\n }\n\n return $reportData;\n }\n\n private function validateReportStatus($status): bool\n {\n if (! in_array($status, [true, false], true)) {\n throw new InvalidArgumentException('Report status is invalid');\n }\n\n return $status;\n }\n\n private function validateReportType($type): string\n {\n if (! in_array($type, self::getTypes(), true)) {\n throw new InvalidArgumentException(sprintf('Report type is invalid: %s', $type));\n }\n\n return $type;\n }\n\n private function validateFrequency($frequency): string\n {\n if (! in_array($frequency, self::getFrequencies(), true)) {\n throw new InvalidArgumentException('Frequency is invalid');\n }\n\n return $frequency;\n }\n\n private function validateAdditionalPromptInput(?string $additionalPromptInput): ?string\n {\n if ($additionalPromptInput && strlen($additionalPromptInput) > 5000) {\n throw new InvalidArgumentException('Additional Prompt Input should be less than 5000 characters');\n }\n\n return $additionalPromptInput;\n }\n\n private function validateCustomReportName(?string $customReportName): ?string\n {\n if ($customReportName === null || $customReportName === '') {\n return null;\n }\n\n if (strlen($customReportName) > 70) {\n throw new InvalidArgumentException('Custom report name should be less than 70 characters');\n }\n\n return $customReportName;\n }\n\n private function validateOrganization(?string $organizationUuid): Team\n {\n if (! $organizationUuid) {\n throw new InvalidArgumentException('Organization is required');\n }\n\n $team = $this->teamRepository->idOrUuid($organizationUuid);\n\n if (! $team) {\n throw new InvalidArgumentException('Organization not found');\n }\n\n if (! $team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {\n throw new InvalidArgumentException('Organization does not have the Automated Reports feature');\n }\n\n return $team;\n }\n\n private function validateAndGetGroupIds(Team $team, array $teamUuids): array\n {\n $groupIds = [];\n\n foreach ($teamUuids as $uuid) {\n $group = $this->groupRepository->findByUuid($uuid);\n\n if ($group === null || $group->getTeamId() !== $team->getId()) {\n throw new InvalidArgumentException(\n sprintf('Group %s not found for team %s', $uuid, $team->getUuid())\n );\n }\n\n $groupIds[] = $group->getId();\n\n }\n\n return $groupIds;\n }\n\n private function validateAndGetDealStageIds(Team $team, array $stageUuids, string $propertyLabel): array\n {\n $stageIds = [];\n\n foreach ($stageUuids as $uuid) {\n $stage = $this->stageRepository->findByUuid($uuid);\n\n if ($stage === null || $stage->getTeamId() !== $team->getId()) {\n throw new InvalidArgumentException(\n sprintf('Stage %s not found for team %s for %s', $uuid, $team->getUuid(), $propertyLabel)\n );\n }\n\n $stageIds[] = $stage->getId();\n }\n\n return $stageIds;\n }\n\n private function validateAndGetUserIds(array $userUuids, callable $teamCheck): array\n {\n if (empty($userUuids)) {\n return [];\n }\n\n $userIds = [];\n\n foreach ($userUuids as $uuid) {\n $user = $this->userRepository->findByUuid($uuid);\n\n if (! $user || ! $user->isStatusActive()) {\n throw new InvalidArgumentException(\n sprintf('User %s not found or is not active', $uuid)\n );\n }\n\n if (! $teamCheck($user)) {\n throw new InvalidArgumentException(\n sprintf('User %s does not belong to the allowed team(s)', $uuid)\n );\n }\n\n $userIds[] = $user->getId();\n }\n\n return $userIds;\n }\n\n private function validateAndGetUserIdsByTeam(Team $team, array $userUuids): array\n {\n return $this->validateAndGetUserIds($userUuids, fn ($user) => $user->getTeamId() === $team->getId());\n }\n\n private function validateAndGetJiminnyUserIds(array $userUuids): array\n {\n $allowedTeamIds = config('kiosk.teamIds', []);\n\n return $this->validateAndGetUserIds($userUuids, fn ($user) => in_array($user->getTeamId(), $allowedTeamIds, true));\n }\n\n private function parseDate(string $dateString): string\n {\n return date('Y-m-d H:i:s', strtotime($dateString));\n }\n\n private function generateReportResultViewUrl(AutomatedReportResult $result): string\n {\n $mediaResource = $this->getReportMediaRouteResource($result);\n\n return route('ai-reports.' . $mediaResource . '.view', ['uuid' => $result->getUuid()]);\n }\n\n private function generateReportResultDownloadUrl(AutomatedReportResult $result): string\n {\n $mediaResource = $this->getReportMediaRouteResource($result);\n\n return route('ai-reports.' . $mediaResource . '.download', ['uuid' => $result->getUuid()]);\n }\n\n private function getReportMediaRouteResource(AutomatedReportResult $result): string\n {\n if ($result->getMediaType() === self::MEDIA_TYPE_PDF) {\n return self::PDF_KEY;\n } elseif ($result->getMediaType() === self::MEDIA_TYPE_PODCAST) {\n return self::AUDIO_KEY;\n }\n\n throw new \\InvalidArgumentException('Unknown media type.');\n }\n\n public function getMediaPath(AutomatedReportResult $result): ?string\n {\n $url = match ($result->getMediaType()) {\n self::MEDIA_TYPE_PDF => $result->getPdfUrl(),\n self::MEDIA_TYPE_PODCAST => $result->getPodcastAudioUrl(),\n default => null,\n };\n\n if ($url === null) {\n return null;\n }\n\n $path = parse_url(trim($url, '\"\\''), PHP_URL_PATH);\n\n return $path ?: null;\n }\n\n public function getFilenameSuffix(AutomatedReportResult $result): ?string\n {\n return match ($result->getMediaType()) {\n self::MEDIA_TYPE_PODCAST => 'Podcast',\n default => null,\n };\n }\n\n public function getMailSubjectSuffix(AutomatedReportResult $result): string\n {\n return match ($result->getMediaType()) {\n self::MEDIA_TYPE_PDF => 'report',\n self::MEDIA_TYPE_PODCAST => 'podcast',\n default => '',\n };\n }\n\n public function getMediaTypeMetadata(AutomatedReportResult $result): array\n {\n return match ($result->getMediaType()) {\n self::MEDIA_TYPE_PODCAST => ['extension' => 'mp3', 'mime' => 'audio/mpeg'],\n self::MEDIA_TYPE_PDF => ['extension' => 'pdf', 'mime' => 'application/pdf'],\n default => ['extension' => null, 'mime' => null],\n };\n }\n\n public function deleteS3Files(AutomatedReportResult $result): void\n {\n $teamUuid = $result->getReport()->getTeam()->getUuid();\n $reportUuid = $result->getUuid();\n\n // delete all files for a report uuid no mather of pdf, podcast, or both\n // in case of both - the podcast files are linked to the pdf (parent) uuid\n // pdf and podcast date times should be close\n $path = sprintf('%s/%s/%s', $teamUuid, self::S3_DIR, $reportUuid);\n\n foreach (self::FILE_EXTENSIONS_VARIANTS as $extension) {\n $file = $path . '.' . $extension;\n\n if (Storage::exists($file)) {\n Storage::delete($file);\n Log::info('[Reports] Deleted S3 file', [\n 'path' => $file,\n ]);\n }\n }\n\n foreach (self::FILE_PODCAST_EXTENSIONS_VARIANTS as $extension) {\n $file = $path . '_podcast.' . $extension;\n\n if (Storage::exists($file)) {\n Storage::delete($file);\n Log::info('[Reports] Deleted Podcast S3 file', [\n 'path' => $file,\n ]);\n }\n }\n }\n\n /**\n *\n * @param int|null $teamId Optional team ID to filter results\n *\n * @return Collection<int, int> Collection of team IDs\n */\n public function getTeamIdsWithReportsResults(?int $teamId = null): Collection\n {\n return $this->automatedReportsRepository->getTeamIdsWithReportsResults($teamId);\n }\n\n /**\n * Core delete logic for report results using a query\n *\n * @param Builder $query\n * @param array $logContext\n *\n * @return int\n */\n private function deleteReportResultsByQuery(Builder $query, array $logContext = []): int\n {\n $deletedCount = 0;\n\n if ($query->exists()) {\n Log::info(\n 'Run delete report results',\n array_merge(\n $logContext,\n [\n 'service' => 'AutomatedReportsService',\n ]\n )\n );\n\n $query->chunkById(50, function ($results) use (&$deletedCount, $logContext) {\n foreach ($results as $result) {\n $this->deleteReportResult($result);\n $deletedCount++;\n\n Log::info(\n 'Deleted a report result',\n array_merge(\n $logContext,\n [\n 'result_id' => $result->getId(),\n 'report_id' => $result->getReportId(),\n ]\n )\n );\n }\n });\n }\n\n return $deletedCount;\n }\n\n /**\n * Delete report results for a team by retention period\n *\n * @param Team $team\n * @param CarbonImmutable $retentionDate\n *\n * @return int Number of deleted report results\n */\n public function deleteReportsResultsInRetentionPeriod(Team $team, CarbonImmutable $retentionDate): int\n {\n $reportIds = $this->automatedReportsRepository->getReportIdsByTeam($team);\n\n if ($reportIds->isEmpty()) {\n return 0;\n }\n\n $query = $this->automatedReportsRepository\n ->getReportResultsQueryForRetention($team, $retentionDate);\n\n return $this->deleteReportResultsByQuery($query, [\n 'team_id' => $team->getId(),\n 'retention_date' => $retentionDate->toDateTimeString(),\n ]);\n }\n\n /**\n * Delete ALL report results for a specific automated report\n *\n * @param string $uuid\n *\n * @return int\n */\n public function deleteReportResults(string $uuid): int\n {\n $report = $this->getReport($uuid);\n\n $query = $this->automatedReportsRepository->getResultsByReportQuery($report);\n\n return $this->deleteReportResultsByQuery($query, [\n 'report_uuid' => $uuid,\n 'report_id' => $report->getId(),\n ]);\n }\n\n public function deleteReportResult(AutomatedReportResult $result): void\n {\n $this->deleteS3Files($result);\n\n $result->delete();\n }\n\n /**\n * Get all reports for a specific team\n *\n * @param Team $team\n *\n * @return \\Illuminate\\Database\\Eloquent\\Collection\n */\n public function getTeamReports(Team $team): \\Illuminate\\Database\\Eloquent\\Collection\n {\n return $this->automatedReportsRepository->getReportsByTeam($team);\n }\n\n /**\n * Get all report results for a specific report\n *\n * @param AutomatedReport $report\n *\n * @return \\Illuminate\\Database\\Eloquent\\Collection\n */\n public function getReportResults(AutomatedReport $report): \\Illuminate\\Database\\Eloquent\\Collection\n {\n return $this->automatedReportsRepository->getResultsByReport($report);\n }\n\n public function deleteAllReportResults(AutomatedReport $report): void\n {\n $results = $this->getReportResults($report);\n\n /** @var AutomatedReportResult $result */\n foreach ($results as $result) {\n Log::info('Deleting result', [\n 'report' => $report->getId(),\n 'result' => $result->getId(),\n ]);\n\n $this->deleteReportResult($result);\n }\n }\n\n public function deleteAllData(Team $team): void\n {\n Log::info('Deleting automated report and results for team', [\n 'team' => $team->getId(),\n ]);\n\n $reports = $this->getTeamReports($team);\n\n /** @var AutomatedReport $report */\n foreach ($reports as $report) {\n Log::info('Deleting report', [\n 'team' => $team->getId(),\n 'report' => $report->getId(),\n ]);\n\n $this->deleteAllReportResults($report);\n\n $report->delete();\n }\n }\n}","depth":4,"value":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Services\\Kiosk\\AutomatedReports;\n\nuse Carbon\\CarbonImmutable;\nuse Carbon\\CarbonInterface;\nuse Carbon\\Exceptions\\InvalidFormatException;\nuse DateTime;\nuse DateTimeInterface;\nuse DateTimeZone;\nuse Illuminate\\Contracts\\Bus\\Dispatcher as BusDispatcher;\nuse Illuminate\\Database\\Eloquent\\Builder;\nuse Illuminate\\Support\\Carbon;\nuse Illuminate\\Support\\Collection;\nuse Illuminate\\Support\\Facades\\Log;\nuse Illuminate\\Support\\Facades\\Storage;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinition\\InputTypeEnum;\nuse Jiminny\\Component\\AskAnything\\AskAnythingPromptService;\nuse Jiminny\\Component\\AskAnything\\Dtos\\AskAnythingPromptDto;\nuse Jiminny\\Component\\UrlGenerator\\Webhook;\nuse Jiminny\\Contracts\\Repositories\\PlaybookCategoryRepository;\nuse Jiminny\\Contracts\\Repositories\\TeamRepository;\nuse Jiminny\\Contracts\\Repositories\\UserRepository;\nuse Jiminny\\Exceptions\\ApplicationException;\nuse Jiminny\\Exceptions\\InvalidArgumentException;\nuse Jiminny\\Exceptions\\ModelNotFoundException;\nuse Jiminny\\Jobs\\AutomatedReports\\RequestGenerateReportJob;\nuse Jiminny\\Models\\Activity\\Search;\nuse Jiminny\\Models\\AskAnything\\AskAnythingPrompt;\nuse Jiminny\\Models\\AskAnything\\AskAnythingPromptTarget;\nuse Jiminny\\Models\\AutomatedReport;\nuse Jiminny\\Models\\AutomatedReportResult;\nuse Jiminny\\Models\\Contracts\\UserContract;\nuse Jiminny\\Models\\Feature\\FeatureEnum;\nuse Jiminny\\Models\\Team;\nuse Jiminny\\Models\\User;\nuse Jiminny\\Repositories\\AskAnythingRepository;\nuse Jiminny\\Repositories\\AutomatedReportsRepository;\nuse Jiminny\\Repositories\\GroupRepository;\nuse Jiminny\\Repositories\\SearchRepository;\nuse Jiminny\\Repositories\\StageRepository;\nuse Throwable;\n\nclass AutomatedReportsService\n{\n public const string TYPE_LOSS_ANALYSIS = 'loss_analysis';\n public const string TYPE_ASK_JIMINNY = 'ask_jiminny';\n\n /**\n * Standard report types (used by kiosk for existing automated reports).\n */\n // @TODO this will add filter, however if we need to control feature by FF we need conditional logic\n public const array TYPES = [\n ['id' => 'exec_summary', 'name' => 'Exec Summary'],\n ['id' => 'coaching_profiles', 'name' => 'Coaching Profiles'],\n ['id' => 'product_feedback', 'name' => 'Product Feedback'],\n ['id' => self::TYPE_LOSS_ANALYSIS, 'name' => 'Loss Analysis'],\n// ['id' => 'questions', 'name' => 'Questions'],\n// ['id' => 'statistical_quant', 'name' => 'Statistical Quantitative'],\n ];\n\n public const array ALL_TYPES = [\n ...self::TYPES,\n ['id' => self::TYPE_ASK_JIMINNY, 'name' => 'Ask Jiminny'],\n ];\n\n public const string FREQUENCY_DAILY = 'daily';\n public const string FREQUENCY_WEEKLY = 'weekly';\n public const string FREQUENCY_MONTHLY = 'monthly';\n public const string FREQUENCY_QUARTERLY = 'quarterly';\n public const string FREQUENCY_ONE_OFF = 'one_off';\n\n /**\n * Frequencies for standard (non-Ask Jiminny) reports.\n */\n public const array FREQUENCIES = [\n ['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],\n ['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],\n ['id' => self::FREQUENCY_QUARTERLY, 'name' => 'Quarterly'],\n ['id' => self::FREQUENCY_ONE_OFF, 'name' => 'One-off'],\n ];\n\n /**\n * Frequencies for Ask Jiminny reports.\n */\n public const array ASK_JIMINNY_FREQUENCIES = [\n ['id' => self::FREQUENCY_DAILY, 'name' => 'Daily'],\n ['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],\n ['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],\n ];\n\n public const string MEDIA_TYPE_PDF = 'pdf';\n public const string MEDIA_TYPE_PODCAST = 'podcast';\n public const array MEDIA_TYPES = [self::MEDIA_TYPE_PDF, self::MEDIA_TYPE_PODCAST];\n public const array MEDIA_TYPE_OBJECT_PDF = ['id' => self::MEDIA_TYPE_PDF, 'name' => 'PDF'];\n public const array MEDIA_TYPE_OBJECT_PODCAST = ['id' => self::MEDIA_TYPE_PODCAST, 'name' => 'Podcast'];\n public const array MEDIA_TYPE_OBJECTS = [self::MEDIA_TYPE_OBJECT_PDF, self::MEDIA_TYPE_OBJECT_PODCAST];\n\n public const array CALL_TYPE_CONFERENCE = ['id' => 'conference', 'name' => 'Conference'];\n public const array CALL_TYPE_DIALER = ['id' => 'dialer', 'name' => 'Dialer'];\n public const int SENT_REPORT_AT_HOURS = 5;\n public const string PDF_KEY = 'pdf';\n public const string AUDIO_KEY = 'audio';\n\n private const array ALL_FREQUENCIES = [\n ['id' => self::FREQUENCY_DAILY, 'name' => 'Daily'],\n ['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],\n ['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],\n ['id' => self::FREQUENCY_QUARTERLY, 'name' => 'Quarterly'],\n ['id' => self::FREQUENCY_ONE_OFF, 'name' => 'One-off'],\n ];\n private const string S3_DIR = 'reports';\n private const array FILE_EXTENSIONS_VARIANTS = ['html', 'MD', 'pdf'];\n private const array FILE_PODCAST_EXTENSIONS_VARIANTS = ['json', 'mp3', 'ssml'];\n\n public function __construct(\n private readonly TeamRepository $teamRepository,\n private readonly GroupRepository $groupRepository,\n private readonly UserRepository $userRepository,\n private readonly StageRepository $stageRepository,\n private readonly DealStagesService $dealStagesService,\n private readonly RecipientsService $recipientsService,\n private readonly AutomatedReportsRepository $automatedReportsRepository,\n private readonly Webhook $webhookService,\n private readonly BusDispatcher $dispatcher,\n private readonly ActivityTypeService $activityTypeService,\n private readonly PlaybookCategoryRepository $playbookCategoryRepository,\n private readonly AskAnythingPromptService $askAnythingPromptService,\n private readonly SearchRepository $activitySearchRepository,\n private readonly AskAnythingRepository $askAnythingRepository,\n ) {\n }\n\n public static function getTypes(): array\n {\n $types = self::TYPES;\n\n return array_map(static function ($type) {\n return $type['id'];\n }, $types);\n }\n\n public static function getCallTypes(): array\n {\n return array_map(static function ($callType) {\n return $callType['id'];\n }, [self::CALL_TYPE_CONFERENCE, self::CALL_TYPE_DIALER]);\n }\n\n public static function getFrequencies(): array\n {\n return array_map(static function ($frequency) {\n return $frequency['id'];\n }, self::FREQUENCIES);\n }\n\n // front-facing structure\n public function getReportEnabledFieldData(bool $value = false): array\n {\n return [\n 'id' => 'report_enabled',\n 'label' => '',\n 'inputType' => InputTypeEnum::TOGGLE,\n 'value' => $value,\n ];\n }\n\n // Organizations = Teams\n public function getOrganizationFieldData(?string $value = null, bool $shortVersion = false): array\n {\n $options = $this->getTeams();\n\n if ($shortVersion) {\n return [\n 'id' => 'organization',\n 'label' => 'Organization',\n 'options' => $options,\n ];\n }\n\n return [\n 'id' => 'organization',\n 'label' => 'Organization',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => $options,\n 'value' => $value,\n 'dependencies' => [\n 'teams',\n 'deal_stage_at_call',\n 'current_deal_stage',\n 'recipients',\n ActivityTypeService::PLAYBOOK_CATEGORIES_KEY,\n ],\n 'dependsOn' => [],\n ];\n }\n\n // Teams = Groups\n public function getTeamFieldData(array $options = [], array $value = [], bool $shortVersion = false): array\n {\n if ($shortVersion) {\n return [\n 'id' => 'teams',\n 'label' => 'Team',\n 'options' => $options,\n ];\n }\n\n return [\n 'id' => 'teams',\n 'label' => 'Team',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'required' => false,\n 'placeholder' => 'Select',\n 'options' => $options,\n 'value' => $value, // value should be an array of objects {id, name}\n 'dependencies' => [ActivityTypeService::PLAYBOOK_CATEGORIES_KEY],\n 'dependsOn' => [],\n ];\n }\n\n public function getReportTypeFieldData(?string $value = null, bool $shortVersion = false, ?Team $team = null): array\n {\n $types = [];\n if ($team instanceof Team) {\n if ($team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {\n $types = self::TYPES;\n }\n if ($team->hasFeature(FeatureEnum::ASK_JIMINNY_REPORTS)) {\n $types[] = ['id' => self::TYPE_ASK_JIMINNY, 'name' => 'Ask Jiminny'];\n }\n } else {\n $types = self::TYPES;\n }\n\n if ($shortVersion) {\n return [\n 'id' => 'report_type',\n 'label' => 'Report Type',\n 'options' => $types,\n ];\n }\n\n return [\n 'id' => 'report_type',\n 'label' => 'Report Type',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => $types,\n 'value' => $value,\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getFrequencyFieldData(?string $value = null): array\n {\n return [\n 'id' => 'frequency',\n 'label' => 'Frequency',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => self::FREQUENCIES,\n 'value' => $value,\n 'dependencies' => ['period'],\n 'dependsOn' => [],\n ];\n }\n\n public function getPeriodFieldData(?string $valueStartDate = null, ?string $valueEndDate = null): array\n {\n return [\n 'id' => 'period',\n 'label' => 'Select one-off period',\n 'inputType' => InputTypeEnum::DATE_RANGE,\n 'required' => true,\n 'placeholder' => 'Select',\n 'value' => ['startDate' => $valueStartDate, 'endDate' => $valueEndDate],\n 'queryParams' => [\n 'startDate' => 'start_date_period',\n 'endDate' => 'end_date_period',\n ],\n 'dependencies' => [],\n 'dependsOn' => ['frequency'],\n ];\n }\n\n public function getActivityTypesFieldData(?Team $team = null, array $value = [], array $teamsFilter = []): array\n {\n return $this->activityTypeService->getActivityTypeFieldData(team: $team, value: $value, groupIds: $teamsFilter);\n }\n\n public function getDealStageAtCallFieldData(?Team $team = null, array $value = []): array\n {\n return $this->dealStagesService->getDealStageAtCallFieldData(team: $team, value: $value);\n }\n\n public function getCurrentDealStageFieldData(?Team $team = null, array $value = []): array\n {\n return $this->dealStagesService->getCurrentDealStageFieldData(team: $team, value: $value);\n }\n\n public function getDealValueFieldData(?int $valueMin = null, ?int $valueMax = null): array\n {\n return [\n 'id' => 'deal_value',\n 'label' => 'Deal Value',\n 'inputType' => InputTypeEnum::INTEGER_RANGE,\n 'required' => false,\n 'value' => ['min' => $valueMin, 'max' => $valueMax],\n 'queryParams' => [\n 'min' => 'min_deal_value',\n 'max' => 'max_deal_value',\n ],\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getCallTypeFieldData(bool $conferenceOn = false, bool $dialerOn = false): array\n {\n $value = [];\n $conferenceOn && $value[] = self::CALL_TYPE_CONFERENCE;\n $dialerOn && $value[] = self::CALL_TYPE_DIALER;\n\n return [\n 'id' => 'call_type',\n 'label' => 'Call Type',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'required' => true,\n 'options' => [\n self::CALL_TYPE_CONFERENCE,\n self::CALL_TYPE_DIALER,\n ],\n 'value' => $value,\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getMediaTypeFieldData(?AutomatedReport $report = null): array\n {\n $value = [];\n\n if ($report) {\n $value = $this->transformMediaTypes($report);\n }\n\n return [\n 'id' => 'media_types',\n 'label' => 'Export as',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'required' => true,\n 'options' => self::MEDIA_TYPE_OBJECTS,\n 'value' => $value,\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getCallDurationFieldData(?int $valueMin = null, ?int $valueMax = null): array\n {\n return [\n 'id' => 'call_duration',\n 'label' => 'Call Duration',\n 'inputType' => InputTypeEnum::INTEGER_RANGE,\n 'required' => false,\n 'value' => ['min' => $valueMin, 'max' => $valueMax],\n 'queryParams' => [\n 'min' => 'min_call_duration',\n 'max' => 'max_call_duration',\n ],\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getRecipientsFieldData(?Team $team = null, array $value = []): array\n {\n return $this->recipientsService->getRecipientsFieldData(team: $team, value: $value);\n }\n\n public function getJiminnyRecipientsFieldData(array $value = []): array\n {\n return $this->recipientsService->getJiminnyRecipientsFieldData($value);\n }\n\n public function getAdditionalPromptInputFieldData(?string $value = null): array\n {\n return [\n 'id' => 'additional_prompt_input',\n 'label' => 'Special requirements',\n 'inputType' => InputTypeEnum::TEXTAREA,\n 'required' => false,\n 'placeholder' => 'What should be the focus of the report?',\n 'value' => $value,\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getCustomReportNameFieldData(?string $value = null): array\n {\n return [\n 'id' => 'custom_name',\n 'label' => 'Custom report name',\n 'inputType' => InputTypeEnum::TEXT,\n 'required' => false,\n 'placeholder' => 'Enter custom name',\n 'value' => $value,\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n // data providers\n public function getTeams(): array\n {\n $teams = $this->teamRepository->getTeamsForKiosk(status: Team::STATUS_ACTIVE);\n\n $teamData = [];\n foreach ($teams as $team) {\n if (! $team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {\n continue;\n }\n\n $teamData[] = $this->transformTeam($team);\n }\n\n return $teamData;\n }\n\n public function getTeamGroups(string $teamUuid): array\n {\n $data = [];\n $team = $this->getTeam($teamUuid);\n\n if ($team !== null) {\n $groups = $team->groups()->get();\n\n foreach ($groups as $group) {\n $data[] = [\n 'id' => $group->getUuid(),\n 'name' => $group->getName(),\n ];\n }\n }\n\n return $data;\n }\n\n public function getTeamsGroupsOptions(array $filterTeamUuids = []): array\n {\n $data = [];\n $teams = $this->getTeams();\n\n foreach ($teams as $team) {\n if (! empty($filterTeamUuids) && ! in_array($team['id'], $filterTeamUuids, true)) {\n continue;\n }\n\n $data[] = [\n 'label' => $team['name'],\n 'groups' => $this->getTeamGroups($team['id']),\n ];\n }\n\n return $data;\n }\n\n public function getTeam(string $teamUuid): ?Team\n {\n return $this->teamRepository->idOrUuid($teamUuid);\n }\n\n public function getTeamById(int $teamId): ?Team\n {\n return $this->teamRepository->find($teamId);\n }\n\n public function getGroupsUuids(AutomatedReport $report): array\n {\n $uuids = [];\n $reportGroups = $report->getGroups();\n foreach ($reportGroups as $groupId) {\n if ($group = $this->groupRepository->find($groupId)) {\n $uuids[] = $group->getUuid();\n }\n }\n\n return $uuids;\n }\n\n public function getPlaybookCategoriesUuids(AutomatedReport $report): array\n {\n $uuids = [];\n $playbookCategories = $report->getPlaybookCategories();\n foreach ($playbookCategories as $id) {\n if ($category = $this->playbookCategoryRepository->find($id)) {\n $uuids[] = $category->getUuid();\n }\n }\n\n return $uuids;\n }\n\n public function getDealAtCallStagesUuids(AutomatedReport $report): array\n {\n $uuids = [];\n $reportStages = $report->getDealAtCallStages();\n foreach ($reportStages as $id) {\n if ($stage = $this->stageRepository->find($id)) {\n $uuids[] = $stage->getUuid();\n }\n }\n\n return $uuids;\n }\n\n public function getCurrentDealStagesUuids(AutomatedReport $report): array\n {\n $uuids = [];\n $reportStages = $report->getCurrentDealStages();\n foreach ($reportStages as $id) {\n if ($stage = $this->stageRepository->find($id)) {\n $uuids[] = $stage->getUuid();\n }\n }\n\n return $uuids;\n }\n\n public function getUsersUuids(AutomatedReport $report): array\n {\n return $this->extractUserUuids($report->getRecipients());\n }\n\n public function getJiminnyUsersUuids(AutomatedReport $report): array\n {\n return $this->extractUserUuids($report->getJiminnyRecipients());\n }\n\n /**\n * @param array<string, mixed> $recipients\n */\n private function extractUserUuids(array $recipients): array\n {\n $userIds = $recipients['users'] ?? [];\n\n return collect($userIds)\n ->map(fn ($id) => $this->userRepository->find((int) $id))\n ->filter()\n ->map(fn (UserContract $user) => $user->getUuid())\n ->values()\n ->all();\n }\n\n // get mail data\n public function getRecipientUsers(AutomatedReport $report): array\n {\n return $this->buildRecipientUsers($report->getRecipients());\n }\n\n private function getJiminnyRecipientUsers(AutomatedReport $report): array\n {\n return $this->buildRecipientUsers($report->getJiminnyRecipients());\n }\n\n /**\n * @param array<string, mixed> $recipients\n */\n private function buildRecipientUsers(array $recipients): array\n {\n $userIds = $recipients['users'] ?? [];\n\n return collect($userIds)\n ->map(fn ($id) => $this->userRepository->find((int) $id))\n ->filter()\n ->map(fn (UserContract $user) => [\n 'email' => $user->getEmailAddress(),\n 'name' => $user->getName(),\n 'timezone' => $user->getTimezone()->getName(),\n ])\n ->values()\n ->all();\n }\n\n public function getValidRecipientUsers(AutomatedReport $report, bool $includeJiminny = false): array\n {\n if ($report->isAskJiminnyReport()) {\n $recipients = $this->resolveAskJiminnyRecipients($report);\n } else {\n $recipients = $this->getRecipientUsers($report);\n if ($includeJiminny) {\n $recipients = array_merge($recipients, $this->getJiminnyRecipientUsers($report));\n }\n }\n\n $emails = [];\n\n return array_values(array_filter(\n $recipients,\n static function ($recipient) use (&$emails) {\n if (empty($recipient['email']) || in_array($recipient['email'], $emails, true)) {\n return false;\n }\n $emails[] = $recipient['email'];\n\n return true;\n }\n ));\n }\n\n private function resolveAskJiminnyRecipients(AutomatedReport $report): array\n {\n $recipients = [];\n\n $creator = $report->getCreator();\n if ($creator !== null) {\n $recipients[] = [\n 'email' => $creator->getEmailAddress(),\n 'name' => $creator->getName(),\n 'timezone' => $creator->getTimezone()->getName(),\n ];\n }\n\n return array_merge(\n $recipients,\n $this->buildRecipientUsers($report->getRecipients()),\n $this->getGroupRecipientUsers($report),\n );\n }\n\n private function getGroupRecipientUsers(AutomatedReport $report): array\n {\n $users = [];\n foreach ($report->getGroups() as $groupId) {\n $group = $this->groupRepository->find($groupId);\n if ($group === null) {\n continue;\n }\n foreach ($group->getMembers() as $member) {\n $users[] = [\n 'email' => $member->getEmailAddress(),\n 'name' => $member->getName(),\n 'timezone' => $member->getTimezone()->getName(),\n ];\n }\n }\n\n return $users;\n }\n\n public function getReportTypeName(AutomatedReportResult $report): string\n {\n $type = $report->getReport()->getType();\n\n $getType = $this->transformReportType($type);\n\n return $getType['name'];\n }\n\n public function getReportPeriodName(AutomatedReportResult $report): string\n {\n $from = $report->getFromDate();\n $to = $report->getToDate();\n $frequency = $report->getReport()->getFrequency();\n\n if ($from === null || $to === null) {\n if (! $report->getReport()->isAskJiminnyReport()) {\n $invalidPeriod = $from === null ? 'from' : 'to';\n\n throw new ApplicationException('Report period is invalid: ' . $invalidPeriod);\n }\n\n $period = $this->calculateFromAndToDatePeriod($frequency);\n $from = $period['fromDate'];\n $to = $period['toDate'];\n }\n\n return $this->formatReportPeriodName($frequency, $from, $to);\n }\n\n private function formatReportPeriodName(string $frequency, Carbon $from, Carbon $to): string\n {\n $fromYear = $from->format('Y');\n $toYear = $to->format('Y');\n $differentYears = $fromYear !== $toYear;\n\n switch ($frequency) {\n case self::FREQUENCY_DAILY:\n return $from->format('j M Y');\n\n case self::FREQUENCY_QUARTERLY:\n // 'Jan-Mar 2025' or 'Nov 2024-Jan 2025' if years differ\n $startMonth = $from->format('M');\n $endMonth = $to->copy()->subMonth();\n $endMonthName = $endMonth->format('M');\n $endMonthYear = $endMonth->format('Y');\n\n if ($differentYears) {\n return \"{$startMonth} {$fromYear} - {$endMonthName} {$endMonthYear}\";\n }\n\n return \"{$startMonth} - {$endMonthName} {$toYear}\";\n\n case self::FREQUENCY_MONTHLY:\n // 'May 2025' - monthly reports are always within the same year\n return $from->format('M Y');\n\n case self::FREQUENCY_WEEKLY:\n // '4 - 8 Aug 2025', '27 Oct - 3 Nov 2025', or '28 Dec 2024 - 3 Jan 2025' if years differ\n $startDay = $from->format('j');\n $endDay = $to->format('j');\n $startMonth = $from->format('M');\n $endMonth = $to->format('M');\n\n if ($differentYears) {\n return \"{$startDay} {$startMonth} {$fromYear} - {$endDay} {$endMonth} {$toYear}\";\n }\n\n if ($startMonth !== $endMonth) {\n return \"{$startDay} {$startMonth} - {$endDay} {$endMonth} {$toYear}\";\n }\n\n return \"{$startDay} - {$endDay} {$endMonth} {$toYear}\";\n\n case self::FREQUENCY_ONE_OFF:\n // '2 May-31 May 2025' or '15 Dec 2024-15 Jan 2025' if years differ\n $startDay = $from->format('j');\n $startMonth = $from->format('M');\n $endDay = $to->format('j');\n $endMonth = $to->format('M');\n\n // If same month and year, use a format like '2-31 May 2025'\n if ($startMonth === $endMonth && ! $differentYears) {\n return \"{$startDay} - {$endDay} {$startMonth} {$toYear}\";\n }\n\n // If different years, include both years\n if ($differentYears) {\n return \"{$startDay} {$startMonth} {$fromYear} - {$endDay} {$endMonth} {$toYear}\";\n }\n\n // Same year but different months\n return \"{$startDay} {$startMonth} - {$endDay} {$endMonth} {$toYear}\";\n\n default:\n // Default format for unknown frequencies\n return $from->format('j M Y') . ' - ' . $to->format('j M Y');\n }\n }\n\n public function getReportTeamsName(AutomatedReportResult $report): string\n {\n $groups = $report->getGroups();\n\n if (empty($groups)) {\n return 'All';\n }\n\n // Get group names from repository\n $groupNames = [];\n foreach ($groups as $groupId) {\n $group = $this->groupRepository->find($groupId);\n if ($group) {\n $groupNames[] = $group->getName();\n }\n }\n\n if (count($groupNames) === 1) {\n // Single team format\n $teamsName = $groupNames[0];\n } else {\n // Multiple teams format\n $teamsName = implode(', ', $groupNames);\n }\n\n return $teamsName;\n }\n\n public function getReportFileName(AutomatedReportResult $report): string\n {\n $customName = $report->getReport()->getCustomName();\n $periodName = $this->getReportPeriodName($report);\n $filenameSuffix = $this->getFilenameSuffix($report);\n\n if ($customName) {\n if ($filenameSuffix) {\n $customName .= \" {$filenameSuffix}\";\n }\n\n return $this->sanitizeFileName(\"{$customName} - {$periodName}\");\n }\n\n $baseName = $this->getReportTypeName($report);\n\n if ($filenameSuffix) {\n $baseName .= \" {$filenameSuffix}\";\n }\n\n return $this->sanitizeFileName(\"{$baseName} - {$periodName} - {$this->getReportTeamsName($report)}\");\n }\n\n public function getReportFileNameWithExtension(AutomatedReportResult $result): string\n {\n $extension = $this->getMediaTypeMetadata($result)['extension'];\n\n return $this->getReportFileName($result) . '.' . $extension;\n }\n\n public function sanitizeFileName(string $fileName): string\n {\n return str_replace(['/', '\\\\'], '-', $fileName);\n }\n\n public function isUserRecipientOfReport(User $user, AutomatedReport $report): bool\n {\n $recipients = array_map('intval', $report->getRecipients()['users'] ?? []);\n\n return in_array($user->getId(), $recipients);\n }\n\n public function transformReportResults(Collection $automatedReportResults): array\n {\n $data = [];\n foreach ($automatedReportResults as $automatedReportResult) {\n /** @var AutomatedReportResult $automatedReportResult */\n\n $report = $automatedReportResult->getReport();\n\n $createdBy = $report->getCreator();\n $creator = [\n 'id' => $createdBy?->getUuid(),\n 'name' => $createdBy?->getName(),\n 'email' => $createdBy?->getEmailAddress(),\n 'photoUrl' => $createdBy?->getPhotoUrl(),\n ];\n\n $data[] = [\n 'id' => $automatedReportResult->getUuid(),\n 'name' => $automatedReportResult->getName(),\n 'frequency' => $this->transformFrequency($report->getFrequency()),\n 'recipients' => [\n ...array_values($this->transformGroups(team: $report->getTeam(), groupsIds: $report->getGroups())),\n ...array_values($this->transformRecipients($report->getRecipients())),\n ],\n 'report_type' => $this->transformReportType($report->getType()),\n 'media_type' => $automatedReportResult->getMediaType(),\n 'downloadUrl' => $this->generateReportResultDownloadUrl($automatedReportResult),\n 'viewUrl' => $this->generateReportResultViewUrl($automatedReportResult),\n 'generated_at' => $automatedReportResult->getGeneratedAt()?->toIso8601String(),\n 'creator' => $creator,\n ];\n }\n\n return $data;\n }\n\n public function hasCallTypeConference(AutomatedReport $report): bool\n {\n return in_array(self::CALL_TYPE_CONFERENCE['id'], $report->getCallTypes(), true);\n }\n\n public function hasCallTypeDialer(AutomatedReport $report): bool\n {\n return in_array(self::CALL_TYPE_DIALER['id'], $report->getCallTypes(), true);\n }\n\n // transformers\n private function transformTeam(Team $team): array\n {\n if (! $team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {\n return [];\n }\n\n return [\n 'id' => $team->getUuid(),\n 'name' => $team->getName(),\n ];\n }\n\n private function transformReportFullView(AutomatedReport $report): array\n {\n $base = $this->transformReportBase($report);\n\n return $report->getType() === self::TYPE_ASK_JIMINNY\n ? $base + $this->transformAskJiminnyFields($report)\n : $base + $this->transformStandardReportFields($report);\n }\n\n private function transformReportBase(AutomatedReport $report): array\n {\n return [\n 'id' => $report->getUuid(),\n 'organization' => $this->transformOrganization(team: $report->getTeam()),\n 'report_type' => $this->transformReportType($report->getType()),\n 'frequency' => $this->transformFrequency($report->getFrequency()),\n ];\n }\n\n private function transformStandardReportFields(AutomatedReport $report): array\n {\n $team = $report->getTeam();\n\n return [\n 'report_enabled' => $report->getStatus(),\n 'start_date_period' => $report->getFrom()?->format('Y-m-d H:i:s'),\n 'end_date_period' => $report->getTo()?->format('Y-m-d H:i:s'),\n 'deal_value_min' => $report->getDealValueMin(),\n 'deal_value_max' => $report->getDealValueMax(),\n 'call_types' => $this->transformCallType($report->getCallTypes()),\n 'media_types' => $this->transformMediaTypes($report),\n 'call_duration_min' => $this->transformDurationToMinutes($report->getCallDurationMin()),\n 'call_duration_max' => $this->transformDurationToMinutes($report->getCallDurationMax()),\n 'teams' => $this->transformGroups(team: $team, groupsIds: $report->getGroups()),\n 'deal_at_call_stages' => $this->transformStages(team: $team, stagesIds: $report->getDealAtCallStages()),\n 'current_deal_stages' => $this->transformStages(team: $team, stagesIds: $report->getCurrentDealStages()),\n 'recipients' => $this->transformRecipients($report->getRecipients()),\n 'created_by' => $this->transformCreator($report->getCreator()),\n 'additional_prompt_input' => $report->getAdditionalPromptInput(),\n 'custom_name' => $report->getCustomName(),\n 'created_at' => $report->getCreatedAt()->format('Y-m-d H:i:s'),\n 'updated_at' => $report->getUpdatedAt()->format('Y-m-d H:i:s'),\n 'deleted_at' => $report->getDeletedAt()?->format('Y-m-d H:i:s'),\n ];\n }\n\n private function transformAskJiminnyFields(AutomatedReport $report): array\n {\n $team = $report->getTeam();\n $creatorId = $report->getAttribute('created_by');\n $explicitUserIds = array_values(array_filter(\n $report->getRecipients()['users'] ?? [],\n static fn ($id) => $id !== $creatorId\n ));\n\n return [\n 'report_name' => $report->getCustomName(),\n 'enabled' => $report->getStatus(),\n 'share_teams' => $this->transformGroups(team: $team, groupsIds: $report->getGroups()),\n 'share_users' => $this->transformRecipients(['users' => $explicitUserIds]),\n 'saved_search' => $this->transformSafeSearch($report->getSavedSearch()),\n 'ask_jiminny_prompt' => $this->transformAskJiminnyPrompt($report->getAskAnythingPrompt()),\n 'expires_on' => $report->getExpiresAt()?->format('Y-m-d'),\n ];\n }\n\n private function transformOrganization(?Team $team): array\n {\n return [\n 'id' => $team?->getUuid(),\n 'name' => $team?->getName(),\n ];\n }\n\n private function transformReportType(string $type): array\n {\n foreach (self::ALL_TYPES as $typeItem) {\n if ($typeItem['id'] === $type) {\n return $typeItem;\n }\n }\n\n return [];\n }\n\n private function transformCallType(array $types): array\n {\n $result = [];\n $callTypes = [self::CALL_TYPE_CONFERENCE, self::CALL_TYPE_DIALER];\n\n foreach ($types as $type) {\n foreach ($callTypes as $callTypeItem) {\n if ($callTypeItem['id'] === $type) {\n $result[] = $callTypeItem;\n\n break;\n }\n }\n }\n\n return $result;\n }\n\n private function transformMediaTypes(AutomatedReport $report): array\n {\n $values = [];\n\n foreach ($report->getMediaTypes() as $mediaType) {\n if (! in_array($mediaType, self::MEDIA_TYPES, true)) {\n continue;\n }\n\n $values[] = match ($mediaType) {\n self::MEDIA_TYPE_PDF => self::MEDIA_TYPE_OBJECT_PDF,\n self::MEDIA_TYPE_PODCAST => self::MEDIA_TYPE_OBJECT_PODCAST,\n };\n }\n\n return $values;\n }\n\n private function transformFrequency(string $frequency): array\n {\n foreach (self::ALL_FREQUENCIES as $frequencyItem) {\n if ($frequencyItem['id'] === $frequency) {\n return $frequencyItem;\n }\n }\n\n return [];\n }\n\n public function transformDurationToMinutes(?int $duration): ?int\n {\n if (! $duration) {\n return null;\n }\n\n return (int) ($duration / 60);\n }\n\n private function transformGroups(?Team $team, array $groupsIds): array\n {\n if (empty($groupsIds) || ! $team) {\n return [];\n }\n\n $data = [];\n foreach ($groupsIds as $groupId) {\n $group = $team->groups()->where('id', $groupId)->first();\n\n if ($group) {\n $data[] = [\n 'id' => $group->getUuid(),\n 'name' => $group->getName(),\n 'photoUrl' => $group->getPhotoUrl(),\n ];\n }\n }\n\n return $data;\n }\n\n private function transformStages(?Team $team, array $stagesIds): array\n {\n if (empty($stagesIds) || ! $team) {\n return [];\n }\n\n $data = [];\n foreach ($stagesIds as $stageId) {\n $stage = $team->stages()->where('id', $stageId)->first();\n\n if ($stage) {\n $data[] = [\n 'id' => $stage->getUuid(),\n 'name' => $stage->getName(),\n ];\n }\n }\n\n return $data;\n }\n\n private function transformRecipients(array $recipients): array\n {\n $users = [];\n foreach ($recipients['users'] ?? [] as $userId) {\n $users[] = $this->transformUser($userId);\n }\n\n return $users;\n }\n\n private function transformCreator(?User $user): ?array\n {\n if ($user === null) {\n return null;\n }\n\n return $this->transformUser($user->getId());\n }\n\n private function transformAskJiminnyPrompt(?AskAnythingPrompt $prompt): ?array\n {\n if ($prompt === null) {\n return null;\n }\n\n return [\n 'id' => $prompt->getUuid(),\n 'name' => $prompt->getTitle(),\n ];\n }\n\n private function transformSafeSearch(?Search $search): ?array\n {\n if ($search === null) {\n return null;\n }\n\n return [\n 'id' => $search->getUuid(),\n 'name' => $search->getName(),\n ];\n }\n\n private function transformUser(int $userId): array\n {\n /* @var ?User $user */\n $user = $this->userRepository->find($userId);\n\n return [\n 'id' => $user?->getUuid(),\n 'name' => $user?->getName(),\n 'email' => $user?->getEmailAddress(),\n 'photoUrl' => $user?->getPhotoUrl(),\n ];\n }\n\n public function create(array $data): array\n {\n $validatedData = $this->validateAndTransformData($data);\n $validatedData['created_by'] = auth()->id();\n\n $automatedReport = $this->automatedReportsRepository->create($validatedData);\n\n $this->generateOneOffReport($automatedReport);\n\n return $this->transformReportFullView($automatedReport);\n }\n\n public function update(string $uuid, array $data): array\n {\n $validatedData = $this->validateAndTransformData($data);\n $report = $this->automatedReportsRepository->findByUuid($uuid);\n\n if (! $report) {\n throw new InvalidArgumentException('Report not found');\n }\n\n $oldCustomName = $report->getCustomName();\n\n $automatedReport = $this->automatedReportsRepository->update($report, $validatedData);\n\n if ($oldCustomName !== $automatedReport->getCustomName()) {\n $this->updateResultNames($automatedReport);\n }\n\n $this->generateOneOffReport($automatedReport);\n\n return $this->transformReportFullView($automatedReport);\n }\n\n /**\n * Create an Ask Jiminny report.\n */\n public function createAskJiminnyReport(array $data, User $creator): array\n {\n $validatedData = $this->validateAskJiminnyReportData($data, $creator);\n $validatedData['created_by'] = $creator->getId();\n\n $automatedReport = $this->automatedReportsRepository->create($validatedData);\n\n return $this->transformReportFullView($automatedReport);\n }\n\n /**\n * Update an Ask Jiminny report.\n */\n public function updateAskJiminnyReport(AutomatedReport $report, array $data, User $user): array\n {\n if (! $report->isAskJiminnyReport()) {\n throw new InvalidArgumentException('Report is not an Ask Jiminny report');\n }\n\n $validatedData = $this->validateAskJiminnyReportData($data, $user);\n\n $oldCustomName = $report->getCustomName();\n\n $automatedReport = $this->automatedReportsRepository->update($report, $validatedData);\n\n if ($oldCustomName !== $automatedReport->getCustomName()) {\n $this->updateResultNames($automatedReport);\n }\n\n return $this->transformReportFullView($automatedReport);\n }\n\n public function updateAskJiminnyReportStatus(AutomatedReport $report, bool $status): array\n {\n $this->automatedReportsRepository->update($report, ['status' => $status]);\n\n return $this->transformReportFullView($report->fresh());\n }\n\n /**\n * Validate and transform data for Ask Jiminny reports.\n */\n private function validateAskJiminnyReportData(array $data, User $user): array\n {\n // Validate name\n $name = trim($data['report_name'] ?? '');\n if (empty($name)) {\n throw new InvalidArgumentException('Report name is required');\n }\n if (mb_strlen($name) > 50) {\n throw new InvalidArgumentException('Report name must be 50 characters or less');\n }\n\n // Validate frequency (only daily, weekly, monthly for Ask Jiminny)\n $frequency = $data['frequency'] ?? null;\n $askJiminnyFrequencies = [self::FREQUENCY_DAILY, self::FREQUENCY_WEEKLY, self::FREQUENCY_MONTHLY];\n if (! in_array($frequency, $askJiminnyFrequencies, true)) {\n throw new InvalidArgumentException('Frequency must be daily, weekly, or monthly');\n }\n\n // Validate expiration date\n $expiresAt = $data['expires_on'] ?? null;\n if (empty($expiresAt)) {\n throw new InvalidArgumentException('Expiration date is required');\n }\n\n try {\n $expiresAtDate = Carbon::parse($expiresAt);\n } catch (InvalidFormatException $e) {\n throw new InvalidArgumentException('Expiration date format is invalid');\n }\n $maxExpiration = Carbon::now()->addYear();\n if ($expiresAtDate->gt($maxExpiration)) {\n throw new InvalidArgumentException('Expiration date cannot be more than 1 year from now');\n }\n if ($expiresAtDate->isPast()) {\n throw new InvalidArgumentException('Expiration date cannot be in the past');\n }\n\n // Validate saved search\n $activitySearchId = $data['saved_search'] ?? null;\n if (empty($activitySearchId)) {\n throw new InvalidArgumentException('Saved search is required');\n }\n $savedSearch = $this->activitySearchRepository->findByUuidAndUser($activitySearchId, $user);\n if (! $savedSearch) {\n throw new InvalidArgumentException('Saved search not found or does not belong to you');\n }\n\n // Validate saved prompt\n $askAnythingPromptId = $data['ask_jiminny_prompt'] ?? null;\n if (empty($askAnythingPromptId)) {\n throw new InvalidArgumentException('Ask Jiminny prompt is required');\n }\n $prompt = $this->askAnythingRepository->getPromptByUuid($askAnythingPromptId);\n if (! $prompt) {\n throw new InvalidArgumentException('Ask Jiminny prompt not found');\n }\n\n // Validate status\n $status = $data['enabled'] ?? false;\n\n $recipientUserIds = [$user->getId()];\n\n if (! empty($data['share_users'])) {\n $sharedUserIds = $this->validateAndGetUserIdsByTeam(\n $user->team,\n (array) $data['share_users']\n );\n $recipientUserIds = array_merge($recipientUserIds, $sharedUserIds);\n }\n\n $sharedGroupIds = [];\n if (! empty($data['share_teams'])) {\n $sharedGroupIds = $this->validateAndGetGroupIds($user->team, (array) $data['share_teams']);\n }\n\n $recipientUserIds = array_values(array_unique($recipientUserIds));\n\n return [\n 'team_id' => $user->getTeamId(),\n 'type' => self::TYPE_ASK_JIMINNY,\n 'status' => (bool) $status,\n 'frequency' => $frequency,\n 'custom_name' => $name,\n 'activity_search_id' => $savedSearch->getId(),\n 'ask_anything_prompt_id' => $prompt->getId(),\n 'expires_at' => $expiresAtDate->toDateString(),\n 'media_types' => [self::MEDIA_TYPE_PDF],\n 'call_types' => [],\n 'recipients' => ['users' => $recipientUserIds],\n 'groups' => $sharedGroupIds,\n ];\n }\n\n public static function getAskJiminnyFrequencies(): array\n {\n return array_map(static function ($frequency) {\n return $frequency['id'];\n }, self::ASK_JIMINNY_FREQUENCIES);\n }\n\n public function getAskJiminnyReportFilters(User $user): array\n {\n $savedSearches = $this->activitySearchRepository->findByUserOrderedByName($user)\n ->map(fn (Search $search) => [\n 'id' => $search->getUuid(),\n 'name' => $search->getName(),\n ])\n ->values()->all();\n\n $prompts = collect(\n $this->askAnythingPromptService->get($user, AskAnythingPromptTarget::on_demand)\n )->map(fn (AskAnythingPromptDto $prompt) => [\n 'id' => $prompt->id,\n 'name' => $prompt->title,\n ])->values()->all();\n\n return [\n [\n 'id' => 'prompt',\n 'label' => 'Prompt',\n 'options' => $prompts,\n ],\n [\n 'id' => 'saved_search',\n 'label' => 'Saved Search',\n 'options' => $savedSearches,\n ],\n ];\n }\n\n public function getAskJiminnyReportFormData(User $user, ?AutomatedReport $report = null): array\n {\n $team = $user->getTeam();\n $userTimezone = $user->getTimezone();\n\n $savedSearches = $this->activitySearchRepository->findByUserOrderedByName($user)\n ->map(fn (Search $search) => [\n 'id' => $search->getUuid(),\n 'name' => $search->getName(),\n ])\n ->values()->all();\n\n $prompts = collect(\n $this->askAnythingPromptService->get($user, AskAnythingPromptTarget::on_demand)\n )->map(fn (AskAnythingPromptDto $prompt) => [\n 'id' => $prompt->id,\n 'name' => $prompt->title,\n ])->values()->all();\n\n $teamGroups = $this->groupRepository->getAllByTeam($team)->map(fn ($group) => [\n 'id' => $group->getUuid(),\n 'name' => $group->getName(),\n ])->values()->all();\n\n $shareUsers = $this->recipientsService->getRecipientsFieldData(team: $team)['options'] ?? [];\n\n $sharedTeamsValue = [];\n $sharedUsersValue = [];\n if ($report) {\n $sharedTeamsValue = $this->transformGroups($team, $report->getGroups());\n\n $recipientUserIds = $report->getRecipients()['users'] ?? [];\n $creatorId = $report->getAttribute('created_by');\n $sharedUserIds = array_values(array_filter(\n $recipientUserIds,\n static fn ($id) => $id !== $creatorId\n ));\n $sharedUsersValue = collect($sharedUserIds)\n ->map(fn ($id) => $this->userRepository->find((int) $id))\n ->filter()\n ->map(fn (User $u) => [\n 'id' => $u->getUuid(),\n 'name' => $u->getName(),\n ])\n ->values()\n ->all();\n }\n\n return [\n 'fields' => [\n [\n 'id' => 'enabled',\n 'inputType' => InputTypeEnum::TOGGLE,\n 'label' => '',\n 'value' => $report?->getStatus() ?? false,\n ],\n [\n 'id' => 'report_name',\n 'inputType' => InputTypeEnum::TEXT,\n 'label' => 'Name',\n 'placeholder' => 'Enter name',\n 'required' => true,\n 'validation' => ['maxLength' => 50],\n 'value' => $report?->getCustomName() ?? '',\n ],\n [\n 'id' => 'frequency',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'label' => 'Frequency',\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => self::ASK_JIMINNY_FREQUENCIES,\n 'value' => $report ? $this->transformFrequency($report->getFrequency()) : null,\n ],\n [\n 'id' => 'expires_on',\n 'inputType' => InputTypeEnum::DATE,\n 'label' => 'Expires on',\n 'required' => true,\n 'placeholder' => 'Select',\n 'validation' => [\n 'minDate' => now($userTimezone)->toDateString(),\n 'maxDate' => now($userTimezone)->addYear()->toDateString(),\n ],\n 'value' => $report?->getExpiresAt()?->toDateString(),\n ],\n [\n 'id' => 'share_teams',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'label' => 'Team',\n 'required' => false,\n 'placeholder' => 'Select',\n 'options' => $teamGroups,\n 'value' => $sharedTeamsValue,\n ],\n [\n 'id' => 'share_users',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'label' => 'Team member',\n 'required' => false,\n 'placeholder' => 'Select',\n 'groupLabelKey' => 'label',\n 'groupValuesKey' => 'users',\n 'optionLabelKey' => 'name',\n 'optionValueKey' => 'id',\n 'options' => $shareUsers,\n 'value' => $sharedUsersValue,\n ],\n [\n 'id' => 'saved_search',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'label' => 'Saved search',\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => $savedSearches,\n 'value' => $report && $report->getSavedSearch() ? [\n 'id' => $report->getSavedSearch()->getUuid(),\n 'name' => $report->getSavedSearch()->getName(),\n ] : null,\n ],\n [\n 'id' => 'ask_jiminny_prompt',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'label' => 'Ask Jiminny prompt',\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => $prompts,\n 'value' => $report && $report->getAskAnythingPrompt() ? [\n 'id' => $report->getAskAnythingPrompt()->getUuid(),\n 'name' => $report->getAskAnythingPrompt()->getTitle(),\n ] : null,\n ],\n ],\n ];\n }\n\n private function updateResultNames(AutomatedReport $automatedReport): void\n {\n $results = $this->automatedReportsRepository->getResultsByReport($automatedReport);\n\n foreach ($results as $result) {\n $result->update(['name' => $this->getReportFileName($result)]);\n }\n }\n\n public function updateStatus(string $uuid, array $data): array\n {\n $automatedReport = $this->automatedReportsRepository->findByUuid($uuid);\n\n if (! $automatedReport) {\n throw new ModelNotFoundException('Report not found');\n }\n\n $status = $this->validateReportStatus($data['report_enabled'] ?? null);\n $automatedReport->update([\n 'status' => $status,\n ]);\n\n $this->generateOneOffReport($automatedReport);\n\n return $this->transformReportFullView($automatedReport);\n }\n\n private function generateOneOffReport(AutomatedReport $automatedReport): void\n {\n // the scheduler handles all the other frequency types\n if ($automatedReport->getStatus() === false || $automatedReport->getFrequency() !== self::FREQUENCY_ONE_OFF) {\n return;\n }\n\n $this->dispatcher->dispatch(new RequestGenerateReportJob($automatedReport->getUuid()));\n }\n\n public function getReport(string $uuid): AutomatedReport\n {\n $automatedReport = $this->automatedReportsRepository->findByUuid($uuid);\n\n if (! $automatedReport) {\n throw new ModelNotFoundException('Report not found');\n }\n\n return $automatedReport;\n }\n\n public function get(string $uuid): array\n {\n $automatedReport = $this->getReport($uuid);\n\n return $this->transformReportFullView($automatedReport);\n }\n\n public function list(string $sortColumn = 'created_at', string $sortDirection = 'desc'): array\n {\n $results = [];\n $collection = $this->automatedReportsRepository->getAllStandardReports($sortColumn, $sortDirection);\n\n /** @var AutomatedReport $report */\n foreach ($collection as $report) {\n $results[] = $this->transformReportFullView($report);\n }\n\n return ['data' => $results];\n }\n\n public function listAskJiminnyReports(\n User $user,\n string $sortColumn = 'created_at',\n string $sortDirection = 'desc'\n ): array {\n $results = [];\n $collection = $this->automatedReportsRepository->getAskJiminnyReportsByUser($user, $sortColumn, $sortDirection);\n\n /** @var AutomatedReport $report */\n foreach ($collection as $report) {\n $results[] = $this->transformReportFullView($report);\n }\n\n return ['data' => $results];\n }\n\n public function delete(string $uuid): void\n {\n $automatedReport = $this->automatedReportsRepository->findByUuid($uuid);\n\n if (! $automatedReport) {\n throw new ModelNotFoundException('Report not found');\n }\n\n $automatedReport->delete();\n }\n\n public function createReportResult(AutomatedReport $automatedReport, array $data = []): AutomatedReportResult\n {\n return $this->automatedReportsRepository->createResult(\n array_merge(\n [\n 'report_id' => $automatedReport->getId(),\n 'status' => AutomatedReportResult::STATUS_DEFAULT,\n ],\n $data\n )\n );\n }\n\n public function getReportResult(string $resultUuid): AutomatedReportResult\n {\n $report = $this->automatedReportsRepository->findResultByUuid($resultUuid);\n\n if (! $report) {\n throw new ModelNotFoundException('Report Result not found');\n }\n\n return $report;\n }\n\n public function findChildResult(AutomatedReportResult $result, string $type): ?AutomatedReportResult\n {\n return $this->automatedReportsRepository->findChildResult($result, $type);\n }\n\n // prophet API calls\n /**\n * @throws ApplicationException\n */\n public function getGenerateReportPayload(AutomatedReport $automatedReport, string $reportResultUuid): array\n {\n $period = $this->calculateFromAndToDate($automatedReport);\n $fromDate = $period['fromDate'];\n $toDate = $period['toDate'];\n\n return [\n 'team_id' => $automatedReport->getTeamId(),\n 'request_id' => $reportResultUuid,\n 'report_type' => $automatedReport->getType(),\n 'media_types' => $automatedReport->getMediaTypes(),\n 'from_date' => $fromDate->startOfDay()->format(DateTimeInterface::RFC3339),\n 'to_date' => $toDate->endOfDay()->format(DateTimeInterface::RFC3339),\n 'group_ids' => $automatedReport->getGroups(),\n 'call_deal_stage' => $automatedReport->getDealAtCallStages(),\n 'current_deal_stage' => $automatedReport->getCurrentDealStages(),\n 'deal_min_value' => $automatedReport->getDealValueMin(),\n 'deal_max_value' => $automatedReport->getDealValueMax(),\n 'call_types' => $automatedReport->getCallTypes(),\n 'call_duration_min_seconds' => $automatedReport->getCallDurationMin(),\n 'call_duration_max_seconds' => $automatedReport->getCallDurationMax(),\n 'special_requirements' => $automatedReport->getAdditionalPromptInput(),\n 'callback_url' => $this->getCallbackUrl(),\n 'report_period' => $this->formatReportPeriodName(\n $automatedReport->getFrequency(),\n $fromDate,\n $toDate,\n ),\n 'playbook_categories' => $automatedReport->getPlaybookCategories(),\n 'custom_name' => $automatedReport->getCustomName(),\n ];\n }\n\n // $inputPayload - FE payload structure\n public function getActivitiesCountPayload(array $inputPayload): array\n {\n // Use validateAndTransformData to validate and normalize input\n $validatedData = $this->validateAndTransformData($inputPayload);\n $period = $this->calculateFromAndToDatePeriod(\n $validatedData['frequency'],\n Carbon::parse($validatedData['from']),\n Carbon::parse($validatedData['to']),\n );\n $fromDate = $period['fromDate'];\n $toDate = $period['toDate'];\n\n // Create payload similar to getGenerateReportPayload\n return [\n 'team_id' => $validatedData['team_id'],\n 'group_ids' => $validatedData['groups'] ?? [],\n 'report_type' => $validatedData['type'],\n 'from_date' => $fromDate->format(DateTimeInterface::RFC3339),\n 'to_date' => $toDate->format(DateTimeInterface::RFC3339),\n 'call_deal_stage' => $validatedData['deal_at_call_stages'] ?? [],\n 'current_deal_stage' => $validatedData['current_deal_stages'] ?? [],\n 'deal_min_value' => $validatedData['deal_value_min'] ?? null,\n 'deal_max_value' => $validatedData['deal_value_max'] ?? null,\n 'call_types' => $validatedData['call_types'],\n 'call_duration_min_seconds' => $validatedData['call_duration_min'] ?? null,\n 'call_duration_max_seconds' => $validatedData['call_duration_max'] ?? null,\n 'special_requirements' => $validatedData['additional_prompt_input'] ?? null,\n 'playbook_categories' => $validatedData['playbook_categories'] ?? [],\n 'request_id' => null,\n 'callback_url' => null,\n ];\n }\n\n public function shouldSendReport(array $users, ?CarbonInterface $generatedAt = null): bool\n {\n if (empty($users)) {\n return false;\n }\n\n $earliestTz = collect($users)\n ->mapWithKeys(function (array $user) {\n $tz = new DateTimeZone($user['timezone']);\n $nowUtc = new DateTime('now', new DateTimeZone('UTC'));\n $offset = $tz->getOffset($nowUtc);\n\n return [$user['timezone'] => $offset];\n })\n ->sortDesc()\n ->keys()\n ->first();\n\n $now = Carbon::now($earliestTz);\n $isScheduledTime = (int) $now->format('H') === self::SENT_REPORT_AT_HOURS;\n\n if ($isScheduledTime) {\n return true;\n }\n\n return $this->hasPassedScheduledTime($generatedAt, $earliestTz);\n }\n\n public function hasPassedScheduledTime(?CarbonInterface $generatedAt, string $timezone): bool\n {\n if ($generatedAt === null) {\n return false;\n }\n\n $now = Carbon::now($timezone);\n $scheduledTime = $now->copy()->setTime(self::SENT_REPORT_AT_HOURS, 0, 0);\n\n if ($now->hour < self::SENT_REPORT_AT_HOURS) {\n $scheduledTime = $scheduledTime->subDay();\n }\n\n $scheduledTimeUtc = $scheduledTime->copy()->utc();\n $generatedAtUtc = $generatedAt->copy()->utc();\n $nowUtc = $now->copy()->utc();\n\n return $generatedAtUtc->lt($scheduledTimeUtc) && $nowUtc->gt($scheduledTimeUtc);\n }\n\n public function calculateFromAndToDatePeriod(\n string $frequency,\n ?Carbon $fromDate = null,\n ?Carbon $toDate = null\n ): array {\n if ($frequency === self::FREQUENCY_ONE_OFF) {\n return [\n 'fromDate' => $fromDate,\n 'toDate' => $toDate,\n ];\n }\n\n $now = Carbon::now();\n\n return match ($frequency) {\n self::FREQUENCY_DAILY => [\n 'fromDate' => $now->copy()->subDay()->startOfDay(),\n 'toDate' => $now->copy()->subDay()->endOfDay(),\n ],\n self::FREQUENCY_WEEKLY => [\n 'fromDate' => $now->copy()->subWeeks(1)->startOfDay(),\n 'toDate' => $now->copy()->subDay()->endOfDay(),\n ],\n self::FREQUENCY_MONTHLY => [\n 'fromDate' => $now->copy()->subMonths(1)->startOfDay(),\n 'toDate' => $now->copy()->subDay()->endOfDay(),\n ],\n self::FREQUENCY_QUARTERLY => [\n 'fromDate' => $now->copy()->subMonths(3)->startOfDay(),\n 'toDate' => $now->copy()->subDay()->endOfDay(),\n ],\n default => throw new InvalidArgumentException(\"Unsupported frequency: {$frequency}\"),\n };\n }\n\n private function calculateFromAndToDate(AutomatedReport $automatedReport): array\n {\n return $this->calculateFromAndToDatePeriod(\n $automatedReport->getFrequency(),\n $automatedReport->getFrom(),\n $automatedReport->getTo()\n );\n }\n\n public function getAskJiminnyGenerateReportPayload(\n AutomatedReport $automatedReport,\n AutomatedReportResult $reportResult,\n array $activityIds,\n ): array {\n return [\n 'user_question' => $automatedReport->getAskAnythingPrompt()?->getContent(),\n 'call_ids' => array_map('strval', $activityIds),\n 'team_id' => $automatedReport->getTeamId(),\n 'request_id' => $reportResult->getUuid(),\n 'callback_url' => $this->getCallbackUrl(),\n 'report_period' => $this->getReportPeriodName($reportResult),\n 'report_name' => $automatedReport->getCustomName(),\n ];\n }\n\n private function getCallbackUrl(): string\n {\n return $this->webhookService->route('jiminny.webhook.reports.ready');\n }\n\n /**\n * Validate and transform payload data for automated reports\n *\n * @param array $data\n *\n * @throws InvalidArgumentException\n *\n * @return array\n */\n private function validateAndTransformData(array $data): array\n {\n // Validate organization (team) and check feature\n $team = $this->validateOrganization($data['organization'] ?? null);\n\n $status = $this->validateReportStatus($data['report_enabled'] ?? null);\n $type = $this->validateReportType($data['report_type'] ?? null);\n $frequency = $this->validateFrequency($data['frequency'] ?? null);\n $additionalPromptInput = $this->validateAdditionalPromptInput(\n $data['additional_prompt_input'] ?? null\n );\n $customReportName = $this->validateCustomReportName($data['custom_name'] ?? null);\n\n // Prepare data for the database\n $reportData = [\n 'team_id' => $team->getId(),\n 'type' => $type,\n 'status' => $status,\n 'frequency' => $frequency,\n 'additional_prompt_input' => $additionalPromptInput,\n 'custom_name' => $customReportName,\n ];\n\n // Validate deal values\n $reportData = $this->validateDealValues($data, $reportData);\n\n // Validate date range\n $reportData = $this->validateDateRange($data, $reportData, $frequency);\n\n // Validate call durations\n $reportData = $this->validateCallDurations($data, $reportData);\n\n // Validate call types\n $reportData = $this->validateCallTypes($data, $reportData);\n\n // Validate media types\n $reportData = $this->validateMediaTypes($data, $reportData);\n\n // Validate groups\n if (isset($data['teams'])) {\n $reportData['groups'] = $this->validateAndGetGroupIds($team, $data['teams']);\n }\n\n // Validate deal stages\n $reportData = $this->validateDealStages($data, $reportData, $team, $type);\n\n // Validate playbook categories\n $reportData = $this->validatePlaybookCategories($data, $reportData, $team);\n\n // Validate recipients\n $reportData['recipients'] = [\n 'users' => $this->validateAndGetUserIdsByTeam($team, $data['recipients'] ?? []),\n ];\n\n if (isset($data['jiminny_recipients'])) {\n // Validate Jiminny recipients\n $reportData['jiminny_recipients'] = [\n 'users' => $this->validateAndGetJiminnyUserIds((array) $data['jiminny_recipients']),\n ];\n }\n\n return $reportData;\n }\n\n private function validateDealValues(array $data, array $reportData): array\n {\n if (isset($data['min_deal_value'])) {\n $reportData['deal_value_min'] = (int) $data['min_deal_value'];\n\n if ($reportData['deal_value_min'] > 4294967295 || $reportData['deal_value_min'] < 0) {\n throw new InvalidArgumentException('Min deal value should be between 0 and 4294967295');\n }\n }\n\n if (isset($data['max_deal_value'])) {\n $reportData['deal_value_max'] = (int) $data['max_deal_value'];\n\n if ($reportData['deal_value_max'] > 4294967295 || $reportData['deal_value_max'] < 0) {\n throw new InvalidArgumentException('Max deal value should be between 0 and 4294967295');\n }\n }\n\n if (isset($data['min_deal_value'], $data['max_deal_value'])\n && $data['min_deal_value'] > $data['max_deal_value']\n ) {\n throw new InvalidArgumentException('Min deal value cannot be greater than max deal value');\n }\n\n return $reportData;\n }\n\n private function validateDateRange(array $data, array $reportData, string $frequency): array\n {\n // Set date range only for one_off frequency\n if ($frequency === 'one_off') {\n if (isset($data['start_date_period'])) {\n $reportData['from'] = $this->parseDate($data['start_date_period']);\n }\n\n if (isset($data['end_date_period'])) {\n $reportData['to'] = $this->parseDate($data['end_date_period']);\n }\n\n if (empty($reportData['from']) || empty($reportData['to'])) {\n throw new InvalidArgumentException(\n 'Start date and end date are required for one_off frequency'\n );\n }\n } else {\n $reportData['from'] = null;\n $reportData['to'] = null;\n }\n\n return $reportData;\n }\n\n private function validateCallDurations(array $data, array $reportData): array\n {\n // Convert call durations from minutes to seconds\n if (isset($data['min_call_duration'])) {\n $reportData['call_duration_min'] = (int) $data['min_call_duration'] * 60;\n\n if ($reportData['call_duration_min'] > 4294967295 || $reportData['call_duration_min'] < 0) {\n throw new InvalidArgumentException('Min call duration should be between 0 and 4294967295');\n }\n }\n\n if (isset($data['max_call_duration'])) {\n $reportData['call_duration_max'] = (int) $data['max_call_duration'] * 60;\n\n if ($reportData['call_duration_max'] > 4294967295 || $reportData['call_duration_max'] < 0) {\n throw new InvalidArgumentException('Max call duration should be between 0 and 4294967295');\n }\n }\n\n return $reportData;\n }\n\n private function validateCallTypes(array $data, array $reportData): array\n {\n // Set call types\n $reportData['call_types'] = $data['call_type'] ?? [];\n if (empty($reportData['call_types'])) {\n $reportData['call_types'] = self::getCallTypes();\n }\n\n foreach ($reportData['call_types'] as $callType) {\n if (! in_array($callType, self::getCallTypes(), true)) {\n throw new InvalidArgumentException(sprintf('Call type %s is invalid', $callType));\n }\n }\n\n return $reportData;\n }\n\n private function validateMediaTypes(array $data, array $reportData): array\n {\n // Set media types from input data\n $reportData['media_types'] = $data['media_types'] ?? [];\n\n if (empty($reportData['media_types'])) {\n throw new InvalidArgumentException('Media types are required');\n }\n\n foreach ($reportData['media_types'] as $mediaType) {\n if (! in_array($mediaType, self::MEDIA_TYPES, true)) {\n throw new InvalidArgumentException(sprintf('Media type %s is invalid', $mediaType));\n }\n }\n\n return $reportData;\n }\n\n private function validateDealStages(array $data, array $reportData, Team $team, string $reportType): array\n {\n // Validate and set deal stages\n if (isset($data['deal_stage_at_call'])) {\n $reportData['deal_at_call_stages'] =\n $this->validateAndGetDealStageIds($team, $data['deal_stage_at_call'], 'Deal stage at call');\n }\n\n if (isset($data['current_deal_stage'])) {\n $reportData['current_deal_stages'] =\n $this->validateAndGetDealStageIds($team, $data['current_deal_stage'], 'Current deal stage');\n }\n\n // Ensure current_deal_stage is not provided for loss_analysis report type\n if ($reportType === self::TYPE_LOSS_ANALYSIS && ! empty($data['current_deal_stage'])) {\n throw new InvalidArgumentException('Current deal stage is not applicable for Loss Analysis reports');\n }\n\n return $reportData;\n }\n\n // transform uuid to id\n private function validatePlaybookCategories(array $data, array $reportData, Team $team): array\n {\n $key = 'playbook_categories';\n\n if (isset($data[$key])) {\n $payloadIds = $data[$key];\n $ids = [];\n\n foreach ($payloadIds as $uuid) {\n $uuid = (string) $uuid;\n\n try {\n $playbookCategory = $this->playbookCategoryRepository->findByUuid($uuid);\n } catch (Throwable $throwable) {\n Log::error(__METHOD__ . ' ' . $throwable->getMessage());\n\n throw new InvalidArgumentException(sprintf('Playbook category %s not found', $uuid));\n }\n\n if (! $playbookCategory) {\n throw new InvalidArgumentException(sprintf('Playbook category %s not found', $uuid));\n }\n\n if (! $playbookCategory->hasPlaybook()) {\n throw new InvalidArgumentException(sprintf('Playbook category %s has no playbook', $uuid));\n }\n\n if ($playbookCategory->getPlaybook()->getTeamId() !== $team->getId()) {\n throw new InvalidArgumentException(\n sprintf('Playbook category %s not found for team %s', $uuid, $team->getUuid())\n );\n }\n\n $ids[] = $playbookCategory->getId();\n }\n\n $reportData[$key] = $ids;\n }\n\n return $reportData;\n }\n\n private function validateReportStatus($status): bool\n {\n if (! in_array($status, [true, false], true)) {\n throw new InvalidArgumentException('Report status is invalid');\n }\n\n return $status;\n }\n\n private function validateReportType($type): string\n {\n if (! in_array($type, self::getTypes(), true)) {\n throw new InvalidArgumentException(sprintf('Report type is invalid: %s', $type));\n }\n\n return $type;\n }\n\n private function validateFrequency($frequency): string\n {\n if (! in_array($frequency, self::getFrequencies(), true)) {\n throw new InvalidArgumentException('Frequency is invalid');\n }\n\n return $frequency;\n }\n\n private function validateAdditionalPromptInput(?string $additionalPromptInput): ?string\n {\n if ($additionalPromptInput && strlen($additionalPromptInput) > 5000) {\n throw new InvalidArgumentException('Additional Prompt Input should be less than 5000 characters');\n }\n\n return $additionalPromptInput;\n }\n\n private function validateCustomReportName(?string $customReportName): ?string\n {\n if ($customReportName === null || $customReportName === '') {\n return null;\n }\n\n if (strlen($customReportName) > 70) {\n throw new InvalidArgumentException('Custom report name should be less than 70 characters');\n }\n\n return $customReportName;\n }\n\n private function validateOrganization(?string $organizationUuid): Team\n {\n if (! $organizationUuid) {\n throw new InvalidArgumentException('Organization is required');\n }\n\n $team = $this->teamRepository->idOrUuid($organizationUuid);\n\n if (! $team) {\n throw new InvalidArgumentException('Organization not found');\n }\n\n if (! $team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {\n throw new InvalidArgumentException('Organization does not have the Automated Reports feature');\n }\n\n return $team;\n }\n\n private function validateAndGetGroupIds(Team $team, array $teamUuids): array\n {\n $groupIds = [];\n\n foreach ($teamUuids as $uuid) {\n $group = $this->groupRepository->findByUuid($uuid);\n\n if ($group === null || $group->getTeamId() !== $team->getId()) {\n throw new InvalidArgumentException(\n sprintf('Group %s not found for team %s', $uuid, $team->getUuid())\n );\n }\n\n $groupIds[] = $group->getId();\n\n }\n\n return $groupIds;\n }\n\n private function validateAndGetDealStageIds(Team $team, array $stageUuids, string $propertyLabel): array\n {\n $stageIds = [];\n\n foreach ($stageUuids as $uuid) {\n $stage = $this->stageRepository->findByUuid($uuid);\n\n if ($stage === null || $stage->getTeamId() !== $team->getId()) {\n throw new InvalidArgumentException(\n sprintf('Stage %s not found for team %s for %s', $uuid, $team->getUuid(), $propertyLabel)\n );\n }\n\n $stageIds[] = $stage->getId();\n }\n\n return $stageIds;\n }\n\n private function validateAndGetUserIds(array $userUuids, callable $teamCheck): array\n {\n if (empty($userUuids)) {\n return [];\n }\n\n $userIds = [];\n\n foreach ($userUuids as $uuid) {\n $user = $this->userRepository->findByUuid($uuid);\n\n if (! $user || ! $user->isStatusActive()) {\n throw new InvalidArgumentException(\n sprintf('User %s not found or is not active', $uuid)\n );\n }\n\n if (! $teamCheck($user)) {\n throw new InvalidArgumentException(\n sprintf('User %s does not belong to the allowed team(s)', $uuid)\n );\n }\n\n $userIds[] = $user->getId();\n }\n\n return $userIds;\n }\n\n private function validateAndGetUserIdsByTeam(Team $team, array $userUuids): array\n {\n return $this->validateAndGetUserIds($userUuids, fn ($user) => $user->getTeamId() === $team->getId());\n }\n\n private function validateAndGetJiminnyUserIds(array $userUuids): array\n {\n $allowedTeamIds = config('kiosk.teamIds', []);\n\n return $this->validateAndGetUserIds($userUuids, fn ($user) => in_array($user->getTeamId(), $allowedTeamIds, true));\n }\n\n private function parseDate(string $dateString): string\n {\n return date('Y-m-d H:i:s', strtotime($dateString));\n }\n\n private function generateReportResultViewUrl(AutomatedReportResult $result): string\n {\n $mediaResource = $this->getReportMediaRouteResource($result);\n\n return route('ai-reports.' . $mediaResource . '.view', ['uuid' => $result->getUuid()]);\n }\n\n private function generateReportResultDownloadUrl(AutomatedReportResult $result): string\n {\n $mediaResource = $this->getReportMediaRouteResource($result);\n\n return route('ai-reports.' . $mediaResource . '.download', ['uuid' => $result->getUuid()]);\n }\n\n private function getReportMediaRouteResource(AutomatedReportResult $result): string\n {\n if ($result->getMediaType() === self::MEDIA_TYPE_PDF) {\n return self::PDF_KEY;\n } elseif ($result->getMediaType() === self::MEDIA_TYPE_PODCAST) {\n return self::AUDIO_KEY;\n }\n\n throw new \\InvalidArgumentException('Unknown media type.');\n }\n\n public function getMediaPath(AutomatedReportResult $result): ?string\n {\n $url = match ($result->getMediaType()) {\n self::MEDIA_TYPE_PDF => $result->getPdfUrl(),\n self::MEDIA_TYPE_PODCAST => $result->getPodcastAudioUrl(),\n default => null,\n };\n\n if ($url === null) {\n return null;\n }\n\n $path = parse_url(trim($url, '\"\\''), PHP_URL_PATH);\n\n return $path ?: null;\n }\n\n public function getFilenameSuffix(AutomatedReportResult $result): ?string\n {\n return match ($result->getMediaType()) {\n self::MEDIA_TYPE_PODCAST => 'Podcast',\n default => null,\n };\n }\n\n public function getMailSubjectSuffix(AutomatedReportResult $result): string\n {\n return match ($result->getMediaType()) {\n self::MEDIA_TYPE_PDF => 'report',\n self::MEDIA_TYPE_PODCAST => 'podcast',\n default => '',\n };\n }\n\n public function getMediaTypeMetadata(AutomatedReportResult $result): array\n {\n return match ($result->getMediaType()) {\n self::MEDIA_TYPE_PODCAST => ['extension' => 'mp3', 'mime' => 'audio/mpeg'],\n self::MEDIA_TYPE_PDF => ['extension' => 'pdf', 'mime' => 'application/pdf'],\n default => ['extension' => null, 'mime' => null],\n };\n }\n\n public function deleteS3Files(AutomatedReportResult $result): void\n {\n $teamUuid = $result->getReport()->getTeam()->getUuid();\n $reportUuid = $result->getUuid();\n\n // delete all files for a report uuid no mather of pdf, podcast, or both\n // in case of both - the podcast files are linked to the pdf (parent) uuid\n // pdf and podcast date times should be close\n $path = sprintf('%s/%s/%s', $teamUuid, self::S3_DIR, $reportUuid);\n\n foreach (self::FILE_EXTENSIONS_VARIANTS as $extension) {\n $file = $path . '.' . $extension;\n\n if (Storage::exists($file)) {\n Storage::delete($file);\n Log::info('[Reports] Deleted S3 file', [\n 'path' => $file,\n ]);\n }\n }\n\n foreach (self::FILE_PODCAST_EXTENSIONS_VARIANTS as $extension) {\n $file = $path . '_podcast.' . $extension;\n\n if (Storage::exists($file)) {\n Storage::delete($file);\n Log::info('[Reports] Deleted Podcast S3 file', [\n 'path' => $file,\n ]);\n }\n }\n }\n\n /**\n *\n * @param int|null $teamId Optional team ID to filter results\n *\n * @return Collection<int, int> Collection of team IDs\n */\n public function getTeamIdsWithReportsResults(?int $teamId = null): Collection\n {\n return $this->automatedReportsRepository->getTeamIdsWithReportsResults($teamId);\n }\n\n /**\n * Core delete logic for report results using a query\n *\n * @param Builder $query\n * @param array $logContext\n *\n * @return int\n */\n private function deleteReportResultsByQuery(Builder $query, array $logContext = []): int\n {\n $deletedCount = 0;\n\n if ($query->exists()) {\n Log::info(\n 'Run delete report results',\n array_merge(\n $logContext,\n [\n 'service' => 'AutomatedReportsService',\n ]\n )\n );\n\n $query->chunkById(50, function ($results) use (&$deletedCount, $logContext) {\n foreach ($results as $result) {\n $this->deleteReportResult($result);\n $deletedCount++;\n\n Log::info(\n 'Deleted a report result',\n array_merge(\n $logContext,\n [\n 'result_id' => $result->getId(),\n 'report_id' => $result->getReportId(),\n ]\n )\n );\n }\n });\n }\n\n return $deletedCount;\n }\n\n /**\n * Delete report results for a team by retention period\n *\n * @param Team $team\n * @param CarbonImmutable $retentionDate\n *\n * @return int Number of deleted report results\n */\n public function deleteReportsResultsInRetentionPeriod(Team $team, CarbonImmutable $retentionDate): int\n {\n $reportIds = $this->automatedReportsRepository->getReportIdsByTeam($team);\n\n if ($reportIds->isEmpty()) {\n return 0;\n }\n\n $query = $this->automatedReportsRepository\n ->getReportResultsQueryForRetention($team, $retentionDate);\n\n return $this->deleteReportResultsByQuery($query, [\n 'team_id' => $team->getId(),\n 'retention_date' => $retentionDate->toDateTimeString(),\n ]);\n }\n\n /**\n * Delete ALL report results for a specific automated report\n *\n * @param string $uuid\n *\n * @return int\n */\n public function deleteReportResults(string $uuid): int\n {\n $report = $this->getReport($uuid);\n\n $query = $this->automatedReportsRepository->getResultsByReportQuery($report);\n\n return $this->deleteReportResultsByQuery($query, [\n 'report_uuid' => $uuid,\n 'report_id' => $report->getId(),\n ]);\n }\n\n public function deleteReportResult(AutomatedReportResult $result): void\n {\n $this->deleteS3Files($result);\n\n $result->delete();\n }\n\n /**\n * Get all reports for a specific team\n *\n * @param Team $team\n *\n * @return \\Illuminate\\Database\\Eloquent\\Collection\n */\n public function getTeamReports(Team $team): \\Illuminate\\Database\\Eloquent\\Collection\n {\n return $this->automatedReportsRepository->getReportsByTeam($team);\n }\n\n /**\n * Get all report results for a specific report\n *\n * @param AutomatedReport $report\n *\n * @return \\Illuminate\\Database\\Eloquent\\Collection\n */\n public function getReportResults(AutomatedReport $report): \\Illuminate\\Database\\Eloquent\\Collection\n {\n return $this->automatedReportsRepository->getResultsByReport($report);\n }\n\n public function deleteAllReportResults(AutomatedReport $report): void\n {\n $results = $this->getReportResults($report);\n\n /** @var AutomatedReportResult $result */\n foreach ($results as $result) {\n Log::info('Deleting result', [\n 'report' => $report->getId(),\n 'result' => $result->getId(),\n ]);\n\n $this->deleteReportResult($result);\n }\n }\n\n public function deleteAllData(Team $team): void\n {\n Log::info('Deleting automated report and results for team', [\n 'team' => $team->getId(),\n ]);\n\n $reports = $this->getTeamReports($team);\n\n /** @var AutomatedReport $report */\n foreach ($reports as $report) {\n Log::info('Deleting report', [\n 'team' => $team->getId(),\n 'report' => $report->getId(),\n ]);\n\n $this->deleteAllReportResults($report);\n\n $report->delete();\n }\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":true,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"Project","depth":3,"role_description":"text"},{"role":"AXButton","text":"Project","depth":3,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"New File or Directory…","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Expand Selected","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Collapse All","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Options","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false}]...
|
3397592283435315795
|
6686367547760219213
|
idle
|
accessibility
|
NULL
|
Project: faVsco.js, menu
#11894 on JY-18909-automa Project: faVsco.js, menu
#11894 on JY-18909-automated-reports-ask-jiminny, menu
Start Listening for PHP Debug Connections
AutomatedReportsCommandTest
Run 'AutomatedReportsCommandTest'
Debug 'AutomatedReportsCommandTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Execute
Explain Plan
Browse Query History
View Parameters
Open Query Execution Settings…
In-Editor Results
Tx: Auto
Cancel Running Statements
Playground
jiminny
Sync Changes
Hide This Notification
Code changed:
Hide
16
13
13
Previous Highlighted Error
Next Highlighted Error
SELECT * FROM teams WHERE id = 1;
select * from crm_layouts where crm_configuration_id = 39;
SELECT * FROM crm_layout_entities WHERE crm_layout_id = 283;
SELECT * FROM crm_fields WHERE id = 2234;
SELECT * FROM crm_field_values WHERE crm_field_id = 2234;
select * from crm_profiles where user_id = 143;
select * from record_types where crm_configuration_id = 39; # 0121K000001MHElQAO,0121K000001MHEqQAO
select * from business_processes where crm_configuration_id = 39;
# 01941000000H669AAC, 01941000000H66JAAS
select * from record_type_field_values
where record_type_id IN (24);
select * from crm_field_values where id IN (2730);
select * from crm_configurations where id = 39;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 1
and sa.provider = 'salesforce'; #1035
select * from users where team_id = 1; # 222 group 3
SELECT * FROM activities WHERE user_id = 222 order by id desc;
select * from sidekick_settings where team_id = 1;
select * from teams where id = 1;
select * from team_features where team_id = 1;
select * from activities where crm_configuration_id = 2
and provider = 'ms-teams' and id = 608765;
SELECT * FROM activities WHERE crm_configuration_id = 2 and crm_provider_id = '59523413338';
select * from sidekick_settings where team_id = 2;
SELECT * FROM activities WHERE id = 608660;
select * from activity_summary_logs where activity_id = 608660;
select * from ai_prompts where transcription_id = 11214;
# [PASSWORD_DOTS]
SELECT * FROM activities WHERE uuid_to_bin('ed78a437-2804-450e-ab2f-56ab1c641346') = uuid;
# id: 608818, crm: 59628809737
SELECT * FROM activities WHERE uuid_to_bin('36b06e55-afdd-4782-8dee-c624cd0af191') = uuid;
# id: 608821, crm: 59632069252
SELECT ce.start_time, ce.end_time, a.id, a.uuid, crm_provider_id, calendar_event_id, title,
playbook_category_id, user_id, lead_id, contact_id, account_id, opportunity_id,
scheduled_start_time, scheduled_end_time, actual_start_time, actual_end_time, a.created_at
FROM activities a
join calendar_events ce on a.calendar_event_id = ce.id
WHERE a.id IN (608818, 608821);
select * from users where team_id = 1;
select * from team_settings where team_id = 1;
select * from crm_profiles where crm_configuration_id = 39 order by user_id;
select * from team_features where team_id = 1;
select * from users where team_id = 2;
SELECT * FROM activities WHERE uuid_to_bin('ec7647e9-5225-458b-b475-f31aa2769204') = uuid; # 612639
# Preslava N. Ivanova, grou id 3
SELECT * FROM opportunities WHERE uuid_to_bin('a2928fe5-aec5-46cb-85d9-7654c89e46a6') = uuid;
select * from activities where opportunity_id = 344 and actual_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00';
select
a.id,
a.type,
a.scheduled_start_time,
a.actual_start_time,
a.created_at,
a.opportunity_id,
a.status
FROM activities a
WHERE opportunity_id = 344
and status IN ('completed', 'received', 'delivered')
and (
(a.actual_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00')
OR (a.created_at between '2024-10-11 00:00:00' and '2024-10-12 00:00:00')
OR (a.scheduled_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00'))
;
SELECT * FROM users WHERE id = 222;
SELECT * FROM crm_profiles WHERE user_id = 222;
select * from crm_layouts where crm_configuration_id = 39;
SELECT * FROM crm_layout_entities WHERE crm_layout_id = 281;
select * from group_deal_risk_types;
select * from opportunities where team_id = 1;
SELECT * FROM opportunities WHERE id = 315;
SELECT * FROM crm_field_data WHERE object_id = 315;
select * from crm_field_data where object_id = 260;
select * from generic_ai_prompts where subject_id = 315;
select * from teams; # 36, 21, 121, [EMAIL]
SELECT * FROM social_accounts WHERE sociable_id = 121 and provider = 'bullhorn';
# [PASSWORD_DOTS]
select * from teams where id = 1;
select * from crm_configurations where id = 39;
select * from users where team_id = 1;
select u.email, cp.* from users u
join crm_profiles cp on u.id = cp.user_id
where u.team_id = 1;
# 1 - 00541000004281rAAA
# 204 - 0052g000003freeAAA
# 429 - 0052g000003qGOiAAM
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 1
and sa.provider = 'salesforce';
select * from activities where type = 'softphone'
and created_at > '2024-12-11 15:24:36' order by id desc;
select * from activity_providers where team_id = 1;
select * from activity_provider_users where activity_provider_id = 328;
select * from opportunities where crm_configuration_id = 39
AND account_id = 178 AND is_closed = false
order by created_at DESC;
select * from contacts where id = 3952;
select * from accounts where id = 178;
# [PASSWORD_DOTS]
select * from teams where id = 36;
select * from crm_configurations where id = 21;
select * from users where team_id = 36;
select u.email, cp.* from users u
join crm_profiles cp on u.id = cp.user_id
where u.team_id = 36;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 36
and sa.provider = 'bullhorn';
select * from social_accounts where id = 348;
UPDATE social_accounts SET
provider_user_token = '21442_6802599_91:41179a58-21e7-4d7c-ad58-56bb666b2f65',
provider_refresh_token = '21442_6802599_91:01c6b335-3f2a-42e4-85ff-8a08fa65fceb',
expires = 1733998131,
state = 'connected'
WHERE id = 348;
# [PASSWORD_DOTS]
select * from teams where id = 31;
select * from crm_configurations where id = 18;
select * from users where team_id = 31; # 257
select u.email, cp.* from users u
join crm_profiles cp on u.id = cp.user_id
where u.team_id = 31;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 31
and sa.provider = 'close';
select * from contacts where crm_configuration_id = 18;
# [PASSWORD_DOTS] NEPTUNE [PASSWORD_DOTS]
select * from teams;
select * from users where id IN (1030, 1035, 1052);
select * from crm_configurations;
select * from users where team_id = 65; # 257
select * from team_settings where team_id = 65; # 257
select * from invitations where team_id = 65; # 257
select * from users where email = '[EMAIL]'; # 257
select u.email, cp.* from users u
join crm_profiles cp on u.id = cp.user_id
where u.team_id = 65;
select * from crm_configurations where id = 53;
select * from accounts where crm_configuration_id = 53 order by id desc;
select * from leads where crm_configuration_id = 53 order by id desc;
select * from contacts where crm_configuration_id = 53 order by id desc;
select * from opportunities where crm_configuration_id = 53 order by id desc;
select * from crm_profiles where crm_configuration_id = 53 order by id desc;
select * from crm_fields where crm_configuration_id = 53 order by id desc;
select * from crm_field_values where crm_field_id = 3341 order by id desc;
select * from crm_layouts where crm_configuration_id = 53 order by id desc;
select * from stages where crm_configuration_id = 53 order by id desc;
select * from crm_profiles where crm_configuration_id = 13;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 65
and sa.provider = 'integration-app';
select * from contacts where crm_configuration_id = 13;
select * from social_accounts where sociable_id = 283;
SELECT * FROM opportunities WHERE crm_provider_id = '006O400000E9bzeIAB';
select * from activity_providers where team_id = 65;
SELECT * FROM activities WHERE crm_configuration_id IN (51, 52, 53);
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 65
;
# [PASSWORD_DOTS] STAGING [PASSWORD_DOTS]
SELECT * FROM teams;
SELECT * FROM teams WHERE id = 88;
SELECT * FROM teams WHERE id = 89;
select * from team_settings where team_id = 89;
SELECT * FROM users WHERE team_id = 89;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 89;
select * from users;
SELECT * FROM social_accounts WHERE sociable_id = 1761;
SELECT * FROM crm_configurations WHERE id = 70;
select * from accounts where crm_configuration_id = 70 order by id desc;
select * from leads where crm_configuration_id = 70 order by id desc;
select * from contacts where crm_configuration_id = 70 order by id desc;
select * from opportunities where crm_configuration_id = 70 order by id desc;
select * from crm_profiles where crm_configuration_id = 70 order by id desc;
select * from crm_fields where crm_configuration_id = 70 order by id desc;
select * from crm_field_values where crm_field_id = 3536 order by id desc;
select * from crm_layouts where crm_configuration_id = 70 order by id desc;
select * from stages where crm_configuration_id = 70 order by id desc;
select * from business_processes where crm_configuration_id = 70 order by id desc;
select * from business_process_stages where business_process_id = 34;
select * from contacts where id = 10468;
select * from crm_layouts where crm_configuration_id = 70;
SELECT * FROM crm_layout_entities WHERE crm_layout_id = 388;
SELECT * FROM crm_fields WHERE id IN (3533,3534,3535);
select * from activities where crm_configuration_id = 70
and (account_id IS NOT NULL or lead_id IS NOT NULL or contact_id IS NOT NULL or opportunity_id IS NOT NULL) order by id desc;
SELECT * FROM activities WHERE uuid_to_bin('2e10b60f-8a61-41c5-a3d4-28835353dc65') = uuid;
SELECT * FROM activities where crm_configuration_id = 69 ;
SELECT * FROM users WHERE email LIKE '%[EMAIL]%';
SELECT * FROM activities WHERE uuid_to_bin('5a150c93-40fc-42ec-b3bd-c1d328e09f6e') = uuid;
SELECT * FROM opportunities WHERE id = 385;
select * from participants p
join activities a on p.activity_id = a.id
where a.crm_configuration_id = 70
and (p.lead_id IS NOT NULL or p.contact_id IS NOT NULL);
SELECT * FROM participants WHERE id = 1013638;
select * from teams where id = 90;
select * from users where team_id = 90;
select * from social_accounts where social_accounts.sociable_id IN (1960,1760);
SELECT * FROM crm_profiles WHERE crm_configuration_id = 71;
select * from invitations where team_id = 90;
select * from crm_configurations where id = 71;
select * from accounts where crm_configuration_id = 71 order by id desc;
select * from leads where crm_configuration_id = 71 order by id desc;
select * from contacts where crm_configuration_id = 71 order by id desc;
select * from opportunities where crm_configuration_id = 71 order by id desc;
select * from crm_profiles where crm_configuration_id = 71 order by id desc;
select * from crm_fields where crm_configuration_id = 71 order by id desc;
select * from crm_field_values where crm_field_id = 3341 order by id desc;
select * from crm_layouts where crm_configuration_id = 71 order by id desc;
select * from stages where crm_configuration_id = 71 order by id desc;
select * from users order by secondary_email desc;
select u.id, u.email, u.status, sa.id, sa.provider_user_id from social_accounts sa
join users u on sa.sociable_id = u.id
where sa.provider = 'google' and u.email LIKE 'aneliya%';
select * from failed_jobs order by id desc;
select * from users where email = '[EMAIL]' or secondary_email = '[EMAIL]';
select * from teams;
SELECT * FROM crm_profiles WHERE crm_configuration_id = 39;
SELECT * FROM crm_fields WHERE crm_configuration_id = 39 and object_type = 'task';
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 1
and sa.provider = 'salesforce';
# [PASSWORD_DOTS]
SELECT * FROM activities WHERE uuid_to_bin('c38b3895-fd0f-4b1f-9fb2-c170dba137c6') = uuid;
SELECT * FROM crm_configurations WHERE id = 70;
select * from teams where id = 1;
select * from groups where team_id = 1;
select * from users where team_id = 1;
select o.id, o.name,o.close_date, u.id, u.name, u.group_id, r.id, r.display_name, g.name, g.scope from opportunities o
join users u on o.user_id = u.id
join groups g on u.group_id = g.id
join role_user ru on u.id = ru.user_id
join roles r on ru.role_id = r.id
where o.crm_configuration_id = 39 and close_date > '2024-01-01 00:00:00';
select * from role_user where user_id = 143;
select * from roles;
select * from role_user;
select * from groups where id = 9;
select * from scope_groups where group_id = 9;
# [PASSWORD_DOTS]
select * from teams where id = 36;
select * from crm_configurations;
SELECT * FROM social_accounts WHERE sociable_id = 121;
[URL_WITH_CREDENTIALS] this will add filter, however if we need to control feature by FF we need conditional logic
public const array TYPES = [
['id' => 'exec_summary', 'name' => 'Exec Summary'],
['id' => 'coaching_profiles', 'name' => 'Coaching Profiles'],
['id' => 'product_feedback', 'name' => 'Product Feedback'],
['id' => self::TYPE_LOSS_ANALYSIS, 'name' => 'Loss Analysis'],
// ['id' => 'questions', 'name' => 'Questions'],
// ['id' => 'statistical_quant', 'name' => 'Statistical Quantitative'],
];
public const array ALL_TYPES = [
...self::TYPES,
['id' => self::TYPE_ASK_JIMINNY, 'name' => 'Ask Jiminny'],
];
public const string FREQUENCY_DAILY = 'daily';
public const string FREQUENCY_WEEKLY = 'weekly';
public const string FREQUENCY_MONTHLY = 'monthly';
public const string FREQUENCY_QUARTERLY = 'quarterly';
public const string FREQUENCY_ONE_OFF = 'one_off';
/**
* Frequencies for standard (non-Ask Jiminny) reports.
*/
public const array FREQUENCIES = [
['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],
['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],
['id' => self::FREQUENCY_QUARTERLY, 'name' => 'Quarterly'],
['id' => self::FREQUENCY_ONE_OFF, 'name' => 'One-off'],
];
/**
* Frequencies for Ask Jiminny reports.
*/
public const array ASK_JIMINNY_FREQUENCIES = [
['id' => self::FREQUENCY_DAILY, 'name' => 'Daily'],
['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],
['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],
];
public const string MEDIA_TYPE_PDF = 'pdf';
public const string MEDIA_TYPE_PODCAST = 'podcast';
public const array MEDIA_TYPES = [self::MEDIA_TYPE_PDF, self::MEDIA_TYPE_PODCAST];
public const array MEDIA_TYPE_OBJECT_PDF = ['id' => self::MEDIA_TYPE_PDF, 'name' => 'PDF'];
public const array MEDIA_TYPE_OBJECT_PODCAST = ['id' => self::MEDIA_TYPE_PODCAST, 'name' => 'Podcast'];
public const array MEDIA_TYPE_OBJECTS = [self::MEDIA_TYPE_OBJECT_PDF, self::MEDIA_TYPE_OBJECT_PODCAST];
public const array CALL_TYPE_CONFERENCE = ['id' => 'conference', 'name' => 'Conference'];
public const array CALL_TYPE_DIALER = ['id' => 'dialer', 'name' => 'Dialer'];
public const int SENT_REPORT_AT_HOURS = 5;
public const string PDF_KEY = 'pdf';
public const string AUDIO_KEY = 'audio';
private const array ALL_FREQUENCIES = [
['id' => self::FREQUENCY_DAILY, 'name' => 'Daily'],
['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],
['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],
['id' => self::FREQUENCY_QUARTERLY, 'name' => 'Quarterly'],
['id' => self::FREQUENCY_ONE_OFF, 'name' => 'One-off'],
];
private const string S3_DIR = 'reports';
private const array FILE_EXTENSIONS_VARIANTS = ['html', 'MD', 'pdf'];
private const array FILE_PODCAST_EXTENSIONS_VARIANTS = ['json', 'mp3', 'ssml'];
public function __construct(
private readonly TeamRepository $teamRepository,
private readonly GroupRepository $groupRepository,
private readonly UserRepository $userRepository,
private readonly StageRepository $stageRepository,
private readonly DealStagesService $dealStagesService,
private readonly RecipientsService $recipientsService,
private readonly AutomatedReportsRepository $automatedReportsRepository,
private readonly Webhook $webhookService,
private readonly BusDispatcher $dispatcher,
private readonly ActivityTypeService $activityTypeService,
private readonly PlaybookCategoryRepository $playbookCategoryRepository,
private readonly AskAnythingPromptService $askAnythingPromptService,
private readonly SearchRepository $activitySearchRepository,
private readonly AskAnythingRepository $askAnythingRepository,
) {
}
public static function getTypes(): array
{
$types = self::TYPES;
return array_map(static function ($type) {
return $type['id'];
}, $types);
}
public static function getCallTypes(): array
{
return array_map(static function ($callType) {
return $callType['id'];
}, [self::CALL_TYPE_CONFERENCE, self::CALL_TYPE_DIALER]);
}
public static function getFrequencies(): array
{
return array_map(static function ($frequency) {
return $frequency['id'];
}, self::FREQUENCIES);
}
// front-facing structure
public function getReportEnabledFieldData(bool $value = false): array
{
return [
'id' => 'report_enabled',
'label' => '',
'inputType' => InputTypeEnum::TOGGLE,
'value' => $value,
];
}
// Organizations = Teams
public function getOrganizationFieldData(?string $value = null, bool $shortVersion = false): array
{
$options = $this->getTeams();
if ($shortVersion) {
return [
'id' => 'organization',
'label' => 'Organization',
'options' => $options,
];
}
return [
'id' => 'organization',
'label' => 'Organization',
'inputType' => InputTypeEnum::DROPDOWN,
'required' => true,
'placeholder' => 'Select',
'options' => $options,
'value' => $value,
'dependencies' => [
'teams',
'deal_stage_at_call',
'current_deal_stage',
'recipients',
ActivityTypeService::PLAYBOOK_CATEGORIES_KEY,
],
'dependsOn' => [],
];
}
// Teams = Groups
public function getTeamFieldData(array $options = [], array $value = [], bool $shortVersion = false): array
{
if ($shortVersion) {
return [
'id' => 'teams',
'label' => 'Team',
'options' => $options,
];
}
return [
'id' => 'teams',
'label' => 'Team',
'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,
'required' => false,
'placeholder' => 'Select',
'options' => $options,
'value' => $value, // value should be an array of objects {id, name}
'dependencies' => [ActivityTypeService::PLAYBOOK_CATEGORIES_KEY],
'dependsOn' => [],
];
}
public function getReportTypeFieldData(?string $value = null, bool $shortVersion = false, ?Team $team = null): array
{
$types = [];
if ($team instanceof Team) {
if ($team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {
$types = self::TYPES;
}
if ($team->hasFeature(FeatureEnum::ASK_JIMINNY_REPORTS)) {
$types[] = ['id' => self::TYPE_ASK_JIMINNY, 'name' => 'Ask Jiminny'];
}
} else {
$types = self::TYPES;
}
if ($shortVersion) {
return [
'id' => 'report_type',
'label' => 'Report Type',
'options' => $types,
];
}
return [
'id' => 'report_type',
'label' => 'Report Type',
'inputType' => InputTypeEnum::DROPDOWN,
'required' => true,
'placeholder' => 'Select',
'options' => $types,
'value' => $value,
'dependencies' => [],
'dependsOn' => [],
];
}
public function getFrequencyFieldData(?string $value = null): array
{
return [
'id' => 'frequency',
'label' => 'Frequency',
'inputType' => InputTypeEnum::DROPDOWN,
'required' => true,
'placeholder' => 'Select',
'options' => self::FREQUENCIES,
'value' => $value,
'dependencies' => ['period'],
'dependsOn' => [],
];
}
public function getPeriodFieldData(?string $valueStartDate = null, ?string $valueEndDate = null): array
{
return [
'id' => 'period',
'label' => 'Select one-off period',
'inputType' => InputTypeEnum::DATE_RANGE,
'required' => true,
'placeholder' => 'Select',
'value' => ['startDate' => $valueStartDate, 'endDate' => $valueEndDate],
'queryParams' => [
'startDate' => 'start_date_period',
'endDate' => 'end_date_period',
],
'dependencies' => [],
'dependsOn' => ['frequency'],
];
}
public function getActivityTypesFieldData(?Team $team = null, array $value = [], array $teamsFilter = []): array
{
return $this->activityTypeService->getActivityTypeFieldData(team: $team, value: $value, groupIds: $teamsFilter);
}
public function getDealStageAtCallFieldData(?Team $team = null, array $value = []): array
{
return $this->dealStagesService->getDealStageAtCallFieldData(team: $team, value: $value);
}
public function getCurrentDealStageFieldData(?Team $team = null, array $value = []): array
{
return $this->dealStagesService->getCurrentDealStageFieldData(team: $team, value: $value);
}
public function getDealValueFieldData(?int $valueMin = null, ?int $valueMax = null): array
{
return [
'id' => 'deal_value',
'label' => 'Deal Value',
'inputType' => InputTypeEnum::INTEGER_RANGE,
'required' => false,
'value' => ['min' => $valueMin, 'max' => $valueMax],
'queryParams' => [
'min' => 'min_deal_value',
'max' => 'max_deal_value',
],
'dependencies' => [],
'dependsOn' => [],
];
}
public function getCallTypeFieldData(bool $conferenceOn = false, bool $dialerOn = false): array
{
$value = [];
$conferenceOn && $value[] = self::CALL_TYPE_CONFERENCE;
$dialerOn && $value[] = self::CALL_TYPE_DIALER;
return [
'id' => 'call_type',
'label' => 'Call Type',
'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,
'required' => true,
'options' => [
self::CALL_TYPE_CONFERENCE,
self::CALL_TYPE_DIALER,
],
'value' => $value,
'dependencies' => [],
'dependsOn' => [],
];
}
public function getMediaTypeFieldData(?AutomatedReport $report = null): array
{
$value = [];
if ($report) {
$value = $this->transformMediaTypes($report);
}
return [
'id' => 'media_types',
'label' => 'Export as',
'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,
'required' => true,
'options' => self::MEDIA_TYPE_OBJECTS,
'value' => $value,
'dependencies' => [],
'dependsOn' => [],
];
}
public function getCallDurationFieldData(?int $valueMin = null, ?int $valueMax = null): array
{
return [
'id' => 'call_duration',
'label' => 'Call Duration',
'inputType' => InputTypeEnum::INTEGER_RANGE,
'required' => false,
'value' => ['min' => $valueMin, 'max' => $valueMax],
'queryParams' => [
'min' => 'min_call_duration',
'max' => 'max_call_duration',
],
'dependencies' => [],
'dependsOn' => [],
];
}
public function getRecipientsFieldData(?Team $team = null, array $value = []): array
{
return $this->recipientsService->getRecipientsFieldData(team: $team, value: $value);
}
public function getJiminnyRecipientsFieldData(array $value = []): array
{
return $this->recipientsService->getJiminnyRecipientsFieldData($value);
}
public function getAdditionalPromptInputFieldData(?string $value = null): array
{
return [
'id' => 'additional_prompt_input',
'label' => 'Special requirements',
'inputType' => InputTypeEnum::TEXTAREA,
'required' => false,
'placeholder' => 'What should be the focus of the report?',
'value' => $value,
'dependencies' => [],
'dependsOn' => [],
];
}
public function getCustomReportNameFieldData(?string $value = null): array
{
return [
'id' => 'custom_name',
'label' => 'Custom report name',
'inputType' => InputTypeEnum::TEXT,
'required' => false,
'placeholder' => 'Enter custom name',
'value' => $value,
'dependencies' => [],
'dependsOn' => [],
];
}
// data providers
public function getTeams(): array
{
$teams = $this->teamRepository->getTeamsForKiosk(status: Team::STATUS_ACTIVE);
$teamData = [];
foreach ($teams as $team) {
if (! $team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {
continue;
}
$teamData[] = $this->transformTeam($team);
}
return $teamData;
}
public function getTeamGroups(string $teamUuid): array
{
$data = [];
$team = $this->getTeam($teamUuid);
if ($team !== null) {
$groups = $team->groups()->get();
foreach ($groups as $group) {
$data[] = [
'id' => $group->getUuid(),
'name' => $group->getName(),
];
}
}
return $data;
}
public function getTeamsGroupsOptions(array $filterTeamUuids = []): array
{
$data = [];
$teams = $this->getTeams();
foreach ($teams as $team) {
if (! empty($filterTeamUuids) && ! in_array($team['id'], $filterTeamUuids, true)) {
continue;
}
$data[] = [
'label' => $team['name'],
'groups' => $this->getTeamGroups($team['id']),
];
}
return $data;
}
public function getTeam(string $teamUuid): ?Team
{
return $this->teamRepository->idOrUuid($teamUuid);
}
public function getTeamById(int $teamId): ?Team
{
return $this->teamRepository->find($teamId);
}
public function getGroupsUuids(AutomatedReport $report): array
{
$uuids = [];
$reportGroups = $report->getGroups();
foreach ($reportGroups as $groupId) {
if ($group = $this->groupRepository->find($groupId)) {
$uuids[] = $group->getUuid();
}
}
return $uuids;
}
public function getPlaybookCategoriesUuids(AutomatedReport $report): array
{
$uuids = [];
$playbookCategories = $report->getPlaybookCategories();
foreach ($playbookCategories as $id) {
if ($category = $this->playbookCategoryRepository->find($id)) {
$uuids[] = $category->getUuid();
}
}
return $uuids;
}
public function getDealAtCallStagesUuids(AutomatedReport $report): array
{
$uuids = [];
$reportStages = $report->getDealAtCallStages();
foreach ($reportStages as $id) {
if ($stage = $this->stageRepository->find($id)) {
$uuids[] = $stage->getUuid();
}
}
return $uuids;
}
public function getCurrentDealStagesUuids(AutomatedReport $report): array
{
$uuids = [];
$reportStages = $report->getCurrentDealStages();
foreach ($reportStages as $id) {
if ($stage = $this->stageRepository->find($id)) {
$uuids[] = $stage->getUuid();
}
}
return $uuids;
}
public function getUsersUuids(AutomatedReport $report): array
{
return $this->extractUserUuids($report->getRecipients());
}
public function getJiminnyUsersUuids(AutomatedReport $report): array
{
return $this->extractUserUuids($report->getJiminnyRecipients());
}
/**
* @param array<string, mixed> $recipients
*/
private function extractUserUuids(array $recipients): array
{
$userIds = $recipients['users'] ?? [];
return collect($userIds)
->map(fn ($id) => $this->userRepository->find((int) $id))
->filter()
->map(fn (UserContract $user) => $user->getUuid())
->values()
->all();
}
// get mail data
public function getRecipientUsers(AutomatedReport $report): array
{
return $this->buildRecipientUsers($report->getRecipients());
}
private function getJiminnyRecipientUsers(AutomatedReport $report): array
{
return $this->buildRecipientUsers($report->getJiminnyRecipients());
}
/**
* @param array<string, mixed> $recipients
*/
private function buildRecipientUsers(array $recipients): array
{
$userIds = $recipients['users'] ?? [];
return collect($userIds)
->map(fn ($id) => $this->userRepository->find((int) $id))
->filter()
->map(fn (UserContract $user) => [
'email' => $user->getEmailAddress(),
'name' => $user->getName(),
'timezone' => $user->getTimezone()->getName(),
])
->values()
->all();
}
public function getValidRecipientUsers(AutomatedReport $report, bool $includeJiminny = false): array
{
if ($report->isAskJiminnyReport()) {
$recipients = $this->resolveAskJiminnyRecipients($report);
} else {
$recipients = $this->getRecipientUsers($report);
if ($includeJiminny) {
$recipients = array_merge($recipients, $this->getJiminnyRecipientUsers($report));
}
}
$emails = [];
return array_values(array_filter(
$recipients,
static function ($recipient) use (&$emails) {
if (empty($recipient['email']) || in_array($recipient['email'], $emails, true)) {
return false;
}
$emails[] = $recipient['email'];
return true;
}
));
}
private function resolveAskJiminnyRecipients(AutomatedReport $report): array
{
$recipients = [];
$creator = $report->getCreator();
if ($creator !== null) {
$recipients[] = [
'email' => $creator->getEmailAddress(),
'name' => $creator->getName(),
'timezone' => $creator->getTimezone()->getName(),
];
}
return array_merge(
$recipients,
$this->buildRecipientUsers($report->getRecipients()),
$this->getGroupRecipientUsers($report),
);
}
private function getGroupRecipientUsers(AutomatedReport $report): array
{
$users = [];
foreach ($report->getGroups() as $groupId) {
$group = $this->groupRepository->find($groupId);
if ($group === null) {
continue;
}
foreach ($group->getMembers() as $member) {
$users[] = [
'email' => $member->getEmailAddress(),
'name' => $member->getName(),
'timezone' => $member->getTimezone()->getName(),
];
}
}
return $users;
}
public function getReportTypeName(AutomatedReportResult $report): string
{
$type = $report->getReport()->getType();
$getType = $this->transformReportType($type);
return $getType['name'];
}
public function getReportPeriodName(AutomatedReportResult $report): string
{
$from = $report->getFromDate();
$to = $report->getToDate();
$frequency = $report->getReport()->getFrequency();
if ($from === null || $to === null) {
if (! $report->getReport()->isAskJiminnyReport()) {
$invalidPeriod = $from === null ? 'from' : 'to';
throw new ApplicationException('Report period is invalid: ' . $invalidPeriod);
}
$period = $this->calculateFromAndToDatePeriod($frequency);
$from = $period['fromDate'];
$to = $period['toDate'];
}
return $this->formatReportPeriodName($frequency, $from, $to);
}
private function formatReportPeriodName(string $frequency, Carbon $from, Carbon $to): string
{
$fromYear = $from->format('Y');
$toYear = $to->format('Y');
$differentYears = $fromYear !== $toYear;
switch ($frequency) {
case self::FREQUENCY_DAILY:
return $from->format('j M Y');
case self::FREQUENCY_QUARTERLY:
// 'Jan-Mar 2025' or 'Nov 2024-Jan 2025' if years differ
$startMonth = $from->format('M');
$endMonth = $to->copy()->subMonth();
$endMonthName = $endMonth->format('M');
$endMonthYear = $endMonth->format('Y');
if ($differentYears) {
return "{$startMonth} {$fromYear} - {$endMonthName} {$endMonthYear}";
}
return "{$startMonth} - {$endMonthName} {$toYear}";
case self::FREQUENCY_MONTHLY:
// 'May 2025' - monthly reports are always within the same year
return $from->format('M Y');
case self::FREQUENCY_WEEKLY:
// '4 - 8 Aug 2025', '27 Oct - 3 Nov 2025', or '28 Dec 2024 - 3 Jan 2025' if years differ
$startDay = $from->format('j');
$endDay = $to->format('j');
$startMonth = $from->format('M');
$endMonth = $to->format('M');
if ($differentYears) {
return "{$startDay} {$startMonth} {$fromYear} - {$endDay} {$endMonth} {$toYear}";
}
if ($startMonth !== $endMonth) {
return "{$startDay} {$startMonth} - {$endDay} {$endMonth} {$toYear}";
}
return "{$startDay} - {$endDay} {$endMonth} {$toYear}";
case self::FREQUENCY_ONE_OFF:
// '2 May-31 May 2025' or '15 Dec 2024-15 Jan 2025' if years differ
$startDay = $from->format('j');
$startMonth = $from->format('M');
$endDay = $to->format('j');
$endMonth = $to->format('M');
// If same month and year, use a format like '2-31 May 2025'
if ($startMonth === $endMonth && ! $differentYears) {
return "{$startDay} - {$endDay} {$startMonth} {$toYear}";
}
// If different years, include both years
if ($differentYears) {
return "{$startDay} {$startMonth} {$fromYear} - {$endDay} {$endMonth} {$toYear}";
}
// Same year but different months
return "{$startDay} {$startMonth} - {$endDay} {$endMonth} {$toYear}";
default:
// Default format for unknown frequencies
return $from->format('j M Y') . ' - ' . $to->format('j M Y');
}
}
public function getReportTeamsName(AutomatedReportResult $report): string
{
$groups = $report->getGroups();
if (empty($groups)) {
return 'All';
}
// Get group names from repository
$groupNames = [];
foreach ($groups as $groupId) {
$group = $this->groupRepository->find($groupId);
if ($group) {
$groupNames[] = $group->getName();
}
}
if (count($groupNames) === 1) {
// Single team format
$teamsName = $groupNames[0];
} else {
// Multiple teams format
$teamsName = implode(', ', $groupNames);
}
return $teamsName;
}
public function getReportFileName(AutomatedReportResult $report): string
...
|
12331
|
|
12337
|
262
|
7
|
2026-04-14T11:09:02.681826+00:00
|
/Users/lukas/.screenpipe/data/data/2026-04-14/1776 /Users/lukas/.screenpipe/data/data/2026-04-14/1776164942681_m1.jpg...
|
PhpStorm
|
faVsco.js – AutomatedReportsService.php
|
1
|
NULL
|
monitor_1
|
NULL
|
NULL
|
NULL
|
NULL
|
Project: faVsco.js, menu
#11894 on JY-18909-automa Project: faVsco.js, menu
#11894 on JY-18909-automated-reports-ask-jiminny, menu
Start Listening for PHP Debug Connections
AutomatedReportsCommandTest
Run 'AutomatedReportsCommandTest'
Debug 'AutomatedReportsCommandTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Execute
Explain Plan
Browse Query History
View Parameters
Open Query Execution Settings…
In-Editor Results
Tx: Auto
Cancel Running Statements
Playground
jiminny
Sync Changes
Hide This Notification
Code changed:
Hide
16
13
13
Previous Highlighted Error
Next Highlighted Error
SELECT * FROM teams WHERE id = 1;
select * from crm_layouts where crm_configuration_id = 39;
SELECT * FROM crm_layout_entities WHERE crm_layout_id = 283;
SELECT * FROM crm_fields WHERE id = 2234;
SELECT * FROM crm_field_values WHERE crm_field_id = 2234;
select * from crm_profiles where user_id = 143;
select * from record_types where crm_configuration_id = 39; # 0121K000001MHElQAO,0121K000001MHEqQAO
select * from business_processes where crm_configuration_id = 39;
# 01941000000H669AAC, 01941000000H66JAAS
select * from record_type_field_values
where record_type_id IN (24);
select * from crm_field_values where id IN (2730);
select * from crm_configurations where id = 39;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 1
and sa.provider = 'salesforce'; #1035
select * from users where team_id = 1; # 222 group 3
SELECT * FROM activities WHERE user_id = 222 order by id desc;
select * from sidekick_settings where team_id = 1;
select * from teams where id = 1;
select * from team_features where team_id = 1;
select * from activities where crm_configuration_id = 2
and provider = 'ms-teams' and id = 608765;
SELECT * FROM activities WHERE crm_configuration_id = 2 and crm_provider_id = '59523413338';
select * from sidekick_settings where team_id = 2;
SELECT * FROM activities WHERE id = 608660;
select * from activity_summary_logs where activity_id = 608660;
select * from ai_prompts where transcription_id = 11214;
# [PASSWORD_DOTS]
SELECT * FROM activities WHERE uuid_to_bin('ed78a437-2804-450e-ab2f-56ab1c641346') = uuid;
# id: 608818, crm: 59628809737
SELECT * FROM activities WHERE uuid_to_bin('36b06e55-afdd-4782-8dee-c624cd0af191') = uuid;
# id: 608821, crm: 59632069252
SELECT ce.start_time, ce.end_time, a.id, a.uuid, crm_provider_id, calendar_event_id, title,
playbook_category_id, user_id, lead_id, contact_id, account_id, opportunity_id,
scheduled_start_time, scheduled_end_time, actual_start_time, actual_end_time, a.created_at
FROM activities a
join calendar_events ce on a.calendar_event_id = ce.id
WHERE a.id IN (608818, 608821);
select * from users where team_id = 1;
select * from team_settings where team_id = 1;
select * from crm_profiles where crm_configuration_id = 39 order by user_id;
select * from team_features where team_id = 1;
select * from users where team_id = 2;
SELECT * FROM activities WHERE uuid_to_bin('ec7647e9-5225-458b-b475-f31aa2769204') = uuid; # 612639
# Preslava N. Ivanova, grou id 3
SELECT * FROM opportunities WHERE uuid_to_bin('a2928fe5-aec5-46cb-85d9-7654c89e46a6') = uuid;
select * from activities where opportunity_id = 344 and actual_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00';
select
a.id,
a.type,
a.scheduled_start_time,
a.actual_start_time,
a.created_at,
a.opportunity_id,
a.status
FROM activities a
WHERE opportunity_id = 344
and status IN ('completed', 'received', 'delivered')
and (
(a.actual_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00')
OR (a.created_at between '2024-10-11 00:00:00' and '2024-10-12 00:00:00')
OR (a.scheduled_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00'))
;
SELECT * FROM users WHERE id = 222;
SELECT * FROM crm_profiles WHERE user_id = 222;
select * from crm_layouts where crm_configuration_id = 39;
SELECT * FROM crm_layout_entities WHERE crm_layout_id = 281;
select * from group_deal_risk_types;
select * from opportunities where team_id = 1;
SELECT * FROM opportunities WHERE id = 315;
SELECT * FROM crm_field_data WHERE object_id = 315;
select * from crm_field_data where object_id = 260;
select * from generic_ai_prompts where subject_id = 315;
select * from teams; # 36, 21, 121, [EMAIL]
SELECT * FROM social_accounts WHERE sociable_id = 121 and provider = 'bullhorn';
# [PASSWORD_DOTS]
select * from teams where id = 1;
select * from crm_configurations where id = 39;
select * from users where team_id = 1;
select u.email, cp.* from users u
join crm_profiles cp on u.id = cp.user_id
where u.team_id = 1;
# 1 - 00541000004281rAAA
# 204 - 0052g000003freeAAA
# 429 - 0052g000003qGOiAAM
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 1
and sa.provider = 'salesforce';
select * from activities where type = 'softphone'
and created_at > '2024-12-11 15:24:36' order by id desc;
select * from activity_providers where team_id = 1;
select * from activity_provider_users where activity_provider_id = 328;
select * from opportunities where crm_configuration_id = 39
AND account_id = 178 AND is_closed = false
order by created_at DESC;
select * from contacts where id = 3952;
select * from accounts where id = 178;
# [PASSWORD_DOTS]
select * from teams where id = 36;
select * from crm_configurations where id = 21;
select * from users where team_id = 36;
select u.email, cp.* from users u
join crm_profiles cp on u.id = cp.user_id
where u.team_id = 36;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 36
and sa.provider = 'bullhorn';
select * from social_accounts where id = 348;
UPDATE social_accounts SET
provider_user_token = '21442_6802599_91:41179a58-21e7-4d7c-ad58-56bb666b2f65',
provider_refresh_token = '21442_6802599_91:01c6b335-3f2a-42e4-85ff-8a08fa65fceb',
expires = 1733998131,
state = 'connected'
WHERE id = 348;
# [PASSWORD_DOTS]
select * from teams where id = 31;
select * from crm_configurations where id = 18;
select * from users where team_id = 31; # 257
select u.email, cp.* from users u
join crm_profiles cp on u.id = cp.user_id
where u.team_id = 31;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 31
and sa.provider = 'close';
select * from contacts where crm_configuration_id = 18;
# [PASSWORD_DOTS] NEPTUNE [PASSWORD_DOTS]
select * from teams;
select * from users where id IN (1030, 1035, 1052);
select * from crm_configurations;
select * from users where team_id = 65; # 257
select * from team_settings where team_id = 65; # 257
select * from invitations where team_id = 65; # 257
select * from users where email = '[EMAIL]'; # 257
select u.email, cp.* from users u
join crm_profiles cp on u.id = cp.user_id
where u.team_id = 65;
select * from crm_configurations where id = 53;
select * from accounts where crm_configuration_id = 53 order by id desc;
select * from leads where crm_configuration_id = 53 order by id desc;
select * from contacts where crm_configuration_id = 53 order by id desc;
select * from opportunities where crm_configuration_id = 53 order by id desc;
select * from crm_profiles where crm_configuration_id = 53 order by id desc;
select * from crm_fields where crm_configuration_id = 53 order by id desc;
select * from crm_field_values where crm_field_id = 3341 order by id desc;
select * from crm_layouts where crm_configuration_id = 53 order by id desc;
select * from stages where crm_configuration_id = 53 order by id desc;
select * from crm_profiles where crm_configuration_id = 13;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 65
and sa.provider = 'integration-app';
select * from contacts where crm_configuration_id = 13;
select * from social_accounts where sociable_id = 283;
SELECT * FROM opportunities WHERE crm_provider_id = '006O400000E9bzeIAB';
select * from activity_providers where team_id = 65;
SELECT * FROM activities WHERE crm_configuration_id IN (51, 52, 53);
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 65
;
# [PASSWORD_DOTS] STAGING [PASSWORD_DOTS]
SELECT * FROM teams;
SELECT * FROM teams WHERE id = 88;
SELECT * FROM teams WHERE id = 89;
select * from team_settings where team_id = 89;
SELECT * FROM users WHERE team_id = 89;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 89;
select * from users;
SELECT * FROM social_accounts WHERE sociable_id = 1761;
SELECT * FROM crm_configurations WHERE id = 70;
select * from accounts where crm_configuration_id = 70 order by id desc;
select * from leads where crm_configuration_id = 70 order by id desc;
select * from contacts where crm_configuration_id = 70 order by id desc;
select * from opportunities where crm_configuration_id = 70 order by id desc;
select * from crm_profiles where crm_configuration_id = 70 order by id desc;
select * from crm_fields where crm_configuration_id = 70 order by id desc;
select * from crm_field_values where crm_field_id = 3536 order by id desc;
select * from crm_layouts where crm_configuration_id = 70 order by id desc;
select * from stages where crm_configuration_id = 70 order by id desc;
select * from business_processes where crm_configuration_id = 70 order by id desc;
select * from business_process_stages where business_process_id = 34;
select * from contacts where id = 10468;
select * from crm_layouts where crm_configuration_id = 70;
SELECT * FROM crm_layout_entities WHERE crm_layout_id = 388;
SELECT * FROM crm_fields WHERE id IN (3533,3534,3535);
select * from activities where crm_configuration_id = 70
and (account_id IS NOT NULL or lead_id IS NOT NULL or contact_id IS NOT NULL or opportunity_id IS NOT NULL) order by id desc;
SELECT * FROM activities WHERE uuid_to_bin('2e10b60f-8a61-41c5-a3d4-28835353dc65') = uuid;
SELECT * FROM activities where crm_configuration_id = 69 ;
SELECT * FROM users WHERE email LIKE '%[EMAIL]%';
SELECT * FROM activities WHERE uuid_to_bin('5a150c93-40fc-42ec-b3bd-c1d328e09f6e') = uuid;
SELECT * FROM opportunities WHERE id = 385;
select * from participants p
join activities a on p.activity_id = a.id
where a.crm_configuration_id = 70
and (p.lead_id IS NOT NULL or p.contact_id IS NOT NULL);
SELECT * FROM participants WHERE id = 1013638;
select * from teams where id = 90;
select * from users where team_id = 90;
select * from social_accounts where social_accounts.sociable_id IN (1960,1760);
SELECT * FROM crm_profiles WHERE crm_configuration_id = 71;
select * from invitations where team_id = 90;
select * from crm_configurations where id = 71;
select * from accounts where crm_configuration_id = 71 order by id desc;
select * from leads where crm_configuration_id = 71 order by id desc;
select * from contacts where crm_configuration_id = 71 order by id desc;
select * from opportunities where crm_configuration_id = 71 order by id desc;
select * from crm_profiles where crm_configuration_id = 71 order by id desc;
select * from crm_fields where crm_configuration_id = 71 order by id desc;
select * from crm_field_values where crm_field_id = 3341 order by id desc;
select * from crm_layouts where crm_configuration_id = 71 order by id desc;
select * from stages where crm_configuration_id = 71 order by id desc;
select * from users order by secondary_email desc;
select u.id, u.email, u.status, sa.id, sa.provider_user_id from social_accounts sa
join users u on sa.sociable_id = u.id
where sa.provider = 'google' and u.email LIKE 'aneliya%';
select * from failed_jobs order by id desc;
select * from users where email = '[EMAIL]' or secondary_email = '[EMAIL]';
select * from teams;
SELECT * FROM crm_profiles WHERE crm_configuration_id = 39;
SELECT * FROM crm_fields WHERE crm_configuration_id = 39 and object_type = 'task';
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 1
and sa.provider = 'salesforce';
# [PASSWORD_DOTS]
SELECT * FROM activities WHERE uuid_to_bin('c38b3895-fd0f-4b1f-9fb2-c170dba137c6') = uuid;
SELECT * FROM crm_configurations WHERE id = 70;
select * from teams where id = 1;
select * from groups where team_id = 1;
select * from users where team_id = 1;
select o.id, o.name,o.close_date, u.id, u.name, u.group_id, r.id, r.display_name, g.name, g.scope from opportunities o
join users u on o.user_id = u.id
join groups g on u.group_id = g.id
join role_user ru on u.id = ru.user_id
join roles r on ru.role_id = r.id
where o.crm_configuration_id = 39 and close_date > '2024-01-01 00:00:00';
select * from role_user where user_id = 143;
select * from roles;
select * from role_user;
select * from groups where id = 9;
select * from scope_groups where group_id = 9;
# [PASSWORD_DOTS]
select * from teams where id = 36;
select * from crm_configurations;
SELECT * FROM social_accounts WHERE sociable_id = 121;
[URL_WITH_CREDENTIALS] this will add filter, however if we need to control feature by FF we need conditional logic
public const array TYPES = [
['id' => 'exec_summary', 'name' => 'Exec Summary'],
['id' => 'coaching_profiles', 'name' => 'Coaching Profiles'],
['id' => 'product_feedback', 'name' => 'Product Feedback'],
['id' => self::TYPE_LOSS_ANALYSIS, 'name' => 'Loss Analysis'],
// ['id' => 'questions', 'name' => 'Questions'],
// ['id' => 'statistical_quant', 'name' => 'Statistical Quantitative'],
];
public const array ALL_TYPES = [
...self::TYPES,
['id' => self::TYPE_ASK_JIMINNY, 'name' => 'Ask Jiminny'],
];
public const string FREQUENCY_DAILY = 'daily';
public const string FREQUENCY_WEEKLY = 'weekly';
public const string FREQUENCY_MONTHLY = 'monthly';
public const string FREQUENCY_QUARTERLY = 'quarterly';
public const string FREQUENCY_ONE_OFF = 'one_off';
/**
* Frequencies for standard (non-Ask Jiminny) reports.
*/
public const array FREQUENCIES = [
['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],
['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],
['id' => self::FREQUENCY_QUARTERLY, 'name' => 'Quarterly'],
['id' => self::FREQUENCY_ONE_OFF, 'name' => 'One-off'],
];
/**
* Frequencies for Ask Jiminny reports.
*/
public const array ASK_JIMINNY_FREQUENCIES = [
['id' => self::FREQUENCY_DAILY, 'name' => 'Daily'],
['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],
['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],
];
public const string MEDIA_TYPE_PDF = 'pdf';
public const string MEDIA_TYPE_PODCAST = 'podcast';
public const array MEDIA_TYPES = [self::MEDIA_TYPE_PDF, self::MEDIA_TYPE_PODCAST];
public const array MEDIA_TYPE_OBJECT_PDF = ['id' => self::MEDIA_TYPE_PDF, 'name' => 'PDF'];
public const array MEDIA_TYPE_OBJECT_PODCAST = ['id' => self::MEDIA_TYPE_PODCAST, 'name' => 'Podcast'];
public const array MEDIA_TYPE_OBJECTS = [self::MEDIA_TYPE_OBJECT_PDF, self::MEDIA_TYPE_OBJECT_PODCAST];
public const array CALL_TYPE_CONFERENCE = ['id' => 'conference', 'name' => 'Conference'];
public const array CALL_TYPE_DIALER = ['id' => 'dialer', 'name' => 'Dialer'];
public const int SENT_REPORT_AT_HOURS = 5;
public const string PDF_KEY = 'pdf';
public const string AUDIO_KEY = 'audio';
private const array ALL_FREQUENCIES = [
['id' => self::FREQUENCY_DAILY, 'name' => 'Daily'],
['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],
['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],
['id' => self::FREQUENCY_QUARTERLY, 'name' => 'Quarterly'],
['id' => self::FREQUENCY_ONE_OFF, 'name' => 'One-off'],
];
private const string S3_DIR = 'reports';
private const array FILE_EXTENSIONS_VARIANTS = ['html', 'MD', 'pdf'];
private const array FILE_PODCAST_EXTENSIONS_VARIANTS = ['json', 'mp3', 'ssml'];
public function __construct(
private readonly TeamRepository $teamRepository,
private readonly GroupRepository $groupRepository,
private readonly UserRepository $userRepository,
private readonly StageRepository $stageRepository,
private readonly DealStagesService $dealStagesService,
private readonly RecipientsService $recipientsService,
private readonly AutomatedReportsRepository $automatedReportsRepository,
private readonly Webhook $webhookService,
private readonly BusDispatcher $dispatcher,
private readonly ActivityTypeService $activityTypeService,
private readonly PlaybookCategoryRepository $playbookCategoryRepository,
private readonly AskAnythingPromptService $askAnythingPromptService,
private readonly SearchRepository $activitySearchRepository,
private readonly AskAnythingRepository $askAnythingRepository,
) {
}
public static function getTypes(): array
{
$types = self::TYPES;
return array_map(static function ($type) {
return $type['id'];
}, $types);
}
public static function getCallTypes(): array
{
return array_map(static function ($callType) {
return $callType['id'];
}, [self::CALL_TYPE_CONFERENCE, self::CALL_TYPE_DIALER]);
}
public static function getFrequencies(): array
{
return array_map(static function ($frequency) {
return $frequency['id'];
}, self::FREQUENCIES);
}
// front-facing structure
public function getReportEnabledFieldData(bool $value = false): array
{
return [
'id' => 'report_enabled',
'label' => '',
'inputType' => InputTypeEnum::TOGGLE,
'value' => $value,
];
}
// Organizations = Teams
public function getOrganizationFieldData(?string $value = null, bool $shortVersion = false): array
{
$options = $this->getTeams();
if ($shortVersion) {
return [
'id' => 'organization',
'label' => 'Organization',
'options' => $options,
];
}
return [
'id' => 'organization',
'label' => 'Organization',
'inputType' => InputTypeEnum::DROPDOWN,
'required' => true,
'placeholder' => 'Select',
'options' => $options,
'value' => $value,
'dependencies' => [
'teams',
'deal_stage_at_call',
'current_deal_stage',
'recipients',
ActivityTypeService::PLAYBOOK_CATEGORIES_KEY,
],
'dependsOn' => [],
];
}
// Teams = Groups
public function getTeamFieldData(array $options = [], array $value = [], bool $shortVersion = false): array
{
if ($shortVersion) {
return [
'id' => 'teams',
'label' => 'Team',
'options' => $options,
];
}
return [
'id' => 'teams',
'label' => 'Team',
'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,
'required' => false,
'placeholder' => 'Select',
'options' => $options,
'value' => $value, // value should be an array of objects {id, name}
'dependencies' => [ActivityTypeService::PLAYBOOK_CATEGORIES_KEY],
'dependsOn' => [],
];
}
public function getReportTypeFieldData(?string $value = null, bool $shortVersion = false, ?Team $team = null): array
{
$types = [];
if ($team instanceof Team) {
if ($team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {
$types = self::TYPES;
}
if ($team->hasFeature(FeatureEnum::ASK_JIMINNY_REPORTS)) {
$types[] = ['id' => self::TYPE_ASK_JIMINNY, 'name' => 'Ask Jiminny'];
}
} else {
$types = self::TYPES;
}
if ($shortVersion) {
return [
'id' => 'report_type',
'label' => 'Report Type',
'options' => $types,
];
}
return [
'id' => 'report_type',
'label' => 'Report Type',
'inputType' => InputTypeEnum::DROPDOWN,
'required' => true,
'placeholder' => 'Select',
'options' => $types,
'value' => $value,
'dependencies' => [],
'dependsOn' => [],
];
}
public function getFrequencyFieldData(?string $value = null): array
{
return [
'id' => 'frequency',
'label' => 'Frequency',
'inputType' => InputTypeEnum::DROPDOWN,
'required' => true,
'placeholder' => 'Select',
'options' => self::FREQUENCIES,
'value' => $value,
'dependencies' => ['period'],
'dependsOn' => [],
];
}
public function getPeriodFieldData(?string $valueStartDate = null, ?string $valueEndDate = null): array
{
return [
'id' => 'period',
'label' => 'Select one-off period',
'inputType' => InputTypeEnum::DATE_RANGE,
'required' => true,
'placeholder' => 'Select',
'value' => ['startDate' => $valueStartDate, 'endDate' => $valueEndDate],
'queryParams' => [
'startDate' => 'start_date_period',
'endDate' => 'end_date_period',
],
'dependencies' => [],
'dependsOn' => ['frequency'],
];
}
public function getActivityTypesFieldData(?Team $team = null, array $value = [], array $teamsFilter = []): array
{
return $this->activityTypeService->getActivityTypeFieldData(team: $team, value: $value, groupIds: $teamsFilter);
}
public function getDealStageAtCallFieldData(?Team $team = null, array $value = []): array
{
return $this->dealStagesService->getDealStageAtCallFieldData(team: $team, value: $value);
}
public function getCurrentDealStageFieldData(?Team $team = null, array $value = []): array
{
return $this->dealStagesService->getCurrentDealStageFieldData(team: $team, value: $value);
}
public function getDealValueFieldData(?int $valueMin = null, ?int $valueMax = null): array
{
return [
'id' => 'deal_value',
'label' => 'Deal Value',
'inputType' => InputTypeEnum::INTEGER_RANGE,
'required' => false,
'value' => ['min' => $valueMin, 'max' => $valueMax],
'queryParams' => [
'min' => 'min_deal_value',
'max' => 'max_deal_value',
],
'dependencies' => [],
'dependsOn' => [],
];
}
public function getCallTypeFieldData(bool $conferenceOn = false, bool $dialerOn = false): array
{
$value = [];
$conferenceOn && $value[] = self::CALL_TYPE_CONFERENCE;
$dialerOn && $value[] = self::CALL_TYPE_DIALER;
return [
'id' => 'call_type',
'label' => 'Call Type',
'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,
'required' => true,
'options' => [
self::CALL_TYPE_CONFERENCE,
self::CALL_TYPE_DIALER,
],
'value' => $value,
'dependencies' => [],
'dependsOn' => [],
];
}
public function getMediaTypeFieldData(?AutomatedReport $report = null): array
{
$value = [];
if ($report) {
$value = $this->transformMediaTypes($report);
}
return [
'id' => 'media_types',
'label' => 'Export as',
'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,
'required' => true,
'options' => self::MEDIA_TYPE_OBJECTS,
'value' => $value,
'dependencies' => [],
'dependsOn' => [],
];
}
public function getCallDurationFieldData(?int $valueMin = null, ?int $valueMax = null): array
{
return [
'id' => 'call_duration',
'label' => 'Call Duration',
'inputType' => InputTypeEnum::INTEGER_RANGE,
'required' => false,
'value' => ['min' => $valueMin, 'max' => $valueMax],
'queryParams' => [
'min' => 'min_call_duration',
'max' => 'max_call_duration',
],
'dependencies' => [],
'dependsOn' => [],
];
}
public function getRecipientsFieldData(?Team $team = null, array $value = []): array
{
return $this->recipientsService->getRecipientsFieldData(team: $team, value: $value);
}
public function getJiminnyRecipientsFieldData(array $value = []): array
{
return $this->recipientsService->getJiminnyRecipientsFieldData($value);
}
public function getAdditionalPromptInputFieldData(?string $value = null): array
{
return [
'id' => 'additional_prompt_input',
'label' => 'Special requirements',
'inputType' => InputTypeEnum::TEXTAREA,
'required' => false,
'placeholder' => 'What should be the focus of the report?',
'value' => $value,
'dependencies' => [],
'dependsOn' => [],
];
}
public function getCustomReportNameFieldData(?string $value = null): array
{
return [
'id' => 'custom_name',
'label' => 'Custom report name',
'inputType' => InputTypeEnum::TEXT,
'required' => false,
'placeholder' => 'Enter custom name',
'value' => $value,
'dependencies' => [],
'dependsOn' => [],
];
}
// data providers
public function getTeams(): array
{
$teams = $this->teamRepository->getTeamsForKiosk(status: Team::STATUS_ACTIVE);
$teamData = [];
foreach ($teams as $team) {
if (! $team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {
continue;
}
$teamData[] = $this->transformTeam($team);
}
return $teamData;
}
public function getTeamGroups(string $teamUuid): array
{
$data = [];
$team = $this->getTeam($teamUuid);
if ($team !== null) {
$groups = $team->groups()->get();
foreach ($groups as $group) {
$data[] = [
'id' => $group->getUuid(),
'name' => $group->getName(),
];
}
}
return $data;
}
public function getTeamsGroupsOptions(array $filterTeamUuids = []): array
{
$data = [];
$teams = $this->getTeams();
foreach ($teams as $team) {
if (! empty($filterTeamUuids) && ! in_array($team['id'], $filterTeamUuids, true)) {
continue;
}
$data[] = [
'label' => $team['name'],
'groups' => $this->getTeamGroups($team['id']),
];
}
return $data;
}
public function getTeam(string $teamUuid): ?Team
{
return $this->teamRepository->idOrUuid($teamUuid);
}
public function getTeamById(int $teamId): ?Team
{
return $this->teamRepository->find($teamId);
}
public function getGroupsUuids(AutomatedReport $report): array
{
$uuids = [];
$reportGroups = $report->getGroups();
foreach ($reportGroups as $groupId) {
if ($group = $this->groupRepository->find($groupId)) {
$uuids[] = $group->getUuid();
}
}
return $uuids;
}
public function getPlaybookCategoriesUuids(AutomatedReport $report): array
{
$uuids = [];
$playbookCategories = $report->getPlaybookCategories();
foreach ($playbookCategories as $id) {
if ($category = $this->playbookCategoryRepository->find($id)) {
$uuids[] = $category->getUuid();
}
}
return $uuids;
}
public function getDealAtCallStagesUuids(AutomatedReport $report): array
{
$uuids = [];
$reportStages = $report->getDealAtCallStages();
foreach ($reportStages as $id) {
if ($stage = $this->stageRepository->find($id)) {
$uuids[] = $stage->getUuid();
}
}
return $uuids;
}
public function getCurrentDealStagesUuids(AutomatedReport $report): array
{
$uuids = [];
$reportStages = $report->getCurrentDealStages();
foreach ($reportStages as $id) {
if ($stage = $this->stageRepository->find($id)) {
$uuids[] = $stage->getUuid();
}
}
return $uuids;
}
public function getUsersUuids(AutomatedReport $report): array
{
return $this->extractUserUuids($report->getRecipients());
}
public function getJiminnyUsersUuids(AutomatedReport $report): array
{
return $this->extractUserUuids($report->getJiminnyRecipients());
}
/**
* @param array<string, mixed> $recipients
*/
private function extractUserUuids(array $recipients): array
{
$userIds = $recipients['users'] ?? [];
return collect($userIds)
->map(fn ($id) => $this->userRepository->find((int) $id))
->filter()
->map(fn (UserContract $user) => $user->getUuid())
->values()
->all();
}
// get mail data
public function getRecipientUsers(AutomatedReport $report): array
{
return $this->buildRecipientUsers($report->getRecipients());
}
private function getJiminnyRecipientUsers(AutomatedReport $report): array
{
return $this->buildRecipientUsers($report->getJiminnyRecipients());
}
/**
* @param array<string, mixed> $recipients
*/
private function buildRecipientUsers(array $recipients): array
{
$userIds = $recipients['users'] ?? [];
return collect($userIds)
->map(fn ($id) => $this->userRepository->find((int) $id))
->filter()
->map(fn (UserContract $user) => [
'email' => $user->getEmailAddress(),
'name' => $user->getName(),
'timezone' => $user->getTimezone()->getName(),
])
->values()
->all();
}
public function getValidRecipientUsers(AutomatedReport $report, bool $includeJiminny = false): array
{
if ($report->isAskJiminnyReport()) {
$recipients = $this->resolveAskJiminnyRecipients($report);
} else {
$recipients = $this->getRecipientUsers($report);
if ($includeJiminny) {
$recipients = array_merge($recipients, $this->getJiminnyRecipientUsers($report));
}
}
$emails = [];
return array_values(array_filter(
$recipients,
static function ($recipient) use (&$emails) {
if (empty($recipient['email']) || in_array($recipient['email'], $emails, true)) {
return false;
}
$emails[] = $recipient['email'];
return true;
}
));
}
private function resolveAskJiminnyRecipients(AutomatedReport $report): array
{
$recipients = [];
$creator = $report->getCreator();
if ($creator !== null) {
$recipients[] = [
'email' => $creator->getEmailAddress(),
'name' => $creator->getName(),
'timezone' => $creator->getTimezone()->getName(),
];
}
return array_merge(
$recipients,
$this->buildRecipientUsers($report->getRecipients()),
$this->getGroupRecipientUsers($report),
);
}
private function getGroupRecipientUsers(AutomatedReport $report): array
{
$users = [];
foreach ($report->getGroups() as $groupId) {
$group = $this->groupRepository->find($groupId);
if ($group === null) {
continue;
}
foreach ($group->getMembers() as $member) {
$users[] = [
'email' => $member->getEmailAddress(),
'name' => $member->getName(),
'timezone' => $member->getTimezone()->getName(),
];
}
}
return $users;
}
public function getReportTypeName(AutomatedReportResult $report): string
{
$type = $report->getReport()->getType();
$getType = $this->transformReportType($type);
return $getType['name'];
}
public function getReportPeriodName(AutomatedReportResult $report): string
{
$from = $report->getFromDate();
$to = $report->getToDate();
$frequency = $report->getReport()->getFrequency();
if ($from === null || $to === null) {
if (! $report->getReport()->isAskJiminnyReport()) {
$invalidPeriod = $from === null ? 'from' : 'to';
throw new ApplicationException('Report period is invalid: ' . $invalidPeriod);
}
$period = $this->calculateFromAndToDatePeriod($frequency);
$from = $period['fromDate'];
$to = $period['toDate'];
}
return $this->formatReportPeriodName($frequency, $from, $to);
}
private function formatReportPeriodName(string $frequency, Carbon $from, Carbon $to): string
{
$fromYear = $from->format('Y');
$toYear = $to->format('Y');
$differentYears = $fromYear !== $toYear;
switch ($frequency) {
case self::FREQUENCY_DAILY:
return $from->format('j M Y');
case self::FREQUENCY_QUARTERLY:
// 'Jan-Mar 2025' or 'Nov 2024-Jan 2025' if years differ
$startMonth = $from->format('M');
$endMonth = $to->copy()->subMonth();
$endMonthName = $endMonth->format('M');
$endMonthYear = $endMonth->format('Y');
if ($differentYears) {
return "{$startMonth} {$fromYear} - {$endMonthName} {$endMonthYear}";
}
return "{$startMonth} - {$endMonthName} {$toYear}";
case self::FREQUENCY_MONTHLY:
// 'May 2025' - monthly reports are always within the same year
return $from->format('M Y');
case self::FREQUENCY_WEEKLY:
// '4 - 8 Aug 2025', '27 Oct - 3 Nov 2025', or '28 Dec 2024 - 3 Jan 2025' if years differ
$startDay = $from->format('j');
$endDay = $to->format('j');
$startMonth = $from->format('M');
$endMonth = $to->format('M');
if ($differentYears) {
return "{$startDay} {$startMonth} {$fromYear} - {$endDay} {$endMonth} {$toYear}";
}
if ($startMonth !== $endMonth) {
return "{$startDay} {$startMonth} - {$endDay} {$endMonth} {$toYear}";
}
return "{$startDay} - {$endDay} {$endMonth} {$toYear}";
case self::FREQUENCY_ONE_OFF:
// '2 May-31 May 2025' or '15 Dec 2024-15 Jan 2025' if years differ
$startDay = $from->format('j');
$startMonth = $from->format('M');
$endDay = $to->format('j');
$endMonth = $to->format('M');
// If same month and year, use a format like '2-31 May 2025'
if ($startMonth === $endMonth && ! $differentYears) {
return "{$startDay} - {$endDay} {$startMonth} {$toYear}";
}
// If different years, include both years
if ($differentYears) {
return "{$startDay} {$startMonth} {$fromYear} - {$endDay} {$endMonth} {$toYear}";
}
// Same year but different months
return "{$startDay} {$startMonth} - {$endDay} {$endMonth} {$toYear}";
default:
// Default format for unknown frequencies
return $from->format('j M Y') . ' - ' . $to->format('j M Y');
}
}
public function getReportTeamsName(AutomatedReportResult $report): string
{
$groups = $report->getGroups();
if (empty($groups)) {
return 'All';
}
// Get group names from repository
$groupNames = [];
foreach ($groups as $groupId) {
$group = $this->groupRepository->find($groupId);
if ($group) {
$groupNames[] = $group->getName();
}
}
if (count($groupNames) === 1) {
// Single team format
$teamsName = $groupNames[0];
} else {
// Multiple teams format
$teamsName = implode(', ', $groupNames);
}
return $teamsName;
}
public function getReportFileName(AutomatedReportResult $report): string
...
|
[{"role":"AXButton","text" [{"role":"AXButton","text":"Project: faVsco.js, menu","depth":5,"help_text":"~/jiminny/app","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"#11894 on JY-18909-automated-reports-ask-jiminny, menu","depth":5,"help_text":"Pull request #11894 exists for current branch JY-18909-automated-reports-ask-jiminny","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Start Listening for PHP Debug Connections","depth":5,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"AutomatedReportsCommandTest","depth":6,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Run 'AutomatedReportsCommandTest'","depth":6,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Debug 'AutomatedReportsCommandTest'","depth":6,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"More Actions","depth":6,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JetBrains AI","depth":5,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Search Everywhere","depth":5,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"IDE and Project Settings","depth":5,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Execute","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Explain Plan","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Browse Query History","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"View Parameters","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Open Query Execution Settings…","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"In-Editor Results","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Tx: Auto","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Cancel Running Statements","depth":4,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Playground","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"jiminny","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.088194445,"height":0.027777778},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"16","depth":4,"role_description":"text"},{"role":"AXStaticText","text":"13","depth":4,"role_description":"text"},{"role":"AXStaticText","text":"13","depth":4,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"SELECT * FROM teams WHERE id = 1;\n\nselect * from crm_layouts where crm_configuration_id = 39;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 283;\nSELECT * FROM crm_fields WHERE id = 2234;\nSELECT * FROM crm_field_values WHERE crm_field_id = 2234;\n\nselect * from crm_profiles where user_id = 143;\n\nselect * from record_types where crm_configuration_id = 39; # 0121K000001MHElQAO,0121K000001MHEqQAO\nselect * from business_processes where crm_configuration_id = 39;\n# 01941000000H669AAC, 01941000000H66JAAS\n\nselect * from record_type_field_values\n where record_type_id IN (24);\n\nselect * from crm_field_values where id IN (2730);\n\nselect * from crm_configurations where id = 39;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 1\nand sa.provider = 'salesforce'; #1035\n\n\nselect * from users where team_id = 1; # 222 group 3\nSELECT * FROM activities WHERE user_id = 222 order by id desc;\nselect * from sidekick_settings where team_id = 1;\nselect * from teams where id = 1;\nselect * from team_features where team_id = 1;\n\nselect * from activities where crm_configuration_id = 2\nand provider = 'ms-teams' and id = 608765;\n\nSELECT * FROM activities WHERE crm_configuration_id = 2 and crm_provider_id = '59523413338';\n\nselect * from sidekick_settings where team_id = 2;\n\nSELECT * FROM activities WHERE id = 608660;\nselect * from activity_summary_logs where activity_id = 608660;\nselect * from ai_prompts where transcription_id = 11214;\n\n# ********************************************************************************************************\nSELECT * FROM activities WHERE uuid_to_bin('ed78a437-2804-450e-ab2f-56ab1c641346') = uuid;\n# id: 608818, crm: 59628809737\nSELECT * FROM activities WHERE uuid_to_bin('36b06e55-afdd-4782-8dee-c624cd0af191') = uuid;\n# id: 608821, crm: 59632069252\nSELECT ce.start_time, ce.end_time, a.id, a.uuid, crm_provider_id, calendar_event_id, title,\nplaybook_category_id, user_id, lead_id, contact_id, account_id, opportunity_id,\nscheduled_start_time, scheduled_end_time, actual_start_time, actual_end_time, a.created_at\nFROM activities a\njoin calendar_events ce on a.calendar_event_id = ce.id\nWHERE a.id IN (608818, 608821);\n\nselect * from users where team_id = 1;\nselect * from team_settings where team_id = 1;\nselect * from crm_profiles where crm_configuration_id = 39 order by user_id;\n\nselect * from team_features where team_id = 1;\n\nselect * from users where team_id = 2;\n\nSELECT * FROM activities WHERE uuid_to_bin('ec7647e9-5225-458b-b475-f31aa2769204') = uuid; # 612639\n# Preslava N. Ivanova, grou id 3\n\nSELECT * FROM opportunities WHERE uuid_to_bin('a2928fe5-aec5-46cb-85d9-7654c89e46a6') = uuid;\n\nselect * from activities where opportunity_id = 344 and actual_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00';\n\nselect\n a.id,\n a.type,\n a.scheduled_start_time,\n a.actual_start_time,\n a.created_at,\n a.opportunity_id,\n a.status\nFROM activities a\nWHERE opportunity_id = 344\nand status IN ('completed', 'received', 'delivered')\nand (\n (a.actual_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00')\nOR (a.created_at between '2024-10-11 00:00:00' and '2024-10-12 00:00:00')\nOR (a.scheduled_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00'))\n;\n\nSELECT * FROM users WHERE id = 222;\n\nSELECT * FROM crm_profiles WHERE user_id = 222;\nselect * from crm_layouts where crm_configuration_id = 39;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 281;\n\nselect * from group_deal_risk_types;\n\nselect * from opportunities where team_id = 1;\n\nSELECT * FROM opportunities WHERE id = 315;\nSELECT * FROM crm_field_data WHERE object_id = 315;\nselect * from crm_field_data where object_id = 260;\n\nselect * from generic_ai_prompts where subject_id = 315;\n\nselect * from teams; # 36, 21, 121, james.graham@bullhorn.jiminny.com\nSELECT * FROM social_accounts WHERE sociable_id = 121 and provider = 'bullhorn';\n\n# ************************************************************************************\nselect * from teams where id = 1;\nselect * from crm_configurations where id = 39;\nselect * from users where team_id = 1;\nselect u.email, cp.* from users u\njoin crm_profiles cp on u.id = cp.user_id\nwhere u.team_id = 1;\n# 1 - 00541000004281rAAA\n# 204 - 0052g000003freeAAA\n# 429 - 0052g000003qGOiAAM\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 1\nand sa.provider = 'salesforce';\n\nselect * from activities where type = 'softphone'\nand created_at > '2024-12-11 15:24:36' order by id desc;\n\nselect * from activity_providers where team_id = 1;\nselect * from activity_provider_users where activity_provider_id = 328;\n\nselect * from opportunities where crm_configuration_id = 39\nAND account_id = 178 AND is_closed = false\norder by created_at DESC;\n\nselect * from contacts where id = 3952;\nselect * from accounts where id = 178;\n\n# ************************************************************************************\nselect * from teams where id = 36;\nselect * from crm_configurations where id = 21;\nselect * from users where team_id = 36;\nselect u.email, cp.* from users u\njoin crm_profiles cp on u.id = cp.user_id\nwhere u.team_id = 36;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 36\nand sa.provider = 'bullhorn';\n\nselect * from social_accounts where id = 348;\nUPDATE social_accounts SET\nprovider_user_token = '21442_6802599_91:41179a58-21e7-4d7c-ad58-56bb666b2f65',\nprovider_refresh_token = '21442_6802599_91:01c6b335-3f2a-42e4-85ff-8a08fa65fceb',\nexpires = 1733998131,\nstate = 'connected'\nWHERE id = 348;\n\n# ************************************************************************************\nselect * from teams where id = 31;\nselect * from crm_configurations where id = 18;\n\nselect * from users where team_id = 31; # 257\nselect u.email, cp.* from users u\njoin crm_profiles cp on u.id = cp.user_id\nwhere u.team_id = 31;\n\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 31\nand sa.provider = 'close';\n\nselect * from contacts where crm_configuration_id = 18;\n\n# ********************** NEPTUNE **************************************************************\nselect * from teams;\nselect * from users where id IN (1030, 1035, 1052);\nselect * from crm_configurations;\n\nselect * from users where team_id = 65; # 257\nselect * from team_settings where team_id = 65; # 257\nselect * from invitations where team_id = 65; # 257\nselect * from users where email = 'integration-account@jiminny.com'; # 257\nselect u.email, cp.* from users u\njoin crm_profiles cp on u.id = cp.user_id\nwhere u.team_id = 65;\n\nselect * from crm_configurations where id = 53;\nselect * from accounts where crm_configuration_id = 53 order by id desc;\nselect * from leads where crm_configuration_id = 53 order by id desc;\nselect * from contacts where crm_configuration_id = 53 order by id desc;\nselect * from opportunities where crm_configuration_id = 53 order by id desc;\nselect * from crm_profiles where crm_configuration_id = 53 order by id desc;\nselect * from crm_fields where crm_configuration_id = 53 order by id desc;\nselect * from crm_field_values where crm_field_id = 3341 order by id desc;\nselect * from crm_layouts where crm_configuration_id = 53 order by id desc;\nselect * from stages where crm_configuration_id = 53 order by id desc;\n\n\nselect * from crm_profiles where crm_configuration_id = 13;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 65\nand sa.provider = 'integration-app';\n\nselect * from contacts where crm_configuration_id = 13;\n\nselect * from social_accounts where sociable_id = 283;\n\nSELECT * FROM opportunities WHERE crm_provider_id = '006O400000E9bzeIAB';\n\nselect * from activity_providers where team_id = 65;\nSELECT * FROM activities WHERE crm_configuration_id IN (51, 52, 53);\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 65\n;\n\n# ***************************** STAGING ********************************************\nSELECT * FROM teams;\nSELECT * FROM teams WHERE id = 88;\nSELECT * FROM teams WHERE id = 89;\nselect * from team_settings where team_id = 89;\nSELECT * FROM users WHERE team_id = 89;\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 89;\n\nselect * from users;\nSELECT * FROM social_accounts WHERE sociable_id = 1761;\nSELECT * FROM crm_configurations WHERE id = 70;\nselect * from accounts where crm_configuration_id = 70 order by id desc;\nselect * from leads where crm_configuration_id = 70 order by id desc;\nselect * from contacts where crm_configuration_id = 70 order by id desc;\nselect * from opportunities where crm_configuration_id = 70 order by id desc;\nselect * from crm_profiles where crm_configuration_id = 70 order by id desc;\nselect * from crm_fields where crm_configuration_id = 70 order by id desc;\nselect * from crm_field_values where crm_field_id = 3536 order by id desc;\nselect * from crm_layouts where crm_configuration_id = 70 order by id desc;\nselect * from stages where crm_configuration_id = 70 order by id desc;\nselect * from business_processes where crm_configuration_id = 70 order by id desc;\nselect * from business_process_stages where business_process_id = 34;\n\nselect * from contacts where id = 10468;\n\nselect * from crm_layouts where crm_configuration_id = 70;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 388;\nSELECT * FROM crm_fields WHERE id IN (3533,3534,3535);\n\nselect * from activities where crm_configuration_id = 70\nand (account_id IS NOT NULL or lead_id IS NOT NULL or contact_id IS NOT NULL or opportunity_id IS NOT NULL) order by id desc;\n\nSELECT * FROM activities WHERE uuid_to_bin('2e10b60f-8a61-41c5-a3d4-28835353dc65') = uuid;\nSELECT * FROM activities where crm_configuration_id = 69 ;\n\nSELECT * FROM users WHERE email LIKE '%jiminny_web_sa2@jiminny.com%';\nSELECT * FROM activities WHERE uuid_to_bin('5a150c93-40fc-42ec-b3bd-c1d328e09f6e') = uuid;\nSELECT * FROM opportunities WHERE id = 385;\n\nselect * from participants p\njoin activities a on p.activity_id = a.id\nwhere a.crm_configuration_id = 70\nand (p.lead_id IS NOT NULL or p.contact_id IS NOT NULL);\nSELECT * FROM participants WHERE id = 1013638;\n\nselect * from teams where id = 90;\nselect * from users where team_id = 90;\nselect * from social_accounts where social_accounts.sociable_id IN (1960,1760);\nSELECT * FROM crm_profiles WHERE crm_configuration_id = 71;\nselect * from invitations where team_id = 90;\n\nselect * from crm_configurations where id = 71;\nselect * from accounts where crm_configuration_id = 71 order by id desc;\nselect * from leads where crm_configuration_id = 71 order by id desc;\nselect * from contacts where crm_configuration_id = 71 order by id desc;\nselect * from opportunities where crm_configuration_id = 71 order by id desc;\nselect * from crm_profiles where crm_configuration_id = 71 order by id desc;\nselect * from crm_fields where crm_configuration_id = 71 order by id desc;\nselect * from crm_field_values where crm_field_id = 3341 order by id desc;\nselect * from crm_layouts where crm_configuration_id = 71 order by id desc;\nselect * from stages where crm_configuration_id = 71 order by id desc;\n\nselect * from users order by secondary_email desc;\nselect u.id, u.email, u.status, sa.id, sa.provider_user_id from social_accounts sa\n join users u on sa.sociable_id = u.id\nwhere sa.provider = 'google' and u.email LIKE 'aneliya%';\n\nselect * from failed_jobs order by id desc;\n\nselect * from users where email = 'ben.allwright@learningpeople.co.uk' or secondary_email = 'ben.allwright@learningpeople.co.uk';\n\nselect * from teams;\nSELECT * FROM crm_profiles WHERE crm_configuration_id = 39;\nSELECT * FROM crm_fields WHERE crm_configuration_id = 39 and object_type = 'task';\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 1\nand sa.provider = 'salesforce';\n\n# ************************************************************************************\nSELECT * FROM activities WHERE uuid_to_bin('c38b3895-fd0f-4b1f-9fb2-c170dba137c6') = uuid;\nSELECT * FROM crm_configurations WHERE id = 70;\n\nselect * from teams where id = 1;\nselect * from groups where team_id = 1;\nselect * from users where team_id = 1;\n\nselect o.id, o.name,o.close_date, u.id, u.name, u.group_id, r.id, r.display_name, g.name, g.scope from opportunities o\njoin users u on o.user_id = u.id\njoin groups g on u.group_id = g.id\njoin role_user ru on u.id = ru.user_id\njoin roles r on ru.role_id = r.id\nwhere o.crm_configuration_id = 39 and close_date > '2024-01-01 00:00:00';\n\nselect * from role_user where user_id = 143;\nselect * from roles;\n\nselect * from role_user;\nselect * from groups where id = 9;\nselect * from scope_groups where group_id = 9;\n\n# ************************************************************************************\nselect * from teams where id = 36;\nselect * from crm_configurations;\nSELECT * FROM social_accounts WHERE sociable_id = 121;\n\nhttps://crmsandbox.zoho.com/crm/jiminnyw4/tab/Leads/4776201000005049105\nhttps://crmsandbox.zoho.com/crm/\n\nhttps://crm.zoho.com/crm/org3469620/tab/Leads/230045000229559080\n https://crm.zoho.com/crm/\n org3469620\n\nSELECT * FROM activities WHERE uuid_to_bin('03382d20-c8bc-48e7-a3d4-90b52fa5ceab') = uuid;\n\nselect * from users where email LIKE \"%mobile_automation_%\";\nselect * from social_accounts where sociable_id IN (2228);\nselect * from crm_profiles where user_id IN (2222,2223,2226,2227);\n\nselect * from teams order by id desc;\nSELECT * FROM users WHERE id = 2229;\nSELECT * FROM crm_profiles WHERE user_id = 2229;\nselect * from opportunities where crm_configuration_id = 88;\nselect * from crm_fields where crm_configuration_id = 88;\nselect * from crm_profiles where crm_configuration_id = 88;\n\nSELECT * FROM teams WHERE id = 1;\n\nSELECT * FROM users WHERE id = 143;\nSELECT * FROM users WHERE uuid_to_bin('fde193d3-06a2-4e1a-8895-62b94039215d') = uuid;\nSELECT * FROM teams WHERE uuid_to_bin('73385071-a756-42ae-9c73-8b53f2309467') = uuid;\n\nhttps://app.staging.jiminny.com/ondemand?\n min_duration=1\n &\n only_recorded=1\n &\n user_id%5B%5D=641f1acb-16b8-42d1-8726-df52979dad0e\n &\n sequence_number=2\n\n select * from users where team_id = 1 and email like '%stoyan%'\n\nselect * from coaching_feedbacks;\n\nselect * from teams;\nSELECT * FROM users WHERE team_id = 36;\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 19\nand sa.provider = 'pipedrive';\n\nselect * from users where id = 143;\n\nSELECT * FROM users WHERE uuid_to_bin('73180eeb-33de-4065-977d-ccbe0e6c94fc') = uuid;\nSELECT * FROM teams WHERE uuid_to_bin('73180eeb-33de-4065-977d-ccbe0e6c94fc') = uuid;\nSELECT * FROM activity_shares WHERE uuid_to_bin('73180eeb-33de-4065-977d-ccbe0e6c94fc') = uuid;\n\nselect * from users where team_id = 2;\nselect * from activities where crm_configuration_id = 39\nand activities.scheduled_start_time BETWEEN '2025-04-09 00:00:00' AND '2025-04-09 23:59:59'\nAND user_id = 143\norder by id desc;\n\n# ************************************************************************************\nselect * from teams where id = 142; # 2312, 126\nselect * from team_settings;\nselect * from users where team_id = 142; # 21642\nSELECT * FROM social_accounts WHERE sociable_id = 21642;\nSELECT * FROM crm_profiles cp join users u ON u.id = cp.user_id WHERE team_id = 142;\nselect * from crm_profiles where id IN (93);\nselect * from invitations;\nselect * from team_features where team_id = 1;\n\nSELECT * FROM crm_configurations WHERE id = 126;\nselect * from accounts where crm_configuration_id = 126 order by id desc;\nselect * from leads where crm_configuration_id = 126 order by id desc;\nselect * from contacts where crm_configuration_id = 126 order by id desc;\nselect * from opportunities where crm_configuration_id = 126 order by id desc;\nselect * from crm_profiles where crm_configuration_id = 126 order by id desc;\nselect * from crm_fields where crm_configuration_id = 126 # 11060\n# and type IN ('picklist', 'status')\n# and object_type = 'task'\norder by id desc;\n# 5731,5732,5733\nselect DISTINCT crm_field_id from crm_field_values where crm_field_id IN (11151,12239,12215,12185,12175,12165,12144,12137,12127,12109,12107,12105,12103,12092,12037,12005,12003,11987,11969,11958,11951,11942,11931,11924,11921,11917,11915,11901,11893,11883,11872,11870,11868,11866,11839,11833,11821,11793,11780,11777,11769,11757,11737,11735,11656,11645,11638,11629,11618,11611,11602,11591,11584,11581,11558,11544,11543,11534,11532,11529,11527,11503,11497,11493,11488,11470,11468,11457,11455,11397,11387,11372,11363,11348,11323,11318,11309,11301,11300,11292,11290,11286,11284,11256,11252,11242,11237,11233,11219,11176,11160) order by id desc;\nselect * from crm_layouts where crm_configuration_id = 126 order by id desc;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id in (300,299,298);\nselect * from stages where crm_configuration_id = 126 order by id desc;\nselect * from business_processes where crm_configuration_id = 126 order by id desc;\nselect * from business_process_stages where business_process_id IN (76,75,74,73);\nselect * from playbooks where team_id = 142;\nselect * from playbook_layouts where playbook_id IN (108);\nSELECT * FROM playbook_categories WHERE playbook_id IN (108);\n\nselect * from teams where id = 130;\nSELECT * FROM social_accounts WHERE sociable_id = 2291;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 2\nand sa.provider = 'hubspot';\n\nSELECT * FROM activities\n WHERE crm_configuration_id = 110;\n\nselect * from teams;\nselect * from crm_configurations;\n\nSELECT * FROM activities WHERE id = 628773;\nSELECT * FROM crm_profiles WHERE user_id = 1460;\nSELECT * FROM social_accounts WHERE sociable_id = 2291;\n\nselect * from teams;\nselect ru.*, pr.*, p.* from users u join role_user ru on ru.user_id = u.id\njoin permission_role pr on pr.role_id = ru.role_id\n join permissions p on p.id = pr.permission_id\nwhere team_id = 495 and p.name IN ('dial');\n\nselect * from teams where id = 145;\nselect * from crm_configurations where id = 129;\nselect * from social_accounts where sociable_id = 2317;\nSELECT * FROM activities WHERE uuid_to_bin('8dbab184-a333-4268-ad57-fb41f8d53a9a') = uuid;\n\nselect * from teams where id = 1;\nSELECT * FROM crm_layouts WHERE crm_configuration_id = 39;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 280;\nSELECT * FROM crm_layout_entities WHERE id = 5507;\nSELECT * FROM crm_fields WHERE crm_configuration_id = 39 and object_type IN ('event');\n\nselect * from teams;\nselect * from activities where crm_configuration_id = 14;\n\nSELECT * FROM social_accounts where provider = 'copper';\n\nselect * from activities where id = 628467;\nselect * from participants where activity_id = 628467;\n\nSELECT * FROM contacts WHERE id = 3969;\nSELECT * FROM accounts WHERE id = 177;\n\nSELECT * FROM activities WHERE uuid_to_bin('4eb54c77-cfa3-2bd4-84a7-9ed46a21c988') = uuid;\n\n# ********************* BH\nselect * from teams where id = 36;\nSELECT * FROM crm_configurations WHERE id = 21;\nselect * from activities where crm_configuration_id = 21 and id = 607901;\nselect * from activities where crm_configuration_id = 21;\n\nselect * roles;\nselect * from permissions;\nselect * from permission_role where permission_id = 226;\n\nselect * from migrations order by id desc;\n\n# mercury\n# neptune\n# earth\n\nselect * from teams;\nselect * from teams where id = 19;\nselect * from teams where id = 27;\nselect * from users where team_id = 27;\nSELECT * FROM crm_configurations WHERE id = 42;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 19\nand sa.provider = 'pipedrive';\n\nselect * from activities where id = 631461;\nSELECT * FROM crm_field_values WHERE crm_field_id = 180;\n\nselect * from teams where id = 2;\nSELECT * FROM social_accounts WHERE sociable_id = 89;\n\nSELECT * FROM activities WHERE uuid_to_bin('ba0c029a-bc14-4e17-8603-64174acebcbb') = uuid; # 634273\nselect * from activity_summary_logs where activity_id = 634273;\n\nselect * from sidekick_settings where team_id = 2;\n\nselect * from teams; # 2, 2\nSELECT * FROM crm_configurations WHERE team_id = 2; # 2\nselect * from team_features where team_id = 2;\nselect * from features;\nSELECT * FROM opportunities WHERE crm_configuration_id = 2 and crm_provider_id = '51317301383';\nSELECT * FROM opportunities WHERE crm_configuration_id = 2 order by id desc;\n\nselect * from automated_reports order by id desc;\nselect * from automated_report_results order by id desc;\nselect * from users where team_id = 1 and id IN (7160, 3248);\nselect * from migrations order by id desc;\n\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 1 and sa.provider = 'salesforce';\n\nselect * from teams where id = 1;\nselect * from groups g JOIN playbooks p on g.playbook_id = p.id where g.team_id = 1;\nselect * from groups where id = 565;\nselect * from playbooks where team_id = 1;\nselect * from playbooks where id = 175;\nselect * from playbook_categories where playbook_id = 175;\nselect * from users where team_id = 1;\nselect * from users where id = 7160;\nselect * from crm_profiles where user_id = 7160;\nselect * from features;\nselect\n *\n# id, uuid, type, provider, playbook_category_id, user_id, lead_id, contact_id, account_id, opportunity_id, stage_id,\n# crm_configuration_id, crm_provider_id, transcription_id, status\nfrom activities where crm_configuration_id = 1 and type = 'conference'\n# and crm_provider_id IS NOT NULL\nand provider != 'uploader' and actual_start_time IS NOT NULL\nORDER by id desc;\nselect * from activities where id = 54747783; # 00UO400000pCzojMAC\n\nselect p.id, p.activity_type, pc.id, pc.name\nFROM playbooks p\njoin playbook_categories pc on p.id = pc.playbook_id\nwhere p.team_id = 1 and p.activity_type = 'event';\n\nSELECT * FROM crm_fields WHERE crm_configuration_id = 1 and object_type = 'event';\nSELECT * FROM crm_field_values WHERE crm_field_id = 4;\n\nselect * from crm_layouts cl join playbook_layouts pl on cl.id = pl.layout_id\nwhere crm_configuration_id = 1 and pl.playbook_id = 175;\n\nselect * from teams;\nSELECT r.* FROM automated_reports r\njoin teams t on r.team_id = t.id\nWHERE r.frequency = 'daily'\n and r.status = 1\nAND t.status = 'active'\nAND (r.expires_at >= now() OR r.expires_at IS NULL);\n\nselect * from automated_report_results where report_id IN (18, 33);\n\nselect * from activity_searches where id = 10932;\nselect * from activity_search_filters where activity_search_id = 10932;\nselect * from automated_reports;\nselect * from automated_report_results where report_id IN (34, 35);","depth":4,"value":"SELECT * FROM teams WHERE id = 1;\n\nselect * from crm_layouts where crm_configuration_id = 39;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 283;\nSELECT * FROM crm_fields WHERE id = 2234;\nSELECT * FROM crm_field_values WHERE crm_field_id = 2234;\n\nselect * from crm_profiles where user_id = 143;\n\nselect * from record_types where crm_configuration_id = 39; # 0121K000001MHElQAO,0121K000001MHEqQAO\nselect * from business_processes where crm_configuration_id = 39;\n# 01941000000H669AAC, 01941000000H66JAAS\n\nselect * from record_type_field_values\n where record_type_id IN (24);\n\nselect * from crm_field_values where id IN (2730);\n\nselect * from crm_configurations where id = 39;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 1\nand sa.provider = 'salesforce'; #1035\n\n\nselect * from users where team_id = 1; # 222 group 3\nSELECT * FROM activities WHERE user_id = 222 order by id desc;\nselect * from sidekick_settings where team_id = 1;\nselect * from teams where id = 1;\nselect * from team_features where team_id = 1;\n\nselect * from activities where crm_configuration_id = 2\nand provider = 'ms-teams' and id = 608765;\n\nSELECT * FROM activities WHERE crm_configuration_id = 2 and crm_provider_id = '59523413338';\n\nselect * from sidekick_settings where team_id = 2;\n\nSELECT * FROM activities WHERE id = 608660;\nselect * from activity_summary_logs where activity_id = 608660;\nselect * from ai_prompts where transcription_id = 11214;\n\n# ********************************************************************************************************\nSELECT * FROM activities WHERE uuid_to_bin('ed78a437-2804-450e-ab2f-56ab1c641346') = uuid;\n# id: 608818, crm: 59628809737\nSELECT * FROM activities WHERE uuid_to_bin('36b06e55-afdd-4782-8dee-c624cd0af191') = uuid;\n# id: 608821, crm: 59632069252\nSELECT ce.start_time, ce.end_time, a.id, a.uuid, crm_provider_id, calendar_event_id, title,\nplaybook_category_id, user_id, lead_id, contact_id, account_id, opportunity_id,\nscheduled_start_time, scheduled_end_time, actual_start_time, actual_end_time, a.created_at\nFROM activities a\njoin calendar_events ce on a.calendar_event_id = ce.id\nWHERE a.id IN (608818, 608821);\n\nselect * from users where team_id = 1;\nselect * from team_settings where team_id = 1;\nselect * from crm_profiles where crm_configuration_id = 39 order by user_id;\n\nselect * from team_features where team_id = 1;\n\nselect * from users where team_id = 2;\n\nSELECT * FROM activities WHERE uuid_to_bin('ec7647e9-5225-458b-b475-f31aa2769204') = uuid; # 612639\n# Preslava N. Ivanova, grou id 3\n\nSELECT * FROM opportunities WHERE uuid_to_bin('a2928fe5-aec5-46cb-85d9-7654c89e46a6') = uuid;\n\nselect * from activities where opportunity_id = 344 and actual_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00';\n\nselect\n a.id,\n a.type,\n a.scheduled_start_time,\n a.actual_start_time,\n a.created_at,\n a.opportunity_id,\n a.status\nFROM activities a\nWHERE opportunity_id = 344\nand status IN ('completed', 'received', 'delivered')\nand (\n (a.actual_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00')\nOR (a.created_at between '2024-10-11 00:00:00' and '2024-10-12 00:00:00')\nOR (a.scheduled_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00'))\n;\n\nSELECT * FROM users WHERE id = 222;\n\nSELECT * FROM crm_profiles WHERE user_id = 222;\nselect * from crm_layouts where crm_configuration_id = 39;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 281;\n\nselect * from group_deal_risk_types;\n\nselect * from opportunities where team_id = 1;\n\nSELECT * FROM opportunities WHERE id = 315;\nSELECT * FROM crm_field_data WHERE object_id = 315;\nselect * from crm_field_data where object_id = 260;\n\nselect * from generic_ai_prompts where subject_id = 315;\n\nselect * from teams; # 36, 21, 121, james.graham@bullhorn.jiminny.com\nSELECT * FROM social_accounts WHERE sociable_id = 121 and provider = 'bullhorn';\n\n# ************************************************************************************\nselect * from teams where id = 1;\nselect * from crm_configurations where id = 39;\nselect * from users where team_id = 1;\nselect u.email, cp.* from users u\njoin crm_profiles cp on u.id = cp.user_id\nwhere u.team_id = 1;\n# 1 - 00541000004281rAAA\n# 204 - 0052g000003freeAAA\n# 429 - 0052g000003qGOiAAM\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 1\nand sa.provider = 'salesforce';\n\nselect * from activities where type = 'softphone'\nand created_at > '2024-12-11 15:24:36' order by id desc;\n\nselect * from activity_providers where team_id = 1;\nselect * from activity_provider_users where activity_provider_id = 328;\n\nselect * from opportunities where crm_configuration_id = 39\nAND account_id = 178 AND is_closed = false\norder by created_at DESC;\n\nselect * from contacts where id = 3952;\nselect * from accounts where id = 178;\n\n# ************************************************************************************\nselect * from teams where id = 36;\nselect * from crm_configurations where id = 21;\nselect * from users where team_id = 36;\nselect u.email, cp.* from users u\njoin crm_profiles cp on u.id = cp.user_id\nwhere u.team_id = 36;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 36\nand sa.provider = 'bullhorn';\n\nselect * from social_accounts where id = 348;\nUPDATE social_accounts SET\nprovider_user_token = '21442_6802599_91:41179a58-21e7-4d7c-ad58-56bb666b2f65',\nprovider_refresh_token = '21442_6802599_91:01c6b335-3f2a-42e4-85ff-8a08fa65fceb',\nexpires = 1733998131,\nstate = 'connected'\nWHERE id = 348;\n\n# ************************************************************************************\nselect * from teams where id = 31;\nselect * from crm_configurations where id = 18;\n\nselect * from users where team_id = 31; # 257\nselect u.email, cp.* from users u\njoin crm_profiles cp on u.id = cp.user_id\nwhere u.team_id = 31;\n\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 31\nand sa.provider = 'close';\n\nselect * from contacts where crm_configuration_id = 18;\n\n# ********************** NEPTUNE **************************************************************\nselect * from teams;\nselect * from users where id IN (1030, 1035, 1052);\nselect * from crm_configurations;\n\nselect * from users where team_id = 65; # 257\nselect * from team_settings where team_id = 65; # 257\nselect * from invitations where team_id = 65; # 257\nselect * from users where email = 'integration-account@jiminny.com'; # 257\nselect u.email, cp.* from users u\njoin crm_profiles cp on u.id = cp.user_id\nwhere u.team_id = 65;\n\nselect * from crm_configurations where id = 53;\nselect * from accounts where crm_configuration_id = 53 order by id desc;\nselect * from leads where crm_configuration_id = 53 order by id desc;\nselect * from contacts where crm_configuration_id = 53 order by id desc;\nselect * from opportunities where crm_configuration_id = 53 order by id desc;\nselect * from crm_profiles where crm_configuration_id = 53 order by id desc;\nselect * from crm_fields where crm_configuration_id = 53 order by id desc;\nselect * from crm_field_values where crm_field_id = 3341 order by id desc;\nselect * from crm_layouts where crm_configuration_id = 53 order by id desc;\nselect * from stages where crm_configuration_id = 53 order by id desc;\n\n\nselect * from crm_profiles where crm_configuration_id = 13;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 65\nand sa.provider = 'integration-app';\n\nselect * from contacts where crm_configuration_id = 13;\n\nselect * from social_accounts where sociable_id = 283;\n\nSELECT * FROM opportunities WHERE crm_provider_id = '006O400000E9bzeIAB';\n\nselect * from activity_providers where team_id = 65;\nSELECT * FROM activities WHERE crm_configuration_id IN (51, 52, 53);\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 65\n;\n\n# ***************************** STAGING ********************************************\nSELECT * FROM teams;\nSELECT * FROM teams WHERE id = 88;\nSELECT * FROM teams WHERE id = 89;\nselect * from team_settings where team_id = 89;\nSELECT * FROM users WHERE team_id = 89;\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 89;\n\nselect * from users;\nSELECT * FROM social_accounts WHERE sociable_id = 1761;\nSELECT * FROM crm_configurations WHERE id = 70;\nselect * from accounts where crm_configuration_id = 70 order by id desc;\nselect * from leads where crm_configuration_id = 70 order by id desc;\nselect * from contacts where crm_configuration_id = 70 order by id desc;\nselect * from opportunities where crm_configuration_id = 70 order by id desc;\nselect * from crm_profiles where crm_configuration_id = 70 order by id desc;\nselect * from crm_fields where crm_configuration_id = 70 order by id desc;\nselect * from crm_field_values where crm_field_id = 3536 order by id desc;\nselect * from crm_layouts where crm_configuration_id = 70 order by id desc;\nselect * from stages where crm_configuration_id = 70 order by id desc;\nselect * from business_processes where crm_configuration_id = 70 order by id desc;\nselect * from business_process_stages where business_process_id = 34;\n\nselect * from contacts where id = 10468;\n\nselect * from crm_layouts where crm_configuration_id = 70;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 388;\nSELECT * FROM crm_fields WHERE id IN (3533,3534,3535);\n\nselect * from activities where crm_configuration_id = 70\nand (account_id IS NOT NULL or lead_id IS NOT NULL or contact_id IS NOT NULL or opportunity_id IS NOT NULL) order by id desc;\n\nSELECT * FROM activities WHERE uuid_to_bin('2e10b60f-8a61-41c5-a3d4-28835353dc65') = uuid;\nSELECT * FROM activities where crm_configuration_id = 69 ;\n\nSELECT * FROM users WHERE email LIKE '%jiminny_web_sa2@jiminny.com%';\nSELECT * FROM activities WHERE uuid_to_bin('5a150c93-40fc-42ec-b3bd-c1d328e09f6e') = uuid;\nSELECT * FROM opportunities WHERE id = 385;\n\nselect * from participants p\njoin activities a on p.activity_id = a.id\nwhere a.crm_configuration_id = 70\nand (p.lead_id IS NOT NULL or p.contact_id IS NOT NULL);\nSELECT * FROM participants WHERE id = 1013638;\n\nselect * from teams where id = 90;\nselect * from users where team_id = 90;\nselect * from social_accounts where social_accounts.sociable_id IN (1960,1760);\nSELECT * FROM crm_profiles WHERE crm_configuration_id = 71;\nselect * from invitations where team_id = 90;\n\nselect * from crm_configurations where id = 71;\nselect * from accounts where crm_configuration_id = 71 order by id desc;\nselect * from leads where crm_configuration_id = 71 order by id desc;\nselect * from contacts where crm_configuration_id = 71 order by id desc;\nselect * from opportunities where crm_configuration_id = 71 order by id desc;\nselect * from crm_profiles where crm_configuration_id = 71 order by id desc;\nselect * from crm_fields where crm_configuration_id = 71 order by id desc;\nselect * from crm_field_values where crm_field_id = 3341 order by id desc;\nselect * from crm_layouts where crm_configuration_id = 71 order by id desc;\nselect * from stages where crm_configuration_id = 71 order by id desc;\n\nselect * from users order by secondary_email desc;\nselect u.id, u.email, u.status, sa.id, sa.provider_user_id from social_accounts sa\n join users u on sa.sociable_id = u.id\nwhere sa.provider = 'google' and u.email LIKE 'aneliya%';\n\nselect * from failed_jobs order by id desc;\n\nselect * from users where email = 'ben.allwright@learningpeople.co.uk' or secondary_email = 'ben.allwright@learningpeople.co.uk';\n\nselect * from teams;\nSELECT * FROM crm_profiles WHERE crm_configuration_id = 39;\nSELECT * FROM crm_fields WHERE crm_configuration_id = 39 and object_type = 'task';\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 1\nand sa.provider = 'salesforce';\n\n# ************************************************************************************\nSELECT * FROM activities WHERE uuid_to_bin('c38b3895-fd0f-4b1f-9fb2-c170dba137c6') = uuid;\nSELECT * FROM crm_configurations WHERE id = 70;\n\nselect * from teams where id = 1;\nselect * from groups where team_id = 1;\nselect * from users where team_id = 1;\n\nselect o.id, o.name,o.close_date, u.id, u.name, u.group_id, r.id, r.display_name, g.name, g.scope from opportunities o\njoin users u on o.user_id = u.id\njoin groups g on u.group_id = g.id\njoin role_user ru on u.id = ru.user_id\njoin roles r on ru.role_id = r.id\nwhere o.crm_configuration_id = 39 and close_date > '2024-01-01 00:00:00';\n\nselect * from role_user where user_id = 143;\nselect * from roles;\n\nselect * from role_user;\nselect * from groups where id = 9;\nselect * from scope_groups where group_id = 9;\n\n# ************************************************************************************\nselect * from teams where id = 36;\nselect * from crm_configurations;\nSELECT * FROM social_accounts WHERE sociable_id = 121;\n\nhttps://crmsandbox.zoho.com/crm/jiminnyw4/tab/Leads/4776201000005049105\nhttps://crmsandbox.zoho.com/crm/\n\nhttps://crm.zoho.com/crm/org3469620/tab/Leads/230045000229559080\n https://crm.zoho.com/crm/\n org3469620\n\nSELECT * FROM activities WHERE uuid_to_bin('03382d20-c8bc-48e7-a3d4-90b52fa5ceab') = uuid;\n\nselect * from users where email LIKE \"%mobile_automation_%\";\nselect * from social_accounts where sociable_id IN (2228);\nselect * from crm_profiles where user_id IN (2222,2223,2226,2227);\n\nselect * from teams order by id desc;\nSELECT * FROM users WHERE id = 2229;\nSELECT * FROM crm_profiles WHERE user_id = 2229;\nselect * from opportunities where crm_configuration_id = 88;\nselect * from crm_fields where crm_configuration_id = 88;\nselect * from crm_profiles where crm_configuration_id = 88;\n\nSELECT * FROM teams WHERE id = 1;\n\nSELECT * FROM users WHERE id = 143;\nSELECT * FROM users WHERE uuid_to_bin('fde193d3-06a2-4e1a-8895-62b94039215d') = uuid;\nSELECT * FROM teams WHERE uuid_to_bin('73385071-a756-42ae-9c73-8b53f2309467') = uuid;\n\nhttps://app.staging.jiminny.com/ondemand?\n min_duration=1\n &\n only_recorded=1\n &\n user_id%5B%5D=641f1acb-16b8-42d1-8726-df52979dad0e\n &\n sequence_number=2\n\n select * from users where team_id = 1 and email like '%stoyan%'\n\nselect * from coaching_feedbacks;\n\nselect * from teams;\nSELECT * FROM users WHERE team_id = 36;\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 19\nand sa.provider = 'pipedrive';\n\nselect * from users where id = 143;\n\nSELECT * FROM users WHERE uuid_to_bin('73180eeb-33de-4065-977d-ccbe0e6c94fc') = uuid;\nSELECT * FROM teams WHERE uuid_to_bin('73180eeb-33de-4065-977d-ccbe0e6c94fc') = uuid;\nSELECT * FROM activity_shares WHERE uuid_to_bin('73180eeb-33de-4065-977d-ccbe0e6c94fc') = uuid;\n\nselect * from users where team_id = 2;\nselect * from activities where crm_configuration_id = 39\nand activities.scheduled_start_time BETWEEN '2025-04-09 00:00:00' AND '2025-04-09 23:59:59'\nAND user_id = 143\norder by id desc;\n\n# ************************************************************************************\nselect * from teams where id = 142; # 2312, 126\nselect * from team_settings;\nselect * from users where team_id = 142; # 21642\nSELECT * FROM social_accounts WHERE sociable_id = 21642;\nSELECT * FROM crm_profiles cp join users u ON u.id = cp.user_id WHERE team_id = 142;\nselect * from crm_profiles where id IN (93);\nselect * from invitations;\nselect * from team_features where team_id = 1;\n\nSELECT * FROM crm_configurations WHERE id = 126;\nselect * from accounts where crm_configuration_id = 126 order by id desc;\nselect * from leads where crm_configuration_id = 126 order by id desc;\nselect * from contacts where crm_configuration_id = 126 order by id desc;\nselect * from opportunities where crm_configuration_id = 126 order by id desc;\nselect * from crm_profiles where crm_configuration_id = 126 order by id desc;\nselect * from crm_fields where crm_configuration_id = 126 # 11060\n# and type IN ('picklist', 'status')\n# and object_type = 'task'\norder by id desc;\n# 5731,5732,5733\nselect DISTINCT crm_field_id from crm_field_values where crm_field_id IN (11151,12239,12215,12185,12175,12165,12144,12137,12127,12109,12107,12105,12103,12092,12037,12005,12003,11987,11969,11958,11951,11942,11931,11924,11921,11917,11915,11901,11893,11883,11872,11870,11868,11866,11839,11833,11821,11793,11780,11777,11769,11757,11737,11735,11656,11645,11638,11629,11618,11611,11602,11591,11584,11581,11558,11544,11543,11534,11532,11529,11527,11503,11497,11493,11488,11470,11468,11457,11455,11397,11387,11372,11363,11348,11323,11318,11309,11301,11300,11292,11290,11286,11284,11256,11252,11242,11237,11233,11219,11176,11160) order by id desc;\nselect * from crm_layouts where crm_configuration_id = 126 order by id desc;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id in (300,299,298);\nselect * from stages where crm_configuration_id = 126 order by id desc;\nselect * from business_processes where crm_configuration_id = 126 order by id desc;\nselect * from business_process_stages where business_process_id IN (76,75,74,73);\nselect * from playbooks where team_id = 142;\nselect * from playbook_layouts where playbook_id IN (108);\nSELECT * FROM playbook_categories WHERE playbook_id IN (108);\n\nselect * from teams where id = 130;\nSELECT * FROM social_accounts WHERE sociable_id = 2291;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 2\nand sa.provider = 'hubspot';\n\nSELECT * FROM activities\n WHERE crm_configuration_id = 110;\n\nselect * from teams;\nselect * from crm_configurations;\n\nSELECT * FROM activities WHERE id = 628773;\nSELECT * FROM crm_profiles WHERE user_id = 1460;\nSELECT * FROM social_accounts WHERE sociable_id = 2291;\n\nselect * from teams;\nselect ru.*, pr.*, p.* from users u join role_user ru on ru.user_id = u.id\njoin permission_role pr on pr.role_id = ru.role_id\n join permissions p on p.id = pr.permission_id\nwhere team_id = 495 and p.name IN ('dial');\n\nselect * from teams where id = 145;\nselect * from crm_configurations where id = 129;\nselect * from social_accounts where sociable_id = 2317;\nSELECT * FROM activities WHERE uuid_to_bin('8dbab184-a333-4268-ad57-fb41f8d53a9a') = uuid;\n\nselect * from teams where id = 1;\nSELECT * FROM crm_layouts WHERE crm_configuration_id = 39;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 280;\nSELECT * FROM crm_layout_entities WHERE id = 5507;\nSELECT * FROM crm_fields WHERE crm_configuration_id = 39 and object_type IN ('event');\n\nselect * from teams;\nselect * from activities where crm_configuration_id = 14;\n\nSELECT * FROM social_accounts where provider = 'copper';\n\nselect * from activities where id = 628467;\nselect * from participants where activity_id = 628467;\n\nSELECT * FROM contacts WHERE id = 3969;\nSELECT * FROM accounts WHERE id = 177;\n\nSELECT * FROM activities WHERE uuid_to_bin('4eb54c77-cfa3-2bd4-84a7-9ed46a21c988') = uuid;\n\n# ********************* BH\nselect * from teams where id = 36;\nSELECT * FROM crm_configurations WHERE id = 21;\nselect * from activities where crm_configuration_id = 21 and id = 607901;\nselect * from activities where crm_configuration_id = 21;\n\nselect * roles;\nselect * from permissions;\nselect * from permission_role where permission_id = 226;\n\nselect * from migrations order by id desc;\n\n# mercury\n# neptune\n# earth\n\nselect * from teams;\nselect * from teams where id = 19;\nselect * from teams where id = 27;\nselect * from users where team_id = 27;\nSELECT * FROM crm_configurations WHERE id = 42;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 19\nand sa.provider = 'pipedrive';\n\nselect * from activities where id = 631461;\nSELECT * FROM crm_field_values WHERE crm_field_id = 180;\n\nselect * from teams where id = 2;\nSELECT * FROM social_accounts WHERE sociable_id = 89;\n\nSELECT * FROM activities WHERE uuid_to_bin('ba0c029a-bc14-4e17-8603-64174acebcbb') = uuid; # 634273\nselect * from activity_summary_logs where activity_id = 634273;\n\nselect * from sidekick_settings where team_id = 2;\n\nselect * from teams; # 2, 2\nSELECT * FROM crm_configurations WHERE team_id = 2; # 2\nselect * from team_features where team_id = 2;\nselect * from features;\nSELECT * FROM opportunities WHERE crm_configuration_id = 2 and crm_provider_id = '51317301383';\nSELECT * FROM opportunities WHERE crm_configuration_id = 2 order by id desc;\n\nselect * from automated_reports order by id desc;\nselect * from automated_report_results order by id desc;\nselect * from users where team_id = 1 and id IN (7160, 3248);\nselect * from migrations order by id desc;\n\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 1 and sa.provider = 'salesforce';\n\nselect * from teams where id = 1;\nselect * from groups g JOIN playbooks p on g.playbook_id = p.id where g.team_id = 1;\nselect * from groups where id = 565;\nselect * from playbooks where team_id = 1;\nselect * from playbooks where id = 175;\nselect * from playbook_categories where playbook_id = 175;\nselect * from users where team_id = 1;\nselect * from users where id = 7160;\nselect * from crm_profiles where user_id = 7160;\nselect * from features;\nselect\n *\n# id, uuid, type, provider, playbook_category_id, user_id, lead_id, contact_id, account_id, opportunity_id, stage_id,\n# crm_configuration_id, crm_provider_id, transcription_id, status\nfrom activities where crm_configuration_id = 1 and type = 'conference'\n# and crm_provider_id IS NOT NULL\nand provider != 'uploader' and actual_start_time IS NOT NULL\nORDER by id desc;\nselect * from activities where id = 54747783; # 00UO400000pCzojMAC\n\nselect p.id, p.activity_type, pc.id, pc.name\nFROM playbooks p\njoin playbook_categories pc on p.id = pc.playbook_id\nwhere p.team_id = 1 and p.activity_type = 'event';\n\nSELECT * FROM crm_fields WHERE crm_configuration_id = 1 and object_type = 'event';\nSELECT * FROM crm_field_values WHERE crm_field_id = 4;\n\nselect * from crm_layouts cl join playbook_layouts pl on cl.id = pl.layout_id\nwhere crm_configuration_id = 1 and pl.playbook_id = 175;\n\nselect * from teams;\nSELECT r.* FROM automated_reports r\njoin teams t on r.team_id = t.id\nWHERE r.frequency = 'daily'\n and r.status = 1\nAND t.status = 'active'\nAND (r.expires_at >= now() OR r.expires_at IS NULL);\n\nselect * from automated_report_results where report_id IN (18, 33);\n\nselect * from activity_searches where id = 10932;\nselect * from activity_search_filters where activity_search_id = 10932;\nselect * from automated_reports;\nselect * from automated_report_results where report_id IN (34, 35);","role_description":"text entry area","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.088194445,"height":0.027777778},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"102","depth":4,"role_description":"text"},{"role":"AXStaticText","text":"3","depth":4,"role_description":"text"},{"role":"AXStaticText","text":"34","depth":4,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Services\\Kiosk\\AutomatedReports;\n\nuse Carbon\\CarbonImmutable;\nuse Carbon\\CarbonInterface;\nuse Carbon\\Exceptions\\InvalidFormatException;\nuse DateTime;\nuse DateTimeInterface;\nuse DateTimeZone;\nuse Illuminate\\Contracts\\Bus\\Dispatcher as BusDispatcher;\nuse Illuminate\\Database\\Eloquent\\Builder;\nuse Illuminate\\Support\\Carbon;\nuse Illuminate\\Support\\Collection;\nuse Illuminate\\Support\\Facades\\Log;\nuse Illuminate\\Support\\Facades\\Storage;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinition\\InputTypeEnum;\nuse Jiminny\\Component\\AskAnything\\AskAnythingPromptService;\nuse Jiminny\\Component\\AskAnything\\Dtos\\AskAnythingPromptDto;\nuse Jiminny\\Component\\UrlGenerator\\Webhook;\nuse Jiminny\\Contracts\\Repositories\\PlaybookCategoryRepository;\nuse Jiminny\\Contracts\\Repositories\\TeamRepository;\nuse Jiminny\\Contracts\\Repositories\\UserRepository;\nuse Jiminny\\Exceptions\\ApplicationException;\nuse Jiminny\\Exceptions\\InvalidArgumentException;\nuse Jiminny\\Exceptions\\ModelNotFoundException;\nuse Jiminny\\Jobs\\AutomatedReports\\RequestGenerateReportJob;\nuse Jiminny\\Models\\Activity\\Search;\nuse Jiminny\\Models\\AskAnything\\AskAnythingPrompt;\nuse Jiminny\\Models\\AskAnything\\AskAnythingPromptTarget;\nuse Jiminny\\Models\\AutomatedReport;\nuse Jiminny\\Models\\AutomatedReportResult;\nuse Jiminny\\Models\\Contracts\\UserContract;\nuse Jiminny\\Models\\Feature\\FeatureEnum;\nuse Jiminny\\Models\\Team;\nuse Jiminny\\Models\\User;\nuse Jiminny\\Repositories\\AskAnythingRepository;\nuse Jiminny\\Repositories\\AutomatedReportsRepository;\nuse Jiminny\\Repositories\\GroupRepository;\nuse Jiminny\\Repositories\\SearchRepository;\nuse Jiminny\\Repositories\\StageRepository;\nuse Throwable;\n\nclass AutomatedReportsService\n{\n public const string TYPE_LOSS_ANALYSIS = 'loss_analysis';\n public const string TYPE_ASK_JIMINNY = 'ask_jiminny';\n\n /**\n * Standard report types (used by kiosk for existing automated reports).\n */\n // @TODO this will add filter, however if we need to control feature by FF we need conditional logic\n public const array TYPES = [\n ['id' => 'exec_summary', 'name' => 'Exec Summary'],\n ['id' => 'coaching_profiles', 'name' => 'Coaching Profiles'],\n ['id' => 'product_feedback', 'name' => 'Product Feedback'],\n ['id' => self::TYPE_LOSS_ANALYSIS, 'name' => 'Loss Analysis'],\n// ['id' => 'questions', 'name' => 'Questions'],\n// ['id' => 'statistical_quant', 'name' => 'Statistical Quantitative'],\n ];\n\n public const array ALL_TYPES = [\n ...self::TYPES,\n ['id' => self::TYPE_ASK_JIMINNY, 'name' => 'Ask Jiminny'],\n ];\n\n public const string FREQUENCY_DAILY = 'daily';\n public const string FREQUENCY_WEEKLY = 'weekly';\n public const string FREQUENCY_MONTHLY = 'monthly';\n public const string FREQUENCY_QUARTERLY = 'quarterly';\n public const string FREQUENCY_ONE_OFF = 'one_off';\n\n /**\n * Frequencies for standard (non-Ask Jiminny) reports.\n */\n public const array FREQUENCIES = [\n ['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],\n ['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],\n ['id' => self::FREQUENCY_QUARTERLY, 'name' => 'Quarterly'],\n ['id' => self::FREQUENCY_ONE_OFF, 'name' => 'One-off'],\n ];\n\n /**\n * Frequencies for Ask Jiminny reports.\n */\n public const array ASK_JIMINNY_FREQUENCIES = [\n ['id' => self::FREQUENCY_DAILY, 'name' => 'Daily'],\n ['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],\n ['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],\n ];\n\n public const string MEDIA_TYPE_PDF = 'pdf';\n public const string MEDIA_TYPE_PODCAST = 'podcast';\n public const array MEDIA_TYPES = [self::MEDIA_TYPE_PDF, self::MEDIA_TYPE_PODCAST];\n public const array MEDIA_TYPE_OBJECT_PDF = ['id' => self::MEDIA_TYPE_PDF, 'name' => 'PDF'];\n public const array MEDIA_TYPE_OBJECT_PODCAST = ['id' => self::MEDIA_TYPE_PODCAST, 'name' => 'Podcast'];\n public const array MEDIA_TYPE_OBJECTS = [self::MEDIA_TYPE_OBJECT_PDF, self::MEDIA_TYPE_OBJECT_PODCAST];\n\n public const array CALL_TYPE_CONFERENCE = ['id' => 'conference', 'name' => 'Conference'];\n public const array CALL_TYPE_DIALER = ['id' => 'dialer', 'name' => 'Dialer'];\n public const int SENT_REPORT_AT_HOURS = 5;\n public const string PDF_KEY = 'pdf';\n public const string AUDIO_KEY = 'audio';\n\n private const array ALL_FREQUENCIES = [\n ['id' => self::FREQUENCY_DAILY, 'name' => 'Daily'],\n ['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],\n ['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],\n ['id' => self::FREQUENCY_QUARTERLY, 'name' => 'Quarterly'],\n ['id' => self::FREQUENCY_ONE_OFF, 'name' => 'One-off'],\n ];\n private const string S3_DIR = 'reports';\n private const array FILE_EXTENSIONS_VARIANTS = ['html', 'MD', 'pdf'];\n private const array FILE_PODCAST_EXTENSIONS_VARIANTS = ['json', 'mp3', 'ssml'];\n\n public function __construct(\n private readonly TeamRepository $teamRepository,\n private readonly GroupRepository $groupRepository,\n private readonly UserRepository $userRepository,\n private readonly StageRepository $stageRepository,\n private readonly DealStagesService $dealStagesService,\n private readonly RecipientsService $recipientsService,\n private readonly AutomatedReportsRepository $automatedReportsRepository,\n private readonly Webhook $webhookService,\n private readonly BusDispatcher $dispatcher,\n private readonly ActivityTypeService $activityTypeService,\n private readonly PlaybookCategoryRepository $playbookCategoryRepository,\n private readonly AskAnythingPromptService $askAnythingPromptService,\n private readonly SearchRepository $activitySearchRepository,\n private readonly AskAnythingRepository $askAnythingRepository,\n ) {\n }\n\n public static function getTypes(): array\n {\n $types = self::TYPES;\n\n return array_map(static function ($type) {\n return $type['id'];\n }, $types);\n }\n\n public static function getCallTypes(): array\n {\n return array_map(static function ($callType) {\n return $callType['id'];\n }, [self::CALL_TYPE_CONFERENCE, self::CALL_TYPE_DIALER]);\n }\n\n public static function getFrequencies(): array\n {\n return array_map(static function ($frequency) {\n return $frequency['id'];\n }, self::FREQUENCIES);\n }\n\n // front-facing structure\n public function getReportEnabledFieldData(bool $value = false): array\n {\n return [\n 'id' => 'report_enabled',\n 'label' => '',\n 'inputType' => InputTypeEnum::TOGGLE,\n 'value' => $value,\n ];\n }\n\n // Organizations = Teams\n public function getOrganizationFieldData(?string $value = null, bool $shortVersion = false): array\n {\n $options = $this->getTeams();\n\n if ($shortVersion) {\n return [\n 'id' => 'organization',\n 'label' => 'Organization',\n 'options' => $options,\n ];\n }\n\n return [\n 'id' => 'organization',\n 'label' => 'Organization',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => $options,\n 'value' => $value,\n 'dependencies' => [\n 'teams',\n 'deal_stage_at_call',\n 'current_deal_stage',\n 'recipients',\n ActivityTypeService::PLAYBOOK_CATEGORIES_KEY,\n ],\n 'dependsOn' => [],\n ];\n }\n\n // Teams = Groups\n public function getTeamFieldData(array $options = [], array $value = [], bool $shortVersion = false): array\n {\n if ($shortVersion) {\n return [\n 'id' => 'teams',\n 'label' => 'Team',\n 'options' => $options,\n ];\n }\n\n return [\n 'id' => 'teams',\n 'label' => 'Team',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'required' => false,\n 'placeholder' => 'Select',\n 'options' => $options,\n 'value' => $value, // value should be an array of objects {id, name}\n 'dependencies' => [ActivityTypeService::PLAYBOOK_CATEGORIES_KEY],\n 'dependsOn' => [],\n ];\n }\n\n public function getReportTypeFieldData(?string $value = null, bool $shortVersion = false, ?Team $team = null): array\n {\n $types = [];\n if ($team instanceof Team) {\n if ($team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {\n $types = self::TYPES;\n }\n if ($team->hasFeature(FeatureEnum::ASK_JIMINNY_REPORTS)) {\n $types[] = ['id' => self::TYPE_ASK_JIMINNY, 'name' => 'Ask Jiminny'];\n }\n } else {\n $types = self::TYPES;\n }\n\n if ($shortVersion) {\n return [\n 'id' => 'report_type',\n 'label' => 'Report Type',\n 'options' => $types,\n ];\n }\n\n return [\n 'id' => 'report_type',\n 'label' => 'Report Type',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => $types,\n 'value' => $value,\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getFrequencyFieldData(?string $value = null): array\n {\n return [\n 'id' => 'frequency',\n 'label' => 'Frequency',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => self::FREQUENCIES,\n 'value' => $value,\n 'dependencies' => ['period'],\n 'dependsOn' => [],\n ];\n }\n\n public function getPeriodFieldData(?string $valueStartDate = null, ?string $valueEndDate = null): array\n {\n return [\n 'id' => 'period',\n 'label' => 'Select one-off period',\n 'inputType' => InputTypeEnum::DATE_RANGE,\n 'required' => true,\n 'placeholder' => 'Select',\n 'value' => ['startDate' => $valueStartDate, 'endDate' => $valueEndDate],\n 'queryParams' => [\n 'startDate' => 'start_date_period',\n 'endDate' => 'end_date_period',\n ],\n 'dependencies' => [],\n 'dependsOn' => ['frequency'],\n ];\n }\n\n public function getActivityTypesFieldData(?Team $team = null, array $value = [], array $teamsFilter = []): array\n {\n return $this->activityTypeService->getActivityTypeFieldData(team: $team, value: $value, groupIds: $teamsFilter);\n }\n\n public function getDealStageAtCallFieldData(?Team $team = null, array $value = []): array\n {\n return $this->dealStagesService->getDealStageAtCallFieldData(team: $team, value: $value);\n }\n\n public function getCurrentDealStageFieldData(?Team $team = null, array $value = []): array\n {\n return $this->dealStagesService->getCurrentDealStageFieldData(team: $team, value: $value);\n }\n\n public function getDealValueFieldData(?int $valueMin = null, ?int $valueMax = null): array\n {\n return [\n 'id' => 'deal_value',\n 'label' => 'Deal Value',\n 'inputType' => InputTypeEnum::INTEGER_RANGE,\n 'required' => false,\n 'value' => ['min' => $valueMin, 'max' => $valueMax],\n 'queryParams' => [\n 'min' => 'min_deal_value',\n 'max' => 'max_deal_value',\n ],\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getCallTypeFieldData(bool $conferenceOn = false, bool $dialerOn = false): array\n {\n $value = [];\n $conferenceOn && $value[] = self::CALL_TYPE_CONFERENCE;\n $dialerOn && $value[] = self::CALL_TYPE_DIALER;\n\n return [\n 'id' => 'call_type',\n 'label' => 'Call Type',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'required' => true,\n 'options' => [\n self::CALL_TYPE_CONFERENCE,\n self::CALL_TYPE_DIALER,\n ],\n 'value' => $value,\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getMediaTypeFieldData(?AutomatedReport $report = null): array\n {\n $value = [];\n\n if ($report) {\n $value = $this->transformMediaTypes($report);\n }\n\n return [\n 'id' => 'media_types',\n 'label' => 'Export as',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'required' => true,\n 'options' => self::MEDIA_TYPE_OBJECTS,\n 'value' => $value,\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getCallDurationFieldData(?int $valueMin = null, ?int $valueMax = null): array\n {\n return [\n 'id' => 'call_duration',\n 'label' => 'Call Duration',\n 'inputType' => InputTypeEnum::INTEGER_RANGE,\n 'required' => false,\n 'value' => ['min' => $valueMin, 'max' => $valueMax],\n 'queryParams' => [\n 'min' => 'min_call_duration',\n 'max' => 'max_call_duration',\n ],\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getRecipientsFieldData(?Team $team = null, array $value = []): array\n {\n return $this->recipientsService->getRecipientsFieldData(team: $team, value: $value);\n }\n\n public function getJiminnyRecipientsFieldData(array $value = []): array\n {\n return $this->recipientsService->getJiminnyRecipientsFieldData($value);\n }\n\n public function getAdditionalPromptInputFieldData(?string $value = null): array\n {\n return [\n 'id' => 'additional_prompt_input',\n 'label' => 'Special requirements',\n 'inputType' => InputTypeEnum::TEXTAREA,\n 'required' => false,\n 'placeholder' => 'What should be the focus of the report?',\n 'value' => $value,\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getCustomReportNameFieldData(?string $value = null): array\n {\n return [\n 'id' => 'custom_name',\n 'label' => 'Custom report name',\n 'inputType' => InputTypeEnum::TEXT,\n 'required' => false,\n 'placeholder' => 'Enter custom name',\n 'value' => $value,\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n // data providers\n public function getTeams(): array\n {\n $teams = $this->teamRepository->getTeamsForKiosk(status: Team::STATUS_ACTIVE);\n\n $teamData = [];\n foreach ($teams as $team) {\n if (! $team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {\n continue;\n }\n\n $teamData[] = $this->transformTeam($team);\n }\n\n return $teamData;\n }\n\n public function getTeamGroups(string $teamUuid): array\n {\n $data = [];\n $team = $this->getTeam($teamUuid);\n\n if ($team !== null) {\n $groups = $team->groups()->get();\n\n foreach ($groups as $group) {\n $data[] = [\n 'id' => $group->getUuid(),\n 'name' => $group->getName(),\n ];\n }\n }\n\n return $data;\n }\n\n public function getTeamsGroupsOptions(array $filterTeamUuids = []): array\n {\n $data = [];\n $teams = $this->getTeams();\n\n foreach ($teams as $team) {\n if (! empty($filterTeamUuids) && ! in_array($team['id'], $filterTeamUuids, true)) {\n continue;\n }\n\n $data[] = [\n 'label' => $team['name'],\n 'groups' => $this->getTeamGroups($team['id']),\n ];\n }\n\n return $data;\n }\n\n public function getTeam(string $teamUuid): ?Team\n {\n return $this->teamRepository->idOrUuid($teamUuid);\n }\n\n public function getTeamById(int $teamId): ?Team\n {\n return $this->teamRepository->find($teamId);\n }\n\n public function getGroupsUuids(AutomatedReport $report): array\n {\n $uuids = [];\n $reportGroups = $report->getGroups();\n foreach ($reportGroups as $groupId) {\n if ($group = $this->groupRepository->find($groupId)) {\n $uuids[] = $group->getUuid();\n }\n }\n\n return $uuids;\n }\n\n public function getPlaybookCategoriesUuids(AutomatedReport $report): array\n {\n $uuids = [];\n $playbookCategories = $report->getPlaybookCategories();\n foreach ($playbookCategories as $id) {\n if ($category = $this->playbookCategoryRepository->find($id)) {\n $uuids[] = $category->getUuid();\n }\n }\n\n return $uuids;\n }\n\n public function getDealAtCallStagesUuids(AutomatedReport $report): array\n {\n $uuids = [];\n $reportStages = $report->getDealAtCallStages();\n foreach ($reportStages as $id) {\n if ($stage = $this->stageRepository->find($id)) {\n $uuids[] = $stage->getUuid();\n }\n }\n\n return $uuids;\n }\n\n public function getCurrentDealStagesUuids(AutomatedReport $report): array\n {\n $uuids = [];\n $reportStages = $report->getCurrentDealStages();\n foreach ($reportStages as $id) {\n if ($stage = $this->stageRepository->find($id)) {\n $uuids[] = $stage->getUuid();\n }\n }\n\n return $uuids;\n }\n\n public function getUsersUuids(AutomatedReport $report): array\n {\n return $this->extractUserUuids($report->getRecipients());\n }\n\n public function getJiminnyUsersUuids(AutomatedReport $report): array\n {\n return $this->extractUserUuids($report->getJiminnyRecipients());\n }\n\n /**\n * @param array<string, mixed> $recipients\n */\n private function extractUserUuids(array $recipients): array\n {\n $userIds = $recipients['users'] ?? [];\n\n return collect($userIds)\n ->map(fn ($id) => $this->userRepository->find((int) $id))\n ->filter()\n ->map(fn (UserContract $user) => $user->getUuid())\n ->values()\n ->all();\n }\n\n // get mail data\n public function getRecipientUsers(AutomatedReport $report): array\n {\n return $this->buildRecipientUsers($report->getRecipients());\n }\n\n private function getJiminnyRecipientUsers(AutomatedReport $report): array\n {\n return $this->buildRecipientUsers($report->getJiminnyRecipients());\n }\n\n /**\n * @param array<string, mixed> $recipients\n */\n private function buildRecipientUsers(array $recipients): array\n {\n $userIds = $recipients['users'] ?? [];\n\n return collect($userIds)\n ->map(fn ($id) => $this->userRepository->find((int) $id))\n ->filter()\n ->map(fn (UserContract $user) => [\n 'email' => $user->getEmailAddress(),\n 'name' => $user->getName(),\n 'timezone' => $user->getTimezone()->getName(),\n ])\n ->values()\n ->all();\n }\n\n public function getValidRecipientUsers(AutomatedReport $report, bool $includeJiminny = false): array\n {\n if ($report->isAskJiminnyReport()) {\n $recipients = $this->resolveAskJiminnyRecipients($report);\n } else {\n $recipients = $this->getRecipientUsers($report);\n if ($includeJiminny) {\n $recipients = array_merge($recipients, $this->getJiminnyRecipientUsers($report));\n }\n }\n\n $emails = [];\n\n return array_values(array_filter(\n $recipients,\n static function ($recipient) use (&$emails) {\n if (empty($recipient['email']) || in_array($recipient['email'], $emails, true)) {\n return false;\n }\n $emails[] = $recipient['email'];\n\n return true;\n }\n ));\n }\n\n private function resolveAskJiminnyRecipients(AutomatedReport $report): array\n {\n $recipients = [];\n\n $creator = $report->getCreator();\n if ($creator !== null) {\n $recipients[] = [\n 'email' => $creator->getEmailAddress(),\n 'name' => $creator->getName(),\n 'timezone' => $creator->getTimezone()->getName(),\n ];\n }\n\n return array_merge(\n $recipients,\n $this->buildRecipientUsers($report->getRecipients()),\n $this->getGroupRecipientUsers($report),\n );\n }\n\n private function getGroupRecipientUsers(AutomatedReport $report): array\n {\n $users = [];\n foreach ($report->getGroups() as $groupId) {\n $group = $this->groupRepository->find($groupId);\n if ($group === null) {\n continue;\n }\n foreach ($group->getMembers() as $member) {\n $users[] = [\n 'email' => $member->getEmailAddress(),\n 'name' => $member->getName(),\n 'timezone' => $member->getTimezone()->getName(),\n ];\n }\n }\n\n return $users;\n }\n\n public function getReportTypeName(AutomatedReportResult $report): string\n {\n $type = $report->getReport()->getType();\n\n $getType = $this->transformReportType($type);\n\n return $getType['name'];\n }\n\n public function getReportPeriodName(AutomatedReportResult $report): string\n {\n $from = $report->getFromDate();\n $to = $report->getToDate();\n $frequency = $report->getReport()->getFrequency();\n\n if ($from === null || $to === null) {\n if (! $report->getReport()->isAskJiminnyReport()) {\n $invalidPeriod = $from === null ? 'from' : 'to';\n\n throw new ApplicationException('Report period is invalid: ' . $invalidPeriod);\n }\n\n $period = $this->calculateFromAndToDatePeriod($frequency);\n $from = $period['fromDate'];\n $to = $period['toDate'];\n }\n\n return $this->formatReportPeriodName($frequency, $from, $to);\n }\n\n private function formatReportPeriodName(string $frequency, Carbon $from, Carbon $to): string\n {\n $fromYear = $from->format('Y');\n $toYear = $to->format('Y');\n $differentYears = $fromYear !== $toYear;\n\n switch ($frequency) {\n case self::FREQUENCY_DAILY:\n return $from->format('j M Y');\n\n case self::FREQUENCY_QUARTERLY:\n // 'Jan-Mar 2025' or 'Nov 2024-Jan 2025' if years differ\n $startMonth = $from->format('M');\n $endMonth = $to->copy()->subMonth();\n $endMonthName = $endMonth->format('M');\n $endMonthYear = $endMonth->format('Y');\n\n if ($differentYears) {\n return \"{$startMonth} {$fromYear} - {$endMonthName} {$endMonthYear}\";\n }\n\n return \"{$startMonth} - {$endMonthName} {$toYear}\";\n\n case self::FREQUENCY_MONTHLY:\n // 'May 2025' - monthly reports are always within the same year\n return $from->format('M Y');\n\n case self::FREQUENCY_WEEKLY:\n // '4 - 8 Aug 2025', '27 Oct - 3 Nov 2025', or '28 Dec 2024 - 3 Jan 2025' if years differ\n $startDay = $from->format('j');\n $endDay = $to->format('j');\n $startMonth = $from->format('M');\n $endMonth = $to->format('M');\n\n if ($differentYears) {\n return \"{$startDay} {$startMonth} {$fromYear} - {$endDay} {$endMonth} {$toYear}\";\n }\n\n if ($startMonth !== $endMonth) {\n return \"{$startDay} {$startMonth} - {$endDay} {$endMonth} {$toYear}\";\n }\n\n return \"{$startDay} - {$endDay} {$endMonth} {$toYear}\";\n\n case self::FREQUENCY_ONE_OFF:\n // '2 May-31 May 2025' or '15 Dec 2024-15 Jan 2025' if years differ\n $startDay = $from->format('j');\n $startMonth = $from->format('M');\n $endDay = $to->format('j');\n $endMonth = $to->format('M');\n\n // If same month and year, use a format like '2-31 May 2025'\n if ($startMonth === $endMonth && ! $differentYears) {\n return \"{$startDay} - {$endDay} {$startMonth} {$toYear}\";\n }\n\n // If different years, include both years\n if ($differentYears) {\n return \"{$startDay} {$startMonth} {$fromYear} - {$endDay} {$endMonth} {$toYear}\";\n }\n\n // Same year but different months\n return \"{$startDay} {$startMonth} - {$endDay} {$endMonth} {$toYear}\";\n\n default:\n // Default format for unknown frequencies\n return $from->format('j M Y') . ' - ' . $to->format('j M Y');\n }\n }\n\n public function getReportTeamsName(AutomatedReportResult $report): string\n {\n $groups = $report->getGroups();\n\n if (empty($groups)) {\n return 'All';\n }\n\n // Get group names from repository\n $groupNames = [];\n foreach ($groups as $groupId) {\n $group = $this->groupRepository->find($groupId);\n if ($group) {\n $groupNames[] = $group->getName();\n }\n }\n\n if (count($groupNames) === 1) {\n // Single team format\n $teamsName = $groupNames[0];\n } else {\n // Multiple teams format\n $teamsName = implode(', ', $groupNames);\n }\n\n return $teamsName;\n }\n\n public function getReportFileName(AutomatedReportResult $report): string\n {\n $customName = $report->getReport()->getCustomName();\n $periodName = $this->getReportPeriodName($report);\n $filenameSuffix = $this->getFilenameSuffix($report);\n\n if ($customName) {\n if ($filenameSuffix) {\n $customName .= \" {$filenameSuffix}\";\n }\n\n return $this->sanitizeFileName(\"{$customName} - {$periodName}\");\n }\n\n $baseName = $this->getReportTypeName($report);\n\n if ($filenameSuffix) {\n $baseName .= \" {$filenameSuffix}\";\n }\n\n return $this->sanitizeFileName(\"{$baseName} - {$periodName} - {$this->getReportTeamsName($report)}\");\n }\n\n public function getReportFileNameWithExtension(AutomatedReportResult $result): string\n {\n $extension = $this->getMediaTypeMetadata($result)['extension'];\n\n return $this->getReportFileName($result) . '.' . $extension;\n }\n\n public function sanitizeFileName(string $fileName): string\n {\n return str_replace(['/', '\\\\'], '-', $fileName);\n }\n\n public function isUserRecipientOfReport(User $user, AutomatedReport $report): bool\n {\n $recipients = array_map('intval', $report->getRecipients()['users'] ?? []);\n\n return in_array($user->getId(), $recipients);\n }\n\n public function transformReportResults(Collection $automatedReportResults): array\n {\n $data = [];\n foreach ($automatedReportResults as $automatedReportResult) {\n /** @var AutomatedReportResult $automatedReportResult */\n\n $report = $automatedReportResult->getReport();\n\n $createdBy = $report->getCreator();\n $creator = [\n 'id' => $createdBy?->getUuid(),\n 'name' => $createdBy?->getName(),\n 'email' => $createdBy?->getEmailAddress(),\n 'photoUrl' => $createdBy?->getPhotoUrl(),\n ];\n\n $data[] = [\n 'id' => $automatedReportResult->getUuid(),\n 'name' => $automatedReportResult->getName(),\n 'frequency' => $this->transformFrequency($report->getFrequency()),\n 'recipients' => [\n ...array_values($this->transformGroups(team: $report->getTeam(), groupsIds: $report->getGroups())),\n ...array_values($this->transformRecipients($report->getRecipients())),\n ],\n 'report_type' => $this->transformReportType($report->getType()),\n 'media_type' => $automatedReportResult->getMediaType(),\n 'downloadUrl' => $this->generateReportResultDownloadUrl($automatedReportResult),\n 'viewUrl' => $this->generateReportResultViewUrl($automatedReportResult),\n 'generated_at' => $automatedReportResult->getGeneratedAt()?->toIso8601String(),\n 'creator' => $creator,\n ];\n }\n\n return $data;\n }\n\n public function hasCallTypeConference(AutomatedReport $report): bool\n {\n return in_array(self::CALL_TYPE_CONFERENCE['id'], $report->getCallTypes(), true);\n }\n\n public function hasCallTypeDialer(AutomatedReport $report): bool\n {\n return in_array(self::CALL_TYPE_DIALER['id'], $report->getCallTypes(), true);\n }\n\n // transformers\n private function transformTeam(Team $team): array\n {\n if (! $team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {\n return [];\n }\n\n return [\n 'id' => $team->getUuid(),\n 'name' => $team->getName(),\n ];\n }\n\n private function transformReportFullView(AutomatedReport $report): array\n {\n $base = $this->transformReportBase($report);\n\n return $report->getType() === self::TYPE_ASK_JIMINNY\n ? $base + $this->transformAskJiminnyFields($report)\n : $base + $this->transformStandardReportFields($report);\n }\n\n private function transformReportBase(AutomatedReport $report): array\n {\n return [\n 'id' => $report->getUuid(),\n 'organization' => $this->transformOrganization(team: $report->getTeam()),\n 'report_type' => $this->transformReportType($report->getType()),\n 'frequency' => $this->transformFrequency($report->getFrequency()),\n ];\n }\n\n private function transformStandardReportFields(AutomatedReport $report): array\n {\n $team = $report->getTeam();\n\n return [\n 'report_enabled' => $report->getStatus(),\n 'start_date_period' => $report->getFrom()?->format('Y-m-d H:i:s'),\n 'end_date_period' => $report->getTo()?->format('Y-m-d H:i:s'),\n 'deal_value_min' => $report->getDealValueMin(),\n 'deal_value_max' => $report->getDealValueMax(),\n 'call_types' => $this->transformCallType($report->getCallTypes()),\n 'media_types' => $this->transformMediaTypes($report),\n 'call_duration_min' => $this->transformDurationToMinutes($report->getCallDurationMin()),\n 'call_duration_max' => $this->transformDurationToMinutes($report->getCallDurationMax()),\n 'teams' => $this->transformGroups(team: $team, groupsIds: $report->getGroups()),\n 'deal_at_call_stages' => $this->transformStages(team: $team, stagesIds: $report->getDealAtCallStages()),\n 'current_deal_stages' => $this->transformStages(team: $team, stagesIds: $report->getCurrentDealStages()),\n 'recipients' => $this->transformRecipients($report->getRecipients()),\n 'created_by' => $this->transformCreator($report->getCreator()),\n 'additional_prompt_input' => $report->getAdditionalPromptInput(),\n 'custom_name' => $report->getCustomName(),\n 'created_at' => $report->getCreatedAt()->format('Y-m-d H:i:s'),\n 'updated_at' => $report->getUpdatedAt()->format('Y-m-d H:i:s'),\n 'deleted_at' => $report->getDeletedAt()?->format('Y-m-d H:i:s'),\n ];\n }\n\n private function transformAskJiminnyFields(AutomatedReport $report): array\n {\n $team = $report->getTeam();\n $creatorId = $report->getAttribute('created_by');\n $explicitUserIds = array_values(array_filter(\n $report->getRecipients()['users'] ?? [],\n static fn ($id) => $id !== $creatorId\n ));\n\n return [\n 'report_name' => $report->getCustomName(),\n 'enabled' => $report->getStatus(),\n 'share_teams' => $this->transformGroups(team: $team, groupsIds: $report->getGroups()),\n 'share_users' => $this->transformRecipients(['users' => $explicitUserIds]),\n 'saved_search' => $this->transformSafeSearch($report->getSavedSearch()),\n 'ask_jiminny_prompt' => $this->transformAskJiminnyPrompt($report->getAskAnythingPrompt()),\n 'expires_on' => $report->getExpiresAt()?->format('Y-m-d'),\n ];\n }\n\n private function transformOrganization(?Team $team): array\n {\n return [\n 'id' => $team?->getUuid(),\n 'name' => $team?->getName(),\n ];\n }\n\n private function transformReportType(string $type): array\n {\n foreach (self::ALL_TYPES as $typeItem) {\n if ($typeItem['id'] === $type) {\n return $typeItem;\n }\n }\n\n return [];\n }\n\n private function transformCallType(array $types): array\n {\n $result = [];\n $callTypes = [self::CALL_TYPE_CONFERENCE, self::CALL_TYPE_DIALER];\n\n foreach ($types as $type) {\n foreach ($callTypes as $callTypeItem) {\n if ($callTypeItem['id'] === $type) {\n $result[] = $callTypeItem;\n\n break;\n }\n }\n }\n\n return $result;\n }\n\n private function transformMediaTypes(AutomatedReport $report): array\n {\n $values = [];\n\n foreach ($report->getMediaTypes() as $mediaType) {\n if (! in_array($mediaType, self::MEDIA_TYPES, true)) {\n continue;\n }\n\n $values[] = match ($mediaType) {\n self::MEDIA_TYPE_PDF => self::MEDIA_TYPE_OBJECT_PDF,\n self::MEDIA_TYPE_PODCAST => self::MEDIA_TYPE_OBJECT_PODCAST,\n };\n }\n\n return $values;\n }\n\n private function transformFrequency(string $frequency): array\n {\n foreach (self::ALL_FREQUENCIES as $frequencyItem) {\n if ($frequencyItem['id'] === $frequency) {\n return $frequencyItem;\n }\n }\n\n return [];\n }\n\n public function transformDurationToMinutes(?int $duration): ?int\n {\n if (! $duration) {\n return null;\n }\n\n return (int) ($duration / 60);\n }\n\n private function transformGroups(?Team $team, array $groupsIds): array\n {\n if (empty($groupsIds) || ! $team) {\n return [];\n }\n\n $data = [];\n foreach ($groupsIds as $groupId) {\n $group = $team->groups()->where('id', $groupId)->first();\n\n if ($group) {\n $data[] = [\n 'id' => $group->getUuid(),\n 'name' => $group->getName(),\n 'photoUrl' => $group->getPhotoUrl(),\n ];\n }\n }\n\n return $data;\n }\n\n private function transformStages(?Team $team, array $stagesIds): array\n {\n if (empty($stagesIds) || ! $team) {\n return [];\n }\n\n $data = [];\n foreach ($stagesIds as $stageId) {\n $stage = $team->stages()->where('id', $stageId)->first();\n\n if ($stage) {\n $data[] = [\n 'id' => $stage->getUuid(),\n 'name' => $stage->getName(),\n ];\n }\n }\n\n return $data;\n }\n\n private function transformRecipients(array $recipients): array\n {\n $users = [];\n foreach ($recipients['users'] ?? [] as $userId) {\n $users[] = $this->transformUser($userId);\n }\n\n return $users;\n }\n\n private function transformCreator(?User $user): ?array\n {\n if ($user === null) {\n return null;\n }\n\n return $this->transformUser($user->getId());\n }\n\n private function transformAskJiminnyPrompt(?AskAnythingPrompt $prompt): ?array\n {\n if ($prompt === null) {\n return null;\n }\n\n return [\n 'id' => $prompt->getUuid(),\n 'name' => $prompt->getTitle(),\n ];\n }\n\n private function transformSafeSearch(?Search $search): ?array\n {\n if ($search === null) {\n return null;\n }\n\n return [\n 'id' => $search->getUuid(),\n 'name' => $search->getName(),\n ];\n }\n\n private function transformUser(int $userId): array\n {\n /* @var ?User $user */\n $user = $this->userRepository->find($userId);\n\n return [\n 'id' => $user?->getUuid(),\n 'name' => $user?->getName(),\n 'email' => $user?->getEmailAddress(),\n 'photoUrl' => $user?->getPhotoUrl(),\n ];\n }\n\n public function create(array $data): array\n {\n $validatedData = $this->validateAndTransformData($data);\n $validatedData['created_by'] = auth()->id();\n\n $automatedReport = $this->automatedReportsRepository->create($validatedData);\n\n $this->generateOneOffReport($automatedReport);\n\n return $this->transformReportFullView($automatedReport);\n }\n\n public function update(string $uuid, array $data): array\n {\n $validatedData = $this->validateAndTransformData($data);\n $report = $this->automatedReportsRepository->findByUuid($uuid);\n\n if (! $report) {\n throw new InvalidArgumentException('Report not found');\n }\n\n $oldCustomName = $report->getCustomName();\n\n $automatedReport = $this->automatedReportsRepository->update($report, $validatedData);\n\n if ($oldCustomName !== $automatedReport->getCustomName()) {\n $this->updateResultNames($automatedReport);\n }\n\n $this->generateOneOffReport($automatedReport);\n\n return $this->transformReportFullView($automatedReport);\n }\n\n /**\n * Create an Ask Jiminny report.\n */\n public function createAskJiminnyReport(array $data, User $creator): array\n {\n $validatedData = $this->validateAskJiminnyReportData($data, $creator);\n $validatedData['created_by'] = $creator->getId();\n\n $automatedReport = $this->automatedReportsRepository->create($validatedData);\n\n return $this->transformReportFullView($automatedReport);\n }\n\n /**\n * Update an Ask Jiminny report.\n */\n public function updateAskJiminnyReport(AutomatedReport $report, array $data, User $user): array\n {\n if (! $report->isAskJiminnyReport()) {\n throw new InvalidArgumentException('Report is not an Ask Jiminny report');\n }\n\n $validatedData = $this->validateAskJiminnyReportData($data, $user);\n\n $oldCustomName = $report->getCustomName();\n\n $automatedReport = $this->automatedReportsRepository->update($report, $validatedData);\n\n if ($oldCustomName !== $automatedReport->getCustomName()) {\n $this->updateResultNames($automatedReport);\n }\n\n return $this->transformReportFullView($automatedReport);\n }\n\n public function updateAskJiminnyReportStatus(AutomatedReport $report, bool $status): array\n {\n $this->automatedReportsRepository->update($report, ['status' => $status]);\n\n return $this->transformReportFullView($report->fresh());\n }\n\n /**\n * Validate and transform data for Ask Jiminny reports.\n */\n private function validateAskJiminnyReportData(array $data, User $user): array\n {\n // Validate name\n $name = trim($data['report_name'] ?? '');\n if (empty($name)) {\n throw new InvalidArgumentException('Report name is required');\n }\n if (mb_strlen($name) > 50) {\n throw new InvalidArgumentException('Report name must be 50 characters or less');\n }\n\n // Validate frequency (only daily, weekly, monthly for Ask Jiminny)\n $frequency = $data['frequency'] ?? null;\n $askJiminnyFrequencies = [self::FREQUENCY_DAILY, self::FREQUENCY_WEEKLY, self::FREQUENCY_MONTHLY];\n if (! in_array($frequency, $askJiminnyFrequencies, true)) {\n throw new InvalidArgumentException('Frequency must be daily, weekly, or monthly');\n }\n\n // Validate expiration date\n $expiresAt = $data['expires_on'] ?? null;\n if (empty($expiresAt)) {\n throw new InvalidArgumentException('Expiration date is required');\n }\n\n try {\n $expiresAtDate = Carbon::parse($expiresAt);\n } catch (InvalidFormatException $e) {\n throw new InvalidArgumentException('Expiration date format is invalid');\n }\n $maxExpiration = Carbon::now()->addYear();\n if ($expiresAtDate->gt($maxExpiration)) {\n throw new InvalidArgumentException('Expiration date cannot be more than 1 year from now');\n }\n if ($expiresAtDate->isPast()) {\n throw new InvalidArgumentException('Expiration date cannot be in the past');\n }\n\n // Validate saved search\n $activitySearchId = $data['saved_search'] ?? null;\n if (empty($activitySearchId)) {\n throw new InvalidArgumentException('Saved search is required');\n }\n $savedSearch = $this->activitySearchRepository->findByUuidAndUser($activitySearchId, $user);\n if (! $savedSearch) {\n throw new InvalidArgumentException('Saved search not found or does not belong to you');\n }\n\n // Validate saved prompt\n $askAnythingPromptId = $data['ask_jiminny_prompt'] ?? null;\n if (empty($askAnythingPromptId)) {\n throw new InvalidArgumentException('Ask Jiminny prompt is required');\n }\n $prompt = $this->askAnythingRepository->getPromptByUuid($askAnythingPromptId);\n if (! $prompt) {\n throw new InvalidArgumentException('Ask Jiminny prompt not found');\n }\n\n // Validate status\n $status = $data['enabled'] ?? false;\n\n $recipientUserIds = [$user->getId()];\n\n if (! empty($data['share_users'])) {\n $sharedUserIds = $this->validateAndGetUserIdsByTeam(\n $user->team,\n (array) $data['share_users']\n );\n $recipientUserIds = array_merge($recipientUserIds, $sharedUserIds);\n }\n\n $sharedGroupIds = [];\n if (! empty($data['share_teams'])) {\n $sharedGroupIds = $this->validateAndGetGroupIds($user->team, (array) $data['share_teams']);\n }\n\n $recipientUserIds = array_values(array_unique($recipientUserIds));\n\n return [\n 'team_id' => $user->getTeamId(),\n 'type' => self::TYPE_ASK_JIMINNY,\n 'status' => (bool) $status,\n 'frequency' => $frequency,\n 'custom_name' => $name,\n 'activity_search_id' => $savedSearch->getId(),\n 'ask_anything_prompt_id' => $prompt->getId(),\n 'expires_at' => $expiresAtDate->toDateString(),\n 'media_types' => [self::MEDIA_TYPE_PDF],\n 'call_types' => [],\n 'recipients' => ['users' => $recipientUserIds],\n 'groups' => $sharedGroupIds,\n ];\n }\n\n public static function getAskJiminnyFrequencies(): array\n {\n return array_map(static function ($frequency) {\n return $frequency['id'];\n }, self::ASK_JIMINNY_FREQUENCIES);\n }\n\n public function getAskJiminnyReportFilters(User $user): array\n {\n $savedSearches = $this->activitySearchRepository->findByUserOrderedByName($user)\n ->map(fn (Search $search) => [\n 'id' => $search->getUuid(),\n 'name' => $search->getName(),\n ])\n ->values()->all();\n\n $prompts = collect(\n $this->askAnythingPromptService->get($user, AskAnythingPromptTarget::on_demand)\n )->map(fn (AskAnythingPromptDto $prompt) => [\n 'id' => $prompt->id,\n 'name' => $prompt->title,\n ])->values()->all();\n\n return [\n [\n 'id' => 'prompt',\n 'label' => 'Prompt',\n 'options' => $prompts,\n ],\n [\n 'id' => 'saved_search',\n 'label' => 'Saved Search',\n 'options' => $savedSearches,\n ],\n ];\n }\n\n public function getAskJiminnyReportFormData(User $user, ?AutomatedReport $report = null): array\n {\n $team = $user->getTeam();\n $userTimezone = $user->getTimezone();\n\n $savedSearches = $this->activitySearchRepository->findByUserOrderedByName($user)\n ->map(fn (Search $search) => [\n 'id' => $search->getUuid(),\n 'name' => $search->getName(),\n ])\n ->values()->all();\n\n $prompts = collect(\n $this->askAnythingPromptService->get($user, AskAnythingPromptTarget::on_demand)\n )->map(fn (AskAnythingPromptDto $prompt) => [\n 'id' => $prompt->id,\n 'name' => $prompt->title,\n ])->values()->all();\n\n $teamGroups = $this->groupRepository->getAllByTeam($team)->map(fn ($group) => [\n 'id' => $group->getUuid(),\n 'name' => $group->getName(),\n ])->values()->all();\n\n $shareUsers = $this->recipientsService->getRecipientsFieldData(team: $team)['options'] ?? [];\n\n $sharedTeamsValue = [];\n $sharedUsersValue = [];\n if ($report) {\n $sharedTeamsValue = $this->transformGroups($team, $report->getGroups());\n\n $recipientUserIds = $report->getRecipients()['users'] ?? [];\n $creatorId = $report->getAttribute('created_by');\n $sharedUserIds = array_values(array_filter(\n $recipientUserIds,\n static fn ($id) => $id !== $creatorId\n ));\n $sharedUsersValue = collect($sharedUserIds)\n ->map(fn ($id) => $this->userRepository->find((int) $id))\n ->filter()\n ->map(fn (User $u) => [\n 'id' => $u->getUuid(),\n 'name' => $u->getName(),\n ])\n ->values()\n ->all();\n }\n\n return [\n 'fields' => [\n [\n 'id' => 'enabled',\n 'inputType' => InputTypeEnum::TOGGLE,\n 'label' => '',\n 'value' => $report?->getStatus() ?? false,\n ],\n [\n 'id' => 'report_name',\n 'inputType' => InputTypeEnum::TEXT,\n 'label' => 'Name',\n 'placeholder' => 'Enter name',\n 'required' => true,\n 'validation' => ['maxLength' => 50],\n 'value' => $report?->getCustomName() ?? '',\n ],\n [\n 'id' => 'frequency',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'label' => 'Frequency',\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => self::ASK_JIMINNY_FREQUENCIES,\n 'value' => $report ? $this->transformFrequency($report->getFrequency()) : null,\n ],\n [\n 'id' => 'expires_on',\n 'inputType' => InputTypeEnum::DATE,\n 'label' => 'Expires on',\n 'required' => true,\n 'placeholder' => 'Select',\n 'validation' => [\n 'minDate' => now($userTimezone)->toDateString(),\n 'maxDate' => now($userTimezone)->addYear()->toDateString(),\n ],\n 'value' => $report?->getExpiresAt()?->toDateString(),\n ],\n [\n 'id' => 'share_teams',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'label' => 'Team',\n 'required' => false,\n 'placeholder' => 'Select',\n 'options' => $teamGroups,\n 'value' => $sharedTeamsValue,\n ],\n [\n 'id' => 'share_users',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'label' => 'Team member',\n 'required' => false,\n 'placeholder' => 'Select',\n 'groupLabelKey' => 'label',\n 'groupValuesKey' => 'users',\n 'optionLabelKey' => 'name',\n 'optionValueKey' => 'id',\n 'options' => $shareUsers,\n 'value' => $sharedUsersValue,\n ],\n [\n 'id' => 'saved_search',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'label' => 'Saved search',\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => $savedSearches,\n 'value' => $report && $report->getSavedSearch() ? [\n 'id' => $report->getSavedSearch()->getUuid(),\n 'name' => $report->getSavedSearch()->getName(),\n ] : null,\n ],\n [\n 'id' => 'ask_jiminny_prompt',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'label' => 'Ask Jiminny prompt',\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => $prompts,\n 'value' => $report && $report->getAskAnythingPrompt() ? [\n 'id' => $report->getAskAnythingPrompt()->getUuid(),\n 'name' => $report->getAskAnythingPrompt()->getTitle(),\n ] : null,\n ],\n ],\n ];\n }\n\n private function updateResultNames(AutomatedReport $automatedReport): void\n {\n $results = $this->automatedReportsRepository->getResultsByReport($automatedReport);\n\n foreach ($results as $result) {\n $result->update(['name' => $this->getReportFileName($result)]);\n }\n }\n\n public function updateStatus(string $uuid, array $data): array\n {\n $automatedReport = $this->automatedReportsRepository->findByUuid($uuid);\n\n if (! $automatedReport) {\n throw new ModelNotFoundException('Report not found');\n }\n\n $status = $this->validateReportStatus($data['report_enabled'] ?? null);\n $automatedReport->update([\n 'status' => $status,\n ]);\n\n $this->generateOneOffReport($automatedReport);\n\n return $this->transformReportFullView($automatedReport);\n }\n\n private function generateOneOffReport(AutomatedReport $automatedReport): void\n {\n // the scheduler handles all the other frequency types\n if ($automatedReport->getStatus() === false || $automatedReport->getFrequency() !== self::FREQUENCY_ONE_OFF) {\n return;\n }\n\n $this->dispatcher->dispatch(new RequestGenerateReportJob($automatedReport->getUuid()));\n }\n\n public function getReport(string $uuid): AutomatedReport\n {\n $automatedReport = $this->automatedReportsRepository->findByUuid($uuid);\n\n if (! $automatedReport) {\n throw new ModelNotFoundException('Report not found');\n }\n\n return $automatedReport;\n }\n\n public function get(string $uuid): array\n {\n $automatedReport = $this->getReport($uuid);\n\n return $this->transformReportFullView($automatedReport);\n }\n\n public function list(string $sortColumn = 'created_at', string $sortDirection = 'desc'): array\n {\n $results = [];\n $collection = $this->automatedReportsRepository->getAllStandardReports($sortColumn, $sortDirection);\n\n /** @var AutomatedReport $report */\n foreach ($collection as $report) {\n $results[] = $this->transformReportFullView($report);\n }\n\n return ['data' => $results];\n }\n\n public function listAskJiminnyReports(\n User $user,\n string $sortColumn = 'created_at',\n string $sortDirection = 'desc'\n ): array {\n $results = [];\n $collection = $this->automatedReportsRepository->getAskJiminnyReportsByUser($user, $sortColumn, $sortDirection);\n\n /** @var AutomatedReport $report */\n foreach ($collection as $report) {\n $results[] = $this->transformReportFullView($report);\n }\n\n return ['data' => $results];\n }\n\n public function delete(string $uuid): void\n {\n $automatedReport = $this->automatedReportsRepository->findByUuid($uuid);\n\n if (! $automatedReport) {\n throw new ModelNotFoundException('Report not found');\n }\n\n $automatedReport->delete();\n }\n\n public function createReportResult(AutomatedReport $automatedReport, array $data = []): AutomatedReportResult\n {\n return $this->automatedReportsRepository->createResult(\n array_merge(\n [\n 'report_id' => $automatedReport->getId(),\n 'status' => AutomatedReportResult::STATUS_DEFAULT,\n ],\n $data\n )\n );\n }\n\n public function getReportResult(string $resultUuid): AutomatedReportResult\n {\n $report = $this->automatedReportsRepository->findResultByUuid($resultUuid);\n\n if (! $report) {\n throw new ModelNotFoundException('Report Result not found');\n }\n\n return $report;\n }\n\n public function findChildResult(AutomatedReportResult $result, string $type): ?AutomatedReportResult\n {\n return $this->automatedReportsRepository->findChildResult($result, $type);\n }\n\n // prophet API calls\n /**\n * @throws ApplicationException\n */\n public function getGenerateReportPayload(AutomatedReport $automatedReport, string $reportResultUuid): array\n {\n $period = $this->calculateFromAndToDate($automatedReport);\n $fromDate = $period['fromDate'];\n $toDate = $period['toDate'];\n\n return [\n 'team_id' => $automatedReport->getTeamId(),\n 'request_id' => $reportResultUuid,\n 'report_type' => $automatedReport->getType(),\n 'media_types' => $automatedReport->getMediaTypes(),\n 'from_date' => $fromDate->startOfDay()->format(DateTimeInterface::RFC3339),\n 'to_date' => $toDate->endOfDay()->format(DateTimeInterface::RFC3339),\n 'group_ids' => $automatedReport->getGroups(),\n 'call_deal_stage' => $automatedReport->getDealAtCallStages(),\n 'current_deal_stage' => $automatedReport->getCurrentDealStages(),\n 'deal_min_value' => $automatedReport->getDealValueMin(),\n 'deal_max_value' => $automatedReport->getDealValueMax(),\n 'call_types' => $automatedReport->getCallTypes(),\n 'call_duration_min_seconds' => $automatedReport->getCallDurationMin(),\n 'call_duration_max_seconds' => $automatedReport->getCallDurationMax(),\n 'special_requirements' => $automatedReport->getAdditionalPromptInput(),\n 'callback_url' => $this->getCallbackUrl(),\n 'report_period' => $this->formatReportPeriodName(\n $automatedReport->getFrequency(),\n $fromDate,\n $toDate,\n ),\n 'playbook_categories' => $automatedReport->getPlaybookCategories(),\n 'custom_name' => $automatedReport->getCustomName(),\n ];\n }\n\n // $inputPayload - FE payload structure\n public function getActivitiesCountPayload(array $inputPayload): array\n {\n // Use validateAndTransformData to validate and normalize input\n $validatedData = $this->validateAndTransformData($inputPayload);\n $period = $this->calculateFromAndToDatePeriod(\n $validatedData['frequency'],\n Carbon::parse($validatedData['from']),\n Carbon::parse($validatedData['to']),\n );\n $fromDate = $period['fromDate'];\n $toDate = $period['toDate'];\n\n // Create payload similar to getGenerateReportPayload\n return [\n 'team_id' => $validatedData['team_id'],\n 'group_ids' => $validatedData['groups'] ?? [],\n 'report_type' => $validatedData['type'],\n 'from_date' => $fromDate->format(DateTimeInterface::RFC3339),\n 'to_date' => $toDate->format(DateTimeInterface::RFC3339),\n 'call_deal_stage' => $validatedData['deal_at_call_stages'] ?? [],\n 'current_deal_stage' => $validatedData['current_deal_stages'] ?? [],\n 'deal_min_value' => $validatedData['deal_value_min'] ?? null,\n 'deal_max_value' => $validatedData['deal_value_max'] ?? null,\n 'call_types' => $validatedData['call_types'],\n 'call_duration_min_seconds' => $validatedData['call_duration_min'] ?? null,\n 'call_duration_max_seconds' => $validatedData['call_duration_max'] ?? null,\n 'special_requirements' => $validatedData['additional_prompt_input'] ?? null,\n 'playbook_categories' => $validatedData['playbook_categories'] ?? [],\n 'request_id' => null,\n 'callback_url' => null,\n ];\n }\n\n public function shouldSendReport(array $users, ?CarbonInterface $generatedAt = null): bool\n {\n if (empty($users)) {\n return false;\n }\n\n $earliestTz = collect($users)\n ->mapWithKeys(function (array $user) {\n $tz = new DateTimeZone($user['timezone']);\n $nowUtc = new DateTime('now', new DateTimeZone('UTC'));\n $offset = $tz->getOffset($nowUtc);\n\n return [$user['timezone'] => $offset];\n })\n ->sortDesc()\n ->keys()\n ->first();\n\n $now = Carbon::now($earliestTz);\n $isScheduledTime = (int) $now->format('H') === self::SENT_REPORT_AT_HOURS;\n\n if ($isScheduledTime) {\n return true;\n }\n\n return $this->hasPassedScheduledTime($generatedAt, $earliestTz);\n }\n\n public function hasPassedScheduledTime(?CarbonInterface $generatedAt, string $timezone): bool\n {\n if ($generatedAt === null) {\n return false;\n }\n\n $now = Carbon::now($timezone);\n $scheduledTime = $now->copy()->setTime(self::SENT_REPORT_AT_HOURS, 0, 0);\n\n if ($now->hour < self::SENT_REPORT_AT_HOURS) {\n $scheduledTime = $scheduledTime->subDay();\n }\n\n $scheduledTimeUtc = $scheduledTime->copy()->utc();\n $generatedAtUtc = $generatedAt->copy()->utc();\n $nowUtc = $now->copy()->utc();\n\n return $generatedAtUtc->lt($scheduledTimeUtc) && $nowUtc->gt($scheduledTimeUtc);\n }\n\n public function calculateFromAndToDatePeriod(\n string $frequency,\n ?Carbon $fromDate = null,\n ?Carbon $toDate = null\n ): array {\n if ($frequency === self::FREQUENCY_ONE_OFF) {\n return [\n 'fromDate' => $fromDate,\n 'toDate' => $toDate,\n ];\n }\n\n $now = Carbon::now();\n\n return match ($frequency) {\n self::FREQUENCY_DAILY => [\n 'fromDate' => $now->copy()->subDay()->startOfDay(),\n 'toDate' => $now->copy()->subDay()->endOfDay(),\n ],\n self::FREQUENCY_WEEKLY => [\n 'fromDate' => $now->copy()->subWeeks(1)->startOfDay(),\n 'toDate' => $now->copy()->subDay()->endOfDay(),\n ],\n self::FREQUENCY_MONTHLY => [\n 'fromDate' => $now->copy()->subMonths(1)->startOfDay(),\n 'toDate' => $now->copy()->subDay()->endOfDay(),\n ],\n self::FREQUENCY_QUARTERLY => [\n 'fromDate' => $now->copy()->subMonths(3)->startOfDay(),\n 'toDate' => $now->copy()->subDay()->endOfDay(),\n ],\n default => throw new InvalidArgumentException(\"Unsupported frequency: {$frequency}\"),\n };\n }\n\n private function calculateFromAndToDate(AutomatedReport $automatedReport): array\n {\n return $this->calculateFromAndToDatePeriod(\n $automatedReport->getFrequency(),\n $automatedReport->getFrom(),\n $automatedReport->getTo()\n );\n }\n\n public function getAskJiminnyGenerateReportPayload(\n AutomatedReport $automatedReport,\n AutomatedReportResult $reportResult,\n array $activityIds,\n ): array {\n return [\n 'user_question' => $automatedReport->getAskAnythingPrompt()?->getContent(),\n 'call_ids' => array_map('strval', $activityIds),\n 'team_id' => $automatedReport->getTeamId(),\n 'request_id' => $reportResult->getUuid(),\n 'callback_url' => $this->getCallbackUrl(),\n 'report_period' => $this->getReportPeriodName($reportResult),\n 'report_name' => $automatedReport->getCustomName(),\n ];\n }\n\n private function getCallbackUrl(): string\n {\n return $this->webhookService->route('jiminny.webhook.reports.ready');\n }\n\n /**\n * Validate and transform payload data for automated reports\n *\n * @param array $data\n *\n * @throws InvalidArgumentException\n *\n * @return array\n */\n private function validateAndTransformData(array $data): array\n {\n // Validate organization (team) and check feature\n $team = $this->validateOrganization($data['organization'] ?? null);\n\n $status = $this->validateReportStatus($data['report_enabled'] ?? null);\n $type = $this->validateReportType($data['report_type'] ?? null);\n $frequency = $this->validateFrequency($data['frequency'] ?? null);\n $additionalPromptInput = $this->validateAdditionalPromptInput(\n $data['additional_prompt_input'] ?? null\n );\n $customReportName = $this->validateCustomReportName($data['custom_name'] ?? null);\n\n // Prepare data for the database\n $reportData = [\n 'team_id' => $team->getId(),\n 'type' => $type,\n 'status' => $status,\n 'frequency' => $frequency,\n 'additional_prompt_input' => $additionalPromptInput,\n 'custom_name' => $customReportName,\n ];\n\n // Validate deal values\n $reportData = $this->validateDealValues($data, $reportData);\n\n // Validate date range\n $reportData = $this->validateDateRange($data, $reportData, $frequency);\n\n // Validate call durations\n $reportData = $this->validateCallDurations($data, $reportData);\n\n // Validate call types\n $reportData = $this->validateCallTypes($data, $reportData);\n\n // Validate media types\n $reportData = $this->validateMediaTypes($data, $reportData);\n\n // Validate groups\n if (isset($data['teams'])) {\n $reportData['groups'] = $this->validateAndGetGroupIds($team, $data['teams']);\n }\n\n // Validate deal stages\n $reportData = $this->validateDealStages($data, $reportData, $team, $type);\n\n // Validate playbook categories\n $reportData = $this->validatePlaybookCategories($data, $reportData, $team);\n\n // Validate recipients\n $reportData['recipients'] = [\n 'users' => $this->validateAndGetUserIdsByTeam($team, $data['recipients'] ?? []),\n ];\n\n if (isset($data['jiminny_recipients'])) {\n // Validate Jiminny recipients\n $reportData['jiminny_recipients'] = [\n 'users' => $this->validateAndGetJiminnyUserIds((array) $data['jiminny_recipients']),\n ];\n }\n\n return $reportData;\n }\n\n private function validateDealValues(array $data, array $reportData): array\n {\n if (isset($data['min_deal_value'])) {\n $reportData['deal_value_min'] = (int) $data['min_deal_value'];\n\n if ($reportData['deal_value_min'] > 4294967295 || $reportData['deal_value_min'] < 0) {\n throw new InvalidArgumentException('Min deal value should be between 0 and 4294967295');\n }\n }\n\n if (isset($data['max_deal_value'])) {\n $reportData['deal_value_max'] = (int) $data['max_deal_value'];\n\n if ($reportData['deal_value_max'] > 4294967295 || $reportData['deal_value_max'] < 0) {\n throw new InvalidArgumentException('Max deal value should be between 0 and 4294967295');\n }\n }\n\n if (isset($data['min_deal_value'], $data['max_deal_value'])\n && $data['min_deal_value'] > $data['max_deal_value']\n ) {\n throw new InvalidArgumentException('Min deal value cannot be greater than max deal value');\n }\n\n return $reportData;\n }\n\n private function validateDateRange(array $data, array $reportData, string $frequency): array\n {\n // Set date range only for one_off frequency\n if ($frequency === 'one_off') {\n if (isset($data['start_date_period'])) {\n $reportData['from'] = $this->parseDate($data['start_date_period']);\n }\n\n if (isset($data['end_date_period'])) {\n $reportData['to'] = $this->parseDate($data['end_date_period']);\n }\n\n if (empty($reportData['from']) || empty($reportData['to'])) {\n throw new InvalidArgumentException(\n 'Start date and end date are required for one_off frequency'\n );\n }\n } else {\n $reportData['from'] = null;\n $reportData['to'] = null;\n }\n\n return $reportData;\n }\n\n private function validateCallDurations(array $data, array $reportData): array\n {\n // Convert call durations from minutes to seconds\n if (isset($data['min_call_duration'])) {\n $reportData['call_duration_min'] = (int) $data['min_call_duration'] * 60;\n\n if ($reportData['call_duration_min'] > 4294967295 || $reportData['call_duration_min'] < 0) {\n throw new InvalidArgumentException('Min call duration should be between 0 and 4294967295');\n }\n }\n\n if (isset($data['max_call_duration'])) {\n $reportData['call_duration_max'] = (int) $data['max_call_duration'] * 60;\n\n if ($reportData['call_duration_max'] > 4294967295 || $reportData['call_duration_max'] < 0) {\n throw new InvalidArgumentException('Max call duration should be between 0 and 4294967295');\n }\n }\n\n return $reportData;\n }\n\n private function validateCallTypes(array $data, array $reportData): array\n {\n // Set call types\n $reportData['call_types'] = $data['call_type'] ?? [];\n if (empty($reportData['call_types'])) {\n $reportData['call_types'] = self::getCallTypes();\n }\n\n foreach ($reportData['call_types'] as $callType) {\n if (! in_array($callType, self::getCallTypes(), true)) {\n throw new InvalidArgumentException(sprintf('Call type %s is invalid', $callType));\n }\n }\n\n return $reportData;\n }\n\n private function validateMediaTypes(array $data, array $reportData): array\n {\n // Set media types from input data\n $reportData['media_types'] = $data['media_types'] ?? [];\n\n if (empty($reportData['media_types'])) {\n throw new InvalidArgumentException('Media types are required');\n }\n\n foreach ($reportData['media_types'] as $mediaType) {\n if (! in_array($mediaType, self::MEDIA_TYPES, true)) {\n throw new InvalidArgumentException(sprintf('Media type %s is invalid', $mediaType));\n }\n }\n\n return $reportData;\n }\n\n private function validateDealStages(array $data, array $reportData, Team $team, string $reportType): array\n {\n // Validate and set deal stages\n if (isset($data['deal_stage_at_call'])) {\n $reportData['deal_at_call_stages'] =\n $this->validateAndGetDealStageIds($team, $data['deal_stage_at_call'], 'Deal stage at call');\n }\n\n if (isset($data['current_deal_stage'])) {\n $reportData['current_deal_stages'] =\n $this->validateAndGetDealStageIds($team, $data['current_deal_stage'], 'Current deal stage');\n }\n\n // Ensure current_deal_stage is not provided for loss_analysis report type\n if ($reportType === self::TYPE_LOSS_ANALYSIS && ! empty($data['current_deal_stage'])) {\n throw new InvalidArgumentException('Current deal stage is not applicable for Loss Analysis reports');\n }\n\n return $reportData;\n }\n\n // transform uuid to id\n private function validatePlaybookCategories(array $data, array $reportData, Team $team): array\n {\n $key = 'playbook_categories';\n\n if (isset($data[$key])) {\n $payloadIds = $data[$key];\n $ids = [];\n\n foreach ($payloadIds as $uuid) {\n $uuid = (string) $uuid;\n\n try {\n $playbookCategory = $this->playbookCategoryRepository->findByUuid($uuid);\n } catch (Throwable $throwable) {\n Log::error(__METHOD__ . ' ' . $throwable->getMessage());\n\n throw new InvalidArgumentException(sprintf('Playbook category %s not found', $uuid));\n }\n\n if (! $playbookCategory) {\n throw new InvalidArgumentException(sprintf('Playbook category %s not found', $uuid));\n }\n\n if (! $playbookCategory->hasPlaybook()) {\n throw new InvalidArgumentException(sprintf('Playbook category %s has no playbook', $uuid));\n }\n\n if ($playbookCategory->getPlaybook()->getTeamId() !== $team->getId()) {\n throw new InvalidArgumentException(\n sprintf('Playbook category %s not found for team %s', $uuid, $team->getUuid())\n );\n }\n\n $ids[] = $playbookCategory->getId();\n }\n\n $reportData[$key] = $ids;\n }\n\n return $reportData;\n }\n\n private function validateReportStatus($status): bool\n {\n if (! in_array($status, [true, false], true)) {\n throw new InvalidArgumentException('Report status is invalid');\n }\n\n return $status;\n }\n\n private function validateReportType($type): string\n {\n if (! in_array($type, self::getTypes(), true)) {\n throw new InvalidArgumentException(sprintf('Report type is invalid: %s', $type));\n }\n\n return $type;\n }\n\n private function validateFrequency($frequency): string\n {\n if (! in_array($frequency, self::getFrequencies(), true)) {\n throw new InvalidArgumentException('Frequency is invalid');\n }\n\n return $frequency;\n }\n\n private function validateAdditionalPromptInput(?string $additionalPromptInput): ?string\n {\n if ($additionalPromptInput && strlen($additionalPromptInput) > 5000) {\n throw new InvalidArgumentException('Additional Prompt Input should be less than 5000 characters');\n }\n\n return $additionalPromptInput;\n }\n\n private function validateCustomReportName(?string $customReportName): ?string\n {\n if ($customReportName === null || $customReportName === '') {\n return null;\n }\n\n if (strlen($customReportName) > 70) {\n throw new InvalidArgumentException('Custom report name should be less than 70 characters');\n }\n\n return $customReportName;\n }\n\n private function validateOrganization(?string $organizationUuid): Team\n {\n if (! $organizationUuid) {\n throw new InvalidArgumentException('Organization is required');\n }\n\n $team = $this->teamRepository->idOrUuid($organizationUuid);\n\n if (! $team) {\n throw new InvalidArgumentException('Organization not found');\n }\n\n if (! $team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {\n throw new InvalidArgumentException('Organization does not have the Automated Reports feature');\n }\n\n return $team;\n }\n\n private function validateAndGetGroupIds(Team $team, array $teamUuids): array\n {\n $groupIds = [];\n\n foreach ($teamUuids as $uuid) {\n $group = $this->groupRepository->findByUuid($uuid);\n\n if ($group === null || $group->getTeamId() !== $team->getId()) {\n throw new InvalidArgumentException(\n sprintf('Group %s not found for team %s', $uuid, $team->getUuid())\n );\n }\n\n $groupIds[] = $group->getId();\n\n }\n\n return $groupIds;\n }\n\n private function validateAndGetDealStageIds(Team $team, array $stageUuids, string $propertyLabel): array\n {\n $stageIds = [];\n\n foreach ($stageUuids as $uuid) {\n $stage = $this->stageRepository->findByUuid($uuid);\n\n if ($stage === null || $stage->getTeamId() !== $team->getId()) {\n throw new InvalidArgumentException(\n sprintf('Stage %s not found for team %s for %s', $uuid, $team->getUuid(), $propertyLabel)\n );\n }\n\n $stageIds[] = $stage->getId();\n }\n\n return $stageIds;\n }\n\n private function validateAndGetUserIds(array $userUuids, callable $teamCheck): array\n {\n if (empty($userUuids)) {\n return [];\n }\n\n $userIds = [];\n\n foreach ($userUuids as $uuid) {\n $user = $this->userRepository->findByUuid($uuid);\n\n if (! $user || ! $user->isStatusActive()) {\n throw new InvalidArgumentException(\n sprintf('User %s not found or is not active', $uuid)\n );\n }\n\n if (! $teamCheck($user)) {\n throw new InvalidArgumentException(\n sprintf('User %s does not belong to the allowed team(s)', $uuid)\n );\n }\n\n $userIds[] = $user->getId();\n }\n\n return $userIds;\n }\n\n private function validateAndGetUserIdsByTeam(Team $team, array $userUuids): array\n {\n return $this->validateAndGetUserIds($userUuids, fn ($user) => $user->getTeamId() === $team->getId());\n }\n\n private function validateAndGetJiminnyUserIds(array $userUuids): array\n {\n $allowedTeamIds = config('kiosk.teamIds', []);\n\n return $this->validateAndGetUserIds($userUuids, fn ($user) => in_array($user->getTeamId(), $allowedTeamIds, true));\n }\n\n private function parseDate(string $dateString): string\n {\n return date('Y-m-d H:i:s', strtotime($dateString));\n }\n\n private function generateReportResultViewUrl(AutomatedReportResult $result): string\n {\n $mediaResource = $this->getReportMediaRouteResource($result);\n\n return route('ai-reports.' . $mediaResource . '.view', ['uuid' => $result->getUuid()]);\n }\n\n private function generateReportResultDownloadUrl(AutomatedReportResult $result): string\n {\n $mediaResource = $this->getReportMediaRouteResource($result);\n\n return route('ai-reports.' . $mediaResource . '.download', ['uuid' => $result->getUuid()]);\n }\n\n private function getReportMediaRouteResource(AutomatedReportResult $result): string\n {\n if ($result->getMediaType() === self::MEDIA_TYPE_PDF) {\n return self::PDF_KEY;\n } elseif ($result->getMediaType() === self::MEDIA_TYPE_PODCAST) {\n return self::AUDIO_KEY;\n }\n\n throw new \\InvalidArgumentException('Unknown media type.');\n }\n\n public function getMediaPath(AutomatedReportResult $result): ?string\n {\n $url = match ($result->getMediaType()) {\n self::MEDIA_TYPE_PDF => $result->getPdfUrl(),\n self::MEDIA_TYPE_PODCAST => $result->getPodcastAudioUrl(),\n default => null,\n };\n\n if ($url === null) {\n return null;\n }\n\n $path = parse_url(trim($url, '\"\\''), PHP_URL_PATH);\n\n return $path ?: null;\n }\n\n public function getFilenameSuffix(AutomatedReportResult $result): ?string\n {\n return match ($result->getMediaType()) {\n self::MEDIA_TYPE_PODCAST => 'Podcast',\n default => null,\n };\n }\n\n public function getMailSubjectSuffix(AutomatedReportResult $result): string\n {\n return match ($result->getMediaType()) {\n self::MEDIA_TYPE_PDF => 'report',\n self::MEDIA_TYPE_PODCAST => 'podcast',\n default => '',\n };\n }\n\n public function getMediaTypeMetadata(AutomatedReportResult $result): array\n {\n return match ($result->getMediaType()) {\n self::MEDIA_TYPE_PODCAST => ['extension' => 'mp3', 'mime' => 'audio/mpeg'],\n self::MEDIA_TYPE_PDF => ['extension' => 'pdf', 'mime' => 'application/pdf'],\n default => ['extension' => null, 'mime' => null],\n };\n }\n\n public function deleteS3Files(AutomatedReportResult $result): void\n {\n $teamUuid = $result->getReport()->getTeam()->getUuid();\n $reportUuid = $result->getUuid();\n\n // delete all files for a report uuid no mather of pdf, podcast, or both\n // in case of both - the podcast files are linked to the pdf (parent) uuid\n // pdf and podcast date times should be close\n $path = sprintf('%s/%s/%s', $teamUuid, self::S3_DIR, $reportUuid);\n\n foreach (self::FILE_EXTENSIONS_VARIANTS as $extension) {\n $file = $path . '.' . $extension;\n\n if (Storage::exists($file)) {\n Storage::delete($file);\n Log::info('[Reports] Deleted S3 file', [\n 'path' => $file,\n ]);\n }\n }\n\n foreach (self::FILE_PODCAST_EXTENSIONS_VARIANTS as $extension) {\n $file = $path . '_podcast.' . $extension;\n\n if (Storage::exists($file)) {\n Storage::delete($file);\n Log::info('[Reports] Deleted Podcast S3 file', [\n 'path' => $file,\n ]);\n }\n }\n }\n\n /**\n *\n * @param int|null $teamId Optional team ID to filter results\n *\n * @return Collection<int, int> Collection of team IDs\n */\n public function getTeamIdsWithReportsResults(?int $teamId = null): Collection\n {\n return $this->automatedReportsRepository->getTeamIdsWithReportsResults($teamId);\n }\n\n /**\n * Core delete logic for report results using a query\n *\n * @param Builder $query\n * @param array $logContext\n *\n * @return int\n */\n private function deleteReportResultsByQuery(Builder $query, array $logContext = []): int\n {\n $deletedCount = 0;\n\n if ($query->exists()) {\n Log::info(\n 'Run delete report results',\n array_merge(\n $logContext,\n [\n 'service' => 'AutomatedReportsService',\n ]\n )\n );\n\n $query->chunkById(50, function ($results) use (&$deletedCount, $logContext) {\n foreach ($results as $result) {\n $this->deleteReportResult($result);\n $deletedCount++;\n\n Log::info(\n 'Deleted a report result',\n array_merge(\n $logContext,\n [\n 'result_id' => $result->getId(),\n 'report_id' => $result->getReportId(),\n ]\n )\n );\n }\n });\n }\n\n return $deletedCount;\n }\n\n /**\n * Delete report results for a team by retention period\n *\n * @param Team $team\n * @param CarbonImmutable $retentionDate\n *\n * @return int Number of deleted report results\n */\n public function deleteReportsResultsInRetentionPeriod(Team $team, CarbonImmutable $retentionDate): int\n {\n $reportIds = $this->automatedReportsRepository->getReportIdsByTeam($team);\n\n if ($reportIds->isEmpty()) {\n return 0;\n }\n\n $query = $this->automatedReportsRepository\n ->getReportResultsQueryForRetention($team, $retentionDate);\n\n return $this->deleteReportResultsByQuery($query, [\n 'team_id' => $team->getId(),\n 'retention_date' => $retentionDate->toDateTimeString(),\n ]);\n }\n\n /**\n * Delete ALL report results for a specific automated report\n *\n * @param string $uuid\n *\n * @return int\n */\n public function deleteReportResults(string $uuid): int\n {\n $report = $this->getReport($uuid);\n\n $query = $this->automatedReportsRepository->getResultsByReportQuery($report);\n\n return $this->deleteReportResultsByQuery($query, [\n 'report_uuid' => $uuid,\n 'report_id' => $report->getId(),\n ]);\n }\n\n public function deleteReportResult(AutomatedReportResult $result): void\n {\n $this->deleteS3Files($result);\n\n $result->delete();\n }\n\n /**\n * Get all reports for a specific team\n *\n * @param Team $team\n *\n * @return \\Illuminate\\Database\\Eloquent\\Collection\n */\n public function getTeamReports(Team $team): \\Illuminate\\Database\\Eloquent\\Collection\n {\n return $this->automatedReportsRepository->getReportsByTeam($team);\n }\n\n /**\n * Get all report results for a specific report\n *\n * @param AutomatedReport $report\n *\n * @return \\Illuminate\\Database\\Eloquent\\Collection\n */\n public function getReportResults(AutomatedReport $report): \\Illuminate\\Database\\Eloquent\\Collection\n {\n return $this->automatedReportsRepository->getResultsByReport($report);\n }\n\n public function deleteAllReportResults(AutomatedReport $report): void\n {\n $results = $this->getReportResults($report);\n\n /** @var AutomatedReportResult $result */\n foreach ($results as $result) {\n Log::info('Deleting result', [\n 'report' => $report->getId(),\n 'result' => $result->getId(),\n ]);\n\n $this->deleteReportResult($result);\n }\n }\n\n public function deleteAllData(Team $team): void\n {\n Log::info('Deleting automated report and results for team', [\n 'team' => $team->getId(),\n ]);\n\n $reports = $this->getTeamReports($team);\n\n /** @var AutomatedReport $report */\n foreach ($reports as $report) {\n Log::info('Deleting report', [\n 'team' => $team->getId(),\n 'report' => $report->getId(),\n ]);\n\n $this->deleteAllReportResults($report);\n\n $report->delete();\n }\n }\n}","depth":4,"value":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Services\\Kiosk\\AutomatedReports;\n\nuse Carbon\\CarbonImmutable;\nuse Carbon\\CarbonInterface;\nuse Carbon\\Exceptions\\InvalidFormatException;\nuse DateTime;\nuse DateTimeInterface;\nuse DateTimeZone;\nuse Illuminate\\Contracts\\Bus\\Dispatcher as BusDispatcher;\nuse Illuminate\\Database\\Eloquent\\Builder;\nuse Illuminate\\Support\\Carbon;\nuse Illuminate\\Support\\Collection;\nuse Illuminate\\Support\\Facades\\Log;\nuse Illuminate\\Support\\Facades\\Storage;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinition\\InputTypeEnum;\nuse Jiminny\\Component\\AskAnything\\AskAnythingPromptService;\nuse Jiminny\\Component\\AskAnything\\Dtos\\AskAnythingPromptDto;\nuse Jiminny\\Component\\UrlGenerator\\Webhook;\nuse Jiminny\\Contracts\\Repositories\\PlaybookCategoryRepository;\nuse Jiminny\\Contracts\\Repositories\\TeamRepository;\nuse Jiminny\\Contracts\\Repositories\\UserRepository;\nuse Jiminny\\Exceptions\\ApplicationException;\nuse Jiminny\\Exceptions\\InvalidArgumentException;\nuse Jiminny\\Exceptions\\ModelNotFoundException;\nuse Jiminny\\Jobs\\AutomatedReports\\RequestGenerateReportJob;\nuse Jiminny\\Models\\Activity\\Search;\nuse Jiminny\\Models\\AskAnything\\AskAnythingPrompt;\nuse Jiminny\\Models\\AskAnything\\AskAnythingPromptTarget;\nuse Jiminny\\Models\\AutomatedReport;\nuse Jiminny\\Models\\AutomatedReportResult;\nuse Jiminny\\Models\\Contracts\\UserContract;\nuse Jiminny\\Models\\Feature\\FeatureEnum;\nuse Jiminny\\Models\\Team;\nuse Jiminny\\Models\\User;\nuse Jiminny\\Repositories\\AskAnythingRepository;\nuse Jiminny\\Repositories\\AutomatedReportsRepository;\nuse Jiminny\\Repositories\\GroupRepository;\nuse Jiminny\\Repositories\\SearchRepository;\nuse Jiminny\\Repositories\\StageRepository;\nuse Throwable;\n\nclass AutomatedReportsService\n{\n public const string TYPE_LOSS_ANALYSIS = 'loss_analysis';\n public const string TYPE_ASK_JIMINNY = 'ask_jiminny';\n\n /**\n * Standard report types (used by kiosk for existing automated reports).\n */\n // @TODO this will add filter, however if we need to control feature by FF we need conditional logic\n public const array TYPES = [\n ['id' => 'exec_summary', 'name' => 'Exec Summary'],\n ['id' => 'coaching_profiles', 'name' => 'Coaching Profiles'],\n ['id' => 'product_feedback', 'name' => 'Product Feedback'],\n ['id' => self::TYPE_LOSS_ANALYSIS, 'name' => 'Loss Analysis'],\n// ['id' => 'questions', 'name' => 'Questions'],\n// ['id' => 'statistical_quant', 'name' => 'Statistical Quantitative'],\n ];\n\n public const array ALL_TYPES = [\n ...self::TYPES,\n ['id' => self::TYPE_ASK_JIMINNY, 'name' => 'Ask Jiminny'],\n ];\n\n public const string FREQUENCY_DAILY = 'daily';\n public const string FREQUENCY_WEEKLY = 'weekly';\n public const string FREQUENCY_MONTHLY = 'monthly';\n public const string FREQUENCY_QUARTERLY = 'quarterly';\n public const string FREQUENCY_ONE_OFF = 'one_off';\n\n /**\n * Frequencies for standard (non-Ask Jiminny) reports.\n */\n public const array FREQUENCIES = [\n ['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],\n ['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],\n ['id' => self::FREQUENCY_QUARTERLY, 'name' => 'Quarterly'],\n ['id' => self::FREQUENCY_ONE_OFF, 'name' => 'One-off'],\n ];\n\n /**\n * Frequencies for Ask Jiminny reports.\n */\n public const array ASK_JIMINNY_FREQUENCIES = [\n ['id' => self::FREQUENCY_DAILY, 'name' => 'Daily'],\n ['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],\n ['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],\n ];\n\n public const string MEDIA_TYPE_PDF = 'pdf';\n public const string MEDIA_TYPE_PODCAST = 'podcast';\n public const array MEDIA_TYPES = [self::MEDIA_TYPE_PDF, self::MEDIA_TYPE_PODCAST];\n public const array MEDIA_TYPE_OBJECT_PDF = ['id' => self::MEDIA_TYPE_PDF, 'name' => 'PDF'];\n public const array MEDIA_TYPE_OBJECT_PODCAST = ['id' => self::MEDIA_TYPE_PODCAST, 'name' => 'Podcast'];\n public const array MEDIA_TYPE_OBJECTS = [self::MEDIA_TYPE_OBJECT_PDF, self::MEDIA_TYPE_OBJECT_PODCAST];\n\n public const array CALL_TYPE_CONFERENCE = ['id' => 'conference', 'name' => 'Conference'];\n public const array CALL_TYPE_DIALER = ['id' => 'dialer', 'name' => 'Dialer'];\n public const int SENT_REPORT_AT_HOURS = 5;\n public const string PDF_KEY = 'pdf';\n public const string AUDIO_KEY = 'audio';\n\n private const array ALL_FREQUENCIES = [\n ['id' => self::FREQUENCY_DAILY, 'name' => 'Daily'],\n ['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],\n ['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],\n ['id' => self::FREQUENCY_QUARTERLY, 'name' => 'Quarterly'],\n ['id' => self::FREQUENCY_ONE_OFF, 'name' => 'One-off'],\n ];\n private const string S3_DIR = 'reports';\n private const array FILE_EXTENSIONS_VARIANTS = ['html', 'MD', 'pdf'];\n private const array FILE_PODCAST_EXTENSIONS_VARIANTS = ['json', 'mp3', 'ssml'];\n\n public function __construct(\n private readonly TeamRepository $teamRepository,\n private readonly GroupRepository $groupRepository,\n private readonly UserRepository $userRepository,\n private readonly StageRepository $stageRepository,\n private readonly DealStagesService $dealStagesService,\n private readonly RecipientsService $recipientsService,\n private readonly AutomatedReportsRepository $automatedReportsRepository,\n private readonly Webhook $webhookService,\n private readonly BusDispatcher $dispatcher,\n private readonly ActivityTypeService $activityTypeService,\n private readonly PlaybookCategoryRepository $playbookCategoryRepository,\n private readonly AskAnythingPromptService $askAnythingPromptService,\n private readonly SearchRepository $activitySearchRepository,\n private readonly AskAnythingRepository $askAnythingRepository,\n ) {\n }\n\n public static function getTypes(): array\n {\n $types = self::TYPES;\n\n return array_map(static function ($type) {\n return $type['id'];\n }, $types);\n }\n\n public static function getCallTypes(): array\n {\n return array_map(static function ($callType) {\n return $callType['id'];\n }, [self::CALL_TYPE_CONFERENCE, self::CALL_TYPE_DIALER]);\n }\n\n public static function getFrequencies(): array\n {\n return array_map(static function ($frequency) {\n return $frequency['id'];\n }, self::FREQUENCIES);\n }\n\n // front-facing structure\n public function getReportEnabledFieldData(bool $value = false): array\n {\n return [\n 'id' => 'report_enabled',\n 'label' => '',\n 'inputType' => InputTypeEnum::TOGGLE,\n 'value' => $value,\n ];\n }\n\n // Organizations = Teams\n public function getOrganizationFieldData(?string $value = null, bool $shortVersion = false): array\n {\n $options = $this->getTeams();\n\n if ($shortVersion) {\n return [\n 'id' => 'organization',\n 'label' => 'Organization',\n 'options' => $options,\n ];\n }\n\n return [\n 'id' => 'organization',\n 'label' => 'Organization',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => $options,\n 'value' => $value,\n 'dependencies' => [\n 'teams',\n 'deal_stage_at_call',\n 'current_deal_stage',\n 'recipients',\n ActivityTypeService::PLAYBOOK_CATEGORIES_KEY,\n ],\n 'dependsOn' => [],\n ];\n }\n\n // Teams = Groups\n public function getTeamFieldData(array $options = [], array $value = [], bool $shortVersion = false): array\n {\n if ($shortVersion) {\n return [\n 'id' => 'teams',\n 'label' => 'Team',\n 'options' => $options,\n ];\n }\n\n return [\n 'id' => 'teams',\n 'label' => 'Team',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'required' => false,\n 'placeholder' => 'Select',\n 'options' => $options,\n 'value' => $value, // value should be an array of objects {id, name}\n 'dependencies' => [ActivityTypeService::PLAYBOOK_CATEGORIES_KEY],\n 'dependsOn' => [],\n ];\n }\n\n public function getReportTypeFieldData(?string $value = null, bool $shortVersion = false, ?Team $team = null): array\n {\n $types = [];\n if ($team instanceof Team) {\n if ($team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {\n $types = self::TYPES;\n }\n if ($team->hasFeature(FeatureEnum::ASK_JIMINNY_REPORTS)) {\n $types[] = ['id' => self::TYPE_ASK_JIMINNY, 'name' => 'Ask Jiminny'];\n }\n } else {\n $types = self::TYPES;\n }\n\n if ($shortVersion) {\n return [\n 'id' => 'report_type',\n 'label' => 'Report Type',\n 'options' => $types,\n ];\n }\n\n return [\n 'id' => 'report_type',\n 'label' => 'Report Type',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => $types,\n 'value' => $value,\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getFrequencyFieldData(?string $value = null): array\n {\n return [\n 'id' => 'frequency',\n 'label' => 'Frequency',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => self::FREQUENCIES,\n 'value' => $value,\n 'dependencies' => ['period'],\n 'dependsOn' => [],\n ];\n }\n\n public function getPeriodFieldData(?string $valueStartDate = null, ?string $valueEndDate = null): array\n {\n return [\n 'id' => 'period',\n 'label' => 'Select one-off period',\n 'inputType' => InputTypeEnum::DATE_RANGE,\n 'required' => true,\n 'placeholder' => 'Select',\n 'value' => ['startDate' => $valueStartDate, 'endDate' => $valueEndDate],\n 'queryParams' => [\n 'startDate' => 'start_date_period',\n 'endDate' => 'end_date_period',\n ],\n 'dependencies' => [],\n 'dependsOn' => ['frequency'],\n ];\n }\n\n public function getActivityTypesFieldData(?Team $team = null, array $value = [], array $teamsFilter = []): array\n {\n return $this->activityTypeService->getActivityTypeFieldData(team: $team, value: $value, groupIds: $teamsFilter);\n }\n\n public function getDealStageAtCallFieldData(?Team $team = null, array $value = []): array\n {\n return $this->dealStagesService->getDealStageAtCallFieldData(team: $team, value: $value);\n }\n\n public function getCurrentDealStageFieldData(?Team $team = null, array $value = []): array\n {\n return $this->dealStagesService->getCurrentDealStageFieldData(team: $team, value: $value);\n }\n\n public function getDealValueFieldData(?int $valueMin = null, ?int $valueMax = null): array\n {\n return [\n 'id' => 'deal_value',\n 'label' => 'Deal Value',\n 'inputType' => InputTypeEnum::INTEGER_RANGE,\n 'required' => false,\n 'value' => ['min' => $valueMin, 'max' => $valueMax],\n 'queryParams' => [\n 'min' => 'min_deal_value',\n 'max' => 'max_deal_value',\n ],\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getCallTypeFieldData(bool $conferenceOn = false, bool $dialerOn = false): array\n {\n $value = [];\n $conferenceOn && $value[] = self::CALL_TYPE_CONFERENCE;\n $dialerOn && $value[] = self::CALL_TYPE_DIALER;\n\n return [\n 'id' => 'call_type',\n 'label' => 'Call Type',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'required' => true,\n 'options' => [\n self::CALL_TYPE_CONFERENCE,\n self::CALL_TYPE_DIALER,\n ],\n 'value' => $value,\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getMediaTypeFieldData(?AutomatedReport $report = null): array\n {\n $value = [];\n\n if ($report) {\n $value = $this->transformMediaTypes($report);\n }\n\n return [\n 'id' => 'media_types',\n 'label' => 'Export as',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'required' => true,\n 'options' => self::MEDIA_TYPE_OBJECTS,\n 'value' => $value,\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getCallDurationFieldData(?int $valueMin = null, ?int $valueMax = null): array\n {\n return [\n 'id' => 'call_duration',\n 'label' => 'Call Duration',\n 'inputType' => InputTypeEnum::INTEGER_RANGE,\n 'required' => false,\n 'value' => ['min' => $valueMin, 'max' => $valueMax],\n 'queryParams' => [\n 'min' => 'min_call_duration',\n 'max' => 'max_call_duration',\n ],\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getRecipientsFieldData(?Team $team = null, array $value = []): array\n {\n return $this->recipientsService->getRecipientsFieldData(team: $team, value: $value);\n }\n\n public function getJiminnyRecipientsFieldData(array $value = []): array\n {\n return $this->recipientsService->getJiminnyRecipientsFieldData($value);\n }\n\n public function getAdditionalPromptInputFieldData(?string $value = null): array\n {\n return [\n 'id' => 'additional_prompt_input',\n 'label' => 'Special requirements',\n 'inputType' => InputTypeEnum::TEXTAREA,\n 'required' => false,\n 'placeholder' => 'What should be the focus of the report?',\n 'value' => $value,\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getCustomReportNameFieldData(?string $value = null): array\n {\n return [\n 'id' => 'custom_name',\n 'label' => 'Custom report name',\n 'inputType' => InputTypeEnum::TEXT,\n 'required' => false,\n 'placeholder' => 'Enter custom name',\n 'value' => $value,\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n // data providers\n public function getTeams(): array\n {\n $teams = $this->teamRepository->getTeamsForKiosk(status: Team::STATUS_ACTIVE);\n\n $teamData = [];\n foreach ($teams as $team) {\n if (! $team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {\n continue;\n }\n\n $teamData[] = $this->transformTeam($team);\n }\n\n return $teamData;\n }\n\n public function getTeamGroups(string $teamUuid): array\n {\n $data = [];\n $team = $this->getTeam($teamUuid);\n\n if ($team !== null) {\n $groups = $team->groups()->get();\n\n foreach ($groups as $group) {\n $data[] = [\n 'id' => $group->getUuid(),\n 'name' => $group->getName(),\n ];\n }\n }\n\n return $data;\n }\n\n public function getTeamsGroupsOptions(array $filterTeamUuids = []): array\n {\n $data = [];\n $teams = $this->getTeams();\n\n foreach ($teams as $team) {\n if (! empty($filterTeamUuids) && ! in_array($team['id'], $filterTeamUuids, true)) {\n continue;\n }\n\n $data[] = [\n 'label' => $team['name'],\n 'groups' => $this->getTeamGroups($team['id']),\n ];\n }\n\n return $data;\n }\n\n public function getTeam(string $teamUuid): ?Team\n {\n return $this->teamRepository->idOrUuid($teamUuid);\n }\n\n public function getTeamById(int $teamId): ?Team\n {\n return $this->teamRepository->find($teamId);\n }\n\n public function getGroupsUuids(AutomatedReport $report): array\n {\n $uuids = [];\n $reportGroups = $report->getGroups();\n foreach ($reportGroups as $groupId) {\n if ($group = $this->groupRepository->find($groupId)) {\n $uuids[] = $group->getUuid();\n }\n }\n\n return $uuids;\n }\n\n public function getPlaybookCategoriesUuids(AutomatedReport $report): array\n {\n $uuids = [];\n $playbookCategories = $report->getPlaybookCategories();\n foreach ($playbookCategories as $id) {\n if ($category = $this->playbookCategoryRepository->find($id)) {\n $uuids[] = $category->getUuid();\n }\n }\n\n return $uuids;\n }\n\n public function getDealAtCallStagesUuids(AutomatedReport $report): array\n {\n $uuids = [];\n $reportStages = $report->getDealAtCallStages();\n foreach ($reportStages as $id) {\n if ($stage = $this->stageRepository->find($id)) {\n $uuids[] = $stage->getUuid();\n }\n }\n\n return $uuids;\n }\n\n public function getCurrentDealStagesUuids(AutomatedReport $report): array\n {\n $uuids = [];\n $reportStages = $report->getCurrentDealStages();\n foreach ($reportStages as $id) {\n if ($stage = $this->stageRepository->find($id)) {\n $uuids[] = $stage->getUuid();\n }\n }\n\n return $uuids;\n }\n\n public function getUsersUuids(AutomatedReport $report): array\n {\n return $this->extractUserUuids($report->getRecipients());\n }\n\n public function getJiminnyUsersUuids(AutomatedReport $report): array\n {\n return $this->extractUserUuids($report->getJiminnyRecipients());\n }\n\n /**\n * @param array<string, mixed> $recipients\n */\n private function extractUserUuids(array $recipients): array\n {\n $userIds = $recipients['users'] ?? [];\n\n return collect($userIds)\n ->map(fn ($id) => $this->userRepository->find((int) $id))\n ->filter()\n ->map(fn (UserContract $user) => $user->getUuid())\n ->values()\n ->all();\n }\n\n // get mail data\n public function getRecipientUsers(AutomatedReport $report): array\n {\n return $this->buildRecipientUsers($report->getRecipients());\n }\n\n private function getJiminnyRecipientUsers(AutomatedReport $report): array\n {\n return $this->buildRecipientUsers($report->getJiminnyRecipients());\n }\n\n /**\n * @param array<string, mixed> $recipients\n */\n private function buildRecipientUsers(array $recipients): array\n {\n $userIds = $recipients['users'] ?? [];\n\n return collect($userIds)\n ->map(fn ($id) => $this->userRepository->find((int) $id))\n ->filter()\n ->map(fn (UserContract $user) => [\n 'email' => $user->getEmailAddress(),\n 'name' => $user->getName(),\n 'timezone' => $user->getTimezone()->getName(),\n ])\n ->values()\n ->all();\n }\n\n public function getValidRecipientUsers(AutomatedReport $report, bool $includeJiminny = false): array\n {\n if ($report->isAskJiminnyReport()) {\n $recipients = $this->resolveAskJiminnyRecipients($report);\n } else {\n $recipients = $this->getRecipientUsers($report);\n if ($includeJiminny) {\n $recipients = array_merge($recipients, $this->getJiminnyRecipientUsers($report));\n }\n }\n\n $emails = [];\n\n return array_values(array_filter(\n $recipients,\n static function ($recipient) use (&$emails) {\n if (empty($recipient['email']) || in_array($recipient['email'], $emails, true)) {\n return false;\n }\n $emails[] = $recipient['email'];\n\n return true;\n }\n ));\n }\n\n private function resolveAskJiminnyRecipients(AutomatedReport $report): array\n {\n $recipients = [];\n\n $creator = $report->getCreator();\n if ($creator !== null) {\n $recipients[] = [\n 'email' => $creator->getEmailAddress(),\n 'name' => $creator->getName(),\n 'timezone' => $creator->getTimezone()->getName(),\n ];\n }\n\n return array_merge(\n $recipients,\n $this->buildRecipientUsers($report->getRecipients()),\n $this->getGroupRecipientUsers($report),\n );\n }\n\n private function getGroupRecipientUsers(AutomatedReport $report): array\n {\n $users = [];\n foreach ($report->getGroups() as $groupId) {\n $group = $this->groupRepository->find($groupId);\n if ($group === null) {\n continue;\n }\n foreach ($group->getMembers() as $member) {\n $users[] = [\n 'email' => $member->getEmailAddress(),\n 'name' => $member->getName(),\n 'timezone' => $member->getTimezone()->getName(),\n ];\n }\n }\n\n return $users;\n }\n\n public function getReportTypeName(AutomatedReportResult $report): string\n {\n $type = $report->getReport()->getType();\n\n $getType = $this->transformReportType($type);\n\n return $getType['name'];\n }\n\n public function getReportPeriodName(AutomatedReportResult $report): string\n {\n $from = $report->getFromDate();\n $to = $report->getToDate();\n $frequency = $report->getReport()->getFrequency();\n\n if ($from === null || $to === null) {\n if (! $report->getReport()->isAskJiminnyReport()) {\n $invalidPeriod = $from === null ? 'from' : 'to';\n\n throw new ApplicationException('Report period is invalid: ' . $invalidPeriod);\n }\n\n $period = $this->calculateFromAndToDatePeriod($frequency);\n $from = $period['fromDate'];\n $to = $period['toDate'];\n }\n\n return $this->formatReportPeriodName($frequency, $from, $to);\n }\n\n private function formatReportPeriodName(string $frequency, Carbon $from, Carbon $to): string\n {\n $fromYear = $from->format('Y');\n $toYear = $to->format('Y');\n $differentYears = $fromYear !== $toYear;\n\n switch ($frequency) {\n case self::FREQUENCY_DAILY:\n return $from->format('j M Y');\n\n case self::FREQUENCY_QUARTERLY:\n // 'Jan-Mar 2025' or 'Nov 2024-Jan 2025' if years differ\n $startMonth = $from->format('M');\n $endMonth = $to->copy()->subMonth();\n $endMonthName = $endMonth->format('M');\n $endMonthYear = $endMonth->format('Y');\n\n if ($differentYears) {\n return \"{$startMonth} {$fromYear} - {$endMonthName} {$endMonthYear}\";\n }\n\n return \"{$startMonth} - {$endMonthName} {$toYear}\";\n\n case self::FREQUENCY_MONTHLY:\n // 'May 2025' - monthly reports are always within the same year\n return $from->format('M Y');\n\n case self::FREQUENCY_WEEKLY:\n // '4 - 8 Aug 2025', '27 Oct - 3 Nov 2025', or '28 Dec 2024 - 3 Jan 2025' if years differ\n $startDay = $from->format('j');\n $endDay = $to->format('j');\n $startMonth = $from->format('M');\n $endMonth = $to->format('M');\n\n if ($differentYears) {\n return \"{$startDay} {$startMonth} {$fromYear} - {$endDay} {$endMonth} {$toYear}\";\n }\n\n if ($startMonth !== $endMonth) {\n return \"{$startDay} {$startMonth} - {$endDay} {$endMonth} {$toYear}\";\n }\n\n return \"{$startDay} - {$endDay} {$endMonth} {$toYear}\";\n\n case self::FREQUENCY_ONE_OFF:\n // '2 May-31 May 2025' or '15 Dec 2024-15 Jan 2025' if years differ\n $startDay = $from->format('j');\n $startMonth = $from->format('M');\n $endDay = $to->format('j');\n $endMonth = $to->format('M');\n\n // If same month and year, use a format like '2-31 May 2025'\n if ($startMonth === $endMonth && ! $differentYears) {\n return \"{$startDay} - {$endDay} {$startMonth} {$toYear}\";\n }\n\n // If different years, include both years\n if ($differentYears) {\n return \"{$startDay} {$startMonth} {$fromYear} - {$endDay} {$endMonth} {$toYear}\";\n }\n\n // Same year but different months\n return \"{$startDay} {$startMonth} - {$endDay} {$endMonth} {$toYear}\";\n\n default:\n // Default format for unknown frequencies\n return $from->format('j M Y') . ' - ' . $to->format('j M Y');\n }\n }\n\n public function getReportTeamsName(AutomatedReportResult $report): string\n {\n $groups = $report->getGroups();\n\n if (empty($groups)) {\n return 'All';\n }\n\n // Get group names from repository\n $groupNames = [];\n foreach ($groups as $groupId) {\n $group = $this->groupRepository->find($groupId);\n if ($group) {\n $groupNames[] = $group->getName();\n }\n }\n\n if (count($groupNames) === 1) {\n // Single team format\n $teamsName = $groupNames[0];\n } else {\n // Multiple teams format\n $teamsName = implode(', ', $groupNames);\n }\n\n return $teamsName;\n }\n\n public function getReportFileName(AutomatedReportResult $report): string\n {\n $customName = $report->getReport()->getCustomName();\n $periodName = $this->getReportPeriodName($report);\n $filenameSuffix = $this->getFilenameSuffix($report);\n\n if ($customName) {\n if ($filenameSuffix) {\n $customName .= \" {$filenameSuffix}\";\n }\n\n return $this->sanitizeFileName(\"{$customName} - {$periodName}\");\n }\n\n $baseName = $this->getReportTypeName($report);\n\n if ($filenameSuffix) {\n $baseName .= \" {$filenameSuffix}\";\n }\n\n return $this->sanitizeFileName(\"{$baseName} - {$periodName} - {$this->getReportTeamsName($report)}\");\n }\n\n public function getReportFileNameWithExtension(AutomatedReportResult $result): string\n {\n $extension = $this->getMediaTypeMetadata($result)['extension'];\n\n return $this->getReportFileName($result) . '.' . $extension;\n }\n\n public function sanitizeFileName(string $fileName): string\n {\n return str_replace(['/', '\\\\'], '-', $fileName);\n }\n\n public function isUserRecipientOfReport(User $user, AutomatedReport $report): bool\n {\n $recipients = array_map('intval', $report->getRecipients()['users'] ?? []);\n\n return in_array($user->getId(), $recipients);\n }\n\n public function transformReportResults(Collection $automatedReportResults): array\n {\n $data = [];\n foreach ($automatedReportResults as $automatedReportResult) {\n /** @var AutomatedReportResult $automatedReportResult */\n\n $report = $automatedReportResult->getReport();\n\n $createdBy = $report->getCreator();\n $creator = [\n 'id' => $createdBy?->getUuid(),\n 'name' => $createdBy?->getName(),\n 'email' => $createdBy?->getEmailAddress(),\n 'photoUrl' => $createdBy?->getPhotoUrl(),\n ];\n\n $data[] = [\n 'id' => $automatedReportResult->getUuid(),\n 'name' => $automatedReportResult->getName(),\n 'frequency' => $this->transformFrequency($report->getFrequency()),\n 'recipients' => [\n ...array_values($this->transformGroups(team: $report->getTeam(), groupsIds: $report->getGroups())),\n ...array_values($this->transformRecipients($report->getRecipients())),\n ],\n 'report_type' => $this->transformReportType($report->getType()),\n 'media_type' => $automatedReportResult->getMediaType(),\n 'downloadUrl' => $this->generateReportResultDownloadUrl($automatedReportResult),\n 'viewUrl' => $this->generateReportResultViewUrl($automatedReportResult),\n 'generated_at' => $automatedReportResult->getGeneratedAt()?->toIso8601String(),\n 'creator' => $creator,\n ];\n }\n\n return $data;\n }\n\n public function hasCallTypeConference(AutomatedReport $report): bool\n {\n return in_array(self::CALL_TYPE_CONFERENCE['id'], $report->getCallTypes(), true);\n }\n\n public function hasCallTypeDialer(AutomatedReport $report): bool\n {\n return in_array(self::CALL_TYPE_DIALER['id'], $report->getCallTypes(), true);\n }\n\n // transformers\n private function transformTeam(Team $team): array\n {\n if (! $team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {\n return [];\n }\n\n return [\n 'id' => $team->getUuid(),\n 'name' => $team->getName(),\n ];\n }\n\n private function transformReportFullView(AutomatedReport $report): array\n {\n $base = $this->transformReportBase($report);\n\n return $report->getType() === self::TYPE_ASK_JIMINNY\n ? $base + $this->transformAskJiminnyFields($report)\n : $base + $this->transformStandardReportFields($report);\n }\n\n private function transformReportBase(AutomatedReport $report): array\n {\n return [\n 'id' => $report->getUuid(),\n 'organization' => $this->transformOrganization(team: $report->getTeam()),\n 'report_type' => $this->transformReportType($report->getType()),\n 'frequency' => $this->transformFrequency($report->getFrequency()),\n ];\n }\n\n private function transformStandardReportFields(AutomatedReport $report): array\n {\n $team = $report->getTeam();\n\n return [\n 'report_enabled' => $report->getStatus(),\n 'start_date_period' => $report->getFrom()?->format('Y-m-d H:i:s'),\n 'end_date_period' => $report->getTo()?->format('Y-m-d H:i:s'),\n 'deal_value_min' => $report->getDealValueMin(),\n 'deal_value_max' => $report->getDealValueMax(),\n 'call_types' => $this->transformCallType($report->getCallTypes()),\n 'media_types' => $this->transformMediaTypes($report),\n 'call_duration_min' => $this->transformDurationToMinutes($report->getCallDurationMin()),\n 'call_duration_max' => $this->transformDurationToMinutes($report->getCallDurationMax()),\n 'teams' => $this->transformGroups(team: $team, groupsIds: $report->getGroups()),\n 'deal_at_call_stages' => $this->transformStages(team: $team, stagesIds: $report->getDealAtCallStages()),\n 'current_deal_stages' => $this->transformStages(team: $team, stagesIds: $report->getCurrentDealStages()),\n 'recipients' => $this->transformRecipients($report->getRecipients()),\n 'created_by' => $this->transformCreator($report->getCreator()),\n 'additional_prompt_input' => $report->getAdditionalPromptInput(),\n 'custom_name' => $report->getCustomName(),\n 'created_at' => $report->getCreatedAt()->format('Y-m-d H:i:s'),\n 'updated_at' => $report->getUpdatedAt()->format('Y-m-d H:i:s'),\n 'deleted_at' => $report->getDeletedAt()?->format('Y-m-d H:i:s'),\n ];\n }\n\n private function transformAskJiminnyFields(AutomatedReport $report): array\n {\n $team = $report->getTeam();\n $creatorId = $report->getAttribute('created_by');\n $explicitUserIds = array_values(array_filter(\n $report->getRecipients()['users'] ?? [],\n static fn ($id) => $id !== $creatorId\n ));\n\n return [\n 'report_name' => $report->getCustomName(),\n 'enabled' => $report->getStatus(),\n 'share_teams' => $this->transformGroups(team: $team, groupsIds: $report->getGroups()),\n 'share_users' => $this->transformRecipients(['users' => $explicitUserIds]),\n 'saved_search' => $this->transformSafeSearch($report->getSavedSearch()),\n 'ask_jiminny_prompt' => $this->transformAskJiminnyPrompt($report->getAskAnythingPrompt()),\n 'expires_on' => $report->getExpiresAt()?->format('Y-m-d'),\n ];\n }\n\n private function transformOrganization(?Team $team): array\n {\n return [\n 'id' => $team?->getUuid(),\n 'name' => $team?->getName(),\n ];\n }\n\n private function transformReportType(string $type): array\n {\n foreach (self::ALL_TYPES as $typeItem) {\n if ($typeItem['id'] === $type) {\n return $typeItem;\n }\n }\n\n return [];\n }\n\n private function transformCallType(array $types): array\n {\n $result = [];\n $callTypes = [self::CALL_TYPE_CONFERENCE, self::CALL_TYPE_DIALER];\n\n foreach ($types as $type) {\n foreach ($callTypes as $callTypeItem) {\n if ($callTypeItem['id'] === $type) {\n $result[] = $callTypeItem;\n\n break;\n }\n }\n }\n\n return $result;\n }\n\n private function transformMediaTypes(AutomatedReport $report): array\n {\n $values = [];\n\n foreach ($report->getMediaTypes() as $mediaType) {\n if (! in_array($mediaType, self::MEDIA_TYPES, true)) {\n continue;\n }\n\n $values[] = match ($mediaType) {\n self::MEDIA_TYPE_PDF => self::MEDIA_TYPE_OBJECT_PDF,\n self::MEDIA_TYPE_PODCAST => self::MEDIA_TYPE_OBJECT_PODCAST,\n };\n }\n\n return $values;\n }\n\n private function transformFrequency(string $frequency): array\n {\n foreach (self::ALL_FREQUENCIES as $frequencyItem) {\n if ($frequencyItem['id'] === $frequency) {\n return $frequencyItem;\n }\n }\n\n return [];\n }\n\n public function transformDurationToMinutes(?int $duration): ?int\n {\n if (! $duration) {\n return null;\n }\n\n return (int) ($duration / 60);\n }\n\n private function transformGroups(?Team $team, array $groupsIds): array\n {\n if (empty($groupsIds) || ! $team) {\n return [];\n }\n\n $data = [];\n foreach ($groupsIds as $groupId) {\n $group = $team->groups()->where('id', $groupId)->first();\n\n if ($group) {\n $data[] = [\n 'id' => $group->getUuid(),\n 'name' => $group->getName(),\n 'photoUrl' => $group->getPhotoUrl(),\n ];\n }\n }\n\n return $data;\n }\n\n private function transformStages(?Team $team, array $stagesIds): array\n {\n if (empty($stagesIds) || ! $team) {\n return [];\n }\n\n $data = [];\n foreach ($stagesIds as $stageId) {\n $stage = $team->stages()->where('id', $stageId)->first();\n\n if ($stage) {\n $data[] = [\n 'id' => $stage->getUuid(),\n 'name' => $stage->getName(),\n ];\n }\n }\n\n return $data;\n }\n\n private function transformRecipients(array $recipients): array\n {\n $users = [];\n foreach ($recipients['users'] ?? [] as $userId) {\n $users[] = $this->transformUser($userId);\n }\n\n return $users;\n }\n\n private function transformCreator(?User $user): ?array\n {\n if ($user === null) {\n return null;\n }\n\n return $this->transformUser($user->getId());\n }\n\n private function transformAskJiminnyPrompt(?AskAnythingPrompt $prompt): ?array\n {\n if ($prompt === null) {\n return null;\n }\n\n return [\n 'id' => $prompt->getUuid(),\n 'name' => $prompt->getTitle(),\n ];\n }\n\n private function transformSafeSearch(?Search $search): ?array\n {\n if ($search === null) {\n return null;\n }\n\n return [\n 'id' => $search->getUuid(),\n 'name' => $search->getName(),\n ];\n }\n\n private function transformUser(int $userId): array\n {\n /* @var ?User $user */\n $user = $this->userRepository->find($userId);\n\n return [\n 'id' => $user?->getUuid(),\n 'name' => $user?->getName(),\n 'email' => $user?->getEmailAddress(),\n 'photoUrl' => $user?->getPhotoUrl(),\n ];\n }\n\n public function create(array $data): array\n {\n $validatedData = $this->validateAndTransformData($data);\n $validatedData['created_by'] = auth()->id();\n\n $automatedReport = $this->automatedReportsRepository->create($validatedData);\n\n $this->generateOneOffReport($automatedReport);\n\n return $this->transformReportFullView($automatedReport);\n }\n\n public function update(string $uuid, array $data): array\n {\n $validatedData = $this->validateAndTransformData($data);\n $report = $this->automatedReportsRepository->findByUuid($uuid);\n\n if (! $report) {\n throw new InvalidArgumentException('Report not found');\n }\n\n $oldCustomName = $report->getCustomName();\n\n $automatedReport = $this->automatedReportsRepository->update($report, $validatedData);\n\n if ($oldCustomName !== $automatedReport->getCustomName()) {\n $this->updateResultNames($automatedReport);\n }\n\n $this->generateOneOffReport($automatedReport);\n\n return $this->transformReportFullView($automatedReport);\n }\n\n /**\n * Create an Ask Jiminny report.\n */\n public function createAskJiminnyReport(array $data, User $creator): array\n {\n $validatedData = $this->validateAskJiminnyReportData($data, $creator);\n $validatedData['created_by'] = $creator->getId();\n\n $automatedReport = $this->automatedReportsRepository->create($validatedData);\n\n return $this->transformReportFullView($automatedReport);\n }\n\n /**\n * Update an Ask Jiminny report.\n */\n public function updateAskJiminnyReport(AutomatedReport $report, array $data, User $user): array\n {\n if (! $report->isAskJiminnyReport()) {\n throw new InvalidArgumentException('Report is not an Ask Jiminny report');\n }\n\n $validatedData = $this->validateAskJiminnyReportData($data, $user);\n\n $oldCustomName = $report->getCustomName();\n\n $automatedReport = $this->automatedReportsRepository->update($report, $validatedData);\n\n if ($oldCustomName !== $automatedReport->getCustomName()) {\n $this->updateResultNames($automatedReport);\n }\n\n return $this->transformReportFullView($automatedReport);\n }\n\n public function updateAskJiminnyReportStatus(AutomatedReport $report, bool $status): array\n {\n $this->automatedReportsRepository->update($report, ['status' => $status]);\n\n return $this->transformReportFullView($report->fresh());\n }\n\n /**\n * Validate and transform data for Ask Jiminny reports.\n */\n private function validateAskJiminnyReportData(array $data, User $user): array\n {\n // Validate name\n $name = trim($data['report_name'] ?? '');\n if (empty($name)) {\n throw new InvalidArgumentException('Report name is required');\n }\n if (mb_strlen($name) > 50) {\n throw new InvalidArgumentException('Report name must be 50 characters or less');\n }\n\n // Validate frequency (only daily, weekly, monthly for Ask Jiminny)\n $frequency = $data['frequency'] ?? null;\n $askJiminnyFrequencies = [self::FREQUENCY_DAILY, self::FREQUENCY_WEEKLY, self::FREQUENCY_MONTHLY];\n if (! in_array($frequency, $askJiminnyFrequencies, true)) {\n throw new InvalidArgumentException('Frequency must be daily, weekly, or monthly');\n }\n\n // Validate expiration date\n $expiresAt = $data['expires_on'] ?? null;\n if (empty($expiresAt)) {\n throw new InvalidArgumentException('Expiration date is required');\n }\n\n try {\n $expiresAtDate = Carbon::parse($expiresAt);\n } catch (InvalidFormatException $e) {\n throw new InvalidArgumentException('Expiration date format is invalid');\n }\n $maxExpiration = Carbon::now()->addYear();\n if ($expiresAtDate->gt($maxExpiration)) {\n throw new InvalidArgumentException('Expiration date cannot be more than 1 year from now');\n }\n if ($expiresAtDate->isPast()) {\n throw new InvalidArgumentException('Expiration date cannot be in the past');\n }\n\n // Validate saved search\n $activitySearchId = $data['saved_search'] ?? null;\n if (empty($activitySearchId)) {\n throw new InvalidArgumentException('Saved search is required');\n }\n $savedSearch = $this->activitySearchRepository->findByUuidAndUser($activitySearchId, $user);\n if (! $savedSearch) {\n throw new InvalidArgumentException('Saved search not found or does not belong to you');\n }\n\n // Validate saved prompt\n $askAnythingPromptId = $data['ask_jiminny_prompt'] ?? null;\n if (empty($askAnythingPromptId)) {\n throw new InvalidArgumentException('Ask Jiminny prompt is required');\n }\n $prompt = $this->askAnythingRepository->getPromptByUuid($askAnythingPromptId);\n if (! $prompt) {\n throw new InvalidArgumentException('Ask Jiminny prompt not found');\n }\n\n // Validate status\n $status = $data['enabled'] ?? false;\n\n $recipientUserIds = [$user->getId()];\n\n if (! empty($data['share_users'])) {\n $sharedUserIds = $this->validateAndGetUserIdsByTeam(\n $user->team,\n (array) $data['share_users']\n );\n $recipientUserIds = array_merge($recipientUserIds, $sharedUserIds);\n }\n\n $sharedGroupIds = [];\n if (! empty($data['share_teams'])) {\n $sharedGroupIds = $this->validateAndGetGroupIds($user->team, (array) $data['share_teams']);\n }\n\n $recipientUserIds = array_values(array_unique($recipientUserIds));\n\n return [\n 'team_id' => $user->getTeamId(),\n 'type' => self::TYPE_ASK_JIMINNY,\n 'status' => (bool) $status,\n 'frequency' => $frequency,\n 'custom_name' => $name,\n 'activity_search_id' => $savedSearch->getId(),\n 'ask_anything_prompt_id' => $prompt->getId(),\n 'expires_at' => $expiresAtDate->toDateString(),\n 'media_types' => [self::MEDIA_TYPE_PDF],\n 'call_types' => [],\n 'recipients' => ['users' => $recipientUserIds],\n 'groups' => $sharedGroupIds,\n ];\n }\n\n public static function getAskJiminnyFrequencies(): array\n {\n return array_map(static function ($frequency) {\n return $frequency['id'];\n }, self::ASK_JIMINNY_FREQUENCIES);\n }\n\n public function getAskJiminnyReportFilters(User $user): array\n {\n $savedSearches = $this->activitySearchRepository->findByUserOrderedByName($user)\n ->map(fn (Search $search) => [\n 'id' => $search->getUuid(),\n 'name' => $search->getName(),\n ])\n ->values()->all();\n\n $prompts = collect(\n $this->askAnythingPromptService->get($user, AskAnythingPromptTarget::on_demand)\n )->map(fn (AskAnythingPromptDto $prompt) => [\n 'id' => $prompt->id,\n 'name' => $prompt->title,\n ])->values()->all();\n\n return [\n [\n 'id' => 'prompt',\n 'label' => 'Prompt',\n 'options' => $prompts,\n ],\n [\n 'id' => 'saved_search',\n 'label' => 'Saved Search',\n 'options' => $savedSearches,\n ],\n ];\n }\n\n public function getAskJiminnyReportFormData(User $user, ?AutomatedReport $report = null): array\n {\n $team = $user->getTeam();\n $userTimezone = $user->getTimezone();\n\n $savedSearches = $this->activitySearchRepository->findByUserOrderedByName($user)\n ->map(fn (Search $search) => [\n 'id' => $search->getUuid(),\n 'name' => $search->getName(),\n ])\n ->values()->all();\n\n $prompts = collect(\n $this->askAnythingPromptService->get($user, AskAnythingPromptTarget::on_demand)\n )->map(fn (AskAnythingPromptDto $prompt) => [\n 'id' => $prompt->id,\n 'name' => $prompt->title,\n ])->values()->all();\n\n $teamGroups = $this->groupRepository->getAllByTeam($team)->map(fn ($group) => [\n 'id' => $group->getUuid(),\n 'name' => $group->getName(),\n ])->values()->all();\n\n $shareUsers = $this->recipientsService->getRecipientsFieldData(team: $team)['options'] ?? [];\n\n $sharedTeamsValue = [];\n $sharedUsersValue = [];\n if ($report) {\n $sharedTeamsValue = $this->transformGroups($team, $report->getGroups());\n\n $recipientUserIds = $report->getRecipients()['users'] ?? [];\n $creatorId = $report->getAttribute('created_by');\n $sharedUserIds = array_values(array_filter(\n $recipientUserIds,\n static fn ($id) => $id !== $creatorId\n ));\n $sharedUsersValue = collect($sharedUserIds)\n ->map(fn ($id) => $this->userRepository->find((int) $id))\n ->filter()\n ->map(fn (User $u) => [\n 'id' => $u->getUuid(),\n 'name' => $u->getName(),\n ])\n ->values()\n ->all();\n }\n\n return [\n 'fields' => [\n [\n 'id' => 'enabled',\n 'inputType' => InputTypeEnum::TOGGLE,\n 'label' => '',\n 'value' => $report?->getStatus() ?? false,\n ],\n [\n 'id' => 'report_name',\n 'inputType' => InputTypeEnum::TEXT,\n 'label' => 'Name',\n 'placeholder' => 'Enter name',\n 'required' => true,\n 'validation' => ['maxLength' => 50],\n 'value' => $report?->getCustomName() ?? '',\n ],\n [\n 'id' => 'frequency',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'label' => 'Frequency',\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => self::ASK_JIMINNY_FREQUENCIES,\n 'value' => $report ? $this->transformFrequency($report->getFrequency()) : null,\n ],\n [\n 'id' => 'expires_on',\n 'inputType' => InputTypeEnum::DATE,\n 'label' => 'Expires on',\n 'required' => true,\n 'placeholder' => 'Select',\n 'validation' => [\n 'minDate' => now($userTimezone)->toDateString(),\n 'maxDate' => now($userTimezone)->addYear()->toDateString(),\n ],\n 'value' => $report?->getExpiresAt()?->toDateString(),\n ],\n [\n 'id' => 'share_teams',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'label' => 'Team',\n 'required' => false,\n 'placeholder' => 'Select',\n 'options' => $teamGroups,\n 'value' => $sharedTeamsValue,\n ],\n [\n 'id' => 'share_users',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'label' => 'Team member',\n 'required' => false,\n 'placeholder' => 'Select',\n 'groupLabelKey' => 'label',\n 'groupValuesKey' => 'users',\n 'optionLabelKey' => 'name',\n 'optionValueKey' => 'id',\n 'options' => $shareUsers,\n 'value' => $sharedUsersValue,\n ],\n [\n 'id' => 'saved_search',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'label' => 'Saved search',\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => $savedSearches,\n 'value' => $report && $report->getSavedSearch() ? [\n 'id' => $report->getSavedSearch()->getUuid(),\n 'name' => $report->getSavedSearch()->getName(),\n ] : null,\n ],\n [\n 'id' => 'ask_jiminny_prompt',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'label' => 'Ask Jiminny prompt',\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => $prompts,\n 'value' => $report && $report->getAskAnythingPrompt() ? [\n 'id' => $report->getAskAnythingPrompt()->getUuid(),\n 'name' => $report->getAskAnythingPrompt()->getTitle(),\n ] : null,\n ],\n ],\n ];\n }\n\n private function updateResultNames(AutomatedReport $automatedReport): void\n {\n $results = $this->automatedReportsRepository->getResultsByReport($automatedReport);\n\n foreach ($results as $result) {\n $result->update(['name' => $this->getReportFileName($result)]);\n }\n }\n\n public function updateStatus(string $uuid, array $data): array\n {\n $automatedReport = $this->automatedReportsRepository->findByUuid($uuid);\n\n if (! $automatedReport) {\n throw new ModelNotFoundException('Report not found');\n }\n\n $status = $this->validateReportStatus($data['report_enabled'] ?? null);\n $automatedReport->update([\n 'status' => $status,\n ]);\n\n $this->generateOneOffReport($automatedReport);\n\n return $this->transformReportFullView($automatedReport);\n }\n\n private function generateOneOffReport(AutomatedReport $automatedReport): void\n {\n // the scheduler handles all the other frequency types\n if ($automatedReport->getStatus() === false || $automatedReport->getFrequency() !== self::FREQUENCY_ONE_OFF) {\n return;\n }\n\n $this->dispatcher->dispatch(new RequestGenerateReportJob($automatedReport->getUuid()));\n }\n\n public function getReport(string $uuid): AutomatedReport\n {\n $automatedReport = $this->automatedReportsRepository->findByUuid($uuid);\n\n if (! $automatedReport) {\n throw new ModelNotFoundException('Report not found');\n }\n\n return $automatedReport;\n }\n\n public function get(string $uuid): array\n {\n $automatedReport = $this->getReport($uuid);\n\n return $this->transformReportFullView($automatedReport);\n }\n\n public function list(string $sortColumn = 'created_at', string $sortDirection = 'desc'): array\n {\n $results = [];\n $collection = $this->automatedReportsRepository->getAllStandardReports($sortColumn, $sortDirection);\n\n /** @var AutomatedReport $report */\n foreach ($collection as $report) {\n $results[] = $this->transformReportFullView($report);\n }\n\n return ['data' => $results];\n }\n\n public function listAskJiminnyReports(\n User $user,\n string $sortColumn = 'created_at',\n string $sortDirection = 'desc'\n ): array {\n $results = [];\n $collection = $this->automatedReportsRepository->getAskJiminnyReportsByUser($user, $sortColumn, $sortDirection);\n\n /** @var AutomatedReport $report */\n foreach ($collection as $report) {\n $results[] = $this->transformReportFullView($report);\n }\n\n return ['data' => $results];\n }\n\n public function delete(string $uuid): void\n {\n $automatedReport = $this->automatedReportsRepository->findByUuid($uuid);\n\n if (! $automatedReport) {\n throw new ModelNotFoundException('Report not found');\n }\n\n $automatedReport->delete();\n }\n\n public function createReportResult(AutomatedReport $automatedReport, array $data = []): AutomatedReportResult\n {\n return $this->automatedReportsRepository->createResult(\n array_merge(\n [\n 'report_id' => $automatedReport->getId(),\n 'status' => AutomatedReportResult::STATUS_DEFAULT,\n ],\n $data\n )\n );\n }\n\n public function getReportResult(string $resultUuid): AutomatedReportResult\n {\n $report = $this->automatedReportsRepository->findResultByUuid($resultUuid);\n\n if (! $report) {\n throw new ModelNotFoundException('Report Result not found');\n }\n\n return $report;\n }\n\n public function findChildResult(AutomatedReportResult $result, string $type): ?AutomatedReportResult\n {\n return $this->automatedReportsRepository->findChildResult($result, $type);\n }\n\n // prophet API calls\n /**\n * @throws ApplicationException\n */\n public function getGenerateReportPayload(AutomatedReport $automatedReport, string $reportResultUuid): array\n {\n $period = $this->calculateFromAndToDate($automatedReport);\n $fromDate = $period['fromDate'];\n $toDate = $period['toDate'];\n\n return [\n 'team_id' => $automatedReport->getTeamId(),\n 'request_id' => $reportResultUuid,\n 'report_type' => $automatedReport->getType(),\n 'media_types' => $automatedReport->getMediaTypes(),\n 'from_date' => $fromDate->startOfDay()->format(DateTimeInterface::RFC3339),\n 'to_date' => $toDate->endOfDay()->format(DateTimeInterface::RFC3339),\n 'group_ids' => $automatedReport->getGroups(),\n 'call_deal_stage' => $automatedReport->getDealAtCallStages(),\n 'current_deal_stage' => $automatedReport->getCurrentDealStages(),\n 'deal_min_value' => $automatedReport->getDealValueMin(),\n 'deal_max_value' => $automatedReport->getDealValueMax(),\n 'call_types' => $automatedReport->getCallTypes(),\n 'call_duration_min_seconds' => $automatedReport->getCallDurationMin(),\n 'call_duration_max_seconds' => $automatedReport->getCallDurationMax(),\n 'special_requirements' => $automatedReport->getAdditionalPromptInput(),\n 'callback_url' => $this->getCallbackUrl(),\n 'report_period' => $this->formatReportPeriodName(\n $automatedReport->getFrequency(),\n $fromDate,\n $toDate,\n ),\n 'playbook_categories' => $automatedReport->getPlaybookCategories(),\n 'custom_name' => $automatedReport->getCustomName(),\n ];\n }\n\n // $inputPayload - FE payload structure\n public function getActivitiesCountPayload(array $inputPayload): array\n {\n // Use validateAndTransformData to validate and normalize input\n $validatedData = $this->validateAndTransformData($inputPayload);\n $period = $this->calculateFromAndToDatePeriod(\n $validatedData['frequency'],\n Carbon::parse($validatedData['from']),\n Carbon::parse($validatedData['to']),\n );\n $fromDate = $period['fromDate'];\n $toDate = $period['toDate'];\n\n // Create payload similar to getGenerateReportPayload\n return [\n 'team_id' => $validatedData['team_id'],\n 'group_ids' => $validatedData['groups'] ?? [],\n 'report_type' => $validatedData['type'],\n 'from_date' => $fromDate->format(DateTimeInterface::RFC3339),\n 'to_date' => $toDate->format(DateTimeInterface::RFC3339),\n 'call_deal_stage' => $validatedData['deal_at_call_stages'] ?? [],\n 'current_deal_stage' => $validatedData['current_deal_stages'] ?? [],\n 'deal_min_value' => $validatedData['deal_value_min'] ?? null,\n 'deal_max_value' => $validatedData['deal_value_max'] ?? null,\n 'call_types' => $validatedData['call_types'],\n 'call_duration_min_seconds' => $validatedData['call_duration_min'] ?? null,\n 'call_duration_max_seconds' => $validatedData['call_duration_max'] ?? null,\n 'special_requirements' => $validatedData['additional_prompt_input'] ?? null,\n 'playbook_categories' => $validatedData['playbook_categories'] ?? [],\n 'request_id' => null,\n 'callback_url' => null,\n ];\n }\n\n public function shouldSendReport(array $users, ?CarbonInterface $generatedAt = null): bool\n {\n if (empty($users)) {\n return false;\n }\n\n $earliestTz = collect($users)\n ->mapWithKeys(function (array $user) {\n $tz = new DateTimeZone($user['timezone']);\n $nowUtc = new DateTime('now', new DateTimeZone('UTC'));\n $offset = $tz->getOffset($nowUtc);\n\n return [$user['timezone'] => $offset];\n })\n ->sortDesc()\n ->keys()\n ->first();\n\n $now = Carbon::now($earliestTz);\n $isScheduledTime = (int) $now->format('H') === self::SENT_REPORT_AT_HOURS;\n\n if ($isScheduledTime) {\n return true;\n }\n\n return $this->hasPassedScheduledTime($generatedAt, $earliestTz);\n }\n\n public function hasPassedScheduledTime(?CarbonInterface $generatedAt, string $timezone): bool\n {\n if ($generatedAt === null) {\n return false;\n }\n\n $now = Carbon::now($timezone);\n $scheduledTime = $now->copy()->setTime(self::SENT_REPORT_AT_HOURS, 0, 0);\n\n if ($now->hour < self::SENT_REPORT_AT_HOURS) {\n $scheduledTime = $scheduledTime->subDay();\n }\n\n $scheduledTimeUtc = $scheduledTime->copy()->utc();\n $generatedAtUtc = $generatedAt->copy()->utc();\n $nowUtc = $now->copy()->utc();\n\n return $generatedAtUtc->lt($scheduledTimeUtc) && $nowUtc->gt($scheduledTimeUtc);\n }\n\n public function calculateFromAndToDatePeriod(\n string $frequency,\n ?Carbon $fromDate = null,\n ?Carbon $toDate = null\n ): array {\n if ($frequency === self::FREQUENCY_ONE_OFF) {\n return [\n 'fromDate' => $fromDate,\n 'toDate' => $toDate,\n ];\n }\n\n $now = Carbon::now();\n\n return match ($frequency) {\n self::FREQUENCY_DAILY => [\n 'fromDate' => $now->copy()->subDay()->startOfDay(),\n 'toDate' => $now->copy()->subDay()->endOfDay(),\n ],\n self::FREQUENCY_WEEKLY => [\n 'fromDate' => $now->copy()->subWeeks(1)->startOfDay(),\n 'toDate' => $now->copy()->subDay()->endOfDay(),\n ],\n self::FREQUENCY_MONTHLY => [\n 'fromDate' => $now->copy()->subMonths(1)->startOfDay(),\n 'toDate' => $now->copy()->subDay()->endOfDay(),\n ],\n self::FREQUENCY_QUARTERLY => [\n 'fromDate' => $now->copy()->subMonths(3)->startOfDay(),\n 'toDate' => $now->copy()->subDay()->endOfDay(),\n ],\n default => throw new InvalidArgumentException(\"Unsupported frequency: {$frequency}\"),\n };\n }\n\n private function calculateFromAndToDate(AutomatedReport $automatedReport): array\n {\n return $this->calculateFromAndToDatePeriod(\n $automatedReport->getFrequency(),\n $automatedReport->getFrom(),\n $automatedReport->getTo()\n );\n }\n\n public function getAskJiminnyGenerateReportPayload(\n AutomatedReport $automatedReport,\n AutomatedReportResult $reportResult,\n array $activityIds,\n ): array {\n return [\n 'user_question' => $automatedReport->getAskAnythingPrompt()?->getContent(),\n 'call_ids' => array_map('strval', $activityIds),\n 'team_id' => $automatedReport->getTeamId(),\n 'request_id' => $reportResult->getUuid(),\n 'callback_url' => $this->getCallbackUrl(),\n 'report_period' => $this->getReportPeriodName($reportResult),\n 'report_name' => $automatedReport->getCustomName(),\n ];\n }\n\n private function getCallbackUrl(): string\n {\n return $this->webhookService->route('jiminny.webhook.reports.ready');\n }\n\n /**\n * Validate and transform payload data for automated reports\n *\n * @param array $data\n *\n * @throws InvalidArgumentException\n *\n * @return array\n */\n private function validateAndTransformData(array $data): array\n {\n // Validate organization (team) and check feature\n $team = $this->validateOrganization($data['organization'] ?? null);\n\n $status = $this->validateReportStatus($data['report_enabled'] ?? null);\n $type = $this->validateReportType($data['report_type'] ?? null);\n $frequency = $this->validateFrequency($data['frequency'] ?? null);\n $additionalPromptInput = $this->validateAdditionalPromptInput(\n $data['additional_prompt_input'] ?? null\n );\n $customReportName = $this->validateCustomReportName($data['custom_name'] ?? null);\n\n // Prepare data for the database\n $reportData = [\n 'team_id' => $team->getId(),\n 'type' => $type,\n 'status' => $status,\n 'frequency' => $frequency,\n 'additional_prompt_input' => $additionalPromptInput,\n 'custom_name' => $customReportName,\n ];\n\n // Validate deal values\n $reportData = $this->validateDealValues($data, $reportData);\n\n // Validate date range\n $reportData = $this->validateDateRange($data, $reportData, $frequency);\n\n // Validate call durations\n $reportData = $this->validateCallDurations($data, $reportData);\n\n // Validate call types\n $reportData = $this->validateCallTypes($data, $reportData);\n\n // Validate media types\n $reportData = $this->validateMediaTypes($data, $reportData);\n\n // Validate groups\n if (isset($data['teams'])) {\n $reportData['groups'] = $this->validateAndGetGroupIds($team, $data['teams']);\n }\n\n // Validate deal stages\n $reportData = $this->validateDealStages($data, $reportData, $team, $type);\n\n // Validate playbook categories\n $reportData = $this->validatePlaybookCategories($data, $reportData, $team);\n\n // Validate recipients\n $reportData['recipients'] = [\n 'users' => $this->validateAndGetUserIdsByTeam($team, $data['recipients'] ?? []),\n ];\n\n if (isset($data['jiminny_recipients'])) {\n // Validate Jiminny recipients\n $reportData['jiminny_recipients'] = [\n 'users' => $this->validateAndGetJiminnyUserIds((array) $data['jiminny_recipients']),\n ];\n }\n\n return $reportData;\n }\n\n private function validateDealValues(array $data, array $reportData): array\n {\n if (isset($data['min_deal_value'])) {\n $reportData['deal_value_min'] = (int) $data['min_deal_value'];\n\n if ($reportData['deal_value_min'] > 4294967295 || $reportData['deal_value_min'] < 0) {\n throw new InvalidArgumentException('Min deal value should be between 0 and 4294967295');\n }\n }\n\n if (isset($data['max_deal_value'])) {\n $reportData['deal_value_max'] = (int) $data['max_deal_value'];\n\n if ($reportData['deal_value_max'] > 4294967295 || $reportData['deal_value_max'] < 0) {\n throw new InvalidArgumentException('Max deal value should be between 0 and 4294967295');\n }\n }\n\n if (isset($data['min_deal_value'], $data['max_deal_value'])\n && $data['min_deal_value'] > $data['max_deal_value']\n ) {\n throw new InvalidArgumentException('Min deal value cannot be greater than max deal value');\n }\n\n return $reportData;\n }\n\n private function validateDateRange(array $data, array $reportData, string $frequency): array\n {\n // Set date range only for one_off frequency\n if ($frequency === 'one_off') {\n if (isset($data['start_date_period'])) {\n $reportData['from'] = $this->parseDate($data['start_date_period']);\n }\n\n if (isset($data['end_date_period'])) {\n $reportData['to'] = $this->parseDate($data['end_date_period']);\n }\n\n if (empty($reportData['from']) || empty($reportData['to'])) {\n throw new InvalidArgumentException(\n 'Start date and end date are required for one_off frequency'\n );\n }\n } else {\n $reportData['from'] = null;\n $reportData['to'] = null;\n }\n\n return $reportData;\n }\n\n private function validateCallDurations(array $data, array $reportData): array\n {\n // Convert call durations from minutes to seconds\n if (isset($data['min_call_duration'])) {\n $reportData['call_duration_min'] = (int) $data['min_call_duration'] * 60;\n\n if ($reportData['call_duration_min'] > 4294967295 || $reportData['call_duration_min'] < 0) {\n throw new InvalidArgumentException('Min call duration should be between 0 and 4294967295');\n }\n }\n\n if (isset($data['max_call_duration'])) {\n $reportData['call_duration_max'] = (int) $data['max_call_duration'] * 60;\n\n if ($reportData['call_duration_max'] > 4294967295 || $reportData['call_duration_max'] < 0) {\n throw new InvalidArgumentException('Max call duration should be between 0 and 4294967295');\n }\n }\n\n return $reportData;\n }\n\n private function validateCallTypes(array $data, array $reportData): array\n {\n // Set call types\n $reportData['call_types'] = $data['call_type'] ?? [];\n if (empty($reportData['call_types'])) {\n $reportData['call_types'] = self::getCallTypes();\n }\n\n foreach ($reportData['call_types'] as $callType) {\n if (! in_array($callType, self::getCallTypes(), true)) {\n throw new InvalidArgumentException(sprintf('Call type %s is invalid', $callType));\n }\n }\n\n return $reportData;\n }\n\n private function validateMediaTypes(array $data, array $reportData): array\n {\n // Set media types from input data\n $reportData['media_types'] = $data['media_types'] ?? [];\n\n if (empty($reportData['media_types'])) {\n throw new InvalidArgumentException('Media types are required');\n }\n\n foreach ($reportData['media_types'] as $mediaType) {\n if (! in_array($mediaType, self::MEDIA_TYPES, true)) {\n throw new InvalidArgumentException(sprintf('Media type %s is invalid', $mediaType));\n }\n }\n\n return $reportData;\n }\n\n private function validateDealStages(array $data, array $reportData, Team $team, string $reportType): array\n {\n // Validate and set deal stages\n if (isset($data['deal_stage_at_call'])) {\n $reportData['deal_at_call_stages'] =\n $this->validateAndGetDealStageIds($team, $data['deal_stage_at_call'], 'Deal stage at call');\n }\n\n if (isset($data['current_deal_stage'])) {\n $reportData['current_deal_stages'] =\n $this->validateAndGetDealStageIds($team, $data['current_deal_stage'], 'Current deal stage');\n }\n\n // Ensure current_deal_stage is not provided for loss_analysis report type\n if ($reportType === self::TYPE_LOSS_ANALYSIS && ! empty($data['current_deal_stage'])) {\n throw new InvalidArgumentException('Current deal stage is not applicable for Loss Analysis reports');\n }\n\n return $reportData;\n }\n\n // transform uuid to id\n private function validatePlaybookCategories(array $data, array $reportData, Team $team): array\n {\n $key = 'playbook_categories';\n\n if (isset($data[$key])) {\n $payloadIds = $data[$key];\n $ids = [];\n\n foreach ($payloadIds as $uuid) {\n $uuid = (string) $uuid;\n\n try {\n $playbookCategory = $this->playbookCategoryRepository->findByUuid($uuid);\n } catch (Throwable $throwable) {\n Log::error(__METHOD__ . ' ' . $throwable->getMessage());\n\n throw new InvalidArgumentException(sprintf('Playbook category %s not found', $uuid));\n }\n\n if (! $playbookCategory) {\n throw new InvalidArgumentException(sprintf('Playbook category %s not found', $uuid));\n }\n\n if (! $playbookCategory->hasPlaybook()) {\n throw new InvalidArgumentException(sprintf('Playbook category %s has no playbook', $uuid));\n }\n\n if ($playbookCategory->getPlaybook()->getTeamId() !== $team->getId()) {\n throw new InvalidArgumentException(\n sprintf('Playbook category %s not found for team %s', $uuid, $team->getUuid())\n );\n }\n\n $ids[] = $playbookCategory->getId();\n }\n\n $reportData[$key] = $ids;\n }\n\n return $reportData;\n }\n\n private function validateReportStatus($status): bool\n {\n if (! in_array($status, [true, false], true)) {\n throw new InvalidArgumentException('Report status is invalid');\n }\n\n return $status;\n }\n\n private function validateReportType($type): string\n {\n if (! in_array($type, self::getTypes(), true)) {\n throw new InvalidArgumentException(sprintf('Report type is invalid: %s', $type));\n }\n\n return $type;\n }\n\n private function validateFrequency($frequency): string\n {\n if (! in_array($frequency, self::getFrequencies(), true)) {\n throw new InvalidArgumentException('Frequency is invalid');\n }\n\n return $frequency;\n }\n\n private function validateAdditionalPromptInput(?string $additionalPromptInput): ?string\n {\n if ($additionalPromptInput && strlen($additionalPromptInput) > 5000) {\n throw new InvalidArgumentException('Additional Prompt Input should be less than 5000 characters');\n }\n\n return $additionalPromptInput;\n }\n\n private function validateCustomReportName(?string $customReportName): ?string\n {\n if ($customReportName === null || $customReportName === '') {\n return null;\n }\n\n if (strlen($customReportName) > 70) {\n throw new InvalidArgumentException('Custom report name should be less than 70 characters');\n }\n\n return $customReportName;\n }\n\n private function validateOrganization(?string $organizationUuid): Team\n {\n if (! $organizationUuid) {\n throw new InvalidArgumentException('Organization is required');\n }\n\n $team = $this->teamRepository->idOrUuid($organizationUuid);\n\n if (! $team) {\n throw new InvalidArgumentException('Organization not found');\n }\n\n if (! $team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {\n throw new InvalidArgumentException('Organization does not have the Automated Reports feature');\n }\n\n return $team;\n }\n\n private function validateAndGetGroupIds(Team $team, array $teamUuids): array\n {\n $groupIds = [];\n\n foreach ($teamUuids as $uuid) {\n $group = $this->groupRepository->findByUuid($uuid);\n\n if ($group === null || $group->getTeamId() !== $team->getId()) {\n throw new InvalidArgumentException(\n sprintf('Group %s not found for team %s', $uuid, $team->getUuid())\n );\n }\n\n $groupIds[] = $group->getId();\n\n }\n\n return $groupIds;\n }\n\n private function validateAndGetDealStageIds(Team $team, array $stageUuids, string $propertyLabel): array\n {\n $stageIds = [];\n\n foreach ($stageUuids as $uuid) {\n $stage = $this->stageRepository->findByUuid($uuid);\n\n if ($stage === null || $stage->getTeamId() !== $team->getId()) {\n throw new InvalidArgumentException(\n sprintf('Stage %s not found for team %s for %s', $uuid, $team->getUuid(), $propertyLabel)\n );\n }\n\n $stageIds[] = $stage->getId();\n }\n\n return $stageIds;\n }\n\n private function validateAndGetUserIds(array $userUuids, callable $teamCheck): array\n {\n if (empty($userUuids)) {\n return [];\n }\n\n $userIds = [];\n\n foreach ($userUuids as $uuid) {\n $user = $this->userRepository->findByUuid($uuid);\n\n if (! $user || ! $user->isStatusActive()) {\n throw new InvalidArgumentException(\n sprintf('User %s not found or is not active', $uuid)\n );\n }\n\n if (! $teamCheck($user)) {\n throw new InvalidArgumentException(\n sprintf('User %s does not belong to the allowed team(s)', $uuid)\n );\n }\n\n $userIds[] = $user->getId();\n }\n\n return $userIds;\n }\n\n private function validateAndGetUserIdsByTeam(Team $team, array $userUuids): array\n {\n return $this->validateAndGetUserIds($userUuids, fn ($user) => $user->getTeamId() === $team->getId());\n }\n\n private function validateAndGetJiminnyUserIds(array $userUuids): array\n {\n $allowedTeamIds = config('kiosk.teamIds', []);\n\n return $this->validateAndGetUserIds($userUuids, fn ($user) => in_array($user->getTeamId(), $allowedTeamIds, true));\n }\n\n private function parseDate(string $dateString): string\n {\n return date('Y-m-d H:i:s', strtotime($dateString));\n }\n\n private function generateReportResultViewUrl(AutomatedReportResult $result): string\n {\n $mediaResource = $this->getReportMediaRouteResource($result);\n\n return route('ai-reports.' . $mediaResource . '.view', ['uuid' => $result->getUuid()]);\n }\n\n private function generateReportResultDownloadUrl(AutomatedReportResult $result): string\n {\n $mediaResource = $this->getReportMediaRouteResource($result);\n\n return route('ai-reports.' . $mediaResource . '.download', ['uuid' => $result->getUuid()]);\n }\n\n private function getReportMediaRouteResource(AutomatedReportResult $result): string\n {\n if ($result->getMediaType() === self::MEDIA_TYPE_PDF) {\n return self::PDF_KEY;\n } elseif ($result->getMediaType() === self::MEDIA_TYPE_PODCAST) {\n return self::AUDIO_KEY;\n }\n\n throw new \\InvalidArgumentException('Unknown media type.');\n }\n\n public function getMediaPath(AutomatedReportResult $result): ?string\n {\n $url = match ($result->getMediaType()) {\n self::MEDIA_TYPE_PDF => $result->getPdfUrl(),\n self::MEDIA_TYPE_PODCAST => $result->getPodcastAudioUrl(),\n default => null,\n };\n\n if ($url === null) {\n return null;\n }\n\n $path = parse_url(trim($url, '\"\\''), PHP_URL_PATH);\n\n return $path ?: null;\n }\n\n public function getFilenameSuffix(AutomatedReportResult $result): ?string\n {\n return match ($result->getMediaType()) {\n self::MEDIA_TYPE_PODCAST => 'Podcast',\n default => null,\n };\n }\n\n public function getMailSubjectSuffix(AutomatedReportResult $result): string\n {\n return match ($result->getMediaType()) {\n self::MEDIA_TYPE_PDF => 'report',\n self::MEDIA_TYPE_PODCAST => 'podcast',\n default => '',\n };\n }\n\n public function getMediaTypeMetadata(AutomatedReportResult $result): array\n {\n return match ($result->getMediaType()) {\n self::MEDIA_TYPE_PODCAST => ['extension' => 'mp3', 'mime' => 'audio/mpeg'],\n self::MEDIA_TYPE_PDF => ['extension' => 'pdf', 'mime' => 'application/pdf'],\n default => ['extension' => null, 'mime' => null],\n };\n }\n\n public function deleteS3Files(AutomatedReportResult $result): void\n {\n $teamUuid = $result->getReport()->getTeam()->getUuid();\n $reportUuid = $result->getUuid();\n\n // delete all files for a report uuid no mather of pdf, podcast, or both\n // in case of both - the podcast files are linked to the pdf (parent) uuid\n // pdf and podcast date times should be close\n $path = sprintf('%s/%s/%s', $teamUuid, self::S3_DIR, $reportUuid);\n\n foreach (self::FILE_EXTENSIONS_VARIANTS as $extension) {\n $file = $path . '.' . $extension;\n\n if (Storage::exists($file)) {\n Storage::delete($file);\n Log::info('[Reports] Deleted S3 file', [\n 'path' => $file,\n ]);\n }\n }\n\n foreach (self::FILE_PODCAST_EXTENSIONS_VARIANTS as $extension) {\n $file = $path . '_podcast.' . $extension;\n\n if (Storage::exists($file)) {\n Storage::delete($file);\n Log::info('[Reports] Deleted Podcast S3 file', [\n 'path' => $file,\n ]);\n }\n }\n }\n\n /**\n *\n * @param int|null $teamId Optional team ID to filter results\n *\n * @return Collection<int, int> Collection of team IDs\n */\n public function getTeamIdsWithReportsResults(?int $teamId = null): Collection\n {\n return $this->automatedReportsRepository->getTeamIdsWithReportsResults($teamId);\n }\n\n /**\n * Core delete logic for report results using a query\n *\n * @param Builder $query\n * @param array $logContext\n *\n * @return int\n */\n private function deleteReportResultsByQuery(Builder $query, array $logContext = []): int\n {\n $deletedCount = 0;\n\n if ($query->exists()) {\n Log::info(\n 'Run delete report results',\n array_merge(\n $logContext,\n [\n 'service' => 'AutomatedReportsService',\n ]\n )\n );\n\n $query->chunkById(50, function ($results) use (&$deletedCount, $logContext) {\n foreach ($results as $result) {\n $this->deleteReportResult($result);\n $deletedCount++;\n\n Log::info(\n 'Deleted a report result',\n array_merge(\n $logContext,\n [\n 'result_id' => $result->getId(),\n 'report_id' => $result->getReportId(),\n ]\n )\n );\n }\n });\n }\n\n return $deletedCount;\n }\n\n /**\n * Delete report results for a team by retention period\n *\n * @param Team $team\n * @param CarbonImmutable $retentionDate\n *\n * @return int Number of deleted report results\n */\n public function deleteReportsResultsInRetentionPeriod(Team $team, CarbonImmutable $retentionDate): int\n {\n $reportIds = $this->automatedReportsRepository->getReportIdsByTeam($team);\n\n if ($reportIds->isEmpty()) {\n return 0;\n }\n\n $query = $this->automatedReportsRepository\n ->getReportResultsQueryForRetention($team, $retentionDate);\n\n return $this->deleteReportResultsByQuery($query, [\n 'team_id' => $team->getId(),\n 'retention_date' => $retentionDate->toDateTimeString(),\n ]);\n }\n\n /**\n * Delete ALL report results for a specific automated report\n *\n * @param string $uuid\n *\n * @return int\n */\n public function deleteReportResults(string $uuid): int\n {\n $report = $this->getReport($uuid);\n\n $query = $this->automatedReportsRepository->getResultsByReportQuery($report);\n\n return $this->deleteReportResultsByQuery($query, [\n 'report_uuid' => $uuid,\n 'report_id' => $report->getId(),\n ]);\n }\n\n public function deleteReportResult(AutomatedReportResult $result): void\n {\n $this->deleteS3Files($result);\n\n $result->delete();\n }\n\n /**\n * Get all reports for a specific team\n *\n * @param Team $team\n *\n * @return \\Illuminate\\Database\\Eloquent\\Collection\n */\n public function getTeamReports(Team $team): \\Illuminate\\Database\\Eloquent\\Collection\n {\n return $this->automatedReportsRepository->getReportsByTeam($team);\n }\n\n /**\n * Get all report results for a specific report\n *\n * @param AutomatedReport $report\n *\n * @return \\Illuminate\\Database\\Eloquent\\Collection\n */\n public function getReportResults(AutomatedReport $report): \\Illuminate\\Database\\Eloquent\\Collection\n {\n return $this->automatedReportsRepository->getResultsByReport($report);\n }\n\n public function deleteAllReportResults(AutomatedReport $report): void\n {\n $results = $this->getReportResults($report);\n\n /** @var AutomatedReportResult $result */\n foreach ($results as $result) {\n Log::info('Deleting result', [\n 'report' => $report->getId(),\n 'result' => $result->getId(),\n ]);\n\n $this->deleteReportResult($result);\n }\n }\n\n public function deleteAllData(Team $team): void\n {\n Log::info('Deleting automated report and results for team', [\n 'team' => $team->getId(),\n ]);\n\n $reports = $this->getTeamReports($team);\n\n /** @var AutomatedReport $report */\n foreach ($reports as $report) {\n Log::info('Deleting report', [\n 'team' => $team->getId(),\n 'report' => $report->getId(),\n ]);\n\n $this->deleteAllReportResults($report);\n\n $report->delete();\n }\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":true,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"Project","depth":3,"role_description":"text"},{"role":"AXButton","text":"Project","depth":3,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"New File or Directory…","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Expand Selected","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Collapse All","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Options","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false}]...
|
3397592283435315795
|
6686367547760219213
|
idle
|
accessibility
|
NULL
|
Project: faVsco.js, menu
#11894 on JY-18909-automa Project: faVsco.js, menu
#11894 on JY-18909-automated-reports-ask-jiminny, menu
Start Listening for PHP Debug Connections
AutomatedReportsCommandTest
Run 'AutomatedReportsCommandTest'
Debug 'AutomatedReportsCommandTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Execute
Explain Plan
Browse Query History
View Parameters
Open Query Execution Settings…
In-Editor Results
Tx: Auto
Cancel Running Statements
Playground
jiminny
Sync Changes
Hide This Notification
Code changed:
Hide
16
13
13
Previous Highlighted Error
Next Highlighted Error
SELECT * FROM teams WHERE id = 1;
select * from crm_layouts where crm_configuration_id = 39;
SELECT * FROM crm_layout_entities WHERE crm_layout_id = 283;
SELECT * FROM crm_fields WHERE id = 2234;
SELECT * FROM crm_field_values WHERE crm_field_id = 2234;
select * from crm_profiles where user_id = 143;
select * from record_types where crm_configuration_id = 39; # 0121K000001MHElQAO,0121K000001MHEqQAO
select * from business_processes where crm_configuration_id = 39;
# 01941000000H669AAC, 01941000000H66JAAS
select * from record_type_field_values
where record_type_id IN (24);
select * from crm_field_values where id IN (2730);
select * from crm_configurations where id = 39;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 1
and sa.provider = 'salesforce'; #1035
select * from users where team_id = 1; # 222 group 3
SELECT * FROM activities WHERE user_id = 222 order by id desc;
select * from sidekick_settings where team_id = 1;
select * from teams where id = 1;
select * from team_features where team_id = 1;
select * from activities where crm_configuration_id = 2
and provider = 'ms-teams' and id = 608765;
SELECT * FROM activities WHERE crm_configuration_id = 2 and crm_provider_id = '59523413338';
select * from sidekick_settings where team_id = 2;
SELECT * FROM activities WHERE id = 608660;
select * from activity_summary_logs where activity_id = 608660;
select * from ai_prompts where transcription_id = 11214;
# [PASSWORD_DOTS]
SELECT * FROM activities WHERE uuid_to_bin('ed78a437-2804-450e-ab2f-56ab1c641346') = uuid;
# id: 608818, crm: 59628809737
SELECT * FROM activities WHERE uuid_to_bin('36b06e55-afdd-4782-8dee-c624cd0af191') = uuid;
# id: 608821, crm: 59632069252
SELECT ce.start_time, ce.end_time, a.id, a.uuid, crm_provider_id, calendar_event_id, title,
playbook_category_id, user_id, lead_id, contact_id, account_id, opportunity_id,
scheduled_start_time, scheduled_end_time, actual_start_time, actual_end_time, a.created_at
FROM activities a
join calendar_events ce on a.calendar_event_id = ce.id
WHERE a.id IN (608818, 608821);
select * from users where team_id = 1;
select * from team_settings where team_id = 1;
select * from crm_profiles where crm_configuration_id = 39 order by user_id;
select * from team_features where team_id = 1;
select * from users where team_id = 2;
SELECT * FROM activities WHERE uuid_to_bin('ec7647e9-5225-458b-b475-f31aa2769204') = uuid; # 612639
# Preslava N. Ivanova, grou id 3
SELECT * FROM opportunities WHERE uuid_to_bin('a2928fe5-aec5-46cb-85d9-7654c89e46a6') = uuid;
select * from activities where opportunity_id = 344 and actual_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00';
select
a.id,
a.type,
a.scheduled_start_time,
a.actual_start_time,
a.created_at,
a.opportunity_id,
a.status
FROM activities a
WHERE opportunity_id = 344
and status IN ('completed', 'received', 'delivered')
and (
(a.actual_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00')
OR (a.created_at between '2024-10-11 00:00:00' and '2024-10-12 00:00:00')
OR (a.scheduled_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00'))
;
SELECT * FROM users WHERE id = 222;
SELECT * FROM crm_profiles WHERE user_id = 222;
select * from crm_layouts where crm_configuration_id = 39;
SELECT * FROM crm_layout_entities WHERE crm_layout_id = 281;
select * from group_deal_risk_types;
select * from opportunities where team_id = 1;
SELECT * FROM opportunities WHERE id = 315;
SELECT * FROM crm_field_data WHERE object_id = 315;
select * from crm_field_data where object_id = 260;
select * from generic_ai_prompts where subject_id = 315;
select * from teams; # 36, 21, 121, [EMAIL]
SELECT * FROM social_accounts WHERE sociable_id = 121 and provider = 'bullhorn';
# [PASSWORD_DOTS]
select * from teams where id = 1;
select * from crm_configurations where id = 39;
select * from users where team_id = 1;
select u.email, cp.* from users u
join crm_profiles cp on u.id = cp.user_id
where u.team_id = 1;
# 1 - 00541000004281rAAA
# 204 - 0052g000003freeAAA
# 429 - 0052g000003qGOiAAM
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 1
and sa.provider = 'salesforce';
select * from activities where type = 'softphone'
and created_at > '2024-12-11 15:24:36' order by id desc;
select * from activity_providers where team_id = 1;
select * from activity_provider_users where activity_provider_id = 328;
select * from opportunities where crm_configuration_id = 39
AND account_id = 178 AND is_closed = false
order by created_at DESC;
select * from contacts where id = 3952;
select * from accounts where id = 178;
# [PASSWORD_DOTS]
select * from teams where id = 36;
select * from crm_configurations where id = 21;
select * from users where team_id = 36;
select u.email, cp.* from users u
join crm_profiles cp on u.id = cp.user_id
where u.team_id = 36;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 36
and sa.provider = 'bullhorn';
select * from social_accounts where id = 348;
UPDATE social_accounts SET
provider_user_token = '21442_6802599_91:41179a58-21e7-4d7c-ad58-56bb666b2f65',
provider_refresh_token = '21442_6802599_91:01c6b335-3f2a-42e4-85ff-8a08fa65fceb',
expires = 1733998131,
state = 'connected'
WHERE id = 348;
# [PASSWORD_DOTS]
select * from teams where id = 31;
select * from crm_configurations where id = 18;
select * from users where team_id = 31; # 257
select u.email, cp.* from users u
join crm_profiles cp on u.id = cp.user_id
where u.team_id = 31;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 31
and sa.provider = 'close';
select * from contacts where crm_configuration_id = 18;
# [PASSWORD_DOTS] NEPTUNE [PASSWORD_DOTS]
select * from teams;
select * from users where id IN (1030, 1035, 1052);
select * from crm_configurations;
select * from users where team_id = 65; # 257
select * from team_settings where team_id = 65; # 257
select * from invitations where team_id = 65; # 257
select * from users where email = '[EMAIL]'; # 257
select u.email, cp.* from users u
join crm_profiles cp on u.id = cp.user_id
where u.team_id = 65;
select * from crm_configurations where id = 53;
select * from accounts where crm_configuration_id = 53 order by id desc;
select * from leads where crm_configuration_id = 53 order by id desc;
select * from contacts where crm_configuration_id = 53 order by id desc;
select * from opportunities where crm_configuration_id = 53 order by id desc;
select * from crm_profiles where crm_configuration_id = 53 order by id desc;
select * from crm_fields where crm_configuration_id = 53 order by id desc;
select * from crm_field_values where crm_field_id = 3341 order by id desc;
select * from crm_layouts where crm_configuration_id = 53 order by id desc;
select * from stages where crm_configuration_id = 53 order by id desc;
select * from crm_profiles where crm_configuration_id = 13;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 65
and sa.provider = 'integration-app';
select * from contacts where crm_configuration_id = 13;
select * from social_accounts where sociable_id = 283;
SELECT * FROM opportunities WHERE crm_provider_id = '006O400000E9bzeIAB';
select * from activity_providers where team_id = 65;
SELECT * FROM activities WHERE crm_configuration_id IN (51, 52, 53);
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 65
;
# [PASSWORD_DOTS] STAGING [PASSWORD_DOTS]
SELECT * FROM teams;
SELECT * FROM teams WHERE id = 88;
SELECT * FROM teams WHERE id = 89;
select * from team_settings where team_id = 89;
SELECT * FROM users WHERE team_id = 89;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 89;
select * from users;
SELECT * FROM social_accounts WHERE sociable_id = 1761;
SELECT * FROM crm_configurations WHERE id = 70;
select * from accounts where crm_configuration_id = 70 order by id desc;
select * from leads where crm_configuration_id = 70 order by id desc;
select * from contacts where crm_configuration_id = 70 order by id desc;
select * from opportunities where crm_configuration_id = 70 order by id desc;
select * from crm_profiles where crm_configuration_id = 70 order by id desc;
select * from crm_fields where crm_configuration_id = 70 order by id desc;
select * from crm_field_values where crm_field_id = 3536 order by id desc;
select * from crm_layouts where crm_configuration_id = 70 order by id desc;
select * from stages where crm_configuration_id = 70 order by id desc;
select * from business_processes where crm_configuration_id = 70 order by id desc;
select * from business_process_stages where business_process_id = 34;
select * from contacts where id = 10468;
select * from crm_layouts where crm_configuration_id = 70;
SELECT * FROM crm_layout_entities WHERE crm_layout_id = 388;
SELECT * FROM crm_fields WHERE id IN (3533,3534,3535);
select * from activities where crm_configuration_id = 70
and (account_id IS NOT NULL or lead_id IS NOT NULL or contact_id IS NOT NULL or opportunity_id IS NOT NULL) order by id desc;
SELECT * FROM activities WHERE uuid_to_bin('2e10b60f-8a61-41c5-a3d4-28835353dc65') = uuid;
SELECT * FROM activities where crm_configuration_id = 69 ;
SELECT * FROM users WHERE email LIKE '%[EMAIL]%';
SELECT * FROM activities WHERE uuid_to_bin('5a150c93-40fc-42ec-b3bd-c1d328e09f6e') = uuid;
SELECT * FROM opportunities WHERE id = 385;
select * from participants p
join activities a on p.activity_id = a.id
where a.crm_configuration_id = 70
and (p.lead_id IS NOT NULL or p.contact_id IS NOT NULL);
SELECT * FROM participants WHERE id = 1013638;
select * from teams where id = 90;
select * from users where team_id = 90;
select * from social_accounts where social_accounts.sociable_id IN (1960,1760);
SELECT * FROM crm_profiles WHERE crm_configuration_id = 71;
select * from invitations where team_id = 90;
select * from crm_configurations where id = 71;
select * from accounts where crm_configuration_id = 71 order by id desc;
select * from leads where crm_configuration_id = 71 order by id desc;
select * from contacts where crm_configuration_id = 71 order by id desc;
select * from opportunities where crm_configuration_id = 71 order by id desc;
select * from crm_profiles where crm_configuration_id = 71 order by id desc;
select * from crm_fields where crm_configuration_id = 71 order by id desc;
select * from crm_field_values where crm_field_id = 3341 order by id desc;
select * from crm_layouts where crm_configuration_id = 71 order by id desc;
select * from stages where crm_configuration_id = 71 order by id desc;
select * from users order by secondary_email desc;
select u.id, u.email, u.status, sa.id, sa.provider_user_id from social_accounts sa
join users u on sa.sociable_id = u.id
where sa.provider = 'google' and u.email LIKE 'aneliya%';
select * from failed_jobs order by id desc;
select * from users where email = '[EMAIL]' or secondary_email = '[EMAIL]';
select * from teams;
SELECT * FROM crm_profiles WHERE crm_configuration_id = 39;
SELECT * FROM crm_fields WHERE crm_configuration_id = 39 and object_type = 'task';
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 1
and sa.provider = 'salesforce';
# [PASSWORD_DOTS]
SELECT * FROM activities WHERE uuid_to_bin('c38b3895-fd0f-4b1f-9fb2-c170dba137c6') = uuid;
SELECT * FROM crm_configurations WHERE id = 70;
select * from teams where id = 1;
select * from groups where team_id = 1;
select * from users where team_id = 1;
select o.id, o.name,o.close_date, u.id, u.name, u.group_id, r.id, r.display_name, g.name, g.scope from opportunities o
join users u on o.user_id = u.id
join groups g on u.group_id = g.id
join role_user ru on u.id = ru.user_id
join roles r on ru.role_id = r.id
where o.crm_configuration_id = 39 and close_date > '2024-01-01 00:00:00';
select * from role_user where user_id = 143;
select * from roles;
select * from role_user;
select * from groups where id = 9;
select * from scope_groups where group_id = 9;
# [PASSWORD_DOTS]
select * from teams where id = 36;
select * from crm_configurations;
SELECT * FROM social_accounts WHERE sociable_id = 121;
[URL_WITH_CREDENTIALS] this will add filter, however if we need to control feature by FF we need conditional logic
public const array TYPES = [
['id' => 'exec_summary', 'name' => 'Exec Summary'],
['id' => 'coaching_profiles', 'name' => 'Coaching Profiles'],
['id' => 'product_feedback', 'name' => 'Product Feedback'],
['id' => self::TYPE_LOSS_ANALYSIS, 'name' => 'Loss Analysis'],
// ['id' => 'questions', 'name' => 'Questions'],
// ['id' => 'statistical_quant', 'name' => 'Statistical Quantitative'],
];
public const array ALL_TYPES = [
...self::TYPES,
['id' => self::TYPE_ASK_JIMINNY, 'name' => 'Ask Jiminny'],
];
public const string FREQUENCY_DAILY = 'daily';
public const string FREQUENCY_WEEKLY = 'weekly';
public const string FREQUENCY_MONTHLY = 'monthly';
public const string FREQUENCY_QUARTERLY = 'quarterly';
public const string FREQUENCY_ONE_OFF = 'one_off';
/**
* Frequencies for standard (non-Ask Jiminny) reports.
*/
public const array FREQUENCIES = [
['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],
['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],
['id' => self::FREQUENCY_QUARTERLY, 'name' => 'Quarterly'],
['id' => self::FREQUENCY_ONE_OFF, 'name' => 'One-off'],
];
/**
* Frequencies for Ask Jiminny reports.
*/
public const array ASK_JIMINNY_FREQUENCIES = [
['id' => self::FREQUENCY_DAILY, 'name' => 'Daily'],
['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],
['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],
];
public const string MEDIA_TYPE_PDF = 'pdf';
public const string MEDIA_TYPE_PODCAST = 'podcast';
public const array MEDIA_TYPES = [self::MEDIA_TYPE_PDF, self::MEDIA_TYPE_PODCAST];
public const array MEDIA_TYPE_OBJECT_PDF = ['id' => self::MEDIA_TYPE_PDF, 'name' => 'PDF'];
public const array MEDIA_TYPE_OBJECT_PODCAST = ['id' => self::MEDIA_TYPE_PODCAST, 'name' => 'Podcast'];
public const array MEDIA_TYPE_OBJECTS = [self::MEDIA_TYPE_OBJECT_PDF, self::MEDIA_TYPE_OBJECT_PODCAST];
public const array CALL_TYPE_CONFERENCE = ['id' => 'conference', 'name' => 'Conference'];
public const array CALL_TYPE_DIALER = ['id' => 'dialer', 'name' => 'Dialer'];
public const int SENT_REPORT_AT_HOURS = 5;
public const string PDF_KEY = 'pdf';
public const string AUDIO_KEY = 'audio';
private const array ALL_FREQUENCIES = [
['id' => self::FREQUENCY_DAILY, 'name' => 'Daily'],
['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],
['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],
['id' => self::FREQUENCY_QUARTERLY, 'name' => 'Quarterly'],
['id' => self::FREQUENCY_ONE_OFF, 'name' => 'One-off'],
];
private const string S3_DIR = 'reports';
private const array FILE_EXTENSIONS_VARIANTS = ['html', 'MD', 'pdf'];
private const array FILE_PODCAST_EXTENSIONS_VARIANTS = ['json', 'mp3', 'ssml'];
public function __construct(
private readonly TeamRepository $teamRepository,
private readonly GroupRepository $groupRepository,
private readonly UserRepository $userRepository,
private readonly StageRepository $stageRepository,
private readonly DealStagesService $dealStagesService,
private readonly RecipientsService $recipientsService,
private readonly AutomatedReportsRepository $automatedReportsRepository,
private readonly Webhook $webhookService,
private readonly BusDispatcher $dispatcher,
private readonly ActivityTypeService $activityTypeService,
private readonly PlaybookCategoryRepository $playbookCategoryRepository,
private readonly AskAnythingPromptService $askAnythingPromptService,
private readonly SearchRepository $activitySearchRepository,
private readonly AskAnythingRepository $askAnythingRepository,
) {
}
public static function getTypes(): array
{
$types = self::TYPES;
return array_map(static function ($type) {
return $type['id'];
}, $types);
}
public static function getCallTypes(): array
{
return array_map(static function ($callType) {
return $callType['id'];
}, [self::CALL_TYPE_CONFERENCE, self::CALL_TYPE_DIALER]);
}
public static function getFrequencies(): array
{
return array_map(static function ($frequency) {
return $frequency['id'];
}, self::FREQUENCIES);
}
// front-facing structure
public function getReportEnabledFieldData(bool $value = false): array
{
return [
'id' => 'report_enabled',
'label' => '',
'inputType' => InputTypeEnum::TOGGLE,
'value' => $value,
];
}
// Organizations = Teams
public function getOrganizationFieldData(?string $value = null, bool $shortVersion = false): array
{
$options = $this->getTeams();
if ($shortVersion) {
return [
'id' => 'organization',
'label' => 'Organization',
'options' => $options,
];
}
return [
'id' => 'organization',
'label' => 'Organization',
'inputType' => InputTypeEnum::DROPDOWN,
'required' => true,
'placeholder' => 'Select',
'options' => $options,
'value' => $value,
'dependencies' => [
'teams',
'deal_stage_at_call',
'current_deal_stage',
'recipients',
ActivityTypeService::PLAYBOOK_CATEGORIES_KEY,
],
'dependsOn' => [],
];
}
// Teams = Groups
public function getTeamFieldData(array $options = [], array $value = [], bool $shortVersion = false): array
{
if ($shortVersion) {
return [
'id' => 'teams',
'label' => 'Team',
'options' => $options,
];
}
return [
'id' => 'teams',
'label' => 'Team',
'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,
'required' => false,
'placeholder' => 'Select',
'options' => $options,
'value' => $value, // value should be an array of objects {id, name}
'dependencies' => [ActivityTypeService::PLAYBOOK_CATEGORIES_KEY],
'dependsOn' => [],
];
}
public function getReportTypeFieldData(?string $value = null, bool $shortVersion = false, ?Team $team = null): array
{
$types = [];
if ($team instanceof Team) {
if ($team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {
$types = self::TYPES;
}
if ($team->hasFeature(FeatureEnum::ASK_JIMINNY_REPORTS)) {
$types[] = ['id' => self::TYPE_ASK_JIMINNY, 'name' => 'Ask Jiminny'];
}
} else {
$types = self::TYPES;
}
if ($shortVersion) {
return [
'id' => 'report_type',
'label' => 'Report Type',
'options' => $types,
];
}
return [
'id' => 'report_type',
'label' => 'Report Type',
'inputType' => InputTypeEnum::DROPDOWN,
'required' => true,
'placeholder' => 'Select',
'options' => $types,
'value' => $value,
'dependencies' => [],
'dependsOn' => [],
];
}
public function getFrequencyFieldData(?string $value = null): array
{
return [
'id' => 'frequency',
'label' => 'Frequency',
'inputType' => InputTypeEnum::DROPDOWN,
'required' => true,
'placeholder' => 'Select',
'options' => self::FREQUENCIES,
'value' => $value,
'dependencies' => ['period'],
'dependsOn' => [],
];
}
public function getPeriodFieldData(?string $valueStartDate = null, ?string $valueEndDate = null): array
{
return [
'id' => 'period',
'label' => 'Select one-off period',
'inputType' => InputTypeEnum::DATE_RANGE,
'required' => true,
'placeholder' => 'Select',
'value' => ['startDate' => $valueStartDate, 'endDate' => $valueEndDate],
'queryParams' => [
'startDate' => 'start_date_period',
'endDate' => 'end_date_period',
],
'dependencies' => [],
'dependsOn' => ['frequency'],
];
}
public function getActivityTypesFieldData(?Team $team = null, array $value = [], array $teamsFilter = []): array
{
return $this->activityTypeService->getActivityTypeFieldData(team: $team, value: $value, groupIds: $teamsFilter);
}
public function getDealStageAtCallFieldData(?Team $team = null, array $value = []): array
{
return $this->dealStagesService->getDealStageAtCallFieldData(team: $team, value: $value);
}
public function getCurrentDealStageFieldData(?Team $team = null, array $value = []): array
{
return $this->dealStagesService->getCurrentDealStageFieldData(team: $team, value: $value);
}
public function getDealValueFieldData(?int $valueMin = null, ?int $valueMax = null): array
{
return [
'id' => 'deal_value',
'label' => 'Deal Value',
'inputType' => InputTypeEnum::INTEGER_RANGE,
'required' => false,
'value' => ['min' => $valueMin, 'max' => $valueMax],
'queryParams' => [
'min' => 'min_deal_value',
'max' => 'max_deal_value',
],
'dependencies' => [],
'dependsOn' => [],
];
}
public function getCallTypeFieldData(bool $conferenceOn = false, bool $dialerOn = false): array
{
$value = [];
$conferenceOn && $value[] = self::CALL_TYPE_CONFERENCE;
$dialerOn && $value[] = self::CALL_TYPE_DIALER;
return [
'id' => 'call_type',
'label' => 'Call Type',
'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,
'required' => true,
'options' => [
self::CALL_TYPE_CONFERENCE,
self::CALL_TYPE_DIALER,
],
'value' => $value,
'dependencies' => [],
'dependsOn' => [],
];
}
public function getMediaTypeFieldData(?AutomatedReport $report = null): array
{
$value = [];
if ($report) {
$value = $this->transformMediaTypes($report);
}
return [
'id' => 'media_types',
'label' => 'Export as',
'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,
'required' => true,
'options' => self::MEDIA_TYPE_OBJECTS,
'value' => $value,
'dependencies' => [],
'dependsOn' => [],
];
}
public function getCallDurationFieldData(?int $valueMin = null, ?int $valueMax = null): array
{
return [
'id' => 'call_duration',
'label' => 'Call Duration',
'inputType' => InputTypeEnum::INTEGER_RANGE,
'required' => false,
'value' => ['min' => $valueMin, 'max' => $valueMax],
'queryParams' => [
'min' => 'min_call_duration',
'max' => 'max_call_duration',
],
'dependencies' => [],
'dependsOn' => [],
];
}
public function getRecipientsFieldData(?Team $team = null, array $value = []): array
{
return $this->recipientsService->getRecipientsFieldData(team: $team, value: $value);
}
public function getJiminnyRecipientsFieldData(array $value = []): array
{
return $this->recipientsService->getJiminnyRecipientsFieldData($value);
}
public function getAdditionalPromptInputFieldData(?string $value = null): array
{
return [
'id' => 'additional_prompt_input',
'label' => 'Special requirements',
'inputType' => InputTypeEnum::TEXTAREA,
'required' => false,
'placeholder' => 'What should be the focus of the report?',
'value' => $value,
'dependencies' => [],
'dependsOn' => [],
];
}
public function getCustomReportNameFieldData(?string $value = null): array
{
return [
'id' => 'custom_name',
'label' => 'Custom report name',
'inputType' => InputTypeEnum::TEXT,
'required' => false,
'placeholder' => 'Enter custom name',
'value' => $value,
'dependencies' => [],
'dependsOn' => [],
];
}
// data providers
public function getTeams(): array
{
$teams = $this->teamRepository->getTeamsForKiosk(status: Team::STATUS_ACTIVE);
$teamData = [];
foreach ($teams as $team) {
if (! $team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {
continue;
}
$teamData[] = $this->transformTeam($team);
}
return $teamData;
}
public function getTeamGroups(string $teamUuid): array
{
$data = [];
$team = $this->getTeam($teamUuid);
if ($team !== null) {
$groups = $team->groups()->get();
foreach ($groups as $group) {
$data[] = [
'id' => $group->getUuid(),
'name' => $group->getName(),
];
}
}
return $data;
}
public function getTeamsGroupsOptions(array $filterTeamUuids = []): array
{
$data = [];
$teams = $this->getTeams();
foreach ($teams as $team) {
if (! empty($filterTeamUuids) && ! in_array($team['id'], $filterTeamUuids, true)) {
continue;
}
$data[] = [
'label' => $team['name'],
'groups' => $this->getTeamGroups($team['id']),
];
}
return $data;
}
public function getTeam(string $teamUuid): ?Team
{
return $this->teamRepository->idOrUuid($teamUuid);
}
public function getTeamById(int $teamId): ?Team
{
return $this->teamRepository->find($teamId);
}
public function getGroupsUuids(AutomatedReport $report): array
{
$uuids = [];
$reportGroups = $report->getGroups();
foreach ($reportGroups as $groupId) {
if ($group = $this->groupRepository->find($groupId)) {
$uuids[] = $group->getUuid();
}
}
return $uuids;
}
public function getPlaybookCategoriesUuids(AutomatedReport $report): array
{
$uuids = [];
$playbookCategories = $report->getPlaybookCategories();
foreach ($playbookCategories as $id) {
if ($category = $this->playbookCategoryRepository->find($id)) {
$uuids[] = $category->getUuid();
}
}
return $uuids;
}
public function getDealAtCallStagesUuids(AutomatedReport $report): array
{
$uuids = [];
$reportStages = $report->getDealAtCallStages();
foreach ($reportStages as $id) {
if ($stage = $this->stageRepository->find($id)) {
$uuids[] = $stage->getUuid();
}
}
return $uuids;
}
public function getCurrentDealStagesUuids(AutomatedReport $report): array
{
$uuids = [];
$reportStages = $report->getCurrentDealStages();
foreach ($reportStages as $id) {
if ($stage = $this->stageRepository->find($id)) {
$uuids[] = $stage->getUuid();
}
}
return $uuids;
}
public function getUsersUuids(AutomatedReport $report): array
{
return $this->extractUserUuids($report->getRecipients());
}
public function getJiminnyUsersUuids(AutomatedReport $report): array
{
return $this->extractUserUuids($report->getJiminnyRecipients());
}
/**
* @param array<string, mixed> $recipients
*/
private function extractUserUuids(array $recipients): array
{
$userIds = $recipients['users'] ?? [];
return collect($userIds)
->map(fn ($id) => $this->userRepository->find((int) $id))
->filter()
->map(fn (UserContract $user) => $user->getUuid())
->values()
->all();
}
// get mail data
public function getRecipientUsers(AutomatedReport $report): array
{
return $this->buildRecipientUsers($report->getRecipients());
}
private function getJiminnyRecipientUsers(AutomatedReport $report): array
{
return $this->buildRecipientUsers($report->getJiminnyRecipients());
}
/**
* @param array<string, mixed> $recipients
*/
private function buildRecipientUsers(array $recipients): array
{
$userIds = $recipients['users'] ?? [];
return collect($userIds)
->map(fn ($id) => $this->userRepository->find((int) $id))
->filter()
->map(fn (UserContract $user) => [
'email' => $user->getEmailAddress(),
'name' => $user->getName(),
'timezone' => $user->getTimezone()->getName(),
])
->values()
->all();
}
public function getValidRecipientUsers(AutomatedReport $report, bool $includeJiminny = false): array
{
if ($report->isAskJiminnyReport()) {
$recipients = $this->resolveAskJiminnyRecipients($report);
} else {
$recipients = $this->getRecipientUsers($report);
if ($includeJiminny) {
$recipients = array_merge($recipients, $this->getJiminnyRecipientUsers($report));
}
}
$emails = [];
return array_values(array_filter(
$recipients,
static function ($recipient) use (&$emails) {
if (empty($recipient['email']) || in_array($recipient['email'], $emails, true)) {
return false;
}
$emails[] = $recipient['email'];
return true;
}
));
}
private function resolveAskJiminnyRecipients(AutomatedReport $report): array
{
$recipients = [];
$creator = $report->getCreator();
if ($creator !== null) {
$recipients[] = [
'email' => $creator->getEmailAddress(),
'name' => $creator->getName(),
'timezone' => $creator->getTimezone()->getName(),
];
}
return array_merge(
$recipients,
$this->buildRecipientUsers($report->getRecipients()),
$this->getGroupRecipientUsers($report),
);
}
private function getGroupRecipientUsers(AutomatedReport $report): array
{
$users = [];
foreach ($report->getGroups() as $groupId) {
$group = $this->groupRepository->find($groupId);
if ($group === null) {
continue;
}
foreach ($group->getMembers() as $member) {
$users[] = [
'email' => $member->getEmailAddress(),
'name' => $member->getName(),
'timezone' => $member->getTimezone()->getName(),
];
}
}
return $users;
}
public function getReportTypeName(AutomatedReportResult $report): string
{
$type = $report->getReport()->getType();
$getType = $this->transformReportType($type);
return $getType['name'];
}
public function getReportPeriodName(AutomatedReportResult $report): string
{
$from = $report->getFromDate();
$to = $report->getToDate();
$frequency = $report->getReport()->getFrequency();
if ($from === null || $to === null) {
if (! $report->getReport()->isAskJiminnyReport()) {
$invalidPeriod = $from === null ? 'from' : 'to';
throw new ApplicationException('Report period is invalid: ' . $invalidPeriod);
}
$period = $this->calculateFromAndToDatePeriod($frequency);
$from = $period['fromDate'];
$to = $period['toDate'];
}
return $this->formatReportPeriodName($frequency, $from, $to);
}
private function formatReportPeriodName(string $frequency, Carbon $from, Carbon $to): string
{
$fromYear = $from->format('Y');
$toYear = $to->format('Y');
$differentYears = $fromYear !== $toYear;
switch ($frequency) {
case self::FREQUENCY_DAILY:
return $from->format('j M Y');
case self::FREQUENCY_QUARTERLY:
// 'Jan-Mar 2025' or 'Nov 2024-Jan 2025' if years differ
$startMonth = $from->format('M');
$endMonth = $to->copy()->subMonth();
$endMonthName = $endMonth->format('M');
$endMonthYear = $endMonth->format('Y');
if ($differentYears) {
return "{$startMonth} {$fromYear} - {$endMonthName} {$endMonthYear}";
}
return "{$startMonth} - {$endMonthName} {$toYear}";
case self::FREQUENCY_MONTHLY:
// 'May 2025' - monthly reports are always within the same year
return $from->format('M Y');
case self::FREQUENCY_WEEKLY:
// '4 - 8 Aug 2025', '27 Oct - 3 Nov 2025', or '28 Dec 2024 - 3 Jan 2025' if years differ
$startDay = $from->format('j');
$endDay = $to->format('j');
$startMonth = $from->format('M');
$endMonth = $to->format('M');
if ($differentYears) {
return "{$startDay} {$startMonth} {$fromYear} - {$endDay} {$endMonth} {$toYear}";
}
if ($startMonth !== $endMonth) {
return "{$startDay} {$startMonth} - {$endDay} {$endMonth} {$toYear}";
}
return "{$startDay} - {$endDay} {$endMonth} {$toYear}";
case self::FREQUENCY_ONE_OFF:
// '2 May-31 May 2025' or '15 Dec 2024-15 Jan 2025' if years differ
$startDay = $from->format('j');
$startMonth = $from->format('M');
$endDay = $to->format('j');
$endMonth = $to->format('M');
// If same month and year, use a format like '2-31 May 2025'
if ($startMonth === $endMonth && ! $differentYears) {
return "{$startDay} - {$endDay} {$startMonth} {$toYear}";
}
// If different years, include both years
if ($differentYears) {
return "{$startDay} {$startMonth} {$fromYear} - {$endDay} {$endMonth} {$toYear}";
}
// Same year but different months
return "{$startDay} {$startMonth} - {$endDay} {$endMonth} {$toYear}";
default:
// Default format for unknown frequencies
return $from->format('j M Y') . ' - ' . $to->format('j M Y');
}
}
public function getReportTeamsName(AutomatedReportResult $report): string
{
$groups = $report->getGroups();
if (empty($groups)) {
return 'All';
}
// Get group names from repository
$groupNames = [];
foreach ($groups as $groupId) {
$group = $this->groupRepository->find($groupId);
if ($group) {
$groupNames[] = $group->getName();
}
}
if (count($groupNames) === 1) {
// Single team format
$teamsName = $groupNames[0];
} else {
// Multiple teams format
$teamsName = implode(', ', $groupNames);
}
return $teamsName;
}
public function getReportFileName(AutomatedReportResult $report): string
...
|
12331
|
|
12339
|
262
|
8
|
2026-04-14T11:09:32.933640+00:00
|
/Users/lukas/.screenpipe/data/data/2026-04-14/1776 /Users/lukas/.screenpipe/data/data/2026-04-14/1776164972933_m1.jpg...
|
PhpStorm
|
faVsco.js – AutomatedReportsService.php
|
1
|
NULL
|
monitor_1
|
NULL
|
NULL
|
NULL
|
NULL
|
Project: faVsco.js, menu
#11894 on JY-18909-automa Project: faVsco.js, menu
#11894 on JY-18909-automated-reports-ask-jiminny, menu
Start Listening for PHP Debug Connections
AutomatedReportsCommandTest
Run 'AutomatedReportsCommandTest'
Debug 'AutomatedReportsCommandTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Execute
Explain Plan
Browse Query History
View Parameters
Open Query Execution Settings…
In-Editor Results
Tx: Auto
Cancel Running Statements
Playground
jiminny
Sync Changes
Hide This Notification
Code changed:
Hide
16
13
13
Previous Highlighted Error
Next Highlighted Error
SELECT * FROM teams WHERE id = 1;
select * from crm_layouts where crm_configuration_id = 39;
SELECT * FROM crm_layout_entities WHERE crm_layout_id = 283;
SELECT * FROM crm_fields WHERE id = 2234;
SELECT * FROM crm_field_values WHERE crm_field_id = 2234;
select * from crm_profiles where user_id = 143;
select * from record_types where crm_configuration_id = 39; # 0121K000001MHElQAO,0121K000001MHEqQAO
select * from business_processes where crm_configuration_id = 39;
# 01941000000H669AAC, 01941000000H66JAAS
select * from record_type_field_values
where record_type_id IN (24);
select * from crm_field_values where id IN (2730);
select * from crm_configurations where id = 39;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 1
and sa.provider = 'salesforce'; #1035
select * from users where team_id = 1; # 222 group 3
SELECT * FROM activities WHERE user_id = 222 order by id desc;
select * from sidekick_settings where team_id = 1;
select * from teams where id = 1;
select * from team_features where team_id = 1;
select * from activities where crm_configuration_id = 2
and provider = 'ms-teams' and id = 608765;
SELECT * FROM activities WHERE crm_configuration_id = 2 and crm_provider_id = '59523413338';
select * from sidekick_settings where team_id = 2;
SELECT * FROM activities WHERE id = 608660;
select * from activity_summary_logs where activity_id = 608660;
select * from ai_prompts where transcription_id = 11214;
# [PASSWORD_DOTS]
SELECT * FROM activities WHERE uuid_to_bin('ed78a437-2804-450e-ab2f-56ab1c641346') = uuid;
# id: 608818, crm: 59628809737
SELECT * FROM activities WHERE uuid_to_bin('36b06e55-afdd-4782-8dee-c624cd0af191') = uuid;
# id: 608821, crm: 59632069252
SELECT ce.start_time, ce.end_time, a.id, a.uuid, crm_provider_id, calendar_event_id, title,
playbook_category_id, user_id, lead_id, contact_id, account_id, opportunity_id,
scheduled_start_time, scheduled_end_time, actual_start_time, actual_end_time, a.created_at
FROM activities a
join calendar_events ce on a.calendar_event_id = ce.id
WHERE a.id IN (608818, 608821);
select * from users where team_id = 1;
select * from team_settings where team_id = 1;
select * from crm_profiles where crm_configuration_id = 39 order by user_id;
select * from team_features where team_id = 1;
select * from users where team_id = 2;
SELECT * FROM activities WHERE uuid_to_bin('ec7647e9-5225-458b-b475-f31aa2769204') = uuid; # 612639
# Preslava N. Ivanova, grou id 3
SELECT * FROM opportunities WHERE uuid_to_bin('a2928fe5-aec5-46cb-85d9-7654c89e46a6') = uuid;
select * from activities where opportunity_id = 344 and actual_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00';
select
a.id,
a.type,
a.scheduled_start_time,
a.actual_start_time,
a.created_at,
a.opportunity_id,
a.status
FROM activities a
WHERE opportunity_id = 344
and status IN ('completed', 'received', 'delivered')
and (
(a.actual_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00')
OR (a.created_at between '2024-10-11 00:00:00' and '2024-10-12 00:00:00')
OR (a.scheduled_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00'))
;
SELECT * FROM users WHERE id = 222;
SELECT * FROM crm_profiles WHERE user_id = 222;
select * from crm_layouts where crm_configuration_id = 39;
SELECT * FROM crm_layout_entities WHERE crm_layout_id = 281;
select * from group_deal_risk_types;
select * from opportunities where team_id = 1;
SELECT * FROM opportunities WHERE id = 315;
SELECT * FROM crm_field_data WHERE object_id = 315;
select * from crm_field_data where object_id = 260;
select * from generic_ai_prompts where subject_id = 315;
select * from teams; # 36, 21, 121, [EMAIL]
SELECT * FROM social_accounts WHERE sociable_id = 121 and provider = 'bullhorn';
# [PASSWORD_DOTS]
select * from teams where id = 1;
select * from crm_configurations where id = 39;
select * from users where team_id = 1;
select u.email, cp.* from users u
join crm_profiles cp on u.id = cp.user_id
where u.team_id = 1;
# 1 - 00541000004281rAAA
# 204 - 0052g000003freeAAA
# 429 - 0052g000003qGOiAAM
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 1
and sa.provider = 'salesforce';
select * from activities where type = 'softphone'
and created_at > '2024-12-11 15:24:36' order by id desc;
select * from activity_providers where team_id = 1;
select * from activity_provider_users where activity_provider_id = 328;
select * from opportunities where crm_configuration_id = 39
AND account_id = 178 AND is_closed = false
order by created_at DESC;
select * from contacts where id = 3952;
select * from accounts where id = 178;
# [PASSWORD_DOTS]
select * from teams where id = 36;
select * from crm_configurations where id = 21;
select * from users where team_id = 36;
select u.email, cp.* from users u
join crm_profiles cp on u.id = cp.user_id
where u.team_id = 36;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 36
and sa.provider = 'bullhorn';
select * from social_accounts where id = 348;
UPDATE social_accounts SET
provider_user_token = '21442_6802599_91:41179a58-21e7-4d7c-ad58-56bb666b2f65',
provider_refresh_token = '21442_6802599_91:01c6b335-3f2a-42e4-85ff-8a08fa65fceb',
expires = 1733998131,
state = 'connected'
WHERE id = 348;
# [PASSWORD_DOTS]
select * from teams where id = 31;
select * from crm_configurations where id = 18;
select * from users where team_id = 31; # 257
select u.email, cp.* from users u
join crm_profiles cp on u.id = cp.user_id
where u.team_id = 31;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 31
and sa.provider = 'close';
select * from contacts where crm_configuration_id = 18;
# [PASSWORD_DOTS] NEPTUNE [PASSWORD_DOTS]
select * from teams;
select * from users where id IN (1030, 1035, 1052);
select * from crm_configurations;
select * from users where team_id = 65; # 257
select * from team_settings where team_id = 65; # 257
select * from invitations where team_id = 65; # 257
select * from users where email = '[EMAIL]'; # 257
select u.email, cp.* from users u
join crm_profiles cp on u.id = cp.user_id
where u.team_id = 65;
select * from crm_configurations where id = 53;
select * from accounts where crm_configuration_id = 53 order by id desc;
select * from leads where crm_configuration_id = 53 order by id desc;
select * from contacts where crm_configuration_id = 53 order by id desc;
select * from opportunities where crm_configuration_id = 53 order by id desc;
select * from crm_profiles where crm_configuration_id = 53 order by id desc;
select * from crm_fields where crm_configuration_id = 53 order by id desc;
select * from crm_field_values where crm_field_id = 3341 order by id desc;
select * from crm_layouts where crm_configuration_id = 53 order by id desc;
select * from stages where crm_configuration_id = 53 order by id desc;
select * from crm_profiles where crm_configuration_id = 13;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 65
and sa.provider = 'integration-app';
select * from contacts where crm_configuration_id = 13;
select * from social_accounts where sociable_id = 283;
SELECT * FROM opportunities WHERE crm_provider_id = '006O400000E9bzeIAB';
select * from activity_providers where team_id = 65;
SELECT * FROM activities WHERE crm_configuration_id IN (51, 52, 53);
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 65
;
# [PASSWORD_DOTS] STAGING [PASSWORD_DOTS]
SELECT * FROM teams;
SELECT * FROM teams WHERE id = 88;
SELECT * FROM teams WHERE id = 89;
select * from team_settings where team_id = 89;
SELECT * FROM users WHERE team_id = 89;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 89;
select * from users;
SELECT * FROM social_accounts WHERE sociable_id = 1761;
SELECT * FROM crm_configurations WHERE id = 70;
select * from accounts where crm_configuration_id = 70 order by id desc;
select * from leads where crm_configuration_id = 70 order by id desc;
select * from contacts where crm_configuration_id = 70 order by id desc;
select * from opportunities where crm_configuration_id = 70 order by id desc;
select * from crm_profiles where crm_configuration_id = 70 order by id desc;
select * from crm_fields where crm_configuration_id = 70 order by id desc;
select * from crm_field_values where crm_field_id = 3536 order by id desc;
select * from crm_layouts where crm_configuration_id = 70 order by id desc;
select * from stages where crm_configuration_id = 70 order by id desc;
select * from business_processes where crm_configuration_id = 70 order by id desc;
select * from business_process_stages where business_process_id = 34;
select * from contacts where id = 10468;
select * from crm_layouts where crm_configuration_id = 70;
SELECT * FROM crm_layout_entities WHERE crm_layout_id = 388;
SELECT * FROM crm_fields WHERE id IN (3533,3534,3535);
select * from activities where crm_configuration_id = 70
and (account_id IS NOT NULL or lead_id IS NOT NULL or contact_id IS NOT NULL or opportunity_id IS NOT NULL) order by id desc;
SELECT * FROM activities WHERE uuid_to_bin('2e10b60f-8a61-41c5-a3d4-28835353dc65') = uuid;
SELECT * FROM activities where crm_configuration_id = 69 ;
SELECT * FROM users WHERE email LIKE '%[EMAIL]%';
SELECT * FROM activities WHERE uuid_to_bin('5a150c93-40fc-42ec-b3bd-c1d328e09f6e') = uuid;
SELECT * FROM opportunities WHERE id = 385;
select * from participants p
join activities a on p.activity_id = a.id
where a.crm_configuration_id = 70
and (p.lead_id IS NOT NULL or p.contact_id IS NOT NULL);
SELECT * FROM participants WHERE id = 1013638;
select * from teams where id = 90;
select * from users where team_id = 90;
select * from social_accounts where social_accounts.sociable_id IN (1960,1760);
SELECT * FROM crm_profiles WHERE crm_configuration_id = 71;
select * from invitations where team_id = 90;
select * from crm_configurations where id = 71;
select * from accounts where crm_configuration_id = 71 order by id desc;
select * from leads where crm_configuration_id = 71 order by id desc;
select * from contacts where crm_configuration_id = 71 order by id desc;
select * from opportunities where crm_configuration_id = 71 order by id desc;
select * from crm_profiles where crm_configuration_id = 71 order by id desc;
select * from crm_fields where crm_configuration_id = 71 order by id desc;
select * from crm_field_values where crm_field_id = 3341 order by id desc;
select * from crm_layouts where crm_configuration_id = 71 order by id desc;
select * from stages where crm_configuration_id = 71 order by id desc;
select * from users order by secondary_email desc;
select u.id, u.email, u.status, sa.id, sa.provider_user_id from social_accounts sa
join users u on sa.sociable_id = u.id
where sa.provider = 'google' and u.email LIKE 'aneliya%';
select * from failed_jobs order by id desc;
select * from users where email = '[EMAIL]' or secondary_email = '[EMAIL]';
select * from teams;
SELECT * FROM crm_profiles WHERE crm_configuration_id = 39;
SELECT * FROM crm_fields WHERE crm_configuration_id = 39 and object_type = 'task';
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 1
and sa.provider = 'salesforce';
# [PASSWORD_DOTS]
SELECT * FROM activities WHERE uuid_to_bin('c38b3895-fd0f-4b1f-9fb2-c170dba137c6') = uuid;
SELECT * FROM crm_configurations WHERE id = 70;
select * from teams where id = 1;
select * from groups where team_id = 1;
select * from users where team_id = 1;
select o.id, o.name,o.close_date, u.id, u.name, u.group_id, r.id, r.display_name, g.name, g.scope from opportunities o
join users u on o.user_id = u.id
join groups g on u.group_id = g.id
join role_user ru on u.id = ru.user_id
join roles r on ru.role_id = r.id
where o.crm_configuration_id = 39 and close_date > '2024-01-01 00:00:00';
select * from role_user where user_id = 143;
select * from roles;
select * from role_user;
select * from groups where id = 9;
select * from scope_groups where group_id = 9;
# [PASSWORD_DOTS]
select * from teams where id = 36;
select * from crm_configurations;
SELECT * FROM social_accounts WHERE sociable_id = 121;
[URL_WITH_CREDENTIALS] this will add filter, however if we need to control feature by FF we need conditional logic
public const array TYPES = [
['id' => 'exec_summary', 'name' => 'Exec Summary'],
['id' => 'coaching_profiles', 'name' => 'Coaching Profiles'],
['id' => 'product_feedback', 'name' => 'Product Feedback'],
['id' => self::TYPE_LOSS_ANALYSIS, 'name' => 'Loss Analysis'],
// ['id' => 'questions', 'name' => 'Questions'],
// ['id' => 'statistical_quant', 'name' => 'Statistical Quantitative'],
];
public const array ALL_TYPES = [
...self::TYPES,
['id' => self::TYPE_ASK_JIMINNY, 'name' => 'Ask Jiminny'],
];
public const string FREQUENCY_DAILY = 'daily';
public const string FREQUENCY_WEEKLY = 'weekly';
public const string FREQUENCY_MONTHLY = 'monthly';
public const string FREQUENCY_QUARTERLY = 'quarterly';
public const string FREQUENCY_ONE_OFF = 'one_off';
/**
* Frequencies for standard (non-Ask Jiminny) reports.
*/
public const array FREQUENCIES = [
['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],
['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],
['id' => self::FREQUENCY_QUARTERLY, 'name' => 'Quarterly'],
['id' => self::FREQUENCY_ONE_OFF, 'name' => 'One-off'],
];
/**
* Frequencies for Ask Jiminny reports.
*/
public const array ASK_JIMINNY_FREQUENCIES = [
['id' => self::FREQUENCY_DAILY, 'name' => 'Daily'],
['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],
['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],
];
public const string MEDIA_TYPE_PDF = 'pdf';
public const string MEDIA_TYPE_PODCAST = 'podcast';
public const array MEDIA_TYPES = [self::MEDIA_TYPE_PDF, self::MEDIA_TYPE_PODCAST];
public const array MEDIA_TYPE_OBJECT_PDF = ['id' => self::MEDIA_TYPE_PDF, 'name' => 'PDF'];
public const array MEDIA_TYPE_OBJECT_PODCAST = ['id' => self::MEDIA_TYPE_PODCAST, 'name' => 'Podcast'];
public const array MEDIA_TYPE_OBJECTS = [self::MEDIA_TYPE_OBJECT_PDF, self::MEDIA_TYPE_OBJECT_PODCAST];
public const array CALL_TYPE_CONFERENCE = ['id' => 'conference', 'name' => 'Conference'];
public const array CALL_TYPE_DIALER = ['id' => 'dialer', 'name' => 'Dialer'];
public const int SENT_REPORT_AT_HOURS = 5;
public const string PDF_KEY = 'pdf';
public const string AUDIO_KEY = 'audio';
private const array ALL_FREQUENCIES = [
['id' => self::FREQUENCY_DAILY, 'name' => 'Daily'],
['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],
['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],
['id' => self::FREQUENCY_QUARTERLY, 'name' => 'Quarterly'],
['id' => self::FREQUENCY_ONE_OFF, 'name' => 'One-off'],
];
private const string S3_DIR = 'reports';
private const array FILE_EXTENSIONS_VARIANTS = ['html', 'MD', 'pdf'];
private const array FILE_PODCAST_EXTENSIONS_VARIANTS = ['json', 'mp3', 'ssml'];
public function __construct(
private readonly TeamRepository $teamRepository,
private readonly GroupRepository $groupRepository,
private readonly UserRepository $userRepository,
private readonly StageRepository $stageRepository,
private readonly DealStagesService $dealStagesService,
private readonly RecipientsService $recipientsService,
private readonly AutomatedReportsRepository $automatedReportsRepository,
private readonly Webhook $webhookService,
private readonly BusDispatcher $dispatcher,
private readonly ActivityTypeService $activityTypeService,
private readonly PlaybookCategoryRepository $playbookCategoryRepository,
private readonly AskAnythingPromptService $askAnythingPromptService,
private readonly SearchRepository $activitySearchRepository,
private readonly AskAnythingRepository $askAnythingRepository,
) {
}
public static function getTypes(): array
{
$types = self::TYPES;
return array_map(static function ($type) {
return $type['id'];
}, $types);
}
public static function getCallTypes(): array
{
return array_map(static function ($callType) {
return $callType['id'];
}, [self::CALL_TYPE_CONFERENCE, self::CALL_TYPE_DIALER]);
}
public static function getFrequencies(): array
{
return array_map(static function ($frequency) {
return $frequency['id'];
}, self::FREQUENCIES);
}
// front-facing structure
public function getReportEnabledFieldData(bool $value = false): array
{
return [
'id' => 'report_enabled',
'label' => '',
'inputType' => InputTypeEnum::TOGGLE,
'value' => $value,
];
}
// Organizations = Teams
public function getOrganizationFieldData(?string $value = null, bool $shortVersion = false): array
{
$options = $this->getTeams();
if ($shortVersion) {
return [
'id' => 'organization',
'label' => 'Organization',
'options' => $options,
];
}
return [
'id' => 'organization',
'label' => 'Organization',
'inputType' => InputTypeEnum::DROPDOWN,
'required' => true,
'placeholder' => 'Select',
'options' => $options,
'value' => $value,
'dependencies' => [
'teams',
'deal_stage_at_call',
'current_deal_stage',
'recipients',
ActivityTypeService::PLAYBOOK_CATEGORIES_KEY,
],
'dependsOn' => [],
];
}
// Teams = Groups
public function getTeamFieldData(array $options = [], array $value = [], bool $shortVersion = false): array
{
if ($shortVersion) {
return [
'id' => 'teams',
'label' => 'Team',
'options' => $options,
];
}
return [
'id' => 'teams',
'label' => 'Team',
'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,
'required' => false,
'placeholder' => 'Select',
'options' => $options,
'value' => $value, // value should be an array of objects {id, name}
'dependencies' => [ActivityTypeService::PLAYBOOK_CATEGORIES_KEY],
'dependsOn' => [],
];
}
public function getReportTypeFieldData(?string $value = null, bool $shortVersion = false, ?Team $team = null): array
{
$types = [];
if ($team instanceof Team) {
if ($team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {
$types = self::TYPES;
}
if ($team->hasFeature(FeatureEnum::ASK_JIMINNY_REPORTS)) {
$types[] = ['id' => self::TYPE_ASK_JIMINNY, 'name' => 'Ask Jiminny'];
}
} else {
$types = self::TYPES;
}
if ($shortVersion) {
return [
'id' => 'report_type',
'label' => 'Report Type',
'options' => $types,
];
}
return [
'id' => 'report_type',
'label' => 'Report Type',
'inputType' => InputTypeEnum::DROPDOWN,
'required' => true,
'placeholder' => 'Select',
'options' => $types,
'value' => $value,
'dependencies' => [],
'dependsOn' => [],
];
}
public function getFrequencyFieldData(?string $value = null): array
{
return [
'id' => 'frequency',
'label' => 'Frequency',
'inputType' => InputTypeEnum::DROPDOWN,
'required' => true,
'placeholder' => 'Select',
'options' => self::FREQUENCIES,
'value' => $value,
'dependencies' => ['period'],
'dependsOn' => [],
];
}
public function getPeriodFieldData(?string $valueStartDate = null, ?string $valueEndDate = null): array
{
return [
'id' => 'period',
'label' => 'Select one-off period',
'inputType' => InputTypeEnum::DATE_RANGE,
'required' => true,
'placeholder' => 'Select',
'value' => ['startDate' => $valueStartDate, 'endDate' => $valueEndDate],
'queryParams' => [
'startDate' => 'start_date_period',
'endDate' => 'end_date_period',
],
'dependencies' => [],
'dependsOn' => ['frequency'],
];
}
public function getActivityTypesFieldData(?Team $team = null, array $value = [], array $teamsFilter = []): array
{
return $this->activityTypeService->getActivityTypeFieldData(team: $team, value: $value, groupIds: $teamsFilter);
}
public function getDealStageAtCallFieldData(?Team $team = null, array $value = []): array
{
return $this->dealStagesService->getDealStageAtCallFieldData(team: $team, value: $value);
}
public function getCurrentDealStageFieldData(?Team $team = null, array $value = []): array
{
return $this->dealStagesService->getCurrentDealStageFieldData(team: $team, value: $value);
}
public function getDealValueFieldData(?int $valueMin = null, ?int $valueMax = null): array
{
return [
'id' => 'deal_value',
'label' => 'Deal Value',
'inputType' => InputTypeEnum::INTEGER_RANGE,
'required' => false,
'value' => ['min' => $valueMin, 'max' => $valueMax],
'queryParams' => [
'min' => 'min_deal_value',
'max' => 'max_deal_value',
],
'dependencies' => [],
'dependsOn' => [],
];
}
public function getCallTypeFieldData(bool $conferenceOn = false, bool $dialerOn = false): array
{
$value = [];
$conferenceOn && $value[] = self::CALL_TYPE_CONFERENCE;
$dialerOn && $value[] = self::CALL_TYPE_DIALER;
return [
'id' => 'call_type',
'label' => 'Call Type',
'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,
'required' => true,
'options' => [
self::CALL_TYPE_CONFERENCE,
self::CALL_TYPE_DIALER,
],
'value' => $value,
'dependencies' => [],
'dependsOn' => [],
];
}
public function getMediaTypeFieldData(?AutomatedReport $report = null): array
{
$value = [];
if ($report) {
$value = $this->transformMediaTypes($report);
}
return [
'id' => 'media_types',
'label' => 'Export as',
'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,
'required' => true,
'options' => self::MEDIA_TYPE_OBJECTS,
'value' => $value,
'dependencies' => [],
'dependsOn' => [],
];
}
public function getCallDurationFieldData(?int $valueMin = null, ?int $valueMax = null): array
{
return [
'id' => 'call_duration',
'label' => 'Call Duration',
'inputType' => InputTypeEnum::INTEGER_RANGE,
'required' => false,
'value' => ['min' => $valueMin, 'max' => $valueMax],
'queryParams' => [
'min' => 'min_call_duration',
'max' => 'max_call_duration',
],
'dependencies' => [],
'dependsOn' => [],
];
}
public function getRecipientsFieldData(?Team $team = null, array $value = []): array
{
return $this->recipientsService->getRecipientsFieldData(team: $team, value: $value);
}
public function getJiminnyRecipientsFieldData(array $value = []): array
{
return $this->recipientsService->getJiminnyRecipientsFieldData($value);
}
public function getAdditionalPromptInputFieldData(?string $value = null): array
{
return [
'id' => 'additional_prompt_input',
'label' => 'Special requirements',
'inputType' => InputTypeEnum::TEXTAREA,
'required' => false,
'placeholder' => 'What should be the focus of the report?',
'value' => $value,
'dependencies' => [],
'dependsOn' => [],
];
}
public function getCustomReportNameFieldData(?string $value = null): array
{
return [
'id' => 'custom_name',
'label' => 'Custom report name',
'inputType' => InputTypeEnum::TEXT,
'required' => false,
'placeholder' => 'Enter custom name',
'value' => $value,
'dependencies' => [],
'dependsOn' => [],
];
}
// data providers
public function getTeams(): array
{
$teams = $this->teamRepository->getTeamsForKiosk(status: Team::STATUS_ACTIVE);
$teamData = [];
foreach ($teams as $team) {
if (! $team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {
continue;
}
$teamData[] = $this->transformTeam($team);
}
return $teamData;
}
public function getTeamGroups(string $teamUuid): array
{
$data = [];
$team = $this->getTeam($teamUuid);
if ($team !== null) {
$groups = $team->groups()->get();
foreach ($groups as $group) {
$data[] = [
'id' => $group->getUuid(),
'name' => $group->getName(),
];
}
}
return $data;
}
public function getTeamsGroupsOptions(array $filterTeamUuids = []): array
{
$data = [];
$teams = $this->getTeams();
foreach ($teams as $team) {
if (! empty($filterTeamUuids) && ! in_array($team['id'], $filterTeamUuids, true)) {
continue;
}
$data[] = [
'label' => $team['name'],
'groups' => $this->getTeamGroups($team['id']),
];
}
return $data;
}
public function getTeam(string $teamUuid): ?Team
{
return $this->teamRepository->idOrUuid($teamUuid);
}
public function getTeamById(int $teamId): ?Team
{
return $this->teamRepository->find($teamId);
}
public function getGroupsUuids(AutomatedReport $report): array
{
$uuids = [];
$reportGroups = $report->getGroups();
foreach ($reportGroups as $groupId) {
if ($group = $this->groupRepository->find($groupId)) {
$uuids[] = $group->getUuid();
}
}
return $uuids;
}
public function getPlaybookCategoriesUuids(AutomatedReport $report): array
{
$uuids = [];
$playbookCategories = $report->getPlaybookCategories();
foreach ($playbookCategories as $id) {
if ($category = $this->playbookCategoryRepository->find($id)) {
$uuids[] = $category->getUuid();
}
}
return $uuids;
}
public function getDealAtCallStagesUuids(AutomatedReport $report): array
{
$uuids = [];
$reportStages = $report->getDealAtCallStages();
foreach ($reportStages as $id) {
if ($stage = $this->stageRepository->find($id)) {
$uuids[] = $stage->getUuid();
}
}
return $uuids;
}
public function getCurrentDealStagesUuids(AutomatedReport $report): array
{
$uuids = [];
$reportStages = $report->getCurrentDealStages();
foreach ($reportStages as $id) {
if ($stage = $this->stageRepository->find($id)) {
$uuids[] = $stage->getUuid();
}
}
return $uuids;
}
public function getUsersUuids(AutomatedReport $report): array
{
return $this->extractUserUuids($report->getRecipients());
}
public function getJiminnyUsersUuids(AutomatedReport $report): array
{
return $this->extractUserUuids($report->getJiminnyRecipients());
}
/**
* @param array<string, mixed> $recipients
*/
private function extractUserUuids(array $recipients): array
{
$userIds = $recipients['users'] ?? [];
return collect($userIds)
->map(fn ($id) => $this->userRepository->find((int) $id))
->filter()
->map(fn (UserContract $user) => $user->getUuid())
->values()
->all();
}
// get mail data
public function getRecipientUsers(AutomatedReport $report): array
{
return $this->buildRecipientUsers($report->getRecipients());
}
private function getJiminnyRecipientUsers(AutomatedReport $report): array
{
return $this->buildRecipientUsers($report->getJiminnyRecipients());
}
/**
* @param array<string, mixed> $recipients
*/
private function buildRecipientUsers(array $recipients): array
{
$userIds = $recipients['users'] ?? [];
return collect($userIds)
->map(fn ($id) => $this->userRepository->find((int) $id))
->filter()
->map(fn (UserContract $user) => [
'email' => $user->getEmailAddress(),
'name' => $user->getName(),
'timezone' => $user->getTimezone()->getName(),
])
->values()
->all();
}
public function getValidRecipientUsers(AutomatedReport $report, bool $includeJiminny = false): array
{
if ($report->isAskJiminnyReport()) {
$recipients = $this->resolveAskJiminnyRecipients($report);
} else {
$recipients = $this->getRecipientUsers($report);
if ($includeJiminny) {
$recipients = array_merge($recipients, $this->getJiminnyRecipientUsers($report));
}
}
$emails = [];
return array_values(array_filter(
$recipients,
static function ($recipient) use (&$emails) {
if (empty($recipient['email']) || in_array($recipient['email'], $emails, true)) {
return false;
}
$emails[] = $recipient['email'];
return true;
}
));
}
private function resolveAskJiminnyRecipients(AutomatedReport $report): array
{
$recipients = [];
$creator = $report->getCreator();
if ($creator !== null) {
$recipients[] = [
'email' => $creator->getEmailAddress(),
'name' => $creator->getName(),
'timezone' => $creator->getTimezone()->getName(),
];
}
return array_merge(
$recipients,
$this->buildRecipientUsers($report->getRecipients()),
$this->getGroupRecipientUsers($report),
);
}
private function getGroupRecipientUsers(AutomatedReport $report): array
{
$users = [];
foreach ($report->getGroups() as $groupId) {
$group = $this->groupRepository->find($groupId);
if ($group === null) {
continue;
}
foreach ($group->getMembers() as $member) {
$users[] = [
'email' => $member->getEmailAddress(),
'name' => $member->getName(),
'timezone' => $member->getTimezone()->getName(),
];
}
}
return $users;
}
public function getReportTypeName(AutomatedReportResult $report): string
{
$type = $report->getReport()->getType();
$getType = $this->transformReportType($type);
return $getType['name'];
}
public function getReportPeriodName(AutomatedReportResult $report): string
{
$from = $report->getFromDate();
$to = $report->getToDate();
$frequency = $report->getReport()->getFrequency();
if ($from === null || $to === null) {
if (! $report->getReport()->isAskJiminnyReport()) {
$invalidPeriod = $from === null ? 'from' : 'to';
throw new ApplicationException('Report period is invalid: ' . $invalidPeriod);
}
$period = $this->calculateFromAndToDatePeriod($frequency);
$from = $period['fromDate'];
$to = $period['toDate'];
}
return $this->formatReportPeriodName($frequency, $from, $to);
}
private function formatReportPeriodName(string $frequency, Carbon $from, Carbon $to): string
{
$fromYear = $from->format('Y');
$toYear = $to->format('Y');
$differentYears = $fromYear !== $toYear;
switch ($frequency) {
case self::FREQUENCY_DAILY:
return $from->format('j M Y');
case self::FREQUENCY_QUARTERLY:
// 'Jan-Mar 2025' or 'Nov 2024-Jan 2025' if years differ
$startMonth = $from->format('M');
$endMonth = $to->copy()->subMonth();
$endMonthName = $endMonth->format('M');
$endMonthYear = $endMonth->format('Y');
if ($differentYears) {
return "{$startMonth} {$fromYear} - {$endMonthName} {$endMonthYear}";
}
return "{$startMonth} - {$endMonthName} {$toYear}";
case self::FREQUENCY_MONTHLY:
// 'May 2025' - monthly reports are always within the same year
return $from->format('M Y');
case self::FREQUENCY_WEEKLY:
// '4 - 8 Aug 2025', '27 Oct - 3 Nov 2025', or '28 Dec 2024 - 3 Jan 2025' if years differ
$startDay = $from->format('j');
$endDay = $to->format('j');
$startMonth = $from->format('M');
$endMonth = $to->format('M');
if ($differentYears) {
return "{$startDay} {$startMonth} {$fromYear} - {$endDay} {$endMonth} {$toYear}";
}
if ($startMonth !== $endMonth) {
return "{$startDay} {$startMonth} - {$endDay} {$endMonth} {$toYear}";
}
return "{$startDay} - {$endDay} {$endMonth} {$toYear}";
case self::FREQUENCY_ONE_OFF:
// '2 May-31 May 2025' or '15 Dec 2024-15 Jan 2025' if years differ
$startDay = $from->format('j');
$startMonth = $from->format('M');
$endDay = $to->format('j');
$endMonth = $to->format('M');
// If same month and year, use a format like '2-31 May 2025'
if ($startMonth === $endMonth && ! $differentYears) {
return "{$startDay} - {$endDay} {$startMonth} {$toYear}";
}
// If different years, include both years
if ($differentYears) {
return "{$startDay} {$startMonth} {$fromYear} - {$endDay} {$endMonth} {$toYear}";
}
// Same year but different months
return "{$startDay} {$startMonth} - {$endDay} {$endMonth} {$toYear}";
default:
// Default format for unknown frequencies
return $from->format('j M Y') . ' - ' . $to->format('j M Y');
}
}
public function getReportTeamsName(AutomatedReportResult $report): string
{
$groups = $report->getGroups();
if (empty($groups)) {
return 'All';
}
// Get group names from repository
$groupNames = [];
foreach ($groups as $groupId) {
$group = $this->groupRepository->find($groupId);
if ($group) {
$groupNames[] = $group->getName();
}
}
if (count($groupNames) === 1) {
// Single team format
$teamsName = $groupNames[0];
} else {
// Multiple teams format
$teamsName = implode(', ', $groupNames);
}
return $teamsName;
}
public function getReportFileName(AutomatedReportResult $report): string
...
|
[{"role":"AXButton","text" [{"role":"AXButton","text":"Project: faVsco.js, menu","depth":5,"help_text":"~/jiminny/app","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"#11894 on JY-18909-automated-reports-ask-jiminny, menu","depth":5,"help_text":"Pull request #11894 exists for current branch JY-18909-automated-reports-ask-jiminny","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Start Listening for PHP Debug Connections","depth":5,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"AutomatedReportsCommandTest","depth":6,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Run 'AutomatedReportsCommandTest'","depth":6,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Debug 'AutomatedReportsCommandTest'","depth":6,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"More Actions","depth":6,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JetBrains AI","depth":5,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Search Everywhere","depth":5,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"IDE and Project Settings","depth":5,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Execute","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Explain Plan","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Browse Query History","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"View Parameters","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Open Query Execution Settings…","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"In-Editor Results","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Tx: Auto","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Cancel Running Statements","depth":4,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Playground","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"jiminny","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.088194445,"height":0.027777778},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"16","depth":4,"role_description":"text"},{"role":"AXStaticText","text":"13","depth":4,"role_description":"text"},{"role":"AXStaticText","text":"13","depth":4,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"SELECT * FROM teams WHERE id = 1;\n\nselect * from crm_layouts where crm_configuration_id = 39;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 283;\nSELECT * FROM crm_fields WHERE id = 2234;\nSELECT * FROM crm_field_values WHERE crm_field_id = 2234;\n\nselect * from crm_profiles where user_id = 143;\n\nselect * from record_types where crm_configuration_id = 39; # 0121K000001MHElQAO,0121K000001MHEqQAO\nselect * from business_processes where crm_configuration_id = 39;\n# 01941000000H669AAC, 01941000000H66JAAS\n\nselect * from record_type_field_values\n where record_type_id IN (24);\n\nselect * from crm_field_values where id IN (2730);\n\nselect * from crm_configurations where id = 39;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 1\nand sa.provider = 'salesforce'; #1035\n\n\nselect * from users where team_id = 1; # 222 group 3\nSELECT * FROM activities WHERE user_id = 222 order by id desc;\nselect * from sidekick_settings where team_id = 1;\nselect * from teams where id = 1;\nselect * from team_features where team_id = 1;\n\nselect * from activities where crm_configuration_id = 2\nand provider = 'ms-teams' and id = 608765;\n\nSELECT * FROM activities WHERE crm_configuration_id = 2 and crm_provider_id = '59523413338';\n\nselect * from sidekick_settings where team_id = 2;\n\nSELECT * FROM activities WHERE id = 608660;\nselect * from activity_summary_logs where activity_id = 608660;\nselect * from ai_prompts where transcription_id = 11214;\n\n# ********************************************************************************************************\nSELECT * FROM activities WHERE uuid_to_bin('ed78a437-2804-450e-ab2f-56ab1c641346') = uuid;\n# id: 608818, crm: 59628809737\nSELECT * FROM activities WHERE uuid_to_bin('36b06e55-afdd-4782-8dee-c624cd0af191') = uuid;\n# id: 608821, crm: 59632069252\nSELECT ce.start_time, ce.end_time, a.id, a.uuid, crm_provider_id, calendar_event_id, title,\nplaybook_category_id, user_id, lead_id, contact_id, account_id, opportunity_id,\nscheduled_start_time, scheduled_end_time, actual_start_time, actual_end_time, a.created_at\nFROM activities a\njoin calendar_events ce on a.calendar_event_id = ce.id\nWHERE a.id IN (608818, 608821);\n\nselect * from users where team_id = 1;\nselect * from team_settings where team_id = 1;\nselect * from crm_profiles where crm_configuration_id = 39 order by user_id;\n\nselect * from team_features where team_id = 1;\n\nselect * from users where team_id = 2;\n\nSELECT * FROM activities WHERE uuid_to_bin('ec7647e9-5225-458b-b475-f31aa2769204') = uuid; # 612639\n# Preslava N. Ivanova, grou id 3\n\nSELECT * FROM opportunities WHERE uuid_to_bin('a2928fe5-aec5-46cb-85d9-7654c89e46a6') = uuid;\n\nselect * from activities where opportunity_id = 344 and actual_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00';\n\nselect\n a.id,\n a.type,\n a.scheduled_start_time,\n a.actual_start_time,\n a.created_at,\n a.opportunity_id,\n a.status\nFROM activities a\nWHERE opportunity_id = 344\nand status IN ('completed', 'received', 'delivered')\nand (\n (a.actual_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00')\nOR (a.created_at between '2024-10-11 00:00:00' and '2024-10-12 00:00:00')\nOR (a.scheduled_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00'))\n;\n\nSELECT * FROM users WHERE id = 222;\n\nSELECT * FROM crm_profiles WHERE user_id = 222;\nselect * from crm_layouts where crm_configuration_id = 39;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 281;\n\nselect * from group_deal_risk_types;\n\nselect * from opportunities where team_id = 1;\n\nSELECT * FROM opportunities WHERE id = 315;\nSELECT * FROM crm_field_data WHERE object_id = 315;\nselect * from crm_field_data where object_id = 260;\n\nselect * from generic_ai_prompts where subject_id = 315;\n\nselect * from teams; # 36, 21, 121, james.graham@bullhorn.jiminny.com\nSELECT * FROM social_accounts WHERE sociable_id = 121 and provider = 'bullhorn';\n\n# ************************************************************************************\nselect * from teams where id = 1;\nselect * from crm_configurations where id = 39;\nselect * from users where team_id = 1;\nselect u.email, cp.* from users u\njoin crm_profiles cp on u.id = cp.user_id\nwhere u.team_id = 1;\n# 1 - 00541000004281rAAA\n# 204 - 0052g000003freeAAA\n# 429 - 0052g000003qGOiAAM\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 1\nand sa.provider = 'salesforce';\n\nselect * from activities where type = 'softphone'\nand created_at > '2024-12-11 15:24:36' order by id desc;\n\nselect * from activity_providers where team_id = 1;\nselect * from activity_provider_users where activity_provider_id = 328;\n\nselect * from opportunities where crm_configuration_id = 39\nAND account_id = 178 AND is_closed = false\norder by created_at DESC;\n\nselect * from contacts where id = 3952;\nselect * from accounts where id = 178;\n\n# ************************************************************************************\nselect * from teams where id = 36;\nselect * from crm_configurations where id = 21;\nselect * from users where team_id = 36;\nselect u.email, cp.* from users u\njoin crm_profiles cp on u.id = cp.user_id\nwhere u.team_id = 36;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 36\nand sa.provider = 'bullhorn';\n\nselect * from social_accounts where id = 348;\nUPDATE social_accounts SET\nprovider_user_token = '21442_6802599_91:41179a58-21e7-4d7c-ad58-56bb666b2f65',\nprovider_refresh_token = '21442_6802599_91:01c6b335-3f2a-42e4-85ff-8a08fa65fceb',\nexpires = 1733998131,\nstate = 'connected'\nWHERE id = 348;\n\n# ************************************************************************************\nselect * from teams where id = 31;\nselect * from crm_configurations where id = 18;\n\nselect * from users where team_id = 31; # 257\nselect u.email, cp.* from users u\njoin crm_profiles cp on u.id = cp.user_id\nwhere u.team_id = 31;\n\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 31\nand sa.provider = 'close';\n\nselect * from contacts where crm_configuration_id = 18;\n\n# ********************** NEPTUNE **************************************************************\nselect * from teams;\nselect * from users where id IN (1030, 1035, 1052);\nselect * from crm_configurations;\n\nselect * from users where team_id = 65; # 257\nselect * from team_settings where team_id = 65; # 257\nselect * from invitations where team_id = 65; # 257\nselect * from users where email = 'integration-account@jiminny.com'; # 257\nselect u.email, cp.* from users u\njoin crm_profiles cp on u.id = cp.user_id\nwhere u.team_id = 65;\n\nselect * from crm_configurations where id = 53;\nselect * from accounts where crm_configuration_id = 53 order by id desc;\nselect * from leads where crm_configuration_id = 53 order by id desc;\nselect * from contacts where crm_configuration_id = 53 order by id desc;\nselect * from opportunities where crm_configuration_id = 53 order by id desc;\nselect * from crm_profiles where crm_configuration_id = 53 order by id desc;\nselect * from crm_fields where crm_configuration_id = 53 order by id desc;\nselect * from crm_field_values where crm_field_id = 3341 order by id desc;\nselect * from crm_layouts where crm_configuration_id = 53 order by id desc;\nselect * from stages where crm_configuration_id = 53 order by id desc;\n\n\nselect * from crm_profiles where crm_configuration_id = 13;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 65\nand sa.provider = 'integration-app';\n\nselect * from contacts where crm_configuration_id = 13;\n\nselect * from social_accounts where sociable_id = 283;\n\nSELECT * FROM opportunities WHERE crm_provider_id = '006O400000E9bzeIAB';\n\nselect * from activity_providers where team_id = 65;\nSELECT * FROM activities WHERE crm_configuration_id IN (51, 52, 53);\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 65\n;\n\n# ***************************** STAGING ********************************************\nSELECT * FROM teams;\nSELECT * FROM teams WHERE id = 88;\nSELECT * FROM teams WHERE id = 89;\nselect * from team_settings where team_id = 89;\nSELECT * FROM users WHERE team_id = 89;\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 89;\n\nselect * from users;\nSELECT * FROM social_accounts WHERE sociable_id = 1761;\nSELECT * FROM crm_configurations WHERE id = 70;\nselect * from accounts where crm_configuration_id = 70 order by id desc;\nselect * from leads where crm_configuration_id = 70 order by id desc;\nselect * from contacts where crm_configuration_id = 70 order by id desc;\nselect * from opportunities where crm_configuration_id = 70 order by id desc;\nselect * from crm_profiles where crm_configuration_id = 70 order by id desc;\nselect * from crm_fields where crm_configuration_id = 70 order by id desc;\nselect * from crm_field_values where crm_field_id = 3536 order by id desc;\nselect * from crm_layouts where crm_configuration_id = 70 order by id desc;\nselect * from stages where crm_configuration_id = 70 order by id desc;\nselect * from business_processes where crm_configuration_id = 70 order by id desc;\nselect * from business_process_stages where business_process_id = 34;\n\nselect * from contacts where id = 10468;\n\nselect * from crm_layouts where crm_configuration_id = 70;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 388;\nSELECT * FROM crm_fields WHERE id IN (3533,3534,3535);\n\nselect * from activities where crm_configuration_id = 70\nand (account_id IS NOT NULL or lead_id IS NOT NULL or contact_id IS NOT NULL or opportunity_id IS NOT NULL) order by id desc;\n\nSELECT * FROM activities WHERE uuid_to_bin('2e10b60f-8a61-41c5-a3d4-28835353dc65') = uuid;\nSELECT * FROM activities where crm_configuration_id = 69 ;\n\nSELECT * FROM users WHERE email LIKE '%jiminny_web_sa2@jiminny.com%';\nSELECT * FROM activities WHERE uuid_to_bin('5a150c93-40fc-42ec-b3bd-c1d328e09f6e') = uuid;\nSELECT * FROM opportunities WHERE id = 385;\n\nselect * from participants p\njoin activities a on p.activity_id = a.id\nwhere a.crm_configuration_id = 70\nand (p.lead_id IS NOT NULL or p.contact_id IS NOT NULL);\nSELECT * FROM participants WHERE id = 1013638;\n\nselect * from teams where id = 90;\nselect * from users where team_id = 90;\nselect * from social_accounts where social_accounts.sociable_id IN (1960,1760);\nSELECT * FROM crm_profiles WHERE crm_configuration_id = 71;\nselect * from invitations where team_id = 90;\n\nselect * from crm_configurations where id = 71;\nselect * from accounts where crm_configuration_id = 71 order by id desc;\nselect * from leads where crm_configuration_id = 71 order by id desc;\nselect * from contacts where crm_configuration_id = 71 order by id desc;\nselect * from opportunities where crm_configuration_id = 71 order by id desc;\nselect * from crm_profiles where crm_configuration_id = 71 order by id desc;\nselect * from crm_fields where crm_configuration_id = 71 order by id desc;\nselect * from crm_field_values where crm_field_id = 3341 order by id desc;\nselect * from crm_layouts where crm_configuration_id = 71 order by id desc;\nselect * from stages where crm_configuration_id = 71 order by id desc;\n\nselect * from users order by secondary_email desc;\nselect u.id, u.email, u.status, sa.id, sa.provider_user_id from social_accounts sa\n join users u on sa.sociable_id = u.id\nwhere sa.provider = 'google' and u.email LIKE 'aneliya%';\n\nselect * from failed_jobs order by id desc;\n\nselect * from users where email = 'ben.allwright@learningpeople.co.uk' or secondary_email = 'ben.allwright@learningpeople.co.uk';\n\nselect * from teams;\nSELECT * FROM crm_profiles WHERE crm_configuration_id = 39;\nSELECT * FROM crm_fields WHERE crm_configuration_id = 39 and object_type = 'task';\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 1\nand sa.provider = 'salesforce';\n\n# ************************************************************************************\nSELECT * FROM activities WHERE uuid_to_bin('c38b3895-fd0f-4b1f-9fb2-c170dba137c6') = uuid;\nSELECT * FROM crm_configurations WHERE id = 70;\n\nselect * from teams where id = 1;\nselect * from groups where team_id = 1;\nselect * from users where team_id = 1;\n\nselect o.id, o.name,o.close_date, u.id, u.name, u.group_id, r.id, r.display_name, g.name, g.scope from opportunities o\njoin users u on o.user_id = u.id\njoin groups g on u.group_id = g.id\njoin role_user ru on u.id = ru.user_id\njoin roles r on ru.role_id = r.id\nwhere o.crm_configuration_id = 39 and close_date > '2024-01-01 00:00:00';\n\nselect * from role_user where user_id = 143;\nselect * from roles;\n\nselect * from role_user;\nselect * from groups where id = 9;\nselect * from scope_groups where group_id = 9;\n\n# ************************************************************************************\nselect * from teams where id = 36;\nselect * from crm_configurations;\nSELECT * FROM social_accounts WHERE sociable_id = 121;\n\nhttps://crmsandbox.zoho.com/crm/jiminnyw4/tab/Leads/4776201000005049105\nhttps://crmsandbox.zoho.com/crm/\n\nhttps://crm.zoho.com/crm/org3469620/tab/Leads/230045000229559080\n https://crm.zoho.com/crm/\n org3469620\n\nSELECT * FROM activities WHERE uuid_to_bin('03382d20-c8bc-48e7-a3d4-90b52fa5ceab') = uuid;\n\nselect * from users where email LIKE \"%mobile_automation_%\";\nselect * from social_accounts where sociable_id IN (2228);\nselect * from crm_profiles where user_id IN (2222,2223,2226,2227);\n\nselect * from teams order by id desc;\nSELECT * FROM users WHERE id = 2229;\nSELECT * FROM crm_profiles WHERE user_id = 2229;\nselect * from opportunities where crm_configuration_id = 88;\nselect * from crm_fields where crm_configuration_id = 88;\nselect * from crm_profiles where crm_configuration_id = 88;\n\nSELECT * FROM teams WHERE id = 1;\n\nSELECT * FROM users WHERE id = 143;\nSELECT * FROM users WHERE uuid_to_bin('fde193d3-06a2-4e1a-8895-62b94039215d') = uuid;\nSELECT * FROM teams WHERE uuid_to_bin('73385071-a756-42ae-9c73-8b53f2309467') = uuid;\n\nhttps://app.staging.jiminny.com/ondemand?\n min_duration=1\n &\n only_recorded=1\n &\n user_id%5B%5D=641f1acb-16b8-42d1-8726-df52979dad0e\n &\n sequence_number=2\n\n select * from users where team_id = 1 and email like '%stoyan%'\n\nselect * from coaching_feedbacks;\n\nselect * from teams;\nSELECT * FROM users WHERE team_id = 36;\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 19\nand sa.provider = 'pipedrive';\n\nselect * from users where id = 143;\n\nSELECT * FROM users WHERE uuid_to_bin('73180eeb-33de-4065-977d-ccbe0e6c94fc') = uuid;\nSELECT * FROM teams WHERE uuid_to_bin('73180eeb-33de-4065-977d-ccbe0e6c94fc') = uuid;\nSELECT * FROM activity_shares WHERE uuid_to_bin('73180eeb-33de-4065-977d-ccbe0e6c94fc') = uuid;\n\nselect * from users where team_id = 2;\nselect * from activities where crm_configuration_id = 39\nand activities.scheduled_start_time BETWEEN '2025-04-09 00:00:00' AND '2025-04-09 23:59:59'\nAND user_id = 143\norder by id desc;\n\n# ************************************************************************************\nselect * from teams where id = 142; # 2312, 126\nselect * from team_settings;\nselect * from users where team_id = 142; # 21642\nSELECT * FROM social_accounts WHERE sociable_id = 21642;\nSELECT * FROM crm_profiles cp join users u ON u.id = cp.user_id WHERE team_id = 142;\nselect * from crm_profiles where id IN (93);\nselect * from invitations;\nselect * from team_features where team_id = 1;\n\nSELECT * FROM crm_configurations WHERE id = 126;\nselect * from accounts where crm_configuration_id = 126 order by id desc;\nselect * from leads where crm_configuration_id = 126 order by id desc;\nselect * from contacts where crm_configuration_id = 126 order by id desc;\nselect * from opportunities where crm_configuration_id = 126 order by id desc;\nselect * from crm_profiles where crm_configuration_id = 126 order by id desc;\nselect * from crm_fields where crm_configuration_id = 126 # 11060\n# and type IN ('picklist', 'status')\n# and object_type = 'task'\norder by id desc;\n# 5731,5732,5733\nselect DISTINCT crm_field_id from crm_field_values where crm_field_id IN (11151,12239,12215,12185,12175,12165,12144,12137,12127,12109,12107,12105,12103,12092,12037,12005,12003,11987,11969,11958,11951,11942,11931,11924,11921,11917,11915,11901,11893,11883,11872,11870,11868,11866,11839,11833,11821,11793,11780,11777,11769,11757,11737,11735,11656,11645,11638,11629,11618,11611,11602,11591,11584,11581,11558,11544,11543,11534,11532,11529,11527,11503,11497,11493,11488,11470,11468,11457,11455,11397,11387,11372,11363,11348,11323,11318,11309,11301,11300,11292,11290,11286,11284,11256,11252,11242,11237,11233,11219,11176,11160) order by id desc;\nselect * from crm_layouts where crm_configuration_id = 126 order by id desc;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id in (300,299,298);\nselect * from stages where crm_configuration_id = 126 order by id desc;\nselect * from business_processes where crm_configuration_id = 126 order by id desc;\nselect * from business_process_stages where business_process_id IN (76,75,74,73);\nselect * from playbooks where team_id = 142;\nselect * from playbook_layouts where playbook_id IN (108);\nSELECT * FROM playbook_categories WHERE playbook_id IN (108);\n\nselect * from teams where id = 130;\nSELECT * FROM social_accounts WHERE sociable_id = 2291;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 2\nand sa.provider = 'hubspot';\n\nSELECT * FROM activities\n WHERE crm_configuration_id = 110;\n\nselect * from teams;\nselect * from crm_configurations;\n\nSELECT * FROM activities WHERE id = 628773;\nSELECT * FROM crm_profiles WHERE user_id = 1460;\nSELECT * FROM social_accounts WHERE sociable_id = 2291;\n\nselect * from teams;\nselect ru.*, pr.*, p.* from users u join role_user ru on ru.user_id = u.id\njoin permission_role pr on pr.role_id = ru.role_id\n join permissions p on p.id = pr.permission_id\nwhere team_id = 495 and p.name IN ('dial');\n\nselect * from teams where id = 145;\nselect * from crm_configurations where id = 129;\nselect * from social_accounts where sociable_id = 2317;\nSELECT * FROM activities WHERE uuid_to_bin('8dbab184-a333-4268-ad57-fb41f8d53a9a') = uuid;\n\nselect * from teams where id = 1;\nSELECT * FROM crm_layouts WHERE crm_configuration_id = 39;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 280;\nSELECT * FROM crm_layout_entities WHERE id = 5507;\nSELECT * FROM crm_fields WHERE crm_configuration_id = 39 and object_type IN ('event');\n\nselect * from teams;\nselect * from activities where crm_configuration_id = 14;\n\nSELECT * FROM social_accounts where provider = 'copper';\n\nselect * from activities where id = 628467;\nselect * from participants where activity_id = 628467;\n\nSELECT * FROM contacts WHERE id = 3969;\nSELECT * FROM accounts WHERE id = 177;\n\nSELECT * FROM activities WHERE uuid_to_bin('4eb54c77-cfa3-2bd4-84a7-9ed46a21c988') = uuid;\n\n# ********************* BH\nselect * from teams where id = 36;\nSELECT * FROM crm_configurations WHERE id = 21;\nselect * from activities where crm_configuration_id = 21 and id = 607901;\nselect * from activities where crm_configuration_id = 21;\n\nselect * roles;\nselect * from permissions;\nselect * from permission_role where permission_id = 226;\n\nselect * from migrations order by id desc;\n\n# mercury\n# neptune\n# earth\n\nselect * from teams;\nselect * from teams where id = 19;\nselect * from teams where id = 27;\nselect * from users where team_id = 27;\nSELECT * FROM crm_configurations WHERE id = 42;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 19\nand sa.provider = 'pipedrive';\n\nselect * from activities where id = 631461;\nSELECT * FROM crm_field_values WHERE crm_field_id = 180;\n\nselect * from teams where id = 2;\nSELECT * FROM social_accounts WHERE sociable_id = 89;\n\nSELECT * FROM activities WHERE uuid_to_bin('ba0c029a-bc14-4e17-8603-64174acebcbb') = uuid; # 634273\nselect * from activity_summary_logs where activity_id = 634273;\n\nselect * from sidekick_settings where team_id = 2;\n\nselect * from teams; # 2, 2\nSELECT * FROM crm_configurations WHERE team_id = 2; # 2\nselect * from team_features where team_id = 2;\nselect * from features;\nSELECT * FROM opportunities WHERE crm_configuration_id = 2 and crm_provider_id = '51317301383';\nSELECT * FROM opportunities WHERE crm_configuration_id = 2 order by id desc;\n\nselect * from automated_reports order by id desc;\nselect * from automated_report_results order by id desc;\nselect * from users where team_id = 1 and id IN (7160, 3248);\nselect * from migrations order by id desc;\n\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 1 and sa.provider = 'salesforce';\n\nselect * from teams where id = 1;\nselect * from groups g JOIN playbooks p on g.playbook_id = p.id where g.team_id = 1;\nselect * from groups where id = 565;\nselect * from playbooks where team_id = 1;\nselect * from playbooks where id = 175;\nselect * from playbook_categories where playbook_id = 175;\nselect * from users where team_id = 1;\nselect * from users where id = 7160;\nselect * from crm_profiles where user_id = 7160;\nselect * from features;\nselect\n *\n# id, uuid, type, provider, playbook_category_id, user_id, lead_id, contact_id, account_id, opportunity_id, stage_id,\n# crm_configuration_id, crm_provider_id, transcription_id, status\nfrom activities where crm_configuration_id = 1 and type = 'conference'\n# and crm_provider_id IS NOT NULL\nand provider != 'uploader' and actual_start_time IS NOT NULL\nORDER by id desc;\nselect * from activities where id = 54747783; # 00UO400000pCzojMAC\n\nselect p.id, p.activity_type, pc.id, pc.name\nFROM playbooks p\njoin playbook_categories pc on p.id = pc.playbook_id\nwhere p.team_id = 1 and p.activity_type = 'event';\n\nSELECT * FROM crm_fields WHERE crm_configuration_id = 1 and object_type = 'event';\nSELECT * FROM crm_field_values WHERE crm_field_id = 4;\n\nselect * from crm_layouts cl join playbook_layouts pl on cl.id = pl.layout_id\nwhere crm_configuration_id = 1 and pl.playbook_id = 175;\n\nselect * from teams;\nSELECT r.* FROM automated_reports r\njoin teams t on r.team_id = t.id\nWHERE r.frequency = 'daily'\n and r.status = 1\nAND t.status = 'active'\nAND (r.expires_at >= now() OR r.expires_at IS NULL);\n\nselect * from automated_report_results where report_id IN (18, 33);\n\nselect * from activity_searches where id = 10932;\nselect * from activity_search_filters where activity_search_id = 10932;\nselect * from automated_reports;\nselect * from automated_report_results where report_id IN (34, 35);","depth":4,"value":"SELECT * FROM teams WHERE id = 1;\n\nselect * from crm_layouts where crm_configuration_id = 39;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 283;\nSELECT * FROM crm_fields WHERE id = 2234;\nSELECT * FROM crm_field_values WHERE crm_field_id = 2234;\n\nselect * from crm_profiles where user_id = 143;\n\nselect * from record_types where crm_configuration_id = 39; # 0121K000001MHElQAO,0121K000001MHEqQAO\nselect * from business_processes where crm_configuration_id = 39;\n# 01941000000H669AAC, 01941000000H66JAAS\n\nselect * from record_type_field_values\n where record_type_id IN (24);\n\nselect * from crm_field_values where id IN (2730);\n\nselect * from crm_configurations where id = 39;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 1\nand sa.provider = 'salesforce'; #1035\n\n\nselect * from users where team_id = 1; # 222 group 3\nSELECT * FROM activities WHERE user_id = 222 order by id desc;\nselect * from sidekick_settings where team_id = 1;\nselect * from teams where id = 1;\nselect * from team_features where team_id = 1;\n\nselect * from activities where crm_configuration_id = 2\nand provider = 'ms-teams' and id = 608765;\n\nSELECT * FROM activities WHERE crm_configuration_id = 2 and crm_provider_id = '59523413338';\n\nselect * from sidekick_settings where team_id = 2;\n\nSELECT * FROM activities WHERE id = 608660;\nselect * from activity_summary_logs where activity_id = 608660;\nselect * from ai_prompts where transcription_id = 11214;\n\n# ********************************************************************************************************\nSELECT * FROM activities WHERE uuid_to_bin('ed78a437-2804-450e-ab2f-56ab1c641346') = uuid;\n# id: 608818, crm: 59628809737\nSELECT * FROM activities WHERE uuid_to_bin('36b06e55-afdd-4782-8dee-c624cd0af191') = uuid;\n# id: 608821, crm: 59632069252\nSELECT ce.start_time, ce.end_time, a.id, a.uuid, crm_provider_id, calendar_event_id, title,\nplaybook_category_id, user_id, lead_id, contact_id, account_id, opportunity_id,\nscheduled_start_time, scheduled_end_time, actual_start_time, actual_end_time, a.created_at\nFROM activities a\njoin calendar_events ce on a.calendar_event_id = ce.id\nWHERE a.id IN (608818, 608821);\n\nselect * from users where team_id = 1;\nselect * from team_settings where team_id = 1;\nselect * from crm_profiles where crm_configuration_id = 39 order by user_id;\n\nselect * from team_features where team_id = 1;\n\nselect * from users where team_id = 2;\n\nSELECT * FROM activities WHERE uuid_to_bin('ec7647e9-5225-458b-b475-f31aa2769204') = uuid; # 612639\n# Preslava N. Ivanova, grou id 3\n\nSELECT * FROM opportunities WHERE uuid_to_bin('a2928fe5-aec5-46cb-85d9-7654c89e46a6') = uuid;\n\nselect * from activities where opportunity_id = 344 and actual_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00';\n\nselect\n a.id,\n a.type,\n a.scheduled_start_time,\n a.actual_start_time,\n a.created_at,\n a.opportunity_id,\n a.status\nFROM activities a\nWHERE opportunity_id = 344\nand status IN ('completed', 'received', 'delivered')\nand (\n (a.actual_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00')\nOR (a.created_at between '2024-10-11 00:00:00' and '2024-10-12 00:00:00')\nOR (a.scheduled_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00'))\n;\n\nSELECT * FROM users WHERE id = 222;\n\nSELECT * FROM crm_profiles WHERE user_id = 222;\nselect * from crm_layouts where crm_configuration_id = 39;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 281;\n\nselect * from group_deal_risk_types;\n\nselect * from opportunities where team_id = 1;\n\nSELECT * FROM opportunities WHERE id = 315;\nSELECT * FROM crm_field_data WHERE object_id = 315;\nselect * from crm_field_data where object_id = 260;\n\nselect * from generic_ai_prompts where subject_id = 315;\n\nselect * from teams; # 36, 21, 121, james.graham@bullhorn.jiminny.com\nSELECT * FROM social_accounts WHERE sociable_id = 121 and provider = 'bullhorn';\n\n# ************************************************************************************\nselect * from teams where id = 1;\nselect * from crm_configurations where id = 39;\nselect * from users where team_id = 1;\nselect u.email, cp.* from users u\njoin crm_profiles cp on u.id = cp.user_id\nwhere u.team_id = 1;\n# 1 - 00541000004281rAAA\n# 204 - 0052g000003freeAAA\n# 429 - 0052g000003qGOiAAM\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 1\nand sa.provider = 'salesforce';\n\nselect * from activities where type = 'softphone'\nand created_at > '2024-12-11 15:24:36' order by id desc;\n\nselect * from activity_providers where team_id = 1;\nselect * from activity_provider_users where activity_provider_id = 328;\n\nselect * from opportunities where crm_configuration_id = 39\nAND account_id = 178 AND is_closed = false\norder by created_at DESC;\n\nselect * from contacts where id = 3952;\nselect * from accounts where id = 178;\n\n# ************************************************************************************\nselect * from teams where id = 36;\nselect * from crm_configurations where id = 21;\nselect * from users where team_id = 36;\nselect u.email, cp.* from users u\njoin crm_profiles cp on u.id = cp.user_id\nwhere u.team_id = 36;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 36\nand sa.provider = 'bullhorn';\n\nselect * from social_accounts where id = 348;\nUPDATE social_accounts SET\nprovider_user_token = '21442_6802599_91:41179a58-21e7-4d7c-ad58-56bb666b2f65',\nprovider_refresh_token = '21442_6802599_91:01c6b335-3f2a-42e4-85ff-8a08fa65fceb',\nexpires = 1733998131,\nstate = 'connected'\nWHERE id = 348;\n\n# ************************************************************************************\nselect * from teams where id = 31;\nselect * from crm_configurations where id = 18;\n\nselect * from users where team_id = 31; # 257\nselect u.email, cp.* from users u\njoin crm_profiles cp on u.id = cp.user_id\nwhere u.team_id = 31;\n\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 31\nand sa.provider = 'close';\n\nselect * from contacts where crm_configuration_id = 18;\n\n# ********************** NEPTUNE **************************************************************\nselect * from teams;\nselect * from users where id IN (1030, 1035, 1052);\nselect * from crm_configurations;\n\nselect * from users where team_id = 65; # 257\nselect * from team_settings where team_id = 65; # 257\nselect * from invitations where team_id = 65; # 257\nselect * from users where email = 'integration-account@jiminny.com'; # 257\nselect u.email, cp.* from users u\njoin crm_profiles cp on u.id = cp.user_id\nwhere u.team_id = 65;\n\nselect * from crm_configurations where id = 53;\nselect * from accounts where crm_configuration_id = 53 order by id desc;\nselect * from leads where crm_configuration_id = 53 order by id desc;\nselect * from contacts where crm_configuration_id = 53 order by id desc;\nselect * from opportunities where crm_configuration_id = 53 order by id desc;\nselect * from crm_profiles where crm_configuration_id = 53 order by id desc;\nselect * from crm_fields where crm_configuration_id = 53 order by id desc;\nselect * from crm_field_values where crm_field_id = 3341 order by id desc;\nselect * from crm_layouts where crm_configuration_id = 53 order by id desc;\nselect * from stages where crm_configuration_id = 53 order by id desc;\n\n\nselect * from crm_profiles where crm_configuration_id = 13;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 65\nand sa.provider = 'integration-app';\n\nselect * from contacts where crm_configuration_id = 13;\n\nselect * from social_accounts where sociable_id = 283;\n\nSELECT * FROM opportunities WHERE crm_provider_id = '006O400000E9bzeIAB';\n\nselect * from activity_providers where team_id = 65;\nSELECT * FROM activities WHERE crm_configuration_id IN (51, 52, 53);\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 65\n;\n\n# ***************************** STAGING ********************************************\nSELECT * FROM teams;\nSELECT * FROM teams WHERE id = 88;\nSELECT * FROM teams WHERE id = 89;\nselect * from team_settings where team_id = 89;\nSELECT * FROM users WHERE team_id = 89;\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 89;\n\nselect * from users;\nSELECT * FROM social_accounts WHERE sociable_id = 1761;\nSELECT * FROM crm_configurations WHERE id = 70;\nselect * from accounts where crm_configuration_id = 70 order by id desc;\nselect * from leads where crm_configuration_id = 70 order by id desc;\nselect * from contacts where crm_configuration_id = 70 order by id desc;\nselect * from opportunities where crm_configuration_id = 70 order by id desc;\nselect * from crm_profiles where crm_configuration_id = 70 order by id desc;\nselect * from crm_fields where crm_configuration_id = 70 order by id desc;\nselect * from crm_field_values where crm_field_id = 3536 order by id desc;\nselect * from crm_layouts where crm_configuration_id = 70 order by id desc;\nselect * from stages where crm_configuration_id = 70 order by id desc;\nselect * from business_processes where crm_configuration_id = 70 order by id desc;\nselect * from business_process_stages where business_process_id = 34;\n\nselect * from contacts where id = 10468;\n\nselect * from crm_layouts where crm_configuration_id = 70;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 388;\nSELECT * FROM crm_fields WHERE id IN (3533,3534,3535);\n\nselect * from activities where crm_configuration_id = 70\nand (account_id IS NOT NULL or lead_id IS NOT NULL or contact_id IS NOT NULL or opportunity_id IS NOT NULL) order by id desc;\n\nSELECT * FROM activities WHERE uuid_to_bin('2e10b60f-8a61-41c5-a3d4-28835353dc65') = uuid;\nSELECT * FROM activities where crm_configuration_id = 69 ;\n\nSELECT * FROM users WHERE email LIKE '%jiminny_web_sa2@jiminny.com%';\nSELECT * FROM activities WHERE uuid_to_bin('5a150c93-40fc-42ec-b3bd-c1d328e09f6e') = uuid;\nSELECT * FROM opportunities WHERE id = 385;\n\nselect * from participants p\njoin activities a on p.activity_id = a.id\nwhere a.crm_configuration_id = 70\nand (p.lead_id IS NOT NULL or p.contact_id IS NOT NULL);\nSELECT * FROM participants WHERE id = 1013638;\n\nselect * from teams where id = 90;\nselect * from users where team_id = 90;\nselect * from social_accounts where social_accounts.sociable_id IN (1960,1760);\nSELECT * FROM crm_profiles WHERE crm_configuration_id = 71;\nselect * from invitations where team_id = 90;\n\nselect * from crm_configurations where id = 71;\nselect * from accounts where crm_configuration_id = 71 order by id desc;\nselect * from leads where crm_configuration_id = 71 order by id desc;\nselect * from contacts where crm_configuration_id = 71 order by id desc;\nselect * from opportunities where crm_configuration_id = 71 order by id desc;\nselect * from crm_profiles where crm_configuration_id = 71 order by id desc;\nselect * from crm_fields where crm_configuration_id = 71 order by id desc;\nselect * from crm_field_values where crm_field_id = 3341 order by id desc;\nselect * from crm_layouts where crm_configuration_id = 71 order by id desc;\nselect * from stages where crm_configuration_id = 71 order by id desc;\n\nselect * from users order by secondary_email desc;\nselect u.id, u.email, u.status, sa.id, sa.provider_user_id from social_accounts sa\n join users u on sa.sociable_id = u.id\nwhere sa.provider = 'google' and u.email LIKE 'aneliya%';\n\nselect * from failed_jobs order by id desc;\n\nselect * from users where email = 'ben.allwright@learningpeople.co.uk' or secondary_email = 'ben.allwright@learningpeople.co.uk';\n\nselect * from teams;\nSELECT * FROM crm_profiles WHERE crm_configuration_id = 39;\nSELECT * FROM crm_fields WHERE crm_configuration_id = 39 and object_type = 'task';\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 1\nand sa.provider = 'salesforce';\n\n# ************************************************************************************\nSELECT * FROM activities WHERE uuid_to_bin('c38b3895-fd0f-4b1f-9fb2-c170dba137c6') = uuid;\nSELECT * FROM crm_configurations WHERE id = 70;\n\nselect * from teams where id = 1;\nselect * from groups where team_id = 1;\nselect * from users where team_id = 1;\n\nselect o.id, o.name,o.close_date, u.id, u.name, u.group_id, r.id, r.display_name, g.name, g.scope from opportunities o\njoin users u on o.user_id = u.id\njoin groups g on u.group_id = g.id\njoin role_user ru on u.id = ru.user_id\njoin roles r on ru.role_id = r.id\nwhere o.crm_configuration_id = 39 and close_date > '2024-01-01 00:00:00';\n\nselect * from role_user where user_id = 143;\nselect * from roles;\n\nselect * from role_user;\nselect * from groups where id = 9;\nselect * from scope_groups where group_id = 9;\n\n# ************************************************************************************\nselect * from teams where id = 36;\nselect * from crm_configurations;\nSELECT * FROM social_accounts WHERE sociable_id = 121;\n\nhttps://crmsandbox.zoho.com/crm/jiminnyw4/tab/Leads/4776201000005049105\nhttps://crmsandbox.zoho.com/crm/\n\nhttps://crm.zoho.com/crm/org3469620/tab/Leads/230045000229559080\n https://crm.zoho.com/crm/\n org3469620\n\nSELECT * FROM activities WHERE uuid_to_bin('03382d20-c8bc-48e7-a3d4-90b52fa5ceab') = uuid;\n\nselect * from users where email LIKE \"%mobile_automation_%\";\nselect * from social_accounts where sociable_id IN (2228);\nselect * from crm_profiles where user_id IN (2222,2223,2226,2227);\n\nselect * from teams order by id desc;\nSELECT * FROM users WHERE id = 2229;\nSELECT * FROM crm_profiles WHERE user_id = 2229;\nselect * from opportunities where crm_configuration_id = 88;\nselect * from crm_fields where crm_configuration_id = 88;\nselect * from crm_profiles where crm_configuration_id = 88;\n\nSELECT * FROM teams WHERE id = 1;\n\nSELECT * FROM users WHERE id = 143;\nSELECT * FROM users WHERE uuid_to_bin('fde193d3-06a2-4e1a-8895-62b94039215d') = uuid;\nSELECT * FROM teams WHERE uuid_to_bin('73385071-a756-42ae-9c73-8b53f2309467') = uuid;\n\nhttps://app.staging.jiminny.com/ondemand?\n min_duration=1\n &\n only_recorded=1\n &\n user_id%5B%5D=641f1acb-16b8-42d1-8726-df52979dad0e\n &\n sequence_number=2\n\n select * from users where team_id = 1 and email like '%stoyan%'\n\nselect * from coaching_feedbacks;\n\nselect * from teams;\nSELECT * FROM users WHERE team_id = 36;\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 19\nand sa.provider = 'pipedrive';\n\nselect * from users where id = 143;\n\nSELECT * FROM users WHERE uuid_to_bin('73180eeb-33de-4065-977d-ccbe0e6c94fc') = uuid;\nSELECT * FROM teams WHERE uuid_to_bin('73180eeb-33de-4065-977d-ccbe0e6c94fc') = uuid;\nSELECT * FROM activity_shares WHERE uuid_to_bin('73180eeb-33de-4065-977d-ccbe0e6c94fc') = uuid;\n\nselect * from users where team_id = 2;\nselect * from activities where crm_configuration_id = 39\nand activities.scheduled_start_time BETWEEN '2025-04-09 00:00:00' AND '2025-04-09 23:59:59'\nAND user_id = 143\norder by id desc;\n\n# ************************************************************************************\nselect * from teams where id = 142; # 2312, 126\nselect * from team_settings;\nselect * from users where team_id = 142; # 21642\nSELECT * FROM social_accounts WHERE sociable_id = 21642;\nSELECT * FROM crm_profiles cp join users u ON u.id = cp.user_id WHERE team_id = 142;\nselect * from crm_profiles where id IN (93);\nselect * from invitations;\nselect * from team_features where team_id = 1;\n\nSELECT * FROM crm_configurations WHERE id = 126;\nselect * from accounts where crm_configuration_id = 126 order by id desc;\nselect * from leads where crm_configuration_id = 126 order by id desc;\nselect * from contacts where crm_configuration_id = 126 order by id desc;\nselect * from opportunities where crm_configuration_id = 126 order by id desc;\nselect * from crm_profiles where crm_configuration_id = 126 order by id desc;\nselect * from crm_fields where crm_configuration_id = 126 # 11060\n# and type IN ('picklist', 'status')\n# and object_type = 'task'\norder by id desc;\n# 5731,5732,5733\nselect DISTINCT crm_field_id from crm_field_values where crm_field_id IN (11151,12239,12215,12185,12175,12165,12144,12137,12127,12109,12107,12105,12103,12092,12037,12005,12003,11987,11969,11958,11951,11942,11931,11924,11921,11917,11915,11901,11893,11883,11872,11870,11868,11866,11839,11833,11821,11793,11780,11777,11769,11757,11737,11735,11656,11645,11638,11629,11618,11611,11602,11591,11584,11581,11558,11544,11543,11534,11532,11529,11527,11503,11497,11493,11488,11470,11468,11457,11455,11397,11387,11372,11363,11348,11323,11318,11309,11301,11300,11292,11290,11286,11284,11256,11252,11242,11237,11233,11219,11176,11160) order by id desc;\nselect * from crm_layouts where crm_configuration_id = 126 order by id desc;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id in (300,299,298);\nselect * from stages where crm_configuration_id = 126 order by id desc;\nselect * from business_processes where crm_configuration_id = 126 order by id desc;\nselect * from business_process_stages where business_process_id IN (76,75,74,73);\nselect * from playbooks where team_id = 142;\nselect * from playbook_layouts where playbook_id IN (108);\nSELECT * FROM playbook_categories WHERE playbook_id IN (108);\n\nselect * from teams where id = 130;\nSELECT * FROM social_accounts WHERE sociable_id = 2291;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 2\nand sa.provider = 'hubspot';\n\nSELECT * FROM activities\n WHERE crm_configuration_id = 110;\n\nselect * from teams;\nselect * from crm_configurations;\n\nSELECT * FROM activities WHERE id = 628773;\nSELECT * FROM crm_profiles WHERE user_id = 1460;\nSELECT * FROM social_accounts WHERE sociable_id = 2291;\n\nselect * from teams;\nselect ru.*, pr.*, p.* from users u join role_user ru on ru.user_id = u.id\njoin permission_role pr on pr.role_id = ru.role_id\n join permissions p on p.id = pr.permission_id\nwhere team_id = 495 and p.name IN ('dial');\n\nselect * from teams where id = 145;\nselect * from crm_configurations where id = 129;\nselect * from social_accounts where sociable_id = 2317;\nSELECT * FROM activities WHERE uuid_to_bin('8dbab184-a333-4268-ad57-fb41f8d53a9a') = uuid;\n\nselect * from teams where id = 1;\nSELECT * FROM crm_layouts WHERE crm_configuration_id = 39;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 280;\nSELECT * FROM crm_layout_entities WHERE id = 5507;\nSELECT * FROM crm_fields WHERE crm_configuration_id = 39 and object_type IN ('event');\n\nselect * from teams;\nselect * from activities where crm_configuration_id = 14;\n\nSELECT * FROM social_accounts where provider = 'copper';\n\nselect * from activities where id = 628467;\nselect * from participants where activity_id = 628467;\n\nSELECT * FROM contacts WHERE id = 3969;\nSELECT * FROM accounts WHERE id = 177;\n\nSELECT * FROM activities WHERE uuid_to_bin('4eb54c77-cfa3-2bd4-84a7-9ed46a21c988') = uuid;\n\n# ********************* BH\nselect * from teams where id = 36;\nSELECT * FROM crm_configurations WHERE id = 21;\nselect * from activities where crm_configuration_id = 21 and id = 607901;\nselect * from activities where crm_configuration_id = 21;\n\nselect * roles;\nselect * from permissions;\nselect * from permission_role where permission_id = 226;\n\nselect * from migrations order by id desc;\n\n# mercury\n# neptune\n# earth\n\nselect * from teams;\nselect * from teams where id = 19;\nselect * from teams where id = 27;\nselect * from users where team_id = 27;\nSELECT * FROM crm_configurations WHERE id = 42;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 19\nand sa.provider = 'pipedrive';\n\nselect * from activities where id = 631461;\nSELECT * FROM crm_field_values WHERE crm_field_id = 180;\n\nselect * from teams where id = 2;\nSELECT * FROM social_accounts WHERE sociable_id = 89;\n\nSELECT * FROM activities WHERE uuid_to_bin('ba0c029a-bc14-4e17-8603-64174acebcbb') = uuid; # 634273\nselect * from activity_summary_logs where activity_id = 634273;\n\nselect * from sidekick_settings where team_id = 2;\n\nselect * from teams; # 2, 2\nSELECT * FROM crm_configurations WHERE team_id = 2; # 2\nselect * from team_features where team_id = 2;\nselect * from features;\nSELECT * FROM opportunities WHERE crm_configuration_id = 2 and crm_provider_id = '51317301383';\nSELECT * FROM opportunities WHERE crm_configuration_id = 2 order by id desc;\n\nselect * from automated_reports order by id desc;\nselect * from automated_report_results order by id desc;\nselect * from users where team_id = 1 and id IN (7160, 3248);\nselect * from migrations order by id desc;\n\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 1 and sa.provider = 'salesforce';\n\nselect * from teams where id = 1;\nselect * from groups g JOIN playbooks p on g.playbook_id = p.id where g.team_id = 1;\nselect * from groups where id = 565;\nselect * from playbooks where team_id = 1;\nselect * from playbooks where id = 175;\nselect * from playbook_categories where playbook_id = 175;\nselect * from users where team_id = 1;\nselect * from users where id = 7160;\nselect * from crm_profiles where user_id = 7160;\nselect * from features;\nselect\n *\n# id, uuid, type, provider, playbook_category_id, user_id, lead_id, contact_id, account_id, opportunity_id, stage_id,\n# crm_configuration_id, crm_provider_id, transcription_id, status\nfrom activities where crm_configuration_id = 1 and type = 'conference'\n# and crm_provider_id IS NOT NULL\nand provider != 'uploader' and actual_start_time IS NOT NULL\nORDER by id desc;\nselect * from activities where id = 54747783; # 00UO400000pCzojMAC\n\nselect p.id, p.activity_type, pc.id, pc.name\nFROM playbooks p\njoin playbook_categories pc on p.id = pc.playbook_id\nwhere p.team_id = 1 and p.activity_type = 'event';\n\nSELECT * FROM crm_fields WHERE crm_configuration_id = 1 and object_type = 'event';\nSELECT * FROM crm_field_values WHERE crm_field_id = 4;\n\nselect * from crm_layouts cl join playbook_layouts pl on cl.id = pl.layout_id\nwhere crm_configuration_id = 1 and pl.playbook_id = 175;\n\nselect * from teams;\nSELECT r.* FROM automated_reports r\njoin teams t on r.team_id = t.id\nWHERE r.frequency = 'daily'\n and r.status = 1\nAND t.status = 'active'\nAND (r.expires_at >= now() OR r.expires_at IS NULL);\n\nselect * from automated_report_results where report_id IN (18, 33);\n\nselect * from activity_searches where id = 10932;\nselect * from activity_search_filters where activity_search_id = 10932;\nselect * from automated_reports;\nselect * from automated_report_results where report_id IN (34, 35);","role_description":"text entry area","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.088194445,"height":0.027777778},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"102","depth":4,"role_description":"text"},{"role":"AXStaticText","text":"3","depth":4,"role_description":"text"},{"role":"AXStaticText","text":"34","depth":4,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Services\\Kiosk\\AutomatedReports;\n\nuse Carbon\\CarbonImmutable;\nuse Carbon\\CarbonInterface;\nuse Carbon\\Exceptions\\InvalidFormatException;\nuse DateTime;\nuse DateTimeInterface;\nuse DateTimeZone;\nuse Illuminate\\Contracts\\Bus\\Dispatcher as BusDispatcher;\nuse Illuminate\\Database\\Eloquent\\Builder;\nuse Illuminate\\Support\\Carbon;\nuse Illuminate\\Support\\Collection;\nuse Illuminate\\Support\\Facades\\Log;\nuse Illuminate\\Support\\Facades\\Storage;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinition\\InputTypeEnum;\nuse Jiminny\\Component\\AskAnything\\AskAnythingPromptService;\nuse Jiminny\\Component\\AskAnything\\Dtos\\AskAnythingPromptDto;\nuse Jiminny\\Component\\UrlGenerator\\Webhook;\nuse Jiminny\\Contracts\\Repositories\\PlaybookCategoryRepository;\nuse Jiminny\\Contracts\\Repositories\\TeamRepository;\nuse Jiminny\\Contracts\\Repositories\\UserRepository;\nuse Jiminny\\Exceptions\\ApplicationException;\nuse Jiminny\\Exceptions\\InvalidArgumentException;\nuse Jiminny\\Exceptions\\ModelNotFoundException;\nuse Jiminny\\Jobs\\AutomatedReports\\RequestGenerateReportJob;\nuse Jiminny\\Models\\Activity\\Search;\nuse Jiminny\\Models\\AskAnything\\AskAnythingPrompt;\nuse Jiminny\\Models\\AskAnything\\AskAnythingPromptTarget;\nuse Jiminny\\Models\\AutomatedReport;\nuse Jiminny\\Models\\AutomatedReportResult;\nuse Jiminny\\Models\\Contracts\\UserContract;\nuse Jiminny\\Models\\Feature\\FeatureEnum;\nuse Jiminny\\Models\\Team;\nuse Jiminny\\Models\\User;\nuse Jiminny\\Repositories\\AskAnythingRepository;\nuse Jiminny\\Repositories\\AutomatedReportsRepository;\nuse Jiminny\\Repositories\\GroupRepository;\nuse Jiminny\\Repositories\\SearchRepository;\nuse Jiminny\\Repositories\\StageRepository;\nuse Throwable;\n\nclass AutomatedReportsService\n{\n public const string TYPE_LOSS_ANALYSIS = 'loss_analysis';\n public const string TYPE_ASK_JIMINNY = 'ask_jiminny';\n\n /**\n * Standard report types (used by kiosk for existing automated reports).\n */\n // @TODO this will add filter, however if we need to control feature by FF we need conditional logic\n public const array TYPES = [\n ['id' => 'exec_summary', 'name' => 'Exec Summary'],\n ['id' => 'coaching_profiles', 'name' => 'Coaching Profiles'],\n ['id' => 'product_feedback', 'name' => 'Product Feedback'],\n ['id' => self::TYPE_LOSS_ANALYSIS, 'name' => 'Loss Analysis'],\n// ['id' => 'questions', 'name' => 'Questions'],\n// ['id' => 'statistical_quant', 'name' => 'Statistical Quantitative'],\n ];\n\n public const array ALL_TYPES = [\n ...self::TYPES,\n ['id' => self::TYPE_ASK_JIMINNY, 'name' => 'Ask Jiminny'],\n ];\n\n public const string FREQUENCY_DAILY = 'daily';\n public const string FREQUENCY_WEEKLY = 'weekly';\n public const string FREQUENCY_MONTHLY = 'monthly';\n public const string FREQUENCY_QUARTERLY = 'quarterly';\n public const string FREQUENCY_ONE_OFF = 'one_off';\n\n /**\n * Frequencies for standard (non-Ask Jiminny) reports.\n */\n public const array FREQUENCIES = [\n ['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],\n ['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],\n ['id' => self::FREQUENCY_QUARTERLY, 'name' => 'Quarterly'],\n ['id' => self::FREQUENCY_ONE_OFF, 'name' => 'One-off'],\n ];\n\n /**\n * Frequencies for Ask Jiminny reports.\n */\n public const array ASK_JIMINNY_FREQUENCIES = [\n ['id' => self::FREQUENCY_DAILY, 'name' => 'Daily'],\n ['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],\n ['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],\n ];\n\n public const string MEDIA_TYPE_PDF = 'pdf';\n public const string MEDIA_TYPE_PODCAST = 'podcast';\n public const array MEDIA_TYPES = [self::MEDIA_TYPE_PDF, self::MEDIA_TYPE_PODCAST];\n public const array MEDIA_TYPE_OBJECT_PDF = ['id' => self::MEDIA_TYPE_PDF, 'name' => 'PDF'];\n public const array MEDIA_TYPE_OBJECT_PODCAST = ['id' => self::MEDIA_TYPE_PODCAST, 'name' => 'Podcast'];\n public const array MEDIA_TYPE_OBJECTS = [self::MEDIA_TYPE_OBJECT_PDF, self::MEDIA_TYPE_OBJECT_PODCAST];\n\n public const array CALL_TYPE_CONFERENCE = ['id' => 'conference', 'name' => 'Conference'];\n public const array CALL_TYPE_DIALER = ['id' => 'dialer', 'name' => 'Dialer'];\n public const int SENT_REPORT_AT_HOURS = 5;\n public const string PDF_KEY = 'pdf';\n public const string AUDIO_KEY = 'audio';\n\n private const array ALL_FREQUENCIES = [\n ['id' => self::FREQUENCY_DAILY, 'name' => 'Daily'],\n ['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],\n ['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],\n ['id' => self::FREQUENCY_QUARTERLY, 'name' => 'Quarterly'],\n ['id' => self::FREQUENCY_ONE_OFF, 'name' => 'One-off'],\n ];\n private const string S3_DIR = 'reports';\n private const array FILE_EXTENSIONS_VARIANTS = ['html', 'MD', 'pdf'];\n private const array FILE_PODCAST_EXTENSIONS_VARIANTS = ['json', 'mp3', 'ssml'];\n\n public function __construct(\n private readonly TeamRepository $teamRepository,\n private readonly GroupRepository $groupRepository,\n private readonly UserRepository $userRepository,\n private readonly StageRepository $stageRepository,\n private readonly DealStagesService $dealStagesService,\n private readonly RecipientsService $recipientsService,\n private readonly AutomatedReportsRepository $automatedReportsRepository,\n private readonly Webhook $webhookService,\n private readonly BusDispatcher $dispatcher,\n private readonly ActivityTypeService $activityTypeService,\n private readonly PlaybookCategoryRepository $playbookCategoryRepository,\n private readonly AskAnythingPromptService $askAnythingPromptService,\n private readonly SearchRepository $activitySearchRepository,\n private readonly AskAnythingRepository $askAnythingRepository,\n ) {\n }\n\n public static function getTypes(): array\n {\n $types = self::TYPES;\n\n return array_map(static function ($type) {\n return $type['id'];\n }, $types);\n }\n\n public static function getCallTypes(): array\n {\n return array_map(static function ($callType) {\n return $callType['id'];\n }, [self::CALL_TYPE_CONFERENCE, self::CALL_TYPE_DIALER]);\n }\n\n public static function getFrequencies(): array\n {\n return array_map(static function ($frequency) {\n return $frequency['id'];\n }, self::FREQUENCIES);\n }\n\n // front-facing structure\n public function getReportEnabledFieldData(bool $value = false): array\n {\n return [\n 'id' => 'report_enabled',\n 'label' => '',\n 'inputType' => InputTypeEnum::TOGGLE,\n 'value' => $value,\n ];\n }\n\n // Organizations = Teams\n public function getOrganizationFieldData(?string $value = null, bool $shortVersion = false): array\n {\n $options = $this->getTeams();\n\n if ($shortVersion) {\n return [\n 'id' => 'organization',\n 'label' => 'Organization',\n 'options' => $options,\n ];\n }\n\n return [\n 'id' => 'organization',\n 'label' => 'Organization',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => $options,\n 'value' => $value,\n 'dependencies' => [\n 'teams',\n 'deal_stage_at_call',\n 'current_deal_stage',\n 'recipients',\n ActivityTypeService::PLAYBOOK_CATEGORIES_KEY,\n ],\n 'dependsOn' => [],\n ];\n }\n\n // Teams = Groups\n public function getTeamFieldData(array $options = [], array $value = [], bool $shortVersion = false): array\n {\n if ($shortVersion) {\n return [\n 'id' => 'teams',\n 'label' => 'Team',\n 'options' => $options,\n ];\n }\n\n return [\n 'id' => 'teams',\n 'label' => 'Team',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'required' => false,\n 'placeholder' => 'Select',\n 'options' => $options,\n 'value' => $value, // value should be an array of objects {id, name}\n 'dependencies' => [ActivityTypeService::PLAYBOOK_CATEGORIES_KEY],\n 'dependsOn' => [],\n ];\n }\n\n public function getReportTypeFieldData(?string $value = null, bool $shortVersion = false, ?Team $team = null): array\n {\n $types = [];\n if ($team instanceof Team) {\n if ($team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {\n $types = self::TYPES;\n }\n if ($team->hasFeature(FeatureEnum::ASK_JIMINNY_REPORTS)) {\n $types[] = ['id' => self::TYPE_ASK_JIMINNY, 'name' => 'Ask Jiminny'];\n }\n } else {\n $types = self::TYPES;\n }\n\n if ($shortVersion) {\n return [\n 'id' => 'report_type',\n 'label' => 'Report Type',\n 'options' => $types,\n ];\n }\n\n return [\n 'id' => 'report_type',\n 'label' => 'Report Type',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => $types,\n 'value' => $value,\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getFrequencyFieldData(?string $value = null): array\n {\n return [\n 'id' => 'frequency',\n 'label' => 'Frequency',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => self::FREQUENCIES,\n 'value' => $value,\n 'dependencies' => ['period'],\n 'dependsOn' => [],\n ];\n }\n\n public function getPeriodFieldData(?string $valueStartDate = null, ?string $valueEndDate = null): array\n {\n return [\n 'id' => 'period',\n 'label' => 'Select one-off period',\n 'inputType' => InputTypeEnum::DATE_RANGE,\n 'required' => true,\n 'placeholder' => 'Select',\n 'value' => ['startDate' => $valueStartDate, 'endDate' => $valueEndDate],\n 'queryParams' => [\n 'startDate' => 'start_date_period',\n 'endDate' => 'end_date_period',\n ],\n 'dependencies' => [],\n 'dependsOn' => ['frequency'],\n ];\n }\n\n public function getActivityTypesFieldData(?Team $team = null, array $value = [], array $teamsFilter = []): array\n {\n return $this->activityTypeService->getActivityTypeFieldData(team: $team, value: $value, groupIds: $teamsFilter);\n }\n\n public function getDealStageAtCallFieldData(?Team $team = null, array $value = []): array\n {\n return $this->dealStagesService->getDealStageAtCallFieldData(team: $team, value: $value);\n }\n\n public function getCurrentDealStageFieldData(?Team $team = null, array $value = []): array\n {\n return $this->dealStagesService->getCurrentDealStageFieldData(team: $team, value: $value);\n }\n\n public function getDealValueFieldData(?int $valueMin = null, ?int $valueMax = null): array\n {\n return [\n 'id' => 'deal_value',\n 'label' => 'Deal Value',\n 'inputType' => InputTypeEnum::INTEGER_RANGE,\n 'required' => false,\n 'value' => ['min' => $valueMin, 'max' => $valueMax],\n 'queryParams' => [\n 'min' => 'min_deal_value',\n 'max' => 'max_deal_value',\n ],\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getCallTypeFieldData(bool $conferenceOn = false, bool $dialerOn = false): array\n {\n $value = [];\n $conferenceOn && $value[] = self::CALL_TYPE_CONFERENCE;\n $dialerOn && $value[] = self::CALL_TYPE_DIALER;\n\n return [\n 'id' => 'call_type',\n 'label' => 'Call Type',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'required' => true,\n 'options' => [\n self::CALL_TYPE_CONFERENCE,\n self::CALL_TYPE_DIALER,\n ],\n 'value' => $value,\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getMediaTypeFieldData(?AutomatedReport $report = null): array\n {\n $value = [];\n\n if ($report) {\n $value = $this->transformMediaTypes($report);\n }\n\n return [\n 'id' => 'media_types',\n 'label' => 'Export as',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'required' => true,\n 'options' => self::MEDIA_TYPE_OBJECTS,\n 'value' => $value,\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getCallDurationFieldData(?int $valueMin = null, ?int $valueMax = null): array\n {\n return [\n 'id' => 'call_duration',\n 'label' => 'Call Duration',\n 'inputType' => InputTypeEnum::INTEGER_RANGE,\n 'required' => false,\n 'value' => ['min' => $valueMin, 'max' => $valueMax],\n 'queryParams' => [\n 'min' => 'min_call_duration',\n 'max' => 'max_call_duration',\n ],\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getRecipientsFieldData(?Team $team = null, array $value = []): array\n {\n return $this->recipientsService->getRecipientsFieldData(team: $team, value: $value);\n }\n\n public function getJiminnyRecipientsFieldData(array $value = []): array\n {\n return $this->recipientsService->getJiminnyRecipientsFieldData($value);\n }\n\n public function getAdditionalPromptInputFieldData(?string $value = null): array\n {\n return [\n 'id' => 'additional_prompt_input',\n 'label' => 'Special requirements',\n 'inputType' => InputTypeEnum::TEXTAREA,\n 'required' => false,\n 'placeholder' => 'What should be the focus of the report?',\n 'value' => $value,\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getCustomReportNameFieldData(?string $value = null): array\n {\n return [\n 'id' => 'custom_name',\n 'label' => 'Custom report name',\n 'inputType' => InputTypeEnum::TEXT,\n 'required' => false,\n 'placeholder' => 'Enter custom name',\n 'value' => $value,\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n // data providers\n public function getTeams(): array\n {\n $teams = $this->teamRepository->getTeamsForKiosk(status: Team::STATUS_ACTIVE);\n\n $teamData = [];\n foreach ($teams as $team) {\n if (! $team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {\n continue;\n }\n\n $teamData[] = $this->transformTeam($team);\n }\n\n return $teamData;\n }\n\n public function getTeamGroups(string $teamUuid): array\n {\n $data = [];\n $team = $this->getTeam($teamUuid);\n\n if ($team !== null) {\n $groups = $team->groups()->get();\n\n foreach ($groups as $group) {\n $data[] = [\n 'id' => $group->getUuid(),\n 'name' => $group->getName(),\n ];\n }\n }\n\n return $data;\n }\n\n public function getTeamsGroupsOptions(array $filterTeamUuids = []): array\n {\n $data = [];\n $teams = $this->getTeams();\n\n foreach ($teams as $team) {\n if (! empty($filterTeamUuids) && ! in_array($team['id'], $filterTeamUuids, true)) {\n continue;\n }\n\n $data[] = [\n 'label' => $team['name'],\n 'groups' => $this->getTeamGroups($team['id']),\n ];\n }\n\n return $data;\n }\n\n public function getTeam(string $teamUuid): ?Team\n {\n return $this->teamRepository->idOrUuid($teamUuid);\n }\n\n public function getTeamById(int $teamId): ?Team\n {\n return $this->teamRepository->find($teamId);\n }\n\n public function getGroupsUuids(AutomatedReport $report): array\n {\n $uuids = [];\n $reportGroups = $report->getGroups();\n foreach ($reportGroups as $groupId) {\n if ($group = $this->groupRepository->find($groupId)) {\n $uuids[] = $group->getUuid();\n }\n }\n\n return $uuids;\n }\n\n public function getPlaybookCategoriesUuids(AutomatedReport $report): array\n {\n $uuids = [];\n $playbookCategories = $report->getPlaybookCategories();\n foreach ($playbookCategories as $id) {\n if ($category = $this->playbookCategoryRepository->find($id)) {\n $uuids[] = $category->getUuid();\n }\n }\n\n return $uuids;\n }\n\n public function getDealAtCallStagesUuids(AutomatedReport $report): array\n {\n $uuids = [];\n $reportStages = $report->getDealAtCallStages();\n foreach ($reportStages as $id) {\n if ($stage = $this->stageRepository->find($id)) {\n $uuids[] = $stage->getUuid();\n }\n }\n\n return $uuids;\n }\n\n public function getCurrentDealStagesUuids(AutomatedReport $report): array\n {\n $uuids = [];\n $reportStages = $report->getCurrentDealStages();\n foreach ($reportStages as $id) {\n if ($stage = $this->stageRepository->find($id)) {\n $uuids[] = $stage->getUuid();\n }\n }\n\n return $uuids;\n }\n\n public function getUsersUuids(AutomatedReport $report): array\n {\n return $this->extractUserUuids($report->getRecipients());\n }\n\n public function getJiminnyUsersUuids(AutomatedReport $report): array\n {\n return $this->extractUserUuids($report->getJiminnyRecipients());\n }\n\n /**\n * @param array<string, mixed> $recipients\n */\n private function extractUserUuids(array $recipients): array\n {\n $userIds = $recipients['users'] ?? [];\n\n return collect($userIds)\n ->map(fn ($id) => $this->userRepository->find((int) $id))\n ->filter()\n ->map(fn (UserContract $user) => $user->getUuid())\n ->values()\n ->all();\n }\n\n // get mail data\n public function getRecipientUsers(AutomatedReport $report): array\n {\n return $this->buildRecipientUsers($report->getRecipients());\n }\n\n private function getJiminnyRecipientUsers(AutomatedReport $report): array\n {\n return $this->buildRecipientUsers($report->getJiminnyRecipients());\n }\n\n /**\n * @param array<string, mixed> $recipients\n */\n private function buildRecipientUsers(array $recipients): array\n {\n $userIds = $recipients['users'] ?? [];\n\n return collect($userIds)\n ->map(fn ($id) => $this->userRepository->find((int) $id))\n ->filter()\n ->map(fn (UserContract $user) => [\n 'email' => $user->getEmailAddress(),\n 'name' => $user->getName(),\n 'timezone' => $user->getTimezone()->getName(),\n ])\n ->values()\n ->all();\n }\n\n public function getValidRecipientUsers(AutomatedReport $report, bool $includeJiminny = false): array\n {\n if ($report->isAskJiminnyReport()) {\n $recipients = $this->resolveAskJiminnyRecipients($report);\n } else {\n $recipients = $this->getRecipientUsers($report);\n if ($includeJiminny) {\n $recipients = array_merge($recipients, $this->getJiminnyRecipientUsers($report));\n }\n }\n\n $emails = [];\n\n return array_values(array_filter(\n $recipients,\n static function ($recipient) use (&$emails) {\n if (empty($recipient['email']) || in_array($recipient['email'], $emails, true)) {\n return false;\n }\n $emails[] = $recipient['email'];\n\n return true;\n }\n ));\n }\n\n private function resolveAskJiminnyRecipients(AutomatedReport $report): array\n {\n $recipients = [];\n\n $creator = $report->getCreator();\n if ($creator !== null) {\n $recipients[] = [\n 'email' => $creator->getEmailAddress(),\n 'name' => $creator->getName(),\n 'timezone' => $creator->getTimezone()->getName(),\n ];\n }\n\n return array_merge(\n $recipients,\n $this->buildRecipientUsers($report->getRecipients()),\n $this->getGroupRecipientUsers($report),\n );\n }\n\n private function getGroupRecipientUsers(AutomatedReport $report): array\n {\n $users = [];\n foreach ($report->getGroups() as $groupId) {\n $group = $this->groupRepository->find($groupId);\n if ($group === null) {\n continue;\n }\n foreach ($group->getMembers() as $member) {\n $users[] = [\n 'email' => $member->getEmailAddress(),\n 'name' => $member->getName(),\n 'timezone' => $member->getTimezone()->getName(),\n ];\n }\n }\n\n return $users;\n }\n\n public function getReportTypeName(AutomatedReportResult $report): string\n {\n $type = $report->getReport()->getType();\n\n $getType = $this->transformReportType($type);\n\n return $getType['name'];\n }\n\n public function getReportPeriodName(AutomatedReportResult $report): string\n {\n $from = $report->getFromDate();\n $to = $report->getToDate();\n $frequency = $report->getReport()->getFrequency();\n\n if ($from === null || $to === null) {\n if (! $report->getReport()->isAskJiminnyReport()) {\n $invalidPeriod = $from === null ? 'from' : 'to';\n\n throw new ApplicationException('Report period is invalid: ' . $invalidPeriod);\n }\n\n $period = $this->calculateFromAndToDatePeriod($frequency);\n $from = $period['fromDate'];\n $to = $period['toDate'];\n }\n\n return $this->formatReportPeriodName($frequency, $from, $to);\n }\n\n private function formatReportPeriodName(string $frequency, Carbon $from, Carbon $to): string\n {\n $fromYear = $from->format('Y');\n $toYear = $to->format('Y');\n $differentYears = $fromYear !== $toYear;\n\n switch ($frequency) {\n case self::FREQUENCY_DAILY:\n return $from->format('j M Y');\n\n case self::FREQUENCY_QUARTERLY:\n // 'Jan-Mar 2025' or 'Nov 2024-Jan 2025' if years differ\n $startMonth = $from->format('M');\n $endMonth = $to->copy()->subMonth();\n $endMonthName = $endMonth->format('M');\n $endMonthYear = $endMonth->format('Y');\n\n if ($differentYears) {\n return \"{$startMonth} {$fromYear} - {$endMonthName} {$endMonthYear}\";\n }\n\n return \"{$startMonth} - {$endMonthName} {$toYear}\";\n\n case self::FREQUENCY_MONTHLY:\n // 'May 2025' - monthly reports are always within the same year\n return $from->format('M Y');\n\n case self::FREQUENCY_WEEKLY:\n // '4 - 8 Aug 2025', '27 Oct - 3 Nov 2025', or '28 Dec 2024 - 3 Jan 2025' if years differ\n $startDay = $from->format('j');\n $endDay = $to->format('j');\n $startMonth = $from->format('M');\n $endMonth = $to->format('M');\n\n if ($differentYears) {\n return \"{$startDay} {$startMonth} {$fromYear} - {$endDay} {$endMonth} {$toYear}\";\n }\n\n if ($startMonth !== $endMonth) {\n return \"{$startDay} {$startMonth} - {$endDay} {$endMonth} {$toYear}\";\n }\n\n return \"{$startDay} - {$endDay} {$endMonth} {$toYear}\";\n\n case self::FREQUENCY_ONE_OFF:\n // '2 May-31 May 2025' or '15 Dec 2024-15 Jan 2025' if years differ\n $startDay = $from->format('j');\n $startMonth = $from->format('M');\n $endDay = $to->format('j');\n $endMonth = $to->format('M');\n\n // If same month and year, use a format like '2-31 May 2025'\n if ($startMonth === $endMonth && ! $differentYears) {\n return \"{$startDay} - {$endDay} {$startMonth} {$toYear}\";\n }\n\n // If different years, include both years\n if ($differentYears) {\n return \"{$startDay} {$startMonth} {$fromYear} - {$endDay} {$endMonth} {$toYear}\";\n }\n\n // Same year but different months\n return \"{$startDay} {$startMonth} - {$endDay} {$endMonth} {$toYear}\";\n\n default:\n // Default format for unknown frequencies\n return $from->format('j M Y') . ' - ' . $to->format('j M Y');\n }\n }\n\n public function getReportTeamsName(AutomatedReportResult $report): string\n {\n $groups = $report->getGroups();\n\n if (empty($groups)) {\n return 'All';\n }\n\n // Get group names from repository\n $groupNames = [];\n foreach ($groups as $groupId) {\n $group = $this->groupRepository->find($groupId);\n if ($group) {\n $groupNames[] = $group->getName();\n }\n }\n\n if (count($groupNames) === 1) {\n // Single team format\n $teamsName = $groupNames[0];\n } else {\n // Multiple teams format\n $teamsName = implode(', ', $groupNames);\n }\n\n return $teamsName;\n }\n\n public function getReportFileName(AutomatedReportResult $report): string\n {\n $customName = $report->getReport()->getCustomName();\n $periodName = $this->getReportPeriodName($report);\n $filenameSuffix = $this->getFilenameSuffix($report);\n\n if ($customName) {\n if ($filenameSuffix) {\n $customName .= \" {$filenameSuffix}\";\n }\n\n return $this->sanitizeFileName(\"{$customName} - {$periodName}\");\n }\n\n $baseName = $this->getReportTypeName($report);\n\n if ($filenameSuffix) {\n $baseName .= \" {$filenameSuffix}\";\n }\n\n return $this->sanitizeFileName(\"{$baseName} - {$periodName} - {$this->getReportTeamsName($report)}\");\n }\n\n public function getReportFileNameWithExtension(AutomatedReportResult $result): string\n {\n $extension = $this->getMediaTypeMetadata($result)['extension'];\n\n return $this->getReportFileName($result) . '.' . $extension;\n }\n\n public function sanitizeFileName(string $fileName): string\n {\n return str_replace(['/', '\\\\'], '-', $fileName);\n }\n\n public function isUserRecipientOfReport(User $user, AutomatedReport $report): bool\n {\n $recipients = array_map('intval', $report->getRecipients()['users'] ?? []);\n\n return in_array($user->getId(), $recipients);\n }\n\n public function transformReportResults(Collection $automatedReportResults): array\n {\n $data = [];\n foreach ($automatedReportResults as $automatedReportResult) {\n /** @var AutomatedReportResult $automatedReportResult */\n\n $report = $automatedReportResult->getReport();\n\n $createdBy = $report->getCreator();\n $creator = [\n 'id' => $createdBy?->getUuid(),\n 'name' => $createdBy?->getName(),\n 'email' => $createdBy?->getEmailAddress(),\n 'photoUrl' => $createdBy?->getPhotoUrl(),\n ];\n\n $data[] = [\n 'id' => $automatedReportResult->getUuid(),\n 'name' => $automatedReportResult->getName(),\n 'frequency' => $this->transformFrequency($report->getFrequency()),\n 'recipients' => [\n ...array_values($this->transformGroups(team: $report->getTeam(), groupsIds: $report->getGroups())),\n ...array_values($this->transformRecipients($report->getRecipients())),\n ],\n 'report_type' => $this->transformReportType($report->getType()),\n 'media_type' => $automatedReportResult->getMediaType(),\n 'downloadUrl' => $this->generateReportResultDownloadUrl($automatedReportResult),\n 'viewUrl' => $this->generateReportResultViewUrl($automatedReportResult),\n 'generated_at' => $automatedReportResult->getGeneratedAt()?->toIso8601String(),\n 'creator' => $creator,\n ];\n }\n\n return $data;\n }\n\n public function hasCallTypeConference(AutomatedReport $report): bool\n {\n return in_array(self::CALL_TYPE_CONFERENCE['id'], $report->getCallTypes(), true);\n }\n\n public function hasCallTypeDialer(AutomatedReport $report): bool\n {\n return in_array(self::CALL_TYPE_DIALER['id'], $report->getCallTypes(), true);\n }\n\n // transformers\n private function transformTeam(Team $team): array\n {\n if (! $team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {\n return [];\n }\n\n return [\n 'id' => $team->getUuid(),\n 'name' => $team->getName(),\n ];\n }\n\n private function transformReportFullView(AutomatedReport $report): array\n {\n $base = $this->transformReportBase($report);\n\n return $report->getType() === self::TYPE_ASK_JIMINNY\n ? $base + $this->transformAskJiminnyFields($report)\n : $base + $this->transformStandardReportFields($report);\n }\n\n private function transformReportBase(AutomatedReport $report): array\n {\n return [\n 'id' => $report->getUuid(),\n 'organization' => $this->transformOrganization(team: $report->getTeam()),\n 'report_type' => $this->transformReportType($report->getType()),\n 'frequency' => $this->transformFrequency($report->getFrequency()),\n ];\n }\n\n private function transformStandardReportFields(AutomatedReport $report): array\n {\n $team = $report->getTeam();\n\n return [\n 'report_enabled' => $report->getStatus(),\n 'start_date_period' => $report->getFrom()?->format('Y-m-d H:i:s'),\n 'end_date_period' => $report->getTo()?->format('Y-m-d H:i:s'),\n 'deal_value_min' => $report->getDealValueMin(),\n 'deal_value_max' => $report->getDealValueMax(),\n 'call_types' => $this->transformCallType($report->getCallTypes()),\n 'media_types' => $this->transformMediaTypes($report),\n 'call_duration_min' => $this->transformDurationToMinutes($report->getCallDurationMin()),\n 'call_duration_max' => $this->transformDurationToMinutes($report->getCallDurationMax()),\n 'teams' => $this->transformGroups(team: $team, groupsIds: $report->getGroups()),\n 'deal_at_call_stages' => $this->transformStages(team: $team, stagesIds: $report->getDealAtCallStages()),\n 'current_deal_stages' => $this->transformStages(team: $team, stagesIds: $report->getCurrentDealStages()),\n 'recipients' => $this->transformRecipients($report->getRecipients()),\n 'created_by' => $this->transformCreator($report->getCreator()),\n 'additional_prompt_input' => $report->getAdditionalPromptInput(),\n 'custom_name' => $report->getCustomName(),\n 'created_at' => $report->getCreatedAt()->format('Y-m-d H:i:s'),\n 'updated_at' => $report->getUpdatedAt()->format('Y-m-d H:i:s'),\n 'deleted_at' => $report->getDeletedAt()?->format('Y-m-d H:i:s'),\n ];\n }\n\n private function transformAskJiminnyFields(AutomatedReport $report): array\n {\n $team = $report->getTeam();\n $creatorId = $report->getAttribute('created_by');\n $explicitUserIds = array_values(array_filter(\n $report->getRecipients()['users'] ?? [],\n static fn ($id) => $id !== $creatorId\n ));\n\n return [\n 'report_name' => $report->getCustomName(),\n 'enabled' => $report->getStatus(),\n 'share_teams' => $this->transformGroups(team: $team, groupsIds: $report->getGroups()),\n 'share_users' => $this->transformRecipients(['users' => $explicitUserIds]),\n 'saved_search' => $this->transformSafeSearch($report->getSavedSearch()),\n 'ask_jiminny_prompt' => $this->transformAskJiminnyPrompt($report->getAskAnythingPrompt()),\n 'expires_on' => $report->getExpiresAt()?->format('Y-m-d'),\n ];\n }\n\n private function transformOrganization(?Team $team): array\n {\n return [\n 'id' => $team?->getUuid(),\n 'name' => $team?->getName(),\n ];\n }\n\n private function transformReportType(string $type): array\n {\n foreach (self::ALL_TYPES as $typeItem) {\n if ($typeItem['id'] === $type) {\n return $typeItem;\n }\n }\n\n return [];\n }\n\n private function transformCallType(array $types): array\n {\n $result = [];\n $callTypes = [self::CALL_TYPE_CONFERENCE, self::CALL_TYPE_DIALER];\n\n foreach ($types as $type) {\n foreach ($callTypes as $callTypeItem) {\n if ($callTypeItem['id'] === $type) {\n $result[] = $callTypeItem;\n\n break;\n }\n }\n }\n\n return $result;\n }\n\n private function transformMediaTypes(AutomatedReport $report): array\n {\n $values = [];\n\n foreach ($report->getMediaTypes() as $mediaType) {\n if (! in_array($mediaType, self::MEDIA_TYPES, true)) {\n continue;\n }\n\n $values[] = match ($mediaType) {\n self::MEDIA_TYPE_PDF => self::MEDIA_TYPE_OBJECT_PDF,\n self::MEDIA_TYPE_PODCAST => self::MEDIA_TYPE_OBJECT_PODCAST,\n };\n }\n\n return $values;\n }\n\n private function transformFrequency(string $frequency): array\n {\n foreach (self::ALL_FREQUENCIES as $frequencyItem) {\n if ($frequencyItem['id'] === $frequency) {\n return $frequencyItem;\n }\n }\n\n return [];\n }\n\n public function transformDurationToMinutes(?int $duration): ?int\n {\n if (! $duration) {\n return null;\n }\n\n return (int) ($duration / 60);\n }\n\n private function transformGroups(?Team $team, array $groupsIds): array\n {\n if (empty($groupsIds) || ! $team) {\n return [];\n }\n\n $data = [];\n foreach ($groupsIds as $groupId) {\n $group = $team->groups()->where('id', $groupId)->first();\n\n if ($group) {\n $data[] = [\n 'id' => $group->getUuid(),\n 'name' => $group->getName(),\n 'photoUrl' => $group->getPhotoUrl(),\n ];\n }\n }\n\n return $data;\n }\n\n private function transformStages(?Team $team, array $stagesIds): array\n {\n if (empty($stagesIds) || ! $team) {\n return [];\n }\n\n $data = [];\n foreach ($stagesIds as $stageId) {\n $stage = $team->stages()->where('id', $stageId)->first();\n\n if ($stage) {\n $data[] = [\n 'id' => $stage->getUuid(),\n 'name' => $stage->getName(),\n ];\n }\n }\n\n return $data;\n }\n\n private function transformRecipients(array $recipients): array\n {\n $users = [];\n foreach ($recipients['users'] ?? [] as $userId) {\n $users[] = $this->transformUser($userId);\n }\n\n return $users;\n }\n\n private function transformCreator(?User $user): ?array\n {\n if ($user === null) {\n return null;\n }\n\n return $this->transformUser($user->getId());\n }\n\n private function transformAskJiminnyPrompt(?AskAnythingPrompt $prompt): ?array\n {\n if ($prompt === null) {\n return null;\n }\n\n return [\n 'id' => $prompt->getUuid(),\n 'name' => $prompt->getTitle(),\n ];\n }\n\n private function transformSafeSearch(?Search $search): ?array\n {\n if ($search === null) {\n return null;\n }\n\n return [\n 'id' => $search->getUuid(),\n 'name' => $search->getName(),\n ];\n }\n\n private function transformUser(int $userId): array\n {\n /* @var ?User $user */\n $user = $this->userRepository->find($userId);\n\n return [\n 'id' => $user?->getUuid(),\n 'name' => $user?->getName(),\n 'email' => $user?->getEmailAddress(),\n 'photoUrl' => $user?->getPhotoUrl(),\n ];\n }\n\n public function create(array $data): array\n {\n $validatedData = $this->validateAndTransformData($data);\n $validatedData['created_by'] = auth()->id();\n\n $automatedReport = $this->automatedReportsRepository->create($validatedData);\n\n $this->generateOneOffReport($automatedReport);\n\n return $this->transformReportFullView($automatedReport);\n }\n\n public function update(string $uuid, array $data): array\n {\n $validatedData = $this->validateAndTransformData($data);\n $report = $this->automatedReportsRepository->findByUuid($uuid);\n\n if (! $report) {\n throw new InvalidArgumentException('Report not found');\n }\n\n $oldCustomName = $report->getCustomName();\n\n $automatedReport = $this->automatedReportsRepository->update($report, $validatedData);\n\n if ($oldCustomName !== $automatedReport->getCustomName()) {\n $this->updateResultNames($automatedReport);\n }\n\n $this->generateOneOffReport($automatedReport);\n\n return $this->transformReportFullView($automatedReport);\n }\n\n /**\n * Create an Ask Jiminny report.\n */\n public function createAskJiminnyReport(array $data, User $creator): array\n {\n $validatedData = $this->validateAskJiminnyReportData($data, $creator);\n $validatedData['created_by'] = $creator->getId();\n\n $automatedReport = $this->automatedReportsRepository->create($validatedData);\n\n return $this->transformReportFullView($automatedReport);\n }\n\n /**\n * Update an Ask Jiminny report.\n */\n public function updateAskJiminnyReport(AutomatedReport $report, array $data, User $user): array\n {\n if (! $report->isAskJiminnyReport()) {\n throw new InvalidArgumentException('Report is not an Ask Jiminny report');\n }\n\n $validatedData = $this->validateAskJiminnyReportData($data, $user);\n\n $oldCustomName = $report->getCustomName();\n\n $automatedReport = $this->automatedReportsRepository->update($report, $validatedData);\n\n if ($oldCustomName !== $automatedReport->getCustomName()) {\n $this->updateResultNames($automatedReport);\n }\n\n return $this->transformReportFullView($automatedReport);\n }\n\n public function updateAskJiminnyReportStatus(AutomatedReport $report, bool $status): array\n {\n $this->automatedReportsRepository->update($report, ['status' => $status]);\n\n return $this->transformReportFullView($report->fresh());\n }\n\n /**\n * Validate and transform data for Ask Jiminny reports.\n */\n private function validateAskJiminnyReportData(array $data, User $user): array\n {\n // Validate name\n $name = trim($data['report_name'] ?? '');\n if (empty($name)) {\n throw new InvalidArgumentException('Report name is required');\n }\n if (mb_strlen($name) > 50) {\n throw new InvalidArgumentException('Report name must be 50 characters or less');\n }\n\n // Validate frequency (only daily, weekly, monthly for Ask Jiminny)\n $frequency = $data['frequency'] ?? null;\n $askJiminnyFrequencies = [self::FREQUENCY_DAILY, self::FREQUENCY_WEEKLY, self::FREQUENCY_MONTHLY];\n if (! in_array($frequency, $askJiminnyFrequencies, true)) {\n throw new InvalidArgumentException('Frequency must be daily, weekly, or monthly');\n }\n\n // Validate expiration date\n $expiresAt = $data['expires_on'] ?? null;\n if (empty($expiresAt)) {\n throw new InvalidArgumentException('Expiration date is required');\n }\n\n try {\n $expiresAtDate = Carbon::parse($expiresAt);\n } catch (InvalidFormatException $e) {\n throw new InvalidArgumentException('Expiration date format is invalid');\n }\n $maxExpiration = Carbon::now()->addYear();\n if ($expiresAtDate->gt($maxExpiration)) {\n throw new InvalidArgumentException('Expiration date cannot be more than 1 year from now');\n }\n if ($expiresAtDate->isPast()) {\n throw new InvalidArgumentException('Expiration date cannot be in the past');\n }\n\n // Validate saved search\n $activitySearchId = $data['saved_search'] ?? null;\n if (empty($activitySearchId)) {\n throw new InvalidArgumentException('Saved search is required');\n }\n $savedSearch = $this->activitySearchRepository->findByUuidAndUser($activitySearchId, $user);\n if (! $savedSearch) {\n throw new InvalidArgumentException('Saved search not found or does not belong to you');\n }\n\n // Validate saved prompt\n $askAnythingPromptId = $data['ask_jiminny_prompt'] ?? null;\n if (empty($askAnythingPromptId)) {\n throw new InvalidArgumentException('Ask Jiminny prompt is required');\n }\n $prompt = $this->askAnythingRepository->getPromptByUuid($askAnythingPromptId);\n if (! $prompt) {\n throw new InvalidArgumentException('Ask Jiminny prompt not found');\n }\n\n // Validate status\n $status = $data['enabled'] ?? false;\n\n $recipientUserIds = [$user->getId()];\n\n if (! empty($data['share_users'])) {\n $sharedUserIds = $this->validateAndGetUserIdsByTeam(\n $user->team,\n (array) $data['share_users']\n );\n $recipientUserIds = array_merge($recipientUserIds, $sharedUserIds);\n }\n\n $sharedGroupIds = [];\n if (! empty($data['share_teams'])) {\n $sharedGroupIds = $this->validateAndGetGroupIds($user->team, (array) $data['share_teams']);\n }\n\n $recipientUserIds = array_values(array_unique($recipientUserIds));\n\n return [\n 'team_id' => $user->getTeamId(),\n 'type' => self::TYPE_ASK_JIMINNY,\n 'status' => (bool) $status,\n 'frequency' => $frequency,\n 'custom_name' => $name,\n 'activity_search_id' => $savedSearch->getId(),\n 'ask_anything_prompt_id' => $prompt->getId(),\n 'expires_at' => $expiresAtDate->toDateString(),\n 'media_types' => [self::MEDIA_TYPE_PDF],\n 'call_types' => [],\n 'recipients' => ['users' => $recipientUserIds],\n 'groups' => $sharedGroupIds,\n ];\n }\n\n public static function getAskJiminnyFrequencies(): array\n {\n return array_map(static function ($frequency) {\n return $frequency['id'];\n }, self::ASK_JIMINNY_FREQUENCIES);\n }\n\n public function getAskJiminnyReportFilters(User $user): array\n {\n $savedSearches = $this->activitySearchRepository->findByUserOrderedByName($user)\n ->map(fn (Search $search) => [\n 'id' => $search->getUuid(),\n 'name' => $search->getName(),\n ])\n ->values()->all();\n\n $prompts = collect(\n $this->askAnythingPromptService->get($user, AskAnythingPromptTarget::on_demand)\n )->map(fn (AskAnythingPromptDto $prompt) => [\n 'id' => $prompt->id,\n 'name' => $prompt->title,\n ])->values()->all();\n\n return [\n [\n 'id' => 'prompt',\n 'label' => 'Prompt',\n 'options' => $prompts,\n ],\n [\n 'id' => 'saved_search',\n 'label' => 'Saved Search',\n 'options' => $savedSearches,\n ],\n ];\n }\n\n public function getAskJiminnyReportFormData(User $user, ?AutomatedReport $report = null): array\n {\n $team = $user->getTeam();\n $userTimezone = $user->getTimezone();\n\n $savedSearches = $this->activitySearchRepository->findByUserOrderedByName($user)\n ->map(fn (Search $search) => [\n 'id' => $search->getUuid(),\n 'name' => $search->getName(),\n ])\n ->values()->all();\n\n $prompts = collect(\n $this->askAnythingPromptService->get($user, AskAnythingPromptTarget::on_demand)\n )->map(fn (AskAnythingPromptDto $prompt) => [\n 'id' => $prompt->id,\n 'name' => $prompt->title,\n ])->values()->all();\n\n $teamGroups = $this->groupRepository->getAllByTeam($team)->map(fn ($group) => [\n 'id' => $group->getUuid(),\n 'name' => $group->getName(),\n ])->values()->all();\n\n $shareUsers = $this->recipientsService->getRecipientsFieldData(team: $team)['options'] ?? [];\n\n $sharedTeamsValue = [];\n $sharedUsersValue = [];\n if ($report) {\n $sharedTeamsValue = $this->transformGroups($team, $report->getGroups());\n\n $recipientUserIds = $report->getRecipients()['users'] ?? [];\n $creatorId = $report->getAttribute('created_by');\n $sharedUserIds = array_values(array_filter(\n $recipientUserIds,\n static fn ($id) => $id !== $creatorId\n ));\n $sharedUsersValue = collect($sharedUserIds)\n ->map(fn ($id) => $this->userRepository->find((int) $id))\n ->filter()\n ->map(fn (User $u) => [\n 'id' => $u->getUuid(),\n 'name' => $u->getName(),\n ])\n ->values()\n ->all();\n }\n\n return [\n 'fields' => [\n [\n 'id' => 'enabled',\n 'inputType' => InputTypeEnum::TOGGLE,\n 'label' => '',\n 'value' => $report?->getStatus() ?? false,\n ],\n [\n 'id' => 'report_name',\n 'inputType' => InputTypeEnum::TEXT,\n 'label' => 'Name',\n 'placeholder' => 'Enter name',\n 'required' => true,\n 'validation' => ['maxLength' => 50],\n 'value' => $report?->getCustomName() ?? '',\n ],\n [\n 'id' => 'frequency',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'label' => 'Frequency',\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => self::ASK_JIMINNY_FREQUENCIES,\n 'value' => $report ? $this->transformFrequency($report->getFrequency()) : null,\n ],\n [\n 'id' => 'expires_on',\n 'inputType' => InputTypeEnum::DATE,\n 'label' => 'Expires on',\n 'required' => true,\n 'placeholder' => 'Select',\n 'validation' => [\n 'minDate' => now($userTimezone)->toDateString(),\n 'maxDate' => now($userTimezone)->addYear()->toDateString(),\n ],\n 'value' => $report?->getExpiresAt()?->toDateString(),\n ],\n [\n 'id' => 'share_teams',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'label' => 'Team',\n 'required' => false,\n 'placeholder' => 'Select',\n 'options' => $teamGroups,\n 'value' => $sharedTeamsValue,\n ],\n [\n 'id' => 'share_users',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'label' => 'Team member',\n 'required' => false,\n 'placeholder' => 'Select',\n 'groupLabelKey' => 'label',\n 'groupValuesKey' => 'users',\n 'optionLabelKey' => 'name',\n 'optionValueKey' => 'id',\n 'options' => $shareUsers,\n 'value' => $sharedUsersValue,\n ],\n [\n 'id' => 'saved_search',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'label' => 'Saved search',\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => $savedSearches,\n 'value' => $report && $report->getSavedSearch() ? [\n 'id' => $report->getSavedSearch()->getUuid(),\n 'name' => $report->getSavedSearch()->getName(),\n ] : null,\n ],\n [\n 'id' => 'ask_jiminny_prompt',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'label' => 'Ask Jiminny prompt',\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => $prompts,\n 'value' => $report && $report->getAskAnythingPrompt() ? [\n 'id' => $report->getAskAnythingPrompt()->getUuid(),\n 'name' => $report->getAskAnythingPrompt()->getTitle(),\n ] : null,\n ],\n ],\n ];\n }\n\n private function updateResultNames(AutomatedReport $automatedReport): void\n {\n $results = $this->automatedReportsRepository->getResultsByReport($automatedReport);\n\n foreach ($results as $result) {\n $result->update(['name' => $this->getReportFileName($result)]);\n }\n }\n\n public function updateStatus(string $uuid, array $data): array\n {\n $automatedReport = $this->automatedReportsRepository->findByUuid($uuid);\n\n if (! $automatedReport) {\n throw new ModelNotFoundException('Report not found');\n }\n\n $status = $this->validateReportStatus($data['report_enabled'] ?? null);\n $automatedReport->update([\n 'status' => $status,\n ]);\n\n $this->generateOneOffReport($automatedReport);\n\n return $this->transformReportFullView($automatedReport);\n }\n\n private function generateOneOffReport(AutomatedReport $automatedReport): void\n {\n // the scheduler handles all the other frequency types\n if ($automatedReport->getStatus() === false || $automatedReport->getFrequency() !== self::FREQUENCY_ONE_OFF) {\n return;\n }\n\n $this->dispatcher->dispatch(new RequestGenerateReportJob($automatedReport->getUuid()));\n }\n\n public function getReport(string $uuid): AutomatedReport\n {\n $automatedReport = $this->automatedReportsRepository->findByUuid($uuid);\n\n if (! $automatedReport) {\n throw new ModelNotFoundException('Report not found');\n }\n\n return $automatedReport;\n }\n\n public function get(string $uuid): array\n {\n $automatedReport = $this->getReport($uuid);\n\n return $this->transformReportFullView($automatedReport);\n }\n\n public function list(string $sortColumn = 'created_at', string $sortDirection = 'desc'): array\n {\n $results = [];\n $collection = $this->automatedReportsRepository->getAllStandardReports($sortColumn, $sortDirection);\n\n /** @var AutomatedReport $report */\n foreach ($collection as $report) {\n $results[] = $this->transformReportFullView($report);\n }\n\n return ['data' => $results];\n }\n\n public function listAskJiminnyReports(\n User $user,\n string $sortColumn = 'created_at',\n string $sortDirection = 'desc'\n ): array {\n $results = [];\n $collection = $this->automatedReportsRepository->getAskJiminnyReportsByUser($user, $sortColumn, $sortDirection);\n\n /** @var AutomatedReport $report */\n foreach ($collection as $report) {\n $results[] = $this->transformReportFullView($report);\n }\n\n return ['data' => $results];\n }\n\n public function delete(string $uuid): void\n {\n $automatedReport = $this->automatedReportsRepository->findByUuid($uuid);\n\n if (! $automatedReport) {\n throw new ModelNotFoundException('Report not found');\n }\n\n $automatedReport->delete();\n }\n\n public function createReportResult(AutomatedReport $automatedReport, array $data = []): AutomatedReportResult\n {\n return $this->automatedReportsRepository->createResult(\n array_merge(\n [\n 'report_id' => $automatedReport->getId(),\n 'status' => AutomatedReportResult::STATUS_DEFAULT,\n ],\n $data\n )\n );\n }\n\n public function getReportResult(string $resultUuid): AutomatedReportResult\n {\n $report = $this->automatedReportsRepository->findResultByUuid($resultUuid);\n\n if (! $report) {\n throw new ModelNotFoundException('Report Result not found');\n }\n\n return $report;\n }\n\n public function findChildResult(AutomatedReportResult $result, string $type): ?AutomatedReportResult\n {\n return $this->automatedReportsRepository->findChildResult($result, $type);\n }\n\n // prophet API calls\n /**\n * @throws ApplicationException\n */\n public function getGenerateReportPayload(AutomatedReport $automatedReport, string $reportResultUuid): array\n {\n $period = $this->calculateFromAndToDate($automatedReport);\n $fromDate = $period['fromDate'];\n $toDate = $period['toDate'];\n\n return [\n 'team_id' => $automatedReport->getTeamId(),\n 'request_id' => $reportResultUuid,\n 'report_type' => $automatedReport->getType(),\n 'media_types' => $automatedReport->getMediaTypes(),\n 'from_date' => $fromDate->startOfDay()->format(DateTimeInterface::RFC3339),\n 'to_date' => $toDate->endOfDay()->format(DateTimeInterface::RFC3339),\n 'group_ids' => $automatedReport->getGroups(),\n 'call_deal_stage' => $automatedReport->getDealAtCallStages(),\n 'current_deal_stage' => $automatedReport->getCurrentDealStages(),\n 'deal_min_value' => $automatedReport->getDealValueMin(),\n 'deal_max_value' => $automatedReport->getDealValueMax(),\n 'call_types' => $automatedReport->getCallTypes(),\n 'call_duration_min_seconds' => $automatedReport->getCallDurationMin(),\n 'call_duration_max_seconds' => $automatedReport->getCallDurationMax(),\n 'special_requirements' => $automatedReport->getAdditionalPromptInput(),\n 'callback_url' => $this->getCallbackUrl(),\n 'report_period' => $this->formatReportPeriodName(\n $automatedReport->getFrequency(),\n $fromDate,\n $toDate,\n ),\n 'playbook_categories' => $automatedReport->getPlaybookCategories(),\n 'custom_name' => $automatedReport->getCustomName(),\n ];\n }\n\n // $inputPayload - FE payload structure\n public function getActivitiesCountPayload(array $inputPayload): array\n {\n // Use validateAndTransformData to validate and normalize input\n $validatedData = $this->validateAndTransformData($inputPayload);\n $period = $this->calculateFromAndToDatePeriod(\n $validatedData['frequency'],\n Carbon::parse($validatedData['from']),\n Carbon::parse($validatedData['to']),\n );\n $fromDate = $period['fromDate'];\n $toDate = $period['toDate'];\n\n // Create payload similar to getGenerateReportPayload\n return [\n 'team_id' => $validatedData['team_id'],\n 'group_ids' => $validatedData['groups'] ?? [],\n 'report_type' => $validatedData['type'],\n 'from_date' => $fromDate->format(DateTimeInterface::RFC3339),\n 'to_date' => $toDate->format(DateTimeInterface::RFC3339),\n 'call_deal_stage' => $validatedData['deal_at_call_stages'] ?? [],\n 'current_deal_stage' => $validatedData['current_deal_stages'] ?? [],\n 'deal_min_value' => $validatedData['deal_value_min'] ?? null,\n 'deal_max_value' => $validatedData['deal_value_max'] ?? null,\n 'call_types' => $validatedData['call_types'],\n 'call_duration_min_seconds' => $validatedData['call_duration_min'] ?? null,\n 'call_duration_max_seconds' => $validatedData['call_duration_max'] ?? null,\n 'special_requirements' => $validatedData['additional_prompt_input'] ?? null,\n 'playbook_categories' => $validatedData['playbook_categories'] ?? [],\n 'request_id' => null,\n 'callback_url' => null,\n ];\n }\n\n public function shouldSendReport(array $users, ?CarbonInterface $generatedAt = null): bool\n {\n if (empty($users)) {\n return false;\n }\n\n $earliestTz = collect($users)\n ->mapWithKeys(function (array $user) {\n $tz = new DateTimeZone($user['timezone']);\n $nowUtc = new DateTime('now', new DateTimeZone('UTC'));\n $offset = $tz->getOffset($nowUtc);\n\n return [$user['timezone'] => $offset];\n })\n ->sortDesc()\n ->keys()\n ->first();\n\n $now = Carbon::now($earliestTz);\n $isScheduledTime = (int) $now->format('H') === self::SENT_REPORT_AT_HOURS;\n\n if ($isScheduledTime) {\n return true;\n }\n\n return $this->hasPassedScheduledTime($generatedAt, $earliestTz);\n }\n\n public function hasPassedScheduledTime(?CarbonInterface $generatedAt, string $timezone): bool\n {\n if ($generatedAt === null) {\n return false;\n }\n\n $now = Carbon::now($timezone);\n $scheduledTime = $now->copy()->setTime(self::SENT_REPORT_AT_HOURS, 0, 0);\n\n if ($now->hour < self::SENT_REPORT_AT_HOURS) {\n $scheduledTime = $scheduledTime->subDay();\n }\n\n $scheduledTimeUtc = $scheduledTime->copy()->utc();\n $generatedAtUtc = $generatedAt->copy()->utc();\n $nowUtc = $now->copy()->utc();\n\n return $generatedAtUtc->lt($scheduledTimeUtc) && $nowUtc->gt($scheduledTimeUtc);\n }\n\n public function calculateFromAndToDatePeriod(\n string $frequency,\n ?Carbon $fromDate = null,\n ?Carbon $toDate = null\n ): array {\n if ($frequency === self::FREQUENCY_ONE_OFF) {\n return [\n 'fromDate' => $fromDate,\n 'toDate' => $toDate,\n ];\n }\n\n $now = Carbon::now();\n\n return match ($frequency) {\n self::FREQUENCY_DAILY => [\n 'fromDate' => $now->copy()->subDay()->startOfDay(),\n 'toDate' => $now->copy()->subDay()->endOfDay(),\n ],\n self::FREQUENCY_WEEKLY => [\n 'fromDate' => $now->copy()->subWeeks(1)->startOfDay(),\n 'toDate' => $now->copy()->subDay()->endOfDay(),\n ],\n self::FREQUENCY_MONTHLY => [\n 'fromDate' => $now->copy()->subMonths(1)->startOfDay(),\n 'toDate' => $now->copy()->subDay()->endOfDay(),\n ],\n self::FREQUENCY_QUARTERLY => [\n 'fromDate' => $now->copy()->subMonths(3)->startOfDay(),\n 'toDate' => $now->copy()->subDay()->endOfDay(),\n ],\n default => throw new InvalidArgumentException(\"Unsupported frequency: {$frequency}\"),\n };\n }\n\n private function calculateFromAndToDate(AutomatedReport $automatedReport): array\n {\n return $this->calculateFromAndToDatePeriod(\n $automatedReport->getFrequency(),\n $automatedReport->getFrom(),\n $automatedReport->getTo()\n );\n }\n\n public function getAskJiminnyGenerateReportPayload(\n AutomatedReport $automatedReport,\n AutomatedReportResult $reportResult,\n array $activityIds,\n ): array {\n return [\n 'user_question' => $automatedReport->getAskAnythingPrompt()?->getContent(),\n 'call_ids' => array_map('strval', $activityIds),\n 'team_id' => $automatedReport->getTeamId(),\n 'request_id' => $reportResult->getUuid(),\n 'callback_url' => $this->getCallbackUrl(),\n 'report_period' => $this->getReportPeriodName($reportResult),\n 'report_name' => $automatedReport->getCustomName(),\n ];\n }\n\n private function getCallbackUrl(): string\n {\n return $this->webhookService->route('jiminny.webhook.reports.ready');\n }\n\n /**\n * Validate and transform payload data for automated reports\n *\n * @param array $data\n *\n * @throws InvalidArgumentException\n *\n * @return array\n */\n private function validateAndTransformData(array $data): array\n {\n // Validate organization (team) and check feature\n $team = $this->validateOrganization($data['organization'] ?? null);\n\n $status = $this->validateReportStatus($data['report_enabled'] ?? null);\n $type = $this->validateReportType($data['report_type'] ?? null);\n $frequency = $this->validateFrequency($data['frequency'] ?? null);\n $additionalPromptInput = $this->validateAdditionalPromptInput(\n $data['additional_prompt_input'] ?? null\n );\n $customReportName = $this->validateCustomReportName($data['custom_name'] ?? null);\n\n // Prepare data for the database\n $reportData = [\n 'team_id' => $team->getId(),\n 'type' => $type,\n 'status' => $status,\n 'frequency' => $frequency,\n 'additional_prompt_input' => $additionalPromptInput,\n 'custom_name' => $customReportName,\n ];\n\n // Validate deal values\n $reportData = $this->validateDealValues($data, $reportData);\n\n // Validate date range\n $reportData = $this->validateDateRange($data, $reportData, $frequency);\n\n // Validate call durations\n $reportData = $this->validateCallDurations($data, $reportData);\n\n // Validate call types\n $reportData = $this->validateCallTypes($data, $reportData);\n\n // Validate media types\n $reportData = $this->validateMediaTypes($data, $reportData);\n\n // Validate groups\n if (isset($data['teams'])) {\n $reportData['groups'] = $this->validateAndGetGroupIds($team, $data['teams']);\n }\n\n // Validate deal stages\n $reportData = $this->validateDealStages($data, $reportData, $team, $type);\n\n // Validate playbook categories\n $reportData = $this->validatePlaybookCategories($data, $reportData, $team);\n\n // Validate recipients\n $reportData['recipients'] = [\n 'users' => $this->validateAndGetUserIdsByTeam($team, $data['recipients'] ?? []),\n ];\n\n if (isset($data['jiminny_recipients'])) {\n // Validate Jiminny recipients\n $reportData['jiminny_recipients'] = [\n 'users' => $this->validateAndGetJiminnyUserIds((array) $data['jiminny_recipients']),\n ];\n }\n\n return $reportData;\n }\n\n private function validateDealValues(array $data, array $reportData): array\n {\n if (isset($data['min_deal_value'])) {\n $reportData['deal_value_min'] = (int) $data['min_deal_value'];\n\n if ($reportData['deal_value_min'] > 4294967295 || $reportData['deal_value_min'] < 0) {\n throw new InvalidArgumentException('Min deal value should be between 0 and 4294967295');\n }\n }\n\n if (isset($data['max_deal_value'])) {\n $reportData['deal_value_max'] = (int) $data['max_deal_value'];\n\n if ($reportData['deal_value_max'] > 4294967295 || $reportData['deal_value_max'] < 0) {\n throw new InvalidArgumentException('Max deal value should be between 0 and 4294967295');\n }\n }\n\n if (isset($data['min_deal_value'], $data['max_deal_value'])\n && $data['min_deal_value'] > $data['max_deal_value']\n ) {\n throw new InvalidArgumentException('Min deal value cannot be greater than max deal value');\n }\n\n return $reportData;\n }\n\n private function validateDateRange(array $data, array $reportData, string $frequency): array\n {\n // Set date range only for one_off frequency\n if ($frequency === 'one_off') {\n if (isset($data['start_date_period'])) {\n $reportData['from'] = $this->parseDate($data['start_date_period']);\n }\n\n if (isset($data['end_date_period'])) {\n $reportData['to'] = $this->parseDate($data['end_date_period']);\n }\n\n if (empty($reportData['from']) || empty($reportData['to'])) {\n throw new InvalidArgumentException(\n 'Start date and end date are required for one_off frequency'\n );\n }\n } else {\n $reportData['from'] = null;\n $reportData['to'] = null;\n }\n\n return $reportData;\n }\n\n private function validateCallDurations(array $data, array $reportData): array\n {\n // Convert call durations from minutes to seconds\n if (isset($data['min_call_duration'])) {\n $reportData['call_duration_min'] = (int) $data['min_call_duration'] * 60;\n\n if ($reportData['call_duration_min'] > 4294967295 || $reportData['call_duration_min'] < 0) {\n throw new InvalidArgumentException('Min call duration should be between 0 and 4294967295');\n }\n }\n\n if (isset($data['max_call_duration'])) {\n $reportData['call_duration_max'] = (int) $data['max_call_duration'] * 60;\n\n if ($reportData['call_duration_max'] > 4294967295 || $reportData['call_duration_max'] < 0) {\n throw new InvalidArgumentException('Max call duration should be between 0 and 4294967295');\n }\n }\n\n return $reportData;\n }\n\n private function validateCallTypes(array $data, array $reportData): array\n {\n // Set call types\n $reportData['call_types'] = $data['call_type'] ?? [];\n if (empty($reportData['call_types'])) {\n $reportData['call_types'] = self::getCallTypes();\n }\n\n foreach ($reportData['call_types'] as $callType) {\n if (! in_array($callType, self::getCallTypes(), true)) {\n throw new InvalidArgumentException(sprintf('Call type %s is invalid', $callType));\n }\n }\n\n return $reportData;\n }\n\n private function validateMediaTypes(array $data, array $reportData): array\n {\n // Set media types from input data\n $reportData['media_types'] = $data['media_types'] ?? [];\n\n if (empty($reportData['media_types'])) {\n throw new InvalidArgumentException('Media types are required');\n }\n\n foreach ($reportData['media_types'] as $mediaType) {\n if (! in_array($mediaType, self::MEDIA_TYPES, true)) {\n throw new InvalidArgumentException(sprintf('Media type %s is invalid', $mediaType));\n }\n }\n\n return $reportData;\n }\n\n private function validateDealStages(array $data, array $reportData, Team $team, string $reportType): array\n {\n // Validate and set deal stages\n if (isset($data['deal_stage_at_call'])) {\n $reportData['deal_at_call_stages'] =\n $this->validateAndGetDealStageIds($team, $data['deal_stage_at_call'], 'Deal stage at call');\n }\n\n if (isset($data['current_deal_stage'])) {\n $reportData['current_deal_stages'] =\n $this->validateAndGetDealStageIds($team, $data['current_deal_stage'], 'Current deal stage');\n }\n\n // Ensure current_deal_stage is not provided for loss_analysis report type\n if ($reportType === self::TYPE_LOSS_ANALYSIS && ! empty($data['current_deal_stage'])) {\n throw new InvalidArgumentException('Current deal stage is not applicable for Loss Analysis reports');\n }\n\n return $reportData;\n }\n\n // transform uuid to id\n private function validatePlaybookCategories(array $data, array $reportData, Team $team): array\n {\n $key = 'playbook_categories';\n\n if (isset($data[$key])) {\n $payloadIds = $data[$key];\n $ids = [];\n\n foreach ($payloadIds as $uuid) {\n $uuid = (string) $uuid;\n\n try {\n $playbookCategory = $this->playbookCategoryRepository->findByUuid($uuid);\n } catch (Throwable $throwable) {\n Log::error(__METHOD__ . ' ' . $throwable->getMessage());\n\n throw new InvalidArgumentException(sprintf('Playbook category %s not found', $uuid));\n }\n\n if (! $playbookCategory) {\n throw new InvalidArgumentException(sprintf('Playbook category %s not found', $uuid));\n }\n\n if (! $playbookCategory->hasPlaybook()) {\n throw new InvalidArgumentException(sprintf('Playbook category %s has no playbook', $uuid));\n }\n\n if ($playbookCategory->getPlaybook()->getTeamId() !== $team->getId()) {\n throw new InvalidArgumentException(\n sprintf('Playbook category %s not found for team %s', $uuid, $team->getUuid())\n );\n }\n\n $ids[] = $playbookCategory->getId();\n }\n\n $reportData[$key] = $ids;\n }\n\n return $reportData;\n }\n\n private function validateReportStatus($status): bool\n {\n if (! in_array($status, [true, false], true)) {\n throw new InvalidArgumentException('Report status is invalid');\n }\n\n return $status;\n }\n\n private function validateReportType($type): string\n {\n if (! in_array($type, self::getTypes(), true)) {\n throw new InvalidArgumentException(sprintf('Report type is invalid: %s', $type));\n }\n\n return $type;\n }\n\n private function validateFrequency($frequency): string\n {\n if (! in_array($frequency, self::getFrequencies(), true)) {\n throw new InvalidArgumentException('Frequency is invalid');\n }\n\n return $frequency;\n }\n\n private function validateAdditionalPromptInput(?string $additionalPromptInput): ?string\n {\n if ($additionalPromptInput && strlen($additionalPromptInput) > 5000) {\n throw new InvalidArgumentException('Additional Prompt Input should be less than 5000 characters');\n }\n\n return $additionalPromptInput;\n }\n\n private function validateCustomReportName(?string $customReportName): ?string\n {\n if ($customReportName === null || $customReportName === '') {\n return null;\n }\n\n if (strlen($customReportName) > 70) {\n throw new InvalidArgumentException('Custom report name should be less than 70 characters');\n }\n\n return $customReportName;\n }\n\n private function validateOrganization(?string $organizationUuid): Team\n {\n if (! $organizationUuid) {\n throw new InvalidArgumentException('Organization is required');\n }\n\n $team = $this->teamRepository->idOrUuid($organizationUuid);\n\n if (! $team) {\n throw new InvalidArgumentException('Organization not found');\n }\n\n if (! $team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {\n throw new InvalidArgumentException('Organization does not have the Automated Reports feature');\n }\n\n return $team;\n }\n\n private function validateAndGetGroupIds(Team $team, array $teamUuids): array\n {\n $groupIds = [];\n\n foreach ($teamUuids as $uuid) {\n $group = $this->groupRepository->findByUuid($uuid);\n\n if ($group === null || $group->getTeamId() !== $team->getId()) {\n throw new InvalidArgumentException(\n sprintf('Group %s not found for team %s', $uuid, $team->getUuid())\n );\n }\n\n $groupIds[] = $group->getId();\n\n }\n\n return $groupIds;\n }\n\n private function validateAndGetDealStageIds(Team $team, array $stageUuids, string $propertyLabel): array\n {\n $stageIds = [];\n\n foreach ($stageUuids as $uuid) {\n $stage = $this->stageRepository->findByUuid($uuid);\n\n if ($stage === null || $stage->getTeamId() !== $team->getId()) {\n throw new InvalidArgumentException(\n sprintf('Stage %s not found for team %s for %s', $uuid, $team->getUuid(), $propertyLabel)\n );\n }\n\n $stageIds[] = $stage->getId();\n }\n\n return $stageIds;\n }\n\n private function validateAndGetUserIds(array $userUuids, callable $teamCheck): array\n {\n if (empty($userUuids)) {\n return [];\n }\n\n $userIds = [];\n\n foreach ($userUuids as $uuid) {\n $user = $this->userRepository->findByUuid($uuid);\n\n if (! $user || ! $user->isStatusActive()) {\n throw new InvalidArgumentException(\n sprintf('User %s not found or is not active', $uuid)\n );\n }\n\n if (! $teamCheck($user)) {\n throw new InvalidArgumentException(\n sprintf('User %s does not belong to the allowed team(s)', $uuid)\n );\n }\n\n $userIds[] = $user->getId();\n }\n\n return $userIds;\n }\n\n private function validateAndGetUserIdsByTeam(Team $team, array $userUuids): array\n {\n return $this->validateAndGetUserIds($userUuids, fn ($user) => $user->getTeamId() === $team->getId());\n }\n\n private function validateAndGetJiminnyUserIds(array $userUuids): array\n {\n $allowedTeamIds = config('kiosk.teamIds', []);\n\n return $this->validateAndGetUserIds($userUuids, fn ($user) => in_array($user->getTeamId(), $allowedTeamIds, true));\n }\n\n private function parseDate(string $dateString): string\n {\n return date('Y-m-d H:i:s', strtotime($dateString));\n }\n\n private function generateReportResultViewUrl(AutomatedReportResult $result): string\n {\n $mediaResource = $this->getReportMediaRouteResource($result);\n\n return route('ai-reports.' . $mediaResource . '.view', ['uuid' => $result->getUuid()]);\n }\n\n private function generateReportResultDownloadUrl(AutomatedReportResult $result): string\n {\n $mediaResource = $this->getReportMediaRouteResource($result);\n\n return route('ai-reports.' . $mediaResource . '.download', ['uuid' => $result->getUuid()]);\n }\n\n private function getReportMediaRouteResource(AutomatedReportResult $result): string\n {\n if ($result->getMediaType() === self::MEDIA_TYPE_PDF) {\n return self::PDF_KEY;\n } elseif ($result->getMediaType() === self::MEDIA_TYPE_PODCAST) {\n return self::AUDIO_KEY;\n }\n\n throw new \\InvalidArgumentException('Unknown media type.');\n }\n\n public function getMediaPath(AutomatedReportResult $result): ?string\n {\n $url = match ($result->getMediaType()) {\n self::MEDIA_TYPE_PDF => $result->getPdfUrl(),\n self::MEDIA_TYPE_PODCAST => $result->getPodcastAudioUrl(),\n default => null,\n };\n\n if ($url === null) {\n return null;\n }\n\n $path = parse_url(trim($url, '\"\\''), PHP_URL_PATH);\n\n return $path ?: null;\n }\n\n public function getFilenameSuffix(AutomatedReportResult $result): ?string\n {\n return match ($result->getMediaType()) {\n self::MEDIA_TYPE_PODCAST => 'Podcast',\n default => null,\n };\n }\n\n public function getMailSubjectSuffix(AutomatedReportResult $result): string\n {\n return match ($result->getMediaType()) {\n self::MEDIA_TYPE_PDF => 'report',\n self::MEDIA_TYPE_PODCAST => 'podcast',\n default => '',\n };\n }\n\n public function getMediaTypeMetadata(AutomatedReportResult $result): array\n {\n return match ($result->getMediaType()) {\n self::MEDIA_TYPE_PODCAST => ['extension' => 'mp3', 'mime' => 'audio/mpeg'],\n self::MEDIA_TYPE_PDF => ['extension' => 'pdf', 'mime' => 'application/pdf'],\n default => ['extension' => null, 'mime' => null],\n };\n }\n\n public function deleteS3Files(AutomatedReportResult $result): void\n {\n $teamUuid = $result->getReport()->getTeam()->getUuid();\n $reportUuid = $result->getUuid();\n\n // delete all files for a report uuid no mather of pdf, podcast, or both\n // in case of both - the podcast files are linked to the pdf (parent) uuid\n // pdf and podcast date times should be close\n $path = sprintf('%s/%s/%s', $teamUuid, self::S3_DIR, $reportUuid);\n\n foreach (self::FILE_EXTENSIONS_VARIANTS as $extension) {\n $file = $path . '.' . $extension;\n\n if (Storage::exists($file)) {\n Storage::delete($file);\n Log::info('[Reports] Deleted S3 file', [\n 'path' => $file,\n ]);\n }\n }\n\n foreach (self::FILE_PODCAST_EXTENSIONS_VARIANTS as $extension) {\n $file = $path . '_podcast.' . $extension;\n\n if (Storage::exists($file)) {\n Storage::delete($file);\n Log::info('[Reports] Deleted Podcast S3 file', [\n 'path' => $file,\n ]);\n }\n }\n }\n\n /**\n *\n * @param int|null $teamId Optional team ID to filter results\n *\n * @return Collection<int, int> Collection of team IDs\n */\n public function getTeamIdsWithReportsResults(?int $teamId = null): Collection\n {\n return $this->automatedReportsRepository->getTeamIdsWithReportsResults($teamId);\n }\n\n /**\n * Core delete logic for report results using a query\n *\n * @param Builder $query\n * @param array $logContext\n *\n * @return int\n */\n private function deleteReportResultsByQuery(Builder $query, array $logContext = []): int\n {\n $deletedCount = 0;\n\n if ($query->exists()) {\n Log::info(\n 'Run delete report results',\n array_merge(\n $logContext,\n [\n 'service' => 'AutomatedReportsService',\n ]\n )\n );\n\n $query->chunkById(50, function ($results) use (&$deletedCount, $logContext) {\n foreach ($results as $result) {\n $this->deleteReportResult($result);\n $deletedCount++;\n\n Log::info(\n 'Deleted a report result',\n array_merge(\n $logContext,\n [\n 'result_id' => $result->getId(),\n 'report_id' => $result->getReportId(),\n ]\n )\n );\n }\n });\n }\n\n return $deletedCount;\n }\n\n /**\n * Delete report results for a team by retention period\n *\n * @param Team $team\n * @param CarbonImmutable $retentionDate\n *\n * @return int Number of deleted report results\n */\n public function deleteReportsResultsInRetentionPeriod(Team $team, CarbonImmutable $retentionDate): int\n {\n $reportIds = $this->automatedReportsRepository->getReportIdsByTeam($team);\n\n if ($reportIds->isEmpty()) {\n return 0;\n }\n\n $query = $this->automatedReportsRepository\n ->getReportResultsQueryForRetention($team, $retentionDate);\n\n return $this->deleteReportResultsByQuery($query, [\n 'team_id' => $team->getId(),\n 'retention_date' => $retentionDate->toDateTimeString(),\n ]);\n }\n\n /**\n * Delete ALL report results for a specific automated report\n *\n * @param string $uuid\n *\n * @return int\n */\n public function deleteReportResults(string $uuid): int\n {\n $report = $this->getReport($uuid);\n\n $query = $this->automatedReportsRepository->getResultsByReportQuery($report);\n\n return $this->deleteReportResultsByQuery($query, [\n 'report_uuid' => $uuid,\n 'report_id' => $report->getId(),\n ]);\n }\n\n public function deleteReportResult(AutomatedReportResult $result): void\n {\n $this->deleteS3Files($result);\n\n $result->delete();\n }\n\n /**\n * Get all reports for a specific team\n *\n * @param Team $team\n *\n * @return \\Illuminate\\Database\\Eloquent\\Collection\n */\n public function getTeamReports(Team $team): \\Illuminate\\Database\\Eloquent\\Collection\n {\n return $this->automatedReportsRepository->getReportsByTeam($team);\n }\n\n /**\n * Get all report results for a specific report\n *\n * @param AutomatedReport $report\n *\n * @return \\Illuminate\\Database\\Eloquent\\Collection\n */\n public function getReportResults(AutomatedReport $report): \\Illuminate\\Database\\Eloquent\\Collection\n {\n return $this->automatedReportsRepository->getResultsByReport($report);\n }\n\n public function deleteAllReportResults(AutomatedReport $report): void\n {\n $results = $this->getReportResults($report);\n\n /** @var AutomatedReportResult $result */\n foreach ($results as $result) {\n Log::info('Deleting result', [\n 'report' => $report->getId(),\n 'result' => $result->getId(),\n ]);\n\n $this->deleteReportResult($result);\n }\n }\n\n public function deleteAllData(Team $team): void\n {\n Log::info('Deleting automated report and results for team', [\n 'team' => $team->getId(),\n ]);\n\n $reports = $this->getTeamReports($team);\n\n /** @var AutomatedReport $report */\n foreach ($reports as $report) {\n Log::info('Deleting report', [\n 'team' => $team->getId(),\n 'report' => $report->getId(),\n ]);\n\n $this->deleteAllReportResults($report);\n\n $report->delete();\n }\n }\n}","depth":4,"value":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Services\\Kiosk\\AutomatedReports;\n\nuse Carbon\\CarbonImmutable;\nuse Carbon\\CarbonInterface;\nuse Carbon\\Exceptions\\InvalidFormatException;\nuse DateTime;\nuse DateTimeInterface;\nuse DateTimeZone;\nuse Illuminate\\Contracts\\Bus\\Dispatcher as BusDispatcher;\nuse Illuminate\\Database\\Eloquent\\Builder;\nuse Illuminate\\Support\\Carbon;\nuse Illuminate\\Support\\Collection;\nuse Illuminate\\Support\\Facades\\Log;\nuse Illuminate\\Support\\Facades\\Storage;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinition\\InputTypeEnum;\nuse Jiminny\\Component\\AskAnything\\AskAnythingPromptService;\nuse Jiminny\\Component\\AskAnything\\Dtos\\AskAnythingPromptDto;\nuse Jiminny\\Component\\UrlGenerator\\Webhook;\nuse Jiminny\\Contracts\\Repositories\\PlaybookCategoryRepository;\nuse Jiminny\\Contracts\\Repositories\\TeamRepository;\nuse Jiminny\\Contracts\\Repositories\\UserRepository;\nuse Jiminny\\Exceptions\\ApplicationException;\nuse Jiminny\\Exceptions\\InvalidArgumentException;\nuse Jiminny\\Exceptions\\ModelNotFoundException;\nuse Jiminny\\Jobs\\AutomatedReports\\RequestGenerateReportJob;\nuse Jiminny\\Models\\Activity\\Search;\nuse Jiminny\\Models\\AskAnything\\AskAnythingPrompt;\nuse Jiminny\\Models\\AskAnything\\AskAnythingPromptTarget;\nuse Jiminny\\Models\\AutomatedReport;\nuse Jiminny\\Models\\AutomatedReportResult;\nuse Jiminny\\Models\\Contracts\\UserContract;\nuse Jiminny\\Models\\Feature\\FeatureEnum;\nuse Jiminny\\Models\\Team;\nuse Jiminny\\Models\\User;\nuse Jiminny\\Repositories\\AskAnythingRepository;\nuse Jiminny\\Repositories\\AutomatedReportsRepository;\nuse Jiminny\\Repositories\\GroupRepository;\nuse Jiminny\\Repositories\\SearchRepository;\nuse Jiminny\\Repositories\\StageRepository;\nuse Throwable;\n\nclass AutomatedReportsService\n{\n public const string TYPE_LOSS_ANALYSIS = 'loss_analysis';\n public const string TYPE_ASK_JIMINNY = 'ask_jiminny';\n\n /**\n * Standard report types (used by kiosk for existing automated reports).\n */\n // @TODO this will add filter, however if we need to control feature by FF we need conditional logic\n public const array TYPES = [\n ['id' => 'exec_summary', 'name' => 'Exec Summary'],\n ['id' => 'coaching_profiles', 'name' => 'Coaching Profiles'],\n ['id' => 'product_feedback', 'name' => 'Product Feedback'],\n ['id' => self::TYPE_LOSS_ANALYSIS, 'name' => 'Loss Analysis'],\n// ['id' => 'questions', 'name' => 'Questions'],\n// ['id' => 'statistical_quant', 'name' => 'Statistical Quantitative'],\n ];\n\n public const array ALL_TYPES = [\n ...self::TYPES,\n ['id' => self::TYPE_ASK_JIMINNY, 'name' => 'Ask Jiminny'],\n ];\n\n public const string FREQUENCY_DAILY = 'daily';\n public const string FREQUENCY_WEEKLY = 'weekly';\n public const string FREQUENCY_MONTHLY = 'monthly';\n public const string FREQUENCY_QUARTERLY = 'quarterly';\n public const string FREQUENCY_ONE_OFF = 'one_off';\n\n /**\n * Frequencies for standard (non-Ask Jiminny) reports.\n */\n public const array FREQUENCIES = [\n ['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],\n ['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],\n ['id' => self::FREQUENCY_QUARTERLY, 'name' => 'Quarterly'],\n ['id' => self::FREQUENCY_ONE_OFF, 'name' => 'One-off'],\n ];\n\n /**\n * Frequencies for Ask Jiminny reports.\n */\n public const array ASK_JIMINNY_FREQUENCIES = [\n ['id' => self::FREQUENCY_DAILY, 'name' => 'Daily'],\n ['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],\n ['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],\n ];\n\n public const string MEDIA_TYPE_PDF = 'pdf';\n public const string MEDIA_TYPE_PODCAST = 'podcast';\n public const array MEDIA_TYPES = [self::MEDIA_TYPE_PDF, self::MEDIA_TYPE_PODCAST];\n public const array MEDIA_TYPE_OBJECT_PDF = ['id' => self::MEDIA_TYPE_PDF, 'name' => 'PDF'];\n public const array MEDIA_TYPE_OBJECT_PODCAST = ['id' => self::MEDIA_TYPE_PODCAST, 'name' => 'Podcast'];\n public const array MEDIA_TYPE_OBJECTS = [self::MEDIA_TYPE_OBJECT_PDF, self::MEDIA_TYPE_OBJECT_PODCAST];\n\n public const array CALL_TYPE_CONFERENCE = ['id' => 'conference', 'name' => 'Conference'];\n public const array CALL_TYPE_DIALER = ['id' => 'dialer', 'name' => 'Dialer'];\n public const int SENT_REPORT_AT_HOURS = 5;\n public const string PDF_KEY = 'pdf';\n public const string AUDIO_KEY = 'audio';\n\n private const array ALL_FREQUENCIES = [\n ['id' => self::FREQUENCY_DAILY, 'name' => 'Daily'],\n ['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],\n ['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],\n ['id' => self::FREQUENCY_QUARTERLY, 'name' => 'Quarterly'],\n ['id' => self::FREQUENCY_ONE_OFF, 'name' => 'One-off'],\n ];\n private const string S3_DIR = 'reports';\n private const array FILE_EXTENSIONS_VARIANTS = ['html', 'MD', 'pdf'];\n private const array FILE_PODCAST_EXTENSIONS_VARIANTS = ['json', 'mp3', 'ssml'];\n\n public function __construct(\n private readonly TeamRepository $teamRepository,\n private readonly GroupRepository $groupRepository,\n private readonly UserRepository $userRepository,\n private readonly StageRepository $stageRepository,\n private readonly DealStagesService $dealStagesService,\n private readonly RecipientsService $recipientsService,\n private readonly AutomatedReportsRepository $automatedReportsRepository,\n private readonly Webhook $webhookService,\n private readonly BusDispatcher $dispatcher,\n private readonly ActivityTypeService $activityTypeService,\n private readonly PlaybookCategoryRepository $playbookCategoryRepository,\n private readonly AskAnythingPromptService $askAnythingPromptService,\n private readonly SearchRepository $activitySearchRepository,\n private readonly AskAnythingRepository $askAnythingRepository,\n ) {\n }\n\n public static function getTypes(): array\n {\n $types = self::TYPES;\n\n return array_map(static function ($type) {\n return $type['id'];\n }, $types);\n }\n\n public static function getCallTypes(): array\n {\n return array_map(static function ($callType) {\n return $callType['id'];\n }, [self::CALL_TYPE_CONFERENCE, self::CALL_TYPE_DIALER]);\n }\n\n public static function getFrequencies(): array\n {\n return array_map(static function ($frequency) {\n return $frequency['id'];\n }, self::FREQUENCIES);\n }\n\n // front-facing structure\n public function getReportEnabledFieldData(bool $value = false): array\n {\n return [\n 'id' => 'report_enabled',\n 'label' => '',\n 'inputType' => InputTypeEnum::TOGGLE,\n 'value' => $value,\n ];\n }\n\n // Organizations = Teams\n public function getOrganizationFieldData(?string $value = null, bool $shortVersion = false): array\n {\n $options = $this->getTeams();\n\n if ($shortVersion) {\n return [\n 'id' => 'organization',\n 'label' => 'Organization',\n 'options' => $options,\n ];\n }\n\n return [\n 'id' => 'organization',\n 'label' => 'Organization',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => $options,\n 'value' => $value,\n 'dependencies' => [\n 'teams',\n 'deal_stage_at_call',\n 'current_deal_stage',\n 'recipients',\n ActivityTypeService::PLAYBOOK_CATEGORIES_KEY,\n ],\n 'dependsOn' => [],\n ];\n }\n\n // Teams = Groups\n public function getTeamFieldData(array $options = [], array $value = [], bool $shortVersion = false): array\n {\n if ($shortVersion) {\n return [\n 'id' => 'teams',\n 'label' => 'Team',\n 'options' => $options,\n ];\n }\n\n return [\n 'id' => 'teams',\n 'label' => 'Team',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'required' => false,\n 'placeholder' => 'Select',\n 'options' => $options,\n 'value' => $value, // value should be an array of objects {id, name}\n 'dependencies' => [ActivityTypeService::PLAYBOOK_CATEGORIES_KEY],\n 'dependsOn' => [],\n ];\n }\n\n public function getReportTypeFieldData(?string $value = null, bool $shortVersion = false, ?Team $team = null): array\n {\n $types = [];\n if ($team instanceof Team) {\n if ($team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {\n $types = self::TYPES;\n }\n if ($team->hasFeature(FeatureEnum::ASK_JIMINNY_REPORTS)) {\n $types[] = ['id' => self::TYPE_ASK_JIMINNY, 'name' => 'Ask Jiminny'];\n }\n } else {\n $types = self::TYPES;\n }\n\n if ($shortVersion) {\n return [\n 'id' => 'report_type',\n 'label' => 'Report Type',\n 'options' => $types,\n ];\n }\n\n return [\n 'id' => 'report_type',\n 'label' => 'Report Type',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => $types,\n 'value' => $value,\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getFrequencyFieldData(?string $value = null): array\n {\n return [\n 'id' => 'frequency',\n 'label' => 'Frequency',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => self::FREQUENCIES,\n 'value' => $value,\n 'dependencies' => ['period'],\n 'dependsOn' => [],\n ];\n }\n\n public function getPeriodFieldData(?string $valueStartDate = null, ?string $valueEndDate = null): array\n {\n return [\n 'id' => 'period',\n 'label' => 'Select one-off period',\n 'inputType' => InputTypeEnum::DATE_RANGE,\n 'required' => true,\n 'placeholder' => 'Select',\n 'value' => ['startDate' => $valueStartDate, 'endDate' => $valueEndDate],\n 'queryParams' => [\n 'startDate' => 'start_date_period',\n 'endDate' => 'end_date_period',\n ],\n 'dependencies' => [],\n 'dependsOn' => ['frequency'],\n ];\n }\n\n public function getActivityTypesFieldData(?Team $team = null, array $value = [], array $teamsFilter = []): array\n {\n return $this->activityTypeService->getActivityTypeFieldData(team: $team, value: $value, groupIds: $teamsFilter);\n }\n\n public function getDealStageAtCallFieldData(?Team $team = null, array $value = []): array\n {\n return $this->dealStagesService->getDealStageAtCallFieldData(team: $team, value: $value);\n }\n\n public function getCurrentDealStageFieldData(?Team $team = null, array $value = []): array\n {\n return $this->dealStagesService->getCurrentDealStageFieldData(team: $team, value: $value);\n }\n\n public function getDealValueFieldData(?int $valueMin = null, ?int $valueMax = null): array\n {\n return [\n 'id' => 'deal_value',\n 'label' => 'Deal Value',\n 'inputType' => InputTypeEnum::INTEGER_RANGE,\n 'required' => false,\n 'value' => ['min' => $valueMin, 'max' => $valueMax],\n 'queryParams' => [\n 'min' => 'min_deal_value',\n 'max' => 'max_deal_value',\n ],\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getCallTypeFieldData(bool $conferenceOn = false, bool $dialerOn = false): array\n {\n $value = [];\n $conferenceOn && $value[] = self::CALL_TYPE_CONFERENCE;\n $dialerOn && $value[] = self::CALL_TYPE_DIALER;\n\n return [\n 'id' => 'call_type',\n 'label' => 'Call Type',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'required' => true,\n 'options' => [\n self::CALL_TYPE_CONFERENCE,\n self::CALL_TYPE_DIALER,\n ],\n 'value' => $value,\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getMediaTypeFieldData(?AutomatedReport $report = null): array\n {\n $value = [];\n\n if ($report) {\n $value = $this->transformMediaTypes($report);\n }\n\n return [\n 'id' => 'media_types',\n 'label' => 'Export as',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'required' => true,\n 'options' => self::MEDIA_TYPE_OBJECTS,\n 'value' => $value,\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getCallDurationFieldData(?int $valueMin = null, ?int $valueMax = null): array\n {\n return [\n 'id' => 'call_duration',\n 'label' => 'Call Duration',\n 'inputType' => InputTypeEnum::INTEGER_RANGE,\n 'required' => false,\n 'value' => ['min' => $valueMin, 'max' => $valueMax],\n 'queryParams' => [\n 'min' => 'min_call_duration',\n 'max' => 'max_call_duration',\n ],\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getRecipientsFieldData(?Team $team = null, array $value = []): array\n {\n return $this->recipientsService->getRecipientsFieldData(team: $team, value: $value);\n }\n\n public function getJiminnyRecipientsFieldData(array $value = []): array\n {\n return $this->recipientsService->getJiminnyRecipientsFieldData($value);\n }\n\n public function getAdditionalPromptInputFieldData(?string $value = null): array\n {\n return [\n 'id' => 'additional_prompt_input',\n 'label' => 'Special requirements',\n 'inputType' => InputTypeEnum::TEXTAREA,\n 'required' => false,\n 'placeholder' => 'What should be the focus of the report?',\n 'value' => $value,\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getCustomReportNameFieldData(?string $value = null): array\n {\n return [\n 'id' => 'custom_name',\n 'label' => 'Custom report name',\n 'inputType' => InputTypeEnum::TEXT,\n 'required' => false,\n 'placeholder' => 'Enter custom name',\n 'value' => $value,\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n // data providers\n public function getTeams(): array\n {\n $teams = $this->teamRepository->getTeamsForKiosk(status: Team::STATUS_ACTIVE);\n\n $teamData = [];\n foreach ($teams as $team) {\n if (! $team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {\n continue;\n }\n\n $teamData[] = $this->transformTeam($team);\n }\n\n return $teamData;\n }\n\n public function getTeamGroups(string $teamUuid): array\n {\n $data = [];\n $team = $this->getTeam($teamUuid);\n\n if ($team !== null) {\n $groups = $team->groups()->get();\n\n foreach ($groups as $group) {\n $data[] = [\n 'id' => $group->getUuid(),\n 'name' => $group->getName(),\n ];\n }\n }\n\n return $data;\n }\n\n public function getTeamsGroupsOptions(array $filterTeamUuids = []): array\n {\n $data = [];\n $teams = $this->getTeams();\n\n foreach ($teams as $team) {\n if (! empty($filterTeamUuids) && ! in_array($team['id'], $filterTeamUuids, true)) {\n continue;\n }\n\n $data[] = [\n 'label' => $team['name'],\n 'groups' => $this->getTeamGroups($team['id']),\n ];\n }\n\n return $data;\n }\n\n public function getTeam(string $teamUuid): ?Team\n {\n return $this->teamRepository->idOrUuid($teamUuid);\n }\n\n public function getTeamById(int $teamId): ?Team\n {\n return $this->teamRepository->find($teamId);\n }\n\n public function getGroupsUuids(AutomatedReport $report): array\n {\n $uuids = [];\n $reportGroups = $report->getGroups();\n foreach ($reportGroups as $groupId) {\n if ($group = $this->groupRepository->find($groupId)) {\n $uuids[] = $group->getUuid();\n }\n }\n\n return $uuids;\n }\n\n public function getPlaybookCategoriesUuids(AutomatedReport $report): array\n {\n $uuids = [];\n $playbookCategories = $report->getPlaybookCategories();\n foreach ($playbookCategories as $id) {\n if ($category = $this->playbookCategoryRepository->find($id)) {\n $uuids[] = $category->getUuid();\n }\n }\n\n return $uuids;\n }\n\n public function getDealAtCallStagesUuids(AutomatedReport $report): array\n {\n $uuids = [];\n $reportStages = $report->getDealAtCallStages();\n foreach ($reportStages as $id) {\n if ($stage = $this->stageRepository->find($id)) {\n $uuids[] = $stage->getUuid();\n }\n }\n\n return $uuids;\n }\n\n public function getCurrentDealStagesUuids(AutomatedReport $report): array\n {\n $uuids = [];\n $reportStages = $report->getCurrentDealStages();\n foreach ($reportStages as $id) {\n if ($stage = $this->stageRepository->find($id)) {\n $uuids[] = $stage->getUuid();\n }\n }\n\n return $uuids;\n }\n\n public function getUsersUuids(AutomatedReport $report): array\n {\n return $this->extractUserUuids($report->getRecipients());\n }\n\n public function getJiminnyUsersUuids(AutomatedReport $report): array\n {\n return $this->extractUserUuids($report->getJiminnyRecipients());\n }\n\n /**\n * @param array<string, mixed> $recipients\n */\n private function extractUserUuids(array $recipients): array\n {\n $userIds = $recipients['users'] ?? [];\n\n return collect($userIds)\n ->map(fn ($id) => $this->userRepository->find((int) $id))\n ->filter()\n ->map(fn (UserContract $user) => $user->getUuid())\n ->values()\n ->all();\n }\n\n // get mail data\n public function getRecipientUsers(AutomatedReport $report): array\n {\n return $this->buildRecipientUsers($report->getRecipients());\n }\n\n private function getJiminnyRecipientUsers(AutomatedReport $report): array\n {\n return $this->buildRecipientUsers($report->getJiminnyRecipients());\n }\n\n /**\n * @param array<string, mixed> $recipients\n */\n private function buildRecipientUsers(array $recipients): array\n {\n $userIds = $recipients['users'] ?? [];\n\n return collect($userIds)\n ->map(fn ($id) => $this->userRepository->find((int) $id))\n ->filter()\n ->map(fn (UserContract $user) => [\n 'email' => $user->getEmailAddress(),\n 'name' => $user->getName(),\n 'timezone' => $user->getTimezone()->getName(),\n ])\n ->values()\n ->all();\n }\n\n public function getValidRecipientUsers(AutomatedReport $report, bool $includeJiminny = false): array\n {\n if ($report->isAskJiminnyReport()) {\n $recipients = $this->resolveAskJiminnyRecipients($report);\n } else {\n $recipients = $this->getRecipientUsers($report);\n if ($includeJiminny) {\n $recipients = array_merge($recipients, $this->getJiminnyRecipientUsers($report));\n }\n }\n\n $emails = [];\n\n return array_values(array_filter(\n $recipients,\n static function ($recipient) use (&$emails) {\n if (empty($recipient['email']) || in_array($recipient['email'], $emails, true)) {\n return false;\n }\n $emails[] = $recipient['email'];\n\n return true;\n }\n ));\n }\n\n private function resolveAskJiminnyRecipients(AutomatedReport $report): array\n {\n $recipients = [];\n\n $creator = $report->getCreator();\n if ($creator !== null) {\n $recipients[] = [\n 'email' => $creator->getEmailAddress(),\n 'name' => $creator->getName(),\n 'timezone' => $creator->getTimezone()->getName(),\n ];\n }\n\n return array_merge(\n $recipients,\n $this->buildRecipientUsers($report->getRecipients()),\n $this->getGroupRecipientUsers($report),\n );\n }\n\n private function getGroupRecipientUsers(AutomatedReport $report): array\n {\n $users = [];\n foreach ($report->getGroups() as $groupId) {\n $group = $this->groupRepository->find($groupId);\n if ($group === null) {\n continue;\n }\n foreach ($group->getMembers() as $member) {\n $users[] = [\n 'email' => $member->getEmailAddress(),\n 'name' => $member->getName(),\n 'timezone' => $member->getTimezone()->getName(),\n ];\n }\n }\n\n return $users;\n }\n\n public function getReportTypeName(AutomatedReportResult $report): string\n {\n $type = $report->getReport()->getType();\n\n $getType = $this->transformReportType($type);\n\n return $getType['name'];\n }\n\n public function getReportPeriodName(AutomatedReportResult $report): string\n {\n $from = $report->getFromDate();\n $to = $report->getToDate();\n $frequency = $report->getReport()->getFrequency();\n\n if ($from === null || $to === null) {\n if (! $report->getReport()->isAskJiminnyReport()) {\n $invalidPeriod = $from === null ? 'from' : 'to';\n\n throw new ApplicationException('Report period is invalid: ' . $invalidPeriod);\n }\n\n $period = $this->calculateFromAndToDatePeriod($frequency);\n $from = $period['fromDate'];\n $to = $period['toDate'];\n }\n\n return $this->formatReportPeriodName($frequency, $from, $to);\n }\n\n private function formatReportPeriodName(string $frequency, Carbon $from, Carbon $to): string\n {\n $fromYear = $from->format('Y');\n $toYear = $to->format('Y');\n $differentYears = $fromYear !== $toYear;\n\n switch ($frequency) {\n case self::FREQUENCY_DAILY:\n return $from->format('j M Y');\n\n case self::FREQUENCY_QUARTERLY:\n // 'Jan-Mar 2025' or 'Nov 2024-Jan 2025' if years differ\n $startMonth = $from->format('M');\n $endMonth = $to->copy()->subMonth();\n $endMonthName = $endMonth->format('M');\n $endMonthYear = $endMonth->format('Y');\n\n if ($differentYears) {\n return \"{$startMonth} {$fromYear} - {$endMonthName} {$endMonthYear}\";\n }\n\n return \"{$startMonth} - {$endMonthName} {$toYear}\";\n\n case self::FREQUENCY_MONTHLY:\n // 'May 2025' - monthly reports are always within the same year\n return $from->format('M Y');\n\n case self::FREQUENCY_WEEKLY:\n // '4 - 8 Aug 2025', '27 Oct - 3 Nov 2025', or '28 Dec 2024 - 3 Jan 2025' if years differ\n $startDay = $from->format('j');\n $endDay = $to->format('j');\n $startMonth = $from->format('M');\n $endMonth = $to->format('M');\n\n if ($differentYears) {\n return \"{$startDay} {$startMonth} {$fromYear} - {$endDay} {$endMonth} {$toYear}\";\n }\n\n if ($startMonth !== $endMonth) {\n return \"{$startDay} {$startMonth} - {$endDay} {$endMonth} {$toYear}\";\n }\n\n return \"{$startDay} - {$endDay} {$endMonth} {$toYear}\";\n\n case self::FREQUENCY_ONE_OFF:\n // '2 May-31 May 2025' or '15 Dec 2024-15 Jan 2025' if years differ\n $startDay = $from->format('j');\n $startMonth = $from->format('M');\n $endDay = $to->format('j');\n $endMonth = $to->format('M');\n\n // If same month and year, use a format like '2-31 May 2025'\n if ($startMonth === $endMonth && ! $differentYears) {\n return \"{$startDay} - {$endDay} {$startMonth} {$toYear}\";\n }\n\n // If different years, include both years\n if ($differentYears) {\n return \"{$startDay} {$startMonth} {$fromYear} - {$endDay} {$endMonth} {$toYear}\";\n }\n\n // Same year but different months\n return \"{$startDay} {$startMonth} - {$endDay} {$endMonth} {$toYear}\";\n\n default:\n // Default format for unknown frequencies\n return $from->format('j M Y') . ' - ' . $to->format('j M Y');\n }\n }\n\n public function getReportTeamsName(AutomatedReportResult $report): string\n {\n $groups = $report->getGroups();\n\n if (empty($groups)) {\n return 'All';\n }\n\n // Get group names from repository\n $groupNames = [];\n foreach ($groups as $groupId) {\n $group = $this->groupRepository->find($groupId);\n if ($group) {\n $groupNames[] = $group->getName();\n }\n }\n\n if (count($groupNames) === 1) {\n // Single team format\n $teamsName = $groupNames[0];\n } else {\n // Multiple teams format\n $teamsName = implode(', ', $groupNames);\n }\n\n return $teamsName;\n }\n\n public function getReportFileName(AutomatedReportResult $report): string\n {\n $customName = $report->getReport()->getCustomName();\n $periodName = $this->getReportPeriodName($report);\n $filenameSuffix = $this->getFilenameSuffix($report);\n\n if ($customName) {\n if ($filenameSuffix) {\n $customName .= \" {$filenameSuffix}\";\n }\n\n return $this->sanitizeFileName(\"{$customName} - {$periodName}\");\n }\n\n $baseName = $this->getReportTypeName($report);\n\n if ($filenameSuffix) {\n $baseName .= \" {$filenameSuffix}\";\n }\n\n return $this->sanitizeFileName(\"{$baseName} - {$periodName} - {$this->getReportTeamsName($report)}\");\n }\n\n public function getReportFileNameWithExtension(AutomatedReportResult $result): string\n {\n $extension = $this->getMediaTypeMetadata($result)['extension'];\n\n return $this->getReportFileName($result) . '.' . $extension;\n }\n\n public function sanitizeFileName(string $fileName): string\n {\n return str_replace(['/', '\\\\'], '-', $fileName);\n }\n\n public function isUserRecipientOfReport(User $user, AutomatedReport $report): bool\n {\n $recipients = array_map('intval', $report->getRecipients()['users'] ?? []);\n\n return in_array($user->getId(), $recipients);\n }\n\n public function transformReportResults(Collection $automatedReportResults): array\n {\n $data = [];\n foreach ($automatedReportResults as $automatedReportResult) {\n /** @var AutomatedReportResult $automatedReportResult */\n\n $report = $automatedReportResult->getReport();\n\n $createdBy = $report->getCreator();\n $creator = [\n 'id' => $createdBy?->getUuid(),\n 'name' => $createdBy?->getName(),\n 'email' => $createdBy?->getEmailAddress(),\n 'photoUrl' => $createdBy?->getPhotoUrl(),\n ];\n\n $data[] = [\n 'id' => $automatedReportResult->getUuid(),\n 'name' => $automatedReportResult->getName(),\n 'frequency' => $this->transformFrequency($report->getFrequency()),\n 'recipients' => [\n ...array_values($this->transformGroups(team: $report->getTeam(), groupsIds: $report->getGroups())),\n ...array_values($this->transformRecipients($report->getRecipients())),\n ],\n 'report_type' => $this->transformReportType($report->getType()),\n 'media_type' => $automatedReportResult->getMediaType(),\n 'downloadUrl' => $this->generateReportResultDownloadUrl($automatedReportResult),\n 'viewUrl' => $this->generateReportResultViewUrl($automatedReportResult),\n 'generated_at' => $automatedReportResult->getGeneratedAt()?->toIso8601String(),\n 'creator' => $creator,\n ];\n }\n\n return $data;\n }\n\n public function hasCallTypeConference(AutomatedReport $report): bool\n {\n return in_array(self::CALL_TYPE_CONFERENCE['id'], $report->getCallTypes(), true);\n }\n\n public function hasCallTypeDialer(AutomatedReport $report): bool\n {\n return in_array(self::CALL_TYPE_DIALER['id'], $report->getCallTypes(), true);\n }\n\n // transformers\n private function transformTeam(Team $team): array\n {\n if (! $team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {\n return [];\n }\n\n return [\n 'id' => $team->getUuid(),\n 'name' => $team->getName(),\n ];\n }\n\n private function transformReportFullView(AutomatedReport $report): array\n {\n $base = $this->transformReportBase($report);\n\n return $report->getType() === self::TYPE_ASK_JIMINNY\n ? $base + $this->transformAskJiminnyFields($report)\n : $base + $this->transformStandardReportFields($report);\n }\n\n private function transformReportBase(AutomatedReport $report): array\n {\n return [\n 'id' => $report->getUuid(),\n 'organization' => $this->transformOrganization(team: $report->getTeam()),\n 'report_type' => $this->transformReportType($report->getType()),\n 'frequency' => $this->transformFrequency($report->getFrequency()),\n ];\n }\n\n private function transformStandardReportFields(AutomatedReport $report): array\n {\n $team = $report->getTeam();\n\n return [\n 'report_enabled' => $report->getStatus(),\n 'start_date_period' => $report->getFrom()?->format('Y-m-d H:i:s'),\n 'end_date_period' => $report->getTo()?->format('Y-m-d H:i:s'),\n 'deal_value_min' => $report->getDealValueMin(),\n 'deal_value_max' => $report->getDealValueMax(),\n 'call_types' => $this->transformCallType($report->getCallTypes()),\n 'media_types' => $this->transformMediaTypes($report),\n 'call_duration_min' => $this->transformDurationToMinutes($report->getCallDurationMin()),\n 'call_duration_max' => $this->transformDurationToMinutes($report->getCallDurationMax()),\n 'teams' => $this->transformGroups(team: $team, groupsIds: $report->getGroups()),\n 'deal_at_call_stages' => $this->transformStages(team: $team, stagesIds: $report->getDealAtCallStages()),\n 'current_deal_stages' => $this->transformStages(team: $team, stagesIds: $report->getCurrentDealStages()),\n 'recipients' => $this->transformRecipients($report->getRecipients()),\n 'created_by' => $this->transformCreator($report->getCreator()),\n 'additional_prompt_input' => $report->getAdditionalPromptInput(),\n 'custom_name' => $report->getCustomName(),\n 'created_at' => $report->getCreatedAt()->format('Y-m-d H:i:s'),\n 'updated_at' => $report->getUpdatedAt()->format('Y-m-d H:i:s'),\n 'deleted_at' => $report->getDeletedAt()?->format('Y-m-d H:i:s'),\n ];\n }\n\n private function transformAskJiminnyFields(AutomatedReport $report): array\n {\n $team = $report->getTeam();\n $creatorId = $report->getAttribute('created_by');\n $explicitUserIds = array_values(array_filter(\n $report->getRecipients()['users'] ?? [],\n static fn ($id) => $id !== $creatorId\n ));\n\n return [\n 'report_name' => $report->getCustomName(),\n 'enabled' => $report->getStatus(),\n 'share_teams' => $this->transformGroups(team: $team, groupsIds: $report->getGroups()),\n 'share_users' => $this->transformRecipients(['users' => $explicitUserIds]),\n 'saved_search' => $this->transformSafeSearch($report->getSavedSearch()),\n 'ask_jiminny_prompt' => $this->transformAskJiminnyPrompt($report->getAskAnythingPrompt()),\n 'expires_on' => $report->getExpiresAt()?->format('Y-m-d'),\n ];\n }\n\n private function transformOrganization(?Team $team): array\n {\n return [\n 'id' => $team?->getUuid(),\n 'name' => $team?->getName(),\n ];\n }\n\n private function transformReportType(string $type): array\n {\n foreach (self::ALL_TYPES as $typeItem) {\n if ($typeItem['id'] === $type) {\n return $typeItem;\n }\n }\n\n return [];\n }\n\n private function transformCallType(array $types): array\n {\n $result = [];\n $callTypes = [self::CALL_TYPE_CONFERENCE, self::CALL_TYPE_DIALER];\n\n foreach ($types as $type) {\n foreach ($callTypes as $callTypeItem) {\n if ($callTypeItem['id'] === $type) {\n $result[] = $callTypeItem;\n\n break;\n }\n }\n }\n\n return $result;\n }\n\n private function transformMediaTypes(AutomatedReport $report): array\n {\n $values = [];\n\n foreach ($report->getMediaTypes() as $mediaType) {\n if (! in_array($mediaType, self::MEDIA_TYPES, true)) {\n continue;\n }\n\n $values[] = match ($mediaType) {\n self::MEDIA_TYPE_PDF => self::MEDIA_TYPE_OBJECT_PDF,\n self::MEDIA_TYPE_PODCAST => self::MEDIA_TYPE_OBJECT_PODCAST,\n };\n }\n\n return $values;\n }\n\n private function transformFrequency(string $frequency): array\n {\n foreach (self::ALL_FREQUENCIES as $frequencyItem) {\n if ($frequencyItem['id'] === $frequency) {\n return $frequencyItem;\n }\n }\n\n return [];\n }\n\n public function transformDurationToMinutes(?int $duration): ?int\n {\n if (! $duration) {\n return null;\n }\n\n return (int) ($duration / 60);\n }\n\n private function transformGroups(?Team $team, array $groupsIds): array\n {\n if (empty($groupsIds) || ! $team) {\n return [];\n }\n\n $data = [];\n foreach ($groupsIds as $groupId) {\n $group = $team->groups()->where('id', $groupId)->first();\n\n if ($group) {\n $data[] = [\n 'id' => $group->getUuid(),\n 'name' => $group->getName(),\n 'photoUrl' => $group->getPhotoUrl(),\n ];\n }\n }\n\n return $data;\n }\n\n private function transformStages(?Team $team, array $stagesIds): array\n {\n if (empty($stagesIds) || ! $team) {\n return [];\n }\n\n $data = [];\n foreach ($stagesIds as $stageId) {\n $stage = $team->stages()->where('id', $stageId)->first();\n\n if ($stage) {\n $data[] = [\n 'id' => $stage->getUuid(),\n 'name' => $stage->getName(),\n ];\n }\n }\n\n return $data;\n }\n\n private function transformRecipients(array $recipients): array\n {\n $users = [];\n foreach ($recipients['users'] ?? [] as $userId) {\n $users[] = $this->transformUser($userId);\n }\n\n return $users;\n }\n\n private function transformCreator(?User $user): ?array\n {\n if ($user === null) {\n return null;\n }\n\n return $this->transformUser($user->getId());\n }\n\n private function transformAskJiminnyPrompt(?AskAnythingPrompt $prompt): ?array\n {\n if ($prompt === null) {\n return null;\n }\n\n return [\n 'id' => $prompt->getUuid(),\n 'name' => $prompt->getTitle(),\n ];\n }\n\n private function transformSafeSearch(?Search $search): ?array\n {\n if ($search === null) {\n return null;\n }\n\n return [\n 'id' => $search->getUuid(),\n 'name' => $search->getName(),\n ];\n }\n\n private function transformUser(int $userId): array\n {\n /* @var ?User $user */\n $user = $this->userRepository->find($userId);\n\n return [\n 'id' => $user?->getUuid(),\n 'name' => $user?->getName(),\n 'email' => $user?->getEmailAddress(),\n 'photoUrl' => $user?->getPhotoUrl(),\n ];\n }\n\n public function create(array $data): array\n {\n $validatedData = $this->validateAndTransformData($data);\n $validatedData['created_by'] = auth()->id();\n\n $automatedReport = $this->automatedReportsRepository->create($validatedData);\n\n $this->generateOneOffReport($automatedReport);\n\n return $this->transformReportFullView($automatedReport);\n }\n\n public function update(string $uuid, array $data): array\n {\n $validatedData = $this->validateAndTransformData($data);\n $report = $this->automatedReportsRepository->findByUuid($uuid);\n\n if (! $report) {\n throw new InvalidArgumentException('Report not found');\n }\n\n $oldCustomName = $report->getCustomName();\n\n $automatedReport = $this->automatedReportsRepository->update($report, $validatedData);\n\n if ($oldCustomName !== $automatedReport->getCustomName()) {\n $this->updateResultNames($automatedReport);\n }\n\n $this->generateOneOffReport($automatedReport);\n\n return $this->transformReportFullView($automatedReport);\n }\n\n /**\n * Create an Ask Jiminny report.\n */\n public function createAskJiminnyReport(array $data, User $creator): array\n {\n $validatedData = $this->validateAskJiminnyReportData($data, $creator);\n $validatedData['created_by'] = $creator->getId();\n\n $automatedReport = $this->automatedReportsRepository->create($validatedData);\n\n return $this->transformReportFullView($automatedReport);\n }\n\n /**\n * Update an Ask Jiminny report.\n */\n public function updateAskJiminnyReport(AutomatedReport $report, array $data, User $user): array\n {\n if (! $report->isAskJiminnyReport()) {\n throw new InvalidArgumentException('Report is not an Ask Jiminny report');\n }\n\n $validatedData = $this->validateAskJiminnyReportData($data, $user);\n\n $oldCustomName = $report->getCustomName();\n\n $automatedReport = $this->automatedReportsRepository->update($report, $validatedData);\n\n if ($oldCustomName !== $automatedReport->getCustomName()) {\n $this->updateResultNames($automatedReport);\n }\n\n return $this->transformReportFullView($automatedReport);\n }\n\n public function updateAskJiminnyReportStatus(AutomatedReport $report, bool $status): array\n {\n $this->automatedReportsRepository->update($report, ['status' => $status]);\n\n return $this->transformReportFullView($report->fresh());\n }\n\n /**\n * Validate and transform data for Ask Jiminny reports.\n */\n private function validateAskJiminnyReportData(array $data, User $user): array\n {\n // Validate name\n $name = trim($data['report_name'] ?? '');\n if (empty($name)) {\n throw new InvalidArgumentException('Report name is required');\n }\n if (mb_strlen($name) > 50) {\n throw new InvalidArgumentException('Report name must be 50 characters or less');\n }\n\n // Validate frequency (only daily, weekly, monthly for Ask Jiminny)\n $frequency = $data['frequency'] ?? null;\n $askJiminnyFrequencies = [self::FREQUENCY_DAILY, self::FREQUENCY_WEEKLY, self::FREQUENCY_MONTHLY];\n if (! in_array($frequency, $askJiminnyFrequencies, true)) {\n throw new InvalidArgumentException('Frequency must be daily, weekly, or monthly');\n }\n\n // Validate expiration date\n $expiresAt = $data['expires_on'] ?? null;\n if (empty($expiresAt)) {\n throw new InvalidArgumentException('Expiration date is required');\n }\n\n try {\n $expiresAtDate = Carbon::parse($expiresAt);\n } catch (InvalidFormatException $e) {\n throw new InvalidArgumentException('Expiration date format is invalid');\n }\n $maxExpiration = Carbon::now()->addYear();\n if ($expiresAtDate->gt($maxExpiration)) {\n throw new InvalidArgumentException('Expiration date cannot be more than 1 year from now');\n }\n if ($expiresAtDate->isPast()) {\n throw new InvalidArgumentException('Expiration date cannot be in the past');\n }\n\n // Validate saved search\n $activitySearchId = $data['saved_search'] ?? null;\n if (empty($activitySearchId)) {\n throw new InvalidArgumentException('Saved search is required');\n }\n $savedSearch = $this->activitySearchRepository->findByUuidAndUser($activitySearchId, $user);\n if (! $savedSearch) {\n throw new InvalidArgumentException('Saved search not found or does not belong to you');\n }\n\n // Validate saved prompt\n $askAnythingPromptId = $data['ask_jiminny_prompt'] ?? null;\n if (empty($askAnythingPromptId)) {\n throw new InvalidArgumentException('Ask Jiminny prompt is required');\n }\n $prompt = $this->askAnythingRepository->getPromptByUuid($askAnythingPromptId);\n if (! $prompt) {\n throw new InvalidArgumentException('Ask Jiminny prompt not found');\n }\n\n // Validate status\n $status = $data['enabled'] ?? false;\n\n $recipientUserIds = [$user->getId()];\n\n if (! empty($data['share_users'])) {\n $sharedUserIds = $this->validateAndGetUserIdsByTeam(\n $user->team,\n (array) $data['share_users']\n );\n $recipientUserIds = array_merge($recipientUserIds, $sharedUserIds);\n }\n\n $sharedGroupIds = [];\n if (! empty($data['share_teams'])) {\n $sharedGroupIds = $this->validateAndGetGroupIds($user->team, (array) $data['share_teams']);\n }\n\n $recipientUserIds = array_values(array_unique($recipientUserIds));\n\n return [\n 'team_id' => $user->getTeamId(),\n 'type' => self::TYPE_ASK_JIMINNY,\n 'status' => (bool) $status,\n 'frequency' => $frequency,\n 'custom_name' => $name,\n 'activity_search_id' => $savedSearch->getId(),\n 'ask_anything_prompt_id' => $prompt->getId(),\n 'expires_at' => $expiresAtDate->toDateString(),\n 'media_types' => [self::MEDIA_TYPE_PDF],\n 'call_types' => [],\n 'recipients' => ['users' => $recipientUserIds],\n 'groups' => $sharedGroupIds,\n ];\n }\n\n public static function getAskJiminnyFrequencies(): array\n {\n return array_map(static function ($frequency) {\n return $frequency['id'];\n }, self::ASK_JIMINNY_FREQUENCIES);\n }\n\n public function getAskJiminnyReportFilters(User $user): array\n {\n $savedSearches = $this->activitySearchRepository->findByUserOrderedByName($user)\n ->map(fn (Search $search) => [\n 'id' => $search->getUuid(),\n 'name' => $search->getName(),\n ])\n ->values()->all();\n\n $prompts = collect(\n $this->askAnythingPromptService->get($user, AskAnythingPromptTarget::on_demand)\n )->map(fn (AskAnythingPromptDto $prompt) => [\n 'id' => $prompt->id,\n 'name' => $prompt->title,\n ])->values()->all();\n\n return [\n [\n 'id' => 'prompt',\n 'label' => 'Prompt',\n 'options' => $prompts,\n ],\n [\n 'id' => 'saved_search',\n 'label' => 'Saved Search',\n 'options' => $savedSearches,\n ],\n ];\n }\n\n public function getAskJiminnyReportFormData(User $user, ?AutomatedReport $report = null): array\n {\n $team = $user->getTeam();\n $userTimezone = $user->getTimezone();\n\n $savedSearches = $this->activitySearchRepository->findByUserOrderedByName($user)\n ->map(fn (Search $search) => [\n 'id' => $search->getUuid(),\n 'name' => $search->getName(),\n ])\n ->values()->all();\n\n $prompts = collect(\n $this->askAnythingPromptService->get($user, AskAnythingPromptTarget::on_demand)\n )->map(fn (AskAnythingPromptDto $prompt) => [\n 'id' => $prompt->id,\n 'name' => $prompt->title,\n ])->values()->all();\n\n $teamGroups = $this->groupRepository->getAllByTeam($team)->map(fn ($group) => [\n 'id' => $group->getUuid(),\n 'name' => $group->getName(),\n ])->values()->all();\n\n $shareUsers = $this->recipientsService->getRecipientsFieldData(team: $team)['options'] ?? [];\n\n $sharedTeamsValue = [];\n $sharedUsersValue = [];\n if ($report) {\n $sharedTeamsValue = $this->transformGroups($team, $report->getGroups());\n\n $recipientUserIds = $report->getRecipients()['users'] ?? [];\n $creatorId = $report->getAttribute('created_by');\n $sharedUserIds = array_values(array_filter(\n $recipientUserIds,\n static fn ($id) => $id !== $creatorId\n ));\n $sharedUsersValue = collect($sharedUserIds)\n ->map(fn ($id) => $this->userRepository->find((int) $id))\n ->filter()\n ->map(fn (User $u) => [\n 'id' => $u->getUuid(),\n 'name' => $u->getName(),\n ])\n ->values()\n ->all();\n }\n\n return [\n 'fields' => [\n [\n 'id' => 'enabled',\n 'inputType' => InputTypeEnum::TOGGLE,\n 'label' => '',\n 'value' => $report?->getStatus() ?? false,\n ],\n [\n 'id' => 'report_name',\n 'inputType' => InputTypeEnum::TEXT,\n 'label' => 'Name',\n 'placeholder' => 'Enter name',\n 'required' => true,\n 'validation' => ['maxLength' => 50],\n 'value' => $report?->getCustomName() ?? '',\n ],\n [\n 'id' => 'frequency',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'label' => 'Frequency',\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => self::ASK_JIMINNY_FREQUENCIES,\n 'value' => $report ? $this->transformFrequency($report->getFrequency()) : null,\n ],\n [\n 'id' => 'expires_on',\n 'inputType' => InputTypeEnum::DATE,\n 'label' => 'Expires on',\n 'required' => true,\n 'placeholder' => 'Select',\n 'validation' => [\n 'minDate' => now($userTimezone)->toDateString(),\n 'maxDate' => now($userTimezone)->addYear()->toDateString(),\n ],\n 'value' => $report?->getExpiresAt()?->toDateString(),\n ],\n [\n 'id' => 'share_teams',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'label' => 'Team',\n 'required' => false,\n 'placeholder' => 'Select',\n 'options' => $teamGroups,\n 'value' => $sharedTeamsValue,\n ],\n [\n 'id' => 'share_users',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'label' => 'Team member',\n 'required' => false,\n 'placeholder' => 'Select',\n 'groupLabelKey' => 'label',\n 'groupValuesKey' => 'users',\n 'optionLabelKey' => 'name',\n 'optionValueKey' => 'id',\n 'options' => $shareUsers,\n 'value' => $sharedUsersValue,\n ],\n [\n 'id' => 'saved_search',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'label' => 'Saved search',\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => $savedSearches,\n 'value' => $report && $report->getSavedSearch() ? [\n 'id' => $report->getSavedSearch()->getUuid(),\n 'name' => $report->getSavedSearch()->getName(),\n ] : null,\n ],\n [\n 'id' => 'ask_jiminny_prompt',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'label' => 'Ask Jiminny prompt',\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => $prompts,\n 'value' => $report && $report->getAskAnythingPrompt() ? [\n 'id' => $report->getAskAnythingPrompt()->getUuid(),\n 'name' => $report->getAskAnythingPrompt()->getTitle(),\n ] : null,\n ],\n ],\n ];\n }\n\n private function updateResultNames(AutomatedReport $automatedReport): void\n {\n $results = $this->automatedReportsRepository->getResultsByReport($automatedReport);\n\n foreach ($results as $result) {\n $result->update(['name' => $this->getReportFileName($result)]);\n }\n }\n\n public function updateStatus(string $uuid, array $data): array\n {\n $automatedReport = $this->automatedReportsRepository->findByUuid($uuid);\n\n if (! $automatedReport) {\n throw new ModelNotFoundException('Report not found');\n }\n\n $status = $this->validateReportStatus($data['report_enabled'] ?? null);\n $automatedReport->update([\n 'status' => $status,\n ]);\n\n $this->generateOneOffReport($automatedReport);\n\n return $this->transformReportFullView($automatedReport);\n }\n\n private function generateOneOffReport(AutomatedReport $automatedReport): void\n {\n // the scheduler handles all the other frequency types\n if ($automatedReport->getStatus() === false || $automatedReport->getFrequency() !== self::FREQUENCY_ONE_OFF) {\n return;\n }\n\n $this->dispatcher->dispatch(new RequestGenerateReportJob($automatedReport->getUuid()));\n }\n\n public function getReport(string $uuid): AutomatedReport\n {\n $automatedReport = $this->automatedReportsRepository->findByUuid($uuid);\n\n if (! $automatedReport) {\n throw new ModelNotFoundException('Report not found');\n }\n\n return $automatedReport;\n }\n\n public function get(string $uuid): array\n {\n $automatedReport = $this->getReport($uuid);\n\n return $this->transformReportFullView($automatedReport);\n }\n\n public function list(string $sortColumn = 'created_at', string $sortDirection = 'desc'): array\n {\n $results = [];\n $collection = $this->automatedReportsRepository->getAllStandardReports($sortColumn, $sortDirection);\n\n /** @var AutomatedReport $report */\n foreach ($collection as $report) {\n $results[] = $this->transformReportFullView($report);\n }\n\n return ['data' => $results];\n }\n\n public function listAskJiminnyReports(\n User $user,\n string $sortColumn = 'created_at',\n string $sortDirection = 'desc'\n ): array {\n $results = [];\n $collection = $this->automatedReportsRepository->getAskJiminnyReportsByUser($user, $sortColumn, $sortDirection);\n\n /** @var AutomatedReport $report */\n foreach ($collection as $report) {\n $results[] = $this->transformReportFullView($report);\n }\n\n return ['data' => $results];\n }\n\n public function delete(string $uuid): void\n {\n $automatedReport = $this->automatedReportsRepository->findByUuid($uuid);\n\n if (! $automatedReport) {\n throw new ModelNotFoundException('Report not found');\n }\n\n $automatedReport->delete();\n }\n\n public function createReportResult(AutomatedReport $automatedReport, array $data = []): AutomatedReportResult\n {\n return $this->automatedReportsRepository->createResult(\n array_merge(\n [\n 'report_id' => $automatedReport->getId(),\n 'status' => AutomatedReportResult::STATUS_DEFAULT,\n ],\n $data\n )\n );\n }\n\n public function getReportResult(string $resultUuid): AutomatedReportResult\n {\n $report = $this->automatedReportsRepository->findResultByUuid($resultUuid);\n\n if (! $report) {\n throw new ModelNotFoundException('Report Result not found');\n }\n\n return $report;\n }\n\n public function findChildResult(AutomatedReportResult $result, string $type): ?AutomatedReportResult\n {\n return $this->automatedReportsRepository->findChildResult($result, $type);\n }\n\n // prophet API calls\n /**\n * @throws ApplicationException\n */\n public function getGenerateReportPayload(AutomatedReport $automatedReport, string $reportResultUuid): array\n {\n $period = $this->calculateFromAndToDate($automatedReport);\n $fromDate = $period['fromDate'];\n $toDate = $period['toDate'];\n\n return [\n 'team_id' => $automatedReport->getTeamId(),\n 'request_id' => $reportResultUuid,\n 'report_type' => $automatedReport->getType(),\n 'media_types' => $automatedReport->getMediaTypes(),\n 'from_date' => $fromDate->startOfDay()->format(DateTimeInterface::RFC3339),\n 'to_date' => $toDate->endOfDay()->format(DateTimeInterface::RFC3339),\n 'group_ids' => $automatedReport->getGroups(),\n 'call_deal_stage' => $automatedReport->getDealAtCallStages(),\n 'current_deal_stage' => $automatedReport->getCurrentDealStages(),\n 'deal_min_value' => $automatedReport->getDealValueMin(),\n 'deal_max_value' => $automatedReport->getDealValueMax(),\n 'call_types' => $automatedReport->getCallTypes(),\n 'call_duration_min_seconds' => $automatedReport->getCallDurationMin(),\n 'call_duration_max_seconds' => $automatedReport->getCallDurationMax(),\n 'special_requirements' => $automatedReport->getAdditionalPromptInput(),\n 'callback_url' => $this->getCallbackUrl(),\n 'report_period' => $this->formatReportPeriodName(\n $automatedReport->getFrequency(),\n $fromDate,\n $toDate,\n ),\n 'playbook_categories' => $automatedReport->getPlaybookCategories(),\n 'custom_name' => $automatedReport->getCustomName(),\n ];\n }\n\n // $inputPayload - FE payload structure\n public function getActivitiesCountPayload(array $inputPayload): array\n {\n // Use validateAndTransformData to validate and normalize input\n $validatedData = $this->validateAndTransformData($inputPayload);\n $period = $this->calculateFromAndToDatePeriod(\n $validatedData['frequency'],\n Carbon::parse($validatedData['from']),\n Carbon::parse($validatedData['to']),\n );\n $fromDate = $period['fromDate'];\n $toDate = $period['toDate'];\n\n // Create payload similar to getGenerateReportPayload\n return [\n 'team_id' => $validatedData['team_id'],\n 'group_ids' => $validatedData['groups'] ?? [],\n 'report_type' => $validatedData['type'],\n 'from_date' => $fromDate->format(DateTimeInterface::RFC3339),\n 'to_date' => $toDate->format(DateTimeInterface::RFC3339),\n 'call_deal_stage' => $validatedData['deal_at_call_stages'] ?? [],\n 'current_deal_stage' => $validatedData['current_deal_stages'] ?? [],\n 'deal_min_value' => $validatedData['deal_value_min'] ?? null,\n 'deal_max_value' => $validatedData['deal_value_max'] ?? null,\n 'call_types' => $validatedData['call_types'],\n 'call_duration_min_seconds' => $validatedData['call_duration_min'] ?? null,\n 'call_duration_max_seconds' => $validatedData['call_duration_max'] ?? null,\n 'special_requirements' => $validatedData['additional_prompt_input'] ?? null,\n 'playbook_categories' => $validatedData['playbook_categories'] ?? [],\n 'request_id' => null,\n 'callback_url' => null,\n ];\n }\n\n public function shouldSendReport(array $users, ?CarbonInterface $generatedAt = null): bool\n {\n if (empty($users)) {\n return false;\n }\n\n $earliestTz = collect($users)\n ->mapWithKeys(function (array $user) {\n $tz = new DateTimeZone($user['timezone']);\n $nowUtc = new DateTime('now', new DateTimeZone('UTC'));\n $offset = $tz->getOffset($nowUtc);\n\n return [$user['timezone'] => $offset];\n })\n ->sortDesc()\n ->keys()\n ->first();\n\n $now = Carbon::now($earliestTz);\n $isScheduledTime = (int) $now->format('H') === self::SENT_REPORT_AT_HOURS;\n\n if ($isScheduledTime) {\n return true;\n }\n\n return $this->hasPassedScheduledTime($generatedAt, $earliestTz);\n }\n\n public function hasPassedScheduledTime(?CarbonInterface $generatedAt, string $timezone): bool\n {\n if ($generatedAt === null) {\n return false;\n }\n\n $now = Carbon::now($timezone);\n $scheduledTime = $now->copy()->setTime(self::SENT_REPORT_AT_HOURS, 0, 0);\n\n if ($now->hour < self::SENT_REPORT_AT_HOURS) {\n $scheduledTime = $scheduledTime->subDay();\n }\n\n $scheduledTimeUtc = $scheduledTime->copy()->utc();\n $generatedAtUtc = $generatedAt->copy()->utc();\n $nowUtc = $now->copy()->utc();\n\n return $generatedAtUtc->lt($scheduledTimeUtc) && $nowUtc->gt($scheduledTimeUtc);\n }\n\n public function calculateFromAndToDatePeriod(\n string $frequency,\n ?Carbon $fromDate = null,\n ?Carbon $toDate = null\n ): array {\n if ($frequency === self::FREQUENCY_ONE_OFF) {\n return [\n 'fromDate' => $fromDate,\n 'toDate' => $toDate,\n ];\n }\n\n $now = Carbon::now();\n\n return match ($frequency) {\n self::FREQUENCY_DAILY => [\n 'fromDate' => $now->copy()->subDay()->startOfDay(),\n 'toDate' => $now->copy()->subDay()->endOfDay(),\n ],\n self::FREQUENCY_WEEKLY => [\n 'fromDate' => $now->copy()->subWeeks(1)->startOfDay(),\n 'toDate' => $now->copy()->subDay()->endOfDay(),\n ],\n self::FREQUENCY_MONTHLY => [\n 'fromDate' => $now->copy()->subMonths(1)->startOfDay(),\n 'toDate' => $now->copy()->subDay()->endOfDay(),\n ],\n self::FREQUENCY_QUARTERLY => [\n 'fromDate' => $now->copy()->subMonths(3)->startOfDay(),\n 'toDate' => $now->copy()->subDay()->endOfDay(),\n ],\n default => throw new InvalidArgumentException(\"Unsupported frequency: {$frequency}\"),\n };\n }\n\n private function calculateFromAndToDate(AutomatedReport $automatedReport): array\n {\n return $this->calculateFromAndToDatePeriod(\n $automatedReport->getFrequency(),\n $automatedReport->getFrom(),\n $automatedReport->getTo()\n );\n }\n\n public function getAskJiminnyGenerateReportPayload(\n AutomatedReport $automatedReport,\n AutomatedReportResult $reportResult,\n array $activityIds,\n ): array {\n return [\n 'user_question' => $automatedReport->getAskAnythingPrompt()?->getContent(),\n 'call_ids' => array_map('strval', $activityIds),\n 'team_id' => $automatedReport->getTeamId(),\n 'request_id' => $reportResult->getUuid(),\n 'callback_url' => $this->getCallbackUrl(),\n 'report_period' => $this->getReportPeriodName($reportResult),\n 'report_name' => $automatedReport->getCustomName(),\n ];\n }\n\n private function getCallbackUrl(): string\n {\n return $this->webhookService->route('jiminny.webhook.reports.ready');\n }\n\n /**\n * Validate and transform payload data for automated reports\n *\n * @param array $data\n *\n * @throws InvalidArgumentException\n *\n * @return array\n */\n private function validateAndTransformData(array $data): array\n {\n // Validate organization (team) and check feature\n $team = $this->validateOrganization($data['organization'] ?? null);\n\n $status = $this->validateReportStatus($data['report_enabled'] ?? null);\n $type = $this->validateReportType($data['report_type'] ?? null);\n $frequency = $this->validateFrequency($data['frequency'] ?? null);\n $additionalPromptInput = $this->validateAdditionalPromptInput(\n $data['additional_prompt_input'] ?? null\n );\n $customReportName = $this->validateCustomReportName($data['custom_name'] ?? null);\n\n // Prepare data for the database\n $reportData = [\n 'team_id' => $team->getId(),\n 'type' => $type,\n 'status' => $status,\n 'frequency' => $frequency,\n 'additional_prompt_input' => $additionalPromptInput,\n 'custom_name' => $customReportName,\n ];\n\n // Validate deal values\n $reportData = $this->validateDealValues($data, $reportData);\n\n // Validate date range\n $reportData = $this->validateDateRange($data, $reportData, $frequency);\n\n // Validate call durations\n $reportData = $this->validateCallDurations($data, $reportData);\n\n // Validate call types\n $reportData = $this->validateCallTypes($data, $reportData);\n\n // Validate media types\n $reportData = $this->validateMediaTypes($data, $reportData);\n\n // Validate groups\n if (isset($data['teams'])) {\n $reportData['groups'] = $this->validateAndGetGroupIds($team, $data['teams']);\n }\n\n // Validate deal stages\n $reportData = $this->validateDealStages($data, $reportData, $team, $type);\n\n // Validate playbook categories\n $reportData = $this->validatePlaybookCategories($data, $reportData, $team);\n\n // Validate recipients\n $reportData['recipients'] = [\n 'users' => $this->validateAndGetUserIdsByTeam($team, $data['recipients'] ?? []),\n ];\n\n if (isset($data['jiminny_recipients'])) {\n // Validate Jiminny recipients\n $reportData['jiminny_recipients'] = [\n 'users' => $this->validateAndGetJiminnyUserIds((array) $data['jiminny_recipients']),\n ];\n }\n\n return $reportData;\n }\n\n private function validateDealValues(array $data, array $reportData): array\n {\n if (isset($data['min_deal_value'])) {\n $reportData['deal_value_min'] = (int) $data['min_deal_value'];\n\n if ($reportData['deal_value_min'] > 4294967295 || $reportData['deal_value_min'] < 0) {\n throw new InvalidArgumentException('Min deal value should be between 0 and 4294967295');\n }\n }\n\n if (isset($data['max_deal_value'])) {\n $reportData['deal_value_max'] = (int) $data['max_deal_value'];\n\n if ($reportData['deal_value_max'] > 4294967295 || $reportData['deal_value_max'] < 0) {\n throw new InvalidArgumentException('Max deal value should be between 0 and 4294967295');\n }\n }\n\n if (isset($data['min_deal_value'], $data['max_deal_value'])\n && $data['min_deal_value'] > $data['max_deal_value']\n ) {\n throw new InvalidArgumentException('Min deal value cannot be greater than max deal value');\n }\n\n return $reportData;\n }\n\n private function validateDateRange(array $data, array $reportData, string $frequency): array\n {\n // Set date range only for one_off frequency\n if ($frequency === 'one_off') {\n if (isset($data['start_date_period'])) {\n $reportData['from'] = $this->parseDate($data['start_date_period']);\n }\n\n if (isset($data['end_date_period'])) {\n $reportData['to'] = $this->parseDate($data['end_date_period']);\n }\n\n if (empty($reportData['from']) || empty($reportData['to'])) {\n throw new InvalidArgumentException(\n 'Start date and end date are required for one_off frequency'\n );\n }\n } else {\n $reportData['from'] = null;\n $reportData['to'] = null;\n }\n\n return $reportData;\n }\n\n private function validateCallDurations(array $data, array $reportData): array\n {\n // Convert call durations from minutes to seconds\n if (isset($data['min_call_duration'])) {\n $reportData['call_duration_min'] = (int) $data['min_call_duration'] * 60;\n\n if ($reportData['call_duration_min'] > 4294967295 || $reportData['call_duration_min'] < 0) {\n throw new InvalidArgumentException('Min call duration should be between 0 and 4294967295');\n }\n }\n\n if (isset($data['max_call_duration'])) {\n $reportData['call_duration_max'] = (int) $data['max_call_duration'] * 60;\n\n if ($reportData['call_duration_max'] > 4294967295 || $reportData['call_duration_max'] < 0) {\n throw new InvalidArgumentException('Max call duration should be between 0 and 4294967295');\n }\n }\n\n return $reportData;\n }\n\n private function validateCallTypes(array $data, array $reportData): array\n {\n // Set call types\n $reportData['call_types'] = $data['call_type'] ?? [];\n if (empty($reportData['call_types'])) {\n $reportData['call_types'] = self::getCallTypes();\n }\n\n foreach ($reportData['call_types'] as $callType) {\n if (! in_array($callType, self::getCallTypes(), true)) {\n throw new InvalidArgumentException(sprintf('Call type %s is invalid', $callType));\n }\n }\n\n return $reportData;\n }\n\n private function validateMediaTypes(array $data, array $reportData): array\n {\n // Set media types from input data\n $reportData['media_types'] = $data['media_types'] ?? [];\n\n if (empty($reportData['media_types'])) {\n throw new InvalidArgumentException('Media types are required');\n }\n\n foreach ($reportData['media_types'] as $mediaType) {\n if (! in_array($mediaType, self::MEDIA_TYPES, true)) {\n throw new InvalidArgumentException(sprintf('Media type %s is invalid', $mediaType));\n }\n }\n\n return $reportData;\n }\n\n private function validateDealStages(array $data, array $reportData, Team $team, string $reportType): array\n {\n // Validate and set deal stages\n if (isset($data['deal_stage_at_call'])) {\n $reportData['deal_at_call_stages'] =\n $this->validateAndGetDealStageIds($team, $data['deal_stage_at_call'], 'Deal stage at call');\n }\n\n if (isset($data['current_deal_stage'])) {\n $reportData['current_deal_stages'] =\n $this->validateAndGetDealStageIds($team, $data['current_deal_stage'], 'Current deal stage');\n }\n\n // Ensure current_deal_stage is not provided for loss_analysis report type\n if ($reportType === self::TYPE_LOSS_ANALYSIS && ! empty($data['current_deal_stage'])) {\n throw new InvalidArgumentException('Current deal stage is not applicable for Loss Analysis reports');\n }\n\n return $reportData;\n }\n\n // transform uuid to id\n private function validatePlaybookCategories(array $data, array $reportData, Team $team): array\n {\n $key = 'playbook_categories';\n\n if (isset($data[$key])) {\n $payloadIds = $data[$key];\n $ids = [];\n\n foreach ($payloadIds as $uuid) {\n $uuid = (string) $uuid;\n\n try {\n $playbookCategory = $this->playbookCategoryRepository->findByUuid($uuid);\n } catch (Throwable $throwable) {\n Log::error(__METHOD__ . ' ' . $throwable->getMessage());\n\n throw new InvalidArgumentException(sprintf('Playbook category %s not found', $uuid));\n }\n\n if (! $playbookCategory) {\n throw new InvalidArgumentException(sprintf('Playbook category %s not found', $uuid));\n }\n\n if (! $playbookCategory->hasPlaybook()) {\n throw new InvalidArgumentException(sprintf('Playbook category %s has no playbook', $uuid));\n }\n\n if ($playbookCategory->getPlaybook()->getTeamId() !== $team->getId()) {\n throw new InvalidArgumentException(\n sprintf('Playbook category %s not found for team %s', $uuid, $team->getUuid())\n );\n }\n\n $ids[] = $playbookCategory->getId();\n }\n\n $reportData[$key] = $ids;\n }\n\n return $reportData;\n }\n\n private function validateReportStatus($status): bool\n {\n if (! in_array($status, [true, false], true)) {\n throw new InvalidArgumentException('Report status is invalid');\n }\n\n return $status;\n }\n\n private function validateReportType($type): string\n {\n if (! in_array($type, self::getTypes(), true)) {\n throw new InvalidArgumentException(sprintf('Report type is invalid: %s', $type));\n }\n\n return $type;\n }\n\n private function validateFrequency($frequency): string\n {\n if (! in_array($frequency, self::getFrequencies(), true)) {\n throw new InvalidArgumentException('Frequency is invalid');\n }\n\n return $frequency;\n }\n\n private function validateAdditionalPromptInput(?string $additionalPromptInput): ?string\n {\n if ($additionalPromptInput && strlen($additionalPromptInput) > 5000) {\n throw new InvalidArgumentException('Additional Prompt Input should be less than 5000 characters');\n }\n\n return $additionalPromptInput;\n }\n\n private function validateCustomReportName(?string $customReportName): ?string\n {\n if ($customReportName === null || $customReportName === '') {\n return null;\n }\n\n if (strlen($customReportName) > 70) {\n throw new InvalidArgumentException('Custom report name should be less than 70 characters');\n }\n\n return $customReportName;\n }\n\n private function validateOrganization(?string $organizationUuid): Team\n {\n if (! $organizationUuid) {\n throw new InvalidArgumentException('Organization is required');\n }\n\n $team = $this->teamRepository->idOrUuid($organizationUuid);\n\n if (! $team) {\n throw new InvalidArgumentException('Organization not found');\n }\n\n if (! $team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {\n throw new InvalidArgumentException('Organization does not have the Automated Reports feature');\n }\n\n return $team;\n }\n\n private function validateAndGetGroupIds(Team $team, array $teamUuids): array\n {\n $groupIds = [];\n\n foreach ($teamUuids as $uuid) {\n $group = $this->groupRepository->findByUuid($uuid);\n\n if ($group === null || $group->getTeamId() !== $team->getId()) {\n throw new InvalidArgumentException(\n sprintf('Group %s not found for team %s', $uuid, $team->getUuid())\n );\n }\n\n $groupIds[] = $group->getId();\n\n }\n\n return $groupIds;\n }\n\n private function validateAndGetDealStageIds(Team $team, array $stageUuids, string $propertyLabel): array\n {\n $stageIds = [];\n\n foreach ($stageUuids as $uuid) {\n $stage = $this->stageRepository->findByUuid($uuid);\n\n if ($stage === null || $stage->getTeamId() !== $team->getId()) {\n throw new InvalidArgumentException(\n sprintf('Stage %s not found for team %s for %s', $uuid, $team->getUuid(), $propertyLabel)\n );\n }\n\n $stageIds[] = $stage->getId();\n }\n\n return $stageIds;\n }\n\n private function validateAndGetUserIds(array $userUuids, callable $teamCheck): array\n {\n if (empty($userUuids)) {\n return [];\n }\n\n $userIds = [];\n\n foreach ($userUuids as $uuid) {\n $user = $this->userRepository->findByUuid($uuid);\n\n if (! $user || ! $user->isStatusActive()) {\n throw new InvalidArgumentException(\n sprintf('User %s not found or is not active', $uuid)\n );\n }\n\n if (! $teamCheck($user)) {\n throw new InvalidArgumentException(\n sprintf('User %s does not belong to the allowed team(s)', $uuid)\n );\n }\n\n $userIds[] = $user->getId();\n }\n\n return $userIds;\n }\n\n private function validateAndGetUserIdsByTeam(Team $team, array $userUuids): array\n {\n return $this->validateAndGetUserIds($userUuids, fn ($user) => $user->getTeamId() === $team->getId());\n }\n\n private function validateAndGetJiminnyUserIds(array $userUuids): array\n {\n $allowedTeamIds = config('kiosk.teamIds', []);\n\n return $this->validateAndGetUserIds($userUuids, fn ($user) => in_array($user->getTeamId(), $allowedTeamIds, true));\n }\n\n private function parseDate(string $dateString): string\n {\n return date('Y-m-d H:i:s', strtotime($dateString));\n }\n\n private function generateReportResultViewUrl(AutomatedReportResult $result): string\n {\n $mediaResource = $this->getReportMediaRouteResource($result);\n\n return route('ai-reports.' . $mediaResource . '.view', ['uuid' => $result->getUuid()]);\n }\n\n private function generateReportResultDownloadUrl(AutomatedReportResult $result): string\n {\n $mediaResource = $this->getReportMediaRouteResource($result);\n\n return route('ai-reports.' . $mediaResource . '.download', ['uuid' => $result->getUuid()]);\n }\n\n private function getReportMediaRouteResource(AutomatedReportResult $result): string\n {\n if ($result->getMediaType() === self::MEDIA_TYPE_PDF) {\n return self::PDF_KEY;\n } elseif ($result->getMediaType() === self::MEDIA_TYPE_PODCAST) {\n return self::AUDIO_KEY;\n }\n\n throw new \\InvalidArgumentException('Unknown media type.');\n }\n\n public function getMediaPath(AutomatedReportResult $result): ?string\n {\n $url = match ($result->getMediaType()) {\n self::MEDIA_TYPE_PDF => $result->getPdfUrl(),\n self::MEDIA_TYPE_PODCAST => $result->getPodcastAudioUrl(),\n default => null,\n };\n\n if ($url === null) {\n return null;\n }\n\n $path = parse_url(trim($url, '\"\\''), PHP_URL_PATH);\n\n return $path ?: null;\n }\n\n public function getFilenameSuffix(AutomatedReportResult $result): ?string\n {\n return match ($result->getMediaType()) {\n self::MEDIA_TYPE_PODCAST => 'Podcast',\n default => null,\n };\n }\n\n public function getMailSubjectSuffix(AutomatedReportResult $result): string\n {\n return match ($result->getMediaType()) {\n self::MEDIA_TYPE_PDF => 'report',\n self::MEDIA_TYPE_PODCAST => 'podcast',\n default => '',\n };\n }\n\n public function getMediaTypeMetadata(AutomatedReportResult $result): array\n {\n return match ($result->getMediaType()) {\n self::MEDIA_TYPE_PODCAST => ['extension' => 'mp3', 'mime' => 'audio/mpeg'],\n self::MEDIA_TYPE_PDF => ['extension' => 'pdf', 'mime' => 'application/pdf'],\n default => ['extension' => null, 'mime' => null],\n };\n }\n\n public function deleteS3Files(AutomatedReportResult $result): void\n {\n $teamUuid = $result->getReport()->getTeam()->getUuid();\n $reportUuid = $result->getUuid();\n\n // delete all files for a report uuid no mather of pdf, podcast, or both\n // in case of both - the podcast files are linked to the pdf (parent) uuid\n // pdf and podcast date times should be close\n $path = sprintf('%s/%s/%s', $teamUuid, self::S3_DIR, $reportUuid);\n\n foreach (self::FILE_EXTENSIONS_VARIANTS as $extension) {\n $file = $path . '.' . $extension;\n\n if (Storage::exists($file)) {\n Storage::delete($file);\n Log::info('[Reports] Deleted S3 file', [\n 'path' => $file,\n ]);\n }\n }\n\n foreach (self::FILE_PODCAST_EXTENSIONS_VARIANTS as $extension) {\n $file = $path . '_podcast.' . $extension;\n\n if (Storage::exists($file)) {\n Storage::delete($file);\n Log::info('[Reports] Deleted Podcast S3 file', [\n 'path' => $file,\n ]);\n }\n }\n }\n\n /**\n *\n * @param int|null $teamId Optional team ID to filter results\n *\n * @return Collection<int, int> Collection of team IDs\n */\n public function getTeamIdsWithReportsResults(?int $teamId = null): Collection\n {\n return $this->automatedReportsRepository->getTeamIdsWithReportsResults($teamId);\n }\n\n /**\n * Core delete logic for report results using a query\n *\n * @param Builder $query\n * @param array $logContext\n *\n * @return int\n */\n private function deleteReportResultsByQuery(Builder $query, array $logContext = []): int\n {\n $deletedCount = 0;\n\n if ($query->exists()) {\n Log::info(\n 'Run delete report results',\n array_merge(\n $logContext,\n [\n 'service' => 'AutomatedReportsService',\n ]\n )\n );\n\n $query->chunkById(50, function ($results) use (&$deletedCount, $logContext) {\n foreach ($results as $result) {\n $this->deleteReportResult($result);\n $deletedCount++;\n\n Log::info(\n 'Deleted a report result',\n array_merge(\n $logContext,\n [\n 'result_id' => $result->getId(),\n 'report_id' => $result->getReportId(),\n ]\n )\n );\n }\n });\n }\n\n return $deletedCount;\n }\n\n /**\n * Delete report results for a team by retention period\n *\n * @param Team $team\n * @param CarbonImmutable $retentionDate\n *\n * @return int Number of deleted report results\n */\n public function deleteReportsResultsInRetentionPeriod(Team $team, CarbonImmutable $retentionDate): int\n {\n $reportIds = $this->automatedReportsRepository->getReportIdsByTeam($team);\n\n if ($reportIds->isEmpty()) {\n return 0;\n }\n\n $query = $this->automatedReportsRepository\n ->getReportResultsQueryForRetention($team, $retentionDate);\n\n return $this->deleteReportResultsByQuery($query, [\n 'team_id' => $team->getId(),\n 'retention_date' => $retentionDate->toDateTimeString(),\n ]);\n }\n\n /**\n * Delete ALL report results for a specific automated report\n *\n * @param string $uuid\n *\n * @return int\n */\n public function deleteReportResults(string $uuid): int\n {\n $report = $this->getReport($uuid);\n\n $query = $this->automatedReportsRepository->getResultsByReportQuery($report);\n\n return $this->deleteReportResultsByQuery($query, [\n 'report_uuid' => $uuid,\n 'report_id' => $report->getId(),\n ]);\n }\n\n public function deleteReportResult(AutomatedReportResult $result): void\n {\n $this->deleteS3Files($result);\n\n $result->delete();\n }\n\n /**\n * Get all reports for a specific team\n *\n * @param Team $team\n *\n * @return \\Illuminate\\Database\\Eloquent\\Collection\n */\n public function getTeamReports(Team $team): \\Illuminate\\Database\\Eloquent\\Collection\n {\n return $this->automatedReportsRepository->getReportsByTeam($team);\n }\n\n /**\n * Get all report results for a specific report\n *\n * @param AutomatedReport $report\n *\n * @return \\Illuminate\\Database\\Eloquent\\Collection\n */\n public function getReportResults(AutomatedReport $report): \\Illuminate\\Database\\Eloquent\\Collection\n {\n return $this->automatedReportsRepository->getResultsByReport($report);\n }\n\n public function deleteAllReportResults(AutomatedReport $report): void\n {\n $results = $this->getReportResults($report);\n\n /** @var AutomatedReportResult $result */\n foreach ($results as $result) {\n Log::info('Deleting result', [\n 'report' => $report->getId(),\n 'result' => $result->getId(),\n ]);\n\n $this->deleteReportResult($result);\n }\n }\n\n public function deleteAllData(Team $team): void\n {\n Log::info('Deleting automated report and results for team', [\n 'team' => $team->getId(),\n ]);\n\n $reports = $this->getTeamReports($team);\n\n /** @var AutomatedReport $report */\n foreach ($reports as $report) {\n Log::info('Deleting report', [\n 'team' => $team->getId(),\n 'report' => $report->getId(),\n ]);\n\n $this->deleteAllReportResults($report);\n\n $report->delete();\n }\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":true,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"Project","depth":3,"role_description":"text"},{"role":"AXButton","text":"Project","depth":3,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"New File or Directory…","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Expand Selected","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Collapse All","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Options","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false}]...
|
3397592283435315795
|
6686367547760219213
|
idle
|
accessibility
|
NULL
|
Project: faVsco.js, menu
#11894 on JY-18909-automa Project: faVsco.js, menu
#11894 on JY-18909-automated-reports-ask-jiminny, menu
Start Listening for PHP Debug Connections
AutomatedReportsCommandTest
Run 'AutomatedReportsCommandTest'
Debug 'AutomatedReportsCommandTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Execute
Explain Plan
Browse Query History
View Parameters
Open Query Execution Settings…
In-Editor Results
Tx: Auto
Cancel Running Statements
Playground
jiminny
Sync Changes
Hide This Notification
Code changed:
Hide
16
13
13
Previous Highlighted Error
Next Highlighted Error
SELECT * FROM teams WHERE id = 1;
select * from crm_layouts where crm_configuration_id = 39;
SELECT * FROM crm_layout_entities WHERE crm_layout_id = 283;
SELECT * FROM crm_fields WHERE id = 2234;
SELECT * FROM crm_field_values WHERE crm_field_id = 2234;
select * from crm_profiles where user_id = 143;
select * from record_types where crm_configuration_id = 39; # 0121K000001MHElQAO,0121K000001MHEqQAO
select * from business_processes where crm_configuration_id = 39;
# 01941000000H669AAC, 01941000000H66JAAS
select * from record_type_field_values
where record_type_id IN (24);
select * from crm_field_values where id IN (2730);
select * from crm_configurations where id = 39;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 1
and sa.provider = 'salesforce'; #1035
select * from users where team_id = 1; # 222 group 3
SELECT * FROM activities WHERE user_id = 222 order by id desc;
select * from sidekick_settings where team_id = 1;
select * from teams where id = 1;
select * from team_features where team_id = 1;
select * from activities where crm_configuration_id = 2
and provider = 'ms-teams' and id = 608765;
SELECT * FROM activities WHERE crm_configuration_id = 2 and crm_provider_id = '59523413338';
select * from sidekick_settings where team_id = 2;
SELECT * FROM activities WHERE id = 608660;
select * from activity_summary_logs where activity_id = 608660;
select * from ai_prompts where transcription_id = 11214;
# [PASSWORD_DOTS]
SELECT * FROM activities WHERE uuid_to_bin('ed78a437-2804-450e-ab2f-56ab1c641346') = uuid;
# id: 608818, crm: 59628809737
SELECT * FROM activities WHERE uuid_to_bin('36b06e55-afdd-4782-8dee-c624cd0af191') = uuid;
# id: 608821, crm: 59632069252
SELECT ce.start_time, ce.end_time, a.id, a.uuid, crm_provider_id, calendar_event_id, title,
playbook_category_id, user_id, lead_id, contact_id, account_id, opportunity_id,
scheduled_start_time, scheduled_end_time, actual_start_time, actual_end_time, a.created_at
FROM activities a
join calendar_events ce on a.calendar_event_id = ce.id
WHERE a.id IN (608818, 608821);
select * from users where team_id = 1;
select * from team_settings where team_id = 1;
select * from crm_profiles where crm_configuration_id = 39 order by user_id;
select * from team_features where team_id = 1;
select * from users where team_id = 2;
SELECT * FROM activities WHERE uuid_to_bin('ec7647e9-5225-458b-b475-f31aa2769204') = uuid; # 612639
# Preslava N. Ivanova, grou id 3
SELECT * FROM opportunities WHERE uuid_to_bin('a2928fe5-aec5-46cb-85d9-7654c89e46a6') = uuid;
select * from activities where opportunity_id = 344 and actual_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00';
select
a.id,
a.type,
a.scheduled_start_time,
a.actual_start_time,
a.created_at,
a.opportunity_id,
a.status
FROM activities a
WHERE opportunity_id = 344
and status IN ('completed', 'received', 'delivered')
and (
(a.actual_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00')
OR (a.created_at between '2024-10-11 00:00:00' and '2024-10-12 00:00:00')
OR (a.scheduled_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00'))
;
SELECT * FROM users WHERE id = 222;
SELECT * FROM crm_profiles WHERE user_id = 222;
select * from crm_layouts where crm_configuration_id = 39;
SELECT * FROM crm_layout_entities WHERE crm_layout_id = 281;
select * from group_deal_risk_types;
select * from opportunities where team_id = 1;
SELECT * FROM opportunities WHERE id = 315;
SELECT * FROM crm_field_data WHERE object_id = 315;
select * from crm_field_data where object_id = 260;
select * from generic_ai_prompts where subject_id = 315;
select * from teams; # 36, 21, 121, [EMAIL]
SELECT * FROM social_accounts WHERE sociable_id = 121 and provider = 'bullhorn';
# [PASSWORD_DOTS]
select * from teams where id = 1;
select * from crm_configurations where id = 39;
select * from users where team_id = 1;
select u.email, cp.* from users u
join crm_profiles cp on u.id = cp.user_id
where u.team_id = 1;
# 1 - 00541000004281rAAA
# 204 - 0052g000003freeAAA
# 429 - 0052g000003qGOiAAM
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 1
and sa.provider = 'salesforce';
select * from activities where type = 'softphone'
and created_at > '2024-12-11 15:24:36' order by id desc;
select * from activity_providers where team_id = 1;
select * from activity_provider_users where activity_provider_id = 328;
select * from opportunities where crm_configuration_id = 39
AND account_id = 178 AND is_closed = false
order by created_at DESC;
select * from contacts where id = 3952;
select * from accounts where id = 178;
# [PASSWORD_DOTS]
select * from teams where id = 36;
select * from crm_configurations where id = 21;
select * from users where team_id = 36;
select u.email, cp.* from users u
join crm_profiles cp on u.id = cp.user_id
where u.team_id = 36;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 36
and sa.provider = 'bullhorn';
select * from social_accounts where id = 348;
UPDATE social_accounts SET
provider_user_token = '21442_6802599_91:41179a58-21e7-4d7c-ad58-56bb666b2f65',
provider_refresh_token = '21442_6802599_91:01c6b335-3f2a-42e4-85ff-8a08fa65fceb',
expires = 1733998131,
state = 'connected'
WHERE id = 348;
# [PASSWORD_DOTS]
select * from teams where id = 31;
select * from crm_configurations where id = 18;
select * from users where team_id = 31; # 257
select u.email, cp.* from users u
join crm_profiles cp on u.id = cp.user_id
where u.team_id = 31;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 31
and sa.provider = 'close';
select * from contacts where crm_configuration_id = 18;
# [PASSWORD_DOTS] NEPTUNE [PASSWORD_DOTS]
select * from teams;
select * from users where id IN (1030, 1035, 1052);
select * from crm_configurations;
select * from users where team_id = 65; # 257
select * from team_settings where team_id = 65; # 257
select * from invitations where team_id = 65; # 257
select * from users where email = '[EMAIL]'; # 257
select u.email, cp.* from users u
join crm_profiles cp on u.id = cp.user_id
where u.team_id = 65;
select * from crm_configurations where id = 53;
select * from accounts where crm_configuration_id = 53 order by id desc;
select * from leads where crm_configuration_id = 53 order by id desc;
select * from contacts where crm_configuration_id = 53 order by id desc;
select * from opportunities where crm_configuration_id = 53 order by id desc;
select * from crm_profiles where crm_configuration_id = 53 order by id desc;
select * from crm_fields where crm_configuration_id = 53 order by id desc;
select * from crm_field_values where crm_field_id = 3341 order by id desc;
select * from crm_layouts where crm_configuration_id = 53 order by id desc;
select * from stages where crm_configuration_id = 53 order by id desc;
select * from crm_profiles where crm_configuration_id = 13;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 65
and sa.provider = 'integration-app';
select * from contacts where crm_configuration_id = 13;
select * from social_accounts where sociable_id = 283;
SELECT * FROM opportunities WHERE crm_provider_id = '006O400000E9bzeIAB';
select * from activity_providers where team_id = 65;
SELECT * FROM activities WHERE crm_configuration_id IN (51, 52, 53);
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 65
;
# [PASSWORD_DOTS] STAGING [PASSWORD_DOTS]
SELECT * FROM teams;
SELECT * FROM teams WHERE id = 88;
SELECT * FROM teams WHERE id = 89;
select * from team_settings where team_id = 89;
SELECT * FROM users WHERE team_id = 89;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 89;
select * from users;
SELECT * FROM social_accounts WHERE sociable_id = 1761;
SELECT * FROM crm_configurations WHERE id = 70;
select * from accounts where crm_configuration_id = 70 order by id desc;
select * from leads where crm_configuration_id = 70 order by id desc;
select * from contacts where crm_configuration_id = 70 order by id desc;
select * from opportunities where crm_configuration_id = 70 order by id desc;
select * from crm_profiles where crm_configuration_id = 70 order by id desc;
select * from crm_fields where crm_configuration_id = 70 order by id desc;
select * from crm_field_values where crm_field_id = 3536 order by id desc;
select * from crm_layouts where crm_configuration_id = 70 order by id desc;
select * from stages where crm_configuration_id = 70 order by id desc;
select * from business_processes where crm_configuration_id = 70 order by id desc;
select * from business_process_stages where business_process_id = 34;
select * from contacts where id = 10468;
select * from crm_layouts where crm_configuration_id = 70;
SELECT * FROM crm_layout_entities WHERE crm_layout_id = 388;
SELECT * FROM crm_fields WHERE id IN (3533,3534,3535);
select * from activities where crm_configuration_id = 70
and (account_id IS NOT NULL or lead_id IS NOT NULL or contact_id IS NOT NULL or opportunity_id IS NOT NULL) order by id desc;
SELECT * FROM activities WHERE uuid_to_bin('2e10b60f-8a61-41c5-a3d4-28835353dc65') = uuid;
SELECT * FROM activities where crm_configuration_id = 69 ;
SELECT * FROM users WHERE email LIKE '%[EMAIL]%';
SELECT * FROM activities WHERE uuid_to_bin('5a150c93-40fc-42ec-b3bd-c1d328e09f6e') = uuid;
SELECT * FROM opportunities WHERE id = 385;
select * from participants p
join activities a on p.activity_id = a.id
where a.crm_configuration_id = 70
and (p.lead_id IS NOT NULL or p.contact_id IS NOT NULL);
SELECT * FROM participants WHERE id = 1013638;
select * from teams where id = 90;
select * from users where team_id = 90;
select * from social_accounts where social_accounts.sociable_id IN (1960,1760);
SELECT * FROM crm_profiles WHERE crm_configuration_id = 71;
select * from invitations where team_id = 90;
select * from crm_configurations where id = 71;
select * from accounts where crm_configuration_id = 71 order by id desc;
select * from leads where crm_configuration_id = 71 order by id desc;
select * from contacts where crm_configuration_id = 71 order by id desc;
select * from opportunities where crm_configuration_id = 71 order by id desc;
select * from crm_profiles where crm_configuration_id = 71 order by id desc;
select * from crm_fields where crm_configuration_id = 71 order by id desc;
select * from crm_field_values where crm_field_id = 3341 order by id desc;
select * from crm_layouts where crm_configuration_id = 71 order by id desc;
select * from stages where crm_configuration_id = 71 order by id desc;
select * from users order by secondary_email desc;
select u.id, u.email, u.status, sa.id, sa.provider_user_id from social_accounts sa
join users u on sa.sociable_id = u.id
where sa.provider = 'google' and u.email LIKE 'aneliya%';
select * from failed_jobs order by id desc;
select * from users where email = '[EMAIL]' or secondary_email = '[EMAIL]';
select * from teams;
SELECT * FROM crm_profiles WHERE crm_configuration_id = 39;
SELECT * FROM crm_fields WHERE crm_configuration_id = 39 and object_type = 'task';
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 1
and sa.provider = 'salesforce';
# [PASSWORD_DOTS]
SELECT * FROM activities WHERE uuid_to_bin('c38b3895-fd0f-4b1f-9fb2-c170dba137c6') = uuid;
SELECT * FROM crm_configurations WHERE id = 70;
select * from teams where id = 1;
select * from groups where team_id = 1;
select * from users where team_id = 1;
select o.id, o.name,o.close_date, u.id, u.name, u.group_id, r.id, r.display_name, g.name, g.scope from opportunities o
join users u on o.user_id = u.id
join groups g on u.group_id = g.id
join role_user ru on u.id = ru.user_id
join roles r on ru.role_id = r.id
where o.crm_configuration_id = 39 and close_date > '2024-01-01 00:00:00';
select * from role_user where user_id = 143;
select * from roles;
select * from role_user;
select * from groups where id = 9;
select * from scope_groups where group_id = 9;
# [PASSWORD_DOTS]
select * from teams where id = 36;
select * from crm_configurations;
SELECT * FROM social_accounts WHERE sociable_id = 121;
[URL_WITH_CREDENTIALS] this will add filter, however if we need to control feature by FF we need conditional logic
public const array TYPES = [
['id' => 'exec_summary', 'name' => 'Exec Summary'],
['id' => 'coaching_profiles', 'name' => 'Coaching Profiles'],
['id' => 'product_feedback', 'name' => 'Product Feedback'],
['id' => self::TYPE_LOSS_ANALYSIS, 'name' => 'Loss Analysis'],
// ['id' => 'questions', 'name' => 'Questions'],
// ['id' => 'statistical_quant', 'name' => 'Statistical Quantitative'],
];
public const array ALL_TYPES = [
...self::TYPES,
['id' => self::TYPE_ASK_JIMINNY, 'name' => 'Ask Jiminny'],
];
public const string FREQUENCY_DAILY = 'daily';
public const string FREQUENCY_WEEKLY = 'weekly';
public const string FREQUENCY_MONTHLY = 'monthly';
public const string FREQUENCY_QUARTERLY = 'quarterly';
public const string FREQUENCY_ONE_OFF = 'one_off';
/**
* Frequencies for standard (non-Ask Jiminny) reports.
*/
public const array FREQUENCIES = [
['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],
['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],
['id' => self::FREQUENCY_QUARTERLY, 'name' => 'Quarterly'],
['id' => self::FREQUENCY_ONE_OFF, 'name' => 'One-off'],
];
/**
* Frequencies for Ask Jiminny reports.
*/
public const array ASK_JIMINNY_FREQUENCIES = [
['id' => self::FREQUENCY_DAILY, 'name' => 'Daily'],
['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],
['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],
];
public const string MEDIA_TYPE_PDF = 'pdf';
public const string MEDIA_TYPE_PODCAST = 'podcast';
public const array MEDIA_TYPES = [self::MEDIA_TYPE_PDF, self::MEDIA_TYPE_PODCAST];
public const array MEDIA_TYPE_OBJECT_PDF = ['id' => self::MEDIA_TYPE_PDF, 'name' => 'PDF'];
public const array MEDIA_TYPE_OBJECT_PODCAST = ['id' => self::MEDIA_TYPE_PODCAST, 'name' => 'Podcast'];
public const array MEDIA_TYPE_OBJECTS = [self::MEDIA_TYPE_OBJECT_PDF, self::MEDIA_TYPE_OBJECT_PODCAST];
public const array CALL_TYPE_CONFERENCE = ['id' => 'conference', 'name' => 'Conference'];
public const array CALL_TYPE_DIALER = ['id' => 'dialer', 'name' => 'Dialer'];
public const int SENT_REPORT_AT_HOURS = 5;
public const string PDF_KEY = 'pdf';
public const string AUDIO_KEY = 'audio';
private const array ALL_FREQUENCIES = [
['id' => self::FREQUENCY_DAILY, 'name' => 'Daily'],
['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],
['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],
['id' => self::FREQUENCY_QUARTERLY, 'name' => 'Quarterly'],
['id' => self::FREQUENCY_ONE_OFF, 'name' => 'One-off'],
];
private const string S3_DIR = 'reports';
private const array FILE_EXTENSIONS_VARIANTS = ['html', 'MD', 'pdf'];
private const array FILE_PODCAST_EXTENSIONS_VARIANTS = ['json', 'mp3', 'ssml'];
public function __construct(
private readonly TeamRepository $teamRepository,
private readonly GroupRepository $groupRepository,
private readonly UserRepository $userRepository,
private readonly StageRepository $stageRepository,
private readonly DealStagesService $dealStagesService,
private readonly RecipientsService $recipientsService,
private readonly AutomatedReportsRepository $automatedReportsRepository,
private readonly Webhook $webhookService,
private readonly BusDispatcher $dispatcher,
private readonly ActivityTypeService $activityTypeService,
private readonly PlaybookCategoryRepository $playbookCategoryRepository,
private readonly AskAnythingPromptService $askAnythingPromptService,
private readonly SearchRepository $activitySearchRepository,
private readonly AskAnythingRepository $askAnythingRepository,
) {
}
public static function getTypes(): array
{
$types = self::TYPES;
return array_map(static function ($type) {
return $type['id'];
}, $types);
}
public static function getCallTypes(): array
{
return array_map(static function ($callType) {
return $callType['id'];
}, [self::CALL_TYPE_CONFERENCE, self::CALL_TYPE_DIALER]);
}
public static function getFrequencies(): array
{
return array_map(static function ($frequency) {
return $frequency['id'];
}, self::FREQUENCIES);
}
// front-facing structure
public function getReportEnabledFieldData(bool $value = false): array
{
return [
'id' => 'report_enabled',
'label' => '',
'inputType' => InputTypeEnum::TOGGLE,
'value' => $value,
];
}
// Organizations = Teams
public function getOrganizationFieldData(?string $value = null, bool $shortVersion = false): array
{
$options = $this->getTeams();
if ($shortVersion) {
return [
'id' => 'organization',
'label' => 'Organization',
'options' => $options,
];
}
return [
'id' => 'organization',
'label' => 'Organization',
'inputType' => InputTypeEnum::DROPDOWN,
'required' => true,
'placeholder' => 'Select',
'options' => $options,
'value' => $value,
'dependencies' => [
'teams',
'deal_stage_at_call',
'current_deal_stage',
'recipients',
ActivityTypeService::PLAYBOOK_CATEGORIES_KEY,
],
'dependsOn' => [],
];
}
// Teams = Groups
public function getTeamFieldData(array $options = [], array $value = [], bool $shortVersion = false): array
{
if ($shortVersion) {
return [
'id' => 'teams',
'label' => 'Team',
'options' => $options,
];
}
return [
'id' => 'teams',
'label' => 'Team',
'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,
'required' => false,
'placeholder' => 'Select',
'options' => $options,
'value' => $value, // value should be an array of objects {id, name}
'dependencies' => [ActivityTypeService::PLAYBOOK_CATEGORIES_KEY],
'dependsOn' => [],
];
}
public function getReportTypeFieldData(?string $value = null, bool $shortVersion = false, ?Team $team = null): array
{
$types = [];
if ($team instanceof Team) {
if ($team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {
$types = self::TYPES;
}
if ($team->hasFeature(FeatureEnum::ASK_JIMINNY_REPORTS)) {
$types[] = ['id' => self::TYPE_ASK_JIMINNY, 'name' => 'Ask Jiminny'];
}
} else {
$types = self::TYPES;
}
if ($shortVersion) {
return [
'id' => 'report_type',
'label' => 'Report Type',
'options' => $types,
];
}
return [
'id' => 'report_type',
'label' => 'Report Type',
'inputType' => InputTypeEnum::DROPDOWN,
'required' => true,
'placeholder' => 'Select',
'options' => $types,
'value' => $value,
'dependencies' => [],
'dependsOn' => [],
];
}
public function getFrequencyFieldData(?string $value = null): array
{
return [
'id' => 'frequency',
'label' => 'Frequency',
'inputType' => InputTypeEnum::DROPDOWN,
'required' => true,
'placeholder' => 'Select',
'options' => self::FREQUENCIES,
'value' => $value,
'dependencies' => ['period'],
'dependsOn' => [],
];
}
public function getPeriodFieldData(?string $valueStartDate = null, ?string $valueEndDate = null): array
{
return [
'id' => 'period',
'label' => 'Select one-off period',
'inputType' => InputTypeEnum::DATE_RANGE,
'required' => true,
'placeholder' => 'Select',
'value' => ['startDate' => $valueStartDate, 'endDate' => $valueEndDate],
'queryParams' => [
'startDate' => 'start_date_period',
'endDate' => 'end_date_period',
],
'dependencies' => [],
'dependsOn' => ['frequency'],
];
}
public function getActivityTypesFieldData(?Team $team = null, array $value = [], array $teamsFilter = []): array
{
return $this->activityTypeService->getActivityTypeFieldData(team: $team, value: $value, groupIds: $teamsFilter);
}
public function getDealStageAtCallFieldData(?Team $team = null, array $value = []): array
{
return $this->dealStagesService->getDealStageAtCallFieldData(team: $team, value: $value);
}
public function getCurrentDealStageFieldData(?Team $team = null, array $value = []): array
{
return $this->dealStagesService->getCurrentDealStageFieldData(team: $team, value: $value);
}
public function getDealValueFieldData(?int $valueMin = null, ?int $valueMax = null): array
{
return [
'id' => 'deal_value',
'label' => 'Deal Value',
'inputType' => InputTypeEnum::INTEGER_RANGE,
'required' => false,
'value' => ['min' => $valueMin, 'max' => $valueMax],
'queryParams' => [
'min' => 'min_deal_value',
'max' => 'max_deal_value',
],
'dependencies' => [],
'dependsOn' => [],
];
}
public function getCallTypeFieldData(bool $conferenceOn = false, bool $dialerOn = false): array
{
$value = [];
$conferenceOn && $value[] = self::CALL_TYPE_CONFERENCE;
$dialerOn && $value[] = self::CALL_TYPE_DIALER;
return [
'id' => 'call_type',
'label' => 'Call Type',
'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,
'required' => true,
'options' => [
self::CALL_TYPE_CONFERENCE,
self::CALL_TYPE_DIALER,
],
'value' => $value,
'dependencies' => [],
'dependsOn' => [],
];
}
public function getMediaTypeFieldData(?AutomatedReport $report = null): array
{
$value = [];
if ($report) {
$value = $this->transformMediaTypes($report);
}
return [
'id' => 'media_types',
'label' => 'Export as',
'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,
'required' => true,
'options' => self::MEDIA_TYPE_OBJECTS,
'value' => $value,
'dependencies' => [],
'dependsOn' => [],
];
}
public function getCallDurationFieldData(?int $valueMin = null, ?int $valueMax = null): array
{
return [
'id' => 'call_duration',
'label' => 'Call Duration',
'inputType' => InputTypeEnum::INTEGER_RANGE,
'required' => false,
'value' => ['min' => $valueMin, 'max' => $valueMax],
'queryParams' => [
'min' => 'min_call_duration',
'max' => 'max_call_duration',
],
'dependencies' => [],
'dependsOn' => [],
];
}
public function getRecipientsFieldData(?Team $team = null, array $value = []): array
{
return $this->recipientsService->getRecipientsFieldData(team: $team, value: $value);
}
public function getJiminnyRecipientsFieldData(array $value = []): array
{
return $this->recipientsService->getJiminnyRecipientsFieldData($value);
}
public function getAdditionalPromptInputFieldData(?string $value = null): array
{
return [
'id' => 'additional_prompt_input',
'label' => 'Special requirements',
'inputType' => InputTypeEnum::TEXTAREA,
'required' => false,
'placeholder' => 'What should be the focus of the report?',
'value' => $value,
'dependencies' => [],
'dependsOn' => [],
];
}
public function getCustomReportNameFieldData(?string $value = null): array
{
return [
'id' => 'custom_name',
'label' => 'Custom report name',
'inputType' => InputTypeEnum::TEXT,
'required' => false,
'placeholder' => 'Enter custom name',
'value' => $value,
'dependencies' => [],
'dependsOn' => [],
];
}
// data providers
public function getTeams(): array
{
$teams = $this->teamRepository->getTeamsForKiosk(status: Team::STATUS_ACTIVE);
$teamData = [];
foreach ($teams as $team) {
if (! $team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {
continue;
}
$teamData[] = $this->transformTeam($team);
}
return $teamData;
}
public function getTeamGroups(string $teamUuid): array
{
$data = [];
$team = $this->getTeam($teamUuid);
if ($team !== null) {
$groups = $team->groups()->get();
foreach ($groups as $group) {
$data[] = [
'id' => $group->getUuid(),
'name' => $group->getName(),
];
}
}
return $data;
}
public function getTeamsGroupsOptions(array $filterTeamUuids = []): array
{
$data = [];
$teams = $this->getTeams();
foreach ($teams as $team) {
if (! empty($filterTeamUuids) && ! in_array($team['id'], $filterTeamUuids, true)) {
continue;
}
$data[] = [
'label' => $team['name'],
'groups' => $this->getTeamGroups($team['id']),
];
}
return $data;
}
public function getTeam(string $teamUuid): ?Team
{
return $this->teamRepository->idOrUuid($teamUuid);
}
public function getTeamById(int $teamId): ?Team
{
return $this->teamRepository->find($teamId);
}
public function getGroupsUuids(AutomatedReport $report): array
{
$uuids = [];
$reportGroups = $report->getGroups();
foreach ($reportGroups as $groupId) {
if ($group = $this->groupRepository->find($groupId)) {
$uuids[] = $group->getUuid();
}
}
return $uuids;
}
public function getPlaybookCategoriesUuids(AutomatedReport $report): array
{
$uuids = [];
$playbookCategories = $report->getPlaybookCategories();
foreach ($playbookCategories as $id) {
if ($category = $this->playbookCategoryRepository->find($id)) {
$uuids[] = $category->getUuid();
}
}
return $uuids;
}
public function getDealAtCallStagesUuids(AutomatedReport $report): array
{
$uuids = [];
$reportStages = $report->getDealAtCallStages();
foreach ($reportStages as $id) {
if ($stage = $this->stageRepository->find($id)) {
$uuids[] = $stage->getUuid();
}
}
return $uuids;
}
public function getCurrentDealStagesUuids(AutomatedReport $report): array
{
$uuids = [];
$reportStages = $report->getCurrentDealStages();
foreach ($reportStages as $id) {
if ($stage = $this->stageRepository->find($id)) {
$uuids[] = $stage->getUuid();
}
}
return $uuids;
}
public function getUsersUuids(AutomatedReport $report): array
{
return $this->extractUserUuids($report->getRecipients());
}
public function getJiminnyUsersUuids(AutomatedReport $report): array
{
return $this->extractUserUuids($report->getJiminnyRecipients());
}
/**
* @param array<string, mixed> $recipients
*/
private function extractUserUuids(array $recipients): array
{
$userIds = $recipients['users'] ?? [];
return collect($userIds)
->map(fn ($id) => $this->userRepository->find((int) $id))
->filter()
->map(fn (UserContract $user) => $user->getUuid())
->values()
->all();
}
// get mail data
public function getRecipientUsers(AutomatedReport $report): array
{
return $this->buildRecipientUsers($report->getRecipients());
}
private function getJiminnyRecipientUsers(AutomatedReport $report): array
{
return $this->buildRecipientUsers($report->getJiminnyRecipients());
}
/**
* @param array<string, mixed> $recipients
*/
private function buildRecipientUsers(array $recipients): array
{
$userIds = $recipients['users'] ?? [];
return collect($userIds)
->map(fn ($id) => $this->userRepository->find((int) $id))
->filter()
->map(fn (UserContract $user) => [
'email' => $user->getEmailAddress(),
'name' => $user->getName(),
'timezone' => $user->getTimezone()->getName(),
])
->values()
->all();
}
public function getValidRecipientUsers(AutomatedReport $report, bool $includeJiminny = false): array
{
if ($report->isAskJiminnyReport()) {
$recipients = $this->resolveAskJiminnyRecipients($report);
} else {
$recipients = $this->getRecipientUsers($report);
if ($includeJiminny) {
$recipients = array_merge($recipients, $this->getJiminnyRecipientUsers($report));
}
}
$emails = [];
return array_values(array_filter(
$recipients,
static function ($recipient) use (&$emails) {
if (empty($recipient['email']) || in_array($recipient['email'], $emails, true)) {
return false;
}
$emails[] = $recipient['email'];
return true;
}
));
}
private function resolveAskJiminnyRecipients(AutomatedReport $report): array
{
$recipients = [];
$creator = $report->getCreator();
if ($creator !== null) {
$recipients[] = [
'email' => $creator->getEmailAddress(),
'name' => $creator->getName(),
'timezone' => $creator->getTimezone()->getName(),
];
}
return array_merge(
$recipients,
$this->buildRecipientUsers($report->getRecipients()),
$this->getGroupRecipientUsers($report),
);
}
private function getGroupRecipientUsers(AutomatedReport $report): array
{
$users = [];
foreach ($report->getGroups() as $groupId) {
$group = $this->groupRepository->find($groupId);
if ($group === null) {
continue;
}
foreach ($group->getMembers() as $member) {
$users[] = [
'email' => $member->getEmailAddress(),
'name' => $member->getName(),
'timezone' => $member->getTimezone()->getName(),
];
}
}
return $users;
}
public function getReportTypeName(AutomatedReportResult $report): string
{
$type = $report->getReport()->getType();
$getType = $this->transformReportType($type);
return $getType['name'];
}
public function getReportPeriodName(AutomatedReportResult $report): string
{
$from = $report->getFromDate();
$to = $report->getToDate();
$frequency = $report->getReport()->getFrequency();
if ($from === null || $to === null) {
if (! $report->getReport()->isAskJiminnyReport()) {
$invalidPeriod = $from === null ? 'from' : 'to';
throw new ApplicationException('Report period is invalid: ' . $invalidPeriod);
}
$period = $this->calculateFromAndToDatePeriod($frequency);
$from = $period['fromDate'];
$to = $period['toDate'];
}
return $this->formatReportPeriodName($frequency, $from, $to);
}
private function formatReportPeriodName(string $frequency, Carbon $from, Carbon $to): string
{
$fromYear = $from->format('Y');
$toYear = $to->format('Y');
$differentYears = $fromYear !== $toYear;
switch ($frequency) {
case self::FREQUENCY_DAILY:
return $from->format('j M Y');
case self::FREQUENCY_QUARTERLY:
// 'Jan-Mar 2025' or 'Nov 2024-Jan 2025' if years differ
$startMonth = $from->format('M');
$endMonth = $to->copy()->subMonth();
$endMonthName = $endMonth->format('M');
$endMonthYear = $endMonth->format('Y');
if ($differentYears) {
return "{$startMonth} {$fromYear} - {$endMonthName} {$endMonthYear}";
}
return "{$startMonth} - {$endMonthName} {$toYear}";
case self::FREQUENCY_MONTHLY:
// 'May 2025' - monthly reports are always within the same year
return $from->format('M Y');
case self::FREQUENCY_WEEKLY:
// '4 - 8 Aug 2025', '27 Oct - 3 Nov 2025', or '28 Dec 2024 - 3 Jan 2025' if years differ
$startDay = $from->format('j');
$endDay = $to->format('j');
$startMonth = $from->format('M');
$endMonth = $to->format('M');
if ($differentYears) {
return "{$startDay} {$startMonth} {$fromYear} - {$endDay} {$endMonth} {$toYear}";
}
if ($startMonth !== $endMonth) {
return "{$startDay} {$startMonth} - {$endDay} {$endMonth} {$toYear}";
}
return "{$startDay} - {$endDay} {$endMonth} {$toYear}";
case self::FREQUENCY_ONE_OFF:
// '2 May-31 May 2025' or '15 Dec 2024-15 Jan 2025' if years differ
$startDay = $from->format('j');
$startMonth = $from->format('M');
$endDay = $to->format('j');
$endMonth = $to->format('M');
// If same month and year, use a format like '2-31 May 2025'
if ($startMonth === $endMonth && ! $differentYears) {
return "{$startDay} - {$endDay} {$startMonth} {$toYear}";
}
// If different years, include both years
if ($differentYears) {
return "{$startDay} {$startMonth} {$fromYear} - {$endDay} {$endMonth} {$toYear}";
}
// Same year but different months
return "{$startDay} {$startMonth} - {$endDay} {$endMonth} {$toYear}";
default:
// Default format for unknown frequencies
return $from->format('j M Y') . ' - ' . $to->format('j M Y');
}
}
public function getReportTeamsName(AutomatedReportResult $report): string
{
$groups = $report->getGroups();
if (empty($groups)) {
return 'All';
}
// Get group names from repository
$groupNames = [];
foreach ($groups as $groupId) {
$group = $this->groupRepository->find($groupId);
if ($group) {
$groupNames[] = $group->getName();
}
}
if (count($groupNames) === 1) {
// Single team format
$teamsName = $groupNames[0];
} else {
// Multiple teams format
$teamsName = implode(', ', $groupNames);
}
return $teamsName;
}
public function getReportFileName(AutomatedReportResult $report): string
...
|
12331
|
|
12341
|
NULL
|
0
|
2026-04-14T11:10:03.302650+00:00
|
/Users/lukas/.screenpipe/data/data/2026-04-14/1776 /Users/lukas/.screenpipe/data/data/2026-04-14/1776165003302_m1.jpg...
|
PhpStorm
|
faVsco.js – AutomatedReportsService.php
|
1
|
NULL
|
monitor_1
|
NULL
|
NULL
|
NULL
|
NULL
|
Project: faVsco.js, menu
#11894 on JY-18909-automa Project: faVsco.js, menu
#11894 on JY-18909-automated-reports-ask-jiminny, menu
Start Listening for PHP Debug Connections
AutomatedReportsCommandTest
Run 'AutomatedReportsCommandTest'
Debug 'AutomatedReportsCommandTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Execute
Explain Plan
Browse Query History
View Parameters
Open Query Execution Settings…
In-Editor Results
Tx: Auto
Cancel Running Statements
Playground
jiminny
Sync Changes
Hide This Notification
Code changed:
Hide
16
13
13
Previous Highlighted Error
Next Highlighted Error
SELECT * FROM teams WHERE id = 1;
select * from crm_layouts where crm_configuration_id = 39;
SELECT * FROM crm_layout_entities WHERE crm_layout_id = 283;
SELECT * FROM crm_fields WHERE id = 2234;
SELECT * FROM crm_field_values WHERE crm_field_id = 2234;
select * from crm_profiles where user_id = 143;
select * from record_types where crm_configuration_id = 39; # 0121K000001MHElQAO,0121K000001MHEqQAO
select * from business_processes where crm_configuration_id = 39;
# 01941000000H669AAC, 01941000000H66JAAS
select * from record_type_field_values
where record_type_id IN (24);
select * from crm_field_values where id IN (2730);
select * from crm_configurations where id = 39;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 1
and sa.provider = 'salesforce'; #1035
select * from users where team_id = 1; # 222 group 3
SELECT * FROM activities WHERE user_id = 222 order by id desc;
select * from sidekick_settings where team_id = 1;
select * from teams where id = 1;
select * from team_features where team_id = 1;
select * from activities where crm_configuration_id = 2
and provider = 'ms-teams' and id = 608765;
SELECT * FROM activities WHERE crm_configuration_id = 2 and crm_provider_id = '59523413338';
select * from sidekick_settings where team_id = 2;
SELECT * FROM activities WHERE id = 608660;
select * from activity_summary_logs where activity_id = 608660;
select * from ai_prompts where transcription_id = 11214;
# [PASSWORD_DOTS]
SELECT * FROM activities WHERE uuid_to_bin('ed78a437-2804-450e-ab2f-56ab1c641346') = uuid;
# id: 608818, crm: 59628809737
SELECT * FROM activities WHERE uuid_to_bin('36b06e55-afdd-4782-8dee-c624cd0af191') = uuid;
# id: 608821, crm: 59632069252
SELECT ce.start_time, ce.end_time, a.id, a.uuid, crm_provider_id, calendar_event_id, title,
playbook_category_id, user_id, lead_id, contact_id, account_id, opportunity_id,
scheduled_start_time, scheduled_end_time, actual_start_time, actual_end_time, a.created_at
FROM activities a
join calendar_events ce on a.calendar_event_id = ce.id
WHERE a.id IN (608818, 608821);
select * from users where team_id = 1;
select * from team_settings where team_id = 1;
select * from crm_profiles where crm_configuration_id = 39 order by user_id;
select * from team_features where team_id = 1;
select * from users where team_id = 2;
SELECT * FROM activities WHERE uuid_to_bin('ec7647e9-5225-458b-b475-f31aa2769204') = uuid; # 612639
# Preslava N. Ivanova, grou id 3
SELECT * FROM opportunities WHERE uuid_to_bin('a2928fe5-aec5-46cb-85d9-7654c89e46a6') = uuid;
select * from activities where opportunity_id = 344 and actual_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00';
select
a.id,
a.type,
a.scheduled_start_time,
a.actual_start_time,
a.created_at,
a.opportunity_id,
a.status
FROM activities a
WHERE opportunity_id = 344
and status IN ('completed', 'received', 'delivered')
and (
(a.actual_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00')
OR (a.created_at between '2024-10-11 00:00:00' and '2024-10-12 00:00:00')
OR (a.scheduled_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00'))
;
SELECT * FROM users WHERE id = 222;
SELECT * FROM crm_profiles WHERE user_id = 222;
select * from crm_layouts where crm_configuration_id = 39;
SELECT * FROM crm_layout_entities WHERE crm_layout_id = 281;
select * from group_deal_risk_types;
select * from opportunities where team_id = 1;
SELECT * FROM opportunities WHERE id = 315;
SELECT * FROM crm_field_data WHERE object_id = 315;
select * from crm_field_data where object_id = 260;
select * from generic_ai_prompts where subject_id = 315;
select * from teams; # 36, 21, 121, [EMAIL]
SELECT * FROM social_accounts WHERE sociable_id = 121 and provider = 'bullhorn';
# [PASSWORD_DOTS]
select * from teams where id = 1;
select * from crm_configurations where id = 39;
select * from users where team_id = 1;
select u.email, cp.* from users u
join crm_profiles cp on u.id = cp.user_id
where u.team_id = 1;
# 1 - 00541000004281rAAA
# 204 - 0052g000003freeAAA
# 429 - 0052g000003qGOiAAM
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 1
and sa.provider = 'salesforce';
select * from activities where type = 'softphone'
and created_at > '2024-12-11 15:24:36' order by id desc;
select * from activity_providers where team_id = 1;
select * from activity_provider_users where activity_provider_id = 328;
select * from opportunities where crm_configuration_id = 39
AND account_id = 178 AND is_closed = false
order by created_at DESC;
select * from contacts where id = 3952;
select * from accounts where id = 178;
# [PASSWORD_DOTS]
select * from teams where id = 36;
select * from crm_configurations where id = 21;
select * from users where team_id = 36;
select u.email, cp.* from users u
join crm_profiles cp on u.id = cp.user_id
where u.team_id = 36;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 36
and sa.provider = 'bullhorn';
select * from social_accounts where id = 348;
UPDATE social_accounts SET
provider_user_token = '21442_6802599_91:41179a58-21e7-4d7c-ad58-56bb666b2f65',
provider_refresh_token = '21442_6802599_91:01c6b335-3f2a-42e4-85ff-8a08fa65fceb',
expires = 1733998131,
state = 'connected'
WHERE id = 348;
# [PASSWORD_DOTS]
select * from teams where id = 31;
select * from crm_configurations where id = 18;
select * from users where team_id = 31; # 257
select u.email, cp.* from users u
join crm_profiles cp on u.id = cp.user_id
where u.team_id = 31;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 31
and sa.provider = 'close';
select * from contacts where crm_configuration_id = 18;
# [PASSWORD_DOTS] NEPTUNE [PASSWORD_DOTS]
select * from teams;
select * from users where id IN (1030, 1035, 1052);
select * from crm_configurations;
select * from users where team_id = 65; # 257
select * from team_settings where team_id = 65; # 257
select * from invitations where team_id = 65; # 257
select * from users where email = '[EMAIL]'; # 257
select u.email, cp.* from users u
join crm_profiles cp on u.id = cp.user_id
where u.team_id = 65;
select * from crm_configurations where id = 53;
select * from accounts where crm_configuration_id = 53 order by id desc;
select * from leads where crm_configuration_id = 53 order by id desc;
select * from contacts where crm_configuration_id = 53 order by id desc;
select * from opportunities where crm_configuration_id = 53 order by id desc;
select * from crm_profiles where crm_configuration_id = 53 order by id desc;
select * from crm_fields where crm_configuration_id = 53 order by id desc;
select * from crm_field_values where crm_field_id = 3341 order by id desc;
select * from crm_layouts where crm_configuration_id = 53 order by id desc;
select * from stages where crm_configuration_id = 53 order by id desc;
select * from crm_profiles where crm_configuration_id = 13;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 65
and sa.provider = 'integration-app';
select * from contacts where crm_configuration_id = 13;
select * from social_accounts where sociable_id = 283;
SELECT * FROM opportunities WHERE crm_provider_id = '006O400000E9bzeIAB';
select * from activity_providers where team_id = 65;
SELECT * FROM activities WHERE crm_configuration_id IN (51, 52, 53);
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 65
;
# [PASSWORD_DOTS] STAGING [PASSWORD_DOTS]
SELECT * FROM teams;
SELECT * FROM teams WHERE id = 88;
SELECT * FROM teams WHERE id = 89;
select * from team_settings where team_id = 89;
SELECT * FROM users WHERE team_id = 89;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 89;
select * from users;
SELECT * FROM social_accounts WHERE sociable_id = 1761;
SELECT * FROM crm_configurations WHERE id = 70;
select * from accounts where crm_configuration_id = 70 order by id desc;
select * from leads where crm_configuration_id = 70 order by id desc;
select * from contacts where crm_configuration_id = 70 order by id desc;
select * from opportunities where crm_configuration_id = 70 order by id desc;
select * from crm_profiles where crm_configuration_id = 70 order by id desc;
select * from crm_fields where crm_configuration_id = 70 order by id desc;
select * from crm_field_values where crm_field_id = 3536 order by id desc;
select * from crm_layouts where crm_configuration_id = 70 order by id desc;
select * from stages where crm_configuration_id = 70 order by id desc;
select * from business_processes where crm_configuration_id = 70 order by id desc;
select * from business_process_stages where business_process_id = 34;
select * from contacts where id = 10468;
select * from crm_layouts where crm_configuration_id = 70;
SELECT * FROM crm_layout_entities WHERE crm_layout_id = 388;
SELECT * FROM crm_fields WHERE id IN (3533,3534,3535);
select * from activities where crm_configuration_id = 70
and (account_id IS NOT NULL or lead_id IS NOT NULL or contact_id IS NOT NULL or opportunity_id IS NOT NULL) order by id desc;
SELECT * FROM activities WHERE uuid_to_bin('2e10b60f-8a61-41c5-a3d4-28835353dc65') = uuid;
SELECT * FROM activities where crm_configuration_id = 69 ;
SELECT * FROM users WHERE email LIKE '%[EMAIL]%';
SELECT * FROM activities WHERE uuid_to_bin('5a150c93-40fc-42ec-b3bd-c1d328e09f6e') = uuid;
SELECT * FROM opportunities WHERE id = 385;
select * from participants p
join activities a on p.activity_id = a.id
where a.crm_configuration_id = 70
and (p.lead_id IS NOT NULL or p.contact_id IS NOT NULL);
SELECT * FROM participants WHERE id = 1013638;
select * from teams where id = 90;
select * from users where team_id = 90;
select * from social_accounts where social_accounts.sociable_id IN (1960,1760);
SELECT * FROM crm_profiles WHERE crm_configuration_id = 71;
select * from invitations where team_id = 90;
select * from crm_configurations where id = 71;
select * from accounts where crm_configuration_id = 71 order by id desc;
select * from leads where crm_configuration_id = 71 order by id desc;
select * from contacts where crm_configuration_id = 71 order by id desc;
select * from opportunities where crm_configuration_id = 71 order by id desc;
select * from crm_profiles where crm_configuration_id = 71 order by id desc;
select * from crm_fields where crm_configuration_id = 71 order by id desc;
select * from crm_field_values where crm_field_id = 3341 order by id desc;
select * from crm_layouts where crm_configuration_id = 71 order by id desc;
select * from stages where crm_configuration_id = 71 order by id desc;
select * from users order by secondary_email desc;
select u.id, u.email, u.status, sa.id, sa.provider_user_id from social_accounts sa
join users u on sa.sociable_id = u.id
where sa.provider = 'google' and u.email LIKE 'aneliya%';
select * from failed_jobs order by id desc;
select * from users where email = '[EMAIL]' or secondary_email = '[EMAIL]';
select * from teams;
SELECT * FROM crm_profiles WHERE crm_configuration_id = 39;
SELECT * FROM crm_fields WHERE crm_configuration_id = 39 and object_type = 'task';
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 1
and sa.provider = 'salesforce';
# [PASSWORD_DOTS]
SELECT * FROM activities WHERE uuid_to_bin('c38b3895-fd0f-4b1f-9fb2-c170dba137c6') = uuid;
SELECT * FROM crm_configurations WHERE id = 70;
select * from teams where id = 1;
select * from groups where team_id = 1;
select * from users where team_id = 1;
select o.id, o.name,o.close_date, u.id, u.name, u.group_id, r.id, r.display_name, g.name, g.scope from opportunities o
join users u on o.user_id = u.id
join groups g on u.group_id = g.id
join role_user ru on u.id = ru.user_id
join roles r on ru.role_id = r.id
where o.crm_configuration_id = 39 and close_date > '2024-01-01 00:00:00';
select * from role_user where user_id = 143;
select * from roles;
select * from role_user;
select * from groups where id = 9;
select * from scope_groups where group_id = 9;
# [PASSWORD_DOTS]
select * from teams where id = 36;
select * from crm_configurations;
SELECT * FROM social_accounts WHERE sociable_id = 121;
[URL_WITH_CREDENTIALS] this will add filter, however if we need to control feature by FF we need conditional logic
public const array TYPES = [
['id' => 'exec_summary', 'name' => 'Exec Summary'],
['id' => 'coaching_profiles', 'name' => 'Coaching Profiles'],
['id' => 'product_feedback', 'name' => 'Product Feedback'],
['id' => self::TYPE_LOSS_ANALYSIS, 'name' => 'Loss Analysis'],
// ['id' => 'questions', 'name' => 'Questions'],
// ['id' => 'statistical_quant', 'name' => 'Statistical Quantitative'],
];
public const array ALL_TYPES = [
...self::TYPES,
['id' => self::TYPE_ASK_JIMINNY, 'name' => 'Ask Jiminny'],
];
public const string FREQUENCY_DAILY = 'daily';
public const string FREQUENCY_WEEKLY = 'weekly';
public const string FREQUENCY_MONTHLY = 'monthly';
public const string FREQUENCY_QUARTERLY = 'quarterly';
public const string FREQUENCY_ONE_OFF = 'one_off';
/**
* Frequencies for standard (non-Ask Jiminny) reports.
*/
public const array FREQUENCIES = [
['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],
['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],
['id' => self::FREQUENCY_QUARTERLY, 'name' => 'Quarterly'],
['id' => self::FREQUENCY_ONE_OFF, 'name' => 'One-off'],
];
/**
* Frequencies for Ask Jiminny reports.
*/
public const array ASK_JIMINNY_FREQUENCIES = [
['id' => self::FREQUENCY_DAILY, 'name' => 'Daily'],
['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],
['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],
];
public const string MEDIA_TYPE_PDF = 'pdf';
public const string MEDIA_TYPE_PODCAST = 'podcast';
public const array MEDIA_TYPES = [self::MEDIA_TYPE_PDF, self::MEDIA_TYPE_PODCAST];
public const array MEDIA_TYPE_OBJECT_PDF = ['id' => self::MEDIA_TYPE_PDF, 'name' => 'PDF'];
public const array MEDIA_TYPE_OBJECT_PODCAST = ['id' => self::MEDIA_TYPE_PODCAST, 'name' => 'Podcast'];
public const array MEDIA_TYPE_OBJECTS = [self::MEDIA_TYPE_OBJECT_PDF, self::MEDIA_TYPE_OBJECT_PODCAST];
public const array CALL_TYPE_CONFERENCE = ['id' => 'conference', 'name' => 'Conference'];
public const array CALL_TYPE_DIALER = ['id' => 'dialer', 'name' => 'Dialer'];
public const int SENT_REPORT_AT_HOURS = 5;
public const string PDF_KEY = 'pdf';
public const string AUDIO_KEY = 'audio';
private const array ALL_FREQUENCIES = [
['id' => self::FREQUENCY_DAILY, 'name' => 'Daily'],
['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],
['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],
['id' => self::FREQUENCY_QUARTERLY, 'name' => 'Quarterly'],
['id' => self::FREQUENCY_ONE_OFF, 'name' => 'One-off'],
];
private const string S3_DIR = 'reports';
private const array FILE_EXTENSIONS_VARIANTS = ['html', 'MD', 'pdf'];
private const array FILE_PODCAST_EXTENSIONS_VARIANTS = ['json', 'mp3', 'ssml'];
public function __construct(
private readonly TeamRepository $teamRepository,
private readonly GroupRepository $groupRepository,
private readonly UserRepository $userRepository,
private readonly StageRepository $stageRepository,
private readonly DealStagesService $dealStagesService,
private readonly RecipientsService $recipientsService,
private readonly AutomatedReportsRepository $automatedReportsRepository,
private readonly Webhook $webhookService,
private readonly BusDispatcher $dispatcher,
private readonly ActivityTypeService $activityTypeService,
private readonly PlaybookCategoryRepository $playbookCategoryRepository,
private readonly AskAnythingPromptService $askAnythingPromptService,
private readonly SearchRepository $activitySearchRepository,
private readonly AskAnythingRepository $askAnythingRepository,
) {
}
public static function getTypes(): array
{
$types = self::TYPES;
return array_map(static function ($type) {
return $type['id'];
}, $types);
}
public static function getCallTypes(): array
{
return array_map(static function ($callType) {
return $callType['id'];
}, [self::CALL_TYPE_CONFERENCE, self::CALL_TYPE_DIALER]);
}
public static function getFrequencies(): array
{
return array_map(static function ($frequency) {
return $frequency['id'];
}, self::FREQUENCIES);
}
// front-facing structure
public function getReportEnabledFieldData(bool $value = false): array
{
return [
'id' => 'report_enabled',
'label' => '',
'inputType' => InputTypeEnum::TOGGLE,
'value' => $value,
];
}
// Organizations = Teams
public function getOrganizationFieldData(?string $value = null, bool $shortVersion = false): array
{
$options = $this->getTeams();
if ($shortVersion) {
return [
'id' => 'organization',
'label' => 'Organization',
'options' => $options,
];
}
return [
'id' => 'organization',
'label' => 'Organization',
'inputType' => InputTypeEnum::DROPDOWN,
'required' => true,
'placeholder' => 'Select',
'options' => $options,
'value' => $value,
'dependencies' => [
'teams',
'deal_stage_at_call',
'current_deal_stage',
'recipients',
ActivityTypeService::PLAYBOOK_CATEGORIES_KEY,
],
'dependsOn' => [],
];
}
// Teams = Groups
public function getTeamFieldData(array $options = [], array $value = [], bool $shortVersion = false): array
{
if ($shortVersion) {
return [
'id' => 'teams',
'label' => 'Team',
'options' => $options,
];
}
return [
'id' => 'teams',
'label' => 'Team',
'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,
'required' => false,
'placeholder' => 'Select',
'options' => $options,
'value' => $value, // value should be an array of objects {id, name}
'dependencies' => [ActivityTypeService::PLAYBOOK_CATEGORIES_KEY],
'dependsOn' => [],
];
}
public function getReportTypeFieldData(?string $value = null, bool $shortVersion = false, ?Team $team = null): array
{
$types = [];
if ($team instanceof Team) {
if ($team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {
$types = self::TYPES;
}
if ($team->hasFeature(FeatureEnum::ASK_JIMINNY_REPORTS)) {
$types[] = ['id' => self::TYPE_ASK_JIMINNY, 'name' => 'Ask Jiminny'];
}
} else {
$types = self::TYPES;
}
if ($shortVersion) {
return [
'id' => 'report_type',
'label' => 'Report Type',
'options' => $types,
];
}
return [
'id' => 'report_type',
'label' => 'Report Type',
'inputType' => InputTypeEnum::DROPDOWN,
'required' => true,
'placeholder' => 'Select',
'options' => $types,
'value' => $value,
'dependencies' => [],
'dependsOn' => [],
];
}
public function getFrequencyFieldData(?string $value = null): array
{
return [
'id' => 'frequency',
'label' => 'Frequency',
'inputType' => InputTypeEnum::DROPDOWN,
'required' => true,
'placeholder' => 'Select',
'options' => self::FREQUENCIES,
'value' => $value,
'dependencies' => ['period'],
'dependsOn' => [],
];
}
public function getPeriodFieldData(?string $valueStartDate = null, ?string $valueEndDate = null): array
{
return [
'id' => 'period',
'label' => 'Select one-off period',
'inputType' => InputTypeEnum::DATE_RANGE,
'required' => true,
'placeholder' => 'Select',
'value' => ['startDate' => $valueStartDate, 'endDate' => $valueEndDate],
'queryParams' => [
'startDate' => 'start_date_period',
'endDate' => 'end_date_period',
],
'dependencies' => [],
'dependsOn' => ['frequency'],
];
}
public function getActivityTypesFieldData(?Team $team = null, array $value = [], array $teamsFilter = []): array
{
return $this->activityTypeService->getActivityTypeFieldData(team: $team, value: $value, groupIds: $teamsFilter);
}
public function getDealStageAtCallFieldData(?Team $team = null, array $value = []): array
{
return $this->dealStagesService->getDealStageAtCallFieldData(team: $team, value: $value);
}
public function getCurrentDealStageFieldData(?Team $team = null, array $value = []): array
{
return $this->dealStagesService->getCurrentDealStageFieldData(team: $team, value: $value);
}
public function getDealValueFieldData(?int $valueMin = null, ?int $valueMax = null): array
{
return [
'id' => 'deal_value',
'label' => 'Deal Value',
'inputType' => InputTypeEnum::INTEGER_RANGE,
'required' => false,
'value' => ['min' => $valueMin, 'max' => $valueMax],
'queryParams' => [
'min' => 'min_deal_value',
'max' => 'max_deal_value',
],
'dependencies' => [],
'dependsOn' => [],
];
}
public function getCallTypeFieldData(bool $conferenceOn = false, bool $dialerOn = false): array
{
$value = [];
$conferenceOn && $value[] = self::CALL_TYPE_CONFERENCE;
$dialerOn && $value[] = self::CALL_TYPE_DIALER;
return [
'id' => 'call_type',
'label' => 'Call Type',
'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,
'required' => true,
'options' => [
self::CALL_TYPE_CONFERENCE,
self::CALL_TYPE_DIALER,
],
'value' => $value,
'dependencies' => [],
'dependsOn' => [],
];
}
public function getMediaTypeFieldData(?AutomatedReport $report = null): array
{
$value = [];
if ($report) {
$value = $this->transformMediaTypes($report);
}
return [
'id' => 'media_types',
'label' => 'Export as',
'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,
'required' => true,
'options' => self::MEDIA_TYPE_OBJECTS,
'value' => $value,
'dependencies' => [],
'dependsOn' => [],
];
}
public function getCallDurationFieldData(?int $valueMin = null, ?int $valueMax = null): array
{
return [
'id' => 'call_duration',
'label' => 'Call Duration',
'inputType' => InputTypeEnum::INTEGER_RANGE,
'required' => false,
'value' => ['min' => $valueMin, 'max' => $valueMax],
'queryParams' => [
'min' => 'min_call_duration',
'max' => 'max_call_duration',
],
'dependencies' => [],
'dependsOn' => [],
];
}
public function getRecipientsFieldData(?Team $team = null, array $value = []): array
{
return $this->recipientsService->getRecipientsFieldData(team: $team, value: $value);
}
public function getJiminnyRecipientsFieldData(array $value = []): array
{
return $this->recipientsService->getJiminnyRecipientsFieldData($value);
}
public function getAdditionalPromptInputFieldData(?string $value = null): array
{
return [
'id' => 'additional_prompt_input',
'label' => 'Special requirements',
'inputType' => InputTypeEnum::TEXTAREA,
'required' => false,
'placeholder' => 'What should be the focus of the report?',
'value' => $value,
'dependencies' => [],
'dependsOn' => [],
];
}
public function getCustomReportNameFieldData(?string $value = null): array
{
return [
'id' => 'custom_name',
'label' => 'Custom report name',
'inputType' => InputTypeEnum::TEXT,
'required' => false,
'placeholder' => 'Enter custom name',
'value' => $value,
'dependencies' => [],
'dependsOn' => [],
];
}
// data providers
public function getTeams(): array
{
$teams = $this->teamRepository->getTeamsForKiosk(status: Team::STATUS_ACTIVE);
$teamData = [];
foreach ($teams as $team) {
if (! $team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {
continue;
}
$teamData[] = $this->transformTeam($team);
}
return $teamData;
}
public function getTeamGroups(string $teamUuid): array
{
$data = [];
$team = $this->getTeam($teamUuid);
if ($team !== null) {
$groups = $team->groups()->get();
foreach ($groups as $group) {
$data[] = [
'id' => $group->getUuid(),
'name' => $group->getName(),
];
}
}
return $data;
}
public function getTeamsGroupsOptions(array $filterTeamUuids = []): array
{
$data = [];
$teams = $this->getTeams();
foreach ($teams as $team) {
if (! empty($filterTeamUuids) && ! in_array($team['id'], $filterTeamUuids, true)) {
continue;
}
$data[] = [
'label' => $team['name'],
'groups' => $this->getTeamGroups($team['id']),
];
}
return $data;
}
public function getTeam(string $teamUuid): ?Team
{
return $this->teamRepository->idOrUuid($teamUuid);
}
public function getTeamById(int $teamId): ?Team
{
return $this->teamRepository->find($teamId);
}
public function getGroupsUuids(AutomatedReport $report): array
{
$uuids = [];
$reportGroups = $report->getGroups();
foreach ($reportGroups as $groupId) {
if ($group = $this->groupRepository->find($groupId)) {
$uuids[] = $group->getUuid();
}
}
return $uuids;
}
public function getPlaybookCategoriesUuids(AutomatedReport $report): array
{
$uuids = [];
$playbookCategories = $report->getPlaybookCategories();
foreach ($playbookCategories as $id) {
if ($category = $this->playbookCategoryRepository->find($id)) {
$uuids[] = $category->getUuid();
}
}
return $uuids;
}
public function getDealAtCallStagesUuids(AutomatedReport $report): array
{
$uuids = [];
$reportStages = $report->getDealAtCallStages();
foreach ($reportStages as $id) {
if ($stage = $this->stageRepository->find($id)) {
$uuids[] = $stage->getUuid();
}
}
return $uuids;
}
public function getCurrentDealStagesUuids(AutomatedReport $report): array
{
$uuids = [];
$reportStages = $report->getCurrentDealStages();
foreach ($reportStages as $id) {
if ($stage = $this->stageRepository->find($id)) {
$uuids[] = $stage->getUuid();
}
}
return $uuids;
}
public function getUsersUuids(AutomatedReport $report): array
{
return $this->extractUserUuids($report->getRecipients());
}
public function getJiminnyUsersUuids(AutomatedReport $report): array
{
return $this->extractUserUuids($report->getJiminnyRecipients());
}
/**
* @param array<string, mixed> $recipients
*/
private function extractUserUuids(array $recipients): array
{
$userIds = $recipients['users'] ?? [];
return collect($userIds)
->map(fn ($id) => $this->userRepository->find((int) $id))
->filter()
->map(fn (UserContract $user) => $user->getUuid())
->values()
->all();
}
// get mail data
public function getRecipientUsers(AutomatedReport $report): array
{
return $this->buildRecipientUsers($report->getRecipients());
}
private function getJiminnyRecipientUsers(AutomatedReport $report): array
{
return $this->buildRecipientUsers($report->getJiminnyRecipients());
}
/**
* @param array<string, mixed> $recipients
*/
private function buildRecipientUsers(array $recipients): array
{
$userIds = $recipients['users'] ?? [];
return collect($userIds)
->map(fn ($id) => $this->userRepository->find((int) $id))
->filter()
->map(fn (UserContract $user) => [
'email' => $user->getEmailAddress(),
'name' => $user->getName(),
'timezone' => $user->getTimezone()->getName(),
])
->values()
->all();
}
public function getValidRecipientUsers(AutomatedReport $report, bool $includeJiminny = false): array
{
if ($report->isAskJiminnyReport()) {
$recipients = $this->resolveAskJiminnyRecipients($report);
} else {
$recipients = $this->getRecipientUsers($report);
if ($includeJiminny) {
$recipients = array_merge($recipients, $this->getJiminnyRecipientUsers($report));
}
}
$emails = [];
return array_values(array_filter(
$recipients,
static function ($recipient) use (&$emails) {
if (empty($recipient['email']) || in_array($recipient['email'], $emails, true)) {
return false;
}
$emails[] = $recipient['email'];
return true;
}
));
}
private function resolveAskJiminnyRecipients(AutomatedReport $report): array
{
$recipients = [];
$creator = $report->getCreator();
if ($creator !== null) {
$recipients[] = [
'email' => $creator->getEmailAddress(),
'name' => $creator->getName(),
'timezone' => $creator->getTimezone()->getName(),
];
}
return array_merge(
$recipients,
$this->buildRecipientUsers($report->getRecipients()),
$this->getGroupRecipientUsers($report),
);
}
private function getGroupRecipientUsers(AutomatedReport $report): array
{
$users = [];
foreach ($report->getGroups() as $groupId) {
$group = $this->groupRepository->find($groupId);
if ($group === null) {
continue;
}
foreach ($group->getMembers() as $member) {
$users[] = [
'email' => $member->getEmailAddress(),
'name' => $member->getName(),
'timezone' => $member->getTimezone()->getName(),
];
}
}
return $users;
}
public function getReportTypeName(AutomatedReportResult $report): string
{
$type = $report->getReport()->getType();
$getType = $this->transformReportType($type);
return $getType['name'];
}
public function getReportPeriodName(AutomatedReportResult $report): string
{
$from = $report->getFromDate();
$to = $report->getToDate();
$frequency = $report->getReport()->getFrequency();
if ($from === null || $to === null) {
if (! $report->getReport()->isAskJiminnyReport()) {
$invalidPeriod = $from === null ? 'from' : 'to';
throw new ApplicationException('Report period is invalid: ' . $invalidPeriod);
}
$period = $this->calculateFromAndToDatePeriod($frequency);
$from = $period['fromDate'];
$to = $period['toDate'];
}
return $this->formatReportPeriodName($frequency, $from, $to);
}
private function formatReportPeriodName(string $frequency, Carbon $from, Carbon $to): string
{
$fromYear = $from->format('Y');
$toYear = $to->format('Y');
$differentYears = $fromYear !== $toYear;
switch ($frequency) {
case self::FREQUENCY_DAILY:
return $from->format('j M Y');
case self::FREQUENCY_QUARTERLY:
// 'Jan-Mar 2025' or 'Nov 2024-Jan 2025' if years differ
$startMonth = $from->format('M');
$endMonth = $to->copy()->subMonth();
$endMonthName = $endMonth->format('M');
$endMonthYear = $endMonth->format('Y');
if ($differentYears) {
return "{$startMonth} {$fromYear} - {$endMonthName} {$endMonthYear}";
}
return "{$startMonth} - {$endMonthName} {$toYear}";
case self::FREQUENCY_MONTHLY:
// 'May 2025' - monthly reports are always within the same year
return $from->format('M Y');
case self::FREQUENCY_WEEKLY:
// '4 - 8 Aug 2025', '27 Oct - 3 Nov 2025', or '28 Dec 2024 - 3 Jan 2025' if years differ
$startDay = $from->format('j');
$endDay = $to->format('j');
$startMonth = $from->format('M');
$endMonth = $to->format('M');
if ($differentYears) {
return "{$startDay} {$startMonth} {$fromYear} - {$endDay} {$endMonth} {$toYear}";
}
if ($startMonth !== $endMonth) {
return "{$startDay} {$startMonth} - {$endDay} {$endMonth} {$toYear}";
}
return "{$startDay} - {$endDay} {$endMonth} {$toYear}";
case self::FREQUENCY_ONE_OFF:
// '2 May-31 May 2025' or '15 Dec 2024-15 Jan 2025' if years differ
$startDay = $from->format('j');
$startMonth = $from->format('M');
$endDay = $to->format('j');
$endMonth = $to->format('M');
// If same month and year, use a format like '2-31 May 2025'
if ($startMonth === $endMonth && ! $differentYears) {
return "{$startDay} - {$endDay} {$startMonth} {$toYear}";
}
// If different years, include both years
if ($differentYears) {
return "{$startDay} {$startMonth} {$fromYear} - {$endDay} {$endMonth} {$toYear}";
}
// Same year but different months
return "{$startDay} {$startMonth} - {$endDay} {$endMonth} {$toYear}";
default:
// Default format for unknown frequencies
return $from->format('j M Y') . ' - ' . $to->format('j M Y');
}
}
public function getReportTeamsName(AutomatedReportResult $report): string
{
$groups = $report->getGroups();
if (empty($groups)) {
return 'All';
}
// Get group names from repository
$groupNames = [];
foreach ($groups as $groupId) {
$group = $this->groupRepository->find($groupId);
if ($group) {
$groupNames[] = $group->getName();
}
}
if (count($groupNames) === 1) {
// Single team format
$teamsName = $groupNames[0];
} else {
// Multiple teams format
$teamsName = implode(', ', $groupNames);
}
return $teamsName;
}
public function getReportFileName(AutomatedReportResult $report): string
...
|
[{"role":"AXButton","text" [{"role":"AXButton","text":"Project: faVsco.js, menu","depth":5,"help_text":"~/jiminny/app","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"#11894 on JY-18909-automated-reports-ask-jiminny, menu","depth":5,"help_text":"Pull request #11894 exists for current branch JY-18909-automated-reports-ask-jiminny","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Start Listening for PHP Debug Connections","depth":5,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"AutomatedReportsCommandTest","depth":6,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Run 'AutomatedReportsCommandTest'","depth":6,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Debug 'AutomatedReportsCommandTest'","depth":6,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"More Actions","depth":6,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JetBrains AI","depth":5,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Search Everywhere","depth":5,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"IDE and Project Settings","depth":5,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Execute","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Explain Plan","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Browse Query History","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"View Parameters","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Open Query Execution Settings…","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"In-Editor Results","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Tx: Auto","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Cancel Running Statements","depth":4,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Playground","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"jiminny","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.088194445,"height":0.027777778},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"16","depth":4,"role_description":"text"},{"role":"AXStaticText","text":"13","depth":4,"role_description":"text"},{"role":"AXStaticText","text":"13","depth":4,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"SELECT * FROM teams WHERE id = 1;\n\nselect * from crm_layouts where crm_configuration_id = 39;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 283;\nSELECT * FROM crm_fields WHERE id = 2234;\nSELECT * FROM crm_field_values WHERE crm_field_id = 2234;\n\nselect * from crm_profiles where user_id = 143;\n\nselect * from record_types where crm_configuration_id = 39; # 0121K000001MHElQAO,0121K000001MHEqQAO\nselect * from business_processes where crm_configuration_id = 39;\n# 01941000000H669AAC, 01941000000H66JAAS\n\nselect * from record_type_field_values\n where record_type_id IN (24);\n\nselect * from crm_field_values where id IN (2730);\n\nselect * from crm_configurations where id = 39;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 1\nand sa.provider = 'salesforce'; #1035\n\n\nselect * from users where team_id = 1; # 222 group 3\nSELECT * FROM activities WHERE user_id = 222 order by id desc;\nselect * from sidekick_settings where team_id = 1;\nselect * from teams where id = 1;\nselect * from team_features where team_id = 1;\n\nselect * from activities where crm_configuration_id = 2\nand provider = 'ms-teams' and id = 608765;\n\nSELECT * FROM activities WHERE crm_configuration_id = 2 and crm_provider_id = '59523413338';\n\nselect * from sidekick_settings where team_id = 2;\n\nSELECT * FROM activities WHERE id = 608660;\nselect * from activity_summary_logs where activity_id = 608660;\nselect * from ai_prompts where transcription_id = 11214;\n\n# ********************************************************************************************************\nSELECT * FROM activities WHERE uuid_to_bin('ed78a437-2804-450e-ab2f-56ab1c641346') = uuid;\n# id: 608818, crm: 59628809737\nSELECT * FROM activities WHERE uuid_to_bin('36b06e55-afdd-4782-8dee-c624cd0af191') = uuid;\n# id: 608821, crm: 59632069252\nSELECT ce.start_time, ce.end_time, a.id, a.uuid, crm_provider_id, calendar_event_id, title,\nplaybook_category_id, user_id, lead_id, contact_id, account_id, opportunity_id,\nscheduled_start_time, scheduled_end_time, actual_start_time, actual_end_time, a.created_at\nFROM activities a\njoin calendar_events ce on a.calendar_event_id = ce.id\nWHERE a.id IN (608818, 608821);\n\nselect * from users where team_id = 1;\nselect * from team_settings where team_id = 1;\nselect * from crm_profiles where crm_configuration_id = 39 order by user_id;\n\nselect * from team_features where team_id = 1;\n\nselect * from users where team_id = 2;\n\nSELECT * FROM activities WHERE uuid_to_bin('ec7647e9-5225-458b-b475-f31aa2769204') = uuid; # 612639\n# Preslava N. Ivanova, grou id 3\n\nSELECT * FROM opportunities WHERE uuid_to_bin('a2928fe5-aec5-46cb-85d9-7654c89e46a6') = uuid;\n\nselect * from activities where opportunity_id = 344 and actual_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00';\n\nselect\n a.id,\n a.type,\n a.scheduled_start_time,\n a.actual_start_time,\n a.created_at,\n a.opportunity_id,\n a.status\nFROM activities a\nWHERE opportunity_id = 344\nand status IN ('completed', 'received', 'delivered')\nand (\n (a.actual_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00')\nOR (a.created_at between '2024-10-11 00:00:00' and '2024-10-12 00:00:00')\nOR (a.scheduled_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00'))\n;\n\nSELECT * FROM users WHERE id = 222;\n\nSELECT * FROM crm_profiles WHERE user_id = 222;\nselect * from crm_layouts where crm_configuration_id = 39;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 281;\n\nselect * from group_deal_risk_types;\n\nselect * from opportunities where team_id = 1;\n\nSELECT * FROM opportunities WHERE id = 315;\nSELECT * FROM crm_field_data WHERE object_id = 315;\nselect * from crm_field_data where object_id = 260;\n\nselect * from generic_ai_prompts where subject_id = 315;\n\nselect * from teams; # 36, 21, 121, james.graham@bullhorn.jiminny.com\nSELECT * FROM social_accounts WHERE sociable_id = 121 and provider = 'bullhorn';\n\n# ************************************************************************************\nselect * from teams where id = 1;\nselect * from crm_configurations where id = 39;\nselect * from users where team_id = 1;\nselect u.email, cp.* from users u\njoin crm_profiles cp on u.id = cp.user_id\nwhere u.team_id = 1;\n# 1 - 00541000004281rAAA\n# 204 - 0052g000003freeAAA\n# 429 - 0052g000003qGOiAAM\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 1\nand sa.provider = 'salesforce';\n\nselect * from activities where type = 'softphone'\nand created_at > '2024-12-11 15:24:36' order by id desc;\n\nselect * from activity_providers where team_id = 1;\nselect * from activity_provider_users where activity_provider_id = 328;\n\nselect * from opportunities where crm_configuration_id = 39\nAND account_id = 178 AND is_closed = false\norder by created_at DESC;\n\nselect * from contacts where id = 3952;\nselect * from accounts where id = 178;\n\n# ************************************************************************************\nselect * from teams where id = 36;\nselect * from crm_configurations where id = 21;\nselect * from users where team_id = 36;\nselect u.email, cp.* from users u\njoin crm_profiles cp on u.id = cp.user_id\nwhere u.team_id = 36;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 36\nand sa.provider = 'bullhorn';\n\nselect * from social_accounts where id = 348;\nUPDATE social_accounts SET\nprovider_user_token = '21442_6802599_91:41179a58-21e7-4d7c-ad58-56bb666b2f65',\nprovider_refresh_token = '21442_6802599_91:01c6b335-3f2a-42e4-85ff-8a08fa65fceb',\nexpires = 1733998131,\nstate = 'connected'\nWHERE id = 348;\n\n# ************************************************************************************\nselect * from teams where id = 31;\nselect * from crm_configurations where id = 18;\n\nselect * from users where team_id = 31; # 257\nselect u.email, cp.* from users u\njoin crm_profiles cp on u.id = cp.user_id\nwhere u.team_id = 31;\n\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 31\nand sa.provider = 'close';\n\nselect * from contacts where crm_configuration_id = 18;\n\n# ********************** NEPTUNE **************************************************************\nselect * from teams;\nselect * from users where id IN (1030, 1035, 1052);\nselect * from crm_configurations;\n\nselect * from users where team_id = 65; # 257\nselect * from team_settings where team_id = 65; # 257\nselect * from invitations where team_id = 65; # 257\nselect * from users where email = 'integration-account@jiminny.com'; # 257\nselect u.email, cp.* from users u\njoin crm_profiles cp on u.id = cp.user_id\nwhere u.team_id = 65;\n\nselect * from crm_configurations where id = 53;\nselect * from accounts where crm_configuration_id = 53 order by id desc;\nselect * from leads where crm_configuration_id = 53 order by id desc;\nselect * from contacts where crm_configuration_id = 53 order by id desc;\nselect * from opportunities where crm_configuration_id = 53 order by id desc;\nselect * from crm_profiles where crm_configuration_id = 53 order by id desc;\nselect * from crm_fields where crm_configuration_id = 53 order by id desc;\nselect * from crm_field_values where crm_field_id = 3341 order by id desc;\nselect * from crm_layouts where crm_configuration_id = 53 order by id desc;\nselect * from stages where crm_configuration_id = 53 order by id desc;\n\n\nselect * from crm_profiles where crm_configuration_id = 13;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 65\nand sa.provider = 'integration-app';\n\nselect * from contacts where crm_configuration_id = 13;\n\nselect * from social_accounts where sociable_id = 283;\n\nSELECT * FROM opportunities WHERE crm_provider_id = '006O400000E9bzeIAB';\n\nselect * from activity_providers where team_id = 65;\nSELECT * FROM activities WHERE crm_configuration_id IN (51, 52, 53);\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 65\n;\n\n# ***************************** STAGING ********************************************\nSELECT * FROM teams;\nSELECT * FROM teams WHERE id = 88;\nSELECT * FROM teams WHERE id = 89;\nselect * from team_settings where team_id = 89;\nSELECT * FROM users WHERE team_id = 89;\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 89;\n\nselect * from users;\nSELECT * FROM social_accounts WHERE sociable_id = 1761;\nSELECT * FROM crm_configurations WHERE id = 70;\nselect * from accounts where crm_configuration_id = 70 order by id desc;\nselect * from leads where crm_configuration_id = 70 order by id desc;\nselect * from contacts where crm_configuration_id = 70 order by id desc;\nselect * from opportunities where crm_configuration_id = 70 order by id desc;\nselect * from crm_profiles where crm_configuration_id = 70 order by id desc;\nselect * from crm_fields where crm_configuration_id = 70 order by id desc;\nselect * from crm_field_values where crm_field_id = 3536 order by id desc;\nselect * from crm_layouts where crm_configuration_id = 70 order by id desc;\nselect * from stages where crm_configuration_id = 70 order by id desc;\nselect * from business_processes where crm_configuration_id = 70 order by id desc;\nselect * from business_process_stages where business_process_id = 34;\n\nselect * from contacts where id = 10468;\n\nselect * from crm_layouts where crm_configuration_id = 70;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 388;\nSELECT * FROM crm_fields WHERE id IN (3533,3534,3535);\n\nselect * from activities where crm_configuration_id = 70\nand (account_id IS NOT NULL or lead_id IS NOT NULL or contact_id IS NOT NULL or opportunity_id IS NOT NULL) order by id desc;\n\nSELECT * FROM activities WHERE uuid_to_bin('2e10b60f-8a61-41c5-a3d4-28835353dc65') = uuid;\nSELECT * FROM activities where crm_configuration_id = 69 ;\n\nSELECT * FROM users WHERE email LIKE '%jiminny_web_sa2@jiminny.com%';\nSELECT * FROM activities WHERE uuid_to_bin('5a150c93-40fc-42ec-b3bd-c1d328e09f6e') = uuid;\nSELECT * FROM opportunities WHERE id = 385;\n\nselect * from participants p\njoin activities a on p.activity_id = a.id\nwhere a.crm_configuration_id = 70\nand (p.lead_id IS NOT NULL or p.contact_id IS NOT NULL);\nSELECT * FROM participants WHERE id = 1013638;\n\nselect * from teams where id = 90;\nselect * from users where team_id = 90;\nselect * from social_accounts where social_accounts.sociable_id IN (1960,1760);\nSELECT * FROM crm_profiles WHERE crm_configuration_id = 71;\nselect * from invitations where team_id = 90;\n\nselect * from crm_configurations where id = 71;\nselect * from accounts where crm_configuration_id = 71 order by id desc;\nselect * from leads where crm_configuration_id = 71 order by id desc;\nselect * from contacts where crm_configuration_id = 71 order by id desc;\nselect * from opportunities where crm_configuration_id = 71 order by id desc;\nselect * from crm_profiles where crm_configuration_id = 71 order by id desc;\nselect * from crm_fields where crm_configuration_id = 71 order by id desc;\nselect * from crm_field_values where crm_field_id = 3341 order by id desc;\nselect * from crm_layouts where crm_configuration_id = 71 order by id desc;\nselect * from stages where crm_configuration_id = 71 order by id desc;\n\nselect * from users order by secondary_email desc;\nselect u.id, u.email, u.status, sa.id, sa.provider_user_id from social_accounts sa\n join users u on sa.sociable_id = u.id\nwhere sa.provider = 'google' and u.email LIKE 'aneliya%';\n\nselect * from failed_jobs order by id desc;\n\nselect * from users where email = 'ben.allwright@learningpeople.co.uk' or secondary_email = 'ben.allwright@learningpeople.co.uk';\n\nselect * from teams;\nSELECT * FROM crm_profiles WHERE crm_configuration_id = 39;\nSELECT * FROM crm_fields WHERE crm_configuration_id = 39 and object_type = 'task';\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 1\nand sa.provider = 'salesforce';\n\n# ************************************************************************************\nSELECT * FROM activities WHERE uuid_to_bin('c38b3895-fd0f-4b1f-9fb2-c170dba137c6') = uuid;\nSELECT * FROM crm_configurations WHERE id = 70;\n\nselect * from teams where id = 1;\nselect * from groups where team_id = 1;\nselect * from users where team_id = 1;\n\nselect o.id, o.name,o.close_date, u.id, u.name, u.group_id, r.id, r.display_name, g.name, g.scope from opportunities o\njoin users u on o.user_id = u.id\njoin groups g on u.group_id = g.id\njoin role_user ru on u.id = ru.user_id\njoin roles r on ru.role_id = r.id\nwhere o.crm_configuration_id = 39 and close_date > '2024-01-01 00:00:00';\n\nselect * from role_user where user_id = 143;\nselect * from roles;\n\nselect * from role_user;\nselect * from groups where id = 9;\nselect * from scope_groups where group_id = 9;\n\n# ************************************************************************************\nselect * from teams where id = 36;\nselect * from crm_configurations;\nSELECT * FROM social_accounts WHERE sociable_id = 121;\n\nhttps://crmsandbox.zoho.com/crm/jiminnyw4/tab/Leads/4776201000005049105\nhttps://crmsandbox.zoho.com/crm/\n\nhttps://crm.zoho.com/crm/org3469620/tab/Leads/230045000229559080\n https://crm.zoho.com/crm/\n org3469620\n\nSELECT * FROM activities WHERE uuid_to_bin('03382d20-c8bc-48e7-a3d4-90b52fa5ceab') = uuid;\n\nselect * from users where email LIKE \"%mobile_automation_%\";\nselect * from social_accounts where sociable_id IN (2228);\nselect * from crm_profiles where user_id IN (2222,2223,2226,2227);\n\nselect * from teams order by id desc;\nSELECT * FROM users WHERE id = 2229;\nSELECT * FROM crm_profiles WHERE user_id = 2229;\nselect * from opportunities where crm_configuration_id = 88;\nselect * from crm_fields where crm_configuration_id = 88;\nselect * from crm_profiles where crm_configuration_id = 88;\n\nSELECT * FROM teams WHERE id = 1;\n\nSELECT * FROM users WHERE id = 143;\nSELECT * FROM users WHERE uuid_to_bin('fde193d3-06a2-4e1a-8895-62b94039215d') = uuid;\nSELECT * FROM teams WHERE uuid_to_bin('73385071-a756-42ae-9c73-8b53f2309467') = uuid;\n\nhttps://app.staging.jiminny.com/ondemand?\n min_duration=1\n &\n only_recorded=1\n &\n user_id%5B%5D=641f1acb-16b8-42d1-8726-df52979dad0e\n &\n sequence_number=2\n\n select * from users where team_id = 1 and email like '%stoyan%'\n\nselect * from coaching_feedbacks;\n\nselect * from teams;\nSELECT * FROM users WHERE team_id = 36;\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 19\nand sa.provider = 'pipedrive';\n\nselect * from users where id = 143;\n\nSELECT * FROM users WHERE uuid_to_bin('73180eeb-33de-4065-977d-ccbe0e6c94fc') = uuid;\nSELECT * FROM teams WHERE uuid_to_bin('73180eeb-33de-4065-977d-ccbe0e6c94fc') = uuid;\nSELECT * FROM activity_shares WHERE uuid_to_bin('73180eeb-33de-4065-977d-ccbe0e6c94fc') = uuid;\n\nselect * from users where team_id = 2;\nselect * from activities where crm_configuration_id = 39\nand activities.scheduled_start_time BETWEEN '2025-04-09 00:00:00' AND '2025-04-09 23:59:59'\nAND user_id = 143\norder by id desc;\n\n# ************************************************************************************\nselect * from teams where id = 142; # 2312, 126\nselect * from team_settings;\nselect * from users where team_id = 142; # 21642\nSELECT * FROM social_accounts WHERE sociable_id = 21642;\nSELECT * FROM crm_profiles cp join users u ON u.id = cp.user_id WHERE team_id = 142;\nselect * from crm_profiles where id IN (93);\nselect * from invitations;\nselect * from team_features where team_id = 1;\n\nSELECT * FROM crm_configurations WHERE id = 126;\nselect * from accounts where crm_configuration_id = 126 order by id desc;\nselect * from leads where crm_configuration_id = 126 order by id desc;\nselect * from contacts where crm_configuration_id = 126 order by id desc;\nselect * from opportunities where crm_configuration_id = 126 order by id desc;\nselect * from crm_profiles where crm_configuration_id = 126 order by id desc;\nselect * from crm_fields where crm_configuration_id = 126 # 11060\n# and type IN ('picklist', 'status')\n# and object_type = 'task'\norder by id desc;\n# 5731,5732,5733\nselect DISTINCT crm_field_id from crm_field_values where crm_field_id IN (11151,12239,12215,12185,12175,12165,12144,12137,12127,12109,12107,12105,12103,12092,12037,12005,12003,11987,11969,11958,11951,11942,11931,11924,11921,11917,11915,11901,11893,11883,11872,11870,11868,11866,11839,11833,11821,11793,11780,11777,11769,11757,11737,11735,11656,11645,11638,11629,11618,11611,11602,11591,11584,11581,11558,11544,11543,11534,11532,11529,11527,11503,11497,11493,11488,11470,11468,11457,11455,11397,11387,11372,11363,11348,11323,11318,11309,11301,11300,11292,11290,11286,11284,11256,11252,11242,11237,11233,11219,11176,11160) order by id desc;\nselect * from crm_layouts where crm_configuration_id = 126 order by id desc;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id in (300,299,298);\nselect * from stages where crm_configuration_id = 126 order by id desc;\nselect * from business_processes where crm_configuration_id = 126 order by id desc;\nselect * from business_process_stages where business_process_id IN (76,75,74,73);\nselect * from playbooks where team_id = 142;\nselect * from playbook_layouts where playbook_id IN (108);\nSELECT * FROM playbook_categories WHERE playbook_id IN (108);\n\nselect * from teams where id = 130;\nSELECT * FROM social_accounts WHERE sociable_id = 2291;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 2\nand sa.provider = 'hubspot';\n\nSELECT * FROM activities\n WHERE crm_configuration_id = 110;\n\nselect * from teams;\nselect * from crm_configurations;\n\nSELECT * FROM activities WHERE id = 628773;\nSELECT * FROM crm_profiles WHERE user_id = 1460;\nSELECT * FROM social_accounts WHERE sociable_id = 2291;\n\nselect * from teams;\nselect ru.*, pr.*, p.* from users u join role_user ru on ru.user_id = u.id\njoin permission_role pr on pr.role_id = ru.role_id\n join permissions p on p.id = pr.permission_id\nwhere team_id = 495 and p.name IN ('dial');\n\nselect * from teams where id = 145;\nselect * from crm_configurations where id = 129;\nselect * from social_accounts where sociable_id = 2317;\nSELECT * FROM activities WHERE uuid_to_bin('8dbab184-a333-4268-ad57-fb41f8d53a9a') = uuid;\n\nselect * from teams where id = 1;\nSELECT * FROM crm_layouts WHERE crm_configuration_id = 39;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 280;\nSELECT * FROM crm_layout_entities WHERE id = 5507;\nSELECT * FROM crm_fields WHERE crm_configuration_id = 39 and object_type IN ('event');\n\nselect * from teams;\nselect * from activities where crm_configuration_id = 14;\n\nSELECT * FROM social_accounts where provider = 'copper';\n\nselect * from activities where id = 628467;\nselect * from participants where activity_id = 628467;\n\nSELECT * FROM contacts WHERE id = 3969;\nSELECT * FROM accounts WHERE id = 177;\n\nSELECT * FROM activities WHERE uuid_to_bin('4eb54c77-cfa3-2bd4-84a7-9ed46a21c988') = uuid;\n\n# ********************* BH\nselect * from teams where id = 36;\nSELECT * FROM crm_configurations WHERE id = 21;\nselect * from activities where crm_configuration_id = 21 and id = 607901;\nselect * from activities where crm_configuration_id = 21;\n\nselect * roles;\nselect * from permissions;\nselect * from permission_role where permission_id = 226;\n\nselect * from migrations order by id desc;\n\n# mercury\n# neptune\n# earth\n\nselect * from teams;\nselect * from teams where id = 19;\nselect * from teams where id = 27;\nselect * from users where team_id = 27;\nSELECT * FROM crm_configurations WHERE id = 42;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 19\nand sa.provider = 'pipedrive';\n\nselect * from activities where id = 631461;\nSELECT * FROM crm_field_values WHERE crm_field_id = 180;\n\nselect * from teams where id = 2;\nSELECT * FROM social_accounts WHERE sociable_id = 89;\n\nSELECT * FROM activities WHERE uuid_to_bin('ba0c029a-bc14-4e17-8603-64174acebcbb') = uuid; # 634273\nselect * from activity_summary_logs where activity_id = 634273;\n\nselect * from sidekick_settings where team_id = 2;\n\nselect * from teams; # 2, 2\nSELECT * FROM crm_configurations WHERE team_id = 2; # 2\nselect * from team_features where team_id = 2;\nselect * from features;\nSELECT * FROM opportunities WHERE crm_configuration_id = 2 and crm_provider_id = '51317301383';\nSELECT * FROM opportunities WHERE crm_configuration_id = 2 order by id desc;\n\nselect * from automated_reports order by id desc;\nselect * from automated_report_results order by id desc;\nselect * from users where team_id = 1 and id IN (7160, 3248);\nselect * from migrations order by id desc;\n\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 1 and sa.provider = 'salesforce';\n\nselect * from teams where id = 1;\nselect * from groups g JOIN playbooks p on g.playbook_id = p.id where g.team_id = 1;\nselect * from groups where id = 565;\nselect * from playbooks where team_id = 1;\nselect * from playbooks where id = 175;\nselect * from playbook_categories where playbook_id = 175;\nselect * from users where team_id = 1;\nselect * from users where id = 7160;\nselect * from crm_profiles where user_id = 7160;\nselect * from features;\nselect\n *\n# id, uuid, type, provider, playbook_category_id, user_id, lead_id, contact_id, account_id, opportunity_id, stage_id,\n# crm_configuration_id, crm_provider_id, transcription_id, status\nfrom activities where crm_configuration_id = 1 and type = 'conference'\n# and crm_provider_id IS NOT NULL\nand provider != 'uploader' and actual_start_time IS NOT NULL\nORDER by id desc;\nselect * from activities where id = 54747783; # 00UO400000pCzojMAC\n\nselect p.id, p.activity_type, pc.id, pc.name\nFROM playbooks p\njoin playbook_categories pc on p.id = pc.playbook_id\nwhere p.team_id = 1 and p.activity_type = 'event';\n\nSELECT * FROM crm_fields WHERE crm_configuration_id = 1 and object_type = 'event';\nSELECT * FROM crm_field_values WHERE crm_field_id = 4;\n\nselect * from crm_layouts cl join playbook_layouts pl on cl.id = pl.layout_id\nwhere crm_configuration_id = 1 and pl.playbook_id = 175;\n\nselect * from teams;\nSELECT r.* FROM automated_reports r\njoin teams t on r.team_id = t.id\nWHERE r.frequency = 'daily'\n and r.status = 1\nAND t.status = 'active'\nAND (r.expires_at >= now() OR r.expires_at IS NULL);\n\nselect * from automated_report_results where report_id IN (18, 33);\n\nselect * from activity_searches where id = 10932;\nselect * from activity_search_filters where activity_search_id = 10932;\nselect * from automated_reports;\nselect * from automated_report_results where report_id IN (34, 35);","depth":4,"value":"SELECT * FROM teams WHERE id = 1;\n\nselect * from crm_layouts where crm_configuration_id = 39;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 283;\nSELECT * FROM crm_fields WHERE id = 2234;\nSELECT * FROM crm_field_values WHERE crm_field_id = 2234;\n\nselect * from crm_profiles where user_id = 143;\n\nselect * from record_types where crm_configuration_id = 39; # 0121K000001MHElQAO,0121K000001MHEqQAO\nselect * from business_processes where crm_configuration_id = 39;\n# 01941000000H669AAC, 01941000000H66JAAS\n\nselect * from record_type_field_values\n where record_type_id IN (24);\n\nselect * from crm_field_values where id IN (2730);\n\nselect * from crm_configurations where id = 39;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 1\nand sa.provider = 'salesforce'; #1035\n\n\nselect * from users where team_id = 1; # 222 group 3\nSELECT * FROM activities WHERE user_id = 222 order by id desc;\nselect * from sidekick_settings where team_id = 1;\nselect * from teams where id = 1;\nselect * from team_features where team_id = 1;\n\nselect * from activities where crm_configuration_id = 2\nand provider = 'ms-teams' and id = 608765;\n\nSELECT * FROM activities WHERE crm_configuration_id = 2 and crm_provider_id = '59523413338';\n\nselect * from sidekick_settings where team_id = 2;\n\nSELECT * FROM activities WHERE id = 608660;\nselect * from activity_summary_logs where activity_id = 608660;\nselect * from ai_prompts where transcription_id = 11214;\n\n# ********************************************************************************************************\nSELECT * FROM activities WHERE uuid_to_bin('ed78a437-2804-450e-ab2f-56ab1c641346') = uuid;\n# id: 608818, crm: 59628809737\nSELECT * FROM activities WHERE uuid_to_bin('36b06e55-afdd-4782-8dee-c624cd0af191') = uuid;\n# id: 608821, crm: 59632069252\nSELECT ce.start_time, ce.end_time, a.id, a.uuid, crm_provider_id, calendar_event_id, title,\nplaybook_category_id, user_id, lead_id, contact_id, account_id, opportunity_id,\nscheduled_start_time, scheduled_end_time, actual_start_time, actual_end_time, a.created_at\nFROM activities a\njoin calendar_events ce on a.calendar_event_id = ce.id\nWHERE a.id IN (608818, 608821);\n\nselect * from users where team_id = 1;\nselect * from team_settings where team_id = 1;\nselect * from crm_profiles where crm_configuration_id = 39 order by user_id;\n\nselect * from team_features where team_id = 1;\n\nselect * from users where team_id = 2;\n\nSELECT * FROM activities WHERE uuid_to_bin('ec7647e9-5225-458b-b475-f31aa2769204') = uuid; # 612639\n# Preslava N. Ivanova, grou id 3\n\nSELECT * FROM opportunities WHERE uuid_to_bin('a2928fe5-aec5-46cb-85d9-7654c89e46a6') = uuid;\n\nselect * from activities where opportunity_id = 344 and actual_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00';\n\nselect\n a.id,\n a.type,\n a.scheduled_start_time,\n a.actual_start_time,\n a.created_at,\n a.opportunity_id,\n a.status\nFROM activities a\nWHERE opportunity_id = 344\nand status IN ('completed', 'received', 'delivered')\nand (\n (a.actual_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00')\nOR (a.created_at between '2024-10-11 00:00:00' and '2024-10-12 00:00:00')\nOR (a.scheduled_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00'))\n;\n\nSELECT * FROM users WHERE id = 222;\n\nSELECT * FROM crm_profiles WHERE user_id = 222;\nselect * from crm_layouts where crm_configuration_id = 39;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 281;\n\nselect * from group_deal_risk_types;\n\nselect * from opportunities where team_id = 1;\n\nSELECT * FROM opportunities WHERE id = 315;\nSELECT * FROM crm_field_data WHERE object_id = 315;\nselect * from crm_field_data where object_id = 260;\n\nselect * from generic_ai_prompts where subject_id = 315;\n\nselect * from teams; # 36, 21, 121, james.graham@bullhorn.jiminny.com\nSELECT * FROM social_accounts WHERE sociable_id = 121 and provider = 'bullhorn';\n\n# ************************************************************************************\nselect * from teams where id = 1;\nselect * from crm_configurations where id = 39;\nselect * from users where team_id = 1;\nselect u.email, cp.* from users u\njoin crm_profiles cp on u.id = cp.user_id\nwhere u.team_id = 1;\n# 1 - 00541000004281rAAA\n# 204 - 0052g000003freeAAA\n# 429 - 0052g000003qGOiAAM\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 1\nand sa.provider = 'salesforce';\n\nselect * from activities where type = 'softphone'\nand created_at > '2024-12-11 15:24:36' order by id desc;\n\nselect * from activity_providers where team_id = 1;\nselect * from activity_provider_users where activity_provider_id = 328;\n\nselect * from opportunities where crm_configuration_id = 39\nAND account_id = 178 AND is_closed = false\norder by created_at DESC;\n\nselect * from contacts where id = 3952;\nselect * from accounts where id = 178;\n\n# ************************************************************************************\nselect * from teams where id = 36;\nselect * from crm_configurations where id = 21;\nselect * from users where team_id = 36;\nselect u.email, cp.* from users u\njoin crm_profiles cp on u.id = cp.user_id\nwhere u.team_id = 36;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 36\nand sa.provider = 'bullhorn';\n\nselect * from social_accounts where id = 348;\nUPDATE social_accounts SET\nprovider_user_token = '21442_6802599_91:41179a58-21e7-4d7c-ad58-56bb666b2f65',\nprovider_refresh_token = '21442_6802599_91:01c6b335-3f2a-42e4-85ff-8a08fa65fceb',\nexpires = 1733998131,\nstate = 'connected'\nWHERE id = 348;\n\n# ************************************************************************************\nselect * from teams where id = 31;\nselect * from crm_configurations where id = 18;\n\nselect * from users where team_id = 31; # 257\nselect u.email, cp.* from users u\njoin crm_profiles cp on u.id = cp.user_id\nwhere u.team_id = 31;\n\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 31\nand sa.provider = 'close';\n\nselect * from contacts where crm_configuration_id = 18;\n\n# ********************** NEPTUNE **************************************************************\nselect * from teams;\nselect * from users where id IN (1030, 1035, 1052);\nselect * from crm_configurations;\n\nselect * from users where team_id = 65; # 257\nselect * from team_settings where team_id = 65; # 257\nselect * from invitations where team_id = 65; # 257\nselect * from users where email = 'integration-account@jiminny.com'; # 257\nselect u.email, cp.* from users u\njoin crm_profiles cp on u.id = cp.user_id\nwhere u.team_id = 65;\n\nselect * from crm_configurations where id = 53;\nselect * from accounts where crm_configuration_id = 53 order by id desc;\nselect * from leads where crm_configuration_id = 53 order by id desc;\nselect * from contacts where crm_configuration_id = 53 order by id desc;\nselect * from opportunities where crm_configuration_id = 53 order by id desc;\nselect * from crm_profiles where crm_configuration_id = 53 order by id desc;\nselect * from crm_fields where crm_configuration_id = 53 order by id desc;\nselect * from crm_field_values where crm_field_id = 3341 order by id desc;\nselect * from crm_layouts where crm_configuration_id = 53 order by id desc;\nselect * from stages where crm_configuration_id = 53 order by id desc;\n\n\nselect * from crm_profiles where crm_configuration_id = 13;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 65\nand sa.provider = 'integration-app';\n\nselect * from contacts where crm_configuration_id = 13;\n\nselect * from social_accounts where sociable_id = 283;\n\nSELECT * FROM opportunities WHERE crm_provider_id = '006O400000E9bzeIAB';\n\nselect * from activity_providers where team_id = 65;\nSELECT * FROM activities WHERE crm_configuration_id IN (51, 52, 53);\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 65\n;\n\n# ***************************** STAGING ********************************************\nSELECT * FROM teams;\nSELECT * FROM teams WHERE id = 88;\nSELECT * FROM teams WHERE id = 89;\nselect * from team_settings where team_id = 89;\nSELECT * FROM users WHERE team_id = 89;\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 89;\n\nselect * from users;\nSELECT * FROM social_accounts WHERE sociable_id = 1761;\nSELECT * FROM crm_configurations WHERE id = 70;\nselect * from accounts where crm_configuration_id = 70 order by id desc;\nselect * from leads where crm_configuration_id = 70 order by id desc;\nselect * from contacts where crm_configuration_id = 70 order by id desc;\nselect * from opportunities where crm_configuration_id = 70 order by id desc;\nselect * from crm_profiles where crm_configuration_id = 70 order by id desc;\nselect * from crm_fields where crm_configuration_id = 70 order by id desc;\nselect * from crm_field_values where crm_field_id = 3536 order by id desc;\nselect * from crm_layouts where crm_configuration_id = 70 order by id desc;\nselect * from stages where crm_configuration_id = 70 order by id desc;\nselect * from business_processes where crm_configuration_id = 70 order by id desc;\nselect * from business_process_stages where business_process_id = 34;\n\nselect * from contacts where id = 10468;\n\nselect * from crm_layouts where crm_configuration_id = 70;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 388;\nSELECT * FROM crm_fields WHERE id IN (3533,3534,3535);\n\nselect * from activities where crm_configuration_id = 70\nand (account_id IS NOT NULL or lead_id IS NOT NULL or contact_id IS NOT NULL or opportunity_id IS NOT NULL) order by id desc;\n\nSELECT * FROM activities WHERE uuid_to_bin('2e10b60f-8a61-41c5-a3d4-28835353dc65') = uuid;\nSELECT * FROM activities where crm_configuration_id = 69 ;\n\nSELECT * FROM users WHERE email LIKE '%jiminny_web_sa2@jiminny.com%';\nSELECT * FROM activities WHERE uuid_to_bin('5a150c93-40fc-42ec-b3bd-c1d328e09f6e') = uuid;\nSELECT * FROM opportunities WHERE id = 385;\n\nselect * from participants p\njoin activities a on p.activity_id = a.id\nwhere a.crm_configuration_id = 70\nand (p.lead_id IS NOT NULL or p.contact_id IS NOT NULL);\nSELECT * FROM participants WHERE id = 1013638;\n\nselect * from teams where id = 90;\nselect * from users where team_id = 90;\nselect * from social_accounts where social_accounts.sociable_id IN (1960,1760);\nSELECT * FROM crm_profiles WHERE crm_configuration_id = 71;\nselect * from invitations where team_id = 90;\n\nselect * from crm_configurations where id = 71;\nselect * from accounts where crm_configuration_id = 71 order by id desc;\nselect * from leads where crm_configuration_id = 71 order by id desc;\nselect * from contacts where crm_configuration_id = 71 order by id desc;\nselect * from opportunities where crm_configuration_id = 71 order by id desc;\nselect * from crm_profiles where crm_configuration_id = 71 order by id desc;\nselect * from crm_fields where crm_configuration_id = 71 order by id desc;\nselect * from crm_field_values where crm_field_id = 3341 order by id desc;\nselect * from crm_layouts where crm_configuration_id = 71 order by id desc;\nselect * from stages where crm_configuration_id = 71 order by id desc;\n\nselect * from users order by secondary_email desc;\nselect u.id, u.email, u.status, sa.id, sa.provider_user_id from social_accounts sa\n join users u on sa.sociable_id = u.id\nwhere sa.provider = 'google' and u.email LIKE 'aneliya%';\n\nselect * from failed_jobs order by id desc;\n\nselect * from users where email = 'ben.allwright@learningpeople.co.uk' or secondary_email = 'ben.allwright@learningpeople.co.uk';\n\nselect * from teams;\nSELECT * FROM crm_profiles WHERE crm_configuration_id = 39;\nSELECT * FROM crm_fields WHERE crm_configuration_id = 39 and object_type = 'task';\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 1\nand sa.provider = 'salesforce';\n\n# ************************************************************************************\nSELECT * FROM activities WHERE uuid_to_bin('c38b3895-fd0f-4b1f-9fb2-c170dba137c6') = uuid;\nSELECT * FROM crm_configurations WHERE id = 70;\n\nselect * from teams where id = 1;\nselect * from groups where team_id = 1;\nselect * from users where team_id = 1;\n\nselect o.id, o.name,o.close_date, u.id, u.name, u.group_id, r.id, r.display_name, g.name, g.scope from opportunities o\njoin users u on o.user_id = u.id\njoin groups g on u.group_id = g.id\njoin role_user ru on u.id = ru.user_id\njoin roles r on ru.role_id = r.id\nwhere o.crm_configuration_id = 39 and close_date > '2024-01-01 00:00:00';\n\nselect * from role_user where user_id = 143;\nselect * from roles;\n\nselect * from role_user;\nselect * from groups where id = 9;\nselect * from scope_groups where group_id = 9;\n\n# ************************************************************************************\nselect * from teams where id = 36;\nselect * from crm_configurations;\nSELECT * FROM social_accounts WHERE sociable_id = 121;\n\nhttps://crmsandbox.zoho.com/crm/jiminnyw4/tab/Leads/4776201000005049105\nhttps://crmsandbox.zoho.com/crm/\n\nhttps://crm.zoho.com/crm/org3469620/tab/Leads/230045000229559080\n https://crm.zoho.com/crm/\n org3469620\n\nSELECT * FROM activities WHERE uuid_to_bin('03382d20-c8bc-48e7-a3d4-90b52fa5ceab') = uuid;\n\nselect * from users where email LIKE \"%mobile_automation_%\";\nselect * from social_accounts where sociable_id IN (2228);\nselect * from crm_profiles where user_id IN (2222,2223,2226,2227);\n\nselect * from teams order by id desc;\nSELECT * FROM users WHERE id = 2229;\nSELECT * FROM crm_profiles WHERE user_id = 2229;\nselect * from opportunities where crm_configuration_id = 88;\nselect * from crm_fields where crm_configuration_id = 88;\nselect * from crm_profiles where crm_configuration_id = 88;\n\nSELECT * FROM teams WHERE id = 1;\n\nSELECT * FROM users WHERE id = 143;\nSELECT * FROM users WHERE uuid_to_bin('fde193d3-06a2-4e1a-8895-62b94039215d') = uuid;\nSELECT * FROM teams WHERE uuid_to_bin('73385071-a756-42ae-9c73-8b53f2309467') = uuid;\n\nhttps://app.staging.jiminny.com/ondemand?\n min_duration=1\n &\n only_recorded=1\n &\n user_id%5B%5D=641f1acb-16b8-42d1-8726-df52979dad0e\n &\n sequence_number=2\n\n select * from users where team_id = 1 and email like '%stoyan%'\n\nselect * from coaching_feedbacks;\n\nselect * from teams;\nSELECT * FROM users WHERE team_id = 36;\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 19\nand sa.provider = 'pipedrive';\n\nselect * from users where id = 143;\n\nSELECT * FROM users WHERE uuid_to_bin('73180eeb-33de-4065-977d-ccbe0e6c94fc') = uuid;\nSELECT * FROM teams WHERE uuid_to_bin('73180eeb-33de-4065-977d-ccbe0e6c94fc') = uuid;\nSELECT * FROM activity_shares WHERE uuid_to_bin('73180eeb-33de-4065-977d-ccbe0e6c94fc') = uuid;\n\nselect * from users where team_id = 2;\nselect * from activities where crm_configuration_id = 39\nand activities.scheduled_start_time BETWEEN '2025-04-09 00:00:00' AND '2025-04-09 23:59:59'\nAND user_id = 143\norder by id desc;\n\n# ************************************************************************************\nselect * from teams where id = 142; # 2312, 126\nselect * from team_settings;\nselect * from users where team_id = 142; # 21642\nSELECT * FROM social_accounts WHERE sociable_id = 21642;\nSELECT * FROM crm_profiles cp join users u ON u.id = cp.user_id WHERE team_id = 142;\nselect * from crm_profiles where id IN (93);\nselect * from invitations;\nselect * from team_features where team_id = 1;\n\nSELECT * FROM crm_configurations WHERE id = 126;\nselect * from accounts where crm_configuration_id = 126 order by id desc;\nselect * from leads where crm_configuration_id = 126 order by id desc;\nselect * from contacts where crm_configuration_id = 126 order by id desc;\nselect * from opportunities where crm_configuration_id = 126 order by id desc;\nselect * from crm_profiles where crm_configuration_id = 126 order by id desc;\nselect * from crm_fields where crm_configuration_id = 126 # 11060\n# and type IN ('picklist', 'status')\n# and object_type = 'task'\norder by id desc;\n# 5731,5732,5733\nselect DISTINCT crm_field_id from crm_field_values where crm_field_id IN (11151,12239,12215,12185,12175,12165,12144,12137,12127,12109,12107,12105,12103,12092,12037,12005,12003,11987,11969,11958,11951,11942,11931,11924,11921,11917,11915,11901,11893,11883,11872,11870,11868,11866,11839,11833,11821,11793,11780,11777,11769,11757,11737,11735,11656,11645,11638,11629,11618,11611,11602,11591,11584,11581,11558,11544,11543,11534,11532,11529,11527,11503,11497,11493,11488,11470,11468,11457,11455,11397,11387,11372,11363,11348,11323,11318,11309,11301,11300,11292,11290,11286,11284,11256,11252,11242,11237,11233,11219,11176,11160) order by id desc;\nselect * from crm_layouts where crm_configuration_id = 126 order by id desc;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id in (300,299,298);\nselect * from stages where crm_configuration_id = 126 order by id desc;\nselect * from business_processes where crm_configuration_id = 126 order by id desc;\nselect * from business_process_stages where business_process_id IN (76,75,74,73);\nselect * from playbooks where team_id = 142;\nselect * from playbook_layouts where playbook_id IN (108);\nSELECT * FROM playbook_categories WHERE playbook_id IN (108);\n\nselect * from teams where id = 130;\nSELECT * FROM social_accounts WHERE sociable_id = 2291;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 2\nand sa.provider = 'hubspot';\n\nSELECT * FROM activities\n WHERE crm_configuration_id = 110;\n\nselect * from teams;\nselect * from crm_configurations;\n\nSELECT * FROM activities WHERE id = 628773;\nSELECT * FROM crm_profiles WHERE user_id = 1460;\nSELECT * FROM social_accounts WHERE sociable_id = 2291;\n\nselect * from teams;\nselect ru.*, pr.*, p.* from users u join role_user ru on ru.user_id = u.id\njoin permission_role pr on pr.role_id = ru.role_id\n join permissions p on p.id = pr.permission_id\nwhere team_id = 495 and p.name IN ('dial');\n\nselect * from teams where id = 145;\nselect * from crm_configurations where id = 129;\nselect * from social_accounts where sociable_id = 2317;\nSELECT * FROM activities WHERE uuid_to_bin('8dbab184-a333-4268-ad57-fb41f8d53a9a') = uuid;\n\nselect * from teams where id = 1;\nSELECT * FROM crm_layouts WHERE crm_configuration_id = 39;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 280;\nSELECT * FROM crm_layout_entities WHERE id = 5507;\nSELECT * FROM crm_fields WHERE crm_configuration_id = 39 and object_type IN ('event');\n\nselect * from teams;\nselect * from activities where crm_configuration_id = 14;\n\nSELECT * FROM social_accounts where provider = 'copper';\n\nselect * from activities where id = 628467;\nselect * from participants where activity_id = 628467;\n\nSELECT * FROM contacts WHERE id = 3969;\nSELECT * FROM accounts WHERE id = 177;\n\nSELECT * FROM activities WHERE uuid_to_bin('4eb54c77-cfa3-2bd4-84a7-9ed46a21c988') = uuid;\n\n# ********************* BH\nselect * from teams where id = 36;\nSELECT * FROM crm_configurations WHERE id = 21;\nselect * from activities where crm_configuration_id = 21 and id = 607901;\nselect * from activities where crm_configuration_id = 21;\n\nselect * roles;\nselect * from permissions;\nselect * from permission_role where permission_id = 226;\n\nselect * from migrations order by id desc;\n\n# mercury\n# neptune\n# earth\n\nselect * from teams;\nselect * from teams where id = 19;\nselect * from teams where id = 27;\nselect * from users where team_id = 27;\nSELECT * FROM crm_configurations WHERE id = 42;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 19\nand sa.provider = 'pipedrive';\n\nselect * from activities where id = 631461;\nSELECT * FROM crm_field_values WHERE crm_field_id = 180;\n\nselect * from teams where id = 2;\nSELECT * FROM social_accounts WHERE sociable_id = 89;\n\nSELECT * FROM activities WHERE uuid_to_bin('ba0c029a-bc14-4e17-8603-64174acebcbb') = uuid; # 634273\nselect * from activity_summary_logs where activity_id = 634273;\n\nselect * from sidekick_settings where team_id = 2;\n\nselect * from teams; # 2, 2\nSELECT * FROM crm_configurations WHERE team_id = 2; # 2\nselect * from team_features where team_id = 2;\nselect * from features;\nSELECT * FROM opportunities WHERE crm_configuration_id = 2 and crm_provider_id = '51317301383';\nSELECT * FROM opportunities WHERE crm_configuration_id = 2 order by id desc;\n\nselect * from automated_reports order by id desc;\nselect * from automated_report_results order by id desc;\nselect * from users where team_id = 1 and id IN (7160, 3248);\nselect * from migrations order by id desc;\n\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 1 and sa.provider = 'salesforce';\n\nselect * from teams where id = 1;\nselect * from groups g JOIN playbooks p on g.playbook_id = p.id where g.team_id = 1;\nselect * from groups where id = 565;\nselect * from playbooks where team_id = 1;\nselect * from playbooks where id = 175;\nselect * from playbook_categories where playbook_id = 175;\nselect * from users where team_id = 1;\nselect * from users where id = 7160;\nselect * from crm_profiles where user_id = 7160;\nselect * from features;\nselect\n *\n# id, uuid, type, provider, playbook_category_id, user_id, lead_id, contact_id, account_id, opportunity_id, stage_id,\n# crm_configuration_id, crm_provider_id, transcription_id, status\nfrom activities where crm_configuration_id = 1 and type = 'conference'\n# and crm_provider_id IS NOT NULL\nand provider != 'uploader' and actual_start_time IS NOT NULL\nORDER by id desc;\nselect * from activities where id = 54747783; # 00UO400000pCzojMAC\n\nselect p.id, p.activity_type, pc.id, pc.name\nFROM playbooks p\njoin playbook_categories pc on p.id = pc.playbook_id\nwhere p.team_id = 1 and p.activity_type = 'event';\n\nSELECT * FROM crm_fields WHERE crm_configuration_id = 1 and object_type = 'event';\nSELECT * FROM crm_field_values WHERE crm_field_id = 4;\n\nselect * from crm_layouts cl join playbook_layouts pl on cl.id = pl.layout_id\nwhere crm_configuration_id = 1 and pl.playbook_id = 175;\n\nselect * from teams;\nSELECT r.* FROM automated_reports r\njoin teams t on r.team_id = t.id\nWHERE r.frequency = 'daily'\n and r.status = 1\nAND t.status = 'active'\nAND (r.expires_at >= now() OR r.expires_at IS NULL);\n\nselect * from automated_report_results where report_id IN (18, 33);\n\nselect * from activity_searches where id = 10932;\nselect * from activity_search_filters where activity_search_id = 10932;\nselect * from automated_reports;\nselect * from automated_report_results where report_id IN (34, 35);","role_description":"text entry area","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.088194445,"height":0.027777778},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"102","depth":4,"role_description":"text"},{"role":"AXStaticText","text":"3","depth":4,"role_description":"text"},{"role":"AXStaticText","text":"34","depth":4,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Services\\Kiosk\\AutomatedReports;\n\nuse Carbon\\CarbonImmutable;\nuse Carbon\\CarbonInterface;\nuse Carbon\\Exceptions\\InvalidFormatException;\nuse DateTime;\nuse DateTimeInterface;\nuse DateTimeZone;\nuse Illuminate\\Contracts\\Bus\\Dispatcher as BusDispatcher;\nuse Illuminate\\Database\\Eloquent\\Builder;\nuse Illuminate\\Support\\Carbon;\nuse Illuminate\\Support\\Collection;\nuse Illuminate\\Support\\Facades\\Log;\nuse Illuminate\\Support\\Facades\\Storage;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinition\\InputTypeEnum;\nuse Jiminny\\Component\\AskAnything\\AskAnythingPromptService;\nuse Jiminny\\Component\\AskAnything\\Dtos\\AskAnythingPromptDto;\nuse Jiminny\\Component\\UrlGenerator\\Webhook;\nuse Jiminny\\Contracts\\Repositories\\PlaybookCategoryRepository;\nuse Jiminny\\Contracts\\Repositories\\TeamRepository;\nuse Jiminny\\Contracts\\Repositories\\UserRepository;\nuse Jiminny\\Exceptions\\ApplicationException;\nuse Jiminny\\Exceptions\\InvalidArgumentException;\nuse Jiminny\\Exceptions\\ModelNotFoundException;\nuse Jiminny\\Jobs\\AutomatedReports\\RequestGenerateReportJob;\nuse Jiminny\\Models\\Activity\\Search;\nuse Jiminny\\Models\\AskAnything\\AskAnythingPrompt;\nuse Jiminny\\Models\\AskAnything\\AskAnythingPromptTarget;\nuse Jiminny\\Models\\AutomatedReport;\nuse Jiminny\\Models\\AutomatedReportResult;\nuse Jiminny\\Models\\Contracts\\UserContract;\nuse Jiminny\\Models\\Feature\\FeatureEnum;\nuse Jiminny\\Models\\Team;\nuse Jiminny\\Models\\User;\nuse Jiminny\\Repositories\\AskAnythingRepository;\nuse Jiminny\\Repositories\\AutomatedReportsRepository;\nuse Jiminny\\Repositories\\GroupRepository;\nuse Jiminny\\Repositories\\SearchRepository;\nuse Jiminny\\Repositories\\StageRepository;\nuse Throwable;\n\nclass AutomatedReportsService\n{\n public const string TYPE_LOSS_ANALYSIS = 'loss_analysis';\n public const string TYPE_ASK_JIMINNY = 'ask_jiminny';\n\n /**\n * Standard report types (used by kiosk for existing automated reports).\n */\n // @TODO this will add filter, however if we need to control feature by FF we need conditional logic\n public const array TYPES = [\n ['id' => 'exec_summary', 'name' => 'Exec Summary'],\n ['id' => 'coaching_profiles', 'name' => 'Coaching Profiles'],\n ['id' => 'product_feedback', 'name' => 'Product Feedback'],\n ['id' => self::TYPE_LOSS_ANALYSIS, 'name' => 'Loss Analysis'],\n// ['id' => 'questions', 'name' => 'Questions'],\n// ['id' => 'statistical_quant', 'name' => 'Statistical Quantitative'],\n ];\n\n public const array ALL_TYPES = [\n ...self::TYPES,\n ['id' => self::TYPE_ASK_JIMINNY, 'name' => 'Ask Jiminny'],\n ];\n\n public const string FREQUENCY_DAILY = 'daily';\n public const string FREQUENCY_WEEKLY = 'weekly';\n public const string FREQUENCY_MONTHLY = 'monthly';\n public const string FREQUENCY_QUARTERLY = 'quarterly';\n public const string FREQUENCY_ONE_OFF = 'one_off';\n\n /**\n * Frequencies for standard (non-Ask Jiminny) reports.\n */\n public const array FREQUENCIES = [\n ['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],\n ['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],\n ['id' => self::FREQUENCY_QUARTERLY, 'name' => 'Quarterly'],\n ['id' => self::FREQUENCY_ONE_OFF, 'name' => 'One-off'],\n ];\n\n /**\n * Frequencies for Ask Jiminny reports.\n */\n public const array ASK_JIMINNY_FREQUENCIES = [\n ['id' => self::FREQUENCY_DAILY, 'name' => 'Daily'],\n ['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],\n ['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],\n ];\n\n public const string MEDIA_TYPE_PDF = 'pdf';\n public const string MEDIA_TYPE_PODCAST = 'podcast';\n public const array MEDIA_TYPES = [self::MEDIA_TYPE_PDF, self::MEDIA_TYPE_PODCAST];\n public const array MEDIA_TYPE_OBJECT_PDF = ['id' => self::MEDIA_TYPE_PDF, 'name' => 'PDF'];\n public const array MEDIA_TYPE_OBJECT_PODCAST = ['id' => self::MEDIA_TYPE_PODCAST, 'name' => 'Podcast'];\n public const array MEDIA_TYPE_OBJECTS = [self::MEDIA_TYPE_OBJECT_PDF, self::MEDIA_TYPE_OBJECT_PODCAST];\n\n public const array CALL_TYPE_CONFERENCE = ['id' => 'conference', 'name' => 'Conference'];\n public const array CALL_TYPE_DIALER = ['id' => 'dialer', 'name' => 'Dialer'];\n public const int SENT_REPORT_AT_HOURS = 5;\n public const string PDF_KEY = 'pdf';\n public const string AUDIO_KEY = 'audio';\n\n private const array ALL_FREQUENCIES = [\n ['id' => self::FREQUENCY_DAILY, 'name' => 'Daily'],\n ['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],\n ['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],\n ['id' => self::FREQUENCY_QUARTERLY, 'name' => 'Quarterly'],\n ['id' => self::FREQUENCY_ONE_OFF, 'name' => 'One-off'],\n ];\n private const string S3_DIR = 'reports';\n private const array FILE_EXTENSIONS_VARIANTS = ['html', 'MD', 'pdf'];\n private const array FILE_PODCAST_EXTENSIONS_VARIANTS = ['json', 'mp3', 'ssml'];\n\n public function __construct(\n private readonly TeamRepository $teamRepository,\n private readonly GroupRepository $groupRepository,\n private readonly UserRepository $userRepository,\n private readonly StageRepository $stageRepository,\n private readonly DealStagesService $dealStagesService,\n private readonly RecipientsService $recipientsService,\n private readonly AutomatedReportsRepository $automatedReportsRepository,\n private readonly Webhook $webhookService,\n private readonly BusDispatcher $dispatcher,\n private readonly ActivityTypeService $activityTypeService,\n private readonly PlaybookCategoryRepository $playbookCategoryRepository,\n private readonly AskAnythingPromptService $askAnythingPromptService,\n private readonly SearchRepository $activitySearchRepository,\n private readonly AskAnythingRepository $askAnythingRepository,\n ) {\n }\n\n public static function getTypes(): array\n {\n $types = self::TYPES;\n\n return array_map(static function ($type) {\n return $type['id'];\n }, $types);\n }\n\n public static function getCallTypes(): array\n {\n return array_map(static function ($callType) {\n return $callType['id'];\n }, [self::CALL_TYPE_CONFERENCE, self::CALL_TYPE_DIALER]);\n }\n\n public static function getFrequencies(): array\n {\n return array_map(static function ($frequency) {\n return $frequency['id'];\n }, self::FREQUENCIES);\n }\n\n // front-facing structure\n public function getReportEnabledFieldData(bool $value = false): array\n {\n return [\n 'id' => 'report_enabled',\n 'label' => '',\n 'inputType' => InputTypeEnum::TOGGLE,\n 'value' => $value,\n ];\n }\n\n // Organizations = Teams\n public function getOrganizationFieldData(?string $value = null, bool $shortVersion = false): array\n {\n $options = $this->getTeams();\n\n if ($shortVersion) {\n return [\n 'id' => 'organization',\n 'label' => 'Organization',\n 'options' => $options,\n ];\n }\n\n return [\n 'id' => 'organization',\n 'label' => 'Organization',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => $options,\n 'value' => $value,\n 'dependencies' => [\n 'teams',\n 'deal_stage_at_call',\n 'current_deal_stage',\n 'recipients',\n ActivityTypeService::PLAYBOOK_CATEGORIES_KEY,\n ],\n 'dependsOn' => [],\n ];\n }\n\n // Teams = Groups\n public function getTeamFieldData(array $options = [], array $value = [], bool $shortVersion = false): array\n {\n if ($shortVersion) {\n return [\n 'id' => 'teams',\n 'label' => 'Team',\n 'options' => $options,\n ];\n }\n\n return [\n 'id' => 'teams',\n 'label' => 'Team',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'required' => false,\n 'placeholder' => 'Select',\n 'options' => $options,\n 'value' => $value, // value should be an array of objects {id, name}\n 'dependencies' => [ActivityTypeService::PLAYBOOK_CATEGORIES_KEY],\n 'dependsOn' => [],\n ];\n }\n\n public function getReportTypeFieldData(?string $value = null, bool $shortVersion = false, ?Team $team = null): array\n {\n $types = [];\n if ($team instanceof Team) {\n if ($team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {\n $types = self::TYPES;\n }\n if ($team->hasFeature(FeatureEnum::ASK_JIMINNY_REPORTS)) {\n $types[] = ['id' => self::TYPE_ASK_JIMINNY, 'name' => 'Ask Jiminny'];\n }\n } else {\n $types = self::TYPES;\n }\n\n if ($shortVersion) {\n return [\n 'id' => 'report_type',\n 'label' => 'Report Type',\n 'options' => $types,\n ];\n }\n\n return [\n 'id' => 'report_type',\n 'label' => 'Report Type',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => $types,\n 'value' => $value,\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getFrequencyFieldData(?string $value = null): array\n {\n return [\n 'id' => 'frequency',\n 'label' => 'Frequency',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => self::FREQUENCIES,\n 'value' => $value,\n 'dependencies' => ['period'],\n 'dependsOn' => [],\n ];\n }\n\n public function getPeriodFieldData(?string $valueStartDate = null, ?string $valueEndDate = null): array\n {\n return [\n 'id' => 'period',\n 'label' => 'Select one-off period',\n 'inputType' => InputTypeEnum::DATE_RANGE,\n 'required' => true,\n 'placeholder' => 'Select',\n 'value' => ['startDate' => $valueStartDate, 'endDate' => $valueEndDate],\n 'queryParams' => [\n 'startDate' => 'start_date_period',\n 'endDate' => 'end_date_period',\n ],\n 'dependencies' => [],\n 'dependsOn' => ['frequency'],\n ];\n }\n\n public function getActivityTypesFieldData(?Team $team = null, array $value = [], array $teamsFilter = []): array\n {\n return $this->activityTypeService->getActivityTypeFieldData(team: $team, value: $value, groupIds: $teamsFilter);\n }\n\n public function getDealStageAtCallFieldData(?Team $team = null, array $value = []): array\n {\n return $this->dealStagesService->getDealStageAtCallFieldData(team: $team, value: $value);\n }\n\n public function getCurrentDealStageFieldData(?Team $team = null, array $value = []): array\n {\n return $this->dealStagesService->getCurrentDealStageFieldData(team: $team, value: $value);\n }\n\n public function getDealValueFieldData(?int $valueMin = null, ?int $valueMax = null): array\n {\n return [\n 'id' => 'deal_value',\n 'label' => 'Deal Value',\n 'inputType' => InputTypeEnum::INTEGER_RANGE,\n 'required' => false,\n 'value' => ['min' => $valueMin, 'max' => $valueMax],\n 'queryParams' => [\n 'min' => 'min_deal_value',\n 'max' => 'max_deal_value',\n ],\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getCallTypeFieldData(bool $conferenceOn = false, bool $dialerOn = false): array\n {\n $value = [];\n $conferenceOn && $value[] = self::CALL_TYPE_CONFERENCE;\n $dialerOn && $value[] = self::CALL_TYPE_DIALER;\n\n return [\n 'id' => 'call_type',\n 'label' => 'Call Type',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'required' => true,\n 'options' => [\n self::CALL_TYPE_CONFERENCE,\n self::CALL_TYPE_DIALER,\n ],\n 'value' => $value,\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getMediaTypeFieldData(?AutomatedReport $report = null): array\n {\n $value = [];\n\n if ($report) {\n $value = $this->transformMediaTypes($report);\n }\n\n return [\n 'id' => 'media_types',\n 'label' => 'Export as',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'required' => true,\n 'options' => self::MEDIA_TYPE_OBJECTS,\n 'value' => $value,\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getCallDurationFieldData(?int $valueMin = null, ?int $valueMax = null): array\n {\n return [\n 'id' => 'call_duration',\n 'label' => 'Call Duration',\n 'inputType' => InputTypeEnum::INTEGER_RANGE,\n 'required' => false,\n 'value' => ['min' => $valueMin, 'max' => $valueMax],\n 'queryParams' => [\n 'min' => 'min_call_duration',\n 'max' => 'max_call_duration',\n ],\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getRecipientsFieldData(?Team $team = null, array $value = []): array\n {\n return $this->recipientsService->getRecipientsFieldData(team: $team, value: $value);\n }\n\n public function getJiminnyRecipientsFieldData(array $value = []): array\n {\n return $this->recipientsService->getJiminnyRecipientsFieldData($value);\n }\n\n public function getAdditionalPromptInputFieldData(?string $value = null): array\n {\n return [\n 'id' => 'additional_prompt_input',\n 'label' => 'Special requirements',\n 'inputType' => InputTypeEnum::TEXTAREA,\n 'required' => false,\n 'placeholder' => 'What should be the focus of the report?',\n 'value' => $value,\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getCustomReportNameFieldData(?string $value = null): array\n {\n return [\n 'id' => 'custom_name',\n 'label' => 'Custom report name',\n 'inputType' => InputTypeEnum::TEXT,\n 'required' => false,\n 'placeholder' => 'Enter custom name',\n 'value' => $value,\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n // data providers\n public function getTeams(): array\n {\n $teams = $this->teamRepository->getTeamsForKiosk(status: Team::STATUS_ACTIVE);\n\n $teamData = [];\n foreach ($teams as $team) {\n if (! $team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {\n continue;\n }\n\n $teamData[] = $this->transformTeam($team);\n }\n\n return $teamData;\n }\n\n public function getTeamGroups(string $teamUuid): array\n {\n $data = [];\n $team = $this->getTeam($teamUuid);\n\n if ($team !== null) {\n $groups = $team->groups()->get();\n\n foreach ($groups as $group) {\n $data[] = [\n 'id' => $group->getUuid(),\n 'name' => $group->getName(),\n ];\n }\n }\n\n return $data;\n }\n\n public function getTeamsGroupsOptions(array $filterTeamUuids = []): array\n {\n $data = [];\n $teams = $this->getTeams();\n\n foreach ($teams as $team) {\n if (! empty($filterTeamUuids) && ! in_array($team['id'], $filterTeamUuids, true)) {\n continue;\n }\n\n $data[] = [\n 'label' => $team['name'],\n 'groups' => $this->getTeamGroups($team['id']),\n ];\n }\n\n return $data;\n }\n\n public function getTeam(string $teamUuid): ?Team\n {\n return $this->teamRepository->idOrUuid($teamUuid);\n }\n\n public function getTeamById(int $teamId): ?Team\n {\n return $this->teamRepository->find($teamId);\n }\n\n public function getGroupsUuids(AutomatedReport $report): array\n {\n $uuids = [];\n $reportGroups = $report->getGroups();\n foreach ($reportGroups as $groupId) {\n if ($group = $this->groupRepository->find($groupId)) {\n $uuids[] = $group->getUuid();\n }\n }\n\n return $uuids;\n }\n\n public function getPlaybookCategoriesUuids(AutomatedReport $report): array\n {\n $uuids = [];\n $playbookCategories = $report->getPlaybookCategories();\n foreach ($playbookCategories as $id) {\n if ($category = $this->playbookCategoryRepository->find($id)) {\n $uuids[] = $category->getUuid();\n }\n }\n\n return $uuids;\n }\n\n public function getDealAtCallStagesUuids(AutomatedReport $report): array\n {\n $uuids = [];\n $reportStages = $report->getDealAtCallStages();\n foreach ($reportStages as $id) {\n if ($stage = $this->stageRepository->find($id)) {\n $uuids[] = $stage->getUuid();\n }\n }\n\n return $uuids;\n }\n\n public function getCurrentDealStagesUuids(AutomatedReport $report): array\n {\n $uuids = [];\n $reportStages = $report->getCurrentDealStages();\n foreach ($reportStages as $id) {\n if ($stage = $this->stageRepository->find($id)) {\n $uuids[] = $stage->getUuid();\n }\n }\n\n return $uuids;\n }\n\n public function getUsersUuids(AutomatedReport $report): array\n {\n return $this->extractUserUuids($report->getRecipients());\n }\n\n public function getJiminnyUsersUuids(AutomatedReport $report): array\n {\n return $this->extractUserUuids($report->getJiminnyRecipients());\n }\n\n /**\n * @param array<string, mixed> $recipients\n */\n private function extractUserUuids(array $recipients): array\n {\n $userIds = $recipients['users'] ?? [];\n\n return collect($userIds)\n ->map(fn ($id) => $this->userRepository->find((int) $id))\n ->filter()\n ->map(fn (UserContract $user) => $user->getUuid())\n ->values()\n ->all();\n }\n\n // get mail data\n public function getRecipientUsers(AutomatedReport $report): array\n {\n return $this->buildRecipientUsers($report->getRecipients());\n }\n\n private function getJiminnyRecipientUsers(AutomatedReport $report): array\n {\n return $this->buildRecipientUsers($report->getJiminnyRecipients());\n }\n\n /**\n * @param array<string, mixed> $recipients\n */\n private function buildRecipientUsers(array $recipients): array\n {\n $userIds = $recipients['users'] ?? [];\n\n return collect($userIds)\n ->map(fn ($id) => $this->userRepository->find((int) $id))\n ->filter()\n ->map(fn (UserContract $user) => [\n 'email' => $user->getEmailAddress(),\n 'name' => $user->getName(),\n 'timezone' => $user->getTimezone()->getName(),\n ])\n ->values()\n ->all();\n }\n\n public function getValidRecipientUsers(AutomatedReport $report, bool $includeJiminny = false): array\n {\n if ($report->isAskJiminnyReport()) {\n $recipients = $this->resolveAskJiminnyRecipients($report);\n } else {\n $recipients = $this->getRecipientUsers($report);\n if ($includeJiminny) {\n $recipients = array_merge($recipients, $this->getJiminnyRecipientUsers($report));\n }\n }\n\n $emails = [];\n\n return array_values(array_filter(\n $recipients,\n static function ($recipient) use (&$emails) {\n if (empty($recipient['email']) || in_array($recipient['email'], $emails, true)) {\n return false;\n }\n $emails[] = $recipient['email'];\n\n return true;\n }\n ));\n }\n\n private function resolveAskJiminnyRecipients(AutomatedReport $report): array\n {\n $recipients = [];\n\n $creator = $report->getCreator();\n if ($creator !== null) {\n $recipients[] = [\n 'email' => $creator->getEmailAddress(),\n 'name' => $creator->getName(),\n 'timezone' => $creator->getTimezone()->getName(),\n ];\n }\n\n return array_merge(\n $recipients,\n $this->buildRecipientUsers($report->getRecipients()),\n $this->getGroupRecipientUsers($report),\n );\n }\n\n private function getGroupRecipientUsers(AutomatedReport $report): array\n {\n $users = [];\n foreach ($report->getGroups() as $groupId) {\n $group = $this->groupRepository->find($groupId);\n if ($group === null) {\n continue;\n }\n foreach ($group->getMembers() as $member) {\n $users[] = [\n 'email' => $member->getEmailAddress(),\n 'name' => $member->getName(),\n 'timezone' => $member->getTimezone()->getName(),\n ];\n }\n }\n\n return $users;\n }\n\n public function getReportTypeName(AutomatedReportResult $report): string\n {\n $type = $report->getReport()->getType();\n\n $getType = $this->transformReportType($type);\n\n return $getType['name'];\n }\n\n public function getReportPeriodName(AutomatedReportResult $report): string\n {\n $from = $report->getFromDate();\n $to = $report->getToDate();\n $frequency = $report->getReport()->getFrequency();\n\n if ($from === null || $to === null) {\n if (! $report->getReport()->isAskJiminnyReport()) {\n $invalidPeriod = $from === null ? 'from' : 'to';\n\n throw new ApplicationException('Report period is invalid: ' . $invalidPeriod);\n }\n\n $period = $this->calculateFromAndToDatePeriod($frequency);\n $from = $period['fromDate'];\n $to = $period['toDate'];\n }\n\n return $this->formatReportPeriodName($frequency, $from, $to);\n }\n\n private function formatReportPeriodName(string $frequency, Carbon $from, Carbon $to): string\n {\n $fromYear = $from->format('Y');\n $toYear = $to->format('Y');\n $differentYears = $fromYear !== $toYear;\n\n switch ($frequency) {\n case self::FREQUENCY_DAILY:\n return $from->format('j M Y');\n\n case self::FREQUENCY_QUARTERLY:\n // 'Jan-Mar 2025' or 'Nov 2024-Jan 2025' if years differ\n $startMonth = $from->format('M');\n $endMonth = $to->copy()->subMonth();\n $endMonthName = $endMonth->format('M');\n $endMonthYear = $endMonth->format('Y');\n\n if ($differentYears) {\n return \"{$startMonth} {$fromYear} - {$endMonthName} {$endMonthYear}\";\n }\n\n return \"{$startMonth} - {$endMonthName} {$toYear}\";\n\n case self::FREQUENCY_MONTHLY:\n // 'May 2025' - monthly reports are always within the same year\n return $from->format('M Y');\n\n case self::FREQUENCY_WEEKLY:\n // '4 - 8 Aug 2025', '27 Oct - 3 Nov 2025', or '28 Dec 2024 - 3 Jan 2025' if years differ\n $startDay = $from->format('j');\n $endDay = $to->format('j');\n $startMonth = $from->format('M');\n $endMonth = $to->format('M');\n\n if ($differentYears) {\n return \"{$startDay} {$startMonth} {$fromYear} - {$endDay} {$endMonth} {$toYear}\";\n }\n\n if ($startMonth !== $endMonth) {\n return \"{$startDay} {$startMonth} - {$endDay} {$endMonth} {$toYear}\";\n }\n\n return \"{$startDay} - {$endDay} {$endMonth} {$toYear}\";\n\n case self::FREQUENCY_ONE_OFF:\n // '2 May-31 May 2025' or '15 Dec 2024-15 Jan 2025' if years differ\n $startDay = $from->format('j');\n $startMonth = $from->format('M');\n $endDay = $to->format('j');\n $endMonth = $to->format('M');\n\n // If same month and year, use a format like '2-31 May 2025'\n if ($startMonth === $endMonth && ! $differentYears) {\n return \"{$startDay} - {$endDay} {$startMonth} {$toYear}\";\n }\n\n // If different years, include both years\n if ($differentYears) {\n return \"{$startDay} {$startMonth} {$fromYear} - {$endDay} {$endMonth} {$toYear}\";\n }\n\n // Same year but different months\n return \"{$startDay} {$startMonth} - {$endDay} {$endMonth} {$toYear}\";\n\n default:\n // Default format for unknown frequencies\n return $from->format('j M Y') . ' - ' . $to->format('j M Y');\n }\n }\n\n public function getReportTeamsName(AutomatedReportResult $report): string\n {\n $groups = $report->getGroups();\n\n if (empty($groups)) {\n return 'All';\n }\n\n // Get group names from repository\n $groupNames = [];\n foreach ($groups as $groupId) {\n $group = $this->groupRepository->find($groupId);\n if ($group) {\n $groupNames[] = $group->getName();\n }\n }\n\n if (count($groupNames) === 1) {\n // Single team format\n $teamsName = $groupNames[0];\n } else {\n // Multiple teams format\n $teamsName = implode(', ', $groupNames);\n }\n\n return $teamsName;\n }\n\n public function getReportFileName(AutomatedReportResult $report): string\n {\n $customName = $report->getReport()->getCustomName();\n $periodName = $this->getReportPeriodName($report);\n $filenameSuffix = $this->getFilenameSuffix($report);\n\n if ($customName) {\n if ($filenameSuffix) {\n $customName .= \" {$filenameSuffix}\";\n }\n\n return $this->sanitizeFileName(\"{$customName} - {$periodName}\");\n }\n\n $baseName = $this->getReportTypeName($report);\n\n if ($filenameSuffix) {\n $baseName .= \" {$filenameSuffix}\";\n }\n\n return $this->sanitizeFileName(\"{$baseName} - {$periodName} - {$this->getReportTeamsName($report)}\");\n }\n\n public function getReportFileNameWithExtension(AutomatedReportResult $result): string\n {\n $extension = $this->getMediaTypeMetadata($result)['extension'];\n\n return $this->getReportFileName($result) . '.' . $extension;\n }\n\n public function sanitizeFileName(string $fileName): string\n {\n return str_replace(['/', '\\\\'], '-', $fileName);\n }\n\n public function isUserRecipientOfReport(User $user, AutomatedReport $report): bool\n {\n $recipients = array_map('intval', $report->getRecipients()['users'] ?? []);\n\n return in_array($user->getId(), $recipients);\n }\n\n public function transformReportResults(Collection $automatedReportResults): array\n {\n $data = [];\n foreach ($automatedReportResults as $automatedReportResult) {\n /** @var AutomatedReportResult $automatedReportResult */\n\n $report = $automatedReportResult->getReport();\n\n $createdBy = $report->getCreator();\n $creator = [\n 'id' => $createdBy?->getUuid(),\n 'name' => $createdBy?->getName(),\n 'email' => $createdBy?->getEmailAddress(),\n 'photoUrl' => $createdBy?->getPhotoUrl(),\n ];\n\n $data[] = [\n 'id' => $automatedReportResult->getUuid(),\n 'name' => $automatedReportResult->getName(),\n 'frequency' => $this->transformFrequency($report->getFrequency()),\n 'recipients' => [\n ...array_values($this->transformGroups(team: $report->getTeam(), groupsIds: $report->getGroups())),\n ...array_values($this->transformRecipients($report->getRecipients())),\n ],\n 'report_type' => $this->transformReportType($report->getType()),\n 'media_type' => $automatedReportResult->getMediaType(),\n 'downloadUrl' => $this->generateReportResultDownloadUrl($automatedReportResult),\n 'viewUrl' => $this->generateReportResultViewUrl($automatedReportResult),\n 'generated_at' => $automatedReportResult->getGeneratedAt()?->toIso8601String(),\n 'creator' => $creator,\n ];\n }\n\n return $data;\n }\n\n public function hasCallTypeConference(AutomatedReport $report): bool\n {\n return in_array(self::CALL_TYPE_CONFERENCE['id'], $report->getCallTypes(), true);\n }\n\n public function hasCallTypeDialer(AutomatedReport $report): bool\n {\n return in_array(self::CALL_TYPE_DIALER['id'], $report->getCallTypes(), true);\n }\n\n // transformers\n private function transformTeam(Team $team): array\n {\n if (! $team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {\n return [];\n }\n\n return [\n 'id' => $team->getUuid(),\n 'name' => $team->getName(),\n ];\n }\n\n private function transformReportFullView(AutomatedReport $report): array\n {\n $base = $this->transformReportBase($report);\n\n return $report->getType() === self::TYPE_ASK_JIMINNY\n ? $base + $this->transformAskJiminnyFields($report)\n : $base + $this->transformStandardReportFields($report);\n }\n\n private function transformReportBase(AutomatedReport $report): array\n {\n return [\n 'id' => $report->getUuid(),\n 'organization' => $this->transformOrganization(team: $report->getTeam()),\n 'report_type' => $this->transformReportType($report->getType()),\n 'frequency' => $this->transformFrequency($report->getFrequency()),\n ];\n }\n\n private function transformStandardReportFields(AutomatedReport $report): array\n {\n $team = $report->getTeam();\n\n return [\n 'report_enabled' => $report->getStatus(),\n 'start_date_period' => $report->getFrom()?->format('Y-m-d H:i:s'),\n 'end_date_period' => $report->getTo()?->format('Y-m-d H:i:s'),\n 'deal_value_min' => $report->getDealValueMin(),\n 'deal_value_max' => $report->getDealValueMax(),\n 'call_types' => $this->transformCallType($report->getCallTypes()),\n 'media_types' => $this->transformMediaTypes($report),\n 'call_duration_min' => $this->transformDurationToMinutes($report->getCallDurationMin()),\n 'call_duration_max' => $this->transformDurationToMinutes($report->getCallDurationMax()),\n 'teams' => $this->transformGroups(team: $team, groupsIds: $report->getGroups()),\n 'deal_at_call_stages' => $this->transformStages(team: $team, stagesIds: $report->getDealAtCallStages()),\n 'current_deal_stages' => $this->transformStages(team: $team, stagesIds: $report->getCurrentDealStages()),\n 'recipients' => $this->transformRecipients($report->getRecipients()),\n 'created_by' => $this->transformCreator($report->getCreator()),\n 'additional_prompt_input' => $report->getAdditionalPromptInput(),\n 'custom_name' => $report->getCustomName(),\n 'created_at' => $report->getCreatedAt()->format('Y-m-d H:i:s'),\n 'updated_at' => $report->getUpdatedAt()->format('Y-m-d H:i:s'),\n 'deleted_at' => $report->getDeletedAt()?->format('Y-m-d H:i:s'),\n ];\n }\n\n private function transformAskJiminnyFields(AutomatedReport $report): array\n {\n $team = $report->getTeam();\n $creatorId = $report->getAttribute('created_by');\n $explicitUserIds = array_values(array_filter(\n $report->getRecipients()['users'] ?? [],\n static fn ($id) => $id !== $creatorId\n ));\n\n return [\n 'report_name' => $report->getCustomName(),\n 'enabled' => $report->getStatus(),\n 'share_teams' => $this->transformGroups(team: $team, groupsIds: $report->getGroups()),\n 'share_users' => $this->transformRecipients(['users' => $explicitUserIds]),\n 'saved_search' => $this->transformSafeSearch($report->getSavedSearch()),\n 'ask_jiminny_prompt' => $this->transformAskJiminnyPrompt($report->getAskAnythingPrompt()),\n 'expires_on' => $report->getExpiresAt()?->format('Y-m-d'),\n ];\n }\n\n private function transformOrganization(?Team $team): array\n {\n return [\n 'id' => $team?->getUuid(),\n 'name' => $team?->getName(),\n ];\n }\n\n private function transformReportType(string $type): array\n {\n foreach (self::ALL_TYPES as $typeItem) {\n if ($typeItem['id'] === $type) {\n return $typeItem;\n }\n }\n\n return [];\n }\n\n private function transformCallType(array $types): array\n {\n $result = [];\n $callTypes = [self::CALL_TYPE_CONFERENCE, self::CALL_TYPE_DIALER];\n\n foreach ($types as $type) {\n foreach ($callTypes as $callTypeItem) {\n if ($callTypeItem['id'] === $type) {\n $result[] = $callTypeItem;\n\n break;\n }\n }\n }\n\n return $result;\n }\n\n private function transformMediaTypes(AutomatedReport $report): array\n {\n $values = [];\n\n foreach ($report->getMediaTypes() as $mediaType) {\n if (! in_array($mediaType, self::MEDIA_TYPES, true)) {\n continue;\n }\n\n $values[] = match ($mediaType) {\n self::MEDIA_TYPE_PDF => self::MEDIA_TYPE_OBJECT_PDF,\n self::MEDIA_TYPE_PODCAST => self::MEDIA_TYPE_OBJECT_PODCAST,\n };\n }\n\n return $values;\n }\n\n private function transformFrequency(string $frequency): array\n {\n foreach (self::ALL_FREQUENCIES as $frequencyItem) {\n if ($frequencyItem['id'] === $frequency) {\n return $frequencyItem;\n }\n }\n\n return [];\n }\n\n public function transformDurationToMinutes(?int $duration): ?int\n {\n if (! $duration) {\n return null;\n }\n\n return (int) ($duration / 60);\n }\n\n private function transformGroups(?Team $team, array $groupsIds): array\n {\n if (empty($groupsIds) || ! $team) {\n return [];\n }\n\n $data = [];\n foreach ($groupsIds as $groupId) {\n $group = $team->groups()->where('id', $groupId)->first();\n\n if ($group) {\n $data[] = [\n 'id' => $group->getUuid(),\n 'name' => $group->getName(),\n 'photoUrl' => $group->getPhotoUrl(),\n ];\n }\n }\n\n return $data;\n }\n\n private function transformStages(?Team $team, array $stagesIds): array\n {\n if (empty($stagesIds) || ! $team) {\n return [];\n }\n\n $data = [];\n foreach ($stagesIds as $stageId) {\n $stage = $team->stages()->where('id', $stageId)->first();\n\n if ($stage) {\n $data[] = [\n 'id' => $stage->getUuid(),\n 'name' => $stage->getName(),\n ];\n }\n }\n\n return $data;\n }\n\n private function transformRecipients(array $recipients): array\n {\n $users = [];\n foreach ($recipients['users'] ?? [] as $userId) {\n $users[] = $this->transformUser($userId);\n }\n\n return $users;\n }\n\n private function transformCreator(?User $user): ?array\n {\n if ($user === null) {\n return null;\n }\n\n return $this->transformUser($user->getId());\n }\n\n private function transformAskJiminnyPrompt(?AskAnythingPrompt $prompt): ?array\n {\n if ($prompt === null) {\n return null;\n }\n\n return [\n 'id' => $prompt->getUuid(),\n 'name' => $prompt->getTitle(),\n ];\n }\n\n private function transformSafeSearch(?Search $search): ?array\n {\n if ($search === null) {\n return null;\n }\n\n return [\n 'id' => $search->getUuid(),\n 'name' => $search->getName(),\n ];\n }\n\n private function transformUser(int $userId): array\n {\n /* @var ?User $user */\n $user = $this->userRepository->find($userId);\n\n return [\n 'id' => $user?->getUuid(),\n 'name' => $user?->getName(),\n 'email' => $user?->getEmailAddress(),\n 'photoUrl' => $user?->getPhotoUrl(),\n ];\n }\n\n public function create(array $data): array\n {\n $validatedData = $this->validateAndTransformData($data);\n $validatedData['created_by'] = auth()->id();\n\n $automatedReport = $this->automatedReportsRepository->create($validatedData);\n\n $this->generateOneOffReport($automatedReport);\n\n return $this->transformReportFullView($automatedReport);\n }\n\n public function update(string $uuid, array $data): array\n {\n $validatedData = $this->validateAndTransformData($data);\n $report = $this->automatedReportsRepository->findByUuid($uuid);\n\n if (! $report) {\n throw new InvalidArgumentException('Report not found');\n }\n\n $oldCustomName = $report->getCustomName();\n\n $automatedReport = $this->automatedReportsRepository->update($report, $validatedData);\n\n if ($oldCustomName !== $automatedReport->getCustomName()) {\n $this->updateResultNames($automatedReport);\n }\n\n $this->generateOneOffReport($automatedReport);\n\n return $this->transformReportFullView($automatedReport);\n }\n\n /**\n * Create an Ask Jiminny report.\n */\n public function createAskJiminnyReport(array $data, User $creator): array\n {\n $validatedData = $this->validateAskJiminnyReportData($data, $creator);\n $validatedData['created_by'] = $creator->getId();\n\n $automatedReport = $this->automatedReportsRepository->create($validatedData);\n\n return $this->transformReportFullView($automatedReport);\n }\n\n /**\n * Update an Ask Jiminny report.\n */\n public function updateAskJiminnyReport(AutomatedReport $report, array $data, User $user): array\n {\n if (! $report->isAskJiminnyReport()) {\n throw new InvalidArgumentException('Report is not an Ask Jiminny report');\n }\n\n $validatedData = $this->validateAskJiminnyReportData($data, $user);\n\n $oldCustomName = $report->getCustomName();\n\n $automatedReport = $this->automatedReportsRepository->update($report, $validatedData);\n\n if ($oldCustomName !== $automatedReport->getCustomName()) {\n $this->updateResultNames($automatedReport);\n }\n\n return $this->transformReportFullView($automatedReport);\n }\n\n public function updateAskJiminnyReportStatus(AutomatedReport $report, bool $status): array\n {\n $this->automatedReportsRepository->update($report, ['status' => $status]);\n\n return $this->transformReportFullView($report->fresh());\n }\n\n /**\n * Validate and transform data for Ask Jiminny reports.\n */\n private function validateAskJiminnyReportData(array $data, User $user): array\n {\n // Validate name\n $name = trim($data['report_name'] ?? '');\n if (empty($name)) {\n throw new InvalidArgumentException('Report name is required');\n }\n if (mb_strlen($name) > 50) {\n throw new InvalidArgumentException('Report name must be 50 characters or less');\n }\n\n // Validate frequency (only daily, weekly, monthly for Ask Jiminny)\n $frequency = $data['frequency'] ?? null;\n $askJiminnyFrequencies = [self::FREQUENCY_DAILY, self::FREQUENCY_WEEKLY, self::FREQUENCY_MONTHLY];\n if (! in_array($frequency, $askJiminnyFrequencies, true)) {\n throw new InvalidArgumentException('Frequency must be daily, weekly, or monthly');\n }\n\n // Validate expiration date\n $expiresAt = $data['expires_on'] ?? null;\n if (empty($expiresAt)) {\n throw new InvalidArgumentException('Expiration date is required');\n }\n\n try {\n $expiresAtDate = Carbon::parse($expiresAt);\n } catch (InvalidFormatException $e) {\n throw new InvalidArgumentException('Expiration date format is invalid');\n }\n $maxExpiration = Carbon::now()->addYear();\n if ($expiresAtDate->gt($maxExpiration)) {\n throw new InvalidArgumentException('Expiration date cannot be more than 1 year from now');\n }\n if ($expiresAtDate->isPast()) {\n throw new InvalidArgumentException('Expiration date cannot be in the past');\n }\n\n // Validate saved search\n $activitySearchId = $data['saved_search'] ?? null;\n if (empty($activitySearchId)) {\n throw new InvalidArgumentException('Saved search is required');\n }\n $savedSearch = $this->activitySearchRepository->findByUuidAndUser($activitySearchId, $user);\n if (! $savedSearch) {\n throw new InvalidArgumentException('Saved search not found or does not belong to you');\n }\n\n // Validate saved prompt\n $askAnythingPromptId = $data['ask_jiminny_prompt'] ?? null;\n if (empty($askAnythingPromptId)) {\n throw new InvalidArgumentException('Ask Jiminny prompt is required');\n }\n $prompt = $this->askAnythingRepository->getPromptByUuid($askAnythingPromptId);\n if (! $prompt) {\n throw new InvalidArgumentException('Ask Jiminny prompt not found');\n }\n\n // Validate status\n $status = $data['enabled'] ?? false;\n\n $recipientUserIds = [$user->getId()];\n\n if (! empty($data['share_users'])) {\n $sharedUserIds = $this->validateAndGetUserIdsByTeam(\n $user->team,\n (array) $data['share_users']\n );\n $recipientUserIds = array_merge($recipientUserIds, $sharedUserIds);\n }\n\n $sharedGroupIds = [];\n if (! empty($data['share_teams'])) {\n $sharedGroupIds = $this->validateAndGetGroupIds($user->team, (array) $data['share_teams']);\n }\n\n $recipientUserIds = array_values(array_unique($recipientUserIds));\n\n return [\n 'team_id' => $user->getTeamId(),\n 'type' => self::TYPE_ASK_JIMINNY,\n 'status' => (bool) $status,\n 'frequency' => $frequency,\n 'custom_name' => $name,\n 'activity_search_id' => $savedSearch->getId(),\n 'ask_anything_prompt_id' => $prompt->getId(),\n 'expires_at' => $expiresAtDate->toDateString(),\n 'media_types' => [self::MEDIA_TYPE_PDF],\n 'call_types' => [],\n 'recipients' => ['users' => $recipientUserIds],\n 'groups' => $sharedGroupIds,\n ];\n }\n\n public static function getAskJiminnyFrequencies(): array\n {\n return array_map(static function ($frequency) {\n return $frequency['id'];\n }, self::ASK_JIMINNY_FREQUENCIES);\n }\n\n public function getAskJiminnyReportFilters(User $user): array\n {\n $savedSearches = $this->activitySearchRepository->findByUserOrderedByName($user)\n ->map(fn (Search $search) => [\n 'id' => $search->getUuid(),\n 'name' => $search->getName(),\n ])\n ->values()->all();\n\n $prompts = collect(\n $this->askAnythingPromptService->get($user, AskAnythingPromptTarget::on_demand)\n )->map(fn (AskAnythingPromptDto $prompt) => [\n 'id' => $prompt->id,\n 'name' => $prompt->title,\n ])->values()->all();\n\n return [\n [\n 'id' => 'prompt',\n 'label' => 'Prompt',\n 'options' => $prompts,\n ],\n [\n 'id' => 'saved_search',\n 'label' => 'Saved Search',\n 'options' => $savedSearches,\n ],\n ];\n }\n\n public function getAskJiminnyReportFormData(User $user, ?AutomatedReport $report = null): array\n {\n $team = $user->getTeam();\n $userTimezone = $user->getTimezone();\n\n $savedSearches = $this->activitySearchRepository->findByUserOrderedByName($user)\n ->map(fn (Search $search) => [\n 'id' => $search->getUuid(),\n 'name' => $search->getName(),\n ])\n ->values()->all();\n\n $prompts = collect(\n $this->askAnythingPromptService->get($user, AskAnythingPromptTarget::on_demand)\n )->map(fn (AskAnythingPromptDto $prompt) => [\n 'id' => $prompt->id,\n 'name' => $prompt->title,\n ])->values()->all();\n\n $teamGroups = $this->groupRepository->getAllByTeam($team)->map(fn ($group) => [\n 'id' => $group->getUuid(),\n 'name' => $group->getName(),\n ])->values()->all();\n\n $shareUsers = $this->recipientsService->getRecipientsFieldData(team: $team)['options'] ?? [];\n\n $sharedTeamsValue = [];\n $sharedUsersValue = [];\n if ($report) {\n $sharedTeamsValue = $this->transformGroups($team, $report->getGroups());\n\n $recipientUserIds = $report->getRecipients()['users'] ?? [];\n $creatorId = $report->getAttribute('created_by');\n $sharedUserIds = array_values(array_filter(\n $recipientUserIds,\n static fn ($id) => $id !== $creatorId\n ));\n $sharedUsersValue = collect($sharedUserIds)\n ->map(fn ($id) => $this->userRepository->find((int) $id))\n ->filter()\n ->map(fn (User $u) => [\n 'id' => $u->getUuid(),\n 'name' => $u->getName(),\n ])\n ->values()\n ->all();\n }\n\n return [\n 'fields' => [\n [\n 'id' => 'enabled',\n 'inputType' => InputTypeEnum::TOGGLE,\n 'label' => '',\n 'value' => $report?->getStatus() ?? false,\n ],\n [\n 'id' => 'report_name',\n 'inputType' => InputTypeEnum::TEXT,\n 'label' => 'Name',\n 'placeholder' => 'Enter name',\n 'required' => true,\n 'validation' => ['maxLength' => 50],\n 'value' => $report?->getCustomName() ?? '',\n ],\n [\n 'id' => 'frequency',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'label' => 'Frequency',\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => self::ASK_JIMINNY_FREQUENCIES,\n 'value' => $report ? $this->transformFrequency($report->getFrequency()) : null,\n ],\n [\n 'id' => 'expires_on',\n 'inputType' => InputTypeEnum::DATE,\n 'label' => 'Expires on',\n 'required' => true,\n 'placeholder' => 'Select',\n 'validation' => [\n 'minDate' => now($userTimezone)->toDateString(),\n 'maxDate' => now($userTimezone)->addYear()->toDateString(),\n ],\n 'value' => $report?->getExpiresAt()?->toDateString(),\n ],\n [\n 'id' => 'share_teams',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'label' => 'Team',\n 'required' => false,\n 'placeholder' => 'Select',\n 'options' => $teamGroups,\n 'value' => $sharedTeamsValue,\n ],\n [\n 'id' => 'share_users',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'label' => 'Team member',\n 'required' => false,\n 'placeholder' => 'Select',\n 'groupLabelKey' => 'label',\n 'groupValuesKey' => 'users',\n 'optionLabelKey' => 'name',\n 'optionValueKey' => 'id',\n 'options' => $shareUsers,\n 'value' => $sharedUsersValue,\n ],\n [\n 'id' => 'saved_search',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'label' => 'Saved search',\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => $savedSearches,\n 'value' => $report && $report->getSavedSearch() ? [\n 'id' => $report->getSavedSearch()->getUuid(),\n 'name' => $report->getSavedSearch()->getName(),\n ] : null,\n ],\n [\n 'id' => 'ask_jiminny_prompt',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'label' => 'Ask Jiminny prompt',\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => $prompts,\n 'value' => $report && $report->getAskAnythingPrompt() ? [\n 'id' => $report->getAskAnythingPrompt()->getUuid(),\n 'name' => $report->getAskAnythingPrompt()->getTitle(),\n ] : null,\n ],\n ],\n ];\n }\n\n private function updateResultNames(AutomatedReport $automatedReport): void\n {\n $results = $this->automatedReportsRepository->getResultsByReport($automatedReport);\n\n foreach ($results as $result) {\n $result->update(['name' => $this->getReportFileName($result)]);\n }\n }\n\n public function updateStatus(string $uuid, array $data): array\n {\n $automatedReport = $this->automatedReportsRepository->findByUuid($uuid);\n\n if (! $automatedReport) {\n throw new ModelNotFoundException('Report not found');\n }\n\n $status = $this->validateReportStatus($data['report_enabled'] ?? null);\n $automatedReport->update([\n 'status' => $status,\n ]);\n\n $this->generateOneOffReport($automatedReport);\n\n return $this->transformReportFullView($automatedReport);\n }\n\n private function generateOneOffReport(AutomatedReport $automatedReport): void\n {\n // the scheduler handles all the other frequency types\n if ($automatedReport->getStatus() === false || $automatedReport->getFrequency() !== self::FREQUENCY_ONE_OFF) {\n return;\n }\n\n $this->dispatcher->dispatch(new RequestGenerateReportJob($automatedReport->getUuid()));\n }\n\n public function getReport(string $uuid): AutomatedReport\n {\n $automatedReport = $this->automatedReportsRepository->findByUuid($uuid);\n\n if (! $automatedReport) {\n throw new ModelNotFoundException('Report not found');\n }\n\n return $automatedReport;\n }\n\n public function get(string $uuid): array\n {\n $automatedReport = $this->getReport($uuid);\n\n return $this->transformReportFullView($automatedReport);\n }\n\n public function list(string $sortColumn = 'created_at', string $sortDirection = 'desc'): array\n {\n $results = [];\n $collection = $this->automatedReportsRepository->getAllStandardReports($sortColumn, $sortDirection);\n\n /** @var AutomatedReport $report */\n foreach ($collection as $report) {\n $results[] = $this->transformReportFullView($report);\n }\n\n return ['data' => $results];\n }\n\n public function listAskJiminnyReports(\n User $user,\n string $sortColumn = 'created_at',\n string $sortDirection = 'desc'\n ): array {\n $results = [];\n $collection = $this->automatedReportsRepository->getAskJiminnyReportsByUser($user, $sortColumn, $sortDirection);\n\n /** @var AutomatedReport $report */\n foreach ($collection as $report) {\n $results[] = $this->transformReportFullView($report);\n }\n\n return ['data' => $results];\n }\n\n public function delete(string $uuid): void\n {\n $automatedReport = $this->automatedReportsRepository->findByUuid($uuid);\n\n if (! $automatedReport) {\n throw new ModelNotFoundException('Report not found');\n }\n\n $automatedReport->delete();\n }\n\n public function createReportResult(AutomatedReport $automatedReport, array $data = []): AutomatedReportResult\n {\n return $this->automatedReportsRepository->createResult(\n array_merge(\n [\n 'report_id' => $automatedReport->getId(),\n 'status' => AutomatedReportResult::STATUS_DEFAULT,\n ],\n $data\n )\n );\n }\n\n public function getReportResult(string $resultUuid): AutomatedReportResult\n {\n $report = $this->automatedReportsRepository->findResultByUuid($resultUuid);\n\n if (! $report) {\n throw new ModelNotFoundException('Report Result not found');\n }\n\n return $report;\n }\n\n public function findChildResult(AutomatedReportResult $result, string $type): ?AutomatedReportResult\n {\n return $this->automatedReportsRepository->findChildResult($result, $type);\n }\n\n // prophet API calls\n /**\n * @throws ApplicationException\n */\n public function getGenerateReportPayload(AutomatedReport $automatedReport, string $reportResultUuid): array\n {\n $period = $this->calculateFromAndToDate($automatedReport);\n $fromDate = $period['fromDate'];\n $toDate = $period['toDate'];\n\n return [\n 'team_id' => $automatedReport->getTeamId(),\n 'request_id' => $reportResultUuid,\n 'report_type' => $automatedReport->getType(),\n 'media_types' => $automatedReport->getMediaTypes(),\n 'from_date' => $fromDate->startOfDay()->format(DateTimeInterface::RFC3339),\n 'to_date' => $toDate->endOfDay()->format(DateTimeInterface::RFC3339),\n 'group_ids' => $automatedReport->getGroups(),\n 'call_deal_stage' => $automatedReport->getDealAtCallStages(),\n 'current_deal_stage' => $automatedReport->getCurrentDealStages(),\n 'deal_min_value' => $automatedReport->getDealValueMin(),\n 'deal_max_value' => $automatedReport->getDealValueMax(),\n 'call_types' => $automatedReport->getCallTypes(),\n 'call_duration_min_seconds' => $automatedReport->getCallDurationMin(),\n 'call_duration_max_seconds' => $automatedReport->getCallDurationMax(),\n 'special_requirements' => $automatedReport->getAdditionalPromptInput(),\n 'callback_url' => $this->getCallbackUrl(),\n 'report_period' => $this->formatReportPeriodName(\n $automatedReport->getFrequency(),\n $fromDate,\n $toDate,\n ),\n 'playbook_categories' => $automatedReport->getPlaybookCategories(),\n 'custom_name' => $automatedReport->getCustomName(),\n ];\n }\n\n // $inputPayload - FE payload structure\n public function getActivitiesCountPayload(array $inputPayload): array\n {\n // Use validateAndTransformData to validate and normalize input\n $validatedData = $this->validateAndTransformData($inputPayload);\n $period = $this->calculateFromAndToDatePeriod(\n $validatedData['frequency'],\n Carbon::parse($validatedData['from']),\n Carbon::parse($validatedData['to']),\n );\n $fromDate = $period['fromDate'];\n $toDate = $period['toDate'];\n\n // Create payload similar to getGenerateReportPayload\n return [\n 'team_id' => $validatedData['team_id'],\n 'group_ids' => $validatedData['groups'] ?? [],\n 'report_type' => $validatedData['type'],\n 'from_date' => $fromDate->format(DateTimeInterface::RFC3339),\n 'to_date' => $toDate->format(DateTimeInterface::RFC3339),\n 'call_deal_stage' => $validatedData['deal_at_call_stages'] ?? [],\n 'current_deal_stage' => $validatedData['current_deal_stages'] ?? [],\n 'deal_min_value' => $validatedData['deal_value_min'] ?? null,\n 'deal_max_value' => $validatedData['deal_value_max'] ?? null,\n 'call_types' => $validatedData['call_types'],\n 'call_duration_min_seconds' => $validatedData['call_duration_min'] ?? null,\n 'call_duration_max_seconds' => $validatedData['call_duration_max'] ?? null,\n 'special_requirements' => $validatedData['additional_prompt_input'] ?? null,\n 'playbook_categories' => $validatedData['playbook_categories'] ?? [],\n 'request_id' => null,\n 'callback_url' => null,\n ];\n }\n\n public function shouldSendReport(array $users, ?CarbonInterface $generatedAt = null): bool\n {\n if (empty($users)) {\n return false;\n }\n\n $earliestTz = collect($users)\n ->mapWithKeys(function (array $user) {\n $tz = new DateTimeZone($user['timezone']);\n $nowUtc = new DateTime('now', new DateTimeZone('UTC'));\n $offset = $tz->getOffset($nowUtc);\n\n return [$user['timezone'] => $offset];\n })\n ->sortDesc()\n ->keys()\n ->first();\n\n $now = Carbon::now($earliestTz);\n $isScheduledTime = (int) $now->format('H') === self::SENT_REPORT_AT_HOURS;\n\n if ($isScheduledTime) {\n return true;\n }\n\n return $this->hasPassedScheduledTime($generatedAt, $earliestTz);\n }\n\n public function hasPassedScheduledTime(?CarbonInterface $generatedAt, string $timezone): bool\n {\n if ($generatedAt === null) {\n return false;\n }\n\n $now = Carbon::now($timezone);\n $scheduledTime = $now->copy()->setTime(self::SENT_REPORT_AT_HOURS, 0, 0);\n\n if ($now->hour < self::SENT_REPORT_AT_HOURS) {\n $scheduledTime = $scheduledTime->subDay();\n }\n\n $scheduledTimeUtc = $scheduledTime->copy()->utc();\n $generatedAtUtc = $generatedAt->copy()->utc();\n $nowUtc = $now->copy()->utc();\n\n return $generatedAtUtc->lt($scheduledTimeUtc) && $nowUtc->gt($scheduledTimeUtc);\n }\n\n public function calculateFromAndToDatePeriod(\n string $frequency,\n ?Carbon $fromDate = null,\n ?Carbon $toDate = null\n ): array {\n if ($frequency === self::FREQUENCY_ONE_OFF) {\n return [\n 'fromDate' => $fromDate,\n 'toDate' => $toDate,\n ];\n }\n\n $now = Carbon::now();\n\n return match ($frequency) {\n self::FREQUENCY_DAILY => [\n 'fromDate' => $now->copy()->subDay()->startOfDay(),\n 'toDate' => $now->copy()->subDay()->endOfDay(),\n ],\n self::FREQUENCY_WEEKLY => [\n 'fromDate' => $now->copy()->subWeeks(1)->startOfDay(),\n 'toDate' => $now->copy()->subDay()->endOfDay(),\n ],\n self::FREQUENCY_MONTHLY => [\n 'fromDate' => $now->copy()->subMonths(1)->startOfDay(),\n 'toDate' => $now->copy()->subDay()->endOfDay(),\n ],\n self::FREQUENCY_QUARTERLY => [\n 'fromDate' => $now->copy()->subMonths(3)->startOfDay(),\n 'toDate' => $now->copy()->subDay()->endOfDay(),\n ],\n default => throw new InvalidArgumentException(\"Unsupported frequency: {$frequency}\"),\n };\n }\n\n private function calculateFromAndToDate(AutomatedReport $automatedReport): array\n {\n return $this->calculateFromAndToDatePeriod(\n $automatedReport->getFrequency(),\n $automatedReport->getFrom(),\n $automatedReport->getTo()\n );\n }\n\n public function getAskJiminnyGenerateReportPayload(\n AutomatedReport $automatedReport,\n AutomatedReportResult $reportResult,\n array $activityIds,\n ): array {\n return [\n 'user_question' => $automatedReport->getAskAnythingPrompt()?->getContent(),\n 'call_ids' => array_map('strval', $activityIds),\n 'team_id' => $automatedReport->getTeamId(),\n 'request_id' => $reportResult->getUuid(),\n 'callback_url' => $this->getCallbackUrl(),\n 'report_period' => $this->getReportPeriodName($reportResult),\n 'report_name' => $automatedReport->getCustomName(),\n ];\n }\n\n private function getCallbackUrl(): string\n {\n return $this->webhookService->route('jiminny.webhook.reports.ready');\n }\n\n /**\n * Validate and transform payload data for automated reports\n *\n * @param array $data\n *\n * @throws InvalidArgumentException\n *\n * @return array\n */\n private function validateAndTransformData(array $data): array\n {\n // Validate organization (team) and check feature\n $team = $this->validateOrganization($data['organization'] ?? null);\n\n $status = $this->validateReportStatus($data['report_enabled'] ?? null);\n $type = $this->validateReportType($data['report_type'] ?? null);\n $frequency = $this->validateFrequency($data['frequency'] ?? null);\n $additionalPromptInput = $this->validateAdditionalPromptInput(\n $data['additional_prompt_input'] ?? null\n );\n $customReportName = $this->validateCustomReportName($data['custom_name'] ?? null);\n\n // Prepare data for the database\n $reportData = [\n 'team_id' => $team->getId(),\n 'type' => $type,\n 'status' => $status,\n 'frequency' => $frequency,\n 'additional_prompt_input' => $additionalPromptInput,\n 'custom_name' => $customReportName,\n ];\n\n // Validate deal values\n $reportData = $this->validateDealValues($data, $reportData);\n\n // Validate date range\n $reportData = $this->validateDateRange($data, $reportData, $frequency);\n\n // Validate call durations\n $reportData = $this->validateCallDurations($data, $reportData);\n\n // Validate call types\n $reportData = $this->validateCallTypes($data, $reportData);\n\n // Validate media types\n $reportData = $this->validateMediaTypes($data, $reportData);\n\n // Validate groups\n if (isset($data['teams'])) {\n $reportData['groups'] = $this->validateAndGetGroupIds($team, $data['teams']);\n }\n\n // Validate deal stages\n $reportData = $this->validateDealStages($data, $reportData, $team, $type);\n\n // Validate playbook categories\n $reportData = $this->validatePlaybookCategories($data, $reportData, $team);\n\n // Validate recipients\n $reportData['recipients'] = [\n 'users' => $this->validateAndGetUserIdsByTeam($team, $data['recipients'] ?? []),\n ];\n\n if (isset($data['jiminny_recipients'])) {\n // Validate Jiminny recipients\n $reportData['jiminny_recipients'] = [\n 'users' => $this->validateAndGetJiminnyUserIds((array) $data['jiminny_recipients']),\n ];\n }\n\n return $reportData;\n }\n\n private function validateDealValues(array $data, array $reportData): array\n {\n if (isset($data['min_deal_value'])) {\n $reportData['deal_value_min'] = (int) $data['min_deal_value'];\n\n if ($reportData['deal_value_min'] > 4294967295 || $reportData['deal_value_min'] < 0) {\n throw new InvalidArgumentException('Min deal value should be between 0 and 4294967295');\n }\n }\n\n if (isset($data['max_deal_value'])) {\n $reportData['deal_value_max'] = (int) $data['max_deal_value'];\n\n if ($reportData['deal_value_max'] > 4294967295 || $reportData['deal_value_max'] < 0) {\n throw new InvalidArgumentException('Max deal value should be between 0 and 4294967295');\n }\n }\n\n if (isset($data['min_deal_value'], $data['max_deal_value'])\n && $data['min_deal_value'] > $data['max_deal_value']\n ) {\n throw new InvalidArgumentException('Min deal value cannot be greater than max deal value');\n }\n\n return $reportData;\n }\n\n private function validateDateRange(array $data, array $reportData, string $frequency): array\n {\n // Set date range only for one_off frequency\n if ($frequency === 'one_off') {\n if (isset($data['start_date_period'])) {\n $reportData['from'] = $this->parseDate($data['start_date_period']);\n }\n\n if (isset($data['end_date_period'])) {\n $reportData['to'] = $this->parseDate($data['end_date_period']);\n }\n\n if (empty($reportData['from']) || empty($reportData['to'])) {\n throw new InvalidArgumentException(\n 'Start date and end date are required for one_off frequency'\n );\n }\n } else {\n $reportData['from'] = null;\n $reportData['to'] = null;\n }\n\n return $reportData;\n }\n\n private function validateCallDurations(array $data, array $reportData): array\n {\n // Convert call durations from minutes to seconds\n if (isset($data['min_call_duration'])) {\n $reportData['call_duration_min'] = (int) $data['min_call_duration'] * 60;\n\n if ($reportData['call_duration_min'] > 4294967295 || $reportData['call_duration_min'] < 0) {\n throw new InvalidArgumentException('Min call duration should be between 0 and 4294967295');\n }\n }\n\n if (isset($data['max_call_duration'])) {\n $reportData['call_duration_max'] = (int) $data['max_call_duration'] * 60;\n\n if ($reportData['call_duration_max'] > 4294967295 || $reportData['call_duration_max'] < 0) {\n throw new InvalidArgumentException('Max call duration should be between 0 and 4294967295');\n }\n }\n\n return $reportData;\n }\n\n private function validateCallTypes(array $data, array $reportData): array\n {\n // Set call types\n $reportData['call_types'] = $data['call_type'] ?? [];\n if (empty($reportData['call_types'])) {\n $reportData['call_types'] = self::getCallTypes();\n }\n\n foreach ($reportData['call_types'] as $callType) {\n if (! in_array($callType, self::getCallTypes(), true)) {\n throw new InvalidArgumentException(sprintf('Call type %s is invalid', $callType));\n }\n }\n\n return $reportData;\n }\n\n private function validateMediaTypes(array $data, array $reportData): array\n {\n // Set media types from input data\n $reportData['media_types'] = $data['media_types'] ?? [];\n\n if (empty($reportData['media_types'])) {\n throw new InvalidArgumentException('Media types are required');\n }\n\n foreach ($reportData['media_types'] as $mediaType) {\n if (! in_array($mediaType, self::MEDIA_TYPES, true)) {\n throw new InvalidArgumentException(sprintf('Media type %s is invalid', $mediaType));\n }\n }\n\n return $reportData;\n }\n\n private function validateDealStages(array $data, array $reportData, Team $team, string $reportType): array\n {\n // Validate and set deal stages\n if (isset($data['deal_stage_at_call'])) {\n $reportData['deal_at_call_stages'] =\n $this->validateAndGetDealStageIds($team, $data['deal_stage_at_call'], 'Deal stage at call');\n }\n\n if (isset($data['current_deal_stage'])) {\n $reportData['current_deal_stages'] =\n $this->validateAndGetDealStageIds($team, $data['current_deal_stage'], 'Current deal stage');\n }\n\n // Ensure current_deal_stage is not provided for loss_analysis report type\n if ($reportType === self::TYPE_LOSS_ANALYSIS && ! empty($data['current_deal_stage'])) {\n throw new InvalidArgumentException('Current deal stage is not applicable for Loss Analysis reports');\n }\n\n return $reportData;\n }\n\n // transform uuid to id\n private function validatePlaybookCategories(array $data, array $reportData, Team $team): array\n {\n $key = 'playbook_categories';\n\n if (isset($data[$key])) {\n $payloadIds = $data[$key];\n $ids = [];\n\n foreach ($payloadIds as $uuid) {\n $uuid = (string) $uuid;\n\n try {\n $playbookCategory = $this->playbookCategoryRepository->findByUuid($uuid);\n } catch (Throwable $throwable) {\n Log::error(__METHOD__ . ' ' . $throwable->getMessage());\n\n throw new InvalidArgumentException(sprintf('Playbook category %s not found', $uuid));\n }\n\n if (! $playbookCategory) {\n throw new InvalidArgumentException(sprintf('Playbook category %s not found', $uuid));\n }\n\n if (! $playbookCategory->hasPlaybook()) {\n throw new InvalidArgumentException(sprintf('Playbook category %s has no playbook', $uuid));\n }\n\n if ($playbookCategory->getPlaybook()->getTeamId() !== $team->getId()) {\n throw new InvalidArgumentException(\n sprintf('Playbook category %s not found for team %s', $uuid, $team->getUuid())\n );\n }\n\n $ids[] = $playbookCategory->getId();\n }\n\n $reportData[$key] = $ids;\n }\n\n return $reportData;\n }\n\n private function validateReportStatus($status): bool\n {\n if (! in_array($status, [true, false], true)) {\n throw new InvalidArgumentException('Report status is invalid');\n }\n\n return $status;\n }\n\n private function validateReportType($type): string\n {\n if (! in_array($type, self::getTypes(), true)) {\n throw new InvalidArgumentException(sprintf('Report type is invalid: %s', $type));\n }\n\n return $type;\n }\n\n private function validateFrequency($frequency): string\n {\n if (! in_array($frequency, self::getFrequencies(), true)) {\n throw new InvalidArgumentException('Frequency is invalid');\n }\n\n return $frequency;\n }\n\n private function validateAdditionalPromptInput(?string $additionalPromptInput): ?string\n {\n if ($additionalPromptInput && strlen($additionalPromptInput) > 5000) {\n throw new InvalidArgumentException('Additional Prompt Input should be less than 5000 characters');\n }\n\n return $additionalPromptInput;\n }\n\n private function validateCustomReportName(?string $customReportName): ?string\n {\n if ($customReportName === null || $customReportName === '') {\n return null;\n }\n\n if (strlen($customReportName) > 70) {\n throw new InvalidArgumentException('Custom report name should be less than 70 characters');\n }\n\n return $customReportName;\n }\n\n private function validateOrganization(?string $organizationUuid): Team\n {\n if (! $organizationUuid) {\n throw new InvalidArgumentException('Organization is required');\n }\n\n $team = $this->teamRepository->idOrUuid($organizationUuid);\n\n if (! $team) {\n throw new InvalidArgumentException('Organization not found');\n }\n\n if (! $team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {\n throw new InvalidArgumentException('Organization does not have the Automated Reports feature');\n }\n\n return $team;\n }\n\n private function validateAndGetGroupIds(Team $team, array $teamUuids): array\n {\n $groupIds = [];\n\n foreach ($teamUuids as $uuid) {\n $group = $this->groupRepository->findByUuid($uuid);\n\n if ($group === null || $group->getTeamId() !== $team->getId()) {\n throw new InvalidArgumentException(\n sprintf('Group %s not found for team %s', $uuid, $team->getUuid())\n );\n }\n\n $groupIds[] = $group->getId();\n\n }\n\n return $groupIds;\n }\n\n private function validateAndGetDealStageIds(Team $team, array $stageUuids, string $propertyLabel): array\n {\n $stageIds = [];\n\n foreach ($stageUuids as $uuid) {\n $stage = $this->stageRepository->findByUuid($uuid);\n\n if ($stage === null || $stage->getTeamId() !== $team->getId()) {\n throw new InvalidArgumentException(\n sprintf('Stage %s not found for team %s for %s', $uuid, $team->getUuid(), $propertyLabel)\n );\n }\n\n $stageIds[] = $stage->getId();\n }\n\n return $stageIds;\n }\n\n private function validateAndGetUserIds(array $userUuids, callable $teamCheck): array\n {\n if (empty($userUuids)) {\n return [];\n }\n\n $userIds = [];\n\n foreach ($userUuids as $uuid) {\n $user = $this->userRepository->findByUuid($uuid);\n\n if (! $user || ! $user->isStatusActive()) {\n throw new InvalidArgumentException(\n sprintf('User %s not found or is not active', $uuid)\n );\n }\n\n if (! $teamCheck($user)) {\n throw new InvalidArgumentException(\n sprintf('User %s does not belong to the allowed team(s)', $uuid)\n );\n }\n\n $userIds[] = $user->getId();\n }\n\n return $userIds;\n }\n\n private function validateAndGetUserIdsByTeam(Team $team, array $userUuids): array\n {\n return $this->validateAndGetUserIds($userUuids, fn ($user) => $user->getTeamId() === $team->getId());\n }\n\n private function validateAndGetJiminnyUserIds(array $userUuids): array\n {\n $allowedTeamIds = config('kiosk.teamIds', []);\n\n return $this->validateAndGetUserIds($userUuids, fn ($user) => in_array($user->getTeamId(), $allowedTeamIds, true));\n }\n\n private function parseDate(string $dateString): string\n {\n return date('Y-m-d H:i:s', strtotime($dateString));\n }\n\n private function generateReportResultViewUrl(AutomatedReportResult $result): string\n {\n $mediaResource = $this->getReportMediaRouteResource($result);\n\n return route('ai-reports.' . $mediaResource . '.view', ['uuid' => $result->getUuid()]);\n }\n\n private function generateReportResultDownloadUrl(AutomatedReportResult $result): string\n {\n $mediaResource = $this->getReportMediaRouteResource($result);\n\n return route('ai-reports.' . $mediaResource . '.download', ['uuid' => $result->getUuid()]);\n }\n\n private function getReportMediaRouteResource(AutomatedReportResult $result): string\n {\n if ($result->getMediaType() === self::MEDIA_TYPE_PDF) {\n return self::PDF_KEY;\n } elseif ($result->getMediaType() === self::MEDIA_TYPE_PODCAST) {\n return self::AUDIO_KEY;\n }\n\n throw new \\InvalidArgumentException('Unknown media type.');\n }\n\n public function getMediaPath(AutomatedReportResult $result): ?string\n {\n $url = match ($result->getMediaType()) {\n self::MEDIA_TYPE_PDF => $result->getPdfUrl(),\n self::MEDIA_TYPE_PODCAST => $result->getPodcastAudioUrl(),\n default => null,\n };\n\n if ($url === null) {\n return null;\n }\n\n $path = parse_url(trim($url, '\"\\''), PHP_URL_PATH);\n\n return $path ?: null;\n }\n\n public function getFilenameSuffix(AutomatedReportResult $result): ?string\n {\n return match ($result->getMediaType()) {\n self::MEDIA_TYPE_PODCAST => 'Podcast',\n default => null,\n };\n }\n\n public function getMailSubjectSuffix(AutomatedReportResult $result): string\n {\n return match ($result->getMediaType()) {\n self::MEDIA_TYPE_PDF => 'report',\n self::MEDIA_TYPE_PODCAST => 'podcast',\n default => '',\n };\n }\n\n public function getMediaTypeMetadata(AutomatedReportResult $result): array\n {\n return match ($result->getMediaType()) {\n self::MEDIA_TYPE_PODCAST => ['extension' => 'mp3', 'mime' => 'audio/mpeg'],\n self::MEDIA_TYPE_PDF => ['extension' => 'pdf', 'mime' => 'application/pdf'],\n default => ['extension' => null, 'mime' => null],\n };\n }\n\n public function deleteS3Files(AutomatedReportResult $result): void\n {\n $teamUuid = $result->getReport()->getTeam()->getUuid();\n $reportUuid = $result->getUuid();\n\n // delete all files for a report uuid no mather of pdf, podcast, or both\n // in case of both - the podcast files are linked to the pdf (parent) uuid\n // pdf and podcast date times should be close\n $path = sprintf('%s/%s/%s', $teamUuid, self::S3_DIR, $reportUuid);\n\n foreach (self::FILE_EXTENSIONS_VARIANTS as $extension) {\n $file = $path . '.' . $extension;\n\n if (Storage::exists($file)) {\n Storage::delete($file);\n Log::info('[Reports] Deleted S3 file', [\n 'path' => $file,\n ]);\n }\n }\n\n foreach (self::FILE_PODCAST_EXTENSIONS_VARIANTS as $extension) {\n $file = $path . '_podcast.' . $extension;\n\n if (Storage::exists($file)) {\n Storage::delete($file);\n Log::info('[Reports] Deleted Podcast S3 file', [\n 'path' => $file,\n ]);\n }\n }\n }\n\n /**\n *\n * @param int|null $teamId Optional team ID to filter results\n *\n * @return Collection<int, int> Collection of team IDs\n */\n public function getTeamIdsWithReportsResults(?int $teamId = null): Collection\n {\n return $this->automatedReportsRepository->getTeamIdsWithReportsResults($teamId);\n }\n\n /**\n * Core delete logic for report results using a query\n *\n * @param Builder $query\n * @param array $logContext\n *\n * @return int\n */\n private function deleteReportResultsByQuery(Builder $query, array $logContext = []): int\n {\n $deletedCount = 0;\n\n if ($query->exists()) {\n Log::info(\n 'Run delete report results',\n array_merge(\n $logContext,\n [\n 'service' => 'AutomatedReportsService',\n ]\n )\n );\n\n $query->chunkById(50, function ($results) use (&$deletedCount, $logContext) {\n foreach ($results as $result) {\n $this->deleteReportResult($result);\n $deletedCount++;\n\n Log::info(\n 'Deleted a report result',\n array_merge(\n $logContext,\n [\n 'result_id' => $result->getId(),\n 'report_id' => $result->getReportId(),\n ]\n )\n );\n }\n });\n }\n\n return $deletedCount;\n }\n\n /**\n * Delete report results for a team by retention period\n *\n * @param Team $team\n * @param CarbonImmutable $retentionDate\n *\n * @return int Number of deleted report results\n */\n public function deleteReportsResultsInRetentionPeriod(Team $team, CarbonImmutable $retentionDate): int\n {\n $reportIds = $this->automatedReportsRepository->getReportIdsByTeam($team);\n\n if ($reportIds->isEmpty()) {\n return 0;\n }\n\n $query = $this->automatedReportsRepository\n ->getReportResultsQueryForRetention($team, $retentionDate);\n\n return $this->deleteReportResultsByQuery($query, [\n 'team_id' => $team->getId(),\n 'retention_date' => $retentionDate->toDateTimeString(),\n ]);\n }\n\n /**\n * Delete ALL report results for a specific automated report\n *\n * @param string $uuid\n *\n * @return int\n */\n public function deleteReportResults(string $uuid): int\n {\n $report = $this->getReport($uuid);\n\n $query = $this->automatedReportsRepository->getResultsByReportQuery($report);\n\n return $this->deleteReportResultsByQuery($query, [\n 'report_uuid' => $uuid,\n 'report_id' => $report->getId(),\n ]);\n }\n\n public function deleteReportResult(AutomatedReportResult $result): void\n {\n $this->deleteS3Files($result);\n\n $result->delete();\n }\n\n /**\n * Get all reports for a specific team\n *\n * @param Team $team\n *\n * @return \\Illuminate\\Database\\Eloquent\\Collection\n */\n public function getTeamReports(Team $team): \\Illuminate\\Database\\Eloquent\\Collection\n {\n return $this->automatedReportsRepository->getReportsByTeam($team);\n }\n\n /**\n * Get all report results for a specific report\n *\n * @param AutomatedReport $report\n *\n * @return \\Illuminate\\Database\\Eloquent\\Collection\n */\n public function getReportResults(AutomatedReport $report): \\Illuminate\\Database\\Eloquent\\Collection\n {\n return $this->automatedReportsRepository->getResultsByReport($report);\n }\n\n public function deleteAllReportResults(AutomatedReport $report): void\n {\n $results = $this->getReportResults($report);\n\n /** @var AutomatedReportResult $result */\n foreach ($results as $result) {\n Log::info('Deleting result', [\n 'report' => $report->getId(),\n 'result' => $result->getId(),\n ]);\n\n $this->deleteReportResult($result);\n }\n }\n\n public function deleteAllData(Team $team): void\n {\n Log::info('Deleting automated report and results for team', [\n 'team' => $team->getId(),\n ]);\n\n $reports = $this->getTeamReports($team);\n\n /** @var AutomatedReport $report */\n foreach ($reports as $report) {\n Log::info('Deleting report', [\n 'team' => $team->getId(),\n 'report' => $report->getId(),\n ]);\n\n $this->deleteAllReportResults($report);\n\n $report->delete();\n }\n }\n}","depth":4,"value":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Services\\Kiosk\\AutomatedReports;\n\nuse Carbon\\CarbonImmutable;\nuse Carbon\\CarbonInterface;\nuse Carbon\\Exceptions\\InvalidFormatException;\nuse DateTime;\nuse DateTimeInterface;\nuse DateTimeZone;\nuse Illuminate\\Contracts\\Bus\\Dispatcher as BusDispatcher;\nuse Illuminate\\Database\\Eloquent\\Builder;\nuse Illuminate\\Support\\Carbon;\nuse Illuminate\\Support\\Collection;\nuse Illuminate\\Support\\Facades\\Log;\nuse Illuminate\\Support\\Facades\\Storage;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinition\\InputTypeEnum;\nuse Jiminny\\Component\\AskAnything\\AskAnythingPromptService;\nuse Jiminny\\Component\\AskAnything\\Dtos\\AskAnythingPromptDto;\nuse Jiminny\\Component\\UrlGenerator\\Webhook;\nuse Jiminny\\Contracts\\Repositories\\PlaybookCategoryRepository;\nuse Jiminny\\Contracts\\Repositories\\TeamRepository;\nuse Jiminny\\Contracts\\Repositories\\UserRepository;\nuse Jiminny\\Exceptions\\ApplicationException;\nuse Jiminny\\Exceptions\\InvalidArgumentException;\nuse Jiminny\\Exceptions\\ModelNotFoundException;\nuse Jiminny\\Jobs\\AutomatedReports\\RequestGenerateReportJob;\nuse Jiminny\\Models\\Activity\\Search;\nuse Jiminny\\Models\\AskAnything\\AskAnythingPrompt;\nuse Jiminny\\Models\\AskAnything\\AskAnythingPromptTarget;\nuse Jiminny\\Models\\AutomatedReport;\nuse Jiminny\\Models\\AutomatedReportResult;\nuse Jiminny\\Models\\Contracts\\UserContract;\nuse Jiminny\\Models\\Feature\\FeatureEnum;\nuse Jiminny\\Models\\Team;\nuse Jiminny\\Models\\User;\nuse Jiminny\\Repositories\\AskAnythingRepository;\nuse Jiminny\\Repositories\\AutomatedReportsRepository;\nuse Jiminny\\Repositories\\GroupRepository;\nuse Jiminny\\Repositories\\SearchRepository;\nuse Jiminny\\Repositories\\StageRepository;\nuse Throwable;\n\nclass AutomatedReportsService\n{\n public const string TYPE_LOSS_ANALYSIS = 'loss_analysis';\n public const string TYPE_ASK_JIMINNY = 'ask_jiminny';\n\n /**\n * Standard report types (used by kiosk for existing automated reports).\n */\n // @TODO this will add filter, however if we need to control feature by FF we need conditional logic\n public const array TYPES = [\n ['id' => 'exec_summary', 'name' => 'Exec Summary'],\n ['id' => 'coaching_profiles', 'name' => 'Coaching Profiles'],\n ['id' => 'product_feedback', 'name' => 'Product Feedback'],\n ['id' => self::TYPE_LOSS_ANALYSIS, 'name' => 'Loss Analysis'],\n// ['id' => 'questions', 'name' => 'Questions'],\n// ['id' => 'statistical_quant', 'name' => 'Statistical Quantitative'],\n ];\n\n public const array ALL_TYPES = [\n ...self::TYPES,\n ['id' => self::TYPE_ASK_JIMINNY, 'name' => 'Ask Jiminny'],\n ];\n\n public const string FREQUENCY_DAILY = 'daily';\n public const string FREQUENCY_WEEKLY = 'weekly';\n public const string FREQUENCY_MONTHLY = 'monthly';\n public const string FREQUENCY_QUARTERLY = 'quarterly';\n public const string FREQUENCY_ONE_OFF = 'one_off';\n\n /**\n * Frequencies for standard (non-Ask Jiminny) reports.\n */\n public const array FREQUENCIES = [\n ['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],\n ['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],\n ['id' => self::FREQUENCY_QUARTERLY, 'name' => 'Quarterly'],\n ['id' => self::FREQUENCY_ONE_OFF, 'name' => 'One-off'],\n ];\n\n /**\n * Frequencies for Ask Jiminny reports.\n */\n public const array ASK_JIMINNY_FREQUENCIES = [\n ['id' => self::FREQUENCY_DAILY, 'name' => 'Daily'],\n ['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],\n ['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],\n ];\n\n public const string MEDIA_TYPE_PDF = 'pdf';\n public const string MEDIA_TYPE_PODCAST = 'podcast';\n public const array MEDIA_TYPES = [self::MEDIA_TYPE_PDF, self::MEDIA_TYPE_PODCAST];\n public const array MEDIA_TYPE_OBJECT_PDF = ['id' => self::MEDIA_TYPE_PDF, 'name' => 'PDF'];\n public const array MEDIA_TYPE_OBJECT_PODCAST = ['id' => self::MEDIA_TYPE_PODCAST, 'name' => 'Podcast'];\n public const array MEDIA_TYPE_OBJECTS = [self::MEDIA_TYPE_OBJECT_PDF, self::MEDIA_TYPE_OBJECT_PODCAST];\n\n public const array CALL_TYPE_CONFERENCE = ['id' => 'conference', 'name' => 'Conference'];\n public const array CALL_TYPE_DIALER = ['id' => 'dialer', 'name' => 'Dialer'];\n public const int SENT_REPORT_AT_HOURS = 5;\n public const string PDF_KEY = 'pdf';\n public const string AUDIO_KEY = 'audio';\n\n private const array ALL_FREQUENCIES = [\n ['id' => self::FREQUENCY_DAILY, 'name' => 'Daily'],\n ['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],\n ['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],\n ['id' => self::FREQUENCY_QUARTERLY, 'name' => 'Quarterly'],\n ['id' => self::FREQUENCY_ONE_OFF, 'name' => 'One-off'],\n ];\n private const string S3_DIR = 'reports';\n private const array FILE_EXTENSIONS_VARIANTS = ['html', 'MD', 'pdf'];\n private const array FILE_PODCAST_EXTENSIONS_VARIANTS = ['json', 'mp3', 'ssml'];\n\n public function __construct(\n private readonly TeamRepository $teamRepository,\n private readonly GroupRepository $groupRepository,\n private readonly UserRepository $userRepository,\n private readonly StageRepository $stageRepository,\n private readonly DealStagesService $dealStagesService,\n private readonly RecipientsService $recipientsService,\n private readonly AutomatedReportsRepository $automatedReportsRepository,\n private readonly Webhook $webhookService,\n private readonly BusDispatcher $dispatcher,\n private readonly ActivityTypeService $activityTypeService,\n private readonly PlaybookCategoryRepository $playbookCategoryRepository,\n private readonly AskAnythingPromptService $askAnythingPromptService,\n private readonly SearchRepository $activitySearchRepository,\n private readonly AskAnythingRepository $askAnythingRepository,\n ) {\n }\n\n public static function getTypes(): array\n {\n $types = self::TYPES;\n\n return array_map(static function ($type) {\n return $type['id'];\n }, $types);\n }\n\n public static function getCallTypes(): array\n {\n return array_map(static function ($callType) {\n return $callType['id'];\n }, [self::CALL_TYPE_CONFERENCE, self::CALL_TYPE_DIALER]);\n }\n\n public static function getFrequencies(): array\n {\n return array_map(static function ($frequency) {\n return $frequency['id'];\n }, self::FREQUENCIES);\n }\n\n // front-facing structure\n public function getReportEnabledFieldData(bool $value = false): array\n {\n return [\n 'id' => 'report_enabled',\n 'label' => '',\n 'inputType' => InputTypeEnum::TOGGLE,\n 'value' => $value,\n ];\n }\n\n // Organizations = Teams\n public function getOrganizationFieldData(?string $value = null, bool $shortVersion = false): array\n {\n $options = $this->getTeams();\n\n if ($shortVersion) {\n return [\n 'id' => 'organization',\n 'label' => 'Organization',\n 'options' => $options,\n ];\n }\n\n return [\n 'id' => 'organization',\n 'label' => 'Organization',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => $options,\n 'value' => $value,\n 'dependencies' => [\n 'teams',\n 'deal_stage_at_call',\n 'current_deal_stage',\n 'recipients',\n ActivityTypeService::PLAYBOOK_CATEGORIES_KEY,\n ],\n 'dependsOn' => [],\n ];\n }\n\n // Teams = Groups\n public function getTeamFieldData(array $options = [], array $value = [], bool $shortVersion = false): array\n {\n if ($shortVersion) {\n return [\n 'id' => 'teams',\n 'label' => 'Team',\n 'options' => $options,\n ];\n }\n\n return [\n 'id' => 'teams',\n 'label' => 'Team',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'required' => false,\n 'placeholder' => 'Select',\n 'options' => $options,\n 'value' => $value, // value should be an array of objects {id, name}\n 'dependencies' => [ActivityTypeService::PLAYBOOK_CATEGORIES_KEY],\n 'dependsOn' => [],\n ];\n }\n\n public function getReportTypeFieldData(?string $value = null, bool $shortVersion = false, ?Team $team = null): array\n {\n $types = [];\n if ($team instanceof Team) {\n if ($team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {\n $types = self::TYPES;\n }\n if ($team->hasFeature(FeatureEnum::ASK_JIMINNY_REPORTS)) {\n $types[] = ['id' => self::TYPE_ASK_JIMINNY, 'name' => 'Ask Jiminny'];\n }\n } else {\n $types = self::TYPES;\n }\n\n if ($shortVersion) {\n return [\n 'id' => 'report_type',\n 'label' => 'Report Type',\n 'options' => $types,\n ];\n }\n\n return [\n 'id' => 'report_type',\n 'label' => 'Report Type',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => $types,\n 'value' => $value,\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getFrequencyFieldData(?string $value = null): array\n {\n return [\n 'id' => 'frequency',\n 'label' => 'Frequency',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => self::FREQUENCIES,\n 'value' => $value,\n 'dependencies' => ['period'],\n 'dependsOn' => [],\n ];\n }\n\n public function getPeriodFieldData(?string $valueStartDate = null, ?string $valueEndDate = null): array\n {\n return [\n 'id' => 'period',\n 'label' => 'Select one-off period',\n 'inputType' => InputTypeEnum::DATE_RANGE,\n 'required' => true,\n 'placeholder' => 'Select',\n 'value' => ['startDate' => $valueStartDate, 'endDate' => $valueEndDate],\n 'queryParams' => [\n 'startDate' => 'start_date_period',\n 'endDate' => 'end_date_period',\n ],\n 'dependencies' => [],\n 'dependsOn' => ['frequency'],\n ];\n }\n\n public function getActivityTypesFieldData(?Team $team = null, array $value = [], array $teamsFilter = []): array\n {\n return $this->activityTypeService->getActivityTypeFieldData(team: $team, value: $value, groupIds: $teamsFilter);\n }\n\n public function getDealStageAtCallFieldData(?Team $team = null, array $value = []): array\n {\n return $this->dealStagesService->getDealStageAtCallFieldData(team: $team, value: $value);\n }\n\n public function getCurrentDealStageFieldData(?Team $team = null, array $value = []): array\n {\n return $this->dealStagesService->getCurrentDealStageFieldData(team: $team, value: $value);\n }\n\n public function getDealValueFieldData(?int $valueMin = null, ?int $valueMax = null): array\n {\n return [\n 'id' => 'deal_value',\n 'label' => 'Deal Value',\n 'inputType' => InputTypeEnum::INTEGER_RANGE,\n 'required' => false,\n 'value' => ['min' => $valueMin, 'max' => $valueMax],\n 'queryParams' => [\n 'min' => 'min_deal_value',\n 'max' => 'max_deal_value',\n ],\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getCallTypeFieldData(bool $conferenceOn = false, bool $dialerOn = false): array\n {\n $value = [];\n $conferenceOn && $value[] = self::CALL_TYPE_CONFERENCE;\n $dialerOn && $value[] = self::CALL_TYPE_DIALER;\n\n return [\n 'id' => 'call_type',\n 'label' => 'Call Type',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'required' => true,\n 'options' => [\n self::CALL_TYPE_CONFERENCE,\n self::CALL_TYPE_DIALER,\n ],\n 'value' => $value,\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getMediaTypeFieldData(?AutomatedReport $report = null): array\n {\n $value = [];\n\n if ($report) {\n $value = $this->transformMediaTypes($report);\n }\n\n return [\n 'id' => 'media_types',\n 'label' => 'Export as',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'required' => true,\n 'options' => self::MEDIA_TYPE_OBJECTS,\n 'value' => $value,\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getCallDurationFieldData(?int $valueMin = null, ?int $valueMax = null): array\n {\n return [\n 'id' => 'call_duration',\n 'label' => 'Call Duration',\n 'inputType' => InputTypeEnum::INTEGER_RANGE,\n 'required' => false,\n 'value' => ['min' => $valueMin, 'max' => $valueMax],\n 'queryParams' => [\n 'min' => 'min_call_duration',\n 'max' => 'max_call_duration',\n ],\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getRecipientsFieldData(?Team $team = null, array $value = []): array\n {\n return $this->recipientsService->getRecipientsFieldData(team: $team, value: $value);\n }\n\n public function getJiminnyRecipientsFieldData(array $value = []): array\n {\n return $this->recipientsService->getJiminnyRecipientsFieldData($value);\n }\n\n public function getAdditionalPromptInputFieldData(?string $value = null): array\n {\n return [\n 'id' => 'additional_prompt_input',\n 'label' => 'Special requirements',\n 'inputType' => InputTypeEnum::TEXTAREA,\n 'required' => false,\n 'placeholder' => 'What should be the focus of the report?',\n 'value' => $value,\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getCustomReportNameFieldData(?string $value = null): array\n {\n return [\n 'id' => 'custom_name',\n 'label' => 'Custom report name',\n 'inputType' => InputTypeEnum::TEXT,\n 'required' => false,\n 'placeholder' => 'Enter custom name',\n 'value' => $value,\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n // data providers\n public function getTeams(): array\n {\n $teams = $this->teamRepository->getTeamsForKiosk(status: Team::STATUS_ACTIVE);\n\n $teamData = [];\n foreach ($teams as $team) {\n if (! $team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {\n continue;\n }\n\n $teamData[] = $this->transformTeam($team);\n }\n\n return $teamData;\n }\n\n public function getTeamGroups(string $teamUuid): array\n {\n $data = [];\n $team = $this->getTeam($teamUuid);\n\n if ($team !== null) {\n $groups = $team->groups()->get();\n\n foreach ($groups as $group) {\n $data[] = [\n 'id' => $group->getUuid(),\n 'name' => $group->getName(),\n ];\n }\n }\n\n return $data;\n }\n\n public function getTeamsGroupsOptions(array $filterTeamUuids = []): array\n {\n $data = [];\n $teams = $this->getTeams();\n\n foreach ($teams as $team) {\n if (! empty($filterTeamUuids) && ! in_array($team['id'], $filterTeamUuids, true)) {\n continue;\n }\n\n $data[] = [\n 'label' => $team['name'],\n 'groups' => $this->getTeamGroups($team['id']),\n ];\n }\n\n return $data;\n }\n\n public function getTeam(string $teamUuid): ?Team\n {\n return $this->teamRepository->idOrUuid($teamUuid);\n }\n\n public function getTeamById(int $teamId): ?Team\n {\n return $this->teamRepository->find($teamId);\n }\n\n public function getGroupsUuids(AutomatedReport $report): array\n {\n $uuids = [];\n $reportGroups = $report->getGroups();\n foreach ($reportGroups as $groupId) {\n if ($group = $this->groupRepository->find($groupId)) {\n $uuids[] = $group->getUuid();\n }\n }\n\n return $uuids;\n }\n\n public function getPlaybookCategoriesUuids(AutomatedReport $report): array\n {\n $uuids = [];\n $playbookCategories = $report->getPlaybookCategories();\n foreach ($playbookCategories as $id) {\n if ($category = $this->playbookCategoryRepository->find($id)) {\n $uuids[] = $category->getUuid();\n }\n }\n\n return $uuids;\n }\n\n public function getDealAtCallStagesUuids(AutomatedReport $report): array\n {\n $uuids = [];\n $reportStages = $report->getDealAtCallStages();\n foreach ($reportStages as $id) {\n if ($stage = $this->stageRepository->find($id)) {\n $uuids[] = $stage->getUuid();\n }\n }\n\n return $uuids;\n }\n\n public function getCurrentDealStagesUuids(AutomatedReport $report): array\n {\n $uuids = [];\n $reportStages = $report->getCurrentDealStages();\n foreach ($reportStages as $id) {\n if ($stage = $this->stageRepository->find($id)) {\n $uuids[] = $stage->getUuid();\n }\n }\n\n return $uuids;\n }\n\n public function getUsersUuids(AutomatedReport $report): array\n {\n return $this->extractUserUuids($report->getRecipients());\n }\n\n public function getJiminnyUsersUuids(AutomatedReport $report): array\n {\n return $this->extractUserUuids($report->getJiminnyRecipients());\n }\n\n /**\n * @param array<string, mixed> $recipients\n */\n private function extractUserUuids(array $recipients): array\n {\n $userIds = $recipients['users'] ?? [];\n\n return collect($userIds)\n ->map(fn ($id) => $this->userRepository->find((int) $id))\n ->filter()\n ->map(fn (UserContract $user) => $user->getUuid())\n ->values()\n ->all();\n }\n\n // get mail data\n public function getRecipientUsers(AutomatedReport $report): array\n {\n return $this->buildRecipientUsers($report->getRecipients());\n }\n\n private function getJiminnyRecipientUsers(AutomatedReport $report): array\n {\n return $this->buildRecipientUsers($report->getJiminnyRecipients());\n }\n\n /**\n * @param array<string, mixed> $recipients\n */\n private function buildRecipientUsers(array $recipients): array\n {\n $userIds = $recipients['users'] ?? [];\n\n return collect($userIds)\n ->map(fn ($id) => $this->userRepository->find((int) $id))\n ->filter()\n ->map(fn (UserContract $user) => [\n 'email' => $user->getEmailAddress(),\n 'name' => $user->getName(),\n 'timezone' => $user->getTimezone()->getName(),\n ])\n ->values()\n ->all();\n }\n\n public function getValidRecipientUsers(AutomatedReport $report, bool $includeJiminny = false): array\n {\n if ($report->isAskJiminnyReport()) {\n $recipients = $this->resolveAskJiminnyRecipients($report);\n } else {\n $recipients = $this->getRecipientUsers($report);\n if ($includeJiminny) {\n $recipients = array_merge($recipients, $this->getJiminnyRecipientUsers($report));\n }\n }\n\n $emails = [];\n\n return array_values(array_filter(\n $recipients,\n static function ($recipient) use (&$emails) {\n if (empty($recipient['email']) || in_array($recipient['email'], $emails, true)) {\n return false;\n }\n $emails[] = $recipient['email'];\n\n return true;\n }\n ));\n }\n\n private function resolveAskJiminnyRecipients(AutomatedReport $report): array\n {\n $recipients = [];\n\n $creator = $report->getCreator();\n if ($creator !== null) {\n $recipients[] = [\n 'email' => $creator->getEmailAddress(),\n 'name' => $creator->getName(),\n 'timezone' => $creator->getTimezone()->getName(),\n ];\n }\n\n return array_merge(\n $recipients,\n $this->buildRecipientUsers($report->getRecipients()),\n $this->getGroupRecipientUsers($report),\n );\n }\n\n private function getGroupRecipientUsers(AutomatedReport $report): array\n {\n $users = [];\n foreach ($report->getGroups() as $groupId) {\n $group = $this->groupRepository->find($groupId);\n if ($group === null) {\n continue;\n }\n foreach ($group->getMembers() as $member) {\n $users[] = [\n 'email' => $member->getEmailAddress(),\n 'name' => $member->getName(),\n 'timezone' => $member->getTimezone()->getName(),\n ];\n }\n }\n\n return $users;\n }\n\n public function getReportTypeName(AutomatedReportResult $report): string\n {\n $type = $report->getReport()->getType();\n\n $getType = $this->transformReportType($type);\n\n return $getType['name'];\n }\n\n public function getReportPeriodName(AutomatedReportResult $report): string\n {\n $from = $report->getFromDate();\n $to = $report->getToDate();\n $frequency = $report->getReport()->getFrequency();\n\n if ($from === null || $to === null) {\n if (! $report->getReport()->isAskJiminnyReport()) {\n $invalidPeriod = $from === null ? 'from' : 'to';\n\n throw new ApplicationException('Report period is invalid: ' . $invalidPeriod);\n }\n\n $period = $this->calculateFromAndToDatePeriod($frequency);\n $from = $period['fromDate'];\n $to = $period['toDate'];\n }\n\n return $this->formatReportPeriodName($frequency, $from, $to);\n }\n\n private function formatReportPeriodName(string $frequency, Carbon $from, Carbon $to): string\n {\n $fromYear = $from->format('Y');\n $toYear = $to->format('Y');\n $differentYears = $fromYear !== $toYear;\n\n switch ($frequency) {\n case self::FREQUENCY_DAILY:\n return $from->format('j M Y');\n\n case self::FREQUENCY_QUARTERLY:\n // 'Jan-Mar 2025' or 'Nov 2024-Jan 2025' if years differ\n $startMonth = $from->format('M');\n $endMonth = $to->copy()->subMonth();\n $endMonthName = $endMonth->format('M');\n $endMonthYear = $endMonth->format('Y');\n\n if ($differentYears) {\n return \"{$startMonth} {$fromYear} - {$endMonthName} {$endMonthYear}\";\n }\n\n return \"{$startMonth} - {$endMonthName} {$toYear}\";\n\n case self::FREQUENCY_MONTHLY:\n // 'May 2025' - monthly reports are always within the same year\n return $from->format('M Y');\n\n case self::FREQUENCY_WEEKLY:\n // '4 - 8 Aug 2025', '27 Oct - 3 Nov 2025', or '28 Dec 2024 - 3 Jan 2025' if years differ\n $startDay = $from->format('j');\n $endDay = $to->format('j');\n $startMonth = $from->format('M');\n $endMonth = $to->format('M');\n\n if ($differentYears) {\n return \"{$startDay} {$startMonth} {$fromYear} - {$endDay} {$endMonth} {$toYear}\";\n }\n\n if ($startMonth !== $endMonth) {\n return \"{$startDay} {$startMonth} - {$endDay} {$endMonth} {$toYear}\";\n }\n\n return \"{$startDay} - {$endDay} {$endMonth} {$toYear}\";\n\n case self::FREQUENCY_ONE_OFF:\n // '2 May-31 May 2025' or '15 Dec 2024-15 Jan 2025' if years differ\n $startDay = $from->format('j');\n $startMonth = $from->format('M');\n $endDay = $to->format('j');\n $endMonth = $to->format('M');\n\n // If same month and year, use a format like '2-31 May 2025'\n if ($startMonth === $endMonth && ! $differentYears) {\n return \"{$startDay} - {$endDay} {$startMonth} {$toYear}\";\n }\n\n // If different years, include both years\n if ($differentYears) {\n return \"{$startDay} {$startMonth} {$fromYear} - {$endDay} {$endMonth} {$toYear}\";\n }\n\n // Same year but different months\n return \"{$startDay} {$startMonth} - {$endDay} {$endMonth} {$toYear}\";\n\n default:\n // Default format for unknown frequencies\n return $from->format('j M Y') . ' - ' . $to->format('j M Y');\n }\n }\n\n public function getReportTeamsName(AutomatedReportResult $report): string\n {\n $groups = $report->getGroups();\n\n if (empty($groups)) {\n return 'All';\n }\n\n // Get group names from repository\n $groupNames = [];\n foreach ($groups as $groupId) {\n $group = $this->groupRepository->find($groupId);\n if ($group) {\n $groupNames[] = $group->getName();\n }\n }\n\n if (count($groupNames) === 1) {\n // Single team format\n $teamsName = $groupNames[0];\n } else {\n // Multiple teams format\n $teamsName = implode(', ', $groupNames);\n }\n\n return $teamsName;\n }\n\n public function getReportFileName(AutomatedReportResult $report): string\n {\n $customName = $report->getReport()->getCustomName();\n $periodName = $this->getReportPeriodName($report);\n $filenameSuffix = $this->getFilenameSuffix($report);\n\n if ($customName) {\n if ($filenameSuffix) {\n $customName .= \" {$filenameSuffix}\";\n }\n\n return $this->sanitizeFileName(\"{$customName} - {$periodName}\");\n }\n\n $baseName = $this->getReportTypeName($report);\n\n if ($filenameSuffix) {\n $baseName .= \" {$filenameSuffix}\";\n }\n\n return $this->sanitizeFileName(\"{$baseName} - {$periodName} - {$this->getReportTeamsName($report)}\");\n }\n\n public function getReportFileNameWithExtension(AutomatedReportResult $result): string\n {\n $extension = $this->getMediaTypeMetadata($result)['extension'];\n\n return $this->getReportFileName($result) . '.' . $extension;\n }\n\n public function sanitizeFileName(string $fileName): string\n {\n return str_replace(['/', '\\\\'], '-', $fileName);\n }\n\n public function isUserRecipientOfReport(User $user, AutomatedReport $report): bool\n {\n $recipients = array_map('intval', $report->getRecipients()['users'] ?? []);\n\n return in_array($user->getId(), $recipients);\n }\n\n public function transformReportResults(Collection $automatedReportResults): array\n {\n $data = [];\n foreach ($automatedReportResults as $automatedReportResult) {\n /** @var AutomatedReportResult $automatedReportResult */\n\n $report = $automatedReportResult->getReport();\n\n $createdBy = $report->getCreator();\n $creator = [\n 'id' => $createdBy?->getUuid(),\n 'name' => $createdBy?->getName(),\n 'email' => $createdBy?->getEmailAddress(),\n 'photoUrl' => $createdBy?->getPhotoUrl(),\n ];\n\n $data[] = [\n 'id' => $automatedReportResult->getUuid(),\n 'name' => $automatedReportResult->getName(),\n 'frequency' => $this->transformFrequency($report->getFrequency()),\n 'recipients' => [\n ...array_values($this->transformGroups(team: $report->getTeam(), groupsIds: $report->getGroups())),\n ...array_values($this->transformRecipients($report->getRecipients())),\n ],\n 'report_type' => $this->transformReportType($report->getType()),\n 'media_type' => $automatedReportResult->getMediaType(),\n 'downloadUrl' => $this->generateReportResultDownloadUrl($automatedReportResult),\n 'viewUrl' => $this->generateReportResultViewUrl($automatedReportResult),\n 'generated_at' => $automatedReportResult->getGeneratedAt()?->toIso8601String(),\n 'creator' => $creator,\n ];\n }\n\n return $data;\n }\n\n public function hasCallTypeConference(AutomatedReport $report): bool\n {\n return in_array(self::CALL_TYPE_CONFERENCE['id'], $report->getCallTypes(), true);\n }\n\n public function hasCallTypeDialer(AutomatedReport $report): bool\n {\n return in_array(self::CALL_TYPE_DIALER['id'], $report->getCallTypes(), true);\n }\n\n // transformers\n private function transformTeam(Team $team): array\n {\n if (! $team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {\n return [];\n }\n\n return [\n 'id' => $team->getUuid(),\n 'name' => $team->getName(),\n ];\n }\n\n private function transformReportFullView(AutomatedReport $report): array\n {\n $base = $this->transformReportBase($report);\n\n return $report->getType() === self::TYPE_ASK_JIMINNY\n ? $base + $this->transformAskJiminnyFields($report)\n : $base + $this->transformStandardReportFields($report);\n }\n\n private function transformReportBase(AutomatedReport $report): array\n {\n return [\n 'id' => $report->getUuid(),\n 'organization' => $this->transformOrganization(team: $report->getTeam()),\n 'report_type' => $this->transformReportType($report->getType()),\n 'frequency' => $this->transformFrequency($report->getFrequency()),\n ];\n }\n\n private function transformStandardReportFields(AutomatedReport $report): array\n {\n $team = $report->getTeam();\n\n return [\n 'report_enabled' => $report->getStatus(),\n 'start_date_period' => $report->getFrom()?->format('Y-m-d H:i:s'),\n 'end_date_period' => $report->getTo()?->format('Y-m-d H:i:s'),\n 'deal_value_min' => $report->getDealValueMin(),\n 'deal_value_max' => $report->getDealValueMax(),\n 'call_types' => $this->transformCallType($report->getCallTypes()),\n 'media_types' => $this->transformMediaTypes($report),\n 'call_duration_min' => $this->transformDurationToMinutes($report->getCallDurationMin()),\n 'call_duration_max' => $this->transformDurationToMinutes($report->getCallDurationMax()),\n 'teams' => $this->transformGroups(team: $team, groupsIds: $report->getGroups()),\n 'deal_at_call_stages' => $this->transformStages(team: $team, stagesIds: $report->getDealAtCallStages()),\n 'current_deal_stages' => $this->transformStages(team: $team, stagesIds: $report->getCurrentDealStages()),\n 'recipients' => $this->transformRecipients($report->getRecipients()),\n 'created_by' => $this->transformCreator($report->getCreator()),\n 'additional_prompt_input' => $report->getAdditionalPromptInput(),\n 'custom_name' => $report->getCustomName(),\n 'created_at' => $report->getCreatedAt()->format('Y-m-d H:i:s'),\n 'updated_at' => $report->getUpdatedAt()->format('Y-m-d H:i:s'),\n 'deleted_at' => $report->getDeletedAt()?->format('Y-m-d H:i:s'),\n ];\n }\n\n private function transformAskJiminnyFields(AutomatedReport $report): array\n {\n $team = $report->getTeam();\n $creatorId = $report->getAttribute('created_by');\n $explicitUserIds = array_values(array_filter(\n $report->getRecipients()['users'] ?? [],\n static fn ($id) => $id !== $creatorId\n ));\n\n return [\n 'report_name' => $report->getCustomName(),\n 'enabled' => $report->getStatus(),\n 'share_teams' => $this->transformGroups(team: $team, groupsIds: $report->getGroups()),\n 'share_users' => $this->transformRecipients(['users' => $explicitUserIds]),\n 'saved_search' => $this->transformSafeSearch($report->getSavedSearch()),\n 'ask_jiminny_prompt' => $this->transformAskJiminnyPrompt($report->getAskAnythingPrompt()),\n 'expires_on' => $report->getExpiresAt()?->format('Y-m-d'),\n ];\n }\n\n private function transformOrganization(?Team $team): array\n {\n return [\n 'id' => $team?->getUuid(),\n 'name' => $team?->getName(),\n ];\n }\n\n private function transformReportType(string $type): array\n {\n foreach (self::ALL_TYPES as $typeItem) {\n if ($typeItem['id'] === $type) {\n return $typeItem;\n }\n }\n\n return [];\n }\n\n private function transformCallType(array $types): array\n {\n $result = [];\n $callTypes = [self::CALL_TYPE_CONFERENCE, self::CALL_TYPE_DIALER];\n\n foreach ($types as $type) {\n foreach ($callTypes as $callTypeItem) {\n if ($callTypeItem['id'] === $type) {\n $result[] = $callTypeItem;\n\n break;\n }\n }\n }\n\n return $result;\n }\n\n private function transformMediaTypes(AutomatedReport $report): array\n {\n $values = [];\n\n foreach ($report->getMediaTypes() as $mediaType) {\n if (! in_array($mediaType, self::MEDIA_TYPES, true)) {\n continue;\n }\n\n $values[] = match ($mediaType) {\n self::MEDIA_TYPE_PDF => self::MEDIA_TYPE_OBJECT_PDF,\n self::MEDIA_TYPE_PODCAST => self::MEDIA_TYPE_OBJECT_PODCAST,\n };\n }\n\n return $values;\n }\n\n private function transformFrequency(string $frequency): array\n {\n foreach (self::ALL_FREQUENCIES as $frequencyItem) {\n if ($frequencyItem['id'] === $frequency) {\n return $frequencyItem;\n }\n }\n\n return [];\n }\n\n public function transformDurationToMinutes(?int $duration): ?int\n {\n if (! $duration) {\n return null;\n }\n\n return (int) ($duration / 60);\n }\n\n private function transformGroups(?Team $team, array $groupsIds): array\n {\n if (empty($groupsIds) || ! $team) {\n return [];\n }\n\n $data = [];\n foreach ($groupsIds as $groupId) {\n $group = $team->groups()->where('id', $groupId)->first();\n\n if ($group) {\n $data[] = [\n 'id' => $group->getUuid(),\n 'name' => $group->getName(),\n 'photoUrl' => $group->getPhotoUrl(),\n ];\n }\n }\n\n return $data;\n }\n\n private function transformStages(?Team $team, array $stagesIds): array\n {\n if (empty($stagesIds) || ! $team) {\n return [];\n }\n\n $data = [];\n foreach ($stagesIds as $stageId) {\n $stage = $team->stages()->where('id', $stageId)->first();\n\n if ($stage) {\n $data[] = [\n 'id' => $stage->getUuid(),\n 'name' => $stage->getName(),\n ];\n }\n }\n\n return $data;\n }\n\n private function transformRecipients(array $recipients): array\n {\n $users = [];\n foreach ($recipients['users'] ?? [] as $userId) {\n $users[] = $this->transformUser($userId);\n }\n\n return $users;\n }\n\n private function transformCreator(?User $user): ?array\n {\n if ($user === null) {\n return null;\n }\n\n return $this->transformUser($user->getId());\n }\n\n private function transformAskJiminnyPrompt(?AskAnythingPrompt $prompt): ?array\n {\n if ($prompt === null) {\n return null;\n }\n\n return [\n 'id' => $prompt->getUuid(),\n 'name' => $prompt->getTitle(),\n ];\n }\n\n private function transformSafeSearch(?Search $search): ?array\n {\n if ($search === null) {\n return null;\n }\n\n return [\n 'id' => $search->getUuid(),\n 'name' => $search->getName(),\n ];\n }\n\n private function transformUser(int $userId): array\n {\n /* @var ?User $user */\n $user = $this->userRepository->find($userId);\n\n return [\n 'id' => $user?->getUuid(),\n 'name' => $user?->getName(),\n 'email' => $user?->getEmailAddress(),\n 'photoUrl' => $user?->getPhotoUrl(),\n ];\n }\n\n public function create(array $data): array\n {\n $validatedData = $this->validateAndTransformData($data);\n $validatedData['created_by'] = auth()->id();\n\n $automatedReport = $this->automatedReportsRepository->create($validatedData);\n\n $this->generateOneOffReport($automatedReport);\n\n return $this->transformReportFullView($automatedReport);\n }\n\n public function update(string $uuid, array $data): array\n {\n $validatedData = $this->validateAndTransformData($data);\n $report = $this->automatedReportsRepository->findByUuid($uuid);\n\n if (! $report) {\n throw new InvalidArgumentException('Report not found');\n }\n\n $oldCustomName = $report->getCustomName();\n\n $automatedReport = $this->automatedReportsRepository->update($report, $validatedData);\n\n if ($oldCustomName !== $automatedReport->getCustomName()) {\n $this->updateResultNames($automatedReport);\n }\n\n $this->generateOneOffReport($automatedReport);\n\n return $this->transformReportFullView($automatedReport);\n }\n\n /**\n * Create an Ask Jiminny report.\n */\n public function createAskJiminnyReport(array $data, User $creator): array\n {\n $validatedData = $this->validateAskJiminnyReportData($data, $creator);\n $validatedData['created_by'] = $creator->getId();\n\n $automatedReport = $this->automatedReportsRepository->create($validatedData);\n\n return $this->transformReportFullView($automatedReport);\n }\n\n /**\n * Update an Ask Jiminny report.\n */\n public function updateAskJiminnyReport(AutomatedReport $report, array $data, User $user): array\n {\n if (! $report->isAskJiminnyReport()) {\n throw new InvalidArgumentException('Report is not an Ask Jiminny report');\n }\n\n $validatedData = $this->validateAskJiminnyReportData($data, $user);\n\n $oldCustomName = $report->getCustomName();\n\n $automatedReport = $this->automatedReportsRepository->update($report, $validatedData);\n\n if ($oldCustomName !== $automatedReport->getCustomName()) {\n $this->updateResultNames($automatedReport);\n }\n\n return $this->transformReportFullView($automatedReport);\n }\n\n public function updateAskJiminnyReportStatus(AutomatedReport $report, bool $status): array\n {\n $this->automatedReportsRepository->update($report, ['status' => $status]);\n\n return $this->transformReportFullView($report->fresh());\n }\n\n /**\n * Validate and transform data for Ask Jiminny reports.\n */\n private function validateAskJiminnyReportData(array $data, User $user): array\n {\n // Validate name\n $name = trim($data['report_name'] ?? '');\n if (empty($name)) {\n throw new InvalidArgumentException('Report name is required');\n }\n if (mb_strlen($name) > 50) {\n throw new InvalidArgumentException('Report name must be 50 characters or less');\n }\n\n // Validate frequency (only daily, weekly, monthly for Ask Jiminny)\n $frequency = $data['frequency'] ?? null;\n $askJiminnyFrequencies = [self::FREQUENCY_DAILY, self::FREQUENCY_WEEKLY, self::FREQUENCY_MONTHLY];\n if (! in_array($frequency, $askJiminnyFrequencies, true)) {\n throw new InvalidArgumentException('Frequency must be daily, weekly, or monthly');\n }\n\n // Validate expiration date\n $expiresAt = $data['expires_on'] ?? null;\n if (empty($expiresAt)) {\n throw new InvalidArgumentException('Expiration date is required');\n }\n\n try {\n $expiresAtDate = Carbon::parse($expiresAt);\n } catch (InvalidFormatException $e) {\n throw new InvalidArgumentException('Expiration date format is invalid');\n }\n $maxExpiration = Carbon::now()->addYear();\n if ($expiresAtDate->gt($maxExpiration)) {\n throw new InvalidArgumentException('Expiration date cannot be more than 1 year from now');\n }\n if ($expiresAtDate->isPast()) {\n throw new InvalidArgumentException('Expiration date cannot be in the past');\n }\n\n // Validate saved search\n $activitySearchId = $data['saved_search'] ?? null;\n if (empty($activitySearchId)) {\n throw new InvalidArgumentException('Saved search is required');\n }\n $savedSearch = $this->activitySearchRepository->findByUuidAndUser($activitySearchId, $user);\n if (! $savedSearch) {\n throw new InvalidArgumentException('Saved search not found or does not belong to you');\n }\n\n // Validate saved prompt\n $askAnythingPromptId = $data['ask_jiminny_prompt'] ?? null;\n if (empty($askAnythingPromptId)) {\n throw new InvalidArgumentException('Ask Jiminny prompt is required');\n }\n $prompt = $this->askAnythingRepository->getPromptByUuid($askAnythingPromptId);\n if (! $prompt) {\n throw new InvalidArgumentException('Ask Jiminny prompt not found');\n }\n\n // Validate status\n $status = $data['enabled'] ?? false;\n\n $recipientUserIds = [$user->getId()];\n\n if (! empty($data['share_users'])) {\n $sharedUserIds = $this->validateAndGetUserIdsByTeam(\n $user->team,\n (array) $data['share_users']\n );\n $recipientUserIds = array_merge($recipientUserIds, $sharedUserIds);\n }\n\n $sharedGroupIds = [];\n if (! empty($data['share_teams'])) {\n $sharedGroupIds = $this->validateAndGetGroupIds($user->team, (array) $data['share_teams']);\n }\n\n $recipientUserIds = array_values(array_unique($recipientUserIds));\n\n return [\n 'team_id' => $user->getTeamId(),\n 'type' => self::TYPE_ASK_JIMINNY,\n 'status' => (bool) $status,\n 'frequency' => $frequency,\n 'custom_name' => $name,\n 'activity_search_id' => $savedSearch->getId(),\n 'ask_anything_prompt_id' => $prompt->getId(),\n 'expires_at' => $expiresAtDate->toDateString(),\n 'media_types' => [self::MEDIA_TYPE_PDF],\n 'call_types' => [],\n 'recipients' => ['users' => $recipientUserIds],\n 'groups' => $sharedGroupIds,\n ];\n }\n\n public static function getAskJiminnyFrequencies(): array\n {\n return array_map(static function ($frequency) {\n return $frequency['id'];\n }, self::ASK_JIMINNY_FREQUENCIES);\n }\n\n public function getAskJiminnyReportFilters(User $user): array\n {\n $savedSearches = $this->activitySearchRepository->findByUserOrderedByName($user)\n ->map(fn (Search $search) => [\n 'id' => $search->getUuid(),\n 'name' => $search->getName(),\n ])\n ->values()->all();\n\n $prompts = collect(\n $this->askAnythingPromptService->get($user, AskAnythingPromptTarget::on_demand)\n )->map(fn (AskAnythingPromptDto $prompt) => [\n 'id' => $prompt->id,\n 'name' => $prompt->title,\n ])->values()->all();\n\n return [\n [\n 'id' => 'prompt',\n 'label' => 'Prompt',\n 'options' => $prompts,\n ],\n [\n 'id' => 'saved_search',\n 'label' => 'Saved Search',\n 'options' => $savedSearches,\n ],\n ];\n }\n\n public function getAskJiminnyReportFormData(User $user, ?AutomatedReport $report = null): array\n {\n $team = $user->getTeam();\n $userTimezone = $user->getTimezone();\n\n $savedSearches = $this->activitySearchRepository->findByUserOrderedByName($user)\n ->map(fn (Search $search) => [\n 'id' => $search->getUuid(),\n 'name' => $search->getName(),\n ])\n ->values()->all();\n\n $prompts = collect(\n $this->askAnythingPromptService->get($user, AskAnythingPromptTarget::on_demand)\n )->map(fn (AskAnythingPromptDto $prompt) => [\n 'id' => $prompt->id,\n 'name' => $prompt->title,\n ])->values()->all();\n\n $teamGroups = $this->groupRepository->getAllByTeam($team)->map(fn ($group) => [\n 'id' => $group->getUuid(),\n 'name' => $group->getName(),\n ])->values()->all();\n\n $shareUsers = $this->recipientsService->getRecipientsFieldData(team: $team)['options'] ?? [];\n\n $sharedTeamsValue = [];\n $sharedUsersValue = [];\n if ($report) {\n $sharedTeamsValue = $this->transformGroups($team, $report->getGroups());\n\n $recipientUserIds = $report->getRecipients()['users'] ?? [];\n $creatorId = $report->getAttribute('created_by');\n $sharedUserIds = array_values(array_filter(\n $recipientUserIds,\n static fn ($id) => $id !== $creatorId\n ));\n $sharedUsersValue = collect($sharedUserIds)\n ->map(fn ($id) => $this->userRepository->find((int) $id))\n ->filter()\n ->map(fn (User $u) => [\n 'id' => $u->getUuid(),\n 'name' => $u->getName(),\n ])\n ->values()\n ->all();\n }\n\n return [\n 'fields' => [\n [\n 'id' => 'enabled',\n 'inputType' => InputTypeEnum::TOGGLE,\n 'label' => '',\n 'value' => $report?->getStatus() ?? false,\n ],\n [\n 'id' => 'report_name',\n 'inputType' => InputTypeEnum::TEXT,\n 'label' => 'Name',\n 'placeholder' => 'Enter name',\n 'required' => true,\n 'validation' => ['maxLength' => 50],\n 'value' => $report?->getCustomName() ?? '',\n ],\n [\n 'id' => 'frequency',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'label' => 'Frequency',\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => self::ASK_JIMINNY_FREQUENCIES,\n 'value' => $report ? $this->transformFrequency($report->getFrequency()) : null,\n ],\n [\n 'id' => 'expires_on',\n 'inputType' => InputTypeEnum::DATE,\n 'label' => 'Expires on',\n 'required' => true,\n 'placeholder' => 'Select',\n 'validation' => [\n 'minDate' => now($userTimezone)->toDateString(),\n 'maxDate' => now($userTimezone)->addYear()->toDateString(),\n ],\n 'value' => $report?->getExpiresAt()?->toDateString(),\n ],\n [\n 'id' => 'share_teams',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'label' => 'Team',\n 'required' => false,\n 'placeholder' => 'Select',\n 'options' => $teamGroups,\n 'value' => $sharedTeamsValue,\n ],\n [\n 'id' => 'share_users',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'label' => 'Team member',\n 'required' => false,\n 'placeholder' => 'Select',\n 'groupLabelKey' => 'label',\n 'groupValuesKey' => 'users',\n 'optionLabelKey' => 'name',\n 'optionValueKey' => 'id',\n 'options' => $shareUsers,\n 'value' => $sharedUsersValue,\n ],\n [\n 'id' => 'saved_search',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'label' => 'Saved search',\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => $savedSearches,\n 'value' => $report && $report->getSavedSearch() ? [\n 'id' => $report->getSavedSearch()->getUuid(),\n 'name' => $report->getSavedSearch()->getName(),\n ] : null,\n ],\n [\n 'id' => 'ask_jiminny_prompt',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'label' => 'Ask Jiminny prompt',\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => $prompts,\n 'value' => $report && $report->getAskAnythingPrompt() ? [\n 'id' => $report->getAskAnythingPrompt()->getUuid(),\n 'name' => $report->getAskAnythingPrompt()->getTitle(),\n ] : null,\n ],\n ],\n ];\n }\n\n private function updateResultNames(AutomatedReport $automatedReport): void\n {\n $results = $this->automatedReportsRepository->getResultsByReport($automatedReport);\n\n foreach ($results as $result) {\n $result->update(['name' => $this->getReportFileName($result)]);\n }\n }\n\n public function updateStatus(string $uuid, array $data): array\n {\n $automatedReport = $this->automatedReportsRepository->findByUuid($uuid);\n\n if (! $automatedReport) {\n throw new ModelNotFoundException('Report not found');\n }\n\n $status = $this->validateReportStatus($data['report_enabled'] ?? null);\n $automatedReport->update([\n 'status' => $status,\n ]);\n\n $this->generateOneOffReport($automatedReport);\n\n return $this->transformReportFullView($automatedReport);\n }\n\n private function generateOneOffReport(AutomatedReport $automatedReport): void\n {\n // the scheduler handles all the other frequency types\n if ($automatedReport->getStatus() === false || $automatedReport->getFrequency() !== self::FREQUENCY_ONE_OFF) {\n return;\n }\n\n $this->dispatcher->dispatch(new RequestGenerateReportJob($automatedReport->getUuid()));\n }\n\n public function getReport(string $uuid): AutomatedReport\n {\n $automatedReport = $this->automatedReportsRepository->findByUuid($uuid);\n\n if (! $automatedReport) {\n throw new ModelNotFoundException('Report not found');\n }\n\n return $automatedReport;\n }\n\n public function get(string $uuid): array\n {\n $automatedReport = $this->getReport($uuid);\n\n return $this->transformReportFullView($automatedReport);\n }\n\n public function list(string $sortColumn = 'created_at', string $sortDirection = 'desc'): array\n {\n $results = [];\n $collection = $this->automatedReportsRepository->getAllStandardReports($sortColumn, $sortDirection);\n\n /** @var AutomatedReport $report */\n foreach ($collection as $report) {\n $results[] = $this->transformReportFullView($report);\n }\n\n return ['data' => $results];\n }\n\n public function listAskJiminnyReports(\n User $user,\n string $sortColumn = 'created_at',\n string $sortDirection = 'desc'\n ): array {\n $results = [];\n $collection = $this->automatedReportsRepository->getAskJiminnyReportsByUser($user, $sortColumn, $sortDirection);\n\n /** @var AutomatedReport $report */\n foreach ($collection as $report) {\n $results[] = $this->transformReportFullView($report);\n }\n\n return ['data' => $results];\n }\n\n public function delete(string $uuid): void\n {\n $automatedReport = $this->automatedReportsRepository->findByUuid($uuid);\n\n if (! $automatedReport) {\n throw new ModelNotFoundException('Report not found');\n }\n\n $automatedReport->delete();\n }\n\n public function createReportResult(AutomatedReport $automatedReport, array $data = []): AutomatedReportResult\n {\n return $this->automatedReportsRepository->createResult(\n array_merge(\n [\n 'report_id' => $automatedReport->getId(),\n 'status' => AutomatedReportResult::STATUS_DEFAULT,\n ],\n $data\n )\n );\n }\n\n public function getReportResult(string $resultUuid): AutomatedReportResult\n {\n $report = $this->automatedReportsRepository->findResultByUuid($resultUuid);\n\n if (! $report) {\n throw new ModelNotFoundException('Report Result not found');\n }\n\n return $report;\n }\n\n public function findChildResult(AutomatedReportResult $result, string $type): ?AutomatedReportResult\n {\n return $this->automatedReportsRepository->findChildResult($result, $type);\n }\n\n // prophet API calls\n /**\n * @throws ApplicationException\n */\n public function getGenerateReportPayload(AutomatedReport $automatedReport, string $reportResultUuid): array\n {\n $period = $this->calculateFromAndToDate($automatedReport);\n $fromDate = $period['fromDate'];\n $toDate = $period['toDate'];\n\n return [\n 'team_id' => $automatedReport->getTeamId(),\n 'request_id' => $reportResultUuid,\n 'report_type' => $automatedReport->getType(),\n 'media_types' => $automatedReport->getMediaTypes(),\n 'from_date' => $fromDate->startOfDay()->format(DateTimeInterface::RFC3339),\n 'to_date' => $toDate->endOfDay()->format(DateTimeInterface::RFC3339),\n 'group_ids' => $automatedReport->getGroups(),\n 'call_deal_stage' => $automatedReport->getDealAtCallStages(),\n 'current_deal_stage' => $automatedReport->getCurrentDealStages(),\n 'deal_min_value' => $automatedReport->getDealValueMin(),\n 'deal_max_value' => $automatedReport->getDealValueMax(),\n 'call_types' => $automatedReport->getCallTypes(),\n 'call_duration_min_seconds' => $automatedReport->getCallDurationMin(),\n 'call_duration_max_seconds' => $automatedReport->getCallDurationMax(),\n 'special_requirements' => $automatedReport->getAdditionalPromptInput(),\n 'callback_url' => $this->getCallbackUrl(),\n 'report_period' => $this->formatReportPeriodName(\n $automatedReport->getFrequency(),\n $fromDate,\n $toDate,\n ),\n 'playbook_categories' => $automatedReport->getPlaybookCategories(),\n 'custom_name' => $automatedReport->getCustomName(),\n ];\n }\n\n // $inputPayload - FE payload structure\n public function getActivitiesCountPayload(array $inputPayload): array\n {\n // Use validateAndTransformData to validate and normalize input\n $validatedData = $this->validateAndTransformData($inputPayload);\n $period = $this->calculateFromAndToDatePeriod(\n $validatedData['frequency'],\n Carbon::parse($validatedData['from']),\n Carbon::parse($validatedData['to']),\n );\n $fromDate = $period['fromDate'];\n $toDate = $period['toDate'];\n\n // Create payload similar to getGenerateReportPayload\n return [\n 'team_id' => $validatedData['team_id'],\n 'group_ids' => $validatedData['groups'] ?? [],\n 'report_type' => $validatedData['type'],\n 'from_date' => $fromDate->format(DateTimeInterface::RFC3339),\n 'to_date' => $toDate->format(DateTimeInterface::RFC3339),\n 'call_deal_stage' => $validatedData['deal_at_call_stages'] ?? [],\n 'current_deal_stage' => $validatedData['current_deal_stages'] ?? [],\n 'deal_min_value' => $validatedData['deal_value_min'] ?? null,\n 'deal_max_value' => $validatedData['deal_value_max'] ?? null,\n 'call_types' => $validatedData['call_types'],\n 'call_duration_min_seconds' => $validatedData['call_duration_min'] ?? null,\n 'call_duration_max_seconds' => $validatedData['call_duration_max'] ?? null,\n 'special_requirements' => $validatedData['additional_prompt_input'] ?? null,\n 'playbook_categories' => $validatedData['playbook_categories'] ?? [],\n 'request_id' => null,\n 'callback_url' => null,\n ];\n }\n\n public function shouldSendReport(array $users, ?CarbonInterface $generatedAt = null): bool\n {\n if (empty($users)) {\n return false;\n }\n\n $earliestTz = collect($users)\n ->mapWithKeys(function (array $user) {\n $tz = new DateTimeZone($user['timezone']);\n $nowUtc = new DateTime('now', new DateTimeZone('UTC'));\n $offset = $tz->getOffset($nowUtc);\n\n return [$user['timezone'] => $offset];\n })\n ->sortDesc()\n ->keys()\n ->first();\n\n $now = Carbon::now($earliestTz);\n $isScheduledTime = (int) $now->format('H') === self::SENT_REPORT_AT_HOURS;\n\n if ($isScheduledTime) {\n return true;\n }\n\n return $this->hasPassedScheduledTime($generatedAt, $earliestTz);\n }\n\n public function hasPassedScheduledTime(?CarbonInterface $generatedAt, string $timezone): bool\n {\n if ($generatedAt === null) {\n return false;\n }\n\n $now = Carbon::now($timezone);\n $scheduledTime = $now->copy()->setTime(self::SENT_REPORT_AT_HOURS, 0, 0);\n\n if ($now->hour < self::SENT_REPORT_AT_HOURS) {\n $scheduledTime = $scheduledTime->subDay();\n }\n\n $scheduledTimeUtc = $scheduledTime->copy()->utc();\n $generatedAtUtc = $generatedAt->copy()->utc();\n $nowUtc = $now->copy()->utc();\n\n return $generatedAtUtc->lt($scheduledTimeUtc) && $nowUtc->gt($scheduledTimeUtc);\n }\n\n public function calculateFromAndToDatePeriod(\n string $frequency,\n ?Carbon $fromDate = null,\n ?Carbon $toDate = null\n ): array {\n if ($frequency === self::FREQUENCY_ONE_OFF) {\n return [\n 'fromDate' => $fromDate,\n 'toDate' => $toDate,\n ];\n }\n\n $now = Carbon::now();\n\n return match ($frequency) {\n self::FREQUENCY_DAILY => [\n 'fromDate' => $now->copy()->subDay()->startOfDay(),\n 'toDate' => $now->copy()->subDay()->endOfDay(),\n ],\n self::FREQUENCY_WEEKLY => [\n 'fromDate' => $now->copy()->subWeeks(1)->startOfDay(),\n 'toDate' => $now->copy()->subDay()->endOfDay(),\n ],\n self::FREQUENCY_MONTHLY => [\n 'fromDate' => $now->copy()->subMonths(1)->startOfDay(),\n 'toDate' => $now->copy()->subDay()->endOfDay(),\n ],\n self::FREQUENCY_QUARTERLY => [\n 'fromDate' => $now->copy()->subMonths(3)->startOfDay(),\n 'toDate' => $now->copy()->subDay()->endOfDay(),\n ],\n default => throw new InvalidArgumentException(\"Unsupported frequency: {$frequency}\"),\n };\n }\n\n private function calculateFromAndToDate(AutomatedReport $automatedReport): array\n {\n return $this->calculateFromAndToDatePeriod(\n $automatedReport->getFrequency(),\n $automatedReport->getFrom(),\n $automatedReport->getTo()\n );\n }\n\n public function getAskJiminnyGenerateReportPayload(\n AutomatedReport $automatedReport,\n AutomatedReportResult $reportResult,\n array $activityIds,\n ): array {\n return [\n 'user_question' => $automatedReport->getAskAnythingPrompt()?->getContent(),\n 'call_ids' => array_map('strval', $activityIds),\n 'team_id' => $automatedReport->getTeamId(),\n 'request_id' => $reportResult->getUuid(),\n 'callback_url' => $this->getCallbackUrl(),\n 'report_period' => $this->getReportPeriodName($reportResult),\n 'report_name' => $automatedReport->getCustomName(),\n ];\n }\n\n private function getCallbackUrl(): string\n {\n return $this->webhookService->route('jiminny.webhook.reports.ready');\n }\n\n /**\n * Validate and transform payload data for automated reports\n *\n * @param array $data\n *\n * @throws InvalidArgumentException\n *\n * @return array\n */\n private function validateAndTransformData(array $data): array\n {\n // Validate organization (team) and check feature\n $team = $this->validateOrganization($data['organization'] ?? null);\n\n $status = $this->validateReportStatus($data['report_enabled'] ?? null);\n $type = $this->validateReportType($data['report_type'] ?? null);\n $frequency = $this->validateFrequency($data['frequency'] ?? null);\n $additionalPromptInput = $this->validateAdditionalPromptInput(\n $data['additional_prompt_input'] ?? null\n );\n $customReportName = $this->validateCustomReportName($data['custom_name'] ?? null);\n\n // Prepare data for the database\n $reportData = [\n 'team_id' => $team->getId(),\n 'type' => $type,\n 'status' => $status,\n 'frequency' => $frequency,\n 'additional_prompt_input' => $additionalPromptInput,\n 'custom_name' => $customReportName,\n ];\n\n // Validate deal values\n $reportData = $this->validateDealValues($data, $reportData);\n\n // Validate date range\n $reportData = $this->validateDateRange($data, $reportData, $frequency);\n\n // Validate call durations\n $reportData = $this->validateCallDurations($data, $reportData);\n\n // Validate call types\n $reportData = $this->validateCallTypes($data, $reportData);\n\n // Validate media types\n $reportData = $this->validateMediaTypes($data, $reportData);\n\n // Validate groups\n if (isset($data['teams'])) {\n $reportData['groups'] = $this->validateAndGetGroupIds($team, $data['teams']);\n }\n\n // Validate deal stages\n $reportData = $this->validateDealStages($data, $reportData, $team, $type);\n\n // Validate playbook categories\n $reportData = $this->validatePlaybookCategories($data, $reportData, $team);\n\n // Validate recipients\n $reportData['recipients'] = [\n 'users' => $this->validateAndGetUserIdsByTeam($team, $data['recipients'] ?? []),\n ];\n\n if (isset($data['jiminny_recipients'])) {\n // Validate Jiminny recipients\n $reportData['jiminny_recipients'] = [\n 'users' => $this->validateAndGetJiminnyUserIds((array) $data['jiminny_recipients']),\n ];\n }\n\n return $reportData;\n }\n\n private function validateDealValues(array $data, array $reportData): array\n {\n if (isset($data['min_deal_value'])) {\n $reportData['deal_value_min'] = (int) $data['min_deal_value'];\n\n if ($reportData['deal_value_min'] > 4294967295 || $reportData['deal_value_min'] < 0) {\n throw new InvalidArgumentException('Min deal value should be between 0 and 4294967295');\n }\n }\n\n if (isset($data['max_deal_value'])) {\n $reportData['deal_value_max'] = (int) $data['max_deal_value'];\n\n if ($reportData['deal_value_max'] > 4294967295 || $reportData['deal_value_max'] < 0) {\n throw new InvalidArgumentException('Max deal value should be between 0 and 4294967295');\n }\n }\n\n if (isset($data['min_deal_value'], $data['max_deal_value'])\n && $data['min_deal_value'] > $data['max_deal_value']\n ) {\n throw new InvalidArgumentException('Min deal value cannot be greater than max deal value');\n }\n\n return $reportData;\n }\n\n private function validateDateRange(array $data, array $reportData, string $frequency): array\n {\n // Set date range only for one_off frequency\n if ($frequency === 'one_off') {\n if (isset($data['start_date_period'])) {\n $reportData['from'] = $this->parseDate($data['start_date_period']);\n }\n\n if (isset($data['end_date_period'])) {\n $reportData['to'] = $this->parseDate($data['end_date_period']);\n }\n\n if (empty($reportData['from']) || empty($reportData['to'])) {\n throw new InvalidArgumentException(\n 'Start date and end date are required for one_off frequency'\n );\n }\n } else {\n $reportData['from'] = null;\n $reportData['to'] = null;\n }\n\n return $reportData;\n }\n\n private function validateCallDurations(array $data, array $reportData): array\n {\n // Convert call durations from minutes to seconds\n if (isset($data['min_call_duration'])) {\n $reportData['call_duration_min'] = (int) $data['min_call_duration'] * 60;\n\n if ($reportData['call_duration_min'] > 4294967295 || $reportData['call_duration_min'] < 0) {\n throw new InvalidArgumentException('Min call duration should be between 0 and 4294967295');\n }\n }\n\n if (isset($data['max_call_duration'])) {\n $reportData['call_duration_max'] = (int) $data['max_call_duration'] * 60;\n\n if ($reportData['call_duration_max'] > 4294967295 || $reportData['call_duration_max'] < 0) {\n throw new InvalidArgumentException('Max call duration should be between 0 and 4294967295');\n }\n }\n\n return $reportData;\n }\n\n private function validateCallTypes(array $data, array $reportData): array\n {\n // Set call types\n $reportData['call_types'] = $data['call_type'] ?? [];\n if (empty($reportData['call_types'])) {\n $reportData['call_types'] = self::getCallTypes();\n }\n\n foreach ($reportData['call_types'] as $callType) {\n if (! in_array($callType, self::getCallTypes(), true)) {\n throw new InvalidArgumentException(sprintf('Call type %s is invalid', $callType));\n }\n }\n\n return $reportData;\n }\n\n private function validateMediaTypes(array $data, array $reportData): array\n {\n // Set media types from input data\n $reportData['media_types'] = $data['media_types'] ?? [];\n\n if (empty($reportData['media_types'])) {\n throw new InvalidArgumentException('Media types are required');\n }\n\n foreach ($reportData['media_types'] as $mediaType) {\n if (! in_array($mediaType, self::MEDIA_TYPES, true)) {\n throw new InvalidArgumentException(sprintf('Media type %s is invalid', $mediaType));\n }\n }\n\n return $reportData;\n }\n\n private function validateDealStages(array $data, array $reportData, Team $team, string $reportType): array\n {\n // Validate and set deal stages\n if (isset($data['deal_stage_at_call'])) {\n $reportData['deal_at_call_stages'] =\n $this->validateAndGetDealStageIds($team, $data['deal_stage_at_call'], 'Deal stage at call');\n }\n\n if (isset($data['current_deal_stage'])) {\n $reportData['current_deal_stages'] =\n $this->validateAndGetDealStageIds($team, $data['current_deal_stage'], 'Current deal stage');\n }\n\n // Ensure current_deal_stage is not provided for loss_analysis report type\n if ($reportType === self::TYPE_LOSS_ANALYSIS && ! empty($data['current_deal_stage'])) {\n throw new InvalidArgumentException('Current deal stage is not applicable for Loss Analysis reports');\n }\n\n return $reportData;\n }\n\n // transform uuid to id\n private function validatePlaybookCategories(array $data, array $reportData, Team $team): array\n {\n $key = 'playbook_categories';\n\n if (isset($data[$key])) {\n $payloadIds = $data[$key];\n $ids = [];\n\n foreach ($payloadIds as $uuid) {\n $uuid = (string) $uuid;\n\n try {\n $playbookCategory = $this->playbookCategoryRepository->findByUuid($uuid);\n } catch (Throwable $throwable) {\n Log::error(__METHOD__ . ' ' . $throwable->getMessage());\n\n throw new InvalidArgumentException(sprintf('Playbook category %s not found', $uuid));\n }\n\n if (! $playbookCategory) {\n throw new InvalidArgumentException(sprintf('Playbook category %s not found', $uuid));\n }\n\n if (! $playbookCategory->hasPlaybook()) {\n throw new InvalidArgumentException(sprintf('Playbook category %s has no playbook', $uuid));\n }\n\n if ($playbookCategory->getPlaybook()->getTeamId() !== $team->getId()) {\n throw new InvalidArgumentException(\n sprintf('Playbook category %s not found for team %s', $uuid, $team->getUuid())\n );\n }\n\n $ids[] = $playbookCategory->getId();\n }\n\n $reportData[$key] = $ids;\n }\n\n return $reportData;\n }\n\n private function validateReportStatus($status): bool\n {\n if (! in_array($status, [true, false], true)) {\n throw new InvalidArgumentException('Report status is invalid');\n }\n\n return $status;\n }\n\n private function validateReportType($type): string\n {\n if (! in_array($type, self::getTypes(), true)) {\n throw new InvalidArgumentException(sprintf('Report type is invalid: %s', $type));\n }\n\n return $type;\n }\n\n private function validateFrequency($frequency): string\n {\n if (! in_array($frequency, self::getFrequencies(), true)) {\n throw new InvalidArgumentException('Frequency is invalid');\n }\n\n return $frequency;\n }\n\n private function validateAdditionalPromptInput(?string $additionalPromptInput): ?string\n {\n if ($additionalPromptInput && strlen($additionalPromptInput) > 5000) {\n throw new InvalidArgumentException('Additional Prompt Input should be less than 5000 characters');\n }\n\n return $additionalPromptInput;\n }\n\n private function validateCustomReportName(?string $customReportName): ?string\n {\n if ($customReportName === null || $customReportName === '') {\n return null;\n }\n\n if (strlen($customReportName) > 70) {\n throw new InvalidArgumentException('Custom report name should be less than 70 characters');\n }\n\n return $customReportName;\n }\n\n private function validateOrganization(?string $organizationUuid): Team\n {\n if (! $organizationUuid) {\n throw new InvalidArgumentException('Organization is required');\n }\n\n $team = $this->teamRepository->idOrUuid($organizationUuid);\n\n if (! $team) {\n throw new InvalidArgumentException('Organization not found');\n }\n\n if (! $team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {\n throw new InvalidArgumentException('Organization does not have the Automated Reports feature');\n }\n\n return $team;\n }\n\n private function validateAndGetGroupIds(Team $team, array $teamUuids): array\n {\n $groupIds = [];\n\n foreach ($teamUuids as $uuid) {\n $group = $this->groupRepository->findByUuid($uuid);\n\n if ($group === null || $group->getTeamId() !== $team->getId()) {\n throw new InvalidArgumentException(\n sprintf('Group %s not found for team %s', $uuid, $team->getUuid())\n );\n }\n\n $groupIds[] = $group->getId();\n\n }\n\n return $groupIds;\n }\n\n private function validateAndGetDealStageIds(Team $team, array $stageUuids, string $propertyLabel): array\n {\n $stageIds = [];\n\n foreach ($stageUuids as $uuid) {\n $stage = $this->stageRepository->findByUuid($uuid);\n\n if ($stage === null || $stage->getTeamId() !== $team->getId()) {\n throw new InvalidArgumentException(\n sprintf('Stage %s not found for team %s for %s', $uuid, $team->getUuid(), $propertyLabel)\n );\n }\n\n $stageIds[] = $stage->getId();\n }\n\n return $stageIds;\n }\n\n private function validateAndGetUserIds(array $userUuids, callable $teamCheck): array\n {\n if (empty($userUuids)) {\n return [];\n }\n\n $userIds = [];\n\n foreach ($userUuids as $uuid) {\n $user = $this->userRepository->findByUuid($uuid);\n\n if (! $user || ! $user->isStatusActive()) {\n throw new InvalidArgumentException(\n sprintf('User %s not found or is not active', $uuid)\n );\n }\n\n if (! $teamCheck($user)) {\n throw new InvalidArgumentException(\n sprintf('User %s does not belong to the allowed team(s)', $uuid)\n );\n }\n\n $userIds[] = $user->getId();\n }\n\n return $userIds;\n }\n\n private function validateAndGetUserIdsByTeam(Team $team, array $userUuids): array\n {\n return $this->validateAndGetUserIds($userUuids, fn ($user) => $user->getTeamId() === $team->getId());\n }\n\n private function validateAndGetJiminnyUserIds(array $userUuids): array\n {\n $allowedTeamIds = config('kiosk.teamIds', []);\n\n return $this->validateAndGetUserIds($userUuids, fn ($user) => in_array($user->getTeamId(), $allowedTeamIds, true));\n }\n\n private function parseDate(string $dateString): string\n {\n return date('Y-m-d H:i:s', strtotime($dateString));\n }\n\n private function generateReportResultViewUrl(AutomatedReportResult $result): string\n {\n $mediaResource = $this->getReportMediaRouteResource($result);\n\n return route('ai-reports.' . $mediaResource . '.view', ['uuid' => $result->getUuid()]);\n }\n\n private function generateReportResultDownloadUrl(AutomatedReportResult $result): string\n {\n $mediaResource = $this->getReportMediaRouteResource($result);\n\n return route('ai-reports.' . $mediaResource . '.download', ['uuid' => $result->getUuid()]);\n }\n\n private function getReportMediaRouteResource(AutomatedReportResult $result): string\n {\n if ($result->getMediaType() === self::MEDIA_TYPE_PDF) {\n return self::PDF_KEY;\n } elseif ($result->getMediaType() === self::MEDIA_TYPE_PODCAST) {\n return self::AUDIO_KEY;\n }\n\n throw new \\InvalidArgumentException('Unknown media type.');\n }\n\n public function getMediaPath(AutomatedReportResult $result): ?string\n {\n $url = match ($result->getMediaType()) {\n self::MEDIA_TYPE_PDF => $result->getPdfUrl(),\n self::MEDIA_TYPE_PODCAST => $result->getPodcastAudioUrl(),\n default => null,\n };\n\n if ($url === null) {\n return null;\n }\n\n $path = parse_url(trim($url, '\"\\''), PHP_URL_PATH);\n\n return $path ?: null;\n }\n\n public function getFilenameSuffix(AutomatedReportResult $result): ?string\n {\n return match ($result->getMediaType()) {\n self::MEDIA_TYPE_PODCAST => 'Podcast',\n default => null,\n };\n }\n\n public function getMailSubjectSuffix(AutomatedReportResult $result): string\n {\n return match ($result->getMediaType()) {\n self::MEDIA_TYPE_PDF => 'report',\n self::MEDIA_TYPE_PODCAST => 'podcast',\n default => '',\n };\n }\n\n public function getMediaTypeMetadata(AutomatedReportResult $result): array\n {\n return match ($result->getMediaType()) {\n self::MEDIA_TYPE_PODCAST => ['extension' => 'mp3', 'mime' => 'audio/mpeg'],\n self::MEDIA_TYPE_PDF => ['extension' => 'pdf', 'mime' => 'application/pdf'],\n default => ['extension' => null, 'mime' => null],\n };\n }\n\n public function deleteS3Files(AutomatedReportResult $result): void\n {\n $teamUuid = $result->getReport()->getTeam()->getUuid();\n $reportUuid = $result->getUuid();\n\n // delete all files for a report uuid no mather of pdf, podcast, or both\n // in case of both - the podcast files are linked to the pdf (parent) uuid\n // pdf and podcast date times should be close\n $path = sprintf('%s/%s/%s', $teamUuid, self::S3_DIR, $reportUuid);\n\n foreach (self::FILE_EXTENSIONS_VARIANTS as $extension) {\n $file = $path . '.' . $extension;\n\n if (Storage::exists($file)) {\n Storage::delete($file);\n Log::info('[Reports] Deleted S3 file', [\n 'path' => $file,\n ]);\n }\n }\n\n foreach (self::FILE_PODCAST_EXTENSIONS_VARIANTS as $extension) {\n $file = $path . '_podcast.' . $extension;\n\n if (Storage::exists($file)) {\n Storage::delete($file);\n Log::info('[Reports] Deleted Podcast S3 file', [\n 'path' => $file,\n ]);\n }\n }\n }\n\n /**\n *\n * @param int|null $teamId Optional team ID to filter results\n *\n * @return Collection<int, int> Collection of team IDs\n */\n public function getTeamIdsWithReportsResults(?int $teamId = null): Collection\n {\n return $this->automatedReportsRepository->getTeamIdsWithReportsResults($teamId);\n }\n\n /**\n * Core delete logic for report results using a query\n *\n * @param Builder $query\n * @param array $logContext\n *\n * @return int\n */\n private function deleteReportResultsByQuery(Builder $query, array $logContext = []): int\n {\n $deletedCount = 0;\n\n if ($query->exists()) {\n Log::info(\n 'Run delete report results',\n array_merge(\n $logContext,\n [\n 'service' => 'AutomatedReportsService',\n ]\n )\n );\n\n $query->chunkById(50, function ($results) use (&$deletedCount, $logContext) {\n foreach ($results as $result) {\n $this->deleteReportResult($result);\n $deletedCount++;\n\n Log::info(\n 'Deleted a report result',\n array_merge(\n $logContext,\n [\n 'result_id' => $result->getId(),\n 'report_id' => $result->getReportId(),\n ]\n )\n );\n }\n });\n }\n\n return $deletedCount;\n }\n\n /**\n * Delete report results for a team by retention period\n *\n * @param Team $team\n * @param CarbonImmutable $retentionDate\n *\n * @return int Number of deleted report results\n */\n public function deleteReportsResultsInRetentionPeriod(Team $team, CarbonImmutable $retentionDate): int\n {\n $reportIds = $this->automatedReportsRepository->getReportIdsByTeam($team);\n\n if ($reportIds->isEmpty()) {\n return 0;\n }\n\n $query = $this->automatedReportsRepository\n ->getReportResultsQueryForRetention($team, $retentionDate);\n\n return $this->deleteReportResultsByQuery($query, [\n 'team_id' => $team->getId(),\n 'retention_date' => $retentionDate->toDateTimeString(),\n ]);\n }\n\n /**\n * Delete ALL report results for a specific automated report\n *\n * @param string $uuid\n *\n * @return int\n */\n public function deleteReportResults(string $uuid): int\n {\n $report = $this->getReport($uuid);\n\n $query = $this->automatedReportsRepository->getResultsByReportQuery($report);\n\n return $this->deleteReportResultsByQuery($query, [\n 'report_uuid' => $uuid,\n 'report_id' => $report->getId(),\n ]);\n }\n\n public function deleteReportResult(AutomatedReportResult $result): void\n {\n $this->deleteS3Files($result);\n\n $result->delete();\n }\n\n /**\n * Get all reports for a specific team\n *\n * @param Team $team\n *\n * @return \\Illuminate\\Database\\Eloquent\\Collection\n */\n public function getTeamReports(Team $team): \\Illuminate\\Database\\Eloquent\\Collection\n {\n return $this->automatedReportsRepository->getReportsByTeam($team);\n }\n\n /**\n * Get all report results for a specific report\n *\n * @param AutomatedReport $report\n *\n * @return \\Illuminate\\Database\\Eloquent\\Collection\n */\n public function getReportResults(AutomatedReport $report): \\Illuminate\\Database\\Eloquent\\Collection\n {\n return $this->automatedReportsRepository->getResultsByReport($report);\n }\n\n public function deleteAllReportResults(AutomatedReport $report): void\n {\n $results = $this->getReportResults($report);\n\n /** @var AutomatedReportResult $result */\n foreach ($results as $result) {\n Log::info('Deleting result', [\n 'report' => $report->getId(),\n 'result' => $result->getId(),\n ]);\n\n $this->deleteReportResult($result);\n }\n }\n\n public function deleteAllData(Team $team): void\n {\n Log::info('Deleting automated report and results for team', [\n 'team' => $team->getId(),\n ]);\n\n $reports = $this->getTeamReports($team);\n\n /** @var AutomatedReport $report */\n foreach ($reports as $report) {\n Log::info('Deleting report', [\n 'team' => $team->getId(),\n 'report' => $report->getId(),\n ]);\n\n $this->deleteAllReportResults($report);\n\n $report->delete();\n }\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":true,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"Project","depth":3,"role_description":"text"},{"role":"AXButton","text":"Project","depth":3,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"New File or Directory…","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Expand Selected","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Collapse All","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Options","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false}]...
|
3397592283435315795
|
6686367547760219213
|
idle
|
accessibility
|
NULL
|
Project: faVsco.js, menu
#11894 on JY-18909-automa Project: faVsco.js, menu
#11894 on JY-18909-automated-reports-ask-jiminny, menu
Start Listening for PHP Debug Connections
AutomatedReportsCommandTest
Run 'AutomatedReportsCommandTest'
Debug 'AutomatedReportsCommandTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Execute
Explain Plan
Browse Query History
View Parameters
Open Query Execution Settings…
In-Editor Results
Tx: Auto
Cancel Running Statements
Playground
jiminny
Sync Changes
Hide This Notification
Code changed:
Hide
16
13
13
Previous Highlighted Error
Next Highlighted Error
SELECT * FROM teams WHERE id = 1;
select * from crm_layouts where crm_configuration_id = 39;
SELECT * FROM crm_layout_entities WHERE crm_layout_id = 283;
SELECT * FROM crm_fields WHERE id = 2234;
SELECT * FROM crm_field_values WHERE crm_field_id = 2234;
select * from crm_profiles where user_id = 143;
select * from record_types where crm_configuration_id = 39; # 0121K000001MHElQAO,0121K000001MHEqQAO
select * from business_processes where crm_configuration_id = 39;
# 01941000000H669AAC, 01941000000H66JAAS
select * from record_type_field_values
where record_type_id IN (24);
select * from crm_field_values where id IN (2730);
select * from crm_configurations where id = 39;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 1
and sa.provider = 'salesforce'; #1035
select * from users where team_id = 1; # 222 group 3
SELECT * FROM activities WHERE user_id = 222 order by id desc;
select * from sidekick_settings where team_id = 1;
select * from teams where id = 1;
select * from team_features where team_id = 1;
select * from activities where crm_configuration_id = 2
and provider = 'ms-teams' and id = 608765;
SELECT * FROM activities WHERE crm_configuration_id = 2 and crm_provider_id = '59523413338';
select * from sidekick_settings where team_id = 2;
SELECT * FROM activities WHERE id = 608660;
select * from activity_summary_logs where activity_id = 608660;
select * from ai_prompts where transcription_id = 11214;
# [PASSWORD_DOTS]
SELECT * FROM activities WHERE uuid_to_bin('ed78a437-2804-450e-ab2f-56ab1c641346') = uuid;
# id: 608818, crm: 59628809737
SELECT * FROM activities WHERE uuid_to_bin('36b06e55-afdd-4782-8dee-c624cd0af191') = uuid;
# id: 608821, crm: 59632069252
SELECT ce.start_time, ce.end_time, a.id, a.uuid, crm_provider_id, calendar_event_id, title,
playbook_category_id, user_id, lead_id, contact_id, account_id, opportunity_id,
scheduled_start_time, scheduled_end_time, actual_start_time, actual_end_time, a.created_at
FROM activities a
join calendar_events ce on a.calendar_event_id = ce.id
WHERE a.id IN (608818, 608821);
select * from users where team_id = 1;
select * from team_settings where team_id = 1;
select * from crm_profiles where crm_configuration_id = 39 order by user_id;
select * from team_features where team_id = 1;
select * from users where team_id = 2;
SELECT * FROM activities WHERE uuid_to_bin('ec7647e9-5225-458b-b475-f31aa2769204') = uuid; # 612639
# Preslava N. Ivanova, grou id 3
SELECT * FROM opportunities WHERE uuid_to_bin('a2928fe5-aec5-46cb-85d9-7654c89e46a6') = uuid;
select * from activities where opportunity_id = 344 and actual_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00';
select
a.id,
a.type,
a.scheduled_start_time,
a.actual_start_time,
a.created_at,
a.opportunity_id,
a.status
FROM activities a
WHERE opportunity_id = 344
and status IN ('completed', 'received', 'delivered')
and (
(a.actual_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00')
OR (a.created_at between '2024-10-11 00:00:00' and '2024-10-12 00:00:00')
OR (a.scheduled_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00'))
;
SELECT * FROM users WHERE id = 222;
SELECT * FROM crm_profiles WHERE user_id = 222;
select * from crm_layouts where crm_configuration_id = 39;
SELECT * FROM crm_layout_entities WHERE crm_layout_id = 281;
select * from group_deal_risk_types;
select * from opportunities where team_id = 1;
SELECT * FROM opportunities WHERE id = 315;
SELECT * FROM crm_field_data WHERE object_id = 315;
select * from crm_field_data where object_id = 260;
select * from generic_ai_prompts where subject_id = 315;
select * from teams; # 36, 21, 121, [EMAIL]
SELECT * FROM social_accounts WHERE sociable_id = 121 and provider = 'bullhorn';
# [PASSWORD_DOTS]
select * from teams where id = 1;
select * from crm_configurations where id = 39;
select * from users where team_id = 1;
select u.email, cp.* from users u
join crm_profiles cp on u.id = cp.user_id
where u.team_id = 1;
# 1 - 00541000004281rAAA
# 204 - 0052g000003freeAAA
# 429 - 0052g000003qGOiAAM
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 1
and sa.provider = 'salesforce';
select * from activities where type = 'softphone'
and created_at > '2024-12-11 15:24:36' order by id desc;
select * from activity_providers where team_id = 1;
select * from activity_provider_users where activity_provider_id = 328;
select * from opportunities where crm_configuration_id = 39
AND account_id = 178 AND is_closed = false
order by created_at DESC;
select * from contacts where id = 3952;
select * from accounts where id = 178;
# [PASSWORD_DOTS]
select * from teams where id = 36;
select * from crm_configurations where id = 21;
select * from users where team_id = 36;
select u.email, cp.* from users u
join crm_profiles cp on u.id = cp.user_id
where u.team_id = 36;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 36
and sa.provider = 'bullhorn';
select * from social_accounts where id = 348;
UPDATE social_accounts SET
provider_user_token = '21442_6802599_91:41179a58-21e7-4d7c-ad58-56bb666b2f65',
provider_refresh_token = '21442_6802599_91:01c6b335-3f2a-42e4-85ff-8a08fa65fceb',
expires = 1733998131,
state = 'connected'
WHERE id = 348;
# [PASSWORD_DOTS]
select * from teams where id = 31;
select * from crm_configurations where id = 18;
select * from users where team_id = 31; # 257
select u.email, cp.* from users u
join crm_profiles cp on u.id = cp.user_id
where u.team_id = 31;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 31
and sa.provider = 'close';
select * from contacts where crm_configuration_id = 18;
# [PASSWORD_DOTS] NEPTUNE [PASSWORD_DOTS]
select * from teams;
select * from users where id IN (1030, 1035, 1052);
select * from crm_configurations;
select * from users where team_id = 65; # 257
select * from team_settings where team_id = 65; # 257
select * from invitations where team_id = 65; # 257
select * from users where email = '[EMAIL]'; # 257
select u.email, cp.* from users u
join crm_profiles cp on u.id = cp.user_id
where u.team_id = 65;
select * from crm_configurations where id = 53;
select * from accounts where crm_configuration_id = 53 order by id desc;
select * from leads where crm_configuration_id = 53 order by id desc;
select * from contacts where crm_configuration_id = 53 order by id desc;
select * from opportunities where crm_configuration_id = 53 order by id desc;
select * from crm_profiles where crm_configuration_id = 53 order by id desc;
select * from crm_fields where crm_configuration_id = 53 order by id desc;
select * from crm_field_values where crm_field_id = 3341 order by id desc;
select * from crm_layouts where crm_configuration_id = 53 order by id desc;
select * from stages where crm_configuration_id = 53 order by id desc;
select * from crm_profiles where crm_configuration_id = 13;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 65
and sa.provider = 'integration-app';
select * from contacts where crm_configuration_id = 13;
select * from social_accounts where sociable_id = 283;
SELECT * FROM opportunities WHERE crm_provider_id = '006O400000E9bzeIAB';
select * from activity_providers where team_id = 65;
SELECT * FROM activities WHERE crm_configuration_id IN (51, 52, 53);
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 65
;
# [PASSWORD_DOTS] STAGING [PASSWORD_DOTS]
SELECT * FROM teams;
SELECT * FROM teams WHERE id = 88;
SELECT * FROM teams WHERE id = 89;
select * from team_settings where team_id = 89;
SELECT * FROM users WHERE team_id = 89;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 89;
select * from users;
SELECT * FROM social_accounts WHERE sociable_id = 1761;
SELECT * FROM crm_configurations WHERE id = 70;
select * from accounts where crm_configuration_id = 70 order by id desc;
select * from leads where crm_configuration_id = 70 order by id desc;
select * from contacts where crm_configuration_id = 70 order by id desc;
select * from opportunities where crm_configuration_id = 70 order by id desc;
select * from crm_profiles where crm_configuration_id = 70 order by id desc;
select * from crm_fields where crm_configuration_id = 70 order by id desc;
select * from crm_field_values where crm_field_id = 3536 order by id desc;
select * from crm_layouts where crm_configuration_id = 70 order by id desc;
select * from stages where crm_configuration_id = 70 order by id desc;
select * from business_processes where crm_configuration_id = 70 order by id desc;
select * from business_process_stages where business_process_id = 34;
select * from contacts where id = 10468;
select * from crm_layouts where crm_configuration_id = 70;
SELECT * FROM crm_layout_entities WHERE crm_layout_id = 388;
SELECT * FROM crm_fields WHERE id IN (3533,3534,3535);
select * from activities where crm_configuration_id = 70
and (account_id IS NOT NULL or lead_id IS NOT NULL or contact_id IS NOT NULL or opportunity_id IS NOT NULL) order by id desc;
SELECT * FROM activities WHERE uuid_to_bin('2e10b60f-8a61-41c5-a3d4-28835353dc65') = uuid;
SELECT * FROM activities where crm_configuration_id = 69 ;
SELECT * FROM users WHERE email LIKE '%[EMAIL]%';
SELECT * FROM activities WHERE uuid_to_bin('5a150c93-40fc-42ec-b3bd-c1d328e09f6e') = uuid;
SELECT * FROM opportunities WHERE id = 385;
select * from participants p
join activities a on p.activity_id = a.id
where a.crm_configuration_id = 70
and (p.lead_id IS NOT NULL or p.contact_id IS NOT NULL);
SELECT * FROM participants WHERE id = 1013638;
select * from teams where id = 90;
select * from users where team_id = 90;
select * from social_accounts where social_accounts.sociable_id IN (1960,1760);
SELECT * FROM crm_profiles WHERE crm_configuration_id = 71;
select * from invitations where team_id = 90;
select * from crm_configurations where id = 71;
select * from accounts where crm_configuration_id = 71 order by id desc;
select * from leads where crm_configuration_id = 71 order by id desc;
select * from contacts where crm_configuration_id = 71 order by id desc;
select * from opportunities where crm_configuration_id = 71 order by id desc;
select * from crm_profiles where crm_configuration_id = 71 order by id desc;
select * from crm_fields where crm_configuration_id = 71 order by id desc;
select * from crm_field_values where crm_field_id = 3341 order by id desc;
select * from crm_layouts where crm_configuration_id = 71 order by id desc;
select * from stages where crm_configuration_id = 71 order by id desc;
select * from users order by secondary_email desc;
select u.id, u.email, u.status, sa.id, sa.provider_user_id from social_accounts sa
join users u on sa.sociable_id = u.id
where sa.provider = 'google' and u.email LIKE 'aneliya%';
select * from failed_jobs order by id desc;
select * from users where email = '[EMAIL]' or secondary_email = '[EMAIL]';
select * from teams;
SELECT * FROM crm_profiles WHERE crm_configuration_id = 39;
SELECT * FROM crm_fields WHERE crm_configuration_id = 39 and object_type = 'task';
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 1
and sa.provider = 'salesforce';
# [PASSWORD_DOTS]
SELECT * FROM activities WHERE uuid_to_bin('c38b3895-fd0f-4b1f-9fb2-c170dba137c6') = uuid;
SELECT * FROM crm_configurations WHERE id = 70;
select * from teams where id = 1;
select * from groups where team_id = 1;
select * from users where team_id = 1;
select o.id, o.name,o.close_date, u.id, u.name, u.group_id, r.id, r.display_name, g.name, g.scope from opportunities o
join users u on o.user_id = u.id
join groups g on u.group_id = g.id
join role_user ru on u.id = ru.user_id
join roles r on ru.role_id = r.id
where o.crm_configuration_id = 39 and close_date > '2024-01-01 00:00:00';
select * from role_user where user_id = 143;
select * from roles;
select * from role_user;
select * from groups where id = 9;
select * from scope_groups where group_id = 9;
# [PASSWORD_DOTS]
select * from teams where id = 36;
select * from crm_configurations;
SELECT * FROM social_accounts WHERE sociable_id = 121;
[URL_WITH_CREDENTIALS] this will add filter, however if we need to control feature by FF we need conditional logic
public const array TYPES = [
['id' => 'exec_summary', 'name' => 'Exec Summary'],
['id' => 'coaching_profiles', 'name' => 'Coaching Profiles'],
['id' => 'product_feedback', 'name' => 'Product Feedback'],
['id' => self::TYPE_LOSS_ANALYSIS, 'name' => 'Loss Analysis'],
// ['id' => 'questions', 'name' => 'Questions'],
// ['id' => 'statistical_quant', 'name' => 'Statistical Quantitative'],
];
public const array ALL_TYPES = [
...self::TYPES,
['id' => self::TYPE_ASK_JIMINNY, 'name' => 'Ask Jiminny'],
];
public const string FREQUENCY_DAILY = 'daily';
public const string FREQUENCY_WEEKLY = 'weekly';
public const string FREQUENCY_MONTHLY = 'monthly';
public const string FREQUENCY_QUARTERLY = 'quarterly';
public const string FREQUENCY_ONE_OFF = 'one_off';
/**
* Frequencies for standard (non-Ask Jiminny) reports.
*/
public const array FREQUENCIES = [
['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],
['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],
['id' => self::FREQUENCY_QUARTERLY, 'name' => 'Quarterly'],
['id' => self::FREQUENCY_ONE_OFF, 'name' => 'One-off'],
];
/**
* Frequencies for Ask Jiminny reports.
*/
public const array ASK_JIMINNY_FREQUENCIES = [
['id' => self::FREQUENCY_DAILY, 'name' => 'Daily'],
['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],
['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],
];
public const string MEDIA_TYPE_PDF = 'pdf';
public const string MEDIA_TYPE_PODCAST = 'podcast';
public const array MEDIA_TYPES = [self::MEDIA_TYPE_PDF, self::MEDIA_TYPE_PODCAST];
public const array MEDIA_TYPE_OBJECT_PDF = ['id' => self::MEDIA_TYPE_PDF, 'name' => 'PDF'];
public const array MEDIA_TYPE_OBJECT_PODCAST = ['id' => self::MEDIA_TYPE_PODCAST, 'name' => 'Podcast'];
public const array MEDIA_TYPE_OBJECTS = [self::MEDIA_TYPE_OBJECT_PDF, self::MEDIA_TYPE_OBJECT_PODCAST];
public const array CALL_TYPE_CONFERENCE = ['id' => 'conference', 'name' => 'Conference'];
public const array CALL_TYPE_DIALER = ['id' => 'dialer', 'name' => 'Dialer'];
public const int SENT_REPORT_AT_HOURS = 5;
public const string PDF_KEY = 'pdf';
public const string AUDIO_KEY = 'audio';
private const array ALL_FREQUENCIES = [
['id' => self::FREQUENCY_DAILY, 'name' => 'Daily'],
['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],
['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],
['id' => self::FREQUENCY_QUARTERLY, 'name' => 'Quarterly'],
['id' => self::FREQUENCY_ONE_OFF, 'name' => 'One-off'],
];
private const string S3_DIR = 'reports';
private const array FILE_EXTENSIONS_VARIANTS = ['html', 'MD', 'pdf'];
private const array FILE_PODCAST_EXTENSIONS_VARIANTS = ['json', 'mp3', 'ssml'];
public function __construct(
private readonly TeamRepository $teamRepository,
private readonly GroupRepository $groupRepository,
private readonly UserRepository $userRepository,
private readonly StageRepository $stageRepository,
private readonly DealStagesService $dealStagesService,
private readonly RecipientsService $recipientsService,
private readonly AutomatedReportsRepository $automatedReportsRepository,
private readonly Webhook $webhookService,
private readonly BusDispatcher $dispatcher,
private readonly ActivityTypeService $activityTypeService,
private readonly PlaybookCategoryRepository $playbookCategoryRepository,
private readonly AskAnythingPromptService $askAnythingPromptService,
private readonly SearchRepository $activitySearchRepository,
private readonly AskAnythingRepository $askAnythingRepository,
) {
}
public static function getTypes(): array
{
$types = self::TYPES;
return array_map(static function ($type) {
return $type['id'];
}, $types);
}
public static function getCallTypes(): array
{
return array_map(static function ($callType) {
return $callType['id'];
}, [self::CALL_TYPE_CONFERENCE, self::CALL_TYPE_DIALER]);
}
public static function getFrequencies(): array
{
return array_map(static function ($frequency) {
return $frequency['id'];
}, self::FREQUENCIES);
}
// front-facing structure
public function getReportEnabledFieldData(bool $value = false): array
{
return [
'id' => 'report_enabled',
'label' => '',
'inputType' => InputTypeEnum::TOGGLE,
'value' => $value,
];
}
// Organizations = Teams
public function getOrganizationFieldData(?string $value = null, bool $shortVersion = false): array
{
$options = $this->getTeams();
if ($shortVersion) {
return [
'id' => 'organization',
'label' => 'Organization',
'options' => $options,
];
}
return [
'id' => 'organization',
'label' => 'Organization',
'inputType' => InputTypeEnum::DROPDOWN,
'required' => true,
'placeholder' => 'Select',
'options' => $options,
'value' => $value,
'dependencies' => [
'teams',
'deal_stage_at_call',
'current_deal_stage',
'recipients',
ActivityTypeService::PLAYBOOK_CATEGORIES_KEY,
],
'dependsOn' => [],
];
}
// Teams = Groups
public function getTeamFieldData(array $options = [], array $value = [], bool $shortVersion = false): array
{
if ($shortVersion) {
return [
'id' => 'teams',
'label' => 'Team',
'options' => $options,
];
}
return [
'id' => 'teams',
'label' => 'Team',
'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,
'required' => false,
'placeholder' => 'Select',
'options' => $options,
'value' => $value, // value should be an array of objects {id, name}
'dependencies' => [ActivityTypeService::PLAYBOOK_CATEGORIES_KEY],
'dependsOn' => [],
];
}
public function getReportTypeFieldData(?string $value = null, bool $shortVersion = false, ?Team $team = null): array
{
$types = [];
if ($team instanceof Team) {
if ($team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {
$types = self::TYPES;
}
if ($team->hasFeature(FeatureEnum::ASK_JIMINNY_REPORTS)) {
$types[] = ['id' => self::TYPE_ASK_JIMINNY, 'name' => 'Ask Jiminny'];
}
} else {
$types = self::TYPES;
}
if ($shortVersion) {
return [
'id' => 'report_type',
'label' => 'Report Type',
'options' => $types,
];
}
return [
'id' => 'report_type',
'label' => 'Report Type',
'inputType' => InputTypeEnum::DROPDOWN,
'required' => true,
'placeholder' => 'Select',
'options' => $types,
'value' => $value,
'dependencies' => [],
'dependsOn' => [],
];
}
public function getFrequencyFieldData(?string $value = null): array
{
return [
'id' => 'frequency',
'label' => 'Frequency',
'inputType' => InputTypeEnum::DROPDOWN,
'required' => true,
'placeholder' => 'Select',
'options' => self::FREQUENCIES,
'value' => $value,
'dependencies' => ['period'],
'dependsOn' => [],
];
}
public function getPeriodFieldData(?string $valueStartDate = null, ?string $valueEndDate = null): array
{
return [
'id' => 'period',
'label' => 'Select one-off period',
'inputType' => InputTypeEnum::DATE_RANGE,
'required' => true,
'placeholder' => 'Select',
'value' => ['startDate' => $valueStartDate, 'endDate' => $valueEndDate],
'queryParams' => [
'startDate' => 'start_date_period',
'endDate' => 'end_date_period',
],
'dependencies' => [],
'dependsOn' => ['frequency'],
];
}
public function getActivityTypesFieldData(?Team $team = null, array $value = [], array $teamsFilter = []): array
{
return $this->activityTypeService->getActivityTypeFieldData(team: $team, value: $value, groupIds: $teamsFilter);
}
public function getDealStageAtCallFieldData(?Team $team = null, array $value = []): array
{
return $this->dealStagesService->getDealStageAtCallFieldData(team: $team, value: $value);
}
public function getCurrentDealStageFieldData(?Team $team = null, array $value = []): array
{
return $this->dealStagesService->getCurrentDealStageFieldData(team: $team, value: $value);
}
public function getDealValueFieldData(?int $valueMin = null, ?int $valueMax = null): array
{
return [
'id' => 'deal_value',
'label' => 'Deal Value',
'inputType' => InputTypeEnum::INTEGER_RANGE,
'required' => false,
'value' => ['min' => $valueMin, 'max' => $valueMax],
'queryParams' => [
'min' => 'min_deal_value',
'max' => 'max_deal_value',
],
'dependencies' => [],
'dependsOn' => [],
];
}
public function getCallTypeFieldData(bool $conferenceOn = false, bool $dialerOn = false): array
{
$value = [];
$conferenceOn && $value[] = self::CALL_TYPE_CONFERENCE;
$dialerOn && $value[] = self::CALL_TYPE_DIALER;
return [
'id' => 'call_type',
'label' => 'Call Type',
'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,
'required' => true,
'options' => [
self::CALL_TYPE_CONFERENCE,
self::CALL_TYPE_DIALER,
],
'value' => $value,
'dependencies' => [],
'dependsOn' => [],
];
}
public function getMediaTypeFieldData(?AutomatedReport $report = null): array
{
$value = [];
if ($report) {
$value = $this->transformMediaTypes($report);
}
return [
'id' => 'media_types',
'label' => 'Export as',
'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,
'required' => true,
'options' => self::MEDIA_TYPE_OBJECTS,
'value' => $value,
'dependencies' => [],
'dependsOn' => [],
];
}
public function getCallDurationFieldData(?int $valueMin = null, ?int $valueMax = null): array
{
return [
'id' => 'call_duration',
'label' => 'Call Duration',
'inputType' => InputTypeEnum::INTEGER_RANGE,
'required' => false,
'value' => ['min' => $valueMin, 'max' => $valueMax],
'queryParams' => [
'min' => 'min_call_duration',
'max' => 'max_call_duration',
],
'dependencies' => [],
'dependsOn' => [],
];
}
public function getRecipientsFieldData(?Team $team = null, array $value = []): array
{
return $this->recipientsService->getRecipientsFieldData(team: $team, value: $value);
}
public function getJiminnyRecipientsFieldData(array $value = []): array
{
return $this->recipientsService->getJiminnyRecipientsFieldData($value);
}
public function getAdditionalPromptInputFieldData(?string $value = null): array
{
return [
'id' => 'additional_prompt_input',
'label' => 'Special requirements',
'inputType' => InputTypeEnum::TEXTAREA,
'required' => false,
'placeholder' => 'What should be the focus of the report?',
'value' => $value,
'dependencies' => [],
'dependsOn' => [],
];
}
public function getCustomReportNameFieldData(?string $value = null): array
{
return [
'id' => 'custom_name',
'label' => 'Custom report name',
'inputType' => InputTypeEnum::TEXT,
'required' => false,
'placeholder' => 'Enter custom name',
'value' => $value,
'dependencies' => [],
'dependsOn' => [],
];
}
// data providers
public function getTeams(): array
{
$teams = $this->teamRepository->getTeamsForKiosk(status: Team::STATUS_ACTIVE);
$teamData = [];
foreach ($teams as $team) {
if (! $team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {
continue;
}
$teamData[] = $this->transformTeam($team);
}
return $teamData;
}
public function getTeamGroups(string $teamUuid): array
{
$data = [];
$team = $this->getTeam($teamUuid);
if ($team !== null) {
$groups = $team->groups()->get();
foreach ($groups as $group) {
$data[] = [
'id' => $group->getUuid(),
'name' => $group->getName(),
];
}
}
return $data;
}
public function getTeamsGroupsOptions(array $filterTeamUuids = []): array
{
$data = [];
$teams = $this->getTeams();
foreach ($teams as $team) {
if (! empty($filterTeamUuids) && ! in_array($team['id'], $filterTeamUuids, true)) {
continue;
}
$data[] = [
'label' => $team['name'],
'groups' => $this->getTeamGroups($team['id']),
];
}
return $data;
}
public function getTeam(string $teamUuid): ?Team
{
return $this->teamRepository->idOrUuid($teamUuid);
}
public function getTeamById(int $teamId): ?Team
{
return $this->teamRepository->find($teamId);
}
public function getGroupsUuids(AutomatedReport $report): array
{
$uuids = [];
$reportGroups = $report->getGroups();
foreach ($reportGroups as $groupId) {
if ($group = $this->groupRepository->find($groupId)) {
$uuids[] = $group->getUuid();
}
}
return $uuids;
}
public function getPlaybookCategoriesUuids(AutomatedReport $report): array
{
$uuids = [];
$playbookCategories = $report->getPlaybookCategories();
foreach ($playbookCategories as $id) {
if ($category = $this->playbookCategoryRepository->find($id)) {
$uuids[] = $category->getUuid();
}
}
return $uuids;
}
public function getDealAtCallStagesUuids(AutomatedReport $report): array
{
$uuids = [];
$reportStages = $report->getDealAtCallStages();
foreach ($reportStages as $id) {
if ($stage = $this->stageRepository->find($id)) {
$uuids[] = $stage->getUuid();
}
}
return $uuids;
}
public function getCurrentDealStagesUuids(AutomatedReport $report): array
{
$uuids = [];
$reportStages = $report->getCurrentDealStages();
foreach ($reportStages as $id) {
if ($stage = $this->stageRepository->find($id)) {
$uuids[] = $stage->getUuid();
}
}
return $uuids;
}
public function getUsersUuids(AutomatedReport $report): array
{
return $this->extractUserUuids($report->getRecipients());
}
public function getJiminnyUsersUuids(AutomatedReport $report): array
{
return $this->extractUserUuids($report->getJiminnyRecipients());
}
/**
* @param array<string, mixed> $recipients
*/
private function extractUserUuids(array $recipients): array
{
$userIds = $recipients['users'] ?? [];
return collect($userIds)
->map(fn ($id) => $this->userRepository->find((int) $id))
->filter()
->map(fn (UserContract $user) => $user->getUuid())
->values()
->all();
}
// get mail data
public function getRecipientUsers(AutomatedReport $report): array
{
return $this->buildRecipientUsers($report->getRecipients());
}
private function getJiminnyRecipientUsers(AutomatedReport $report): array
{
return $this->buildRecipientUsers($report->getJiminnyRecipients());
}
/**
* @param array<string, mixed> $recipients
*/
private function buildRecipientUsers(array $recipients): array
{
$userIds = $recipients['users'] ?? [];
return collect($userIds)
->map(fn ($id) => $this->userRepository->find((int) $id))
->filter()
->map(fn (UserContract $user) => [
'email' => $user->getEmailAddress(),
'name' => $user->getName(),
'timezone' => $user->getTimezone()->getName(),
])
->values()
->all();
}
public function getValidRecipientUsers(AutomatedReport $report, bool $includeJiminny = false): array
{
if ($report->isAskJiminnyReport()) {
$recipients = $this->resolveAskJiminnyRecipients($report);
} else {
$recipients = $this->getRecipientUsers($report);
if ($includeJiminny) {
$recipients = array_merge($recipients, $this->getJiminnyRecipientUsers($report));
}
}
$emails = [];
return array_values(array_filter(
$recipients,
static function ($recipient) use (&$emails) {
if (empty($recipient['email']) || in_array($recipient['email'], $emails, true)) {
return false;
}
$emails[] = $recipient['email'];
return true;
}
));
}
private function resolveAskJiminnyRecipients(AutomatedReport $report): array
{
$recipients = [];
$creator = $report->getCreator();
if ($creator !== null) {
$recipients[] = [
'email' => $creator->getEmailAddress(),
'name' => $creator->getName(),
'timezone' => $creator->getTimezone()->getName(),
];
}
return array_merge(
$recipients,
$this->buildRecipientUsers($report->getRecipients()),
$this->getGroupRecipientUsers($report),
);
}
private function getGroupRecipientUsers(AutomatedReport $report): array
{
$users = [];
foreach ($report->getGroups() as $groupId) {
$group = $this->groupRepository->find($groupId);
if ($group === null) {
continue;
}
foreach ($group->getMembers() as $member) {
$users[] = [
'email' => $member->getEmailAddress(),
'name' => $member->getName(),
'timezone' => $member->getTimezone()->getName(),
];
}
}
return $users;
}
public function getReportTypeName(AutomatedReportResult $report): string
{
$type = $report->getReport()->getType();
$getType = $this->transformReportType($type);
return $getType['name'];
}
public function getReportPeriodName(AutomatedReportResult $report): string
{
$from = $report->getFromDate();
$to = $report->getToDate();
$frequency = $report->getReport()->getFrequency();
if ($from === null || $to === null) {
if (! $report->getReport()->isAskJiminnyReport()) {
$invalidPeriod = $from === null ? 'from' : 'to';
throw new ApplicationException('Report period is invalid: ' . $invalidPeriod);
}
$period = $this->calculateFromAndToDatePeriod($frequency);
$from = $period['fromDate'];
$to = $period['toDate'];
}
return $this->formatReportPeriodName($frequency, $from, $to);
}
private function formatReportPeriodName(string $frequency, Carbon $from, Carbon $to): string
{
$fromYear = $from->format('Y');
$toYear = $to->format('Y');
$differentYears = $fromYear !== $toYear;
switch ($frequency) {
case self::FREQUENCY_DAILY:
return $from->format('j M Y');
case self::FREQUENCY_QUARTERLY:
// 'Jan-Mar 2025' or 'Nov 2024-Jan 2025' if years differ
$startMonth = $from->format('M');
$endMonth = $to->copy()->subMonth();
$endMonthName = $endMonth->format('M');
$endMonthYear = $endMonth->format('Y');
if ($differentYears) {
return "{$startMonth} {$fromYear} - {$endMonthName} {$endMonthYear}";
}
return "{$startMonth} - {$endMonthName} {$toYear}";
case self::FREQUENCY_MONTHLY:
// 'May 2025' - monthly reports are always within the same year
return $from->format('M Y');
case self::FREQUENCY_WEEKLY:
// '4 - 8 Aug 2025', '27 Oct - 3 Nov 2025', or '28 Dec 2024 - 3 Jan 2025' if years differ
$startDay = $from->format('j');
$endDay = $to->format('j');
$startMonth = $from->format('M');
$endMonth = $to->format('M');
if ($differentYears) {
return "{$startDay} {$startMonth} {$fromYear} - {$endDay} {$endMonth} {$toYear}";
}
if ($startMonth !== $endMonth) {
return "{$startDay} {$startMonth} - {$endDay} {$endMonth} {$toYear}";
}
return "{$startDay} - {$endDay} {$endMonth} {$toYear}";
case self::FREQUENCY_ONE_OFF:
// '2 May-31 May 2025' or '15 Dec 2024-15 Jan 2025' if years differ
$startDay = $from->format('j');
$startMonth = $from->format('M');
$endDay = $to->format('j');
$endMonth = $to->format('M');
// If same month and year, use a format like '2-31 May 2025'
if ($startMonth === $endMonth && ! $differentYears) {
return "{$startDay} - {$endDay} {$startMonth} {$toYear}";
}
// If different years, include both years
if ($differentYears) {
return "{$startDay} {$startMonth} {$fromYear} - {$endDay} {$endMonth} {$toYear}";
}
// Same year but different months
return "{$startDay} {$startMonth} - {$endDay} {$endMonth} {$toYear}";
default:
// Default format for unknown frequencies
return $from->format('j M Y') . ' - ' . $to->format('j M Y');
}
}
public function getReportTeamsName(AutomatedReportResult $report): string
{
$groups = $report->getGroups();
if (empty($groups)) {
return 'All';
}
// Get group names from repository
$groupNames = [];
foreach ($groups as $groupId) {
$group = $this->groupRepository->find($groupId);
if ($group) {
$groupNames[] = $group->getName();
}
}
if (count($groupNames) === 1) {
// Single team format
$teamsName = $groupNames[0];
} else {
// Multiple teams format
$teamsName = implode(', ', $groupNames);
}
return $teamsName;
}
public function getReportFileName(AutomatedReportResult $report): string
...
|
12331
|
|
12343
|
264
|
0
|
2026-04-14T11:14:47.363905+00:00
|
/Users/lukas/.screenpipe/data/data/2026-04-14/1776 /Users/lukas/.screenpipe/data/data/2026-04-14/1776165287363_m1.jpg...
|
Slack
|
Vasil Vasilev (DM) - Jiminny Inc - 1 new item - Sl Vasil Vasilev (DM) - Jiminny Inc - 1 new item - Slack...
|
1
|
NULL
|
monitor_1
|
NULL
|
NULL
|
NULL
|
NULL
|
Jiminny Inc
Jiminny (Staging)
Add workspaces
Home
Jiminny Inc
Jiminny (Staging)
Add workspaces
Home
Home
DMs
DMs
Activity
Activity
Files
Files
Later
Later
More…
More
Unreads
Threads
Huddles
Drafts & sent
Directories
platform-inner-team
ai-chapter
alerts
backend
confusion-clinic
curiosity_lab
engineering
frontend
general
infra-changes
jiminny-bg
platform-tickets
product_launches
random
releases
sofia-office
support
thank-yous
the_people_of_jiminny
Vasil Vasilev
Aneliya Angelova
,
Nikolay Yankov
,
Steliyan Georgiev
Steliyan Georgiev
Adelina Petrova
,
Ilian Kyuchukov
,
Steliyan Georgiev
Adelina Petrova
Galya Dimitrova
Nikolay Nikolov
Galya Dimitrova
,
Nikolay Nikolov
Galya Dimitrova
,
Nikolay Yankov
Nikolay Yankov
Jira Cloud
Toast
Google Calendar
Messages
Messages
Add canvas
Add canvas
Files
Files
Pins
Pins
Add and Edit Channel Tabs
Canvas
List
Folder
Jump to date
Vasil Vasilev
Apr 8th at 7:33:52 PM
7:33 PM
Лукас, привет
Apr 8th at 7:33:54 PM...
|
[{"role":"AXRadioButton","text [{"role":"AXRadioButton","text":"Jiminny Inc","depth":12,"bounds":{"left":0.4861111,"top":0.08777778,"width":0.022222223,"height":0.035555556},"role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":true,"is_expanded":false},{"role":"AXRadioButton","text":"Jiminny (Staging)","depth":12,"bounds":{"left":0.4861111,"top":0.14555556,"width":0.022222223,"height":0.035555556},"role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXPopUpButton","text":"Add workspaces","depth":12,"bounds":{"left":0.4861111,"top":0.20333333,"width":0.022222223,"height":0.035555556},"role_description":"pop-up button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXRadioButton","text":"Home","depth":14,"bounds":{"left":0.525,"top":0.07777778,"width":0.036111113,"height":0.075555556},"role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":true,"is_expanded":false},{"role":"AXStaticText","text":"Home","depth":16,"bounds":{"left":0.5326389,"top":0.13,"width":0.020833334,"height":0.015555556},"role_description":"text"},{"role":"AXRadioButton","text":"DMs","depth":14,"bounds":{"left":0.525,"top":0.15333334,"width":0.036111113,"height":0.075555556},"role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"DMs","depth":16,"bounds":{"left":0.5347222,"top":0.20555556,"width":0.016666668,"height":0.015555556},"role_description":"text"},{"role":"AXRadioButton","text":"Activity","depth":14,"bounds":{"left":0.525,"top":0.22888888,"width":0.036111113,"height":0.075555556},"role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"Activity","depth":16,"bounds":{"left":0.52916664,"top":0.28111112,"width":0.027083334,"height":0.015555556},"role_description":"text"},{"role":"AXRadioButton","text":"Files","depth":14,"bounds":{"left":0.525,"top":0.30444443,"width":0.036111113,"height":0.075555556},"role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"Files","depth":16,"bounds":{"left":0.5347222,"top":0.35666665,"width":0.015972223,"height":0.015555556},"role_description":"text"},{"role":"AXRadioButton","text":"Later","depth":14,"bounds":{"left":0.525,"top":0.38,"width":0.036111113,"height":0.075555556},"role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"Later","depth":16,"bounds":{"left":0.53402776,"top":0.43222222,"width":0.018055556,"height":0.015555556},"role_description":"text"},{"role":"AXRadioButton","text":"More…","depth":14,"bounds":{"left":0.525,"top":0.45555556,"width":0.036111113,"height":0.075555556},"role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"More","depth":16,"bounds":{"left":0.53333336,"top":0.50777775,"width":0.01875,"height":0.015555556},"role_description":"text"},{"role":"AXStaticText","text":"Unreads","depth":21,"bounds":{"left":0.5951389,"top":0.12777779,"width":0.038194444,"height":0.0011111111},"role_description":"text"},{"role":"AXStaticText","text":"Threads","depth":21,"bounds":{"left":0.5951389,"top":0.12777779,"width":0.036805555,"height":0.0011111111},"role_description":"text"},{"role":"AXStaticText","text":"Huddles","depth":21,"bounds":{"left":0.5951389,"top":0.12777779,"width":0.038194444,"height":0.0011111111},"role_description":"text"},{"role":"AXStaticText","text":"Drafts & sent","depth":21,"bounds":{"left":0.5951389,"top":0.12777779,"width":0.06111111,"height":0.0011111111},"role_description":"text"},{"role":"AXStaticText","text":"Directories","depth":21,"bounds":{"left":0.5951389,"top":0.12777779,"width":0.050694443,"height":0.0011111111},"role_description":"text"},{"role":"AXStaticText","text":"platform-inner-team","depth":23,"bounds":{"left":0.60625,"top":0.12777779,"width":0.093055554,"height":0.0011111111},"role_description":"text"},{"role":"AXStaticText","text":"ai-chapter","depth":23,"bounds":{"left":0.60625,"top":0.12777779,"width":0.046527777,"height":0.0011111111},"role_description":"text"},{"role":"AXStaticText","text":"alerts","depth":23,"bounds":{"left":0.60625,"top":0.12777779,"width":0.025694445,"height":0.0011111111},"role_description":"text"},{"role":"AXStaticText","text":"backend","depth":23,"bounds":{"left":0.60625,"top":0.12777779,"width":0.038194444,"height":0.0011111111},"role_description":"text"},{"role":"AXStaticText","text":"confusion-clinic","depth":23,"bounds":{"left":0.60625,"top":0.12777779,"width":0.072222225,"height":0.0011111111},"role_description":"text"},{"role":"AXStaticText","text":"curiosity_lab","depth":23,"bounds":{"left":0.60625,"top":0.12777779,"width":0.057638887,"height":0.0011111111},"role_description":"text"},{"role":"AXStaticText","text":"engineering","depth":23,"bounds":{"left":0.60625,"top":0.12777779,"width":0.054166667,"height":0.0011111111},"role_description":"text"},{"role":"AXStaticText","text":"frontend","depth":23,"bounds":{"left":0.60625,"top":0.12777779,"width":0.04027778,"height":0.0011111111},"role_description":"text"},{"role":"AXStaticText","text":"general","depth":23,"bounds":{"left":0.60625,"top":0.12777779,"width":0.034027778,"height":0.007777778},"role_description":"text"},{"role":"AXStaticText","text":"infra-changes","depth":23,"bounds":{"left":0.60625,"top":0.14666666,"width":0.061805554,"height":0.02},"role_description":"text"},{"role":"AXStaticText","text":"jiminny-bg","depth":23,"bounds":{"left":0.60625,"top":0.17777778,"width":0.048611112,"height":0.02},"role_description":"text"},{"role":"AXStaticText","text":"platform-tickets","depth":23,"bounds":{"left":0.60625,"top":0.20888889,"width":0.072916664,"height":0.02},"role_description":"text"},{"role":"AXStaticText","text":"product_launches","depth":23,"bounds":{"left":0.60625,"top":0.24,"width":0.08055556,"height":0.02},"role_description":"text"},{"role":"AXStaticText","text":"random","depth":23,"bounds":{"left":0.60625,"top":0.2711111,"width":0.035416666,"height":0.02},"role_description":"text"},{"role":"AXStaticText","text":"releases","depth":23,"bounds":{"left":0.60625,"top":0.30222222,"width":0.036805555,"height":0.02},"role_description":"text"},{"role":"AXStaticText","text":"sofia-office","depth":23,"bounds":{"left":0.60625,"top":0.33333334,"width":0.05138889,"height":0.02},"role_description":"text"},{"role":"AXStaticText","text":"support","depth":23,"bounds":{"left":0.60625,"top":0.36444443,"width":0.036111113,"height":0.02},"role_description":"text"},{"role":"AXStaticText","text":"thank-yous","depth":23,"bounds":{"left":0.60625,"top":0.39555556,"width":0.05138889,"height":0.02},"role_description":"text"},{"role":"AXStaticText","text":"the_people_of_jiminny","depth":23,"bounds":{"left":0.60625,"top":0.42666668,"width":0.094444446,"height":0.02},"role_description":"text"},{"role":"AXStaticText","text":"Vasil Vasilev","depth":23,"bounds":{"left":0.60625,"top":0.5,"width":0.055555556,"height":0.02},"role_description":"text"},{"role":"AXStaticText","text":"Aneliya Angelova","depth":23,"bounds":{"left":0.60625,"top":0.5311111,"width":0.07847222,"height":0.02},"role_description":"text"},{"role":"AXStaticText","text":",","depth":23,"bounds":{"left":0.68472224,"top":0.5311111,"width":0.013194445,"height":0.02},"role_description":"text"},{"role":"AXStaticText","text":"Nikolay Yankov","depth":23,"bounds":{"left":0.68958336,"top":0.5311111,"width":0.029861111,"height":0.02},"role_description":"text"},{"role":"AXStaticText","text":",","depth":23,"role_description":"text"},{"role":"AXStaticText","text":"Steliyan Georgiev","depth":23,"role_description":"text"},{"role":"AXStaticText","text":"Steliyan Georgiev","depth":23,"bounds":{"left":0.60625,"top":0.56222224,"width":0.07986111,"height":0.02},"role_description":"text"},{"role":"AXStaticText","text":"Adelina Petrova","depth":23,"bounds":{"left":0.60625,"top":0.5933333,"width":0.072222225,"height":0.02},"role_description":"text"},{"role":"AXStaticText","text":",","depth":23,"bounds":{"left":0.67777777,"top":0.5933333,"width":0.0055555557,"height":0.02},"role_description":"text"},{"role":"AXStaticText","text":"Ilian Kyuchukov","depth":23,"bounds":{"left":0.68333334,"top":0.5933333,"width":0.015972223,"height":0.02},"role_description":"text"},{"role":"AXStaticText","text":",","depth":23,"role_description":"text"},{"role":"AXStaticText","text":"Steliyan Georgiev","depth":23,"role_description":"text"},{"role":"AXStaticText","text":"Adelina Petrova","depth":23,"bounds":{"left":0.60625,"top":0.6244444,"width":0.072222225,"height":0.02},"role_description":"text"},{"role":"AXStaticText","text":"Galya Dimitrova","depth":23,"bounds":{"left":0.60625,"top":0.65555555,"width":0.07361111,"height":0.02},"role_description":"text"},{"role":"AXStaticText","text":"Nikolay Nikolov","depth":23,"bounds":{"left":0.60625,"top":0.68666667,"width":0.07152778,"height":0.02},"role_description":"text"},{"role":"AXStaticText","text":"Galya Dimitrova","depth":23,"bounds":{"left":0.60625,"top":0.7177778,"width":0.07361111,"height":0.02},"role_description":"text"},{"role":"AXStaticText","text":",","depth":23,"bounds":{"left":0.6791667,"top":0.7177778,"width":0.0055555557,"height":0.02},"role_description":"text"},{"role":"AXStaticText","text":"Nikolay Nikolov","depth":23,"bounds":{"left":0.68472224,"top":0.7177778,"width":0.018055556,"height":0.02},"role_description":"text"},{"role":"AXStaticText","text":"Galya Dimitrova","depth":23,"bounds":{"left":0.60625,"top":0.7488889,"width":0.07361111,"height":0.02},"role_description":"text"},{"role":"AXStaticText","text":",","depth":23,"bounds":{"left":0.6791667,"top":0.7488889,"width":0.0055555557,"height":0.02},"role_description":"text"},{"role":"AXStaticText","text":"Nikolay Yankov","depth":23,"bounds":{"left":0.68472224,"top":0.7488889,"width":0.018055556,"height":0.02},"role_description":"text"},{"role":"AXStaticText","text":"Nikolay Yankov","depth":23,"bounds":{"left":0.60625,"top":0.78,"width":0.06875,"height":0.02},"role_description":"text"},{"role":"AXStaticText","text":"Jira Cloud","depth":23,"bounds":{"left":0.60625,"top":0.85333335,"width":0.045833334,"height":0.02},"role_description":"text"},{"role":"AXStaticText","text":"Toast","depth":23,"bounds":{"left":0.60625,"top":0.8844444,"width":0.024305556,"height":0.02},"role_description":"text"},{"role":"AXStaticText","text":"Google Calendar","depth":23,"bounds":{"left":0.60625,"top":0.91555554,"width":0.06388889,"height":0.02},"role_description":"text"},{"role":"AXRadioButton","text":"Messages","depth":17,"bounds":{"left":0.73125,"top":0.12777779,"width":0.06458333,"height":0.04222222},"role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":true,"is_expanded":false},{"role":"AXStaticText","text":"Messages","depth":19,"bounds":{"left":0.75069445,"top":0.14,"width":0.039583333,"height":0.017777778},"role_description":"text"},{"role":"AXRadioButton","text":"Add canvas","depth":18,"bounds":{"left":0.79791665,"top":0.12777779,"width":0.07152778,"height":0.04222222},"role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"Add canvas","depth":20,"bounds":{"left":0.8173611,"top":0.14,"width":0.046527777,"height":0.017777778},"role_description":"text"},{"role":"AXRadioButton","text":"Files","depth":17,"bounds":{"left":0.8715278,"top":0.12777779,"width":0.04375,"height":0.04222222},"role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"Files","depth":19,"bounds":{"left":0.8909722,"top":0.14,"width":0.01875,"height":0.017777778},"role_description":"text"},{"role":"AXRadioButton","text":"Pins","depth":17,"bounds":{"left":0.91805553,"top":0.12777779,"width":0.04236111,"height":0.04222222},"role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"Pins","depth":19,"bounds":{"left":0.9375,"top":0.14,"width":0.017361112,"height":0.017777778},"role_description":"text"},{"role":"AXPopUpButton","text":"Add and Edit Channel Tabs","depth":17,"bounds":{"left":0.9625,"top":0.12777779,"width":0.022916667,"height":0.04222222},"role_description":"pop-up button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"Canvas","depth":17,"role_description":"text"},{"role":"AXStaticText","text":"List","depth":17,"role_description":"text"},{"role":"AXStaticText","text":"Folder","depth":17,"role_description":"text"},{"role":"AXPopUpButton","text":"Jump to date","depth":23,"bounds":{"left":0.80138886,"top":0.17666666,"width":0.114583336,"height":0.031111112},"role_description":"pop-up button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Vasil Vasilev","depth":24,"bounds":{"left":0.76458335,"top":0.16111112,"width":0.057638887,"height":0.0011111111},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"","depth":24,"bounds":{"left":0.82222223,"top":0.16111112,"width":0.0055555557,"height":0.0011111111},"role_description":"text"},{"role":"AXLink","text":"Apr 8th at 7:33:52 PM","depth":24,"bounds":{"left":0.82708335,"top":0.16111112,"width":0.031944446,"height":0.0011111111},"role_description":"link","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"7:33 PM","depth":25,"bounds":{"left":0.82708335,"top":0.16111112,"width":0.031944446,"height":0.0011111111},"role_description":"text"},{"role":"AXStaticText","text":"Лукас, привет","depth":25,"bounds":{"left":0.76458335,"top":0.16111112,"width":0.06736111,"height":0.0011111111},"role_description":"text"},{"role":"AXLink","text":"Apr 8th at 7:33:54 PM","depth":25,"bounds":{"left":0.7423611,"top":0.16111112,"width":0.016666668,"height":0.0011111111},"role_description":"link","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false}]...
|
-1654369245267095013
|
-4055220299034420471
|
idle
|
hybrid
|
NULL
|
Jiminny Inc
Jiminny (Staging)
Add workspaces
Home
Jiminny Inc
Jiminny (Staging)
Add workspaces
Home
Home
DMs
DMs
Activity
Activity
Files
Files
Later
Later
More…
More
Unreads
Threads
Huddles
Drafts & sent
Directories
platform-inner-team
ai-chapter
alerts
backend
confusion-clinic
curiosity_lab
engineering
frontend
general
infra-changes
jiminny-bg
platform-tickets
product_launches
random
releases
sofia-office
support
thank-yous
the_people_of_jiminny
Vasil Vasilev
Aneliya Angelova
,
Nikolay Yankov
,
Steliyan Georgiev
Steliyan Georgiev
Adelina Petrova
,
Ilian Kyuchukov
,
Steliyan Georgiev
Adelina Petrova
Galya Dimitrova
Nikolay Nikolov
Galya Dimitrova
,
Nikolay Nikolov
Galya Dimitrova
,
Nikolay Yankov
Nikolay Yankov
Jira Cloud
Toast
Google Calendar
Messages
Messages
Add canvas
Add canvas
Files
Files
Pins
Pins
Add and Edit Channel Tabs
Canvas
List
Folder
Jump to date
Vasil Vasilev
Apr 8th at 7:33:52 PM
7:33 PM
Лукас, привет
Apr 8th at 7:33:54 PM
SlackFileEditViewGoHistoryWindowHelpec2-userGDOCKER981DEV (docker)882APP (-zsh)[EMAIL]@73b64f5d54a3:/home/jiminny#[ec2-user@ip-10-30-93-249 ~]$ dockerexec -it $(dockny && bash"root@c78a087b1345:/home/Jiminny# php artisan automated-reports[2026-04-14 10:46:08] staging.INF0: [automated-reports] Started{"correlation_id":"5[2026-04-1410:46:08]staging.INFO: [automated-reports] Checking conditions {"isMondaid":"5c23e861-2ca9-4f92-9f67-773d6bc80ca0","trace_id" :"185df6f6-4327-4609-9cZe-2ab83a[2026-04-14 10:46:08]ab83a0f5432"}staging.INFO: [automated-reports] Processing daily reports{"c[2026-04-1410:46:08]9-9c2e-2ab83a0f5432"}staging.INFO: [automated-reports]Found 3 daily reports to proc[2026-04-1410:46:087daily"staging.INFO: [automated-reports]Dispatching Generate Report j,"type":"ask_jiminny"} {"correlation_id":"5c23e861-2ca9-4f92-9f67-773d6bc80ca®"[2026-04-14 10:46:08]staging.INFO: [automated-reports]Dispatching Generate Report jdaily", "type": "ask_jiminny"} {"correlation_id":"5c23e861-2ca9-4f92-9f67-773d6bc80cab"[2026-04-14 10:46:08]staging. INFO: [automated-reports]daily'", "type" "ask-_fiminny"') ("correlation-id : 5c2se861-2ca9-4h32-9f62-1736be80ca *[2026-04-14 10:46:08]staging.INFO: [automated-reports]Completed{"correlation_id":root@c78a087b1345:/home/jiminny# phpartisanautomated-reports --report-id 35[2026-04-14 10:48:42] staging.INFO: [automated-reports]Started{"correlation_id":"2[2026-04-1410:48:42]staging.INFO: [automated-reports]Checking conditions {"isMondaid":"246a1ala-7076-458c-bd7d-49d2f5a2db88","trace_id" : "1f894bf6-e50d-4e99-b635-2aa526[2026-04-14 10:48:42]staging.INFO: [automated-reports]Processing daily reports{"caa52627fc27"}[automated-reports] Automated report[2026-04-1410:48:42]staging.INFO: [automated-reports] Found 1 daily reports to proc9-b635-2aa52627f c27"}[2026-04-14 10:48:42]staging.INF0: [automated-reports]Dispatching Generate Reportdaily","type": "ask_jiminny"} {"correlation_id":"246a1a1a-7076-458c-bd7d-49d2f5a2db88"[2026-04-14 10:48:42]staging.INFO: [automated-reports]Completed {"correlation_id":root@c78a087b1345:/home/jiminny#|+HomeDMsActivityFilesLater.*•MorelhlJiminny ...+tscnicrol# infra-changes# jiminny-bg# platform-tickets# product_launches# random# releases# sofia-office# support# thank-yous# the_people_of jimi...Direct messagesE. Vasil VasilevAneliya Angelova, ...Steliyan GeorgievAdelina Petrova, Ili...0. Adelina Petrova. Galya Dimitrova *&s Nikolay Nikolov "2Galya Dimitrova, Ni...2Galya Dimitrova, Ni...P. Nikolay Yankov::: AppsJira CloudToastGoogle Cale...§ Support Daily • in 46 m100% <7Tue 14 Apr 14:14:56→Search Jiminny IncVasil VasilevMessagesAdd canvasC Files< Pins+Vasil Va*Wednesday, April 8th~благодариThursday, April 9th~Vasil Vasilev 12:08 PMЛукаш, приветhttps://github.com/jiminny/app/pull/11928трябва ми един approve, моляправя fine tuning на настойките засинхронизация на мейлиLukas Kovalik 12:11 PMготовоVasil Vasilev 12:11 PMблагодаряToday ~NewVasil Vasilev 2:01 PMЛукаш приветможе ли да разглдаш този ПР като имашмалко време:https://github.com/jiminny/app/pull/11949повечето промени са семантични, не сафункционалниразделям по голям ПР на две частиMessage Vasil Vasilfy...
|
12331
|
|
12344
|
264
|
1
|
2026-04-14T11:14:58.322481+00:00
|
/Users/lukas/.screenpipe/data/data/2026-04-14/1776 /Users/lukas/.screenpipe/data/data/2026-04-14/1776165298322_m1.jpg...
|
NULL
|
NULL
|
1
|
NULL
|
monitor_1
|
NULL
|
NULL
|
NULL
|
NULL
|
SlackFileEditViewGoHistoryWindowHelpec2-userGDOCKE SlackFileEditViewGoHistoryWindowHelpec2-userGDOCKER0 81DEV (docker)882APP (-zsh)[EMAIL]@73b64f5d54a3:/home/jiminny#[ec2-user@ip-10-30-93-249 ~]$ dockerexec -it $(dockny && bash"root@c78a087b1345:/home/Jiminny# php artisan automated-reports[2026-04-14 10:46:08]staging.INFO: [automated-reports] Started{"correlation_id":"5[2026-04-1410:46:08]staging.INFO: [automated-reports] Checking conditions {"isMondaid":"5c23e861-2ca9-4f92-9f67-773d6bc80ca0","trace_id" :"185df6f6-4327-4609-9cZe-2ab83a[2026-04-14 10:46:08]ab83a0f5432"}staging.INFO: [automated-reports] Processing daily reports{"c[2026-04-1410:46:08]9-9c2Ze-2ab83a0f5432"}staging.INFO: [automated-reports]Found 3 daily reports to proc[2026-04-1410:46:087daily"staging.INFO: [automated-reports]Dispatching Generate Report j,"type":"ask_jiminny"} {"correlation_id":"5c23e861-2ca9-4f92-9f67-773d6bc80ca0"[2026-04-14 10:46:08]staging.INFO: [automated-reports]Dispatching Generate Report jdaily", "type": "ask_jiminny"} {"correlation_id":"5c23e861-2ca9-4f92-9f67-773d6bc80cab"[2026-04-14 10:46:08]staging. INFO: [automated-reports]daily'", "type" "ask-fiminny"'} ("correlation-id' : 5c2se861-2ca -4792-9f87-773 e8oca[2026-04-14 10:46:08]staging.INFO: [automated-reports]Completed{"correlation_id":root@c78a087b1345:/home/jiminny# phpartisanautomated-reports --report-id 35[2026-04-14 10:48:42] staging.INFO: [automated-reports]Started{"correlation_id":"2[2026-04-1410:48:42]staging.INFO: [automated-reports]Checking conditions {"isMondaid":"246a1ala-7076-458c-bd7d-49d2f5a2db88","trace_id" : "1f894bf6-e50d-4e99-b635-2aa526[2026-04-14 10:48:42]staging.INFO: [automated-reports]Processing daily reportsaa52627fc27"}{"c[automated-reports] Automated report[2026-04-1410:48:42]staging.INFO: [automated-reports] Found 1 daily reports to proc9-b635-2aa52627f c27"}[2026-04-14 10:48:42]staging.INF0: [automated-reports]Dispatching Generate Reportdaily","type": "ask_jiminny"} {"correlation_id":"246a1a1a-7076-458c-bd7d-49d2f5a2db88"[2026-04-14 10:48:42]staging.INFO: [automated-reports]Completed {"correlation_id":root@c78a087b1345:/home/jiminny#|+HomeDMsActivityFilesLater.*•MorelhlJiminny ...+tscnicrol# infra-changes# jiminny-bg# platform-tickets# product_launches# random# releases# sofia-office# support# thank-yous# the_people_of jimi...Direct messagesE. Vasil VasilevAneliya Angelova, ...Steliyan GeorgievAdelina Petrova, Ili...0. Adelina Petrova. Galya Dimitrova *&s Nikolay Nikolov "2Galya Dimitrova, Ni...2Galya Dimitrova, Ni...P. Nikolay Yankov::: AppsJira CloudToastGoogle Cale...§ Support Daily • in 46 m100% <7Tue 14 Apr 14:14:59→Search Jiminny IncVasil VasilevMessagesAdd canvasC Files< Pins+Vasil Va*Wednesday, April 8th~благодариThursday, April 9th~Vasil Vasilev 12:08 PMЛукаш, приветhttps://github.com/jiminny/app/pull/11928трябва ми един approve, моляправя fine tuning на настойките засинхронизация на мейлиLukas Kovalik 12:11 PMготовоVasil Vasilev 12:11 PMблагодаряToday ~NewVasil Vasilev 2:01 PMЛукаш приветможе лмалко в,https://gози ПР като имашTaking a look...2:01 повечето промени са семантични, не сафункционалниразделям по голям ПР на две частиMessage Vasil VasilevAa...
|
NULL
|
1276754187996074974
|
NULL
|
click
|
ocr
|
NULL
|
SlackFileEditViewGoHistoryWindowHelpec2-userGDOCKE SlackFileEditViewGoHistoryWindowHelpec2-userGDOCKER0 81DEV (docker)882APP (-zsh)[EMAIL]@73b64f5d54a3:/home/jiminny#[ec2-user@ip-10-30-93-249 ~]$ dockerexec -it $(dockny && bash"root@c78a087b1345:/home/Jiminny# php artisan automated-reports[2026-04-14 10:46:08]staging.INFO: [automated-reports] Started{"correlation_id":"5[2026-04-1410:46:08]staging.INFO: [automated-reports] Checking conditions {"isMondaid":"5c23e861-2ca9-4f92-9f67-773d6bc80ca0","trace_id" :"185df6f6-4327-4609-9cZe-2ab83a[2026-04-14 10:46:08]ab83a0f5432"}staging.INFO: [automated-reports] Processing daily reports{"c[2026-04-1410:46:08]9-9c2Ze-2ab83a0f5432"}staging.INFO: [automated-reports]Found 3 daily reports to proc[2026-04-1410:46:087daily"staging.INFO: [automated-reports]Dispatching Generate Report j,"type":"ask_jiminny"} {"correlation_id":"5c23e861-2ca9-4f92-9f67-773d6bc80ca0"[2026-04-14 10:46:08]staging.INFO: [automated-reports]Dispatching Generate Report jdaily", "type": "ask_jiminny"} {"correlation_id":"5c23e861-2ca9-4f92-9f67-773d6bc80cab"[2026-04-14 10:46:08]staging. INFO: [automated-reports]daily'", "type" "ask-fiminny"'} ("correlation-id' : 5c2se861-2ca -4792-9f87-773 e8oca[2026-04-14 10:46:08]staging.INFO: [automated-reports]Completed{"correlation_id":root@c78a087b1345:/home/jiminny# phpartisanautomated-reports --report-id 35[2026-04-14 10:48:42] staging.INFO: [automated-reports]Started{"correlation_id":"2[2026-04-1410:48:42]staging.INFO: [automated-reports]Checking conditions {"isMondaid":"246a1ala-7076-458c-bd7d-49d2f5a2db88","trace_id" : "1f894bf6-e50d-4e99-b635-2aa526[2026-04-14 10:48:42]staging.INFO: [automated-reports]Processing daily reportsaa52627fc27"}{"c[automated-reports] Automated report[2026-04-1410:48:42]staging.INFO: [automated-reports] Found 1 daily reports to proc9-b635-2aa52627f c27"}[2026-04-14 10:48:42]staging.INF0: [automated-reports]Dispatching Generate Reportdaily","type": "ask_jiminny"} {"correlation_id":"246a1a1a-7076-458c-bd7d-49d2f5a2db88"[2026-04-14 10:48:42]staging.INFO: [automated-reports]Completed {"correlation_id":root@c78a087b1345:/home/jiminny#|+HomeDMsActivityFilesLater.*•MorelhlJiminny ...+tscnicrol# infra-changes# jiminny-bg# platform-tickets# product_launches# random# releases# sofia-office# support# thank-yous# the_people_of jimi...Direct messagesE. Vasil VasilevAneliya Angelova, ...Steliyan GeorgievAdelina Petrova, Ili...0. Adelina Petrova. Galya Dimitrova *&s Nikolay Nikolov "2Galya Dimitrova, Ni...2Galya Dimitrova, Ni...P. Nikolay Yankov::: AppsJira CloudToastGoogle Cale...§ Support Daily • in 46 m100% <7Tue 14 Apr 14:14:59→Search Jiminny IncVasil VasilevMessagesAdd canvasC Files< Pins+Vasil Va*Wednesday, April 8th~благодариThursday, April 9th~Vasil Vasilev 12:08 PMЛукаш, приветhttps://github.com/jiminny/app/pull/11928трябва ми един approve, моляправя fine tuning на настойките засинхронизация на мейлиLukas Kovalik 12:11 PMготовоVasil Vasilev 12:11 PMблагодаряToday ~NewVasil Vasilev 2:01 PMЛукаш приветможе лмалко в,https://gози ПР като имашTaking a look...2:01 повечето промени са семантични, не сафункционалниразделям по голям ПР на две частиMessage Vasil VasilevAa...
|
NULL
|
|
12345
|
264
|
2
|
2026-04-14T11:15:01.095505+00:00
|
/Users/lukas/.screenpipe/data/data/2026-04-14/1776 /Users/lukas/.screenpipe/data/data/2026-04-14/1776165301095_m1.jpg...
|
Firefox
|
Work — Mozilla Firefox
|
1
|
github.com/jiminny/app/pull/11949
|
monitor_1
|
NULL
|
NULL
|
NULL
|
NULL
|
JY-20543 add AJ reports User pilot tracking by Lak JY-20543 add AJ reports User pilot tracking by LakyLak · Pull Request #11932 · jiminny/app
Pipelines - jiminny/app
Feed — jiminny — Sentry
Platform Sprint 1 Q2 - Platform Team - Scrum Board - Jira
Platform Sprint 1 Q2 - Platform Team - Scrum Board - Jira
JY-20543 add AJ reports User pilot tracking by LakyLak · Pull Request #11932 · jiminny/app
JY-20543 add AJ reports User pilot tracking by LakyLak · Pull Request #11932 · jiminny/app
Configure SSH access to multiple environment - Engineering - Confluence
Configure SSH access to multiple environment - Engineering - Confluence
Console Home | Console Home | us-east-2
Console Home | Console Home | us-east-2
SecurityGroup | EC2 | us-east-2
SecurityGroup | EC2 | us-east-2
JY-20543 add AJ reports User pilot tracking by LakyLak · Pull Request #11932 · jiminny/app
JY-20543 add AJ reports User pilot tracking by LakyLak · Pull Request #11932 · jiminny/app
SRD-6779 | JY-20632 | Unable to log in to Sidekick with SSO by yalokin-jiminny · Pull Request #11935 · jiminny/app
SRD-6779 | JY-20632 | Unable to log in to Sidekick with SSO by yalokin-jiminny · Pull Request #11935 · jiminny/app
Jy 19798 evaluation for ai activity types by nikolaybiaivanov · Pull Request #468 · jiminny/prophet
Jy 19798 evaluation for ai activity types by nikolaybiaivanov · Pull Request #468 · jiminny/prophet
Jiminny
Jiminny
Ask Jiminny test report - 8 Apr 2026 - Ask Jiminny test report - 13 Apr 2026.pdf
Ask Jiminny test report - 8 Apr 2026 - Ask Jiminny test report - 13 Apr 2026.pdf
Service-Desk - Queues - Platform team - Service space - Jira
Service-Desk - Queues - Platform team - Service space - Jira
JY-20543 add AJ reports User pilot tracking by LakyLak · Pull Request #11932 · jiminny/app
JY-20543 add AJ reports User pilot tracking by LakyLak · Pull Request #11932 · jiminny/app
Configure SSH access to multiple environment - Engineering - Confluence
Configure SSH access to multiple environment - Engineering - Confluence
New Tab
New Tab
CloudWatch | us-east-2
CloudWatch | us-east-2
github.com/jiminny/app/pull/11949
github.com/jiminny/app/pull/11949
Close tab
New Tab
Customize sidebar
Open Google Gemini (⌃X)
Tabs from other devices
Open history (⇧⌘H)
Open bookmarks (⌘B)
Waiting for github.com…...
|
[{"role":"AXRadioButton","text [{"role":"AXRadioButton","text":"JY-20543 add AJ reports User pilot tracking by LakyLak · Pull Request #11932 · jiminny/app","depth":4,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXRadioButton","text":"Pipelines - jiminny/app","depth":4,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXRadioButton","text":"Feed — jiminny — Sentry","depth":4,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXRadioButton","text":"Platform Sprint 1 Q2 - Platform Team - Scrum Board - Jira","depth":4,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Platform Sprint 1 Q2 - Platform Team - Scrum Board - Jira","depth":5,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"JY-20543 add AJ reports User pilot tracking by LakyLak · Pull Request #11932 · jiminny/app","depth":4,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"JY-20543 add AJ reports User pilot tracking by LakyLak · Pull Request #11932 · jiminny/app","depth":5,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Configure SSH access to multiple environment - Engineering - Confluence","depth":4,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Configure SSH access to multiple environment - Engineering - Confluence","depth":5,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Console Home | Console Home | us-east-2","depth":4,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Console Home | Console Home | us-east-2","depth":5,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"SecurityGroup | EC2 | us-east-2","depth":4,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"SecurityGroup | EC2 | us-east-2","depth":5,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"JY-20543 add AJ reports User pilot tracking by LakyLak · Pull Request #11932 · jiminny/app","depth":4,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"JY-20543 add AJ reports User pilot tracking by LakyLak · Pull Request #11932 · jiminny/app","depth":5,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"SRD-6779 | JY-20632 | Unable to log in to Sidekick with SSO by yalokin-jiminny · Pull Request #11935 · jiminny/app","depth":4,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"SRD-6779 | JY-20632 | Unable to log in to Sidekick with SSO by yalokin-jiminny · Pull Request #11935 · jiminny/app","depth":5,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Jy 19798 evaluation for ai activity types by nikolaybiaivanov · Pull Request #468 · jiminny/prophet","depth":4,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Jy 19798 evaluation for ai activity types by nikolaybiaivanov · Pull Request #468 · jiminny/prophet","depth":5,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Jiminny","depth":4,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Jiminny","depth":5,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Ask Jiminny test report - 8 Apr 2026 - Ask Jiminny test report - 13 Apr 2026.pdf","depth":4,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Ask Jiminny test report - 8 Apr 2026 - Ask Jiminny test report - 13 Apr 2026.pdf","depth":5,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Service-Desk - Queues - Platform team - Service space - Jira","depth":4,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Service-Desk - Queues - Platform team - Service space - Jira","depth":5,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"JY-20543 add AJ reports User pilot tracking by LakyLak · Pull Request #11932 · jiminny/app","depth":4,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"JY-20543 add AJ reports User pilot tracking by LakyLak · Pull Request #11932 · jiminny/app","depth":5,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Configure SSH access to multiple environment - Engineering - Confluence","depth":4,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Configure SSH access to multiple environment - Engineering - Confluence","depth":5,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"New Tab","depth":4,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"New Tab","depth":5,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"CloudWatch | us-east-2","depth":4,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"CloudWatch | us-east-2","depth":5,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"github.com/jiminny/app/pull/11949","depth":4,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":true},{"role":"AXStaticText","text":"github.com/jiminny/app/pull/11949","depth":5,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"Close tab","depth":5,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXButton","text":"New Tab","depth":4,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXCheckBox","text":"Customize sidebar","depth":6,"help_text":"","role_description":"toggle button","subrole":"AXToggle","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXCheckBox","text":"Open Google Gemini (⌃X)","depth":6,"help_text":"","role_description":"toggle button","subrole":"AXToggle","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXCheckBox","text":"Tabs from other devices","depth":6,"help_text":"","role_description":"toggle button","subrole":"AXToggle","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXCheckBox","text":"Open history (⇧⌘H)","depth":6,"help_text":"","role_description":"toggle button","subrole":"AXToggle","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXCheckBox","text":"Open bookmarks (⌘B)","depth":6,"help_text":"","role_description":"toggle button","subrole":"AXToggle","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Waiting for github.com…","depth":5,"help_text":"","role_description":"text","subrole":"AXUnknown"}]...
|
-6262373749270935117
|
1375657960978118862
|
visual_change
|
accessibility
|
NULL
|
JY-20543 add AJ reports User pilot tracking by Lak JY-20543 add AJ reports User pilot tracking by LakyLak · Pull Request #11932 · jiminny/app
Pipelines - jiminny/app
Feed — jiminny — Sentry
Platform Sprint 1 Q2 - Platform Team - Scrum Board - Jira
Platform Sprint 1 Q2 - Platform Team - Scrum Board - Jira
JY-20543 add AJ reports User pilot tracking by LakyLak · Pull Request #11932 · jiminny/app
JY-20543 add AJ reports User pilot tracking by LakyLak · Pull Request #11932 · jiminny/app
Configure SSH access to multiple environment - Engineering - Confluence
Configure SSH access to multiple environment - Engineering - Confluence
Console Home | Console Home | us-east-2
Console Home | Console Home | us-east-2
SecurityGroup | EC2 | us-east-2
SecurityGroup | EC2 | us-east-2
JY-20543 add AJ reports User pilot tracking by LakyLak · Pull Request #11932 · jiminny/app
JY-20543 add AJ reports User pilot tracking by LakyLak · Pull Request #11932 · jiminny/app
SRD-6779 | JY-20632 | Unable to log in to Sidekick with SSO by yalokin-jiminny · Pull Request #11935 · jiminny/app
SRD-6779 | JY-20632 | Unable to log in to Sidekick with SSO by yalokin-jiminny · Pull Request #11935 · jiminny/app
Jy 19798 evaluation for ai activity types by nikolaybiaivanov · Pull Request #468 · jiminny/prophet
Jy 19798 evaluation for ai activity types by nikolaybiaivanov · Pull Request #468 · jiminny/prophet
Jiminny
Jiminny
Ask Jiminny test report - 8 Apr 2026 - Ask Jiminny test report - 13 Apr 2026.pdf
Ask Jiminny test report - 8 Apr 2026 - Ask Jiminny test report - 13 Apr 2026.pdf
Service-Desk - Queues - Platform team - Service space - Jira
Service-Desk - Queues - Platform team - Service space - Jira
JY-20543 add AJ reports User pilot tracking by LakyLak · Pull Request #11932 · jiminny/app
JY-20543 add AJ reports User pilot tracking by LakyLak · Pull Request #11932 · jiminny/app
Configure SSH access to multiple environment - Engineering - Confluence
Configure SSH access to multiple environment - Engineering - Confluence
New Tab
New Tab
CloudWatch | us-east-2
CloudWatch | us-east-2
github.com/jiminny/app/pull/11949
github.com/jiminny/app/pull/11949
Close tab
New Tab
Customize sidebar
Open Google Gemini (⌃X)
Tabs from other devices
Open history (⇧⌘H)
Open bookmarks (⌘B)
Waiting for github.com…...
|
12344
|
|
12350
|
264
|
3
|
2026-04-14T11:15:10.605579+00:00
|
/Users/lukas/.screenpipe/data/data/2026-04-14/1776 /Users/lukas/.screenpipe/data/data/2026-04-14/1776165310605_m1.jpg...
|
Slack
|
Vasil Vasilev (DM) - Jiminny Inc - 1 new item - Sl Vasil Vasilev (DM) - Jiminny Inc - 1 new item - Slack...
|
1
|
NULL
|
monitor_1
|
NULL
|
NULL
|
NULL
|
NULL
|
Firefox FileEditViewHistoryBookmarksProfilesToolsW Firefox FileEditViewHistoryBookmarksProfilesToolsWindowHelpec2-userGDOCKER981DEV (docker)882APP (-zsh)[EMAIL]@73b64f5d54a3:/home/jiminny#[ec2-user@ip-10-30-93-249 ~]$ dockerexec -it $(dockny && bash"root@c78a087b1345:/home/Jiminny# php artisan automated-reports[2026-04-14 10:46:08] staging.INF0: [automated-reports] Started{"correlation_id":"5[2026-04-1410:46:08]staging.INFO: [automated-reports] Checking conditions {"isMondaid":"5c23e861-2ca9-4f92-9f67-773d6bc80ca0","trace_id" :"185df6f6-4327-4609-9c2e-2ab83a[2026-04-14 10:46:08]staging.INFO: [automated-reports] Processing daily reports {"cab83a0f5432"}[2026-04-1410:46:08]9-9c2e-2ab83a0f5432"}staging.INFO: [automated-reports]Found 3 daily reports to proc[2026-04-1410:46:087daily"staging.INFO: [automated-reports]Dispatching Generate Report j,"type":"ask_jiminny"} {"correlation_id":"5c23e861-2ca9-4f92-9f67-773d6bc80ca0"[2026-04-14 10:46:08]staging.INFO: [automated-reports]Dispatching Generate Report jdaily", "type": "ask_jiminny"} {"correlation_id":"5c23e861-2ca9-4f92-9f67-773d6bc80cab"[2026-04-14 10:46:08]staging. INFO: [automated-reports]daily", "type": "ask_fiminny') ('"correlation-te : Sc2se861-2C0 -4792-9f67-773d 6e8oco[2026-04-14 10:46:08]staging.INFO: [automated-reports]Completed{"correlation_id":root@c78a087b1345:/home/jiminny# phpartisanautomated-reports --report-id 35[2026-04-14 10:48:42] staging.INFO: [automated-reports]{"correlation_id":"2[2026-04-14 10:48:42]staging.INFO: [automated-reports]Checking conditions {"isMondaid":"246a1ala-7076-458c-bd7d-49d2f5a2db88","trace_id":"1f894bf6-e50d-4e99-b635-2aa526[2026-04-14 10:48:42]staging.INFO: [automated-reports]Processing daily reports{"caa52627fc27"}[automated-reports] Automated report[2026-04-14 10:48:42]staging.INFO: [automated-reports] Found 1 daily reports to proc9-b635-2aa52627f c27"}[2026-04-14 10:48:42]staging.INF0: [automated-reports]Dispatching Generate Report jdaily","type": "ask_jiminny"} {"correlation_id":"246a1a1a-7076-458c-bd7d-49d2f5a2db88"[2026-04-14 10:48:42]staging.INFO: [automated-reports]Completed{"correlation_id":root@c78a087b1345:/home/jiminny# [ec2-user@ip-10-30-93-249 ~]$I+EDHomeDMsActivityFilesLater.*•More(ahlJiminny ...+tscnicrel# infra-changes# jiminny-bg# platform-tickets# product_launches# random# releases# sofia-office# support# thank-yous# the_people_of jimi...Direct messagesE. Vasil VasilevAneliya Angelova, ...Steliyan GeorgievAdelina Petrova, Ili...0. Adelina Petrova. Galya Dimitrova *Rs Nikolay Nikolov "2Galya Dimitrova, Ni...2Galya Dimitrova, Ni...P. Nikolay Yankov::: AppsJira CloudToastGoogle Cale...• Support Daily • in 45 m100% 147Tue 14 Apr 14:15:10→Search Jiminny IncVasil Vasilev2 MessagesAdd canvasC Files< Pins+Vasil VarWednesday, April 8th~благодариThursday, April 9th~Vasil Vasilev 12:08 PMЛукаш, приветhttps://github.com/jiminny/app/pull/11928трябва ми един approve, моляправя fine tuning на настойките засинхронизация на мейлиLukas Kovalik 12:11 PMготовоVasil Vasilev 12:11 PMблагодаряToday ~NewVasil Vasilev 2:01 PMЛукаш приветможе ли да разглдаш този ПР като имашмалко време:https://github.com/jiminny/app/pull/11949повечето промени са семантични, не сафункционалниразделям по голям ПР на две частиMessage Vasil VasilevAa...
|
NULL
|
4578089496756378497
|
NULL
|
click
|
ocr
|
NULL
|
Firefox FileEditViewHistoryBookmarksProfilesToolsW Firefox FileEditViewHistoryBookmarksProfilesToolsWindowHelpec2-userGDOCKER981DEV (docker)882APP (-zsh)[EMAIL]@73b64f5d54a3:/home/jiminny#[ec2-user@ip-10-30-93-249 ~]$ dockerexec -it $(dockny && bash"root@c78a087b1345:/home/Jiminny# php artisan automated-reports[2026-04-14 10:46:08] staging.INF0: [automated-reports] Started{"correlation_id":"5[2026-04-1410:46:08]staging.INFO: [automated-reports] Checking conditions {"isMondaid":"5c23e861-2ca9-4f92-9f67-773d6bc80ca0","trace_id" :"185df6f6-4327-4609-9c2e-2ab83a[2026-04-14 10:46:08]staging.INFO: [automated-reports] Processing daily reports {"cab83a0f5432"}[2026-04-1410:46:08]9-9c2e-2ab83a0f5432"}staging.INFO: [automated-reports]Found 3 daily reports to proc[2026-04-1410:46:087daily"staging.INFO: [automated-reports]Dispatching Generate Report j,"type":"ask_jiminny"} {"correlation_id":"5c23e861-2ca9-4f92-9f67-773d6bc80ca0"[2026-04-14 10:46:08]staging.INFO: [automated-reports]Dispatching Generate Report jdaily", "type": "ask_jiminny"} {"correlation_id":"5c23e861-2ca9-4f92-9f67-773d6bc80cab"[2026-04-14 10:46:08]staging. INFO: [automated-reports]daily", "type": "ask_fiminny') ('"correlation-te : Sc2se861-2C0 -4792-9f67-773d 6e8oco[2026-04-14 10:46:08]staging.INFO: [automated-reports]Completed{"correlation_id":root@c78a087b1345:/home/jiminny# phpartisanautomated-reports --report-id 35[2026-04-14 10:48:42] staging.INFO: [automated-reports]{"correlation_id":"2[2026-04-14 10:48:42]staging.INFO: [automated-reports]Checking conditions {"isMondaid":"246a1ala-7076-458c-bd7d-49d2f5a2db88","trace_id":"1f894bf6-e50d-4e99-b635-2aa526[2026-04-14 10:48:42]staging.INFO: [automated-reports]Processing daily reports{"caa52627fc27"}[automated-reports] Automated report[2026-04-14 10:48:42]staging.INFO: [automated-reports] Found 1 daily reports to proc9-b635-2aa52627f c27"}[2026-04-14 10:48:42]staging.INF0: [automated-reports]Dispatching Generate Report jdaily","type": "ask_jiminny"} {"correlation_id":"246a1a1a-7076-458c-bd7d-49d2f5a2db88"[2026-04-14 10:48:42]staging.INFO: [automated-reports]Completed{"correlation_id":root@c78a087b1345:/home/jiminny# [ec2-user@ip-10-30-93-249 ~]$I+EDHomeDMsActivityFilesLater.*•More(ahlJiminny ...+tscnicrel# infra-changes# jiminny-bg# platform-tickets# product_launches# random# releases# sofia-office# support# thank-yous# the_people_of jimi...Direct messagesE. Vasil VasilevAneliya Angelova, ...Steliyan GeorgievAdelina Petrova, Ili...0. Adelina Petrova. Galya Dimitrova *Rs Nikolay Nikolov "2Galya Dimitrova, Ni...2Galya Dimitrova, Ni...P. Nikolay Yankov::: AppsJira CloudToastGoogle Cale...• Support Daily • in 45 m100% 147Tue 14 Apr 14:15:10→Search Jiminny IncVasil Vasilev2 MessagesAdd canvasC Files< Pins+Vasil VarWednesday, April 8th~благодариThursday, April 9th~Vasil Vasilev 12:08 PMЛукаш, приветhttps://github.com/jiminny/app/pull/11928трябва ми един approve, моляправя fine tuning на настойките засинхронизация на мейлиLukas Kovalik 12:11 PMготовоVasil Vasilev 12:11 PMблагодаряToday ~NewVasil Vasilev 2:01 PMЛукаш приветможе ли да разглдаш този ПР като имашмалко време:https://github.com/jiminny/app/pull/11949повечето промени са семантични, не сафункционалниразделям по голям ПР на две частиMessage Vasil VasilevAa...
|
NULL
|
|
12353
|
NULL
|
0
|
2026-04-14T11:15:13.200042+00:00
|
/Users/lukas/.screenpipe/data/data/2026-04-14/1776 /Users/lukas/.screenpipe/data/data/2026-04-14/1776165313200_m1.jpg...
|
NULL
|
NULL
|
1
|
NULL
|
monitor_1
|
NULL
|
NULL
|
NULL
|
NULL
|
SlackFileEditViewGoHistoryWindowHelpec2-userGDOCKE SlackFileEditViewGoHistoryWindowHelpec2-userGDOCKER-₴81DEV (docker)882APP (-zsh)[EMAIL]@73b64f5d54a3:/home/jiminny#[ec2-user@ip-10-30-93-249 ~]$ dockerexec -it $(dockny && bash"root@c78a087b1345:/home/Jiminny# php artisan automated-reports[2026-04-14 10:46:08] staging.INF0: [automated-reports] Started{"correlation_id":"5[2026-04-1410:46:08]staging.INFO: [automated-reports] Checking conditions {"isMondaid":"5c23e861-2ca9-4f92-9f67-773d6bc80ca0","trace_id" :"185df6f6-4327-4609-9cZe-2ab83a[2026-04-14 10:46:08]ab83a0f5432"}staging. INFO: [automated-reports] Processing daily reports{"c[2026-04-1410:46:08]9-9c2e-2ab83a0f5432"'}staging.INFO: [automated-reports]Found 3 daily reports to proc[2026-04-1410:46:087daily"staging.INFO: [automated-reports]Dispatching Generate Report j,"type":"ask_jiminny"} {"correlation_id":"5c23e861-2ca9-4f92-9f67-773d6bc80ca®"[2026-04-14 10:46:08]staging.INFO: [automated-reports]Dispatching Generate Report jdaily", "type": "ask_jiminny"} {"correlation_id":"5c23e861-2ca9-4f92-9f67-773d6bc80cab"[2026-04-14 10:46:08]staging. INFO: [automated-reports]daily'", "type" "ask-fiminny"'} ("correlation-id' : 5c2se861-2ca -4792-9f87-773 e8oca[2026-04-14 10:46:08]staging.INFO: [automated-reports]Completed{"correlation_id":root@c78a087b1345:/home/jiminny# phpartisanautomated-reports --report-id 35[2026-04-14 10:48:42] staging.INFO: [automated-reports]Started{"correlation_id":"2[2026-04-14 10:48:42]staging.INFO: [automated-reports]Checking conditions {"isMondaid":"246a1ala-7076-458c-bd7d-49d2f5a2db88","trace_id":"1f894bf6-e50d-4e99-b635-2aa526[2026-04-14 10:48:42]staging.INFO: [automated-reports]Processing daily reports{"caa52627fc27"}[automated-reports] Automated report[2026-04-14 10:48:42]staging.INFO: [automated-reports] Found 1 daily reports to proc9-b635-2aa52627f c27"}[2026-04-14 10:48:42]staging.INF0: [automated-reports]Dispatching Generate Reportdaily","type": "ask_jiminny"} {"correlation_id":"246a1a1a-7076-458c-bd7d-49d2f5a2db88"[2026-04-14 10:48:42]staging.INFO: [automated-reports]Completed{"correlation_id":root@c78a087b1345:/home/jiminny# [ec2-user@ip-10-30-93-249 ~]$I+HomeDMsActivityFilesLater.*•MorelhlJiminny ...+tscnicrol# infra-changes# jiminny-bg# platform-tickets# product_launches# random# releases# sofia-office# support# thank-yous# the_people_of jimi...Direct messagesE. Vasil VasilevAneliya Angelova, ...Steliyan GeorgievAdelina Petrova, Ili...0. Adelina Petrova. Galya Dimitrova *&s Nikolay Nikolov "2Galya Dimitrova, Ni...2Galya Dimitrova, Ni...P. Nikolay Yankov::: AppsJira CloudToastGoogle Cale...§ Support Daily • in 45 m100% <7Tue 14 Apr 14:15:13→Search Jiminny IncVasil VasilevMessagesAdd canvasC Files< Pins+Vasil Va*Wednesday, April 8th~благодариThursday, April 9th~Vasil Vasilev 12:08 PMЛукаш, приветhttps://github.com/jiminny/app/pull/11928трябва ми един approve, моляправя fine tuning на настойките засинхронизация на мейлиLukas Kovalik 12:11 PMготовоVasil Vasilev 12:11 PMблагодаряToday ~NewVasil Vasilev 2:01 PMЛукаш приветможе ли да разглдаш този ПР като имашмалко време:https://github.com/jiminny/app/pull/11949повечето промени са семантични, не сафункционалниразделям по голям ПР на две частиздрAaShift + Return to add a new line...
|
NULL
|
-1903687493051113274
|
NULL
|
visual_change
|
ocr
|
NULL
|
SlackFileEditViewGoHistoryWindowHelpec2-userGDOCKE SlackFileEditViewGoHistoryWindowHelpec2-userGDOCKER-₴81DEV (docker)882APP (-zsh)[EMAIL]@73b64f5d54a3:/home/jiminny#[ec2-user@ip-10-30-93-249 ~]$ dockerexec -it $(dockny && bash"root@c78a087b1345:/home/Jiminny# php artisan automated-reports[2026-04-14 10:46:08] staging.INF0: [automated-reports] Started{"correlation_id":"5[2026-04-1410:46:08]staging.INFO: [automated-reports] Checking conditions {"isMondaid":"5c23e861-2ca9-4f92-9f67-773d6bc80ca0","trace_id" :"185df6f6-4327-4609-9cZe-2ab83a[2026-04-14 10:46:08]ab83a0f5432"}staging. INFO: [automated-reports] Processing daily reports{"c[2026-04-1410:46:08]9-9c2e-2ab83a0f5432"'}staging.INFO: [automated-reports]Found 3 daily reports to proc[2026-04-1410:46:087daily"staging.INFO: [automated-reports]Dispatching Generate Report j,"type":"ask_jiminny"} {"correlation_id":"5c23e861-2ca9-4f92-9f67-773d6bc80ca®"[2026-04-14 10:46:08]staging.INFO: [automated-reports]Dispatching Generate Report jdaily", "type": "ask_jiminny"} {"correlation_id":"5c23e861-2ca9-4f92-9f67-773d6bc80cab"[2026-04-14 10:46:08]staging. INFO: [automated-reports]daily'", "type" "ask-fiminny"'} ("correlation-id' : 5c2se861-2ca -4792-9f87-773 e8oca[2026-04-14 10:46:08]staging.INFO: [automated-reports]Completed{"correlation_id":root@c78a087b1345:/home/jiminny# phpartisanautomated-reports --report-id 35[2026-04-14 10:48:42] staging.INFO: [automated-reports]Started{"correlation_id":"2[2026-04-14 10:48:42]staging.INFO: [automated-reports]Checking conditions {"isMondaid":"246a1ala-7076-458c-bd7d-49d2f5a2db88","trace_id":"1f894bf6-e50d-4e99-b635-2aa526[2026-04-14 10:48:42]staging.INFO: [automated-reports]Processing daily reports{"caa52627fc27"}[automated-reports] Automated report[2026-04-14 10:48:42]staging.INFO: [automated-reports] Found 1 daily reports to proc9-b635-2aa52627f c27"}[2026-04-14 10:48:42]staging.INF0: [automated-reports]Dispatching Generate Reportdaily","type": "ask_jiminny"} {"correlation_id":"246a1a1a-7076-458c-bd7d-49d2f5a2db88"[2026-04-14 10:48:42]staging.INFO: [automated-reports]Completed{"correlation_id":root@c78a087b1345:/home/jiminny# [ec2-user@ip-10-30-93-249 ~]$I+HomeDMsActivityFilesLater.*•MorelhlJiminny ...+tscnicrol# infra-changes# jiminny-bg# platform-tickets# product_launches# random# releases# sofia-office# support# thank-yous# the_people_of jimi...Direct messagesE. Vasil VasilevAneliya Angelova, ...Steliyan GeorgievAdelina Petrova, Ili...0. Adelina Petrova. Galya Dimitrova *&s Nikolay Nikolov "2Galya Dimitrova, Ni...2Galya Dimitrova, Ni...P. Nikolay Yankov::: AppsJira CloudToastGoogle Cale...§ Support Daily • in 45 m100% <7Tue 14 Apr 14:15:13→Search Jiminny IncVasil VasilevMessagesAdd canvasC Files< Pins+Vasil Va*Wednesday, April 8th~благодариThursday, April 9th~Vasil Vasilev 12:08 PMЛукаш, приветhttps://github.com/jiminny/app/pull/11928трябва ми един approve, моляправя fine tuning на настойките засинхронизация на мейлиLukas Kovalik 12:11 PMготовоVasil Vasilev 12:11 PMблагодаряToday ~NewVasil Vasilev 2:01 PMЛукаш приветможе ли да разглдаш този ПР като имашмалко време:https://github.com/jiminny/app/pull/11949повечето промени са семантични, не сафункционалниразделям по голям ПР на две частиздрAaShift + Return to add a new line...
|
12350
|
|
12355
|
266
|
0
|
2026-04-14T11:15:44.414161+00:00
|
/Users/lukas/.screenpipe/data/data/2026-04-14/1776 /Users/lukas/.screenpipe/data/data/2026-04-14/1776165344414_m1.jpg...
|
Slack
|
Vasil Vasilev (DM) - Jiminny Inc - 1 new item - Sl Vasil Vasilev (DM) - Jiminny Inc - 1 new item - Slack...
|
1
|
NULL
|
monitor_1
|
NULL
|
NULL
|
NULL
|
NULL
|
Jiminny Inc
Jiminny (Staging)
Add workspaces
Home
Jiminny Inc
Jiminny (Staging)
Add workspaces
Home
Home
DMs
DMs
Activity
Activity
Files
Files
Later
Later
More…
More
Unreads
Threads
Huddles
Drafts & sent
Directories
platform-inner-team
ai-chapter
alerts
backend
confusion-clinic
curiosity_lab
engineering
frontend
general
infra-changes
jiminny-bg
platform-tickets
product_launches
random
releases
sofia-office
support
thank-yous
the_people_of_jiminny
Vasil Vasilev
Aneliya Angelova
,
Nikolay Yankov
,
Steliyan Georgiev
Steliyan Georgiev
Adelina Petrova
,
Ilian Kyuchukov
,
Steliyan Georgiev
Adelina Petrova
Galya Dimitrova
Nikolay Nikolov
Galya Dimitrova
,
Nikolay Nikolov
Galya Dimitrova
,
Nikolay Yankov
Nikolay Yankov
Jira Cloud
Toast
Google Calendar
Messages
Messages
Add canvas
Add canvas
Files
Files
Pins
Pins
Add and Edit Channel Tabs
Canvas
List
Folder
Jump to date
Apr 8th at 7:34:06 PM
7:34
можеш ли да дадеш един approve тука
Apr 8th at 7:34:09 PM
7:34
че видях един тъп проблем
Lukas Kovalik
Apr 8th at 7:34:09 PM
7:34 PM
здрасти, да
Vasil Vasilev
Apr 8th at 7:34:10 PM
7:34 PM
https://github.com/jiminny/app/pull/11920
https://github.com/jiminny/app/pull/11920
Lukas Kovalik
Apr 8th at 7:34:31 PM
7:34 PM
готово
Vasil Vasilev
Apr 8th at 7:34:36 PM
7:34 PM
благодаря
Jump to date
Vasil Vasilev
Apr 9th at 12:08:16 PM
12:08 PM
Лукаш, привет
Apr 9th at 12:08:19 PM
12:08
https://github.com/jiminny/app/pull/11928
https://github.com/jiminny/app/pull/11928
React with white_check_mark
React with eyes
React with raised_hands
Add reaction…
Reply in thread
Forward message…
Save for later
More actions
Apr 9th at 12:08:25 PM
12:08
трябва ми един approve, моля
React with white_check_mark
React with eyes
React with raised_hands
Add reaction…
Reply in thread
Forward message…
Save for later
More actions
Apr 9th at 12:08:35 PM
12:08
правя fine tuning на настойките за синхронизация на мейли
React with white_check_mark
React with eyes
React with raised_hands
Add reaction…
Reply in thread
Forward message…
Save for later
More actions
Lukas Kovalik
Apr 9th at 12:11:24 PM
12:11 PM
готово
React with white_check_mark
React with eyes
React with raised_hands
Add reaction…
Reply in thread
Forward message…
Save for later
More actions
Vasil Vasilev
Apr 9th at 12:11:50 PM
12:11 PM
благодаря
React with white_check_mark
React with eyes
React with raised_hands
Add reaction…
Reply in thread
Forward message…
Save for later
More actions
Jump to date
New
Vasil Vasilev
Today at 2:01:40 PM
2:01 PM
Лукаш привет
React with white_check_mark
React with eyes
React with raised_hands
Add reaction…
Reply in thread
Forward message…
Save for later
More actions
Today at 2:01:49 PM
2:01
може ли да разглдаш този ПР като имаш малко време:
https://github.com/jiminny/app/pull/11949
https://github.com/jiminny/app/pull/11949
React with white_check_mark
React with eyes
React with raised_hands
Add reaction…
Reply in thread
Forward message…
Save for later
More actions
Today at 2:01:59 PM
2:01
повечето промени са семантични, не са функционални...
|
[{"role":"AXRadioButton","text [{"role":"AXRadioButton","text":"Jiminny Inc","depth":12,"bounds":{"left":0.4861111,"top":0.08777778,"width":0.022222223,"height":0.035555556},"role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":true,"is_expanded":false},{"role":"AXRadioButton","text":"Jiminny (Staging)","depth":12,"bounds":{"left":0.4861111,"top":0.14555556,"width":0.022222223,"height":0.035555556},"role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXPopUpButton","text":"Add workspaces","depth":12,"bounds":{"left":0.4861111,"top":0.20333333,"width":0.022222223,"height":0.035555556},"role_description":"pop-up button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXRadioButton","text":"Home","depth":14,"bounds":{"left":0.525,"top":0.07777778,"width":0.036111113,"height":0.075555556},"role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":true,"is_expanded":false},{"role":"AXStaticText","text":"Home","depth":16,"bounds":{"left":0.5326389,"top":0.13,"width":0.020833334,"height":0.015555556},"role_description":"text"},{"role":"AXRadioButton","text":"DMs","depth":14,"bounds":{"left":0.525,"top":0.15333334,"width":0.036111113,"height":0.075555556},"role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"DMs","depth":16,"bounds":{"left":0.5347222,"top":0.20555556,"width":0.016666668,"height":0.015555556},"role_description":"text"},{"role":"AXRadioButton","text":"Activity","depth":14,"bounds":{"left":0.525,"top":0.22888888,"width":0.036111113,"height":0.075555556},"role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"Activity","depth":16,"bounds":{"left":0.52916664,"top":0.28111112,"width":0.027083334,"height":0.015555556},"role_description":"text"},{"role":"AXRadioButton","text":"Files","depth":14,"bounds":{"left":0.525,"top":0.30444443,"width":0.036111113,"height":0.075555556},"role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"Files","depth":16,"bounds":{"left":0.5347222,"top":0.35666665,"width":0.015972223,"height":0.015555556},"role_description":"text"},{"role":"AXRadioButton","text":"Later","depth":14,"bounds":{"left":0.525,"top":0.38,"width":0.036111113,"height":0.075555556},"role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"Later","depth":16,"bounds":{"left":0.53402776,"top":0.43222222,"width":0.018055556,"height":0.015555556},"role_description":"text"},{"role":"AXRadioButton","text":"More…","depth":14,"bounds":{"left":0.525,"top":0.45555556,"width":0.036111113,"height":0.075555556},"role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"More","depth":16,"bounds":{"left":0.53333336,"top":0.50777775,"width":0.01875,"height":0.015555556},"role_description":"text"},{"role":"AXStaticText","text":"Unreads","depth":21,"bounds":{"left":0.5951389,"top":0.12777779,"width":0.038194444,"height":0.0011111111},"role_description":"text"},{"role":"AXStaticText","text":"Threads","depth":21,"bounds":{"left":0.5951389,"top":0.12777779,"width":0.036805555,"height":0.0011111111},"role_description":"text"},{"role":"AXStaticText","text":"Huddles","depth":21,"bounds":{"left":0.5951389,"top":0.12777779,"width":0.038194444,"height":0.0011111111},"role_description":"text"},{"role":"AXStaticText","text":"Drafts & sent","depth":21,"bounds":{"left":0.5951389,"top":0.12777779,"width":0.06111111,"height":0.0011111111},"role_description":"text"},{"role":"AXStaticText","text":"Directories","depth":21,"bounds":{"left":0.5951389,"top":0.12777779,"width":0.050694443,"height":0.0011111111},"role_description":"text"},{"role":"AXStaticText","text":"platform-inner-team","depth":23,"bounds":{"left":0.60625,"top":0.12777779,"width":0.093055554,"height":0.0011111111},"role_description":"text"},{"role":"AXStaticText","text":"ai-chapter","depth":23,"bounds":{"left":0.60625,"top":0.12777779,"width":0.046527777,"height":0.0011111111},"role_description":"text"},{"role":"AXStaticText","text":"alerts","depth":23,"bounds":{"left":0.60625,"top":0.12777779,"width":0.025694445,"height":0.0011111111},"role_description":"text"},{"role":"AXStaticText","text":"backend","depth":23,"bounds":{"left":0.60625,"top":0.12777779,"width":0.038194444,"height":0.0011111111},"role_description":"text"},{"role":"AXStaticText","text":"confusion-clinic","depth":23,"bounds":{"left":0.60625,"top":0.12777779,"width":0.072222225,"height":0.0011111111},"role_description":"text"},{"role":"AXStaticText","text":"curiosity_lab","depth":23,"bounds":{"left":0.60625,"top":0.12777779,"width":0.057638887,"height":0.0011111111},"role_description":"text"},{"role":"AXStaticText","text":"engineering","depth":23,"bounds":{"left":0.60625,"top":0.12777779,"width":0.054166667,"height":0.0011111111},"role_description":"text"},{"role":"AXStaticText","text":"frontend","depth":23,"bounds":{"left":0.60625,"top":0.12777779,"width":0.04027778,"height":0.0011111111},"role_description":"text"},{"role":"AXStaticText","text":"general","depth":23,"bounds":{"left":0.60625,"top":0.12777779,"width":0.034027778,"height":0.007777778},"role_description":"text"},{"role":"AXStaticText","text":"infra-changes","depth":23,"bounds":{"left":0.60625,"top":0.14666666,"width":0.061805554,"height":0.02},"role_description":"text"},{"role":"AXStaticText","text":"jiminny-bg","depth":23,"bounds":{"left":0.60625,"top":0.17777778,"width":0.048611112,"height":0.02},"role_description":"text"},{"role":"AXStaticText","text":"platform-tickets","depth":23,"bounds":{"left":0.60625,"top":0.20888889,"width":0.072916664,"height":0.02},"role_description":"text"},{"role":"AXStaticText","text":"product_launches","depth":23,"bounds":{"left":0.60625,"top":0.24,"width":0.08055556,"height":0.02},"role_description":"text"},{"role":"AXStaticText","text":"random","depth":23,"bounds":{"left":0.60625,"top":0.2711111,"width":0.035416666,"height":0.02},"role_description":"text"},{"role":"AXStaticText","text":"releases","depth":23,"bounds":{"left":0.60625,"top":0.30222222,"width":0.036805555,"height":0.02},"role_description":"text"},{"role":"AXStaticText","text":"sofia-office","depth":23,"bounds":{"left":0.60625,"top":0.33333334,"width":0.05138889,"height":0.02},"role_description":"text"},{"role":"AXStaticText","text":"support","depth":23,"bounds":{"left":0.60625,"top":0.36444443,"width":0.036111113,"height":0.02},"role_description":"text"},{"role":"AXStaticText","text":"thank-yous","depth":23,"bounds":{"left":0.60625,"top":0.39555556,"width":0.05138889,"height":0.02},"role_description":"text"},{"role":"AXStaticText","text":"the_people_of_jiminny","depth":23,"bounds":{"left":0.60625,"top":0.42666668,"width":0.094444446,"height":0.02},"role_description":"text"},{"role":"AXStaticText","text":"Vasil Vasilev","depth":23,"bounds":{"left":0.60625,"top":0.5,"width":0.055555556,"height":0.02},"role_description":"text"},{"role":"AXStaticText","text":"Aneliya Angelova","depth":23,"bounds":{"left":0.60625,"top":0.5311111,"width":0.07847222,"height":0.02},"role_description":"text"},{"role":"AXStaticText","text":",","depth":23,"bounds":{"left":0.68472224,"top":0.5311111,"width":0.013194445,"height":0.02},"role_description":"text"},{"role":"AXStaticText","text":"Nikolay Yankov","depth":23,"bounds":{"left":0.68958336,"top":0.5311111,"width":0.029861111,"height":0.02},"role_description":"text"},{"role":"AXStaticText","text":",","depth":23,"role_description":"text"},{"role":"AXStaticText","text":"Steliyan Georgiev","depth":23,"role_description":"text"},{"role":"AXStaticText","text":"Steliyan Georgiev","depth":23,"bounds":{"left":0.60625,"top":0.56222224,"width":0.07986111,"height":0.02},"role_description":"text"},{"role":"AXStaticText","text":"Adelina Petrova","depth":23,"bounds":{"left":0.60625,"top":0.5933333,"width":0.072222225,"height":0.02},"role_description":"text"},{"role":"AXStaticText","text":",","depth":23,"bounds":{"left":0.67777777,"top":0.5933333,"width":0.0055555557,"height":0.02},"role_description":"text"},{"role":"AXStaticText","text":"Ilian Kyuchukov","depth":23,"bounds":{"left":0.68333334,"top":0.5933333,"width":0.015972223,"height":0.02},"role_description":"text"},{"role":"AXStaticText","text":",","depth":23,"role_description":"text"},{"role":"AXStaticText","text":"Steliyan Georgiev","depth":23,"role_description":"text"},{"role":"AXStaticText","text":"Adelina Petrova","depth":23,"bounds":{"left":0.60625,"top":0.6244444,"width":0.072222225,"height":0.02},"role_description":"text"},{"role":"AXStaticText","text":"Galya Dimitrova","depth":23,"bounds":{"left":0.60625,"top":0.65555555,"width":0.07361111,"height":0.02},"role_description":"text"},{"role":"AXStaticText","text":"Nikolay Nikolov","depth":23,"bounds":{"left":0.60625,"top":0.68666667,"width":0.07152778,"height":0.02},"role_description":"text"},{"role":"AXStaticText","text":"Galya Dimitrova","depth":23,"bounds":{"left":0.60625,"top":0.7177778,"width":0.07361111,"height":0.02},"role_description":"text"},{"role":"AXStaticText","text":",","depth":23,"bounds":{"left":0.6791667,"top":0.7177778,"width":0.0055555557,"height":0.02},"role_description":"text"},{"role":"AXStaticText","text":"Nikolay Nikolov","depth":23,"bounds":{"left":0.68472224,"top":0.7177778,"width":0.018055556,"height":0.02},"role_description":"text"},{"role":"AXStaticText","text":"Galya Dimitrova","depth":23,"bounds":{"left":0.60625,"top":0.7488889,"width":0.07361111,"height":0.02},"role_description":"text"},{"role":"AXStaticText","text":",","depth":23,"bounds":{"left":0.6791667,"top":0.7488889,"width":0.0055555557,"height":0.02},"role_description":"text"},{"role":"AXStaticText","text":"Nikolay Yankov","depth":23,"bounds":{"left":0.68472224,"top":0.7488889,"width":0.018055556,"height":0.02},"role_description":"text"},{"role":"AXStaticText","text":"Nikolay Yankov","depth":23,"bounds":{"left":0.60625,"top":0.78,"width":0.06875,"height":0.02},"role_description":"text"},{"role":"AXStaticText","text":"Jira Cloud","depth":23,"bounds":{"left":0.60625,"top":0.85333335,"width":0.045833334,"height":0.02},"role_description":"text"},{"role":"AXStaticText","text":"Toast","depth":23,"bounds":{"left":0.60625,"top":0.8844444,"width":0.024305556,"height":0.02},"role_description":"text"},{"role":"AXStaticText","text":"Google Calendar","depth":23,"bounds":{"left":0.60625,"top":0.91555554,"width":0.06388889,"height":0.02},"role_description":"text"},{"role":"AXRadioButton","text":"Messages","depth":17,"bounds":{"left":0.73125,"top":0.12777779,"width":0.06458333,"height":0.04222222},"role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":true,"is_expanded":false},{"role":"AXStaticText","text":"Messages","depth":19,"bounds":{"left":0.75069445,"top":0.14,"width":0.039583333,"height":0.017777778},"role_description":"text"},{"role":"AXRadioButton","text":"Add canvas","depth":18,"bounds":{"left":0.79791665,"top":0.12777779,"width":0.07152778,"height":0.04222222},"role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"Add canvas","depth":20,"bounds":{"left":0.8173611,"top":0.14,"width":0.046527777,"height":0.017777778},"role_description":"text"},{"role":"AXRadioButton","text":"Files","depth":17,"bounds":{"left":0.8715278,"top":0.12777779,"width":0.04375,"height":0.04222222},"role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"Files","depth":19,"bounds":{"left":0.8909722,"top":0.14,"width":0.01875,"height":0.017777778},"role_description":"text"},{"role":"AXRadioButton","text":"Pins","depth":17,"bounds":{"left":0.91805553,"top":0.12777779,"width":0.04236111,"height":0.04222222},"role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"Pins","depth":19,"bounds":{"left":0.9375,"top":0.14,"width":0.017361112,"height":0.017777778},"role_description":"text"},{"role":"AXPopUpButton","text":"Add and Edit Channel Tabs","depth":17,"bounds":{"left":0.9625,"top":0.12777779,"width":0.022916667,"height":0.04222222},"role_description":"pop-up button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"Canvas","depth":17,"role_description":"text"},{"role":"AXStaticText","text":"List","depth":17,"role_description":"text"},{"role":"AXStaticText","text":"Folder","depth":17,"role_description":"text"},{"role":"AXPopUpButton","text":"Jump to date","depth":23,"bounds":{"left":0.80138886,"top":0.16111112,"width":0.114583336,"height":0.0011111111},"role_description":"pop-up button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXLink","text":"Apr 8th at 7:34:06 PM","depth":25,"bounds":{"left":0.7423611,"top":0.16111112,"width":0.016666668,"height":0.0011111111},"role_description":"link","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"7:34","depth":26,"bounds":{"left":0.7423611,"top":0.16111112,"width":0.016666668,"height":0.0011111111},"role_description":"text"},{"role":"AXStaticText","text":"можеш ли да дадеш един approve тука","depth":25,"bounds":{"left":0.76458335,"top":0.16111112,"width":0.18888889,"height":0.0011111111},"role_description":"text"},{"role":"AXLink","text":"Apr 8th at 7:34:09 PM","depth":25,"bounds":{"left":0.7423611,"top":0.16111112,"width":0.016666668,"height":0.0011111111},"role_description":"link","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"7:34","depth":26,"bounds":{"left":0.7423611,"top":0.16111112,"width":0.016666668,"height":0.0011111111},"role_description":"text"},{"role":"AXStaticText","text":"че видях един тъп проблем","depth":25,"bounds":{"left":0.76458335,"top":0.16111112,"width":0.13333334,"height":0.0011111111},"role_description":"text"},{"role":"AXButton","text":"Lukas Kovalik","depth":24,"bounds":{"left":0.76458335,"top":0.16111112,"width":0.06458333,"height":0.0011111111},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"","depth":24,"bounds":{"left":0.82916665,"top":0.16111112,"width":0.0055555557,"height":0.0011111111},"role_description":"text"},{"role":"AXLink","text":"Apr 8th at 7:34:09 PM","depth":24,"bounds":{"left":0.8347222,"top":0.16111112,"width":0.03125,"height":0.0011111111},"role_description":"link","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"7:34 PM","depth":25,"bounds":{"left":0.8347222,"top":0.16111112,"width":0.03125,"height":0.0011111111},"role_description":"text"},{"role":"AXStaticText","text":"здрасти, да","depth":25,"bounds":{"left":0.76458335,"top":0.16111112,"width":0.055555556,"height":0.0011111111},"role_description":"text"},{"role":"AXButton","text":"Vasil Vasilev","depth":24,"bounds":{"left":0.76458335,"top":0.16111112,"width":0.057638887,"height":0.0011111111},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"","depth":24,"bounds":{"left":0.82222223,"top":0.16111112,"width":0.0055555557,"height":0.0011111111},"role_description":"text"},{"role":"AXLink","text":"Apr 8th at 7:34:10 PM","depth":24,"bounds":{"left":0.82708335,"top":0.16111112,"width":0.031944446,"height":0.0011111111},"role_description":"link","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"7:34 PM","depth":25,"bounds":{"left":0.82708335,"top":0.16111112,"width":0.031944446,"height":0.0011111111},"role_description":"text"},{"role":"AXLink","text":"https://github.com/jiminny/app/pull/11920","depth":25,"bounds":{"left":0.76458335,"top":0.16111112,"width":0.19791667,"height":0.0011111111},"role_description":"link","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"https://github.com/jiminny/app/pull/11920","depth":26,"bounds":{"left":0.76458335,"top":0.16111112,"width":0.19791667,"height":0.0011111111},"role_description":"text"},{"role":"AXButton","text":"Lukas Kovalik","depth":24,"bounds":{"left":0.76458335,"top":0.16111112,"width":0.06458333,"height":0.0011111111},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"","depth":24,"bounds":{"left":0.82916665,"top":0.16111112,"width":0.0055555557,"height":0.0011111111},"role_description":"text"},{"role":"AXLink","text":"Apr 8th at 7:34:31 PM","depth":24,"bounds":{"left":0.8347222,"top":0.16111112,"width":0.03125,"height":0.0011111111},"role_description":"link","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"7:34 PM","depth":25,"bounds":{"left":0.8347222,"top":0.16111112,"width":0.03125,"height":0.0011111111},"role_description":"text"},{"role":"AXStaticText","text":"готово","depth":25,"bounds":{"left":0.76458335,"top":0.16111112,"width":0.031944446,"height":0.0011111111},"role_description":"text"},{"role":"AXButton","text":"Vasil Vasilev","depth":24,"bounds":{"left":0.76458335,"top":0.16111112,"width":0.057638887,"height":0.0011111111},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"","depth":24,"bounds":{"left":0.82222223,"top":0.16111112,"width":0.0055555557,"height":0.0011111111},"role_description":"text"},{"role":"AXLink","text":"Apr 8th at 7:34:36 PM","depth":24,"bounds":{"left":0.82708335,"top":0.16111112,"width":0.031944446,"height":0.0011111111},"role_description":"link","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"7:34 PM","depth":25,"bounds":{"left":0.82708335,"top":0.16111112,"width":0.031944446,"height":0.0011111111},"role_description":"text"},{"role":"AXStaticText","text":"благодаря","depth":25,"bounds":{"left":0.76458335,"top":0.16111112,"width":0.05,"height":0.0011111111},"role_description":"text"},{"role":"AXPopUpButton","text":"Jump to date","depth":23,"bounds":{"left":0.80625,"top":0.17666666,"width":0.10486111,"height":0.031111112},"role_description":"pop-up button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Vasil Vasilev","depth":24,"bounds":{"left":0.76458335,"top":0.16111112,"width":0.057638887,"height":0.0011111111},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"","depth":24,"bounds":{"left":0.82222223,"top":0.16111112,"width":0.0055555557,"height":0.0011111111},"role_description":"text"},{"role":"AXLink","text":"Apr 9th at 12:08:16 PM","depth":24,"bounds":{"left":0.82708335,"top":0.16111112,"width":0.036805555,"height":0.0011111111},"role_description":"link","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"12:08 PM","depth":25,"bounds":{"left":0.82708335,"top":0.16111112,"width":0.036805555,"height":0.0011111111},"role_description":"text"},{"role":"AXStaticText","text":"Лукаш, привет","depth":25,"bounds":{"left":0.76458335,"top":0.16111112,"width":0.07083333,"height":0.018888889},"role_description":"text"},{"role":"AXLink","text":"Apr 9th at 12:08:19 PM","depth":25,"bounds":{"left":0.7375,"top":0.19666667,"width":0.021527778,"height":0.016666668},"role_description":"link","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"12:08","depth":26,"bounds":{"left":0.7375,"top":0.19666667,"width":0.021527778,"height":0.016666668},"role_description":"text"},{"role":"AXLink","text":"https://github.com/jiminny/app/pull/11928","depth":25,"bounds":{"left":0.76458335,"top":0.19333333,"width":0.19791667,"height":0.02},"role_description":"link","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"https://github.com/jiminny/app/pull/11928","depth":26,"bounds":{"left":0.76458335,"top":0.19333333,"width":0.19791667,"height":0.02},"role_description":"text"},{"role":"AXCheckBox","text":"React with white_check_mark","depth":26,"bounds":{"left":0.8048611,"top":0.16111112,"width":0.022222223,"height":0.033333335},"role_description":"toggle button","subrole":"AXToggleButton","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXCheckBox","text":"React with eyes","depth":26,"bounds":{"left":0.82708335,"top":0.16111112,"width":0.022222223,"height":0.033333335},"role_description":"toggle button","subrole":"AXToggleButton","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXCheckBox","text":"React with raised_hands","depth":26,"bounds":{"left":0.84930557,"top":0.16111112,"width":0.022222223,"height":0.033333335},"role_description":"toggle button","subrole":"AXToggleButton","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Add reaction…","depth":26,"bounds":{"left":0.8715278,"top":0.16111112,"width":0.022222223,"height":0.033333335},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Reply in thread","depth":26,"bounds":{"left":0.89375,"top":0.16111112,"width":0.022222223,"height":0.033333335},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Forward message…","depth":26,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXCheckBox","text":"Save for later","depth":26,"role_description":"toggle button","subrole":"AXToggleButton","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXPopUpButton","text":"More actions","depth":26,"role_description":"pop-up button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXLink","text":"Apr 9th at 12:08:25 PM","depth":25,"bounds":{"left":0.7375,"top":0.23,"width":0.021527778,"height":0.016666668},"role_description":"link","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"12:08","depth":26,"bounds":{"left":0.7375,"top":0.23,"width":0.021527778,"height":0.016666668},"role_description":"text"},{"role":"AXStaticText","text":"трябва ми един approve, моля","depth":25,"bounds":{"left":0.76458335,"top":0.22666667,"width":0.14444445,"height":0.02},"role_description":"text"},{"role":"AXCheckBox","text":"React with white_check_mark","depth":26,"bounds":{"left":0.8048611,"top":0.19222222,"width":0.022222223,"height":0.035555556},"role_description":"toggle button","subrole":"AXToggleButton","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXCheckBox","text":"React with eyes","depth":26,"bounds":{"left":0.82708335,"top":0.19222222,"width":0.022222223,"height":0.035555556},"role_description":"toggle button","subrole":"AXToggleButton","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXCheckBox","text":"React with raised_hands","depth":26,"bounds":{"left":0.84930557,"top":0.19222222,"width":0.022222223,"height":0.035555556},"role_description":"toggle button","subrole":"AXToggleButton","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Add reaction…","depth":26,"bounds":{"left":0.8715278,"top":0.19222222,"width":0.022222223,"height":0.035555556},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Reply in thread","depth":26,"bounds":{"left":0.89375,"top":0.19222222,"width":0.022222223,"height":0.035555556},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Forward message…","depth":26,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXCheckBox","text":"Save for later","depth":26,"role_description":"toggle button","subrole":"AXToggleButton","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXPopUpButton","text":"More actions","depth":26,"role_description":"pop-up button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXLink","text":"Apr 9th at 12:08:35 PM","depth":25,"bounds":{"left":0.7375,"top":0.26333332,"width":0.021527778,"height":0.016666668},"role_description":"link","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"12:08","depth":26,"bounds":{"left":0.7375,"top":0.26333332,"width":0.021527778,"height":0.016666668},"role_description":"text"},{"role":"AXStaticText","text":"правя fine tuning на настойките за синхронизация на мейли","depth":25,"bounds":{"left":0.76458335,"top":0.26,"width":0.16319445,"height":0.044444446},"role_description":"text"},{"role":"AXCheckBox","text":"React with white_check_mark","depth":26,"bounds":{"left":0.8048611,"top":0.22555555,"width":0.022222223,"height":0.035555556},"role_description":"toggle button","subrole":"AXToggleButton","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXCheckBox","text":"React with eyes","depth":26,"bounds":{"left":0.82708335,"top":0.22555555,"width":0.022222223,"height":0.035555556},"role_description":"toggle button","subrole":"AXToggleButton","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXCheckBox","text":"React with raised_hands","depth":26,"bounds":{"left":0.84930557,"top":0.22555555,"width":0.022222223,"height":0.035555556},"role_description":"toggle button","subrole":"AXToggleButton","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Add reaction…","depth":26,"bounds":{"left":0.8715278,"top":0.22555555,"width":0.022222223,"height":0.035555556},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Reply in thread","depth":26,"bounds":{"left":0.89375,"top":0.22555555,"width":0.022222223,"height":0.035555556},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Forward message…","depth":26,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXCheckBox","text":"Save for later","depth":26,"role_description":"toggle button","subrole":"AXToggleButton","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXPopUpButton","text":"More actions","depth":26,"role_description":"pop-up button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Lukas Kovalik","depth":24,"bounds":{"left":0.76458335,"top":0.31555554,"width":0.06458333,"height":0.024444444},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"","depth":24,"bounds":{"left":0.82916665,"top":0.31777778,"width":0.0055555557,"height":0.02},"role_description":"text"},{"role":"AXLink","text":"Apr 9th at 12:11:24 PM","depth":24,"bounds":{"left":0.8347222,"top":0.3211111,"width":0.036111113,"height":0.016666668},"role_description":"link","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"12:11 PM","depth":25,"bounds":{"left":0.8347222,"top":0.3211111,"width":0.036111113,"height":0.016666668},"role_description":"text"},{"role":"AXStaticText","text":"готово","depth":25,"bounds":{"left":0.76458335,"top":0.3422222,"width":0.031944446,"height":0.02},"role_description":"text"},{"role":"AXCheckBox","text":"React with white_check_mark","depth":26,"bounds":{"left":0.8048611,"top":0.29666665,"width":0.022222223,"height":0.035555556},"role_description":"toggle button","subrole":"AXToggleButton","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXCheckBox","text":"React with eyes","depth":26,"bounds":{"left":0.82708335,"top":0.29666665,"width":0.022222223,"height":0.035555556},"role_description":"toggle button","subrole":"AXToggleButton","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXCheckBox","text":"React with raised_hands","depth":26,"bounds":{"left":0.84930557,"top":0.29666665,"width":0.022222223,"height":0.035555556},"role_description":"toggle button","subrole":"AXToggleButton","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Add reaction…","depth":26,"bounds":{"left":0.8715278,"top":0.29666665,"width":0.022222223,"height":0.035555556},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Reply in thread","depth":26,"bounds":{"left":0.89375,"top":0.29666665,"width":0.022222223,"height":0.035555556},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Forward message…","depth":26,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXCheckBox","text":"Save for later","depth":26,"role_description":"toggle button","subrole":"AXToggleButton","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXPopUpButton","text":"More actions","depth":26,"role_description":"pop-up button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Vasil Vasilev","depth":24,"bounds":{"left":0.76458335,"top":0.37333333,"width":0.057638887,"height":0.024444444},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"","depth":24,"bounds":{"left":0.82222223,"top":0.37555555,"width":0.0055555557,"height":0.02},"role_description":"text"},{"role":"AXLink","text":"Apr 9th at 12:11:50 PM","depth":24,"bounds":{"left":0.82708335,"top":0.37888888,"width":0.036805555,"height":0.016666668},"role_description":"link","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"12:11 PM","depth":25,"bounds":{"left":0.82708335,"top":0.37888888,"width":0.036805555,"height":0.016666668},"role_description":"text"},{"role":"AXStaticText","text":"благодаря","depth":25,"bounds":{"left":0.76458335,"top":0.4,"width":0.05,"height":0.02},"role_description":"text"},{"role":"AXCheckBox","text":"React with white_check_mark","depth":26,"bounds":{"left":0.8048611,"top":0.35444444,"width":0.022222223,"height":0.035555556},"role_description":"toggle button","subrole":"AXToggleButton","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXCheckBox","text":"React with eyes","depth":26,"bounds":{"left":0.82708335,"top":0.35444444,"width":0.022222223,"height":0.035555556},"role_description":"toggle button","subrole":"AXToggleButton","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXCheckBox","text":"React with raised_hands","depth":26,"bounds":{"left":0.84930557,"top":0.35444444,"width":0.022222223,"height":0.035555556},"role_description":"toggle button","subrole":"AXToggleButton","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Add reaction…","depth":26,"bounds":{"left":0.8715278,"top":0.35444444,"width":0.022222223,"height":0.035555556},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Reply in thread","depth":26,"bounds":{"left":0.89375,"top":0.35444444,"width":0.022222223,"height":0.035555556},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Forward message…","depth":26,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXCheckBox","text":"Save for later","depth":26,"role_description":"toggle button","subrole":"AXToggleButton","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXPopUpButton","text":"More actions","depth":26,"role_description":"pop-up button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXPopUpButton","text":"Jump to date","depth":23,"bounds":{"left":0.83194447,"top":0.4422222,"width":0.05277778,"height":0.031111112},"role_description":"pop-up button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"New","depth":23,"bounds":{"left":0.96458334,"top":0.4488889,"width":0.01875,"height":0.017777778},"role_description":"text"},{"role":"AXButton","text":"Vasil Vasilev","depth":24,"bounds":{"left":0.76458335,"top":0.48555556,"width":0.057638887,"height":0.024444444},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"","depth":24,"bounds":{"left":0.82222223,"top":0.48777777,"width":0.0055555557,"height":0.02},"role_description":"text"},{"role":"AXLink","text":"Today at 2:01:40 PM","depth":24,"bounds":{"left":0.82708335,"top":0.4911111,"width":0.031944446,"height":0.016666668},"role_description":"link","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"2:01 PM","depth":25,"bounds":{"left":0.82708335,"top":0.4911111,"width":0.031944446,"height":0.016666668},"role_description":"text"},{"role":"AXStaticText","text":"Лукаш привет","depth":25,"bounds":{"left":0.76458335,"top":0.51222223,"width":0.06875,"height":0.02},"role_description":"text"},{"role":"AXCheckBox","text":"React with white_check_mark","depth":26,"bounds":{"left":0.8048611,"top":0.46666667,"width":0.022222223,"height":0.035555556},"role_description":"toggle button","subrole":"AXToggleButton","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXCheckBox","text":"React with eyes","depth":26,"bounds":{"left":0.82708335,"top":0.46666667,"width":0.022222223,"height":0.035555556},"role_description":"toggle button","subrole":"AXToggleButton","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXCheckBox","text":"React with raised_hands","depth":26,"bounds":{"left":0.84930557,"top":0.46666667,"width":0.022222223,"height":0.035555556},"role_description":"toggle button","subrole":"AXToggleButton","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Add reaction…","depth":26,"bounds":{"left":0.8715278,"top":0.46666667,"width":0.022222223,"height":0.035555556},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Reply in thread","depth":26,"bounds":{"left":0.89375,"top":0.46666667,"width":0.022222223,"height":0.035555556},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Forward message…","depth":26,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXCheckBox","text":"Save for later","depth":26,"role_description":"toggle button","subrole":"AXToggleButton","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXPopUpButton","text":"More actions","depth":26,"role_description":"pop-up button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXLink","text":"Today at 2:01:49 PM","depth":25,"bounds":{"left":0.7423611,"top":0.54888886,"width":0.016666668,"height":0.016666668},"role_description":"link","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"2:01","depth":26,"bounds":{"left":0.7423611,"top":0.54888886,"width":0.016666668,"height":0.016666668},"role_description":"text"},{"role":"AXStaticText","text":"може ли да разглдаш този ПР като имаш малко време:","depth":25,"bounds":{"left":0.76458335,"top":0.54555553,"width":0.19861111,"height":0.044444446},"role_description":"text"},{"role":"AXLink","text":"https://github.com/jiminny/app/pull/11949","depth":25,"bounds":{"left":0.76458335,"top":0.59444445,"width":0.19791667,"height":0.02},"role_description":"link","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"https://github.com/jiminny/app/pull/11949","depth":26,"bounds":{"left":0.76458335,"top":0.59444445,"width":0.19791667,"height":0.02},"role_description":"text"},{"role":"AXCheckBox","text":"React with white_check_mark","depth":26,"bounds":{"left":0.8048611,"top":0.51111114,"width":0.022222223,"height":0.035555556},"role_description":"toggle button","subrole":"AXToggleButton","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXCheckBox","text":"React with eyes","depth":26,"bounds":{"left":0.82708335,"top":0.51111114,"width":0.022222223,"height":0.035555556},"role_description":"toggle button","subrole":"AXToggleButton","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXCheckBox","text":"React with raised_hands","depth":26,"bounds":{"left":0.84930557,"top":0.51111114,"width":0.022222223,"height":0.035555556},"role_description":"toggle button","subrole":"AXToggleButton","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Add reaction…","depth":26,"bounds":{"left":0.8715278,"top":0.51111114,"width":0.022222223,"height":0.035555556},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Reply in thread","depth":26,"bounds":{"left":0.89375,"top":0.51111114,"width":0.022222223,"height":0.035555556},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Forward message…","depth":26,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXCheckBox","text":"Save for later","depth":26,"role_description":"toggle button","subrole":"AXToggleButton","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXPopUpButton","text":"More actions","depth":26,"role_description":"pop-up button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXLink","text":"Today at 2:01:59 PM","depth":25,"bounds":{"left":0.7423611,"top":0.6311111,"width":0.016666668,"height":0.016666668},"role_description":"link","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"2:01","depth":26,"bounds":{"left":0.7423611,"top":0.6311111,"width":0.016666668,"height":0.016666668},"role_description":"text"},{"role":"AXStaticText","text":"повечето промени са семантични, не са функционални","depth":25,"bounds":{"left":0.76458335,"top":0.62777776,"width":0.19166666,"height":0.044444446},"role_description":"text"}]...
|
-4771166984679079823
|
-1280828954467972796
|
idle
|
hybrid
|
NULL
|
Jiminny Inc
Jiminny (Staging)
Add workspaces
Home
Jiminny Inc
Jiminny (Staging)
Add workspaces
Home
Home
DMs
DMs
Activity
Activity
Files
Files
Later
Later
More…
More
Unreads
Threads
Huddles
Drafts & sent
Directories
platform-inner-team
ai-chapter
alerts
backend
confusion-clinic
curiosity_lab
engineering
frontend
general
infra-changes
jiminny-bg
platform-tickets
product_launches
random
releases
sofia-office
support
thank-yous
the_people_of_jiminny
Vasil Vasilev
Aneliya Angelova
,
Nikolay Yankov
,
Steliyan Georgiev
Steliyan Georgiev
Adelina Petrova
,
Ilian Kyuchukov
,
Steliyan Georgiev
Adelina Petrova
Galya Dimitrova
Nikolay Nikolov
Galya Dimitrova
,
Nikolay Nikolov
Galya Dimitrova
,
Nikolay Yankov
Nikolay Yankov
Jira Cloud
Toast
Google Calendar
Messages
Messages
Add canvas
Add canvas
Files
Files
Pins
Pins
Add and Edit Channel Tabs
Canvas
List
Folder
Jump to date
Apr 8th at 7:34:06 PM
7:34
можеш ли да дадеш един approve тука
Apr 8th at 7:34:09 PM
7:34
че видях един тъп проблем
Lukas Kovalik
Apr 8th at 7:34:09 PM
7:34 PM
здрасти, да
Vasil Vasilev
Apr 8th at 7:34:10 PM
7:34 PM
https://github.com/jiminny/app/pull/11920
https://github.com/jiminny/app/pull/11920
Lukas Kovalik
Apr 8th at 7:34:31 PM
7:34 PM
готово
Vasil Vasilev
Apr 8th at 7:34:36 PM
7:34 PM
благодаря
Jump to date
Vasil Vasilev
Apr 9th at 12:08:16 PM
12:08 PM
Лукаш, привет
Apr 9th at 12:08:19 PM
12:08
https://github.com/jiminny/app/pull/11928
https://github.com/jiminny/app/pull/11928
React with white_check_mark
React with eyes
React with raised_hands
Add reaction…
Reply in thread
Forward message…
Save for later
More actions
Apr 9th at 12:08:25 PM
12:08
трябва ми един approve, моля
React with white_check_mark
React with eyes
React with raised_hands
Add reaction…
Reply in thread
Forward message…
Save for later
More actions
Apr 9th at 12:08:35 PM
12:08
правя fine tuning на настойките за синхронизация на мейли
React with white_check_mark
React with eyes
React with raised_hands
Add reaction…
Reply in thread
Forward message…
Save for later
More actions
Lukas Kovalik
Apr 9th at 12:11:24 PM
12:11 PM
готово
React with white_check_mark
React with eyes
React with raised_hands
Add reaction…
Reply in thread
Forward message…
Save for later
More actions
Vasil Vasilev
Apr 9th at 12:11:50 PM
12:11 PM
благодаря
React with white_check_mark
React with eyes
React with raised_hands
Add reaction…
Reply in thread
Forward message…
Save for later
More actions
Jump to date
New
Vasil Vasilev
Today at 2:01:40 PM
2:01 PM
Лукаш привет
React with white_check_mark
React with eyes
React with raised_hands
Add reaction…
Reply in thread
Forward message…
Save for later
More actions
Today at 2:01:49 PM
2:01
може ли да разглдаш този ПР като имаш малко време:
https://github.com/jiminny/app/pull/11949
https://github.com/jiminny/app/pull/11949
React with white_check_mark
React with eyes
React with raised_hands
Add reaction…
Reply in thread
Forward message…
Save for later
More actions
Today at 2:01:59 PM
2:01
повечето промени са семантични, не са функционални
SlackFileEditViewGoHistoryWindowHelpec2-userGDOCKER981DEV (docker)882APP (-zsh)[EMAIL]@73b64f5d54a3:/home/jiminny#[ec2-user@ip-10-30-93-249 ~]$ dockerexec -it $(dockny && bash"root@c78a087b1345:/home/Jiminny# php artisan automated-reports[2026-04-14 10:46:08] staging.INF0: [automated-reports] Started{"correlation_id":"5[2026-04-1410:46:08]staging.INFO: [automated-reports] Checking conditions {"isMondaid":"5c23e861-2ca9-4f92-9f67-773d6bc80ca0","trace_id" :"185df6f6-4327-4609-9cZe-2ab83a[2026-04-14 10:46:08]ab83a0f5432"}staging. INFO: [automated-reports] Processing daily reports{"c[2026-04-1410:46:08]9-9c2e-2ab83a0f5432"}staging.INFO: [automated-reports]Found 3 daily reports to proc[2026-04-1410:46:087daily"staging.INFO: [automated-reports]Dispatching Generate Report j,"type":"ask_jiminny"} {"correlation_id":"5c23e861-2ca9-4f92-9f67-773d6bc80ca®"[2026-04-14 10:46:08]staging.INFO: [automated-reports]Dispatching Generate Report jdaily", "type": "ask_jiminny"} {"correlation_id":"5c23e861-2ca9-4f92-9f67-773d6bc80cab"[2026-04-14 10:46:08]staging. INFO: [automated-reports]daily'", "type" "ask-fiminny"'} ("correlation-id' : 5c2se861-2ca -4792-9f87-773 e8oca[2026-04-14 10:46:08]staging.INFO: [automated-reports]Completed{"correlation_id":root@c78a087b1345:/home/jiminny# phpartisanautomated-reports --report-id 35[2026-04-14 10:48:42] staging.INFO: [automated-reports]Started{"correlation_id":"2[2026-04-14 10:48:42]staging.INFO: [automated-reports]Checking conditions {"isMondaid":"246a1ala-7076-458c-bd7d-49d2f5a2db88","trace_id":"1f894bf6-e50d-4e99-b635-2aa526[2026-04-14 10:48:42]staging.INFO: [automated-reports]Processing daily reports{"caa52627fc27"}[automated-reports] Automated report[2026-04-14 10:48:42]staging.INFO: [automated-reports] Found 1 daily reports to proc9-b635-2aa52627f c27"}[2026-04-14 10:48:42]staging.INF0: [automated-reports]Dispatching Generate Reportdaily","type": "ask_jiminny"} {"correlation_id":"246a1a1a-7076-458c-bd7d-49d2f5a2db88"[2026-04-14 10:48:42]staging.INFO: [automated-reports]Completed{"correlation_id":root@c78a087b1345:/home/jiminny# [ec2-user@ip-10-30-93-249 ~]$I+HomeDMsActivityFilesLater.*•MorelhlJiminny ...+tscnicrol# infra-changes# jiminny-bg# platform-tickets# product_launches# random# releases# sofia-office# support# thank-yous# the_people_of jimi...Direct messagesE. Vasil VasilevAneliya Angelova, ...Steliyan GeorgievAdelina Petrova, Ili...0. Adelina Petrova. Galya Dimitrova&s Nikolay Nikolov "2Galya Dimitrova, Ni...2Galya Dimitrova, Ni...P. Nikolay Yankov::: AppsJira CloudToastGoogle Cale...§ Support Daily • in 45 m100% <7Tue 14 Apr 14:15:44→Search Jiminny IncVasil VasilevMessagesAdd canvasC Files< Pinsлукаш, приветThursday, April 9th~https://git...rorr/pull/11928+трябва ми един approve, моляправя fine tuning на настойките засинхронизация на мейлиLukas Kovalik 12:11 PMготовоVasil Vasilev 12:11 PMблагодаряToday ~NewVasil Vasilev 2:01 PMЛукаш приветможе ли да разглдаш този ПР като имашмалко време:https://github.com/jiminny/app/pull/11949повечето промени са семантични, не сафункционалниразделям по голям ПР на две частиLukas Kovalik 2:15 PMздрасти, да ще го погледна по-кьсноспешно ли еVasil Vasilev 2:15 PMмерсиMessage Vasil Vasilev...Vasil Vasilev is typing...
|
NULL
|
|
12356
|
266
|
1
|
2026-04-14T11:15:49.563392+00:00
|
/Users/lukas/.screenpipe/data/data/2026-04-14/1776 /Users/lukas/.screenpipe/data/data/2026-04-14/1776165349563_m1.jpg...
|
Firefox
|
Jy 20541 stale records pr 1 by Vasil-Jiminny · Pul Jy 20541 stale records pr 1 by Vasil-Jiminny · Pull Request #11949 · jiminny/app — Work...
|
1
|
github.com/jiminny/app/pull/11949
|
monitor_1
|
NULL
|
NULL
|
NULL
|
NULL
|
JY-20543 add AJ reports User pilot tracking by Lak JY-20543 add AJ reports User pilot tracking by LakyLak · Pull Request #11932 · jiminny/app...
|
[{"role":"AXRadioButton","text [{"role":"AXRadioButton","text":"JY-20543 add AJ reports User pilot tracking by LakyLak · Pull Request #11932 · jiminny/app","depth":4,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false}]...
|
-6086885605405199207
|
-5254201428227363634
|
visual_change
|
hybrid
|
NULL
|
JY-20543 add AJ reports User pilot tracking by Lak JY-20543 add AJ reports User pilot tracking by LakyLak · Pull Request #11932 · jiminny/app
SlackFileEditViewGoHistoryWindowHelpec2-userGDOCKER981DEV (docker)882APP (-zsh)[EMAIL]@73b64f5d54a3:/home/jiminny#[ec2-user@ip-10-30-93-249ny && bash"root@c78a087b1345:/home/jiminny# php artisan automated-reports[2026-04-1410:46:087staging.INFO: [automated-reports]Started~7$ dockerexec -it $(dock{"correlation_id":"5[2026-04-1410:46:08]staging. INFO: [automated-reports]Checking conditions {"isMondaid":"5c23e861-2ca9-4f92-9f67-773d6bc80ca0","trace_id" :"185df6f6-4327-4609-9cZe-2ab83a[2026-04-1410:46:08]ab83a0f5432"}staging.INFO: [automated-reports] Processing daily reports[2026-04-1410:46:08]9-9cZe-2ab83a0f5432"}staging.INFO:[automated-reports]Found 3 daily reports to proc[2026-04-1410:46:08Jstaging.INF0:[automated-reports]Dispatching Generate ReportPS-Firefoxroot@c78a087b1345:/home/jiminny# php artisan automated-reports --report-id 35[2026-04-14 10:48:42]staging.INFO: [automated-reports] Started{"correlation_id":"2[2026-04-14 10:48:42]staging.INF0: [automated-reports]Checking conditions {"isMondaid": "246a1a1a-7076-458c-bd7d-49d2f5a2db88", "trace_id" : "1f894bf6-e50d-4e99-b635-2aa526[2026-04-14 10:48:42]staging.INFO: [automated-reports] Processing daily reportsaa52627fc27"}[automated-reports] Automated report found Test[2026-04-14 10:48:42]staging. INFO: [automated-reports]Found 1 daily reports to proc9-b635-2aa52627f c27"}[2026-04-14 10:48:42]staging.INFO: [automated-reports]Dispatching Generate Reportdaily","type": "ask_jiminny"} {"correlation_id":"246a1a1a-7076-458c-bd7d-49d2f5a2db88"[2026-04-14 10:48:42] staging.INF0: [automated-reports]Completed{"correlation_id":root@c78a087b1345:/home/jiminny# [ec2-user@ip-10-30-93-249 ~]$D+EDHomeDMsActivityFileslhlSupport Daily • in 45 m100% <7Tue 14 Apr 14:15:49→Search Jiminny IncJiminny ...scnicre# infra-changes# jiminny-bg# platform-tickets# product_launches# random# releases# sofia-office# supportthank-vous(3Adelina Petrova, Ili...0. Adelina Petrova. Galya Dimitrova&s Nikolay Nikolov "2 Galya Dimitrova, Ni...2Galya Dimitrova, Ni...P. Nikolay YankovAppsJira CloudToastGoogle Cale... SsVasil Vasilev6 0• MessagesAdd canvasC Files< Pinsлукаш, приветThursday, April 9th~https://gitr.yrery/pull/11928+трябва ми един approve, моляправя fine tuning на настойките засинхронизация на мейлиLukas Kovalik 12:11 PMготовоVasil Vasilev 12:11 PMKaarAnanaNhttps://github.com/jiminny/app/pull/11949повечето промени са семантични, не сафункционалниразделям по голям ПР на две частиLukas Kovalik 2:15 PMздрасти, да ще го погледна по-кьсноспешно ли еVasil Vasilev 2:15 PMмерсиMessage Vasil Vasilev+Aa.••Vasil Vasilev is typing...
|
12355
|
|
12358
|
266
|
2
|
2026-04-14T11:15:52.505850+00:00
|
/Users/lukas/.screenpipe/data/data/2026-04-14/1776 /Users/lukas/.screenpipe/data/data/2026-04-14/1776165352505_m1.jpg...
|
Firefox
|
Jy 20541 stale records pr 1 by Vasil-Jiminny · Pul Jy 20541 stale records pr 1 by Vasil-Jiminny · Pull Request #11949 · jiminny/app — Work...
|
1
|
github.com/jiminny/app/pull/11949
|
monitor_1
|
NULL
|
NULL
|
NULL
|
NULL
|
JY-20543 add AJ reports User pilot tracking by Lak JY-20543 add AJ reports User pilot tracking by LakyLak · Pull Request #11932 · jiminny/app
Pipelines - jiminny/app
Feed — jiminny — Sentry
Platform Sprint 1 Q2 - Platform Team - Scrum Board - Jira
Platform Sprint 1 Q2 - Platform Team - Scrum Board - Jira
JY-20543 add AJ reports User pilot tracking by LakyLak · Pull Request #11932 · jiminny/app
JY-20543 add AJ reports User pilot tracking by LakyLak · Pull Request #11932 · jiminny/app
Configure SSH access to multiple environment - Engineering - Confluence
Configure SSH access to multiple environment - Engineering - Confluence
Console Home | Console Home | us-east-2
Console Home | Console Home | us-east-2
SecurityGroup | EC2 | us-east-2
SecurityGroup | EC2 | us-east-2
JY-20543 add AJ reports User pilot tracking by LakyLak · Pull Request #11932 · jiminny/app
JY-20543 add AJ reports User pilot tracking by LakyLak · Pull Request #11932 · jiminny/app
SRD-6779 | JY-20632 | Unable to log in to Sidekick with SSO by yalokin-jiminny · Pull Request #11935 · jiminny/app
SRD-6779 | JY-20632 | Unable to log in to Sidekick with SSO by yalokin-jiminny · Pull Request #11935 · jiminny/app
Jy 19798 evaluation for ai activity types by nikolaybiaivanov · Pull Request #468 · jiminny/prophet
Jy 19798 evaluation for ai activity types by nikolaybiaivanov · Pull Request #468 · jiminny/prophet
Jiminny
Jiminny
Ask Jiminny test report - 8 Apr 2026 - Ask Jiminny test report - 13 Apr 2026.pdf
Ask Jiminny test report - 8 Apr 2026 - Ask Jiminny test report - 13 Apr 2026.pdf
Service-Desk - Queues - Platform team - Service space - Jira
Service-Desk - Queues - Platform team - Service space - Jira
JY-20543 add AJ reports User pilot tracking by LakyLak · Pull Request #11932 · jiminny/app
JY-20543 add AJ reports User pilot tracking by LakyLak · Pull Request #11932 · jiminny/app
Configure SSH access to multiple environment - Engineering - Confluence
Configure SSH access to multiple environment - Engineering - Confluence
New Tab
New Tab
CloudWatch | us-east-2
CloudWatch | us-east-2
Jy 20541 stale records pr 1 by Vasil-Jiminny · Pull Request #11949 · jiminny/app
Jy 20541 stale records pr 1 by Vasil-Jiminny · Pull Request #11949 · jiminny/app
Close tab
New Tab
Customize sidebar
Open Google Gemini (⌃X)
Tabs from other devices
Open history (⇧⌘H)
Open bookmarks (⌘B)
Skip to content
Skip to content
Open menu
Homepage (g then d)
jiminny
jiminny
app
app
Search or jump to…
Type
/
to search
Chat with Copilot
Open Copilot…
Create new...
Issues(g then i)
Pull requests
Repositories
You have unread notifications(g then n)
Open user navigation menu
Repository navigation
Repository navigation
Code
Code
Pull requests (28)
Pull requests
(
28
)
Agents
Agents
Actions
Actions
Wiki
Wiki
Security and quality (24)
Security and quality
(
24
)
Insights
Insights
Settings
Settings
Important update
Important update
On April 24 we'll start using GitHub Copilot interaction data for AI model training unless you opt out.
Review this update
Review this update
and manage your preferences in your
GitHub account settings
GitHub account settings
.
Dismiss banner
Review requested
Review requested
Vasil-Jiminny
Vasil-Jiminny
requested your review on this pull request.
Add your review
Add your review
Jy 20541 stale records pr 1 #11949 Edit title
Jy 20541 stale records pr 1
#
11949
Edit title
Awaiting approval
Awaiting approval
Code
Code
Open
Vasil-Jiminny
Vasil-Jiminny
wants to merge 18 commits into
master
master
from
JY-20541-stale-records-pr-1
JY-20541-stale-records-pr-1
Copy head branch name to clipboard
Lines changed: 183 additions & 33 deletions
Conversation (11)
Conversation
(
11
)
Commits (18)
Commits
(
18
)
Checks (3)
Checks
(
3
)
Files changed (18)
Files changed
(
18
)
Conversation
Conversation
@Vasil-Jiminny
Show options
Vasil-Jiminny commented 2 hours ago •
Vasil-Jiminny
Vasil-Jiminny
commented
2 hours ago
2 hours ago
•
edited
edited
JIRA: JY-20541
JIRA:
JY-20541
JY-20541...
|
[{"role":"AXRadioButton","text [{"role":"AXRadioButton","text":"JY-20543 add AJ reports User pilot tracking by LakyLak · Pull Request #11932 · jiminny/app","depth":4,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXRadioButton","text":"Pipelines - jiminny/app","depth":4,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXRadioButton","text":"Feed — jiminny — Sentry","depth":4,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXRadioButton","text":"Platform Sprint 1 Q2 - Platform Team - Scrum Board - Jira","depth":4,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Platform Sprint 1 Q2 - Platform Team - Scrum Board - Jira","depth":5,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"JY-20543 add AJ reports User pilot tracking by LakyLak · Pull Request #11932 · jiminny/app","depth":4,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"JY-20543 add AJ reports User pilot tracking by LakyLak · Pull Request #11932 · jiminny/app","depth":5,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Configure SSH access to multiple environment - Engineering - Confluence","depth":4,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Configure SSH access to multiple environment - Engineering - Confluence","depth":5,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Console Home | Console Home | us-east-2","depth":4,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Console Home | Console Home | us-east-2","depth":5,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"SecurityGroup | EC2 | us-east-2","depth":4,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"SecurityGroup | EC2 | us-east-2","depth":5,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"JY-20543 add AJ reports User pilot tracking by LakyLak · Pull Request #11932 · jiminny/app","depth":4,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"JY-20543 add AJ reports User pilot tracking by LakyLak · Pull Request #11932 · jiminny/app","depth":5,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"SRD-6779 | JY-20632 | Unable to log in to Sidekick with SSO by yalokin-jiminny · Pull Request #11935 · jiminny/app","depth":4,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"SRD-6779 | JY-20632 | Unable to log in to Sidekick with SSO by yalokin-jiminny · Pull Request #11935 · jiminny/app","depth":5,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Jy 19798 evaluation for ai activity types by nikolaybiaivanov · Pull Request #468 · jiminny/prophet","depth":4,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Jy 19798 evaluation for ai activity types by nikolaybiaivanov · Pull Request #468 · jiminny/prophet","depth":5,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Jiminny","depth":4,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Jiminny","depth":5,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Ask Jiminny test report - 8 Apr 2026 - Ask Jiminny test report - 13 Apr 2026.pdf","depth":4,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Ask Jiminny test report - 8 Apr 2026 - Ask Jiminny test report - 13 Apr 2026.pdf","depth":5,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Service-Desk - Queues - Platform team - Service space - Jira","depth":4,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Service-Desk - Queues - Platform team - Service space - Jira","depth":5,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"JY-20543 add AJ reports User pilot tracking by LakyLak · Pull Request #11932 · jiminny/app","depth":4,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"JY-20543 add AJ reports User pilot tracking by LakyLak · Pull Request #11932 · jiminny/app","depth":5,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Configure SSH access to multiple environment - Engineering - Confluence","depth":4,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Configure SSH access to multiple environment - Engineering - Confluence","depth":5,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"New Tab","depth":4,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"New Tab","depth":5,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"CloudWatch | us-east-2","depth":4,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"CloudWatch | us-east-2","depth":5,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Jy 20541 stale records pr 1 by Vasil-Jiminny · Pull Request #11949 · jiminny/app","depth":4,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":true},{"role":"AXStaticText","text":"Jy 20541 stale records pr 1 by Vasil-Jiminny · Pull Request #11949 · jiminny/app","depth":5,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"Close tab","depth":5,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXButton","text":"New Tab","depth":4,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXCheckBox","text":"Customize sidebar","depth":6,"help_text":"","role_description":"toggle button","subrole":"AXToggle","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXCheckBox","text":"Open Google Gemini (⌃X)","depth":6,"help_text":"","role_description":"toggle button","subrole":"AXToggle","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXCheckBox","text":"Tabs from other devices","depth":6,"help_text":"","role_description":"toggle button","subrole":"AXToggle","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXCheckBox","text":"Open history (⇧⌘H)","depth":6,"help_text":"","role_description":"toggle button","subrole":"AXToggle","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXCheckBox","text":"Open bookmarks (⌘B)","depth":6,"help_text":"","role_description":"toggle button","subrole":"AXToggle","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXLink","text":"Skip to content","depth":6,"help_text":"","role_description":"link","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Skip to content","depth":7,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"Open menu","depth":10,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXLink","text":"Homepage (g then d)","depth":9,"help_text":"","role_description":"link","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXLink","text":"jiminny","depth":12,"help_text":"","role_description":"link","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"jiminny","depth":14,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXLink","text":"app","depth":12,"help_text":"","role_description":"link","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"app","depth":14,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"Search or jump to…","depth":9,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Type","depth":12,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"/","depth":12,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"to search","depth":12,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXLink","text":"Chat with Copilot","depth":10,"help_text":"","role_description":"link","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXMenuButton","text":"Open Copilot…","depth":9,"help_text":"","role_description":"menu button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXMenuButton","text":"Create new...","depth":9,"help_text":"","role_description":"menu button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXLink","text":"Issues(g then i)","depth":9,"help_text":"","role_description":"link","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXLink","text":"Pull requests","depth":9,"help_text":"","role_description":"link","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXLink","text":"Repositories","depth":9,"help_text":"","role_description":"link","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXLink","text":"You have unread notifications(g then n)","depth":9,"help_text":"","role_description":"link","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXButton","text":"Open user navigation menu","depth":9,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXHeading","text":"Repository navigation","depth":9,"help_text":"","role_description":"heading","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Repository navigation","depth":10,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXLink","text":"Code","depth":12,"help_text":"","role_description":"link","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Code","depth":14,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXLink","text":"Pull requests (28)","depth":12,"help_text":"","role_description":"link","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Pull requests","depth":14,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"(","depth":14,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"28","depth":14,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":")","depth":14,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXLink","text":"Agents","depth":12,"help_text":"","role_description":"link","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Agents","depth":14,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXLink","text":"Actions","depth":12,"help_text":"","role_description":"link","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Actions","depth":14,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXLink","text":"Wiki","depth":12,"help_text":"","role_description":"link","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Wiki","depth":14,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXLink","text":"Security and quality (24)","depth":12,"help_text":"","role_description":"link","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Security and quality","depth":14,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"(","depth":14,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"24","depth":14,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":")","depth":14,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXLink","text":"Insights","depth":12,"help_text":"","role_description":"link","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Insights","depth":14,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXLink","text":"Settings","depth":12,"help_text":"","role_description":"link","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Settings","depth":14,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXHeading","text":"Important update","depth":10,"help_text":"","role_description":"heading","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Important update","depth":11,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"On April 24 we'll start using GitHub Copilot interaction data for AI model training unless you opt out.","depth":10,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXLink","text":"Review this update","depth":10,"help_text":"","role_description":"link","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Review this update","depth":11,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"and manage your preferences in your","depth":10,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXLink","text":"GitHub account settings","depth":10,"help_text":"","role_description":"link","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"GitHub account settings","depth":11,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":".","depth":10,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"Dismiss banner","depth":9,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXHeading","text":"Review requested","depth":15,"help_text":"","role_description":"heading","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Review requested","depth":16,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXLink","text":"Vasil-Jiminny","depth":15,"help_text":"","role_description":"link","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Vasil-Jiminny","depth":16,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"requested your review on this pull request.","depth":15,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXLink","text":"Add your review","depth":14,"help_text":"","role_description":"link","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Add your review","depth":16,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXHeading","text":"Jy 20541 stale records pr 1 #11949 Edit title","depth":13,"help_text":"","role_description":"heading","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Jy 20541 stale records pr 1","depth":14,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"#","depth":15,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"11949","depth":15,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"Edit title","depth":14,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXButton","text":"Awaiting approval","depth":13,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Awaiting approval","depth":15,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXMenuButton","text":"Code","depth":13,"help_text":"","role_description":"menu button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"Code","depth":15,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Open","depth":13,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXLink","text":"Vasil-Jiminny","depth":15,"help_text":"","role_description":"link","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Vasil-Jiminny","depth":16,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"wants to merge 18 commits into","depth":15,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXLink","text":"master","depth":15,"role_description":"link","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"master","depth":16,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"from","depth":16,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXLink","text":"JY-20541-stale-records-pr-1","depth":16,"role_description":"link","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"JY-20541-stale-records-pr-1","depth":17,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"Copy head branch name to clipboard","depth":16,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Lines changed: 183 additions & 33 deletions","depth":14,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Conversation (11)","depth":16,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":true},{"role":"AXStaticText","text":"Conversation","depth":17,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"(","depth":18,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"11","depth":18,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":")","depth":18,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Commits (18)","depth":16,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Commits","depth":17,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"(","depth":18,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"18","depth":18,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":")","depth":18,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Checks (3)","depth":16,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Checks","depth":17,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"(","depth":18,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"3","depth":18,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":")","depth":18,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Files changed (18)","depth":16,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Files changed","depth":17,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"(","depth":18,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"18","depth":18,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":")","depth":18,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXHeading","text":"Conversation","depth":12,"help_text":"","role_description":"heading","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Conversation","depth":13,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXLink","text":"@Vasil-Jiminny","depth":12,"help_text":"","role_description":"link","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXButton","text":"Show options","depth":15,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXHeading","text":"Vasil-Jiminny commented 2 hours ago •","depth":14,"help_text":"","role_description":"heading","subrole":"AXUnknown"},{"role":"AXLink","text":"Vasil-Jiminny","depth":16,"help_text":"","role_description":"link","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Vasil-Jiminny","depth":17,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"commented","depth":15,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXLink","text":"2 hours ago","depth":15,"help_text":"","role_description":"link","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"2 hours ago","depth":17,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"•","depth":17,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"edited","depth":17,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"edited","depth":19,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXHeading","text":"JIRA: JY-20541","depth":16,"help_text":"","role_description":"heading","subrole":"AXUnknown"},{"role":"AXStaticText","text":"JIRA:","depth":17,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXLink","text":"JY-20541","depth":17,"help_text":"","role_description":"link","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"JY-20541","depth":18,"help_text":"","role_description":"text","subrole":"AXUnknown"}]...
|
-4387842904135014429
|
-5677537538402895154
|
visual_change
|
accessibility
|
NULL
|
JY-20543 add AJ reports User pilot tracking by Lak JY-20543 add AJ reports User pilot tracking by LakyLak · Pull Request #11932 · jiminny/app
Pipelines - jiminny/app
Feed — jiminny — Sentry
Platform Sprint 1 Q2 - Platform Team - Scrum Board - Jira
Platform Sprint 1 Q2 - Platform Team - Scrum Board - Jira
JY-20543 add AJ reports User pilot tracking by LakyLak · Pull Request #11932 · jiminny/app
JY-20543 add AJ reports User pilot tracking by LakyLak · Pull Request #11932 · jiminny/app
Configure SSH access to multiple environment - Engineering - Confluence
Configure SSH access to multiple environment - Engineering - Confluence
Console Home | Console Home | us-east-2
Console Home | Console Home | us-east-2
SecurityGroup | EC2 | us-east-2
SecurityGroup | EC2 | us-east-2
JY-20543 add AJ reports User pilot tracking by LakyLak · Pull Request #11932 · jiminny/app
JY-20543 add AJ reports User pilot tracking by LakyLak · Pull Request #11932 · jiminny/app
SRD-6779 | JY-20632 | Unable to log in to Sidekick with SSO by yalokin-jiminny · Pull Request #11935 · jiminny/app
SRD-6779 | JY-20632 | Unable to log in to Sidekick with SSO by yalokin-jiminny · Pull Request #11935 · jiminny/app
Jy 19798 evaluation for ai activity types by nikolaybiaivanov · Pull Request #468 · jiminny/prophet
Jy 19798 evaluation for ai activity types by nikolaybiaivanov · Pull Request #468 · jiminny/prophet
Jiminny
Jiminny
Ask Jiminny test report - 8 Apr 2026 - Ask Jiminny test report - 13 Apr 2026.pdf
Ask Jiminny test report - 8 Apr 2026 - Ask Jiminny test report - 13 Apr 2026.pdf
Service-Desk - Queues - Platform team - Service space - Jira
Service-Desk - Queues - Platform team - Service space - Jira
JY-20543 add AJ reports User pilot tracking by LakyLak · Pull Request #11932 · jiminny/app
JY-20543 add AJ reports User pilot tracking by LakyLak · Pull Request #11932 · jiminny/app
Configure SSH access to multiple environment - Engineering - Confluence
Configure SSH access to multiple environment - Engineering - Confluence
New Tab
New Tab
CloudWatch | us-east-2
CloudWatch | us-east-2
Jy 20541 stale records pr 1 by Vasil-Jiminny · Pull Request #11949 · jiminny/app
Jy 20541 stale records pr 1 by Vasil-Jiminny · Pull Request #11949 · jiminny/app
Close tab
New Tab
Customize sidebar
Open Google Gemini (⌃X)
Tabs from other devices
Open history (⇧⌘H)
Open bookmarks (⌘B)
Skip to content
Skip to content
Open menu
Homepage (g then d)
jiminny
jiminny
app
app
Search or jump to…
Type
/
to search
Chat with Copilot
Open Copilot…
Create new...
Issues(g then i)
Pull requests
Repositories
You have unread notifications(g then n)
Open user navigation menu
Repository navigation
Repository navigation
Code
Code
Pull requests (28)
Pull requests
(
28
)
Agents
Agents
Actions
Actions
Wiki
Wiki
Security and quality (24)
Security and quality
(
24
)
Insights
Insights
Settings
Settings
Important update
Important update
On April 24 we'll start using GitHub Copilot interaction data for AI model training unless you opt out.
Review this update
Review this update
and manage your preferences in your
GitHub account settings
GitHub account settings
.
Dismiss banner
Review requested
Review requested
Vasil-Jiminny
Vasil-Jiminny
requested your review on this pull request.
Add your review
Add your review
Jy 20541 stale records pr 1 #11949 Edit title
Jy 20541 stale records pr 1
#
11949
Edit title
Awaiting approval
Awaiting approval
Code
Code
Open
Vasil-Jiminny
Vasil-Jiminny
wants to merge 18 commits into
master
master
from
JY-20541-stale-records-pr-1
JY-20541-stale-records-pr-1
Copy head branch name to clipboard
Lines changed: 183 additions & 33 deletions
Conversation (11)
Conversation
(
11
)
Commits (18)
Commits
(
18
)
Checks (3)
Checks
(
3
)
Files changed (18)
Files changed
(
18
)
Conversation
Conversation
@Vasil-Jiminny
Show options
Vasil-Jiminny commented 2 hours ago •
Vasil-Jiminny
Vasil-Jiminny
commented
2 hours ago
2 hours ago
•
edited
edited
JIRA: JY-20541
JIRA:
JY-20541
JY-20541...
|
NULL
|
|
12359
|
266
|
3
|
2026-04-14T11:15:55.563545+00:00
|
/Users/lukas/.screenpipe/data/data/2026-04-14/1776 /Users/lukas/.screenpipe/data/data/2026-04-14/1776165355563_m1.jpg...
|
Slack
|
Vasil Vasilev (DM) - Jiminny Inc - 1 new item - Sl Vasil Vasilev (DM) - Jiminny Inc - 1 new item - Slack...
|
1
|
NULL
|
monitor_1
|
NULL
|
NULL
|
NULL
|
NULL
|
Jiminny Inc
Jiminny (Staging)
Add workspaces
|
[{"role":"AXRadioButton","text [{"role":"AXRadioButton","text":"Jiminny Inc","depth":12,"bounds":{"left":0.4861111,"top":0.08777778,"width":0.022222223,"height":0.035555556},"role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":true,"is_expanded":false},{"role":"AXRadioButton","text":"Jiminny (Staging)","depth":12,"bounds":{"left":0.4861111,"top":0.14555556,"width":0.022222223,"height":0.035555556},"role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXPopUpButton","text":"Add workspaces","depth":12,"bounds":{"left":0.4861111,"top":0.20333333,"width":0.022222223,"height":0.035555556},"role_description":"pop-up button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false}]...
|
-6060099160039832832
|
7299504895039379552
|
visual_change
|
hybrid
|
NULL
|
Jiminny Inc
Jiminny (Staging)
Add workspaces
Slack Jiminny Inc
Jiminny (Staging)
Add workspaces
SlackFileEditViewGoHistoryWindowHelpec2-userGDOCKER981DEV (docker)882APP (-zsh)[EMAIL]@73b64f5d54a3:/home/jiminny#[ec2-user@ip-10-30-93-249 ~]$ dockerexec -it $(dockny && bash"root@c78a087b1345:/home/Jiminny# php artisan automated-reports[2026-04-14 10:46:08] staging.INF0: [automated-reports] Started{"correlation_id":"5[2026-04-1410:46:08]staging.INFO: [automated-reports] Checking conditions {"isMondaid":"5c23e861-2ca9-4f92-9f67-773d6bc80ca0","trace_id" :"185df6f6-4327-4609-9c2e-2ab83a[2026-04-14 10:46:08]ab83a0f5432"}staging.INFO: [automated-reports] Processing daily reports{"c[2026-04-1410:46:08]9-9c2e-2ab83a0f5432"}staging.INFO: [automated-reports]Found 3 daily reports to proc[2026-04-1410:46:087daily"staging.INFO: [automated-reports]Dispatching Generate Report j,"type":"ask_jiminny"} {"correlation_id":"5c23e861-2ca9-4f92-9f67-773d6bc80ca0"[2026-04-14 10:46:08]staging.INFO: [automated-reports]Dispatching Generate Report jdaily", "type": "ask_jiminny"} {"correlation_id":"5c23e861-2ca9-4f92-9f67-773d6bc80cab"[2026-04-14 10:46:08]staging. INFO: [automated-reports]daily'", "type" "ask-fiminny"'} ("correlation-id' : 5c2se861-2ca -4792-9f87-773 e8oca[2026-04-14 10:46:08]staging.INFO: [automated-reports]Completed{"correlation_id":root@c78a087b1345:/home/jiminny# phpartisanautomated-reports --report-id 35[2026-04-14 10:48:42] staging.INFO: [automated-reports]Started{"correlation_id":"2[2026-04-14 10:48:42]staging.INFO: [automated-reports]Checking conditions {"isMondaid":"246alala-7076-458c-bd7d-49d2f5a2db88","trace_id":"1f894bf6-e50d-4e99-b635-2aa526[2026-04-14 10:48:42]staging.INFO: [automated-reports]Processing daily reports{"caa52627fc27"}[automated-reports] Automated report[2026-04-14 10:48:42]staging. INFO: [automated-reports] Found 1 daily reports to proc9-b635-2aa52627f c27"}[2026-04-14 10:48:42]staging.INF0: [automated-reports]Dispatching Generate Reportdaily","type": "ask_jiminny"} {"correlation_id":"246a1a1a-7076-458c-bd7d-49d2f5a2db88"[2026-04-14 10:48:42]staging.INFO: [automated-reports]Completed{"correlation_id":root@c78a087b1345:/home/jiminny# [ec2-user@ip-10-30-93-249 ~]$D+HomeDMsActivityFilesLater.*•MorelhlJiminny ...+tcncrel# infra-changes# jiminny-bg# platform-tickets# product_launches# random# releases# sofia-office# support# thank-yous# the_people_of jimi...Direct messagesE. Vasil VasilevAneliya Angelova, ...Steliyan GeorgievAdelina Petrova, Ili...0. Adelina Petrova. Galya Dimitrova *&s Nikolay Nikolov "2Galya Dimitrova, Ni...2Galya Dimitrova, Ni...P. Nikolay Yankov::: AppsJira CloudToastGoogle Cale...§ Support Daily • in 45 m100% <Tue 14 Apr 14:15:55→Search Jiminny IncVasil VasilevMessagesAdd canvasC Files< Pins+Thursday, April 9th~трябва Ми -м...правя fine tuning на настойките засинхронизация на мейлиLukas Kovalik 12:11 PMГОТОВОVasil Vasilev 12:11 PMблагодаряToday ~NewVasil Vasilev 2:01 PMЛукаш г2:01https://github.com/jiminny/app/pull/11949M._https:wgithub.com/fiminny/aRP/pull/11949повечето промени са семантични, не сафункционалниразделям по голям ПР на две частиLukas Kovalik 2:15 PMздрасти, да ще го погледна по-кьсноспешно ли еVasil Vasilev 2:15 PMмерсине е спешноMessage Vasil Vasilev...Vasil Vasilev is typing...
|
12358
|
|
12361
|
266
|
4
|
2026-04-14T11:15:57.618531+00:00
|
/Users/lukas/.screenpipe/data/data/2026-04-14/1776 /Users/lukas/.screenpipe/data/data/2026-04-14/1776165357618_m1.jpg...
|
NULL
|
NULL
|
1
|
NULL
|
monitor_1
|
NULL
|
NULL
|
NULL
|
NULL
|
SlackFileEditViewGoHistoryWindowHelpec2-userGDOCKE SlackFileEditViewGoHistoryWindowHelpec2-userGDOCKER981DEV (docker)882APP (-zsh)[EMAIL]@73b64f5d54a3:/home/jiminny#[ec2-user@ip-10-30-93-249 ~]$ dockerexec -it $(dockny && bash"root@c78a087b1345:/home/Jiminny# php artisan automated-reports[2026-04-14 10:46:08] staging.INF0: [automated-reports] Started{"correlation_id":"5[2026-04-1410:46:08]staging.INFO: [automated-reports] Checking conditions {"isMondaid":"5c23e861-2ca9-4f92-9f67-773d6bc80ca0","trace_id" :"185df6f6-4327-4609-9cZe-2ab83a[2026-04-14 10:46:08]ab83a0f5432"}staging.INFO: [automated-reports] Processing daily reports{"c[2026-04-1410:46:08]9-9c2e-2ab83a0f5432"'}staging.INFO: [automated-reports]Found 3 daily reports to proc[2026-04-1410:46:087daily"staging.INFO: [automated-reports]Dispatching Generate Report j,"type":"ask_jiminny"} {"correlation_id":"5c23e861-2ca9-4f92-9f67-773d6bc80ca®"[2026-04-14 10:46:08]staging.INFO: [automated-reports]Dispatching Generate Report jdaily", "type": "ask_jiminny"} {"correlation_id":"5c23e861-2ca9-4f92-9f67-773d6bc80cab"[2026-04-14 10:46:08]staging. INFO: [automated-reports]daily'", "type" "ask-fiminny"'} ("correlation-id' : 5c2se861-2ca -4792-9f87-773 e8oca[2026-04-14 10:46:08]staging.INFO: [automated-reports]Completed{"correlation_id":root@c78a087b1345:/home/jiminny# phpartisanautomated-reports --report-id 35[2026-04-14 10:48:42] staging.INFO: [automated-reports]Started{"correlation_id":"2[2026-04-14 10:48:42]staging.INFO: [automated-reports]Checking conditions {"isMondaid":"246alala-7076-458c-bd7d-49d2f5a2db88","trace_id":"1f894bf6-e50d-4e99-b635-2aa526[2026-04-14 10:48:42]staging.INFO: [automated-reports]Processing daily reports{"caa52627fc27"}[automated-reports] Automated report[2026-04-14 10:48:42]staging.INFO: [automated-reports] Found 1 daily reports to proc9-b635-2aa52627f c27"}[2026-04-14 10:48:42]staging.INF0: [automated-reports]Dispatching Generate Reportdaily","type": "ask_jiminny"} {"correlation_id":"246a1a1a-7076-458c-bd7d-49d2f5a2db88"[2026-04-14 10:48:42]staging.INFO: [automated-reports]Completed{"correlation_id":root@c78a087b1345:/home/jiminny# [ec2-user@ip-10-30-93-249 ~]$I+HomeDMsActivityFilesLater.*•MorelhlJiminny ...+tcncrel# infra-changes# jiminny-bg# platform-tickets# product_launches# random# releases# sofia-office# support# thank-yous# the_people_of jimi...Direct messagesE. Vasil VasilevAneliya Angelova, ...Steliyan GeorgievAdelina Petrova, Ili...0. Adelina Petrova. Galya Dimitrova *&s Nikolay Nikolov "2Galya Dimitrova, Ni...2Galya Dimitrova, Ni...P. Nikolay Yankov::: AppsJira CloudToastGoogle Cale...§ Support Daily • in 45 m100% <Tue 14 Apr 14:15:57→Search Jiminny IncVasil VasilevMessagesAdd canvasC Files< Pinsmaps#/grnao.com/mminnv/aDp/pui/11720Thursday, April 9th~трябва Ми -м...правя fine tuning на настойките засинхронизация на мейли+Lukas Kovalik 12:11 PMГОТОВОVasil Vasilev 12:11 PMблагодаряToday ~NewVasil Vasilev 2:01 PMЛукаш г992:01може ли да разглдаш този ПР като имашмалко време:https://github.com/jiminny/app/pull/11949повечето промени са семантични, не сафункционалниразделям по голям ПР на две частиLukas Kovalik 2:15 PMздрасти, да ще го погледна по-кьсноспешно ли еVasil Vasilev 2:15 PMмерсине е спешноMessage Vasil VasilevVasil Vasilev is typing...
|
NULL
|
-8380495251076539581
|
NULL
|
click
|
ocr
|
NULL
|
SlackFileEditViewGoHistoryWindowHelpec2-userGDOCKE SlackFileEditViewGoHistoryWindowHelpec2-userGDOCKER981DEV (docker)882APP (-zsh)[EMAIL]@73b64f5d54a3:/home/jiminny#[ec2-user@ip-10-30-93-249 ~]$ dockerexec -it $(dockny && bash"root@c78a087b1345:/home/Jiminny# php artisan automated-reports[2026-04-14 10:46:08] staging.INF0: [automated-reports] Started{"correlation_id":"5[2026-04-1410:46:08]staging.INFO: [automated-reports] Checking conditions {"isMondaid":"5c23e861-2ca9-4f92-9f67-773d6bc80ca0","trace_id" :"185df6f6-4327-4609-9cZe-2ab83a[2026-04-14 10:46:08]ab83a0f5432"}staging.INFO: [automated-reports] Processing daily reports{"c[2026-04-1410:46:08]9-9c2e-2ab83a0f5432"'}staging.INFO: [automated-reports]Found 3 daily reports to proc[2026-04-1410:46:087daily"staging.INFO: [automated-reports]Dispatching Generate Report j,"type":"ask_jiminny"} {"correlation_id":"5c23e861-2ca9-4f92-9f67-773d6bc80ca®"[2026-04-14 10:46:08]staging.INFO: [automated-reports]Dispatching Generate Report jdaily", "type": "ask_jiminny"} {"correlation_id":"5c23e861-2ca9-4f92-9f67-773d6bc80cab"[2026-04-14 10:46:08]staging. INFO: [automated-reports]daily'", "type" "ask-fiminny"'} ("correlation-id' : 5c2se861-2ca -4792-9f87-773 e8oca[2026-04-14 10:46:08]staging.INFO: [automated-reports]Completed{"correlation_id":root@c78a087b1345:/home/jiminny# phpartisanautomated-reports --report-id 35[2026-04-14 10:48:42] staging.INFO: [automated-reports]Started{"correlation_id":"2[2026-04-14 10:48:42]staging.INFO: [automated-reports]Checking conditions {"isMondaid":"246alala-7076-458c-bd7d-49d2f5a2db88","trace_id":"1f894bf6-e50d-4e99-b635-2aa526[2026-04-14 10:48:42]staging.INFO: [automated-reports]Processing daily reports{"caa52627fc27"}[automated-reports] Automated report[2026-04-14 10:48:42]staging.INFO: [automated-reports] Found 1 daily reports to proc9-b635-2aa52627f c27"}[2026-04-14 10:48:42]staging.INF0: [automated-reports]Dispatching Generate Reportdaily","type": "ask_jiminny"} {"correlation_id":"246a1a1a-7076-458c-bd7d-49d2f5a2db88"[2026-04-14 10:48:42]staging.INFO: [automated-reports]Completed{"correlation_id":root@c78a087b1345:/home/jiminny# [ec2-user@ip-10-30-93-249 ~]$I+HomeDMsActivityFilesLater.*•MorelhlJiminny ...+tcncrel# infra-changes# jiminny-bg# platform-tickets# product_launches# random# releases# sofia-office# support# thank-yous# the_people_of jimi...Direct messagesE. Vasil VasilevAneliya Angelova, ...Steliyan GeorgievAdelina Petrova, Ili...0. Adelina Petrova. Galya Dimitrova *&s Nikolay Nikolov "2Galya Dimitrova, Ni...2Galya Dimitrova, Ni...P. Nikolay Yankov::: AppsJira CloudToastGoogle Cale...§ Support Daily • in 45 m100% <Tue 14 Apr 14:15:57→Search Jiminny IncVasil VasilevMessagesAdd canvasC Files< Pinsmaps#/grnao.com/mminnv/aDp/pui/11720Thursday, April 9th~трябва Ми -м...правя fine tuning на настойките засинхронизация на мейли+Lukas Kovalik 12:11 PMГОТОВОVasil Vasilev 12:11 PMблагодаряToday ~NewVasil Vasilev 2:01 PMЛукаш г992:01може ли да разглдаш този ПР като имашмалко време:https://github.com/jiminny/app/pull/11949повечето промени са семантични, не сафункционалниразделям по голям ПР на две частиLukas Kovalik 2:15 PMздрасти, да ще го погледна по-кьсноспешно ли еVasil Vasilev 2:15 PMмерсине е спешноMessage Vasil VasilevVasil Vasilev is typing...
|
NULL
|
|
12363
|
266
|
5
|
2026-04-14T11:15:59.012866+00:00
|
/Users/lukas/.screenpipe/data/data/2026-04-14/1776 /Users/lukas/.screenpipe/data/data/2026-04-14/1776165359012_m1.jpg...
|
NULL
|
NULL
|
1
|
NULL
|
monitor_1
|
NULL
|
NULL
|
NULL
|
NULL
|
SlackFileEditViewGoHistoryWindowHelpec2-userGDOCKE SlackFileEditViewGoHistoryWindowHelpec2-userGDOCKER₴81DEV (docker)882APP (-zsh)[EMAIL]@73b64f5d54a3:/home/jiminny#[ec2-user@ip-10-30-93-249 ~]$ dockerexec -it $(dockny && bash"root@c78a087b1345:/home/Jiminny# php artisan automated-reports[2026-04-14 10:46:08] staging.INF0: [automated-reports] Started{"correlation_id":"5[2026-04-1410:46:08]staging.INFO: [automated-reports] Checking conditions {"isMondaid":"5c23e861-2ca9-4f92-9f67-773d6bc80ca0","trace_id" :"185df6f6-4327-4609-9cZe-2ab83a[2026-04-14 10:46:08]ab83a0f5432"}staging. INFO: [automated-reports] Processing daily reports{"c[2026-04-1410:46:08]9-9c2e-2ab83a0f5432"}staging.INFO: [automated-reports]Found 3 daily reports to proc[2026-04-1410:46:087daily"staging.INFO: [automated-reports]Dispatching Generate Report j,"type":"ask_jiminny"} {"correlation_id":"5c23e861-2ca9-4f92-9f67-773d6bc80ca®"[2026-04-14 10:46:08]staging.INFO: [automated-reports]Dispatching Generate Report jdaily", "type": "ask_jiminny"} {"correlation_id":"5c23e861-2ca9-4f92-9f67-773d6bc80cab"[2026-04-14 10:46:08]staging. INFO: [automated-reports]daily'", "type" "ask-fiminny"'} ("correlation-id' : 5c2se861-2ca -4792-9f87-773 e8oca[2026-04-14 10:46:08]staging.INFO: [automated-reports]Completed{"correlation_id":root@c78a087b1345:/home/jiminny# phpartisanautomated-reports --report-id 35[2026-04-14 10:48:42] staging.INFO: [automated-reports]Started{"correlation_id":"2[2026-04-14 10:48:42]staging.INFO: [automated-reports]Checking conditions {"isMondaid":"246a1ala-7076-458c-bd7d-49d2f5a2db88","trace_id":"1f894bf6-e50d-4e99-b635-2aa526[2026-04-14 10:48:42]staging.INFO: [automated-reports]Processing daily reports{"caa52627fc27"}[automated-reports] Automated report[2026-04-14 10:48:42]staging.INFO: [automated-reports] Found 1 daily reports to proc9-b635-2aa52627f c27"}[2026-04-14 10:48:42]staging.INF0: [automated-reports]Dispatching Generate Reportdaily","type": "ask_jiminny"} {"correlation_id":"246a1a1a-7076-458c-bd7d-49d2f5a2db88"[2026-04-14 10:48:42]staging.INFO: [automated-reports]Completed{"correlation_id":root@c78a087b1345:/home/jiminny# [ec2-user@ip-10-30-93-249 ~]$I+HomeDMsActivityFilesLater.*•More+lhl§ Support Daily • in 45 m100% <7Tue 14 Apr 14:15:58→Search Jiminny IncJiminny ...+tscnicre# infra-changes# jiminny-bg# platform-tickets# product_launches# random# releases# sofia-office# support# thank-yous# the_people_of jimi...Direct messagesE. Vasil Vasilev3Aneliya Angelova, ...Steliyan GeorgievAdelina Petrova, Ili...0. Adelina Petrova* Pin to this conversationAdd to list...2Galya Dimitrova, Ni...8. Nikolay Yankov::: AppsJira CloudToastGoogle Cale...Vasil Vasilev2 MessagesAdd canvasC Files< Pinsnups/ grnao.comzmmnnv/a00/Pui/11740Thursday, April 9th~трябва Ми -м...правя fine tuning на настойките засинхронизация на мейли+Lukas Kovalik 12:11 PMГОТОВОVasil Vasilev 12:11 PMблагодаряTodayNewMark unreadU2:01Remind me$ Turn off notifications for repliesc Copy linkT Copy messageL*CVOrganizeConnect to appsReport to Slackмерсине е спешноMessage Vasil VasilevVasil Vasilev is typing...
|
NULL
|
6807871665293687526
|
NULL
|
visual_change
|
ocr
|
NULL
|
SlackFileEditViewGoHistoryWindowHelpec2-userGDOCKE SlackFileEditViewGoHistoryWindowHelpec2-userGDOCKER₴81DEV (docker)882APP (-zsh)[EMAIL]@73b64f5d54a3:/home/jiminny#[ec2-user@ip-10-30-93-249 ~]$ dockerexec -it $(dockny && bash"root@c78a087b1345:/home/Jiminny# php artisan automated-reports[2026-04-14 10:46:08] staging.INF0: [automated-reports] Started{"correlation_id":"5[2026-04-1410:46:08]staging.INFO: [automated-reports] Checking conditions {"isMondaid":"5c23e861-2ca9-4f92-9f67-773d6bc80ca0","trace_id" :"185df6f6-4327-4609-9cZe-2ab83a[2026-04-14 10:46:08]ab83a0f5432"}staging. INFO: [automated-reports] Processing daily reports{"c[2026-04-1410:46:08]9-9c2e-2ab83a0f5432"}staging.INFO: [automated-reports]Found 3 daily reports to proc[2026-04-1410:46:087daily"staging.INFO: [automated-reports]Dispatching Generate Report j,"type":"ask_jiminny"} {"correlation_id":"5c23e861-2ca9-4f92-9f67-773d6bc80ca®"[2026-04-14 10:46:08]staging.INFO: [automated-reports]Dispatching Generate Report jdaily", "type": "ask_jiminny"} {"correlation_id":"5c23e861-2ca9-4f92-9f67-773d6bc80cab"[2026-04-14 10:46:08]staging. INFO: [automated-reports]daily'", "type" "ask-fiminny"'} ("correlation-id' : 5c2se861-2ca -4792-9f87-773 e8oca[2026-04-14 10:46:08]staging.INFO: [automated-reports]Completed{"correlation_id":root@c78a087b1345:/home/jiminny# phpartisanautomated-reports --report-id 35[2026-04-14 10:48:42] staging.INFO: [automated-reports]Started{"correlation_id":"2[2026-04-14 10:48:42]staging.INFO: [automated-reports]Checking conditions {"isMondaid":"246a1ala-7076-458c-bd7d-49d2f5a2db88","trace_id":"1f894bf6-e50d-4e99-b635-2aa526[2026-04-14 10:48:42]staging.INFO: [automated-reports]Processing daily reports{"caa52627fc27"}[automated-reports] Automated report[2026-04-14 10:48:42]staging.INFO: [automated-reports] Found 1 daily reports to proc9-b635-2aa52627f c27"}[2026-04-14 10:48:42]staging.INF0: [automated-reports]Dispatching Generate Reportdaily","type": "ask_jiminny"} {"correlation_id":"246a1a1a-7076-458c-bd7d-49d2f5a2db88"[2026-04-14 10:48:42]staging.INFO: [automated-reports]Completed{"correlation_id":root@c78a087b1345:/home/jiminny# [ec2-user@ip-10-30-93-249 ~]$I+HomeDMsActivityFilesLater.*•More+lhl§ Support Daily • in 45 m100% <7Tue 14 Apr 14:15:58→Search Jiminny IncJiminny ...+tscnicre# infra-changes# jiminny-bg# platform-tickets# product_launches# random# releases# sofia-office# support# thank-yous# the_people_of jimi...Direct messagesE. Vasil Vasilev3Aneliya Angelova, ...Steliyan GeorgievAdelina Petrova, Ili...0. Adelina Petrova* Pin to this conversationAdd to list...2Galya Dimitrova, Ni...8. Nikolay Yankov::: AppsJira CloudToastGoogle Cale...Vasil Vasilev2 MessagesAdd canvasC Files< Pinsnups/ grnao.comzmmnnv/a00/Pui/11740Thursday, April 9th~трябва Ми -м...правя fine tuning на настойките засинхронизация на мейли+Lukas Kovalik 12:11 PMГОТОВОVasil Vasilev 12:11 PMблагодаряTodayNewMark unreadU2:01Remind me$ Turn off notifications for repliesc Copy linkT Copy messageL*CVOrganizeConnect to appsReport to Slackмерсине е спешноMessage Vasil VasilevVasil Vasilev is typing...
|
12361
|
|
12364
|
266
|
6
|
2026-04-14T11:16:03.226459+00:00
|
/Users/lukas/.screenpipe/data/data/2026-04-14/1776 /Users/lukas/.screenpipe/data/data/2026-04-14/1776165363226_m1.jpg...
|
NULL
|
NULL
|
1
|
NULL
|
monitor_1
|
NULL
|
NULL
|
NULL
|
NULL
|
SlackFileEditViewGoHistoryWindowHelpec2-userGDOCKE SlackFileEditViewGoHistoryWindowHelpec2-userGDOCKER₴81DEV (docker)882APP (-zsh)[EMAIL]@73b64f5d54a3:/home/jiminny#[ec2-user@ip-10-30-93-249 ~]$ dockerexec -it $(dockny && bash"root@c78a087b1345:/home/Jiminny# php artisan automated-reports[2026-04-14 10:46:08] staging.INF0: [automated-reports] Started{"correlation_id":"5[2026-04-1410:46:08]staging.INFO: [automated-reports] Checking conditions {"isMondaid":"5c23e861-2ca9-4f92-9f67-773d6bc80ca0","trace_id" :"185df6f6-4327-4609-9cZe-2ab83a[2026-04-14 10:46:08]ab83a0f5432"}staging. INFO: [automated-reports] Processing daily reports{"c[2026-04-1410:46:08]9-9c2e-2ab83a0f5432"}staging.INFO: [automated-reports]Found 3 daily reports to proc[2026-04-1410:46:087daily"staging.INFO: [automated-reports]Dispatching Generate Report j,"type":"ask_jiminny"} {"correlation_id":"5c23e861-2ca9-4f92-9f67-773d6bc80ca®"[2026-04-14 10:46:08]staging.INFO: [automated-reports]Dispatching Generate Report jdaily", "type": "ask_jiminny"} {"correlation_id":"5c23e861-2ca9-4f92-9f67-773d6bc80cab"[2026-04-14 10:46:08]staging. INFO: [automated-reports]daily'", "type" "ask-fiminny"'} ("correlation-id' : 5c2se861-2ca -4792-9f87-773 e8oca[2026-04-14 10:46:08]staging.INFO: [automated-reports]Completed{"correlation_id":root@c78a087b1345:/home/jiminny# phpartisanautomated-reports --report-id 35[2026-04-14 10:48:42] staging.INFO: [automated-reports]{"correlation_id":"2[2026-04-14 10:48:42]staging.INFO: [automated-reports]Checking conditions {"isMondaid":"246a1ala-7076-458c-bd7d-49d2f5a2db88","trace_id":"1f894bf6-e50d-4e99-b635-2aa526[2026-04-14 10:48:42]staging.INFO: [automated-reports]Processing daily reports{"caa52627fc27"}[automated-reports] Automated report[2026-04-14 10:48:42]staging.INFO: [automated-reports] Found 1 daily reports to proc9-b635-2aa52627f c27"}[2026-04-14 10:48:42]staging.INF0: [automated-reports]Dispatching Generate Reportdaily","type": "ask_jiminny"} {"correlation_id":"246a1a1a-7076-458c-bd7d-49d2f5a2db88"[2026-04-14 10:48:42]staging.INFO: [automated-reports]Completed{"correlation_id":root@c78a087b1345:/home/jiminny# [ec2-user@ip-10-30-93-249 ~]$I+Home.*•Morelhl§ Support Daily • in 44 m100% <7Tue 14 Apr 14:16:02→Search Jiminny IncJiminny ...scnicre# infra-changes# jiminny-bg# platform-tickets# product_launches# random# releases# sofia-office# support# thank-yous# the_people_of jimi...Direct messages6. Va:In 20 minutesAnSte3Ad. AdIn 1 hourin 3 hoursTomorrowNext week®. GaCustom...8g Nit2Galya Dimitrova, Ni...2Galya Dimitrova, Ni...P. Nikolay YankovAppsJira CloudToastGoogle Cale...Vasil VasilevMessagesAdd canvasC Files< Pins+правя finсинхрони».1 new messageе заXLukas Kovalik 12:11 PMготовоVasil Vasilev 12:11 PMблагодаряTodayVasil Vasilev 2:01 PMЛукаш г2:01Mark unreadURemind me# Turn off notifications for repliesc Copy linkT Copy messageLMOrganizeConnect to appsReport to SlackNewпросто искам да го разкарам, за да сиотпуша следващия ПРMessage Vasil Vasilev+Aa...
|
NULL
|
6283982976248232054
|
NULL
|
click
|
ocr
|
NULL
|
SlackFileEditViewGoHistoryWindowHelpec2-userGDOCKE SlackFileEditViewGoHistoryWindowHelpec2-userGDOCKER₴81DEV (docker)882APP (-zsh)[EMAIL]@73b64f5d54a3:/home/jiminny#[ec2-user@ip-10-30-93-249 ~]$ dockerexec -it $(dockny && bash"root@c78a087b1345:/home/Jiminny# php artisan automated-reports[2026-04-14 10:46:08] staging.INF0: [automated-reports] Started{"correlation_id":"5[2026-04-1410:46:08]staging.INFO: [automated-reports] Checking conditions {"isMondaid":"5c23e861-2ca9-4f92-9f67-773d6bc80ca0","trace_id" :"185df6f6-4327-4609-9cZe-2ab83a[2026-04-14 10:46:08]ab83a0f5432"}staging. INFO: [automated-reports] Processing daily reports{"c[2026-04-1410:46:08]9-9c2e-2ab83a0f5432"}staging.INFO: [automated-reports]Found 3 daily reports to proc[2026-04-1410:46:087daily"staging.INFO: [automated-reports]Dispatching Generate Report j,"type":"ask_jiminny"} {"correlation_id":"5c23e861-2ca9-4f92-9f67-773d6bc80ca®"[2026-04-14 10:46:08]staging.INFO: [automated-reports]Dispatching Generate Report jdaily", "type": "ask_jiminny"} {"correlation_id":"5c23e861-2ca9-4f92-9f67-773d6bc80cab"[2026-04-14 10:46:08]staging. INFO: [automated-reports]daily'", "type" "ask-fiminny"'} ("correlation-id' : 5c2se861-2ca -4792-9f87-773 e8oca[2026-04-14 10:46:08]staging.INFO: [automated-reports]Completed{"correlation_id":root@c78a087b1345:/home/jiminny# phpartisanautomated-reports --report-id 35[2026-04-14 10:48:42] staging.INFO: [automated-reports]{"correlation_id":"2[2026-04-14 10:48:42]staging.INFO: [automated-reports]Checking conditions {"isMondaid":"246a1ala-7076-458c-bd7d-49d2f5a2db88","trace_id":"1f894bf6-e50d-4e99-b635-2aa526[2026-04-14 10:48:42]staging.INFO: [automated-reports]Processing daily reports{"caa52627fc27"}[automated-reports] Automated report[2026-04-14 10:48:42]staging.INFO: [automated-reports] Found 1 daily reports to proc9-b635-2aa52627f c27"}[2026-04-14 10:48:42]staging.INF0: [automated-reports]Dispatching Generate Reportdaily","type": "ask_jiminny"} {"correlation_id":"246a1a1a-7076-458c-bd7d-49d2f5a2db88"[2026-04-14 10:48:42]staging.INFO: [automated-reports]Completed{"correlation_id":root@c78a087b1345:/home/jiminny# [ec2-user@ip-10-30-93-249 ~]$I+Home.*•Morelhl§ Support Daily • in 44 m100% <7Tue 14 Apr 14:16:02→Search Jiminny IncJiminny ...scnicre# infra-changes# jiminny-bg# platform-tickets# product_launches# random# releases# sofia-office# support# thank-yous# the_people_of jimi...Direct messages6. Va:In 20 minutesAnSte3Ad. AdIn 1 hourin 3 hoursTomorrowNext week®. GaCustom...8g Nit2Galya Dimitrova, Ni...2Galya Dimitrova, Ni...P. Nikolay YankovAppsJira CloudToastGoogle Cale...Vasil VasilevMessagesAdd canvasC Files< Pins+правя finсинхрони».1 new messageе заXLukas Kovalik 12:11 PMготовоVasil Vasilev 12:11 PMблагодаряTodayVasil Vasilev 2:01 PMЛукаш г2:01Mark unreadURemind me# Turn off notifications for repliesc Copy linkT Copy messageLMOrganizeConnect to appsReport to SlackNewпросто искам да го разкарам, за да сиотпуша следващия ПРMessage Vasil Vasilev+Aa...
|
NULL
|
|
12366
|
266
|
7
|
2026-04-14T11:16:05.067996+00:00
|
/Users/lukas/.screenpipe/data/data/2026-04-14/1776 /Users/lukas/.screenpipe/data/data/2026-04-14/1776165365067_m1.jpg...
|
NULL
|
NULL
|
1
|
NULL
|
monitor_1
|
NULL
|
NULL
|
NULL
|
NULL
|
SlackFileEditViewGoHistoryWindowHelpec2-userGDOCKE SlackFileEditViewGoHistoryWindowHelpec2-userGDOCKER- ₴81DEV (docker)882APP (-zsh)[EMAIL]@73b64f5d54a3:/home/jiminny#[ec2-user@ip-10-30-93-249 ~]$ dockerexec -it $(dockny && bash"root@c78a087b1345:/home/Jiminny# php artisan automated-reports[2026-04-14 10:46:08]staging.INFO: [automated-reports] Started{"correlation_id":"5[2026-04-1410:46:08]staging.INFO: [automated-reports] Checking conditions {"isMondaid":"5c23e861-2ca9-4f92-9f67-773d6bc80ca0","trace_id" :"185df6f6-4327-4609-9cZe-2ab83a[2026-04-14 10:46:08]ab83a0f5432"}staging. INFO: [automated-reports] Processing daily reports{"c[2026-04-1410:46:08]9-9c2e-2ab83a0f5432"'}staging.INFO: [automated-reports]Found 3 daily reports to proc[2026-04-1410:46:087daily"staging.INFO: [automated-reports]Dispatching Generate Report j,"type":"ask_jiminny"} {"correlation_id":"5c23e861-2ca9-4f92-9f67-773d6bc80ca0"[2026-04-14 10:46:08]staging.INFO: [automated-reports]Dispatching Generate Report jdaily", "type": "ask_jiminny"} {"correlation_id":"5c23e861-2ca9-4f92-9f67-773d6bc80cab"[2026-04-14 10:46:08]staging. INFO: [automated-reports]daily'", "type" "ask-fiminny"'} ("correlation-id' : 5c2se861-2ca -4792-9f87-773 e8oca[2026-04-14 10:46:08]staging.INFO: [automated-reports]Completed{"correlation_id":root@c78a087b1345:/home/jiminny# phpartisanautomated-reports --report-id 35[2026-04-14 10:48:42] staging.INFO: [automated-reports]{"correlation_id":"2[2026-04-14 10:48:42]staging.INFO: [automated-reports]Checking conditions {"isMondaid":"246a1ala-7076-458c-bd7d-49d2f5a2db88","trace_id":"1f894bf6-e50d-4e99-b635-2aa526[2026-04-14 10:48:42]staging.INFO: [automated-reports]Processing daily reports{"caa52627fc27"}[automated-reports] Automated report[2026-04-14 10:48:42]staging.INFO: [automated-reports] Found 1 daily reports to proc9-b635-2aa52627f c27"}[2026-04-14 10:48:42]staging.INF0: [automated-reports]Dispatching Generate Reportdaily","type": "ask_jiminny"} {"correlation_id":"246a1a1a-7076-458c-bd7d-49d2f5a2db88"[2026-04-14 10:48:42]staging.INFO: [automated-reports]Completed{"correlation_id":root@c78a087b1345:/home/jiminny# [ec2-user@ip-10-30-93-249 ~]$D+HomeDMsActivityFilesLater.*•Morelhl§ Support Daily • in 44 m100% CTue 14 Apr 14:16:04→Search Jiminny IncJiminny ...scnicre# infra-changes# jiminny-bg# platform-tickets# product_launches# random# releases# sofia-office# support# thank-yous# the_people_of jimi...Direct messagesE. Vasil VasilevAneliya Angelova, ...Steliyan GeorgievAdelina Petrova, Ili...0. Adelina Petrova. Galya Dimitrova&s Nikolay Nikolov "2Galya Dimitrova, Ni...2Galya Dimitrova, Ni...P. Nikolay Yankov::: AppsJira CloudToastGoogle Cale...Vasil Vasilev2 MessagesTAdd canvasC Files< Pins+синхрониThursday, April 9th~Lukas Kovalik 12:11 PMГоТОвоVasil Vasilev 12:11 PMблагодаряToday ~Vasil Vasilev 2:01 PMЛукаш гSaved for later • vue in 3 nours2:01 може ли да разглдаш този ПР като имашмалко време:https://github.com/jiminny/app/pull/11949повечето промени са семантични, не сафункционалниразделям по голям ПР на две частиLukas Kovalik 2:15 PMздрасти, да ще го погледна по-кьсноспешно ли е:Vasil Vasilev 2:15 PMмерсине е спешноNewпросто искам да го разкарам, за да сиотпуша следващия ПРMessage Vasil Vasilev+Aa...
|
NULL
|
-3897628359868784785
|
NULL
|
visual_change
|
ocr
|
NULL
|
SlackFileEditViewGoHistoryWindowHelpec2-userGDOCKE SlackFileEditViewGoHistoryWindowHelpec2-userGDOCKER- ₴81DEV (docker)882APP (-zsh)[EMAIL]@73b64f5d54a3:/home/jiminny#[ec2-user@ip-10-30-93-249 ~]$ dockerexec -it $(dockny && bash"root@c78a087b1345:/home/Jiminny# php artisan automated-reports[2026-04-14 10:46:08]staging.INFO: [automated-reports] Started{"correlation_id":"5[2026-04-1410:46:08]staging.INFO: [automated-reports] Checking conditions {"isMondaid":"5c23e861-2ca9-4f92-9f67-773d6bc80ca0","trace_id" :"185df6f6-4327-4609-9cZe-2ab83a[2026-04-14 10:46:08]ab83a0f5432"}staging. INFO: [automated-reports] Processing daily reports{"c[2026-04-1410:46:08]9-9c2e-2ab83a0f5432"'}staging.INFO: [automated-reports]Found 3 daily reports to proc[2026-04-1410:46:087daily"staging.INFO: [automated-reports]Dispatching Generate Report j,"type":"ask_jiminny"} {"correlation_id":"5c23e861-2ca9-4f92-9f67-773d6bc80ca0"[2026-04-14 10:46:08]staging.INFO: [automated-reports]Dispatching Generate Report jdaily", "type": "ask_jiminny"} {"correlation_id":"5c23e861-2ca9-4f92-9f67-773d6bc80cab"[2026-04-14 10:46:08]staging. INFO: [automated-reports]daily'", "type" "ask-fiminny"'} ("correlation-id' : 5c2se861-2ca -4792-9f87-773 e8oca[2026-04-14 10:46:08]staging.INFO: [automated-reports]Completed{"correlation_id":root@c78a087b1345:/home/jiminny# phpartisanautomated-reports --report-id 35[2026-04-14 10:48:42] staging.INFO: [automated-reports]{"correlation_id":"2[2026-04-14 10:48:42]staging.INFO: [automated-reports]Checking conditions {"isMondaid":"246a1ala-7076-458c-bd7d-49d2f5a2db88","trace_id":"1f894bf6-e50d-4e99-b635-2aa526[2026-04-14 10:48:42]staging.INFO: [automated-reports]Processing daily reports{"caa52627fc27"}[automated-reports] Automated report[2026-04-14 10:48:42]staging.INFO: [automated-reports] Found 1 daily reports to proc9-b635-2aa52627f c27"}[2026-04-14 10:48:42]staging.INF0: [automated-reports]Dispatching Generate Reportdaily","type": "ask_jiminny"} {"correlation_id":"246a1a1a-7076-458c-bd7d-49d2f5a2db88"[2026-04-14 10:48:42]staging.INFO: [automated-reports]Completed{"correlation_id":root@c78a087b1345:/home/jiminny# [ec2-user@ip-10-30-93-249 ~]$D+HomeDMsActivityFilesLater.*•Morelhl§ Support Daily • in 44 m100% CTue 14 Apr 14:16:04→Search Jiminny IncJiminny ...scnicre# infra-changes# jiminny-bg# platform-tickets# product_launches# random# releases# sofia-office# support# thank-yous# the_people_of jimi...Direct messagesE. Vasil VasilevAneliya Angelova, ...Steliyan GeorgievAdelina Petrova, Ili...0. Adelina Petrova. Galya Dimitrova&s Nikolay Nikolov "2Galya Dimitrova, Ni...2Galya Dimitrova, Ni...P. Nikolay Yankov::: AppsJira CloudToastGoogle Cale...Vasil Vasilev2 MessagesTAdd canvasC Files< Pins+синхрониThursday, April 9th~Lukas Kovalik 12:11 PMГоТОвоVasil Vasilev 12:11 PMблагодаряToday ~Vasil Vasilev 2:01 PMЛукаш гSaved for later • vue in 3 nours2:01 може ли да разглдаш този ПР като имашмалко време:https://github.com/jiminny/app/pull/11949повечето промени са семантични, не сафункционалниразделям по голям ПР на две частиLukas Kovalik 2:15 PMздрасти, да ще го погледна по-кьсноспешно ли е:Vasil Vasilev 2:15 PMмерсине е спешноNewпросто искам да го разкарам, за да сиотпуша следващия ПРMessage Vasil Vasilev+Aa...
|
12364
|
|
12368
|
266
|
8
|
2026-04-14T11:16:14.125370+00:00
|
/Users/lukas/.screenpipe/data/data/2026-04-14/1776 /Users/lukas/.screenpipe/data/data/2026-04-14/1776165374125_m1.jpg...
|
PhpStorm
|
faVsco.js – AutomatedReportsService.php
|
1
|
NULL
|
monitor_1
|
NULL
|
NULL
|
NULL
|
NULL
|
Project: faVsco.js, menu
#11894 on JY-18909-automa Project: faVsco.js, menu
#11894 on JY-18909-automated-reports-ask-jiminny, menu
Start Listening for PHP Debug Connections
AutomatedReportsCommandTest
Run 'AutomatedReportsCommandTest'
Debug 'AutomatedReportsCommandTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Execute
Explain Plan
Browse Query History
View Parameters
Open Query Execution Settings…
In-Editor Results
Tx: Auto
Cancel Running Statements
Playground
jiminny
Sync Changes
Hide This Notification
Code changed:
Hide
16
13
13
Previous Highlighted Error
Next Highlighted Error
SELECT * FROM teams WHERE id = 1;
select * from crm_layouts where crm_configuration_id = 39;
SELECT * FROM crm_layout_entities WHERE crm_layout_id = 283;
SELECT * FROM crm_fields WHERE id = 2234;
SELECT * FROM crm_field_values WHERE crm_field_id = 2234;
select * from crm_profiles where user_id = 143;
select * from record_types where crm_configuration_id = 39; # 0121K000001MHElQAO,0121K000001MHEqQAO
select * from business_processes where crm_configuration_id = 39;
# 01941000000H669AAC, 01941000000H66JAAS
select * from record_type_field_values
where record_type_id IN (24);
select * from crm_field_values where id IN (2730);
select * from crm_configurations where id = 39;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 1
and sa.provider = 'salesforce'; #1035
select * from users where team_id = 1; # 222 group 3
SELECT * FROM activities WHERE user_id = 222 order by id desc;
select * from sidekick_settings where team_id = 1;
select * from teams where id = 1;
select * from team_features where team_id = 1;
select * from activities where crm_configuration_id = 2
and provider = 'ms-teams' and id = 608765;
SELECT * FROM activities WHERE crm_configuration_id = 2 and crm_provider_id = '59523413338';
select * from sidekick_settings where team_id = 2;
SELECT * FROM activities WHERE id = 608660;
select * from activity_summary_logs where activity_id = 608660;
select * from ai_prompts where transcription_id = 11214;
# [PASSWORD_DOTS]
SELECT * FROM activities WHERE uuid_to_bin('ed78a437-2804-450e-ab2f-56ab1c641346') = uuid;
# id: 608818, crm: 59628809737
SELECT * FROM activities WHERE uuid_to_bin('36b06e55-afdd-4782-8dee-c624cd0af191') = uuid;
# id: 608821, crm: 59632069252
SELECT ce.start_time, ce.end_time, a.id, a.uuid, crm_provider_id, calendar_event_id, title,
playbook_category_id, user_id, lead_id, contact_id, account_id, opportunity_id,
scheduled_start_time, scheduled_end_time, actual_start_time, actual_end_time, a.created_at
FROM activities a
join calendar_events ce on a.calendar_event_id = ce.id
WHERE a.id IN (608818, 608821);
select * from users where team_id = 1;
select * from team_settings where team_id = 1;
select * from crm_profiles where crm_configuration_id = 39 order by user_id;
select * from team_features where team_id = 1;
select * from users where team_id = 2;
SELECT * FROM activities WHERE uuid_to_bin('ec7647e9-5225-458b-b475-f31aa2769204') = uuid; # 612639
# Preslava N. Ivanova, grou id 3
SELECT * FROM opportunities WHERE uuid_to_bin('a2928fe5-aec5-46cb-85d9-7654c89e46a6') = uuid;
select * from activities where opportunity_id = 344 and actual_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00';
select
a.id,
a.type,
a.scheduled_start_time,
a.actual_start_time,
a.created_at,
a.opportunity_id,
a.status
FROM activities a
WHERE opportunity_id = 344
and status IN ('completed', 'received', 'delivered')
and (
(a.actual_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00')
OR (a.created_at between '2024-10-11 00:00:00' and '2024-10-12 00:00:00')
OR (a.scheduled_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00'))
;
SELECT * FROM users WHERE id = 222;
SELECT * FROM crm_profiles WHERE user_id = 222;
select * from crm_layouts where crm_configuration_id = 39;
SELECT * FROM crm_layout_entities WHERE crm_layout_id = 281;
select * from group_deal_risk_types;
select * from opportunities where team_id = 1;
SELECT * FROM opportunities WHERE id = 315;
SELECT * FROM crm_field_data WHERE object_id = 315;
select * from crm_field_data where object_id = 260;
select * from generic_ai_prompts where subject_id = 315;
select * from teams; # 36, 21, 121, [EMAIL]
SELECT * FROM social_accounts WHERE sociable_id = 121 and provider = 'bullhorn';
# [PASSWORD_DOTS]
select * from teams where id = 1;
select * from crm_configurations where id = 39;
select * from users where team_id = 1;
select u.email, cp.* from users u
join crm_profiles cp on u.id = cp.user_id
where u.team_id = 1;
# 1 - 00541000004281rAAA
# 204 - 0052g000003freeAAA
# 429 - 0052g000003qGOiAAM
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 1
and sa.provider = 'salesforce';
select * from activities where type = 'softphone'
and created_at > '2024-12-11 15:24:36' order by id desc;
select * from activity_providers where team_id = 1;
select * from activity_provider_users where activity_provider_id = 328;
select * from opportunities where crm_configuration_id = 39
AND account_id = 178 AND is_closed = false
order by created_at DESC;
select * from contacts where id = 3952;
select * from accounts where id = 178;
# [PASSWORD_DOTS]
select * from teams where id = 36;
select * from crm_configurations where id = 21;
select * from users where team_id = 36;
select u.email, cp.* from users u
join crm_profiles cp on u.id = cp.user_id
where u.team_id = 36;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 36
and sa.provider = 'bullhorn';
select * from social_accounts where id = 348;
UPDATE social_accounts SET
provider_user_token = '21442_6802599_91:41179a58-21e7-4d7c-ad58-56bb666b2f65',
provider_refresh_token = '21442_6802599_91:01c6b335-3f2a-42e4-85ff-8a08fa65fceb',
expires = 1733998131,
state = 'connected'
WHERE id = 348;
# [PASSWORD_DOTS]
select * from teams where id = 31;
select * from crm_configurations where id = 18;
select * from users where team_id = 31; # 257
select u.email, cp.* from users u
join crm_profiles cp on u.id = cp.user_id
where u.team_id = 31;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 31
and sa.provider = 'close';
select * from contacts where crm_configuration_id = 18;
# [PASSWORD_DOTS] NEPTUNE [PASSWORD_DOTS]
select * from teams;
select * from users where id IN (1030, 1035, 1052);
select * from crm_configurations;
select * from users where team_id = 65; # 257
select * from team_settings where team_id = 65; # 257
select * from invitations where team_id = 65; # 257
select * from users where email = '[EMAIL]'; # 257
select u.email, cp.* from users u
join crm_profiles cp on u.id = cp.user_id
where u.team_id = 65;
select * from crm_configurations where id = 53;
select * from accounts where crm_configuration_id = 53 order by id desc;
select * from leads where crm_configuration_id = 53 order by id desc;
select * from contacts where crm_configuration_id = 53 order by id desc;
select * from opportunities where crm_configuration_id = 53 order by id desc;
select * from crm_profiles where crm_configuration_id = 53 order by id desc;
select * from crm_fields where crm_configuration_id = 53 order by id desc;
select * from crm_field_values where crm_field_id = 3341 order by id desc;
select * from crm_layouts where crm_configuration_id = 53 order by id desc;
select * from stages where crm_configuration_id = 53 order by id desc;
select * from crm_profiles where crm_configuration_id = 13;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 65
and sa.provider = 'integration-app';
select * from contacts where crm_configuration_id = 13;
select * from social_accounts where sociable_id = 283;
SELECT * FROM opportunities WHERE crm_provider_id = '006O400000E9bzeIAB';
select * from activity_providers where team_id = 65;
SELECT * FROM activities WHERE crm_configuration_id IN (51, 52, 53);
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 65
;
# [PASSWORD_DOTS] STAGING [PASSWORD_DOTS]
SELECT * FROM teams;
SELECT * FROM teams WHERE id = 88;
SELECT * FROM teams WHERE id = 89;
select * from team_settings where team_id = 89;
SELECT * FROM users WHERE team_id = 89;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 89;
select * from users;
SELECT * FROM social_accounts WHERE sociable_id = 1761;
SELECT * FROM crm_configurations WHERE id = 70;
select * from accounts where crm_configuration_id = 70 order by id desc;
select * from leads where crm_configuration_id = 70 order by id desc;
select * from contacts where crm_configuration_id = 70 order by id desc;
select * from opportunities where crm_configuration_id = 70 order by id desc;
select * from crm_profiles where crm_configuration_id = 70 order by id desc;
select * from crm_fields where crm_configuration_id = 70 order by id desc;
select * from crm_field_values where crm_field_id = 3536 order by id desc;
select * from crm_layouts where crm_configuration_id = 70 order by id desc;
select * from stages where crm_configuration_id = 70 order by id desc;
select * from business_processes where crm_configuration_id = 70 order by id desc;
select * from business_process_stages where business_process_id = 34;
select * from contacts where id = 10468;
select * from crm_layouts where crm_configuration_id = 70;
SELECT * FROM crm_layout_entities WHERE crm_layout_id = 388;
SELECT * FROM crm_fields WHERE id IN (3533,3534,3535);
select * from activities where crm_configuration_id = 70
and (account_id IS NOT NULL or lead_id IS NOT NULL or contact_id IS NOT NULL or opportunity_id IS NOT NULL) order by id desc;
SELECT * FROM activities WHERE uuid_to_bin('2e10b60f-8a61-41c5-a3d4-28835353dc65') = uuid;
SELECT * FROM activities where crm_configuration_id = 69 ;
SELECT * FROM users WHERE email LIKE '%[EMAIL]%';
SELECT * FROM activities WHERE uuid_to_bin('5a150c93-40fc-42ec-b3bd-c1d328e09f6e') = uuid;
SELECT * FROM opportunities WHERE id = 385;
select * from participants p
join activities a on p.activity_id = a.id
where a.crm_configuration_id = 70
and (p.lead_id IS NOT NULL or p.contact_id IS NOT NULL);
SELECT * FROM participants WHERE id = 1013638;
select * from teams where id = 90;
select * from users where team_id = 90;
select * from social_accounts where social_accounts.sociable_id IN (1960,1760);
SELECT * FROM crm_profiles WHERE crm_configuration_id = 71;
select * from invitations where team_id = 90;
select * from crm_configurations where id = 71;
select * from accounts where crm_configuration_id = 71 order by id desc;
select * from leads where crm_configuration_id = 71 order by id desc;
select * from contacts where crm_configuration_id = 71 order by id desc;
select * from opportunities where crm_configuration_id = 71 order by id desc;
select * from crm_profiles where crm_configuration_id = 71 order by id desc;
select * from crm_fields where crm_configuration_id = 71 order by id desc;
select * from crm_field_values where crm_field_id = 3341 order by id desc;
select * from crm_layouts where crm_configuration_id = 71 order by id desc;
select * from stages where crm_configuration_id = 71 order by id desc;
select * from users order by secondary_email desc;
select u.id, u.email, u.status, sa.id, sa.provider_user_id from social_accounts sa
join users u on sa.sociable_id = u.id
where sa.provider = 'google' and u.email LIKE 'aneliya%';
select * from failed_jobs order by id desc;
select * from users where email = '[EMAIL]' or secondary_email = '[EMAIL]';
select * from teams;
SELECT * FROM crm_profiles WHERE crm_configuration_id = 39;
SELECT * FROM crm_fields WHERE crm_configuration_id = 39 and object_type = 'task';
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 1
and sa.provider = 'salesforce';
# [PASSWORD_DOTS]
SELECT * FROM activities WHERE uuid_to_bin('c38b3895-fd0f-4b1f-9fb2-c170dba137c6') = uuid;
SELECT * FROM crm_configurations WHERE id = 70;
select * from teams where id = 1;
select * from groups where team_id = 1;
select * from users where team_id = 1;
select o.id, o.name,o.close_date, u.id, u.name, u.group_id, r.id, r.display_name, g.name, g.scope from opportunities o
join users u on o.user_id = u.id
join groups g on u.group_id = g.id
join role_user ru on u.id = ru.user_id
join roles r on ru.role_id = r.id
where o.crm_configuration_id = 39 and close_date > '2024-01-01 00:00:00';
select * from role_user where user_id = 143;
select * from roles;
select * from role_user;
select * from groups where id = 9;
select * from scope_groups where group_id = 9;
# [PASSWORD_DOTS]
select * from teams where id = 36;
select * from crm_configurations;
SELECT * FROM social_accounts WHERE sociable_id = 121;
[URL_WITH_CREDENTIALS] this will add filter, however if we need to control feature by FF we need conditional logic
public const array TYPES = [
['id' => 'exec_summary', 'name' => 'Exec Summary'],
['id' => 'coaching_profiles', 'name' => 'Coaching Profiles'],
['id' => 'product_feedback', 'name' => 'Product Feedback'],
['id' => self::TYPE_LOSS_ANALYSIS, 'name' => 'Loss Analysis'],
// ['id' => 'questions', 'name' => 'Questions'],
// ['id' => 'statistical_quant', 'name' => 'Statistical Quantitative'],
];
public const array ALL_TYPES = [
...self::TYPES,
['id' => self::TYPE_ASK_JIMINNY, 'name' => 'Ask Jiminny'],
];
public const string FREQUENCY_DAILY = 'daily';
public const string FREQUENCY_WEEKLY = 'weekly';
public const string FREQUENCY_MONTHLY = 'monthly';
public const string FREQUENCY_QUARTERLY = 'quarterly';
public const string FREQUENCY_ONE_OFF = 'one_off';
/**
* Frequencies for standard (non-Ask Jiminny) reports.
*/
public const array FREQUENCIES = [
['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],
['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],
['id' => self::FREQUENCY_QUARTERLY, 'name' => 'Quarterly'],
['id' => self::FREQUENCY_ONE_OFF, 'name' => 'One-off'],
];
/**
* Frequencies for Ask Jiminny reports.
*/
public const array ASK_JIMINNY_FREQUENCIES = [
['id' => self::FREQUENCY_DAILY, 'name' => 'Daily'],
['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],
['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],
];
public const string MEDIA_TYPE_PDF = 'pdf';
public const string MEDIA_TYPE_PODCAST = 'podcast';
public const array MEDIA_TYPES = [self::MEDIA_TYPE_PDF, self::MEDIA_TYPE_PODCAST];
public const array MEDIA_TYPE_OBJECT_PDF = ['id' => self::MEDIA_TYPE_PDF, 'name' => 'PDF'];
public const array MEDIA_TYPE_OBJECT_PODCAST = ['id' => self::MEDIA_TYPE_PODCAST, 'name' => 'Podcast'];
public const array MEDIA_TYPE_OBJECTS = [self::MEDIA_TYPE_OBJECT_PDF, self::MEDIA_TYPE_OBJECT_PODCAST];
public const array CALL_TYPE_CONFERENCE = ['id' => 'conference', 'name' => 'Conference'];
public const array CALL_TYPE_DIALER = ['id' => 'dialer', 'name' => 'Dialer'];
public const int SENT_REPORT_AT_HOURS = 5;
public const string PDF_KEY = 'pdf';
public const string AUDIO_KEY = 'audio';
private const array ALL_FREQUENCIES = [
['id' => self::FREQUENCY_DAILY, 'name' => 'Daily'],
['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],
['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],
['id' => self::FREQUENCY_QUARTERLY, 'name' => 'Quarterly'],
['id' => self::FREQUENCY_ONE_OFF, 'name' => 'One-off'],
];
private const string S3_DIR = 'reports';
private const array FILE_EXTENSIONS_VARIANTS = ['html', 'MD', 'pdf'];
private const array FILE_PODCAST_EXTENSIONS_VARIANTS = ['json', 'mp3', 'ssml'];
public function __construct(
private readonly TeamRepository $teamRepository,
private readonly GroupRepository $groupRepository,
private readonly UserRepository $userRepository,
private readonly StageRepository $stageRepository,
private readonly DealStagesService $dealStagesService,
private readonly RecipientsService $recipientsService,
private readonly AutomatedReportsRepository $automatedReportsRepository,
private readonly Webhook $webhookService,
private readonly BusDispatcher $dispatcher,
private readonly ActivityTypeService $activityTypeService,
private readonly PlaybookCategoryRepository $playbookCategoryRepository,
private readonly AskAnythingPromptService $askAnythingPromptService,
private readonly SearchRepository $activitySearchRepository,
private readonly AskAnythingRepository $askAnythingRepository,
) {
}
public static function getTypes(): array
{
$types = self::TYPES;
return array_map(static function ($type) {
return $type['id'];
}, $types);
}
public static function getCallTypes(): array
{
return array_map(static function ($callType) {
return $callType['id'];
}, [self::CALL_TYPE_CONFERENCE, self::CALL_TYPE_DIALER]);
}
public static function getFrequencies(): array
{
return array_map(static function ($frequency) {
return $frequency['id'];
}, self::FREQUENCIES);
}
// front-facing structure
public function getReportEnabledFieldData(bool $value = false): array
{
return [
'id' => 'report_enabled',
'label' => '',
'inputType' => InputTypeEnum::TOGGLE,
'value' => $value,
];
}
// Organizations = Teams
public function getOrganizationFieldData(?string $value = null, bool $shortVersion = false): array
{
$options = $this->getTeams();
if ($shortVersion) {
return [
'id' => 'organization',
'label' => 'Organization',
'options' => $options,
];
}
return [
'id' => 'organization',
'label' => 'Organization',
'inputType' => InputTypeEnum::DROPDOWN,
'required' => true,
'placeholder' => 'Select',
'options' => $options,
'value' => $value,
'dependencies' => [
'teams',
'deal_stage_at_call',
'current_deal_stage',
'recipients',
ActivityTypeService::PLAYBOOK_CATEGORIES_KEY,
],
'dependsOn' => [],
];
}
// Teams = Groups
public function getTeamFieldData(array $options = [], array $value = [], bool $shortVersion = false): array
{
if ($shortVersion) {
return [
'id' => 'teams',
'label' => 'Team',
'options' => $options,
];
}
return [
'id' => 'teams',
'label' => 'Team',
'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,
'required' => false,
'placeholder' => 'Select',
'options' => $options,
'value' => $value, // value should be an array of objects {id, name}
'dependencies' => [ActivityTypeService::PLAYBOOK_CATEGORIES_KEY],
'dependsOn' => [],
];
}
public function getReportTypeFieldData(?string $value = null, bool $shortVersion = false, ?Team $team = null): array
{
$types = [];
if ($team instanceof Team) {
if ($team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {
$types = self::TYPES;
}
if ($team->hasFeature(FeatureEnum::ASK_JIMINNY_REPORTS)) {
$types[] = ['id' => self::TYPE_ASK_JIMINNY, 'name' => 'Ask Jiminny'];
}
} else {
$types = self::TYPES;
}
if ($shortVersion) {
return [
'id' => 'report_type',
'label' => 'Report Type',
'options' => $types,
];
}
return [
'id' => 'report_type',
'label' => 'Report Type',
'inputType' => InputTypeEnum::DROPDOWN,
'required' => true,
'placeholder' => 'Select',
'options' => $types,
'value' => $value,
'dependencies' => [],
'dependsOn' => [],
];
}
public function getFrequencyFieldData(?string $value = null): array
{
return [
'id' => 'frequency',
'label' => 'Frequency',
'inputType' => InputTypeEnum::DROPDOWN,
'required' => true,
'placeholder' => 'Select',
'options' => self::FREQUENCIES,
'value' => $value,
'dependencies' => ['period'],
'dependsOn' => [],
];
}
public function getPeriodFieldData(?string $valueStartDate = null, ?string $valueEndDate = null): array
{
return [
'id' => 'period',
'label' => 'Select one-off period',
'inputType' => InputTypeEnum::DATE_RANGE,
'required' => true,
'placeholder' => 'Select',
'value' => ['startDate' => $valueStartDate, 'endDate' => $valueEndDate],
'queryParams' => [
'startDate' => 'start_date_period',
'endDate' => 'end_date_period',
],
'dependencies' => [],
'dependsOn' => ['frequency'],
];
}
public function getActivityTypesFieldData(?Team $team = null, array $value = [], array $teamsFilter = []): array
{
return $this->activityTypeService->getActivityTypeFieldData(team: $team, value: $value, groupIds: $teamsFilter);
}
public function getDealStageAtCallFieldData(?Team $team = null, array $value = []): array
{
return $this->dealStagesService->getDealStageAtCallFieldData(team: $team, value: $value);
}
public function getCurrentDealStageFieldData(?Team $team = null, array $value = []): array
{
return $this->dealStagesService->getCurrentDealStageFieldData(team: $team, value: $value);
}
public function getDealValueFieldData(?int $valueMin = null, ?int $valueMax = null): array
{
return [
'id' => 'deal_value',
'label' => 'Deal Value',
'inputType' => InputTypeEnum::INTEGER_RANGE,
'required' => false,
'value' => ['min' => $valueMin, 'max' => $valueMax],
'queryParams' => [
'min' => 'min_deal_value',
'max' => 'max_deal_value',
],
'dependencies' => [],
'dependsOn' => [],
];
}
public function getCallTypeFieldData(bool $conferenceOn = false, bool $dialerOn = false): array
{
$value = [];
$conferenceOn && $value[] = self::CALL_TYPE_CONFERENCE;
$dialerOn && $value[] = self::CALL_TYPE_DIALER;
return [
'id' => 'call_type',
'label' => 'Call Type',
'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,
'required' => true,
'options' => [
self::CALL_TYPE_CONFERENCE,
self::CALL_TYPE_DIALER,
],
'value' => $value,
'dependencies' => [],
'dependsOn' => [],
];
}
public function getMediaTypeFieldData(?AutomatedReport $report = null): array
{
$value = [];
if ($report) {
$value = $this->transformMediaTypes($report);
}
return [
'id' => 'media_types',
'label' => 'Export as',
'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,
'required' => true,
'options' => self::MEDIA_TYPE_OBJECTS,
'value' => $value,
'dependencies' => [],
'dependsOn' => [],
];
}
public function getCallDurationFieldData(?int $valueMin = null, ?int $valueMax = null): array
{
return [
'id' => 'call_duration',
'label' => 'Call Duration',
'inputType' => InputTypeEnum::INTEGER_RANGE,
'required' => false,
'value' => ['min' => $valueMin, 'max' => $valueMax],
'queryParams' => [
'min' => 'min_call_duration',
'max' => 'max_call_duration',
],
'dependencies' => [],
'dependsOn' => [],
];
}
public function getRecipientsFieldData(?Team $team = null, array $value = []): array
{
return $this->recipientsService->getRecipientsFieldData(team: $team, value: $value);
}
public function getJiminnyRecipientsFieldData(array $value = []): array
{
return $this->recipientsService->getJiminnyRecipientsFieldData($value);
}
public function getAdditionalPromptInputFieldData(?string $value = null): array
{
return [
'id' => 'additional_prompt_input',
'label' => 'Special requirements',
'inputType' => InputTypeEnum::TEXTAREA,
'required' => false,
'placeholder' => 'What should be the focus of the report?',
'value' => $value,
'dependencies' => [],
'dependsOn' => [],
];
}
public function getCustomReportNameFieldData(?string $value = null): array
{
return [
'id' => 'custom_name',
'label' => 'Custom report name',
'inputType' => InputTypeEnum::TEXT,
'required' => false,
'placeholder' => 'Enter custom name',
'value' => $value,
'dependencies' => [],
'dependsOn' => [],
];
}
// data providers
public function getTeams(): array
{
$teams = $this->teamRepository->getTeamsForKiosk(status: Team::STATUS_ACTIVE);
$teamData = [];
foreach ($teams as $team) {
if (! $team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {
continue;
}
$teamData[] = $this->transformTeam($team);
}
return $teamData;
}
public function getTeamGroups(string $teamUuid): array
{
$data = [];
$team = $this->getTeam($teamUuid);
if ($team !== null) {
$groups = $team->groups()->get();
foreach ($groups as $group) {
$data[] = [
'id' => $group->getUuid(),
'name' => $group->getName(),
];
}
}
return $data;
}
public function getTeamsGroupsOptions(array $filterTeamUuids = []): array
{
$data = [];
$teams = $this->getTeams();
foreach ($teams as $team) {
if (! empty($filterTeamUuids) && ! in_array($team['id'], $filterTeamUuids, true)) {
continue;
}
$data[] = [
'label' => $team['name'],
'groups' => $this->getTeamGroups($team['id']),
];
}
return $data;
}
public function getTeam(string $teamUuid): ?Team
{
return $this->teamRepository->idOrUuid($teamUuid);
}
public function getTeamById(int $teamId): ?Team
{
return $this->teamRepository->find($teamId);
}
public function getGroupsUuids(AutomatedReport $report): array
{
$uuids = [];
$reportGroups = $report->getGroups();
foreach ($reportGroups as $groupId) {
if ($group = $this->groupRepository->find($groupId)) {
$uuids[] = $group->getUuid();
}
}
return $uuids;
}
public function getPlaybookCategoriesUuids(AutomatedReport $report): array
{
$uuids = [];
$playbookCategories = $report->getPlaybookCategories();
foreach ($playbookCategories as $id) {
if ($category = $this->playbookCategoryRepository->find($id)) {
$uuids[] = $category->getUuid();
}
}
return $uuids;
}
public function getDealAtCallStagesUuids(AutomatedReport $report): array
{
$uuids = [];
$reportStages = $report->getDealAtCallStages();
foreach ($reportStages as $id) {
if ($stage = $this->stageRepository->find($id)) {
$uuids[] = $stage->getUuid();
}
}
return $uuids;
}
public function getCurrentDealStagesUuids(AutomatedReport $report): array
{
$uuids = [];
$reportStages = $report->getCurrentDealStages();
foreach ($reportStages as $id) {
if ($stage = $this->stageRepository->find($id)) {
$uuids[] = $stage->getUuid();
}
}
return $uuids;
}
public function getUsersUuids(AutomatedReport $report): array
{
return $this->extractUserUuids($report->getRecipients());
}
public function getJiminnyUsersUuids(AutomatedReport $report): array
{
return $this->extractUserUuids($report->getJiminnyRecipients());
}
/**
* @param array<string, mixed> $recipients
*/
private function extractUserUuids(array $recipients): array
{
$userIds = $recipients['users'] ?? [];
return collect($userIds)
->map(fn ($id) => $this->userRepository->find((int) $id))
->filter()
->map(fn (UserContract $user) => $user->getUuid())
->values()
->all();
}
// get mail data
public function getRecipientUsers(AutomatedReport $report): array
{
return $this->buildRecipientUsers($report->getRecipients());
}
private function getJiminnyRecipientUsers(AutomatedReport $report): array
{
return $this->buildRecipientUsers($report->getJiminnyRecipients());
}
/**
* @param array<string, mixed> $recipients
*/
private function buildRecipientUsers(array $recipients): array
{
$userIds = $recipients['users'] ?? [];
return collect($userIds)
->map(fn ($id) => $this->userRepository->find((int) $id))
->filter()
->map(fn (UserContract $user) => [
'email' => $user->getEmailAddress(),
'name' => $user->getName(),
'timezone' => $user->getTimezone()->getName(),
])
->values()
->all();
}
public function getValidRecipientUsers(AutomatedReport $report, bool $includeJiminny = false): array
{
if ($report->isAskJiminnyReport()) {
$recipients = $this->resolveAskJiminnyRecipients($report);
} else {
$recipients = $this->getRecipientUsers($report);
if ($includeJiminny) {
$recipients = array_merge($recipients, $this->getJiminnyRecipientUsers($report));
}
}
$emails = [];
return array_values(array_filter(
$recipients,
static function ($recipient) use (&$emails) {
if (empty($recipient['email']) || in_array($recipient['email'], $emails, true)) {
return false;
}
$emails[] = $recipient['email'];
return true;
}
));
}
private function resolveAskJiminnyRecipients(AutomatedReport $report): array
{
$recipients = [];
$creator = $report->getCreator();
if ($creator !== null) {
$recipients[] = [
'email' => $creator->getEmailAddress(),
'name' => $creator->getName(),
'timezone' => $creator->getTimezone()->getName(),
];
}
return array_merge(
$recipients,
$this->buildRecipientUsers($report->getRecipients()),
$this->getGroupRecipientUsers($report),
);
}
private function getGroupRecipientUsers(AutomatedReport $report): array
{
$users = [];
foreach ($report->getGroups() as $groupId) {
$group = $this->groupRepository->find($groupId);
if ($group === null) {
continue;
}
foreach ($group->getMembers() as $member) {
$users[] = [
'email' => $member->getEmailAddress(),
'name' => $member->getName(),
'timezone' => $member->getTimezone()->getName(),
];
}
}
return $users;
}
public function getReportTypeName(AutomatedReportResult $report): string
{
$type = $report->getReport()->getType();
$getType = $this->transformReportType($type);
return $getType['name'];
}
public function getReportPeriodName(AutomatedReportResult $report): string
{
$from = $report->getFromDate();
$to = $report->getToDate();
$frequency = $report->getReport()->getFrequency();
if ($from === null || $to === null) {
if (! $report->getReport()->isAskJiminnyReport()) {
$invalidPeriod = $from === null ? 'from' : 'to';
throw new ApplicationException('Report period is invalid: ' . $invalidPeriod);
}
$period = $this->calculateFromAndToDatePeriod($frequency);
$from = $period['fromDate'];
$to = $period['toDate'];
}
return $this->formatReportPeriodName($frequency, $from, $to);
}
private function formatReportPeriodName(string $frequency, Carbon $from, Carbon $to): string
{
$fromYear = $from->format('Y');
$toYear = $to->format('Y');
$differentYears = $fromYear !== $toYear;
switch ($frequency) {
case self::FREQUENCY_DAILY:
return $from->format('j M Y');
case self::FREQUENCY_QUARTERLY:
// 'Jan-Mar 2025' or 'Nov 2024-Jan 2025' if years differ
$startMonth = $from->format('M');
$endMonth = $to->copy()->subMonth();
$endMonthName = $endMonth->format('M');
$endMonthYear = $endMonth->format('Y');
if ($differentYears) {
return "{$startMonth} {$fromYear} - {$endMonthName} {$endMonthYear}";
}
return "{$startMonth} - {$endMonthName} {$toYear}";
case self::FREQUENCY_MONTHLY:
// 'May 2025' - monthly reports are always within the same year
return $from->format('M Y');
case self::FREQUENCY_WEEKLY:
// '4 - 8 Aug 2025', '27 Oct - 3 Nov 2025', or '28 Dec 2024 - 3 Jan 2025' if years differ
$startDay = $from->format('j');
$endDay = $to->format('j');
$startMonth = $from->format('M');
$endMonth = $to->format('M');
if ($differentYears) {
return "{$startDay} {$startMonth} {$fromYear} - {$endDay} {$endMonth} {$toYear}";
}
if ($startMonth !== $endMonth) {
return "{$startDay} {$startMonth} - {$endDay} {$endMonth} {$toYear}";
}
return "{$startDay} - {$endDay} {$endMonth} {$toYear}";
case self::FREQUENCY_ONE_OFF:
// '2 May-31 May 2025' or '15 Dec 2024-15 Jan 2025' if years differ
$startDay = $from->format('j');
$startMonth = $from->format('M');
$endDay = $to->format('j');
$endMonth = $to->format('M');
// If same month and year, use a format like '2-31 May 2025'
if ($startMonth === $endMonth && ! $differentYears) {
return "{$startDay} - {$endDay} {$startMonth} {$toYear}";
}
// If different years, include both years
if ($differentYears) {
return "{$startDay} {$startMonth} {$fromYear} - {$endDay} {$endMonth} {$toYear}";
}
// Same year but different months
return "{$startDay} {$startMonth} - {$endDay} {$endMonth} {$toYear}";
default:
// Default format for unknown frequencies
return $from->format('j M Y') . ' - ' . $to->format('j M Y');
}
}
public function getReportTeamsName(AutomatedReportResult $report): string
{
$groups = $report->getGroups();
if (empty($groups)) {
return 'All';
}
// Get group names from repository
$groupNames = [];
foreach ($groups as $groupId) {
$group = $this->groupRepository->find($groupId);
if ($group) {
$groupNames[] = $group->getName();
}
}
if (count($groupNames) === 1) {
// Single team format
$teamsName = $groupNames[0];
} else {
// Multiple teams format
$teamsName = implode(', ', $groupNames);
}
return $teamsName;
}
public function getReportFileName(AutomatedReportResult $report): string
...
|
[{"role":"AXButton","text" [{"role":"AXButton","text":"Project: faVsco.js, menu","depth":5,"help_text":"~/jiminny/app","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"#11894 on JY-18909-automated-reports-ask-jiminny, menu","depth":5,"help_text":"Pull request #11894 exists for current branch JY-18909-automated-reports-ask-jiminny","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Start Listening for PHP Debug Connections","depth":5,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"AutomatedReportsCommandTest","depth":6,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Run 'AutomatedReportsCommandTest'","depth":6,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Debug 'AutomatedReportsCommandTest'","depth":6,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"More Actions","depth":6,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JetBrains AI","depth":5,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Search Everywhere","depth":5,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"IDE and Project Settings","depth":5,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Execute","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Explain Plan","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Browse Query History","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"View Parameters","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Open Query Execution Settings…","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"In-Editor Results","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Tx: Auto","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Cancel Running Statements","depth":4,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Playground","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"jiminny","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.088194445,"height":0.027777778},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"16","depth":4,"role_description":"text"},{"role":"AXStaticText","text":"13","depth":4,"role_description":"text"},{"role":"AXStaticText","text":"13","depth":4,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"SELECT * FROM teams WHERE id = 1;\n\nselect * from crm_layouts where crm_configuration_id = 39;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 283;\nSELECT * FROM crm_fields WHERE id = 2234;\nSELECT * FROM crm_field_values WHERE crm_field_id = 2234;\n\nselect * from crm_profiles where user_id = 143;\n\nselect * from record_types where crm_configuration_id = 39; # 0121K000001MHElQAO,0121K000001MHEqQAO\nselect * from business_processes where crm_configuration_id = 39;\n# 01941000000H669AAC, 01941000000H66JAAS\n\nselect * from record_type_field_values\n where record_type_id IN (24);\n\nselect * from crm_field_values where id IN (2730);\n\nselect * from crm_configurations where id = 39;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 1\nand sa.provider = 'salesforce'; #1035\n\n\nselect * from users where team_id = 1; # 222 group 3\nSELECT * FROM activities WHERE user_id = 222 order by id desc;\nselect * from sidekick_settings where team_id = 1;\nselect * from teams where id = 1;\nselect * from team_features where team_id = 1;\n\nselect * from activities where crm_configuration_id = 2\nand provider = 'ms-teams' and id = 608765;\n\nSELECT * FROM activities WHERE crm_configuration_id = 2 and crm_provider_id = '59523413338';\n\nselect * from sidekick_settings where team_id = 2;\n\nSELECT * FROM activities WHERE id = 608660;\nselect * from activity_summary_logs where activity_id = 608660;\nselect * from ai_prompts where transcription_id = 11214;\n\n# ********************************************************************************************************\nSELECT * FROM activities WHERE uuid_to_bin('ed78a437-2804-450e-ab2f-56ab1c641346') = uuid;\n# id: 608818, crm: 59628809737\nSELECT * FROM activities WHERE uuid_to_bin('36b06e55-afdd-4782-8dee-c624cd0af191') = uuid;\n# id: 608821, crm: 59632069252\nSELECT ce.start_time, ce.end_time, a.id, a.uuid, crm_provider_id, calendar_event_id, title,\nplaybook_category_id, user_id, lead_id, contact_id, account_id, opportunity_id,\nscheduled_start_time, scheduled_end_time, actual_start_time, actual_end_time, a.created_at\nFROM activities a\njoin calendar_events ce on a.calendar_event_id = ce.id\nWHERE a.id IN (608818, 608821);\n\nselect * from users where team_id = 1;\nselect * from team_settings where team_id = 1;\nselect * from crm_profiles where crm_configuration_id = 39 order by user_id;\n\nselect * from team_features where team_id = 1;\n\nselect * from users where team_id = 2;\n\nSELECT * FROM activities WHERE uuid_to_bin('ec7647e9-5225-458b-b475-f31aa2769204') = uuid; # 612639\n# Preslava N. Ivanova, grou id 3\n\nSELECT * FROM opportunities WHERE uuid_to_bin('a2928fe5-aec5-46cb-85d9-7654c89e46a6') = uuid;\n\nselect * from activities where opportunity_id = 344 and actual_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00';\n\nselect\n a.id,\n a.type,\n a.scheduled_start_time,\n a.actual_start_time,\n a.created_at,\n a.opportunity_id,\n a.status\nFROM activities a\nWHERE opportunity_id = 344\nand status IN ('completed', 'received', 'delivered')\nand (\n (a.actual_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00')\nOR (a.created_at between '2024-10-11 00:00:00' and '2024-10-12 00:00:00')\nOR (a.scheduled_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00'))\n;\n\nSELECT * FROM users WHERE id = 222;\n\nSELECT * FROM crm_profiles WHERE user_id = 222;\nselect * from crm_layouts where crm_configuration_id = 39;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 281;\n\nselect * from group_deal_risk_types;\n\nselect * from opportunities where team_id = 1;\n\nSELECT * FROM opportunities WHERE id = 315;\nSELECT * FROM crm_field_data WHERE object_id = 315;\nselect * from crm_field_data where object_id = 260;\n\nselect * from generic_ai_prompts where subject_id = 315;\n\nselect * from teams; # 36, 21, 121, james.graham@bullhorn.jiminny.com\nSELECT * FROM social_accounts WHERE sociable_id = 121 and provider = 'bullhorn';\n\n# ************************************************************************************\nselect * from teams where id = 1;\nselect * from crm_configurations where id = 39;\nselect * from users where team_id = 1;\nselect u.email, cp.* from users u\njoin crm_profiles cp on u.id = cp.user_id\nwhere u.team_id = 1;\n# 1 - 00541000004281rAAA\n# 204 - 0052g000003freeAAA\n# 429 - 0052g000003qGOiAAM\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 1\nand sa.provider = 'salesforce';\n\nselect * from activities where type = 'softphone'\nand created_at > '2024-12-11 15:24:36' order by id desc;\n\nselect * from activity_providers where team_id = 1;\nselect * from activity_provider_users where activity_provider_id = 328;\n\nselect * from opportunities where crm_configuration_id = 39\nAND account_id = 178 AND is_closed = false\norder by created_at DESC;\n\nselect * from contacts where id = 3952;\nselect * from accounts where id = 178;\n\n# ************************************************************************************\nselect * from teams where id = 36;\nselect * from crm_configurations where id = 21;\nselect * from users where team_id = 36;\nselect u.email, cp.* from users u\njoin crm_profiles cp on u.id = cp.user_id\nwhere u.team_id = 36;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 36\nand sa.provider = 'bullhorn';\n\nselect * from social_accounts where id = 348;\nUPDATE social_accounts SET\nprovider_user_token = '21442_6802599_91:41179a58-21e7-4d7c-ad58-56bb666b2f65',\nprovider_refresh_token = '21442_6802599_91:01c6b335-3f2a-42e4-85ff-8a08fa65fceb',\nexpires = 1733998131,\nstate = 'connected'\nWHERE id = 348;\n\n# ************************************************************************************\nselect * from teams where id = 31;\nselect * from crm_configurations where id = 18;\n\nselect * from users where team_id = 31; # 257\nselect u.email, cp.* from users u\njoin crm_profiles cp on u.id = cp.user_id\nwhere u.team_id = 31;\n\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 31\nand sa.provider = 'close';\n\nselect * from contacts where crm_configuration_id = 18;\n\n# ********************** NEPTUNE **************************************************************\nselect * from teams;\nselect * from users where id IN (1030, 1035, 1052);\nselect * from crm_configurations;\n\nselect * from users where team_id = 65; # 257\nselect * from team_settings where team_id = 65; # 257\nselect * from invitations where team_id = 65; # 257\nselect * from users where email = 'integration-account@jiminny.com'; # 257\nselect u.email, cp.* from users u\njoin crm_profiles cp on u.id = cp.user_id\nwhere u.team_id = 65;\n\nselect * from crm_configurations where id = 53;\nselect * from accounts where crm_configuration_id = 53 order by id desc;\nselect * from leads where crm_configuration_id = 53 order by id desc;\nselect * from contacts where crm_configuration_id = 53 order by id desc;\nselect * from opportunities where crm_configuration_id = 53 order by id desc;\nselect * from crm_profiles where crm_configuration_id = 53 order by id desc;\nselect * from crm_fields where crm_configuration_id = 53 order by id desc;\nselect * from crm_field_values where crm_field_id = 3341 order by id desc;\nselect * from crm_layouts where crm_configuration_id = 53 order by id desc;\nselect * from stages where crm_configuration_id = 53 order by id desc;\n\n\nselect * from crm_profiles where crm_configuration_id = 13;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 65\nand sa.provider = 'integration-app';\n\nselect * from contacts where crm_configuration_id = 13;\n\nselect * from social_accounts where sociable_id = 283;\n\nSELECT * FROM opportunities WHERE crm_provider_id = '006O400000E9bzeIAB';\n\nselect * from activity_providers where team_id = 65;\nSELECT * FROM activities WHERE crm_configuration_id IN (51, 52, 53);\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 65\n;\n\n# ***************************** STAGING ********************************************\nSELECT * FROM teams;\nSELECT * FROM teams WHERE id = 88;\nSELECT * FROM teams WHERE id = 89;\nselect * from team_settings where team_id = 89;\nSELECT * FROM users WHERE team_id = 89;\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 89;\n\nselect * from users;\nSELECT * FROM social_accounts WHERE sociable_id = 1761;\nSELECT * FROM crm_configurations WHERE id = 70;\nselect * from accounts where crm_configuration_id = 70 order by id desc;\nselect * from leads where crm_configuration_id = 70 order by id desc;\nselect * from contacts where crm_configuration_id = 70 order by id desc;\nselect * from opportunities where crm_configuration_id = 70 order by id desc;\nselect * from crm_profiles where crm_configuration_id = 70 order by id desc;\nselect * from crm_fields where crm_configuration_id = 70 order by id desc;\nselect * from crm_field_values where crm_field_id = 3536 order by id desc;\nselect * from crm_layouts where crm_configuration_id = 70 order by id desc;\nselect * from stages where crm_configuration_id = 70 order by id desc;\nselect * from business_processes where crm_configuration_id = 70 order by id desc;\nselect * from business_process_stages where business_process_id = 34;\n\nselect * from contacts where id = 10468;\n\nselect * from crm_layouts where crm_configuration_id = 70;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 388;\nSELECT * FROM crm_fields WHERE id IN (3533,3534,3535);\n\nselect * from activities where crm_configuration_id = 70\nand (account_id IS NOT NULL or lead_id IS NOT NULL or contact_id IS NOT NULL or opportunity_id IS NOT NULL) order by id desc;\n\nSELECT * FROM activities WHERE uuid_to_bin('2e10b60f-8a61-41c5-a3d4-28835353dc65') = uuid;\nSELECT * FROM activities where crm_configuration_id = 69 ;\n\nSELECT * FROM users WHERE email LIKE '%jiminny_web_sa2@jiminny.com%';\nSELECT * FROM activities WHERE uuid_to_bin('5a150c93-40fc-42ec-b3bd-c1d328e09f6e') = uuid;\nSELECT * FROM opportunities WHERE id = 385;\n\nselect * from participants p\njoin activities a on p.activity_id = a.id\nwhere a.crm_configuration_id = 70\nand (p.lead_id IS NOT NULL or p.contact_id IS NOT NULL);\nSELECT * FROM participants WHERE id = 1013638;\n\nselect * from teams where id = 90;\nselect * from users where team_id = 90;\nselect * from social_accounts where social_accounts.sociable_id IN (1960,1760);\nSELECT * FROM crm_profiles WHERE crm_configuration_id = 71;\nselect * from invitations where team_id = 90;\n\nselect * from crm_configurations where id = 71;\nselect * from accounts where crm_configuration_id = 71 order by id desc;\nselect * from leads where crm_configuration_id = 71 order by id desc;\nselect * from contacts where crm_configuration_id = 71 order by id desc;\nselect * from opportunities where crm_configuration_id = 71 order by id desc;\nselect * from crm_profiles where crm_configuration_id = 71 order by id desc;\nselect * from crm_fields where crm_configuration_id = 71 order by id desc;\nselect * from crm_field_values where crm_field_id = 3341 order by id desc;\nselect * from crm_layouts where crm_configuration_id = 71 order by id desc;\nselect * from stages where crm_configuration_id = 71 order by id desc;\n\nselect * from users order by secondary_email desc;\nselect u.id, u.email, u.status, sa.id, sa.provider_user_id from social_accounts sa\n join users u on sa.sociable_id = u.id\nwhere sa.provider = 'google' and u.email LIKE 'aneliya%';\n\nselect * from failed_jobs order by id desc;\n\nselect * from users where email = 'ben.allwright@learningpeople.co.uk' or secondary_email = 'ben.allwright@learningpeople.co.uk';\n\nselect * from teams;\nSELECT * FROM crm_profiles WHERE crm_configuration_id = 39;\nSELECT * FROM crm_fields WHERE crm_configuration_id = 39 and object_type = 'task';\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 1\nand sa.provider = 'salesforce';\n\n# ************************************************************************************\nSELECT * FROM activities WHERE uuid_to_bin('c38b3895-fd0f-4b1f-9fb2-c170dba137c6') = uuid;\nSELECT * FROM crm_configurations WHERE id = 70;\n\nselect * from teams where id = 1;\nselect * from groups where team_id = 1;\nselect * from users where team_id = 1;\n\nselect o.id, o.name,o.close_date, u.id, u.name, u.group_id, r.id, r.display_name, g.name, g.scope from opportunities o\njoin users u on o.user_id = u.id\njoin groups g on u.group_id = g.id\njoin role_user ru on u.id = ru.user_id\njoin roles r on ru.role_id = r.id\nwhere o.crm_configuration_id = 39 and close_date > '2024-01-01 00:00:00';\n\nselect * from role_user where user_id = 143;\nselect * from roles;\n\nselect * from role_user;\nselect * from groups where id = 9;\nselect * from scope_groups where group_id = 9;\n\n# ************************************************************************************\nselect * from teams where id = 36;\nselect * from crm_configurations;\nSELECT * FROM social_accounts WHERE sociable_id = 121;\n\nhttps://crmsandbox.zoho.com/crm/jiminnyw4/tab/Leads/4776201000005049105\nhttps://crmsandbox.zoho.com/crm/\n\nhttps://crm.zoho.com/crm/org3469620/tab/Leads/230045000229559080\n https://crm.zoho.com/crm/\n org3469620\n\nSELECT * FROM activities WHERE uuid_to_bin('03382d20-c8bc-48e7-a3d4-90b52fa5ceab') = uuid;\n\nselect * from users where email LIKE \"%mobile_automation_%\";\nselect * from social_accounts where sociable_id IN (2228);\nselect * from crm_profiles where user_id IN (2222,2223,2226,2227);\n\nselect * from teams order by id desc;\nSELECT * FROM users WHERE id = 2229;\nSELECT * FROM crm_profiles WHERE user_id = 2229;\nselect * from opportunities where crm_configuration_id = 88;\nselect * from crm_fields where crm_configuration_id = 88;\nselect * from crm_profiles where crm_configuration_id = 88;\n\nSELECT * FROM teams WHERE id = 1;\n\nSELECT * FROM users WHERE id = 143;\nSELECT * FROM users WHERE uuid_to_bin('fde193d3-06a2-4e1a-8895-62b94039215d') = uuid;\nSELECT * FROM teams WHERE uuid_to_bin('73385071-a756-42ae-9c73-8b53f2309467') = uuid;\n\nhttps://app.staging.jiminny.com/ondemand?\n min_duration=1\n &\n only_recorded=1\n &\n user_id%5B%5D=641f1acb-16b8-42d1-8726-df52979dad0e\n &\n sequence_number=2\n\n select * from users where team_id = 1 and email like '%stoyan%'\n\nselect * from coaching_feedbacks;\n\nselect * from teams;\nSELECT * FROM users WHERE team_id = 36;\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 19\nand sa.provider = 'pipedrive';\n\nselect * from users where id = 143;\n\nSELECT * FROM users WHERE uuid_to_bin('73180eeb-33de-4065-977d-ccbe0e6c94fc') = uuid;\nSELECT * FROM teams WHERE uuid_to_bin('73180eeb-33de-4065-977d-ccbe0e6c94fc') = uuid;\nSELECT * FROM activity_shares WHERE uuid_to_bin('73180eeb-33de-4065-977d-ccbe0e6c94fc') = uuid;\n\nselect * from users where team_id = 2;\nselect * from activities where crm_configuration_id = 39\nand activities.scheduled_start_time BETWEEN '2025-04-09 00:00:00' AND '2025-04-09 23:59:59'\nAND user_id = 143\norder by id desc;\n\n# ************************************************************************************\nselect * from teams where id = 142; # 2312, 126\nselect * from team_settings;\nselect * from users where team_id = 142; # 21642\nSELECT * FROM social_accounts WHERE sociable_id = 21642;\nSELECT * FROM crm_profiles cp join users u ON u.id = cp.user_id WHERE team_id = 142;\nselect * from crm_profiles where id IN (93);\nselect * from invitations;\nselect * from team_features where team_id = 1;\n\nSELECT * FROM crm_configurations WHERE id = 126;\nselect * from accounts where crm_configuration_id = 126 order by id desc;\nselect * from leads where crm_configuration_id = 126 order by id desc;\nselect * from contacts where crm_configuration_id = 126 order by id desc;\nselect * from opportunities where crm_configuration_id = 126 order by id desc;\nselect * from crm_profiles where crm_configuration_id = 126 order by id desc;\nselect * from crm_fields where crm_configuration_id = 126 # 11060\n# and type IN ('picklist', 'status')\n# and object_type = 'task'\norder by id desc;\n# 5731,5732,5733\nselect DISTINCT crm_field_id from crm_field_values where crm_field_id IN (11151,12239,12215,12185,12175,12165,12144,12137,12127,12109,12107,12105,12103,12092,12037,12005,12003,11987,11969,11958,11951,11942,11931,11924,11921,11917,11915,11901,11893,11883,11872,11870,11868,11866,11839,11833,11821,11793,11780,11777,11769,11757,11737,11735,11656,11645,11638,11629,11618,11611,11602,11591,11584,11581,11558,11544,11543,11534,11532,11529,11527,11503,11497,11493,11488,11470,11468,11457,11455,11397,11387,11372,11363,11348,11323,11318,11309,11301,11300,11292,11290,11286,11284,11256,11252,11242,11237,11233,11219,11176,11160) order by id desc;\nselect * from crm_layouts where crm_configuration_id = 126 order by id desc;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id in (300,299,298);\nselect * from stages where crm_configuration_id = 126 order by id desc;\nselect * from business_processes where crm_configuration_id = 126 order by id desc;\nselect * from business_process_stages where business_process_id IN (76,75,74,73);\nselect * from playbooks where team_id = 142;\nselect * from playbook_layouts where playbook_id IN (108);\nSELECT * FROM playbook_categories WHERE playbook_id IN (108);\n\nselect * from teams where id = 130;\nSELECT * FROM social_accounts WHERE sociable_id = 2291;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 2\nand sa.provider = 'hubspot';\n\nSELECT * FROM activities\n WHERE crm_configuration_id = 110;\n\nselect * from teams;\nselect * from crm_configurations;\n\nSELECT * FROM activities WHERE id = 628773;\nSELECT * FROM crm_profiles WHERE user_id = 1460;\nSELECT * FROM social_accounts WHERE sociable_id = 2291;\n\nselect * from teams;\nselect ru.*, pr.*, p.* from users u join role_user ru on ru.user_id = u.id\njoin permission_role pr on pr.role_id = ru.role_id\n join permissions p on p.id = pr.permission_id\nwhere team_id = 495 and p.name IN ('dial');\n\nselect * from teams where id = 145;\nselect * from crm_configurations where id = 129;\nselect * from social_accounts where sociable_id = 2317;\nSELECT * FROM activities WHERE uuid_to_bin('8dbab184-a333-4268-ad57-fb41f8d53a9a') = uuid;\n\nselect * from teams where id = 1;\nSELECT * FROM crm_layouts WHERE crm_configuration_id = 39;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 280;\nSELECT * FROM crm_layout_entities WHERE id = 5507;\nSELECT * FROM crm_fields WHERE crm_configuration_id = 39 and object_type IN ('event');\n\nselect * from teams;\nselect * from activities where crm_configuration_id = 14;\n\nSELECT * FROM social_accounts where provider = 'copper';\n\nselect * from activities where id = 628467;\nselect * from participants where activity_id = 628467;\n\nSELECT * FROM contacts WHERE id = 3969;\nSELECT * FROM accounts WHERE id = 177;\n\nSELECT * FROM activities WHERE uuid_to_bin('4eb54c77-cfa3-2bd4-84a7-9ed46a21c988') = uuid;\n\n# ********************* BH\nselect * from teams where id = 36;\nSELECT * FROM crm_configurations WHERE id = 21;\nselect * from activities where crm_configuration_id = 21 and id = 607901;\nselect * from activities where crm_configuration_id = 21;\n\nselect * roles;\nselect * from permissions;\nselect * from permission_role where permission_id = 226;\n\nselect * from migrations order by id desc;\n\n# mercury\n# neptune\n# earth\n\nselect * from teams;\nselect * from teams where id = 19;\nselect * from teams where id = 27;\nselect * from users where team_id = 27;\nSELECT * FROM crm_configurations WHERE id = 42;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 19\nand sa.provider = 'pipedrive';\n\nselect * from activities where id = 631461;\nSELECT * FROM crm_field_values WHERE crm_field_id = 180;\n\nselect * from teams where id = 2;\nSELECT * FROM social_accounts WHERE sociable_id = 89;\n\nSELECT * FROM activities WHERE uuid_to_bin('ba0c029a-bc14-4e17-8603-64174acebcbb') = uuid; # 634273\nselect * from activity_summary_logs where activity_id = 634273;\n\nselect * from sidekick_settings where team_id = 2;\n\nselect * from teams; # 2, 2\nSELECT * FROM crm_configurations WHERE team_id = 2; # 2\nselect * from team_features where team_id = 2;\nselect * from features;\nSELECT * FROM opportunities WHERE crm_configuration_id = 2 and crm_provider_id = '51317301383';\nSELECT * FROM opportunities WHERE crm_configuration_id = 2 order by id desc;\n\nselect * from automated_reports order by id desc;\nselect * from automated_report_results order by id desc;\nselect * from users where team_id = 1 and id IN (7160, 3248);\nselect * from migrations order by id desc;\n\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 1 and sa.provider = 'salesforce';\n\nselect * from teams where id = 1;\nselect * from groups g JOIN playbooks p on g.playbook_id = p.id where g.team_id = 1;\nselect * from groups where id = 565;\nselect * from playbooks where team_id = 1;\nselect * from playbooks where id = 175;\nselect * from playbook_categories where playbook_id = 175;\nselect * from users where team_id = 1;\nselect * from users where id = 7160;\nselect * from crm_profiles where user_id = 7160;\nselect * from features;\nselect\n *\n# id, uuid, type, provider, playbook_category_id, user_id, lead_id, contact_id, account_id, opportunity_id, stage_id,\n# crm_configuration_id, crm_provider_id, transcription_id, status\nfrom activities where crm_configuration_id = 1 and type = 'conference'\n# and crm_provider_id IS NOT NULL\nand provider != 'uploader' and actual_start_time IS NOT NULL\nORDER by id desc;\nselect * from activities where id = 54747783; # 00UO400000pCzojMAC\n\nselect p.id, p.activity_type, pc.id, pc.name\nFROM playbooks p\njoin playbook_categories pc on p.id = pc.playbook_id\nwhere p.team_id = 1 and p.activity_type = 'event';\n\nSELECT * FROM crm_fields WHERE crm_configuration_id = 1 and object_type = 'event';\nSELECT * FROM crm_field_values WHERE crm_field_id = 4;\n\nselect * from crm_layouts cl join playbook_layouts pl on cl.id = pl.layout_id\nwhere crm_configuration_id = 1 and pl.playbook_id = 175;\n\nselect * from teams;\nSELECT r.* FROM automated_reports r\njoin teams t on r.team_id = t.id\nWHERE r.frequency = 'daily'\n and r.status = 1\nAND t.status = 'active'\nAND (r.expires_at >= now() OR r.expires_at IS NULL);\n\nselect * from automated_report_results where report_id IN (18, 33);\n\nselect * from activity_searches where id = 10932;\nselect * from activity_search_filters where activity_search_id = 10932;\nselect * from automated_reports;\nselect * from automated_report_results where report_id IN (34, 35);","depth":4,"value":"SELECT * FROM teams WHERE id = 1;\n\nselect * from crm_layouts where crm_configuration_id = 39;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 283;\nSELECT * FROM crm_fields WHERE id = 2234;\nSELECT * FROM crm_field_values WHERE crm_field_id = 2234;\n\nselect * from crm_profiles where user_id = 143;\n\nselect * from record_types where crm_configuration_id = 39; # 0121K000001MHElQAO,0121K000001MHEqQAO\nselect * from business_processes where crm_configuration_id = 39;\n# 01941000000H669AAC, 01941000000H66JAAS\n\nselect * from record_type_field_values\n where record_type_id IN (24);\n\nselect * from crm_field_values where id IN (2730);\n\nselect * from crm_configurations where id = 39;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 1\nand sa.provider = 'salesforce'; #1035\n\n\nselect * from users where team_id = 1; # 222 group 3\nSELECT * FROM activities WHERE user_id = 222 order by id desc;\nselect * from sidekick_settings where team_id = 1;\nselect * from teams where id = 1;\nselect * from team_features where team_id = 1;\n\nselect * from activities where crm_configuration_id = 2\nand provider = 'ms-teams' and id = 608765;\n\nSELECT * FROM activities WHERE crm_configuration_id = 2 and crm_provider_id = '59523413338';\n\nselect * from sidekick_settings where team_id = 2;\n\nSELECT * FROM activities WHERE id = 608660;\nselect * from activity_summary_logs where activity_id = 608660;\nselect * from ai_prompts where transcription_id = 11214;\n\n# ********************************************************************************************************\nSELECT * FROM activities WHERE uuid_to_bin('ed78a437-2804-450e-ab2f-56ab1c641346') = uuid;\n# id: 608818, crm: 59628809737\nSELECT * FROM activities WHERE uuid_to_bin('36b06e55-afdd-4782-8dee-c624cd0af191') = uuid;\n# id: 608821, crm: 59632069252\nSELECT ce.start_time, ce.end_time, a.id, a.uuid, crm_provider_id, calendar_event_id, title,\nplaybook_category_id, user_id, lead_id, contact_id, account_id, opportunity_id,\nscheduled_start_time, scheduled_end_time, actual_start_time, actual_end_time, a.created_at\nFROM activities a\njoin calendar_events ce on a.calendar_event_id = ce.id\nWHERE a.id IN (608818, 608821);\n\nselect * from users where team_id = 1;\nselect * from team_settings where team_id = 1;\nselect * from crm_profiles where crm_configuration_id = 39 order by user_id;\n\nselect * from team_features where team_id = 1;\n\nselect * from users where team_id = 2;\n\nSELECT * FROM activities WHERE uuid_to_bin('ec7647e9-5225-458b-b475-f31aa2769204') = uuid; # 612639\n# Preslava N. Ivanova, grou id 3\n\nSELECT * FROM opportunities WHERE uuid_to_bin('a2928fe5-aec5-46cb-85d9-7654c89e46a6') = uuid;\n\nselect * from activities where opportunity_id = 344 and actual_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00';\n\nselect\n a.id,\n a.type,\n a.scheduled_start_time,\n a.actual_start_time,\n a.created_at,\n a.opportunity_id,\n a.status\nFROM activities a\nWHERE opportunity_id = 344\nand status IN ('completed', 'received', 'delivered')\nand (\n (a.actual_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00')\nOR (a.created_at between '2024-10-11 00:00:00' and '2024-10-12 00:00:00')\nOR (a.scheduled_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00'))\n;\n\nSELECT * FROM users WHERE id = 222;\n\nSELECT * FROM crm_profiles WHERE user_id = 222;\nselect * from crm_layouts where crm_configuration_id = 39;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 281;\n\nselect * from group_deal_risk_types;\n\nselect * from opportunities where team_id = 1;\n\nSELECT * FROM opportunities WHERE id = 315;\nSELECT * FROM crm_field_data WHERE object_id = 315;\nselect * from crm_field_data where object_id = 260;\n\nselect * from generic_ai_prompts where subject_id = 315;\n\nselect * from teams; # 36, 21, 121, james.graham@bullhorn.jiminny.com\nSELECT * FROM social_accounts WHERE sociable_id = 121 and provider = 'bullhorn';\n\n# ************************************************************************************\nselect * from teams where id = 1;\nselect * from crm_configurations where id = 39;\nselect * from users where team_id = 1;\nselect u.email, cp.* from users u\njoin crm_profiles cp on u.id = cp.user_id\nwhere u.team_id = 1;\n# 1 - 00541000004281rAAA\n# 204 - 0052g000003freeAAA\n# 429 - 0052g000003qGOiAAM\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 1\nand sa.provider = 'salesforce';\n\nselect * from activities where type = 'softphone'\nand created_at > '2024-12-11 15:24:36' order by id desc;\n\nselect * from activity_providers where team_id = 1;\nselect * from activity_provider_users where activity_provider_id = 328;\n\nselect * from opportunities where crm_configuration_id = 39\nAND account_id = 178 AND is_closed = false\norder by created_at DESC;\n\nselect * from contacts where id = 3952;\nselect * from accounts where id = 178;\n\n# ************************************************************************************\nselect * from teams where id = 36;\nselect * from crm_configurations where id = 21;\nselect * from users where team_id = 36;\nselect u.email, cp.* from users u\njoin crm_profiles cp on u.id = cp.user_id\nwhere u.team_id = 36;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 36\nand sa.provider = 'bullhorn';\n\nselect * from social_accounts where id = 348;\nUPDATE social_accounts SET\nprovider_user_token = '21442_6802599_91:41179a58-21e7-4d7c-ad58-56bb666b2f65',\nprovider_refresh_token = '21442_6802599_91:01c6b335-3f2a-42e4-85ff-8a08fa65fceb',\nexpires = 1733998131,\nstate = 'connected'\nWHERE id = 348;\n\n# ************************************************************************************\nselect * from teams where id = 31;\nselect * from crm_configurations where id = 18;\n\nselect * from users where team_id = 31; # 257\nselect u.email, cp.* from users u\njoin crm_profiles cp on u.id = cp.user_id\nwhere u.team_id = 31;\n\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 31\nand sa.provider = 'close';\n\nselect * from contacts where crm_configuration_id = 18;\n\n# ********************** NEPTUNE **************************************************************\nselect * from teams;\nselect * from users where id IN (1030, 1035, 1052);\nselect * from crm_configurations;\n\nselect * from users where team_id = 65; # 257\nselect * from team_settings where team_id = 65; # 257\nselect * from invitations where team_id = 65; # 257\nselect * from users where email = 'integration-account@jiminny.com'; # 257\nselect u.email, cp.* from users u\njoin crm_profiles cp on u.id = cp.user_id\nwhere u.team_id = 65;\n\nselect * from crm_configurations where id = 53;\nselect * from accounts where crm_configuration_id = 53 order by id desc;\nselect * from leads where crm_configuration_id = 53 order by id desc;\nselect * from contacts where crm_configuration_id = 53 order by id desc;\nselect * from opportunities where crm_configuration_id = 53 order by id desc;\nselect * from crm_profiles where crm_configuration_id = 53 order by id desc;\nselect * from crm_fields where crm_configuration_id = 53 order by id desc;\nselect * from crm_field_values where crm_field_id = 3341 order by id desc;\nselect * from crm_layouts where crm_configuration_id = 53 order by id desc;\nselect * from stages where crm_configuration_id = 53 order by id desc;\n\n\nselect * from crm_profiles where crm_configuration_id = 13;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 65\nand sa.provider = 'integration-app';\n\nselect * from contacts where crm_configuration_id = 13;\n\nselect * from social_accounts where sociable_id = 283;\n\nSELECT * FROM opportunities WHERE crm_provider_id = '006O400000E9bzeIAB';\n\nselect * from activity_providers where team_id = 65;\nSELECT * FROM activities WHERE crm_configuration_id IN (51, 52, 53);\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 65\n;\n\n# ***************************** STAGING ********************************************\nSELECT * FROM teams;\nSELECT * FROM teams WHERE id = 88;\nSELECT * FROM teams WHERE id = 89;\nselect * from team_settings where team_id = 89;\nSELECT * FROM users WHERE team_id = 89;\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 89;\n\nselect * from users;\nSELECT * FROM social_accounts WHERE sociable_id = 1761;\nSELECT * FROM crm_configurations WHERE id = 70;\nselect * from accounts where crm_configuration_id = 70 order by id desc;\nselect * from leads where crm_configuration_id = 70 order by id desc;\nselect * from contacts where crm_configuration_id = 70 order by id desc;\nselect * from opportunities where crm_configuration_id = 70 order by id desc;\nselect * from crm_profiles where crm_configuration_id = 70 order by id desc;\nselect * from crm_fields where crm_configuration_id = 70 order by id desc;\nselect * from crm_field_values where crm_field_id = 3536 order by id desc;\nselect * from crm_layouts where crm_configuration_id = 70 order by id desc;\nselect * from stages where crm_configuration_id = 70 order by id desc;\nselect * from business_processes where crm_configuration_id = 70 order by id desc;\nselect * from business_process_stages where business_process_id = 34;\n\nselect * from contacts where id = 10468;\n\nselect * from crm_layouts where crm_configuration_id = 70;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 388;\nSELECT * FROM crm_fields WHERE id IN (3533,3534,3535);\n\nselect * from activities where crm_configuration_id = 70\nand (account_id IS NOT NULL or lead_id IS NOT NULL or contact_id IS NOT NULL or opportunity_id IS NOT NULL) order by id desc;\n\nSELECT * FROM activities WHERE uuid_to_bin('2e10b60f-8a61-41c5-a3d4-28835353dc65') = uuid;\nSELECT * FROM activities where crm_configuration_id = 69 ;\n\nSELECT * FROM users WHERE email LIKE '%jiminny_web_sa2@jiminny.com%';\nSELECT * FROM activities WHERE uuid_to_bin('5a150c93-40fc-42ec-b3bd-c1d328e09f6e') = uuid;\nSELECT * FROM opportunities WHERE id = 385;\n\nselect * from participants p\njoin activities a on p.activity_id = a.id\nwhere a.crm_configuration_id = 70\nand (p.lead_id IS NOT NULL or p.contact_id IS NOT NULL);\nSELECT * FROM participants WHERE id = 1013638;\n\nselect * from teams where id = 90;\nselect * from users where team_id = 90;\nselect * from social_accounts where social_accounts.sociable_id IN (1960,1760);\nSELECT * FROM crm_profiles WHERE crm_configuration_id = 71;\nselect * from invitations where team_id = 90;\n\nselect * from crm_configurations where id = 71;\nselect * from accounts where crm_configuration_id = 71 order by id desc;\nselect * from leads where crm_configuration_id = 71 order by id desc;\nselect * from contacts where crm_configuration_id = 71 order by id desc;\nselect * from opportunities where crm_configuration_id = 71 order by id desc;\nselect * from crm_profiles where crm_configuration_id = 71 order by id desc;\nselect * from crm_fields where crm_configuration_id = 71 order by id desc;\nselect * from crm_field_values where crm_field_id = 3341 order by id desc;\nselect * from crm_layouts where crm_configuration_id = 71 order by id desc;\nselect * from stages where crm_configuration_id = 71 order by id desc;\n\nselect * from users order by secondary_email desc;\nselect u.id, u.email, u.status, sa.id, sa.provider_user_id from social_accounts sa\n join users u on sa.sociable_id = u.id\nwhere sa.provider = 'google' and u.email LIKE 'aneliya%';\n\nselect * from failed_jobs order by id desc;\n\nselect * from users where email = 'ben.allwright@learningpeople.co.uk' or secondary_email = 'ben.allwright@learningpeople.co.uk';\n\nselect * from teams;\nSELECT * FROM crm_profiles WHERE crm_configuration_id = 39;\nSELECT * FROM crm_fields WHERE crm_configuration_id = 39 and object_type = 'task';\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 1\nand sa.provider = 'salesforce';\n\n# ************************************************************************************\nSELECT * FROM activities WHERE uuid_to_bin('c38b3895-fd0f-4b1f-9fb2-c170dba137c6') = uuid;\nSELECT * FROM crm_configurations WHERE id = 70;\n\nselect * from teams where id = 1;\nselect * from groups where team_id = 1;\nselect * from users where team_id = 1;\n\nselect o.id, o.name,o.close_date, u.id, u.name, u.group_id, r.id, r.display_name, g.name, g.scope from opportunities o\njoin users u on o.user_id = u.id\njoin groups g on u.group_id = g.id\njoin role_user ru on u.id = ru.user_id\njoin roles r on ru.role_id = r.id\nwhere o.crm_configuration_id = 39 and close_date > '2024-01-01 00:00:00';\n\nselect * from role_user where user_id = 143;\nselect * from roles;\n\nselect * from role_user;\nselect * from groups where id = 9;\nselect * from scope_groups where group_id = 9;\n\n# ************************************************************************************\nselect * from teams where id = 36;\nselect * from crm_configurations;\nSELECT * FROM social_accounts WHERE sociable_id = 121;\n\nhttps://crmsandbox.zoho.com/crm/jiminnyw4/tab/Leads/4776201000005049105\nhttps://crmsandbox.zoho.com/crm/\n\nhttps://crm.zoho.com/crm/org3469620/tab/Leads/230045000229559080\n https://crm.zoho.com/crm/\n org3469620\n\nSELECT * FROM activities WHERE uuid_to_bin('03382d20-c8bc-48e7-a3d4-90b52fa5ceab') = uuid;\n\nselect * from users where email LIKE \"%mobile_automation_%\";\nselect * from social_accounts where sociable_id IN (2228);\nselect * from crm_profiles where user_id IN (2222,2223,2226,2227);\n\nselect * from teams order by id desc;\nSELECT * FROM users WHERE id = 2229;\nSELECT * FROM crm_profiles WHERE user_id = 2229;\nselect * from opportunities where crm_configuration_id = 88;\nselect * from crm_fields where crm_configuration_id = 88;\nselect * from crm_profiles where crm_configuration_id = 88;\n\nSELECT * FROM teams WHERE id = 1;\n\nSELECT * FROM users WHERE id = 143;\nSELECT * FROM users WHERE uuid_to_bin('fde193d3-06a2-4e1a-8895-62b94039215d') = uuid;\nSELECT * FROM teams WHERE uuid_to_bin('73385071-a756-42ae-9c73-8b53f2309467') = uuid;\n\nhttps://app.staging.jiminny.com/ondemand?\n min_duration=1\n &\n only_recorded=1\n &\n user_id%5B%5D=641f1acb-16b8-42d1-8726-df52979dad0e\n &\n sequence_number=2\n\n select * from users where team_id = 1 and email like '%stoyan%'\n\nselect * from coaching_feedbacks;\n\nselect * from teams;\nSELECT * FROM users WHERE team_id = 36;\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 19\nand sa.provider = 'pipedrive';\n\nselect * from users where id = 143;\n\nSELECT * FROM users WHERE uuid_to_bin('73180eeb-33de-4065-977d-ccbe0e6c94fc') = uuid;\nSELECT * FROM teams WHERE uuid_to_bin('73180eeb-33de-4065-977d-ccbe0e6c94fc') = uuid;\nSELECT * FROM activity_shares WHERE uuid_to_bin('73180eeb-33de-4065-977d-ccbe0e6c94fc') = uuid;\n\nselect * from users where team_id = 2;\nselect * from activities where crm_configuration_id = 39\nand activities.scheduled_start_time BETWEEN '2025-04-09 00:00:00' AND '2025-04-09 23:59:59'\nAND user_id = 143\norder by id desc;\n\n# ************************************************************************************\nselect * from teams where id = 142; # 2312, 126\nselect * from team_settings;\nselect * from users where team_id = 142; # 21642\nSELECT * FROM social_accounts WHERE sociable_id = 21642;\nSELECT * FROM crm_profiles cp join users u ON u.id = cp.user_id WHERE team_id = 142;\nselect * from crm_profiles where id IN (93);\nselect * from invitations;\nselect * from team_features where team_id = 1;\n\nSELECT * FROM crm_configurations WHERE id = 126;\nselect * from accounts where crm_configuration_id = 126 order by id desc;\nselect * from leads where crm_configuration_id = 126 order by id desc;\nselect * from contacts where crm_configuration_id = 126 order by id desc;\nselect * from opportunities where crm_configuration_id = 126 order by id desc;\nselect * from crm_profiles where crm_configuration_id = 126 order by id desc;\nselect * from crm_fields where crm_configuration_id = 126 # 11060\n# and type IN ('picklist', 'status')\n# and object_type = 'task'\norder by id desc;\n# 5731,5732,5733\nselect DISTINCT crm_field_id from crm_field_values where crm_field_id IN (11151,12239,12215,12185,12175,12165,12144,12137,12127,12109,12107,12105,12103,12092,12037,12005,12003,11987,11969,11958,11951,11942,11931,11924,11921,11917,11915,11901,11893,11883,11872,11870,11868,11866,11839,11833,11821,11793,11780,11777,11769,11757,11737,11735,11656,11645,11638,11629,11618,11611,11602,11591,11584,11581,11558,11544,11543,11534,11532,11529,11527,11503,11497,11493,11488,11470,11468,11457,11455,11397,11387,11372,11363,11348,11323,11318,11309,11301,11300,11292,11290,11286,11284,11256,11252,11242,11237,11233,11219,11176,11160) order by id desc;\nselect * from crm_layouts where crm_configuration_id = 126 order by id desc;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id in (300,299,298);\nselect * from stages where crm_configuration_id = 126 order by id desc;\nselect * from business_processes where crm_configuration_id = 126 order by id desc;\nselect * from business_process_stages where business_process_id IN (76,75,74,73);\nselect * from playbooks where team_id = 142;\nselect * from playbook_layouts where playbook_id IN (108);\nSELECT * FROM playbook_categories WHERE playbook_id IN (108);\n\nselect * from teams where id = 130;\nSELECT * FROM social_accounts WHERE sociable_id = 2291;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 2\nand sa.provider = 'hubspot';\n\nSELECT * FROM activities\n WHERE crm_configuration_id = 110;\n\nselect * from teams;\nselect * from crm_configurations;\n\nSELECT * FROM activities WHERE id = 628773;\nSELECT * FROM crm_profiles WHERE user_id = 1460;\nSELECT * FROM social_accounts WHERE sociable_id = 2291;\n\nselect * from teams;\nselect ru.*, pr.*, p.* from users u join role_user ru on ru.user_id = u.id\njoin permission_role pr on pr.role_id = ru.role_id\n join permissions p on p.id = pr.permission_id\nwhere team_id = 495 and p.name IN ('dial');\n\nselect * from teams where id = 145;\nselect * from crm_configurations where id = 129;\nselect * from social_accounts where sociable_id = 2317;\nSELECT * FROM activities WHERE uuid_to_bin('8dbab184-a333-4268-ad57-fb41f8d53a9a') = uuid;\n\nselect * from teams where id = 1;\nSELECT * FROM crm_layouts WHERE crm_configuration_id = 39;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 280;\nSELECT * FROM crm_layout_entities WHERE id = 5507;\nSELECT * FROM crm_fields WHERE crm_configuration_id = 39 and object_type IN ('event');\n\nselect * from teams;\nselect * from activities where crm_configuration_id = 14;\n\nSELECT * FROM social_accounts where provider = 'copper';\n\nselect * from activities where id = 628467;\nselect * from participants where activity_id = 628467;\n\nSELECT * FROM contacts WHERE id = 3969;\nSELECT * FROM accounts WHERE id = 177;\n\nSELECT * FROM activities WHERE uuid_to_bin('4eb54c77-cfa3-2bd4-84a7-9ed46a21c988') = uuid;\n\n# ********************* BH\nselect * from teams where id = 36;\nSELECT * FROM crm_configurations WHERE id = 21;\nselect * from activities where crm_configuration_id = 21 and id = 607901;\nselect * from activities where crm_configuration_id = 21;\n\nselect * roles;\nselect * from permissions;\nselect * from permission_role where permission_id = 226;\n\nselect * from migrations order by id desc;\n\n# mercury\n# neptune\n# earth\n\nselect * from teams;\nselect * from teams where id = 19;\nselect * from teams where id = 27;\nselect * from users where team_id = 27;\nSELECT * FROM crm_configurations WHERE id = 42;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 19\nand sa.provider = 'pipedrive';\n\nselect * from activities where id = 631461;\nSELECT * FROM crm_field_values WHERE crm_field_id = 180;\n\nselect * from teams where id = 2;\nSELECT * FROM social_accounts WHERE sociable_id = 89;\n\nSELECT * FROM activities WHERE uuid_to_bin('ba0c029a-bc14-4e17-8603-64174acebcbb') = uuid; # 634273\nselect * from activity_summary_logs where activity_id = 634273;\n\nselect * from sidekick_settings where team_id = 2;\n\nselect * from teams; # 2, 2\nSELECT * FROM crm_configurations WHERE team_id = 2; # 2\nselect * from team_features where team_id = 2;\nselect * from features;\nSELECT * FROM opportunities WHERE crm_configuration_id = 2 and crm_provider_id = '51317301383';\nSELECT * FROM opportunities WHERE crm_configuration_id = 2 order by id desc;\n\nselect * from automated_reports order by id desc;\nselect * from automated_report_results order by id desc;\nselect * from users where team_id = 1 and id IN (7160, 3248);\nselect * from migrations order by id desc;\n\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 1 and sa.provider = 'salesforce';\n\nselect * from teams where id = 1;\nselect * from groups g JOIN playbooks p on g.playbook_id = p.id where g.team_id = 1;\nselect * from groups where id = 565;\nselect * from playbooks where team_id = 1;\nselect * from playbooks where id = 175;\nselect * from playbook_categories where playbook_id = 175;\nselect * from users where team_id = 1;\nselect * from users where id = 7160;\nselect * from crm_profiles where user_id = 7160;\nselect * from features;\nselect\n *\n# id, uuid, type, provider, playbook_category_id, user_id, lead_id, contact_id, account_id, opportunity_id, stage_id,\n# crm_configuration_id, crm_provider_id, transcription_id, status\nfrom activities where crm_configuration_id = 1 and type = 'conference'\n# and crm_provider_id IS NOT NULL\nand provider != 'uploader' and actual_start_time IS NOT NULL\nORDER by id desc;\nselect * from activities where id = 54747783; # 00UO400000pCzojMAC\n\nselect p.id, p.activity_type, pc.id, pc.name\nFROM playbooks p\njoin playbook_categories pc on p.id = pc.playbook_id\nwhere p.team_id = 1 and p.activity_type = 'event';\n\nSELECT * FROM crm_fields WHERE crm_configuration_id = 1 and object_type = 'event';\nSELECT * FROM crm_field_values WHERE crm_field_id = 4;\n\nselect * from crm_layouts cl join playbook_layouts pl on cl.id = pl.layout_id\nwhere crm_configuration_id = 1 and pl.playbook_id = 175;\n\nselect * from teams;\nSELECT r.* FROM automated_reports r\njoin teams t on r.team_id = t.id\nWHERE r.frequency = 'daily'\n and r.status = 1\nAND t.status = 'active'\nAND (r.expires_at >= now() OR r.expires_at IS NULL);\n\nselect * from automated_report_results where report_id IN (18, 33);\n\nselect * from activity_searches where id = 10932;\nselect * from activity_search_filters where activity_search_id = 10932;\nselect * from automated_reports;\nselect * from automated_report_results where report_id IN (34, 35);","role_description":"text entry area","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.088194445,"height":0.027777778},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"102","depth":4,"role_description":"text"},{"role":"AXStaticText","text":"3","depth":4,"role_description":"text"},{"role":"AXStaticText","text":"34","depth":4,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Services\\Kiosk\\AutomatedReports;\n\nuse Carbon\\CarbonImmutable;\nuse Carbon\\CarbonInterface;\nuse Carbon\\Exceptions\\InvalidFormatException;\nuse DateTime;\nuse DateTimeInterface;\nuse DateTimeZone;\nuse Illuminate\\Contracts\\Bus\\Dispatcher as BusDispatcher;\nuse Illuminate\\Database\\Eloquent\\Builder;\nuse Illuminate\\Support\\Carbon;\nuse Illuminate\\Support\\Collection;\nuse Illuminate\\Support\\Facades\\Log;\nuse Illuminate\\Support\\Facades\\Storage;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinition\\InputTypeEnum;\nuse Jiminny\\Component\\AskAnything\\AskAnythingPromptService;\nuse Jiminny\\Component\\AskAnything\\Dtos\\AskAnythingPromptDto;\nuse Jiminny\\Component\\UrlGenerator\\Webhook;\nuse Jiminny\\Contracts\\Repositories\\PlaybookCategoryRepository;\nuse Jiminny\\Contracts\\Repositories\\TeamRepository;\nuse Jiminny\\Contracts\\Repositories\\UserRepository;\nuse Jiminny\\Exceptions\\ApplicationException;\nuse Jiminny\\Exceptions\\InvalidArgumentException;\nuse Jiminny\\Exceptions\\ModelNotFoundException;\nuse Jiminny\\Jobs\\AutomatedReports\\RequestGenerateReportJob;\nuse Jiminny\\Models\\Activity\\Search;\nuse Jiminny\\Models\\AskAnything\\AskAnythingPrompt;\nuse Jiminny\\Models\\AskAnything\\AskAnythingPromptTarget;\nuse Jiminny\\Models\\AutomatedReport;\nuse Jiminny\\Models\\AutomatedReportResult;\nuse Jiminny\\Models\\Contracts\\UserContract;\nuse Jiminny\\Models\\Feature\\FeatureEnum;\nuse Jiminny\\Models\\Team;\nuse Jiminny\\Models\\User;\nuse Jiminny\\Repositories\\AskAnythingRepository;\nuse Jiminny\\Repositories\\AutomatedReportsRepository;\nuse Jiminny\\Repositories\\GroupRepository;\nuse Jiminny\\Repositories\\SearchRepository;\nuse Jiminny\\Repositories\\StageRepository;\nuse Throwable;\n\nclass AutomatedReportsService\n{\n public const string TYPE_LOSS_ANALYSIS = 'loss_analysis';\n public const string TYPE_ASK_JIMINNY = 'ask_jiminny';\n\n /**\n * Standard report types (used by kiosk for existing automated reports).\n */\n // @TODO this will add filter, however if we need to control feature by FF we need conditional logic\n public const array TYPES = [\n ['id' => 'exec_summary', 'name' => 'Exec Summary'],\n ['id' => 'coaching_profiles', 'name' => 'Coaching Profiles'],\n ['id' => 'product_feedback', 'name' => 'Product Feedback'],\n ['id' => self::TYPE_LOSS_ANALYSIS, 'name' => 'Loss Analysis'],\n// ['id' => 'questions', 'name' => 'Questions'],\n// ['id' => 'statistical_quant', 'name' => 'Statistical Quantitative'],\n ];\n\n public const array ALL_TYPES = [\n ...self::TYPES,\n ['id' => self::TYPE_ASK_JIMINNY, 'name' => 'Ask Jiminny'],\n ];\n\n public const string FREQUENCY_DAILY = 'daily';\n public const string FREQUENCY_WEEKLY = 'weekly';\n public const string FREQUENCY_MONTHLY = 'monthly';\n public const string FREQUENCY_QUARTERLY = 'quarterly';\n public const string FREQUENCY_ONE_OFF = 'one_off';\n\n /**\n * Frequencies for standard (non-Ask Jiminny) reports.\n */\n public const array FREQUENCIES = [\n ['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],\n ['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],\n ['id' => self::FREQUENCY_QUARTERLY, 'name' => 'Quarterly'],\n ['id' => self::FREQUENCY_ONE_OFF, 'name' => 'One-off'],\n ];\n\n /**\n * Frequencies for Ask Jiminny reports.\n */\n public const array ASK_JIMINNY_FREQUENCIES = [\n ['id' => self::FREQUENCY_DAILY, 'name' => 'Daily'],\n ['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],\n ['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],\n ];\n\n public const string MEDIA_TYPE_PDF = 'pdf';\n public const string MEDIA_TYPE_PODCAST = 'podcast';\n public const array MEDIA_TYPES = [self::MEDIA_TYPE_PDF, self::MEDIA_TYPE_PODCAST];\n public const array MEDIA_TYPE_OBJECT_PDF = ['id' => self::MEDIA_TYPE_PDF, 'name' => 'PDF'];\n public const array MEDIA_TYPE_OBJECT_PODCAST = ['id' => self::MEDIA_TYPE_PODCAST, 'name' => 'Podcast'];\n public const array MEDIA_TYPE_OBJECTS = [self::MEDIA_TYPE_OBJECT_PDF, self::MEDIA_TYPE_OBJECT_PODCAST];\n\n public const array CALL_TYPE_CONFERENCE = ['id' => 'conference', 'name' => 'Conference'];\n public const array CALL_TYPE_DIALER = ['id' => 'dialer', 'name' => 'Dialer'];\n public const int SENT_REPORT_AT_HOURS = 5;\n public const string PDF_KEY = 'pdf';\n public const string AUDIO_KEY = 'audio';\n\n private const array ALL_FREQUENCIES = [\n ['id' => self::FREQUENCY_DAILY, 'name' => 'Daily'],\n ['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],\n ['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],\n ['id' => self::FREQUENCY_QUARTERLY, 'name' => 'Quarterly'],\n ['id' => self::FREQUENCY_ONE_OFF, 'name' => 'One-off'],\n ];\n private const string S3_DIR = 'reports';\n private const array FILE_EXTENSIONS_VARIANTS = ['html', 'MD', 'pdf'];\n private const array FILE_PODCAST_EXTENSIONS_VARIANTS = ['json', 'mp3', 'ssml'];\n\n public function __construct(\n private readonly TeamRepository $teamRepository,\n private readonly GroupRepository $groupRepository,\n private readonly UserRepository $userRepository,\n private readonly StageRepository $stageRepository,\n private readonly DealStagesService $dealStagesService,\n private readonly RecipientsService $recipientsService,\n private readonly AutomatedReportsRepository $automatedReportsRepository,\n private readonly Webhook $webhookService,\n private readonly BusDispatcher $dispatcher,\n private readonly ActivityTypeService $activityTypeService,\n private readonly PlaybookCategoryRepository $playbookCategoryRepository,\n private readonly AskAnythingPromptService $askAnythingPromptService,\n private readonly SearchRepository $activitySearchRepository,\n private readonly AskAnythingRepository $askAnythingRepository,\n ) {\n }\n\n public static function getTypes(): array\n {\n $types = self::TYPES;\n\n return array_map(static function ($type) {\n return $type['id'];\n }, $types);\n }\n\n public static function getCallTypes(): array\n {\n return array_map(static function ($callType) {\n return $callType['id'];\n }, [self::CALL_TYPE_CONFERENCE, self::CALL_TYPE_DIALER]);\n }\n\n public static function getFrequencies(): array\n {\n return array_map(static function ($frequency) {\n return $frequency['id'];\n }, self::FREQUENCIES);\n }\n\n // front-facing structure\n public function getReportEnabledFieldData(bool $value = false): array\n {\n return [\n 'id' => 'report_enabled',\n 'label' => '',\n 'inputType' => InputTypeEnum::TOGGLE,\n 'value' => $value,\n ];\n }\n\n // Organizations = Teams\n public function getOrganizationFieldData(?string $value = null, bool $shortVersion = false): array\n {\n $options = $this->getTeams();\n\n if ($shortVersion) {\n return [\n 'id' => 'organization',\n 'label' => 'Organization',\n 'options' => $options,\n ];\n }\n\n return [\n 'id' => 'organization',\n 'label' => 'Organization',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => $options,\n 'value' => $value,\n 'dependencies' => [\n 'teams',\n 'deal_stage_at_call',\n 'current_deal_stage',\n 'recipients',\n ActivityTypeService::PLAYBOOK_CATEGORIES_KEY,\n ],\n 'dependsOn' => [],\n ];\n }\n\n // Teams = Groups\n public function getTeamFieldData(array $options = [], array $value = [], bool $shortVersion = false): array\n {\n if ($shortVersion) {\n return [\n 'id' => 'teams',\n 'label' => 'Team',\n 'options' => $options,\n ];\n }\n\n return [\n 'id' => 'teams',\n 'label' => 'Team',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'required' => false,\n 'placeholder' => 'Select',\n 'options' => $options,\n 'value' => $value, // value should be an array of objects {id, name}\n 'dependencies' => [ActivityTypeService::PLAYBOOK_CATEGORIES_KEY],\n 'dependsOn' => [],\n ];\n }\n\n public function getReportTypeFieldData(?string $value = null, bool $shortVersion = false, ?Team $team = null): array\n {\n $types = [];\n if ($team instanceof Team) {\n if ($team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {\n $types = self::TYPES;\n }\n if ($team->hasFeature(FeatureEnum::ASK_JIMINNY_REPORTS)) {\n $types[] = ['id' => self::TYPE_ASK_JIMINNY, 'name' => 'Ask Jiminny'];\n }\n } else {\n $types = self::TYPES;\n }\n\n if ($shortVersion) {\n return [\n 'id' => 'report_type',\n 'label' => 'Report Type',\n 'options' => $types,\n ];\n }\n\n return [\n 'id' => 'report_type',\n 'label' => 'Report Type',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => $types,\n 'value' => $value,\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getFrequencyFieldData(?string $value = null): array\n {\n return [\n 'id' => 'frequency',\n 'label' => 'Frequency',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => self::FREQUENCIES,\n 'value' => $value,\n 'dependencies' => ['period'],\n 'dependsOn' => [],\n ];\n }\n\n public function getPeriodFieldData(?string $valueStartDate = null, ?string $valueEndDate = null): array\n {\n return [\n 'id' => 'period',\n 'label' => 'Select one-off period',\n 'inputType' => InputTypeEnum::DATE_RANGE,\n 'required' => true,\n 'placeholder' => 'Select',\n 'value' => ['startDate' => $valueStartDate, 'endDate' => $valueEndDate],\n 'queryParams' => [\n 'startDate' => 'start_date_period',\n 'endDate' => 'end_date_period',\n ],\n 'dependencies' => [],\n 'dependsOn' => ['frequency'],\n ];\n }\n\n public function getActivityTypesFieldData(?Team $team = null, array $value = [], array $teamsFilter = []): array\n {\n return $this->activityTypeService->getActivityTypeFieldData(team: $team, value: $value, groupIds: $teamsFilter);\n }\n\n public function getDealStageAtCallFieldData(?Team $team = null, array $value = []): array\n {\n return $this->dealStagesService->getDealStageAtCallFieldData(team: $team, value: $value);\n }\n\n public function getCurrentDealStageFieldData(?Team $team = null, array $value = []): array\n {\n return $this->dealStagesService->getCurrentDealStageFieldData(team: $team, value: $value);\n }\n\n public function getDealValueFieldData(?int $valueMin = null, ?int $valueMax = null): array\n {\n return [\n 'id' => 'deal_value',\n 'label' => 'Deal Value',\n 'inputType' => InputTypeEnum::INTEGER_RANGE,\n 'required' => false,\n 'value' => ['min' => $valueMin, 'max' => $valueMax],\n 'queryParams' => [\n 'min' => 'min_deal_value',\n 'max' => 'max_deal_value',\n ],\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getCallTypeFieldData(bool $conferenceOn = false, bool $dialerOn = false): array\n {\n $value = [];\n $conferenceOn && $value[] = self::CALL_TYPE_CONFERENCE;\n $dialerOn && $value[] = self::CALL_TYPE_DIALER;\n\n return [\n 'id' => 'call_type',\n 'label' => 'Call Type',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'required' => true,\n 'options' => [\n self::CALL_TYPE_CONFERENCE,\n self::CALL_TYPE_DIALER,\n ],\n 'value' => $value,\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getMediaTypeFieldData(?AutomatedReport $report = null): array\n {\n $value = [];\n\n if ($report) {\n $value = $this->transformMediaTypes($report);\n }\n\n return [\n 'id' => 'media_types',\n 'label' => 'Export as',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'required' => true,\n 'options' => self::MEDIA_TYPE_OBJECTS,\n 'value' => $value,\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getCallDurationFieldData(?int $valueMin = null, ?int $valueMax = null): array\n {\n return [\n 'id' => 'call_duration',\n 'label' => 'Call Duration',\n 'inputType' => InputTypeEnum::INTEGER_RANGE,\n 'required' => false,\n 'value' => ['min' => $valueMin, 'max' => $valueMax],\n 'queryParams' => [\n 'min' => 'min_call_duration',\n 'max' => 'max_call_duration',\n ],\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getRecipientsFieldData(?Team $team = null, array $value = []): array\n {\n return $this->recipientsService->getRecipientsFieldData(team: $team, value: $value);\n }\n\n public function getJiminnyRecipientsFieldData(array $value = []): array\n {\n return $this->recipientsService->getJiminnyRecipientsFieldData($value);\n }\n\n public function getAdditionalPromptInputFieldData(?string $value = null): array\n {\n return [\n 'id' => 'additional_prompt_input',\n 'label' => 'Special requirements',\n 'inputType' => InputTypeEnum::TEXTAREA,\n 'required' => false,\n 'placeholder' => 'What should be the focus of the report?',\n 'value' => $value,\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getCustomReportNameFieldData(?string $value = null): array\n {\n return [\n 'id' => 'custom_name',\n 'label' => 'Custom report name',\n 'inputType' => InputTypeEnum::TEXT,\n 'required' => false,\n 'placeholder' => 'Enter custom name',\n 'value' => $value,\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n // data providers\n public function getTeams(): array\n {\n $teams = $this->teamRepository->getTeamsForKiosk(status: Team::STATUS_ACTIVE);\n\n $teamData = [];\n foreach ($teams as $team) {\n if (! $team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {\n continue;\n }\n\n $teamData[] = $this->transformTeam($team);\n }\n\n return $teamData;\n }\n\n public function getTeamGroups(string $teamUuid): array\n {\n $data = [];\n $team = $this->getTeam($teamUuid);\n\n if ($team !== null) {\n $groups = $team->groups()->get();\n\n foreach ($groups as $group) {\n $data[] = [\n 'id' => $group->getUuid(),\n 'name' => $group->getName(),\n ];\n }\n }\n\n return $data;\n }\n\n public function getTeamsGroupsOptions(array $filterTeamUuids = []): array\n {\n $data = [];\n $teams = $this->getTeams();\n\n foreach ($teams as $team) {\n if (! empty($filterTeamUuids) && ! in_array($team['id'], $filterTeamUuids, true)) {\n continue;\n }\n\n $data[] = [\n 'label' => $team['name'],\n 'groups' => $this->getTeamGroups($team['id']),\n ];\n }\n\n return $data;\n }\n\n public function getTeam(string $teamUuid): ?Team\n {\n return $this->teamRepository->idOrUuid($teamUuid);\n }\n\n public function getTeamById(int $teamId): ?Team\n {\n return $this->teamRepository->find($teamId);\n }\n\n public function getGroupsUuids(AutomatedReport $report): array\n {\n $uuids = [];\n $reportGroups = $report->getGroups();\n foreach ($reportGroups as $groupId) {\n if ($group = $this->groupRepository->find($groupId)) {\n $uuids[] = $group->getUuid();\n }\n }\n\n return $uuids;\n }\n\n public function getPlaybookCategoriesUuids(AutomatedReport $report): array\n {\n $uuids = [];\n $playbookCategories = $report->getPlaybookCategories();\n foreach ($playbookCategories as $id) {\n if ($category = $this->playbookCategoryRepository->find($id)) {\n $uuids[] = $category->getUuid();\n }\n }\n\n return $uuids;\n }\n\n public function getDealAtCallStagesUuids(AutomatedReport $report): array\n {\n $uuids = [];\n $reportStages = $report->getDealAtCallStages();\n foreach ($reportStages as $id) {\n if ($stage = $this->stageRepository->find($id)) {\n $uuids[] = $stage->getUuid();\n }\n }\n\n return $uuids;\n }\n\n public function getCurrentDealStagesUuids(AutomatedReport $report): array\n {\n $uuids = [];\n $reportStages = $report->getCurrentDealStages();\n foreach ($reportStages as $id) {\n if ($stage = $this->stageRepository->find($id)) {\n $uuids[] = $stage->getUuid();\n }\n }\n\n return $uuids;\n }\n\n public function getUsersUuids(AutomatedReport $report): array\n {\n return $this->extractUserUuids($report->getRecipients());\n }\n\n public function getJiminnyUsersUuids(AutomatedReport $report): array\n {\n return $this->extractUserUuids($report->getJiminnyRecipients());\n }\n\n /**\n * @param array<string, mixed> $recipients\n */\n private function extractUserUuids(array $recipients): array\n {\n $userIds = $recipients['users'] ?? [];\n\n return collect($userIds)\n ->map(fn ($id) => $this->userRepository->find((int) $id))\n ->filter()\n ->map(fn (UserContract $user) => $user->getUuid())\n ->values()\n ->all();\n }\n\n // get mail data\n public function getRecipientUsers(AutomatedReport $report): array\n {\n return $this->buildRecipientUsers($report->getRecipients());\n }\n\n private function getJiminnyRecipientUsers(AutomatedReport $report): array\n {\n return $this->buildRecipientUsers($report->getJiminnyRecipients());\n }\n\n /**\n * @param array<string, mixed> $recipients\n */\n private function buildRecipientUsers(array $recipients): array\n {\n $userIds = $recipients['users'] ?? [];\n\n return collect($userIds)\n ->map(fn ($id) => $this->userRepository->find((int) $id))\n ->filter()\n ->map(fn (UserContract $user) => [\n 'email' => $user->getEmailAddress(),\n 'name' => $user->getName(),\n 'timezone' => $user->getTimezone()->getName(),\n ])\n ->values()\n ->all();\n }\n\n public function getValidRecipientUsers(AutomatedReport $report, bool $includeJiminny = false): array\n {\n if ($report->isAskJiminnyReport()) {\n $recipients = $this->resolveAskJiminnyRecipients($report);\n } else {\n $recipients = $this->getRecipientUsers($report);\n if ($includeJiminny) {\n $recipients = array_merge($recipients, $this->getJiminnyRecipientUsers($report));\n }\n }\n\n $emails = [];\n\n return array_values(array_filter(\n $recipients,\n static function ($recipient) use (&$emails) {\n if (empty($recipient['email']) || in_array($recipient['email'], $emails, true)) {\n return false;\n }\n $emails[] = $recipient['email'];\n\n return true;\n }\n ));\n }\n\n private function resolveAskJiminnyRecipients(AutomatedReport $report): array\n {\n $recipients = [];\n\n $creator = $report->getCreator();\n if ($creator !== null) {\n $recipients[] = [\n 'email' => $creator->getEmailAddress(),\n 'name' => $creator->getName(),\n 'timezone' => $creator->getTimezone()->getName(),\n ];\n }\n\n return array_merge(\n $recipients,\n $this->buildRecipientUsers($report->getRecipients()),\n $this->getGroupRecipientUsers($report),\n );\n }\n\n private function getGroupRecipientUsers(AutomatedReport $report): array\n {\n $users = [];\n foreach ($report->getGroups() as $groupId) {\n $group = $this->groupRepository->find($groupId);\n if ($group === null) {\n continue;\n }\n foreach ($group->getMembers() as $member) {\n $users[] = [\n 'email' => $member->getEmailAddress(),\n 'name' => $member->getName(),\n 'timezone' => $member->getTimezone()->getName(),\n ];\n }\n }\n\n return $users;\n }\n\n public function getReportTypeName(AutomatedReportResult $report): string\n {\n $type = $report->getReport()->getType();\n\n $getType = $this->transformReportType($type);\n\n return $getType['name'];\n }\n\n public function getReportPeriodName(AutomatedReportResult $report): string\n {\n $from = $report->getFromDate();\n $to = $report->getToDate();\n $frequency = $report->getReport()->getFrequency();\n\n if ($from === null || $to === null) {\n if (! $report->getReport()->isAskJiminnyReport()) {\n $invalidPeriod = $from === null ? 'from' : 'to';\n\n throw new ApplicationException('Report period is invalid: ' . $invalidPeriod);\n }\n\n $period = $this->calculateFromAndToDatePeriod($frequency);\n $from = $period['fromDate'];\n $to = $period['toDate'];\n }\n\n return $this->formatReportPeriodName($frequency, $from, $to);\n }\n\n private function formatReportPeriodName(string $frequency, Carbon $from, Carbon $to): string\n {\n $fromYear = $from->format('Y');\n $toYear = $to->format('Y');\n $differentYears = $fromYear !== $toYear;\n\n switch ($frequency) {\n case self::FREQUENCY_DAILY:\n return $from->format('j M Y');\n\n case self::FREQUENCY_QUARTERLY:\n // 'Jan-Mar 2025' or 'Nov 2024-Jan 2025' if years differ\n $startMonth = $from->format('M');\n $endMonth = $to->copy()->subMonth();\n $endMonthName = $endMonth->format('M');\n $endMonthYear = $endMonth->format('Y');\n\n if ($differentYears) {\n return \"{$startMonth} {$fromYear} - {$endMonthName} {$endMonthYear}\";\n }\n\n return \"{$startMonth} - {$endMonthName} {$toYear}\";\n\n case self::FREQUENCY_MONTHLY:\n // 'May 2025' - monthly reports are always within the same year\n return $from->format('M Y');\n\n case self::FREQUENCY_WEEKLY:\n // '4 - 8 Aug 2025', '27 Oct - 3 Nov 2025', or '28 Dec 2024 - 3 Jan 2025' if years differ\n $startDay = $from->format('j');\n $endDay = $to->format('j');\n $startMonth = $from->format('M');\n $endMonth = $to->format('M');\n\n if ($differentYears) {\n return \"{$startDay} {$startMonth} {$fromYear} - {$endDay} {$endMonth} {$toYear}\";\n }\n\n if ($startMonth !== $endMonth) {\n return \"{$startDay} {$startMonth} - {$endDay} {$endMonth} {$toYear}\";\n }\n\n return \"{$startDay} - {$endDay} {$endMonth} {$toYear}\";\n\n case self::FREQUENCY_ONE_OFF:\n // '2 May-31 May 2025' or '15 Dec 2024-15 Jan 2025' if years differ\n $startDay = $from->format('j');\n $startMonth = $from->format('M');\n $endDay = $to->format('j');\n $endMonth = $to->format('M');\n\n // If same month and year, use a format like '2-31 May 2025'\n if ($startMonth === $endMonth && ! $differentYears) {\n return \"{$startDay} - {$endDay} {$startMonth} {$toYear}\";\n }\n\n // If different years, include both years\n if ($differentYears) {\n return \"{$startDay} {$startMonth} {$fromYear} - {$endDay} {$endMonth} {$toYear}\";\n }\n\n // Same year but different months\n return \"{$startDay} {$startMonth} - {$endDay} {$endMonth} {$toYear}\";\n\n default:\n // Default format for unknown frequencies\n return $from->format('j M Y') . ' - ' . $to->format('j M Y');\n }\n }\n\n public function getReportTeamsName(AutomatedReportResult $report): string\n {\n $groups = $report->getGroups();\n\n if (empty($groups)) {\n return 'All';\n }\n\n // Get group names from repository\n $groupNames = [];\n foreach ($groups as $groupId) {\n $group = $this->groupRepository->find($groupId);\n if ($group) {\n $groupNames[] = $group->getName();\n }\n }\n\n if (count($groupNames) === 1) {\n // Single team format\n $teamsName = $groupNames[0];\n } else {\n // Multiple teams format\n $teamsName = implode(', ', $groupNames);\n }\n\n return $teamsName;\n }\n\n public function getReportFileName(AutomatedReportResult $report): string\n {\n $customName = $report->getReport()->getCustomName();\n $periodName = $this->getReportPeriodName($report);\n $filenameSuffix = $this->getFilenameSuffix($report);\n\n if ($customName) {\n if ($filenameSuffix) {\n $customName .= \" {$filenameSuffix}\";\n }\n\n return $this->sanitizeFileName(\"{$customName} - {$periodName}\");\n }\n\n $baseName = $this->getReportTypeName($report);\n\n if ($filenameSuffix) {\n $baseName .= \" {$filenameSuffix}\";\n }\n\n return $this->sanitizeFileName(\"{$baseName} - {$periodName} - {$this->getReportTeamsName($report)}\");\n }\n\n public function getReportFileNameWithExtension(AutomatedReportResult $result): string\n {\n $extension = $this->getMediaTypeMetadata($result)['extension'];\n\n return $this->getReportFileName($result) . '.' . $extension;\n }\n\n public function sanitizeFileName(string $fileName): string\n {\n return str_replace(['/', '\\\\'], '-', $fileName);\n }\n\n public function isUserRecipientOfReport(User $user, AutomatedReport $report): bool\n {\n $recipients = array_map('intval', $report->getRecipients()['users'] ?? []);\n\n return in_array($user->getId(), $recipients);\n }\n\n public function transformReportResults(Collection $automatedReportResults): array\n {\n $data = [];\n foreach ($automatedReportResults as $automatedReportResult) {\n /** @var AutomatedReportResult $automatedReportResult */\n\n $report = $automatedReportResult->getReport();\n\n $createdBy = $report->getCreator();\n $creator = [\n 'id' => $createdBy?->getUuid(),\n 'name' => $createdBy?->getName(),\n 'email' => $createdBy?->getEmailAddress(),\n 'photoUrl' => $createdBy?->getPhotoUrl(),\n ];\n\n $data[] = [\n 'id' => $automatedReportResult->getUuid(),\n 'name' => $automatedReportResult->getName(),\n 'frequency' => $this->transformFrequency($report->getFrequency()),\n 'recipients' => [\n ...array_values($this->transformGroups(team: $report->getTeam(), groupsIds: $report->getGroups())),\n ...array_values($this->transformRecipients($report->getRecipients())),\n ],\n 'report_type' => $this->transformReportType($report->getType()),\n 'media_type' => $automatedReportResult->getMediaType(),\n 'downloadUrl' => $this->generateReportResultDownloadUrl($automatedReportResult),\n 'viewUrl' => $this->generateReportResultViewUrl($automatedReportResult),\n 'generated_at' => $automatedReportResult->getGeneratedAt()?->toIso8601String(),\n 'creator' => $creator,\n ];\n }\n\n return $data;\n }\n\n public function hasCallTypeConference(AutomatedReport $report): bool\n {\n return in_array(self::CALL_TYPE_CONFERENCE['id'], $report->getCallTypes(), true);\n }\n\n public function hasCallTypeDialer(AutomatedReport $report): bool\n {\n return in_array(self::CALL_TYPE_DIALER['id'], $report->getCallTypes(), true);\n }\n\n // transformers\n private function transformTeam(Team $team): array\n {\n if (! $team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {\n return [];\n }\n\n return [\n 'id' => $team->getUuid(),\n 'name' => $team->getName(),\n ];\n }\n\n private function transformReportFullView(AutomatedReport $report): array\n {\n $base = $this->transformReportBase($report);\n\n return $report->getType() === self::TYPE_ASK_JIMINNY\n ? $base + $this->transformAskJiminnyFields($report)\n : $base + $this->transformStandardReportFields($report);\n }\n\n private function transformReportBase(AutomatedReport $report): array\n {\n return [\n 'id' => $report->getUuid(),\n 'organization' => $this->transformOrganization(team: $report->getTeam()),\n 'report_type' => $this->transformReportType($report->getType()),\n 'frequency' => $this->transformFrequency($report->getFrequency()),\n ];\n }\n\n private function transformStandardReportFields(AutomatedReport $report): array\n {\n $team = $report->getTeam();\n\n return [\n 'report_enabled' => $report->getStatus(),\n 'start_date_period' => $report->getFrom()?->format('Y-m-d H:i:s'),\n 'end_date_period' => $report->getTo()?->format('Y-m-d H:i:s'),\n 'deal_value_min' => $report->getDealValueMin(),\n 'deal_value_max' => $report->getDealValueMax(),\n 'call_types' => $this->transformCallType($report->getCallTypes()),\n 'media_types' => $this->transformMediaTypes($report),\n 'call_duration_min' => $this->transformDurationToMinutes($report->getCallDurationMin()),\n 'call_duration_max' => $this->transformDurationToMinutes($report->getCallDurationMax()),\n 'teams' => $this->transformGroups(team: $team, groupsIds: $report->getGroups()),\n 'deal_at_call_stages' => $this->transformStages(team: $team, stagesIds: $report->getDealAtCallStages()),\n 'current_deal_stages' => $this->transformStages(team: $team, stagesIds: $report->getCurrentDealStages()),\n 'recipients' => $this->transformRecipients($report->getRecipients()),\n 'created_by' => $this->transformCreator($report->getCreator()),\n 'additional_prompt_input' => $report->getAdditionalPromptInput(),\n 'custom_name' => $report->getCustomName(),\n 'created_at' => $report->getCreatedAt()->format('Y-m-d H:i:s'),\n 'updated_at' => $report->getUpdatedAt()->format('Y-m-d H:i:s'),\n 'deleted_at' => $report->getDeletedAt()?->format('Y-m-d H:i:s'),\n ];\n }\n\n private function transformAskJiminnyFields(AutomatedReport $report): array\n {\n $team = $report->getTeam();\n $creatorId = $report->getAttribute('created_by');\n $explicitUserIds = array_values(array_filter(\n $report->getRecipients()['users'] ?? [],\n static fn ($id) => $id !== $creatorId\n ));\n\n return [\n 'report_name' => $report->getCustomName(),\n 'enabled' => $report->getStatus(),\n 'share_teams' => $this->transformGroups(team: $team, groupsIds: $report->getGroups()),\n 'share_users' => $this->transformRecipients(['users' => $explicitUserIds]),\n 'saved_search' => $this->transformSafeSearch($report->getSavedSearch()),\n 'ask_jiminny_prompt' => $this->transformAskJiminnyPrompt($report->getAskAnythingPrompt()),\n 'expires_on' => $report->getExpiresAt()?->format('Y-m-d'),\n ];\n }\n\n private function transformOrganization(?Team $team): array\n {\n return [\n 'id' => $team?->getUuid(),\n 'name' => $team?->getName(),\n ];\n }\n\n private function transformReportType(string $type): array\n {\n foreach (self::ALL_TYPES as $typeItem) {\n if ($typeItem['id'] === $type) {\n return $typeItem;\n }\n }\n\n return [];\n }\n\n private function transformCallType(array $types): array\n {\n $result = [];\n $callTypes = [self::CALL_TYPE_CONFERENCE, self::CALL_TYPE_DIALER];\n\n foreach ($types as $type) {\n foreach ($callTypes as $callTypeItem) {\n if ($callTypeItem['id'] === $type) {\n $result[] = $callTypeItem;\n\n break;\n }\n }\n }\n\n return $result;\n }\n\n private function transformMediaTypes(AutomatedReport $report): array\n {\n $values = [];\n\n foreach ($report->getMediaTypes() as $mediaType) {\n if (! in_array($mediaType, self::MEDIA_TYPES, true)) {\n continue;\n }\n\n $values[] = match ($mediaType) {\n self::MEDIA_TYPE_PDF => self::MEDIA_TYPE_OBJECT_PDF,\n self::MEDIA_TYPE_PODCAST => self::MEDIA_TYPE_OBJECT_PODCAST,\n };\n }\n\n return $values;\n }\n\n private function transformFrequency(string $frequency): array\n {\n foreach (self::ALL_FREQUENCIES as $frequencyItem) {\n if ($frequencyItem['id'] === $frequency) {\n return $frequencyItem;\n }\n }\n\n return [];\n }\n\n public function transformDurationToMinutes(?int $duration): ?int\n {\n if (! $duration) {\n return null;\n }\n\n return (int) ($duration / 60);\n }\n\n private function transformGroups(?Team $team, array $groupsIds): array\n {\n if (empty($groupsIds) || ! $team) {\n return [];\n }\n\n $data = [];\n foreach ($groupsIds as $groupId) {\n $group = $team->groups()->where('id', $groupId)->first();\n\n if ($group) {\n $data[] = [\n 'id' => $group->getUuid(),\n 'name' => $group->getName(),\n 'photoUrl' => $group->getPhotoUrl(),\n ];\n }\n }\n\n return $data;\n }\n\n private function transformStages(?Team $team, array $stagesIds): array\n {\n if (empty($stagesIds) || ! $team) {\n return [];\n }\n\n $data = [];\n foreach ($stagesIds as $stageId) {\n $stage = $team->stages()->where('id', $stageId)->first();\n\n if ($stage) {\n $data[] = [\n 'id' => $stage->getUuid(),\n 'name' => $stage->getName(),\n ];\n }\n }\n\n return $data;\n }\n\n private function transformRecipients(array $recipients): array\n {\n $users = [];\n foreach ($recipients['users'] ?? [] as $userId) {\n $users[] = $this->transformUser($userId);\n }\n\n return $users;\n }\n\n private function transformCreator(?User $user): ?array\n {\n if ($user === null) {\n return null;\n }\n\n return $this->transformUser($user->getId());\n }\n\n private function transformAskJiminnyPrompt(?AskAnythingPrompt $prompt): ?array\n {\n if ($prompt === null) {\n return null;\n }\n\n return [\n 'id' => $prompt->getUuid(),\n 'name' => $prompt->getTitle(),\n ];\n }\n\n private function transformSafeSearch(?Search $search): ?array\n {\n if ($search === null) {\n return null;\n }\n\n return [\n 'id' => $search->getUuid(),\n 'name' => $search->getName(),\n ];\n }\n\n private function transformUser(int $userId): array\n {\n /* @var ?User $user */\n $user = $this->userRepository->find($userId);\n\n return [\n 'id' => $user?->getUuid(),\n 'name' => $user?->getName(),\n 'email' => $user?->getEmailAddress(),\n 'photoUrl' => $user?->getPhotoUrl(),\n ];\n }\n\n public function create(array $data): array\n {\n $validatedData = $this->validateAndTransformData($data);\n $validatedData['created_by'] = auth()->id();\n\n $automatedReport = $this->automatedReportsRepository->create($validatedData);\n\n $this->generateOneOffReport($automatedReport);\n\n return $this->transformReportFullView($automatedReport);\n }\n\n public function update(string $uuid, array $data): array\n {\n $validatedData = $this->validateAndTransformData($data);\n $report = $this->automatedReportsRepository->findByUuid($uuid);\n\n if (! $report) {\n throw new InvalidArgumentException('Report not found');\n }\n\n $oldCustomName = $report->getCustomName();\n\n $automatedReport = $this->automatedReportsRepository->update($report, $validatedData);\n\n if ($oldCustomName !== $automatedReport->getCustomName()) {\n $this->updateResultNames($automatedReport);\n }\n\n $this->generateOneOffReport($automatedReport);\n\n return $this->transformReportFullView($automatedReport);\n }\n\n /**\n * Create an Ask Jiminny report.\n */\n public function createAskJiminnyReport(array $data, User $creator): array\n {\n $validatedData = $this->validateAskJiminnyReportData($data, $creator);\n $validatedData['created_by'] = $creator->getId();\n\n $automatedReport = $this->automatedReportsRepository->create($validatedData);\n\n return $this->transformReportFullView($automatedReport);\n }\n\n /**\n * Update an Ask Jiminny report.\n */\n public function updateAskJiminnyReport(AutomatedReport $report, array $data, User $user): array\n {\n if (! $report->isAskJiminnyReport()) {\n throw new InvalidArgumentException('Report is not an Ask Jiminny report');\n }\n\n $validatedData = $this->validateAskJiminnyReportData($data, $user);\n\n $oldCustomName = $report->getCustomName();\n\n $automatedReport = $this->automatedReportsRepository->update($report, $validatedData);\n\n if ($oldCustomName !== $automatedReport->getCustomName()) {\n $this->updateResultNames($automatedReport);\n }\n\n return $this->transformReportFullView($automatedReport);\n }\n\n public function updateAskJiminnyReportStatus(AutomatedReport $report, bool $status): array\n {\n $this->automatedReportsRepository->update($report, ['status' => $status]);\n\n return $this->transformReportFullView($report->fresh());\n }\n\n /**\n * Validate and transform data for Ask Jiminny reports.\n */\n private function validateAskJiminnyReportData(array $data, User $user): array\n {\n // Validate name\n $name = trim($data['report_name'] ?? '');\n if (empty($name)) {\n throw new InvalidArgumentException('Report name is required');\n }\n if (mb_strlen($name) > 50) {\n throw new InvalidArgumentException('Report name must be 50 characters or less');\n }\n\n // Validate frequency (only daily, weekly, monthly for Ask Jiminny)\n $frequency = $data['frequency'] ?? null;\n $askJiminnyFrequencies = [self::FREQUENCY_DAILY, self::FREQUENCY_WEEKLY, self::FREQUENCY_MONTHLY];\n if (! in_array($frequency, $askJiminnyFrequencies, true)) {\n throw new InvalidArgumentException('Frequency must be daily, weekly, or monthly');\n }\n\n // Validate expiration date\n $expiresAt = $data['expires_on'] ?? null;\n if (empty($expiresAt)) {\n throw new InvalidArgumentException('Expiration date is required');\n }\n\n try {\n $expiresAtDate = Carbon::parse($expiresAt);\n } catch (InvalidFormatException $e) {\n throw new InvalidArgumentException('Expiration date format is invalid');\n }\n $maxExpiration = Carbon::now()->addYear();\n if ($expiresAtDate->gt($maxExpiration)) {\n throw new InvalidArgumentException('Expiration date cannot be more than 1 year from now');\n }\n if ($expiresAtDate->isPast()) {\n throw new InvalidArgumentException('Expiration date cannot be in the past');\n }\n\n // Validate saved search\n $activitySearchId = $data['saved_search'] ?? null;\n if (empty($activitySearchId)) {\n throw new InvalidArgumentException('Saved search is required');\n }\n $savedSearch = $this->activitySearchRepository->findByUuidAndUser($activitySearchId, $user);\n if (! $savedSearch) {\n throw new InvalidArgumentException('Saved search not found or does not belong to you');\n }\n\n // Validate saved prompt\n $askAnythingPromptId = $data['ask_jiminny_prompt'] ?? null;\n if (empty($askAnythingPromptId)) {\n throw new InvalidArgumentException('Ask Jiminny prompt is required');\n }\n $prompt = $this->askAnythingRepository->getPromptByUuid($askAnythingPromptId);\n if (! $prompt) {\n throw new InvalidArgumentException('Ask Jiminny prompt not found');\n }\n\n // Validate status\n $status = $data['enabled'] ?? false;\n\n $recipientUserIds = [$user->getId()];\n\n if (! empty($data['share_users'])) {\n $sharedUserIds = $this->validateAndGetUserIdsByTeam(\n $user->team,\n (array) $data['share_users']\n );\n $recipientUserIds = array_merge($recipientUserIds, $sharedUserIds);\n }\n\n $sharedGroupIds = [];\n if (! empty($data['share_teams'])) {\n $sharedGroupIds = $this->validateAndGetGroupIds($user->team, (array) $data['share_teams']);\n }\n\n $recipientUserIds = array_values(array_unique($recipientUserIds));\n\n return [\n 'team_id' => $user->getTeamId(),\n 'type' => self::TYPE_ASK_JIMINNY,\n 'status' => (bool) $status,\n 'frequency' => $frequency,\n 'custom_name' => $name,\n 'activity_search_id' => $savedSearch->getId(),\n 'ask_anything_prompt_id' => $prompt->getId(),\n 'expires_at' => $expiresAtDate->toDateString(),\n 'media_types' => [self::MEDIA_TYPE_PDF],\n 'call_types' => [],\n 'recipients' => ['users' => $recipientUserIds],\n 'groups' => $sharedGroupIds,\n ];\n }\n\n public static function getAskJiminnyFrequencies(): array\n {\n return array_map(static function ($frequency) {\n return $frequency['id'];\n }, self::ASK_JIMINNY_FREQUENCIES);\n }\n\n public function getAskJiminnyReportFilters(User $user): array\n {\n $savedSearches = $this->activitySearchRepository->findByUserOrderedByName($user)\n ->map(fn (Search $search) => [\n 'id' => $search->getUuid(),\n 'name' => $search->getName(),\n ])\n ->values()->all();\n\n $prompts = collect(\n $this->askAnythingPromptService->get($user, AskAnythingPromptTarget::on_demand)\n )->map(fn (AskAnythingPromptDto $prompt) => [\n 'id' => $prompt->id,\n 'name' => $prompt->title,\n ])->values()->all();\n\n return [\n [\n 'id' => 'prompt',\n 'label' => 'Prompt',\n 'options' => $prompts,\n ],\n [\n 'id' => 'saved_search',\n 'label' => 'Saved Search',\n 'options' => $savedSearches,\n ],\n ];\n }\n\n public function getAskJiminnyReportFormData(User $user, ?AutomatedReport $report = null): array\n {\n $team = $user->getTeam();\n $userTimezone = $user->getTimezone();\n\n $savedSearches = $this->activitySearchRepository->findByUserOrderedByName($user)\n ->map(fn (Search $search) => [\n 'id' => $search->getUuid(),\n 'name' => $search->getName(),\n ])\n ->values()->all();\n\n $prompts = collect(\n $this->askAnythingPromptService->get($user, AskAnythingPromptTarget::on_demand)\n )->map(fn (AskAnythingPromptDto $prompt) => [\n 'id' => $prompt->id,\n 'name' => $prompt->title,\n ])->values()->all();\n\n $teamGroups = $this->groupRepository->getAllByTeam($team)->map(fn ($group) => [\n 'id' => $group->getUuid(),\n 'name' => $group->getName(),\n ])->values()->all();\n\n $shareUsers = $this->recipientsService->getRecipientsFieldData(team: $team)['options'] ?? [];\n\n $sharedTeamsValue = [];\n $sharedUsersValue = [];\n if ($report) {\n $sharedTeamsValue = $this->transformGroups($team, $report->getGroups());\n\n $recipientUserIds = $report->getRecipients()['users'] ?? [];\n $creatorId = $report->getAttribute('created_by');\n $sharedUserIds = array_values(array_filter(\n $recipientUserIds,\n static fn ($id) => $id !== $creatorId\n ));\n $sharedUsersValue = collect($sharedUserIds)\n ->map(fn ($id) => $this->userRepository->find((int) $id))\n ->filter()\n ->map(fn (User $u) => [\n 'id' => $u->getUuid(),\n 'name' => $u->getName(),\n ])\n ->values()\n ->all();\n }\n\n return [\n 'fields' => [\n [\n 'id' => 'enabled',\n 'inputType' => InputTypeEnum::TOGGLE,\n 'label' => '',\n 'value' => $report?->getStatus() ?? false,\n ],\n [\n 'id' => 'report_name',\n 'inputType' => InputTypeEnum::TEXT,\n 'label' => 'Name',\n 'placeholder' => 'Enter name',\n 'required' => true,\n 'validation' => ['maxLength' => 50],\n 'value' => $report?->getCustomName() ?? '',\n ],\n [\n 'id' => 'frequency',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'label' => 'Frequency',\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => self::ASK_JIMINNY_FREQUENCIES,\n 'value' => $report ? $this->transformFrequency($report->getFrequency()) : null,\n ],\n [\n 'id' => 'expires_on',\n 'inputType' => InputTypeEnum::DATE,\n 'label' => 'Expires on',\n 'required' => true,\n 'placeholder' => 'Select',\n 'validation' => [\n 'minDate' => now($userTimezone)->toDateString(),\n 'maxDate' => now($userTimezone)->addYear()->toDateString(),\n ],\n 'value' => $report?->getExpiresAt()?->toDateString(),\n ],\n [\n 'id' => 'share_teams',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'label' => 'Team',\n 'required' => false,\n 'placeholder' => 'Select',\n 'options' => $teamGroups,\n 'value' => $sharedTeamsValue,\n ],\n [\n 'id' => 'share_users',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'label' => 'Team member',\n 'required' => false,\n 'placeholder' => 'Select',\n 'groupLabelKey' => 'label',\n 'groupValuesKey' => 'users',\n 'optionLabelKey' => 'name',\n 'optionValueKey' => 'id',\n 'options' => $shareUsers,\n 'value' => $sharedUsersValue,\n ],\n [\n 'id' => 'saved_search',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'label' => 'Saved search',\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => $savedSearches,\n 'value' => $report && $report->getSavedSearch() ? [\n 'id' => $report->getSavedSearch()->getUuid(),\n 'name' => $report->getSavedSearch()->getName(),\n ] : null,\n ],\n [\n 'id' => 'ask_jiminny_prompt',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'label' => 'Ask Jiminny prompt',\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => $prompts,\n 'value' => $report && $report->getAskAnythingPrompt() ? [\n 'id' => $report->getAskAnythingPrompt()->getUuid(),\n 'name' => $report->getAskAnythingPrompt()->getTitle(),\n ] : null,\n ],\n ],\n ];\n }\n\n private function updateResultNames(AutomatedReport $automatedReport): void\n {\n $results = $this->automatedReportsRepository->getResultsByReport($automatedReport);\n\n foreach ($results as $result) {\n $result->update(['name' => $this->getReportFileName($result)]);\n }\n }\n\n public function updateStatus(string $uuid, array $data): array\n {\n $automatedReport = $this->automatedReportsRepository->findByUuid($uuid);\n\n if (! $automatedReport) {\n throw new ModelNotFoundException('Report not found');\n }\n\n $status = $this->validateReportStatus($data['report_enabled'] ?? null);\n $automatedReport->update([\n 'status' => $status,\n ]);\n\n $this->generateOneOffReport($automatedReport);\n\n return $this->transformReportFullView($automatedReport);\n }\n\n private function generateOneOffReport(AutomatedReport $automatedReport): void\n {\n // the scheduler handles all the other frequency types\n if ($automatedReport->getStatus() === false || $automatedReport->getFrequency() !== self::FREQUENCY_ONE_OFF) {\n return;\n }\n\n $this->dispatcher->dispatch(new RequestGenerateReportJob($automatedReport->getUuid()));\n }\n\n public function getReport(string $uuid): AutomatedReport\n {\n $automatedReport = $this->automatedReportsRepository->findByUuid($uuid);\n\n if (! $automatedReport) {\n throw new ModelNotFoundException('Report not found');\n }\n\n return $automatedReport;\n }\n\n public function get(string $uuid): array\n {\n $automatedReport = $this->getReport($uuid);\n\n return $this->transformReportFullView($automatedReport);\n }\n\n public function list(string $sortColumn = 'created_at', string $sortDirection = 'desc'): array\n {\n $results = [];\n $collection = $this->automatedReportsRepository->getAllStandardReports($sortColumn, $sortDirection);\n\n /** @var AutomatedReport $report */\n foreach ($collection as $report) {\n $results[] = $this->transformReportFullView($report);\n }\n\n return ['data' => $results];\n }\n\n public function listAskJiminnyReports(\n User $user,\n string $sortColumn = 'created_at',\n string $sortDirection = 'desc'\n ): array {\n $results = [];\n $collection = $this->automatedReportsRepository->getAskJiminnyReportsByUser($user, $sortColumn, $sortDirection);\n\n /** @var AutomatedReport $report */\n foreach ($collection as $report) {\n $results[] = $this->transformReportFullView($report);\n }\n\n return ['data' => $results];\n }\n\n public function delete(string $uuid): void\n {\n $automatedReport = $this->automatedReportsRepository->findByUuid($uuid);\n\n if (! $automatedReport) {\n throw new ModelNotFoundException('Report not found');\n }\n\n $automatedReport->delete();\n }\n\n public function createReportResult(AutomatedReport $automatedReport, array $data = []): AutomatedReportResult\n {\n return $this->automatedReportsRepository->createResult(\n array_merge(\n [\n 'report_id' => $automatedReport->getId(),\n 'status' => AutomatedReportResult::STATUS_DEFAULT,\n ],\n $data\n )\n );\n }\n\n public function getReportResult(string $resultUuid): AutomatedReportResult\n {\n $report = $this->automatedReportsRepository->findResultByUuid($resultUuid);\n\n if (! $report) {\n throw new ModelNotFoundException('Report Result not found');\n }\n\n return $report;\n }\n\n public function findChildResult(AutomatedReportResult $result, string $type): ?AutomatedReportResult\n {\n return $this->automatedReportsRepository->findChildResult($result, $type);\n }\n\n // prophet API calls\n /**\n * @throws ApplicationException\n */\n public function getGenerateReportPayload(AutomatedReport $automatedReport, string $reportResultUuid): array\n {\n $period = $this->calculateFromAndToDate($automatedReport);\n $fromDate = $period['fromDate'];\n $toDate = $period['toDate'];\n\n return [\n 'team_id' => $automatedReport->getTeamId(),\n 'request_id' => $reportResultUuid,\n 'report_type' => $automatedReport->getType(),\n 'media_types' => $automatedReport->getMediaTypes(),\n 'from_date' => $fromDate->startOfDay()->format(DateTimeInterface::RFC3339),\n 'to_date' => $toDate->endOfDay()->format(DateTimeInterface::RFC3339),\n 'group_ids' => $automatedReport->getGroups(),\n 'call_deal_stage' => $automatedReport->getDealAtCallStages(),\n 'current_deal_stage' => $automatedReport->getCurrentDealStages(),\n 'deal_min_value' => $automatedReport->getDealValueMin(),\n 'deal_max_value' => $automatedReport->getDealValueMax(),\n 'call_types' => $automatedReport->getCallTypes(),\n 'call_duration_min_seconds' => $automatedReport->getCallDurationMin(),\n 'call_duration_max_seconds' => $automatedReport->getCallDurationMax(),\n 'special_requirements' => $automatedReport->getAdditionalPromptInput(),\n 'callback_url' => $this->getCallbackUrl(),\n 'report_period' => $this->formatReportPeriodName(\n $automatedReport->getFrequency(),\n $fromDate,\n $toDate,\n ),\n 'playbook_categories' => $automatedReport->getPlaybookCategories(),\n 'custom_name' => $automatedReport->getCustomName(),\n ];\n }\n\n // $inputPayload - FE payload structure\n public function getActivitiesCountPayload(array $inputPayload): array\n {\n // Use validateAndTransformData to validate and normalize input\n $validatedData = $this->validateAndTransformData($inputPayload);\n $period = $this->calculateFromAndToDatePeriod(\n $validatedData['frequency'],\n Carbon::parse($validatedData['from']),\n Carbon::parse($validatedData['to']),\n );\n $fromDate = $period['fromDate'];\n $toDate = $period['toDate'];\n\n // Create payload similar to getGenerateReportPayload\n return [\n 'team_id' => $validatedData['team_id'],\n 'group_ids' => $validatedData['groups'] ?? [],\n 'report_type' => $validatedData['type'],\n 'from_date' => $fromDate->format(DateTimeInterface::RFC3339),\n 'to_date' => $toDate->format(DateTimeInterface::RFC3339),\n 'call_deal_stage' => $validatedData['deal_at_call_stages'] ?? [],\n 'current_deal_stage' => $validatedData['current_deal_stages'] ?? [],\n 'deal_min_value' => $validatedData['deal_value_min'] ?? null,\n 'deal_max_value' => $validatedData['deal_value_max'] ?? null,\n 'call_types' => $validatedData['call_types'],\n 'call_duration_min_seconds' => $validatedData['call_duration_min'] ?? null,\n 'call_duration_max_seconds' => $validatedData['call_duration_max'] ?? null,\n 'special_requirements' => $validatedData['additional_prompt_input'] ?? null,\n 'playbook_categories' => $validatedData['playbook_categories'] ?? [],\n 'request_id' => null,\n 'callback_url' => null,\n ];\n }\n\n public function shouldSendReport(array $users, ?CarbonInterface $generatedAt = null): bool\n {\n if (empty($users)) {\n return false;\n }\n\n $earliestTz = collect($users)\n ->mapWithKeys(function (array $user) {\n $tz = new DateTimeZone($user['timezone']);\n $nowUtc = new DateTime('now', new DateTimeZone('UTC'));\n $offset = $tz->getOffset($nowUtc);\n\n return [$user['timezone'] => $offset];\n })\n ->sortDesc()\n ->keys()\n ->first();\n\n $now = Carbon::now($earliestTz);\n $isScheduledTime = (int) $now->format('H') === self::SENT_REPORT_AT_HOURS;\n\n if ($isScheduledTime) {\n return true;\n }\n\n return $this->hasPassedScheduledTime($generatedAt, $earliestTz);\n }\n\n public function hasPassedScheduledTime(?CarbonInterface $generatedAt, string $timezone): bool\n {\n if ($generatedAt === null) {\n return false;\n }\n\n $now = Carbon::now($timezone);\n $scheduledTime = $now->copy()->setTime(self::SENT_REPORT_AT_HOURS, 0, 0);\n\n if ($now->hour < self::SENT_REPORT_AT_HOURS) {\n $scheduledTime = $scheduledTime->subDay();\n }\n\n $scheduledTimeUtc = $scheduledTime->copy()->utc();\n $generatedAtUtc = $generatedAt->copy()->utc();\n $nowUtc = $now->copy()->utc();\n\n return $generatedAtUtc->lt($scheduledTimeUtc) && $nowUtc->gt($scheduledTimeUtc);\n }\n\n public function calculateFromAndToDatePeriod(\n string $frequency,\n ?Carbon $fromDate = null,\n ?Carbon $toDate = null\n ): array {\n if ($frequency === self::FREQUENCY_ONE_OFF) {\n return [\n 'fromDate' => $fromDate,\n 'toDate' => $toDate,\n ];\n }\n\n $now = Carbon::now();\n\n return match ($frequency) {\n self::FREQUENCY_DAILY => [\n 'fromDate' => $now->copy()->subDay()->startOfDay(),\n 'toDate' => $now->copy()->subDay()->endOfDay(),\n ],\n self::FREQUENCY_WEEKLY => [\n 'fromDate' => $now->copy()->subWeeks(1)->startOfDay(),\n 'toDate' => $now->copy()->subDay()->endOfDay(),\n ],\n self::FREQUENCY_MONTHLY => [\n 'fromDate' => $now->copy()->subMonths(1)->startOfDay(),\n 'toDate' => $now->copy()->subDay()->endOfDay(),\n ],\n self::FREQUENCY_QUARTERLY => [\n 'fromDate' => $now->copy()->subMonths(3)->startOfDay(),\n 'toDate' => $now->copy()->subDay()->endOfDay(),\n ],\n default => throw new InvalidArgumentException(\"Unsupported frequency: {$frequency}\"),\n };\n }\n\n private function calculateFromAndToDate(AutomatedReport $automatedReport): array\n {\n return $this->calculateFromAndToDatePeriod(\n $automatedReport->getFrequency(),\n $automatedReport->getFrom(),\n $automatedReport->getTo()\n );\n }\n\n public function getAskJiminnyGenerateReportPayload(\n AutomatedReport $automatedReport,\n AutomatedReportResult $reportResult,\n array $activityIds,\n ): array {\n return [\n 'user_question' => $automatedReport->getAskAnythingPrompt()?->getContent(),\n 'call_ids' => array_map('strval', $activityIds),\n 'team_id' => $automatedReport->getTeamId(),\n 'request_id' => $reportResult->getUuid(),\n 'callback_url' => $this->getCallbackUrl(),\n 'report_period' => $this->getReportPeriodName($reportResult),\n 'report_name' => $automatedReport->getCustomName(),\n ];\n }\n\n private function getCallbackUrl(): string\n {\n return $this->webhookService->route('jiminny.webhook.reports.ready');\n }\n\n /**\n * Validate and transform payload data for automated reports\n *\n * @param array $data\n *\n * @throws InvalidArgumentException\n *\n * @return array\n */\n private function validateAndTransformData(array $data): array\n {\n // Validate organization (team) and check feature\n $team = $this->validateOrganization($data['organization'] ?? null);\n\n $status = $this->validateReportStatus($data['report_enabled'] ?? null);\n $type = $this->validateReportType($data['report_type'] ?? null);\n $frequency = $this->validateFrequency($data['frequency'] ?? null);\n $additionalPromptInput = $this->validateAdditionalPromptInput(\n $data['additional_prompt_input'] ?? null\n );\n $customReportName = $this->validateCustomReportName($data['custom_name'] ?? null);\n\n // Prepare data for the database\n $reportData = [\n 'team_id' => $team->getId(),\n 'type' => $type,\n 'status' => $status,\n 'frequency' => $frequency,\n 'additional_prompt_input' => $additionalPromptInput,\n 'custom_name' => $customReportName,\n ];\n\n // Validate deal values\n $reportData = $this->validateDealValues($data, $reportData);\n\n // Validate date range\n $reportData = $this->validateDateRange($data, $reportData, $frequency);\n\n // Validate call durations\n $reportData = $this->validateCallDurations($data, $reportData);\n\n // Validate call types\n $reportData = $this->validateCallTypes($data, $reportData);\n\n // Validate media types\n $reportData = $this->validateMediaTypes($data, $reportData);\n\n // Validate groups\n if (isset($data['teams'])) {\n $reportData['groups'] = $this->validateAndGetGroupIds($team, $data['teams']);\n }\n\n // Validate deal stages\n $reportData = $this->validateDealStages($data, $reportData, $team, $type);\n\n // Validate playbook categories\n $reportData = $this->validatePlaybookCategories($data, $reportData, $team);\n\n // Validate recipients\n $reportData['recipients'] = [\n 'users' => $this->validateAndGetUserIdsByTeam($team, $data['recipients'] ?? []),\n ];\n\n if (isset($data['jiminny_recipients'])) {\n // Validate Jiminny recipients\n $reportData['jiminny_recipients'] = [\n 'users' => $this->validateAndGetJiminnyUserIds((array) $data['jiminny_recipients']),\n ];\n }\n\n return $reportData;\n }\n\n private function validateDealValues(array $data, array $reportData): array\n {\n if (isset($data['min_deal_value'])) {\n $reportData['deal_value_min'] = (int) $data['min_deal_value'];\n\n if ($reportData['deal_value_min'] > 4294967295 || $reportData['deal_value_min'] < 0) {\n throw new InvalidArgumentException('Min deal value should be between 0 and 4294967295');\n }\n }\n\n if (isset($data['max_deal_value'])) {\n $reportData['deal_value_max'] = (int) $data['max_deal_value'];\n\n if ($reportData['deal_value_max'] > 4294967295 || $reportData['deal_value_max'] < 0) {\n throw new InvalidArgumentException('Max deal value should be between 0 and 4294967295');\n }\n }\n\n if (isset($data['min_deal_value'], $data['max_deal_value'])\n && $data['min_deal_value'] > $data['max_deal_value']\n ) {\n throw new InvalidArgumentException('Min deal value cannot be greater than max deal value');\n }\n\n return $reportData;\n }\n\n private function validateDateRange(array $data, array $reportData, string $frequency): array\n {\n // Set date range only for one_off frequency\n if ($frequency === 'one_off') {\n if (isset($data['start_date_period'])) {\n $reportData['from'] = $this->parseDate($data['start_date_period']);\n }\n\n if (isset($data['end_date_period'])) {\n $reportData['to'] = $this->parseDate($data['end_date_period']);\n }\n\n if (empty($reportData['from']) || empty($reportData['to'])) {\n throw new InvalidArgumentException(\n 'Start date and end date are required for one_off frequency'\n );\n }\n } else {\n $reportData['from'] = null;\n $reportData['to'] = null;\n }\n\n return $reportData;\n }\n\n private function validateCallDurations(array $data, array $reportData): array\n {\n // Convert call durations from minutes to seconds\n if (isset($data['min_call_duration'])) {\n $reportData['call_duration_min'] = (int) $data['min_call_duration'] * 60;\n\n if ($reportData['call_duration_min'] > 4294967295 || $reportData['call_duration_min'] < 0) {\n throw new InvalidArgumentException('Min call duration should be between 0 and 4294967295');\n }\n }\n\n if (isset($data['max_call_duration'])) {\n $reportData['call_duration_max'] = (int) $data['max_call_duration'] * 60;\n\n if ($reportData['call_duration_max'] > 4294967295 || $reportData['call_duration_max'] < 0) {\n throw new InvalidArgumentException('Max call duration should be between 0 and 4294967295');\n }\n }\n\n return $reportData;\n }\n\n private function validateCallTypes(array $data, array $reportData): array\n {\n // Set call types\n $reportData['call_types'] = $data['call_type'] ?? [];\n if (empty($reportData['call_types'])) {\n $reportData['call_types'] = self::getCallTypes();\n }\n\n foreach ($reportData['call_types'] as $callType) {\n if (! in_array($callType, self::getCallTypes(), true)) {\n throw new InvalidArgumentException(sprintf('Call type %s is invalid', $callType));\n }\n }\n\n return $reportData;\n }\n\n private function validateMediaTypes(array $data, array $reportData): array\n {\n // Set media types from input data\n $reportData['media_types'] = $data['media_types'] ?? [];\n\n if (empty($reportData['media_types'])) {\n throw new InvalidArgumentException('Media types are required');\n }\n\n foreach ($reportData['media_types'] as $mediaType) {\n if (! in_array($mediaType, self::MEDIA_TYPES, true)) {\n throw new InvalidArgumentException(sprintf('Media type %s is invalid', $mediaType));\n }\n }\n\n return $reportData;\n }\n\n private function validateDealStages(array $data, array $reportData, Team $team, string $reportType): array\n {\n // Validate and set deal stages\n if (isset($data['deal_stage_at_call'])) {\n $reportData['deal_at_call_stages'] =\n $this->validateAndGetDealStageIds($team, $data['deal_stage_at_call'], 'Deal stage at call');\n }\n\n if (isset($data['current_deal_stage'])) {\n $reportData['current_deal_stages'] =\n $this->validateAndGetDealStageIds($team, $data['current_deal_stage'], 'Current deal stage');\n }\n\n // Ensure current_deal_stage is not provided for loss_analysis report type\n if ($reportType === self::TYPE_LOSS_ANALYSIS && ! empty($data['current_deal_stage'])) {\n throw new InvalidArgumentException('Current deal stage is not applicable for Loss Analysis reports');\n }\n\n return $reportData;\n }\n\n // transform uuid to id\n private function validatePlaybookCategories(array $data, array $reportData, Team $team): array\n {\n $key = 'playbook_categories';\n\n if (isset($data[$key])) {\n $payloadIds = $data[$key];\n $ids = [];\n\n foreach ($payloadIds as $uuid) {\n $uuid = (string) $uuid;\n\n try {\n $playbookCategory = $this->playbookCategoryRepository->findByUuid($uuid);\n } catch (Throwable $throwable) {\n Log::error(__METHOD__ . ' ' . $throwable->getMessage());\n\n throw new InvalidArgumentException(sprintf('Playbook category %s not found', $uuid));\n }\n\n if (! $playbookCategory) {\n throw new InvalidArgumentException(sprintf('Playbook category %s not found', $uuid));\n }\n\n if (! $playbookCategory->hasPlaybook()) {\n throw new InvalidArgumentException(sprintf('Playbook category %s has no playbook', $uuid));\n }\n\n if ($playbookCategory->getPlaybook()->getTeamId() !== $team->getId()) {\n throw new InvalidArgumentException(\n sprintf('Playbook category %s not found for team %s', $uuid, $team->getUuid())\n );\n }\n\n $ids[] = $playbookCategory->getId();\n }\n\n $reportData[$key] = $ids;\n }\n\n return $reportData;\n }\n\n private function validateReportStatus($status): bool\n {\n if (! in_array($status, [true, false], true)) {\n throw new InvalidArgumentException('Report status is invalid');\n }\n\n return $status;\n }\n\n private function validateReportType($type): string\n {\n if (! in_array($type, self::getTypes(), true)) {\n throw new InvalidArgumentException(sprintf('Report type is invalid: %s', $type));\n }\n\n return $type;\n }\n\n private function validateFrequency($frequency): string\n {\n if (! in_array($frequency, self::getFrequencies(), true)) {\n throw new InvalidArgumentException('Frequency is invalid');\n }\n\n return $frequency;\n }\n\n private function validateAdditionalPromptInput(?string $additionalPromptInput): ?string\n {\n if ($additionalPromptInput && strlen($additionalPromptInput) > 5000) {\n throw new InvalidArgumentException('Additional Prompt Input should be less than 5000 characters');\n }\n\n return $additionalPromptInput;\n }\n\n private function validateCustomReportName(?string $customReportName): ?string\n {\n if ($customReportName === null || $customReportName === '') {\n return null;\n }\n\n if (strlen($customReportName) > 70) {\n throw new InvalidArgumentException('Custom report name should be less than 70 characters');\n }\n\n return $customReportName;\n }\n\n private function validateOrganization(?string $organizationUuid): Team\n {\n if (! $organizationUuid) {\n throw new InvalidArgumentException('Organization is required');\n }\n\n $team = $this->teamRepository->idOrUuid($organizationUuid);\n\n if (! $team) {\n throw new InvalidArgumentException('Organization not found');\n }\n\n if (! $team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {\n throw new InvalidArgumentException('Organization does not have the Automated Reports feature');\n }\n\n return $team;\n }\n\n private function validateAndGetGroupIds(Team $team, array $teamUuids): array\n {\n $groupIds = [];\n\n foreach ($teamUuids as $uuid) {\n $group = $this->groupRepository->findByUuid($uuid);\n\n if ($group === null || $group->getTeamId() !== $team->getId()) {\n throw new InvalidArgumentException(\n sprintf('Group %s not found for team %s', $uuid, $team->getUuid())\n );\n }\n\n $groupIds[] = $group->getId();\n\n }\n\n return $groupIds;\n }\n\n private function validateAndGetDealStageIds(Team $team, array $stageUuids, string $propertyLabel): array\n {\n $stageIds = [];\n\n foreach ($stageUuids as $uuid) {\n $stage = $this->stageRepository->findByUuid($uuid);\n\n if ($stage === null || $stage->getTeamId() !== $team->getId()) {\n throw new InvalidArgumentException(\n sprintf('Stage %s not found for team %s for %s', $uuid, $team->getUuid(), $propertyLabel)\n );\n }\n\n $stageIds[] = $stage->getId();\n }\n\n return $stageIds;\n }\n\n private function validateAndGetUserIds(array $userUuids, callable $teamCheck): array\n {\n if (empty($userUuids)) {\n return [];\n }\n\n $userIds = [];\n\n foreach ($userUuids as $uuid) {\n $user = $this->userRepository->findByUuid($uuid);\n\n if (! $user || ! $user->isStatusActive()) {\n throw new InvalidArgumentException(\n sprintf('User %s not found or is not active', $uuid)\n );\n }\n\n if (! $teamCheck($user)) {\n throw new InvalidArgumentException(\n sprintf('User %s does not belong to the allowed team(s)', $uuid)\n );\n }\n\n $userIds[] = $user->getId();\n }\n\n return $userIds;\n }\n\n private function validateAndGetUserIdsByTeam(Team $team, array $userUuids): array\n {\n return $this->validateAndGetUserIds($userUuids, fn ($user) => $user->getTeamId() === $team->getId());\n }\n\n private function validateAndGetJiminnyUserIds(array $userUuids): array\n {\n $allowedTeamIds = config('kiosk.teamIds', []);\n\n return $this->validateAndGetUserIds($userUuids, fn ($user) => in_array($user->getTeamId(), $allowedTeamIds, true));\n }\n\n private function parseDate(string $dateString): string\n {\n return date('Y-m-d H:i:s', strtotime($dateString));\n }\n\n private function generateReportResultViewUrl(AutomatedReportResult $result): string\n {\n $mediaResource = $this->getReportMediaRouteResource($result);\n\n return route('ai-reports.' . $mediaResource . '.view', ['uuid' => $result->getUuid()]);\n }\n\n private function generateReportResultDownloadUrl(AutomatedReportResult $result): string\n {\n $mediaResource = $this->getReportMediaRouteResource($result);\n\n return route('ai-reports.' . $mediaResource . '.download', ['uuid' => $result->getUuid()]);\n }\n\n private function getReportMediaRouteResource(AutomatedReportResult $result): string\n {\n if ($result->getMediaType() === self::MEDIA_TYPE_PDF) {\n return self::PDF_KEY;\n } elseif ($result->getMediaType() === self::MEDIA_TYPE_PODCAST) {\n return self::AUDIO_KEY;\n }\n\n throw new \\InvalidArgumentException('Unknown media type.');\n }\n\n public function getMediaPath(AutomatedReportResult $result): ?string\n {\n $url = match ($result->getMediaType()) {\n self::MEDIA_TYPE_PDF => $result->getPdfUrl(),\n self::MEDIA_TYPE_PODCAST => $result->getPodcastAudioUrl(),\n default => null,\n };\n\n if ($url === null) {\n return null;\n }\n\n $path = parse_url(trim($url, '\"\\''), PHP_URL_PATH);\n\n return $path ?: null;\n }\n\n public function getFilenameSuffix(AutomatedReportResult $result): ?string\n {\n return match ($result->getMediaType()) {\n self::MEDIA_TYPE_PODCAST => 'Podcast',\n default => null,\n };\n }\n\n public function getMailSubjectSuffix(AutomatedReportResult $result): string\n {\n return match ($result->getMediaType()) {\n self::MEDIA_TYPE_PDF => 'report',\n self::MEDIA_TYPE_PODCAST => 'podcast',\n default => '',\n };\n }\n\n public function getMediaTypeMetadata(AutomatedReportResult $result): array\n {\n return match ($result->getMediaType()) {\n self::MEDIA_TYPE_PODCAST => ['extension' => 'mp3', 'mime' => 'audio/mpeg'],\n self::MEDIA_TYPE_PDF => ['extension' => 'pdf', 'mime' => 'application/pdf'],\n default => ['extension' => null, 'mime' => null],\n };\n }\n\n public function deleteS3Files(AutomatedReportResult $result): void\n {\n $teamUuid = $result->getReport()->getTeam()->getUuid();\n $reportUuid = $result->getUuid();\n\n // delete all files for a report uuid no mather of pdf, podcast, or both\n // in case of both - the podcast files are linked to the pdf (parent) uuid\n // pdf and podcast date times should be close\n $path = sprintf('%s/%s/%s', $teamUuid, self::S3_DIR, $reportUuid);\n\n foreach (self::FILE_EXTENSIONS_VARIANTS as $extension) {\n $file = $path . '.' . $extension;\n\n if (Storage::exists($file)) {\n Storage::delete($file);\n Log::info('[Reports] Deleted S3 file', [\n 'path' => $file,\n ]);\n }\n }\n\n foreach (self::FILE_PODCAST_EXTENSIONS_VARIANTS as $extension) {\n $file = $path . '_podcast.' . $extension;\n\n if (Storage::exists($file)) {\n Storage::delete($file);\n Log::info('[Reports] Deleted Podcast S3 file', [\n 'path' => $file,\n ]);\n }\n }\n }\n\n /**\n *\n * @param int|null $teamId Optional team ID to filter results\n *\n * @return Collection<int, int> Collection of team IDs\n */\n public function getTeamIdsWithReportsResults(?int $teamId = null): Collection\n {\n return $this->automatedReportsRepository->getTeamIdsWithReportsResults($teamId);\n }\n\n /**\n * Core delete logic for report results using a query\n *\n * @param Builder $query\n * @param array $logContext\n *\n * @return int\n */\n private function deleteReportResultsByQuery(Builder $query, array $logContext = []): int\n {\n $deletedCount = 0;\n\n if ($query->exists()) {\n Log::info(\n 'Run delete report results',\n array_merge(\n $logContext,\n [\n 'service' => 'AutomatedReportsService',\n ]\n )\n );\n\n $query->chunkById(50, function ($results) use (&$deletedCount, $logContext) {\n foreach ($results as $result) {\n $this->deleteReportResult($result);\n $deletedCount++;\n\n Log::info(\n 'Deleted a report result',\n array_merge(\n $logContext,\n [\n 'result_id' => $result->getId(),\n 'report_id' => $result->getReportId(),\n ]\n )\n );\n }\n });\n }\n\n return $deletedCount;\n }\n\n /**\n * Delete report results for a team by retention period\n *\n * @param Team $team\n * @param CarbonImmutable $retentionDate\n *\n * @return int Number of deleted report results\n */\n public function deleteReportsResultsInRetentionPeriod(Team $team, CarbonImmutable $retentionDate): int\n {\n $reportIds = $this->automatedReportsRepository->getReportIdsByTeam($team);\n\n if ($reportIds->isEmpty()) {\n return 0;\n }\n\n $query = $this->automatedReportsRepository\n ->getReportResultsQueryForRetention($team, $retentionDate);\n\n return $this->deleteReportResultsByQuery($query, [\n 'team_id' => $team->getId(),\n 'retention_date' => $retentionDate->toDateTimeString(),\n ]);\n }\n\n /**\n * Delete ALL report results for a specific automated report\n *\n * @param string $uuid\n *\n * @return int\n */\n public function deleteReportResults(string $uuid): int\n {\n $report = $this->getReport($uuid);\n\n $query = $this->automatedReportsRepository->getResultsByReportQuery($report);\n\n return $this->deleteReportResultsByQuery($query, [\n 'report_uuid' => $uuid,\n 'report_id' => $report->getId(),\n ]);\n }\n\n public function deleteReportResult(AutomatedReportResult $result): void\n {\n $this->deleteS3Files($result);\n\n $result->delete();\n }\n\n /**\n * Get all reports for a specific team\n *\n * @param Team $team\n *\n * @return \\Illuminate\\Database\\Eloquent\\Collection\n */\n public function getTeamReports(Team $team): \\Illuminate\\Database\\Eloquent\\Collection\n {\n return $this->automatedReportsRepository->getReportsByTeam($team);\n }\n\n /**\n * Get all report results for a specific report\n *\n * @param AutomatedReport $report\n *\n * @return \\Illuminate\\Database\\Eloquent\\Collection\n */\n public function getReportResults(AutomatedReport $report): \\Illuminate\\Database\\Eloquent\\Collection\n {\n return $this->automatedReportsRepository->getResultsByReport($report);\n }\n\n public function deleteAllReportResults(AutomatedReport $report): void\n {\n $results = $this->getReportResults($report);\n\n /** @var AutomatedReportResult $result */\n foreach ($results as $result) {\n Log::info('Deleting result', [\n 'report' => $report->getId(),\n 'result' => $result->getId(),\n ]);\n\n $this->deleteReportResult($result);\n }\n }\n\n public function deleteAllData(Team $team): void\n {\n Log::info('Deleting automated report and results for team', [\n 'team' => $team->getId(),\n ]);\n\n $reports = $this->getTeamReports($team);\n\n /** @var AutomatedReport $report */\n foreach ($reports as $report) {\n Log::info('Deleting report', [\n 'team' => $team->getId(),\n 'report' => $report->getId(),\n ]);\n\n $this->deleteAllReportResults($report);\n\n $report->delete();\n }\n }\n}","depth":4,"value":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Services\\Kiosk\\AutomatedReports;\n\nuse Carbon\\CarbonImmutable;\nuse Carbon\\CarbonInterface;\nuse Carbon\\Exceptions\\InvalidFormatException;\nuse DateTime;\nuse DateTimeInterface;\nuse DateTimeZone;\nuse Illuminate\\Contracts\\Bus\\Dispatcher as BusDispatcher;\nuse Illuminate\\Database\\Eloquent\\Builder;\nuse Illuminate\\Support\\Carbon;\nuse Illuminate\\Support\\Collection;\nuse Illuminate\\Support\\Facades\\Log;\nuse Illuminate\\Support\\Facades\\Storage;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinition\\InputTypeEnum;\nuse Jiminny\\Component\\AskAnything\\AskAnythingPromptService;\nuse Jiminny\\Component\\AskAnything\\Dtos\\AskAnythingPromptDto;\nuse Jiminny\\Component\\UrlGenerator\\Webhook;\nuse Jiminny\\Contracts\\Repositories\\PlaybookCategoryRepository;\nuse Jiminny\\Contracts\\Repositories\\TeamRepository;\nuse Jiminny\\Contracts\\Repositories\\UserRepository;\nuse Jiminny\\Exceptions\\ApplicationException;\nuse Jiminny\\Exceptions\\InvalidArgumentException;\nuse Jiminny\\Exceptions\\ModelNotFoundException;\nuse Jiminny\\Jobs\\AutomatedReports\\RequestGenerateReportJob;\nuse Jiminny\\Models\\Activity\\Search;\nuse Jiminny\\Models\\AskAnything\\AskAnythingPrompt;\nuse Jiminny\\Models\\AskAnything\\AskAnythingPromptTarget;\nuse Jiminny\\Models\\AutomatedReport;\nuse Jiminny\\Models\\AutomatedReportResult;\nuse Jiminny\\Models\\Contracts\\UserContract;\nuse Jiminny\\Models\\Feature\\FeatureEnum;\nuse Jiminny\\Models\\Team;\nuse Jiminny\\Models\\User;\nuse Jiminny\\Repositories\\AskAnythingRepository;\nuse Jiminny\\Repositories\\AutomatedReportsRepository;\nuse Jiminny\\Repositories\\GroupRepository;\nuse Jiminny\\Repositories\\SearchRepository;\nuse Jiminny\\Repositories\\StageRepository;\nuse Throwable;\n\nclass AutomatedReportsService\n{\n public const string TYPE_LOSS_ANALYSIS = 'loss_analysis';\n public const string TYPE_ASK_JIMINNY = 'ask_jiminny';\n\n /**\n * Standard report types (used by kiosk for existing automated reports).\n */\n // @TODO this will add filter, however if we need to control feature by FF we need conditional logic\n public const array TYPES = [\n ['id' => 'exec_summary', 'name' => 'Exec Summary'],\n ['id' => 'coaching_profiles', 'name' => 'Coaching Profiles'],\n ['id' => 'product_feedback', 'name' => 'Product Feedback'],\n ['id' => self::TYPE_LOSS_ANALYSIS, 'name' => 'Loss Analysis'],\n// ['id' => 'questions', 'name' => 'Questions'],\n// ['id' => 'statistical_quant', 'name' => 'Statistical Quantitative'],\n ];\n\n public const array ALL_TYPES = [\n ...self::TYPES,\n ['id' => self::TYPE_ASK_JIMINNY, 'name' => 'Ask Jiminny'],\n ];\n\n public const string FREQUENCY_DAILY = 'daily';\n public const string FREQUENCY_WEEKLY = 'weekly';\n public const string FREQUENCY_MONTHLY = 'monthly';\n public const string FREQUENCY_QUARTERLY = 'quarterly';\n public const string FREQUENCY_ONE_OFF = 'one_off';\n\n /**\n * Frequencies for standard (non-Ask Jiminny) reports.\n */\n public const array FREQUENCIES = [\n ['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],\n ['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],\n ['id' => self::FREQUENCY_QUARTERLY, 'name' => 'Quarterly'],\n ['id' => self::FREQUENCY_ONE_OFF, 'name' => 'One-off'],\n ];\n\n /**\n * Frequencies for Ask Jiminny reports.\n */\n public const array ASK_JIMINNY_FREQUENCIES = [\n ['id' => self::FREQUENCY_DAILY, 'name' => 'Daily'],\n ['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],\n ['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],\n ];\n\n public const string MEDIA_TYPE_PDF = 'pdf';\n public const string MEDIA_TYPE_PODCAST = 'podcast';\n public const array MEDIA_TYPES = [self::MEDIA_TYPE_PDF, self::MEDIA_TYPE_PODCAST];\n public const array MEDIA_TYPE_OBJECT_PDF = ['id' => self::MEDIA_TYPE_PDF, 'name' => 'PDF'];\n public const array MEDIA_TYPE_OBJECT_PODCAST = ['id' => self::MEDIA_TYPE_PODCAST, 'name' => 'Podcast'];\n public const array MEDIA_TYPE_OBJECTS = [self::MEDIA_TYPE_OBJECT_PDF, self::MEDIA_TYPE_OBJECT_PODCAST];\n\n public const array CALL_TYPE_CONFERENCE = ['id' => 'conference', 'name' => 'Conference'];\n public const array CALL_TYPE_DIALER = ['id' => 'dialer', 'name' => 'Dialer'];\n public const int SENT_REPORT_AT_HOURS = 5;\n public const string PDF_KEY = 'pdf';\n public const string AUDIO_KEY = 'audio';\n\n private const array ALL_FREQUENCIES = [\n ['id' => self::FREQUENCY_DAILY, 'name' => 'Daily'],\n ['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],\n ['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],\n ['id' => self::FREQUENCY_QUARTERLY, 'name' => 'Quarterly'],\n ['id' => self::FREQUENCY_ONE_OFF, 'name' => 'One-off'],\n ];\n private const string S3_DIR = 'reports';\n private const array FILE_EXTENSIONS_VARIANTS = ['html', 'MD', 'pdf'];\n private const array FILE_PODCAST_EXTENSIONS_VARIANTS = ['json', 'mp3', 'ssml'];\n\n public function __construct(\n private readonly TeamRepository $teamRepository,\n private readonly GroupRepository $groupRepository,\n private readonly UserRepository $userRepository,\n private readonly StageRepository $stageRepository,\n private readonly DealStagesService $dealStagesService,\n private readonly RecipientsService $recipientsService,\n private readonly AutomatedReportsRepository $automatedReportsRepository,\n private readonly Webhook $webhookService,\n private readonly BusDispatcher $dispatcher,\n private readonly ActivityTypeService $activityTypeService,\n private readonly PlaybookCategoryRepository $playbookCategoryRepository,\n private readonly AskAnythingPromptService $askAnythingPromptService,\n private readonly SearchRepository $activitySearchRepository,\n private readonly AskAnythingRepository $askAnythingRepository,\n ) {\n }\n\n public static function getTypes(): array\n {\n $types = self::TYPES;\n\n return array_map(static function ($type) {\n return $type['id'];\n }, $types);\n }\n\n public static function getCallTypes(): array\n {\n return array_map(static function ($callType) {\n return $callType['id'];\n }, [self::CALL_TYPE_CONFERENCE, self::CALL_TYPE_DIALER]);\n }\n\n public static function getFrequencies(): array\n {\n return array_map(static function ($frequency) {\n return $frequency['id'];\n }, self::FREQUENCIES);\n }\n\n // front-facing structure\n public function getReportEnabledFieldData(bool $value = false): array\n {\n return [\n 'id' => 'report_enabled',\n 'label' => '',\n 'inputType' => InputTypeEnum::TOGGLE,\n 'value' => $value,\n ];\n }\n\n // Organizations = Teams\n public function getOrganizationFieldData(?string $value = null, bool $shortVersion = false): array\n {\n $options = $this->getTeams();\n\n if ($shortVersion) {\n return [\n 'id' => 'organization',\n 'label' => 'Organization',\n 'options' => $options,\n ];\n }\n\n return [\n 'id' => 'organization',\n 'label' => 'Organization',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => $options,\n 'value' => $value,\n 'dependencies' => [\n 'teams',\n 'deal_stage_at_call',\n 'current_deal_stage',\n 'recipients',\n ActivityTypeService::PLAYBOOK_CATEGORIES_KEY,\n ],\n 'dependsOn' => [],\n ];\n }\n\n // Teams = Groups\n public function getTeamFieldData(array $options = [], array $value = [], bool $shortVersion = false): array\n {\n if ($shortVersion) {\n return [\n 'id' => 'teams',\n 'label' => 'Team',\n 'options' => $options,\n ];\n }\n\n return [\n 'id' => 'teams',\n 'label' => 'Team',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'required' => false,\n 'placeholder' => 'Select',\n 'options' => $options,\n 'value' => $value, // value should be an array of objects {id, name}\n 'dependencies' => [ActivityTypeService::PLAYBOOK_CATEGORIES_KEY],\n 'dependsOn' => [],\n ];\n }\n\n public function getReportTypeFieldData(?string $value = null, bool $shortVersion = false, ?Team $team = null): array\n {\n $types = [];\n if ($team instanceof Team) {\n if ($team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {\n $types = self::TYPES;\n }\n if ($team->hasFeature(FeatureEnum::ASK_JIMINNY_REPORTS)) {\n $types[] = ['id' => self::TYPE_ASK_JIMINNY, 'name' => 'Ask Jiminny'];\n }\n } else {\n $types = self::TYPES;\n }\n\n if ($shortVersion) {\n return [\n 'id' => 'report_type',\n 'label' => 'Report Type',\n 'options' => $types,\n ];\n }\n\n return [\n 'id' => 'report_type',\n 'label' => 'Report Type',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => $types,\n 'value' => $value,\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getFrequencyFieldData(?string $value = null): array\n {\n return [\n 'id' => 'frequency',\n 'label' => 'Frequency',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => self::FREQUENCIES,\n 'value' => $value,\n 'dependencies' => ['period'],\n 'dependsOn' => [],\n ];\n }\n\n public function getPeriodFieldData(?string $valueStartDate = null, ?string $valueEndDate = null): array\n {\n return [\n 'id' => 'period',\n 'label' => 'Select one-off period',\n 'inputType' => InputTypeEnum::DATE_RANGE,\n 'required' => true,\n 'placeholder' => 'Select',\n 'value' => ['startDate' => $valueStartDate, 'endDate' => $valueEndDate],\n 'queryParams' => [\n 'startDate' => 'start_date_period',\n 'endDate' => 'end_date_period',\n ],\n 'dependencies' => [],\n 'dependsOn' => ['frequency'],\n ];\n }\n\n public function getActivityTypesFieldData(?Team $team = null, array $value = [], array $teamsFilter = []): array\n {\n return $this->activityTypeService->getActivityTypeFieldData(team: $team, value: $value, groupIds: $teamsFilter);\n }\n\n public function getDealStageAtCallFieldData(?Team $team = null, array $value = []): array\n {\n return $this->dealStagesService->getDealStageAtCallFieldData(team: $team, value: $value);\n }\n\n public function getCurrentDealStageFieldData(?Team $team = null, array $value = []): array\n {\n return $this->dealStagesService->getCurrentDealStageFieldData(team: $team, value: $value);\n }\n\n public function getDealValueFieldData(?int $valueMin = null, ?int $valueMax = null): array\n {\n return [\n 'id' => 'deal_value',\n 'label' => 'Deal Value',\n 'inputType' => InputTypeEnum::INTEGER_RANGE,\n 'required' => false,\n 'value' => ['min' => $valueMin, 'max' => $valueMax],\n 'queryParams' => [\n 'min' => 'min_deal_value',\n 'max' => 'max_deal_value',\n ],\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getCallTypeFieldData(bool $conferenceOn = false, bool $dialerOn = false): array\n {\n $value = [];\n $conferenceOn && $value[] = self::CALL_TYPE_CONFERENCE;\n $dialerOn && $value[] = self::CALL_TYPE_DIALER;\n\n return [\n 'id' => 'call_type',\n 'label' => 'Call Type',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'required' => true,\n 'options' => [\n self::CALL_TYPE_CONFERENCE,\n self::CALL_TYPE_DIALER,\n ],\n 'value' => $value,\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getMediaTypeFieldData(?AutomatedReport $report = null): array\n {\n $value = [];\n\n if ($report) {\n $value = $this->transformMediaTypes($report);\n }\n\n return [\n 'id' => 'media_types',\n 'label' => 'Export as',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'required' => true,\n 'options' => self::MEDIA_TYPE_OBJECTS,\n 'value' => $value,\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getCallDurationFieldData(?int $valueMin = null, ?int $valueMax = null): array\n {\n return [\n 'id' => 'call_duration',\n 'label' => 'Call Duration',\n 'inputType' => InputTypeEnum::INTEGER_RANGE,\n 'required' => false,\n 'value' => ['min' => $valueMin, 'max' => $valueMax],\n 'queryParams' => [\n 'min' => 'min_call_duration',\n 'max' => 'max_call_duration',\n ],\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getRecipientsFieldData(?Team $team = null, array $value = []): array\n {\n return $this->recipientsService->getRecipientsFieldData(team: $team, value: $value);\n }\n\n public function getJiminnyRecipientsFieldData(array $value = []): array\n {\n return $this->recipientsService->getJiminnyRecipientsFieldData($value);\n }\n\n public function getAdditionalPromptInputFieldData(?string $value = null): array\n {\n return [\n 'id' => 'additional_prompt_input',\n 'label' => 'Special requirements',\n 'inputType' => InputTypeEnum::TEXTAREA,\n 'required' => false,\n 'placeholder' => 'What should be the focus of the report?',\n 'value' => $value,\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getCustomReportNameFieldData(?string $value = null): array\n {\n return [\n 'id' => 'custom_name',\n 'label' => 'Custom report name',\n 'inputType' => InputTypeEnum::TEXT,\n 'required' => false,\n 'placeholder' => 'Enter custom name',\n 'value' => $value,\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n // data providers\n public function getTeams(): array\n {\n $teams = $this->teamRepository->getTeamsForKiosk(status: Team::STATUS_ACTIVE);\n\n $teamData = [];\n foreach ($teams as $team) {\n if (! $team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {\n continue;\n }\n\n $teamData[] = $this->transformTeam($team);\n }\n\n return $teamData;\n }\n\n public function getTeamGroups(string $teamUuid): array\n {\n $data = [];\n $team = $this->getTeam($teamUuid);\n\n if ($team !== null) {\n $groups = $team->groups()->get();\n\n foreach ($groups as $group) {\n $data[] = [\n 'id' => $group->getUuid(),\n 'name' => $group->getName(),\n ];\n }\n }\n\n return $data;\n }\n\n public function getTeamsGroupsOptions(array $filterTeamUuids = []): array\n {\n $data = [];\n $teams = $this->getTeams();\n\n foreach ($teams as $team) {\n if (! empty($filterTeamUuids) && ! in_array($team['id'], $filterTeamUuids, true)) {\n continue;\n }\n\n $data[] = [\n 'label' => $team['name'],\n 'groups' => $this->getTeamGroups($team['id']),\n ];\n }\n\n return $data;\n }\n\n public function getTeam(string $teamUuid): ?Team\n {\n return $this->teamRepository->idOrUuid($teamUuid);\n }\n\n public function getTeamById(int $teamId): ?Team\n {\n return $this->teamRepository->find($teamId);\n }\n\n public function getGroupsUuids(AutomatedReport $report): array\n {\n $uuids = [];\n $reportGroups = $report->getGroups();\n foreach ($reportGroups as $groupId) {\n if ($group = $this->groupRepository->find($groupId)) {\n $uuids[] = $group->getUuid();\n }\n }\n\n return $uuids;\n }\n\n public function getPlaybookCategoriesUuids(AutomatedReport $report): array\n {\n $uuids = [];\n $playbookCategories = $report->getPlaybookCategories();\n foreach ($playbookCategories as $id) {\n if ($category = $this->playbookCategoryRepository->find($id)) {\n $uuids[] = $category->getUuid();\n }\n }\n\n return $uuids;\n }\n\n public function getDealAtCallStagesUuids(AutomatedReport $report): array\n {\n $uuids = [];\n $reportStages = $report->getDealAtCallStages();\n foreach ($reportStages as $id) {\n if ($stage = $this->stageRepository->find($id)) {\n $uuids[] = $stage->getUuid();\n }\n }\n\n return $uuids;\n }\n\n public function getCurrentDealStagesUuids(AutomatedReport $report): array\n {\n $uuids = [];\n $reportStages = $report->getCurrentDealStages();\n foreach ($reportStages as $id) {\n if ($stage = $this->stageRepository->find($id)) {\n $uuids[] = $stage->getUuid();\n }\n }\n\n return $uuids;\n }\n\n public function getUsersUuids(AutomatedReport $report): array\n {\n return $this->extractUserUuids($report->getRecipients());\n }\n\n public function getJiminnyUsersUuids(AutomatedReport $report): array\n {\n return $this->extractUserUuids($report->getJiminnyRecipients());\n }\n\n /**\n * @param array<string, mixed> $recipients\n */\n private function extractUserUuids(array $recipients): array\n {\n $userIds = $recipients['users'] ?? [];\n\n return collect($userIds)\n ->map(fn ($id) => $this->userRepository->find((int) $id))\n ->filter()\n ->map(fn (UserContract $user) => $user->getUuid())\n ->values()\n ->all();\n }\n\n // get mail data\n public function getRecipientUsers(AutomatedReport $report): array\n {\n return $this->buildRecipientUsers($report->getRecipients());\n }\n\n private function getJiminnyRecipientUsers(AutomatedReport $report): array\n {\n return $this->buildRecipientUsers($report->getJiminnyRecipients());\n }\n\n /**\n * @param array<string, mixed> $recipients\n */\n private function buildRecipientUsers(array $recipients): array\n {\n $userIds = $recipients['users'] ?? [];\n\n return collect($userIds)\n ->map(fn ($id) => $this->userRepository->find((int) $id))\n ->filter()\n ->map(fn (UserContract $user) => [\n 'email' => $user->getEmailAddress(),\n 'name' => $user->getName(),\n 'timezone' => $user->getTimezone()->getName(),\n ])\n ->values()\n ->all();\n }\n\n public function getValidRecipientUsers(AutomatedReport $report, bool $includeJiminny = false): array\n {\n if ($report->isAskJiminnyReport()) {\n $recipients = $this->resolveAskJiminnyRecipients($report);\n } else {\n $recipients = $this->getRecipientUsers($report);\n if ($includeJiminny) {\n $recipients = array_merge($recipients, $this->getJiminnyRecipientUsers($report));\n }\n }\n\n $emails = [];\n\n return array_values(array_filter(\n $recipients,\n static function ($recipient) use (&$emails) {\n if (empty($recipient['email']) || in_array($recipient['email'], $emails, true)) {\n return false;\n }\n $emails[] = $recipient['email'];\n\n return true;\n }\n ));\n }\n\n private function resolveAskJiminnyRecipients(AutomatedReport $report): array\n {\n $recipients = [];\n\n $creator = $report->getCreator();\n if ($creator !== null) {\n $recipients[] = [\n 'email' => $creator->getEmailAddress(),\n 'name' => $creator->getName(),\n 'timezone' => $creator->getTimezone()->getName(),\n ];\n }\n\n return array_merge(\n $recipients,\n $this->buildRecipientUsers($report->getRecipients()),\n $this->getGroupRecipientUsers($report),\n );\n }\n\n private function getGroupRecipientUsers(AutomatedReport $report): array\n {\n $users = [];\n foreach ($report->getGroups() as $groupId) {\n $group = $this->groupRepository->find($groupId);\n if ($group === null) {\n continue;\n }\n foreach ($group->getMembers() as $member) {\n $users[] = [\n 'email' => $member->getEmailAddress(),\n 'name' => $member->getName(),\n 'timezone' => $member->getTimezone()->getName(),\n ];\n }\n }\n\n return $users;\n }\n\n public function getReportTypeName(AutomatedReportResult $report): string\n {\n $type = $report->getReport()->getType();\n\n $getType = $this->transformReportType($type);\n\n return $getType['name'];\n }\n\n public function getReportPeriodName(AutomatedReportResult $report): string\n {\n $from = $report->getFromDate();\n $to = $report->getToDate();\n $frequency = $report->getReport()->getFrequency();\n\n if ($from === null || $to === null) {\n if (! $report->getReport()->isAskJiminnyReport()) {\n $invalidPeriod = $from === null ? 'from' : 'to';\n\n throw new ApplicationException('Report period is invalid: ' . $invalidPeriod);\n }\n\n $period = $this->calculateFromAndToDatePeriod($frequency);\n $from = $period['fromDate'];\n $to = $period['toDate'];\n }\n\n return $this->formatReportPeriodName($frequency, $from, $to);\n }\n\n private function formatReportPeriodName(string $frequency, Carbon $from, Carbon $to): string\n {\n $fromYear = $from->format('Y');\n $toYear = $to->format('Y');\n $differentYears = $fromYear !== $toYear;\n\n switch ($frequency) {\n case self::FREQUENCY_DAILY:\n return $from->format('j M Y');\n\n case self::FREQUENCY_QUARTERLY:\n // 'Jan-Mar 2025' or 'Nov 2024-Jan 2025' if years differ\n $startMonth = $from->format('M');\n $endMonth = $to->copy()->subMonth();\n $endMonthName = $endMonth->format('M');\n $endMonthYear = $endMonth->format('Y');\n\n if ($differentYears) {\n return \"{$startMonth} {$fromYear} - {$endMonthName} {$endMonthYear}\";\n }\n\n return \"{$startMonth} - {$endMonthName} {$toYear}\";\n\n case self::FREQUENCY_MONTHLY:\n // 'May 2025' - monthly reports are always within the same year\n return $from->format('M Y');\n\n case self::FREQUENCY_WEEKLY:\n // '4 - 8 Aug 2025', '27 Oct - 3 Nov 2025', or '28 Dec 2024 - 3 Jan 2025' if years differ\n $startDay = $from->format('j');\n $endDay = $to->format('j');\n $startMonth = $from->format('M');\n $endMonth = $to->format('M');\n\n if ($differentYears) {\n return \"{$startDay} {$startMonth} {$fromYear} - {$endDay} {$endMonth} {$toYear}\";\n }\n\n if ($startMonth !== $endMonth) {\n return \"{$startDay} {$startMonth} - {$endDay} {$endMonth} {$toYear}\";\n }\n\n return \"{$startDay} - {$endDay} {$endMonth} {$toYear}\";\n\n case self::FREQUENCY_ONE_OFF:\n // '2 May-31 May 2025' or '15 Dec 2024-15 Jan 2025' if years differ\n $startDay = $from->format('j');\n $startMonth = $from->format('M');\n $endDay = $to->format('j');\n $endMonth = $to->format('M');\n\n // If same month and year, use a format like '2-31 May 2025'\n if ($startMonth === $endMonth && ! $differentYears) {\n return \"{$startDay} - {$endDay} {$startMonth} {$toYear}\";\n }\n\n // If different years, include both years\n if ($differentYears) {\n return \"{$startDay} {$startMonth} {$fromYear} - {$endDay} {$endMonth} {$toYear}\";\n }\n\n // Same year but different months\n return \"{$startDay} {$startMonth} - {$endDay} {$endMonth} {$toYear}\";\n\n default:\n // Default format for unknown frequencies\n return $from->format('j M Y') . ' - ' . $to->format('j M Y');\n }\n }\n\n public function getReportTeamsName(AutomatedReportResult $report): string\n {\n $groups = $report->getGroups();\n\n if (empty($groups)) {\n return 'All';\n }\n\n // Get group names from repository\n $groupNames = [];\n foreach ($groups as $groupId) {\n $group = $this->groupRepository->find($groupId);\n if ($group) {\n $groupNames[] = $group->getName();\n }\n }\n\n if (count($groupNames) === 1) {\n // Single team format\n $teamsName = $groupNames[0];\n } else {\n // Multiple teams format\n $teamsName = implode(', ', $groupNames);\n }\n\n return $teamsName;\n }\n\n public function getReportFileName(AutomatedReportResult $report): string\n {\n $customName = $report->getReport()->getCustomName();\n $periodName = $this->getReportPeriodName($report);\n $filenameSuffix = $this->getFilenameSuffix($report);\n\n if ($customName) {\n if ($filenameSuffix) {\n $customName .= \" {$filenameSuffix}\";\n }\n\n return $this->sanitizeFileName(\"{$customName} - {$periodName}\");\n }\n\n $baseName = $this->getReportTypeName($report);\n\n if ($filenameSuffix) {\n $baseName .= \" {$filenameSuffix}\";\n }\n\n return $this->sanitizeFileName(\"{$baseName} - {$periodName} - {$this->getReportTeamsName($report)}\");\n }\n\n public function getReportFileNameWithExtension(AutomatedReportResult $result): string\n {\n $extension = $this->getMediaTypeMetadata($result)['extension'];\n\n return $this->getReportFileName($result) . '.' . $extension;\n }\n\n public function sanitizeFileName(string $fileName): string\n {\n return str_replace(['/', '\\\\'], '-', $fileName);\n }\n\n public function isUserRecipientOfReport(User $user, AutomatedReport $report): bool\n {\n $recipients = array_map('intval', $report->getRecipients()['users'] ?? []);\n\n return in_array($user->getId(), $recipients);\n }\n\n public function transformReportResults(Collection $automatedReportResults): array\n {\n $data = [];\n foreach ($automatedReportResults as $automatedReportResult) {\n /** @var AutomatedReportResult $automatedReportResult */\n\n $report = $automatedReportResult->getReport();\n\n $createdBy = $report->getCreator();\n $creator = [\n 'id' => $createdBy?->getUuid(),\n 'name' => $createdBy?->getName(),\n 'email' => $createdBy?->getEmailAddress(),\n 'photoUrl' => $createdBy?->getPhotoUrl(),\n ];\n\n $data[] = [\n 'id' => $automatedReportResult->getUuid(),\n 'name' => $automatedReportResult->getName(),\n 'frequency' => $this->transformFrequency($report->getFrequency()),\n 'recipients' => [\n ...array_values($this->transformGroups(team: $report->getTeam(), groupsIds: $report->getGroups())),\n ...array_values($this->transformRecipients($report->getRecipients())),\n ],\n 'report_type' => $this->transformReportType($report->getType()),\n 'media_type' => $automatedReportResult->getMediaType(),\n 'downloadUrl' => $this->generateReportResultDownloadUrl($automatedReportResult),\n 'viewUrl' => $this->generateReportResultViewUrl($automatedReportResult),\n 'generated_at' => $automatedReportResult->getGeneratedAt()?->toIso8601String(),\n 'creator' => $creator,\n ];\n }\n\n return $data;\n }\n\n public function hasCallTypeConference(AutomatedReport $report): bool\n {\n return in_array(self::CALL_TYPE_CONFERENCE['id'], $report->getCallTypes(), true);\n }\n\n public function hasCallTypeDialer(AutomatedReport $report): bool\n {\n return in_array(self::CALL_TYPE_DIALER['id'], $report->getCallTypes(), true);\n }\n\n // transformers\n private function transformTeam(Team $team): array\n {\n if (! $team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {\n return [];\n }\n\n return [\n 'id' => $team->getUuid(),\n 'name' => $team->getName(),\n ];\n }\n\n private function transformReportFullView(AutomatedReport $report): array\n {\n $base = $this->transformReportBase($report);\n\n return $report->getType() === self::TYPE_ASK_JIMINNY\n ? $base + $this->transformAskJiminnyFields($report)\n : $base + $this->transformStandardReportFields($report);\n }\n\n private function transformReportBase(AutomatedReport $report): array\n {\n return [\n 'id' => $report->getUuid(),\n 'organization' => $this->transformOrganization(team: $report->getTeam()),\n 'report_type' => $this->transformReportType($report->getType()),\n 'frequency' => $this->transformFrequency($report->getFrequency()),\n ];\n }\n\n private function transformStandardReportFields(AutomatedReport $report): array\n {\n $team = $report->getTeam();\n\n return [\n 'report_enabled' => $report->getStatus(),\n 'start_date_period' => $report->getFrom()?->format('Y-m-d H:i:s'),\n 'end_date_period' => $report->getTo()?->format('Y-m-d H:i:s'),\n 'deal_value_min' => $report->getDealValueMin(),\n 'deal_value_max' => $report->getDealValueMax(),\n 'call_types' => $this->transformCallType($report->getCallTypes()),\n 'media_types' => $this->transformMediaTypes($report),\n 'call_duration_min' => $this->transformDurationToMinutes($report->getCallDurationMin()),\n 'call_duration_max' => $this->transformDurationToMinutes($report->getCallDurationMax()),\n 'teams' => $this->transformGroups(team: $team, groupsIds: $report->getGroups()),\n 'deal_at_call_stages' => $this->transformStages(team: $team, stagesIds: $report->getDealAtCallStages()),\n 'current_deal_stages' => $this->transformStages(team: $team, stagesIds: $report->getCurrentDealStages()),\n 'recipients' => $this->transformRecipients($report->getRecipients()),\n 'created_by' => $this->transformCreator($report->getCreator()),\n 'additional_prompt_input' => $report->getAdditionalPromptInput(),\n 'custom_name' => $report->getCustomName(),\n 'created_at' => $report->getCreatedAt()->format('Y-m-d H:i:s'),\n 'updated_at' => $report->getUpdatedAt()->format('Y-m-d H:i:s'),\n 'deleted_at' => $report->getDeletedAt()?->format('Y-m-d H:i:s'),\n ];\n }\n\n private function transformAskJiminnyFields(AutomatedReport $report): array\n {\n $team = $report->getTeam();\n $creatorId = $report->getAttribute('created_by');\n $explicitUserIds = array_values(array_filter(\n $report->getRecipients()['users'] ?? [],\n static fn ($id) => $id !== $creatorId\n ));\n\n return [\n 'report_name' => $report->getCustomName(),\n 'enabled' => $report->getStatus(),\n 'share_teams' => $this->transformGroups(team: $team, groupsIds: $report->getGroups()),\n 'share_users' => $this->transformRecipients(['users' => $explicitUserIds]),\n 'saved_search' => $this->transformSafeSearch($report->getSavedSearch()),\n 'ask_jiminny_prompt' => $this->transformAskJiminnyPrompt($report->getAskAnythingPrompt()),\n 'expires_on' => $report->getExpiresAt()?->format('Y-m-d'),\n ];\n }\n\n private function transformOrganization(?Team $team): array\n {\n return [\n 'id' => $team?->getUuid(),\n 'name' => $team?->getName(),\n ];\n }\n\n private function transformReportType(string $type): array\n {\n foreach (self::ALL_TYPES as $typeItem) {\n if ($typeItem['id'] === $type) {\n return $typeItem;\n }\n }\n\n return [];\n }\n\n private function transformCallType(array $types): array\n {\n $result = [];\n $callTypes = [self::CALL_TYPE_CONFERENCE, self::CALL_TYPE_DIALER];\n\n foreach ($types as $type) {\n foreach ($callTypes as $callTypeItem) {\n if ($callTypeItem['id'] === $type) {\n $result[] = $callTypeItem;\n\n break;\n }\n }\n }\n\n return $result;\n }\n\n private function transformMediaTypes(AutomatedReport $report): array\n {\n $values = [];\n\n foreach ($report->getMediaTypes() as $mediaType) {\n if (! in_array($mediaType, self::MEDIA_TYPES, true)) {\n continue;\n }\n\n $values[] = match ($mediaType) {\n self::MEDIA_TYPE_PDF => self::MEDIA_TYPE_OBJECT_PDF,\n self::MEDIA_TYPE_PODCAST => self::MEDIA_TYPE_OBJECT_PODCAST,\n };\n }\n\n return $values;\n }\n\n private function transformFrequency(string $frequency): array\n {\n foreach (self::ALL_FREQUENCIES as $frequencyItem) {\n if ($frequencyItem['id'] === $frequency) {\n return $frequencyItem;\n }\n }\n\n return [];\n }\n\n public function transformDurationToMinutes(?int $duration): ?int\n {\n if (! $duration) {\n return null;\n }\n\n return (int) ($duration / 60);\n }\n\n private function transformGroups(?Team $team, array $groupsIds): array\n {\n if (empty($groupsIds) || ! $team) {\n return [];\n }\n\n $data = [];\n foreach ($groupsIds as $groupId) {\n $group = $team->groups()->where('id', $groupId)->first();\n\n if ($group) {\n $data[] = [\n 'id' => $group->getUuid(),\n 'name' => $group->getName(),\n 'photoUrl' => $group->getPhotoUrl(),\n ];\n }\n }\n\n return $data;\n }\n\n private function transformStages(?Team $team, array $stagesIds): array\n {\n if (empty($stagesIds) || ! $team) {\n return [];\n }\n\n $data = [];\n foreach ($stagesIds as $stageId) {\n $stage = $team->stages()->where('id', $stageId)->first();\n\n if ($stage) {\n $data[] = [\n 'id' => $stage->getUuid(),\n 'name' => $stage->getName(),\n ];\n }\n }\n\n return $data;\n }\n\n private function transformRecipients(array $recipients): array\n {\n $users = [];\n foreach ($recipients['users'] ?? [] as $userId) {\n $users[] = $this->transformUser($userId);\n }\n\n return $users;\n }\n\n private function transformCreator(?User $user): ?array\n {\n if ($user === null) {\n return null;\n }\n\n return $this->transformUser($user->getId());\n }\n\n private function transformAskJiminnyPrompt(?AskAnythingPrompt $prompt): ?array\n {\n if ($prompt === null) {\n return null;\n }\n\n return [\n 'id' => $prompt->getUuid(),\n 'name' => $prompt->getTitle(),\n ];\n }\n\n private function transformSafeSearch(?Search $search): ?array\n {\n if ($search === null) {\n return null;\n }\n\n return [\n 'id' => $search->getUuid(),\n 'name' => $search->getName(),\n ];\n }\n\n private function transformUser(int $userId): array\n {\n /* @var ?User $user */\n $user = $this->userRepository->find($userId);\n\n return [\n 'id' => $user?->getUuid(),\n 'name' => $user?->getName(),\n 'email' => $user?->getEmailAddress(),\n 'photoUrl' => $user?->getPhotoUrl(),\n ];\n }\n\n public function create(array $data): array\n {\n $validatedData = $this->validateAndTransformData($data);\n $validatedData['created_by'] = auth()->id();\n\n $automatedReport = $this->automatedReportsRepository->create($validatedData);\n\n $this->generateOneOffReport($automatedReport);\n\n return $this->transformReportFullView($automatedReport);\n }\n\n public function update(string $uuid, array $data): array\n {\n $validatedData = $this->validateAndTransformData($data);\n $report = $this->automatedReportsRepository->findByUuid($uuid);\n\n if (! $report) {\n throw new InvalidArgumentException('Report not found');\n }\n\n $oldCustomName = $report->getCustomName();\n\n $automatedReport = $this->automatedReportsRepository->update($report, $validatedData);\n\n if ($oldCustomName !== $automatedReport->getCustomName()) {\n $this->updateResultNames($automatedReport);\n }\n\n $this->generateOneOffReport($automatedReport);\n\n return $this->transformReportFullView($automatedReport);\n }\n\n /**\n * Create an Ask Jiminny report.\n */\n public function createAskJiminnyReport(array $data, User $creator): array\n {\n $validatedData = $this->validateAskJiminnyReportData($data, $creator);\n $validatedData['created_by'] = $creator->getId();\n\n $automatedReport = $this->automatedReportsRepository->create($validatedData);\n\n return $this->transformReportFullView($automatedReport);\n }\n\n /**\n * Update an Ask Jiminny report.\n */\n public function updateAskJiminnyReport(AutomatedReport $report, array $data, User $user): array\n {\n if (! $report->isAskJiminnyReport()) {\n throw new InvalidArgumentException('Report is not an Ask Jiminny report');\n }\n\n $validatedData = $this->validateAskJiminnyReportData($data, $user);\n\n $oldCustomName = $report->getCustomName();\n\n $automatedReport = $this->automatedReportsRepository->update($report, $validatedData);\n\n if ($oldCustomName !== $automatedReport->getCustomName()) {\n $this->updateResultNames($automatedReport);\n }\n\n return $this->transformReportFullView($automatedReport);\n }\n\n public function updateAskJiminnyReportStatus(AutomatedReport $report, bool $status): array\n {\n $this->automatedReportsRepository->update($report, ['status' => $status]);\n\n return $this->transformReportFullView($report->fresh());\n }\n\n /**\n * Validate and transform data for Ask Jiminny reports.\n */\n private function validateAskJiminnyReportData(array $data, User $user): array\n {\n // Validate name\n $name = trim($data['report_name'] ?? '');\n if (empty($name)) {\n throw new InvalidArgumentException('Report name is required');\n }\n if (mb_strlen($name) > 50) {\n throw new InvalidArgumentException('Report name must be 50 characters or less');\n }\n\n // Validate frequency (only daily, weekly, monthly for Ask Jiminny)\n $frequency = $data['frequency'] ?? null;\n $askJiminnyFrequencies = [self::FREQUENCY_DAILY, self::FREQUENCY_WEEKLY, self::FREQUENCY_MONTHLY];\n if (! in_array($frequency, $askJiminnyFrequencies, true)) {\n throw new InvalidArgumentException('Frequency must be daily, weekly, or monthly');\n }\n\n // Validate expiration date\n $expiresAt = $data['expires_on'] ?? null;\n if (empty($expiresAt)) {\n throw new InvalidArgumentException('Expiration date is required');\n }\n\n try {\n $expiresAtDate = Carbon::parse($expiresAt);\n } catch (InvalidFormatException $e) {\n throw new InvalidArgumentException('Expiration date format is invalid');\n }\n $maxExpiration = Carbon::now()->addYear();\n if ($expiresAtDate->gt($maxExpiration)) {\n throw new InvalidArgumentException('Expiration date cannot be more than 1 year from now');\n }\n if ($expiresAtDate->isPast()) {\n throw new InvalidArgumentException('Expiration date cannot be in the past');\n }\n\n // Validate saved search\n $activitySearchId = $data['saved_search'] ?? null;\n if (empty($activitySearchId)) {\n throw new InvalidArgumentException('Saved search is required');\n }\n $savedSearch = $this->activitySearchRepository->findByUuidAndUser($activitySearchId, $user);\n if (! $savedSearch) {\n throw new InvalidArgumentException('Saved search not found or does not belong to you');\n }\n\n // Validate saved prompt\n $askAnythingPromptId = $data['ask_jiminny_prompt'] ?? null;\n if (empty($askAnythingPromptId)) {\n throw new InvalidArgumentException('Ask Jiminny prompt is required');\n }\n $prompt = $this->askAnythingRepository->getPromptByUuid($askAnythingPromptId);\n if (! $prompt) {\n throw new InvalidArgumentException('Ask Jiminny prompt not found');\n }\n\n // Validate status\n $status = $data['enabled'] ?? false;\n\n $recipientUserIds = [$user->getId()];\n\n if (! empty($data['share_users'])) {\n $sharedUserIds = $this->validateAndGetUserIdsByTeam(\n $user->team,\n (array) $data['share_users']\n );\n $recipientUserIds = array_merge($recipientUserIds, $sharedUserIds);\n }\n\n $sharedGroupIds = [];\n if (! empty($data['share_teams'])) {\n $sharedGroupIds = $this->validateAndGetGroupIds($user->team, (array) $data['share_teams']);\n }\n\n $recipientUserIds = array_values(array_unique($recipientUserIds));\n\n return [\n 'team_id' => $user->getTeamId(),\n 'type' => self::TYPE_ASK_JIMINNY,\n 'status' => (bool) $status,\n 'frequency' => $frequency,\n 'custom_name' => $name,\n 'activity_search_id' => $savedSearch->getId(),\n 'ask_anything_prompt_id' => $prompt->getId(),\n 'expires_at' => $expiresAtDate->toDateString(),\n 'media_types' => [self::MEDIA_TYPE_PDF],\n 'call_types' => [],\n 'recipients' => ['users' => $recipientUserIds],\n 'groups' => $sharedGroupIds,\n ];\n }\n\n public static function getAskJiminnyFrequencies(): array\n {\n return array_map(static function ($frequency) {\n return $frequency['id'];\n }, self::ASK_JIMINNY_FREQUENCIES);\n }\n\n public function getAskJiminnyReportFilters(User $user): array\n {\n $savedSearches = $this->activitySearchRepository->findByUserOrderedByName($user)\n ->map(fn (Search $search) => [\n 'id' => $search->getUuid(),\n 'name' => $search->getName(),\n ])\n ->values()->all();\n\n $prompts = collect(\n $this->askAnythingPromptService->get($user, AskAnythingPromptTarget::on_demand)\n )->map(fn (AskAnythingPromptDto $prompt) => [\n 'id' => $prompt->id,\n 'name' => $prompt->title,\n ])->values()->all();\n\n return [\n [\n 'id' => 'prompt',\n 'label' => 'Prompt',\n 'options' => $prompts,\n ],\n [\n 'id' => 'saved_search',\n 'label' => 'Saved Search',\n 'options' => $savedSearches,\n ],\n ];\n }\n\n public function getAskJiminnyReportFormData(User $user, ?AutomatedReport $report = null): array\n {\n $team = $user->getTeam();\n $userTimezone = $user->getTimezone();\n\n $savedSearches = $this->activitySearchRepository->findByUserOrderedByName($user)\n ->map(fn (Search $search) => [\n 'id' => $search->getUuid(),\n 'name' => $search->getName(),\n ])\n ->values()->all();\n\n $prompts = collect(\n $this->askAnythingPromptService->get($user, AskAnythingPromptTarget::on_demand)\n )->map(fn (AskAnythingPromptDto $prompt) => [\n 'id' => $prompt->id,\n 'name' => $prompt->title,\n ])->values()->all();\n\n $teamGroups = $this->groupRepository->getAllByTeam($team)->map(fn ($group) => [\n 'id' => $group->getUuid(),\n 'name' => $group->getName(),\n ])->values()->all();\n\n $shareUsers = $this->recipientsService->getRecipientsFieldData(team: $team)['options'] ?? [];\n\n $sharedTeamsValue = [];\n $sharedUsersValue = [];\n if ($report) {\n $sharedTeamsValue = $this->transformGroups($team, $report->getGroups());\n\n $recipientUserIds = $report->getRecipients()['users'] ?? [];\n $creatorId = $report->getAttribute('created_by');\n $sharedUserIds = array_values(array_filter(\n $recipientUserIds,\n static fn ($id) => $id !== $creatorId\n ));\n $sharedUsersValue = collect($sharedUserIds)\n ->map(fn ($id) => $this->userRepository->find((int) $id))\n ->filter()\n ->map(fn (User $u) => [\n 'id' => $u->getUuid(),\n 'name' => $u->getName(),\n ])\n ->values()\n ->all();\n }\n\n return [\n 'fields' => [\n [\n 'id' => 'enabled',\n 'inputType' => InputTypeEnum::TOGGLE,\n 'label' => '',\n 'value' => $report?->getStatus() ?? false,\n ],\n [\n 'id' => 'report_name',\n 'inputType' => InputTypeEnum::TEXT,\n 'label' => 'Name',\n 'placeholder' => 'Enter name',\n 'required' => true,\n 'validation' => ['maxLength' => 50],\n 'value' => $report?->getCustomName() ?? '',\n ],\n [\n 'id' => 'frequency',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'label' => 'Frequency',\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => self::ASK_JIMINNY_FREQUENCIES,\n 'value' => $report ? $this->transformFrequency($report->getFrequency()) : null,\n ],\n [\n 'id' => 'expires_on',\n 'inputType' => InputTypeEnum::DATE,\n 'label' => 'Expires on',\n 'required' => true,\n 'placeholder' => 'Select',\n 'validation' => [\n 'minDate' => now($userTimezone)->toDateString(),\n 'maxDate' => now($userTimezone)->addYear()->toDateString(),\n ],\n 'value' => $report?->getExpiresAt()?->toDateString(),\n ],\n [\n 'id' => 'share_teams',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'label' => 'Team',\n 'required' => false,\n 'placeholder' => 'Select',\n 'options' => $teamGroups,\n 'value' => $sharedTeamsValue,\n ],\n [\n 'id' => 'share_users',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'label' => 'Team member',\n 'required' => false,\n 'placeholder' => 'Select',\n 'groupLabelKey' => 'label',\n 'groupValuesKey' => 'users',\n 'optionLabelKey' => 'name',\n 'optionValueKey' => 'id',\n 'options' => $shareUsers,\n 'value' => $sharedUsersValue,\n ],\n [\n 'id' => 'saved_search',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'label' => 'Saved search',\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => $savedSearches,\n 'value' => $report && $report->getSavedSearch() ? [\n 'id' => $report->getSavedSearch()->getUuid(),\n 'name' => $report->getSavedSearch()->getName(),\n ] : null,\n ],\n [\n 'id' => 'ask_jiminny_prompt',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'label' => 'Ask Jiminny prompt',\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => $prompts,\n 'value' => $report && $report->getAskAnythingPrompt() ? [\n 'id' => $report->getAskAnythingPrompt()->getUuid(),\n 'name' => $report->getAskAnythingPrompt()->getTitle(),\n ] : null,\n ],\n ],\n ];\n }\n\n private function updateResultNames(AutomatedReport $automatedReport): void\n {\n $results = $this->automatedReportsRepository->getResultsByReport($automatedReport);\n\n foreach ($results as $result) {\n $result->update(['name' => $this->getReportFileName($result)]);\n }\n }\n\n public function updateStatus(string $uuid, array $data): array\n {\n $automatedReport = $this->automatedReportsRepository->findByUuid($uuid);\n\n if (! $automatedReport) {\n throw new ModelNotFoundException('Report not found');\n }\n\n $status = $this->validateReportStatus($data['report_enabled'] ?? null);\n $automatedReport->update([\n 'status' => $status,\n ]);\n\n $this->generateOneOffReport($automatedReport);\n\n return $this->transformReportFullView($automatedReport);\n }\n\n private function generateOneOffReport(AutomatedReport $automatedReport): void\n {\n // the scheduler handles all the other frequency types\n if ($automatedReport->getStatus() === false || $automatedReport->getFrequency() !== self::FREQUENCY_ONE_OFF) {\n return;\n }\n\n $this->dispatcher->dispatch(new RequestGenerateReportJob($automatedReport->getUuid()));\n }\n\n public function getReport(string $uuid): AutomatedReport\n {\n $automatedReport = $this->automatedReportsRepository->findByUuid($uuid);\n\n if (! $automatedReport) {\n throw new ModelNotFoundException('Report not found');\n }\n\n return $automatedReport;\n }\n\n public function get(string $uuid): array\n {\n $automatedReport = $this->getReport($uuid);\n\n return $this->transformReportFullView($automatedReport);\n }\n\n public function list(string $sortColumn = 'created_at', string $sortDirection = 'desc'): array\n {\n $results = [];\n $collection = $this->automatedReportsRepository->getAllStandardReports($sortColumn, $sortDirection);\n\n /** @var AutomatedReport $report */\n foreach ($collection as $report) {\n $results[] = $this->transformReportFullView($report);\n }\n\n return ['data' => $results];\n }\n\n public function listAskJiminnyReports(\n User $user,\n string $sortColumn = 'created_at',\n string $sortDirection = 'desc'\n ): array {\n $results = [];\n $collection = $this->automatedReportsRepository->getAskJiminnyReportsByUser($user, $sortColumn, $sortDirection);\n\n /** @var AutomatedReport $report */\n foreach ($collection as $report) {\n $results[] = $this->transformReportFullView($report);\n }\n\n return ['data' => $results];\n }\n\n public function delete(string $uuid): void\n {\n $automatedReport = $this->automatedReportsRepository->findByUuid($uuid);\n\n if (! $automatedReport) {\n throw new ModelNotFoundException('Report not found');\n }\n\n $automatedReport->delete();\n }\n\n public function createReportResult(AutomatedReport $automatedReport, array $data = []): AutomatedReportResult\n {\n return $this->automatedReportsRepository->createResult(\n array_merge(\n [\n 'report_id' => $automatedReport->getId(),\n 'status' => AutomatedReportResult::STATUS_DEFAULT,\n ],\n $data\n )\n );\n }\n\n public function getReportResult(string $resultUuid): AutomatedReportResult\n {\n $report = $this->automatedReportsRepository->findResultByUuid($resultUuid);\n\n if (! $report) {\n throw new ModelNotFoundException('Report Result not found');\n }\n\n return $report;\n }\n\n public function findChildResult(AutomatedReportResult $result, string $type): ?AutomatedReportResult\n {\n return $this->automatedReportsRepository->findChildResult($result, $type);\n }\n\n // prophet API calls\n /**\n * @throws ApplicationException\n */\n public function getGenerateReportPayload(AutomatedReport $automatedReport, string $reportResultUuid): array\n {\n $period = $this->calculateFromAndToDate($automatedReport);\n $fromDate = $period['fromDate'];\n $toDate = $period['toDate'];\n\n return [\n 'team_id' => $automatedReport->getTeamId(),\n 'request_id' => $reportResultUuid,\n 'report_type' => $automatedReport->getType(),\n 'media_types' => $automatedReport->getMediaTypes(),\n 'from_date' => $fromDate->startOfDay()->format(DateTimeInterface::RFC3339),\n 'to_date' => $toDate->endOfDay()->format(DateTimeInterface::RFC3339),\n 'group_ids' => $automatedReport->getGroups(),\n 'call_deal_stage' => $automatedReport->getDealAtCallStages(),\n 'current_deal_stage' => $automatedReport->getCurrentDealStages(),\n 'deal_min_value' => $automatedReport->getDealValueMin(),\n 'deal_max_value' => $automatedReport->getDealValueMax(),\n 'call_types' => $automatedReport->getCallTypes(),\n 'call_duration_min_seconds' => $automatedReport->getCallDurationMin(),\n 'call_duration_max_seconds' => $automatedReport->getCallDurationMax(),\n 'special_requirements' => $automatedReport->getAdditionalPromptInput(),\n 'callback_url' => $this->getCallbackUrl(),\n 'report_period' => $this->formatReportPeriodName(\n $automatedReport->getFrequency(),\n $fromDate,\n $toDate,\n ),\n 'playbook_categories' => $automatedReport->getPlaybookCategories(),\n 'custom_name' => $automatedReport->getCustomName(),\n ];\n }\n\n // $inputPayload - FE payload structure\n public function getActivitiesCountPayload(array $inputPayload): array\n {\n // Use validateAndTransformData to validate and normalize input\n $validatedData = $this->validateAndTransformData($inputPayload);\n $period = $this->calculateFromAndToDatePeriod(\n $validatedData['frequency'],\n Carbon::parse($validatedData['from']),\n Carbon::parse($validatedData['to']),\n );\n $fromDate = $period['fromDate'];\n $toDate = $period['toDate'];\n\n // Create payload similar to getGenerateReportPayload\n return [\n 'team_id' => $validatedData['team_id'],\n 'group_ids' => $validatedData['groups'] ?? [],\n 'report_type' => $validatedData['type'],\n 'from_date' => $fromDate->format(DateTimeInterface::RFC3339),\n 'to_date' => $toDate->format(DateTimeInterface::RFC3339),\n 'call_deal_stage' => $validatedData['deal_at_call_stages'] ?? [],\n 'current_deal_stage' => $validatedData['current_deal_stages'] ?? [],\n 'deal_min_value' => $validatedData['deal_value_min'] ?? null,\n 'deal_max_value' => $validatedData['deal_value_max'] ?? null,\n 'call_types' => $validatedData['call_types'],\n 'call_duration_min_seconds' => $validatedData['call_duration_min'] ?? null,\n 'call_duration_max_seconds' => $validatedData['call_duration_max'] ?? null,\n 'special_requirements' => $validatedData['additional_prompt_input'] ?? null,\n 'playbook_categories' => $validatedData['playbook_categories'] ?? [],\n 'request_id' => null,\n 'callback_url' => null,\n ];\n }\n\n public function shouldSendReport(array $users, ?CarbonInterface $generatedAt = null): bool\n {\n if (empty($users)) {\n return false;\n }\n\n $earliestTz = collect($users)\n ->mapWithKeys(function (array $user) {\n $tz = new DateTimeZone($user['timezone']);\n $nowUtc = new DateTime('now', new DateTimeZone('UTC'));\n $offset = $tz->getOffset($nowUtc);\n\n return [$user['timezone'] => $offset];\n })\n ->sortDesc()\n ->keys()\n ->first();\n\n $now = Carbon::now($earliestTz);\n $isScheduledTime = (int) $now->format('H') === self::SENT_REPORT_AT_HOURS;\n\n if ($isScheduledTime) {\n return true;\n }\n\n return $this->hasPassedScheduledTime($generatedAt, $earliestTz);\n }\n\n public function hasPassedScheduledTime(?CarbonInterface $generatedAt, string $timezone): bool\n {\n if ($generatedAt === null) {\n return false;\n }\n\n $now = Carbon::now($timezone);\n $scheduledTime = $now->copy()->setTime(self::SENT_REPORT_AT_HOURS, 0, 0);\n\n if ($now->hour < self::SENT_REPORT_AT_HOURS) {\n $scheduledTime = $scheduledTime->subDay();\n }\n\n $scheduledTimeUtc = $scheduledTime->copy()->utc();\n $generatedAtUtc = $generatedAt->copy()->utc();\n $nowUtc = $now->copy()->utc();\n\n return $generatedAtUtc->lt($scheduledTimeUtc) && $nowUtc->gt($scheduledTimeUtc);\n }\n\n public function calculateFromAndToDatePeriod(\n string $frequency,\n ?Carbon $fromDate = null,\n ?Carbon $toDate = null\n ): array {\n if ($frequency === self::FREQUENCY_ONE_OFF) {\n return [\n 'fromDate' => $fromDate,\n 'toDate' => $toDate,\n ];\n }\n\n $now = Carbon::now();\n\n return match ($frequency) {\n self::FREQUENCY_DAILY => [\n 'fromDate' => $now->copy()->subDay()->startOfDay(),\n 'toDate' => $now->copy()->subDay()->endOfDay(),\n ],\n self::FREQUENCY_WEEKLY => [\n 'fromDate' => $now->copy()->subWeeks(1)->startOfDay(),\n 'toDate' => $now->copy()->subDay()->endOfDay(),\n ],\n self::FREQUENCY_MONTHLY => [\n 'fromDate' => $now->copy()->subMonths(1)->startOfDay(),\n 'toDate' => $now->copy()->subDay()->endOfDay(),\n ],\n self::FREQUENCY_QUARTERLY => [\n 'fromDate' => $now->copy()->subMonths(3)->startOfDay(),\n 'toDate' => $now->copy()->subDay()->endOfDay(),\n ],\n default => throw new InvalidArgumentException(\"Unsupported frequency: {$frequency}\"),\n };\n }\n\n private function calculateFromAndToDate(AutomatedReport $automatedReport): array\n {\n return $this->calculateFromAndToDatePeriod(\n $automatedReport->getFrequency(),\n $automatedReport->getFrom(),\n $automatedReport->getTo()\n );\n }\n\n public function getAskJiminnyGenerateReportPayload(\n AutomatedReport $automatedReport,\n AutomatedReportResult $reportResult,\n array $activityIds,\n ): array {\n return [\n 'user_question' => $automatedReport->getAskAnythingPrompt()?->getContent(),\n 'call_ids' => array_map('strval', $activityIds),\n 'team_id' => $automatedReport->getTeamId(),\n 'request_id' => $reportResult->getUuid(),\n 'callback_url' => $this->getCallbackUrl(),\n 'report_period' => $this->getReportPeriodName($reportResult),\n 'report_name' => $automatedReport->getCustomName(),\n ];\n }\n\n private function getCallbackUrl(): string\n {\n return $this->webhookService->route('jiminny.webhook.reports.ready');\n }\n\n /**\n * Validate and transform payload data for automated reports\n *\n * @param array $data\n *\n * @throws InvalidArgumentException\n *\n * @return array\n */\n private function validateAndTransformData(array $data): array\n {\n // Validate organization (team) and check feature\n $team = $this->validateOrganization($data['organization'] ?? null);\n\n $status = $this->validateReportStatus($data['report_enabled'] ?? null);\n $type = $this->validateReportType($data['report_type'] ?? null);\n $frequency = $this->validateFrequency($data['frequency'] ?? null);\n $additionalPromptInput = $this->validateAdditionalPromptInput(\n $data['additional_prompt_input'] ?? null\n );\n $customReportName = $this->validateCustomReportName($data['custom_name'] ?? null);\n\n // Prepare data for the database\n $reportData = [\n 'team_id' => $team->getId(),\n 'type' => $type,\n 'status' => $status,\n 'frequency' => $frequency,\n 'additional_prompt_input' => $additionalPromptInput,\n 'custom_name' => $customReportName,\n ];\n\n // Validate deal values\n $reportData = $this->validateDealValues($data, $reportData);\n\n // Validate date range\n $reportData = $this->validateDateRange($data, $reportData, $frequency);\n\n // Validate call durations\n $reportData = $this->validateCallDurations($data, $reportData);\n\n // Validate call types\n $reportData = $this->validateCallTypes($data, $reportData);\n\n // Validate media types\n $reportData = $this->validateMediaTypes($data, $reportData);\n\n // Validate groups\n if (isset($data['teams'])) {\n $reportData['groups'] = $this->validateAndGetGroupIds($team, $data['teams']);\n }\n\n // Validate deal stages\n $reportData = $this->validateDealStages($data, $reportData, $team, $type);\n\n // Validate playbook categories\n $reportData = $this->validatePlaybookCategories($data, $reportData, $team);\n\n // Validate recipients\n $reportData['recipients'] = [\n 'users' => $this->validateAndGetUserIdsByTeam($team, $data['recipients'] ?? []),\n ];\n\n if (isset($data['jiminny_recipients'])) {\n // Validate Jiminny recipients\n $reportData['jiminny_recipients'] = [\n 'users' => $this->validateAndGetJiminnyUserIds((array) $data['jiminny_recipients']),\n ];\n }\n\n return $reportData;\n }\n\n private function validateDealValues(array $data, array $reportData): array\n {\n if (isset($data['min_deal_value'])) {\n $reportData['deal_value_min'] = (int) $data['min_deal_value'];\n\n if ($reportData['deal_value_min'] > 4294967295 || $reportData['deal_value_min'] < 0) {\n throw new InvalidArgumentException('Min deal value should be between 0 and 4294967295');\n }\n }\n\n if (isset($data['max_deal_value'])) {\n $reportData['deal_value_max'] = (int) $data['max_deal_value'];\n\n if ($reportData['deal_value_max'] > 4294967295 || $reportData['deal_value_max'] < 0) {\n throw new InvalidArgumentException('Max deal value should be between 0 and 4294967295');\n }\n }\n\n if (isset($data['min_deal_value'], $data['max_deal_value'])\n && $data['min_deal_value'] > $data['max_deal_value']\n ) {\n throw new InvalidArgumentException('Min deal value cannot be greater than max deal value');\n }\n\n return $reportData;\n }\n\n private function validateDateRange(array $data, array $reportData, string $frequency): array\n {\n // Set date range only for one_off frequency\n if ($frequency === 'one_off') {\n if (isset($data['start_date_period'])) {\n $reportData['from'] = $this->parseDate($data['start_date_period']);\n }\n\n if (isset($data['end_date_period'])) {\n $reportData['to'] = $this->parseDate($data['end_date_period']);\n }\n\n if (empty($reportData['from']) || empty($reportData['to'])) {\n throw new InvalidArgumentException(\n 'Start date and end date are required for one_off frequency'\n );\n }\n } else {\n $reportData['from'] = null;\n $reportData['to'] = null;\n }\n\n return $reportData;\n }\n\n private function validateCallDurations(array $data, array $reportData): array\n {\n // Convert call durations from minutes to seconds\n if (isset($data['min_call_duration'])) {\n $reportData['call_duration_min'] = (int) $data['min_call_duration'] * 60;\n\n if ($reportData['call_duration_min'] > 4294967295 || $reportData['call_duration_min'] < 0) {\n throw new InvalidArgumentException('Min call duration should be between 0 and 4294967295');\n }\n }\n\n if (isset($data['max_call_duration'])) {\n $reportData['call_duration_max'] = (int) $data['max_call_duration'] * 60;\n\n if ($reportData['call_duration_max'] > 4294967295 || $reportData['call_duration_max'] < 0) {\n throw new InvalidArgumentException('Max call duration should be between 0 and 4294967295');\n }\n }\n\n return $reportData;\n }\n\n private function validateCallTypes(array $data, array $reportData): array\n {\n // Set call types\n $reportData['call_types'] = $data['call_type'] ?? [];\n if (empty($reportData['call_types'])) {\n $reportData['call_types'] = self::getCallTypes();\n }\n\n foreach ($reportData['call_types'] as $callType) {\n if (! in_array($callType, self::getCallTypes(), true)) {\n throw new InvalidArgumentException(sprintf('Call type %s is invalid', $callType));\n }\n }\n\n return $reportData;\n }\n\n private function validateMediaTypes(array $data, array $reportData): array\n {\n // Set media types from input data\n $reportData['media_types'] = $data['media_types'] ?? [];\n\n if (empty($reportData['media_types'])) {\n throw new InvalidArgumentException('Media types are required');\n }\n\n foreach ($reportData['media_types'] as $mediaType) {\n if (! in_array($mediaType, self::MEDIA_TYPES, true)) {\n throw new InvalidArgumentException(sprintf('Media type %s is invalid', $mediaType));\n }\n }\n\n return $reportData;\n }\n\n private function validateDealStages(array $data, array $reportData, Team $team, string $reportType): array\n {\n // Validate and set deal stages\n if (isset($data['deal_stage_at_call'])) {\n $reportData['deal_at_call_stages'] =\n $this->validateAndGetDealStageIds($team, $data['deal_stage_at_call'], 'Deal stage at call');\n }\n\n if (isset($data['current_deal_stage'])) {\n $reportData['current_deal_stages'] =\n $this->validateAndGetDealStageIds($team, $data['current_deal_stage'], 'Current deal stage');\n }\n\n // Ensure current_deal_stage is not provided for loss_analysis report type\n if ($reportType === self::TYPE_LOSS_ANALYSIS && ! empty($data['current_deal_stage'])) {\n throw new InvalidArgumentException('Current deal stage is not applicable for Loss Analysis reports');\n }\n\n return $reportData;\n }\n\n // transform uuid to id\n private function validatePlaybookCategories(array $data, array $reportData, Team $team): array\n {\n $key = 'playbook_categories';\n\n if (isset($data[$key])) {\n $payloadIds = $data[$key];\n $ids = [];\n\n foreach ($payloadIds as $uuid) {\n $uuid = (string) $uuid;\n\n try {\n $playbookCategory = $this->playbookCategoryRepository->findByUuid($uuid);\n } catch (Throwable $throwable) {\n Log::error(__METHOD__ . ' ' . $throwable->getMessage());\n\n throw new InvalidArgumentException(sprintf('Playbook category %s not found', $uuid));\n }\n\n if (! $playbookCategory) {\n throw new InvalidArgumentException(sprintf('Playbook category %s not found', $uuid));\n }\n\n if (! $playbookCategory->hasPlaybook()) {\n throw new InvalidArgumentException(sprintf('Playbook category %s has no playbook', $uuid));\n }\n\n if ($playbookCategory->getPlaybook()->getTeamId() !== $team->getId()) {\n throw new InvalidArgumentException(\n sprintf('Playbook category %s not found for team %s', $uuid, $team->getUuid())\n );\n }\n\n $ids[] = $playbookCategory->getId();\n }\n\n $reportData[$key] = $ids;\n }\n\n return $reportData;\n }\n\n private function validateReportStatus($status): bool\n {\n if (! in_array($status, [true, false], true)) {\n throw new InvalidArgumentException('Report status is invalid');\n }\n\n return $status;\n }\n\n private function validateReportType($type): string\n {\n if (! in_array($type, self::getTypes(), true)) {\n throw new InvalidArgumentException(sprintf('Report type is invalid: %s', $type));\n }\n\n return $type;\n }\n\n private function validateFrequency($frequency): string\n {\n if (! in_array($frequency, self::getFrequencies(), true)) {\n throw new InvalidArgumentException('Frequency is invalid');\n }\n\n return $frequency;\n }\n\n private function validateAdditionalPromptInput(?string $additionalPromptInput): ?string\n {\n if ($additionalPromptInput && strlen($additionalPromptInput) > 5000) {\n throw new InvalidArgumentException('Additional Prompt Input should be less than 5000 characters');\n }\n\n return $additionalPromptInput;\n }\n\n private function validateCustomReportName(?string $customReportName): ?string\n {\n if ($customReportName === null || $customReportName === '') {\n return null;\n }\n\n if (strlen($customReportName) > 70) {\n throw new InvalidArgumentException('Custom report name should be less than 70 characters');\n }\n\n return $customReportName;\n }\n\n private function validateOrganization(?string $organizationUuid): Team\n {\n if (! $organizationUuid) {\n throw new InvalidArgumentException('Organization is required');\n }\n\n $team = $this->teamRepository->idOrUuid($organizationUuid);\n\n if (! $team) {\n throw new InvalidArgumentException('Organization not found');\n }\n\n if (! $team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {\n throw new InvalidArgumentException('Organization does not have the Automated Reports feature');\n }\n\n return $team;\n }\n\n private function validateAndGetGroupIds(Team $team, array $teamUuids): array\n {\n $groupIds = [];\n\n foreach ($teamUuids as $uuid) {\n $group = $this->groupRepository->findByUuid($uuid);\n\n if ($group === null || $group->getTeamId() !== $team->getId()) {\n throw new InvalidArgumentException(\n sprintf('Group %s not found for team %s', $uuid, $team->getUuid())\n );\n }\n\n $groupIds[] = $group->getId();\n\n }\n\n return $groupIds;\n }\n\n private function validateAndGetDealStageIds(Team $team, array $stageUuids, string $propertyLabel): array\n {\n $stageIds = [];\n\n foreach ($stageUuids as $uuid) {\n $stage = $this->stageRepository->findByUuid($uuid);\n\n if ($stage === null || $stage->getTeamId() !== $team->getId()) {\n throw new InvalidArgumentException(\n sprintf('Stage %s not found for team %s for %s', $uuid, $team->getUuid(), $propertyLabel)\n );\n }\n\n $stageIds[] = $stage->getId();\n }\n\n return $stageIds;\n }\n\n private function validateAndGetUserIds(array $userUuids, callable $teamCheck): array\n {\n if (empty($userUuids)) {\n return [];\n }\n\n $userIds = [];\n\n foreach ($userUuids as $uuid) {\n $user = $this->userRepository->findByUuid($uuid);\n\n if (! $user || ! $user->isStatusActive()) {\n throw new InvalidArgumentException(\n sprintf('User %s not found or is not active', $uuid)\n );\n }\n\n if (! $teamCheck($user)) {\n throw new InvalidArgumentException(\n sprintf('User %s does not belong to the allowed team(s)', $uuid)\n );\n }\n\n $userIds[] = $user->getId();\n }\n\n return $userIds;\n }\n\n private function validateAndGetUserIdsByTeam(Team $team, array $userUuids): array\n {\n return $this->validateAndGetUserIds($userUuids, fn ($user) => $user->getTeamId() === $team->getId());\n }\n\n private function validateAndGetJiminnyUserIds(array $userUuids): array\n {\n $allowedTeamIds = config('kiosk.teamIds', []);\n\n return $this->validateAndGetUserIds($userUuids, fn ($user) => in_array($user->getTeamId(), $allowedTeamIds, true));\n }\n\n private function parseDate(string $dateString): string\n {\n return date('Y-m-d H:i:s', strtotime($dateString));\n }\n\n private function generateReportResultViewUrl(AutomatedReportResult $result): string\n {\n $mediaResource = $this->getReportMediaRouteResource($result);\n\n return route('ai-reports.' . $mediaResource . '.view', ['uuid' => $result->getUuid()]);\n }\n\n private function generateReportResultDownloadUrl(AutomatedReportResult $result): string\n {\n $mediaResource = $this->getReportMediaRouteResource($result);\n\n return route('ai-reports.' . $mediaResource . '.download', ['uuid' => $result->getUuid()]);\n }\n\n private function getReportMediaRouteResource(AutomatedReportResult $result): string\n {\n if ($result->getMediaType() === self::MEDIA_TYPE_PDF) {\n return self::PDF_KEY;\n } elseif ($result->getMediaType() === self::MEDIA_TYPE_PODCAST) {\n return self::AUDIO_KEY;\n }\n\n throw new \\InvalidArgumentException('Unknown media type.');\n }\n\n public function getMediaPath(AutomatedReportResult $result): ?string\n {\n $url = match ($result->getMediaType()) {\n self::MEDIA_TYPE_PDF => $result->getPdfUrl(),\n self::MEDIA_TYPE_PODCAST => $result->getPodcastAudioUrl(),\n default => null,\n };\n\n if ($url === null) {\n return null;\n }\n\n $path = parse_url(trim($url, '\"\\''), PHP_URL_PATH);\n\n return $path ?: null;\n }\n\n public function getFilenameSuffix(AutomatedReportResult $result): ?string\n {\n return match ($result->getMediaType()) {\n self::MEDIA_TYPE_PODCAST => 'Podcast',\n default => null,\n };\n }\n\n public function getMailSubjectSuffix(AutomatedReportResult $result): string\n {\n return match ($result->getMediaType()) {\n self::MEDIA_TYPE_PDF => 'report',\n self::MEDIA_TYPE_PODCAST => 'podcast',\n default => '',\n };\n }\n\n public function getMediaTypeMetadata(AutomatedReportResult $result): array\n {\n return match ($result->getMediaType()) {\n self::MEDIA_TYPE_PODCAST => ['extension' => 'mp3', 'mime' => 'audio/mpeg'],\n self::MEDIA_TYPE_PDF => ['extension' => 'pdf', 'mime' => 'application/pdf'],\n default => ['extension' => null, 'mime' => null],\n };\n }\n\n public function deleteS3Files(AutomatedReportResult $result): void\n {\n $teamUuid = $result->getReport()->getTeam()->getUuid();\n $reportUuid = $result->getUuid();\n\n // delete all files for a report uuid no mather of pdf, podcast, or both\n // in case of both - the podcast files are linked to the pdf (parent) uuid\n // pdf and podcast date times should be close\n $path = sprintf('%s/%s/%s', $teamUuid, self::S3_DIR, $reportUuid);\n\n foreach (self::FILE_EXTENSIONS_VARIANTS as $extension) {\n $file = $path . '.' . $extension;\n\n if (Storage::exists($file)) {\n Storage::delete($file);\n Log::info('[Reports] Deleted S3 file', [\n 'path' => $file,\n ]);\n }\n }\n\n foreach (self::FILE_PODCAST_EXTENSIONS_VARIANTS as $extension) {\n $file = $path . '_podcast.' . $extension;\n\n if (Storage::exists($file)) {\n Storage::delete($file);\n Log::info('[Reports] Deleted Podcast S3 file', [\n 'path' => $file,\n ]);\n }\n }\n }\n\n /**\n *\n * @param int|null $teamId Optional team ID to filter results\n *\n * @return Collection<int, int> Collection of team IDs\n */\n public function getTeamIdsWithReportsResults(?int $teamId = null): Collection\n {\n return $this->automatedReportsRepository->getTeamIdsWithReportsResults($teamId);\n }\n\n /**\n * Core delete logic for report results using a query\n *\n * @param Builder $query\n * @param array $logContext\n *\n * @return int\n */\n private function deleteReportResultsByQuery(Builder $query, array $logContext = []): int\n {\n $deletedCount = 0;\n\n if ($query->exists()) {\n Log::info(\n 'Run delete report results',\n array_merge(\n $logContext,\n [\n 'service' => 'AutomatedReportsService',\n ]\n )\n );\n\n $query->chunkById(50, function ($results) use (&$deletedCount, $logContext) {\n foreach ($results as $result) {\n $this->deleteReportResult($result);\n $deletedCount++;\n\n Log::info(\n 'Deleted a report result',\n array_merge(\n $logContext,\n [\n 'result_id' => $result->getId(),\n 'report_id' => $result->getReportId(),\n ]\n )\n );\n }\n });\n }\n\n return $deletedCount;\n }\n\n /**\n * Delete report results for a team by retention period\n *\n * @param Team $team\n * @param CarbonImmutable $retentionDate\n *\n * @return int Number of deleted report results\n */\n public function deleteReportsResultsInRetentionPeriod(Team $team, CarbonImmutable $retentionDate): int\n {\n $reportIds = $this->automatedReportsRepository->getReportIdsByTeam($team);\n\n if ($reportIds->isEmpty()) {\n return 0;\n }\n\n $query = $this->automatedReportsRepository\n ->getReportResultsQueryForRetention($team, $retentionDate);\n\n return $this->deleteReportResultsByQuery($query, [\n 'team_id' => $team->getId(),\n 'retention_date' => $retentionDate->toDateTimeString(),\n ]);\n }\n\n /**\n * Delete ALL report results for a specific automated report\n *\n * @param string $uuid\n *\n * @return int\n */\n public function deleteReportResults(string $uuid): int\n {\n $report = $this->getReport($uuid);\n\n $query = $this->automatedReportsRepository->getResultsByReportQuery($report);\n\n return $this->deleteReportResultsByQuery($query, [\n 'report_uuid' => $uuid,\n 'report_id' => $report->getId(),\n ]);\n }\n\n public function deleteReportResult(AutomatedReportResult $result): void\n {\n $this->deleteS3Files($result);\n\n $result->delete();\n }\n\n /**\n * Get all reports for a specific team\n *\n * @param Team $team\n *\n * @return \\Illuminate\\Database\\Eloquent\\Collection\n */\n public function getTeamReports(Team $team): \\Illuminate\\Database\\Eloquent\\Collection\n {\n return $this->automatedReportsRepository->getReportsByTeam($team);\n }\n\n /**\n * Get all report results for a specific report\n *\n * @param AutomatedReport $report\n *\n * @return \\Illuminate\\Database\\Eloquent\\Collection\n */\n public function getReportResults(AutomatedReport $report): \\Illuminate\\Database\\Eloquent\\Collection\n {\n return $this->automatedReportsRepository->getResultsByReport($report);\n }\n\n public function deleteAllReportResults(AutomatedReport $report): void\n {\n $results = $this->getReportResults($report);\n\n /** @var AutomatedReportResult $result */\n foreach ($results as $result) {\n Log::info('Deleting result', [\n 'report' => $report->getId(),\n 'result' => $result->getId(),\n ]);\n\n $this->deleteReportResult($result);\n }\n }\n\n public function deleteAllData(Team $team): void\n {\n Log::info('Deleting automated report and results for team', [\n 'team' => $team->getId(),\n ]);\n\n $reports = $this->getTeamReports($team);\n\n /** @var AutomatedReport $report */\n foreach ($reports as $report) {\n Log::info('Deleting report', [\n 'team' => $team->getId(),\n 'report' => $report->getId(),\n ]);\n\n $this->deleteAllReportResults($report);\n\n $report->delete();\n }\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":true,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"Project","depth":3,"role_description":"text"},{"role":"AXButton","text":"Project","depth":3,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"New File or Directory…","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Expand Selected","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Collapse All","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Options","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false}]...
|
3397592283435315795
|
6686367547760219213
|
visual_change
|
accessibility
|
NULL
|
Project: faVsco.js, menu
#11894 on JY-18909-automa Project: faVsco.js, menu
#11894 on JY-18909-automated-reports-ask-jiminny, menu
Start Listening for PHP Debug Connections
AutomatedReportsCommandTest
Run 'AutomatedReportsCommandTest'
Debug 'AutomatedReportsCommandTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Execute
Explain Plan
Browse Query History
View Parameters
Open Query Execution Settings…
In-Editor Results
Tx: Auto
Cancel Running Statements
Playground
jiminny
Sync Changes
Hide This Notification
Code changed:
Hide
16
13
13
Previous Highlighted Error
Next Highlighted Error
SELECT * FROM teams WHERE id = 1;
select * from crm_layouts where crm_configuration_id = 39;
SELECT * FROM crm_layout_entities WHERE crm_layout_id = 283;
SELECT * FROM crm_fields WHERE id = 2234;
SELECT * FROM crm_field_values WHERE crm_field_id = 2234;
select * from crm_profiles where user_id = 143;
select * from record_types where crm_configuration_id = 39; # 0121K000001MHElQAO,0121K000001MHEqQAO
select * from business_processes where crm_configuration_id = 39;
# 01941000000H669AAC, 01941000000H66JAAS
select * from record_type_field_values
where record_type_id IN (24);
select * from crm_field_values where id IN (2730);
select * from crm_configurations where id = 39;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 1
and sa.provider = 'salesforce'; #1035
select * from users where team_id = 1; # 222 group 3
SELECT * FROM activities WHERE user_id = 222 order by id desc;
select * from sidekick_settings where team_id = 1;
select * from teams where id = 1;
select * from team_features where team_id = 1;
select * from activities where crm_configuration_id = 2
and provider = 'ms-teams' and id = 608765;
SELECT * FROM activities WHERE crm_configuration_id = 2 and crm_provider_id = '59523413338';
select * from sidekick_settings where team_id = 2;
SELECT * FROM activities WHERE id = 608660;
select * from activity_summary_logs where activity_id = 608660;
select * from ai_prompts where transcription_id = 11214;
# [PASSWORD_DOTS]
SELECT * FROM activities WHERE uuid_to_bin('ed78a437-2804-450e-ab2f-56ab1c641346') = uuid;
# id: 608818, crm: 59628809737
SELECT * FROM activities WHERE uuid_to_bin('36b06e55-afdd-4782-8dee-c624cd0af191') = uuid;
# id: 608821, crm: 59632069252
SELECT ce.start_time, ce.end_time, a.id, a.uuid, crm_provider_id, calendar_event_id, title,
playbook_category_id, user_id, lead_id, contact_id, account_id, opportunity_id,
scheduled_start_time, scheduled_end_time, actual_start_time, actual_end_time, a.created_at
FROM activities a
join calendar_events ce on a.calendar_event_id = ce.id
WHERE a.id IN (608818, 608821);
select * from users where team_id = 1;
select * from team_settings where team_id = 1;
select * from crm_profiles where crm_configuration_id = 39 order by user_id;
select * from team_features where team_id = 1;
select * from users where team_id = 2;
SELECT * FROM activities WHERE uuid_to_bin('ec7647e9-5225-458b-b475-f31aa2769204') = uuid; # 612639
# Preslava N. Ivanova, grou id 3
SELECT * FROM opportunities WHERE uuid_to_bin('a2928fe5-aec5-46cb-85d9-7654c89e46a6') = uuid;
select * from activities where opportunity_id = 344 and actual_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00';
select
a.id,
a.type,
a.scheduled_start_time,
a.actual_start_time,
a.created_at,
a.opportunity_id,
a.status
FROM activities a
WHERE opportunity_id = 344
and status IN ('completed', 'received', 'delivered')
and (
(a.actual_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00')
OR (a.created_at between '2024-10-11 00:00:00' and '2024-10-12 00:00:00')
OR (a.scheduled_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00'))
;
SELECT * FROM users WHERE id = 222;
SELECT * FROM crm_profiles WHERE user_id = 222;
select * from crm_layouts where crm_configuration_id = 39;
SELECT * FROM crm_layout_entities WHERE crm_layout_id = 281;
select * from group_deal_risk_types;
select * from opportunities where team_id = 1;
SELECT * FROM opportunities WHERE id = 315;
SELECT * FROM crm_field_data WHERE object_id = 315;
select * from crm_field_data where object_id = 260;
select * from generic_ai_prompts where subject_id = 315;
select * from teams; # 36, 21, 121, [EMAIL]
SELECT * FROM social_accounts WHERE sociable_id = 121 and provider = 'bullhorn';
# [PASSWORD_DOTS]
select * from teams where id = 1;
select * from crm_configurations where id = 39;
select * from users where team_id = 1;
select u.email, cp.* from users u
join crm_profiles cp on u.id = cp.user_id
where u.team_id = 1;
# 1 - 00541000004281rAAA
# 204 - 0052g000003freeAAA
# 429 - 0052g000003qGOiAAM
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 1
and sa.provider = 'salesforce';
select * from activities where type = 'softphone'
and created_at > '2024-12-11 15:24:36' order by id desc;
select * from activity_providers where team_id = 1;
select * from activity_provider_users where activity_provider_id = 328;
select * from opportunities where crm_configuration_id = 39
AND account_id = 178 AND is_closed = false
order by created_at DESC;
select * from contacts where id = 3952;
select * from accounts where id = 178;
# [PASSWORD_DOTS]
select * from teams where id = 36;
select * from crm_configurations where id = 21;
select * from users where team_id = 36;
select u.email, cp.* from users u
join crm_profiles cp on u.id = cp.user_id
where u.team_id = 36;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 36
and sa.provider = 'bullhorn';
select * from social_accounts where id = 348;
UPDATE social_accounts SET
provider_user_token = '21442_6802599_91:41179a58-21e7-4d7c-ad58-56bb666b2f65',
provider_refresh_token = '21442_6802599_91:01c6b335-3f2a-42e4-85ff-8a08fa65fceb',
expires = 1733998131,
state = 'connected'
WHERE id = 348;
# [PASSWORD_DOTS]
select * from teams where id = 31;
select * from crm_configurations where id = 18;
select * from users where team_id = 31; # 257
select u.email, cp.* from users u
join crm_profiles cp on u.id = cp.user_id
where u.team_id = 31;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 31
and sa.provider = 'close';
select * from contacts where crm_configuration_id = 18;
# [PASSWORD_DOTS] NEPTUNE [PASSWORD_DOTS]
select * from teams;
select * from users where id IN (1030, 1035, 1052);
select * from crm_configurations;
select * from users where team_id = 65; # 257
select * from team_settings where team_id = 65; # 257
select * from invitations where team_id = 65; # 257
select * from users where email = '[EMAIL]'; # 257
select u.email, cp.* from users u
join crm_profiles cp on u.id = cp.user_id
where u.team_id = 65;
select * from crm_configurations where id = 53;
select * from accounts where crm_configuration_id = 53 order by id desc;
select * from leads where crm_configuration_id = 53 order by id desc;
select * from contacts where crm_configuration_id = 53 order by id desc;
select * from opportunities where crm_configuration_id = 53 order by id desc;
select * from crm_profiles where crm_configuration_id = 53 order by id desc;
select * from crm_fields where crm_configuration_id = 53 order by id desc;
select * from crm_field_values where crm_field_id = 3341 order by id desc;
select * from crm_layouts where crm_configuration_id = 53 order by id desc;
select * from stages where crm_configuration_id = 53 order by id desc;
select * from crm_profiles where crm_configuration_id = 13;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 65
and sa.provider = 'integration-app';
select * from contacts where crm_configuration_id = 13;
select * from social_accounts where sociable_id = 283;
SELECT * FROM opportunities WHERE crm_provider_id = '006O400000E9bzeIAB';
select * from activity_providers where team_id = 65;
SELECT * FROM activities WHERE crm_configuration_id IN (51, 52, 53);
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 65
;
# [PASSWORD_DOTS] STAGING [PASSWORD_DOTS]
SELECT * FROM teams;
SELECT * FROM teams WHERE id = 88;
SELECT * FROM teams WHERE id = 89;
select * from team_settings where team_id = 89;
SELECT * FROM users WHERE team_id = 89;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 89;
select * from users;
SELECT * FROM social_accounts WHERE sociable_id = 1761;
SELECT * FROM crm_configurations WHERE id = 70;
select * from accounts where crm_configuration_id = 70 order by id desc;
select * from leads where crm_configuration_id = 70 order by id desc;
select * from contacts where crm_configuration_id = 70 order by id desc;
select * from opportunities where crm_configuration_id = 70 order by id desc;
select * from crm_profiles where crm_configuration_id = 70 order by id desc;
select * from crm_fields where crm_configuration_id = 70 order by id desc;
select * from crm_field_values where crm_field_id = 3536 order by id desc;
select * from crm_layouts where crm_configuration_id = 70 order by id desc;
select * from stages where crm_configuration_id = 70 order by id desc;
select * from business_processes where crm_configuration_id = 70 order by id desc;
select * from business_process_stages where business_process_id = 34;
select * from contacts where id = 10468;
select * from crm_layouts where crm_configuration_id = 70;
SELECT * FROM crm_layout_entities WHERE crm_layout_id = 388;
SELECT * FROM crm_fields WHERE id IN (3533,3534,3535);
select * from activities where crm_configuration_id = 70
and (account_id IS NOT NULL or lead_id IS NOT NULL or contact_id IS NOT NULL or opportunity_id IS NOT NULL) order by id desc;
SELECT * FROM activities WHERE uuid_to_bin('2e10b60f-8a61-41c5-a3d4-28835353dc65') = uuid;
SELECT * FROM activities where crm_configuration_id = 69 ;
SELECT * FROM users WHERE email LIKE '%[EMAIL]%';
SELECT * FROM activities WHERE uuid_to_bin('5a150c93-40fc-42ec-b3bd-c1d328e09f6e') = uuid;
SELECT * FROM opportunities WHERE id = 385;
select * from participants p
join activities a on p.activity_id = a.id
where a.crm_configuration_id = 70
and (p.lead_id IS NOT NULL or p.contact_id IS NOT NULL);
SELECT * FROM participants WHERE id = 1013638;
select * from teams where id = 90;
select * from users where team_id = 90;
select * from social_accounts where social_accounts.sociable_id IN (1960,1760);
SELECT * FROM crm_profiles WHERE crm_configuration_id = 71;
select * from invitations where team_id = 90;
select * from crm_configurations where id = 71;
select * from accounts where crm_configuration_id = 71 order by id desc;
select * from leads where crm_configuration_id = 71 order by id desc;
select * from contacts where crm_configuration_id = 71 order by id desc;
select * from opportunities where crm_configuration_id = 71 order by id desc;
select * from crm_profiles where crm_configuration_id = 71 order by id desc;
select * from crm_fields where crm_configuration_id = 71 order by id desc;
select * from crm_field_values where crm_field_id = 3341 order by id desc;
select * from crm_layouts where crm_configuration_id = 71 order by id desc;
select * from stages where crm_configuration_id = 71 order by id desc;
select * from users order by secondary_email desc;
select u.id, u.email, u.status, sa.id, sa.provider_user_id from social_accounts sa
join users u on sa.sociable_id = u.id
where sa.provider = 'google' and u.email LIKE 'aneliya%';
select * from failed_jobs order by id desc;
select * from users where email = '[EMAIL]' or secondary_email = '[EMAIL]';
select * from teams;
SELECT * FROM crm_profiles WHERE crm_configuration_id = 39;
SELECT * FROM crm_fields WHERE crm_configuration_id = 39 and object_type = 'task';
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 1
and sa.provider = 'salesforce';
# [PASSWORD_DOTS]
SELECT * FROM activities WHERE uuid_to_bin('c38b3895-fd0f-4b1f-9fb2-c170dba137c6') = uuid;
SELECT * FROM crm_configurations WHERE id = 70;
select * from teams where id = 1;
select * from groups where team_id = 1;
select * from users where team_id = 1;
select o.id, o.name,o.close_date, u.id, u.name, u.group_id, r.id, r.display_name, g.name, g.scope from opportunities o
join users u on o.user_id = u.id
join groups g on u.group_id = g.id
join role_user ru on u.id = ru.user_id
join roles r on ru.role_id = r.id
where o.crm_configuration_id = 39 and close_date > '2024-01-01 00:00:00';
select * from role_user where user_id = 143;
select * from roles;
select * from role_user;
select * from groups where id = 9;
select * from scope_groups where group_id = 9;
# [PASSWORD_DOTS]
select * from teams where id = 36;
select * from crm_configurations;
SELECT * FROM social_accounts WHERE sociable_id = 121;
[URL_WITH_CREDENTIALS] this will add filter, however if we need to control feature by FF we need conditional logic
public const array TYPES = [
['id' => 'exec_summary', 'name' => 'Exec Summary'],
['id' => 'coaching_profiles', 'name' => 'Coaching Profiles'],
['id' => 'product_feedback', 'name' => 'Product Feedback'],
['id' => self::TYPE_LOSS_ANALYSIS, 'name' => 'Loss Analysis'],
// ['id' => 'questions', 'name' => 'Questions'],
// ['id' => 'statistical_quant', 'name' => 'Statistical Quantitative'],
];
public const array ALL_TYPES = [
...self::TYPES,
['id' => self::TYPE_ASK_JIMINNY, 'name' => 'Ask Jiminny'],
];
public const string FREQUENCY_DAILY = 'daily';
public const string FREQUENCY_WEEKLY = 'weekly';
public const string FREQUENCY_MONTHLY = 'monthly';
public const string FREQUENCY_QUARTERLY = 'quarterly';
public const string FREQUENCY_ONE_OFF = 'one_off';
/**
* Frequencies for standard (non-Ask Jiminny) reports.
*/
public const array FREQUENCIES = [
['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],
['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],
['id' => self::FREQUENCY_QUARTERLY, 'name' => 'Quarterly'],
['id' => self::FREQUENCY_ONE_OFF, 'name' => 'One-off'],
];
/**
* Frequencies for Ask Jiminny reports.
*/
public const array ASK_JIMINNY_FREQUENCIES = [
['id' => self::FREQUENCY_DAILY, 'name' => 'Daily'],
['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],
['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],
];
public const string MEDIA_TYPE_PDF = 'pdf';
public const string MEDIA_TYPE_PODCAST = 'podcast';
public const array MEDIA_TYPES = [self::MEDIA_TYPE_PDF, self::MEDIA_TYPE_PODCAST];
public const array MEDIA_TYPE_OBJECT_PDF = ['id' => self::MEDIA_TYPE_PDF, 'name' => 'PDF'];
public const array MEDIA_TYPE_OBJECT_PODCAST = ['id' => self::MEDIA_TYPE_PODCAST, 'name' => 'Podcast'];
public const array MEDIA_TYPE_OBJECTS = [self::MEDIA_TYPE_OBJECT_PDF, self::MEDIA_TYPE_OBJECT_PODCAST];
public const array CALL_TYPE_CONFERENCE = ['id' => 'conference', 'name' => 'Conference'];
public const array CALL_TYPE_DIALER = ['id' => 'dialer', 'name' => 'Dialer'];
public const int SENT_REPORT_AT_HOURS = 5;
public const string PDF_KEY = 'pdf';
public const string AUDIO_KEY = 'audio';
private const array ALL_FREQUENCIES = [
['id' => self::FREQUENCY_DAILY, 'name' => 'Daily'],
['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],
['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],
['id' => self::FREQUENCY_QUARTERLY, 'name' => 'Quarterly'],
['id' => self::FREQUENCY_ONE_OFF, 'name' => 'One-off'],
];
private const string S3_DIR = 'reports';
private const array FILE_EXTENSIONS_VARIANTS = ['html', 'MD', 'pdf'];
private const array FILE_PODCAST_EXTENSIONS_VARIANTS = ['json', 'mp3', 'ssml'];
public function __construct(
private readonly TeamRepository $teamRepository,
private readonly GroupRepository $groupRepository,
private readonly UserRepository $userRepository,
private readonly StageRepository $stageRepository,
private readonly DealStagesService $dealStagesService,
private readonly RecipientsService $recipientsService,
private readonly AutomatedReportsRepository $automatedReportsRepository,
private readonly Webhook $webhookService,
private readonly BusDispatcher $dispatcher,
private readonly ActivityTypeService $activityTypeService,
private readonly PlaybookCategoryRepository $playbookCategoryRepository,
private readonly AskAnythingPromptService $askAnythingPromptService,
private readonly SearchRepository $activitySearchRepository,
private readonly AskAnythingRepository $askAnythingRepository,
) {
}
public static function getTypes(): array
{
$types = self::TYPES;
return array_map(static function ($type) {
return $type['id'];
}, $types);
}
public static function getCallTypes(): array
{
return array_map(static function ($callType) {
return $callType['id'];
}, [self::CALL_TYPE_CONFERENCE, self::CALL_TYPE_DIALER]);
}
public static function getFrequencies(): array
{
return array_map(static function ($frequency) {
return $frequency['id'];
}, self::FREQUENCIES);
}
// front-facing structure
public function getReportEnabledFieldData(bool $value = false): array
{
return [
'id' => 'report_enabled',
'label' => '',
'inputType' => InputTypeEnum::TOGGLE,
'value' => $value,
];
}
// Organizations = Teams
public function getOrganizationFieldData(?string $value = null, bool $shortVersion = false): array
{
$options = $this->getTeams();
if ($shortVersion) {
return [
'id' => 'organization',
'label' => 'Organization',
'options' => $options,
];
}
return [
'id' => 'organization',
'label' => 'Organization',
'inputType' => InputTypeEnum::DROPDOWN,
'required' => true,
'placeholder' => 'Select',
'options' => $options,
'value' => $value,
'dependencies' => [
'teams',
'deal_stage_at_call',
'current_deal_stage',
'recipients',
ActivityTypeService::PLAYBOOK_CATEGORIES_KEY,
],
'dependsOn' => [],
];
}
// Teams = Groups
public function getTeamFieldData(array $options = [], array $value = [], bool $shortVersion = false): array
{
if ($shortVersion) {
return [
'id' => 'teams',
'label' => 'Team',
'options' => $options,
];
}
return [
'id' => 'teams',
'label' => 'Team',
'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,
'required' => false,
'placeholder' => 'Select',
'options' => $options,
'value' => $value, // value should be an array of objects {id, name}
'dependencies' => [ActivityTypeService::PLAYBOOK_CATEGORIES_KEY],
'dependsOn' => [],
];
}
public function getReportTypeFieldData(?string $value = null, bool $shortVersion = false, ?Team $team = null): array
{
$types = [];
if ($team instanceof Team) {
if ($team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {
$types = self::TYPES;
}
if ($team->hasFeature(FeatureEnum::ASK_JIMINNY_REPORTS)) {
$types[] = ['id' => self::TYPE_ASK_JIMINNY, 'name' => 'Ask Jiminny'];
}
} else {
$types = self::TYPES;
}
if ($shortVersion) {
return [
'id' => 'report_type',
'label' => 'Report Type',
'options' => $types,
];
}
return [
'id' => 'report_type',
'label' => 'Report Type',
'inputType' => InputTypeEnum::DROPDOWN,
'required' => true,
'placeholder' => 'Select',
'options' => $types,
'value' => $value,
'dependencies' => [],
'dependsOn' => [],
];
}
public function getFrequencyFieldData(?string $value = null): array
{
return [
'id' => 'frequency',
'label' => 'Frequency',
'inputType' => InputTypeEnum::DROPDOWN,
'required' => true,
'placeholder' => 'Select',
'options' => self::FREQUENCIES,
'value' => $value,
'dependencies' => ['period'],
'dependsOn' => [],
];
}
public function getPeriodFieldData(?string $valueStartDate = null, ?string $valueEndDate = null): array
{
return [
'id' => 'period',
'label' => 'Select one-off period',
'inputType' => InputTypeEnum::DATE_RANGE,
'required' => true,
'placeholder' => 'Select',
'value' => ['startDate' => $valueStartDate, 'endDate' => $valueEndDate],
'queryParams' => [
'startDate' => 'start_date_period',
'endDate' => 'end_date_period',
],
'dependencies' => [],
'dependsOn' => ['frequency'],
];
}
public function getActivityTypesFieldData(?Team $team = null, array $value = [], array $teamsFilter = []): array
{
return $this->activityTypeService->getActivityTypeFieldData(team: $team, value: $value, groupIds: $teamsFilter);
}
public function getDealStageAtCallFieldData(?Team $team = null, array $value = []): array
{
return $this->dealStagesService->getDealStageAtCallFieldData(team: $team, value: $value);
}
public function getCurrentDealStageFieldData(?Team $team = null, array $value = []): array
{
return $this->dealStagesService->getCurrentDealStageFieldData(team: $team, value: $value);
}
public function getDealValueFieldData(?int $valueMin = null, ?int $valueMax = null): array
{
return [
'id' => 'deal_value',
'label' => 'Deal Value',
'inputType' => InputTypeEnum::INTEGER_RANGE,
'required' => false,
'value' => ['min' => $valueMin, 'max' => $valueMax],
'queryParams' => [
'min' => 'min_deal_value',
'max' => 'max_deal_value',
],
'dependencies' => [],
'dependsOn' => [],
];
}
public function getCallTypeFieldData(bool $conferenceOn = false, bool $dialerOn = false): array
{
$value = [];
$conferenceOn && $value[] = self::CALL_TYPE_CONFERENCE;
$dialerOn && $value[] = self::CALL_TYPE_DIALER;
return [
'id' => 'call_type',
'label' => 'Call Type',
'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,
'required' => true,
'options' => [
self::CALL_TYPE_CONFERENCE,
self::CALL_TYPE_DIALER,
],
'value' => $value,
'dependencies' => [],
'dependsOn' => [],
];
}
public function getMediaTypeFieldData(?AutomatedReport $report = null): array
{
$value = [];
if ($report) {
$value = $this->transformMediaTypes($report);
}
return [
'id' => 'media_types',
'label' => 'Export as',
'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,
'required' => true,
'options' => self::MEDIA_TYPE_OBJECTS,
'value' => $value,
'dependencies' => [],
'dependsOn' => [],
];
}
public function getCallDurationFieldData(?int $valueMin = null, ?int $valueMax = null): array
{
return [
'id' => 'call_duration',
'label' => 'Call Duration',
'inputType' => InputTypeEnum::INTEGER_RANGE,
'required' => false,
'value' => ['min' => $valueMin, 'max' => $valueMax],
'queryParams' => [
'min' => 'min_call_duration',
'max' => 'max_call_duration',
],
'dependencies' => [],
'dependsOn' => [],
];
}
public function getRecipientsFieldData(?Team $team = null, array $value = []): array
{
return $this->recipientsService->getRecipientsFieldData(team: $team, value: $value);
}
public function getJiminnyRecipientsFieldData(array $value = []): array
{
return $this->recipientsService->getJiminnyRecipientsFieldData($value);
}
public function getAdditionalPromptInputFieldData(?string $value = null): array
{
return [
'id' => 'additional_prompt_input',
'label' => 'Special requirements',
'inputType' => InputTypeEnum::TEXTAREA,
'required' => false,
'placeholder' => 'What should be the focus of the report?',
'value' => $value,
'dependencies' => [],
'dependsOn' => [],
];
}
public function getCustomReportNameFieldData(?string $value = null): array
{
return [
'id' => 'custom_name',
'label' => 'Custom report name',
'inputType' => InputTypeEnum::TEXT,
'required' => false,
'placeholder' => 'Enter custom name',
'value' => $value,
'dependencies' => [],
'dependsOn' => [],
];
}
// data providers
public function getTeams(): array
{
$teams = $this->teamRepository->getTeamsForKiosk(status: Team::STATUS_ACTIVE);
$teamData = [];
foreach ($teams as $team) {
if (! $team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {
continue;
}
$teamData[] = $this->transformTeam($team);
}
return $teamData;
}
public function getTeamGroups(string $teamUuid): array
{
$data = [];
$team = $this->getTeam($teamUuid);
if ($team !== null) {
$groups = $team->groups()->get();
foreach ($groups as $group) {
$data[] = [
'id' => $group->getUuid(),
'name' => $group->getName(),
];
}
}
return $data;
}
public function getTeamsGroupsOptions(array $filterTeamUuids = []): array
{
$data = [];
$teams = $this->getTeams();
foreach ($teams as $team) {
if (! empty($filterTeamUuids) && ! in_array($team['id'], $filterTeamUuids, true)) {
continue;
}
$data[] = [
'label' => $team['name'],
'groups' => $this->getTeamGroups($team['id']),
];
}
return $data;
}
public function getTeam(string $teamUuid): ?Team
{
return $this->teamRepository->idOrUuid($teamUuid);
}
public function getTeamById(int $teamId): ?Team
{
return $this->teamRepository->find($teamId);
}
public function getGroupsUuids(AutomatedReport $report): array
{
$uuids = [];
$reportGroups = $report->getGroups();
foreach ($reportGroups as $groupId) {
if ($group = $this->groupRepository->find($groupId)) {
$uuids[] = $group->getUuid();
}
}
return $uuids;
}
public function getPlaybookCategoriesUuids(AutomatedReport $report): array
{
$uuids = [];
$playbookCategories = $report->getPlaybookCategories();
foreach ($playbookCategories as $id) {
if ($category = $this->playbookCategoryRepository->find($id)) {
$uuids[] = $category->getUuid();
}
}
return $uuids;
}
public function getDealAtCallStagesUuids(AutomatedReport $report): array
{
$uuids = [];
$reportStages = $report->getDealAtCallStages();
foreach ($reportStages as $id) {
if ($stage = $this->stageRepository->find($id)) {
$uuids[] = $stage->getUuid();
}
}
return $uuids;
}
public function getCurrentDealStagesUuids(AutomatedReport $report): array
{
$uuids = [];
$reportStages = $report->getCurrentDealStages();
foreach ($reportStages as $id) {
if ($stage = $this->stageRepository->find($id)) {
$uuids[] = $stage->getUuid();
}
}
return $uuids;
}
public function getUsersUuids(AutomatedReport $report): array
{
return $this->extractUserUuids($report->getRecipients());
}
public function getJiminnyUsersUuids(AutomatedReport $report): array
{
return $this->extractUserUuids($report->getJiminnyRecipients());
}
/**
* @param array<string, mixed> $recipients
*/
private function extractUserUuids(array $recipients): array
{
$userIds = $recipients['users'] ?? [];
return collect($userIds)
->map(fn ($id) => $this->userRepository->find((int) $id))
->filter()
->map(fn (UserContract $user) => $user->getUuid())
->values()
->all();
}
// get mail data
public function getRecipientUsers(AutomatedReport $report): array
{
return $this->buildRecipientUsers($report->getRecipients());
}
private function getJiminnyRecipientUsers(AutomatedReport $report): array
{
return $this->buildRecipientUsers($report->getJiminnyRecipients());
}
/**
* @param array<string, mixed> $recipients
*/
private function buildRecipientUsers(array $recipients): array
{
$userIds = $recipients['users'] ?? [];
return collect($userIds)
->map(fn ($id) => $this->userRepository->find((int) $id))
->filter()
->map(fn (UserContract $user) => [
'email' => $user->getEmailAddress(),
'name' => $user->getName(),
'timezone' => $user->getTimezone()->getName(),
])
->values()
->all();
}
public function getValidRecipientUsers(AutomatedReport $report, bool $includeJiminny = false): array
{
if ($report->isAskJiminnyReport()) {
$recipients = $this->resolveAskJiminnyRecipients($report);
} else {
$recipients = $this->getRecipientUsers($report);
if ($includeJiminny) {
$recipients = array_merge($recipients, $this->getJiminnyRecipientUsers($report));
}
}
$emails = [];
return array_values(array_filter(
$recipients,
static function ($recipient) use (&$emails) {
if (empty($recipient['email']) || in_array($recipient['email'], $emails, true)) {
return false;
}
$emails[] = $recipient['email'];
return true;
}
));
}
private function resolveAskJiminnyRecipients(AutomatedReport $report): array
{
$recipients = [];
$creator = $report->getCreator();
if ($creator !== null) {
$recipients[] = [
'email' => $creator->getEmailAddress(),
'name' => $creator->getName(),
'timezone' => $creator->getTimezone()->getName(),
];
}
return array_merge(
$recipients,
$this->buildRecipientUsers($report->getRecipients()),
$this->getGroupRecipientUsers($report),
);
}
private function getGroupRecipientUsers(AutomatedReport $report): array
{
$users = [];
foreach ($report->getGroups() as $groupId) {
$group = $this->groupRepository->find($groupId);
if ($group === null) {
continue;
}
foreach ($group->getMembers() as $member) {
$users[] = [
'email' => $member->getEmailAddress(),
'name' => $member->getName(),
'timezone' => $member->getTimezone()->getName(),
];
}
}
return $users;
}
public function getReportTypeName(AutomatedReportResult $report): string
{
$type = $report->getReport()->getType();
$getType = $this->transformReportType($type);
return $getType['name'];
}
public function getReportPeriodName(AutomatedReportResult $report): string
{
$from = $report->getFromDate();
$to = $report->getToDate();
$frequency = $report->getReport()->getFrequency();
if ($from === null || $to === null) {
if (! $report->getReport()->isAskJiminnyReport()) {
$invalidPeriod = $from === null ? 'from' : 'to';
throw new ApplicationException('Report period is invalid: ' . $invalidPeriod);
}
$period = $this->calculateFromAndToDatePeriod($frequency);
$from = $period['fromDate'];
$to = $period['toDate'];
}
return $this->formatReportPeriodName($frequency, $from, $to);
}
private function formatReportPeriodName(string $frequency, Carbon $from, Carbon $to): string
{
$fromYear = $from->format('Y');
$toYear = $to->format('Y');
$differentYears = $fromYear !== $toYear;
switch ($frequency) {
case self::FREQUENCY_DAILY:
return $from->format('j M Y');
case self::FREQUENCY_QUARTERLY:
// 'Jan-Mar 2025' or 'Nov 2024-Jan 2025' if years differ
$startMonth = $from->format('M');
$endMonth = $to->copy()->subMonth();
$endMonthName = $endMonth->format('M');
$endMonthYear = $endMonth->format('Y');
if ($differentYears) {
return "{$startMonth} {$fromYear} - {$endMonthName} {$endMonthYear}";
}
return "{$startMonth} - {$endMonthName} {$toYear}";
case self::FREQUENCY_MONTHLY:
// 'May 2025' - monthly reports are always within the same year
return $from->format('M Y');
case self::FREQUENCY_WEEKLY:
// '4 - 8 Aug 2025', '27 Oct - 3 Nov 2025', or '28 Dec 2024 - 3 Jan 2025' if years differ
$startDay = $from->format('j');
$endDay = $to->format('j');
$startMonth = $from->format('M');
$endMonth = $to->format('M');
if ($differentYears) {
return "{$startDay} {$startMonth} {$fromYear} - {$endDay} {$endMonth} {$toYear}";
}
if ($startMonth !== $endMonth) {
return "{$startDay} {$startMonth} - {$endDay} {$endMonth} {$toYear}";
}
return "{$startDay} - {$endDay} {$endMonth} {$toYear}";
case self::FREQUENCY_ONE_OFF:
// '2 May-31 May 2025' or '15 Dec 2024-15 Jan 2025' if years differ
$startDay = $from->format('j');
$startMonth = $from->format('M');
$endDay = $to->format('j');
$endMonth = $to->format('M');
// If same month and year, use a format like '2-31 May 2025'
if ($startMonth === $endMonth && ! $differentYears) {
return "{$startDay} - {$endDay} {$startMonth} {$toYear}";
}
// If different years, include both years
if ($differentYears) {
return "{$startDay} {$startMonth} {$fromYear} - {$endDay} {$endMonth} {$toYear}";
}
// Same year but different months
return "{$startDay} {$startMonth} - {$endDay} {$endMonth} {$toYear}";
default:
// Default format for unknown frequencies
return $from->format('j M Y') . ' - ' . $to->format('j M Y');
}
}
public function getReportTeamsName(AutomatedReportResult $report): string
{
$groups = $report->getGroups();
if (empty($groups)) {
return 'All';
}
// Get group names from repository
$groupNames = [];
foreach ($groups as $groupId) {
$group = $this->groupRepository->find($groupId);
if ($group) {
$groupNames[] = $group->getName();
}
}
if (count($groupNames) === 1) {
// Single team format
$teamsName = $groupNames[0];
} else {
// Multiple teams format
$teamsName = implode(', ', $groupNames);
}
return $teamsName;
}
public function getReportFileName(AutomatedReportResult $report): string
...
|
NULL
|
|
12369
|
266
|
9
|
2026-04-14T11:16:16.044002+00:00
|
/Users/lukas/.screenpipe/data/data/2026-04-14/1776 /Users/lukas/.screenpipe/data/data/2026-04-14/1776165376044_m1.jpg...
|
NULL
|
NULL
|
1
|
NULL
|
monitor_1
|
NULL
|
NULL
|
NULL
|
NULL
|
SlackFileEdit ViewGoHistoryWindowHelpec2-userGDOCK SlackFileEdit ViewGoHistoryWindowHelpec2-userGDOCKER981DEV (docker)882APP (-zsh)[EMAIL]@73b64f5d54a3:/home/jiminny#[ec2-user@ip-10-30-93-249~]$ dockerexec -it $(dockny && bash"root@c78a087b1345:/home/Jiminny# php artisan automated-reports[2026-04-14 10:46:08] staging.INF0: [automated-reports] Started{"correlation_id":"5[2026-04-1410:46:08Jstaging. INFO: [automated-reports]id":"5c23e861-2ca9-4f92-9f67-773d6bc80ca0"Checking conditions {"isMonda,"trace_id" :"185df6f6-4327-4609-9c2e-2ab83a[2026-04-14 10:46:08]staging.INFO: [automated-reports] Processing daily reports {"cab83a0f5432"}[2026-04-1410:46:08]9-9c2e-2ab83a0f5432"}staging.INFO: [automated-reports]Found 3 daily reports to proc[2026-04-1410:46:087daily"staging.INFO: [automated-reports]Dispatching Generate Report j,"type":"ask_jiminny"} {"correlation_id":"5c23e861-2ca9-4f92-9f67-773d6bc80ca0"[2026-04-14 10:46:08]staging.INFO: [automated-reports]Dispatching Generate Report jdaily", "type": "ask_jiminny"} {"correlation_id":"5c23e861-2ca9-4f92-9f67-773d6bc80cab"[2026-04-14 10:46:08]staging. INFO: [automated-reports]daily'", "type" "ask-fiminny"'} ("correlation-id' : 5c2se861-2ca -4792-9f87-773 Be8oca[2026-04-14 10:46:08]staging.INFO: [automated-reports]Completed{"correlation_id":root@c78a087b1345:/home/jiminny# phpartisanautomated-reports --report-id 35[2026-04-14 10:48:42] staging.INFO: [automated-reports]{"correlation_id":"2[2026-04-14 10:48:42]staging.INFO: [automated-reports]Checking conditions {"isMondaid":"246a1ala-7076-458c-bd7d-49d2f5a2db88","trace_id":"1f894bf6-e50d-4e99-b635-2aa526[2026-04-14 10:48:42]staging.INFO: [automated-reports]Processing daily reportsaa52627fc27"}[automated-reports] Automated reportfound Test 6[2026-04-14 10:48:42]staging.INFO: [automated-reports] Found 1 daily reports to proc9-b635-2aa52627f c27"}[2026-04-14 10:48:42]staging.INF0: [automated-reports]Dispatching Generate Reportdaily","type": "ask_jiminny"} {"correlation_id":"246a1a1a-7076-458c-bd7d-49d2f5a2db88"[2026-04-14 10:48:42]staging.INFO: [automated-reports]Completed{"correlation_id":root@c78a087b1345:/home/jiminny# [ec2-user@ip-10-30-93-249 ~]$I+EDHomeDMsActivityFilesLater.*•More(ahlJiminny ...+tscnicrel# infra-changes# jiminny-bg# platform-tickets# product_launches# random# releases# sofia-office# support# thank-yous# the_people_of jimi...Direct messagesE. Vasil VasilevAneliya Angelova, ...Steliyan GeorgievAdelina Petrova, Ili...0. Adelina Petrova. Galya Dimitrova&s Nikolay Nikolov "2 Galya Dimitrova, Ni...2Galya Dimitrova, Ni...P. Nikolay Yankov::: AppsJira CloudToastGoogle Cale...• Support Daily - in 44 m100% 147Tue 14 Apr 14:16:15→Search Jiminny IncVasil Vasilev• Messages(Add canvasC Files< Pins+синхрониThursday, April 9th~Lukas Kovalik 12:11 PMГоТОвоVasil Vasilev 12:11 PMблагодаряToday ~Vasil Vasilev 2:01 PMЛукаш приветSaved for later • Due in 3 hoursможе ли да разглдаш този ПР като имашмалко време:https://github.com/jiminny/app/pull/11949повечето промени са семантични, не сафункционалниразделям по голям ПР на две частиLukas Kovalik 2:15 PMздрасти, да ще го погледна по-кьсноспешно ли еVasil Vasilev 2:15 PMмерсине е спешноNewпросто искам да го разкарам, за да сиотпуша следващия ПРMessage Vasil Vasilev+Aa...
|
NULL
|
-1778708762533742682
|
NULL
|
click
|
ocr
|
NULL
|
SlackFileEdit ViewGoHistoryWindowHelpec2-userGDOCK SlackFileEdit ViewGoHistoryWindowHelpec2-userGDOCKER981DEV (docker)882APP (-zsh)[EMAIL]@73b64f5d54a3:/home/jiminny#[ec2-user@ip-10-30-93-249~]$ dockerexec -it $(dockny && bash"root@c78a087b1345:/home/Jiminny# php artisan automated-reports[2026-04-14 10:46:08] staging.INF0: [automated-reports] Started{"correlation_id":"5[2026-04-1410:46:08Jstaging. INFO: [automated-reports]id":"5c23e861-2ca9-4f92-9f67-773d6bc80ca0"Checking conditions {"isMonda,"trace_id" :"185df6f6-4327-4609-9c2e-2ab83a[2026-04-14 10:46:08]staging.INFO: [automated-reports] Processing daily reports {"cab83a0f5432"}[2026-04-1410:46:08]9-9c2e-2ab83a0f5432"}staging.INFO: [automated-reports]Found 3 daily reports to proc[2026-04-1410:46:087daily"staging.INFO: [automated-reports]Dispatching Generate Report j,"type":"ask_jiminny"} {"correlation_id":"5c23e861-2ca9-4f92-9f67-773d6bc80ca0"[2026-04-14 10:46:08]staging.INFO: [automated-reports]Dispatching Generate Report jdaily", "type": "ask_jiminny"} {"correlation_id":"5c23e861-2ca9-4f92-9f67-773d6bc80cab"[2026-04-14 10:46:08]staging. INFO: [automated-reports]daily'", "type" "ask-fiminny"'} ("correlation-id' : 5c2se861-2ca -4792-9f87-773 Be8oca[2026-04-14 10:46:08]staging.INFO: [automated-reports]Completed{"correlation_id":root@c78a087b1345:/home/jiminny# phpartisanautomated-reports --report-id 35[2026-04-14 10:48:42] staging.INFO: [automated-reports]{"correlation_id":"2[2026-04-14 10:48:42]staging.INFO: [automated-reports]Checking conditions {"isMondaid":"246a1ala-7076-458c-bd7d-49d2f5a2db88","trace_id":"1f894bf6-e50d-4e99-b635-2aa526[2026-04-14 10:48:42]staging.INFO: [automated-reports]Processing daily reportsaa52627fc27"}[automated-reports] Automated reportfound Test 6[2026-04-14 10:48:42]staging.INFO: [automated-reports] Found 1 daily reports to proc9-b635-2aa52627f c27"}[2026-04-14 10:48:42]staging.INF0: [automated-reports]Dispatching Generate Reportdaily","type": "ask_jiminny"} {"correlation_id":"246a1a1a-7076-458c-bd7d-49d2f5a2db88"[2026-04-14 10:48:42]staging.INFO: [automated-reports]Completed{"correlation_id":root@c78a087b1345:/home/jiminny# [ec2-user@ip-10-30-93-249 ~]$I+EDHomeDMsActivityFilesLater.*•More(ahlJiminny ...+tscnicrel# infra-changes# jiminny-bg# platform-tickets# product_launches# random# releases# sofia-office# support# thank-yous# the_people_of jimi...Direct messagesE. Vasil VasilevAneliya Angelova, ...Steliyan GeorgievAdelina Petrova, Ili...0. Adelina Petrova. Galya Dimitrova&s Nikolay Nikolov "2 Galya Dimitrova, Ni...2Galya Dimitrova, Ni...P. Nikolay Yankov::: AppsJira CloudToastGoogle Cale...• Support Daily - in 44 m100% 147Tue 14 Apr 14:16:15→Search Jiminny IncVasil Vasilev• Messages(Add canvasC Files< Pins+синхрониThursday, April 9th~Lukas Kovalik 12:11 PMГоТОвоVasil Vasilev 12:11 PMблагодаряToday ~Vasil Vasilev 2:01 PMЛукаш приветSaved for later • Due in 3 hoursможе ли да разглдаш този ПР като имашмалко време:https://github.com/jiminny/app/pull/11949повечето промени са семантични, не сафункционалниразделям по голям ПР на две частиLukas Kovalik 2:15 PMздрасти, да ще го погледна по-кьсноспешно ли еVasil Vasilev 2:15 PMмерсине е спешноNewпросто искам да го разкарам, за да сиотпуша следващия ПРMessage Vasil Vasilev+Aa...
|
12368
|
|
12371
|
266
|
10
|
2026-04-14T11:16:21.730423+00:00
|
/Users/lukas/.screenpipe/data/data/2026-04-14/1776 /Users/lukas/.screenpipe/data/data/2026-04-14/1776165381730_m1.jpg...
|
NULL
|
NULL
|
1
|
NULL
|
monitor_1
|
NULL
|
NULL
|
NULL
|
NULL
|
SlackFileEdit ViewGoHistoryWindowHelpec2-userGDOCK SlackFileEdit ViewGoHistoryWindowHelpec2-userGDOCKER- 281DEV (docker)882APP (-zsh)[EMAIL]@73b64f5d54a3:/home/jiminny#[ec2-user@ip-10-30-93-249~]$ dockerexec -it $(dockny && bash"root@c78a087b1345:/home/Jiminny# php artisan automated-reports[2026-04-14 10:46:08] staging.INF0: [automated-reports] Started{"correlation_id":"5[2026-04-1410:46:08Jstaging. INFO: [automated-reports]id":"5c23e861-2ca9-4f92-9f67-773d6bc80ca0"Checking conditions {"isMonda,"trace_id" :"185df6f6-4327-4609-9c2e-2ab83a[2026-04-14 10:46:08]staging.INFO: [automated-reports] Processing daily reports {"cab83a0f5432"}[2026-04-1410:46:08]9-9c2e-2ab83a0f5432"}staging.INFO: [automated-reports]Found 3 daily reports to proc[2026-04-1410:46:087daily"staging.INFO: [automated-reports]Dispatching Generate Report j,"type":"ask_jiminny"} {"correlation_id":"5c23e861-2ca9-4f92-9f67-773d6bc80ca0"[2026-04-14 10:46:08]staging.INFO: [automated-reports]Dispatching Generate Report jdaily", "type": "ask_jiminny"} {"correlation_id":"5c23e861-2ca9-4f92-9f67-773d6bc80cab"[2026-04-14 10:46:08]staging. INFO: [automated-reports]daily'", "type" "ask-fiminny"'} ("correlation-id' : 5c2se861-2ca -4792-9f87-773 Be8oca[2026-04-14 10:46:08]staging.INFO: [automated-reports]Completed{"correlation_id":root@c78a087b1345:/home/jiminny# phpartisanautomated-reports --report-id 35[2026-04-14 10:48:42] staging.INFO: [automated-reports]{"correlation_id":"2[2026-04-14 10:48:42]staging.INFO: [automated-reports]Checking conditions {"isMondaid":"246a1ala-7076-458c-bd7d-49d2f5a2db88","trace_id":"1f894bf6-e50d-4e99-b635-2aa526[2026-04-14 10:48:42]staging.INFO: [automated-reports]Processing daily reportsaa52627fc27"}[automated-reports] Automated reportfound Test 6[2026-04-14 10:48:42]staging.INFO: [automated-reports] Found 1 daily reports to proc9-b635-2aa52627f c27"}[2026-04-14 10:48:42]staging.INF0: [automated-reports]Dispatching Generate Report jdaily","type": "ask_jiminny"} {"correlation_id":"246a1a1a-7076-458c-bd7d-49d2f5a2db88"[2026-04-14 10:48:42]staging.INFO: [automated-reports]Completed{"correlation_id":root@c78a087b1345:/home/jiminny# [ec2-user@ip-10-30-93-249 ~]$I+EDHomeDMsActivityFilesLater.*•More(ahlJiminny ...+tscnicrel# infra-changes# jiminny-bg# platform-tickets# product_launches# random# releases# sofia-office# support# thank-yous# the_people_of jimi...Direct messagesE. Vasil VasilevAneliya Angelova, ...Steliyan SeorgievAdelina Petrova, Ili...0. Adelina Petrova. Galya Dimitrova *Rs Nikolay Nikolov "2Galya Dimitrova, Ni...2Galya Dimitrova, Ni...P. Nikolay Yankov::: AppsJira CloudToastGoogle Cale...• Support Daily - in 44 m100% 147Tue 14 Apr 14:16:21→Search Jiminny IncVasil Vasilev• MessagesTAdd canvasC Files< Pins+синхрониThursday, April 9th~Lukas Kovalik 12:11 PMГоТОвоVasil Vasilev 12:11 PMблагодаряToday ~Vasil Vasilev 2:01 PMЛукаш приветSaved for later • Due in 3 hoursможе ли да разглдаш този ПР като имашмалко време:https://github.com/jiminny/app/pull/11949повечето промени са семантични, не сафункционалниразделям по голям ПР на две частиLukas Kovalik 2:15 PMздрасти, да ще го погледна по-кьсноспешно ли еVasil Vasilev 2:15 PMмерсине е спешноNewпросто искам да го разкарам, за да сиотпуша следващия ПРMessage Vasil Vasilev+Aa...
|
NULL
|
3351454770972159881
|
NULL
|
click
|
ocr
|
NULL
|
SlackFileEdit ViewGoHistoryWindowHelpec2-userGDOCK SlackFileEdit ViewGoHistoryWindowHelpec2-userGDOCKER- 281DEV (docker)882APP (-zsh)[EMAIL]@73b64f5d54a3:/home/jiminny#[ec2-user@ip-10-30-93-249~]$ dockerexec -it $(dockny && bash"root@c78a087b1345:/home/Jiminny# php artisan automated-reports[2026-04-14 10:46:08] staging.INF0: [automated-reports] Started{"correlation_id":"5[2026-04-1410:46:08Jstaging. INFO: [automated-reports]id":"5c23e861-2ca9-4f92-9f67-773d6bc80ca0"Checking conditions {"isMonda,"trace_id" :"185df6f6-4327-4609-9c2e-2ab83a[2026-04-14 10:46:08]staging.INFO: [automated-reports] Processing daily reports {"cab83a0f5432"}[2026-04-1410:46:08]9-9c2e-2ab83a0f5432"}staging.INFO: [automated-reports]Found 3 daily reports to proc[2026-04-1410:46:087daily"staging.INFO: [automated-reports]Dispatching Generate Report j,"type":"ask_jiminny"} {"correlation_id":"5c23e861-2ca9-4f92-9f67-773d6bc80ca0"[2026-04-14 10:46:08]staging.INFO: [automated-reports]Dispatching Generate Report jdaily", "type": "ask_jiminny"} {"correlation_id":"5c23e861-2ca9-4f92-9f67-773d6bc80cab"[2026-04-14 10:46:08]staging. INFO: [automated-reports]daily'", "type" "ask-fiminny"'} ("correlation-id' : 5c2se861-2ca -4792-9f87-773 Be8oca[2026-04-14 10:46:08]staging.INFO: [automated-reports]Completed{"correlation_id":root@c78a087b1345:/home/jiminny# phpartisanautomated-reports --report-id 35[2026-04-14 10:48:42] staging.INFO: [automated-reports]{"correlation_id":"2[2026-04-14 10:48:42]staging.INFO: [automated-reports]Checking conditions {"isMondaid":"246a1ala-7076-458c-bd7d-49d2f5a2db88","trace_id":"1f894bf6-e50d-4e99-b635-2aa526[2026-04-14 10:48:42]staging.INFO: [automated-reports]Processing daily reportsaa52627fc27"}[automated-reports] Automated reportfound Test 6[2026-04-14 10:48:42]staging.INFO: [automated-reports] Found 1 daily reports to proc9-b635-2aa52627f c27"}[2026-04-14 10:48:42]staging.INF0: [automated-reports]Dispatching Generate Report jdaily","type": "ask_jiminny"} {"correlation_id":"246a1a1a-7076-458c-bd7d-49d2f5a2db88"[2026-04-14 10:48:42]staging.INFO: [automated-reports]Completed{"correlation_id":root@c78a087b1345:/home/jiminny# [ec2-user@ip-10-30-93-249 ~]$I+EDHomeDMsActivityFilesLater.*•More(ahlJiminny ...+tscnicrel# infra-changes# jiminny-bg# platform-tickets# product_launches# random# releases# sofia-office# support# thank-yous# the_people_of jimi...Direct messagesE. Vasil VasilevAneliya Angelova, ...Steliyan SeorgievAdelina Petrova, Ili...0. Adelina Petrova. Galya Dimitrova *Rs Nikolay Nikolov "2Galya Dimitrova, Ni...2Galya Dimitrova, Ni...P. Nikolay Yankov::: AppsJira CloudToastGoogle Cale...• Support Daily - in 44 m100% 147Tue 14 Apr 14:16:21→Search Jiminny IncVasil Vasilev• MessagesTAdd canvasC Files< Pins+синхрониThursday, April 9th~Lukas Kovalik 12:11 PMГоТОвоVasil Vasilev 12:11 PMблагодаряToday ~Vasil Vasilev 2:01 PMЛукаш приветSaved for later • Due in 3 hoursможе ли да разглдаш този ПР като имашмалко време:https://github.com/jiminny/app/pull/11949повечето промени са семантични, не сафункционалниразделям по голям ПР на две частиLukas Kovalik 2:15 PMздрасти, да ще го погледна по-кьсноспешно ли еVasil Vasilev 2:15 PMмерсине е спешноNewпросто искам да го разкарам, за да сиотпуша следващия ПРMessage Vasil Vasilev+Aa...
|
NULL
|
|
12373
|
266
|
11
|
2026-04-14T11:16:23.183755+00:00
|
/Users/lukas/.screenpipe/data/data/2026-04-14/1776 /Users/lukas/.screenpipe/data/data/2026-04-14/1776165383183_m1.jpg...
|
NULL
|
NULL
|
1
|
NULL
|
monitor_1
|
NULL
|
NULL
|
NULL
|
NULL
|
SlackFileEditViewGoHistoryWindowHelpec2-userGDOCKE SlackFileEditViewGoHistoryWindowHelpec2-userGDOCKER-₴81DEV (docker)882APP (-zsh)[EMAIL]@73b64f5d54a3:/home/jiminny#[ec2-user@ip-10-30-93-249 ~]$ dockerexec -it $(dockny && bash"root@c78a087b1345:/home/Jiminny# php artisan automated-reports[2026-04-14 10:46:08] staging.INF0: [automated-reports] Started{"correlation_id":"5[2026-04-1410:46:08]staging.INFO: [automated-reports] Checking conditions {"isMondaid":"5c23e861-2ca9-4f92-9f67-773d6bc80ca0","trace_id" :"185df6f6-4327-4609-9cZe-2ab83a[2026-04-14 10:46:08]ab83a0f5432"}staging. INFO: [automated-reports] Processing daily reports{"c[2026-04-1410:46:08]9-9c2e-2ab83a0f5432"}staging.INFO: [automated-reports]Found 3 daily reports to proc[2026-04-1410:46:087daily"staging.INFO: [automated-reports]Dispatching Generate Report j,"type":"ask_jiminny"} {"correlation_id":"5c23e861-2ca9-4f92-9f67-773d6bc80ca®"[2026-04-14 10:46:08]staging.INFO: [automated-reports]Dispatching Generate Report jdaily", "type": "ask_jiminny"} {"correlation_id":"5c23e861-2ca9-4f92-9f67-773d6bc80cab"[2026-04-14 10:46:08]staging. INFO: [automated-reports]daily'", "type" "ask-fiminny"'} ("correlation-id' : 5c2se861-2ca -4792-9f87-773 e8oca[2026-04-14 10:46:08]staging.INFO: [automated-reports]Completed{"correlation_id":root@c78a087b1345:/home/jiminny# phpartisanautomated-reports --report-id 35[2026-04-14 10:48:42] staging.INFO: [automated-reports]Started{"correlation_id":"2[2026-04-14 10:48:42]staging.INFO: [automated-reports]Checking conditions {"isMondaid":"246alala-7076-458c-bd7d-49d2f5a2db88","trace_id":"1f894bf6-e50d-4e99-b635-2aa526[2026-04-14 10:48:42]staging.INFO: [automated-reports]Processing daily reports{"caa52627fc27"}[automated-reports] Automated report[2026-04-14 10:48:42]staging.INFO: [automated-reports] Found 1 daily reports to proc9-b635-2aa52627f c27"}[2026-04-14 10:48:42]staging.INF0: [automated-reports]Dispatching Generate Reportdaily","type": "ask_jiminny"} {"correlation_id":"246a1a1a-7076-458c-bd7d-49d2f5a2db88"[2026-04-14 10:48:42]staging.INFO: [automated-reports]Completed{"correlation_id":root@c78a087b1345:/home/jiminny# [ec2-user@ip-10-30-93-249 ~]$I+HomeDMsActivityFilesLater.*•MorelhlJiminny ...+tscnicrol# infra-changes# jiminny-bg# platform-tickets# product_launches# random# releases# sofia-office# support# thank-yous# the_people_of jimi...Aneliya Angelova, NikolayYankov, Steliyan GeorgievAneliya,Angel...Steliyan GeorgievAdelina Petrova, Ili...0. Adelina Petrova. Galya Dimitrova *&s Nikolay Nikolov "2Galya Dimitrova, Ni...2Galya Dimitrova, Ni...P. Nikolay Yankov::: AppsJira CloudToastGoogle Cale...§ Support Daily • in 44 m100% <Tue 14 Apr 14:16:22→Search Jiminny IncThread Direct message with 3 othersвчера, не днес• и имейл не дойдеimage.png• • 8.5 repliesLukas Kovalik 18 minutes agoза дата там не знам как искаме да го правим.по принцип при всички други се гледа ден назад при положение че идва през нощта.Nikolay Yankov 18 minutes ago@Lukas Kovalik видя ли този коментарLukas Kovalik 18 minutes agoдаNikolay Yankov 17 minutes agoне е ли датата на която е генерирано? (edited)Lukas Kovalik 17 minutes agoemail ще го видяReply...Also send to the group+•*•...
|
NULL
|
586301804903477482
|
NULL
|
visual_change
|
ocr
|
NULL
|
SlackFileEditViewGoHistoryWindowHelpec2-userGDOCKE SlackFileEditViewGoHistoryWindowHelpec2-userGDOCKER-₴81DEV (docker)882APP (-zsh)[EMAIL]@73b64f5d54a3:/home/jiminny#[ec2-user@ip-10-30-93-249 ~]$ dockerexec -it $(dockny && bash"root@c78a087b1345:/home/Jiminny# php artisan automated-reports[2026-04-14 10:46:08] staging.INF0: [automated-reports] Started{"correlation_id":"5[2026-04-1410:46:08]staging.INFO: [automated-reports] Checking conditions {"isMondaid":"5c23e861-2ca9-4f92-9f67-773d6bc80ca0","trace_id" :"185df6f6-4327-4609-9cZe-2ab83a[2026-04-14 10:46:08]ab83a0f5432"}staging. INFO: [automated-reports] Processing daily reports{"c[2026-04-1410:46:08]9-9c2e-2ab83a0f5432"}staging.INFO: [automated-reports]Found 3 daily reports to proc[2026-04-1410:46:087daily"staging.INFO: [automated-reports]Dispatching Generate Report j,"type":"ask_jiminny"} {"correlation_id":"5c23e861-2ca9-4f92-9f67-773d6bc80ca®"[2026-04-14 10:46:08]staging.INFO: [automated-reports]Dispatching Generate Report jdaily", "type": "ask_jiminny"} {"correlation_id":"5c23e861-2ca9-4f92-9f67-773d6bc80cab"[2026-04-14 10:46:08]staging. INFO: [automated-reports]daily'", "type" "ask-fiminny"'} ("correlation-id' : 5c2se861-2ca -4792-9f87-773 e8oca[2026-04-14 10:46:08]staging.INFO: [automated-reports]Completed{"correlation_id":root@c78a087b1345:/home/jiminny# phpartisanautomated-reports --report-id 35[2026-04-14 10:48:42] staging.INFO: [automated-reports]Started{"correlation_id":"2[2026-04-14 10:48:42]staging.INFO: [automated-reports]Checking conditions {"isMondaid":"246alala-7076-458c-bd7d-49d2f5a2db88","trace_id":"1f894bf6-e50d-4e99-b635-2aa526[2026-04-14 10:48:42]staging.INFO: [automated-reports]Processing daily reports{"caa52627fc27"}[automated-reports] Automated report[2026-04-14 10:48:42]staging.INFO: [automated-reports] Found 1 daily reports to proc9-b635-2aa52627f c27"}[2026-04-14 10:48:42]staging.INF0: [automated-reports]Dispatching Generate Reportdaily","type": "ask_jiminny"} {"correlation_id":"246a1a1a-7076-458c-bd7d-49d2f5a2db88"[2026-04-14 10:48:42]staging.INFO: [automated-reports]Completed{"correlation_id":root@c78a087b1345:/home/jiminny# [ec2-user@ip-10-30-93-249 ~]$I+HomeDMsActivityFilesLater.*•MorelhlJiminny ...+tscnicrol# infra-changes# jiminny-bg# platform-tickets# product_launches# random# releases# sofia-office# support# thank-yous# the_people_of jimi...Aneliya Angelova, NikolayYankov, Steliyan GeorgievAneliya,Angel...Steliyan GeorgievAdelina Petrova, Ili...0. Adelina Petrova. Galya Dimitrova *&s Nikolay Nikolov "2Galya Dimitrova, Ni...2Galya Dimitrova, Ni...P. Nikolay Yankov::: AppsJira CloudToastGoogle Cale...§ Support Daily • in 44 m100% <Tue 14 Apr 14:16:22→Search Jiminny IncThread Direct message with 3 othersвчера, не днес• и имейл не дойдеimage.png• • 8.5 repliesLukas Kovalik 18 minutes agoза дата там не знам как искаме да го правим.по принцип при всички други се гледа ден назад при положение че идва през нощта.Nikolay Yankov 18 minutes ago@Lukas Kovalik видя ли този коментарLukas Kovalik 18 minutes agoдаNikolay Yankov 17 minutes agoне е ли датата на която е генерирано? (edited)Lukas Kovalik 17 minutes agoemail ще го видяReply...Also send to the group+•*•...
|
12371
|
|
12374
|
266
|
12
|
2026-04-14T11:16:41.329600+00:00
|
/Users/lukas/.screenpipe/data/data/2026-04-14/1776 /Users/lukas/.screenpipe/data/data/2026-04-14/1776165401329_m1.jpg...
|
Firefox
|
Jy 20541 stale records pr 1 by Vasil-Jiminny · Pul Jy 20541 stale records pr 1 by Vasil-Jiminny · Pull Request #11949 · jiminny/app — Work...
|
1
|
github.com/jiminny/app/pull/11949
|
monitor_1
|
NULL
|
NULL
|
NULL
|
NULL
|
JY-20543 add AJ reports User pilot tracking by Lak JY-20543 add AJ reports User pilot tracking by LakyLak · Pull Request #11932 · jiminny/app
github.com
JY-20543 add AJ reports User pilot tracking by LakyLak · Pull Request #11932 · jiminny/app
Pipelines - jiminny/app
Feed — jiminny — Sentry
Platform Sprint 1 Q2 - Platform Team - Scrum Board - Jira
Platform Sprint 1 Q2 - Platform Team - Scrum Board - Jira
JY-20543 add AJ reports User pilot tracking by LakyLak · Pull Request #11932 · jiminny/app
JY-20543 add AJ reports User pilot tracking by LakyLak · Pull Request #11932 · jiminny/app
Configure SSH access to multiple environment - Engineering - Confluence
Configure SSH access to multiple environment - Engineering - Confluence
Console Home | Console Home | us-east-2
Console Home | Console Home | us-east-2
SecurityGroup | EC2 | us-east-2
SecurityGroup | EC2 | us-east-2
JY-20543 add AJ reports User pilot tracking by LakyLak · Pull Request #11932 · jiminny/app
JY-20543 add AJ reports User pilot tracking by LakyLak · Pull Request #11932 · jiminny/app
Close tab
SRD-6779 | JY-20632 | Unable to log in to Sidekick with SSO by yalokin-jiminny · Pull Request #11935 · jiminny/app
SRD-6779 | JY-20632 | Unable to log in to Sidekick with SSO by yalokin-jiminny · Pull Request #11935 · jiminny/app
Jy 19798 evaluation for ai activity types by nikolaybiaivanov · Pull Request #468 · jiminny/prophet
Jy 19798 evaluation for ai activity types by nikolaybiaivanov · Pull Request #468 · jiminny/prophet
Jiminny
Jiminny
Ask Jiminny test report - 8 Apr 2026 - Ask Jiminny test report - 13 Apr 2026.pdf
Ask Jiminny test report - 8 Apr 2026 - Ask Jiminny test report - 13 Apr 2026.pdf
Service-Desk - Queues - Platform team - Service space - Jira
Service-Desk - Queues - Platform team - Service space - Jira
JY-20543 add AJ reports User pilot tracking by LakyLak · Pull Request #11932 · jiminny/app
JY-20543 add AJ reports User pilot tracking by LakyLak · Pull Request #11932 · jiminny/app
Configure SSH access to multiple environment - Engineering - Confluence
Configure SSH access to multiple environment - Engineering - Confluence
New Tab
New Tab
CloudWatch | us-east-2
CloudWatch | us-east-2
Jy 20541 stale records pr 1 by Vasil-Jiminny · Pull Request #11949 · jiminny/app
Jy 20541 stale records pr 1 by Vasil-Jiminny · Pull Request #11949 · jiminny/app
Close tab
New Tab
Customize sidebar
Open Google Gemini (⌃X)
Tabs from other devices
Open history (⇧⌘H)
Open bookmarks (⌘B)
Skip to content
Skip to content
Open menu
Homepage (g then d)
jiminny
jiminny
app
app
Search or jump to…
Type
/
to search
Chat with Copilot
Open Copilot…
Create new...
Issues(g then i)
Pull requests
Repositories
You have unread notifications(g then n)
Open user navigation menu
Repository navigation
Repository navigation
Code
Code
Pull requests (28)
Pull requests
(
28
)
Agents
Agents
Actions
Actions
Wiki
Wiki
Security and quality (24)
Security and quality
(
24
)
Insights
Insights
Settings
Settings
Important update
Important update
On April 24 we'll start using GitHub Copilot interaction data for AI model training unless you opt out.
Review this update
Review this update
and manage your preferences in your
GitHub account settings
GitHub account settings
.
Dismiss banner
Review requested
Review requested
Vasil-Jiminny
Vasil-Jiminny
requested your review on this pull request.
Add your review
Add your review
Jy 20541 stale records pr 1 #11949 Edit title
Jy 20541 stale records pr 1
#
11949
Edit title
Awaiting approval
Awaiting approval
Code
Code
Open
Vasil-Jiminny
Vasil-Jiminny
wants to merge 18 commits into
master
master
from
JY-20541-stale-records-pr-1
JY-20541-stale-records-pr-1
Copy head branch name to clipboard
Lines changed: 183 additions & 33 deletions
Conversation (11)
Conversation
(
11
)
Commits (18)
Commits
(
18
)
Checks (3)
Checks
(
3
)
Files changed (18)
Files changed
(
18
)
Conversation
Conversation
@Vasil-Jiminny
Show options
Vasil-Jiminny commented 2 hours ago •
Vasil-Jiminny
Vasil-Jiminny
commented
2 hours ago
2 hours ago
•
edited
edited
JIRA: JY-20541
JIRA:
JY-20541
JY-20541
Description:
Description:
This PR will be followed by
#11879
#11879
No significant functional changes.
This PR introduces/updates a few shared contracts. There is a contact for Lead/Account/Contact/Opportunity (syncable crm entities), and another for Lead/Account/Contact (prospect entities)
It also semantically updates a few HTTP-family exceptions.
Changes:
Changes:
Introduce SyncableCrmObjectContract.
Update models to comply with new contract.
Added missing accessor methods to Activity, Opportunity and Participant models. Added safe guard checks for logical issues, like missing
crm_configuration_id
, which should never happen, but the DB allows it.
Update HTTP exception definitions with type hints and struct types.
Add or remove reactions
Vasil-Jiminny
Vasil-Jiminny
added
6
commits
3 hours ago
3 hours ago
@Vasil-Jiminny
Define exceptions that may be thrown from sync "syncle object by id" …...
|
[{"role":"AXStaticText","text& [{"role":"AXStaticText","text":"JY-20543 add AJ reports User pilot tracking by LakyLak · Pull Request #11932 · jiminny/app","depth":4,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"github.com","depth":4,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"JY-20543 add AJ reports User pilot tracking by LakyLak · Pull Request #11932 · jiminny/app","depth":4,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXRadioButton","text":"Pipelines - jiminny/app","depth":4,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXRadioButton","text":"Feed — jiminny — Sentry","depth":4,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXRadioButton","text":"Platform Sprint 1 Q2 - Platform Team - Scrum Board - Jira","depth":4,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Platform Sprint 1 Q2 - Platform Team - Scrum Board - Jira","depth":5,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"JY-20543 add AJ reports User pilot tracking by LakyLak · Pull Request #11932 · jiminny/app","depth":4,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"JY-20543 add AJ reports User pilot tracking by LakyLak · Pull Request #11932 · jiminny/app","depth":5,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Configure SSH access to multiple environment - Engineering - Confluence","depth":4,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Configure SSH access to multiple environment - Engineering - Confluence","depth":5,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Console Home | Console Home | us-east-2","depth":4,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Console Home | Console Home | us-east-2","depth":5,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"SecurityGroup | EC2 | us-east-2","depth":4,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"SecurityGroup | EC2 | us-east-2","depth":5,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"JY-20543 add AJ reports User pilot tracking by LakyLak · Pull Request #11932 · jiminny/app","depth":4,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"JY-20543 add AJ reports User pilot tracking by LakyLak · Pull Request #11932 · jiminny/app","depth":5,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"Close tab","depth":5,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXRadioButton","text":"SRD-6779 | JY-20632 | Unable to log in to Sidekick with SSO by yalokin-jiminny · Pull Request #11935 · jiminny/app","depth":4,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"SRD-6779 | JY-20632 | Unable to log in to Sidekick with SSO by yalokin-jiminny · Pull Request #11935 · jiminny/app","depth":5,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Jy 19798 evaluation for ai activity types by nikolaybiaivanov · Pull Request #468 · jiminny/prophet","depth":4,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Jy 19798 evaluation for ai activity types by nikolaybiaivanov · Pull Request #468 · jiminny/prophet","depth":5,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Jiminny","depth":4,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Jiminny","depth":5,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Ask Jiminny test report - 8 Apr 2026 - Ask Jiminny test report - 13 Apr 2026.pdf","depth":4,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Ask Jiminny test report - 8 Apr 2026 - Ask Jiminny test report - 13 Apr 2026.pdf","depth":5,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Service-Desk - Queues - Platform team - Service space - Jira","depth":4,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Service-Desk - Queues - Platform team - Service space - Jira","depth":5,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"JY-20543 add AJ reports User pilot tracking by LakyLak · Pull Request #11932 · jiminny/app","depth":4,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"JY-20543 add AJ reports User pilot tracking by LakyLak · Pull Request #11932 · jiminny/app","depth":5,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Configure SSH access to multiple environment - Engineering - Confluence","depth":4,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Configure SSH access to multiple environment - Engineering - Confluence","depth":5,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"New Tab","depth":4,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"New Tab","depth":5,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"CloudWatch | us-east-2","depth":4,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"CloudWatch | us-east-2","depth":5,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Jy 20541 stale records pr 1 by Vasil-Jiminny · Pull Request #11949 · jiminny/app","depth":4,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":true},{"role":"AXStaticText","text":"Jy 20541 stale records pr 1 by Vasil-Jiminny · Pull Request #11949 · jiminny/app","depth":5,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"Close tab","depth":5,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXButton","text":"New Tab","depth":4,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXCheckBox","text":"Customize sidebar","depth":6,"help_text":"","role_description":"toggle button","subrole":"AXToggle","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXCheckBox","text":"Open Google Gemini (⌃X)","depth":6,"help_text":"","role_description":"toggle button","subrole":"AXToggle","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXCheckBox","text":"Tabs from other devices","depth":6,"help_text":"","role_description":"toggle button","subrole":"AXToggle","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXCheckBox","text":"Open history (⇧⌘H)","depth":6,"help_text":"","role_description":"toggle button","subrole":"AXToggle","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXCheckBox","text":"Open bookmarks (⌘B)","depth":6,"help_text":"","role_description":"toggle button","subrole":"AXToggle","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXLink","text":"Skip to content","depth":6,"help_text":"","role_description":"link","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Skip to content","depth":7,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"Open menu","depth":10,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXLink","text":"Homepage (g then d)","depth":9,"help_text":"","role_description":"link","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXLink","text":"jiminny","depth":12,"help_text":"","role_description":"link","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"jiminny","depth":14,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXLink","text":"app","depth":12,"help_text":"","role_description":"link","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"app","depth":14,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"Search or jump to…","depth":9,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Type","depth":12,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"/","depth":12,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"to search","depth":12,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXLink","text":"Chat with Copilot","depth":10,"help_text":"","role_description":"link","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXMenuButton","text":"Open Copilot…","depth":9,"help_text":"","role_description":"menu button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXMenuButton","text":"Create new...","depth":9,"help_text":"","role_description":"menu button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXLink","text":"Issues(g then i)","depth":9,"help_text":"","role_description":"link","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXLink","text":"Pull requests","depth":9,"help_text":"","role_description":"link","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXLink","text":"Repositories","depth":9,"help_text":"","role_description":"link","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXLink","text":"You have unread notifications(g then n)","depth":9,"help_text":"","role_description":"link","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXButton","text":"Open user navigation menu","depth":9,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXHeading","text":"Repository navigation","depth":9,"help_text":"","role_description":"heading","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Repository navigation","depth":10,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXLink","text":"Code","depth":12,"help_text":"","role_description":"link","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Code","depth":14,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXLink","text":"Pull requests (28)","depth":12,"help_text":"","role_description":"link","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Pull requests","depth":14,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"(","depth":14,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"28","depth":14,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":")","depth":14,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXLink","text":"Agents","depth":12,"help_text":"","role_description":"link","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Agents","depth":14,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXLink","text":"Actions","depth":12,"help_text":"","role_description":"link","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Actions","depth":14,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXLink","text":"Wiki","depth":12,"help_text":"","role_description":"link","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Wiki","depth":14,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXLink","text":"Security and quality (24)","depth":12,"help_text":"","role_description":"link","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Security and quality","depth":14,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"(","depth":14,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"24","depth":14,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":")","depth":14,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXLink","text":"Insights","depth":12,"help_text":"","role_description":"link","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Insights","depth":14,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXLink","text":"Settings","depth":12,"help_text":"","role_description":"link","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Settings","depth":14,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXHeading","text":"Important update","depth":10,"help_text":"","role_description":"heading","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Important update","depth":11,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"On April 24 we'll start using GitHub Copilot interaction data for AI model training unless you opt out.","depth":10,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXLink","text":"Review this update","depth":10,"help_text":"","role_description":"link","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Review this update","depth":11,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"and manage your preferences in your","depth":10,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXLink","text":"GitHub account settings","depth":10,"help_text":"","role_description":"link","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"GitHub account settings","depth":11,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":".","depth":10,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"Dismiss banner","depth":9,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXHeading","text":"Review requested","depth":15,"help_text":"","role_description":"heading","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Review requested","depth":16,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXLink","text":"Vasil-Jiminny","depth":15,"help_text":"","role_description":"link","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Vasil-Jiminny","depth":16,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"requested your review on this pull request.","depth":15,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXLink","text":"Add your review","depth":14,"help_text":"","role_description":"link","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Add your review","depth":16,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXHeading","text":"Jy 20541 stale records pr 1 #11949 Edit title","depth":13,"help_text":"","role_description":"heading","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Jy 20541 stale records pr 1","depth":14,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"#","depth":15,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"11949","depth":15,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"Edit title","depth":14,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXButton","text":"Awaiting approval","depth":13,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Awaiting approval","depth":15,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXMenuButton","text":"Code","depth":13,"help_text":"","role_description":"menu button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"Code","depth":15,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Open","depth":13,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXLink","text":"Vasil-Jiminny","depth":15,"help_text":"","role_description":"link","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Vasil-Jiminny","depth":16,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"wants to merge 18 commits into","depth":15,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXLink","text":"master","depth":15,"role_description":"link","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"master","depth":16,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"from","depth":16,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXLink","text":"JY-20541-stale-records-pr-1","depth":16,"role_description":"link","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"JY-20541-stale-records-pr-1","depth":17,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"Copy head branch name to clipboard","depth":16,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Lines changed: 183 additions & 33 deletions","depth":14,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Conversation (11)","depth":16,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":true},{"role":"AXStaticText","text":"Conversation","depth":17,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"(","depth":18,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"11","depth":18,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":")","depth":18,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Commits (18)","depth":16,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Commits","depth":17,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"(","depth":18,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"18","depth":18,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":")","depth":18,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Checks (3)","depth":16,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Checks","depth":17,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"(","depth":18,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"3","depth":18,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":")","depth":18,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Files changed (18)","depth":16,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Files changed","depth":17,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"(","depth":18,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"18","depth":18,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":")","depth":18,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXHeading","text":"Conversation","depth":12,"help_text":"","role_description":"heading","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Conversation","depth":13,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXLink","text":"@Vasil-Jiminny","depth":12,"help_text":"","role_description":"link","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXButton","text":"Show options","depth":15,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXHeading","text":"Vasil-Jiminny commented 2 hours ago •","depth":14,"help_text":"","role_description":"heading","subrole":"AXUnknown"},{"role":"AXLink","text":"Vasil-Jiminny","depth":16,"help_text":"","role_description":"link","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Vasil-Jiminny","depth":17,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"commented","depth":15,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXLink","text":"2 hours ago","depth":15,"help_text":"","role_description":"link","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"2 hours ago","depth":17,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"•","depth":17,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"edited","depth":17,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"edited","depth":19,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXHeading","text":"JIRA: JY-20541","depth":16,"help_text":"","role_description":"heading","subrole":"AXUnknown"},{"role":"AXStaticText","text":"JIRA:","depth":17,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXLink","text":"JY-20541","depth":17,"help_text":"","role_description":"link","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"JY-20541","depth":18,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXHeading","text":"Description:","depth":16,"help_text":"","role_description":"heading","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Description:","depth":17,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"This PR will be followed by","depth":17,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXLink","text":"#11879","depth":17,"help_text":"","role_description":"link","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"#11879","depth":18,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"No significant functional changes.","depth":17,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"This PR introduces/updates a few shared contracts. There is a contact for Lead/Account/Contact/Opportunity (syncable crm entities), and another for Lead/Account/Contact (prospect entities)","depth":17,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"It also semantically updates a few HTTP-family exceptions.","depth":17,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXHeading","text":"Changes:","depth":16,"help_text":"","role_description":"heading","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Changes:","depth":17,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Introduce SyncableCrmObjectContract.","depth":18,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Update models to comply with new contract.","depth":18,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Added missing accessor methods to Activity, Opportunity and Participant models. Added safe guard checks for logical issues, like missing","depth":18,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"crm_configuration_id","depth":19,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":", which should never happen, but the DB allows it.","depth":18,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Update HTTP exception definitions with type hints and struct types.","depth":18,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"Add or remove reactions","depth":16,"help_text":"","role_description":"summary","subrole":"AXSummary","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXLink","text":"Vasil-Jiminny","depth":14,"help_text":"","role_description":"link","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Vasil-Jiminny","depth":15,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"added","depth":14,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"6","depth":14,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"commits","depth":14,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXLink","text":"3 hours ago","depth":14,"help_text":"","role_description":"link","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"3 hours ago","depth":16,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXLink","text":"@Vasil-Jiminny","depth":12,"help_text":"","role_description":"link","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXLink","text":"Define exceptions that may be thrown from sync \"syncle object by id\" …","depth":14,"help_text":"Define exceptions that may be thrown from sync \"syncle object by id\" operaitons.","role_description":"link","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false}]...
|
4179185073381966055
|
-7990135947057628466
|
visual_change
|
accessibility
|
NULL
|
JY-20543 add AJ reports User pilot tracking by Lak JY-20543 add AJ reports User pilot tracking by LakyLak · Pull Request #11932 · jiminny/app
github.com
JY-20543 add AJ reports User pilot tracking by LakyLak · Pull Request #11932 · jiminny/app
Pipelines - jiminny/app
Feed — jiminny — Sentry
Platform Sprint 1 Q2 - Platform Team - Scrum Board - Jira
Platform Sprint 1 Q2 - Platform Team - Scrum Board - Jira
JY-20543 add AJ reports User pilot tracking by LakyLak · Pull Request #11932 · jiminny/app
JY-20543 add AJ reports User pilot tracking by LakyLak · Pull Request #11932 · jiminny/app
Configure SSH access to multiple environment - Engineering - Confluence
Configure SSH access to multiple environment - Engineering - Confluence
Console Home | Console Home | us-east-2
Console Home | Console Home | us-east-2
SecurityGroup | EC2 | us-east-2
SecurityGroup | EC2 | us-east-2
JY-20543 add AJ reports User pilot tracking by LakyLak · Pull Request #11932 · jiminny/app
JY-20543 add AJ reports User pilot tracking by LakyLak · Pull Request #11932 · jiminny/app
Close tab
SRD-6779 | JY-20632 | Unable to log in to Sidekick with SSO by yalokin-jiminny · Pull Request #11935 · jiminny/app
SRD-6779 | JY-20632 | Unable to log in to Sidekick with SSO by yalokin-jiminny · Pull Request #11935 · jiminny/app
Jy 19798 evaluation for ai activity types by nikolaybiaivanov · Pull Request #468 · jiminny/prophet
Jy 19798 evaluation for ai activity types by nikolaybiaivanov · Pull Request #468 · jiminny/prophet
Jiminny
Jiminny
Ask Jiminny test report - 8 Apr 2026 - Ask Jiminny test report - 13 Apr 2026.pdf
Ask Jiminny test report - 8 Apr 2026 - Ask Jiminny test report - 13 Apr 2026.pdf
Service-Desk - Queues - Platform team - Service space - Jira
Service-Desk - Queues - Platform team - Service space - Jira
JY-20543 add AJ reports User pilot tracking by LakyLak · Pull Request #11932 · jiminny/app
JY-20543 add AJ reports User pilot tracking by LakyLak · Pull Request #11932 · jiminny/app
Configure SSH access to multiple environment - Engineering - Confluence
Configure SSH access to multiple environment - Engineering - Confluence
New Tab
New Tab
CloudWatch | us-east-2
CloudWatch | us-east-2
Jy 20541 stale records pr 1 by Vasil-Jiminny · Pull Request #11949 · jiminny/app
Jy 20541 stale records pr 1 by Vasil-Jiminny · Pull Request #11949 · jiminny/app
Close tab
New Tab
Customize sidebar
Open Google Gemini (⌃X)
Tabs from other devices
Open history (⇧⌘H)
Open bookmarks (⌘B)
Skip to content
Skip to content
Open menu
Homepage (g then d)
jiminny
jiminny
app
app
Search or jump to…
Type
/
to search
Chat with Copilot
Open Copilot…
Create new...
Issues(g then i)
Pull requests
Repositories
You have unread notifications(g then n)
Open user navigation menu
Repository navigation
Repository navigation
Code
Code
Pull requests (28)
Pull requests
(
28
)
Agents
Agents
Actions
Actions
Wiki
Wiki
Security and quality (24)
Security and quality
(
24
)
Insights
Insights
Settings
Settings
Important update
Important update
On April 24 we'll start using GitHub Copilot interaction data for AI model training unless you opt out.
Review this update
Review this update
and manage your preferences in your
GitHub account settings
GitHub account settings
.
Dismiss banner
Review requested
Review requested
Vasil-Jiminny
Vasil-Jiminny
requested your review on this pull request.
Add your review
Add your review
Jy 20541 stale records pr 1 #11949 Edit title
Jy 20541 stale records pr 1
#
11949
Edit title
Awaiting approval
Awaiting approval
Code
Code
Open
Vasil-Jiminny
Vasil-Jiminny
wants to merge 18 commits into
master
master
from
JY-20541-stale-records-pr-1
JY-20541-stale-records-pr-1
Copy head branch name to clipboard
Lines changed: 183 additions & 33 deletions
Conversation (11)
Conversation
(
11
)
Commits (18)
Commits
(
18
)
Checks (3)
Checks
(
3
)
Files changed (18)
Files changed
(
18
)
Conversation
Conversation
@Vasil-Jiminny
Show options
Vasil-Jiminny commented 2 hours ago •
Vasil-Jiminny
Vasil-Jiminny
commented
2 hours ago
2 hours ago
•
edited
edited
JIRA: JY-20541
JIRA:
JY-20541
JY-20541
Description:
Description:
This PR will be followed by
#11879
#11879
No significant functional changes.
This PR introduces/updates a few shared contracts. There is a contact for Lead/Account/Contact/Opportunity (syncable crm entities), and another for Lead/Account/Contact (prospect entities)
It also semantically updates a few HTTP-family exceptions.
Changes:
Changes:
Introduce SyncableCrmObjectContract.
Update models to comply with new contract.
Added missing accessor methods to Activity, Opportunity and Participant models. Added safe guard checks for logical issues, like missing
crm_configuration_id
, which should never happen, but the DB allows it.
Update HTTP exception definitions with type hints and struct types.
Add or remove reactions
Vasil-Jiminny
Vasil-Jiminny
added
6
commits
3 hours ago
3 hours ago
@Vasil-Jiminny
Define exceptions that may be thrown from sync "syncle object by id" …...
|
NULL
|
|
12376
|
266
|
13
|
2026-04-14T11:16:44.392656+00:00
|
/Users/lukas/.screenpipe/data/data/2026-04-14/1776 /Users/lukas/.screenpipe/data/data/2026-04-14/1776165404392_m1.jpg...
|
NULL
|
NULL
|
1
|
NULL
|
monitor_1
|
NULL
|
NULL
|
NULL
|
NULL
|
SlackFileEditViewGoHistoryWindowHelpec2-userGDOCKE SlackFileEditViewGoHistoryWindowHelpec2-userGDOCKERS'381DEV (docker)882APP (-zsh)[EMAIL]@73b64f5d54a3:/home/jiminny#[ec2-user@ip-10-30-93-249~7$ dockerexec -it $(dockroot@c78a087b1345:/home/jiminny# php artisan automated-reports[2026-04-14 10:46:08]staging.INFO: [automated-reports]Started{"correlation_id":"5[2026-04-1410:46:087staging. INFO: [automated-reports]id":"5c23e861-2ca9-4f92-9f67-773d6bc80ca0"Checking conditions {"isMonda,"trace_id" :"185df6f6-4327-4609-9c2e-2ab83a[2026-04-1410:46:08]ab83a0f5432"}staging.INFO: [automated-reports]Processing daily reports[2026-04-1410:46:08]9-9cZe-2ab83a0f5432"}staging.INFO:[automated-reports]Found 3 daily reports to proc[2026-04-1410:46:08]staging.INFO:[automated-reports]Dispatching Generate ReportPSSlackroot@c78a087b1345:/home/jiminny# php artisan automated-reports --report-id 35[2026-04-14 10:48:42]staging.INFO: [automated-reports] Started{"correlation_id":"2[2026-04-14 10:48:42]staging.INFO: [automated-reports]Checking conditions {"isMondaid":"246a1ala-7076-458c-bd7d-49d2f5a2db88","trace_id" : "1f894bf6-e50d-4e99-b635-2aa526[2026-04-14 10:48:42]staging.INFO: [automated-reports] Processing daily reportsaa52627fc27"}[automated-reports] Automated report found Test[2026-04-14 10:48:42]staging. INFO: [automated-reports] Found 1 daily reports to proc9-b635-2aa52627f c27"}[2026-04-14 10:48:42]staging.INFO: [automated-reports]Dispatching Generate Reportdaily","type": "ask_jiminny"} {"correlation_id":"246a1a1a-7076-458c-bd7d-49d2f5a2db88"[2026-04-14 10:48:42] staging.INF0: [automated-reports]Completed{"correlation_id":root@c78a087b1345:/home/jiminny# [ec2-user@ip-10-30-93-249 ~]$D+HomeDMsActivityFiles0allSupport Daily - in 44 m100% L2Tue 14 Apr 14:16:43→Search Jiminny IncJiminny ...+tscncret# infra-changes# jiminny-bg# platform-tickets# product_launches# random# releases# sofia-office# support#thank-vousThread Direct message with 3 othersвчера, не днес• и имейл не дойдеimage.png vМtrрesA6S•a n9(3Adelina Petrova, Ili...0. Adelina Petrova. Galya Dimitrova *Rs Nikolay Nikolov "2 Galya Dimitrova, Ni...2Galya Dimitrova, Ni...P. Nikolay YankovAppsJira CloudToastGoogle Cale... PsNзад при положение че идва през нощід.Nikolay Yankov 18 minutes ago@Lukas Kovalik видя ли този коментарLukas Kovalik 18 minutes agoдаNikolay Yankov 17 minutes agoне е ли датата на която е генерирано? (edited)Lukas Kovalik 17 minutes agoemail ще го видяReply...+Also send to the groupAa...
|
NULL
|
-3335754418976201769
|
NULL
|
visual_change
|
ocr
|
NULL
|
SlackFileEditViewGoHistoryWindowHelpec2-userGDOCKE SlackFileEditViewGoHistoryWindowHelpec2-userGDOCKERS'381DEV (docker)882APP (-zsh)[EMAIL]@73b64f5d54a3:/home/jiminny#[ec2-user@ip-10-30-93-249~7$ dockerexec -it $(dockroot@c78a087b1345:/home/jiminny# php artisan automated-reports[2026-04-14 10:46:08]staging.INFO: [automated-reports]Started{"correlation_id":"5[2026-04-1410:46:087staging. INFO: [automated-reports]id":"5c23e861-2ca9-4f92-9f67-773d6bc80ca0"Checking conditions {"isMonda,"trace_id" :"185df6f6-4327-4609-9c2e-2ab83a[2026-04-1410:46:08]ab83a0f5432"}staging.INFO: [automated-reports]Processing daily reports[2026-04-1410:46:08]9-9cZe-2ab83a0f5432"}staging.INFO:[automated-reports]Found 3 daily reports to proc[2026-04-1410:46:08]staging.INFO:[automated-reports]Dispatching Generate ReportPSSlackroot@c78a087b1345:/home/jiminny# php artisan automated-reports --report-id 35[2026-04-14 10:48:42]staging.INFO: [automated-reports] Started{"correlation_id":"2[2026-04-14 10:48:42]staging.INFO: [automated-reports]Checking conditions {"isMondaid":"246a1ala-7076-458c-bd7d-49d2f5a2db88","trace_id" : "1f894bf6-e50d-4e99-b635-2aa526[2026-04-14 10:48:42]staging.INFO: [automated-reports] Processing daily reportsaa52627fc27"}[automated-reports] Automated report found Test[2026-04-14 10:48:42]staging. INFO: [automated-reports] Found 1 daily reports to proc9-b635-2aa52627f c27"}[2026-04-14 10:48:42]staging.INFO: [automated-reports]Dispatching Generate Reportdaily","type": "ask_jiminny"} {"correlation_id":"246a1a1a-7076-458c-bd7d-49d2f5a2db88"[2026-04-14 10:48:42] staging.INF0: [automated-reports]Completed{"correlation_id":root@c78a087b1345:/home/jiminny# [ec2-user@ip-10-30-93-249 ~]$D+HomeDMsActivityFiles0allSupport Daily - in 44 m100% L2Tue 14 Apr 14:16:43→Search Jiminny IncJiminny ...+tscncret# infra-changes# jiminny-bg# platform-tickets# product_launches# random# releases# sofia-office# support#thank-vousThread Direct message with 3 othersвчера, не днес• и имейл не дойдеimage.png vМtrрesA6S•a n9(3Adelina Petrova, Ili...0. Adelina Petrova. Galya Dimitrova *Rs Nikolay Nikolov "2 Galya Dimitrova, Ni...2Galya Dimitrova, Ni...P. Nikolay YankovAppsJira CloudToastGoogle Cale... PsNзад при положение че идва през нощід.Nikolay Yankov 18 minutes ago@Lukas Kovalik видя ли този коментарLukas Kovalik 18 minutes agoдаNikolay Yankov 17 minutes agoне е ли датата на която е генерирано? (edited)Lukas Kovalik 17 minutes agoemail ще го видяReply...+Also send to the groupAa...
|
12374
|
|
12377
|
266
|
14
|
2026-04-14T11:16:47.391745+00:00
|
/Users/lukas/.screenpipe/data/data/2026-04-14/1776 /Users/lukas/.screenpipe/data/data/2026-04-14/1776165407391_m1.jpg...
|
Slack
|
Aneliya Angelova, Nikolay Yankov, Steliyan Georgie Aneliya Angelova, Nikolay Yankov, Steliyan Georgiev (DM) - Jiminny Inc - Slack...
|
1
|
NULL
|
monitor_1
|
NULL
|
NULL
|
NULL
|
NULL
|
Jiminny Inc
Jiminny (Staging)
Add workspaces
Home
Jiminny Inc
Jiminny (Staging)
Add workspaces
Home
Home
DMs
DMs
Activity
Activity
Files
Files
Later
Later
More…
More
Unreads
Threads
Huddles
Drafts & sent
Directories
platform-inner-team
ai-chapter
alerts
backend
confusion-clinic
curiosity_lab
engineering
frontend
general
infra-changes
jiminny-bg
platform-tickets
product_launches
random
releases
sofia-office
support
thank-yous
the_people_of_jiminny
Vasil Vasilev
Aneliya Angelova
,
Nikolay Yankov
,
Steliyan Georgiev
Steliyan Georgiev
Adelina Petrova
,
Ilian Kyuchukov
,
Steliyan Georgiev
Adelina Petrova
Galya Dimitrova
Nikolay Nikolov
Galya Dimitrova
,
Nikolay Nikolov
Galya Dimitrova
,
Nikolay Yankov
Nikolay Yankov
Jira Cloud
Toast
Google Calendar
Nikolay Yankov
Today at 1:49:38 PM
27 minutes ago
Добре, 2 неща:
в името на генерирания репорт е дата вчера, не днес
и имейл не дойде
image.png
Toggle file
image.png
Download image.png
Share file: image.png
View canvas details
More actions
5 replies
Lukas Kovalik
Today at 1:58:20 PM
18 minutes ago
за дата там не знам как искаме да го правим. по принцип при всички други се гледа ден на зад при положение че идва през нощта.
React with white_check_mark
React with eyes
React with raised_hands
Add reaction…
Forward message…
Save for later
More actions
Nikolay Yankov
Today at 1:58:22 PM
18 minutes ago
@Lukas Kovalik
@Lukas Kovalik
видя ли този коментар
React with white_check_mark
React with eyes
React with raised_hands
Add reaction…
Forward message…
Save for later
More actions
Lukas Kovalik
Today at 1:58:27 PM
18 minutes ago
да
React with white_check_mark
React with eyes
React with raised_hands
Add reaction…
Forward message…
Save for later
More actions
Nikolay Yankov
Today at 1:59:00 PM
17 minutes ago
не е ли датата на която е генерирано?
(edited)
React with white_check_mark
React with eyes
React with raised_hands
Add reaction…
Forward message…
Save for later
More actions
Lukas Kovalik
Today at 1:59:04 PM
17 minutes ago
email ще го видя
React with white_check_mark
React with eyes
React with raised_hands
Add reaction…
Forward message…
Save for later
More actions
Also send to the group
Also send to the group
loading…
loading…...
|
[{"role":"AXRadioButton","text [{"role":"AXRadioButton","text":"Jiminny Inc","depth":12,"bounds":{"left":0.4861111,"top":0.08777778,"width":0.022222223,"height":0.035555556},"role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":true,"is_expanded":false},{"role":"AXRadioButton","text":"Jiminny (Staging)","depth":12,"bounds":{"left":0.4861111,"top":0.14555556,"width":0.022222223,"height":0.035555556},"role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXPopUpButton","text":"Add workspaces","depth":12,"bounds":{"left":0.4861111,"top":0.20333333,"width":0.022222223,"height":0.035555556},"role_description":"pop-up button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXRadioButton","text":"Home","depth":14,"bounds":{"left":0.525,"top":0.07777778,"width":0.036111113,"height":0.075555556},"role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":true,"is_expanded":false},{"role":"AXStaticText","text":"Home","depth":16,"bounds":{"left":0.5326389,"top":0.13,"width":0.020833334,"height":0.015555556},"role_description":"text"},{"role":"AXRadioButton","text":"DMs","depth":14,"bounds":{"left":0.525,"top":0.15333334,"width":0.036111113,"height":0.075555556},"role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"DMs","depth":16,"bounds":{"left":0.5347222,"top":0.20555556,"width":0.016666668,"height":0.015555556},"role_description":"text"},{"role":"AXRadioButton","text":"Activity","depth":14,"bounds":{"left":0.525,"top":0.22888888,"width":0.036111113,"height":0.075555556},"role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"Activity","depth":16,"bounds":{"left":0.52916664,"top":0.28111112,"width":0.027083334,"height":0.015555556},"role_description":"text"},{"role":"AXRadioButton","text":"Files","depth":14,"bounds":{"left":0.525,"top":0.30444443,"width":0.036111113,"height":0.075555556},"role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"Files","depth":16,"bounds":{"left":0.5347222,"top":0.35666665,"width":0.015972223,"height":0.015555556},"role_description":"text"},{"role":"AXRadioButton","text":"Later","depth":14,"bounds":{"left":0.525,"top":0.38,"width":0.036111113,"height":0.075555556},"role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"Later","depth":16,"bounds":{"left":0.53402776,"top":0.43222222,"width":0.018055556,"height":0.015555556},"role_description":"text"},{"role":"AXRadioButton","text":"More…","depth":14,"bounds":{"left":0.525,"top":0.45555556,"width":0.036111113,"height":0.075555556},"role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"More","depth":16,"bounds":{"left":0.53333336,"top":0.50777775,"width":0.01875,"height":0.015555556},"role_description":"text"},{"role":"AXStaticText","text":"Unreads","depth":21,"bounds":{"left":0.5951389,"top":0.12777779,"width":0.039583333,"height":0.0011111111},"role_description":"text"},{"role":"AXStaticText","text":"Threads","depth":21,"bounds":{"left":0.5951389,"top":0.12777779,"width":0.036805555,"height":0.0011111111},"role_description":"text"},{"role":"AXStaticText","text":"Huddles","depth":21,"bounds":{"left":0.5951389,"top":0.12777779,"width":0.038194444,"height":0.0011111111},"role_description":"text"},{"role":"AXStaticText","text":"Drafts & sent","depth":21,"bounds":{"left":0.5951389,"top":0.12777779,"width":0.06111111,"height":0.0011111111},"role_description":"text"},{"role":"AXStaticText","text":"Directories","depth":21,"bounds":{"left":0.5951389,"top":0.12777779,"width":0.050694443,"height":0.0011111111},"role_description":"text"},{"role":"AXStaticText","text":"platform-inner-team","depth":23,"bounds":{"left":0.60625,"top":0.12777779,"width":0.093055554,"height":0.0011111111},"role_description":"text"},{"role":"AXStaticText","text":"ai-chapter","depth":23,"bounds":{"left":0.60625,"top":0.12777779,"width":0.046527777,"height":0.0011111111},"role_description":"text"},{"role":"AXStaticText","text":"alerts","depth":23,"bounds":{"left":0.60625,"top":0.12777779,"width":0.025694445,"height":0.0011111111},"role_description":"text"},{"role":"AXStaticText","text":"backend","depth":23,"bounds":{"left":0.60625,"top":0.12777779,"width":0.038194444,"height":0.0011111111},"role_description":"text"},{"role":"AXStaticText","text":"confusion-clinic","depth":23,"bounds":{"left":0.60625,"top":0.12777779,"width":0.072222225,"height":0.0011111111},"role_description":"text"},{"role":"AXStaticText","text":"curiosity_lab","depth":23,"bounds":{"left":0.60625,"top":0.12777779,"width":0.057638887,"height":0.0011111111},"role_description":"text"},{"role":"AXStaticText","text":"engineering","depth":23,"bounds":{"left":0.60625,"top":0.12777779,"width":0.054166667,"height":0.0011111111},"role_description":"text"},{"role":"AXStaticText","text":"frontend","depth":23,"bounds":{"left":0.60625,"top":0.12777779,"width":0.04027778,"height":0.0011111111},"role_description":"text"},{"role":"AXStaticText","text":"general","depth":23,"bounds":{"left":0.60625,"top":0.12777779,"width":0.034027778,"height":0.007777778},"role_description":"text"},{"role":"AXStaticText","text":"infra-changes","depth":23,"bounds":{"left":0.60625,"top":0.14666666,"width":0.061805554,"height":0.02},"role_description":"text"},{"role":"AXStaticText","text":"jiminny-bg","depth":23,"bounds":{"left":0.60625,"top":0.17777778,"width":0.048611112,"height":0.02},"role_description":"text"},{"role":"AXStaticText","text":"platform-tickets","depth":23,"bounds":{"left":0.60625,"top":0.20888889,"width":0.072916664,"height":0.02},"role_description":"text"},{"role":"AXStaticText","text":"product_launches","depth":23,"bounds":{"left":0.60625,"top":0.24,"width":0.08055556,"height":0.02},"role_description":"text"},{"role":"AXStaticText","text":"random","depth":23,"bounds":{"left":0.60625,"top":0.2711111,"width":0.035416666,"height":0.02},"role_description":"text"},{"role":"AXStaticText","text":"releases","depth":23,"bounds":{"left":0.60625,"top":0.30222222,"width":0.038194444,"height":0.02},"role_description":"text"},{"role":"AXStaticText","text":"sofia-office","depth":23,"bounds":{"left":0.60625,"top":0.33333334,"width":0.05138889,"height":0.02},"role_description":"text"},{"role":"AXStaticText","text":"support","depth":23,"bounds":{"left":0.60625,"top":0.36444443,"width":0.036111113,"height":0.02},"role_description":"text"},{"role":"AXStaticText","text":"thank-yous","depth":23,"bounds":{"left":0.60625,"top":0.39555556,"width":0.05138889,"height":0.02},"role_description":"text"},{"role":"AXStaticText","text":"the_people_of_jiminny","depth":23,"bounds":{"left":0.60625,"top":0.42666668,"width":0.094444446,"height":0.02},"role_description":"text"},{"role":"AXStaticText","text":"Vasil Vasilev","depth":23,"bounds":{"left":0.60625,"top":0.5,"width":0.055555556,"height":0.02},"role_description":"text"},{"role":"AXStaticText","text":"Aneliya Angelova","depth":23,"bounds":{"left":0.60625,"top":0.5311111,"width":0.07847222,"height":0.02},"role_description":"text"},{"role":"AXStaticText","text":",","depth":23,"bounds":{"left":0.68472224,"top":0.5311111,"width":0.013194445,"height":0.02},"role_description":"text"},{"role":"AXStaticText","text":"Nikolay Yankov","depth":23,"bounds":{"left":0.68958336,"top":0.5311111,"width":0.029861111,"height":0.02},"role_description":"text"},{"role":"AXStaticText","text":",","depth":23,"role_description":"text"},{"role":"AXStaticText","text":"Steliyan Georgiev","depth":23,"role_description":"text"},{"role":"AXStaticText","text":"Steliyan Georgiev","depth":23,"bounds":{"left":0.60625,"top":0.56222224,"width":0.07986111,"height":0.02},"role_description":"text"},{"role":"AXStaticText","text":"Adelina Petrova","depth":23,"bounds":{"left":0.60625,"top":0.5933333,"width":0.072222225,"height":0.02},"role_description":"text"},{"role":"AXStaticText","text":",","depth":23,"bounds":{"left":0.67777777,"top":0.5933333,"width":0.0055555557,"height":0.02},"role_description":"text"},{"role":"AXStaticText","text":"Ilian Kyuchukov","depth":23,"bounds":{"left":0.68333334,"top":0.5933333,"width":0.015972223,"height":0.02},"role_description":"text"},{"role":"AXStaticText","text":",","depth":23,"role_description":"text"},{"role":"AXStaticText","text":"Steliyan Georgiev","depth":23,"role_description":"text"},{"role":"AXStaticText","text":"Adelina Petrova","depth":23,"bounds":{"left":0.60625,"top":0.6244444,"width":0.072222225,"height":0.02},"role_description":"text"},{"role":"AXStaticText","text":"Galya Dimitrova","depth":23,"bounds":{"left":0.60625,"top":0.65555555,"width":0.07361111,"height":0.02},"role_description":"text"},{"role":"AXStaticText","text":"Nikolay Nikolov","depth":23,"bounds":{"left":0.60625,"top":0.68666667,"width":0.07152778,"height":0.02},"role_description":"text"},{"role":"AXStaticText","text":"Galya Dimitrova","depth":23,"bounds":{"left":0.60625,"top":0.7177778,"width":0.07361111,"height":0.02},"role_description":"text"},{"role":"AXStaticText","text":",","depth":23,"bounds":{"left":0.6791667,"top":0.7177778,"width":0.0055555557,"height":0.02},"role_description":"text"},{"role":"AXStaticText","text":"Nikolay Nikolov","depth":23,"bounds":{"left":0.68472224,"top":0.7177778,"width":0.018055556,"height":0.02},"role_description":"text"},{"role":"AXStaticText","text":"Galya Dimitrova","depth":23,"bounds":{"left":0.60625,"top":0.7488889,"width":0.07361111,"height":0.02},"role_description":"text"},{"role":"AXStaticText","text":",","depth":23,"bounds":{"left":0.6791667,"top":0.7488889,"width":0.0055555557,"height":0.02},"role_description":"text"},{"role":"AXStaticText","text":"Nikolay Yankov","depth":23,"bounds":{"left":0.68472224,"top":0.7488889,"width":0.018055556,"height":0.02},"role_description":"text"},{"role":"AXStaticText","text":"Nikolay Yankov","depth":23,"bounds":{"left":0.60625,"top":0.78,"width":0.06875,"height":0.02},"role_description":"text"},{"role":"AXStaticText","text":"Jira Cloud","depth":23,"bounds":{"left":0.60625,"top":0.85333335,"width":0.045833334,"height":0.02},"role_description":"text"},{"role":"AXStaticText","text":"Toast","depth":23,"bounds":{"left":0.60625,"top":0.8844444,"width":0.024305556,"height":0.02},"role_description":"text"},{"role":"AXStaticText","text":"Google Calendar","depth":23,"bounds":{"left":0.60625,"top":0.91555554,"width":0.06388889,"height":0.02},"role_description":"text"},{"role":"AXButton","text":"Nikolay Yankov","depth":22,"bounds":{"left":0.7625,"top":0.072222225,"width":0.072222225,"height":0.0055555557},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"","depth":22,"bounds":{"left":0.83402777,"top":0.072222225,"width":0.00625,"height":0.0033333334},"role_description":"text"},{"role":"AXLink","text":"Today at 1:49:38 PM","depth":22,"bounds":{"left":0.83958334,"top":0.072222225,"width":0.056944445,"height":0.0033333334},"role_description":"link","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"27 minutes ago","depth":23,"bounds":{"left":0.83958334,"top":0.072222225,"width":0.056944445,"height":0.0033333334},"role_description":"text"},{"role":"AXStaticText","text":"Добре, 2 неща:","depth":23,"bounds":{"left":0.7625,"top":0.08,"width":0.07361111,"height":0.02},"role_description":"text"},{"role":"AXStaticText","text":"","depth":25,"bounds":{"left":0.7652778,"top":0.10666667,"width":0.010416667,"height":0.017777778},"role_description":"text"},{"role":"AXStaticText","text":"в името на генерирания репорт е дата вчера, не днес","depth":24,"bounds":{"left":0.78194445,"top":0.104444444,"width":0.18472221,"height":0.044444446},"role_description":"text"},{"role":"AXStaticText","text":"","depth":25,"bounds":{"left":0.7652778,"top":0.15555556,"width":0.010416667,"height":0.017777778},"role_description":"text"},{"role":"AXStaticText","text":"и имейл не дойде","depth":24,"bounds":{"left":0.78194445,"top":0.15333334,"width":0.08680555,"height":0.02},"role_description":"text"},{"role":"AXStaticText","text":"image.png","depth":23,"bounds":{"left":0.7625,"top":0.18333334,"width":0.04097222,"height":0.017777778},"role_description":"text"},{"role":"AXStaticText","text":"","depth":23,"bounds":{"left":0.80277777,"top":0.18222222,"width":0.0034722222,"height":0.02},"role_description":"text"},{"role":"AXButton","text":"Toggle file","depth":23,"bounds":{"left":0.8055556,"top":0.18111111,"width":0.014583333,"height":0.022222223},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":true},{"role":"AXLink","text":"image.png","depth":25,"bounds":{"left":0.7625,"top":0.20888889,"width":0.22291666,"height":0.25555557},"role_description":"Unlabelled image","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXLink","text":"Download image.png","depth":26,"bounds":{"left":0.88680553,"top":0.22444445,"width":0.022222223,"height":0.035555556},"role_description":"link","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Share file: image.png","depth":26,"bounds":{"left":0.90902776,"top":0.22444445,"width":0.022222223,"height":0.035555556},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"View canvas details","depth":26,"bounds":{"left":0.93125,"top":0.22444445,"width":0.022222223,"height":0.035555556},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXPopUpButton","text":"More actions","depth":26,"bounds":{"left":0.9534722,"top":0.22444445,"width":0.022222223,"height":0.035555556},"role_description":"pop-up button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"5 replies","depth":21,"bounds":{"left":0.73194444,"top":0.47777778,"width":0.034027778,"height":0.018888889},"role_description":"text"},{"role":"AXButton","text":"Lukas Kovalik","depth":22,"bounds":{"left":0.7625,"top":0.50333333,"width":0.06458333,"height":0.025555555},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"","depth":22,"bounds":{"left":0.82708335,"top":0.50555557,"width":0.0055555557,"height":0.02111111},"role_description":"text"},{"role":"AXLink","text":"Today at 1:58:20 PM","depth":22,"bounds":{"left":0.83263886,"top":0.5088889,"width":0.05625,"height":0.016666668},"role_description":"link","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"18 minutes ago","depth":23,"bounds":{"left":0.83263886,"top":0.5088889,"width":0.05625,"height":0.016666668},"role_description":"text"},{"role":"AXStaticText","text":"за дата там не знам как искаме да го правим. по принцип при всички други се гледа ден на зад при положение че идва през нощта.","depth":23,"bounds":{"left":0.7625,"top":0.53,"width":0.21944444,"height":0.07},"role_description":"text"},{"role":"AXCheckBox","text":"React with white_check_mark","depth":24,"bounds":{"left":0.82708335,"top":0.48444444,"width":0.022222223,"height":0.036666665},"role_description":"toggle button","subrole":"AXToggleButton","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXCheckBox","text":"React with eyes","depth":24,"bounds":{"left":0.84930557,"top":0.48444444,"width":0.022222223,"height":0.036666665},"role_description":"toggle button","subrole":"AXToggleButton","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXCheckBox","text":"React with raised_hands","depth":24,"bounds":{"left":0.8715278,"top":0.48444444,"width":0.022222223,"height":0.036666665},"role_description":"toggle button","subrole":"AXToggleButton","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Add reaction…","depth":24,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Forward message…","depth":24,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXCheckBox","text":"Save for later","depth":24,"role_description":"toggle button","subrole":"AXToggleButton","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXPopUpButton","text":"More actions","depth":24,"role_description":"pop-up button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Nikolay Yankov","depth":22,"bounds":{"left":0.7625,"top":0.61,"width":0.072222225,"height":0.025555555},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"","depth":22,"bounds":{"left":0.83402777,"top":0.6122222,"width":0.00625,"height":0.02111111},"role_description":"text"},{"role":"AXLink","text":"Today at 1:58:22 PM","depth":22,"bounds":{"left":0.83958334,"top":0.6155556,"width":0.056944445,"height":0.016666668},"role_description":"link","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"18 minutes ago","depth":23,"bounds":{"left":0.83958334,"top":0.6155556,"width":0.056944445,"height":0.016666668},"role_description":"text"},{"role":"AXLink","text":"@Lukas Kovalik","depth":23,"bounds":{"left":0.7625,"top":0.63555557,"width":0.07361111,"height":0.023333333},"role_description":"link","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"@Lukas Kovalik","depth":24,"bounds":{"left":0.7638889,"top":0.63666666,"width":0.07083333,"height":0.02111111},"role_description":"text"},{"role":"AXStaticText","text":"видя ли този коментар","depth":23,"bounds":{"left":0.8354167,"top":0.63666666,"width":0.11319444,"height":0.02111111},"role_description":"text"},{"role":"AXCheckBox","text":"React with white_check_mark","depth":24,"bounds":{"left":0.82708335,"top":0.5911111,"width":0.022222223,"height":0.036666665},"role_description":"toggle button","subrole":"AXToggleButton","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXCheckBox","text":"React with eyes","depth":24,"bounds":{"left":0.84930557,"top":0.5911111,"width":0.022222223,"height":0.036666665},"role_description":"toggle button","subrole":"AXToggleButton","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXCheckBox","text":"React with raised_hands","depth":24,"bounds":{"left":0.8715278,"top":0.5911111,"width":0.022222223,"height":0.036666665},"role_description":"toggle button","subrole":"AXToggleButton","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Add reaction…","depth":24,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Forward message…","depth":24,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXCheckBox","text":"Save for later","depth":24,"role_description":"toggle button","subrole":"AXToggleButton","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXPopUpButton","text":"More actions","depth":24,"role_description":"pop-up button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Lukas Kovalik","depth":22,"bounds":{"left":0.7625,"top":0.6677778,"width":0.06458333,"height":0.025555555},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"","depth":22,"bounds":{"left":0.82708335,"top":0.67,"width":0.0055555557,"height":0.02111111},"role_description":"text"},{"role":"AXLink","text":"Today at 1:58:27 PM","depth":22,"bounds":{"left":0.83263886,"top":0.67333335,"width":0.05625,"height":0.016666668},"role_description":"link","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"18 minutes ago","depth":23,"bounds":{"left":0.83263886,"top":0.67333335,"width":0.05625,"height":0.016666668},"role_description":"text"},{"role":"AXStaticText","text":"да","depth":23,"bounds":{"left":0.7625,"top":0.6944444,"width":0.011805556,"height":0.02111111},"role_description":"text"},{"role":"AXCheckBox","text":"React with white_check_mark","depth":24,"bounds":{"left":0.82708335,"top":0.6488889,"width":0.022222223,"height":0.036666665},"role_description":"toggle button","subrole":"AXToggleButton","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXCheckBox","text":"React with eyes","depth":24,"bounds":{"left":0.84930557,"top":0.6488889,"width":0.022222223,"height":0.036666665},"role_description":"toggle button","subrole":"AXToggleButton","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXCheckBox","text":"React with raised_hands","depth":24,"bounds":{"left":0.8715278,"top":0.6488889,"width":0.022222223,"height":0.036666665},"role_description":"toggle button","subrole":"AXToggleButton","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Add reaction…","depth":24,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Forward message…","depth":24,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXCheckBox","text":"Save for later","depth":24,"role_description":"toggle button","subrole":"AXToggleButton","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXPopUpButton","text":"More actions","depth":24,"role_description":"pop-up button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Nikolay Yankov","depth":22,"bounds":{"left":0.7625,"top":0.72555554,"width":0.072222225,"height":0.025555555},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"","depth":22,"bounds":{"left":0.83402777,"top":0.7277778,"width":0.00625,"height":0.02111111},"role_description":"text"},{"role":"AXLink","text":"Today at 1:59:00 PM","depth":22,"bounds":{"left":0.83958334,"top":0.7311111,"width":0.056944445,"height":0.016666668},"role_description":"link","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"17 minutes ago","depth":23,"bounds":{"left":0.83958334,"top":0.7311111,"width":0.056944445,"height":0.016666668},"role_description":"text"},{"role":"AXStaticText","text":"не е ли датата на която е генерирано?","depth":23,"bounds":{"left":0.7625,"top":0.75222224,"width":0.18333334,"height":0.02111111},"role_description":"text"},{"role":"AXStaticText","text":"","depth":23,"bounds":{"left":0.9458333,"top":0.7544444,"width":0.0027777778,"height":0.018888889},"role_description":"text"},{"role":"AXStaticText","text":"(edited)","depth":23,"bounds":{"left":0.9479167,"top":0.7544444,"width":0.030555556,"height":0.018888889},"role_description":"text"},{"role":"AXStaticText","text":"","depth":23,"bounds":{"left":0.9777778,"top":0.7544444,"width":0.0027777778,"height":0.018888889},"role_description":"text"},{"role":"AXCheckBox","text":"React with white_check_mark","depth":24,"bounds":{"left":0.82708335,"top":0.70666665,"width":0.022222223,"height":0.036666665},"role_description":"toggle button","subrole":"AXToggleButton","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXCheckBox","text":"React with eyes","depth":24,"bounds":{"left":0.84930557,"top":0.70666665,"width":0.022222223,"height":0.036666665},"role_description":"toggle button","subrole":"AXToggleButton","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXCheckBox","text":"React with raised_hands","depth":24,"bounds":{"left":0.8715278,"top":0.70666665,"width":0.022222223,"height":0.036666665},"role_description":"toggle button","subrole":"AXToggleButton","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Add reaction…","depth":24,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Forward message…","depth":24,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXCheckBox","text":"Save for later","depth":24,"role_description":"toggle button","subrole":"AXToggleButton","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXPopUpButton","text":"More actions","depth":24,"role_description":"pop-up button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Lukas Kovalik","depth":22,"bounds":{"left":0.7625,"top":0.78333336,"width":0.06458333,"height":0.025555555},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"","depth":22,"bounds":{"left":0.82708335,"top":0.78555554,"width":0.0055555557,"height":0.02111111},"role_description":"text"},{"role":"AXLink","text":"Today at 1:59:04 PM","depth":22,"bounds":{"left":0.83263886,"top":0.7888889,"width":0.05625,"height":0.016666668},"role_description":"link","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"17 minutes ago","depth":23,"bounds":{"left":0.83263886,"top":0.7888889,"width":0.05625,"height":0.016666668},"role_description":"text"},{"role":"AXStaticText","text":"email ще го видя","depth":23,"bounds":{"left":0.7625,"top":0.81,"width":0.07986111,"height":0.02111111},"role_description":"text"},{"role":"AXCheckBox","text":"React with white_check_mark","depth":24,"bounds":{"left":0.82708335,"top":0.7644445,"width":0.022222223,"height":0.036666665},"role_description":"toggle button","subrole":"AXToggleButton","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXCheckBox","text":"React with eyes","depth":24,"bounds":{"left":0.84930557,"top":0.7644445,"width":0.022222223,"height":0.036666665},"role_description":"toggle button","subrole":"AXToggleButton","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXCheckBox","text":"React with raised_hands","depth":24,"bounds":{"left":0.8715278,"top":0.7644445,"width":0.022222223,"height":0.036666665},"role_description":"toggle button","subrole":"AXToggleButton","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Add reaction…","depth":24,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Forward message…","depth":24,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXCheckBox","text":"Save for later","depth":24,"role_description":"toggle button","subrole":"AXToggleButton","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXPopUpButton","text":"More actions","depth":24,"role_description":"pop-up button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"","depth":25,"bounds":{"left":0.7326389,"top":0.8511111,"width":0.25208333,"height":0.043333333},"value":"","role_description":"text entry area","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"Also send to the group","depth":24,"bounds":{"left":0.75972223,"top":0.9033333,"width":0.08263889,"height":0.016666668},"role_description":"text"},{"role":"AXCheckBox","text":"Also send to the group","depth":24,"bounds":{"left":0.7423611,"top":0.9033333,"width":0.009027778,"height":0.014444444},"role_description":"Tick box","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"loading…","depth":11,"role_description":"text"},{"role":"AXStaticText","text":"loading…","depth":11,"role_description":"text"}]...
|
-1199747662314242072
|
-1785159833251295168
|
visual_change
|
hybrid
|
NULL
|
Jiminny Inc
Jiminny (Staging)
Add workspaces
Home
Jiminny Inc
Jiminny (Staging)
Add workspaces
Home
Home
DMs
DMs
Activity
Activity
Files
Files
Later
Later
More…
More
Unreads
Threads
Huddles
Drafts & sent
Directories
platform-inner-team
ai-chapter
alerts
backend
confusion-clinic
curiosity_lab
engineering
frontend
general
infra-changes
jiminny-bg
platform-tickets
product_launches
random
releases
sofia-office
support
thank-yous
the_people_of_jiminny
Vasil Vasilev
Aneliya Angelova
,
Nikolay Yankov
,
Steliyan Georgiev
Steliyan Georgiev
Adelina Petrova
,
Ilian Kyuchukov
,
Steliyan Georgiev
Adelina Petrova
Galya Dimitrova
Nikolay Nikolov
Galya Dimitrova
,
Nikolay Nikolov
Galya Dimitrova
,
Nikolay Yankov
Nikolay Yankov
Jira Cloud
Toast
Google Calendar
Nikolay Yankov
Today at 1:49:38 PM
27 minutes ago
Добре, 2 неща:
в името на генерирания репорт е дата вчера, не днес
и имейл не дойде
image.png
Toggle file
image.png
Download image.png
Share file: image.png
View canvas details
More actions
5 replies
Lukas Kovalik
Today at 1:58:20 PM
18 minutes ago
за дата там не знам как искаме да го правим. по принцип при всички други се гледа ден на зад при положение че идва през нощта.
React with white_check_mark
React with eyes
React with raised_hands
Add reaction…
Forward message…
Save for later
More actions
Nikolay Yankov
Today at 1:58:22 PM
18 minutes ago
@Lukas Kovalik
@Lukas Kovalik
видя ли този коментар
React with white_check_mark
React with eyes
React with raised_hands
Add reaction…
Forward message…
Save for later
More actions
Lukas Kovalik
Today at 1:58:27 PM
18 minutes ago
да
React with white_check_mark
React with eyes
React with raised_hands
Add reaction…
Forward message…
Save for later
More actions
Nikolay Yankov
Today at 1:59:00 PM
17 minutes ago
не е ли датата на която е генерирано?
(edited)
React with white_check_mark
React with eyes
React with raised_hands
Add reaction…
Forward message…
Save for later
More actions
Lukas Kovalik
Today at 1:59:04 PM
17 minutes ago
email ще го видя
React with white_check_mark
React with eyes
React with raised_hands
Add reaction…
Forward message…
Save for later
More actions
Also send to the group
Also send to the group
loading…
loading…
SlackFileEditViewGoHistoryWindowHelpec2-userGDOCKER₴81DEV (docker)882APP (-zsh)[EMAIL]@73b64f5d54a3:/home/jiminny#[ec2-user@ip-10-30-93-249ny && bash"root@c78a087b1345:/home/jiminny# php artisan automated-reports[2026-04-1410:46:087staging.INFO: [automated-reports]Started~7$ dockerexec -it $(dock{"correlation_id":"5[2026-04-1410:46:087staging. INFO: [automated-reports]Checking conditions {"isMondaid":"5c23e861-2ca9-4f92-9f67-773d6bc80ca0","trace_id" :"185df6f6-4327-4609-9cZe-2ab83a[2026-04-1410:46:08]ab83a0f5432"}staging.INFO: [automated-reports] Processing daily reports[2026-04-1410:46:08]9-9cZe-2ab83a0f5432"}staging.INFO:[automated-reports]Found 3 daily reports to proc(2026-04-1410:46:08]staging.INF0:[automated-reports]Dispatching Generate ReportPSPhpStormroot@c78a087b1345:/home/jiminny# php artisan automated-reports --report-id 35[2026-04-14 10:48:42]staging.INFO: [automated-reports] Started{"correlation_id":"2[2026-04-1410:48:42]staging.INF0: [automated-reports]Checking conditions {"isMondaid":"246alala-7076-458c-bd7d-49d2f5a2db88","trace_id" : "1f894bf6-e50d-4e99-b635-2aa526[2026-04-14 10:48:42]staging.INFO: [automated-reports] Processing daily reportsaa52627fc27"}[automated-reports]Automated report[2026-04-1410:48:42]staging. INFO: [automated-reports]Found 1 daily reports to proc9-b635-2aa52627f c27"}[2026-04-14 10:48:42]staging.INF0: [automated-reports]Dispatching Generate Reportdaily","type": "ask_jiminny"} {"correlation_id":"246a1a1a-7076-458c-bd7d-49d2f5a2db88"[2026-04-14 10:48:42] staging.INF0: [automated-reports]Completed{"correlation_id":root@c78a087b1345:/home/jiminny# [ec2-user@ip-10-30-93-249 ~]$D+EDHomeDMsActivityFileslhl§ Support Daily • in 44 m100% <7Tue 14 Apr 14:16:46→Search Jiminny IncJiminny ...scnicre# infra-changes# jiminny-bg# platform-tickets# product_launches# random# releases# sofia-office# supportthank-vousThread Direct message with 3 othersвчера, не днес• и имейл не дойдеimage.png vМtrрesAOS(3Adelina Petrova, Ili...0. Adelina Petrova. Galya Dimitrova&s Nikolay Nikolov "2 Galya Dimitrova, Ni...2Galya Dimitrova, Ni...P. Nikolay YankovAppsJira CloudToastGoogle Cale... PsNзад при положение че идва през нощід.Nikolay Yankov 18 minutes ago@Lukas Kovalik видя ли този коментарLukas Kovalik 18 minutes agoдаNikolay Yankov 17 minutes agoне е ли датата на която е генерирано? (edited)Lukas Kovalik 17 minutes agoemail ще го видяReply...+Also send to the groupAa...
|
NULL
|
|
12379
|
266
|
15
|
2026-04-14T11:16:50.447485+00:00
|
/Users/lukas/.screenpipe/data/data/2026-04-14/1776 /Users/lukas/.screenpipe/data/data/2026-04-14/1776165410447_m1.jpg...
|
PhpStorm
|
faVsco.js – AutomatedReportsService.php
|
1
|
NULL
|
monitor_1
|
NULL
|
NULL
|
NULL
|
NULL
|
Project: faVsco.js, menu
#11894 on JY-18909-automa Project: faVsco.js, menu
#11894 on JY-18909-automated-reports-ask-jiminny, menu
Start Listening for PHP Debug Connections
AutomatedReportsCommandTest
Run 'AutomatedReportsCommandTest'
Debug 'AutomatedReportsCommandTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Execute
Explain Plan
Browse Query History
View Parameters
Open Query Execution Settings…
In-Editor Results
Tx: Auto
Cancel Running Statements
Playground
jiminny
Sync Changes
Hide This Notification
Code changed:
Hide
16
13
13
Previous Highlighted Error
Next Highlighted Error
SELECT * FROM teams WHERE id = 1;
select * from crm_layouts where crm_configuration_id = 39;
SELECT * FROM crm_layout_entities WHERE crm_layout_id = 283;
SELECT * FROM crm_fields WHERE id = 2234;
SELECT * FROM crm_field_values WHERE crm_field_id = 2234;
select * from crm_profiles where user_id = 143;
select * from record_types where crm_configuration_id = 39; # 0121K000001MHElQAO,0121K000001MHEqQAO
select * from business_processes where crm_configuration_id = 39;
# 01941000000H669AAC, 01941000000H66JAAS
select * from record_type_field_values
where record_type_id IN (24);
select * from crm_field_values where id IN (2730);
select * from crm_configurations where id = 39;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 1
and sa.provider = 'salesforce'; #1035
select * from users where team_id = 1; # 222 group 3
SELECT * FROM activities WHERE user_id = 222 order by id desc;
select * from sidekick_settings where team_id = 1;
select * from teams where id = 1;
select * from team_features where team_id = 1;
select * from activities where crm_configuration_id = 2
and provider = 'ms-teams' and id = 608765;
SELECT * FROM activities WHERE crm_configuration_id = 2 and crm_provider_id = '59523413338';
select * from sidekick_settings where team_id = 2;
SELECT * FROM activities WHERE id = 608660;
select * from activity_summary_logs where activity_id = 608660;
select * from ai_prompts where transcription_id = 11214;
# [PASSWORD_DOTS]
SELECT * FROM activities WHERE uuid_to_bin('ed78a437-2804-450e-ab2f-56ab1c641346') = uuid;
# id: 608818, crm: 59628809737
SELECT * FROM activities WHERE uuid_to_bin('36b06e55-afdd-4782-8dee-c624cd0af191') = uuid;
# id: 608821, crm: 59632069252
SELECT ce.start_time, ce.end_time, a.id, a.uuid, crm_provider_id, calendar_event_id, title,
playbook_category_id, user_id, lead_id, contact_id, account_id, opportunity_id,
scheduled_start_time, scheduled_end_time, actual_start_time, actual_end_time, a.created_at
FROM activities a
join calendar_events ce on a.calendar_event_id = ce.id
WHERE a.id IN (608818, 608821);
select * from users where team_id = 1;
select * from team_settings where team_id = 1;
select * from crm_profiles where crm_configuration_id = 39 order by user_id;
select * from team_features where team_id = 1;
select * from users where team_id = 2;
SELECT * FROM activities WHERE uuid_to_bin('ec7647e9-5225-458b-b475-f31aa2769204') = uuid; # 612639
# Preslava N. Ivanova, grou id 3
SELECT * FROM opportunities WHERE uuid_to_bin('a2928fe5-aec5-46cb-85d9-7654c89e46a6') = uuid;
select * from activities where opportunity_id = 344 and actual_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00';
select
a.id,
a.type,
a.scheduled_start_time,
a.actual_start_time,
a.created_at,
a.opportunity_id,
a.status
FROM activities a
WHERE opportunity_id = 344
and status IN ('completed', 'received', 'delivered')
and (
(a.actual_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00')
OR (a.created_at between '2024-10-11 00:00:00' and '2024-10-12 00:00:00')
OR (a.scheduled_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00'))
;
SELECT * FROM users WHERE id = 222;
SELECT * FROM crm_profiles WHERE user_id = 222;
select * from crm_layouts where crm_configuration_id = 39;
SELECT * FROM crm_layout_entities WHERE crm_layout_id = 281;
select * from group_deal_risk_types;
select * from opportunities where team_id = 1;
SELECT * FROM opportunities WHERE id = 315;
SELECT * FROM crm_field_data WHERE object_id = 315;
select * from crm_field_data where object_id = 260;
select * from generic_ai_prompts where subject_id = 315;
select * from teams; # 36, 21, 121, [EMAIL]
SELECT * FROM social_accounts WHERE sociable_id = 121 and provider = 'bullhorn';
# [PASSWORD_DOTS]
select * from teams where id = 1;
select * from crm_configurations where id = 39;
select * from users where team_id = 1;
select u.email, cp.* from users u
join crm_profiles cp on u.id = cp.user_id
where u.team_id = 1;
# 1 - 00541000004281rAAA
# 204 - 0052g000003freeAAA
# 429 - 0052g000003qGOiAAM
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 1
and sa.provider = 'salesforce';
select * from activities where type = 'softphone'
and created_at > '2024-12-11 15:24:36' order by id desc;
select * from activity_providers where team_id = 1;
select * from activity_provider_users where activity_provider_id = 328;
select * from opportunities where crm_configuration_id = 39
AND account_id = 178 AND is_closed = false
order by created_at DESC;
select * from contacts where id = 3952;
select * from accounts where id = 178;
# [PASSWORD_DOTS]
select * from teams where id = 36;
select * from crm_configurations where id = 21;
select * from users where team_id = 36;
select u.email, cp.* from users u
join crm_profiles cp on u.id = cp.user_id
where u.team_id = 36;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 36
and sa.provider = 'bullhorn';
select * from social_accounts where id = 348;
UPDATE social_accounts SET
provider_user_token = '21442_6802599_91:41179a58-21e7-4d7c-ad58-56bb666b2f65',
provider_refresh_token = '21442_6802599_91:01c6b335-3f2a-42e4-85ff-8a08fa65fceb',
expires = 1733998131,
state = 'connected'
WHERE id = 348;
# [PASSWORD_DOTS]
select * from teams where id = 31;
select * from crm_configurations where id = 18;
select * from users where team_id = 31; # 257
select u.email, cp.* from users u
join crm_profiles cp on u.id = cp.user_id
where u.team_id = 31;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 31
and sa.provider = 'close';
select * from contacts where crm_configuration_id = 18;
# [PASSWORD_DOTS] NEPTUNE [PASSWORD_DOTS]
select * from teams;
select * from users where id IN (1030, 1035, 1052);
select * from crm_configurations;
select * from users where team_id = 65; # 257
select * from team_settings where team_id = 65; # 257
select * from invitations where team_id = 65; # 257
select * from users where email = '[EMAIL]'; # 257
select u.email, cp.* from users u
join crm_profiles cp on u.id = cp.user_id
where u.team_id = 65;
select * from crm_configurations where id = 53;
select * from accounts where crm_configuration_id = 53 order by id desc;
select * from leads where crm_configuration_id = 53 order by id desc;
select * from contacts where crm_configuration_id = 53 order by id desc;
select * from opportunities where crm_configuration_id = 53 order by id desc;
select * from crm_profiles where crm_configuration_id = 53 order by id desc;
select * from crm_fields where crm_configuration_id = 53 order by id desc;
select * from crm_field_values where crm_field_id = 3341 order by id desc;
select * from crm_layouts where crm_configuration_id = 53 order by id desc;
select * from stages where crm_configuration_id = 53 order by id desc;
select * from crm_profiles where crm_configuration_id = 13;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 65
and sa.provider = 'integration-app';
select * from contacts where crm_configuration_id = 13;
select * from social_accounts where sociable_id = 283;
SELECT * FROM opportunities WHERE crm_provider_id = '006O400000E9bzeIAB';
select * from activity_providers where team_id = 65;
SELECT * FROM activities WHERE crm_configuration_id IN (51, 52, 53);
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 65
;
# [PASSWORD_DOTS] STAGING [PASSWORD_DOTS]
SELECT * FROM teams;
SELECT * FROM teams WHERE id = 88;
SELECT * FROM teams WHERE id = 89;
select * from team_settings where team_id = 89;
SELECT * FROM users WHERE team_id = 89;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 89;
select * from users;
SELECT * FROM social_accounts WHERE sociable_id = 1761;
SELECT * FROM crm_configurations WHERE id = 70;
select * from accounts where crm_configuration_id = 70 order by id desc;
select * from leads where crm_configuration_id = 70 order by id desc;
select * from contacts where crm_configuration_id = 70 order by id desc;
select * from opportunities where crm_configuration_id = 70 order by id desc;
select * from crm_profiles where crm_configuration_id = 70 order by id desc;
select * from crm_fields where crm_configuration_id = 70 order by id desc;
select * from crm_field_values where crm_field_id = 3536 order by id desc;
select * from crm_layouts where crm_configuration_id = 70 order by id desc;
select * from stages where crm_configuration_id = 70 order by id desc;
select * from business_processes where crm_configuration_id = 70 order by id desc;
select * from business_process_stages where business_process_id = 34;
select * from contacts where id = 10468;
select * from crm_layouts where crm_configuration_id = 70;
SELECT * FROM crm_layout_entities WHERE crm_layout_id = 388;
SELECT * FROM crm_fields WHERE id IN (3533,3534,3535);
select * from activities where crm_configuration_id = 70
and (account_id IS NOT NULL or lead_id IS NOT NULL or contact_id IS NOT NULL or opportunity_id IS NOT NULL) order by id desc;
SELECT * FROM activities WHERE uuid_to_bin('2e10b60f-8a61-41c5-a3d4-28835353dc65') = uuid;
SELECT * FROM activities where crm_configuration_id = 69 ;
SELECT * FROM users WHERE email LIKE '%[EMAIL]%';
SELECT * FROM activities WHERE uuid_to_bin('5a150c93-40fc-42ec-b3bd-c1d328e09f6e') = uuid;
SELECT * FROM opportunities WHERE id = 385;
select * from participants p
join activities a on p.activity_id = a.id
where a.crm_configuration_id = 70
and (p.lead_id IS NOT NULL or p.contact_id IS NOT NULL);
SELECT * FROM participants WHERE id = 1013638;
select * from teams where id = 90;
select * from users where team_id = 90;
select * from social_accounts where social_accounts.sociable_id IN (1960,1760);
SELECT * FROM crm_profiles WHERE crm_configuration_id = 71;
select * from invitations where team_id = 90;
select * from crm_configurations where id = 71;
select * from accounts where crm_configuration_id = 71 order by id desc;
select * from leads where crm_configuration_id = 71 order by id desc;
select * from contacts where crm_configuration_id = 71 order by id desc;
select * from opportunities where crm_configuration_id = 71 order by id desc;
select * from crm_profiles where crm_configuration_id = 71 order by id desc;
select * from crm_fields where crm_configuration_id = 71 order by id desc;
select * from crm_field_values where crm_field_id = 3341 order by id desc;
select * from crm_layouts where crm_configuration_id = 71 order by id desc;
select * from stages where crm_configuration_id = 71 order by id desc;
select * from users order by secondary_email desc;
select u.id, u.email, u.status, sa.id, sa.provider_user_id from social_accounts sa
join users u on sa.sociable_id = u.id
where sa.provider = 'google' and u.email LIKE 'aneliya%';
select * from failed_jobs order by id desc;
select * from users where email = '[EMAIL]' or secondary_email = '[EMAIL]';
select * from teams;
SELECT * FROM crm_profiles WHERE crm_configuration_id = 39;
SELECT * FROM crm_fields WHERE crm_configuration_id = 39 and object_type = 'task';
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 1
and sa.provider = 'salesforce';
# [PASSWORD_DOTS]
SELECT * FROM activities WHERE uuid_to_bin('c38b3895-fd0f-4b1f-9fb2-c170dba137c6') = uuid;
SELECT * FROM crm_configurations WHERE id = 70;
select * from teams where id = 1;
select * from groups where team_id = 1;
select * from users where team_id = 1;
select o.id, o.name,o.close_date, u.id, u.name, u.group_id, r.id, r.display_name, g.name, g.scope from opportunities o
join users u on o.user_id = u.id
join groups g on u.group_id = g.id
join role_user ru on u.id = ru.user_id
join roles r on ru.role_id = r.id
where o.crm_configuration_id = 39 and close_date > '2024-01-01 00:00:00';
select * from role_user where user_id = 143;
select * from roles;
select * from role_user;
select * from groups where id = 9;
select * from scope_groups where group_id = 9;
# [PASSWORD_DOTS]
select * from teams where id = 36;
select * from crm_configurations;
SELECT * FROM social_accounts WHERE sociable_id = 121;
[URL_WITH_CREDENTIALS] this will add filter, however if we need to control feature by FF we need conditional logic
public const array TYPES = [
['id' => 'exec_summary', 'name' => 'Exec Summary'],
['id' => 'coaching_profiles', 'name' => 'Coaching Profiles'],
['id' => 'product_feedback', 'name' => 'Product Feedback'],
['id' => self::TYPE_LOSS_ANALYSIS, 'name' => 'Loss Analysis'],
// ['id' => 'questions', 'name' => 'Questions'],
// ['id' => 'statistical_quant', 'name' => 'Statistical Quantitative'],
];
public const array ALL_TYPES = [
...self::TYPES,
['id' => self::TYPE_ASK_JIMINNY, 'name' => 'Ask Jiminny'],
];
public const string FREQUENCY_DAILY = 'daily';
public const string FREQUENCY_WEEKLY = 'weekly';
public const string FREQUENCY_MONTHLY = 'monthly';
public const string FREQUENCY_QUARTERLY = 'quarterly';
public const string FREQUENCY_ONE_OFF = 'one_off';
/**
* Frequencies for standard (non-Ask Jiminny) reports.
*/
public const array FREQUENCIES = [
['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],
['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],
['id' => self::FREQUENCY_QUARTERLY, 'name' => 'Quarterly'],
['id' => self::FREQUENCY_ONE_OFF, 'name' => 'One-off'],
];
/**
* Frequencies for Ask Jiminny reports.
*/
public const array ASK_JIMINNY_FREQUENCIES = [
['id' => self::FREQUENCY_DAILY, 'name' => 'Daily'],
['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],
['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],
];
public const string MEDIA_TYPE_PDF = 'pdf';
public const string MEDIA_TYPE_PODCAST = 'podcast';
public const array MEDIA_TYPES = [self::MEDIA_TYPE_PDF, self::MEDIA_TYPE_PODCAST];
public const array MEDIA_TYPE_OBJECT_PDF = ['id' => self::MEDIA_TYPE_PDF, 'name' => 'PDF'];
public const array MEDIA_TYPE_OBJECT_PODCAST = ['id' => self::MEDIA_TYPE_PODCAST, 'name' => 'Podcast'];
public const array MEDIA_TYPE_OBJECTS = [self::MEDIA_TYPE_OBJECT_PDF, self::MEDIA_TYPE_OBJECT_PODCAST];
public const array CALL_TYPE_CONFERENCE = ['id' => 'conference', 'name' => 'Conference'];
public const array CALL_TYPE_DIALER = ['id' => 'dialer', 'name' => 'Dialer'];
public const int SENT_REPORT_AT_HOURS = 5;
public const string PDF_KEY = 'pdf';
public const string AUDIO_KEY = 'audio';
private const array ALL_FREQUENCIES = [
['id' => self::FREQUENCY_DAILY, 'name' => 'Daily'],
['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],
['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],
['id' => self::FREQUENCY_QUARTERLY, 'name' => 'Quarterly'],
['id' => self::FREQUENCY_ONE_OFF, 'name' => 'One-off'],
];
private const string S3_DIR = 'reports';
private const array FILE_EXTENSIONS_VARIANTS = ['html', 'MD', 'pdf'];
private const array FILE_PODCAST_EXTENSIONS_VARIANTS = ['json', 'mp3', 'ssml'];
public function __construct(
private readonly TeamRepository $teamRepository,
private readonly GroupRepository $groupRepository,
private readonly UserRepository $userRepository,
private readonly StageRepository $stageRepository,
private readonly DealStagesService $dealStagesService,
private readonly RecipientsService $recipientsService,
private readonly AutomatedReportsRepository $automatedReportsRepository,
private readonly Webhook $webhookService,
private readonly BusDispatcher $dispatcher,
private readonly ActivityTypeService $activityTypeService,
private readonly PlaybookCategoryRepository $playbookCategoryRepository,
private readonly AskAnythingPromptService $askAnythingPromptService,
private readonly SearchRepository $activitySearchRepository,
private readonly AskAnythingRepository $askAnythingRepository,
) {
}
public static function getTypes(): array
{
$types = self::TYPES;
return array_map(static function ($type) {
return $type['id'];
}, $types);
}
public static function getCallTypes(): array
{
return array_map(static function ($callType) {
return $callType['id'];
}, [self::CALL_TYPE_CONFERENCE, self::CALL_TYPE_DIALER]);
}
public static function getFrequencies(): array
{
return array_map(static function ($frequency) {
return $frequency['id'];
}, self::FREQUENCIES);
}
// front-facing structure
public function getReportEnabledFieldData(bool $value = false): array
{
return [
'id' => 'report_enabled',
'label' => '',
'inputType' => InputTypeEnum::TOGGLE,
'value' => $value,
];
}
// Organizations = Teams
public function getOrganizationFieldData(?string $value = null, bool $shortVersion = false): array
{
$options = $this->getTeams();
if ($shortVersion) {
return [
'id' => 'organization',
'label' => 'Organization',
'options' => $options,
];
}
return [
'id' => 'organization',
'label' => 'Organization',
'inputType' => InputTypeEnum::DROPDOWN,
'required' => true,
'placeholder' => 'Select',
'options' => $options,
'value' => $value,
'dependencies' => [
'teams',
'deal_stage_at_call',
'current_deal_stage',
'recipients',
ActivityTypeService::PLAYBOOK_CATEGORIES_KEY,
],
'dependsOn' => [],
];
}
// Teams = Groups
public function getTeamFieldData(array $options = [], array $value = [], bool $shortVersion = false): array
{
if ($shortVersion) {
return [
'id' => 'teams',
'label' => 'Team',
'options' => $options,
];
}
return [
'id' => 'teams',
'label' => 'Team',
'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,
'required' => false,
'placeholder' => 'Select',
'options' => $options,
'value' => $value, // value should be an array of objects {id, name}
'dependencies' => [ActivityTypeService::PLAYBOOK_CATEGORIES_KEY],
'dependsOn' => [],
];
}
public function getReportTypeFieldData(?string $value = null, bool $shortVersion = false, ?Team $team = null): array
{
$types = [];
if ($team instanceof Team) {
if ($team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {
$types = self::TYPES;
}
if ($team->hasFeature(FeatureEnum::ASK_JIMINNY_REPORTS)) {
$types[] = ['id' => self::TYPE_ASK_JIMINNY, 'name' => 'Ask Jiminny'];
}
} else {
$types = self::TYPES;
}
if ($shortVersion) {
return [
'id' => 'report_type',
'label' => 'Report Type',
'options' => $types,
];
}
return [
'id' => 'report_type',
'label' => 'Report Type',
'inputType' => InputTypeEnum::DROPDOWN,
'required' => true,
'placeholder' => 'Select',
'options' => $types,
'value' => $value,
'dependencies' => [],
'dependsOn' => [],
];
}
public function getFrequencyFieldData(?string $value = null): array
{
return [
'id' => 'frequency',
'label' => 'Frequency',
'inputType' => InputTypeEnum::DROPDOWN,
'required' => true,
'placeholder' => 'Select',
'options' => self::FREQUENCIES,
'value' => $value,
'dependencies' => ['period'],
'dependsOn' => [],
];
}
public function getPeriodFieldData(?string $valueStartDate = null, ?string $valueEndDate = null): array
{
return [
'id' => 'period',
'label' => 'Select one-off period',
'inputType' => InputTypeEnum::DATE_RANGE,
'required' => true,
'placeholder' => 'Select',
'value' => ['startDate' => $valueStartDate, 'endDate' => $valueEndDate],
'queryParams' => [
'startDate' => 'start_date_period',
'endDate' => 'end_date_period',
],
'dependencies' => [],
'dependsOn' => ['frequency'],
];
}
public function getActivityTypesFieldData(?Team $team = null, array $value = [], array $teamsFilter = []): array
{
return $this->activityTypeService->getActivityTypeFieldData(team: $team, value: $value, groupIds: $teamsFilter);
}
public function getDealStageAtCallFieldData(?Team $team = null, array $value = []): array
{
return $this->dealStagesService->getDealStageAtCallFieldData(team: $team, value: $value);
}
public function getCurrentDealStageFieldData(?Team $team = null, array $value = []): array
{
return $this->dealStagesService->getCurrentDealStageFieldData(team: $team, value: $value);
}
public function getDealValueFieldData(?int $valueMin = null, ?int $valueMax = null): array
{
return [
'id' => 'deal_value',
'label' => 'Deal Value',
'inputType' => InputTypeEnum::INTEGER_RANGE,
'required' => false,
'value' => ['min' => $valueMin, 'max' => $valueMax],
'queryParams' => [
'min' => 'min_deal_value',
'max' => 'max_deal_value',
],
'dependencies' => [],
'dependsOn' => [],
];
}
public function getCallTypeFieldData(bool $conferenceOn = false, bool $dialerOn = false): array
{
$value = [];
$conferenceOn && $value[] = self::CALL_TYPE_CONFERENCE;
$dialerOn && $value[] = self::CALL_TYPE_DIALER;
return [
'id' => 'call_type',
'label' => 'Call Type',
'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,
'required' => true,
'options' => [
self::CALL_TYPE_CONFERENCE,
self::CALL_TYPE_DIALER,
],
'value' => $value,
'dependencies' => [],
'dependsOn' => [],
];
}
public function getMediaTypeFieldData(?AutomatedReport $report = null): array
{
$value = [];
if ($report) {
$value = $this->transformMediaTypes($report);
}
return [
'id' => 'media_types',
'label' => 'Export as',
'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,
'required' => true,
'options' => self::MEDIA_TYPE_OBJECTS,
'value' => $value,
'dependencies' => [],
'dependsOn' => [],
];
}
public function getCallDurationFieldData(?int $valueMin = null, ?int $valueMax = null): array
{
return [
'id' => 'call_duration',
'label' => 'Call Duration',
'inputType' => InputTypeEnum::INTEGER_RANGE,
'required' => false,
'value' => ['min' => $valueMin, 'max' => $valueMax],
'queryParams' => [
'min' => 'min_call_duration',
'max' => 'max_call_duration',
],
'dependencies' => [],
'dependsOn' => [],
];
}
public function getRecipientsFieldData(?Team $team = null, array $value = []): array
{
return $this->recipientsService->getRecipientsFieldData(team: $team, value: $value);
}
public function getJiminnyRecipientsFieldData(array $value = []): array
{
return $this->recipientsService->getJiminnyRecipientsFieldData($value);
}
public function getAdditionalPromptInputFieldData(?string $value = null): array
{
return [
'id' => 'additional_prompt_input',
'label' => 'Special requirements',
'inputType' => InputTypeEnum::TEXTAREA,
'required' => false,
'placeholder' => 'What should be the focus of the report?',
'value' => $value,
'dependencies' => [],
'dependsOn' => [],
];
}
public function getCustomReportNameFieldData(?string $value = null): array
{
return [
'id' => 'custom_name',
'label' => 'Custom report name',
'inputType' => InputTypeEnum::TEXT,
'required' => false,
'placeholder' => 'Enter custom name',
'value' => $value,
'dependencies' => [],
'dependsOn' => [],
];
}
// data providers
public function getTeams(): array
{
$teams = $this->teamRepository->getTeamsForKiosk(status: Team::STATUS_ACTIVE);
$teamData = [];
foreach ($teams as $team) {
if (! $team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {
continue;
}
$teamData[] = $this->transformTeam($team);
}
return $teamData;
}
public function getTeamGroups(string $teamUuid): array
{
$data = [];
$team = $this->getTeam($teamUuid);
if ($team !== null) {
$groups = $team->groups()->get();
foreach ($groups as $group) {
$data[] = [
'id' => $group->getUuid(),
'name' => $group->getName(),
];
}
}
return $data;
}
public function getTeamsGroupsOptions(array $filterTeamUuids = []): array
{
$data = [];
$teams = $this->getTeams();
foreach ($teams as $team) {
if (! empty($filterTeamUuids) && ! in_array($team['id'], $filterTeamUuids, true)) {
continue;
}
$data[] = [
'label' => $team['name'],
'groups' => $this->getTeamGroups($team['id']),
];
}
return $data;
}
public function getTeam(string $teamUuid): ?Team
{
return $this->teamRepository->idOrUuid($teamUuid);
}
public function getTeamById(int $teamId): ?Team
{
return $this->teamRepository->find($teamId);
}
public function getGroupsUuids(AutomatedReport $report): array
{
$uuids = [];
$reportGroups = $report->getGroups();
foreach ($reportGroups as $groupId) {
if ($group = $this->groupRepository->find($groupId)) {
$uuids[] = $group->getUuid();
}
}
return $uuids;
}
public function getPlaybookCategoriesUuids(AutomatedReport $report): array
{
$uuids = [];
$playbookCategories = $report->getPlaybookCategories();
foreach ($playbookCategories as $id) {
if ($category = $this->playbookCategoryRepository->find($id)) {
$uuids[] = $category->getUuid();
}
}
return $uuids;
}
public function getDealAtCallStagesUuids(AutomatedReport $report): array
{
$uuids = [];
$reportStages = $report->getDealAtCallStages();
foreach ($reportStages as $id) {
if ($stage = $this->stageRepository->find($id)) {
$uuids[] = $stage->getUuid();
}
}
return $uuids;
}
public function getCurrentDealStagesUuids(AutomatedReport $report): array
{
$uuids = [];
$reportStages = $report->getCurrentDealStages();
foreach ($reportStages as $id) {
if ($stage = $this->stageRepository->find($id)) {
$uuids[] = $stage->getUuid();
}
}
return $uuids;
}
public function getUsersUuids(AutomatedReport $report): array
{
return $this->extractUserUuids($report->getRecipients());
}
public function getJiminnyUsersUuids(AutomatedReport $report): array
{
return $this->extractUserUuids($report->getJiminnyRecipients());
}
/**
* @param array<string, mixed> $recipients
*/
private function extractUserUuids(array $recipients): array
{
$userIds = $recipients['users'] ?? [];
return collect($userIds)
->map(fn ($id) => $this->userRepository->find((int) $id))
->filter()
->map(fn (UserContract $user) => $user->getUuid())
->values()
->all();
}
// get mail data
public function getRecipientUsers(AutomatedReport $report): array
{
return $this->buildRecipientUsers($report->getRecipients());
}
private function getJiminnyRecipientUsers(AutomatedReport $report): array
{
return $this->buildRecipientUsers($report->getJiminnyRecipients());
}
/**
* @param array<string, mixed> $recipients
*/
private function buildRecipientUsers(array $recipients): array
{
$userIds = $recipients['users'] ?? [];
return collect($userIds)
->map(fn ($id) => $this->userRepository->find((int) $id))
->filter()
->map(fn (UserContract $user) => [
'email' => $user->getEmailAddress(),
'name' => $user->getName(),
'timezone' => $user->getTimezone()->getName(),
])
->values()
->all();
}
public function getValidRecipientUsers(AutomatedReport $report, bool $includeJiminny = false): array
{
if ($report->isAskJiminnyReport()) {
$recipients = $this->resolveAskJiminnyRecipients($report);
} else {
$recipients = $this->getRecipientUsers($report);
if ($includeJiminny) {
$recipients = array_merge($recipients, $this->getJiminnyRecipientUsers($report));
}
}
$emails = [];
return array_values(array_filter(
$recipients,
static function ($recipient) use (&$emails) {
if (empty($recipient['email']) || in_array($recipient['email'], $emails, true)) {
return false;
}
$emails[] = $recipient['email'];
return true;
}
));
}
private function resolveAskJiminnyRecipients(AutomatedReport $report): array
{
$recipients = [];
$creator = $report->getCreator();
if ($creator !== null) {
$recipients[] = [
'email' => $creator->getEmailAddress(),
'name' => $creator->getName(),
'timezone' => $creator->getTimezone()->getName(),
];
}
return array_merge(
$recipients,
$this->buildRecipientUsers($report->getRecipients()),
$this->getGroupRecipientUsers($report),
);
}
private function getGroupRecipientUsers(AutomatedReport $report): array
{
$users = [];
foreach ($report->getGroups() as $groupId) {
$group = $this->groupRepository->find($groupId);
if ($group === null) {
continue;
}
foreach ($group->getMembers() as $member) {
$users[] = [
'email' => $member->getEmailAddress(),
'name' => $member->getName(),
'timezone' => $member->getTimezone()->getName(),
];
}
}
return $users;
}
public function getReportTypeName(AutomatedReportResult $report): string
{
$type = $report->getReport()->getType();
$getType = $this->transformReportType($type);
return $getType['name'];
}
public function getReportPeriodName(AutomatedReportResult $report): string
{
$from = $report->getFromDate();
$to = $report->getToDate();
$frequency = $report->getReport()->getFrequency();
if ($from === null || $to === null) {
if (! $report->getReport()->isAskJiminnyReport()) {
$invalidPeriod = $from === null ? 'from' : 'to';
throw new ApplicationException('Report period is invalid: ' . $invalidPeriod);
}
$period = $this->calculateFromAndToDatePeriod($frequency);
$from = $period['fromDate'];
$to = $period['toDate'];
}
return $this->formatReportPeriodName($frequency, $from, $to);
}
private function formatReportPeriodName(string $frequency, Carbon $from, Carbon $to): string
{
$fromYear = $from->format('Y');
$toYear = $to->format('Y');
$differentYears = $fromYear !== $toYear;
switch ($frequency) {
case self::FREQUENCY_DAILY:
return $from->format('j M Y');
case self::FREQUENCY_QUARTERLY:
// 'Jan-Mar 2025' or 'Nov 2024-Jan 2025' if years differ
$startMonth = $from->format('M');
$endMonth = $to->copy()->subMonth();
$endMonthName = $endMonth->format('M');
$endMonthYear = $endMonth->format('Y');
if ($differentYears) {
return "{$startMonth} {$fromYear} - {$endMonthName} {$endMonthYear}";
}
return "{$startMonth} - {$endMonthName} {$toYear}";
case self::FREQUENCY_MONTHLY:
// 'May 2025' - monthly reports are always within the same year
return $from->format('M Y');
case self::FREQUENCY_WEEKLY:
// '4 - 8 Aug 2025', '27 Oct - 3 Nov 2025', or '28 Dec 2024 - 3 Jan 2025' if years differ
$startDay = $from->format('j');
$endDay = $to->format('j');
$startMonth = $from->format('M');
$endMonth = $to->format('M');
if ($differentYears) {
return "{$startDay} {$startMonth} {$fromYear} - {$endDay} {$endMonth} {$toYear}";
}
if ($startMonth !== $endMonth) {
return "{$startDay} {$startMonth} - {$endDay} {$endMonth} {$toYear}";
}
return "{$startDay} - {$endDay} {$endMonth} {$toYear}";
case self::FREQUENCY_ONE_OFF:
// '2 May-31 May 2025' or '15 Dec 2024-15 Jan 2025' if years differ
$startDay = $from->format('j');
$startMonth = $from->format('M');
$endDay = $to->format('j');
$endMonth = $to->format('M');
// If same month and year, use a format like '2-31 May 2025'
if ($startMonth === $endMonth && ! $differentYears) {
return "{$startDay} - {$endDay} {$startMonth} {$toYear}";
}
// If different years, include both years
if ($differentYears) {
return "{$startDay} {$startMonth} {$fromYear} - {$endDay} {$endMonth} {$toYear}";
}
// Same year but different months
return "{$startDay} {$startMonth} - {$endDay} {$endMonth} {$toYear}";
default:
// Default format for unknown frequencies
return $from->format('j M Y') . ' - ' . $to->format('j M Y');
}
}
public function getReportTeamsName(AutomatedReportResult $report): string
{
$groups = $report->getGroups();
if (empty($groups)) {
return 'All';
}
// Get group names from repository
$groupNames = [];
foreach ($groups as $groupId) {
$group = $this->groupRepository->find($groupId);
if ($group) {
$groupNames[] = $group->getName();
}
}
if (count($groupNames) === 1) {
// Single team format
$teamsName = $groupNames[0];
} else {
// Multiple teams format
$teamsName = implode(', ', $groupNames);
}
return $teamsName;
}
public function getReportFileName(AutomatedReportResult $report): string
...
|
[{"role":"AXButton","text" [{"role":"AXButton","text":"Project: faVsco.js, menu","depth":5,"help_text":"~/jiminny/app","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"#11894 on JY-18909-automated-reports-ask-jiminny, menu","depth":5,"help_text":"Pull request #11894 exists for current branch JY-18909-automated-reports-ask-jiminny","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Start Listening for PHP Debug Connections","depth":5,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"AutomatedReportsCommandTest","depth":6,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Run 'AutomatedReportsCommandTest'","depth":6,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Debug 'AutomatedReportsCommandTest'","depth":6,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"More Actions","depth":6,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JetBrains AI","depth":5,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Search Everywhere","depth":5,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"IDE and Project Settings","depth":5,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Execute","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Explain Plan","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Browse Query History","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"View Parameters","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Open Query Execution Settings…","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"In-Editor Results","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Tx: Auto","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Cancel Running Statements","depth":4,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Playground","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"jiminny","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.088194445,"height":0.027777778},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"16","depth":4,"role_description":"text"},{"role":"AXStaticText","text":"13","depth":4,"role_description":"text"},{"role":"AXStaticText","text":"13","depth":4,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"SELECT * FROM teams WHERE id = 1;\n\nselect * from crm_layouts where crm_configuration_id = 39;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 283;\nSELECT * FROM crm_fields WHERE id = 2234;\nSELECT * FROM crm_field_values WHERE crm_field_id = 2234;\n\nselect * from crm_profiles where user_id = 143;\n\nselect * from record_types where crm_configuration_id = 39; # 0121K000001MHElQAO,0121K000001MHEqQAO\nselect * from business_processes where crm_configuration_id = 39;\n# 01941000000H669AAC, 01941000000H66JAAS\n\nselect * from record_type_field_values\n where record_type_id IN (24);\n\nselect * from crm_field_values where id IN (2730);\n\nselect * from crm_configurations where id = 39;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 1\nand sa.provider = 'salesforce'; #1035\n\n\nselect * from users where team_id = 1; # 222 group 3\nSELECT * FROM activities WHERE user_id = 222 order by id desc;\nselect * from sidekick_settings where team_id = 1;\nselect * from teams where id = 1;\nselect * from team_features where team_id = 1;\n\nselect * from activities where crm_configuration_id = 2\nand provider = 'ms-teams' and id = 608765;\n\nSELECT * FROM activities WHERE crm_configuration_id = 2 and crm_provider_id = '59523413338';\n\nselect * from sidekick_settings where team_id = 2;\n\nSELECT * FROM activities WHERE id = 608660;\nselect * from activity_summary_logs where activity_id = 608660;\nselect * from ai_prompts where transcription_id = 11214;\n\n# ********************************************************************************************************\nSELECT * FROM activities WHERE uuid_to_bin('ed78a437-2804-450e-ab2f-56ab1c641346') = uuid;\n# id: 608818, crm: 59628809737\nSELECT * FROM activities WHERE uuid_to_bin('36b06e55-afdd-4782-8dee-c624cd0af191') = uuid;\n# id: 608821, crm: 59632069252\nSELECT ce.start_time, ce.end_time, a.id, a.uuid, crm_provider_id, calendar_event_id, title,\nplaybook_category_id, user_id, lead_id, contact_id, account_id, opportunity_id,\nscheduled_start_time, scheduled_end_time, actual_start_time, actual_end_time, a.created_at\nFROM activities a\njoin calendar_events ce on a.calendar_event_id = ce.id\nWHERE a.id IN (608818, 608821);\n\nselect * from users where team_id = 1;\nselect * from team_settings where team_id = 1;\nselect * from crm_profiles where crm_configuration_id = 39 order by user_id;\n\nselect * from team_features where team_id = 1;\n\nselect * from users where team_id = 2;\n\nSELECT * FROM activities WHERE uuid_to_bin('ec7647e9-5225-458b-b475-f31aa2769204') = uuid; # 612639\n# Preslava N. Ivanova, grou id 3\n\nSELECT * FROM opportunities WHERE uuid_to_bin('a2928fe5-aec5-46cb-85d9-7654c89e46a6') = uuid;\n\nselect * from activities where opportunity_id = 344 and actual_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00';\n\nselect\n a.id,\n a.type,\n a.scheduled_start_time,\n a.actual_start_time,\n a.created_at,\n a.opportunity_id,\n a.status\nFROM activities a\nWHERE opportunity_id = 344\nand status IN ('completed', 'received', 'delivered')\nand (\n (a.actual_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00')\nOR (a.created_at between '2024-10-11 00:00:00' and '2024-10-12 00:00:00')\nOR (a.scheduled_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00'))\n;\n\nSELECT * FROM users WHERE id = 222;\n\nSELECT * FROM crm_profiles WHERE user_id = 222;\nselect * from crm_layouts where crm_configuration_id = 39;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 281;\n\nselect * from group_deal_risk_types;\n\nselect * from opportunities where team_id = 1;\n\nSELECT * FROM opportunities WHERE id = 315;\nSELECT * FROM crm_field_data WHERE object_id = 315;\nselect * from crm_field_data where object_id = 260;\n\nselect * from generic_ai_prompts where subject_id = 315;\n\nselect * from teams; # 36, 21, 121, james.graham@bullhorn.jiminny.com\nSELECT * FROM social_accounts WHERE sociable_id = 121 and provider = 'bullhorn';\n\n# ************************************************************************************\nselect * from teams where id = 1;\nselect * from crm_configurations where id = 39;\nselect * from users where team_id = 1;\nselect u.email, cp.* from users u\njoin crm_profiles cp on u.id = cp.user_id\nwhere u.team_id = 1;\n# 1 - 00541000004281rAAA\n# 204 - 0052g000003freeAAA\n# 429 - 0052g000003qGOiAAM\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 1\nand sa.provider = 'salesforce';\n\nselect * from activities where type = 'softphone'\nand created_at > '2024-12-11 15:24:36' order by id desc;\n\nselect * from activity_providers where team_id = 1;\nselect * from activity_provider_users where activity_provider_id = 328;\n\nselect * from opportunities where crm_configuration_id = 39\nAND account_id = 178 AND is_closed = false\norder by created_at DESC;\n\nselect * from contacts where id = 3952;\nselect * from accounts where id = 178;\n\n# ************************************************************************************\nselect * from teams where id = 36;\nselect * from crm_configurations where id = 21;\nselect * from users where team_id = 36;\nselect u.email, cp.* from users u\njoin crm_profiles cp on u.id = cp.user_id\nwhere u.team_id = 36;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 36\nand sa.provider = 'bullhorn';\n\nselect * from social_accounts where id = 348;\nUPDATE social_accounts SET\nprovider_user_token = '21442_6802599_91:41179a58-21e7-4d7c-ad58-56bb666b2f65',\nprovider_refresh_token = '21442_6802599_91:01c6b335-3f2a-42e4-85ff-8a08fa65fceb',\nexpires = 1733998131,\nstate = 'connected'\nWHERE id = 348;\n\n# ************************************************************************************\nselect * from teams where id = 31;\nselect * from crm_configurations where id = 18;\n\nselect * from users where team_id = 31; # 257\nselect u.email, cp.* from users u\njoin crm_profiles cp on u.id = cp.user_id\nwhere u.team_id = 31;\n\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 31\nand sa.provider = 'close';\n\nselect * from contacts where crm_configuration_id = 18;\n\n# ********************** NEPTUNE **************************************************************\nselect * from teams;\nselect * from users where id IN (1030, 1035, 1052);\nselect * from crm_configurations;\n\nselect * from users where team_id = 65; # 257\nselect * from team_settings where team_id = 65; # 257\nselect * from invitations where team_id = 65; # 257\nselect * from users where email = 'integration-account@jiminny.com'; # 257\nselect u.email, cp.* from users u\njoin crm_profiles cp on u.id = cp.user_id\nwhere u.team_id = 65;\n\nselect * from crm_configurations where id = 53;\nselect * from accounts where crm_configuration_id = 53 order by id desc;\nselect * from leads where crm_configuration_id = 53 order by id desc;\nselect * from contacts where crm_configuration_id = 53 order by id desc;\nselect * from opportunities where crm_configuration_id = 53 order by id desc;\nselect * from crm_profiles where crm_configuration_id = 53 order by id desc;\nselect * from crm_fields where crm_configuration_id = 53 order by id desc;\nselect * from crm_field_values where crm_field_id = 3341 order by id desc;\nselect * from crm_layouts where crm_configuration_id = 53 order by id desc;\nselect * from stages where crm_configuration_id = 53 order by id desc;\n\n\nselect * from crm_profiles where crm_configuration_id = 13;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 65\nand sa.provider = 'integration-app';\n\nselect * from contacts where crm_configuration_id = 13;\n\nselect * from social_accounts where sociable_id = 283;\n\nSELECT * FROM opportunities WHERE crm_provider_id = '006O400000E9bzeIAB';\n\nselect * from activity_providers where team_id = 65;\nSELECT * FROM activities WHERE crm_configuration_id IN (51, 52, 53);\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 65\n;\n\n# ***************************** STAGING ********************************************\nSELECT * FROM teams;\nSELECT * FROM teams WHERE id = 88;\nSELECT * FROM teams WHERE id = 89;\nselect * from team_settings where team_id = 89;\nSELECT * FROM users WHERE team_id = 89;\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 89;\n\nselect * from users;\nSELECT * FROM social_accounts WHERE sociable_id = 1761;\nSELECT * FROM crm_configurations WHERE id = 70;\nselect * from accounts where crm_configuration_id = 70 order by id desc;\nselect * from leads where crm_configuration_id = 70 order by id desc;\nselect * from contacts where crm_configuration_id = 70 order by id desc;\nselect * from opportunities where crm_configuration_id = 70 order by id desc;\nselect * from crm_profiles where crm_configuration_id = 70 order by id desc;\nselect * from crm_fields where crm_configuration_id = 70 order by id desc;\nselect * from crm_field_values where crm_field_id = 3536 order by id desc;\nselect * from crm_layouts where crm_configuration_id = 70 order by id desc;\nselect * from stages where crm_configuration_id = 70 order by id desc;\nselect * from business_processes where crm_configuration_id = 70 order by id desc;\nselect * from business_process_stages where business_process_id = 34;\n\nselect * from contacts where id = 10468;\n\nselect * from crm_layouts where crm_configuration_id = 70;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 388;\nSELECT * FROM crm_fields WHERE id IN (3533,3534,3535);\n\nselect * from activities where crm_configuration_id = 70\nand (account_id IS NOT NULL or lead_id IS NOT NULL or contact_id IS NOT NULL or opportunity_id IS NOT NULL) order by id desc;\n\nSELECT * FROM activities WHERE uuid_to_bin('2e10b60f-8a61-41c5-a3d4-28835353dc65') = uuid;\nSELECT * FROM activities where crm_configuration_id = 69 ;\n\nSELECT * FROM users WHERE email LIKE '%jiminny_web_sa2@jiminny.com%';\nSELECT * FROM activities WHERE uuid_to_bin('5a150c93-40fc-42ec-b3bd-c1d328e09f6e') = uuid;\nSELECT * FROM opportunities WHERE id = 385;\n\nselect * from participants p\njoin activities a on p.activity_id = a.id\nwhere a.crm_configuration_id = 70\nand (p.lead_id IS NOT NULL or p.contact_id IS NOT NULL);\nSELECT * FROM participants WHERE id = 1013638;\n\nselect * from teams where id = 90;\nselect * from users where team_id = 90;\nselect * from social_accounts where social_accounts.sociable_id IN (1960,1760);\nSELECT * FROM crm_profiles WHERE crm_configuration_id = 71;\nselect * from invitations where team_id = 90;\n\nselect * from crm_configurations where id = 71;\nselect * from accounts where crm_configuration_id = 71 order by id desc;\nselect * from leads where crm_configuration_id = 71 order by id desc;\nselect * from contacts where crm_configuration_id = 71 order by id desc;\nselect * from opportunities where crm_configuration_id = 71 order by id desc;\nselect * from crm_profiles where crm_configuration_id = 71 order by id desc;\nselect * from crm_fields where crm_configuration_id = 71 order by id desc;\nselect * from crm_field_values where crm_field_id = 3341 order by id desc;\nselect * from crm_layouts where crm_configuration_id = 71 order by id desc;\nselect * from stages where crm_configuration_id = 71 order by id desc;\n\nselect * from users order by secondary_email desc;\nselect u.id, u.email, u.status, sa.id, sa.provider_user_id from social_accounts sa\n join users u on sa.sociable_id = u.id\nwhere sa.provider = 'google' and u.email LIKE 'aneliya%';\n\nselect * from failed_jobs order by id desc;\n\nselect * from users where email = 'ben.allwright@learningpeople.co.uk' or secondary_email = 'ben.allwright@learningpeople.co.uk';\n\nselect * from teams;\nSELECT * FROM crm_profiles WHERE crm_configuration_id = 39;\nSELECT * FROM crm_fields WHERE crm_configuration_id = 39 and object_type = 'task';\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 1\nand sa.provider = 'salesforce';\n\n# ************************************************************************************\nSELECT * FROM activities WHERE uuid_to_bin('c38b3895-fd0f-4b1f-9fb2-c170dba137c6') = uuid;\nSELECT * FROM crm_configurations WHERE id = 70;\n\nselect * from teams where id = 1;\nselect * from groups where team_id = 1;\nselect * from users where team_id = 1;\n\nselect o.id, o.name,o.close_date, u.id, u.name, u.group_id, r.id, r.display_name, g.name, g.scope from opportunities o\njoin users u on o.user_id = u.id\njoin groups g on u.group_id = g.id\njoin role_user ru on u.id = ru.user_id\njoin roles r on ru.role_id = r.id\nwhere o.crm_configuration_id = 39 and close_date > '2024-01-01 00:00:00';\n\nselect * from role_user where user_id = 143;\nselect * from roles;\n\nselect * from role_user;\nselect * from groups where id = 9;\nselect * from scope_groups where group_id = 9;\n\n# ************************************************************************************\nselect * from teams where id = 36;\nselect * from crm_configurations;\nSELECT * FROM social_accounts WHERE sociable_id = 121;\n\nhttps://crmsandbox.zoho.com/crm/jiminnyw4/tab/Leads/4776201000005049105\nhttps://crmsandbox.zoho.com/crm/\n\nhttps://crm.zoho.com/crm/org3469620/tab/Leads/230045000229559080\n https://crm.zoho.com/crm/\n org3469620\n\nSELECT * FROM activities WHERE uuid_to_bin('03382d20-c8bc-48e7-a3d4-90b52fa5ceab') = uuid;\n\nselect * from users where email LIKE \"%mobile_automation_%\";\nselect * from social_accounts where sociable_id IN (2228);\nselect * from crm_profiles where user_id IN (2222,2223,2226,2227);\n\nselect * from teams order by id desc;\nSELECT * FROM users WHERE id = 2229;\nSELECT * FROM crm_profiles WHERE user_id = 2229;\nselect * from opportunities where crm_configuration_id = 88;\nselect * from crm_fields where crm_configuration_id = 88;\nselect * from crm_profiles where crm_configuration_id = 88;\n\nSELECT * FROM teams WHERE id = 1;\n\nSELECT * FROM users WHERE id = 143;\nSELECT * FROM users WHERE uuid_to_bin('fde193d3-06a2-4e1a-8895-62b94039215d') = uuid;\nSELECT * FROM teams WHERE uuid_to_bin('73385071-a756-42ae-9c73-8b53f2309467') = uuid;\n\nhttps://app.staging.jiminny.com/ondemand?\n min_duration=1\n &\n only_recorded=1\n &\n user_id%5B%5D=641f1acb-16b8-42d1-8726-df52979dad0e\n &\n sequence_number=2\n\n select * from users where team_id = 1 and email like '%stoyan%'\n\nselect * from coaching_feedbacks;\n\nselect * from teams;\nSELECT * FROM users WHERE team_id = 36;\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 19\nand sa.provider = 'pipedrive';\n\nselect * from users where id = 143;\n\nSELECT * FROM users WHERE uuid_to_bin('73180eeb-33de-4065-977d-ccbe0e6c94fc') = uuid;\nSELECT * FROM teams WHERE uuid_to_bin('73180eeb-33de-4065-977d-ccbe0e6c94fc') = uuid;\nSELECT * FROM activity_shares WHERE uuid_to_bin('73180eeb-33de-4065-977d-ccbe0e6c94fc') = uuid;\n\nselect * from users where team_id = 2;\nselect * from activities where crm_configuration_id = 39\nand activities.scheduled_start_time BETWEEN '2025-04-09 00:00:00' AND '2025-04-09 23:59:59'\nAND user_id = 143\norder by id desc;\n\n# ************************************************************************************\nselect * from teams where id = 142; # 2312, 126\nselect * from team_settings;\nselect * from users where team_id = 142; # 21642\nSELECT * FROM social_accounts WHERE sociable_id = 21642;\nSELECT * FROM crm_profiles cp join users u ON u.id = cp.user_id WHERE team_id = 142;\nselect * from crm_profiles where id IN (93);\nselect * from invitations;\nselect * from team_features where team_id = 1;\n\nSELECT * FROM crm_configurations WHERE id = 126;\nselect * from accounts where crm_configuration_id = 126 order by id desc;\nselect * from leads where crm_configuration_id = 126 order by id desc;\nselect * from contacts where crm_configuration_id = 126 order by id desc;\nselect * from opportunities where crm_configuration_id = 126 order by id desc;\nselect * from crm_profiles where crm_configuration_id = 126 order by id desc;\nselect * from crm_fields where crm_configuration_id = 126 # 11060\n# and type IN ('picklist', 'status')\n# and object_type = 'task'\norder by id desc;\n# 5731,5732,5733\nselect DISTINCT crm_field_id from crm_field_values where crm_field_id IN (11151,12239,12215,12185,12175,12165,12144,12137,12127,12109,12107,12105,12103,12092,12037,12005,12003,11987,11969,11958,11951,11942,11931,11924,11921,11917,11915,11901,11893,11883,11872,11870,11868,11866,11839,11833,11821,11793,11780,11777,11769,11757,11737,11735,11656,11645,11638,11629,11618,11611,11602,11591,11584,11581,11558,11544,11543,11534,11532,11529,11527,11503,11497,11493,11488,11470,11468,11457,11455,11397,11387,11372,11363,11348,11323,11318,11309,11301,11300,11292,11290,11286,11284,11256,11252,11242,11237,11233,11219,11176,11160) order by id desc;\nselect * from crm_layouts where crm_configuration_id = 126 order by id desc;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id in (300,299,298);\nselect * from stages where crm_configuration_id = 126 order by id desc;\nselect * from business_processes where crm_configuration_id = 126 order by id desc;\nselect * from business_process_stages where business_process_id IN (76,75,74,73);\nselect * from playbooks where team_id = 142;\nselect * from playbook_layouts where playbook_id IN (108);\nSELECT * FROM playbook_categories WHERE playbook_id IN (108);\n\nselect * from teams where id = 130;\nSELECT * FROM social_accounts WHERE sociable_id = 2291;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 2\nand sa.provider = 'hubspot';\n\nSELECT * FROM activities\n WHERE crm_configuration_id = 110;\n\nselect * from teams;\nselect * from crm_configurations;\n\nSELECT * FROM activities WHERE id = 628773;\nSELECT * FROM crm_profiles WHERE user_id = 1460;\nSELECT * FROM social_accounts WHERE sociable_id = 2291;\n\nselect * from teams;\nselect ru.*, pr.*, p.* from users u join role_user ru on ru.user_id = u.id\njoin permission_role pr on pr.role_id = ru.role_id\n join permissions p on p.id = pr.permission_id\nwhere team_id = 495 and p.name IN ('dial');\n\nselect * from teams where id = 145;\nselect * from crm_configurations where id = 129;\nselect * from social_accounts where sociable_id = 2317;\nSELECT * FROM activities WHERE uuid_to_bin('8dbab184-a333-4268-ad57-fb41f8d53a9a') = uuid;\n\nselect * from teams where id = 1;\nSELECT * FROM crm_layouts WHERE crm_configuration_id = 39;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 280;\nSELECT * FROM crm_layout_entities WHERE id = 5507;\nSELECT * FROM crm_fields WHERE crm_configuration_id = 39 and object_type IN ('event');\n\nselect * from teams;\nselect * from activities where crm_configuration_id = 14;\n\nSELECT * FROM social_accounts where provider = 'copper';\n\nselect * from activities where id = 628467;\nselect * from participants where activity_id = 628467;\n\nSELECT * FROM contacts WHERE id = 3969;\nSELECT * FROM accounts WHERE id = 177;\n\nSELECT * FROM activities WHERE uuid_to_bin('4eb54c77-cfa3-2bd4-84a7-9ed46a21c988') = uuid;\n\n# ********************* BH\nselect * from teams where id = 36;\nSELECT * FROM crm_configurations WHERE id = 21;\nselect * from activities where crm_configuration_id = 21 and id = 607901;\nselect * from activities where crm_configuration_id = 21;\n\nselect * roles;\nselect * from permissions;\nselect * from permission_role where permission_id = 226;\n\nselect * from migrations order by id desc;\n\n# mercury\n# neptune\n# earth\n\nselect * from teams;\nselect * from teams where id = 19;\nselect * from teams where id = 27;\nselect * from users where team_id = 27;\nSELECT * FROM crm_configurations WHERE id = 42;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 19\nand sa.provider = 'pipedrive';\n\nselect * from activities where id = 631461;\nSELECT * FROM crm_field_values WHERE crm_field_id = 180;\n\nselect * from teams where id = 2;\nSELECT * FROM social_accounts WHERE sociable_id = 89;\n\nSELECT * FROM activities WHERE uuid_to_bin('ba0c029a-bc14-4e17-8603-64174acebcbb') = uuid; # 634273\nselect * from activity_summary_logs where activity_id = 634273;\n\nselect * from sidekick_settings where team_id = 2;\n\nselect * from teams; # 2, 2\nSELECT * FROM crm_configurations WHERE team_id = 2; # 2\nselect * from team_features where team_id = 2;\nselect * from features;\nSELECT * FROM opportunities WHERE crm_configuration_id = 2 and crm_provider_id = '51317301383';\nSELECT * FROM opportunities WHERE crm_configuration_id = 2 order by id desc;\n\nselect * from automated_reports order by id desc;\nselect * from automated_report_results order by id desc;\nselect * from users where team_id = 1 and id IN (7160, 3248);\nselect * from migrations order by id desc;\n\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 1 and sa.provider = 'salesforce';\n\nselect * from teams where id = 1;\nselect * from groups g JOIN playbooks p on g.playbook_id = p.id where g.team_id = 1;\nselect * from groups where id = 565;\nselect * from playbooks where team_id = 1;\nselect * from playbooks where id = 175;\nselect * from playbook_categories where playbook_id = 175;\nselect * from users where team_id = 1;\nselect * from users where id = 7160;\nselect * from crm_profiles where user_id = 7160;\nselect * from features;\nselect\n *\n# id, uuid, type, provider, playbook_category_id, user_id, lead_id, contact_id, account_id, opportunity_id, stage_id,\n# crm_configuration_id, crm_provider_id, transcription_id, status\nfrom activities where crm_configuration_id = 1 and type = 'conference'\n# and crm_provider_id IS NOT NULL\nand provider != 'uploader' and actual_start_time IS NOT NULL\nORDER by id desc;\nselect * from activities where id = 54747783; # 00UO400000pCzojMAC\n\nselect p.id, p.activity_type, pc.id, pc.name\nFROM playbooks p\njoin playbook_categories pc on p.id = pc.playbook_id\nwhere p.team_id = 1 and p.activity_type = 'event';\n\nSELECT * FROM crm_fields WHERE crm_configuration_id = 1 and object_type = 'event';\nSELECT * FROM crm_field_values WHERE crm_field_id = 4;\n\nselect * from crm_layouts cl join playbook_layouts pl on cl.id = pl.layout_id\nwhere crm_configuration_id = 1 and pl.playbook_id = 175;\n\nselect * from teams;\nSELECT r.* FROM automated_reports r\njoin teams t on r.team_id = t.id\nWHERE r.frequency = 'daily'\n and r.status = 1\nAND t.status = 'active'\nAND (r.expires_at >= now() OR r.expires_at IS NULL);\n\nselect * from automated_report_results where report_id IN (18, 33);\n\nselect * from activity_searches where id = 10932;\nselect * from activity_search_filters where activity_search_id = 10932;\nselect * from automated_reports;\nselect * from automated_report_results where report_id IN (34, 35);","depth":4,"value":"SELECT * FROM teams WHERE id = 1;\n\nselect * from crm_layouts where crm_configuration_id = 39;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 283;\nSELECT * FROM crm_fields WHERE id = 2234;\nSELECT * FROM crm_field_values WHERE crm_field_id = 2234;\n\nselect * from crm_profiles where user_id = 143;\n\nselect * from record_types where crm_configuration_id = 39; # 0121K000001MHElQAO,0121K000001MHEqQAO\nselect * from business_processes where crm_configuration_id = 39;\n# 01941000000H669AAC, 01941000000H66JAAS\n\nselect * from record_type_field_values\n where record_type_id IN (24);\n\nselect * from crm_field_values where id IN (2730);\n\nselect * from crm_configurations where id = 39;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 1\nand sa.provider = 'salesforce'; #1035\n\n\nselect * from users where team_id = 1; # 222 group 3\nSELECT * FROM activities WHERE user_id = 222 order by id desc;\nselect * from sidekick_settings where team_id = 1;\nselect * from teams where id = 1;\nselect * from team_features where team_id = 1;\n\nselect * from activities where crm_configuration_id = 2\nand provider = 'ms-teams' and id = 608765;\n\nSELECT * FROM activities WHERE crm_configuration_id = 2 and crm_provider_id = '59523413338';\n\nselect * from sidekick_settings where team_id = 2;\n\nSELECT * FROM activities WHERE id = 608660;\nselect * from activity_summary_logs where activity_id = 608660;\nselect * from ai_prompts where transcription_id = 11214;\n\n# ********************************************************************************************************\nSELECT * FROM activities WHERE uuid_to_bin('ed78a437-2804-450e-ab2f-56ab1c641346') = uuid;\n# id: 608818, crm: 59628809737\nSELECT * FROM activities WHERE uuid_to_bin('36b06e55-afdd-4782-8dee-c624cd0af191') = uuid;\n# id: 608821, crm: 59632069252\nSELECT ce.start_time, ce.end_time, a.id, a.uuid, crm_provider_id, calendar_event_id, title,\nplaybook_category_id, user_id, lead_id, contact_id, account_id, opportunity_id,\nscheduled_start_time, scheduled_end_time, actual_start_time, actual_end_time, a.created_at\nFROM activities a\njoin calendar_events ce on a.calendar_event_id = ce.id\nWHERE a.id IN (608818, 608821);\n\nselect * from users where team_id = 1;\nselect * from team_settings where team_id = 1;\nselect * from crm_profiles where crm_configuration_id = 39 order by user_id;\n\nselect * from team_features where team_id = 1;\n\nselect * from users where team_id = 2;\n\nSELECT * FROM activities WHERE uuid_to_bin('ec7647e9-5225-458b-b475-f31aa2769204') = uuid; # 612639\n# Preslava N. Ivanova, grou id 3\n\nSELECT * FROM opportunities WHERE uuid_to_bin('a2928fe5-aec5-46cb-85d9-7654c89e46a6') = uuid;\n\nselect * from activities where opportunity_id = 344 and actual_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00';\n\nselect\n a.id,\n a.type,\n a.scheduled_start_time,\n a.actual_start_time,\n a.created_at,\n a.opportunity_id,\n a.status\nFROM activities a\nWHERE opportunity_id = 344\nand status IN ('completed', 'received', 'delivered')\nand (\n (a.actual_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00')\nOR (a.created_at between '2024-10-11 00:00:00' and '2024-10-12 00:00:00')\nOR (a.scheduled_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00'))\n;\n\nSELECT * FROM users WHERE id = 222;\n\nSELECT * FROM crm_profiles WHERE user_id = 222;\nselect * from crm_layouts where crm_configuration_id = 39;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 281;\n\nselect * from group_deal_risk_types;\n\nselect * from opportunities where team_id = 1;\n\nSELECT * FROM opportunities WHERE id = 315;\nSELECT * FROM crm_field_data WHERE object_id = 315;\nselect * from crm_field_data where object_id = 260;\n\nselect * from generic_ai_prompts where subject_id = 315;\n\nselect * from teams; # 36, 21, 121, james.graham@bullhorn.jiminny.com\nSELECT * FROM social_accounts WHERE sociable_id = 121 and provider = 'bullhorn';\n\n# ************************************************************************************\nselect * from teams where id = 1;\nselect * from crm_configurations where id = 39;\nselect * from users where team_id = 1;\nselect u.email, cp.* from users u\njoin crm_profiles cp on u.id = cp.user_id\nwhere u.team_id = 1;\n# 1 - 00541000004281rAAA\n# 204 - 0052g000003freeAAA\n# 429 - 0052g000003qGOiAAM\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 1\nand sa.provider = 'salesforce';\n\nselect * from activities where type = 'softphone'\nand created_at > '2024-12-11 15:24:36' order by id desc;\n\nselect * from activity_providers where team_id = 1;\nselect * from activity_provider_users where activity_provider_id = 328;\n\nselect * from opportunities where crm_configuration_id = 39\nAND account_id = 178 AND is_closed = false\norder by created_at DESC;\n\nselect * from contacts where id = 3952;\nselect * from accounts where id = 178;\n\n# ************************************************************************************\nselect * from teams where id = 36;\nselect * from crm_configurations where id = 21;\nselect * from users where team_id = 36;\nselect u.email, cp.* from users u\njoin crm_profiles cp on u.id = cp.user_id\nwhere u.team_id = 36;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 36\nand sa.provider = 'bullhorn';\n\nselect * from social_accounts where id = 348;\nUPDATE social_accounts SET\nprovider_user_token = '21442_6802599_91:41179a58-21e7-4d7c-ad58-56bb666b2f65',\nprovider_refresh_token = '21442_6802599_91:01c6b335-3f2a-42e4-85ff-8a08fa65fceb',\nexpires = 1733998131,\nstate = 'connected'\nWHERE id = 348;\n\n# ************************************************************************************\nselect * from teams where id = 31;\nselect * from crm_configurations where id = 18;\n\nselect * from users where team_id = 31; # 257\nselect u.email, cp.* from users u\njoin crm_profiles cp on u.id = cp.user_id\nwhere u.team_id = 31;\n\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 31\nand sa.provider = 'close';\n\nselect * from contacts where crm_configuration_id = 18;\n\n# ********************** NEPTUNE **************************************************************\nselect * from teams;\nselect * from users where id IN (1030, 1035, 1052);\nselect * from crm_configurations;\n\nselect * from users where team_id = 65; # 257\nselect * from team_settings where team_id = 65; # 257\nselect * from invitations where team_id = 65; # 257\nselect * from users where email = 'integration-account@jiminny.com'; # 257\nselect u.email, cp.* from users u\njoin crm_profiles cp on u.id = cp.user_id\nwhere u.team_id = 65;\n\nselect * from crm_configurations where id = 53;\nselect * from accounts where crm_configuration_id = 53 order by id desc;\nselect * from leads where crm_configuration_id = 53 order by id desc;\nselect * from contacts where crm_configuration_id = 53 order by id desc;\nselect * from opportunities where crm_configuration_id = 53 order by id desc;\nselect * from crm_profiles where crm_configuration_id = 53 order by id desc;\nselect * from crm_fields where crm_configuration_id = 53 order by id desc;\nselect * from crm_field_values where crm_field_id = 3341 order by id desc;\nselect * from crm_layouts where crm_configuration_id = 53 order by id desc;\nselect * from stages where crm_configuration_id = 53 order by id desc;\n\n\nselect * from crm_profiles where crm_configuration_id = 13;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 65\nand sa.provider = 'integration-app';\n\nselect * from contacts where crm_configuration_id = 13;\n\nselect * from social_accounts where sociable_id = 283;\n\nSELECT * FROM opportunities WHERE crm_provider_id = '006O400000E9bzeIAB';\n\nselect * from activity_providers where team_id = 65;\nSELECT * FROM activities WHERE crm_configuration_id IN (51, 52, 53);\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 65\n;\n\n# ***************************** STAGING ********************************************\nSELECT * FROM teams;\nSELECT * FROM teams WHERE id = 88;\nSELECT * FROM teams WHERE id = 89;\nselect * from team_settings where team_id = 89;\nSELECT * FROM users WHERE team_id = 89;\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 89;\n\nselect * from users;\nSELECT * FROM social_accounts WHERE sociable_id = 1761;\nSELECT * FROM crm_configurations WHERE id = 70;\nselect * from accounts where crm_configuration_id = 70 order by id desc;\nselect * from leads where crm_configuration_id = 70 order by id desc;\nselect * from contacts where crm_configuration_id = 70 order by id desc;\nselect * from opportunities where crm_configuration_id = 70 order by id desc;\nselect * from crm_profiles where crm_configuration_id = 70 order by id desc;\nselect * from crm_fields where crm_configuration_id = 70 order by id desc;\nselect * from crm_field_values where crm_field_id = 3536 order by id desc;\nselect * from crm_layouts where crm_configuration_id = 70 order by id desc;\nselect * from stages where crm_configuration_id = 70 order by id desc;\nselect * from business_processes where crm_configuration_id = 70 order by id desc;\nselect * from business_process_stages where business_process_id = 34;\n\nselect * from contacts where id = 10468;\n\nselect * from crm_layouts where crm_configuration_id = 70;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 388;\nSELECT * FROM crm_fields WHERE id IN (3533,3534,3535);\n\nselect * from activities where crm_configuration_id = 70\nand (account_id IS NOT NULL or lead_id IS NOT NULL or contact_id IS NOT NULL or opportunity_id IS NOT NULL) order by id desc;\n\nSELECT * FROM activities WHERE uuid_to_bin('2e10b60f-8a61-41c5-a3d4-28835353dc65') = uuid;\nSELECT * FROM activities where crm_configuration_id = 69 ;\n\nSELECT * FROM users WHERE email LIKE '%jiminny_web_sa2@jiminny.com%';\nSELECT * FROM activities WHERE uuid_to_bin('5a150c93-40fc-42ec-b3bd-c1d328e09f6e') = uuid;\nSELECT * FROM opportunities WHERE id = 385;\n\nselect * from participants p\njoin activities a on p.activity_id = a.id\nwhere a.crm_configuration_id = 70\nand (p.lead_id IS NOT NULL or p.contact_id IS NOT NULL);\nSELECT * FROM participants WHERE id = 1013638;\n\nselect * from teams where id = 90;\nselect * from users where team_id = 90;\nselect * from social_accounts where social_accounts.sociable_id IN (1960,1760);\nSELECT * FROM crm_profiles WHERE crm_configuration_id = 71;\nselect * from invitations where team_id = 90;\n\nselect * from crm_configurations where id = 71;\nselect * from accounts where crm_configuration_id = 71 order by id desc;\nselect * from leads where crm_configuration_id = 71 order by id desc;\nselect * from contacts where crm_configuration_id = 71 order by id desc;\nselect * from opportunities where crm_configuration_id = 71 order by id desc;\nselect * from crm_profiles where crm_configuration_id = 71 order by id desc;\nselect * from crm_fields where crm_configuration_id = 71 order by id desc;\nselect * from crm_field_values where crm_field_id = 3341 order by id desc;\nselect * from crm_layouts where crm_configuration_id = 71 order by id desc;\nselect * from stages where crm_configuration_id = 71 order by id desc;\n\nselect * from users order by secondary_email desc;\nselect u.id, u.email, u.status, sa.id, sa.provider_user_id from social_accounts sa\n join users u on sa.sociable_id = u.id\nwhere sa.provider = 'google' and u.email LIKE 'aneliya%';\n\nselect * from failed_jobs order by id desc;\n\nselect * from users where email = 'ben.allwright@learningpeople.co.uk' or secondary_email = 'ben.allwright@learningpeople.co.uk';\n\nselect * from teams;\nSELECT * FROM crm_profiles WHERE crm_configuration_id = 39;\nSELECT * FROM crm_fields WHERE crm_configuration_id = 39 and object_type = 'task';\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 1\nand sa.provider = 'salesforce';\n\n# ************************************************************************************\nSELECT * FROM activities WHERE uuid_to_bin('c38b3895-fd0f-4b1f-9fb2-c170dba137c6') = uuid;\nSELECT * FROM crm_configurations WHERE id = 70;\n\nselect * from teams where id = 1;\nselect * from groups where team_id = 1;\nselect * from users where team_id = 1;\n\nselect o.id, o.name,o.close_date, u.id, u.name, u.group_id, r.id, r.display_name, g.name, g.scope from opportunities o\njoin users u on o.user_id = u.id\njoin groups g on u.group_id = g.id\njoin role_user ru on u.id = ru.user_id\njoin roles r on ru.role_id = r.id\nwhere o.crm_configuration_id = 39 and close_date > '2024-01-01 00:00:00';\n\nselect * from role_user where user_id = 143;\nselect * from roles;\n\nselect * from role_user;\nselect * from groups where id = 9;\nselect * from scope_groups where group_id = 9;\n\n# ************************************************************************************\nselect * from teams where id = 36;\nselect * from crm_configurations;\nSELECT * FROM social_accounts WHERE sociable_id = 121;\n\nhttps://crmsandbox.zoho.com/crm/jiminnyw4/tab/Leads/4776201000005049105\nhttps://crmsandbox.zoho.com/crm/\n\nhttps://crm.zoho.com/crm/org3469620/tab/Leads/230045000229559080\n https://crm.zoho.com/crm/\n org3469620\n\nSELECT * FROM activities WHERE uuid_to_bin('03382d20-c8bc-48e7-a3d4-90b52fa5ceab') = uuid;\n\nselect * from users where email LIKE \"%mobile_automation_%\";\nselect * from social_accounts where sociable_id IN (2228);\nselect * from crm_profiles where user_id IN (2222,2223,2226,2227);\n\nselect * from teams order by id desc;\nSELECT * FROM users WHERE id = 2229;\nSELECT * FROM crm_profiles WHERE user_id = 2229;\nselect * from opportunities where crm_configuration_id = 88;\nselect * from crm_fields where crm_configuration_id = 88;\nselect * from crm_profiles where crm_configuration_id = 88;\n\nSELECT * FROM teams WHERE id = 1;\n\nSELECT * FROM users WHERE id = 143;\nSELECT * FROM users WHERE uuid_to_bin('fde193d3-06a2-4e1a-8895-62b94039215d') = uuid;\nSELECT * FROM teams WHERE uuid_to_bin('73385071-a756-42ae-9c73-8b53f2309467') = uuid;\n\nhttps://app.staging.jiminny.com/ondemand?\n min_duration=1\n &\n only_recorded=1\n &\n user_id%5B%5D=641f1acb-16b8-42d1-8726-df52979dad0e\n &\n sequence_number=2\n\n select * from users where team_id = 1 and email like '%stoyan%'\n\nselect * from coaching_feedbacks;\n\nselect * from teams;\nSELECT * FROM users WHERE team_id = 36;\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 19\nand sa.provider = 'pipedrive';\n\nselect * from users where id = 143;\n\nSELECT * FROM users WHERE uuid_to_bin('73180eeb-33de-4065-977d-ccbe0e6c94fc') = uuid;\nSELECT * FROM teams WHERE uuid_to_bin('73180eeb-33de-4065-977d-ccbe0e6c94fc') = uuid;\nSELECT * FROM activity_shares WHERE uuid_to_bin('73180eeb-33de-4065-977d-ccbe0e6c94fc') = uuid;\n\nselect * from users where team_id = 2;\nselect * from activities where crm_configuration_id = 39\nand activities.scheduled_start_time BETWEEN '2025-04-09 00:00:00' AND '2025-04-09 23:59:59'\nAND user_id = 143\norder by id desc;\n\n# ************************************************************************************\nselect * from teams where id = 142; # 2312, 126\nselect * from team_settings;\nselect * from users where team_id = 142; # 21642\nSELECT * FROM social_accounts WHERE sociable_id = 21642;\nSELECT * FROM crm_profiles cp join users u ON u.id = cp.user_id WHERE team_id = 142;\nselect * from crm_profiles where id IN (93);\nselect * from invitations;\nselect * from team_features where team_id = 1;\n\nSELECT * FROM crm_configurations WHERE id = 126;\nselect * from accounts where crm_configuration_id = 126 order by id desc;\nselect * from leads where crm_configuration_id = 126 order by id desc;\nselect * from contacts where crm_configuration_id = 126 order by id desc;\nselect * from opportunities where crm_configuration_id = 126 order by id desc;\nselect * from crm_profiles where crm_configuration_id = 126 order by id desc;\nselect * from crm_fields where crm_configuration_id = 126 # 11060\n# and type IN ('picklist', 'status')\n# and object_type = 'task'\norder by id desc;\n# 5731,5732,5733\nselect DISTINCT crm_field_id from crm_field_values where crm_field_id IN (11151,12239,12215,12185,12175,12165,12144,12137,12127,12109,12107,12105,12103,12092,12037,12005,12003,11987,11969,11958,11951,11942,11931,11924,11921,11917,11915,11901,11893,11883,11872,11870,11868,11866,11839,11833,11821,11793,11780,11777,11769,11757,11737,11735,11656,11645,11638,11629,11618,11611,11602,11591,11584,11581,11558,11544,11543,11534,11532,11529,11527,11503,11497,11493,11488,11470,11468,11457,11455,11397,11387,11372,11363,11348,11323,11318,11309,11301,11300,11292,11290,11286,11284,11256,11252,11242,11237,11233,11219,11176,11160) order by id desc;\nselect * from crm_layouts where crm_configuration_id = 126 order by id desc;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id in (300,299,298);\nselect * from stages where crm_configuration_id = 126 order by id desc;\nselect * from business_processes where crm_configuration_id = 126 order by id desc;\nselect * from business_process_stages where business_process_id IN (76,75,74,73);\nselect * from playbooks where team_id = 142;\nselect * from playbook_layouts where playbook_id IN (108);\nSELECT * FROM playbook_categories WHERE playbook_id IN (108);\n\nselect * from teams where id = 130;\nSELECT * FROM social_accounts WHERE sociable_id = 2291;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 2\nand sa.provider = 'hubspot';\n\nSELECT * FROM activities\n WHERE crm_configuration_id = 110;\n\nselect * from teams;\nselect * from crm_configurations;\n\nSELECT * FROM activities WHERE id = 628773;\nSELECT * FROM crm_profiles WHERE user_id = 1460;\nSELECT * FROM social_accounts WHERE sociable_id = 2291;\n\nselect * from teams;\nselect ru.*, pr.*, p.* from users u join role_user ru on ru.user_id = u.id\njoin permission_role pr on pr.role_id = ru.role_id\n join permissions p on p.id = pr.permission_id\nwhere team_id = 495 and p.name IN ('dial');\n\nselect * from teams where id = 145;\nselect * from crm_configurations where id = 129;\nselect * from social_accounts where sociable_id = 2317;\nSELECT * FROM activities WHERE uuid_to_bin('8dbab184-a333-4268-ad57-fb41f8d53a9a') = uuid;\n\nselect * from teams where id = 1;\nSELECT * FROM crm_layouts WHERE crm_configuration_id = 39;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 280;\nSELECT * FROM crm_layout_entities WHERE id = 5507;\nSELECT * FROM crm_fields WHERE crm_configuration_id = 39 and object_type IN ('event');\n\nselect * from teams;\nselect * from activities where crm_configuration_id = 14;\n\nSELECT * FROM social_accounts where provider = 'copper';\n\nselect * from activities where id = 628467;\nselect * from participants where activity_id = 628467;\n\nSELECT * FROM contacts WHERE id = 3969;\nSELECT * FROM accounts WHERE id = 177;\n\nSELECT * FROM activities WHERE uuid_to_bin('4eb54c77-cfa3-2bd4-84a7-9ed46a21c988') = uuid;\n\n# ********************* BH\nselect * from teams where id = 36;\nSELECT * FROM crm_configurations WHERE id = 21;\nselect * from activities where crm_configuration_id = 21 and id = 607901;\nselect * from activities where crm_configuration_id = 21;\n\nselect * roles;\nselect * from permissions;\nselect * from permission_role where permission_id = 226;\n\nselect * from migrations order by id desc;\n\n# mercury\n# neptune\n# earth\n\nselect * from teams;\nselect * from teams where id = 19;\nselect * from teams where id = 27;\nselect * from users where team_id = 27;\nSELECT * FROM crm_configurations WHERE id = 42;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 19\nand sa.provider = 'pipedrive';\n\nselect * from activities where id = 631461;\nSELECT * FROM crm_field_values WHERE crm_field_id = 180;\n\nselect * from teams where id = 2;\nSELECT * FROM social_accounts WHERE sociable_id = 89;\n\nSELECT * FROM activities WHERE uuid_to_bin('ba0c029a-bc14-4e17-8603-64174acebcbb') = uuid; # 634273\nselect * from activity_summary_logs where activity_id = 634273;\n\nselect * from sidekick_settings where team_id = 2;\n\nselect * from teams; # 2, 2\nSELECT * FROM crm_configurations WHERE team_id = 2; # 2\nselect * from team_features where team_id = 2;\nselect * from features;\nSELECT * FROM opportunities WHERE crm_configuration_id = 2 and crm_provider_id = '51317301383';\nSELECT * FROM opportunities WHERE crm_configuration_id = 2 order by id desc;\n\nselect * from automated_reports order by id desc;\nselect * from automated_report_results order by id desc;\nselect * from users where team_id = 1 and id IN (7160, 3248);\nselect * from migrations order by id desc;\n\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 1 and sa.provider = 'salesforce';\n\nselect * from teams where id = 1;\nselect * from groups g JOIN playbooks p on g.playbook_id = p.id where g.team_id = 1;\nselect * from groups where id = 565;\nselect * from playbooks where team_id = 1;\nselect * from playbooks where id = 175;\nselect * from playbook_categories where playbook_id = 175;\nselect * from users where team_id = 1;\nselect * from users where id = 7160;\nselect * from crm_profiles where user_id = 7160;\nselect * from features;\nselect\n *\n# id, uuid, type, provider, playbook_category_id, user_id, lead_id, contact_id, account_id, opportunity_id, stage_id,\n# crm_configuration_id, crm_provider_id, transcription_id, status\nfrom activities where crm_configuration_id = 1 and type = 'conference'\n# and crm_provider_id IS NOT NULL\nand provider != 'uploader' and actual_start_time IS NOT NULL\nORDER by id desc;\nselect * from activities where id = 54747783; # 00UO400000pCzojMAC\n\nselect p.id, p.activity_type, pc.id, pc.name\nFROM playbooks p\njoin playbook_categories pc on p.id = pc.playbook_id\nwhere p.team_id = 1 and p.activity_type = 'event';\n\nSELECT * FROM crm_fields WHERE crm_configuration_id = 1 and object_type = 'event';\nSELECT * FROM crm_field_values WHERE crm_field_id = 4;\n\nselect * from crm_layouts cl join playbook_layouts pl on cl.id = pl.layout_id\nwhere crm_configuration_id = 1 and pl.playbook_id = 175;\n\nselect * from teams;\nSELECT r.* FROM automated_reports r\njoin teams t on r.team_id = t.id\nWHERE r.frequency = 'daily'\n and r.status = 1\nAND t.status = 'active'\nAND (r.expires_at >= now() OR r.expires_at IS NULL);\n\nselect * from automated_report_results where report_id IN (18, 33);\n\nselect * from activity_searches where id = 10932;\nselect * from activity_search_filters where activity_search_id = 10932;\nselect * from automated_reports;\nselect * from automated_report_results where report_id IN (34, 35);","role_description":"text entry area","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.088194445,"height":0.027777778},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"102","depth":4,"role_description":"text"},{"role":"AXStaticText","text":"3","depth":4,"role_description":"text"},{"role":"AXStaticText","text":"34","depth":4,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Services\\Kiosk\\AutomatedReports;\n\nuse Carbon\\CarbonImmutable;\nuse Carbon\\CarbonInterface;\nuse Carbon\\Exceptions\\InvalidFormatException;\nuse DateTime;\nuse DateTimeInterface;\nuse DateTimeZone;\nuse Illuminate\\Contracts\\Bus\\Dispatcher as BusDispatcher;\nuse Illuminate\\Database\\Eloquent\\Builder;\nuse Illuminate\\Support\\Carbon;\nuse Illuminate\\Support\\Collection;\nuse Illuminate\\Support\\Facades\\Log;\nuse Illuminate\\Support\\Facades\\Storage;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinition\\InputTypeEnum;\nuse Jiminny\\Component\\AskAnything\\AskAnythingPromptService;\nuse Jiminny\\Component\\AskAnything\\Dtos\\AskAnythingPromptDto;\nuse Jiminny\\Component\\UrlGenerator\\Webhook;\nuse Jiminny\\Contracts\\Repositories\\PlaybookCategoryRepository;\nuse Jiminny\\Contracts\\Repositories\\TeamRepository;\nuse Jiminny\\Contracts\\Repositories\\UserRepository;\nuse Jiminny\\Exceptions\\ApplicationException;\nuse Jiminny\\Exceptions\\InvalidArgumentException;\nuse Jiminny\\Exceptions\\ModelNotFoundException;\nuse Jiminny\\Jobs\\AutomatedReports\\RequestGenerateReportJob;\nuse Jiminny\\Models\\Activity\\Search;\nuse Jiminny\\Models\\AskAnything\\AskAnythingPrompt;\nuse Jiminny\\Models\\AskAnything\\AskAnythingPromptTarget;\nuse Jiminny\\Models\\AutomatedReport;\nuse Jiminny\\Models\\AutomatedReportResult;\nuse Jiminny\\Models\\Contracts\\UserContract;\nuse Jiminny\\Models\\Feature\\FeatureEnum;\nuse Jiminny\\Models\\Team;\nuse Jiminny\\Models\\User;\nuse Jiminny\\Repositories\\AskAnythingRepository;\nuse Jiminny\\Repositories\\AutomatedReportsRepository;\nuse Jiminny\\Repositories\\GroupRepository;\nuse Jiminny\\Repositories\\SearchRepository;\nuse Jiminny\\Repositories\\StageRepository;\nuse Throwable;\n\nclass AutomatedReportsService\n{\n public const string TYPE_LOSS_ANALYSIS = 'loss_analysis';\n public const string TYPE_ASK_JIMINNY = 'ask_jiminny';\n\n /**\n * Standard report types (used by kiosk for existing automated reports).\n */\n // @TODO this will add filter, however if we need to control feature by FF we need conditional logic\n public const array TYPES = [\n ['id' => 'exec_summary', 'name' => 'Exec Summary'],\n ['id' => 'coaching_profiles', 'name' => 'Coaching Profiles'],\n ['id' => 'product_feedback', 'name' => 'Product Feedback'],\n ['id' => self::TYPE_LOSS_ANALYSIS, 'name' => 'Loss Analysis'],\n// ['id' => 'questions', 'name' => 'Questions'],\n// ['id' => 'statistical_quant', 'name' => 'Statistical Quantitative'],\n ];\n\n public const array ALL_TYPES = [\n ...self::TYPES,\n ['id' => self::TYPE_ASK_JIMINNY, 'name' => 'Ask Jiminny'],\n ];\n\n public const string FREQUENCY_DAILY = 'daily';\n public const string FREQUENCY_WEEKLY = 'weekly';\n public const string FREQUENCY_MONTHLY = 'monthly';\n public const string FREQUENCY_QUARTERLY = 'quarterly';\n public const string FREQUENCY_ONE_OFF = 'one_off';\n\n /**\n * Frequencies for standard (non-Ask Jiminny) reports.\n */\n public const array FREQUENCIES = [\n ['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],\n ['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],\n ['id' => self::FREQUENCY_QUARTERLY, 'name' => 'Quarterly'],\n ['id' => self::FREQUENCY_ONE_OFF, 'name' => 'One-off'],\n ];\n\n /**\n * Frequencies for Ask Jiminny reports.\n */\n public const array ASK_JIMINNY_FREQUENCIES = [\n ['id' => self::FREQUENCY_DAILY, 'name' => 'Daily'],\n ['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],\n ['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],\n ];\n\n public const string MEDIA_TYPE_PDF = 'pdf';\n public const string MEDIA_TYPE_PODCAST = 'podcast';\n public const array MEDIA_TYPES = [self::MEDIA_TYPE_PDF, self::MEDIA_TYPE_PODCAST];\n public const array MEDIA_TYPE_OBJECT_PDF = ['id' => self::MEDIA_TYPE_PDF, 'name' => 'PDF'];\n public const array MEDIA_TYPE_OBJECT_PODCAST = ['id' => self::MEDIA_TYPE_PODCAST, 'name' => 'Podcast'];\n public const array MEDIA_TYPE_OBJECTS = [self::MEDIA_TYPE_OBJECT_PDF, self::MEDIA_TYPE_OBJECT_PODCAST];\n\n public const array CALL_TYPE_CONFERENCE = ['id' => 'conference', 'name' => 'Conference'];\n public const array CALL_TYPE_DIALER = ['id' => 'dialer', 'name' => 'Dialer'];\n public const int SENT_REPORT_AT_HOURS = 5;\n public const string PDF_KEY = 'pdf';\n public const string AUDIO_KEY = 'audio';\n\n private const array ALL_FREQUENCIES = [\n ['id' => self::FREQUENCY_DAILY, 'name' => 'Daily'],\n ['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],\n ['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],\n ['id' => self::FREQUENCY_QUARTERLY, 'name' => 'Quarterly'],\n ['id' => self::FREQUENCY_ONE_OFF, 'name' => 'One-off'],\n ];\n private const string S3_DIR = 'reports';\n private const array FILE_EXTENSIONS_VARIANTS = ['html', 'MD', 'pdf'];\n private const array FILE_PODCAST_EXTENSIONS_VARIANTS = ['json', 'mp3', 'ssml'];\n\n public function __construct(\n private readonly TeamRepository $teamRepository,\n private readonly GroupRepository $groupRepository,\n private readonly UserRepository $userRepository,\n private readonly StageRepository $stageRepository,\n private readonly DealStagesService $dealStagesService,\n private readonly RecipientsService $recipientsService,\n private readonly AutomatedReportsRepository $automatedReportsRepository,\n private readonly Webhook $webhookService,\n private readonly BusDispatcher $dispatcher,\n private readonly ActivityTypeService $activityTypeService,\n private readonly PlaybookCategoryRepository $playbookCategoryRepository,\n private readonly AskAnythingPromptService $askAnythingPromptService,\n private readonly SearchRepository $activitySearchRepository,\n private readonly AskAnythingRepository $askAnythingRepository,\n ) {\n }\n\n public static function getTypes(): array\n {\n $types = self::TYPES;\n\n return array_map(static function ($type) {\n return $type['id'];\n }, $types);\n }\n\n public static function getCallTypes(): array\n {\n return array_map(static function ($callType) {\n return $callType['id'];\n }, [self::CALL_TYPE_CONFERENCE, self::CALL_TYPE_DIALER]);\n }\n\n public static function getFrequencies(): array\n {\n return array_map(static function ($frequency) {\n return $frequency['id'];\n }, self::FREQUENCIES);\n }\n\n // front-facing structure\n public function getReportEnabledFieldData(bool $value = false): array\n {\n return [\n 'id' => 'report_enabled',\n 'label' => '',\n 'inputType' => InputTypeEnum::TOGGLE,\n 'value' => $value,\n ];\n }\n\n // Organizations = Teams\n public function getOrganizationFieldData(?string $value = null, bool $shortVersion = false): array\n {\n $options = $this->getTeams();\n\n if ($shortVersion) {\n return [\n 'id' => 'organization',\n 'label' => 'Organization',\n 'options' => $options,\n ];\n }\n\n return [\n 'id' => 'organization',\n 'label' => 'Organization',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => $options,\n 'value' => $value,\n 'dependencies' => [\n 'teams',\n 'deal_stage_at_call',\n 'current_deal_stage',\n 'recipients',\n ActivityTypeService::PLAYBOOK_CATEGORIES_KEY,\n ],\n 'dependsOn' => [],\n ];\n }\n\n // Teams = Groups\n public function getTeamFieldData(array $options = [], array $value = [], bool $shortVersion = false): array\n {\n if ($shortVersion) {\n return [\n 'id' => 'teams',\n 'label' => 'Team',\n 'options' => $options,\n ];\n }\n\n return [\n 'id' => 'teams',\n 'label' => 'Team',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'required' => false,\n 'placeholder' => 'Select',\n 'options' => $options,\n 'value' => $value, // value should be an array of objects {id, name}\n 'dependencies' => [ActivityTypeService::PLAYBOOK_CATEGORIES_KEY],\n 'dependsOn' => [],\n ];\n }\n\n public function getReportTypeFieldData(?string $value = null, bool $shortVersion = false, ?Team $team = null): array\n {\n $types = [];\n if ($team instanceof Team) {\n if ($team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {\n $types = self::TYPES;\n }\n if ($team->hasFeature(FeatureEnum::ASK_JIMINNY_REPORTS)) {\n $types[] = ['id' => self::TYPE_ASK_JIMINNY, 'name' => 'Ask Jiminny'];\n }\n } else {\n $types = self::TYPES;\n }\n\n if ($shortVersion) {\n return [\n 'id' => 'report_type',\n 'label' => 'Report Type',\n 'options' => $types,\n ];\n }\n\n return [\n 'id' => 'report_type',\n 'label' => 'Report Type',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => $types,\n 'value' => $value,\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getFrequencyFieldData(?string $value = null): array\n {\n return [\n 'id' => 'frequency',\n 'label' => 'Frequency',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => self::FREQUENCIES,\n 'value' => $value,\n 'dependencies' => ['period'],\n 'dependsOn' => [],\n ];\n }\n\n public function getPeriodFieldData(?string $valueStartDate = null, ?string $valueEndDate = null): array\n {\n return [\n 'id' => 'period',\n 'label' => 'Select one-off period',\n 'inputType' => InputTypeEnum::DATE_RANGE,\n 'required' => true,\n 'placeholder' => 'Select',\n 'value' => ['startDate' => $valueStartDate, 'endDate' => $valueEndDate],\n 'queryParams' => [\n 'startDate' => 'start_date_period',\n 'endDate' => 'end_date_period',\n ],\n 'dependencies' => [],\n 'dependsOn' => ['frequency'],\n ];\n }\n\n public function getActivityTypesFieldData(?Team $team = null, array $value = [], array $teamsFilter = []): array\n {\n return $this->activityTypeService->getActivityTypeFieldData(team: $team, value: $value, groupIds: $teamsFilter);\n }\n\n public function getDealStageAtCallFieldData(?Team $team = null, array $value = []): array\n {\n return $this->dealStagesService->getDealStageAtCallFieldData(team: $team, value: $value);\n }\n\n public function getCurrentDealStageFieldData(?Team $team = null, array $value = []): array\n {\n return $this->dealStagesService->getCurrentDealStageFieldData(team: $team, value: $value);\n }\n\n public function getDealValueFieldData(?int $valueMin = null, ?int $valueMax = null): array\n {\n return [\n 'id' => 'deal_value',\n 'label' => 'Deal Value',\n 'inputType' => InputTypeEnum::INTEGER_RANGE,\n 'required' => false,\n 'value' => ['min' => $valueMin, 'max' => $valueMax],\n 'queryParams' => [\n 'min' => 'min_deal_value',\n 'max' => 'max_deal_value',\n ],\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getCallTypeFieldData(bool $conferenceOn = false, bool $dialerOn = false): array\n {\n $value = [];\n $conferenceOn && $value[] = self::CALL_TYPE_CONFERENCE;\n $dialerOn && $value[] = self::CALL_TYPE_DIALER;\n\n return [\n 'id' => 'call_type',\n 'label' => 'Call Type',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'required' => true,\n 'options' => [\n self::CALL_TYPE_CONFERENCE,\n self::CALL_TYPE_DIALER,\n ],\n 'value' => $value,\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getMediaTypeFieldData(?AutomatedReport $report = null): array\n {\n $value = [];\n\n if ($report) {\n $value = $this->transformMediaTypes($report);\n }\n\n return [\n 'id' => 'media_types',\n 'label' => 'Export as',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'required' => true,\n 'options' => self::MEDIA_TYPE_OBJECTS,\n 'value' => $value,\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getCallDurationFieldData(?int $valueMin = null, ?int $valueMax = null): array\n {\n return [\n 'id' => 'call_duration',\n 'label' => 'Call Duration',\n 'inputType' => InputTypeEnum::INTEGER_RANGE,\n 'required' => false,\n 'value' => ['min' => $valueMin, 'max' => $valueMax],\n 'queryParams' => [\n 'min' => 'min_call_duration',\n 'max' => 'max_call_duration',\n ],\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getRecipientsFieldData(?Team $team = null, array $value = []): array\n {\n return $this->recipientsService->getRecipientsFieldData(team: $team, value: $value);\n }\n\n public function getJiminnyRecipientsFieldData(array $value = []): array\n {\n return $this->recipientsService->getJiminnyRecipientsFieldData($value);\n }\n\n public function getAdditionalPromptInputFieldData(?string $value = null): array\n {\n return [\n 'id' => 'additional_prompt_input',\n 'label' => 'Special requirements',\n 'inputType' => InputTypeEnum::TEXTAREA,\n 'required' => false,\n 'placeholder' => 'What should be the focus of the report?',\n 'value' => $value,\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getCustomReportNameFieldData(?string $value = null): array\n {\n return [\n 'id' => 'custom_name',\n 'label' => 'Custom report name',\n 'inputType' => InputTypeEnum::TEXT,\n 'required' => false,\n 'placeholder' => 'Enter custom name',\n 'value' => $value,\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n // data providers\n public function getTeams(): array\n {\n $teams = $this->teamRepository->getTeamsForKiosk(status: Team::STATUS_ACTIVE);\n\n $teamData = [];\n foreach ($teams as $team) {\n if (! $team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {\n continue;\n }\n\n $teamData[] = $this->transformTeam($team);\n }\n\n return $teamData;\n }\n\n public function getTeamGroups(string $teamUuid): array\n {\n $data = [];\n $team = $this->getTeam($teamUuid);\n\n if ($team !== null) {\n $groups = $team->groups()->get();\n\n foreach ($groups as $group) {\n $data[] = [\n 'id' => $group->getUuid(),\n 'name' => $group->getName(),\n ];\n }\n }\n\n return $data;\n }\n\n public function getTeamsGroupsOptions(array $filterTeamUuids = []): array\n {\n $data = [];\n $teams = $this->getTeams();\n\n foreach ($teams as $team) {\n if (! empty($filterTeamUuids) && ! in_array($team['id'], $filterTeamUuids, true)) {\n continue;\n }\n\n $data[] = [\n 'label' => $team['name'],\n 'groups' => $this->getTeamGroups($team['id']),\n ];\n }\n\n return $data;\n }\n\n public function getTeam(string $teamUuid): ?Team\n {\n return $this->teamRepository->idOrUuid($teamUuid);\n }\n\n public function getTeamById(int $teamId): ?Team\n {\n return $this->teamRepository->find($teamId);\n }\n\n public function getGroupsUuids(AutomatedReport $report): array\n {\n $uuids = [];\n $reportGroups = $report->getGroups();\n foreach ($reportGroups as $groupId) {\n if ($group = $this->groupRepository->find($groupId)) {\n $uuids[] = $group->getUuid();\n }\n }\n\n return $uuids;\n }\n\n public function getPlaybookCategoriesUuids(AutomatedReport $report): array\n {\n $uuids = [];\n $playbookCategories = $report->getPlaybookCategories();\n foreach ($playbookCategories as $id) {\n if ($category = $this->playbookCategoryRepository->find($id)) {\n $uuids[] = $category->getUuid();\n }\n }\n\n return $uuids;\n }\n\n public function getDealAtCallStagesUuids(AutomatedReport $report): array\n {\n $uuids = [];\n $reportStages = $report->getDealAtCallStages();\n foreach ($reportStages as $id) {\n if ($stage = $this->stageRepository->find($id)) {\n $uuids[] = $stage->getUuid();\n }\n }\n\n return $uuids;\n }\n\n public function getCurrentDealStagesUuids(AutomatedReport $report): array\n {\n $uuids = [];\n $reportStages = $report->getCurrentDealStages();\n foreach ($reportStages as $id) {\n if ($stage = $this->stageRepository->find($id)) {\n $uuids[] = $stage->getUuid();\n }\n }\n\n return $uuids;\n }\n\n public function getUsersUuids(AutomatedReport $report): array\n {\n return $this->extractUserUuids($report->getRecipients());\n }\n\n public function getJiminnyUsersUuids(AutomatedReport $report): array\n {\n return $this->extractUserUuids($report->getJiminnyRecipients());\n }\n\n /**\n * @param array<string, mixed> $recipients\n */\n private function extractUserUuids(array $recipients): array\n {\n $userIds = $recipients['users'] ?? [];\n\n return collect($userIds)\n ->map(fn ($id) => $this->userRepository->find((int) $id))\n ->filter()\n ->map(fn (UserContract $user) => $user->getUuid())\n ->values()\n ->all();\n }\n\n // get mail data\n public function getRecipientUsers(AutomatedReport $report): array\n {\n return $this->buildRecipientUsers($report->getRecipients());\n }\n\n private function getJiminnyRecipientUsers(AutomatedReport $report): array\n {\n return $this->buildRecipientUsers($report->getJiminnyRecipients());\n }\n\n /**\n * @param array<string, mixed> $recipients\n */\n private function buildRecipientUsers(array $recipients): array\n {\n $userIds = $recipients['users'] ?? [];\n\n return collect($userIds)\n ->map(fn ($id) => $this->userRepository->find((int) $id))\n ->filter()\n ->map(fn (UserContract $user) => [\n 'email' => $user->getEmailAddress(),\n 'name' => $user->getName(),\n 'timezone' => $user->getTimezone()->getName(),\n ])\n ->values()\n ->all();\n }\n\n public function getValidRecipientUsers(AutomatedReport $report, bool $includeJiminny = false): array\n {\n if ($report->isAskJiminnyReport()) {\n $recipients = $this->resolveAskJiminnyRecipients($report);\n } else {\n $recipients = $this->getRecipientUsers($report);\n if ($includeJiminny) {\n $recipients = array_merge($recipients, $this->getJiminnyRecipientUsers($report));\n }\n }\n\n $emails = [];\n\n return array_values(array_filter(\n $recipients,\n static function ($recipient) use (&$emails) {\n if (empty($recipient['email']) || in_array($recipient['email'], $emails, true)) {\n return false;\n }\n $emails[] = $recipient['email'];\n\n return true;\n }\n ));\n }\n\n private function resolveAskJiminnyRecipients(AutomatedReport $report): array\n {\n $recipients = [];\n\n $creator = $report->getCreator();\n if ($creator !== null) {\n $recipients[] = [\n 'email' => $creator->getEmailAddress(),\n 'name' => $creator->getName(),\n 'timezone' => $creator->getTimezone()->getName(),\n ];\n }\n\n return array_merge(\n $recipients,\n $this->buildRecipientUsers($report->getRecipients()),\n $this->getGroupRecipientUsers($report),\n );\n }\n\n private function getGroupRecipientUsers(AutomatedReport $report): array\n {\n $users = [];\n foreach ($report->getGroups() as $groupId) {\n $group = $this->groupRepository->find($groupId);\n if ($group === null) {\n continue;\n }\n foreach ($group->getMembers() as $member) {\n $users[] = [\n 'email' => $member->getEmailAddress(),\n 'name' => $member->getName(),\n 'timezone' => $member->getTimezone()->getName(),\n ];\n }\n }\n\n return $users;\n }\n\n public function getReportTypeName(AutomatedReportResult $report): string\n {\n $type = $report->getReport()->getType();\n\n $getType = $this->transformReportType($type);\n\n return $getType['name'];\n }\n\n public function getReportPeriodName(AutomatedReportResult $report): string\n {\n $from = $report->getFromDate();\n $to = $report->getToDate();\n $frequency = $report->getReport()->getFrequency();\n\n if ($from === null || $to === null) {\n if (! $report->getReport()->isAskJiminnyReport()) {\n $invalidPeriod = $from === null ? 'from' : 'to';\n\n throw new ApplicationException('Report period is invalid: ' . $invalidPeriod);\n }\n\n $period = $this->calculateFromAndToDatePeriod($frequency);\n $from = $period['fromDate'];\n $to = $period['toDate'];\n }\n\n return $this->formatReportPeriodName($frequency, $from, $to);\n }\n\n private function formatReportPeriodName(string $frequency, Carbon $from, Carbon $to): string\n {\n $fromYear = $from->format('Y');\n $toYear = $to->format('Y');\n $differentYears = $fromYear !== $toYear;\n\n switch ($frequency) {\n case self::FREQUENCY_DAILY:\n return $from->format('j M Y');\n\n case self::FREQUENCY_QUARTERLY:\n // 'Jan-Mar 2025' or 'Nov 2024-Jan 2025' if years differ\n $startMonth = $from->format('M');\n $endMonth = $to->copy()->subMonth();\n $endMonthName = $endMonth->format('M');\n $endMonthYear = $endMonth->format('Y');\n\n if ($differentYears) {\n return \"{$startMonth} {$fromYear} - {$endMonthName} {$endMonthYear}\";\n }\n\n return \"{$startMonth} - {$endMonthName} {$toYear}\";\n\n case self::FREQUENCY_MONTHLY:\n // 'May 2025' - monthly reports are always within the same year\n return $from->format('M Y');\n\n case self::FREQUENCY_WEEKLY:\n // '4 - 8 Aug 2025', '27 Oct - 3 Nov 2025', or '28 Dec 2024 - 3 Jan 2025' if years differ\n $startDay = $from->format('j');\n $endDay = $to->format('j');\n $startMonth = $from->format('M');\n $endMonth = $to->format('M');\n\n if ($differentYears) {\n return \"{$startDay} {$startMonth} {$fromYear} - {$endDay} {$endMonth} {$toYear}\";\n }\n\n if ($startMonth !== $endMonth) {\n return \"{$startDay} {$startMonth} - {$endDay} {$endMonth} {$toYear}\";\n }\n\n return \"{$startDay} - {$endDay} {$endMonth} {$toYear}\";\n\n case self::FREQUENCY_ONE_OFF:\n // '2 May-31 May 2025' or '15 Dec 2024-15 Jan 2025' if years differ\n $startDay = $from->format('j');\n $startMonth = $from->format('M');\n $endDay = $to->format('j');\n $endMonth = $to->format('M');\n\n // If same month and year, use a format like '2-31 May 2025'\n if ($startMonth === $endMonth && ! $differentYears) {\n return \"{$startDay} - {$endDay} {$startMonth} {$toYear}\";\n }\n\n // If different years, include both years\n if ($differentYears) {\n return \"{$startDay} {$startMonth} {$fromYear} - {$endDay} {$endMonth} {$toYear}\";\n }\n\n // Same year but different months\n return \"{$startDay} {$startMonth} - {$endDay} {$endMonth} {$toYear}\";\n\n default:\n // Default format for unknown frequencies\n return $from->format('j M Y') . ' - ' . $to->format('j M Y');\n }\n }\n\n public function getReportTeamsName(AutomatedReportResult $report): string\n {\n $groups = $report->getGroups();\n\n if (empty($groups)) {\n return 'All';\n }\n\n // Get group names from repository\n $groupNames = [];\n foreach ($groups as $groupId) {\n $group = $this->groupRepository->find($groupId);\n if ($group) {\n $groupNames[] = $group->getName();\n }\n }\n\n if (count($groupNames) === 1) {\n // Single team format\n $teamsName = $groupNames[0];\n } else {\n // Multiple teams format\n $teamsName = implode(', ', $groupNames);\n }\n\n return $teamsName;\n }\n\n public function getReportFileName(AutomatedReportResult $report): string\n {\n $customName = $report->getReport()->getCustomName();\n $periodName = $this->getReportPeriodName($report);\n $filenameSuffix = $this->getFilenameSuffix($report);\n\n if ($customName) {\n if ($filenameSuffix) {\n $customName .= \" {$filenameSuffix}\";\n }\n\n return $this->sanitizeFileName(\"{$customName} - {$periodName}\");\n }\n\n $baseName = $this->getReportTypeName($report);\n\n if ($filenameSuffix) {\n $baseName .= \" {$filenameSuffix}\";\n }\n\n return $this->sanitizeFileName(\"{$baseName} - {$periodName} - {$this->getReportTeamsName($report)}\");\n }\n\n public function getReportFileNameWithExtension(AutomatedReportResult $result): string\n {\n $extension = $this->getMediaTypeMetadata($result)['extension'];\n\n return $this->getReportFileName($result) . '.' . $extension;\n }\n\n public function sanitizeFileName(string $fileName): string\n {\n return str_replace(['/', '\\\\'], '-', $fileName);\n }\n\n public function isUserRecipientOfReport(User $user, AutomatedReport $report): bool\n {\n $recipients = array_map('intval', $report->getRecipients()['users'] ?? []);\n\n return in_array($user->getId(), $recipients);\n }\n\n public function transformReportResults(Collection $automatedReportResults): array\n {\n $data = [];\n foreach ($automatedReportResults as $automatedReportResult) {\n /** @var AutomatedReportResult $automatedReportResult */\n\n $report = $automatedReportResult->getReport();\n\n $createdBy = $report->getCreator();\n $creator = [\n 'id' => $createdBy?->getUuid(),\n 'name' => $createdBy?->getName(),\n 'email' => $createdBy?->getEmailAddress(),\n 'photoUrl' => $createdBy?->getPhotoUrl(),\n ];\n\n $data[] = [\n 'id' => $automatedReportResult->getUuid(),\n 'name' => $automatedReportResult->getName(),\n 'frequency' => $this->transformFrequency($report->getFrequency()),\n 'recipients' => [\n ...array_values($this->transformGroups(team: $report->getTeam(), groupsIds: $report->getGroups())),\n ...array_values($this->transformRecipients($report->getRecipients())),\n ],\n 'report_type' => $this->transformReportType($report->getType()),\n 'media_type' => $automatedReportResult->getMediaType(),\n 'downloadUrl' => $this->generateReportResultDownloadUrl($automatedReportResult),\n 'viewUrl' => $this->generateReportResultViewUrl($automatedReportResult),\n 'generated_at' => $automatedReportResult->getGeneratedAt()?->toIso8601String(),\n 'creator' => $creator,\n ];\n }\n\n return $data;\n }\n\n public function hasCallTypeConference(AutomatedReport $report): bool\n {\n return in_array(self::CALL_TYPE_CONFERENCE['id'], $report->getCallTypes(), true);\n }\n\n public function hasCallTypeDialer(AutomatedReport $report): bool\n {\n return in_array(self::CALL_TYPE_DIALER['id'], $report->getCallTypes(), true);\n }\n\n // transformers\n private function transformTeam(Team $team): array\n {\n if (! $team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {\n return [];\n }\n\n return [\n 'id' => $team->getUuid(),\n 'name' => $team->getName(),\n ];\n }\n\n private function transformReportFullView(AutomatedReport $report): array\n {\n $base = $this->transformReportBase($report);\n\n return $report->getType() === self::TYPE_ASK_JIMINNY\n ? $base + $this->transformAskJiminnyFields($report)\n : $base + $this->transformStandardReportFields($report);\n }\n\n private function transformReportBase(AutomatedReport $report): array\n {\n return [\n 'id' => $report->getUuid(),\n 'organization' => $this->transformOrganization(team: $report->getTeam()),\n 'report_type' => $this->transformReportType($report->getType()),\n 'frequency' => $this->transformFrequency($report->getFrequency()),\n ];\n }\n\n private function transformStandardReportFields(AutomatedReport $report): array\n {\n $team = $report->getTeam();\n\n return [\n 'report_enabled' => $report->getStatus(),\n 'start_date_period' => $report->getFrom()?->format('Y-m-d H:i:s'),\n 'end_date_period' => $report->getTo()?->format('Y-m-d H:i:s'),\n 'deal_value_min' => $report->getDealValueMin(),\n 'deal_value_max' => $report->getDealValueMax(),\n 'call_types' => $this->transformCallType($report->getCallTypes()),\n 'media_types' => $this->transformMediaTypes($report),\n 'call_duration_min' => $this->transformDurationToMinutes($report->getCallDurationMin()),\n 'call_duration_max' => $this->transformDurationToMinutes($report->getCallDurationMax()),\n 'teams' => $this->transformGroups(team: $team, groupsIds: $report->getGroups()),\n 'deal_at_call_stages' => $this->transformStages(team: $team, stagesIds: $report->getDealAtCallStages()),\n 'current_deal_stages' => $this->transformStages(team: $team, stagesIds: $report->getCurrentDealStages()),\n 'recipients' => $this->transformRecipients($report->getRecipients()),\n 'created_by' => $this->transformCreator($report->getCreator()),\n 'additional_prompt_input' => $report->getAdditionalPromptInput(),\n 'custom_name' => $report->getCustomName(),\n 'created_at' => $report->getCreatedAt()->format('Y-m-d H:i:s'),\n 'updated_at' => $report->getUpdatedAt()->format('Y-m-d H:i:s'),\n 'deleted_at' => $report->getDeletedAt()?->format('Y-m-d H:i:s'),\n ];\n }\n\n private function transformAskJiminnyFields(AutomatedReport $report): array\n {\n $team = $report->getTeam();\n $creatorId = $report->getAttribute('created_by');\n $explicitUserIds = array_values(array_filter(\n $report->getRecipients()['users'] ?? [],\n static fn ($id) => $id !== $creatorId\n ));\n\n return [\n 'report_name' => $report->getCustomName(),\n 'enabled' => $report->getStatus(),\n 'share_teams' => $this->transformGroups(team: $team, groupsIds: $report->getGroups()),\n 'share_users' => $this->transformRecipients(['users' => $explicitUserIds]),\n 'saved_search' => $this->transformSafeSearch($report->getSavedSearch()),\n 'ask_jiminny_prompt' => $this->transformAskJiminnyPrompt($report->getAskAnythingPrompt()),\n 'expires_on' => $report->getExpiresAt()?->format('Y-m-d'),\n ];\n }\n\n private function transformOrganization(?Team $team): array\n {\n return [\n 'id' => $team?->getUuid(),\n 'name' => $team?->getName(),\n ];\n }\n\n private function transformReportType(string $type): array\n {\n foreach (self::ALL_TYPES as $typeItem) {\n if ($typeItem['id'] === $type) {\n return $typeItem;\n }\n }\n\n return [];\n }\n\n private function transformCallType(array $types): array\n {\n $result = [];\n $callTypes = [self::CALL_TYPE_CONFERENCE, self::CALL_TYPE_DIALER];\n\n foreach ($types as $type) {\n foreach ($callTypes as $callTypeItem) {\n if ($callTypeItem['id'] === $type) {\n $result[] = $callTypeItem;\n\n break;\n }\n }\n }\n\n return $result;\n }\n\n private function transformMediaTypes(AutomatedReport $report): array\n {\n $values = [];\n\n foreach ($report->getMediaTypes() as $mediaType) {\n if (! in_array($mediaType, self::MEDIA_TYPES, true)) {\n continue;\n }\n\n $values[] = match ($mediaType) {\n self::MEDIA_TYPE_PDF => self::MEDIA_TYPE_OBJECT_PDF,\n self::MEDIA_TYPE_PODCAST => self::MEDIA_TYPE_OBJECT_PODCAST,\n };\n }\n\n return $values;\n }\n\n private function transformFrequency(string $frequency): array\n {\n foreach (self::ALL_FREQUENCIES as $frequencyItem) {\n if ($frequencyItem['id'] === $frequency) {\n return $frequencyItem;\n }\n }\n\n return [];\n }\n\n public function transformDurationToMinutes(?int $duration): ?int\n {\n if (! $duration) {\n return null;\n }\n\n return (int) ($duration / 60);\n }\n\n private function transformGroups(?Team $team, array $groupsIds): array\n {\n if (empty($groupsIds) || ! $team) {\n return [];\n }\n\n $data = [];\n foreach ($groupsIds as $groupId) {\n $group = $team->groups()->where('id', $groupId)->first();\n\n if ($group) {\n $data[] = [\n 'id' => $group->getUuid(),\n 'name' => $group->getName(),\n 'photoUrl' => $group->getPhotoUrl(),\n ];\n }\n }\n\n return $data;\n }\n\n private function transformStages(?Team $team, array $stagesIds): array\n {\n if (empty($stagesIds) || ! $team) {\n return [];\n }\n\n $data = [];\n foreach ($stagesIds as $stageId) {\n $stage = $team->stages()->where('id', $stageId)->first();\n\n if ($stage) {\n $data[] = [\n 'id' => $stage->getUuid(),\n 'name' => $stage->getName(),\n ];\n }\n }\n\n return $data;\n }\n\n private function transformRecipients(array $recipients): array\n {\n $users = [];\n foreach ($recipients['users'] ?? [] as $userId) {\n $users[] = $this->transformUser($userId);\n }\n\n return $users;\n }\n\n private function transformCreator(?User $user): ?array\n {\n if ($user === null) {\n return null;\n }\n\n return $this->transformUser($user->getId());\n }\n\n private function transformAskJiminnyPrompt(?AskAnythingPrompt $prompt): ?array\n {\n if ($prompt === null) {\n return null;\n }\n\n return [\n 'id' => $prompt->getUuid(),\n 'name' => $prompt->getTitle(),\n ];\n }\n\n private function transformSafeSearch(?Search $search): ?array\n {\n if ($search === null) {\n return null;\n }\n\n return [\n 'id' => $search->getUuid(),\n 'name' => $search->getName(),\n ];\n }\n\n private function transformUser(int $userId): array\n {\n /* @var ?User $user */\n $user = $this->userRepository->find($userId);\n\n return [\n 'id' => $user?->getUuid(),\n 'name' => $user?->getName(),\n 'email' => $user?->getEmailAddress(),\n 'photoUrl' => $user?->getPhotoUrl(),\n ];\n }\n\n public function create(array $data): array\n {\n $validatedData = $this->validateAndTransformData($data);\n $validatedData['created_by'] = auth()->id();\n\n $automatedReport = $this->automatedReportsRepository->create($validatedData);\n\n $this->generateOneOffReport($automatedReport);\n\n return $this->transformReportFullView($automatedReport);\n }\n\n public function update(string $uuid, array $data): array\n {\n $validatedData = $this->validateAndTransformData($data);\n $report = $this->automatedReportsRepository->findByUuid($uuid);\n\n if (! $report) {\n throw new InvalidArgumentException('Report not found');\n }\n\n $oldCustomName = $report->getCustomName();\n\n $automatedReport = $this->automatedReportsRepository->update($report, $validatedData);\n\n if ($oldCustomName !== $automatedReport->getCustomName()) {\n $this->updateResultNames($automatedReport);\n }\n\n $this->generateOneOffReport($automatedReport);\n\n return $this->transformReportFullView($automatedReport);\n }\n\n /**\n * Create an Ask Jiminny report.\n */\n public function createAskJiminnyReport(array $data, User $creator): array\n {\n $validatedData = $this->validateAskJiminnyReportData($data, $creator);\n $validatedData['created_by'] = $creator->getId();\n\n $automatedReport = $this->automatedReportsRepository->create($validatedData);\n\n return $this->transformReportFullView($automatedReport);\n }\n\n /**\n * Update an Ask Jiminny report.\n */\n public function updateAskJiminnyReport(AutomatedReport $report, array $data, User $user): array\n {\n if (! $report->isAskJiminnyReport()) {\n throw new InvalidArgumentException('Report is not an Ask Jiminny report');\n }\n\n $validatedData = $this->validateAskJiminnyReportData($data, $user);\n\n $oldCustomName = $report->getCustomName();\n\n $automatedReport = $this->automatedReportsRepository->update($report, $validatedData);\n\n if ($oldCustomName !== $automatedReport->getCustomName()) {\n $this->updateResultNames($automatedReport);\n }\n\n return $this->transformReportFullView($automatedReport);\n }\n\n public function updateAskJiminnyReportStatus(AutomatedReport $report, bool $status): array\n {\n $this->automatedReportsRepository->update($report, ['status' => $status]);\n\n return $this->transformReportFullView($report->fresh());\n }\n\n /**\n * Validate and transform data for Ask Jiminny reports.\n */\n private function validateAskJiminnyReportData(array $data, User $user): array\n {\n // Validate name\n $name = trim($data['report_name'] ?? '');\n if (empty($name)) {\n throw new InvalidArgumentException('Report name is required');\n }\n if (mb_strlen($name) > 50) {\n throw new InvalidArgumentException('Report name must be 50 characters or less');\n }\n\n // Validate frequency (only daily, weekly, monthly for Ask Jiminny)\n $frequency = $data['frequency'] ?? null;\n $askJiminnyFrequencies = [self::FREQUENCY_DAILY, self::FREQUENCY_WEEKLY, self::FREQUENCY_MONTHLY];\n if (! in_array($frequency, $askJiminnyFrequencies, true)) {\n throw new InvalidArgumentException('Frequency must be daily, weekly, or monthly');\n }\n\n // Validate expiration date\n $expiresAt = $data['expires_on'] ?? null;\n if (empty($expiresAt)) {\n throw new InvalidArgumentException('Expiration date is required');\n }\n\n try {\n $expiresAtDate = Carbon::parse($expiresAt);\n } catch (InvalidFormatException $e) {\n throw new InvalidArgumentException('Expiration date format is invalid');\n }\n $maxExpiration = Carbon::now()->addYear();\n if ($expiresAtDate->gt($maxExpiration)) {\n throw new InvalidArgumentException('Expiration date cannot be more than 1 year from now');\n }\n if ($expiresAtDate->isPast()) {\n throw new InvalidArgumentException('Expiration date cannot be in the past');\n }\n\n // Validate saved search\n $activitySearchId = $data['saved_search'] ?? null;\n if (empty($activitySearchId)) {\n throw new InvalidArgumentException('Saved search is required');\n }\n $savedSearch = $this->activitySearchRepository->findByUuidAndUser($activitySearchId, $user);\n if (! $savedSearch) {\n throw new InvalidArgumentException('Saved search not found or does not belong to you');\n }\n\n // Validate saved prompt\n $askAnythingPromptId = $data['ask_jiminny_prompt'] ?? null;\n if (empty($askAnythingPromptId)) {\n throw new InvalidArgumentException('Ask Jiminny prompt is required');\n }\n $prompt = $this->askAnythingRepository->getPromptByUuid($askAnythingPromptId);\n if (! $prompt) {\n throw new InvalidArgumentException('Ask Jiminny prompt not found');\n }\n\n // Validate status\n $status = $data['enabled'] ?? false;\n\n $recipientUserIds = [$user->getId()];\n\n if (! empty($data['share_users'])) {\n $sharedUserIds = $this->validateAndGetUserIdsByTeam(\n $user->team,\n (array) $data['share_users']\n );\n $recipientUserIds = array_merge($recipientUserIds, $sharedUserIds);\n }\n\n $sharedGroupIds = [];\n if (! empty($data['share_teams'])) {\n $sharedGroupIds = $this->validateAndGetGroupIds($user->team, (array) $data['share_teams']);\n }\n\n $recipientUserIds = array_values(array_unique($recipientUserIds));\n\n return [\n 'team_id' => $user->getTeamId(),\n 'type' => self::TYPE_ASK_JIMINNY,\n 'status' => (bool) $status,\n 'frequency' => $frequency,\n 'custom_name' => $name,\n 'activity_search_id' => $savedSearch->getId(),\n 'ask_anything_prompt_id' => $prompt->getId(),\n 'expires_at' => $expiresAtDate->toDateString(),\n 'media_types' => [self::MEDIA_TYPE_PDF],\n 'call_types' => [],\n 'recipients' => ['users' => $recipientUserIds],\n 'groups' => $sharedGroupIds,\n ];\n }\n\n public static function getAskJiminnyFrequencies(): array\n {\n return array_map(static function ($frequency) {\n return $frequency['id'];\n }, self::ASK_JIMINNY_FREQUENCIES);\n }\n\n public function getAskJiminnyReportFilters(User $user): array\n {\n $savedSearches = $this->activitySearchRepository->findByUserOrderedByName($user)\n ->map(fn (Search $search) => [\n 'id' => $search->getUuid(),\n 'name' => $search->getName(),\n ])\n ->values()->all();\n\n $prompts = collect(\n $this->askAnythingPromptService->get($user, AskAnythingPromptTarget::on_demand)\n )->map(fn (AskAnythingPromptDto $prompt) => [\n 'id' => $prompt->id,\n 'name' => $prompt->title,\n ])->values()->all();\n\n return [\n [\n 'id' => 'prompt',\n 'label' => 'Prompt',\n 'options' => $prompts,\n ],\n [\n 'id' => 'saved_search',\n 'label' => 'Saved Search',\n 'options' => $savedSearches,\n ],\n ];\n }\n\n public function getAskJiminnyReportFormData(User $user, ?AutomatedReport $report = null): array\n {\n $team = $user->getTeam();\n $userTimezone = $user->getTimezone();\n\n $savedSearches = $this->activitySearchRepository->findByUserOrderedByName($user)\n ->map(fn (Search $search) => [\n 'id' => $search->getUuid(),\n 'name' => $search->getName(),\n ])\n ->values()->all();\n\n $prompts = collect(\n $this->askAnythingPromptService->get($user, AskAnythingPromptTarget::on_demand)\n )->map(fn (AskAnythingPromptDto $prompt) => [\n 'id' => $prompt->id,\n 'name' => $prompt->title,\n ])->values()->all();\n\n $teamGroups = $this->groupRepository->getAllByTeam($team)->map(fn ($group) => [\n 'id' => $group->getUuid(),\n 'name' => $group->getName(),\n ])->values()->all();\n\n $shareUsers = $this->recipientsService->getRecipientsFieldData(team: $team)['options'] ?? [];\n\n $sharedTeamsValue = [];\n $sharedUsersValue = [];\n if ($report) {\n $sharedTeamsValue = $this->transformGroups($team, $report->getGroups());\n\n $recipientUserIds = $report->getRecipients()['users'] ?? [];\n $creatorId = $report->getAttribute('created_by');\n $sharedUserIds = array_values(array_filter(\n $recipientUserIds,\n static fn ($id) => $id !== $creatorId\n ));\n $sharedUsersValue = collect($sharedUserIds)\n ->map(fn ($id) => $this->userRepository->find((int) $id))\n ->filter()\n ->map(fn (User $u) => [\n 'id' => $u->getUuid(),\n 'name' => $u->getName(),\n ])\n ->values()\n ->all();\n }\n\n return [\n 'fields' => [\n [\n 'id' => 'enabled',\n 'inputType' => InputTypeEnum::TOGGLE,\n 'label' => '',\n 'value' => $report?->getStatus() ?? false,\n ],\n [\n 'id' => 'report_name',\n 'inputType' => InputTypeEnum::TEXT,\n 'label' => 'Name',\n 'placeholder' => 'Enter name',\n 'required' => true,\n 'validation' => ['maxLength' => 50],\n 'value' => $report?->getCustomName() ?? '',\n ],\n [\n 'id' => 'frequency',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'label' => 'Frequency',\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => self::ASK_JIMINNY_FREQUENCIES,\n 'value' => $report ? $this->transformFrequency($report->getFrequency()) : null,\n ],\n [\n 'id' => 'expires_on',\n 'inputType' => InputTypeEnum::DATE,\n 'label' => 'Expires on',\n 'required' => true,\n 'placeholder' => 'Select',\n 'validation' => [\n 'minDate' => now($userTimezone)->toDateString(),\n 'maxDate' => now($userTimezone)->addYear()->toDateString(),\n ],\n 'value' => $report?->getExpiresAt()?->toDateString(),\n ],\n [\n 'id' => 'share_teams',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'label' => 'Team',\n 'required' => false,\n 'placeholder' => 'Select',\n 'options' => $teamGroups,\n 'value' => $sharedTeamsValue,\n ],\n [\n 'id' => 'share_users',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'label' => 'Team member',\n 'required' => false,\n 'placeholder' => 'Select',\n 'groupLabelKey' => 'label',\n 'groupValuesKey' => 'users',\n 'optionLabelKey' => 'name',\n 'optionValueKey' => 'id',\n 'options' => $shareUsers,\n 'value' => $sharedUsersValue,\n ],\n [\n 'id' => 'saved_search',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'label' => 'Saved search',\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => $savedSearches,\n 'value' => $report && $report->getSavedSearch() ? [\n 'id' => $report->getSavedSearch()->getUuid(),\n 'name' => $report->getSavedSearch()->getName(),\n ] : null,\n ],\n [\n 'id' => 'ask_jiminny_prompt',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'label' => 'Ask Jiminny prompt',\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => $prompts,\n 'value' => $report && $report->getAskAnythingPrompt() ? [\n 'id' => $report->getAskAnythingPrompt()->getUuid(),\n 'name' => $report->getAskAnythingPrompt()->getTitle(),\n ] : null,\n ],\n ],\n ];\n }\n\n private function updateResultNames(AutomatedReport $automatedReport): void\n {\n $results = $this->automatedReportsRepository->getResultsByReport($automatedReport);\n\n foreach ($results as $result) {\n $result->update(['name' => $this->getReportFileName($result)]);\n }\n }\n\n public function updateStatus(string $uuid, array $data): array\n {\n $automatedReport = $this->automatedReportsRepository->findByUuid($uuid);\n\n if (! $automatedReport) {\n throw new ModelNotFoundException('Report not found');\n }\n\n $status = $this->validateReportStatus($data['report_enabled'] ?? null);\n $automatedReport->update([\n 'status' => $status,\n ]);\n\n $this->generateOneOffReport($automatedReport);\n\n return $this->transformReportFullView($automatedReport);\n }\n\n private function generateOneOffReport(AutomatedReport $automatedReport): void\n {\n // the scheduler handles all the other frequency types\n if ($automatedReport->getStatus() === false || $automatedReport->getFrequency() !== self::FREQUENCY_ONE_OFF) {\n return;\n }\n\n $this->dispatcher->dispatch(new RequestGenerateReportJob($automatedReport->getUuid()));\n }\n\n public function getReport(string $uuid): AutomatedReport\n {\n $automatedReport = $this->automatedReportsRepository->findByUuid($uuid);\n\n if (! $automatedReport) {\n throw new ModelNotFoundException('Report not found');\n }\n\n return $automatedReport;\n }\n\n public function get(string $uuid): array\n {\n $automatedReport = $this->getReport($uuid);\n\n return $this->transformReportFullView($automatedReport);\n }\n\n public function list(string $sortColumn = 'created_at', string $sortDirection = 'desc'): array\n {\n $results = [];\n $collection = $this->automatedReportsRepository->getAllStandardReports($sortColumn, $sortDirection);\n\n /** @var AutomatedReport $report */\n foreach ($collection as $report) {\n $results[] = $this->transformReportFullView($report);\n }\n\n return ['data' => $results];\n }\n\n public function listAskJiminnyReports(\n User $user,\n string $sortColumn = 'created_at',\n string $sortDirection = 'desc'\n ): array {\n $results = [];\n $collection = $this->automatedReportsRepository->getAskJiminnyReportsByUser($user, $sortColumn, $sortDirection);\n\n /** @var AutomatedReport $report */\n foreach ($collection as $report) {\n $results[] = $this->transformReportFullView($report);\n }\n\n return ['data' => $results];\n }\n\n public function delete(string $uuid): void\n {\n $automatedReport = $this->automatedReportsRepository->findByUuid($uuid);\n\n if (! $automatedReport) {\n throw new ModelNotFoundException('Report not found');\n }\n\n $automatedReport->delete();\n }\n\n public function createReportResult(AutomatedReport $automatedReport, array $data = []): AutomatedReportResult\n {\n return $this->automatedReportsRepository->createResult(\n array_merge(\n [\n 'report_id' => $automatedReport->getId(),\n 'status' => AutomatedReportResult::STATUS_DEFAULT,\n ],\n $data\n )\n );\n }\n\n public function getReportResult(string $resultUuid): AutomatedReportResult\n {\n $report = $this->automatedReportsRepository->findResultByUuid($resultUuid);\n\n if (! $report) {\n throw new ModelNotFoundException('Report Result not found');\n }\n\n return $report;\n }\n\n public function findChildResult(AutomatedReportResult $result, string $type): ?AutomatedReportResult\n {\n return $this->automatedReportsRepository->findChildResult($result, $type);\n }\n\n // prophet API calls\n /**\n * @throws ApplicationException\n */\n public function getGenerateReportPayload(AutomatedReport $automatedReport, string $reportResultUuid): array\n {\n $period = $this->calculateFromAndToDate($automatedReport);\n $fromDate = $period['fromDate'];\n $toDate = $period['toDate'];\n\n return [\n 'team_id' => $automatedReport->getTeamId(),\n 'request_id' => $reportResultUuid,\n 'report_type' => $automatedReport->getType(),\n 'media_types' => $automatedReport->getMediaTypes(),\n 'from_date' => $fromDate->startOfDay()->format(DateTimeInterface::RFC3339),\n 'to_date' => $toDate->endOfDay()->format(DateTimeInterface::RFC3339),\n 'group_ids' => $automatedReport->getGroups(),\n 'call_deal_stage' => $automatedReport->getDealAtCallStages(),\n 'current_deal_stage' => $automatedReport->getCurrentDealStages(),\n 'deal_min_value' => $automatedReport->getDealValueMin(),\n 'deal_max_value' => $automatedReport->getDealValueMax(),\n 'call_types' => $automatedReport->getCallTypes(),\n 'call_duration_min_seconds' => $automatedReport->getCallDurationMin(),\n 'call_duration_max_seconds' => $automatedReport->getCallDurationMax(),\n 'special_requirements' => $automatedReport->getAdditionalPromptInput(),\n 'callback_url' => $this->getCallbackUrl(),\n 'report_period' => $this->formatReportPeriodName(\n $automatedReport->getFrequency(),\n $fromDate,\n $toDate,\n ),\n 'playbook_categories' => $automatedReport->getPlaybookCategories(),\n 'custom_name' => $automatedReport->getCustomName(),\n ];\n }\n\n // $inputPayload - FE payload structure\n public function getActivitiesCountPayload(array $inputPayload): array\n {\n // Use validateAndTransformData to validate and normalize input\n $validatedData = $this->validateAndTransformData($inputPayload);\n $period = $this->calculateFromAndToDatePeriod(\n $validatedData['frequency'],\n Carbon::parse($validatedData['from']),\n Carbon::parse($validatedData['to']),\n );\n $fromDate = $period['fromDate'];\n $toDate = $period['toDate'];\n\n // Create payload similar to getGenerateReportPayload\n return [\n 'team_id' => $validatedData['team_id'],\n 'group_ids' => $validatedData['groups'] ?? [],\n 'report_type' => $validatedData['type'],\n 'from_date' => $fromDate->format(DateTimeInterface::RFC3339),\n 'to_date' => $toDate->format(DateTimeInterface::RFC3339),\n 'call_deal_stage' => $validatedData['deal_at_call_stages'] ?? [],\n 'current_deal_stage' => $validatedData['current_deal_stages'] ?? [],\n 'deal_min_value' => $validatedData['deal_value_min'] ?? null,\n 'deal_max_value' => $validatedData['deal_value_max'] ?? null,\n 'call_types' => $validatedData['call_types'],\n 'call_duration_min_seconds' => $validatedData['call_duration_min'] ?? null,\n 'call_duration_max_seconds' => $validatedData['call_duration_max'] ?? null,\n 'special_requirements' => $validatedData['additional_prompt_input'] ?? null,\n 'playbook_categories' => $validatedData['playbook_categories'] ?? [],\n 'request_id' => null,\n 'callback_url' => null,\n ];\n }\n\n public function shouldSendReport(array $users, ?CarbonInterface $generatedAt = null): bool\n {\n if (empty($users)) {\n return false;\n }\n\n $earliestTz = collect($users)\n ->mapWithKeys(function (array $user) {\n $tz = new DateTimeZone($user['timezone']);\n $nowUtc = new DateTime('now', new DateTimeZone('UTC'));\n $offset = $tz->getOffset($nowUtc);\n\n return [$user['timezone'] => $offset];\n })\n ->sortDesc()\n ->keys()\n ->first();\n\n $now = Carbon::now($earliestTz);\n $isScheduledTime = (int) $now->format('H') === self::SENT_REPORT_AT_HOURS;\n\n if ($isScheduledTime) {\n return true;\n }\n\n return $this->hasPassedScheduledTime($generatedAt, $earliestTz);\n }\n\n public function hasPassedScheduledTime(?CarbonInterface $generatedAt, string $timezone): bool\n {\n if ($generatedAt === null) {\n return false;\n }\n\n $now = Carbon::now($timezone);\n $scheduledTime = $now->copy()->setTime(self::SENT_REPORT_AT_HOURS, 0, 0);\n\n if ($now->hour < self::SENT_REPORT_AT_HOURS) {\n $scheduledTime = $scheduledTime->subDay();\n }\n\n $scheduledTimeUtc = $scheduledTime->copy()->utc();\n $generatedAtUtc = $generatedAt->copy()->utc();\n $nowUtc = $now->copy()->utc();\n\n return $generatedAtUtc->lt($scheduledTimeUtc) && $nowUtc->gt($scheduledTimeUtc);\n }\n\n public function calculateFromAndToDatePeriod(\n string $frequency,\n ?Carbon $fromDate = null,\n ?Carbon $toDate = null\n ): array {\n if ($frequency === self::FREQUENCY_ONE_OFF) {\n return [\n 'fromDate' => $fromDate,\n 'toDate' => $toDate,\n ];\n }\n\n $now = Carbon::now();\n\n return match ($frequency) {\n self::FREQUENCY_DAILY => [\n 'fromDate' => $now->copy()->subDay()->startOfDay(),\n 'toDate' => $now->copy()->subDay()->endOfDay(),\n ],\n self::FREQUENCY_WEEKLY => [\n 'fromDate' => $now->copy()->subWeeks(1)->startOfDay(),\n 'toDate' => $now->copy()->subDay()->endOfDay(),\n ],\n self::FREQUENCY_MONTHLY => [\n 'fromDate' => $now->copy()->subMonths(1)->startOfDay(),\n 'toDate' => $now->copy()->subDay()->endOfDay(),\n ],\n self::FREQUENCY_QUARTERLY => [\n 'fromDate' => $now->copy()->subMonths(3)->startOfDay(),\n 'toDate' => $now->copy()->subDay()->endOfDay(),\n ],\n default => throw new InvalidArgumentException(\"Unsupported frequency: {$frequency}\"),\n };\n }\n\n private function calculateFromAndToDate(AutomatedReport $automatedReport): array\n {\n return $this->calculateFromAndToDatePeriod(\n $automatedReport->getFrequency(),\n $automatedReport->getFrom(),\n $automatedReport->getTo()\n );\n }\n\n public function getAskJiminnyGenerateReportPayload(\n AutomatedReport $automatedReport,\n AutomatedReportResult $reportResult,\n array $activityIds,\n ): array {\n return [\n 'user_question' => $automatedReport->getAskAnythingPrompt()?->getContent(),\n 'call_ids' => array_map('strval', $activityIds),\n 'team_id' => $automatedReport->getTeamId(),\n 'request_id' => $reportResult->getUuid(),\n 'callback_url' => $this->getCallbackUrl(),\n 'report_period' => $this->getReportPeriodName($reportResult),\n 'report_name' => $automatedReport->getCustomName(),\n ];\n }\n\n private function getCallbackUrl(): string\n {\n return $this->webhookService->route('jiminny.webhook.reports.ready');\n }\n\n /**\n * Validate and transform payload data for automated reports\n *\n * @param array $data\n *\n * @throws InvalidArgumentException\n *\n * @return array\n */\n private function validateAndTransformData(array $data): array\n {\n // Validate organization (team) and check feature\n $team = $this->validateOrganization($data['organization'] ?? null);\n\n $status = $this->validateReportStatus($data['report_enabled'] ?? null);\n $type = $this->validateReportType($data['report_type'] ?? null);\n $frequency = $this->validateFrequency($data['frequency'] ?? null);\n $additionalPromptInput = $this->validateAdditionalPromptInput(\n $data['additional_prompt_input'] ?? null\n );\n $customReportName = $this->validateCustomReportName($data['custom_name'] ?? null);\n\n // Prepare data for the database\n $reportData = [\n 'team_id' => $team->getId(),\n 'type' => $type,\n 'status' => $status,\n 'frequency' => $frequency,\n 'additional_prompt_input' => $additionalPromptInput,\n 'custom_name' => $customReportName,\n ];\n\n // Validate deal values\n $reportData = $this->validateDealValues($data, $reportData);\n\n // Validate date range\n $reportData = $this->validateDateRange($data, $reportData, $frequency);\n\n // Validate call durations\n $reportData = $this->validateCallDurations($data, $reportData);\n\n // Validate call types\n $reportData = $this->validateCallTypes($data, $reportData);\n\n // Validate media types\n $reportData = $this->validateMediaTypes($data, $reportData);\n\n // Validate groups\n if (isset($data['teams'])) {\n $reportData['groups'] = $this->validateAndGetGroupIds($team, $data['teams']);\n }\n\n // Validate deal stages\n $reportData = $this->validateDealStages($data, $reportData, $team, $type);\n\n // Validate playbook categories\n $reportData = $this->validatePlaybookCategories($data, $reportData, $team);\n\n // Validate recipients\n $reportData['recipients'] = [\n 'users' => $this->validateAndGetUserIdsByTeam($team, $data['recipients'] ?? []),\n ];\n\n if (isset($data['jiminny_recipients'])) {\n // Validate Jiminny recipients\n $reportData['jiminny_recipients'] = [\n 'users' => $this->validateAndGetJiminnyUserIds((array) $data['jiminny_recipients']),\n ];\n }\n\n return $reportData;\n }\n\n private function validateDealValues(array $data, array $reportData): array\n {\n if (isset($data['min_deal_value'])) {\n $reportData['deal_value_min'] = (int) $data['min_deal_value'];\n\n if ($reportData['deal_value_min'] > 4294967295 || $reportData['deal_value_min'] < 0) {\n throw new InvalidArgumentException('Min deal value should be between 0 and 4294967295');\n }\n }\n\n if (isset($data['max_deal_value'])) {\n $reportData['deal_value_max'] = (int) $data['max_deal_value'];\n\n if ($reportData['deal_value_max'] > 4294967295 || $reportData['deal_value_max'] < 0) {\n throw new InvalidArgumentException('Max deal value should be between 0 and 4294967295');\n }\n }\n\n if (isset($data['min_deal_value'], $data['max_deal_value'])\n && $data['min_deal_value'] > $data['max_deal_value']\n ) {\n throw new InvalidArgumentException('Min deal value cannot be greater than max deal value');\n }\n\n return $reportData;\n }\n\n private function validateDateRange(array $data, array $reportData, string $frequency): array\n {\n // Set date range only for one_off frequency\n if ($frequency === 'one_off') {\n if (isset($data['start_date_period'])) {\n $reportData['from'] = $this->parseDate($data['start_date_period']);\n }\n\n if (isset($data['end_date_period'])) {\n $reportData['to'] = $this->parseDate($data['end_date_period']);\n }\n\n if (empty($reportData['from']) || empty($reportData['to'])) {\n throw new InvalidArgumentException(\n 'Start date and end date are required for one_off frequency'\n );\n }\n } else {\n $reportData['from'] = null;\n $reportData['to'] = null;\n }\n\n return $reportData;\n }\n\n private function validateCallDurations(array $data, array $reportData): array\n {\n // Convert call durations from minutes to seconds\n if (isset($data['min_call_duration'])) {\n $reportData['call_duration_min'] = (int) $data['min_call_duration'] * 60;\n\n if ($reportData['call_duration_min'] > 4294967295 || $reportData['call_duration_min'] < 0) {\n throw new InvalidArgumentException('Min call duration should be between 0 and 4294967295');\n }\n }\n\n if (isset($data['max_call_duration'])) {\n $reportData['call_duration_max'] = (int) $data['max_call_duration'] * 60;\n\n if ($reportData['call_duration_max'] > 4294967295 || $reportData['call_duration_max'] < 0) {\n throw new InvalidArgumentException('Max call duration should be between 0 and 4294967295');\n }\n }\n\n return $reportData;\n }\n\n private function validateCallTypes(array $data, array $reportData): array\n {\n // Set call types\n $reportData['call_types'] = $data['call_type'] ?? [];\n if (empty($reportData['call_types'])) {\n $reportData['call_types'] = self::getCallTypes();\n }\n\n foreach ($reportData['call_types'] as $callType) {\n if (! in_array($callType, self::getCallTypes(), true)) {\n throw new InvalidArgumentException(sprintf('Call type %s is invalid', $callType));\n }\n }\n\n return $reportData;\n }\n\n private function validateMediaTypes(array $data, array $reportData): array\n {\n // Set media types from input data\n $reportData['media_types'] = $data['media_types'] ?? [];\n\n if (empty($reportData['media_types'])) {\n throw new InvalidArgumentException('Media types are required');\n }\n\n foreach ($reportData['media_types'] as $mediaType) {\n if (! in_array($mediaType, self::MEDIA_TYPES, true)) {\n throw new InvalidArgumentException(sprintf('Media type %s is invalid', $mediaType));\n }\n }\n\n return $reportData;\n }\n\n private function validateDealStages(array $data, array $reportData, Team $team, string $reportType): array\n {\n // Validate and set deal stages\n if (isset($data['deal_stage_at_call'])) {\n $reportData['deal_at_call_stages'] =\n $this->validateAndGetDealStageIds($team, $data['deal_stage_at_call'], 'Deal stage at call');\n }\n\n if (isset($data['current_deal_stage'])) {\n $reportData['current_deal_stages'] =\n $this->validateAndGetDealStageIds($team, $data['current_deal_stage'], 'Current deal stage');\n }\n\n // Ensure current_deal_stage is not provided for loss_analysis report type\n if ($reportType === self::TYPE_LOSS_ANALYSIS && ! empty($data['current_deal_stage'])) {\n throw new InvalidArgumentException('Current deal stage is not applicable for Loss Analysis reports');\n }\n\n return $reportData;\n }\n\n // transform uuid to id\n private function validatePlaybookCategories(array $data, array $reportData, Team $team): array\n {\n $key = 'playbook_categories';\n\n if (isset($data[$key])) {\n $payloadIds = $data[$key];\n $ids = [];\n\n foreach ($payloadIds as $uuid) {\n $uuid = (string) $uuid;\n\n try {\n $playbookCategory = $this->playbookCategoryRepository->findByUuid($uuid);\n } catch (Throwable $throwable) {\n Log::error(__METHOD__ . ' ' . $throwable->getMessage());\n\n throw new InvalidArgumentException(sprintf('Playbook category %s not found', $uuid));\n }\n\n if (! $playbookCategory) {\n throw new InvalidArgumentException(sprintf('Playbook category %s not found', $uuid));\n }\n\n if (! $playbookCategory->hasPlaybook()) {\n throw new InvalidArgumentException(sprintf('Playbook category %s has no playbook', $uuid));\n }\n\n if ($playbookCategory->getPlaybook()->getTeamId() !== $team->getId()) {\n throw new InvalidArgumentException(\n sprintf('Playbook category %s not found for team %s', $uuid, $team->getUuid())\n );\n }\n\n $ids[] = $playbookCategory->getId();\n }\n\n $reportData[$key] = $ids;\n }\n\n return $reportData;\n }\n\n private function validateReportStatus($status): bool\n {\n if (! in_array($status, [true, false], true)) {\n throw new InvalidArgumentException('Report status is invalid');\n }\n\n return $status;\n }\n\n private function validateReportType($type): string\n {\n if (! in_array($type, self::getTypes(), true)) {\n throw new InvalidArgumentException(sprintf('Report type is invalid: %s', $type));\n }\n\n return $type;\n }\n\n private function validateFrequency($frequency): string\n {\n if (! in_array($frequency, self::getFrequencies(), true)) {\n throw new InvalidArgumentException('Frequency is invalid');\n }\n\n return $frequency;\n }\n\n private function validateAdditionalPromptInput(?string $additionalPromptInput): ?string\n {\n if ($additionalPromptInput && strlen($additionalPromptInput) > 5000) {\n throw new InvalidArgumentException('Additional Prompt Input should be less than 5000 characters');\n }\n\n return $additionalPromptInput;\n }\n\n private function validateCustomReportName(?string $customReportName): ?string\n {\n if ($customReportName === null || $customReportName === '') {\n return null;\n }\n\n if (strlen($customReportName) > 70) {\n throw new InvalidArgumentException('Custom report name should be less than 70 characters');\n }\n\n return $customReportName;\n }\n\n private function validateOrganization(?string $organizationUuid): Team\n {\n if (! $organizationUuid) {\n throw new InvalidArgumentException('Organization is required');\n }\n\n $team = $this->teamRepository->idOrUuid($organizationUuid);\n\n if (! $team) {\n throw new InvalidArgumentException('Organization not found');\n }\n\n if (! $team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {\n throw new InvalidArgumentException('Organization does not have the Automated Reports feature');\n }\n\n return $team;\n }\n\n private function validateAndGetGroupIds(Team $team, array $teamUuids): array\n {\n $groupIds = [];\n\n foreach ($teamUuids as $uuid) {\n $group = $this->groupRepository->findByUuid($uuid);\n\n if ($group === null || $group->getTeamId() !== $team->getId()) {\n throw new InvalidArgumentException(\n sprintf('Group %s not found for team %s', $uuid, $team->getUuid())\n );\n }\n\n $groupIds[] = $group->getId();\n\n }\n\n return $groupIds;\n }\n\n private function validateAndGetDealStageIds(Team $team, array $stageUuids, string $propertyLabel): array\n {\n $stageIds = [];\n\n foreach ($stageUuids as $uuid) {\n $stage = $this->stageRepository->findByUuid($uuid);\n\n if ($stage === null || $stage->getTeamId() !== $team->getId()) {\n throw new InvalidArgumentException(\n sprintf('Stage %s not found for team %s for %s', $uuid, $team->getUuid(), $propertyLabel)\n );\n }\n\n $stageIds[] = $stage->getId();\n }\n\n return $stageIds;\n }\n\n private function validateAndGetUserIds(array $userUuids, callable $teamCheck): array\n {\n if (empty($userUuids)) {\n return [];\n }\n\n $userIds = [];\n\n foreach ($userUuids as $uuid) {\n $user = $this->userRepository->findByUuid($uuid);\n\n if (! $user || ! $user->isStatusActive()) {\n throw new InvalidArgumentException(\n sprintf('User %s not found or is not active', $uuid)\n );\n }\n\n if (! $teamCheck($user)) {\n throw new InvalidArgumentException(\n sprintf('User %s does not belong to the allowed team(s)', $uuid)\n );\n }\n\n $userIds[] = $user->getId();\n }\n\n return $userIds;\n }\n\n private function validateAndGetUserIdsByTeam(Team $team, array $userUuids): array\n {\n return $this->validateAndGetUserIds($userUuids, fn ($user) => $user->getTeamId() === $team->getId());\n }\n\n private function validateAndGetJiminnyUserIds(array $userUuids): array\n {\n $allowedTeamIds = config('kiosk.teamIds', []);\n\n return $this->validateAndGetUserIds($userUuids, fn ($user) => in_array($user->getTeamId(), $allowedTeamIds, true));\n }\n\n private function parseDate(string $dateString): string\n {\n return date('Y-m-d H:i:s', strtotime($dateString));\n }\n\n private function generateReportResultViewUrl(AutomatedReportResult $result): string\n {\n $mediaResource = $this->getReportMediaRouteResource($result);\n\n return route('ai-reports.' . $mediaResource . '.view', ['uuid' => $result->getUuid()]);\n }\n\n private function generateReportResultDownloadUrl(AutomatedReportResult $result): string\n {\n $mediaResource = $this->getReportMediaRouteResource($result);\n\n return route('ai-reports.' . $mediaResource . '.download', ['uuid' => $result->getUuid()]);\n }\n\n private function getReportMediaRouteResource(AutomatedReportResult $result): string\n {\n if ($result->getMediaType() === self::MEDIA_TYPE_PDF) {\n return self::PDF_KEY;\n } elseif ($result->getMediaType() === self::MEDIA_TYPE_PODCAST) {\n return self::AUDIO_KEY;\n }\n\n throw new \\InvalidArgumentException('Unknown media type.');\n }\n\n public function getMediaPath(AutomatedReportResult $result): ?string\n {\n $url = match ($result->getMediaType()) {\n self::MEDIA_TYPE_PDF => $result->getPdfUrl(),\n self::MEDIA_TYPE_PODCAST => $result->getPodcastAudioUrl(),\n default => null,\n };\n\n if ($url === null) {\n return null;\n }\n\n $path = parse_url(trim($url, '\"\\''), PHP_URL_PATH);\n\n return $path ?: null;\n }\n\n public function getFilenameSuffix(AutomatedReportResult $result): ?string\n {\n return match ($result->getMediaType()) {\n self::MEDIA_TYPE_PODCAST => 'Podcast',\n default => null,\n };\n }\n\n public function getMailSubjectSuffix(AutomatedReportResult $result): string\n {\n return match ($result->getMediaType()) {\n self::MEDIA_TYPE_PDF => 'report',\n self::MEDIA_TYPE_PODCAST => 'podcast',\n default => '',\n };\n }\n\n public function getMediaTypeMetadata(AutomatedReportResult $result): array\n {\n return match ($result->getMediaType()) {\n self::MEDIA_TYPE_PODCAST => ['extension' => 'mp3', 'mime' => 'audio/mpeg'],\n self::MEDIA_TYPE_PDF => ['extension' => 'pdf', 'mime' => 'application/pdf'],\n default => ['extension' => null, 'mime' => null],\n };\n }\n\n public function deleteS3Files(AutomatedReportResult $result): void\n {\n $teamUuid = $result->getReport()->getTeam()->getUuid();\n $reportUuid = $result->getUuid();\n\n // delete all files for a report uuid no mather of pdf, podcast, or both\n // in case of both - the podcast files are linked to the pdf (parent) uuid\n // pdf and podcast date times should be close\n $path = sprintf('%s/%s/%s', $teamUuid, self::S3_DIR, $reportUuid);\n\n foreach (self::FILE_EXTENSIONS_VARIANTS as $extension) {\n $file = $path . '.' . $extension;\n\n if (Storage::exists($file)) {\n Storage::delete($file);\n Log::info('[Reports] Deleted S3 file', [\n 'path' => $file,\n ]);\n }\n }\n\n foreach (self::FILE_PODCAST_EXTENSIONS_VARIANTS as $extension) {\n $file = $path . '_podcast.' . $extension;\n\n if (Storage::exists($file)) {\n Storage::delete($file);\n Log::info('[Reports] Deleted Podcast S3 file', [\n 'path' => $file,\n ]);\n }\n }\n }\n\n /**\n *\n * @param int|null $teamId Optional team ID to filter results\n *\n * @return Collection<int, int> Collection of team IDs\n */\n public function getTeamIdsWithReportsResults(?int $teamId = null): Collection\n {\n return $this->automatedReportsRepository->getTeamIdsWithReportsResults($teamId);\n }\n\n /**\n * Core delete logic for report results using a query\n *\n * @param Builder $query\n * @param array $logContext\n *\n * @return int\n */\n private function deleteReportResultsByQuery(Builder $query, array $logContext = []): int\n {\n $deletedCount = 0;\n\n if ($query->exists()) {\n Log::info(\n 'Run delete report results',\n array_merge(\n $logContext,\n [\n 'service' => 'AutomatedReportsService',\n ]\n )\n );\n\n $query->chunkById(50, function ($results) use (&$deletedCount, $logContext) {\n foreach ($results as $result) {\n $this->deleteReportResult($result);\n $deletedCount++;\n\n Log::info(\n 'Deleted a report result',\n array_merge(\n $logContext,\n [\n 'result_id' => $result->getId(),\n 'report_id' => $result->getReportId(),\n ]\n )\n );\n }\n });\n }\n\n return $deletedCount;\n }\n\n /**\n * Delete report results for a team by retention period\n *\n * @param Team $team\n * @param CarbonImmutable $retentionDate\n *\n * @return int Number of deleted report results\n */\n public function deleteReportsResultsInRetentionPeriod(Team $team, CarbonImmutable $retentionDate): int\n {\n $reportIds = $this->automatedReportsRepository->getReportIdsByTeam($team);\n\n if ($reportIds->isEmpty()) {\n return 0;\n }\n\n $query = $this->automatedReportsRepository\n ->getReportResultsQueryForRetention($team, $retentionDate);\n\n return $this->deleteReportResultsByQuery($query, [\n 'team_id' => $team->getId(),\n 'retention_date' => $retentionDate->toDateTimeString(),\n ]);\n }\n\n /**\n * Delete ALL report results for a specific automated report\n *\n * @param string $uuid\n *\n * @return int\n */\n public function deleteReportResults(string $uuid): int\n {\n $report = $this->getReport($uuid);\n\n $query = $this->automatedReportsRepository->getResultsByReportQuery($report);\n\n return $this->deleteReportResultsByQuery($query, [\n 'report_uuid' => $uuid,\n 'report_id' => $report->getId(),\n ]);\n }\n\n public function deleteReportResult(AutomatedReportResult $result): void\n {\n $this->deleteS3Files($result);\n\n $result->delete();\n }\n\n /**\n * Get all reports for a specific team\n *\n * @param Team $team\n *\n * @return \\Illuminate\\Database\\Eloquent\\Collection\n */\n public function getTeamReports(Team $team): \\Illuminate\\Database\\Eloquent\\Collection\n {\n return $this->automatedReportsRepository->getReportsByTeam($team);\n }\n\n /**\n * Get all report results for a specific report\n *\n * @param AutomatedReport $report\n *\n * @return \\Illuminate\\Database\\Eloquent\\Collection\n */\n public function getReportResults(AutomatedReport $report): \\Illuminate\\Database\\Eloquent\\Collection\n {\n return $this->automatedReportsRepository->getResultsByReport($report);\n }\n\n public function deleteAllReportResults(AutomatedReport $report): void\n {\n $results = $this->getReportResults($report);\n\n /** @var AutomatedReportResult $result */\n foreach ($results as $result) {\n Log::info('Deleting result', [\n 'report' => $report->getId(),\n 'result' => $result->getId(),\n ]);\n\n $this->deleteReportResult($result);\n }\n }\n\n public function deleteAllData(Team $team): void\n {\n Log::info('Deleting automated report and results for team', [\n 'team' => $team->getId(),\n ]);\n\n $reports = $this->getTeamReports($team);\n\n /** @var AutomatedReport $report */\n foreach ($reports as $report) {\n Log::info('Deleting report', [\n 'team' => $team->getId(),\n 'report' => $report->getId(),\n ]);\n\n $this->deleteAllReportResults($report);\n\n $report->delete();\n }\n }\n}","depth":4,"value":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Services\\Kiosk\\AutomatedReports;\n\nuse Carbon\\CarbonImmutable;\nuse Carbon\\CarbonInterface;\nuse Carbon\\Exceptions\\InvalidFormatException;\nuse DateTime;\nuse DateTimeInterface;\nuse DateTimeZone;\nuse Illuminate\\Contracts\\Bus\\Dispatcher as BusDispatcher;\nuse Illuminate\\Database\\Eloquent\\Builder;\nuse Illuminate\\Support\\Carbon;\nuse Illuminate\\Support\\Collection;\nuse Illuminate\\Support\\Facades\\Log;\nuse Illuminate\\Support\\Facades\\Storage;\nuse Jiminny\\Component\\ActivitySearch\\FilterDefinition\\InputTypeEnum;\nuse Jiminny\\Component\\AskAnything\\AskAnythingPromptService;\nuse Jiminny\\Component\\AskAnything\\Dtos\\AskAnythingPromptDto;\nuse Jiminny\\Component\\UrlGenerator\\Webhook;\nuse Jiminny\\Contracts\\Repositories\\PlaybookCategoryRepository;\nuse Jiminny\\Contracts\\Repositories\\TeamRepository;\nuse Jiminny\\Contracts\\Repositories\\UserRepository;\nuse Jiminny\\Exceptions\\ApplicationException;\nuse Jiminny\\Exceptions\\InvalidArgumentException;\nuse Jiminny\\Exceptions\\ModelNotFoundException;\nuse Jiminny\\Jobs\\AutomatedReports\\RequestGenerateReportJob;\nuse Jiminny\\Models\\Activity\\Search;\nuse Jiminny\\Models\\AskAnything\\AskAnythingPrompt;\nuse Jiminny\\Models\\AskAnything\\AskAnythingPromptTarget;\nuse Jiminny\\Models\\AutomatedReport;\nuse Jiminny\\Models\\AutomatedReportResult;\nuse Jiminny\\Models\\Contracts\\UserContract;\nuse Jiminny\\Models\\Feature\\FeatureEnum;\nuse Jiminny\\Models\\Team;\nuse Jiminny\\Models\\User;\nuse Jiminny\\Repositories\\AskAnythingRepository;\nuse Jiminny\\Repositories\\AutomatedReportsRepository;\nuse Jiminny\\Repositories\\GroupRepository;\nuse Jiminny\\Repositories\\SearchRepository;\nuse Jiminny\\Repositories\\StageRepository;\nuse Throwable;\n\nclass AutomatedReportsService\n{\n public const string TYPE_LOSS_ANALYSIS = 'loss_analysis';\n public const string TYPE_ASK_JIMINNY = 'ask_jiminny';\n\n /**\n * Standard report types (used by kiosk for existing automated reports).\n */\n // @TODO this will add filter, however if we need to control feature by FF we need conditional logic\n public const array TYPES = [\n ['id' => 'exec_summary', 'name' => 'Exec Summary'],\n ['id' => 'coaching_profiles', 'name' => 'Coaching Profiles'],\n ['id' => 'product_feedback', 'name' => 'Product Feedback'],\n ['id' => self::TYPE_LOSS_ANALYSIS, 'name' => 'Loss Analysis'],\n// ['id' => 'questions', 'name' => 'Questions'],\n// ['id' => 'statistical_quant', 'name' => 'Statistical Quantitative'],\n ];\n\n public const array ALL_TYPES = [\n ...self::TYPES,\n ['id' => self::TYPE_ASK_JIMINNY, 'name' => 'Ask Jiminny'],\n ];\n\n public const string FREQUENCY_DAILY = 'daily';\n public const string FREQUENCY_WEEKLY = 'weekly';\n public const string FREQUENCY_MONTHLY = 'monthly';\n public const string FREQUENCY_QUARTERLY = 'quarterly';\n public const string FREQUENCY_ONE_OFF = 'one_off';\n\n /**\n * Frequencies for standard (non-Ask Jiminny) reports.\n */\n public const array FREQUENCIES = [\n ['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],\n ['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],\n ['id' => self::FREQUENCY_QUARTERLY, 'name' => 'Quarterly'],\n ['id' => self::FREQUENCY_ONE_OFF, 'name' => 'One-off'],\n ];\n\n /**\n * Frequencies for Ask Jiminny reports.\n */\n public const array ASK_JIMINNY_FREQUENCIES = [\n ['id' => self::FREQUENCY_DAILY, 'name' => 'Daily'],\n ['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],\n ['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],\n ];\n\n public const string MEDIA_TYPE_PDF = 'pdf';\n public const string MEDIA_TYPE_PODCAST = 'podcast';\n public const array MEDIA_TYPES = [self::MEDIA_TYPE_PDF, self::MEDIA_TYPE_PODCAST];\n public const array MEDIA_TYPE_OBJECT_PDF = ['id' => self::MEDIA_TYPE_PDF, 'name' => 'PDF'];\n public const array MEDIA_TYPE_OBJECT_PODCAST = ['id' => self::MEDIA_TYPE_PODCAST, 'name' => 'Podcast'];\n public const array MEDIA_TYPE_OBJECTS = [self::MEDIA_TYPE_OBJECT_PDF, self::MEDIA_TYPE_OBJECT_PODCAST];\n\n public const array CALL_TYPE_CONFERENCE = ['id' => 'conference', 'name' => 'Conference'];\n public const array CALL_TYPE_DIALER = ['id' => 'dialer', 'name' => 'Dialer'];\n public const int SENT_REPORT_AT_HOURS = 5;\n public const string PDF_KEY = 'pdf';\n public const string AUDIO_KEY = 'audio';\n\n private const array ALL_FREQUENCIES = [\n ['id' => self::FREQUENCY_DAILY, 'name' => 'Daily'],\n ['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],\n ['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],\n ['id' => self::FREQUENCY_QUARTERLY, 'name' => 'Quarterly'],\n ['id' => self::FREQUENCY_ONE_OFF, 'name' => 'One-off'],\n ];\n private const string S3_DIR = 'reports';\n private const array FILE_EXTENSIONS_VARIANTS = ['html', 'MD', 'pdf'];\n private const array FILE_PODCAST_EXTENSIONS_VARIANTS = ['json', 'mp3', 'ssml'];\n\n public function __construct(\n private readonly TeamRepository $teamRepository,\n private readonly GroupRepository $groupRepository,\n private readonly UserRepository $userRepository,\n private readonly StageRepository $stageRepository,\n private readonly DealStagesService $dealStagesService,\n private readonly RecipientsService $recipientsService,\n private readonly AutomatedReportsRepository $automatedReportsRepository,\n private readonly Webhook $webhookService,\n private readonly BusDispatcher $dispatcher,\n private readonly ActivityTypeService $activityTypeService,\n private readonly PlaybookCategoryRepository $playbookCategoryRepository,\n private readonly AskAnythingPromptService $askAnythingPromptService,\n private readonly SearchRepository $activitySearchRepository,\n private readonly AskAnythingRepository $askAnythingRepository,\n ) {\n }\n\n public static function getTypes(): array\n {\n $types = self::TYPES;\n\n return array_map(static function ($type) {\n return $type['id'];\n }, $types);\n }\n\n public static function getCallTypes(): array\n {\n return array_map(static function ($callType) {\n return $callType['id'];\n }, [self::CALL_TYPE_CONFERENCE, self::CALL_TYPE_DIALER]);\n }\n\n public static function getFrequencies(): array\n {\n return array_map(static function ($frequency) {\n return $frequency['id'];\n }, self::FREQUENCIES);\n }\n\n // front-facing structure\n public function getReportEnabledFieldData(bool $value = false): array\n {\n return [\n 'id' => 'report_enabled',\n 'label' => '',\n 'inputType' => InputTypeEnum::TOGGLE,\n 'value' => $value,\n ];\n }\n\n // Organizations = Teams\n public function getOrganizationFieldData(?string $value = null, bool $shortVersion = false): array\n {\n $options = $this->getTeams();\n\n if ($shortVersion) {\n return [\n 'id' => 'organization',\n 'label' => 'Organization',\n 'options' => $options,\n ];\n }\n\n return [\n 'id' => 'organization',\n 'label' => 'Organization',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => $options,\n 'value' => $value,\n 'dependencies' => [\n 'teams',\n 'deal_stage_at_call',\n 'current_deal_stage',\n 'recipients',\n ActivityTypeService::PLAYBOOK_CATEGORIES_KEY,\n ],\n 'dependsOn' => [],\n ];\n }\n\n // Teams = Groups\n public function getTeamFieldData(array $options = [], array $value = [], bool $shortVersion = false): array\n {\n if ($shortVersion) {\n return [\n 'id' => 'teams',\n 'label' => 'Team',\n 'options' => $options,\n ];\n }\n\n return [\n 'id' => 'teams',\n 'label' => 'Team',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'required' => false,\n 'placeholder' => 'Select',\n 'options' => $options,\n 'value' => $value, // value should be an array of objects {id, name}\n 'dependencies' => [ActivityTypeService::PLAYBOOK_CATEGORIES_KEY],\n 'dependsOn' => [],\n ];\n }\n\n public function getReportTypeFieldData(?string $value = null, bool $shortVersion = false, ?Team $team = null): array\n {\n $types = [];\n if ($team instanceof Team) {\n if ($team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {\n $types = self::TYPES;\n }\n if ($team->hasFeature(FeatureEnum::ASK_JIMINNY_REPORTS)) {\n $types[] = ['id' => self::TYPE_ASK_JIMINNY, 'name' => 'Ask Jiminny'];\n }\n } else {\n $types = self::TYPES;\n }\n\n if ($shortVersion) {\n return [\n 'id' => 'report_type',\n 'label' => 'Report Type',\n 'options' => $types,\n ];\n }\n\n return [\n 'id' => 'report_type',\n 'label' => 'Report Type',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => $types,\n 'value' => $value,\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getFrequencyFieldData(?string $value = null): array\n {\n return [\n 'id' => 'frequency',\n 'label' => 'Frequency',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => self::FREQUENCIES,\n 'value' => $value,\n 'dependencies' => ['period'],\n 'dependsOn' => [],\n ];\n }\n\n public function getPeriodFieldData(?string $valueStartDate = null, ?string $valueEndDate = null): array\n {\n return [\n 'id' => 'period',\n 'label' => 'Select one-off period',\n 'inputType' => InputTypeEnum::DATE_RANGE,\n 'required' => true,\n 'placeholder' => 'Select',\n 'value' => ['startDate' => $valueStartDate, 'endDate' => $valueEndDate],\n 'queryParams' => [\n 'startDate' => 'start_date_period',\n 'endDate' => 'end_date_period',\n ],\n 'dependencies' => [],\n 'dependsOn' => ['frequency'],\n ];\n }\n\n public function getActivityTypesFieldData(?Team $team = null, array $value = [], array $teamsFilter = []): array\n {\n return $this->activityTypeService->getActivityTypeFieldData(team: $team, value: $value, groupIds: $teamsFilter);\n }\n\n public function getDealStageAtCallFieldData(?Team $team = null, array $value = []): array\n {\n return $this->dealStagesService->getDealStageAtCallFieldData(team: $team, value: $value);\n }\n\n public function getCurrentDealStageFieldData(?Team $team = null, array $value = []): array\n {\n return $this->dealStagesService->getCurrentDealStageFieldData(team: $team, value: $value);\n }\n\n public function getDealValueFieldData(?int $valueMin = null, ?int $valueMax = null): array\n {\n return [\n 'id' => 'deal_value',\n 'label' => 'Deal Value',\n 'inputType' => InputTypeEnum::INTEGER_RANGE,\n 'required' => false,\n 'value' => ['min' => $valueMin, 'max' => $valueMax],\n 'queryParams' => [\n 'min' => 'min_deal_value',\n 'max' => 'max_deal_value',\n ],\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getCallTypeFieldData(bool $conferenceOn = false, bool $dialerOn = false): array\n {\n $value = [];\n $conferenceOn && $value[] = self::CALL_TYPE_CONFERENCE;\n $dialerOn && $value[] = self::CALL_TYPE_DIALER;\n\n return [\n 'id' => 'call_type',\n 'label' => 'Call Type',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'required' => true,\n 'options' => [\n self::CALL_TYPE_CONFERENCE,\n self::CALL_TYPE_DIALER,\n ],\n 'value' => $value,\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getMediaTypeFieldData(?AutomatedReport $report = null): array\n {\n $value = [];\n\n if ($report) {\n $value = $this->transformMediaTypes($report);\n }\n\n return [\n 'id' => 'media_types',\n 'label' => 'Export as',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'required' => true,\n 'options' => self::MEDIA_TYPE_OBJECTS,\n 'value' => $value,\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getCallDurationFieldData(?int $valueMin = null, ?int $valueMax = null): array\n {\n return [\n 'id' => 'call_duration',\n 'label' => 'Call Duration',\n 'inputType' => InputTypeEnum::INTEGER_RANGE,\n 'required' => false,\n 'value' => ['min' => $valueMin, 'max' => $valueMax],\n 'queryParams' => [\n 'min' => 'min_call_duration',\n 'max' => 'max_call_duration',\n ],\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getRecipientsFieldData(?Team $team = null, array $value = []): array\n {\n return $this->recipientsService->getRecipientsFieldData(team: $team, value: $value);\n }\n\n public function getJiminnyRecipientsFieldData(array $value = []): array\n {\n return $this->recipientsService->getJiminnyRecipientsFieldData($value);\n }\n\n public function getAdditionalPromptInputFieldData(?string $value = null): array\n {\n return [\n 'id' => 'additional_prompt_input',\n 'label' => 'Special requirements',\n 'inputType' => InputTypeEnum::TEXTAREA,\n 'required' => false,\n 'placeholder' => 'What should be the focus of the report?',\n 'value' => $value,\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n public function getCustomReportNameFieldData(?string $value = null): array\n {\n return [\n 'id' => 'custom_name',\n 'label' => 'Custom report name',\n 'inputType' => InputTypeEnum::TEXT,\n 'required' => false,\n 'placeholder' => 'Enter custom name',\n 'value' => $value,\n 'dependencies' => [],\n 'dependsOn' => [],\n ];\n }\n\n // data providers\n public function getTeams(): array\n {\n $teams = $this->teamRepository->getTeamsForKiosk(status: Team::STATUS_ACTIVE);\n\n $teamData = [];\n foreach ($teams as $team) {\n if (! $team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {\n continue;\n }\n\n $teamData[] = $this->transformTeam($team);\n }\n\n return $teamData;\n }\n\n public function getTeamGroups(string $teamUuid): array\n {\n $data = [];\n $team = $this->getTeam($teamUuid);\n\n if ($team !== null) {\n $groups = $team->groups()->get();\n\n foreach ($groups as $group) {\n $data[] = [\n 'id' => $group->getUuid(),\n 'name' => $group->getName(),\n ];\n }\n }\n\n return $data;\n }\n\n public function getTeamsGroupsOptions(array $filterTeamUuids = []): array\n {\n $data = [];\n $teams = $this->getTeams();\n\n foreach ($teams as $team) {\n if (! empty($filterTeamUuids) && ! in_array($team['id'], $filterTeamUuids, true)) {\n continue;\n }\n\n $data[] = [\n 'label' => $team['name'],\n 'groups' => $this->getTeamGroups($team['id']),\n ];\n }\n\n return $data;\n }\n\n public function getTeam(string $teamUuid): ?Team\n {\n return $this->teamRepository->idOrUuid($teamUuid);\n }\n\n public function getTeamById(int $teamId): ?Team\n {\n return $this->teamRepository->find($teamId);\n }\n\n public function getGroupsUuids(AutomatedReport $report): array\n {\n $uuids = [];\n $reportGroups = $report->getGroups();\n foreach ($reportGroups as $groupId) {\n if ($group = $this->groupRepository->find($groupId)) {\n $uuids[] = $group->getUuid();\n }\n }\n\n return $uuids;\n }\n\n public function getPlaybookCategoriesUuids(AutomatedReport $report): array\n {\n $uuids = [];\n $playbookCategories = $report->getPlaybookCategories();\n foreach ($playbookCategories as $id) {\n if ($category = $this->playbookCategoryRepository->find($id)) {\n $uuids[] = $category->getUuid();\n }\n }\n\n return $uuids;\n }\n\n public function getDealAtCallStagesUuids(AutomatedReport $report): array\n {\n $uuids = [];\n $reportStages = $report->getDealAtCallStages();\n foreach ($reportStages as $id) {\n if ($stage = $this->stageRepository->find($id)) {\n $uuids[] = $stage->getUuid();\n }\n }\n\n return $uuids;\n }\n\n public function getCurrentDealStagesUuids(AutomatedReport $report): array\n {\n $uuids = [];\n $reportStages = $report->getCurrentDealStages();\n foreach ($reportStages as $id) {\n if ($stage = $this->stageRepository->find($id)) {\n $uuids[] = $stage->getUuid();\n }\n }\n\n return $uuids;\n }\n\n public function getUsersUuids(AutomatedReport $report): array\n {\n return $this->extractUserUuids($report->getRecipients());\n }\n\n public function getJiminnyUsersUuids(AutomatedReport $report): array\n {\n return $this->extractUserUuids($report->getJiminnyRecipients());\n }\n\n /**\n * @param array<string, mixed> $recipients\n */\n private function extractUserUuids(array $recipients): array\n {\n $userIds = $recipients['users'] ?? [];\n\n return collect($userIds)\n ->map(fn ($id) => $this->userRepository->find((int) $id))\n ->filter()\n ->map(fn (UserContract $user) => $user->getUuid())\n ->values()\n ->all();\n }\n\n // get mail data\n public function getRecipientUsers(AutomatedReport $report): array\n {\n return $this->buildRecipientUsers($report->getRecipients());\n }\n\n private function getJiminnyRecipientUsers(AutomatedReport $report): array\n {\n return $this->buildRecipientUsers($report->getJiminnyRecipients());\n }\n\n /**\n * @param array<string, mixed> $recipients\n */\n private function buildRecipientUsers(array $recipients): array\n {\n $userIds = $recipients['users'] ?? [];\n\n return collect($userIds)\n ->map(fn ($id) => $this->userRepository->find((int) $id))\n ->filter()\n ->map(fn (UserContract $user) => [\n 'email' => $user->getEmailAddress(),\n 'name' => $user->getName(),\n 'timezone' => $user->getTimezone()->getName(),\n ])\n ->values()\n ->all();\n }\n\n public function getValidRecipientUsers(AutomatedReport $report, bool $includeJiminny = false): array\n {\n if ($report->isAskJiminnyReport()) {\n $recipients = $this->resolveAskJiminnyRecipients($report);\n } else {\n $recipients = $this->getRecipientUsers($report);\n if ($includeJiminny) {\n $recipients = array_merge($recipients, $this->getJiminnyRecipientUsers($report));\n }\n }\n\n $emails = [];\n\n return array_values(array_filter(\n $recipients,\n static function ($recipient) use (&$emails) {\n if (empty($recipient['email']) || in_array($recipient['email'], $emails, true)) {\n return false;\n }\n $emails[] = $recipient['email'];\n\n return true;\n }\n ));\n }\n\n private function resolveAskJiminnyRecipients(AutomatedReport $report): array\n {\n $recipients = [];\n\n $creator = $report->getCreator();\n if ($creator !== null) {\n $recipients[] = [\n 'email' => $creator->getEmailAddress(),\n 'name' => $creator->getName(),\n 'timezone' => $creator->getTimezone()->getName(),\n ];\n }\n\n return array_merge(\n $recipients,\n $this->buildRecipientUsers($report->getRecipients()),\n $this->getGroupRecipientUsers($report),\n );\n }\n\n private function getGroupRecipientUsers(AutomatedReport $report): array\n {\n $users = [];\n foreach ($report->getGroups() as $groupId) {\n $group = $this->groupRepository->find($groupId);\n if ($group === null) {\n continue;\n }\n foreach ($group->getMembers() as $member) {\n $users[] = [\n 'email' => $member->getEmailAddress(),\n 'name' => $member->getName(),\n 'timezone' => $member->getTimezone()->getName(),\n ];\n }\n }\n\n return $users;\n }\n\n public function getReportTypeName(AutomatedReportResult $report): string\n {\n $type = $report->getReport()->getType();\n\n $getType = $this->transformReportType($type);\n\n return $getType['name'];\n }\n\n public function getReportPeriodName(AutomatedReportResult $report): string\n {\n $from = $report->getFromDate();\n $to = $report->getToDate();\n $frequency = $report->getReport()->getFrequency();\n\n if ($from === null || $to === null) {\n if (! $report->getReport()->isAskJiminnyReport()) {\n $invalidPeriod = $from === null ? 'from' : 'to';\n\n throw new ApplicationException('Report period is invalid: ' . $invalidPeriod);\n }\n\n $period = $this->calculateFromAndToDatePeriod($frequency);\n $from = $period['fromDate'];\n $to = $period['toDate'];\n }\n\n return $this->formatReportPeriodName($frequency, $from, $to);\n }\n\n private function formatReportPeriodName(string $frequency, Carbon $from, Carbon $to): string\n {\n $fromYear = $from->format('Y');\n $toYear = $to->format('Y');\n $differentYears = $fromYear !== $toYear;\n\n switch ($frequency) {\n case self::FREQUENCY_DAILY:\n return $from->format('j M Y');\n\n case self::FREQUENCY_QUARTERLY:\n // 'Jan-Mar 2025' or 'Nov 2024-Jan 2025' if years differ\n $startMonth = $from->format('M');\n $endMonth = $to->copy()->subMonth();\n $endMonthName = $endMonth->format('M');\n $endMonthYear = $endMonth->format('Y');\n\n if ($differentYears) {\n return \"{$startMonth} {$fromYear} - {$endMonthName} {$endMonthYear}\";\n }\n\n return \"{$startMonth} - {$endMonthName} {$toYear}\";\n\n case self::FREQUENCY_MONTHLY:\n // 'May 2025' - monthly reports are always within the same year\n return $from->format('M Y');\n\n case self::FREQUENCY_WEEKLY:\n // '4 - 8 Aug 2025', '27 Oct - 3 Nov 2025', or '28 Dec 2024 - 3 Jan 2025' if years differ\n $startDay = $from->format('j');\n $endDay = $to->format('j');\n $startMonth = $from->format('M');\n $endMonth = $to->format('M');\n\n if ($differentYears) {\n return \"{$startDay} {$startMonth} {$fromYear} - {$endDay} {$endMonth} {$toYear}\";\n }\n\n if ($startMonth !== $endMonth) {\n return \"{$startDay} {$startMonth} - {$endDay} {$endMonth} {$toYear}\";\n }\n\n return \"{$startDay} - {$endDay} {$endMonth} {$toYear}\";\n\n case self::FREQUENCY_ONE_OFF:\n // '2 May-31 May 2025' or '15 Dec 2024-15 Jan 2025' if years differ\n $startDay = $from->format('j');\n $startMonth = $from->format('M');\n $endDay = $to->format('j');\n $endMonth = $to->format('M');\n\n // If same month and year, use a format like '2-31 May 2025'\n if ($startMonth === $endMonth && ! $differentYears) {\n return \"{$startDay} - {$endDay} {$startMonth} {$toYear}\";\n }\n\n // If different years, include both years\n if ($differentYears) {\n return \"{$startDay} {$startMonth} {$fromYear} - {$endDay} {$endMonth} {$toYear}\";\n }\n\n // Same year but different months\n return \"{$startDay} {$startMonth} - {$endDay} {$endMonth} {$toYear}\";\n\n default:\n // Default format for unknown frequencies\n return $from->format('j M Y') . ' - ' . $to->format('j M Y');\n }\n }\n\n public function getReportTeamsName(AutomatedReportResult $report): string\n {\n $groups = $report->getGroups();\n\n if (empty($groups)) {\n return 'All';\n }\n\n // Get group names from repository\n $groupNames = [];\n foreach ($groups as $groupId) {\n $group = $this->groupRepository->find($groupId);\n if ($group) {\n $groupNames[] = $group->getName();\n }\n }\n\n if (count($groupNames) === 1) {\n // Single team format\n $teamsName = $groupNames[0];\n } else {\n // Multiple teams format\n $teamsName = implode(', ', $groupNames);\n }\n\n return $teamsName;\n }\n\n public function getReportFileName(AutomatedReportResult $report): string\n {\n $customName = $report->getReport()->getCustomName();\n $periodName = $this->getReportPeriodName($report);\n $filenameSuffix = $this->getFilenameSuffix($report);\n\n if ($customName) {\n if ($filenameSuffix) {\n $customName .= \" {$filenameSuffix}\";\n }\n\n return $this->sanitizeFileName(\"{$customName} - {$periodName}\");\n }\n\n $baseName = $this->getReportTypeName($report);\n\n if ($filenameSuffix) {\n $baseName .= \" {$filenameSuffix}\";\n }\n\n return $this->sanitizeFileName(\"{$baseName} - {$periodName} - {$this->getReportTeamsName($report)}\");\n }\n\n public function getReportFileNameWithExtension(AutomatedReportResult $result): string\n {\n $extension = $this->getMediaTypeMetadata($result)['extension'];\n\n return $this->getReportFileName($result) . '.' . $extension;\n }\n\n public function sanitizeFileName(string $fileName): string\n {\n return str_replace(['/', '\\\\'], '-', $fileName);\n }\n\n public function isUserRecipientOfReport(User $user, AutomatedReport $report): bool\n {\n $recipients = array_map('intval', $report->getRecipients()['users'] ?? []);\n\n return in_array($user->getId(), $recipients);\n }\n\n public function transformReportResults(Collection $automatedReportResults): array\n {\n $data = [];\n foreach ($automatedReportResults as $automatedReportResult) {\n /** @var AutomatedReportResult $automatedReportResult */\n\n $report = $automatedReportResult->getReport();\n\n $createdBy = $report->getCreator();\n $creator = [\n 'id' => $createdBy?->getUuid(),\n 'name' => $createdBy?->getName(),\n 'email' => $createdBy?->getEmailAddress(),\n 'photoUrl' => $createdBy?->getPhotoUrl(),\n ];\n\n $data[] = [\n 'id' => $automatedReportResult->getUuid(),\n 'name' => $automatedReportResult->getName(),\n 'frequency' => $this->transformFrequency($report->getFrequency()),\n 'recipients' => [\n ...array_values($this->transformGroups(team: $report->getTeam(), groupsIds: $report->getGroups())),\n ...array_values($this->transformRecipients($report->getRecipients())),\n ],\n 'report_type' => $this->transformReportType($report->getType()),\n 'media_type' => $automatedReportResult->getMediaType(),\n 'downloadUrl' => $this->generateReportResultDownloadUrl($automatedReportResult),\n 'viewUrl' => $this->generateReportResultViewUrl($automatedReportResult),\n 'generated_at' => $automatedReportResult->getGeneratedAt()?->toIso8601String(),\n 'creator' => $creator,\n ];\n }\n\n return $data;\n }\n\n public function hasCallTypeConference(AutomatedReport $report): bool\n {\n return in_array(self::CALL_TYPE_CONFERENCE['id'], $report->getCallTypes(), true);\n }\n\n public function hasCallTypeDialer(AutomatedReport $report): bool\n {\n return in_array(self::CALL_TYPE_DIALER['id'], $report->getCallTypes(), true);\n }\n\n // transformers\n private function transformTeam(Team $team): array\n {\n if (! $team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {\n return [];\n }\n\n return [\n 'id' => $team->getUuid(),\n 'name' => $team->getName(),\n ];\n }\n\n private function transformReportFullView(AutomatedReport $report): array\n {\n $base = $this->transformReportBase($report);\n\n return $report->getType() === self::TYPE_ASK_JIMINNY\n ? $base + $this->transformAskJiminnyFields($report)\n : $base + $this->transformStandardReportFields($report);\n }\n\n private function transformReportBase(AutomatedReport $report): array\n {\n return [\n 'id' => $report->getUuid(),\n 'organization' => $this->transformOrganization(team: $report->getTeam()),\n 'report_type' => $this->transformReportType($report->getType()),\n 'frequency' => $this->transformFrequency($report->getFrequency()),\n ];\n }\n\n private function transformStandardReportFields(AutomatedReport $report): array\n {\n $team = $report->getTeam();\n\n return [\n 'report_enabled' => $report->getStatus(),\n 'start_date_period' => $report->getFrom()?->format('Y-m-d H:i:s'),\n 'end_date_period' => $report->getTo()?->format('Y-m-d H:i:s'),\n 'deal_value_min' => $report->getDealValueMin(),\n 'deal_value_max' => $report->getDealValueMax(),\n 'call_types' => $this->transformCallType($report->getCallTypes()),\n 'media_types' => $this->transformMediaTypes($report),\n 'call_duration_min' => $this->transformDurationToMinutes($report->getCallDurationMin()),\n 'call_duration_max' => $this->transformDurationToMinutes($report->getCallDurationMax()),\n 'teams' => $this->transformGroups(team: $team, groupsIds: $report->getGroups()),\n 'deal_at_call_stages' => $this->transformStages(team: $team, stagesIds: $report->getDealAtCallStages()),\n 'current_deal_stages' => $this->transformStages(team: $team, stagesIds: $report->getCurrentDealStages()),\n 'recipients' => $this->transformRecipients($report->getRecipients()),\n 'created_by' => $this->transformCreator($report->getCreator()),\n 'additional_prompt_input' => $report->getAdditionalPromptInput(),\n 'custom_name' => $report->getCustomName(),\n 'created_at' => $report->getCreatedAt()->format('Y-m-d H:i:s'),\n 'updated_at' => $report->getUpdatedAt()->format('Y-m-d H:i:s'),\n 'deleted_at' => $report->getDeletedAt()?->format('Y-m-d H:i:s'),\n ];\n }\n\n private function transformAskJiminnyFields(AutomatedReport $report): array\n {\n $team = $report->getTeam();\n $creatorId = $report->getAttribute('created_by');\n $explicitUserIds = array_values(array_filter(\n $report->getRecipients()['users'] ?? [],\n static fn ($id) => $id !== $creatorId\n ));\n\n return [\n 'report_name' => $report->getCustomName(),\n 'enabled' => $report->getStatus(),\n 'share_teams' => $this->transformGroups(team: $team, groupsIds: $report->getGroups()),\n 'share_users' => $this->transformRecipients(['users' => $explicitUserIds]),\n 'saved_search' => $this->transformSafeSearch($report->getSavedSearch()),\n 'ask_jiminny_prompt' => $this->transformAskJiminnyPrompt($report->getAskAnythingPrompt()),\n 'expires_on' => $report->getExpiresAt()?->format('Y-m-d'),\n ];\n }\n\n private function transformOrganization(?Team $team): array\n {\n return [\n 'id' => $team?->getUuid(),\n 'name' => $team?->getName(),\n ];\n }\n\n private function transformReportType(string $type): array\n {\n foreach (self::ALL_TYPES as $typeItem) {\n if ($typeItem['id'] === $type) {\n return $typeItem;\n }\n }\n\n return [];\n }\n\n private function transformCallType(array $types): array\n {\n $result = [];\n $callTypes = [self::CALL_TYPE_CONFERENCE, self::CALL_TYPE_DIALER];\n\n foreach ($types as $type) {\n foreach ($callTypes as $callTypeItem) {\n if ($callTypeItem['id'] === $type) {\n $result[] = $callTypeItem;\n\n break;\n }\n }\n }\n\n return $result;\n }\n\n private function transformMediaTypes(AutomatedReport $report): array\n {\n $values = [];\n\n foreach ($report->getMediaTypes() as $mediaType) {\n if (! in_array($mediaType, self::MEDIA_TYPES, true)) {\n continue;\n }\n\n $values[] = match ($mediaType) {\n self::MEDIA_TYPE_PDF => self::MEDIA_TYPE_OBJECT_PDF,\n self::MEDIA_TYPE_PODCAST => self::MEDIA_TYPE_OBJECT_PODCAST,\n };\n }\n\n return $values;\n }\n\n private function transformFrequency(string $frequency): array\n {\n foreach (self::ALL_FREQUENCIES as $frequencyItem) {\n if ($frequencyItem['id'] === $frequency) {\n return $frequencyItem;\n }\n }\n\n return [];\n }\n\n public function transformDurationToMinutes(?int $duration): ?int\n {\n if (! $duration) {\n return null;\n }\n\n return (int) ($duration / 60);\n }\n\n private function transformGroups(?Team $team, array $groupsIds): array\n {\n if (empty($groupsIds) || ! $team) {\n return [];\n }\n\n $data = [];\n foreach ($groupsIds as $groupId) {\n $group = $team->groups()->where('id', $groupId)->first();\n\n if ($group) {\n $data[] = [\n 'id' => $group->getUuid(),\n 'name' => $group->getName(),\n 'photoUrl' => $group->getPhotoUrl(),\n ];\n }\n }\n\n return $data;\n }\n\n private function transformStages(?Team $team, array $stagesIds): array\n {\n if (empty($stagesIds) || ! $team) {\n return [];\n }\n\n $data = [];\n foreach ($stagesIds as $stageId) {\n $stage = $team->stages()->where('id', $stageId)->first();\n\n if ($stage) {\n $data[] = [\n 'id' => $stage->getUuid(),\n 'name' => $stage->getName(),\n ];\n }\n }\n\n return $data;\n }\n\n private function transformRecipients(array $recipients): array\n {\n $users = [];\n foreach ($recipients['users'] ?? [] as $userId) {\n $users[] = $this->transformUser($userId);\n }\n\n return $users;\n }\n\n private function transformCreator(?User $user): ?array\n {\n if ($user === null) {\n return null;\n }\n\n return $this->transformUser($user->getId());\n }\n\n private function transformAskJiminnyPrompt(?AskAnythingPrompt $prompt): ?array\n {\n if ($prompt === null) {\n return null;\n }\n\n return [\n 'id' => $prompt->getUuid(),\n 'name' => $prompt->getTitle(),\n ];\n }\n\n private function transformSafeSearch(?Search $search): ?array\n {\n if ($search === null) {\n return null;\n }\n\n return [\n 'id' => $search->getUuid(),\n 'name' => $search->getName(),\n ];\n }\n\n private function transformUser(int $userId): array\n {\n /* @var ?User $user */\n $user = $this->userRepository->find($userId);\n\n return [\n 'id' => $user?->getUuid(),\n 'name' => $user?->getName(),\n 'email' => $user?->getEmailAddress(),\n 'photoUrl' => $user?->getPhotoUrl(),\n ];\n }\n\n public function create(array $data): array\n {\n $validatedData = $this->validateAndTransformData($data);\n $validatedData['created_by'] = auth()->id();\n\n $automatedReport = $this->automatedReportsRepository->create($validatedData);\n\n $this->generateOneOffReport($automatedReport);\n\n return $this->transformReportFullView($automatedReport);\n }\n\n public function update(string $uuid, array $data): array\n {\n $validatedData = $this->validateAndTransformData($data);\n $report = $this->automatedReportsRepository->findByUuid($uuid);\n\n if (! $report) {\n throw new InvalidArgumentException('Report not found');\n }\n\n $oldCustomName = $report->getCustomName();\n\n $automatedReport = $this->automatedReportsRepository->update($report, $validatedData);\n\n if ($oldCustomName !== $automatedReport->getCustomName()) {\n $this->updateResultNames($automatedReport);\n }\n\n $this->generateOneOffReport($automatedReport);\n\n return $this->transformReportFullView($automatedReport);\n }\n\n /**\n * Create an Ask Jiminny report.\n */\n public function createAskJiminnyReport(array $data, User $creator): array\n {\n $validatedData = $this->validateAskJiminnyReportData($data, $creator);\n $validatedData['created_by'] = $creator->getId();\n\n $automatedReport = $this->automatedReportsRepository->create($validatedData);\n\n return $this->transformReportFullView($automatedReport);\n }\n\n /**\n * Update an Ask Jiminny report.\n */\n public function updateAskJiminnyReport(AutomatedReport $report, array $data, User $user): array\n {\n if (! $report->isAskJiminnyReport()) {\n throw new InvalidArgumentException('Report is not an Ask Jiminny report');\n }\n\n $validatedData = $this->validateAskJiminnyReportData($data, $user);\n\n $oldCustomName = $report->getCustomName();\n\n $automatedReport = $this->automatedReportsRepository->update($report, $validatedData);\n\n if ($oldCustomName !== $automatedReport->getCustomName()) {\n $this->updateResultNames($automatedReport);\n }\n\n return $this->transformReportFullView($automatedReport);\n }\n\n public function updateAskJiminnyReportStatus(AutomatedReport $report, bool $status): array\n {\n $this->automatedReportsRepository->update($report, ['status' => $status]);\n\n return $this->transformReportFullView($report->fresh());\n }\n\n /**\n * Validate and transform data for Ask Jiminny reports.\n */\n private function validateAskJiminnyReportData(array $data, User $user): array\n {\n // Validate name\n $name = trim($data['report_name'] ?? '');\n if (empty($name)) {\n throw new InvalidArgumentException('Report name is required');\n }\n if (mb_strlen($name) > 50) {\n throw new InvalidArgumentException('Report name must be 50 characters or less');\n }\n\n // Validate frequency (only daily, weekly, monthly for Ask Jiminny)\n $frequency = $data['frequency'] ?? null;\n $askJiminnyFrequencies = [self::FREQUENCY_DAILY, self::FREQUENCY_WEEKLY, self::FREQUENCY_MONTHLY];\n if (! in_array($frequency, $askJiminnyFrequencies, true)) {\n throw new InvalidArgumentException('Frequency must be daily, weekly, or monthly');\n }\n\n // Validate expiration date\n $expiresAt = $data['expires_on'] ?? null;\n if (empty($expiresAt)) {\n throw new InvalidArgumentException('Expiration date is required');\n }\n\n try {\n $expiresAtDate = Carbon::parse($expiresAt);\n } catch (InvalidFormatException $e) {\n throw new InvalidArgumentException('Expiration date format is invalid');\n }\n $maxExpiration = Carbon::now()->addYear();\n if ($expiresAtDate->gt($maxExpiration)) {\n throw new InvalidArgumentException('Expiration date cannot be more than 1 year from now');\n }\n if ($expiresAtDate->isPast()) {\n throw new InvalidArgumentException('Expiration date cannot be in the past');\n }\n\n // Validate saved search\n $activitySearchId = $data['saved_search'] ?? null;\n if (empty($activitySearchId)) {\n throw new InvalidArgumentException('Saved search is required');\n }\n $savedSearch = $this->activitySearchRepository->findByUuidAndUser($activitySearchId, $user);\n if (! $savedSearch) {\n throw new InvalidArgumentException('Saved search not found or does not belong to you');\n }\n\n // Validate saved prompt\n $askAnythingPromptId = $data['ask_jiminny_prompt'] ?? null;\n if (empty($askAnythingPromptId)) {\n throw new InvalidArgumentException('Ask Jiminny prompt is required');\n }\n $prompt = $this->askAnythingRepository->getPromptByUuid($askAnythingPromptId);\n if (! $prompt) {\n throw new InvalidArgumentException('Ask Jiminny prompt not found');\n }\n\n // Validate status\n $status = $data['enabled'] ?? false;\n\n $recipientUserIds = [$user->getId()];\n\n if (! empty($data['share_users'])) {\n $sharedUserIds = $this->validateAndGetUserIdsByTeam(\n $user->team,\n (array) $data['share_users']\n );\n $recipientUserIds = array_merge($recipientUserIds, $sharedUserIds);\n }\n\n $sharedGroupIds = [];\n if (! empty($data['share_teams'])) {\n $sharedGroupIds = $this->validateAndGetGroupIds($user->team, (array) $data['share_teams']);\n }\n\n $recipientUserIds = array_values(array_unique($recipientUserIds));\n\n return [\n 'team_id' => $user->getTeamId(),\n 'type' => self::TYPE_ASK_JIMINNY,\n 'status' => (bool) $status,\n 'frequency' => $frequency,\n 'custom_name' => $name,\n 'activity_search_id' => $savedSearch->getId(),\n 'ask_anything_prompt_id' => $prompt->getId(),\n 'expires_at' => $expiresAtDate->toDateString(),\n 'media_types' => [self::MEDIA_TYPE_PDF],\n 'call_types' => [],\n 'recipients' => ['users' => $recipientUserIds],\n 'groups' => $sharedGroupIds,\n ];\n }\n\n public static function getAskJiminnyFrequencies(): array\n {\n return array_map(static function ($frequency) {\n return $frequency['id'];\n }, self::ASK_JIMINNY_FREQUENCIES);\n }\n\n public function getAskJiminnyReportFilters(User $user): array\n {\n $savedSearches = $this->activitySearchRepository->findByUserOrderedByName($user)\n ->map(fn (Search $search) => [\n 'id' => $search->getUuid(),\n 'name' => $search->getName(),\n ])\n ->values()->all();\n\n $prompts = collect(\n $this->askAnythingPromptService->get($user, AskAnythingPromptTarget::on_demand)\n )->map(fn (AskAnythingPromptDto $prompt) => [\n 'id' => $prompt->id,\n 'name' => $prompt->title,\n ])->values()->all();\n\n return [\n [\n 'id' => 'prompt',\n 'label' => 'Prompt',\n 'options' => $prompts,\n ],\n [\n 'id' => 'saved_search',\n 'label' => 'Saved Search',\n 'options' => $savedSearches,\n ],\n ];\n }\n\n public function getAskJiminnyReportFormData(User $user, ?AutomatedReport $report = null): array\n {\n $team = $user->getTeam();\n $userTimezone = $user->getTimezone();\n\n $savedSearches = $this->activitySearchRepository->findByUserOrderedByName($user)\n ->map(fn (Search $search) => [\n 'id' => $search->getUuid(),\n 'name' => $search->getName(),\n ])\n ->values()->all();\n\n $prompts = collect(\n $this->askAnythingPromptService->get($user, AskAnythingPromptTarget::on_demand)\n )->map(fn (AskAnythingPromptDto $prompt) => [\n 'id' => $prompt->id,\n 'name' => $prompt->title,\n ])->values()->all();\n\n $teamGroups = $this->groupRepository->getAllByTeam($team)->map(fn ($group) => [\n 'id' => $group->getUuid(),\n 'name' => $group->getName(),\n ])->values()->all();\n\n $shareUsers = $this->recipientsService->getRecipientsFieldData(team: $team)['options'] ?? [];\n\n $sharedTeamsValue = [];\n $sharedUsersValue = [];\n if ($report) {\n $sharedTeamsValue = $this->transformGroups($team, $report->getGroups());\n\n $recipientUserIds = $report->getRecipients()['users'] ?? [];\n $creatorId = $report->getAttribute('created_by');\n $sharedUserIds = array_values(array_filter(\n $recipientUserIds,\n static fn ($id) => $id !== $creatorId\n ));\n $sharedUsersValue = collect($sharedUserIds)\n ->map(fn ($id) => $this->userRepository->find((int) $id))\n ->filter()\n ->map(fn (User $u) => [\n 'id' => $u->getUuid(),\n 'name' => $u->getName(),\n ])\n ->values()\n ->all();\n }\n\n return [\n 'fields' => [\n [\n 'id' => 'enabled',\n 'inputType' => InputTypeEnum::TOGGLE,\n 'label' => '',\n 'value' => $report?->getStatus() ?? false,\n ],\n [\n 'id' => 'report_name',\n 'inputType' => InputTypeEnum::TEXT,\n 'label' => 'Name',\n 'placeholder' => 'Enter name',\n 'required' => true,\n 'validation' => ['maxLength' => 50],\n 'value' => $report?->getCustomName() ?? '',\n ],\n [\n 'id' => 'frequency',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'label' => 'Frequency',\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => self::ASK_JIMINNY_FREQUENCIES,\n 'value' => $report ? $this->transformFrequency($report->getFrequency()) : null,\n ],\n [\n 'id' => 'expires_on',\n 'inputType' => InputTypeEnum::DATE,\n 'label' => 'Expires on',\n 'required' => true,\n 'placeholder' => 'Select',\n 'validation' => [\n 'minDate' => now($userTimezone)->toDateString(),\n 'maxDate' => now($userTimezone)->addYear()->toDateString(),\n ],\n 'value' => $report?->getExpiresAt()?->toDateString(),\n ],\n [\n 'id' => 'share_teams',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'label' => 'Team',\n 'required' => false,\n 'placeholder' => 'Select',\n 'options' => $teamGroups,\n 'value' => $sharedTeamsValue,\n ],\n [\n 'id' => 'share_users',\n 'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,\n 'label' => 'Team member',\n 'required' => false,\n 'placeholder' => 'Select',\n 'groupLabelKey' => 'label',\n 'groupValuesKey' => 'users',\n 'optionLabelKey' => 'name',\n 'optionValueKey' => 'id',\n 'options' => $shareUsers,\n 'value' => $sharedUsersValue,\n ],\n [\n 'id' => 'saved_search',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'label' => 'Saved search',\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => $savedSearches,\n 'value' => $report && $report->getSavedSearch() ? [\n 'id' => $report->getSavedSearch()->getUuid(),\n 'name' => $report->getSavedSearch()->getName(),\n ] : null,\n ],\n [\n 'id' => 'ask_jiminny_prompt',\n 'inputType' => InputTypeEnum::DROPDOWN,\n 'label' => 'Ask Jiminny prompt',\n 'required' => true,\n 'placeholder' => 'Select',\n 'options' => $prompts,\n 'value' => $report && $report->getAskAnythingPrompt() ? [\n 'id' => $report->getAskAnythingPrompt()->getUuid(),\n 'name' => $report->getAskAnythingPrompt()->getTitle(),\n ] : null,\n ],\n ],\n ];\n }\n\n private function updateResultNames(AutomatedReport $automatedReport): void\n {\n $results = $this->automatedReportsRepository->getResultsByReport($automatedReport);\n\n foreach ($results as $result) {\n $result->update(['name' => $this->getReportFileName($result)]);\n }\n }\n\n public function updateStatus(string $uuid, array $data): array\n {\n $automatedReport = $this->automatedReportsRepository->findByUuid($uuid);\n\n if (! $automatedReport) {\n throw new ModelNotFoundException('Report not found');\n }\n\n $status = $this->validateReportStatus($data['report_enabled'] ?? null);\n $automatedReport->update([\n 'status' => $status,\n ]);\n\n $this->generateOneOffReport($automatedReport);\n\n return $this->transformReportFullView($automatedReport);\n }\n\n private function generateOneOffReport(AutomatedReport $automatedReport): void\n {\n // the scheduler handles all the other frequency types\n if ($automatedReport->getStatus() === false || $automatedReport->getFrequency() !== self::FREQUENCY_ONE_OFF) {\n return;\n }\n\n $this->dispatcher->dispatch(new RequestGenerateReportJob($automatedReport->getUuid()));\n }\n\n public function getReport(string $uuid): AutomatedReport\n {\n $automatedReport = $this->automatedReportsRepository->findByUuid($uuid);\n\n if (! $automatedReport) {\n throw new ModelNotFoundException('Report not found');\n }\n\n return $automatedReport;\n }\n\n public function get(string $uuid): array\n {\n $automatedReport = $this->getReport($uuid);\n\n return $this->transformReportFullView($automatedReport);\n }\n\n public function list(string $sortColumn = 'created_at', string $sortDirection = 'desc'): array\n {\n $results = [];\n $collection = $this->automatedReportsRepository->getAllStandardReports($sortColumn, $sortDirection);\n\n /** @var AutomatedReport $report */\n foreach ($collection as $report) {\n $results[] = $this->transformReportFullView($report);\n }\n\n return ['data' => $results];\n }\n\n public function listAskJiminnyReports(\n User $user,\n string $sortColumn = 'created_at',\n string $sortDirection = 'desc'\n ): array {\n $results = [];\n $collection = $this->automatedReportsRepository->getAskJiminnyReportsByUser($user, $sortColumn, $sortDirection);\n\n /** @var AutomatedReport $report */\n foreach ($collection as $report) {\n $results[] = $this->transformReportFullView($report);\n }\n\n return ['data' => $results];\n }\n\n public function delete(string $uuid): void\n {\n $automatedReport = $this->automatedReportsRepository->findByUuid($uuid);\n\n if (! $automatedReport) {\n throw new ModelNotFoundException('Report not found');\n }\n\n $automatedReport->delete();\n }\n\n public function createReportResult(AutomatedReport $automatedReport, array $data = []): AutomatedReportResult\n {\n return $this->automatedReportsRepository->createResult(\n array_merge(\n [\n 'report_id' => $automatedReport->getId(),\n 'status' => AutomatedReportResult::STATUS_DEFAULT,\n ],\n $data\n )\n );\n }\n\n public function getReportResult(string $resultUuid): AutomatedReportResult\n {\n $report = $this->automatedReportsRepository->findResultByUuid($resultUuid);\n\n if (! $report) {\n throw new ModelNotFoundException('Report Result not found');\n }\n\n return $report;\n }\n\n public function findChildResult(AutomatedReportResult $result, string $type): ?AutomatedReportResult\n {\n return $this->automatedReportsRepository->findChildResult($result, $type);\n }\n\n // prophet API calls\n /**\n * @throws ApplicationException\n */\n public function getGenerateReportPayload(AutomatedReport $automatedReport, string $reportResultUuid): array\n {\n $period = $this->calculateFromAndToDate($automatedReport);\n $fromDate = $period['fromDate'];\n $toDate = $period['toDate'];\n\n return [\n 'team_id' => $automatedReport->getTeamId(),\n 'request_id' => $reportResultUuid,\n 'report_type' => $automatedReport->getType(),\n 'media_types' => $automatedReport->getMediaTypes(),\n 'from_date' => $fromDate->startOfDay()->format(DateTimeInterface::RFC3339),\n 'to_date' => $toDate->endOfDay()->format(DateTimeInterface::RFC3339),\n 'group_ids' => $automatedReport->getGroups(),\n 'call_deal_stage' => $automatedReport->getDealAtCallStages(),\n 'current_deal_stage' => $automatedReport->getCurrentDealStages(),\n 'deal_min_value' => $automatedReport->getDealValueMin(),\n 'deal_max_value' => $automatedReport->getDealValueMax(),\n 'call_types' => $automatedReport->getCallTypes(),\n 'call_duration_min_seconds' => $automatedReport->getCallDurationMin(),\n 'call_duration_max_seconds' => $automatedReport->getCallDurationMax(),\n 'special_requirements' => $automatedReport->getAdditionalPromptInput(),\n 'callback_url' => $this->getCallbackUrl(),\n 'report_period' => $this->formatReportPeriodName(\n $automatedReport->getFrequency(),\n $fromDate,\n $toDate,\n ),\n 'playbook_categories' => $automatedReport->getPlaybookCategories(),\n 'custom_name' => $automatedReport->getCustomName(),\n ];\n }\n\n // $inputPayload - FE payload structure\n public function getActivitiesCountPayload(array $inputPayload): array\n {\n // Use validateAndTransformData to validate and normalize input\n $validatedData = $this->validateAndTransformData($inputPayload);\n $period = $this->calculateFromAndToDatePeriod(\n $validatedData['frequency'],\n Carbon::parse($validatedData['from']),\n Carbon::parse($validatedData['to']),\n );\n $fromDate = $period['fromDate'];\n $toDate = $period['toDate'];\n\n // Create payload similar to getGenerateReportPayload\n return [\n 'team_id' => $validatedData['team_id'],\n 'group_ids' => $validatedData['groups'] ?? [],\n 'report_type' => $validatedData['type'],\n 'from_date' => $fromDate->format(DateTimeInterface::RFC3339),\n 'to_date' => $toDate->format(DateTimeInterface::RFC3339),\n 'call_deal_stage' => $validatedData['deal_at_call_stages'] ?? [],\n 'current_deal_stage' => $validatedData['current_deal_stages'] ?? [],\n 'deal_min_value' => $validatedData['deal_value_min'] ?? null,\n 'deal_max_value' => $validatedData['deal_value_max'] ?? null,\n 'call_types' => $validatedData['call_types'],\n 'call_duration_min_seconds' => $validatedData['call_duration_min'] ?? null,\n 'call_duration_max_seconds' => $validatedData['call_duration_max'] ?? null,\n 'special_requirements' => $validatedData['additional_prompt_input'] ?? null,\n 'playbook_categories' => $validatedData['playbook_categories'] ?? [],\n 'request_id' => null,\n 'callback_url' => null,\n ];\n }\n\n public function shouldSendReport(array $users, ?CarbonInterface $generatedAt = null): bool\n {\n if (empty($users)) {\n return false;\n }\n\n $earliestTz = collect($users)\n ->mapWithKeys(function (array $user) {\n $tz = new DateTimeZone($user['timezone']);\n $nowUtc = new DateTime('now', new DateTimeZone('UTC'));\n $offset = $tz->getOffset($nowUtc);\n\n return [$user['timezone'] => $offset];\n })\n ->sortDesc()\n ->keys()\n ->first();\n\n $now = Carbon::now($earliestTz);\n $isScheduledTime = (int) $now->format('H') === self::SENT_REPORT_AT_HOURS;\n\n if ($isScheduledTime) {\n return true;\n }\n\n return $this->hasPassedScheduledTime($generatedAt, $earliestTz);\n }\n\n public function hasPassedScheduledTime(?CarbonInterface $generatedAt, string $timezone): bool\n {\n if ($generatedAt === null) {\n return false;\n }\n\n $now = Carbon::now($timezone);\n $scheduledTime = $now->copy()->setTime(self::SENT_REPORT_AT_HOURS, 0, 0);\n\n if ($now->hour < self::SENT_REPORT_AT_HOURS) {\n $scheduledTime = $scheduledTime->subDay();\n }\n\n $scheduledTimeUtc = $scheduledTime->copy()->utc();\n $generatedAtUtc = $generatedAt->copy()->utc();\n $nowUtc = $now->copy()->utc();\n\n return $generatedAtUtc->lt($scheduledTimeUtc) && $nowUtc->gt($scheduledTimeUtc);\n }\n\n public function calculateFromAndToDatePeriod(\n string $frequency,\n ?Carbon $fromDate = null,\n ?Carbon $toDate = null\n ): array {\n if ($frequency === self::FREQUENCY_ONE_OFF) {\n return [\n 'fromDate' => $fromDate,\n 'toDate' => $toDate,\n ];\n }\n\n $now = Carbon::now();\n\n return match ($frequency) {\n self::FREQUENCY_DAILY => [\n 'fromDate' => $now->copy()->subDay()->startOfDay(),\n 'toDate' => $now->copy()->subDay()->endOfDay(),\n ],\n self::FREQUENCY_WEEKLY => [\n 'fromDate' => $now->copy()->subWeeks(1)->startOfDay(),\n 'toDate' => $now->copy()->subDay()->endOfDay(),\n ],\n self::FREQUENCY_MONTHLY => [\n 'fromDate' => $now->copy()->subMonths(1)->startOfDay(),\n 'toDate' => $now->copy()->subDay()->endOfDay(),\n ],\n self::FREQUENCY_QUARTERLY => [\n 'fromDate' => $now->copy()->subMonths(3)->startOfDay(),\n 'toDate' => $now->copy()->subDay()->endOfDay(),\n ],\n default => throw new InvalidArgumentException(\"Unsupported frequency: {$frequency}\"),\n };\n }\n\n private function calculateFromAndToDate(AutomatedReport $automatedReport): array\n {\n return $this->calculateFromAndToDatePeriod(\n $automatedReport->getFrequency(),\n $automatedReport->getFrom(),\n $automatedReport->getTo()\n );\n }\n\n public function getAskJiminnyGenerateReportPayload(\n AutomatedReport $automatedReport,\n AutomatedReportResult $reportResult,\n array $activityIds,\n ): array {\n return [\n 'user_question' => $automatedReport->getAskAnythingPrompt()?->getContent(),\n 'call_ids' => array_map('strval', $activityIds),\n 'team_id' => $automatedReport->getTeamId(),\n 'request_id' => $reportResult->getUuid(),\n 'callback_url' => $this->getCallbackUrl(),\n 'report_period' => $this->getReportPeriodName($reportResult),\n 'report_name' => $automatedReport->getCustomName(),\n ];\n }\n\n private function getCallbackUrl(): string\n {\n return $this->webhookService->route('jiminny.webhook.reports.ready');\n }\n\n /**\n * Validate and transform payload data for automated reports\n *\n * @param array $data\n *\n * @throws InvalidArgumentException\n *\n * @return array\n */\n private function validateAndTransformData(array $data): array\n {\n // Validate organization (team) and check feature\n $team = $this->validateOrganization($data['organization'] ?? null);\n\n $status = $this->validateReportStatus($data['report_enabled'] ?? null);\n $type = $this->validateReportType($data['report_type'] ?? null);\n $frequency = $this->validateFrequency($data['frequency'] ?? null);\n $additionalPromptInput = $this->validateAdditionalPromptInput(\n $data['additional_prompt_input'] ?? null\n );\n $customReportName = $this->validateCustomReportName($data['custom_name'] ?? null);\n\n // Prepare data for the database\n $reportData = [\n 'team_id' => $team->getId(),\n 'type' => $type,\n 'status' => $status,\n 'frequency' => $frequency,\n 'additional_prompt_input' => $additionalPromptInput,\n 'custom_name' => $customReportName,\n ];\n\n // Validate deal values\n $reportData = $this->validateDealValues($data, $reportData);\n\n // Validate date range\n $reportData = $this->validateDateRange($data, $reportData, $frequency);\n\n // Validate call durations\n $reportData = $this->validateCallDurations($data, $reportData);\n\n // Validate call types\n $reportData = $this->validateCallTypes($data, $reportData);\n\n // Validate media types\n $reportData = $this->validateMediaTypes($data, $reportData);\n\n // Validate groups\n if (isset($data['teams'])) {\n $reportData['groups'] = $this->validateAndGetGroupIds($team, $data['teams']);\n }\n\n // Validate deal stages\n $reportData = $this->validateDealStages($data, $reportData, $team, $type);\n\n // Validate playbook categories\n $reportData = $this->validatePlaybookCategories($data, $reportData, $team);\n\n // Validate recipients\n $reportData['recipients'] = [\n 'users' => $this->validateAndGetUserIdsByTeam($team, $data['recipients'] ?? []),\n ];\n\n if (isset($data['jiminny_recipients'])) {\n // Validate Jiminny recipients\n $reportData['jiminny_recipients'] = [\n 'users' => $this->validateAndGetJiminnyUserIds((array) $data['jiminny_recipients']),\n ];\n }\n\n return $reportData;\n }\n\n private function validateDealValues(array $data, array $reportData): array\n {\n if (isset($data['min_deal_value'])) {\n $reportData['deal_value_min'] = (int) $data['min_deal_value'];\n\n if ($reportData['deal_value_min'] > 4294967295 || $reportData['deal_value_min'] < 0) {\n throw new InvalidArgumentException('Min deal value should be between 0 and 4294967295');\n }\n }\n\n if (isset($data['max_deal_value'])) {\n $reportData['deal_value_max'] = (int) $data['max_deal_value'];\n\n if ($reportData['deal_value_max'] > 4294967295 || $reportData['deal_value_max'] < 0) {\n throw new InvalidArgumentException('Max deal value should be between 0 and 4294967295');\n }\n }\n\n if (isset($data['min_deal_value'], $data['max_deal_value'])\n && $data['min_deal_value'] > $data['max_deal_value']\n ) {\n throw new InvalidArgumentException('Min deal value cannot be greater than max deal value');\n }\n\n return $reportData;\n }\n\n private function validateDateRange(array $data, array $reportData, string $frequency): array\n {\n // Set date range only for one_off frequency\n if ($frequency === 'one_off') {\n if (isset($data['start_date_period'])) {\n $reportData['from'] = $this->parseDate($data['start_date_period']);\n }\n\n if (isset($data['end_date_period'])) {\n $reportData['to'] = $this->parseDate($data['end_date_period']);\n }\n\n if (empty($reportData['from']) || empty($reportData['to'])) {\n throw new InvalidArgumentException(\n 'Start date and end date are required for one_off frequency'\n );\n }\n } else {\n $reportData['from'] = null;\n $reportData['to'] = null;\n }\n\n return $reportData;\n }\n\n private function validateCallDurations(array $data, array $reportData): array\n {\n // Convert call durations from minutes to seconds\n if (isset($data['min_call_duration'])) {\n $reportData['call_duration_min'] = (int) $data['min_call_duration'] * 60;\n\n if ($reportData['call_duration_min'] > 4294967295 || $reportData['call_duration_min'] < 0) {\n throw new InvalidArgumentException('Min call duration should be between 0 and 4294967295');\n }\n }\n\n if (isset($data['max_call_duration'])) {\n $reportData['call_duration_max'] = (int) $data['max_call_duration'] * 60;\n\n if ($reportData['call_duration_max'] > 4294967295 || $reportData['call_duration_max'] < 0) {\n throw new InvalidArgumentException('Max call duration should be between 0 and 4294967295');\n }\n }\n\n return $reportData;\n }\n\n private function validateCallTypes(array $data, array $reportData): array\n {\n // Set call types\n $reportData['call_types'] = $data['call_type'] ?? [];\n if (empty($reportData['call_types'])) {\n $reportData['call_types'] = self::getCallTypes();\n }\n\n foreach ($reportData['call_types'] as $callType) {\n if (! in_array($callType, self::getCallTypes(), true)) {\n throw new InvalidArgumentException(sprintf('Call type %s is invalid', $callType));\n }\n }\n\n return $reportData;\n }\n\n private function validateMediaTypes(array $data, array $reportData): array\n {\n // Set media types from input data\n $reportData['media_types'] = $data['media_types'] ?? [];\n\n if (empty($reportData['media_types'])) {\n throw new InvalidArgumentException('Media types are required');\n }\n\n foreach ($reportData['media_types'] as $mediaType) {\n if (! in_array($mediaType, self::MEDIA_TYPES, true)) {\n throw new InvalidArgumentException(sprintf('Media type %s is invalid', $mediaType));\n }\n }\n\n return $reportData;\n }\n\n private function validateDealStages(array $data, array $reportData, Team $team, string $reportType): array\n {\n // Validate and set deal stages\n if (isset($data['deal_stage_at_call'])) {\n $reportData['deal_at_call_stages'] =\n $this->validateAndGetDealStageIds($team, $data['deal_stage_at_call'], 'Deal stage at call');\n }\n\n if (isset($data['current_deal_stage'])) {\n $reportData['current_deal_stages'] =\n $this->validateAndGetDealStageIds($team, $data['current_deal_stage'], 'Current deal stage');\n }\n\n // Ensure current_deal_stage is not provided for loss_analysis report type\n if ($reportType === self::TYPE_LOSS_ANALYSIS && ! empty($data['current_deal_stage'])) {\n throw new InvalidArgumentException('Current deal stage is not applicable for Loss Analysis reports');\n }\n\n return $reportData;\n }\n\n // transform uuid to id\n private function validatePlaybookCategories(array $data, array $reportData, Team $team): array\n {\n $key = 'playbook_categories';\n\n if (isset($data[$key])) {\n $payloadIds = $data[$key];\n $ids = [];\n\n foreach ($payloadIds as $uuid) {\n $uuid = (string) $uuid;\n\n try {\n $playbookCategory = $this->playbookCategoryRepository->findByUuid($uuid);\n } catch (Throwable $throwable) {\n Log::error(__METHOD__ . ' ' . $throwable->getMessage());\n\n throw new InvalidArgumentException(sprintf('Playbook category %s not found', $uuid));\n }\n\n if (! $playbookCategory) {\n throw new InvalidArgumentException(sprintf('Playbook category %s not found', $uuid));\n }\n\n if (! $playbookCategory->hasPlaybook()) {\n throw new InvalidArgumentException(sprintf('Playbook category %s has no playbook', $uuid));\n }\n\n if ($playbookCategory->getPlaybook()->getTeamId() !== $team->getId()) {\n throw new InvalidArgumentException(\n sprintf('Playbook category %s not found for team %s', $uuid, $team->getUuid())\n );\n }\n\n $ids[] = $playbookCategory->getId();\n }\n\n $reportData[$key] = $ids;\n }\n\n return $reportData;\n }\n\n private function validateReportStatus($status): bool\n {\n if (! in_array($status, [true, false], true)) {\n throw new InvalidArgumentException('Report status is invalid');\n }\n\n return $status;\n }\n\n private function validateReportType($type): string\n {\n if (! in_array($type, self::getTypes(), true)) {\n throw new InvalidArgumentException(sprintf('Report type is invalid: %s', $type));\n }\n\n return $type;\n }\n\n private function validateFrequency($frequency): string\n {\n if (! in_array($frequency, self::getFrequencies(), true)) {\n throw new InvalidArgumentException('Frequency is invalid');\n }\n\n return $frequency;\n }\n\n private function validateAdditionalPromptInput(?string $additionalPromptInput): ?string\n {\n if ($additionalPromptInput && strlen($additionalPromptInput) > 5000) {\n throw new InvalidArgumentException('Additional Prompt Input should be less than 5000 characters');\n }\n\n return $additionalPromptInput;\n }\n\n private function validateCustomReportName(?string $customReportName): ?string\n {\n if ($customReportName === null || $customReportName === '') {\n return null;\n }\n\n if (strlen($customReportName) > 70) {\n throw new InvalidArgumentException('Custom report name should be less than 70 characters');\n }\n\n return $customReportName;\n }\n\n private function validateOrganization(?string $organizationUuid): Team\n {\n if (! $organizationUuid) {\n throw new InvalidArgumentException('Organization is required');\n }\n\n $team = $this->teamRepository->idOrUuid($organizationUuid);\n\n if (! $team) {\n throw new InvalidArgumentException('Organization not found');\n }\n\n if (! $team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {\n throw new InvalidArgumentException('Organization does not have the Automated Reports feature');\n }\n\n return $team;\n }\n\n private function validateAndGetGroupIds(Team $team, array $teamUuids): array\n {\n $groupIds = [];\n\n foreach ($teamUuids as $uuid) {\n $group = $this->groupRepository->findByUuid($uuid);\n\n if ($group === null || $group->getTeamId() !== $team->getId()) {\n throw new InvalidArgumentException(\n sprintf('Group %s not found for team %s', $uuid, $team->getUuid())\n );\n }\n\n $groupIds[] = $group->getId();\n\n }\n\n return $groupIds;\n }\n\n private function validateAndGetDealStageIds(Team $team, array $stageUuids, string $propertyLabel): array\n {\n $stageIds = [];\n\n foreach ($stageUuids as $uuid) {\n $stage = $this->stageRepository->findByUuid($uuid);\n\n if ($stage === null || $stage->getTeamId() !== $team->getId()) {\n throw new InvalidArgumentException(\n sprintf('Stage %s not found for team %s for %s', $uuid, $team->getUuid(), $propertyLabel)\n );\n }\n\n $stageIds[] = $stage->getId();\n }\n\n return $stageIds;\n }\n\n private function validateAndGetUserIds(array $userUuids, callable $teamCheck): array\n {\n if (empty($userUuids)) {\n return [];\n }\n\n $userIds = [];\n\n foreach ($userUuids as $uuid) {\n $user = $this->userRepository->findByUuid($uuid);\n\n if (! $user || ! $user->isStatusActive()) {\n throw new InvalidArgumentException(\n sprintf('User %s not found or is not active', $uuid)\n );\n }\n\n if (! $teamCheck($user)) {\n throw new InvalidArgumentException(\n sprintf('User %s does not belong to the allowed team(s)', $uuid)\n );\n }\n\n $userIds[] = $user->getId();\n }\n\n return $userIds;\n }\n\n private function validateAndGetUserIdsByTeam(Team $team, array $userUuids): array\n {\n return $this->validateAndGetUserIds($userUuids, fn ($user) => $user->getTeamId() === $team->getId());\n }\n\n private function validateAndGetJiminnyUserIds(array $userUuids): array\n {\n $allowedTeamIds = config('kiosk.teamIds', []);\n\n return $this->validateAndGetUserIds($userUuids, fn ($user) => in_array($user->getTeamId(), $allowedTeamIds, true));\n }\n\n private function parseDate(string $dateString): string\n {\n return date('Y-m-d H:i:s', strtotime($dateString));\n }\n\n private function generateReportResultViewUrl(AutomatedReportResult $result): string\n {\n $mediaResource = $this->getReportMediaRouteResource($result);\n\n return route('ai-reports.' . $mediaResource . '.view', ['uuid' => $result->getUuid()]);\n }\n\n private function generateReportResultDownloadUrl(AutomatedReportResult $result): string\n {\n $mediaResource = $this->getReportMediaRouteResource($result);\n\n return route('ai-reports.' . $mediaResource . '.download', ['uuid' => $result->getUuid()]);\n }\n\n private function getReportMediaRouteResource(AutomatedReportResult $result): string\n {\n if ($result->getMediaType() === self::MEDIA_TYPE_PDF) {\n return self::PDF_KEY;\n } elseif ($result->getMediaType() === self::MEDIA_TYPE_PODCAST) {\n return self::AUDIO_KEY;\n }\n\n throw new \\InvalidArgumentException('Unknown media type.');\n }\n\n public function getMediaPath(AutomatedReportResult $result): ?string\n {\n $url = match ($result->getMediaType()) {\n self::MEDIA_TYPE_PDF => $result->getPdfUrl(),\n self::MEDIA_TYPE_PODCAST => $result->getPodcastAudioUrl(),\n default => null,\n };\n\n if ($url === null) {\n return null;\n }\n\n $path = parse_url(trim($url, '\"\\''), PHP_URL_PATH);\n\n return $path ?: null;\n }\n\n public function getFilenameSuffix(AutomatedReportResult $result): ?string\n {\n return match ($result->getMediaType()) {\n self::MEDIA_TYPE_PODCAST => 'Podcast',\n default => null,\n };\n }\n\n public function getMailSubjectSuffix(AutomatedReportResult $result): string\n {\n return match ($result->getMediaType()) {\n self::MEDIA_TYPE_PDF => 'report',\n self::MEDIA_TYPE_PODCAST => 'podcast',\n default => '',\n };\n }\n\n public function getMediaTypeMetadata(AutomatedReportResult $result): array\n {\n return match ($result->getMediaType()) {\n self::MEDIA_TYPE_PODCAST => ['extension' => 'mp3', 'mime' => 'audio/mpeg'],\n self::MEDIA_TYPE_PDF => ['extension' => 'pdf', 'mime' => 'application/pdf'],\n default => ['extension' => null, 'mime' => null],\n };\n }\n\n public function deleteS3Files(AutomatedReportResult $result): void\n {\n $teamUuid = $result->getReport()->getTeam()->getUuid();\n $reportUuid = $result->getUuid();\n\n // delete all files for a report uuid no mather of pdf, podcast, or both\n // in case of both - the podcast files are linked to the pdf (parent) uuid\n // pdf and podcast date times should be close\n $path = sprintf('%s/%s/%s', $teamUuid, self::S3_DIR, $reportUuid);\n\n foreach (self::FILE_EXTENSIONS_VARIANTS as $extension) {\n $file = $path . '.' . $extension;\n\n if (Storage::exists($file)) {\n Storage::delete($file);\n Log::info('[Reports] Deleted S3 file', [\n 'path' => $file,\n ]);\n }\n }\n\n foreach (self::FILE_PODCAST_EXTENSIONS_VARIANTS as $extension) {\n $file = $path . '_podcast.' . $extension;\n\n if (Storage::exists($file)) {\n Storage::delete($file);\n Log::info('[Reports] Deleted Podcast S3 file', [\n 'path' => $file,\n ]);\n }\n }\n }\n\n /**\n *\n * @param int|null $teamId Optional team ID to filter results\n *\n * @return Collection<int, int> Collection of team IDs\n */\n public function getTeamIdsWithReportsResults(?int $teamId = null): Collection\n {\n return $this->automatedReportsRepository->getTeamIdsWithReportsResults($teamId);\n }\n\n /**\n * Core delete logic for report results using a query\n *\n * @param Builder $query\n * @param array $logContext\n *\n * @return int\n */\n private function deleteReportResultsByQuery(Builder $query, array $logContext = []): int\n {\n $deletedCount = 0;\n\n if ($query->exists()) {\n Log::info(\n 'Run delete report results',\n array_merge(\n $logContext,\n [\n 'service' => 'AutomatedReportsService',\n ]\n )\n );\n\n $query->chunkById(50, function ($results) use (&$deletedCount, $logContext) {\n foreach ($results as $result) {\n $this->deleteReportResult($result);\n $deletedCount++;\n\n Log::info(\n 'Deleted a report result',\n array_merge(\n $logContext,\n [\n 'result_id' => $result->getId(),\n 'report_id' => $result->getReportId(),\n ]\n )\n );\n }\n });\n }\n\n return $deletedCount;\n }\n\n /**\n * Delete report results for a team by retention period\n *\n * @param Team $team\n * @param CarbonImmutable $retentionDate\n *\n * @return int Number of deleted report results\n */\n public function deleteReportsResultsInRetentionPeriod(Team $team, CarbonImmutable $retentionDate): int\n {\n $reportIds = $this->automatedReportsRepository->getReportIdsByTeam($team);\n\n if ($reportIds->isEmpty()) {\n return 0;\n }\n\n $query = $this->automatedReportsRepository\n ->getReportResultsQueryForRetention($team, $retentionDate);\n\n return $this->deleteReportResultsByQuery($query, [\n 'team_id' => $team->getId(),\n 'retention_date' => $retentionDate->toDateTimeString(),\n ]);\n }\n\n /**\n * Delete ALL report results for a specific automated report\n *\n * @param string $uuid\n *\n * @return int\n */\n public function deleteReportResults(string $uuid): int\n {\n $report = $this->getReport($uuid);\n\n $query = $this->automatedReportsRepository->getResultsByReportQuery($report);\n\n return $this->deleteReportResultsByQuery($query, [\n 'report_uuid' => $uuid,\n 'report_id' => $report->getId(),\n ]);\n }\n\n public function deleteReportResult(AutomatedReportResult $result): void\n {\n $this->deleteS3Files($result);\n\n $result->delete();\n }\n\n /**\n * Get all reports for a specific team\n *\n * @param Team $team\n *\n * @return \\Illuminate\\Database\\Eloquent\\Collection\n */\n public function getTeamReports(Team $team): \\Illuminate\\Database\\Eloquent\\Collection\n {\n return $this->automatedReportsRepository->getReportsByTeam($team);\n }\n\n /**\n * Get all report results for a specific report\n *\n * @param AutomatedReport $report\n *\n * @return \\Illuminate\\Database\\Eloquent\\Collection\n */\n public function getReportResults(AutomatedReport $report): \\Illuminate\\Database\\Eloquent\\Collection\n {\n return $this->automatedReportsRepository->getResultsByReport($report);\n }\n\n public function deleteAllReportResults(AutomatedReport $report): void\n {\n $results = $this->getReportResults($report);\n\n /** @var AutomatedReportResult $result */\n foreach ($results as $result) {\n Log::info('Deleting result', [\n 'report' => $report->getId(),\n 'result' => $result->getId(),\n ]);\n\n $this->deleteReportResult($result);\n }\n }\n\n public function deleteAllData(Team $team): void\n {\n Log::info('Deleting automated report and results for team', [\n 'team' => $team->getId(),\n ]);\n\n $reports = $this->getTeamReports($team);\n\n /** @var AutomatedReport $report */\n foreach ($reports as $report) {\n Log::info('Deleting report', [\n 'team' => $team->getId(),\n 'report' => $report->getId(),\n ]);\n\n $this->deleteAllReportResults($report);\n\n $report->delete();\n }\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":true,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"Project","depth":3,"role_description":"text"},{"role":"AXButton","text":"Project","depth":3,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"New File or Directory…","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Expand Selected","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Collapse All","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Options","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false}]...
|
3397592283435315795
|
6686367547760219213
|
visual_change
|
accessibility
|
NULL
|
Project: faVsco.js, menu
#11894 on JY-18909-automa Project: faVsco.js, menu
#11894 on JY-18909-automated-reports-ask-jiminny, menu
Start Listening for PHP Debug Connections
AutomatedReportsCommandTest
Run 'AutomatedReportsCommandTest'
Debug 'AutomatedReportsCommandTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Execute
Explain Plan
Browse Query History
View Parameters
Open Query Execution Settings…
In-Editor Results
Tx: Auto
Cancel Running Statements
Playground
jiminny
Sync Changes
Hide This Notification
Code changed:
Hide
16
13
13
Previous Highlighted Error
Next Highlighted Error
SELECT * FROM teams WHERE id = 1;
select * from crm_layouts where crm_configuration_id = 39;
SELECT * FROM crm_layout_entities WHERE crm_layout_id = 283;
SELECT * FROM crm_fields WHERE id = 2234;
SELECT * FROM crm_field_values WHERE crm_field_id = 2234;
select * from crm_profiles where user_id = 143;
select * from record_types where crm_configuration_id = 39; # 0121K000001MHElQAO,0121K000001MHEqQAO
select * from business_processes where crm_configuration_id = 39;
# 01941000000H669AAC, 01941000000H66JAAS
select * from record_type_field_values
where record_type_id IN (24);
select * from crm_field_values where id IN (2730);
select * from crm_configurations where id = 39;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 1
and sa.provider = 'salesforce'; #1035
select * from users where team_id = 1; # 222 group 3
SELECT * FROM activities WHERE user_id = 222 order by id desc;
select * from sidekick_settings where team_id = 1;
select * from teams where id = 1;
select * from team_features where team_id = 1;
select * from activities where crm_configuration_id = 2
and provider = 'ms-teams' and id = 608765;
SELECT * FROM activities WHERE crm_configuration_id = 2 and crm_provider_id = '59523413338';
select * from sidekick_settings where team_id = 2;
SELECT * FROM activities WHERE id = 608660;
select * from activity_summary_logs where activity_id = 608660;
select * from ai_prompts where transcription_id = 11214;
# [PASSWORD_DOTS]
SELECT * FROM activities WHERE uuid_to_bin('ed78a437-2804-450e-ab2f-56ab1c641346') = uuid;
# id: 608818, crm: 59628809737
SELECT * FROM activities WHERE uuid_to_bin('36b06e55-afdd-4782-8dee-c624cd0af191') = uuid;
# id: 608821, crm: 59632069252
SELECT ce.start_time, ce.end_time, a.id, a.uuid, crm_provider_id, calendar_event_id, title,
playbook_category_id, user_id, lead_id, contact_id, account_id, opportunity_id,
scheduled_start_time, scheduled_end_time, actual_start_time, actual_end_time, a.created_at
FROM activities a
join calendar_events ce on a.calendar_event_id = ce.id
WHERE a.id IN (608818, 608821);
select * from users where team_id = 1;
select * from team_settings where team_id = 1;
select * from crm_profiles where crm_configuration_id = 39 order by user_id;
select * from team_features where team_id = 1;
select * from users where team_id = 2;
SELECT * FROM activities WHERE uuid_to_bin('ec7647e9-5225-458b-b475-f31aa2769204') = uuid; # 612639
# Preslava N. Ivanova, grou id 3
SELECT * FROM opportunities WHERE uuid_to_bin('a2928fe5-aec5-46cb-85d9-7654c89e46a6') = uuid;
select * from activities where opportunity_id = 344 and actual_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00';
select
a.id,
a.type,
a.scheduled_start_time,
a.actual_start_time,
a.created_at,
a.opportunity_id,
a.status
FROM activities a
WHERE opportunity_id = 344
and status IN ('completed', 'received', 'delivered')
and (
(a.actual_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00')
OR (a.created_at between '2024-10-11 00:00:00' and '2024-10-12 00:00:00')
OR (a.scheduled_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00'))
;
SELECT * FROM users WHERE id = 222;
SELECT * FROM crm_profiles WHERE user_id = 222;
select * from crm_layouts where crm_configuration_id = 39;
SELECT * FROM crm_layout_entities WHERE crm_layout_id = 281;
select * from group_deal_risk_types;
select * from opportunities where team_id = 1;
SELECT * FROM opportunities WHERE id = 315;
SELECT * FROM crm_field_data WHERE object_id = 315;
select * from crm_field_data where object_id = 260;
select * from generic_ai_prompts where subject_id = 315;
select * from teams; # 36, 21, 121, [EMAIL]
SELECT * FROM social_accounts WHERE sociable_id = 121 and provider = 'bullhorn';
# [PASSWORD_DOTS]
select * from teams where id = 1;
select * from crm_configurations where id = 39;
select * from users where team_id = 1;
select u.email, cp.* from users u
join crm_profiles cp on u.id = cp.user_id
where u.team_id = 1;
# 1 - 00541000004281rAAA
# 204 - 0052g000003freeAAA
# 429 - 0052g000003qGOiAAM
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 1
and sa.provider = 'salesforce';
select * from activities where type = 'softphone'
and created_at > '2024-12-11 15:24:36' order by id desc;
select * from activity_providers where team_id = 1;
select * from activity_provider_users where activity_provider_id = 328;
select * from opportunities where crm_configuration_id = 39
AND account_id = 178 AND is_closed = false
order by created_at DESC;
select * from contacts where id = 3952;
select * from accounts where id = 178;
# [PASSWORD_DOTS]
select * from teams where id = 36;
select * from crm_configurations where id = 21;
select * from users where team_id = 36;
select u.email, cp.* from users u
join crm_profiles cp on u.id = cp.user_id
where u.team_id = 36;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 36
and sa.provider = 'bullhorn';
select * from social_accounts where id = 348;
UPDATE social_accounts SET
provider_user_token = '21442_6802599_91:41179a58-21e7-4d7c-ad58-56bb666b2f65',
provider_refresh_token = '21442_6802599_91:01c6b335-3f2a-42e4-85ff-8a08fa65fceb',
expires = 1733998131,
state = 'connected'
WHERE id = 348;
# [PASSWORD_DOTS]
select * from teams where id = 31;
select * from crm_configurations where id = 18;
select * from users where team_id = 31; # 257
select u.email, cp.* from users u
join crm_profiles cp on u.id = cp.user_id
where u.team_id = 31;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 31
and sa.provider = 'close';
select * from contacts where crm_configuration_id = 18;
# [PASSWORD_DOTS] NEPTUNE [PASSWORD_DOTS]
select * from teams;
select * from users where id IN (1030, 1035, 1052);
select * from crm_configurations;
select * from users where team_id = 65; # 257
select * from team_settings where team_id = 65; # 257
select * from invitations where team_id = 65; # 257
select * from users where email = '[EMAIL]'; # 257
select u.email, cp.* from users u
join crm_profiles cp on u.id = cp.user_id
where u.team_id = 65;
select * from crm_configurations where id = 53;
select * from accounts where crm_configuration_id = 53 order by id desc;
select * from leads where crm_configuration_id = 53 order by id desc;
select * from contacts where crm_configuration_id = 53 order by id desc;
select * from opportunities where crm_configuration_id = 53 order by id desc;
select * from crm_profiles where crm_configuration_id = 53 order by id desc;
select * from crm_fields where crm_configuration_id = 53 order by id desc;
select * from crm_field_values where crm_field_id = 3341 order by id desc;
select * from crm_layouts where crm_configuration_id = 53 order by id desc;
select * from stages where crm_configuration_id = 53 order by id desc;
select * from crm_profiles where crm_configuration_id = 13;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 65
and sa.provider = 'integration-app';
select * from contacts where crm_configuration_id = 13;
select * from social_accounts where sociable_id = 283;
SELECT * FROM opportunities WHERE crm_provider_id = '006O400000E9bzeIAB';
select * from activity_providers where team_id = 65;
SELECT * FROM activities WHERE crm_configuration_id IN (51, 52, 53);
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 65
;
# [PASSWORD_DOTS] STAGING [PASSWORD_DOTS]
SELECT * FROM teams;
SELECT * FROM teams WHERE id = 88;
SELECT * FROM teams WHERE id = 89;
select * from team_settings where team_id = 89;
SELECT * FROM users WHERE team_id = 89;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 89;
select * from users;
SELECT * FROM social_accounts WHERE sociable_id = 1761;
SELECT * FROM crm_configurations WHERE id = 70;
select * from accounts where crm_configuration_id = 70 order by id desc;
select * from leads where crm_configuration_id = 70 order by id desc;
select * from contacts where crm_configuration_id = 70 order by id desc;
select * from opportunities where crm_configuration_id = 70 order by id desc;
select * from crm_profiles where crm_configuration_id = 70 order by id desc;
select * from crm_fields where crm_configuration_id = 70 order by id desc;
select * from crm_field_values where crm_field_id = 3536 order by id desc;
select * from crm_layouts where crm_configuration_id = 70 order by id desc;
select * from stages where crm_configuration_id = 70 order by id desc;
select * from business_processes where crm_configuration_id = 70 order by id desc;
select * from business_process_stages where business_process_id = 34;
select * from contacts where id = 10468;
select * from crm_layouts where crm_configuration_id = 70;
SELECT * FROM crm_layout_entities WHERE crm_layout_id = 388;
SELECT * FROM crm_fields WHERE id IN (3533,3534,3535);
select * from activities where crm_configuration_id = 70
and (account_id IS NOT NULL or lead_id IS NOT NULL or contact_id IS NOT NULL or opportunity_id IS NOT NULL) order by id desc;
SELECT * FROM activities WHERE uuid_to_bin('2e10b60f-8a61-41c5-a3d4-28835353dc65') = uuid;
SELECT * FROM activities where crm_configuration_id = 69 ;
SELECT * FROM users WHERE email LIKE '%[EMAIL]%';
SELECT * FROM activities WHERE uuid_to_bin('5a150c93-40fc-42ec-b3bd-c1d328e09f6e') = uuid;
SELECT * FROM opportunities WHERE id = 385;
select * from participants p
join activities a on p.activity_id = a.id
where a.crm_configuration_id = 70
and (p.lead_id IS NOT NULL or p.contact_id IS NOT NULL);
SELECT * FROM participants WHERE id = 1013638;
select * from teams where id = 90;
select * from users where team_id = 90;
select * from social_accounts where social_accounts.sociable_id IN (1960,1760);
SELECT * FROM crm_profiles WHERE crm_configuration_id = 71;
select * from invitations where team_id = 90;
select * from crm_configurations where id = 71;
select * from accounts where crm_configuration_id = 71 order by id desc;
select * from leads where crm_configuration_id = 71 order by id desc;
select * from contacts where crm_configuration_id = 71 order by id desc;
select * from opportunities where crm_configuration_id = 71 order by id desc;
select * from crm_profiles where crm_configuration_id = 71 order by id desc;
select * from crm_fields where crm_configuration_id = 71 order by id desc;
select * from crm_field_values where crm_field_id = 3341 order by id desc;
select * from crm_layouts where crm_configuration_id = 71 order by id desc;
select * from stages where crm_configuration_id = 71 order by id desc;
select * from users order by secondary_email desc;
select u.id, u.email, u.status, sa.id, sa.provider_user_id from social_accounts sa
join users u on sa.sociable_id = u.id
where sa.provider = 'google' and u.email LIKE 'aneliya%';
select * from failed_jobs order by id desc;
select * from users where email = '[EMAIL]' or secondary_email = '[EMAIL]';
select * from teams;
SELECT * FROM crm_profiles WHERE crm_configuration_id = 39;
SELECT * FROM crm_fields WHERE crm_configuration_id = 39 and object_type = 'task';
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 1
and sa.provider = 'salesforce';
# [PASSWORD_DOTS]
SELECT * FROM activities WHERE uuid_to_bin('c38b3895-fd0f-4b1f-9fb2-c170dba137c6') = uuid;
SELECT * FROM crm_configurations WHERE id = 70;
select * from teams where id = 1;
select * from groups where team_id = 1;
select * from users where team_id = 1;
select o.id, o.name,o.close_date, u.id, u.name, u.group_id, r.id, r.display_name, g.name, g.scope from opportunities o
join users u on o.user_id = u.id
join groups g on u.group_id = g.id
join role_user ru on u.id = ru.user_id
join roles r on ru.role_id = r.id
where o.crm_configuration_id = 39 and close_date > '2024-01-01 00:00:00';
select * from role_user where user_id = 143;
select * from roles;
select * from role_user;
select * from groups where id = 9;
select * from scope_groups where group_id = 9;
# [PASSWORD_DOTS]
select * from teams where id = 36;
select * from crm_configurations;
SELECT * FROM social_accounts WHERE sociable_id = 121;
[URL_WITH_CREDENTIALS] this will add filter, however if we need to control feature by FF we need conditional logic
public const array TYPES = [
['id' => 'exec_summary', 'name' => 'Exec Summary'],
['id' => 'coaching_profiles', 'name' => 'Coaching Profiles'],
['id' => 'product_feedback', 'name' => 'Product Feedback'],
['id' => self::TYPE_LOSS_ANALYSIS, 'name' => 'Loss Analysis'],
// ['id' => 'questions', 'name' => 'Questions'],
// ['id' => 'statistical_quant', 'name' => 'Statistical Quantitative'],
];
public const array ALL_TYPES = [
...self::TYPES,
['id' => self::TYPE_ASK_JIMINNY, 'name' => 'Ask Jiminny'],
];
public const string FREQUENCY_DAILY = 'daily';
public const string FREQUENCY_WEEKLY = 'weekly';
public const string FREQUENCY_MONTHLY = 'monthly';
public const string FREQUENCY_QUARTERLY = 'quarterly';
public const string FREQUENCY_ONE_OFF = 'one_off';
/**
* Frequencies for standard (non-Ask Jiminny) reports.
*/
public const array FREQUENCIES = [
['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],
['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],
['id' => self::FREQUENCY_QUARTERLY, 'name' => 'Quarterly'],
['id' => self::FREQUENCY_ONE_OFF, 'name' => 'One-off'],
];
/**
* Frequencies for Ask Jiminny reports.
*/
public const array ASK_JIMINNY_FREQUENCIES = [
['id' => self::FREQUENCY_DAILY, 'name' => 'Daily'],
['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],
['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],
];
public const string MEDIA_TYPE_PDF = 'pdf';
public const string MEDIA_TYPE_PODCAST = 'podcast';
public const array MEDIA_TYPES = [self::MEDIA_TYPE_PDF, self::MEDIA_TYPE_PODCAST];
public const array MEDIA_TYPE_OBJECT_PDF = ['id' => self::MEDIA_TYPE_PDF, 'name' => 'PDF'];
public const array MEDIA_TYPE_OBJECT_PODCAST = ['id' => self::MEDIA_TYPE_PODCAST, 'name' => 'Podcast'];
public const array MEDIA_TYPE_OBJECTS = [self::MEDIA_TYPE_OBJECT_PDF, self::MEDIA_TYPE_OBJECT_PODCAST];
public const array CALL_TYPE_CONFERENCE = ['id' => 'conference', 'name' => 'Conference'];
public const array CALL_TYPE_DIALER = ['id' => 'dialer', 'name' => 'Dialer'];
public const int SENT_REPORT_AT_HOURS = 5;
public const string PDF_KEY = 'pdf';
public const string AUDIO_KEY = 'audio';
private const array ALL_FREQUENCIES = [
['id' => self::FREQUENCY_DAILY, 'name' => 'Daily'],
['id' => self::FREQUENCY_WEEKLY, 'name' => 'Weekly'],
['id' => self::FREQUENCY_MONTHLY, 'name' => 'Monthly'],
['id' => self::FREQUENCY_QUARTERLY, 'name' => 'Quarterly'],
['id' => self::FREQUENCY_ONE_OFF, 'name' => 'One-off'],
];
private const string S3_DIR = 'reports';
private const array FILE_EXTENSIONS_VARIANTS = ['html', 'MD', 'pdf'];
private const array FILE_PODCAST_EXTENSIONS_VARIANTS = ['json', 'mp3', 'ssml'];
public function __construct(
private readonly TeamRepository $teamRepository,
private readonly GroupRepository $groupRepository,
private readonly UserRepository $userRepository,
private readonly StageRepository $stageRepository,
private readonly DealStagesService $dealStagesService,
private readonly RecipientsService $recipientsService,
private readonly AutomatedReportsRepository $automatedReportsRepository,
private readonly Webhook $webhookService,
private readonly BusDispatcher $dispatcher,
private readonly ActivityTypeService $activityTypeService,
private readonly PlaybookCategoryRepository $playbookCategoryRepository,
private readonly AskAnythingPromptService $askAnythingPromptService,
private readonly SearchRepository $activitySearchRepository,
private readonly AskAnythingRepository $askAnythingRepository,
) {
}
public static function getTypes(): array
{
$types = self::TYPES;
return array_map(static function ($type) {
return $type['id'];
}, $types);
}
public static function getCallTypes(): array
{
return array_map(static function ($callType) {
return $callType['id'];
}, [self::CALL_TYPE_CONFERENCE, self::CALL_TYPE_DIALER]);
}
public static function getFrequencies(): array
{
return array_map(static function ($frequency) {
return $frequency['id'];
}, self::FREQUENCIES);
}
// front-facing structure
public function getReportEnabledFieldData(bool $value = false): array
{
return [
'id' => 'report_enabled',
'label' => '',
'inputType' => InputTypeEnum::TOGGLE,
'value' => $value,
];
}
// Organizations = Teams
public function getOrganizationFieldData(?string $value = null, bool $shortVersion = false): array
{
$options = $this->getTeams();
if ($shortVersion) {
return [
'id' => 'organization',
'label' => 'Organization',
'options' => $options,
];
}
return [
'id' => 'organization',
'label' => 'Organization',
'inputType' => InputTypeEnum::DROPDOWN,
'required' => true,
'placeholder' => 'Select',
'options' => $options,
'value' => $value,
'dependencies' => [
'teams',
'deal_stage_at_call',
'current_deal_stage',
'recipients',
ActivityTypeService::PLAYBOOK_CATEGORIES_KEY,
],
'dependsOn' => [],
];
}
// Teams = Groups
public function getTeamFieldData(array $options = [], array $value = [], bool $shortVersion = false): array
{
if ($shortVersion) {
return [
'id' => 'teams',
'label' => 'Team',
'options' => $options,
];
}
return [
'id' => 'teams',
'label' => 'Team',
'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,
'required' => false,
'placeholder' => 'Select',
'options' => $options,
'value' => $value, // value should be an array of objects {id, name}
'dependencies' => [ActivityTypeService::PLAYBOOK_CATEGORIES_KEY],
'dependsOn' => [],
];
}
public function getReportTypeFieldData(?string $value = null, bool $shortVersion = false, ?Team $team = null): array
{
$types = [];
if ($team instanceof Team) {
if ($team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {
$types = self::TYPES;
}
if ($team->hasFeature(FeatureEnum::ASK_JIMINNY_REPORTS)) {
$types[] = ['id' => self::TYPE_ASK_JIMINNY, 'name' => 'Ask Jiminny'];
}
} else {
$types = self::TYPES;
}
if ($shortVersion) {
return [
'id' => 'report_type',
'label' => 'Report Type',
'options' => $types,
];
}
return [
'id' => 'report_type',
'label' => 'Report Type',
'inputType' => InputTypeEnum::DROPDOWN,
'required' => true,
'placeholder' => 'Select',
'options' => $types,
'value' => $value,
'dependencies' => [],
'dependsOn' => [],
];
}
public function getFrequencyFieldData(?string $value = null): array
{
return [
'id' => 'frequency',
'label' => 'Frequency',
'inputType' => InputTypeEnum::DROPDOWN,
'required' => true,
'placeholder' => 'Select',
'options' => self::FREQUENCIES,
'value' => $value,
'dependencies' => ['period'],
'dependsOn' => [],
];
}
public function getPeriodFieldData(?string $valueStartDate = null, ?string $valueEndDate = null): array
{
return [
'id' => 'period',
'label' => 'Select one-off period',
'inputType' => InputTypeEnum::DATE_RANGE,
'required' => true,
'placeholder' => 'Select',
'value' => ['startDate' => $valueStartDate, 'endDate' => $valueEndDate],
'queryParams' => [
'startDate' => 'start_date_period',
'endDate' => 'end_date_period',
],
'dependencies' => [],
'dependsOn' => ['frequency'],
];
}
public function getActivityTypesFieldData(?Team $team = null, array $value = [], array $teamsFilter = []): array
{
return $this->activityTypeService->getActivityTypeFieldData(team: $team, value: $value, groupIds: $teamsFilter);
}
public function getDealStageAtCallFieldData(?Team $team = null, array $value = []): array
{
return $this->dealStagesService->getDealStageAtCallFieldData(team: $team, value: $value);
}
public function getCurrentDealStageFieldData(?Team $team = null, array $value = []): array
{
return $this->dealStagesService->getCurrentDealStageFieldData(team: $team, value: $value);
}
public function getDealValueFieldData(?int $valueMin = null, ?int $valueMax = null): array
{
return [
'id' => 'deal_value',
'label' => 'Deal Value',
'inputType' => InputTypeEnum::INTEGER_RANGE,
'required' => false,
'value' => ['min' => $valueMin, 'max' => $valueMax],
'queryParams' => [
'min' => 'min_deal_value',
'max' => 'max_deal_value',
],
'dependencies' => [],
'dependsOn' => [],
];
}
public function getCallTypeFieldData(bool $conferenceOn = false, bool $dialerOn = false): array
{
$value = [];
$conferenceOn && $value[] = self::CALL_TYPE_CONFERENCE;
$dialerOn && $value[] = self::CALL_TYPE_DIALER;
return [
'id' => 'call_type',
'label' => 'Call Type',
'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,
'required' => true,
'options' => [
self::CALL_TYPE_CONFERENCE,
self::CALL_TYPE_DIALER,
],
'value' => $value,
'dependencies' => [],
'dependsOn' => [],
];
}
public function getMediaTypeFieldData(?AutomatedReport $report = null): array
{
$value = [];
if ($report) {
$value = $this->transformMediaTypes($report);
}
return [
'id' => 'media_types',
'label' => 'Export as',
'inputType' => InputTypeEnum::DROPDOWN_MULTIPLE,
'required' => true,
'options' => self::MEDIA_TYPE_OBJECTS,
'value' => $value,
'dependencies' => [],
'dependsOn' => [],
];
}
public function getCallDurationFieldData(?int $valueMin = null, ?int $valueMax = null): array
{
return [
'id' => 'call_duration',
'label' => 'Call Duration',
'inputType' => InputTypeEnum::INTEGER_RANGE,
'required' => false,
'value' => ['min' => $valueMin, 'max' => $valueMax],
'queryParams' => [
'min' => 'min_call_duration',
'max' => 'max_call_duration',
],
'dependencies' => [],
'dependsOn' => [],
];
}
public function getRecipientsFieldData(?Team $team = null, array $value = []): array
{
return $this->recipientsService->getRecipientsFieldData(team: $team, value: $value);
}
public function getJiminnyRecipientsFieldData(array $value = []): array
{
return $this->recipientsService->getJiminnyRecipientsFieldData($value);
}
public function getAdditionalPromptInputFieldData(?string $value = null): array
{
return [
'id' => 'additional_prompt_input',
'label' => 'Special requirements',
'inputType' => InputTypeEnum::TEXTAREA,
'required' => false,
'placeholder' => 'What should be the focus of the report?',
'value' => $value,
'dependencies' => [],
'dependsOn' => [],
];
}
public function getCustomReportNameFieldData(?string $value = null): array
{
return [
'id' => 'custom_name',
'label' => 'Custom report name',
'inputType' => InputTypeEnum::TEXT,
'required' => false,
'placeholder' => 'Enter custom name',
'value' => $value,
'dependencies' => [],
'dependsOn' => [],
];
}
// data providers
public function getTeams(): array
{
$teams = $this->teamRepository->getTeamsForKiosk(status: Team::STATUS_ACTIVE);
$teamData = [];
foreach ($teams as $team) {
if (! $team->hasFeature(FeatureEnum::AUTOMATED_REPORTS)) {
continue;
}
$teamData[] = $this->transformTeam($team);
}
return $teamData;
}
public function getTeamGroups(string $teamUuid): array
{
$data = [];
$team = $this->getTeam($teamUuid);
if ($team !== null) {
$groups = $team->groups()->get();
foreach ($groups as $group) {
$data[] = [
'id' => $group->getUuid(),
'name' => $group->getName(),
];
}
}
return $data;
}
public function getTeamsGroupsOptions(array $filterTeamUuids = []): array
{
$data = [];
$teams = $this->getTeams();
foreach ($teams as $team) {
if (! empty($filterTeamUuids) && ! in_array($team['id'], $filterTeamUuids, true)) {
continue;
}
$data[] = [
'label' => $team['name'],
'groups' => $this->getTeamGroups($team['id']),
];
}
return $data;
}
public function getTeam(string $teamUuid): ?Team
{
return $this->teamRepository->idOrUuid($teamUuid);
}
public function getTeamById(int $teamId): ?Team
{
return $this->teamRepository->find($teamId);
}
public function getGroupsUuids(AutomatedReport $report): array
{
$uuids = [];
$reportGroups = $report->getGroups();
foreach ($reportGroups as $groupId) {
if ($group = $this->groupRepository->find($groupId)) {
$uuids[] = $group->getUuid();
}
}
return $uuids;
}
public function getPlaybookCategoriesUuids(AutomatedReport $report): array
{
$uuids = [];
$playbookCategories = $report->getPlaybookCategories();
foreach ($playbookCategories as $id) {
if ($category = $this->playbookCategoryRepository->find($id)) {
$uuids[] = $category->getUuid();
}
}
return $uuids;
}
public function getDealAtCallStagesUuids(AutomatedReport $report): array
{
$uuids = [];
$reportStages = $report->getDealAtCallStages();
foreach ($reportStages as $id) {
if ($stage = $this->stageRepository->find($id)) {
$uuids[] = $stage->getUuid();
}
}
return $uuids;
}
public function getCurrentDealStagesUuids(AutomatedReport $report): array
{
$uuids = [];
$reportStages = $report->getCurrentDealStages();
foreach ($reportStages as $id) {
if ($stage = $this->stageRepository->find($id)) {
$uuids[] = $stage->getUuid();
}
}
return $uuids;
}
public function getUsersUuids(AutomatedReport $report): array
{
return $this->extractUserUuids($report->getRecipients());
}
public function getJiminnyUsersUuids(AutomatedReport $report): array
{
return $this->extractUserUuids($report->getJiminnyRecipients());
}
/**
* @param array<string, mixed> $recipients
*/
private function extractUserUuids(array $recipients): array
{
$userIds = $recipients['users'] ?? [];
return collect($userIds)
->map(fn ($id) => $this->userRepository->find((int) $id))
->filter()
->map(fn (UserContract $user) => $user->getUuid())
->values()
->all();
}
// get mail data
public function getRecipientUsers(AutomatedReport $report): array
{
return $this->buildRecipientUsers($report->getRecipients());
}
private function getJiminnyRecipientUsers(AutomatedReport $report): array
{
return $this->buildRecipientUsers($report->getJiminnyRecipients());
}
/**
* @param array<string, mixed> $recipients
*/
private function buildRecipientUsers(array $recipients): array
{
$userIds = $recipients['users'] ?? [];
return collect($userIds)
->map(fn ($id) => $this->userRepository->find((int) $id))
->filter()
->map(fn (UserContract $user) => [
'email' => $user->getEmailAddress(),
'name' => $user->getName(),
'timezone' => $user->getTimezone()->getName(),
])
->values()
->all();
}
public function getValidRecipientUsers(AutomatedReport $report, bool $includeJiminny = false): array
{
if ($report->isAskJiminnyReport()) {
$recipients = $this->resolveAskJiminnyRecipients($report);
} else {
$recipients = $this->getRecipientUsers($report);
if ($includeJiminny) {
$recipients = array_merge($recipients, $this->getJiminnyRecipientUsers($report));
}
}
$emails = [];
return array_values(array_filter(
$recipients,
static function ($recipient) use (&$emails) {
if (empty($recipient['email']) || in_array($recipient['email'], $emails, true)) {
return false;
}
$emails[] = $recipient['email'];
return true;
}
));
}
private function resolveAskJiminnyRecipients(AutomatedReport $report): array
{
$recipients = [];
$creator = $report->getCreator();
if ($creator !== null) {
$recipients[] = [
'email' => $creator->getEmailAddress(),
'name' => $creator->getName(),
'timezone' => $creator->getTimezone()->getName(),
];
}
return array_merge(
$recipients,
$this->buildRecipientUsers($report->getRecipients()),
$this->getGroupRecipientUsers($report),
);
}
private function getGroupRecipientUsers(AutomatedReport $report): array
{
$users = [];
foreach ($report->getGroups() as $groupId) {
$group = $this->groupRepository->find($groupId);
if ($group === null) {
continue;
}
foreach ($group->getMembers() as $member) {
$users[] = [
'email' => $member->getEmailAddress(),
'name' => $member->getName(),
'timezone' => $member->getTimezone()->getName(),
];
}
}
return $users;
}
public function getReportTypeName(AutomatedReportResult $report): string
{
$type = $report->getReport()->getType();
$getType = $this->transformReportType($type);
return $getType['name'];
}
public function getReportPeriodName(AutomatedReportResult $report): string
{
$from = $report->getFromDate();
$to = $report->getToDate();
$frequency = $report->getReport()->getFrequency();
if ($from === null || $to === null) {
if (! $report->getReport()->isAskJiminnyReport()) {
$invalidPeriod = $from === null ? 'from' : 'to';
throw new ApplicationException('Report period is invalid: ' . $invalidPeriod);
}
$period = $this->calculateFromAndToDatePeriod($frequency);
$from = $period['fromDate'];
$to = $period['toDate'];
}
return $this->formatReportPeriodName($frequency, $from, $to);
}
private function formatReportPeriodName(string $frequency, Carbon $from, Carbon $to): string
{
$fromYear = $from->format('Y');
$toYear = $to->format('Y');
$differentYears = $fromYear !== $toYear;
switch ($frequency) {
case self::FREQUENCY_DAILY:
return $from->format('j M Y');
case self::FREQUENCY_QUARTERLY:
// 'Jan-Mar 2025' or 'Nov 2024-Jan 2025' if years differ
$startMonth = $from->format('M');
$endMonth = $to->copy()->subMonth();
$endMonthName = $endMonth->format('M');
$endMonthYear = $endMonth->format('Y');
if ($differentYears) {
return "{$startMonth} {$fromYear} - {$endMonthName} {$endMonthYear}";
}
return "{$startMonth} - {$endMonthName} {$toYear}";
case self::FREQUENCY_MONTHLY:
// 'May 2025' - monthly reports are always within the same year
return $from->format('M Y');
case self::FREQUENCY_WEEKLY:
// '4 - 8 Aug 2025', '27 Oct - 3 Nov 2025', or '28 Dec 2024 - 3 Jan 2025' if years differ
$startDay = $from->format('j');
$endDay = $to->format('j');
$startMonth = $from->format('M');
$endMonth = $to->format('M');
if ($differentYears) {
return "{$startDay} {$startMonth} {$fromYear} - {$endDay} {$endMonth} {$toYear}";
}
if ($startMonth !== $endMonth) {
return "{$startDay} {$startMonth} - {$endDay} {$endMonth} {$toYear}";
}
return "{$startDay} - {$endDay} {$endMonth} {$toYear}";
case self::FREQUENCY_ONE_OFF:
// '2 May-31 May 2025' or '15 Dec 2024-15 Jan 2025' if years differ
$startDay = $from->format('j');
$startMonth = $from->format('M');
$endDay = $to->format('j');
$endMonth = $to->format('M');
// If same month and year, use a format like '2-31 May 2025'
if ($startMonth === $endMonth && ! $differentYears) {
return "{$startDay} - {$endDay} {$startMonth} {$toYear}";
}
// If different years, include both years
if ($differentYears) {
return "{$startDay} {$startMonth} {$fromYear} - {$endDay} {$endMonth} {$toYear}";
}
// Same year but different months
return "{$startDay} {$startMonth} - {$endDay} {$endMonth} {$toYear}";
default:
// Default format for unknown frequencies
return $from->format('j M Y') . ' - ' . $to->format('j M Y');
}
}
public function getReportTeamsName(AutomatedReportResult $report): string
{
$groups = $report->getGroups();
if (empty($groups)) {
return 'All';
}
// Get group names from repository
$groupNames = [];
foreach ($groups as $groupId) {
$group = $this->groupRepository->find($groupId);
if ($group) {
$groupNames[] = $group->getName();
}
}
if (count($groupNames) === 1) {
// Single team format
$teamsName = $groupNames[0];
} else {
// Multiple teams format
$teamsName = implode(', ', $groupNames);
}
return $teamsName;
}
public function getReportFileName(AutomatedReportResult $report): string
...
|
12377
|
|
12381
|
266
|
16
|
2026-04-14T11:16:52.452920+00:00
|
/Users/lukas/.screenpipe/data/data/2026-04-14/1776 /Users/lukas/.screenpipe/data/data/2026-04-14/1776165412452_m1.jpg...
|
NULL
|
NULL
|
1
|
NULL
|
monitor_1
|
NULL
|
NULL
|
NULL
|
NULL
|
SlackFileEdit ViewGoHistoryWindowHelpec2-userGDOCK SlackFileEdit ViewGoHistoryWindowHelpec2-userGDOCKER₴81DEV (docker)882APP (-zsh)[EMAIL]@73b64f5d54a3:/home/jiminny#[ec2-user@ip-10-30-93-249~]$ dockerexec -it $(dockny && bash"root@c78a087b1345:/home/Jiminny# php artisan automated-reports[2026-04-14 10:46:08] staging.INF0: [automated-reports] Started{"correlation_id":"5[2026-04-1410:46:08Jstaging. INFO: [automated-reports]id":"5c23e861-2ca9-4f92-9f67-773d6bc80ca0"Checking conditions {"isMonda,"trace_id" :"185df6f6-4327-4609-9c2e-2ab83a[2026-04-14 10:46:08]staging.INFO: [automated-reports] Processing daily reports {"cab83a0f5432"}[2026-04-1410:46:08]9-9c2e-2ab83a0f5432"}staging.INFO: [automated-reports]Found 3 daily reports to proc[2026-04-1410:46:087daily"staging.INFO: [automated-reports]Dispatching Generate Report j,"type":"ask_jiminny"} {"correlation_id":"5c23e861-2ca9-4f92-9f67-773d6bc80ca0"[2026-04-14 10:46:08]staging.INFO: [automated-reports]Dispatching Generate Report jdaily", "type": "ask_jiminny"} {"correlation_id":"5c23e861-2ca9-4f92-9f67-773d6bc80cab"[2026-04-14 10:46:08]staging. INFO: [automated-reports]daily'", "type" "ask-fiminny"'} ("correlation-id' : 5c2se861-2ca -4792-9f87-773 Be8oca[2026-04-14 10:46:08]staging.INFO: [automated-reports]Completed{"correlation_id":root@c78a087b1345:/home/jiminny# phpartisanautomated-reports --report-id 35[2026-04-14 10:48:42] staging.INFO: [automated-reports]{"correlation_id":"2[2026-04-14 10:48:42]staging.INFO: [automated-reports]Checking conditions {"isMondaid":"246a1ala-7076-458c-bd7d-49d2f5a2db88","trace_id":"1f894bf6-e50d-4e99-b635-2aa526[2026-04-14 10:48:42]staging.INFO: [automated-reports]Processing daily reports{"caa52627fc27"}[automated-reports] Automated report[2026-04-14 10:48:42]staging.INFO: [automated-reports] Found 1 daily reports to proc9-b635-2aa52627f c27"}[2026-04-14 10:48:42]staging.INF0: [automated-reports]Dispatching Generate Report jdaily","type": "ask_jiminny"} {"correlation_id":"246a1a1a-7076-458c-bd7d-49d2f5a2db88"[2026-04-14 10:48:42]staging.INFO: [automated-reports]Completed{"correlation_id":root@c78a087b1345:/home/jiminny# [ec2-user@ip-10-30-93-249 ~]$I+EDHomeDMsActivityFilesLater.*•MoreallJiminny ...+tscnicrel# infra-changes# jiminny-bg# platform-tickets# product_launches# random# releases# sofia-office# support# thank-yous# the_people_of jimi...Direct messagesVasil VasilevAneliya Angelova, ...Steliyan Georgiev3Adelina Petrova, Ili...0. Adelina Petrova. Galya Dimitrova *&s Nikolay Nikolov "2 Galya Dimitrova, Ni...2Galya Dimitrova, Ni...P. Nikolay Yankov::: AppsJira CloudToastGoogle Cale...• Support Daily • in 44 m100% 147Tue 14 Apr 14:16:52→Search Jiminny Inc<Thread Direct message with 3 othersвчера, не днес• и имейл не дойдеimage.pngSOV• с в5 repliesLukas Kovalik 18 minutes agoза дата там не знам как искаме да го правим.по принцип при всички други се гледа ден назад при положение че идва през нощта.Nikolay Yankov 18 minutes ago@Lukas Kovalik видя ли този коментарLukas Kovalik 18 minutes agoдаNikolay Yankov 17 minutes agoне е ли датата на която е генерирано? (edited)Lukas Kovalik 17 minutes agoemail ще го видяReply...Also send to the group+•*•...
|
NULL
|
1965145393230217425
|
NULL
|
click
|
ocr
|
NULL
|
SlackFileEdit ViewGoHistoryWindowHelpec2-userGDOCK SlackFileEdit ViewGoHistoryWindowHelpec2-userGDOCKER₴81DEV (docker)882APP (-zsh)[EMAIL]@73b64f5d54a3:/home/jiminny#[ec2-user@ip-10-30-93-249~]$ dockerexec -it $(dockny && bash"root@c78a087b1345:/home/Jiminny# php artisan automated-reports[2026-04-14 10:46:08] staging.INF0: [automated-reports] Started{"correlation_id":"5[2026-04-1410:46:08Jstaging. INFO: [automated-reports]id":"5c23e861-2ca9-4f92-9f67-773d6bc80ca0"Checking conditions {"isMonda,"trace_id" :"185df6f6-4327-4609-9c2e-2ab83a[2026-04-14 10:46:08]staging.INFO: [automated-reports] Processing daily reports {"cab83a0f5432"}[2026-04-1410:46:08]9-9c2e-2ab83a0f5432"}staging.INFO: [automated-reports]Found 3 daily reports to proc[2026-04-1410:46:087daily"staging.INFO: [automated-reports]Dispatching Generate Report j,"type":"ask_jiminny"} {"correlation_id":"5c23e861-2ca9-4f92-9f67-773d6bc80ca0"[2026-04-14 10:46:08]staging.INFO: [automated-reports]Dispatching Generate Report jdaily", "type": "ask_jiminny"} {"correlation_id":"5c23e861-2ca9-4f92-9f67-773d6bc80cab"[2026-04-14 10:46:08]staging. INFO: [automated-reports]daily'", "type" "ask-fiminny"'} ("correlation-id' : 5c2se861-2ca -4792-9f87-773 Be8oca[2026-04-14 10:46:08]staging.INFO: [automated-reports]Completed{"correlation_id":root@c78a087b1345:/home/jiminny# phpartisanautomated-reports --report-id 35[2026-04-14 10:48:42] staging.INFO: [automated-reports]{"correlation_id":"2[2026-04-14 10:48:42]staging.INFO: [automated-reports]Checking conditions {"isMondaid":"246a1ala-7076-458c-bd7d-49d2f5a2db88","trace_id":"1f894bf6-e50d-4e99-b635-2aa526[2026-04-14 10:48:42]staging.INFO: [automated-reports]Processing daily reports{"caa52627fc27"}[automated-reports] Automated report[2026-04-14 10:48:42]staging.INFO: [automated-reports] Found 1 daily reports to proc9-b635-2aa52627f c27"}[2026-04-14 10:48:42]staging.INF0: [automated-reports]Dispatching Generate Report jdaily","type": "ask_jiminny"} {"correlation_id":"246a1a1a-7076-458c-bd7d-49d2f5a2db88"[2026-04-14 10:48:42]staging.INFO: [automated-reports]Completed{"correlation_id":root@c78a087b1345:/home/jiminny# [ec2-user@ip-10-30-93-249 ~]$I+EDHomeDMsActivityFilesLater.*•MoreallJiminny ...+tscnicrel# infra-changes# jiminny-bg# platform-tickets# product_launches# random# releases# sofia-office# support# thank-yous# the_people_of jimi...Direct messagesVasil VasilevAneliya Angelova, ...Steliyan Georgiev3Adelina Petrova, Ili...0. Adelina Petrova. Galya Dimitrova *&s Nikolay Nikolov "2 Galya Dimitrova, Ni...2Galya Dimitrova, Ni...P. Nikolay Yankov::: AppsJira CloudToastGoogle Cale...• Support Daily • in 44 m100% 147Tue 14 Apr 14:16:52→Search Jiminny Inc<Thread Direct message with 3 othersвчера, не днес• и имейл не дойдеimage.pngSOV• с в5 repliesLukas Kovalik 18 minutes agoза дата там не знам как искаме да го правим.по принцип при всички други се гледа ден назад при положение че идва през нощта.Nikolay Yankov 18 minutes ago@Lukas Kovalik видя ли този коментарLukas Kovalik 18 minutes agoдаNikolay Yankov 17 minutes agoне е ли датата на която е генерирано? (edited)Lukas Kovalik 17 minutes agoemail ще го видяReply...Also send to the group+•*•...
|
NULL
|
|
12383
|
266
|
17
|
2026-04-14T11:16:53.579534+00:00
|
/Users/lukas/.screenpipe/data/data/2026-04-14/1776 /Users/lukas/.screenpipe/data/data/2026-04-14/1776165413579_m1.jpg...
|
NULL
|
NULL
|
1
|
NULL
|
monitor_1
|
NULL
|
NULL
|
NULL
|
NULL
|
SlackFileEdit ViewGoHistoryWindowHelpec2-userGDOCK SlackFileEdit ViewGoHistoryWindowHelpec2-userGDOCKER981DEV (docker)882APP (-zsh)[EMAIL]@73b64f5d54a3:/home/jiminny#[ec2-user@ip-10-30-93-249~]$ dockerexec -it $(dockny && bash"root@c78a087b1345:/home/Jiminny# php artisan automated-reports[2026-04-14 10:46:08] staging.INF0: [automated-reports] Started{"correlation_id":"5[2026-04-1410:46:08Jstaging. INFO: [automated-reports]id":"5c23e861-2ca9-4f92-9f67-773d6bc80ca0"Checking conditions {"isMonda,"trace_id" :"185df6f6-4327-4609-9c2e-2ab83a[2026-04-14 10:46:08]staging.INFO: [automated-reports] Processing daily reports {"cab83a0f5432"}[2026-04-1410:46:08]9-9c2e-2ab83a0f5432"}staging.INFO: [automated-reports]Found 3 daily reports to proc[2026-04-1410:46:087daily"staging.INFO: [automated-reports]Dispatching Generate Report j,"type":"ask_jiminny"} {"correlation_id":"5c23e861-2ca9-4f92-9f67-773d6bc80ca0"[2026-04-14 10:46:08]staging.INFO: [automated-reports]Dispatching Generate Report jdaily", "type": "ask_jiminny"} {"correlation_id":"5c23e861-2ca9-4f92-9f67-773d6bc80cab"[2026-04-14 10:46:08]staging. INFO: [automated-reports]daily'", "type" "ask-fiminny"'} ("correlation-id' : 5c2se861-2ca -4792-9f87-773 Be8oca[2026-04-14 10:46:08]staging.INFO: [automated-reports]Completed{"correlation_id":root@c78a087b1345:/home/jiminny# phpartisanautomated-reports --report-id 35[2026-04-14 10:48:42] staging.INFO: [automated-reports]{"correlation_id":"2[2026-04-14 10:48:42]staging.INFO: [automated-reports]Checking conditions {"isMondaid":"246a1ala-7076-458c-bd7d-49d2f5a2db88","trace_id":"1f894bf6-e50d-4e99-b635-2aa526[2026-04-14 10:48:42]staging.INFO: [automated-reports]Processing daily reports{"caa52627fc27"}[automated-reports] Automated report[2026-04-14 10:48:42]staging.INFO: [automated-reports] Found 1 daily reports to proc9-b635-2aa52627f c27"}[2026-04-14 10:48:42]staging.INF0: [automated-reports]Dispatching Generate Report jdaily","type": "ask_jiminny"} {"correlation_id":"246a1a1a-7076-458c-bd7d-49d2f5a2db88"[2026-04-14 10:48:42]staging.INFO: [automated-reports]Completed{"correlation_id":root@c78a087b1345:/home/jiminny# [ec2-user@ip-10-30-93-249 ~]$I+EDHomeDMsActivityFilesLater.*•MoreallJiminny ...+tscnicrel# infra-changes# jiminny-bg# platform-tickets# product_launches# random# releases# sofia-office# support# thank-yous# the_people_of jimi...Direct messagesVasil VasilevAneliya Angelova, ...Steliyan Georgiev3Adelina Petrova, Ili...0. Adelina Petrova. Galya Dimitrova *&s Nikolay Nikolov "2 Galya Dimitrova, Ni...2Galya Dimitrova, Ni...P. Nikolay Yankov::: AppsJira CloudToastGoogle Cale...• Support Daily • in 44 m100% 147Tue 14 Apr 14:16:53→Search Jiminny Inc<Thread Direct message with 3 othersвчера, не днес• и имейл не дойдеimage.pngSOV• с в5 repliesLukas Kovalik 18 minutes agoза дата там не знам как искаме да го правим.по принцип при всички други се гледа ден назад при положение че идва през нощта.Nikolay Yankov 18 minutes ago@Lukas Kovalik видя ли този коментарLukas Kovalik 18 minutes agoдаNikolay Yankov 17 minutes agoне е ли датата на която е генерирано? (edited)Lukas Kovalik 17 minutes agoemail ще го видяReply...Also send to the group+•*•...
|
NULL
|
6744008788216802545
|
NULL
|
click
|
ocr
|
NULL
|
SlackFileEdit ViewGoHistoryWindowHelpec2-userGDOCK SlackFileEdit ViewGoHistoryWindowHelpec2-userGDOCKER981DEV (docker)882APP (-zsh)[EMAIL]@73b64f5d54a3:/home/jiminny#[ec2-user@ip-10-30-93-249~]$ dockerexec -it $(dockny && bash"root@c78a087b1345:/home/Jiminny# php artisan automated-reports[2026-04-14 10:46:08] staging.INF0: [automated-reports] Started{"correlation_id":"5[2026-04-1410:46:08Jstaging. INFO: [automated-reports]id":"5c23e861-2ca9-4f92-9f67-773d6bc80ca0"Checking conditions {"isMonda,"trace_id" :"185df6f6-4327-4609-9c2e-2ab83a[2026-04-14 10:46:08]staging.INFO: [automated-reports] Processing daily reports {"cab83a0f5432"}[2026-04-1410:46:08]9-9c2e-2ab83a0f5432"}staging.INFO: [automated-reports]Found 3 daily reports to proc[2026-04-1410:46:087daily"staging.INFO: [automated-reports]Dispatching Generate Report j,"type":"ask_jiminny"} {"correlation_id":"5c23e861-2ca9-4f92-9f67-773d6bc80ca0"[2026-04-14 10:46:08]staging.INFO: [automated-reports]Dispatching Generate Report jdaily", "type": "ask_jiminny"} {"correlation_id":"5c23e861-2ca9-4f92-9f67-773d6bc80cab"[2026-04-14 10:46:08]staging. INFO: [automated-reports]daily'", "type" "ask-fiminny"'} ("correlation-id' : 5c2se861-2ca -4792-9f87-773 Be8oca[2026-04-14 10:46:08]staging.INFO: [automated-reports]Completed{"correlation_id":root@c78a087b1345:/home/jiminny# phpartisanautomated-reports --report-id 35[2026-04-14 10:48:42] staging.INFO: [automated-reports]{"correlation_id":"2[2026-04-14 10:48:42]staging.INFO: [automated-reports]Checking conditions {"isMondaid":"246a1ala-7076-458c-bd7d-49d2f5a2db88","trace_id":"1f894bf6-e50d-4e99-b635-2aa526[2026-04-14 10:48:42]staging.INFO: [automated-reports]Processing daily reports{"caa52627fc27"}[automated-reports] Automated report[2026-04-14 10:48:42]staging.INFO: [automated-reports] Found 1 daily reports to proc9-b635-2aa52627f c27"}[2026-04-14 10:48:42]staging.INF0: [automated-reports]Dispatching Generate Report jdaily","type": "ask_jiminny"} {"correlation_id":"246a1a1a-7076-458c-bd7d-49d2f5a2db88"[2026-04-14 10:48:42]staging.INFO: [automated-reports]Completed{"correlation_id":root@c78a087b1345:/home/jiminny# [ec2-user@ip-10-30-93-249 ~]$I+EDHomeDMsActivityFilesLater.*•MoreallJiminny ...+tscnicrel# infra-changes# jiminny-bg# platform-tickets# product_launches# random# releases# sofia-office# support# thank-yous# the_people_of jimi...Direct messagesVasil VasilevAneliya Angelova, ...Steliyan Georgiev3Adelina Petrova, Ili...0. Adelina Petrova. Galya Dimitrova *&s Nikolay Nikolov "2 Galya Dimitrova, Ni...2Galya Dimitrova, Ni...P. Nikolay Yankov::: AppsJira CloudToastGoogle Cale...• Support Daily • in 44 m100% 147Tue 14 Apr 14:16:53→Search Jiminny Inc<Thread Direct message with 3 othersвчера, не днес• и имейл не дойдеimage.pngSOV• с в5 repliesLukas Kovalik 18 minutes agoза дата там не знам как искаме да го правим.по принцип при всички други се гледа ден назад при положение че идва през нощта.Nikolay Yankov 18 minutes ago@Lukas Kovalik видя ли този коментарLukas Kovalik 18 minutes agoдаNikolay Yankov 17 minutes agoне е ли датата на която е генерирано? (edited)Lukas Kovalik 17 minutes agoemail ще го видяReply...Also send to the group+•*•...
|
12381
|
|
12385
|
266
|
18
|
2026-04-14T11:16:59.587032+00:00
|
/Users/lukas/.screenpipe/data/data/2026-04-14/1776 /Users/lukas/.screenpipe/data/data/2026-04-14/1776165419587_m1.jpg...
|
PhpStorm
|
faVsco.js – AutomatedReportsCommand.php
|
1
|
NULL
|
monitor_1
|
NULL
|
NULL
|
NULL
|
NULL
|
Project: faVsco.js, menu
#11894 on JY-18909-automa Project: faVsco.js, menu
#11894 on JY-18909-automated-reports-ask-jiminny, menu
Start Listening for PHP Debug Connections
AutomatedReportsCommandTest
Run 'AutomatedReportsCommandTest'
Debug 'AutomatedReportsCommandTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Execute
Explain Plan
Browse Query History
View Parameters
Open Query Execution Settings…
In-Editor Results
Tx: Auto
Cancel Running Statements
Playground
jiminny
Sync Changes
Hide This Notification
Code changed:
Hide
16
13
13
Previous Highlighted Error
Next Highlighted Error
SELECT * FROM teams WHERE id = 1;
select * from crm_layouts where crm_configuration_id = 39;
SELECT * FROM crm_layout_entities WHERE crm_layout_id = 283;
SELECT * FROM crm_fields WHERE id = 2234;
SELECT * FROM crm_field_values WHERE crm_field_id = 2234;
select * from crm_profiles where user_id = 143;
select * from record_types where crm_configuration_id = 39; # 0121K000001MHElQAO,0121K000001MHEqQAO
select * from business_processes where crm_configuration_id = 39;
# 01941000000H669AAC, 01941000000H66JAAS
select * from record_type_field_values
where record_type_id IN (24);
select * from crm_field_values where id IN (2730);
select * from crm_configurations where id = 39;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 1
and sa.provider = 'salesforce'; #1035
select * from users where team_id = 1; # 222 group 3
SELECT * FROM activities WHERE user_id = 222 order by id desc;
select * from sidekick_settings where team_id = 1;
select * from teams where id = 1;
select * from team_features where team_id = 1;
select * from activities where crm_configuration_id = 2
and provider = 'ms-teams' and id = 608765;
SELECT * FROM activities WHERE crm_configuration_id = 2 and crm_provider_id = '59523413338';
select * from sidekick_settings where team_id = 2;
SELECT * FROM activities WHERE id = 608660;
select * from activity_summary_logs where activity_id = 608660;
select * from ai_prompts where transcription_id = 11214;
# [PASSWORD_DOTS]
SELECT * FROM activities WHERE uuid_to_bin('ed78a437-2804-450e-ab2f-56ab1c641346') = uuid;
# id: 608818, crm: 59628809737
SELECT * FROM activities WHERE uuid_to_bin('36b06e55-afdd-4782-8dee-c624cd0af191') = uuid;
# id: 608821, crm: 59632069252
SELECT ce.start_time, ce.end_time, a.id, a.uuid, crm_provider_id, calendar_event_id, title,
playbook_category_id, user_id, lead_id, contact_id, account_id, opportunity_id,
scheduled_start_time, scheduled_end_time, actual_start_time, actual_end_time, a.created_at
FROM activities a
join calendar_events ce on a.calendar_event_id = ce.id
WHERE a.id IN (608818, 608821);
select * from users where team_id = 1;
select * from team_settings where team_id = 1;
select * from crm_profiles where crm_configuration_id = 39 order by user_id;
select * from team_features where team_id = 1;
select * from users where team_id = 2;
SELECT * FROM activities WHERE uuid_to_bin('ec7647e9-5225-458b-b475-f31aa2769204') = uuid; # 612639
# Preslava N. Ivanova, grou id 3
SELECT * FROM opportunities WHERE uuid_to_bin('a2928fe5-aec5-46cb-85d9-7654c89e46a6') = uuid;
select * from activities where opportunity_id = 344 and actual_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00';
select
a.id,
a.type,
a.scheduled_start_time,
a.actual_start_time,
a.created_at,
a.opportunity_id,
a.status
FROM activities a
WHERE opportunity_id = 344
and status IN ('completed', 'received', 'delivered')
and (
(a.actual_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00')
OR (a.created_at between '2024-10-11 00:00:00' and '2024-10-12 00:00:00')
OR (a.scheduled_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00'))
;
SELECT * FROM users WHERE id = 222;
SELECT * FROM crm_profiles WHERE user_id = 222;
select * from crm_layouts where crm_configuration_id = 39;
SELECT * FROM crm_layout_entities WHERE crm_layout_id = 281;
select * from group_deal_risk_types;
select * from opportunities where team_id = 1;
SELECT * FROM opportunities WHERE id = 315;
SELECT * FROM crm_field_data WHERE object_id = 315;
select * from crm_field_data where object_id = 260;
select * from generic_ai_prompts where subject_id = 315;
select * from teams; # 36, 21, 121, [EMAIL]
SELECT * FROM social_accounts WHERE sociable_id = 121 and provider = 'bullhorn';
# [PASSWORD_DOTS]
select * from teams where id = 1;
select * from crm_configurations where id = 39;
select * from users where team_id = 1;
select u.email, cp.* from users u
join crm_profiles cp on u.id = cp.user_id
where u.team_id = 1;
# 1 - 00541000004281rAAA
# 204 - 0052g000003freeAAA
# 429 - 0052g000003qGOiAAM
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 1
and sa.provider = 'salesforce';
select * from activities where type = 'softphone'
and created_at > '2024-12-11 15:24:36' order by id desc;
select * from activity_providers where team_id = 1;
select * from activity_provider_users where activity_provider_id = 328;
select * from opportunities where crm_configuration_id = 39
AND account_id = 178 AND is_closed = false
order by created_at DESC;
select * from contacts where id = 3952;
select * from accounts where id = 178;
# [PASSWORD_DOTS]
select * from teams where id = 36;
select * from crm_configurations where id = 21;
select * from users where team_id = 36;
select u.email, cp.* from users u
join crm_profiles cp on u.id = cp.user_id
where u.team_id = 36;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 36
and sa.provider = 'bullhorn';
select * from social_accounts where id = 348;
UPDATE social_accounts SET
provider_user_token = '21442_6802599_91:41179a58-21e7-4d7c-ad58-56bb666b2f65',
provider_refresh_token = '21442_6802599_91:01c6b335-3f2a-42e4-85ff-8a08fa65fceb',
expires = 1733998131,
state = 'connected'
WHERE id = 348;
# [PASSWORD_DOTS]
select * from teams where id = 31;
select * from crm_configurations where id = 18;
select * from users where team_id = 31; # 257
select u.email, cp.* from users u
join crm_profiles cp on u.id = cp.user_id
where u.team_id = 31;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 31
and sa.provider = 'close';
select * from contacts where crm_configuration_id = 18;
# [PASSWORD_DOTS] NEPTUNE [PASSWORD_DOTS]
select * from teams;
select * from users where id IN (1030, 1035, 1052);
select * from crm_configurations;
select * from users where team_id = 65; # 257
select * from team_settings where team_id = 65; # 257
select * from invitations where team_id = 65; # 257
select * from users where email = '[EMAIL]'; # 257
select u.email, cp.* from users u
join crm_profiles cp on u.id = cp.user_id
where u.team_id = 65;
select * from crm_configurations where id = 53;
select * from accounts where crm_configuration_id = 53 order by id desc;
select * from leads where crm_configuration_id = 53 order by id desc;
select * from contacts where crm_configuration_id = 53 order by id desc;
select * from opportunities where crm_configuration_id = 53 order by id desc;
select * from crm_profiles where crm_configuration_id = 53 order by id desc;
select * from crm_fields where crm_configuration_id = 53 order by id desc;
select * from crm_field_values where crm_field_id = 3341 order by id desc;
select * from crm_layouts where crm_configuration_id = 53 order by id desc;
select * from stages where crm_configuration_id = 53 order by id desc;
select * from crm_profiles where crm_configuration_id = 13;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 65
and sa.provider = 'integration-app';
select * from contacts where crm_configuration_id = 13;
select * from social_accounts where sociable_id = 283;
SELECT * FROM opportunities WHERE crm_provider_id = '006O400000E9bzeIAB';
select * from activity_providers where team_id = 65;
SELECT * FROM activities WHERE crm_configuration_id IN (51, 52, 53);
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 65
;
# [PASSWORD_DOTS] STAGING [PASSWORD_DOTS]
SELECT * FROM teams;
SELECT * FROM teams WHERE id = 88;
SELECT * FROM teams WHERE id = 89;
select * from team_settings where team_id = 89;
SELECT * FROM users WHERE team_id = 89;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 89;
select * from users;
SELECT * FROM social_accounts WHERE sociable_id = 1761;
SELECT * FROM crm_configurations WHERE id = 70;
select * from accounts where crm_configuration_id = 70 order by id desc;
select * from leads where crm_configuration_id = 70 order by id desc;
select * from contacts where crm_configuration_id = 70 order by id desc;
select * from opportunities where crm_configuration_id = 70 order by id desc;
select * from crm_profiles where crm_configuration_id = 70 order by id desc;
select * from crm_fields where crm_configuration_id = 70 order by id desc;
select * from crm_field_values where crm_field_id = 3536 order by id desc;
select * from crm_layouts where crm_configuration_id = 70 order by id desc;
select * from stages where crm_configuration_id = 70 order by id desc;
select * from business_processes where crm_configuration_id = 70 order by id desc;
select * from business_process_stages where business_process_id = 34;
select * from contacts where id = 10468;
select * from crm_layouts where crm_configuration_id = 70;
SELECT * FROM crm_layout_entities WHERE crm_layout_id = 388;
SELECT * FROM crm_fields WHERE id IN (3533,3534,3535);
select * from activities where crm_configuration_id = 70
and (account_id IS NOT NULL or lead_id IS NOT NULL or contact_id IS NOT NULL or opportunity_id IS NOT NULL) order by id desc;
SELECT * FROM activities WHERE uuid_to_bin('2e10b60f-8a61-41c5-a3d4-28835353dc65') = uuid;
SELECT * FROM activities where crm_configuration_id = 69 ;
SELECT * FROM users WHERE email LIKE '%[EMAIL]%';
SELECT * FROM activities WHERE uuid_to_bin('5a150c93-40fc-42ec-b3bd-c1d328e09f6e') = uuid;
SELECT * FROM opportunities WHERE id = 385;
select * from participants p
join activities a on p.activity_id = a.id
where a.crm_configuration_id = 70
and (p.lead_id IS NOT NULL or p.contact_id IS NOT NULL);
SELECT * FROM participants WHERE id = 1013638;
select * from teams where id = 90;
select * from users where team_id = 90;
select * from social_accounts where social_accounts.sociable_id IN (1960,1760);
SELECT * FROM crm_profiles WHERE crm_configuration_id = 71;
select * from invitations where team_id = 90;
select * from crm_configurations where id = 71;
select * from accounts where crm_configuration_id = 71 order by id desc;
select * from leads where crm_configuration_id = 71 order by id desc;
select * from contacts where crm_configuration_id = 71 order by id desc;
select * from opportunities where crm_configuration_id = 71 order by id desc;
select * from crm_profiles where crm_configuration_id = 71 order by id desc;
select * from crm_fields where crm_configuration_id = 71 order by id desc;
select * from crm_field_values where crm_field_id = 3341 order by id desc;
select * from crm_layouts where crm_configuration_id = 71 order by id desc;
select * from stages where crm_configuration_id = 71 order by id desc;
select * from users order by secondary_email desc;
select u.id, u.email, u.status, sa.id, sa.provider_user_id from social_accounts sa
join users u on sa.sociable_id = u.id
where sa.provider = 'google' and u.email LIKE 'aneliya%';
select * from failed_jobs order by id desc;
select * from users where email = '[EMAIL]' or secondary_email = '[EMAIL]';
select * from teams;
SELECT * FROM crm_profiles WHERE crm_configuration_id = 39;
SELECT * FROM crm_fields WHERE crm_configuration_id = 39 and object_type = 'task';
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 1
and sa.provider = 'salesforce';
# [PASSWORD_DOTS]
SELECT * FROM activities WHERE uuid_to_bin('c38b3895-fd0f-4b1f-9fb2-c170dba137c6') = uuid;
SELECT * FROM crm_configurations WHERE id = 70;
select * from teams where id = 1;
select * from groups where team_id = 1;
select * from users where team_id = 1;
select o.id, o.name,o.close_date, u.id, u.name, u.group_id, r.id, r.display_name, g.name, g.scope from opportunities o
join users u on o.user_id = u.id
join groups g on u.group_id = g.id
join role_user ru on u.id = ru.user_id
join roles r on ru.role_id = r.id
where o.crm_configuration_id = 39 and close_date > '2024-01-01 00:00:00';
select * from role_user where user_id = 143;
select * from roles;
select * from role_user;
select * from groups where id = 9;
select * from scope_groups where group_id = 9;
# [PASSWORD_DOTS]
select * from teams where id = 36;
select * from crm_configurations;
SELECT * FROM social_accounts WHERE sociable_id = 121;
[URL_WITH_CREDENTIALS] string
*/
protected $signature = 'automated-reports
{--report-id= : Process a specific report by ID or UUID (bypasses frequency scheduling)}';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Process automated reports based on their frequency (weekly, monthly, quarterly).
Use --report-id to manually trigger a specific report by ID or UUID.';
public function __construct(
private readonly LoggerInterface $logger,
private readonly BusDispatcher $dispatcher,
private readonly AutomatedReportsRepository $reportRepository
) {
parent::__construct();
}
/**
* Execute the console command.
*
* @return int
*/
public function handle(): int
{
$this->logger->info(self::LOG_PREFIX . ' Started');
$now = Carbon::now();
$isMonday = $now->isMonday();
$isFirstDayOfMonth = $now->day === 1;
$currentMonth = $now->month;
// Check if the current month is a quarterly month (January, April, July, October)
$isQuarterlyMonth = in_array($currentMonth, [1, 4, 7, 10], true);
$this->logger->info(self::LOG_PREFIX . ' Checking conditions', [
'isMonday' => $isMonday,
'isFirstDayOfMonth' => $isFirstDayOfMonth,
'currentMonth' => $currentMonth,
'isQuarterlyMonth' => $isQuarterlyMonth,
]);
// Process daily reports
$this->processReports(AutomatedReportsService::FREQUENCY_DAILY);
// Process weekly reports on Mondays
if ($isMonday) {
$this->processReports(AutomatedReportsService::FREQUENCY_WEEKLY);
}
// Process monthly reports on the first day of the month
if ($isFirstDayOfMonth) {
$this->processReports(AutomatedReportsService::FREQUENCY_MONTHLY);
}
// Process quarterly reports on the first day of January, April, July, and October
if ($isFirstDayOfMonth && $isQuarterlyMonth) {
$this->processReports(AutomatedReportsService::FREQUENCY_QUARTERLY);
}
$this->logger->info(self::LOG_PREFIX . ' Completed');
return 0;
}
/**
* Process reports for a specific frequency.
*
* @param string $frequency
*
* @return void
*/
private function processReports(string $frequency): void
{
$this->logger->info(self::LOG_PREFIX . " Processing $frequency reports");
$reportId = $this->option('report-id');
if ($reportId !== null) {
$reports = $this->getReportById($reportId);
} else {
// Get all enabled, not deleted reports with active teams for the specified frequency
$reports = $this->reportRepository->getActiveReportsByFrequency($frequency);
}
$this->logger->info(self::LOG_PREFIX . " Found {$reports->count()} $frequency reports to process");
/** @var AutomatedReport $report */
foreach ($reports as $report) {
$this->logger->info(self::LOG_PREFIX . ' Dispatching Generate Report job for report', [
'reportUuid' => $report->getUuid(),
'teamId' => $report->getTeamId(),
'frequency' => $report->getFrequency(),
'type' => $report->getType(),
]);
$job = $report->isAskJiminnyReport()
? new RequestGenerateAskJiminnyReportJob($report->getUuid())
: new RequestGenerateReportJob($report->getUuid());
$this->dispatcher->dispatch($job);
}
}
private function getReportById(string $reportId): Collection
{
$report = $this->reportRepository->findByIdOrUuid($reportId);
if ($report === null) {
$this->logger->warning(self::LOG_PREFIX . ' Report not found for --report-id', ['reportId' => $reportId]);
$this->warn("Report not found: {$reportId}");
return collect();
}
if (! $report->getStatus()) {
$this->logger->warning(self::LOG_PREFIX . ' Report is inactive, processing anyway (manual override)', [
'reportId' => $reportId,
'reportUuid' => $report->getUuid(),
]);
$this->warn('Report is inactive — processing anyway (manual override).');
}
$team = $report->getTeam();
if ($team->getStatus() !== Team::STATUS_ACTIVE) {
$this->logger->warning(self::LOG_PREFIX . ' Team is not active, processing anyway (manual override)', [
'reportId' => $reportId,
'reportUuid' => $report->getUuid(),
'teamId' => $report->getTeamId(),
'teamStatus' => $team->getStatus(),
]);
$this->warn("Team #{$report->getTeamId()} is not active — processing anyway (manual override).");
}
if ($report->isExpired()) {
$this->logger->warning(self::LOG_PREFIX . ' Report is expired, processing anyway (manual override)', [
'reportId' => $reportId,
'reportUuid' => $report->getUuid(),
'expiresAt' => $report->getExpiresAt()?->toDateString(),
]);
$this->warn('Report is expired (expires_at: ' . $report->getExpiresAt()?->toDateString() . ') — processing anyway (manual override).');
}
$this->info(self::LOG_PREFIX . ' Automated report found ' . $report->getCustomName());
return collect([$report]);
}
}
Project
Project
New File or Directory…
Expand Selected
Collapse All
Options
Hide...
|
[{"role":"AXButton","text" [{"role":"AXButton","text":"Project: faVsco.js, menu","depth":5,"help_text":"~/jiminny/app","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"#11894 on JY-18909-automated-reports-ask-jiminny, menu","depth":5,"help_text":"Pull request #11894 exists for current branch JY-18909-automated-reports-ask-jiminny","role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Start Listening for PHP Debug Connections","depth":5,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"AutomatedReportsCommandTest","depth":6,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Run 'AutomatedReportsCommandTest'","depth":6,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Debug 'AutomatedReportsCommandTest'","depth":6,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"More Actions","depth":6,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"JetBrains AI","depth":5,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Search Everywhere","depth":5,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"IDE and Project Settings","depth":5,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Execute","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Explain Plan","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Browse Query History","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"View Parameters","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Open Query Execution Settings…","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"In-Editor Results","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Tx: Auto","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Cancel Running Statements","depth":4,"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Playground","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"jiminny","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.088194445,"height":0.027777778},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"16","depth":4,"role_description":"text"},{"role":"AXStaticText","text":"13","depth":4,"role_description":"text"},{"role":"AXStaticText","text":"13","depth":4,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"SELECT * FROM teams WHERE id = 1;\n\nselect * from crm_layouts where crm_configuration_id = 39;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 283;\nSELECT * FROM crm_fields WHERE id = 2234;\nSELECT * FROM crm_field_values WHERE crm_field_id = 2234;\n\nselect * from crm_profiles where user_id = 143;\n\nselect * from record_types where crm_configuration_id = 39; # 0121K000001MHElQAO,0121K000001MHEqQAO\nselect * from business_processes where crm_configuration_id = 39;\n# 01941000000H669AAC, 01941000000H66JAAS\n\nselect * from record_type_field_values\n where record_type_id IN (24);\n\nselect * from crm_field_values where id IN (2730);\n\nselect * from crm_configurations where id = 39;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 1\nand sa.provider = 'salesforce'; #1035\n\n\nselect * from users where team_id = 1; # 222 group 3\nSELECT * FROM activities WHERE user_id = 222 order by id desc;\nselect * from sidekick_settings where team_id = 1;\nselect * from teams where id = 1;\nselect * from team_features where team_id = 1;\n\nselect * from activities where crm_configuration_id = 2\nand provider = 'ms-teams' and id = 608765;\n\nSELECT * FROM activities WHERE crm_configuration_id = 2 and crm_provider_id = '59523413338';\n\nselect * from sidekick_settings where team_id = 2;\n\nSELECT * FROM activities WHERE id = 608660;\nselect * from activity_summary_logs where activity_id = 608660;\nselect * from ai_prompts where transcription_id = 11214;\n\n# ********************************************************************************************************\nSELECT * FROM activities WHERE uuid_to_bin('ed78a437-2804-450e-ab2f-56ab1c641346') = uuid;\n# id: 608818, crm: 59628809737\nSELECT * FROM activities WHERE uuid_to_bin('36b06e55-afdd-4782-8dee-c624cd0af191') = uuid;\n# id: 608821, crm: 59632069252\nSELECT ce.start_time, ce.end_time, a.id, a.uuid, crm_provider_id, calendar_event_id, title,\nplaybook_category_id, user_id, lead_id, contact_id, account_id, opportunity_id,\nscheduled_start_time, scheduled_end_time, actual_start_time, actual_end_time, a.created_at\nFROM activities a\njoin calendar_events ce on a.calendar_event_id = ce.id\nWHERE a.id IN (608818, 608821);\n\nselect * from users where team_id = 1;\nselect * from team_settings where team_id = 1;\nselect * from crm_profiles where crm_configuration_id = 39 order by user_id;\n\nselect * from team_features where team_id = 1;\n\nselect * from users where team_id = 2;\n\nSELECT * FROM activities WHERE uuid_to_bin('ec7647e9-5225-458b-b475-f31aa2769204') = uuid; # 612639\n# Preslava N. Ivanova, grou id 3\n\nSELECT * FROM opportunities WHERE uuid_to_bin('a2928fe5-aec5-46cb-85d9-7654c89e46a6') = uuid;\n\nselect * from activities where opportunity_id = 344 and actual_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00';\n\nselect\n a.id,\n a.type,\n a.scheduled_start_time,\n a.actual_start_time,\n a.created_at,\n a.opportunity_id,\n a.status\nFROM activities a\nWHERE opportunity_id = 344\nand status IN ('completed', 'received', 'delivered')\nand (\n (a.actual_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00')\nOR (a.created_at between '2024-10-11 00:00:00' and '2024-10-12 00:00:00')\nOR (a.scheduled_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00'))\n;\n\nSELECT * FROM users WHERE id = 222;\n\nSELECT * FROM crm_profiles WHERE user_id = 222;\nselect * from crm_layouts where crm_configuration_id = 39;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 281;\n\nselect * from group_deal_risk_types;\n\nselect * from opportunities where team_id = 1;\n\nSELECT * FROM opportunities WHERE id = 315;\nSELECT * FROM crm_field_data WHERE object_id = 315;\nselect * from crm_field_data where object_id = 260;\n\nselect * from generic_ai_prompts where subject_id = 315;\n\nselect * from teams; # 36, 21, 121, james.graham@bullhorn.jiminny.com\nSELECT * FROM social_accounts WHERE sociable_id = 121 and provider = 'bullhorn';\n\n# ************************************************************************************\nselect * from teams where id = 1;\nselect * from crm_configurations where id = 39;\nselect * from users where team_id = 1;\nselect u.email, cp.* from users u\njoin crm_profiles cp on u.id = cp.user_id\nwhere u.team_id = 1;\n# 1 - 00541000004281rAAA\n# 204 - 0052g000003freeAAA\n# 429 - 0052g000003qGOiAAM\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 1\nand sa.provider = 'salesforce';\n\nselect * from activities where type = 'softphone'\nand created_at > '2024-12-11 15:24:36' order by id desc;\n\nselect * from activity_providers where team_id = 1;\nselect * from activity_provider_users where activity_provider_id = 328;\n\nselect * from opportunities where crm_configuration_id = 39\nAND account_id = 178 AND is_closed = false\norder by created_at DESC;\n\nselect * from contacts where id = 3952;\nselect * from accounts where id = 178;\n\n# ************************************************************************************\nselect * from teams where id = 36;\nselect * from crm_configurations where id = 21;\nselect * from users where team_id = 36;\nselect u.email, cp.* from users u\njoin crm_profiles cp on u.id = cp.user_id\nwhere u.team_id = 36;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 36\nand sa.provider = 'bullhorn';\n\nselect * from social_accounts where id = 348;\nUPDATE social_accounts SET\nprovider_user_token = '21442_6802599_91:41179a58-21e7-4d7c-ad58-56bb666b2f65',\nprovider_refresh_token = '21442_6802599_91:01c6b335-3f2a-42e4-85ff-8a08fa65fceb',\nexpires = 1733998131,\nstate = 'connected'\nWHERE id = 348;\n\n# ************************************************************************************\nselect * from teams where id = 31;\nselect * from crm_configurations where id = 18;\n\nselect * from users where team_id = 31; # 257\nselect u.email, cp.* from users u\njoin crm_profiles cp on u.id = cp.user_id\nwhere u.team_id = 31;\n\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 31\nand sa.provider = 'close';\n\nselect * from contacts where crm_configuration_id = 18;\n\n# ********************** NEPTUNE **************************************************************\nselect * from teams;\nselect * from users where id IN (1030, 1035, 1052);\nselect * from crm_configurations;\n\nselect * from users where team_id = 65; # 257\nselect * from team_settings where team_id = 65; # 257\nselect * from invitations where team_id = 65; # 257\nselect * from users where email = 'integration-account@jiminny.com'; # 257\nselect u.email, cp.* from users u\njoin crm_profiles cp on u.id = cp.user_id\nwhere u.team_id = 65;\n\nselect * from crm_configurations where id = 53;\nselect * from accounts where crm_configuration_id = 53 order by id desc;\nselect * from leads where crm_configuration_id = 53 order by id desc;\nselect * from contacts where crm_configuration_id = 53 order by id desc;\nselect * from opportunities where crm_configuration_id = 53 order by id desc;\nselect * from crm_profiles where crm_configuration_id = 53 order by id desc;\nselect * from crm_fields where crm_configuration_id = 53 order by id desc;\nselect * from crm_field_values where crm_field_id = 3341 order by id desc;\nselect * from crm_layouts where crm_configuration_id = 53 order by id desc;\nselect * from stages where crm_configuration_id = 53 order by id desc;\n\n\nselect * from crm_profiles where crm_configuration_id = 13;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 65\nand sa.provider = 'integration-app';\n\nselect * from contacts where crm_configuration_id = 13;\n\nselect * from social_accounts where sociable_id = 283;\n\nSELECT * FROM opportunities WHERE crm_provider_id = '006O400000E9bzeIAB';\n\nselect * from activity_providers where team_id = 65;\nSELECT * FROM activities WHERE crm_configuration_id IN (51, 52, 53);\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 65\n;\n\n# ***************************** STAGING ********************************************\nSELECT * FROM teams;\nSELECT * FROM teams WHERE id = 88;\nSELECT * FROM teams WHERE id = 89;\nselect * from team_settings where team_id = 89;\nSELECT * FROM users WHERE team_id = 89;\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 89;\n\nselect * from users;\nSELECT * FROM social_accounts WHERE sociable_id = 1761;\nSELECT * FROM crm_configurations WHERE id = 70;\nselect * from accounts where crm_configuration_id = 70 order by id desc;\nselect * from leads where crm_configuration_id = 70 order by id desc;\nselect * from contacts where crm_configuration_id = 70 order by id desc;\nselect * from opportunities where crm_configuration_id = 70 order by id desc;\nselect * from crm_profiles where crm_configuration_id = 70 order by id desc;\nselect * from crm_fields where crm_configuration_id = 70 order by id desc;\nselect * from crm_field_values where crm_field_id = 3536 order by id desc;\nselect * from crm_layouts where crm_configuration_id = 70 order by id desc;\nselect * from stages where crm_configuration_id = 70 order by id desc;\nselect * from business_processes where crm_configuration_id = 70 order by id desc;\nselect * from business_process_stages where business_process_id = 34;\n\nselect * from contacts where id = 10468;\n\nselect * from crm_layouts where crm_configuration_id = 70;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 388;\nSELECT * FROM crm_fields WHERE id IN (3533,3534,3535);\n\nselect * from activities where crm_configuration_id = 70\nand (account_id IS NOT NULL or lead_id IS NOT NULL or contact_id IS NOT NULL or opportunity_id IS NOT NULL) order by id desc;\n\nSELECT * FROM activities WHERE uuid_to_bin('2e10b60f-8a61-41c5-a3d4-28835353dc65') = uuid;\nSELECT * FROM activities where crm_configuration_id = 69 ;\n\nSELECT * FROM users WHERE email LIKE '%jiminny_web_sa2@jiminny.com%';\nSELECT * FROM activities WHERE uuid_to_bin('5a150c93-40fc-42ec-b3bd-c1d328e09f6e') = uuid;\nSELECT * FROM opportunities WHERE id = 385;\n\nselect * from participants p\njoin activities a on p.activity_id = a.id\nwhere a.crm_configuration_id = 70\nand (p.lead_id IS NOT NULL or p.contact_id IS NOT NULL);\nSELECT * FROM participants WHERE id = 1013638;\n\nselect * from teams where id = 90;\nselect * from users where team_id = 90;\nselect * from social_accounts where social_accounts.sociable_id IN (1960,1760);\nSELECT * FROM crm_profiles WHERE crm_configuration_id = 71;\nselect * from invitations where team_id = 90;\n\nselect * from crm_configurations where id = 71;\nselect * from accounts where crm_configuration_id = 71 order by id desc;\nselect * from leads where crm_configuration_id = 71 order by id desc;\nselect * from contacts where crm_configuration_id = 71 order by id desc;\nselect * from opportunities where crm_configuration_id = 71 order by id desc;\nselect * from crm_profiles where crm_configuration_id = 71 order by id desc;\nselect * from crm_fields where crm_configuration_id = 71 order by id desc;\nselect * from crm_field_values where crm_field_id = 3341 order by id desc;\nselect * from crm_layouts where crm_configuration_id = 71 order by id desc;\nselect * from stages where crm_configuration_id = 71 order by id desc;\n\nselect * from users order by secondary_email desc;\nselect u.id, u.email, u.status, sa.id, sa.provider_user_id from social_accounts sa\n join users u on sa.sociable_id = u.id\nwhere sa.provider = 'google' and u.email LIKE 'aneliya%';\n\nselect * from failed_jobs order by id desc;\n\nselect * from users where email = 'ben.allwright@learningpeople.co.uk' or secondary_email = 'ben.allwright@learningpeople.co.uk';\n\nselect * from teams;\nSELECT * FROM crm_profiles WHERE crm_configuration_id = 39;\nSELECT * FROM crm_fields WHERE crm_configuration_id = 39 and object_type = 'task';\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 1\nand sa.provider = 'salesforce';\n\n# ************************************************************************************\nSELECT * FROM activities WHERE uuid_to_bin('c38b3895-fd0f-4b1f-9fb2-c170dba137c6') = uuid;\nSELECT * FROM crm_configurations WHERE id = 70;\n\nselect * from teams where id = 1;\nselect * from groups where team_id = 1;\nselect * from users where team_id = 1;\n\nselect o.id, o.name,o.close_date, u.id, u.name, u.group_id, r.id, r.display_name, g.name, g.scope from opportunities o\njoin users u on o.user_id = u.id\njoin groups g on u.group_id = g.id\njoin role_user ru on u.id = ru.user_id\njoin roles r on ru.role_id = r.id\nwhere o.crm_configuration_id = 39 and close_date > '2024-01-01 00:00:00';\n\nselect * from role_user where user_id = 143;\nselect * from roles;\n\nselect * from role_user;\nselect * from groups where id = 9;\nselect * from scope_groups where group_id = 9;\n\n# ************************************************************************************\nselect * from teams where id = 36;\nselect * from crm_configurations;\nSELECT * FROM social_accounts WHERE sociable_id = 121;\n\nhttps://crmsandbox.zoho.com/crm/jiminnyw4/tab/Leads/4776201000005049105\nhttps://crmsandbox.zoho.com/crm/\n\nhttps://crm.zoho.com/crm/org3469620/tab/Leads/230045000229559080\n https://crm.zoho.com/crm/\n org3469620\n\nSELECT * FROM activities WHERE uuid_to_bin('03382d20-c8bc-48e7-a3d4-90b52fa5ceab') = uuid;\n\nselect * from users where email LIKE \"%mobile_automation_%\";\nselect * from social_accounts where sociable_id IN (2228);\nselect * from crm_profiles where user_id IN (2222,2223,2226,2227);\n\nselect * from teams order by id desc;\nSELECT * FROM users WHERE id = 2229;\nSELECT * FROM crm_profiles WHERE user_id = 2229;\nselect * from opportunities where crm_configuration_id = 88;\nselect * from crm_fields where crm_configuration_id = 88;\nselect * from crm_profiles where crm_configuration_id = 88;\n\nSELECT * FROM teams WHERE id = 1;\n\nSELECT * FROM users WHERE id = 143;\nSELECT * FROM users WHERE uuid_to_bin('fde193d3-06a2-4e1a-8895-62b94039215d') = uuid;\nSELECT * FROM teams WHERE uuid_to_bin('73385071-a756-42ae-9c73-8b53f2309467') = uuid;\n\nhttps://app.staging.jiminny.com/ondemand?\n min_duration=1\n &\n only_recorded=1\n &\n user_id%5B%5D=641f1acb-16b8-42d1-8726-df52979dad0e\n &\n sequence_number=2\n\n select * from users where team_id = 1 and email like '%stoyan%'\n\nselect * from coaching_feedbacks;\n\nselect * from teams;\nSELECT * FROM users WHERE team_id = 36;\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 19\nand sa.provider = 'pipedrive';\n\nselect * from users where id = 143;\n\nSELECT * FROM users WHERE uuid_to_bin('73180eeb-33de-4065-977d-ccbe0e6c94fc') = uuid;\nSELECT * FROM teams WHERE uuid_to_bin('73180eeb-33de-4065-977d-ccbe0e6c94fc') = uuid;\nSELECT * FROM activity_shares WHERE uuid_to_bin('73180eeb-33de-4065-977d-ccbe0e6c94fc') = uuid;\n\nselect * from users where team_id = 2;\nselect * from activities where crm_configuration_id = 39\nand activities.scheduled_start_time BETWEEN '2025-04-09 00:00:00' AND '2025-04-09 23:59:59'\nAND user_id = 143\norder by id desc;\n\n# ************************************************************************************\nselect * from teams where id = 142; # 2312, 126\nselect * from team_settings;\nselect * from users where team_id = 142; # 21642\nSELECT * FROM social_accounts WHERE sociable_id = 21642;\nSELECT * FROM crm_profiles cp join users u ON u.id = cp.user_id WHERE team_id = 142;\nselect * from crm_profiles where id IN (93);\nselect * from invitations;\nselect * from team_features where team_id = 1;\n\nSELECT * FROM crm_configurations WHERE id = 126;\nselect * from accounts where crm_configuration_id = 126 order by id desc;\nselect * from leads where crm_configuration_id = 126 order by id desc;\nselect * from contacts where crm_configuration_id = 126 order by id desc;\nselect * from opportunities where crm_configuration_id = 126 order by id desc;\nselect * from crm_profiles where crm_configuration_id = 126 order by id desc;\nselect * from crm_fields where crm_configuration_id = 126 # 11060\n# and type IN ('picklist', 'status')\n# and object_type = 'task'\norder by id desc;\n# 5731,5732,5733\nselect DISTINCT crm_field_id from crm_field_values where crm_field_id IN (11151,12239,12215,12185,12175,12165,12144,12137,12127,12109,12107,12105,12103,12092,12037,12005,12003,11987,11969,11958,11951,11942,11931,11924,11921,11917,11915,11901,11893,11883,11872,11870,11868,11866,11839,11833,11821,11793,11780,11777,11769,11757,11737,11735,11656,11645,11638,11629,11618,11611,11602,11591,11584,11581,11558,11544,11543,11534,11532,11529,11527,11503,11497,11493,11488,11470,11468,11457,11455,11397,11387,11372,11363,11348,11323,11318,11309,11301,11300,11292,11290,11286,11284,11256,11252,11242,11237,11233,11219,11176,11160) order by id desc;\nselect * from crm_layouts where crm_configuration_id = 126 order by id desc;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id in (300,299,298);\nselect * from stages where crm_configuration_id = 126 order by id desc;\nselect * from business_processes where crm_configuration_id = 126 order by id desc;\nselect * from business_process_stages where business_process_id IN (76,75,74,73);\nselect * from playbooks where team_id = 142;\nselect * from playbook_layouts where playbook_id IN (108);\nSELECT * FROM playbook_categories WHERE playbook_id IN (108);\n\nselect * from teams where id = 130;\nSELECT * FROM social_accounts WHERE sociable_id = 2291;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 2\nand sa.provider = 'hubspot';\n\nSELECT * FROM activities\n WHERE crm_configuration_id = 110;\n\nselect * from teams;\nselect * from crm_configurations;\n\nSELECT * FROM activities WHERE id = 628773;\nSELECT * FROM crm_profiles WHERE user_id = 1460;\nSELECT * FROM social_accounts WHERE sociable_id = 2291;\n\nselect * from teams;\nselect ru.*, pr.*, p.* from users u join role_user ru on ru.user_id = u.id\njoin permission_role pr on pr.role_id = ru.role_id\n join permissions p on p.id = pr.permission_id\nwhere team_id = 495 and p.name IN ('dial');\n\nselect * from teams where id = 145;\nselect * from crm_configurations where id = 129;\nselect * from social_accounts where sociable_id = 2317;\nSELECT * FROM activities WHERE uuid_to_bin('8dbab184-a333-4268-ad57-fb41f8d53a9a') = uuid;\n\nselect * from teams where id = 1;\nSELECT * FROM crm_layouts WHERE crm_configuration_id = 39;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 280;\nSELECT * FROM crm_layout_entities WHERE id = 5507;\nSELECT * FROM crm_fields WHERE crm_configuration_id = 39 and object_type IN ('event');\n\nselect * from teams;\nselect * from activities where crm_configuration_id = 14;\n\nSELECT * FROM social_accounts where provider = 'copper';\n\nselect * from activities where id = 628467;\nselect * from participants where activity_id = 628467;\n\nSELECT * FROM contacts WHERE id = 3969;\nSELECT * FROM accounts WHERE id = 177;\n\nSELECT * FROM activities WHERE uuid_to_bin('4eb54c77-cfa3-2bd4-84a7-9ed46a21c988') = uuid;\n\n# ********************* BH\nselect * from teams where id = 36;\nSELECT * FROM crm_configurations WHERE id = 21;\nselect * from activities where crm_configuration_id = 21 and id = 607901;\nselect * from activities where crm_configuration_id = 21;\n\nselect * roles;\nselect * from permissions;\nselect * from permission_role where permission_id = 226;\n\nselect * from migrations order by id desc;\n\n# mercury\n# neptune\n# earth\n\nselect * from teams;\nselect * from teams where id = 19;\nselect * from teams where id = 27;\nselect * from users where team_id = 27;\nSELECT * FROM crm_configurations WHERE id = 42;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 19\nand sa.provider = 'pipedrive';\n\nselect * from activities where id = 631461;\nSELECT * FROM crm_field_values WHERE crm_field_id = 180;\n\nselect * from teams where id = 2;\nSELECT * FROM social_accounts WHERE sociable_id = 89;\n\nSELECT * FROM activities WHERE uuid_to_bin('ba0c029a-bc14-4e17-8603-64174acebcbb') = uuid; # 634273\nselect * from activity_summary_logs where activity_id = 634273;\n\nselect * from sidekick_settings where team_id = 2;\n\nselect * from teams; # 2, 2\nSELECT * FROM crm_configurations WHERE team_id = 2; # 2\nselect * from team_features where team_id = 2;\nselect * from features;\nSELECT * FROM opportunities WHERE crm_configuration_id = 2 and crm_provider_id = '51317301383';\nSELECT * FROM opportunities WHERE crm_configuration_id = 2 order by id desc;\n\nselect * from automated_reports order by id desc;\nselect * from automated_report_results order by id desc;\nselect * from users where team_id = 1 and id IN (7160, 3248);\nselect * from migrations order by id desc;\n\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 1 and sa.provider = 'salesforce';\n\nselect * from teams where id = 1;\nselect * from groups g JOIN playbooks p on g.playbook_id = p.id where g.team_id = 1;\nselect * from groups where id = 565;\nselect * from playbooks where team_id = 1;\nselect * from playbooks where id = 175;\nselect * from playbook_categories where playbook_id = 175;\nselect * from users where team_id = 1;\nselect * from users where id = 7160;\nselect * from crm_profiles where user_id = 7160;\nselect * from features;\nselect\n *\n# id, uuid, type, provider, playbook_category_id, user_id, lead_id, contact_id, account_id, opportunity_id, stage_id,\n# crm_configuration_id, crm_provider_id, transcription_id, status\nfrom activities where crm_configuration_id = 1 and type = 'conference'\n# and crm_provider_id IS NOT NULL\nand provider != 'uploader' and actual_start_time IS NOT NULL\nORDER by id desc;\nselect * from activities where id = 54747783; # 00UO400000pCzojMAC\n\nselect p.id, p.activity_type, pc.id, pc.name\nFROM playbooks p\njoin playbook_categories pc on p.id = pc.playbook_id\nwhere p.team_id = 1 and p.activity_type = 'event';\n\nSELECT * FROM crm_fields WHERE crm_configuration_id = 1 and object_type = 'event';\nSELECT * FROM crm_field_values WHERE crm_field_id = 4;\n\nselect * from crm_layouts cl join playbook_layouts pl on cl.id = pl.layout_id\nwhere crm_configuration_id = 1 and pl.playbook_id = 175;\n\nselect * from teams;\nSELECT r.* FROM automated_reports r\njoin teams t on r.team_id = t.id\nWHERE r.frequency = 'daily'\n and r.status = 1\nAND t.status = 'active'\nAND (r.expires_at >= now() OR r.expires_at IS NULL);\n\nselect * from automated_report_results where report_id IN (18, 33);\n\nselect * from activity_searches where id = 10932;\nselect * from activity_search_filters where activity_search_id = 10932;\nselect * from automated_reports;\nselect * from automated_report_results where report_id IN (34, 35);","depth":4,"value":"SELECT * FROM teams WHERE id = 1;\n\nselect * from crm_layouts where crm_configuration_id = 39;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 283;\nSELECT * FROM crm_fields WHERE id = 2234;\nSELECT * FROM crm_field_values WHERE crm_field_id = 2234;\n\nselect * from crm_profiles where user_id = 143;\n\nselect * from record_types where crm_configuration_id = 39; # 0121K000001MHElQAO,0121K000001MHEqQAO\nselect * from business_processes where crm_configuration_id = 39;\n# 01941000000H669AAC, 01941000000H66JAAS\n\nselect * from record_type_field_values\n where record_type_id IN (24);\n\nselect * from crm_field_values where id IN (2730);\n\nselect * from crm_configurations where id = 39;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 1\nand sa.provider = 'salesforce'; #1035\n\n\nselect * from users where team_id = 1; # 222 group 3\nSELECT * FROM activities WHERE user_id = 222 order by id desc;\nselect * from sidekick_settings where team_id = 1;\nselect * from teams where id = 1;\nselect * from team_features where team_id = 1;\n\nselect * from activities where crm_configuration_id = 2\nand provider = 'ms-teams' and id = 608765;\n\nSELECT * FROM activities WHERE crm_configuration_id = 2 and crm_provider_id = '59523413338';\n\nselect * from sidekick_settings where team_id = 2;\n\nSELECT * FROM activities WHERE id = 608660;\nselect * from activity_summary_logs where activity_id = 608660;\nselect * from ai_prompts where transcription_id = 11214;\n\n# ********************************************************************************************************\nSELECT * FROM activities WHERE uuid_to_bin('ed78a437-2804-450e-ab2f-56ab1c641346') = uuid;\n# id: 608818, crm: 59628809737\nSELECT * FROM activities WHERE uuid_to_bin('36b06e55-afdd-4782-8dee-c624cd0af191') = uuid;\n# id: 608821, crm: 59632069252\nSELECT ce.start_time, ce.end_time, a.id, a.uuid, crm_provider_id, calendar_event_id, title,\nplaybook_category_id, user_id, lead_id, contact_id, account_id, opportunity_id,\nscheduled_start_time, scheduled_end_time, actual_start_time, actual_end_time, a.created_at\nFROM activities a\njoin calendar_events ce on a.calendar_event_id = ce.id\nWHERE a.id IN (608818, 608821);\n\nselect * from users where team_id = 1;\nselect * from team_settings where team_id = 1;\nselect * from crm_profiles where crm_configuration_id = 39 order by user_id;\n\nselect * from team_features where team_id = 1;\n\nselect * from users where team_id = 2;\n\nSELECT * FROM activities WHERE uuid_to_bin('ec7647e9-5225-458b-b475-f31aa2769204') = uuid; # 612639\n# Preslava N. Ivanova, grou id 3\n\nSELECT * FROM opportunities WHERE uuid_to_bin('a2928fe5-aec5-46cb-85d9-7654c89e46a6') = uuid;\n\nselect * from activities where opportunity_id = 344 and actual_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00';\n\nselect\n a.id,\n a.type,\n a.scheduled_start_time,\n a.actual_start_time,\n a.created_at,\n a.opportunity_id,\n a.status\nFROM activities a\nWHERE opportunity_id = 344\nand status IN ('completed', 'received', 'delivered')\nand (\n (a.actual_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00')\nOR (a.created_at between '2024-10-11 00:00:00' and '2024-10-12 00:00:00')\nOR (a.scheduled_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00'))\n;\n\nSELECT * FROM users WHERE id = 222;\n\nSELECT * FROM crm_profiles WHERE user_id = 222;\nselect * from crm_layouts where crm_configuration_id = 39;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 281;\n\nselect * from group_deal_risk_types;\n\nselect * from opportunities where team_id = 1;\n\nSELECT * FROM opportunities WHERE id = 315;\nSELECT * FROM crm_field_data WHERE object_id = 315;\nselect * from crm_field_data where object_id = 260;\n\nselect * from generic_ai_prompts where subject_id = 315;\n\nselect * from teams; # 36, 21, 121, james.graham@bullhorn.jiminny.com\nSELECT * FROM social_accounts WHERE sociable_id = 121 and provider = 'bullhorn';\n\n# ************************************************************************************\nselect * from teams where id = 1;\nselect * from crm_configurations where id = 39;\nselect * from users where team_id = 1;\nselect u.email, cp.* from users u\njoin crm_profiles cp on u.id = cp.user_id\nwhere u.team_id = 1;\n# 1 - 00541000004281rAAA\n# 204 - 0052g000003freeAAA\n# 429 - 0052g000003qGOiAAM\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 1\nand sa.provider = 'salesforce';\n\nselect * from activities where type = 'softphone'\nand created_at > '2024-12-11 15:24:36' order by id desc;\n\nselect * from activity_providers where team_id = 1;\nselect * from activity_provider_users where activity_provider_id = 328;\n\nselect * from opportunities where crm_configuration_id = 39\nAND account_id = 178 AND is_closed = false\norder by created_at DESC;\n\nselect * from contacts where id = 3952;\nselect * from accounts where id = 178;\n\n# ************************************************************************************\nselect * from teams where id = 36;\nselect * from crm_configurations where id = 21;\nselect * from users where team_id = 36;\nselect u.email, cp.* from users u\njoin crm_profiles cp on u.id = cp.user_id\nwhere u.team_id = 36;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 36\nand sa.provider = 'bullhorn';\n\nselect * from social_accounts where id = 348;\nUPDATE social_accounts SET\nprovider_user_token = '21442_6802599_91:41179a58-21e7-4d7c-ad58-56bb666b2f65',\nprovider_refresh_token = '21442_6802599_91:01c6b335-3f2a-42e4-85ff-8a08fa65fceb',\nexpires = 1733998131,\nstate = 'connected'\nWHERE id = 348;\n\n# ************************************************************************************\nselect * from teams where id = 31;\nselect * from crm_configurations where id = 18;\n\nselect * from users where team_id = 31; # 257\nselect u.email, cp.* from users u\njoin crm_profiles cp on u.id = cp.user_id\nwhere u.team_id = 31;\n\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 31\nand sa.provider = 'close';\n\nselect * from contacts where crm_configuration_id = 18;\n\n# ********************** NEPTUNE **************************************************************\nselect * from teams;\nselect * from users where id IN (1030, 1035, 1052);\nselect * from crm_configurations;\n\nselect * from users where team_id = 65; # 257\nselect * from team_settings where team_id = 65; # 257\nselect * from invitations where team_id = 65; # 257\nselect * from users where email = 'integration-account@jiminny.com'; # 257\nselect u.email, cp.* from users u\njoin crm_profiles cp on u.id = cp.user_id\nwhere u.team_id = 65;\n\nselect * from crm_configurations where id = 53;\nselect * from accounts where crm_configuration_id = 53 order by id desc;\nselect * from leads where crm_configuration_id = 53 order by id desc;\nselect * from contacts where crm_configuration_id = 53 order by id desc;\nselect * from opportunities where crm_configuration_id = 53 order by id desc;\nselect * from crm_profiles where crm_configuration_id = 53 order by id desc;\nselect * from crm_fields where crm_configuration_id = 53 order by id desc;\nselect * from crm_field_values where crm_field_id = 3341 order by id desc;\nselect * from crm_layouts where crm_configuration_id = 53 order by id desc;\nselect * from stages where crm_configuration_id = 53 order by id desc;\n\n\nselect * from crm_profiles where crm_configuration_id = 13;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 65\nand sa.provider = 'integration-app';\n\nselect * from contacts where crm_configuration_id = 13;\n\nselect * from social_accounts where sociable_id = 283;\n\nSELECT * FROM opportunities WHERE crm_provider_id = '006O400000E9bzeIAB';\n\nselect * from activity_providers where team_id = 65;\nSELECT * FROM activities WHERE crm_configuration_id IN (51, 52, 53);\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 65\n;\n\n# ***************************** STAGING ********************************************\nSELECT * FROM teams;\nSELECT * FROM teams WHERE id = 88;\nSELECT * FROM teams WHERE id = 89;\nselect * from team_settings where team_id = 89;\nSELECT * FROM users WHERE team_id = 89;\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 89;\n\nselect * from users;\nSELECT * FROM social_accounts WHERE sociable_id = 1761;\nSELECT * FROM crm_configurations WHERE id = 70;\nselect * from accounts where crm_configuration_id = 70 order by id desc;\nselect * from leads where crm_configuration_id = 70 order by id desc;\nselect * from contacts where crm_configuration_id = 70 order by id desc;\nselect * from opportunities where crm_configuration_id = 70 order by id desc;\nselect * from crm_profiles where crm_configuration_id = 70 order by id desc;\nselect * from crm_fields where crm_configuration_id = 70 order by id desc;\nselect * from crm_field_values where crm_field_id = 3536 order by id desc;\nselect * from crm_layouts where crm_configuration_id = 70 order by id desc;\nselect * from stages where crm_configuration_id = 70 order by id desc;\nselect * from business_processes where crm_configuration_id = 70 order by id desc;\nselect * from business_process_stages where business_process_id = 34;\n\nselect * from contacts where id = 10468;\n\nselect * from crm_layouts where crm_configuration_id = 70;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 388;\nSELECT * FROM crm_fields WHERE id IN (3533,3534,3535);\n\nselect * from activities where crm_configuration_id = 70\nand (account_id IS NOT NULL or lead_id IS NOT NULL or contact_id IS NOT NULL or opportunity_id IS NOT NULL) order by id desc;\n\nSELECT * FROM activities WHERE uuid_to_bin('2e10b60f-8a61-41c5-a3d4-28835353dc65') = uuid;\nSELECT * FROM activities where crm_configuration_id = 69 ;\n\nSELECT * FROM users WHERE email LIKE '%jiminny_web_sa2@jiminny.com%';\nSELECT * FROM activities WHERE uuid_to_bin('5a150c93-40fc-42ec-b3bd-c1d328e09f6e') = uuid;\nSELECT * FROM opportunities WHERE id = 385;\n\nselect * from participants p\njoin activities a on p.activity_id = a.id\nwhere a.crm_configuration_id = 70\nand (p.lead_id IS NOT NULL or p.contact_id IS NOT NULL);\nSELECT * FROM participants WHERE id = 1013638;\n\nselect * from teams where id = 90;\nselect * from users where team_id = 90;\nselect * from social_accounts where social_accounts.sociable_id IN (1960,1760);\nSELECT * FROM crm_profiles WHERE crm_configuration_id = 71;\nselect * from invitations where team_id = 90;\n\nselect * from crm_configurations where id = 71;\nselect * from accounts where crm_configuration_id = 71 order by id desc;\nselect * from leads where crm_configuration_id = 71 order by id desc;\nselect * from contacts where crm_configuration_id = 71 order by id desc;\nselect * from opportunities where crm_configuration_id = 71 order by id desc;\nselect * from crm_profiles where crm_configuration_id = 71 order by id desc;\nselect * from crm_fields where crm_configuration_id = 71 order by id desc;\nselect * from crm_field_values where crm_field_id = 3341 order by id desc;\nselect * from crm_layouts where crm_configuration_id = 71 order by id desc;\nselect * from stages where crm_configuration_id = 71 order by id desc;\n\nselect * from users order by secondary_email desc;\nselect u.id, u.email, u.status, sa.id, sa.provider_user_id from social_accounts sa\n join users u on sa.sociable_id = u.id\nwhere sa.provider = 'google' and u.email LIKE 'aneliya%';\n\nselect * from failed_jobs order by id desc;\n\nselect * from users where email = 'ben.allwright@learningpeople.co.uk' or secondary_email = 'ben.allwright@learningpeople.co.uk';\n\nselect * from teams;\nSELECT * FROM crm_profiles WHERE crm_configuration_id = 39;\nSELECT * FROM crm_fields WHERE crm_configuration_id = 39 and object_type = 'task';\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 1\nand sa.provider = 'salesforce';\n\n# ************************************************************************************\nSELECT * FROM activities WHERE uuid_to_bin('c38b3895-fd0f-4b1f-9fb2-c170dba137c6') = uuid;\nSELECT * FROM crm_configurations WHERE id = 70;\n\nselect * from teams where id = 1;\nselect * from groups where team_id = 1;\nselect * from users where team_id = 1;\n\nselect o.id, o.name,o.close_date, u.id, u.name, u.group_id, r.id, r.display_name, g.name, g.scope from opportunities o\njoin users u on o.user_id = u.id\njoin groups g on u.group_id = g.id\njoin role_user ru on u.id = ru.user_id\njoin roles r on ru.role_id = r.id\nwhere o.crm_configuration_id = 39 and close_date > '2024-01-01 00:00:00';\n\nselect * from role_user where user_id = 143;\nselect * from roles;\n\nselect * from role_user;\nselect * from groups where id = 9;\nselect * from scope_groups where group_id = 9;\n\n# ************************************************************************************\nselect * from teams where id = 36;\nselect * from crm_configurations;\nSELECT * FROM social_accounts WHERE sociable_id = 121;\n\nhttps://crmsandbox.zoho.com/crm/jiminnyw4/tab/Leads/4776201000005049105\nhttps://crmsandbox.zoho.com/crm/\n\nhttps://crm.zoho.com/crm/org3469620/tab/Leads/230045000229559080\n https://crm.zoho.com/crm/\n org3469620\n\nSELECT * FROM activities WHERE uuid_to_bin('03382d20-c8bc-48e7-a3d4-90b52fa5ceab') = uuid;\n\nselect * from users where email LIKE \"%mobile_automation_%\";\nselect * from social_accounts where sociable_id IN (2228);\nselect * from crm_profiles where user_id IN (2222,2223,2226,2227);\n\nselect * from teams order by id desc;\nSELECT * FROM users WHERE id = 2229;\nSELECT * FROM crm_profiles WHERE user_id = 2229;\nselect * from opportunities where crm_configuration_id = 88;\nselect * from crm_fields where crm_configuration_id = 88;\nselect * from crm_profiles where crm_configuration_id = 88;\n\nSELECT * FROM teams WHERE id = 1;\n\nSELECT * FROM users WHERE id = 143;\nSELECT * FROM users WHERE uuid_to_bin('fde193d3-06a2-4e1a-8895-62b94039215d') = uuid;\nSELECT * FROM teams WHERE uuid_to_bin('73385071-a756-42ae-9c73-8b53f2309467') = uuid;\n\nhttps://app.staging.jiminny.com/ondemand?\n min_duration=1\n &\n only_recorded=1\n &\n user_id%5B%5D=641f1acb-16b8-42d1-8726-df52979dad0e\n &\n sequence_number=2\n\n select * from users where team_id = 1 and email like '%stoyan%'\n\nselect * from coaching_feedbacks;\n\nselect * from teams;\nSELECT * FROM users WHERE team_id = 36;\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 19\nand sa.provider = 'pipedrive';\n\nselect * from users where id = 143;\n\nSELECT * FROM users WHERE uuid_to_bin('73180eeb-33de-4065-977d-ccbe0e6c94fc') = uuid;\nSELECT * FROM teams WHERE uuid_to_bin('73180eeb-33de-4065-977d-ccbe0e6c94fc') = uuid;\nSELECT * FROM activity_shares WHERE uuid_to_bin('73180eeb-33de-4065-977d-ccbe0e6c94fc') = uuid;\n\nselect * from users where team_id = 2;\nselect * from activities where crm_configuration_id = 39\nand activities.scheduled_start_time BETWEEN '2025-04-09 00:00:00' AND '2025-04-09 23:59:59'\nAND user_id = 143\norder by id desc;\n\n# ************************************************************************************\nselect * from teams where id = 142; # 2312, 126\nselect * from team_settings;\nselect * from users where team_id = 142; # 21642\nSELECT * FROM social_accounts WHERE sociable_id = 21642;\nSELECT * FROM crm_profiles cp join users u ON u.id = cp.user_id WHERE team_id = 142;\nselect * from crm_profiles where id IN (93);\nselect * from invitations;\nselect * from team_features where team_id = 1;\n\nSELECT * FROM crm_configurations WHERE id = 126;\nselect * from accounts where crm_configuration_id = 126 order by id desc;\nselect * from leads where crm_configuration_id = 126 order by id desc;\nselect * from contacts where crm_configuration_id = 126 order by id desc;\nselect * from opportunities where crm_configuration_id = 126 order by id desc;\nselect * from crm_profiles where crm_configuration_id = 126 order by id desc;\nselect * from crm_fields where crm_configuration_id = 126 # 11060\n# and type IN ('picklist', 'status')\n# and object_type = 'task'\norder by id desc;\n# 5731,5732,5733\nselect DISTINCT crm_field_id from crm_field_values where crm_field_id IN (11151,12239,12215,12185,12175,12165,12144,12137,12127,12109,12107,12105,12103,12092,12037,12005,12003,11987,11969,11958,11951,11942,11931,11924,11921,11917,11915,11901,11893,11883,11872,11870,11868,11866,11839,11833,11821,11793,11780,11777,11769,11757,11737,11735,11656,11645,11638,11629,11618,11611,11602,11591,11584,11581,11558,11544,11543,11534,11532,11529,11527,11503,11497,11493,11488,11470,11468,11457,11455,11397,11387,11372,11363,11348,11323,11318,11309,11301,11300,11292,11290,11286,11284,11256,11252,11242,11237,11233,11219,11176,11160) order by id desc;\nselect * from crm_layouts where crm_configuration_id = 126 order by id desc;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id in (300,299,298);\nselect * from stages where crm_configuration_id = 126 order by id desc;\nselect * from business_processes where crm_configuration_id = 126 order by id desc;\nselect * from business_process_stages where business_process_id IN (76,75,74,73);\nselect * from playbooks where team_id = 142;\nselect * from playbook_layouts where playbook_id IN (108);\nSELECT * FROM playbook_categories WHERE playbook_id IN (108);\n\nselect * from teams where id = 130;\nSELECT * FROM social_accounts WHERE sociable_id = 2291;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 2\nand sa.provider = 'hubspot';\n\nSELECT * FROM activities\n WHERE crm_configuration_id = 110;\n\nselect * from teams;\nselect * from crm_configurations;\n\nSELECT * FROM activities WHERE id = 628773;\nSELECT * FROM crm_profiles WHERE user_id = 1460;\nSELECT * FROM social_accounts WHERE sociable_id = 2291;\n\nselect * from teams;\nselect ru.*, pr.*, p.* from users u join role_user ru on ru.user_id = u.id\njoin permission_role pr on pr.role_id = ru.role_id\n join permissions p on p.id = pr.permission_id\nwhere team_id = 495 and p.name IN ('dial');\n\nselect * from teams where id = 145;\nselect * from crm_configurations where id = 129;\nselect * from social_accounts where sociable_id = 2317;\nSELECT * FROM activities WHERE uuid_to_bin('8dbab184-a333-4268-ad57-fb41f8d53a9a') = uuid;\n\nselect * from teams where id = 1;\nSELECT * FROM crm_layouts WHERE crm_configuration_id = 39;\nSELECT * FROM crm_layout_entities WHERE crm_layout_id = 280;\nSELECT * FROM crm_layout_entities WHERE id = 5507;\nSELECT * FROM crm_fields WHERE crm_configuration_id = 39 and object_type IN ('event');\n\nselect * from teams;\nselect * from activities where crm_configuration_id = 14;\n\nSELECT * FROM social_accounts where provider = 'copper';\n\nselect * from activities where id = 628467;\nselect * from participants where activity_id = 628467;\n\nSELECT * FROM contacts WHERE id = 3969;\nSELECT * FROM accounts WHERE id = 177;\n\nSELECT * FROM activities WHERE uuid_to_bin('4eb54c77-cfa3-2bd4-84a7-9ed46a21c988') = uuid;\n\n# ********************* BH\nselect * from teams where id = 36;\nSELECT * FROM crm_configurations WHERE id = 21;\nselect * from activities where crm_configuration_id = 21 and id = 607901;\nselect * from activities where crm_configuration_id = 21;\n\nselect * roles;\nselect * from permissions;\nselect * from permission_role where permission_id = 226;\n\nselect * from migrations order by id desc;\n\n# mercury\n# neptune\n# earth\n\nselect * from teams;\nselect * from teams where id = 19;\nselect * from teams where id = 27;\nselect * from users where team_id = 27;\nSELECT * FROM crm_configurations WHERE id = 42;\n\nselect * from social_accounts sa\njoin users u on sa.sociable_id = u.id\nwhere u.team_id = 19\nand sa.provider = 'pipedrive';\n\nselect * from activities where id = 631461;\nSELECT * FROM crm_field_values WHERE crm_field_id = 180;\n\nselect * from teams where id = 2;\nSELECT * FROM social_accounts WHERE sociable_id = 89;\n\nSELECT * FROM activities WHERE uuid_to_bin('ba0c029a-bc14-4e17-8603-64174acebcbb') = uuid; # 634273\nselect * from activity_summary_logs where activity_id = 634273;\n\nselect * from sidekick_settings where team_id = 2;\n\nselect * from teams; # 2, 2\nSELECT * FROM crm_configurations WHERE team_id = 2; # 2\nselect * from team_features where team_id = 2;\nselect * from features;\nSELECT * FROM opportunities WHERE crm_configuration_id = 2 and crm_provider_id = '51317301383';\nSELECT * FROM opportunities WHERE crm_configuration_id = 2 order by id desc;\n\nselect * from automated_reports order by id desc;\nselect * from automated_report_results order by id desc;\nselect * from users where team_id = 1 and id IN (7160, 3248);\nselect * from migrations order by id desc;\n\nSELECT\n CONCAT(u.id, CASE WHEN u.id = t.owner_id THEN ' (owner)' ELSE '' END) AS user_id,\n u.email,\n sa.*,\n t.owner_id FROM social_accounts sa\nJOIN users u on u.id = sa.sociable_id\nJOIN teams t on t.id = u.team_id\nWHERE u.team_id = 1 and sa.provider = 'salesforce';\n\nselect * from teams where id = 1;\nselect * from groups g JOIN playbooks p on g.playbook_id = p.id where g.team_id = 1;\nselect * from groups where id = 565;\nselect * from playbooks where team_id = 1;\nselect * from playbooks where id = 175;\nselect * from playbook_categories where playbook_id = 175;\nselect * from users where team_id = 1;\nselect * from users where id = 7160;\nselect * from crm_profiles where user_id = 7160;\nselect * from features;\nselect\n *\n# id, uuid, type, provider, playbook_category_id, user_id, lead_id, contact_id, account_id, opportunity_id, stage_id,\n# crm_configuration_id, crm_provider_id, transcription_id, status\nfrom activities where crm_configuration_id = 1 and type = 'conference'\n# and crm_provider_id IS NOT NULL\nand provider != 'uploader' and actual_start_time IS NOT NULL\nORDER by id desc;\nselect * from activities where id = 54747783; # 00UO400000pCzojMAC\n\nselect p.id, p.activity_type, pc.id, pc.name\nFROM playbooks p\njoin playbook_categories pc on p.id = pc.playbook_id\nwhere p.team_id = 1 and p.activity_type = 'event';\n\nSELECT * FROM crm_fields WHERE crm_configuration_id = 1 and object_type = 'event';\nSELECT * FROM crm_field_values WHERE crm_field_id = 4;\n\nselect * from crm_layouts cl join playbook_layouts pl on cl.id = pl.layout_id\nwhere crm_configuration_id = 1 and pl.playbook_id = 175;\n\nselect * from teams;\nSELECT r.* FROM automated_reports r\njoin teams t on r.team_id = t.id\nWHERE r.frequency = 'daily'\n and r.status = 1\nAND t.status = 'active'\nAND (r.expires_at >= now() OR r.expires_at IS NULL);\n\nselect * from automated_report_results where report_id IN (18, 33);\n\nselect * from activity_searches where id = 10932;\nselect * from activity_search_filters where activity_search_id = 10932;\nselect * from automated_reports;\nselect * from automated_report_results where report_id IN (34, 35);","role_description":"text entry area","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Code changed:","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.088194445,"height":0.027777778},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Sync Changes","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide This Notification","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":false,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"2","depth":4,"role_description":"text"},{"role":"AXButton","text":"Previous Highlighted Error","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Next Highlighted Error","depth":4,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXTextArea","text":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Console\\Commands\\Reports;\n\nuse Carbon\\Carbon;\nuse Illuminate\\Console\\Command;\nuse Illuminate\\Contracts\\Bus\\Dispatcher as BusDispatcher;\nuse Illuminate\\Support\\Collection;\nuse Jiminny\\Jobs\\AutomatedReports\\RequestGenerateAskJiminnyReportJob;\nuse Jiminny\\Jobs\\AutomatedReports\\RequestGenerateReportJob;\nuse Jiminny\\Models\\AutomatedReport;\nuse Jiminny\\Models\\Team;\nuse Jiminny\\Repositories\\AutomatedReportsRepository;\nuse Jiminny\\Services\\Kiosk\\AutomatedReports\\AutomatedReportsService;\nuse Psr\\Log\\LoggerInterface;\n\nclass AutomatedReportsCommand extends Command\n{\n /**\n * Log prefix for all log messages\n */\n private const string LOG_PREFIX = '[automated-reports]';\n\n /**\n * The name and signature of the console command.\n *\n * @var string\n */\n protected $signature = 'automated-reports \n {--report-id= : Process a specific report by ID or UUID (bypasses frequency scheduling)}';\n\n /**\n * The console command description.\n *\n * @var string\n */\n protected $description = 'Process automated reports based on their frequency (weekly, monthly, quarterly). \n Use --report-id to manually trigger a specific report by ID or UUID.';\n\n\n public function __construct(\n private readonly LoggerInterface $logger,\n private readonly BusDispatcher $dispatcher,\n private readonly AutomatedReportsRepository $reportRepository\n ) {\n parent::__construct();\n }\n\n /**\n * Execute the console command.\n *\n * @return int\n */\n public function handle(): int\n {\n $this->logger->info(self::LOG_PREFIX . ' Started');\n\n $now = Carbon::now();\n $isMonday = $now->isMonday();\n $isFirstDayOfMonth = $now->day === 1;\n $currentMonth = $now->month;\n\n // Check if the current month is a quarterly month (January, April, July, October)\n $isQuarterlyMonth = in_array($currentMonth, [1, 4, 7, 10], true);\n\n $this->logger->info(self::LOG_PREFIX . ' Checking conditions', [\n 'isMonday' => $isMonday,\n 'isFirstDayOfMonth' => $isFirstDayOfMonth,\n 'currentMonth' => $currentMonth,\n 'isQuarterlyMonth' => $isQuarterlyMonth,\n ]);\n\n // Process daily reports\n $this->processReports(AutomatedReportsService::FREQUENCY_DAILY);\n\n // Process weekly reports on Mondays\n if ($isMonday) {\n $this->processReports(AutomatedReportsService::FREQUENCY_WEEKLY);\n }\n\n // Process monthly reports on the first day of the month\n if ($isFirstDayOfMonth) {\n $this->processReports(AutomatedReportsService::FREQUENCY_MONTHLY);\n }\n\n // Process quarterly reports on the first day of January, April, July, and October\n if ($isFirstDayOfMonth && $isQuarterlyMonth) {\n $this->processReports(AutomatedReportsService::FREQUENCY_QUARTERLY);\n }\n\n $this->logger->info(self::LOG_PREFIX . ' Completed');\n\n return 0;\n }\n\n /**\n * Process reports for a specific frequency.\n *\n * @param string $frequency\n *\n * @return void\n */\n private function processReports(string $frequency): void\n {\n $this->logger->info(self::LOG_PREFIX . \" Processing $frequency reports\");\n\n $reportId = $this->option('report-id');\n if ($reportId !== null) {\n $reports = $this->getReportById($reportId);\n } else {\n // Get all enabled, not deleted reports with active teams for the specified frequency\n $reports = $this->reportRepository->getActiveReportsByFrequency($frequency);\n }\n\n $this->logger->info(self::LOG_PREFIX . \" Found {$reports->count()} $frequency reports to process\");\n\n /** @var AutomatedReport $report */\n foreach ($reports as $report) {\n $this->logger->info(self::LOG_PREFIX . ' Dispatching Generate Report job for report', [\n 'reportUuid' => $report->getUuid(),\n 'teamId' => $report->getTeamId(),\n 'frequency' => $report->getFrequency(),\n 'type' => $report->getType(),\n ]);\n\n $job = $report->isAskJiminnyReport()\n ? new RequestGenerateAskJiminnyReportJob($report->getUuid())\n : new RequestGenerateReportJob($report->getUuid());\n\n $this->dispatcher->dispatch($job);\n }\n }\n\n private function getReportById(string $reportId): Collection\n {\n $report = $this->reportRepository->findByIdOrUuid($reportId);\n\n if ($report === null) {\n $this->logger->warning(self::LOG_PREFIX . ' Report not found for --report-id', ['reportId' => $reportId]);\n $this->warn(\"Report not found: {$reportId}\");\n\n return collect();\n }\n\n if (! $report->getStatus()) {\n $this->logger->warning(self::LOG_PREFIX . ' Report is inactive, processing anyway (manual override)', [\n 'reportId' => $reportId,\n 'reportUuid' => $report->getUuid(),\n ]);\n $this->warn('Report is inactive — processing anyway (manual override).');\n }\n\n $team = $report->getTeam();\n if ($team->getStatus() !== Team::STATUS_ACTIVE) {\n $this->logger->warning(self::LOG_PREFIX . ' Team is not active, processing anyway (manual override)', [\n 'reportId' => $reportId,\n 'reportUuid' => $report->getUuid(),\n 'teamId' => $report->getTeamId(),\n 'teamStatus' => $team->getStatus(),\n ]);\n $this->warn(\"Team #{$report->getTeamId()} is not active — processing anyway (manual override).\");\n }\n\n if ($report->isExpired()) {\n $this->logger->warning(self::LOG_PREFIX . ' Report is expired, processing anyway (manual override)', [\n 'reportId' => $reportId,\n 'reportUuid' => $report->getUuid(),\n 'expiresAt' => $report->getExpiresAt()?->toDateString(),\n ]);\n $this->warn('Report is expired (expires_at: ' . $report->getExpiresAt()?->toDateString() . ') — processing anyway (manual override).');\n }\n\n $this->info(self::LOG_PREFIX . ' Automated report found ' . $report->getCustomName());\n\n return collect([$report]);\n }\n}","depth":4,"value":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Jiminny\\Console\\Commands\\Reports;\n\nuse Carbon\\Carbon;\nuse Illuminate\\Console\\Command;\nuse Illuminate\\Contracts\\Bus\\Dispatcher as BusDispatcher;\nuse Illuminate\\Support\\Collection;\nuse Jiminny\\Jobs\\AutomatedReports\\RequestGenerateAskJiminnyReportJob;\nuse Jiminny\\Jobs\\AutomatedReports\\RequestGenerateReportJob;\nuse Jiminny\\Models\\AutomatedReport;\nuse Jiminny\\Models\\Team;\nuse Jiminny\\Repositories\\AutomatedReportsRepository;\nuse Jiminny\\Services\\Kiosk\\AutomatedReports\\AutomatedReportsService;\nuse Psr\\Log\\LoggerInterface;\n\nclass AutomatedReportsCommand extends Command\n{\n /**\n * Log prefix for all log messages\n */\n private const string LOG_PREFIX = '[automated-reports]';\n\n /**\n * The name and signature of the console command.\n *\n * @var string\n */\n protected $signature = 'automated-reports \n {--report-id= : Process a specific report by ID or UUID (bypasses frequency scheduling)}';\n\n /**\n * The console command description.\n *\n * @var string\n */\n protected $description = 'Process automated reports based on their frequency (weekly, monthly, quarterly). \n Use --report-id to manually trigger a specific report by ID or UUID.';\n\n\n public function __construct(\n private readonly LoggerInterface $logger,\n private readonly BusDispatcher $dispatcher,\n private readonly AutomatedReportsRepository $reportRepository\n ) {\n parent::__construct();\n }\n\n /**\n * Execute the console command.\n *\n * @return int\n */\n public function handle(): int\n {\n $this->logger->info(self::LOG_PREFIX . ' Started');\n\n $now = Carbon::now();\n $isMonday = $now->isMonday();\n $isFirstDayOfMonth = $now->day === 1;\n $currentMonth = $now->month;\n\n // Check if the current month is a quarterly month (January, April, July, October)\n $isQuarterlyMonth = in_array($currentMonth, [1, 4, 7, 10], true);\n\n $this->logger->info(self::LOG_PREFIX . ' Checking conditions', [\n 'isMonday' => $isMonday,\n 'isFirstDayOfMonth' => $isFirstDayOfMonth,\n 'currentMonth' => $currentMonth,\n 'isQuarterlyMonth' => $isQuarterlyMonth,\n ]);\n\n // Process daily reports\n $this->processReports(AutomatedReportsService::FREQUENCY_DAILY);\n\n // Process weekly reports on Mondays\n if ($isMonday) {\n $this->processReports(AutomatedReportsService::FREQUENCY_WEEKLY);\n }\n\n // Process monthly reports on the first day of the month\n if ($isFirstDayOfMonth) {\n $this->processReports(AutomatedReportsService::FREQUENCY_MONTHLY);\n }\n\n // Process quarterly reports on the first day of January, April, July, and October\n if ($isFirstDayOfMonth && $isQuarterlyMonth) {\n $this->processReports(AutomatedReportsService::FREQUENCY_QUARTERLY);\n }\n\n $this->logger->info(self::LOG_PREFIX . ' Completed');\n\n return 0;\n }\n\n /**\n * Process reports for a specific frequency.\n *\n * @param string $frequency\n *\n * @return void\n */\n private function processReports(string $frequency): void\n {\n $this->logger->info(self::LOG_PREFIX . \" Processing $frequency reports\");\n\n $reportId = $this->option('report-id');\n if ($reportId !== null) {\n $reports = $this->getReportById($reportId);\n } else {\n // Get all enabled, not deleted reports with active teams for the specified frequency\n $reports = $this->reportRepository->getActiveReportsByFrequency($frequency);\n }\n\n $this->logger->info(self::LOG_PREFIX . \" Found {$reports->count()} $frequency reports to process\");\n\n /** @var AutomatedReport $report */\n foreach ($reports as $report) {\n $this->logger->info(self::LOG_PREFIX . ' Dispatching Generate Report job for report', [\n 'reportUuid' => $report->getUuid(),\n 'teamId' => $report->getTeamId(),\n 'frequency' => $report->getFrequency(),\n 'type' => $report->getType(),\n ]);\n\n $job = $report->isAskJiminnyReport()\n ? new RequestGenerateAskJiminnyReportJob($report->getUuid())\n : new RequestGenerateReportJob($report->getUuid());\n\n $this->dispatcher->dispatch($job);\n }\n }\n\n private function getReportById(string $reportId): Collection\n {\n $report = $this->reportRepository->findByIdOrUuid($reportId);\n\n if ($report === null) {\n $this->logger->warning(self::LOG_PREFIX . ' Report not found for --report-id', ['reportId' => $reportId]);\n $this->warn(\"Report not found: {$reportId}\");\n\n return collect();\n }\n\n if (! $report->getStatus()) {\n $this->logger->warning(self::LOG_PREFIX . ' Report is inactive, processing anyway (manual override)', [\n 'reportId' => $reportId,\n 'reportUuid' => $report->getUuid(),\n ]);\n $this->warn('Report is inactive — processing anyway (manual override).');\n }\n\n $team = $report->getTeam();\n if ($team->getStatus() !== Team::STATUS_ACTIVE) {\n $this->logger->warning(self::LOG_PREFIX . ' Team is not active, processing anyway (manual override)', [\n 'reportId' => $reportId,\n 'reportUuid' => $report->getUuid(),\n 'teamId' => $report->getTeamId(),\n 'teamStatus' => $team->getStatus(),\n ]);\n $this->warn(\"Team #{$report->getTeamId()} is not active — processing anyway (manual override).\");\n }\n\n if ($report->isExpired()) {\n $this->logger->warning(self::LOG_PREFIX . ' Report is expired, processing anyway (manual override)', [\n 'reportId' => $reportId,\n 'reportUuid' => $report->getUuid(),\n 'expiresAt' => $report->getExpiresAt()?->toDateString(),\n ]);\n $this->warn('Report is expired (expires_at: ' . $report->getExpiresAt()?->toDateString() . ') — processing anyway (manual override).');\n }\n\n $this->info(self::LOG_PREFIX . ' Automated report found ' . $report->getCustomName());\n\n return collect([$report]);\n }\n}","role_description":"text entry area","is_enabled":true,"is_focused":true,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"Project","depth":3,"role_description":"text"},{"role":"AXButton","text":"Project","depth":3,"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"New File or Directory…","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Expand Selected","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Collapse All","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Options","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXButton","text":"Hide","depth":4,"bounds":{"left":0.0,"top":0.0,"width":0.018055556,"height":0.026666667},"role_description":"button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false}]...
|
-4899705489579526080
|
6686649022737167437
|
visual_change
|
accessibility
|
NULL
|
Project: faVsco.js, menu
#11894 on JY-18909-automa Project: faVsco.js, menu
#11894 on JY-18909-automated-reports-ask-jiminny, menu
Start Listening for PHP Debug Connections
AutomatedReportsCommandTest
Run 'AutomatedReportsCommandTest'
Debug 'AutomatedReportsCommandTest'
More Actions
JetBrains AI
Search Everywhere
IDE and Project Settings
Execute
Explain Plan
Browse Query History
View Parameters
Open Query Execution Settings…
In-Editor Results
Tx: Auto
Cancel Running Statements
Playground
jiminny
Sync Changes
Hide This Notification
Code changed:
Hide
16
13
13
Previous Highlighted Error
Next Highlighted Error
SELECT * FROM teams WHERE id = 1;
select * from crm_layouts where crm_configuration_id = 39;
SELECT * FROM crm_layout_entities WHERE crm_layout_id = 283;
SELECT * FROM crm_fields WHERE id = 2234;
SELECT * FROM crm_field_values WHERE crm_field_id = 2234;
select * from crm_profiles where user_id = 143;
select * from record_types where crm_configuration_id = 39; # 0121K000001MHElQAO,0121K000001MHEqQAO
select * from business_processes where crm_configuration_id = 39;
# 01941000000H669AAC, 01941000000H66JAAS
select * from record_type_field_values
where record_type_id IN (24);
select * from crm_field_values where id IN (2730);
select * from crm_configurations where id = 39;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 1
and sa.provider = 'salesforce'; #1035
select * from users where team_id = 1; # 222 group 3
SELECT * FROM activities WHERE user_id = 222 order by id desc;
select * from sidekick_settings where team_id = 1;
select * from teams where id = 1;
select * from team_features where team_id = 1;
select * from activities where crm_configuration_id = 2
and provider = 'ms-teams' and id = 608765;
SELECT * FROM activities WHERE crm_configuration_id = 2 and crm_provider_id = '59523413338';
select * from sidekick_settings where team_id = 2;
SELECT * FROM activities WHERE id = 608660;
select * from activity_summary_logs where activity_id = 608660;
select * from ai_prompts where transcription_id = 11214;
# [PASSWORD_DOTS]
SELECT * FROM activities WHERE uuid_to_bin('ed78a437-2804-450e-ab2f-56ab1c641346') = uuid;
# id: 608818, crm: 59628809737
SELECT * FROM activities WHERE uuid_to_bin('36b06e55-afdd-4782-8dee-c624cd0af191') = uuid;
# id: 608821, crm: 59632069252
SELECT ce.start_time, ce.end_time, a.id, a.uuid, crm_provider_id, calendar_event_id, title,
playbook_category_id, user_id, lead_id, contact_id, account_id, opportunity_id,
scheduled_start_time, scheduled_end_time, actual_start_time, actual_end_time, a.created_at
FROM activities a
join calendar_events ce on a.calendar_event_id = ce.id
WHERE a.id IN (608818, 608821);
select * from users where team_id = 1;
select * from team_settings where team_id = 1;
select * from crm_profiles where crm_configuration_id = 39 order by user_id;
select * from team_features where team_id = 1;
select * from users where team_id = 2;
SELECT * FROM activities WHERE uuid_to_bin('ec7647e9-5225-458b-b475-f31aa2769204') = uuid; # 612639
# Preslava N. Ivanova, grou id 3
SELECT * FROM opportunities WHERE uuid_to_bin('a2928fe5-aec5-46cb-85d9-7654c89e46a6') = uuid;
select * from activities where opportunity_id = 344 and actual_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00';
select
a.id,
a.type,
a.scheduled_start_time,
a.actual_start_time,
a.created_at,
a.opportunity_id,
a.status
FROM activities a
WHERE opportunity_id = 344
and status IN ('completed', 'received', 'delivered')
and (
(a.actual_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00')
OR (a.created_at between '2024-10-11 00:00:00' and '2024-10-12 00:00:00')
OR (a.scheduled_start_time between '2024-10-11 00:00:00' and '2024-10-12 00:00:00'))
;
SELECT * FROM users WHERE id = 222;
SELECT * FROM crm_profiles WHERE user_id = 222;
select * from crm_layouts where crm_configuration_id = 39;
SELECT * FROM crm_layout_entities WHERE crm_layout_id = 281;
select * from group_deal_risk_types;
select * from opportunities where team_id = 1;
SELECT * FROM opportunities WHERE id = 315;
SELECT * FROM crm_field_data WHERE object_id = 315;
select * from crm_field_data where object_id = 260;
select * from generic_ai_prompts where subject_id = 315;
select * from teams; # 36, 21, 121, [EMAIL]
SELECT * FROM social_accounts WHERE sociable_id = 121 and provider = 'bullhorn';
# [PASSWORD_DOTS]
select * from teams where id = 1;
select * from crm_configurations where id = 39;
select * from users where team_id = 1;
select u.email, cp.* from users u
join crm_profiles cp on u.id = cp.user_id
where u.team_id = 1;
# 1 - 00541000004281rAAA
# 204 - 0052g000003freeAAA
# 429 - 0052g000003qGOiAAM
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 1
and sa.provider = 'salesforce';
select * from activities where type = 'softphone'
and created_at > '2024-12-11 15:24:36' order by id desc;
select * from activity_providers where team_id = 1;
select * from activity_provider_users where activity_provider_id = 328;
select * from opportunities where crm_configuration_id = 39
AND account_id = 178 AND is_closed = false
order by created_at DESC;
select * from contacts where id = 3952;
select * from accounts where id = 178;
# [PASSWORD_DOTS]
select * from teams where id = 36;
select * from crm_configurations where id = 21;
select * from users where team_id = 36;
select u.email, cp.* from users u
join crm_profiles cp on u.id = cp.user_id
where u.team_id = 36;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 36
and sa.provider = 'bullhorn';
select * from social_accounts where id = 348;
UPDATE social_accounts SET
provider_user_token = '21442_6802599_91:41179a58-21e7-4d7c-ad58-56bb666b2f65',
provider_refresh_token = '21442_6802599_91:01c6b335-3f2a-42e4-85ff-8a08fa65fceb',
expires = 1733998131,
state = 'connected'
WHERE id = 348;
# [PASSWORD_DOTS]
select * from teams where id = 31;
select * from crm_configurations where id = 18;
select * from users where team_id = 31; # 257
select u.email, cp.* from users u
join crm_profiles cp on u.id = cp.user_id
where u.team_id = 31;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 31
and sa.provider = 'close';
select * from contacts where crm_configuration_id = 18;
# [PASSWORD_DOTS] NEPTUNE [PASSWORD_DOTS]
select * from teams;
select * from users where id IN (1030, 1035, 1052);
select * from crm_configurations;
select * from users where team_id = 65; # 257
select * from team_settings where team_id = 65; # 257
select * from invitations where team_id = 65; # 257
select * from users where email = '[EMAIL]'; # 257
select u.email, cp.* from users u
join crm_profiles cp on u.id = cp.user_id
where u.team_id = 65;
select * from crm_configurations where id = 53;
select * from accounts where crm_configuration_id = 53 order by id desc;
select * from leads where crm_configuration_id = 53 order by id desc;
select * from contacts where crm_configuration_id = 53 order by id desc;
select * from opportunities where crm_configuration_id = 53 order by id desc;
select * from crm_profiles where crm_configuration_id = 53 order by id desc;
select * from crm_fields where crm_configuration_id = 53 order by id desc;
select * from crm_field_values where crm_field_id = 3341 order by id desc;
select * from crm_layouts where crm_configuration_id = 53 order by id desc;
select * from stages where crm_configuration_id = 53 order by id desc;
select * from crm_profiles where crm_configuration_id = 13;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 65
and sa.provider = 'integration-app';
select * from contacts where crm_configuration_id = 13;
select * from social_accounts where sociable_id = 283;
SELECT * FROM opportunities WHERE crm_provider_id = '006O400000E9bzeIAB';
select * from activity_providers where team_id = 65;
SELECT * FROM activities WHERE crm_configuration_id IN (51, 52, 53);
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 65
;
# [PASSWORD_DOTS] STAGING [PASSWORD_DOTS]
SELECT * FROM teams;
SELECT * FROM teams WHERE id = 88;
SELECT * FROM teams WHERE id = 89;
select * from team_settings where team_id = 89;
SELECT * FROM users WHERE team_id = 89;
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 89;
select * from users;
SELECT * FROM social_accounts WHERE sociable_id = 1761;
SELECT * FROM crm_configurations WHERE id = 70;
select * from accounts where crm_configuration_id = 70 order by id desc;
select * from leads where crm_configuration_id = 70 order by id desc;
select * from contacts where crm_configuration_id = 70 order by id desc;
select * from opportunities where crm_configuration_id = 70 order by id desc;
select * from crm_profiles where crm_configuration_id = 70 order by id desc;
select * from crm_fields where crm_configuration_id = 70 order by id desc;
select * from crm_field_values where crm_field_id = 3536 order by id desc;
select * from crm_layouts where crm_configuration_id = 70 order by id desc;
select * from stages where crm_configuration_id = 70 order by id desc;
select * from business_processes where crm_configuration_id = 70 order by id desc;
select * from business_process_stages where business_process_id = 34;
select * from contacts where id = 10468;
select * from crm_layouts where crm_configuration_id = 70;
SELECT * FROM crm_layout_entities WHERE crm_layout_id = 388;
SELECT * FROM crm_fields WHERE id IN (3533,3534,3535);
select * from activities where crm_configuration_id = 70
and (account_id IS NOT NULL or lead_id IS NOT NULL or contact_id IS NOT NULL or opportunity_id IS NOT NULL) order by id desc;
SELECT * FROM activities WHERE uuid_to_bin('2e10b60f-8a61-41c5-a3d4-28835353dc65') = uuid;
SELECT * FROM activities where crm_configuration_id = 69 ;
SELECT * FROM users WHERE email LIKE '%[EMAIL]%';
SELECT * FROM activities WHERE uuid_to_bin('5a150c93-40fc-42ec-b3bd-c1d328e09f6e') = uuid;
SELECT * FROM opportunities WHERE id = 385;
select * from participants p
join activities a on p.activity_id = a.id
where a.crm_configuration_id = 70
and (p.lead_id IS NOT NULL or p.contact_id IS NOT NULL);
SELECT * FROM participants WHERE id = 1013638;
select * from teams where id = 90;
select * from users where team_id = 90;
select * from social_accounts where social_accounts.sociable_id IN (1960,1760);
SELECT * FROM crm_profiles WHERE crm_configuration_id = 71;
select * from invitations where team_id = 90;
select * from crm_configurations where id = 71;
select * from accounts where crm_configuration_id = 71 order by id desc;
select * from leads where crm_configuration_id = 71 order by id desc;
select * from contacts where crm_configuration_id = 71 order by id desc;
select * from opportunities where crm_configuration_id = 71 order by id desc;
select * from crm_profiles where crm_configuration_id = 71 order by id desc;
select * from crm_fields where crm_configuration_id = 71 order by id desc;
select * from crm_field_values where crm_field_id = 3341 order by id desc;
select * from crm_layouts where crm_configuration_id = 71 order by id desc;
select * from stages where crm_configuration_id = 71 order by id desc;
select * from users order by secondary_email desc;
select u.id, u.email, u.status, sa.id, sa.provider_user_id from social_accounts sa
join users u on sa.sociable_id = u.id
where sa.provider = 'google' and u.email LIKE 'aneliya%';
select * from failed_jobs order by id desc;
select * from users where email = '[EMAIL]' or secondary_email = '[EMAIL]';
select * from teams;
SELECT * FROM crm_profiles WHERE crm_configuration_id = 39;
SELECT * FROM crm_fields WHERE crm_configuration_id = 39 and object_type = 'task';
select * from social_accounts sa
join users u on sa.sociable_id = u.id
where u.team_id = 1
and sa.provider = 'salesforce';
# [PASSWORD_DOTS]
SELECT * FROM activities WHERE uuid_to_bin('c38b3895-fd0f-4b1f-9fb2-c170dba137c6') = uuid;
SELECT * FROM crm_configurations WHERE id = 70;
select * from teams where id = 1;
select * from groups where team_id = 1;
select * from users where team_id = 1;
select o.id, o.name,o.close_date, u.id, u.name, u.group_id, r.id, r.display_name, g.name, g.scope from opportunities o
join users u on o.user_id = u.id
join groups g on u.group_id = g.id
join role_user ru on u.id = ru.user_id
join roles r on ru.role_id = r.id
where o.crm_configuration_id = 39 and close_date > '2024-01-01 00:00:00';
select * from role_user where user_id = 143;
select * from roles;
select * from role_user;
select * from groups where id = 9;
select * from scope_groups where group_id = 9;
# [PASSWORD_DOTS]
select * from teams where id = 36;
select * from crm_configurations;
SELECT * FROM social_accounts WHERE sociable_id = 121;
[URL_WITH_CREDENTIALS] string
*/
protected $signature = 'automated-reports
{--report-id= : Process a specific report by ID or UUID (bypasses frequency scheduling)}';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Process automated reports based on their frequency (weekly, monthly, quarterly).
Use --report-id to manually trigger a specific report by ID or UUID.';
public function __construct(
private readonly LoggerInterface $logger,
private readonly BusDispatcher $dispatcher,
private readonly AutomatedReportsRepository $reportRepository
) {
parent::__construct();
}
/**
* Execute the console command.
*
* @return int
*/
public function handle(): int
{
$this->logger->info(self::LOG_PREFIX . ' Started');
$now = Carbon::now();
$isMonday = $now->isMonday();
$isFirstDayOfMonth = $now->day === 1;
$currentMonth = $now->month;
// Check if the current month is a quarterly month (January, April, July, October)
$isQuarterlyMonth = in_array($currentMonth, [1, 4, 7, 10], true);
$this->logger->info(self::LOG_PREFIX . ' Checking conditions', [
'isMonday' => $isMonday,
'isFirstDayOfMonth' => $isFirstDayOfMonth,
'currentMonth' => $currentMonth,
'isQuarterlyMonth' => $isQuarterlyMonth,
]);
// Process daily reports
$this->processReports(AutomatedReportsService::FREQUENCY_DAILY);
// Process weekly reports on Mondays
if ($isMonday) {
$this->processReports(AutomatedReportsService::FREQUENCY_WEEKLY);
}
// Process monthly reports on the first day of the month
if ($isFirstDayOfMonth) {
$this->processReports(AutomatedReportsService::FREQUENCY_MONTHLY);
}
// Process quarterly reports on the first day of January, April, July, and October
if ($isFirstDayOfMonth && $isQuarterlyMonth) {
$this->processReports(AutomatedReportsService::FREQUENCY_QUARTERLY);
}
$this->logger->info(self::LOG_PREFIX . ' Completed');
return 0;
}
/**
* Process reports for a specific frequency.
*
* @param string $frequency
*
* @return void
*/
private function processReports(string $frequency): void
{
$this->logger->info(self::LOG_PREFIX . " Processing $frequency reports");
$reportId = $this->option('report-id');
if ($reportId !== null) {
$reports = $this->getReportById($reportId);
} else {
// Get all enabled, not deleted reports with active teams for the specified frequency
$reports = $this->reportRepository->getActiveReportsByFrequency($frequency);
}
$this->logger->info(self::LOG_PREFIX . " Found {$reports->count()} $frequency reports to process");
/** @var AutomatedReport $report */
foreach ($reports as $report) {
$this->logger->info(self::LOG_PREFIX . ' Dispatching Generate Report job for report', [
'reportUuid' => $report->getUuid(),
'teamId' => $report->getTeamId(),
'frequency' => $report->getFrequency(),
'type' => $report->getType(),
]);
$job = $report->isAskJiminnyReport()
? new RequestGenerateAskJiminnyReportJob($report->getUuid())
: new RequestGenerateReportJob($report->getUuid());
$this->dispatcher->dispatch($job);
}
}
private function getReportById(string $reportId): Collection
{
$report = $this->reportRepository->findByIdOrUuid($reportId);
if ($report === null) {
$this->logger->warning(self::LOG_PREFIX . ' Report not found for --report-id', ['reportId' => $reportId]);
$this->warn("Report not found: {$reportId}");
return collect();
}
if (! $report->getStatus()) {
$this->logger->warning(self::LOG_PREFIX . ' Report is inactive, processing anyway (manual override)', [
'reportId' => $reportId,
'reportUuid' => $report->getUuid(),
]);
$this->warn('Report is inactive — processing anyway (manual override).');
}
$team = $report->getTeam();
if ($team->getStatus() !== Team::STATUS_ACTIVE) {
$this->logger->warning(self::LOG_PREFIX . ' Team is not active, processing anyway (manual override)', [
'reportId' => $reportId,
'reportUuid' => $report->getUuid(),
'teamId' => $report->getTeamId(),
'teamStatus' => $team->getStatus(),
]);
$this->warn("Team #{$report->getTeamId()} is not active — processing anyway (manual override).");
}
if ($report->isExpired()) {
$this->logger->warning(self::LOG_PREFIX . ' Report is expired, processing anyway (manual override)', [
'reportId' => $reportId,
'reportUuid' => $report->getUuid(),
'expiresAt' => $report->getExpiresAt()?->toDateString(),
]);
$this->warn('Report is expired (expires_at: ' . $report->getExpiresAt()?->toDateString() . ') — processing anyway (manual override).');
}
$this->info(self::LOG_PREFIX . ' Automated report found ' . $report->getCustomName());
return collect([$report]);
}
}
Project
Project
New File or Directory…
Expand Selected
Collapse All
Options
Hide...
|
NULL
|
|
12387
|
266
|
19
|
2026-04-14T11:17:02.600155+00:00
|
/Users/lukas/.screenpipe/data/data/2026-04-14/1776 /Users/lukas/.screenpipe/data/data/2026-04-14/1776165422600_m1.jpg...
|
Firefox
|
Jy 20541 stale records pr 1 by Vasil-Jiminny · Pul Jy 20541 stale records pr 1 by Vasil-Jiminny · Pull Request #11949 · jiminny/app — Work...
|
1
|
github.com/jiminny/app/pull/11949
|
monitor_1
|
NULL
|
NULL
|
NULL
|
NULL
|
Jy 20541 stale records pr 1 by Vasil-Jiminny · Pul Jy 20541 stale records pr 1 by Vasil-Jiminny · Pull Request #11949 · jiminny/app
github.com
JY-20543 add AJ reports User pilot tracking by LakyLak · Pull Request #11932 · jiminny/app
Pipelines - jiminny/app
Feed — jiminny — Sentry
Platform Sprint 1 Q2 - Platform Team - Scrum Board - Jira
Platform Sprint 1 Q2 - Platform Team - Scrum Board - Jira
JY-20543 add AJ reports User pilot tracking by LakyLak · Pull Request #11932 · jiminny/app
JY-20543 add AJ reports User pilot tracking by LakyLak · Pull Request #11932 · jiminny/app
Configure SSH access to multiple environment - Engineering - Confluence
Configure SSH access to multiple environment - Engineering - Confluence
Console Home | Console Home | us-east-2
Console Home | Console Home | us-east-2
SecurityGroup | EC2 | us-east-2
SecurityGroup | EC2 | us-east-2
JY-20543 add AJ reports User pilot tracking by LakyLak · Pull Request #11932 · jiminny/app
JY-20543 add AJ reports User pilot tracking by LakyLak · Pull Request #11932 · jiminny/app
SRD-6779 | JY-20632 | Unable to log in to Sidekick with SSO by yalokin-jiminny · Pull Request #11935 · jiminny/app
SRD-6779 | JY-20632 | Unable to log in to Sidekick with SSO by yalokin-jiminny · Pull Request #11935 · jiminny/app
Jy 19798 evaluation for ai activity types by nikolaybiaivanov · Pull Request #468 · jiminny/prophet
Jy 19798 evaluation for ai activity types by nikolaybiaivanov · Pull Request #468 · jiminny/prophet
Jiminny
Jiminny
Ask Jiminny test report - 8 Apr 2026 - Ask Jiminny test report - 13 Apr 2026.pdf
Ask Jiminny test report - 8 Apr 2026 - Ask Jiminny test report - 13 Apr 2026.pdf
Service-Desk - Queues - Platform team - Service space - Jira
Service-Desk - Queues - Platform team - Service space - Jira
JY-20543 add AJ reports User pilot tracking by LakyLak · Pull Request #11932 · jiminny/app
JY-20543 add AJ reports User pilot tracking by LakyLak · Pull Request #11932 · jiminny/app
Configure SSH access to multiple environment - Engineering - Confluence
Configure SSH access to multiple environment - Engineering - Confluence
New Tab
New Tab
CloudWatch | us-east-2
CloudWatch | us-east-2
Jy 20541 stale records pr 1 by Vasil-Jiminny · Pull Request #11949 · jiminny/app
Jy 20541 stale records pr 1 by Vasil-Jiminny · Pull Request #11949 · jiminny/app
Close tab
New Tab
Customize sidebar
Open Google Gemini (⌃X)
Tabs from other devices
Open history (⇧⌘H)
Open bookmarks (⌘B)
Skip to content
Skip to content
Open menu
Homepage (g then d)
jiminny
jiminny
app
app
Search or jump to…
Type
/
to search
Chat with Copilot
Open Copilot…
Create new...
Issues(g then i)
Pull requests
Repositories
You have unread notifications(g then n)
Open user navigation menu
Repository navigation
Repository navigation
Code
Code...
|
[{"role":"AXStaticText","text& [{"role":"AXStaticText","text":"Jy 20541 stale records pr 1 by Vasil-Jiminny · Pull Request #11949 · jiminny/app","depth":4,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"github.com","depth":4,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"JY-20543 add AJ reports User pilot tracking by LakyLak · Pull Request #11932 · jiminny/app","depth":4,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXRadioButton","text":"Pipelines - jiminny/app","depth":4,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXRadioButton","text":"Feed — jiminny — Sentry","depth":4,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXRadioButton","text":"Platform Sprint 1 Q2 - Platform Team - Scrum Board - Jira","depth":4,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Platform Sprint 1 Q2 - Platform Team - Scrum Board - Jira","depth":5,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"JY-20543 add AJ reports User pilot tracking by LakyLak · Pull Request #11932 · jiminny/app","depth":4,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"JY-20543 add AJ reports User pilot tracking by LakyLak · Pull Request #11932 · jiminny/app","depth":5,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Configure SSH access to multiple environment - Engineering - Confluence","depth":4,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Configure SSH access to multiple environment - Engineering - Confluence","depth":5,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Console Home | Console Home | us-east-2","depth":4,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Console Home | Console Home | us-east-2","depth":5,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"SecurityGroup | EC2 | us-east-2","depth":4,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"SecurityGroup | EC2 | us-east-2","depth":5,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"JY-20543 add AJ reports User pilot tracking by LakyLak · Pull Request #11932 · jiminny/app","depth":4,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"JY-20543 add AJ reports User pilot tracking by LakyLak · Pull Request #11932 · jiminny/app","depth":5,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"SRD-6779 | JY-20632 | Unable to log in to Sidekick with SSO by yalokin-jiminny · Pull Request #11935 · jiminny/app","depth":4,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"SRD-6779 | JY-20632 | Unable to log in to Sidekick with SSO by yalokin-jiminny · Pull Request #11935 · jiminny/app","depth":5,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Jy 19798 evaluation for ai activity types by nikolaybiaivanov · Pull Request #468 · jiminny/prophet","depth":4,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Jy 19798 evaluation for ai activity types by nikolaybiaivanov · Pull Request #468 · jiminny/prophet","depth":5,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Jiminny","depth":4,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Jiminny","depth":5,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Ask Jiminny test report - 8 Apr 2026 - Ask Jiminny test report - 13 Apr 2026.pdf","depth":4,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Ask Jiminny test report - 8 Apr 2026 - Ask Jiminny test report - 13 Apr 2026.pdf","depth":5,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Service-Desk - Queues - Platform team - Service space - Jira","depth":4,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Service-Desk - Queues - Platform team - Service space - Jira","depth":5,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"JY-20543 add AJ reports User pilot tracking by LakyLak · Pull Request #11932 · jiminny/app","depth":4,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"JY-20543 add AJ reports User pilot tracking by LakyLak · Pull Request #11932 · jiminny/app","depth":5,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Configure SSH access to multiple environment - Engineering - Confluence","depth":4,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Configure SSH access to multiple environment - Engineering - Confluence","depth":5,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"New Tab","depth":4,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"New Tab","depth":5,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"CloudWatch | us-east-2","depth":4,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"CloudWatch | us-east-2","depth":5,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Jy 20541 stale records pr 1 by Vasil-Jiminny · Pull Request #11949 · jiminny/app","depth":4,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":true},{"role":"AXStaticText","text":"Jy 20541 stale records pr 1 by Vasil-Jiminny · Pull Request #11949 · jiminny/app","depth":5,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"Close tab","depth":5,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXButton","text":"New Tab","depth":4,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXCheckBox","text":"Customize sidebar","depth":6,"help_text":"","role_description":"toggle button","subrole":"AXToggle","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXCheckBox","text":"Open Google Gemini (⌃X)","depth":6,"help_text":"","role_description":"toggle button","subrole":"AXToggle","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXCheckBox","text":"Tabs from other devices","depth":6,"help_text":"","role_description":"toggle button","subrole":"AXToggle","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXCheckBox","text":"Open history (⇧⌘H)","depth":6,"help_text":"","role_description":"toggle button","subrole":"AXToggle","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXCheckBox","text":"Open bookmarks (⌘B)","depth":6,"help_text":"","role_description":"toggle button","subrole":"AXToggle","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXLink","text":"Skip to content","depth":6,"help_text":"","role_description":"link","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Skip to content","depth":7,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"Open menu","depth":10,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXLink","text":"Homepage (g then d)","depth":9,"help_text":"","role_description":"link","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXLink","text":"jiminny","depth":12,"help_text":"","role_description":"link","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"jiminny","depth":14,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXLink","text":"app","depth":12,"help_text":"","role_description":"link","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"app","depth":14,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"Search or jump to…","depth":9,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Type","depth":12,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"/","depth":12,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"to search","depth":12,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXLink","text":"Chat with Copilot","depth":10,"help_text":"","role_description":"link","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXMenuButton","text":"Open Copilot…","depth":9,"help_text":"","role_description":"menu button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXMenuButton","text":"Create new...","depth":9,"help_text":"","role_description":"menu button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXLink","text":"Issues(g then i)","depth":9,"help_text":"","role_description":"link","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXLink","text":"Pull requests","depth":9,"help_text":"","role_description":"link","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXLink","text":"Repositories","depth":9,"help_text":"","role_description":"link","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXLink","text":"You have unread notifications(g then n)","depth":9,"help_text":"","role_description":"link","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXButton","text":"Open user navigation menu","depth":9,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXHeading","text":"Repository navigation","depth":9,"help_text":"","role_description":"heading","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Repository navigation","depth":10,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXLink","text":"Code","depth":12,"help_text":"","role_description":"link","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Code","depth":14,"help_text":"","role_description":"text","subrole":"AXUnknown"}]...
|
6307773681856598013
|
1663325387176540878
|
visual_change
|
accessibility
|
NULL
|
Jy 20541 stale records pr 1 by Vasil-Jiminny · Pul Jy 20541 stale records pr 1 by Vasil-Jiminny · Pull Request #11949 · jiminny/app
github.com
JY-20543 add AJ reports User pilot tracking by LakyLak · Pull Request #11932 · jiminny/app
Pipelines - jiminny/app
Feed — jiminny — Sentry
Platform Sprint 1 Q2 - Platform Team - Scrum Board - Jira
Platform Sprint 1 Q2 - Platform Team - Scrum Board - Jira
JY-20543 add AJ reports User pilot tracking by LakyLak · Pull Request #11932 · jiminny/app
JY-20543 add AJ reports User pilot tracking by LakyLak · Pull Request #11932 · jiminny/app
Configure SSH access to multiple environment - Engineering - Confluence
Configure SSH access to multiple environment - Engineering - Confluence
Console Home | Console Home | us-east-2
Console Home | Console Home | us-east-2
SecurityGroup | EC2 | us-east-2
SecurityGroup | EC2 | us-east-2
JY-20543 add AJ reports User pilot tracking by LakyLak · Pull Request #11932 · jiminny/app
JY-20543 add AJ reports User pilot tracking by LakyLak · Pull Request #11932 · jiminny/app
SRD-6779 | JY-20632 | Unable to log in to Sidekick with SSO by yalokin-jiminny · Pull Request #11935 · jiminny/app
SRD-6779 | JY-20632 | Unable to log in to Sidekick with SSO by yalokin-jiminny · Pull Request #11935 · jiminny/app
Jy 19798 evaluation for ai activity types by nikolaybiaivanov · Pull Request #468 · jiminny/prophet
Jy 19798 evaluation for ai activity types by nikolaybiaivanov · Pull Request #468 · jiminny/prophet
Jiminny
Jiminny
Ask Jiminny test report - 8 Apr 2026 - Ask Jiminny test report - 13 Apr 2026.pdf
Ask Jiminny test report - 8 Apr 2026 - Ask Jiminny test report - 13 Apr 2026.pdf
Service-Desk - Queues - Platform team - Service space - Jira
Service-Desk - Queues - Platform team - Service space - Jira
JY-20543 add AJ reports User pilot tracking by LakyLak · Pull Request #11932 · jiminny/app
JY-20543 add AJ reports User pilot tracking by LakyLak · Pull Request #11932 · jiminny/app
Configure SSH access to multiple environment - Engineering - Confluence
Configure SSH access to multiple environment - Engineering - Confluence
New Tab
New Tab
CloudWatch | us-east-2
CloudWatch | us-east-2
Jy 20541 stale records pr 1 by Vasil-Jiminny · Pull Request #11949 · jiminny/app
Jy 20541 stale records pr 1 by Vasil-Jiminny · Pull Request #11949 · jiminny/app
Close tab
New Tab
Customize sidebar
Open Google Gemini (⌃X)
Tabs from other devices
Open history (⇧⌘H)
Open bookmarks (⌘B)
Skip to content
Skip to content
Open menu
Homepage (g then d)
jiminny
jiminny
app
app
Search or jump to…
Type
/
to search
Chat with Copilot
Open Copilot…
Create new...
Issues(g then i)
Pull requests
Repositories
You have unread notifications(g then n)
Open user navigation menu
Repository navigation
Repository navigation
Code
Code...
|
12385
|
|
12388
|
266
|
20
|
2026-04-14T11:17:06.106612+00:00
|
/Users/lukas/.screenpipe/data/data/2026-04-14/1776 /Users/lukas/.screenpipe/data/data/2026-04-14/1776165426106_m1.jpg...
|
NULL
|
NULL
|
1
|
NULL
|
monitor_1
|
NULL
|
NULL
|
NULL
|
NULL
|
SlackFile Edit ViewGoHistoryWindowHelpec2-userGDOC SlackFile Edit ViewGoHistoryWindowHelpec2-userGDOCKER2881DEV (docker)882APP (-zsh)[EMAIL]@73b64f5d54a3:/home/jiminny#[ec2-user@ip-10-30-93-249~]$ dockerexec -it $(dockny && bash"root@c78a087b1345:/home/Jiminny# php artisan automated-reports[2026-04-14 10:46:08] staging.INF0: [automated-reports] Started{"correlation_id":"5[2026-04-1410:46:08Jstaging. INFO: [automated-reports]id":"5c23e861-2ca9-4f92-9f67-773d6bc80ca0"Checking conditions {"isMonda,"trace_id" :"185df6f6-4327-4609-9c2e-2ab83a[2026-04-14 10:46:08]staging.INFO: [automated-reports] Processing daily reports {"cab83a0f5432"}[2026-04-1410:46:08]9-9c2e-2ab83a0f5432"}staging.INFO: [automated-reports]Found 3 daily reports to proc[2026-04-1410:46:087daily"staging.INFO: [automated-reports]Dispatching Generate Report j,"type":"ask_jiminny"} {"correlation_id":"5c23e861-2ca9-4f92-9f67-773d6bc80ca0"[2026-04-14 10:46:08]staging.INFO: [automated-reports]Dispatching Generate Report jdaily", "type": "ask_jiminny"} {"correlation_id":"5c23e861-2ca9-4f92-9f67-773d6bc80cab"[2026-04-14 10:46:08]staging. INFO: [automated-reports]daily'", "type" "ask-fiminny"'} ("correlation-id' : 5c2se861-2ca -4792-9f87-773 Be8oca[2026-04-14 10:46:08]staging.INFO: [automated-reports]Completed{"correlation_id":root@c78a087b1345:/home/jiminny# phpartisanautomated-reports --report-id 35[2026-04-14 10:48:42] staging.INFO: [automated-reports]{"correlation_id":"2[2026-04-14 10:48:42]staging.INFO: [automated-reports]Checking conditions {"isMondaid":"246a1ala-7076-458c-bd7d-49d2f5a2db88","trace_id":"1f894bf6-e50d-4e99-b635-2aa526[2026-04-14 10:48:42]staging.INFO: [automated-reports]Processing daily reports{"caa52627fc27"}[automated-reports] Automated report[2026-04-14 10:48:42]staging.INFO: [automated-reports] Found 1 daily reports to proc9-b635-2aa52627f c27"}[2026-04-14 10:48:42]staging.INF0: [automated-reports]Dispatching Generate Report jdaily","type": "ask_jiminny"} {"correlation_id":"246a1a1a-7076-458c-bd7d-49d2f5a2db88"[2026-04-14 10:48:42]staging.INFO: [automated-reports]Completed{"correlation_id":root@c78a087b1345:/home/jiminny# [ec2-user@ip-10-30-93-249 ~]$I+EDHomeDMsActivityFilesLater.*•MoreallJiminny ...+tscnicrel# infra-changes# jiminny-bg# platform-tickets# product_launches# random# releases# sofia-office# support# thank-yous# the_people_of jimi...Direct messagesVasil VasilevAneliya Angelova, ...Steliyan GeorgievAdelina Petrova, Ili...0. Adelina Petrova. Galya Dimitrova *Rs Nikolay Nikolov "2 Galya Dimitrova, Ni...2Galya Dimitrova, Ni...P. Nikolay Yankov::: AppsJira CloudToastGoogle Cale...• Support Daily • in 43 m100% <47Tue 14 Apr 14:17:05→Search Jiminny Inc<Thread Direct message with 3 othersвчера, не днес• и имейл не дойдеimage.pngSOV• с в5 repliesLukas Kovalik 18 minutes agoза дата там не знам как искаме да го правим.по принцип при всички други се гледа ден назад при положение че идва през нощта.Nikolay Yankov 18 minutes ago@Lukas Kovalik видя ли този коментарLukas Kovalik 18 minutes agoдаNikolay Yankov 17 minutes agoне е ли датата на която е генерирано? (edited)Lukas Kovalik 17 minutes agoemail ще го видяReply...Also send to the group+•*•...
|
NULL
|
-9200556002098578442
|
NULL
|
click
|
ocr
|
NULL
|
SlackFile Edit ViewGoHistoryWindowHelpec2-userGDOC SlackFile Edit ViewGoHistoryWindowHelpec2-userGDOCKER2881DEV (docker)882APP (-zsh)[EMAIL]@73b64f5d54a3:/home/jiminny#[ec2-user@ip-10-30-93-249~]$ dockerexec -it $(dockny && bash"root@c78a087b1345:/home/Jiminny# php artisan automated-reports[2026-04-14 10:46:08] staging.INF0: [automated-reports] Started{"correlation_id":"5[2026-04-1410:46:08Jstaging. INFO: [automated-reports]id":"5c23e861-2ca9-4f92-9f67-773d6bc80ca0"Checking conditions {"isMonda,"trace_id" :"185df6f6-4327-4609-9c2e-2ab83a[2026-04-14 10:46:08]staging.INFO: [automated-reports] Processing daily reports {"cab83a0f5432"}[2026-04-1410:46:08]9-9c2e-2ab83a0f5432"}staging.INFO: [automated-reports]Found 3 daily reports to proc[2026-04-1410:46:087daily"staging.INFO: [automated-reports]Dispatching Generate Report j,"type":"ask_jiminny"} {"correlation_id":"5c23e861-2ca9-4f92-9f67-773d6bc80ca0"[2026-04-14 10:46:08]staging.INFO: [automated-reports]Dispatching Generate Report jdaily", "type": "ask_jiminny"} {"correlation_id":"5c23e861-2ca9-4f92-9f67-773d6bc80cab"[2026-04-14 10:46:08]staging. INFO: [automated-reports]daily'", "type" "ask-fiminny"'} ("correlation-id' : 5c2se861-2ca -4792-9f87-773 Be8oca[2026-04-14 10:46:08]staging.INFO: [automated-reports]Completed{"correlation_id":root@c78a087b1345:/home/jiminny# phpartisanautomated-reports --report-id 35[2026-04-14 10:48:42] staging.INFO: [automated-reports]{"correlation_id":"2[2026-04-14 10:48:42]staging.INFO: [automated-reports]Checking conditions {"isMondaid":"246a1ala-7076-458c-bd7d-49d2f5a2db88","trace_id":"1f894bf6-e50d-4e99-b635-2aa526[2026-04-14 10:48:42]staging.INFO: [automated-reports]Processing daily reports{"caa52627fc27"}[automated-reports] Automated report[2026-04-14 10:48:42]staging.INFO: [automated-reports] Found 1 daily reports to proc9-b635-2aa52627f c27"}[2026-04-14 10:48:42]staging.INF0: [automated-reports]Dispatching Generate Report jdaily","type": "ask_jiminny"} {"correlation_id":"246a1a1a-7076-458c-bd7d-49d2f5a2db88"[2026-04-14 10:48:42]staging.INFO: [automated-reports]Completed{"correlation_id":root@c78a087b1345:/home/jiminny# [ec2-user@ip-10-30-93-249 ~]$I+EDHomeDMsActivityFilesLater.*•MoreallJiminny ...+tscnicrel# infra-changes# jiminny-bg# platform-tickets# product_launches# random# releases# sofia-office# support# thank-yous# the_people_of jimi...Direct messagesVasil VasilevAneliya Angelova, ...Steliyan GeorgievAdelina Petrova, Ili...0. Adelina Petrova. Galya Dimitrova *Rs Nikolay Nikolov "2 Galya Dimitrova, Ni...2Galya Dimitrova, Ni...P. Nikolay Yankov::: AppsJira CloudToastGoogle Cale...• Support Daily • in 43 m100% <47Tue 14 Apr 14:17:05→Search Jiminny Inc<Thread Direct message with 3 othersвчера, не днес• и имейл не дойдеimage.pngSOV• с в5 repliesLukas Kovalik 18 minutes agoза дата там не знам как искаме да го правим.по принцип при всички други се гледа ден назад при положение че идва през нощта.Nikolay Yankov 18 minutes ago@Lukas Kovalik видя ли този коментарLukas Kovalik 18 minutes agoдаNikolay Yankov 17 minutes agoне е ли датата на която е генерирано? (edited)Lukas Kovalik 17 minutes agoemail ще го видяReply...Also send to the group+•*•...
|
NULL
|
|
12391
|
266
|
21
|
2026-04-14T11:17:09.609428+00:00
|
/Users/lukas/.screenpipe/data/data/2026-04-14/1776 /Users/lukas/.screenpipe/data/data/2026-04-14/1776165429609_m1.jpg...
|
Firefox
|
Jiminny — Work
|
1
|
app.staging.jiminny.com/ai-reports
|
monitor_1
|
NULL
|
NULL
|
NULL
|
NULL
|
JY-20543 add AJ reports User pilot tracking by Lak JY-20543 add AJ reports User pilot tracking by LakyLak · Pull Request #11932 · jiminny/app
Pipelines - jiminny/app
Feed — jiminny — Sentry...
|
[{"role":"AXRadioButton","text [{"role":"AXRadioButton","text":"JY-20543 add AJ reports User pilot tracking by LakyLak · Pull Request #11932 · jiminny/app","depth":4,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXRadioButton","text":"Pipelines - jiminny/app","depth":4,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXRadioButton","text":"Feed — jiminny — Sentry","depth":4,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false}]...
|
7187893506249116441
|
-5326259022255830641
|
click
|
hybrid
|
NULL
|
JY-20543 add AJ reports User pilot tracking by Lak JY-20543 add AJ reports User pilot tracking by LakyLak · Pull Request #11932 · jiminny/app
Pipelines - jiminny/app
Feed — jiminny — Sentry
SlackHileEdit ViewGoHistoryWindowHelpec2-userGDOCKER981DEV (docker)882APP (-zsh)[EMAIL]@73b64f5d54a3:/home/jiminny#[ec2-user@ip-10-30-93-249~]$ dockerexec -it $(dockny && bash"root@c78a087b1345:/home/Jiminny# php artisan automated-reports[2026-04-14 10:46:08] staging.INF0: [automated-reports] Started{"correlation_id":"5[2026-04-1410:46:08Jstaging. INFO: [automated-reports]id":"5c23e861-2ca9-4f92-9f67-773d6bc80ca0"Checking conditions {"isMonda,"trace_id" :"185df6f6-4327-4609-9c2e-2ab83a[2026-04-14 10:46:08]staging.INFO: [automated-reports] Processing daily reports {"cab83a0f5432"}[2026-04-1410:46:08]9-9c2e-2ab83a0f5432"}staging.INFO: [automated-reports]Found 3 daily reports to proc[2026-04-1410:46:087daily"staging.INFO: [automated-reports]Dispatching Generate Report j,"type":"ask_jiminny"} {"correlation_id":"5c23e861-2ca9-4f92-9f67-773d6bc80ca0"[2026-04-14 10:46:08]staging.INFO: [automated-reports]Dispatching Generate Report jdaily", "type": "ask_jiminny"} {"correlation_id":"5c23e861-2ca9-4f92-9f67-773d6bc80cab"[2026-04-14 10:46:08]staging. INFO: [automated-reports]daily'", "type" "ask-fiminny"'} ("correlation-id' : 5c2se861-2ca -4792-9f87-773 Be8oca[2026-04-14 10:46:08]staging.INFO: [automated-reports]Completed{"correlation_id":root@c78a087b1345:/home/jiminny# phpartisanautomated-reports --report-id 35[2026-04-14 10:48:42] staging.INFO: [automated-reports]{"correlation_id":"2[2026-04-14 10:48:42]staging.INFO: [automated-reports]Checking conditions {"isMondaid":"246a1ala-7076-458c-bd7d-49d2f5a2db88","trace_id":"1f894bf6-e50d-4e99-b635-2aa526[2026-04-14 10:48:42]staging.INFO: [automated-reports]Processing daily reports{"caa52627fc27"}[automated-reports] Automated report[2026-04-14 10:48:42]staging.INFO: [automated-reports] Found 1 daily reports to proc9-b635-2aa52627f c27"}[2026-04-14 10:48:42]staging.INF0: [automated-reports]Dispatching Generate Report jdaily","type": "ask_jiminny"} {"correlation_id":"246a1a1a-7076-458c-bd7d-49d2f5a2db88"[2026-04-14 10:48:42]staging.INFO: [automated-reports]Completed{"correlation_id":root@c78a087b1345:/home/jiminny# [ec2-user@ip-10-30-93-249 ~]$I+EDHomeDMsActivityFilesLater.*•MoreallJiminny ...+tscnicrel# infra-changes# jiminny-bg# platform-tickets# product_launches# random# releases# sofia-office# support# thank-yous# the_people_of jimi...Direct messagesVasil VasilevAneliya Angelova, ...Steliyan GeorgievAdelina Petrova, Ili...0. Adelina Petrova. Galya Dimitrova *Rs Nikolay Nikolov "2 Galya Dimitrova, Ni...2Galya Dimitrova, Ni...P. Nikolay Yankov::: AppsJira CloudToastGoogle Cale...• Support Daily • in 43 m100% <47Tue 14 Apr 14:17:09→Search Jiminny Inc<Thread Direct message with 3 othersвчера, не днес• и имейл не дойдеimage.pngSOV• с в5 repliesLukas Kovalik 18 minutes agoза дата там не знам как искаме да го правим.по принцип при всички други се гледа ден назад при положение че идва през нощта.Nikolay Yankov 18 minutes ago@Lukas Kovalik видя ли този коментарLukas Kovalik 18 minutes agoдаNikolay Yankov 17 minutes agoне е ли датата на която е генерирано? (edited)Lukas Kovalik 17 minutes agoemail ще го видяReply...Also send to the group+•*•...
|
12388
|
|
12398
|
266
|
22
|
2026-04-14T11:17:41.575171+00:00
|
/Users/lukas/.screenpipe/data/data/2026-04-14/1776 /Users/lukas/.screenpipe/data/data/2026-04-14/1776165461575_m1.jpg...
|
Firefox
|
Jiminny — Work
|
1
|
app.staging.jiminny.com/kiosk/users?id=c4fb084a-b3 app.staging.jiminny.com/kiosk/users?id=c4fb084a-b33a-46fe-904b-351b592a4b0f...
|
monitor_1
|
NULL
|
NULL
|
NULL
|
NULL
|
JY-20543 add AJ reports User pilot tracking by Lak JY-20543 add AJ reports User pilot tracking by LakyLak · Pull Request #11932 · jiminny/app
Pipelines - jiminny/app
Feed — jiminny — Sentry
Platform Sprint 1 Q2 - Platform Team - Scrum Board - Jira
Platform Sprint 1 Q2 - Platform Team - Scrum Board - Jira
JY-20543 add AJ reports User pilot tracking by LakyLak · Pull Request #11932 · jiminny/app
JY-20543 add AJ reports User pilot tracking by LakyLak · Pull Request #11932 · jiminny/app
Configure SSH access to multiple environment - Engineering - Confluence
Configure SSH access to multiple environment - Engineering - Confluence
Console Home | Console Home | us-east-2
Console Home | Console Home | us-east-2
SecurityGroup | EC2 | us-east-2
SecurityGroup | EC2 | us-east-2
JY-20543 add AJ reports User pilot tracking by LakyLak · Pull Request #11932 · jiminny/app
JY-20543 add AJ reports User pilot tracking by LakyLak · Pull Request #11932 · jiminny/app
SRD-6779 | JY-20632 | Unable to log in to Sidekick with SSO by yalokin-jiminny · Pull Request #11935 · jiminny/app
SRD-6779 | JY-20632 | Unable to log in to Sidekick with SSO by yalokin-jiminny · Pull Request #11935 · jiminny/app
Jy 19798 evaluation for ai activity types by nikolaybiaivanov · Pull Request #468 · jiminny/prophet
Jy 19798 evaluation for ai activity types by nikolaybiaivanov · Pull Request #468 · jiminny/prophet
Jiminny
Jiminny
Close tab
Ask Jiminny test report - 8 Apr 2026 - Ask Jiminny test report - 13 Apr 2026.pdf
Ask Jiminny test report - 8 Apr 2026 - Ask Jiminny test report - 13 Apr 2026.pdf
Service-Desk - Queues - Platform team - Service space - Jira
Service-Desk - Queues - Platform team - Service space - Jira
JY-20543 add AJ reports User pilot tracking by LakyLak · Pull Request #11932 · jiminny/app
JY-20543 add AJ reports User pilot tracking by LakyLak · Pull Request #11932 · jiminny/app
Configure SSH access to multiple environment - Engineering - Confluence
Configure SSH access to multiple environment - Engineering - Confluence
New Tab
New Tab
CloudWatch | us-east-2
CloudWatch | us-east-2
Jy 20541 stale records pr 1 by Vasil-Jiminny · Pull Request #11949 · jiminny/app
Jy 20541 stale records pr 1 by Vasil-Jiminny · Pull Request #11949 · jiminny/app
New Tab
Customize sidebar
Open Google Gemini (⌃X)
Tabs from other devices
Open history (⇧⌘H)
Open bookmarks (⌘B)
JY-18909-automated-reports-ask-jiminny ■ 869909
75
75
Kiosk
Organizations
Organizations
Setup Account
Setup Account
Users
Users
Activities
Activities
Automated Reports
Automated Reports
Mobile version
Mobile version...
|
[{"role":"AXRadioButton","text [{"role":"AXRadioButton","text":"JY-20543 add AJ reports User pilot tracking by LakyLak · Pull Request #11932 · jiminny/app","depth":4,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXRadioButton","text":"Pipelines - jiminny/app","depth":4,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXRadioButton","text":"Feed — jiminny — Sentry","depth":4,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXRadioButton","text":"Platform Sprint 1 Q2 - Platform Team - Scrum Board - Jira","depth":4,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Platform Sprint 1 Q2 - Platform Team - Scrum Board - Jira","depth":5,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"JY-20543 add AJ reports User pilot tracking by LakyLak · Pull Request #11932 · jiminny/app","depth":4,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"JY-20543 add AJ reports User pilot tracking by LakyLak · Pull Request #11932 · jiminny/app","depth":5,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Configure SSH access to multiple environment - Engineering - Confluence","depth":4,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Configure SSH access to multiple environment - Engineering - Confluence","depth":5,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Console Home | Console Home | us-east-2","depth":4,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Console Home | Console Home | us-east-2","depth":5,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"SecurityGroup | EC2 | us-east-2","depth":4,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"SecurityGroup | EC2 | us-east-2","depth":5,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"JY-20543 add AJ reports User pilot tracking by LakyLak · Pull Request #11932 · jiminny/app","depth":4,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"JY-20543 add AJ reports User pilot tracking by LakyLak · Pull Request #11932 · jiminny/app","depth":5,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"SRD-6779 | JY-20632 | Unable to log in to Sidekick with SSO by yalokin-jiminny · Pull Request #11935 · jiminny/app","depth":4,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"SRD-6779 | JY-20632 | Unable to log in to Sidekick with SSO by yalokin-jiminny · Pull Request #11935 · jiminny/app","depth":5,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Jy 19798 evaluation for ai activity types by nikolaybiaivanov · Pull Request #468 · jiminny/prophet","depth":4,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Jy 19798 evaluation for ai activity types by nikolaybiaivanov · Pull Request #468 · jiminny/prophet","depth":5,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Jiminny","depth":4,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":true},{"role":"AXStaticText","text":"Jiminny","depth":5,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"Close tab","depth":5,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXRadioButton","text":"Ask Jiminny test report - 8 Apr 2026 - Ask Jiminny test report - 13 Apr 2026.pdf","depth":4,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Ask Jiminny test report - 8 Apr 2026 - Ask Jiminny test report - 13 Apr 2026.pdf","depth":5,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Service-Desk - Queues - Platform team - Service space - Jira","depth":4,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Service-Desk - Queues - Platform team - Service space - Jira","depth":5,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"JY-20543 add AJ reports User pilot tracking by LakyLak · Pull Request #11932 · jiminny/app","depth":4,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"JY-20543 add AJ reports User pilot tracking by LakyLak · Pull Request #11932 · jiminny/app","depth":5,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Configure SSH access to multiple environment - Engineering - Confluence","depth":4,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Configure SSH access to multiple environment - Engineering - Confluence","depth":5,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"New Tab","depth":4,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"New Tab","depth":5,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"CloudWatch | us-east-2","depth":4,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"CloudWatch | us-east-2","depth":5,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXRadioButton","text":"Jy 20541 stale records pr 1 by Vasil-Jiminny · Pull Request #11949 · jiminny/app","depth":4,"help_text":"","role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Jy 20541 stale records pr 1 by Vasil-Jiminny · Pull Request #11949 · jiminny/app","depth":5,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"New Tab","depth":4,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXCheckBox","text":"Customize sidebar","depth":6,"help_text":"","role_description":"toggle button","subrole":"AXToggle","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXCheckBox","text":"Open Google Gemini (⌃X)","depth":6,"help_text":"","role_description":"toggle button","subrole":"AXToggle","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXCheckBox","text":"Tabs from other devices","depth":6,"help_text":"","role_description":"toggle button","subrole":"AXToggle","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXCheckBox","text":"Open history (⇧⌘H)","depth":6,"help_text":"","role_description":"toggle button","subrole":"AXToggle","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXCheckBox","text":"Open bookmarks (⌘B)","depth":6,"help_text":"","role_description":"toggle button","subrole":"AXToggle","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"JY-18909-automated-reports-ask-jiminny ■ 869909","depth":9,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXButton","text":"75","depth":12,"help_text":"","role_description":"button","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"75","depth":14,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXStaticText","text":"Kiosk","depth":15,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXLink","text":"Organizations","depth":15,"help_text":"","role_description":"link","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Organizations","depth":16,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXLink","text":"Setup Account","depth":15,"help_text":"","role_description":"link","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Setup Account","depth":16,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXLink","text":"Users","depth":15,"help_text":"","role_description":"link","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Users","depth":16,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXLink","text":"Activities","depth":15,"help_text":"","role_description":"link","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Activities","depth":16,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXLink","text":"Automated Reports","depth":15,"help_text":"","role_description":"link","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Automated Reports","depth":16,"help_text":"","role_description":"text","subrole":"AXUnknown"},{"role":"AXLink","text":"Mobile version","depth":15,"help_text":"","role_description":"link","subrole":"AXUnknown","is_enabled":true,"is_focused":false,"is_selected":false},{"role":"AXStaticText","text":"Mobile version","depth":16,"help_text":"","role_description":"text","subrole":"AXUnknown"}]...
|
3891616149679273536
|
1519773153617509070
|
idle
|
accessibility
|
NULL
|
JY-20543 add AJ reports User pilot tracking by Lak JY-20543 add AJ reports User pilot tracking by LakyLak · Pull Request #11932 · jiminny/app
Pipelines - jiminny/app
Feed — jiminny — Sentry
Platform Sprint 1 Q2 - Platform Team - Scrum Board - Jira
Platform Sprint 1 Q2 - Platform Team - Scrum Board - Jira
JY-20543 add AJ reports User pilot tracking by LakyLak · Pull Request #11932 · jiminny/app
JY-20543 add AJ reports User pilot tracking by LakyLak · Pull Request #11932 · jiminny/app
Configure SSH access to multiple environment - Engineering - Confluence
Configure SSH access to multiple environment - Engineering - Confluence
Console Home | Console Home | us-east-2
Console Home | Console Home | us-east-2
SecurityGroup | EC2 | us-east-2
SecurityGroup | EC2 | us-east-2
JY-20543 add AJ reports User pilot tracking by LakyLak · Pull Request #11932 · jiminny/app
JY-20543 add AJ reports User pilot tracking by LakyLak · Pull Request #11932 · jiminny/app
SRD-6779 | JY-20632 | Unable to log in to Sidekick with SSO by yalokin-jiminny · Pull Request #11935 · jiminny/app
SRD-6779 | JY-20632 | Unable to log in to Sidekick with SSO by yalokin-jiminny · Pull Request #11935 · jiminny/app
Jy 19798 evaluation for ai activity types by nikolaybiaivanov · Pull Request #468 · jiminny/prophet
Jy 19798 evaluation for ai activity types by nikolaybiaivanov · Pull Request #468 · jiminny/prophet
Jiminny
Jiminny
Close tab
Ask Jiminny test report - 8 Apr 2026 - Ask Jiminny test report - 13 Apr 2026.pdf
Ask Jiminny test report - 8 Apr 2026 - Ask Jiminny test report - 13 Apr 2026.pdf
Service-Desk - Queues - Platform team - Service space - Jira
Service-Desk - Queues - Platform team - Service space - Jira
JY-20543 add AJ reports User pilot tracking by LakyLak · Pull Request #11932 · jiminny/app
JY-20543 add AJ reports User pilot tracking by LakyLak · Pull Request #11932 · jiminny/app
Configure SSH access to multiple environment - Engineering - Confluence
Configure SSH access to multiple environment - Engineering - Confluence
New Tab
New Tab
CloudWatch | us-east-2
CloudWatch | us-east-2
Jy 20541 stale records pr 1 by Vasil-Jiminny · Pull Request #11949 · jiminny/app
Jy 20541 stale records pr 1 by Vasil-Jiminny · Pull Request #11949 · jiminny/app
New Tab
Customize sidebar
Open Google Gemini (⌃X)
Tabs from other devices
Open history (⇧⌘H)
Open bookmarks (⌘B)
JY-18909-automated-reports-ask-jiminny ■ 869909
75
75
Kiosk
Organizations
Organizations
Setup Account
Setup Account
Users
Users
Activities
Activities
Automated Reports
Automated Reports
Mobile version
Mobile version...
|
NULL
|
|
12401
|
266
|
23
|
2026-04-14T11:18:11.114328+00:00
|
/Users/lukas/.screenpipe/data/data/2026-04-14/1776 /Users/lukas/.screenpipe/data/data/2026-04-14/1776165491114_m1.jpg...
|
Slack
|
Aneliya Angelova, Nikolay Yankov, Steliyan Georgie Aneliya Angelova, Nikolay Yankov, Steliyan Georgiev (DM) - Jiminny Inc - Slack...
|
1
|
NULL
|
monitor_1
|
NULL
|
NULL
|
NULL
|
NULL
|
Jiminny Inc
Jiminny (Staging)
Add workspaces
Home
Jiminny Inc
Jiminny (Staging)
Add workspaces
Home
Home
DMs
DMs
Activity
Activity
Files
Files
Later
Later
More…
More
Unreads
Threads
Huddles
Drafts & sent
Directories
platform-inner-team
ai-chapter
alerts
backend
confusion-clinic
curiosity_lab
engineering
frontend
general
infra-changes
jiminny-bg
platform-tickets
product_launches
random
releases
sofia-office
support
thank-yous
the_people_of_jiminny
Vasil Vasilev
Aneliya Angelova
,
Nikolay Yankov
,
Steliyan Georgiev
Steliyan Georgiev
Adelina Petrova
,
Ilian Kyuchukov
,
Steliyan Georgiev
Adelina Petrova
Galya Dimitrova
Nikolay Nikolov
Galya Dimitrova
,
Nikolay Nikolov
Galya Dimitrova
,
Nikolay Yankov...
|
[{"role":"AXRadioButton","text [{"role":"AXRadioButton","text":"Jiminny Inc","depth":12,"bounds":{"left":0.4861111,"top":0.08777778,"width":0.022222223,"height":0.035555556},"role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":true,"is_expanded":false},{"role":"AXRadioButton","text":"Jiminny (Staging)","depth":12,"bounds":{"left":0.4861111,"top":0.14555556,"width":0.022222223,"height":0.035555556},"role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXPopUpButton","text":"Add workspaces","depth":12,"bounds":{"left":0.4861111,"top":0.20333333,"width":0.022222223,"height":0.035555556},"role_description":"pop-up button","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXRadioButton","text":"Home","depth":14,"bounds":{"left":0.525,"top":0.07777778,"width":0.036111113,"height":0.075555556},"role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":true,"is_expanded":false},{"role":"AXStaticText","text":"Home","depth":16,"bounds":{"left":0.5326389,"top":0.13,"width":0.020833334,"height":0.015555556},"role_description":"text"},{"role":"AXRadioButton","text":"DMs","depth":14,"bounds":{"left":0.525,"top":0.15333334,"width":0.036111113,"height":0.075555556},"role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"DMs","depth":16,"bounds":{"left":0.5347222,"top":0.20555556,"width":0.016666668,"height":0.015555556},"role_description":"text"},{"role":"AXRadioButton","text":"Activity","depth":14,"bounds":{"left":0.525,"top":0.22888888,"width":0.036111113,"height":0.075555556},"role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"Activity","depth":16,"bounds":{"left":0.52916664,"top":0.28111112,"width":0.027083334,"height":0.015555556},"role_description":"text"},{"role":"AXRadioButton","text":"Files","depth":14,"bounds":{"left":0.525,"top":0.30444443,"width":0.036111113,"height":0.075555556},"role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"Files","depth":16,"bounds":{"left":0.5347222,"top":0.35666665,"width":0.015972223,"height":0.015555556},"role_description":"text"},{"role":"AXRadioButton","text":"Later","depth":14,"bounds":{"left":0.525,"top":0.38,"width":0.036111113,"height":0.075555556},"role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"Later","depth":16,"bounds":{"left":0.53402776,"top":0.43222222,"width":0.018055556,"height":0.015555556},"role_description":"text"},{"role":"AXRadioButton","text":"More…","depth":14,"bounds":{"left":0.525,"top":0.45555556,"width":0.036111113,"height":0.075555556},"role_description":"tab","subrole":"AXTabButton","is_enabled":true,"is_focused":false,"is_selected":false,"is_expanded":false},{"role":"AXStaticText","text":"More","depth":16,"bounds":{"left":0.53333336,"top":0.50777775,"width":0.01875,"height":0.015555556},"role_description":"text"},{"role":"AXStaticText","text":"Unreads","depth":21,"bounds":{"left":0.5951389,"top":0.12777779,"width":0.039583333,"height":0.0011111111},"role_description":"text"},{"role":"AXStaticText","text":"Threads","depth":21,"bounds":{"left":0.5951389,"top":0.12777779,"width":0.036805555,"height":0.0011111111},"role_description":"text"},{"role":"AXStaticText","text":"Huddles","depth":21,"bounds":{"left":0.5951389,"top":0.12777779,"width":0.038194444,"height":0.0011111111},"role_description":"text"},{"role":"AXStaticText","text":"Drafts & sent","depth":21,"bounds":{"left":0.5951389,"top":0.12777779,"width":0.06111111,"height":0.0011111111},"role_description":"text"},{"role":"AXStaticText","text":"Directories","depth":21,"bounds":{"left":0.5951389,"top":0.12777779,"width":0.050694443,"height":0.0011111111},"role_description":"text"},{"role":"AXStaticText","text":"platform-inner-team","depth":23,"bounds":{"left":0.60625,"top":0.12777779,"width":0.093055554,"height":0.0011111111},"role_description":"text"},{"role":"AXStaticText","text":"ai-chapter","depth":23,"bounds":{"left":0.60625,"top":0.12777779,"width":0.046527777,"height":0.0011111111},"role_description":"text"},{"role":"AXStaticText","text":"alerts","depth":23,"bounds":{"left":0.60625,"top":0.12777779,"width":0.025694445,"height":0.0011111111},"role_description":"text"},{"role":"AXStaticText","text":"backend","depth":23,"bounds":{"left":0.60625,"top":0.12777779,"width":0.038194444,"height":0.0011111111},"role_description":"text"},{"role":"AXStaticText","text":"confusion-clinic","depth":23,"bounds":{"left":0.60625,"top":0.12777779,"width":0.072222225,"height":0.0011111111},"role_description":"text"},{"role":"AXStaticText","text":"curiosity_lab","depth":23,"bounds":{"left":0.60625,"top":0.12777779,"width":0.057638887,"height":0.0011111111},"role_description":"text"},{"role":"AXStaticText","text":"engineering","depth":23,"bounds":{"left":0.60625,"top":0.12777779,"width":0.054166667,"height":0.0011111111},"role_description":"text"},{"role":"AXStaticText","text":"frontend","depth":23,"bounds":{"left":0.60625,"top":0.12777779,"width":0.04027778,"height":0.0011111111},"role_description":"text"},{"role":"AXStaticText","text":"general","depth":23,"bounds":{"left":0.60625,"top":0.12777779,"width":0.034027778,"height":0.007777778},"role_description":"text"},{"role":"AXStaticText","text":"infra-changes","depth":23,"bounds":{"left":0.60625,"top":0.14666666,"width":0.061805554,"height":0.02},"role_description":"text"},{"role":"AXStaticText","text":"jiminny-bg","depth":23,"bounds":{"left":0.60625,"top":0.17777778,"width":0.048611112,"height":0.02},"role_description":"text"},{"role":"AXStaticText","text":"platform-tickets","depth":23,"bounds":{"left":0.60625,"top":0.20888889,"width":0.072916664,"height":0.02},"role_description":"text"},{"role":"AXStaticText","text":"product_launches","depth":23,"bounds":{"left":0.60625,"top":0.24,"width":0.08055556,"height":0.02},"role_description":"text"},{"role":"AXStaticText","text":"random","depth":23,"bounds":{"left":0.60625,"top":0.2711111,"width":0.035416666,"height":0.02},"role_description":"text"},{"role":"AXStaticText","text":"releases","depth":23,"bounds":{"left":0.60625,"top":0.30222222,"width":0.038194444,"height":0.02},"role_description":"text"},{"role":"AXStaticText","text":"sofia-office","depth":23,"bounds":{"left":0.60625,"top":0.33333334,"width":0.05138889,"height":0.02},"role_description":"text"},{"role":"AXStaticText","text":"support","depth":23,"bounds":{"left":0.60625,"top":0.36444443,"width":0.036111113,"height":0.02},"role_description":"text"},{"role":"AXStaticText","text":"thank-yous","depth":23,"bounds":{"left":0.60625,"top":0.39555556,"width":0.05138889,"height":0.02},"role_description":"text"},{"role":"AXStaticText","text":"the_people_of_jiminny","depth":23,"bounds":{"left":0.60625,"top":0.42666668,"width":0.094444446,"height":0.02},"role_description":"text"},{"role":"AXStaticText","text":"Vasil Vasilev","depth":23,"bounds":{"left":0.60625,"top":0.5,"width":0.055555556,"height":0.02},"role_description":"text"},{"role":"AXStaticText","text":"Aneliya Angelova","depth":23,"bounds":{"left":0.60625,"top":0.5311111,"width":0.07847222,"height":0.02},"role_description":"text"},{"role":"AXStaticText","text":",","depth":23,"bounds":{"left":0.68472224,"top":0.5311111,"width":0.013194445,"height":0.02},"role_description":"text"},{"role":"AXStaticText","text":"Nikolay Yankov","depth":23,"bounds":{"left":0.68958336,"top":0.5311111,"width":0.029861111,"height":0.02},"role_description":"text"},{"role":"AXStaticText","text":",","depth":23,"role_description":"text"},{"role":"AXStaticText","text":"Steliyan Georgiev","depth":23,"role_description":"text"},{"role":"AXStaticText","text":"Steliyan Georgiev","depth":23,"bounds":{"left":0.60625,"top":0.56222224,"width":0.07986111,"height":0.02},"role_description":"text"},{"role":"AXStaticText","text":"Adelina Petrova","depth":23,"bounds":{"left":0.60625,"top":0.5933333,"width":0.072222225,"height":0.02},"role_description":"text"},{"role":"AXStaticText","text":",","depth":23,"bounds":{"left":0.67777777,"top":0.5933333,"width":0.0055555557,"height":0.02},"role_description":"text"},{"role":"AXStaticText","text":"Ilian Kyuchukov","depth":23,"bounds":{"left":0.68333334,"top":0.5933333,"width":0.015972223,"height":0.02},"role_description":"text"},{"role":"AXStaticText","text":",","depth":23,"role_description":"text"},{"role":"AXStaticText","text":"Steliyan Georgiev","depth":23,"role_description":"text"},{"role":"AXStaticText","text":"Adelina Petrova","depth":23,"bounds":{"left":0.60625,"top":0.6244444,"width":0.072222225,"height":0.02},"role_description":"text"},{"role":"AXStaticText","text":"Galya Dimitrova","depth":23,"bounds":{"left":0.60625,"top":0.65555555,"width":0.07361111,"height":0.02},"role_description":"text"},{"role":"AXStaticText","text":"Nikolay Nikolov","depth":23,"bounds":{"left":0.60625,"top":0.68666667,"width":0.07152778,"height":0.02},"role_description":"text"},{"role":"AXStaticText","text":"Galya Dimitrova","depth":23,"bounds":{"left":0.60625,"top":0.7177778,"width":0.07361111,"height":0.02},"role_description":"text"},{"role":"AXStaticText","text":",","depth":23,"bounds":{"left":0.6791667,"top":0.7177778,"width":0.0055555557,"height":0.02},"role_description":"text"},{"role":"AXStaticText","text":"Nikolay Nikolov","depth":23,"bounds":{"left":0.68472224,"top":0.7177778,"width":0.018055556,"height":0.02},"role_description":"text"},{"role":"AXStaticText","text":"Galya Dimitrova","depth":23,"bounds":{"left":0.60625,"top":0.7488889,"width":0.07361111,"height":0.02},"role_description":"text"},{"role":"AXStaticText","text":",","depth":23,"bounds":{"left":0.6791667,"top":0.7488889,"width":0.0055555557,"height":0.02},"role_description":"text"},{"role":"AXStaticText","text":"Nikolay Yankov","depth":23,"bounds":{"left":0.68472224,"top":0.7488889,"width":0.018055556,"height":0.02},"role_description":"text"}]...
|
5207170398896831040
|
-1749130999007430103
|
click
|
hybrid
|
NULL
|
Jiminny Inc
Jiminny (Staging)
Add workspaces
Home
Jiminny Inc
Jiminny (Staging)
Add workspaces
Home
Home
DMs
DMs
Activity
Activity
Files
Files
Later
Later
More…
More
Unreads
Threads
Huddles
Drafts & sent
Directories
platform-inner-team
ai-chapter
alerts
backend
confusion-clinic
curiosity_lab
engineering
frontend
general
infra-changes
jiminny-bg
platform-tickets
product_launches
random
releases
sofia-office
support
thank-yous
the_people_of_jiminny
Vasil Vasilev
Aneliya Angelova
,
Nikolay Yankov
,
Steliyan Georgiev
Steliyan Georgiev
Adelina Petrova
,
Ilian Kyuchukov
,
Steliyan Georgiev
Adelina Petrova
Galya Dimitrova
Nikolay Nikolov
Galya Dimitrova
,
Nikolay Nikolov
Galya Dimitrova
,
Nikolay Yankov
SlackFileEdit ViewGoHistoryWindowHelpec2-userGDOCKER981DEV (docker)882APP (-zsh)[EMAIL]@73b64f5d54a3:/home/jiminny#[ec2-user@ip-10-30-93-249~]$ dockerexec -it $(dockny && bash"root@c78a087b1345:/home/Jiminny# php artisan automated-reports[2026-04-14 10:46:08] staging.INF0: [automated-reports] Started{"correlation_id":"5[2026-04-1410:46:08Jstaging. INFO: [automated-reports]id":"5c23e861-2ca9-4f92-9f67-773d6bc80ca0"Checking conditions {"isMonda,"trace_id" :"185df6f6-4327-4609-9c2e-2ab83a[2026-04-14 10:46:08]staging.INFO: [automated-reports] Processing daily reports {"cab83a0f5432"}[2026-04-1410:46:08]9-9c2e-2ab83a0f5432"}staging.INFO: [automated-reports]Found 3 daily reports to proc[2026-04-1410:46:087daily"staging.INFO: [automated-reports]Dispatching Generate Report j,"type":"ask_jiminny"} {"correlation_id":"5c23e861-2ca9-4f92-9f67-773d6bc80ca0"[2026-04-14 10:46:08]staging.INFO: [automated-reports]Dispatching Generate Report jdaily", "type": "ask_jiminny"} {"correlation_id":"5c23e861-2ca9-4f92-9f67-773d6bc80cab"[2026-04-14 10:46:08]staging. INFO: [automated-reports]daily'", "type" "ask-fiminny"'} ("correlation-id' : 5c2se861-2ca -4792-9f87-773 Be8oca[2026-04-14 10:46:08]staging.INFO: [automated-reports]Completed{"correlation_id":root@c78a087b1345:/home/jiminny# phpartisanautomated-reports --report-id 35[2026-04-14 10:48:42] staging.INFO: [automated-reports]{"correlation_id":"2[2026-04-14 10:48:42]staging.INFO: [automated-reports]Checking conditions {"isMondaid":"246a1ala-7076-458c-bd7d-49d2f5a2db88","trace_id":"1f894bf6-e50d-4e99-b635-2aa526[2026-04-14 10:48:42]staging.INFO: [automated-reports]Processing daily reports{"caa52627fc27"}[automated-reports] Automated report[2026-04-14 10:48:42]staging.INFO: [automated-reports] Found 1 daily reports to proc9-b635-2aa52627f c27"}[2026-04-14 10:48:42]staging.INF0: [automated-reports]Dispatching Generate Report jdaily","type": "ask_jiminny"} {"correlation_id":"246a1a1a-7076-458c-bd7d-49d2f5a2db88"[2026-04-14 10:48:42]staging.INFO: [automated-reports]Completed{"correlation_id":root@c78a087b1345:/home/jiminny# [ec2-user@ip-10-30-93-249 ~]$I+EDHomeDMsActivityFilesLater.*•MoreallJiminny ...+tscnicrel# infra-changes# jiminny-bg# platform-tickets# product_launches# random# rbdeases# sofia-office# support# thank-yous# the_people_of jimi...Direct messagesVasil VasilevAneliya Angelova, ...Steliyan GeorgievAdelina Petrova, Ili...0. Adelina Petrova. Galya Dimitrova *&s Nikolay Nikolov "2Galya Dimitrova, Ni...2Galya Dimitrova, Ni...P. Nikolay Yankov::: AppsJira CloudToastGoogle Cale...• Support Daily • in 42 ml100% 147Tue 14 Apr 14:18:10→Search Jiminny Inc<Thread Direct message with 3 othersвчера, не днес• и имейл не дойдеimage.pngSOV• с в5 repliesLukas Kovalik 19 minutes agoза дата там не знам как искаме да го правим.по принцип при всички други се гледа ден назад при положение че идва през нощта.Nikolay Yankov 19 minutes ago@Lukas Kovalik видя ли този коментарLukas Kovalik 19 minutes agoдаNikolay Yankov 18 minutes agoне е ли датата на която е генерирано? (edited)Lukas Kovalik 18 minutes agoemail ще го видяReply...Also send to the group+•*•...
|
12398
|
|
12403
|
266
|
24
|
2026-04-14T11:18:13.029925+00:00
|
/Users/lukas/.screenpipe/data/data/2026-04-14/1776 /Users/lukas/.screenpipe/data/data/2026-04-14/1776165493029_m1.jpg...
|
NULL
|
NULL
|
1
|
NULL
|
monitor_1
|
NULL
|
NULL
|
NULL
|
NULL
|
SlackFileEditViewGoHistoryWindowHelpec2-userGDOCKE SlackFileEditViewGoHistoryWindowHelpec2-userGDOCKER981DEV (docker)882APP (-zsh)[EMAIL]@73b64f5d54a3:/home/jiminny#[ec2-user@ip-10-30-93-249 ~]$ dockerexec -it $(dockny && bash"root@c78a087b1345:/home/Jiminny# php artisan automated-reports[2026-04-14 10:46:08] staging.INF0: [automated-reports] Started{"correlation_id":"5[2026-04-1410:46:08]staging.INFO: [automated-reports] Checking conditions {"isMondaid":"5c23e861-2ca9-4f92-9f67-773d6bc80ca0","trace_id" :"185df6f6-4327-4609-9cZe-2ab83a[2026-04-14 10:46:08]ab83a0f5432"}staging.INFO: [automated-reports] Processing daily reports{"c[2026-04-1410:46:08]9-9c2e-2ab83a0f5432"}staging.INFO: [automated-reports]Found 3 daily reports to proc[2026-04-1410:46:087daily"staging.INFO: [automated-reports]Dispatching Generate Report j,"type":"ask_jiminny"} {"correlation_id":"5c23e861-2ca9-4f92-9f67-773d6bc80ca®"[2026-04-14 10:46:08]staging.INFO: [automated-reports]Dispatching Generate Report jdaily", "type": "ask_jiminny"} {"correlation_id":"5c23e861-2ca9-4f92-9f67-773d6bc80cab"[2026-04-14 10:46:08]staging. INFO: [automated-reports]daily'", "type" "ask-fiminny"'} ("correlation-id' : 5c2se861-2ca -4792-9f87-773 e8oca[2026-04-14 10:46:08]staging.INFO: [automated-reports]Completed{"correlation_id":root@c78a087b1345:/home/jiminny# phpartisanautomated-reports --report-id 35[2026-04-14 10:48:42] staging.INFO: [automated-reports]Started{"correlation_id":"2[2026-04-14 10:48:42]staging.INFO: [automated-reports]Checking conditions {"isMondaid":"246alala-7076-458c-bd7d-49d2f5a2db88","trace_id":"1f894bf6-e50d-4e99-b635-2aa526[2026-04-14 10:48:42]staging.INFO: [automated-reports]Processing daily reports{"caa52627fc27"}[automated-reports] Automated report[2026-04-14 10:48:42]staging.INFO: [automated-reports] Found 1 daily reports to proc9-b635-2aa52627f c27"}[2026-04-14 10:48:42]staging.INF0: [automated-reports]Dispatching Generate Reportdaily","type": "ask_jiminny"} {"correlation_id":"246a1a1a-7076-458c-bd7d-49d2f5a2db88"[2026-04-14 10:48:42]staging.INFO: [automated-reports]Completed{"correlation_id":root@c78a087b1345:/home/jiminny# [ec2-user@ip-10-30-93-249 ~]$I+HomeDMsActivityFilesLater.*•MorelhlJiminny ...scnicre# infra-changes# jiminny-bg# platform-tickets# product_launches# random# relgases# sofia-office# support# thank-yous# the_people_of jimi...Direct messages€. Vasil VasilevAneliya Angelova, ...Steliyan GeorgievAdelina Petrova, Ili...0. Adelina Petrova. Galya Dimitrova *&s Nikolay Nikolov "2Galya Dimitrova, Ni...2Galya Dimitrova, Ni...P. Nikolay Yankov::: AppsJira CloudToastGoogle Cale...§ Support Daily - in 42 m100% CTue 14 Apr 14:18:12Search Jiminny Inc# releases8 226 0• Messages• Files@ Bookmarks+1f99de0e313cToday ~8b256855f58e5bf1f5) - [JY-20571](https://jiminny.atlassian.net/browse/JY-20571): Panorama offline reports (#465)(steliyan-g)(8cf63ce)(https://github.com/jiminny/prophet/commit/8cf63cec5153b6e1320e84c67b03977ce6fe4c0c) - [JY-19982](https://jiminny.atlassian.net/browse/JY-19982): Allow multiple LLM evals with onecommand run (#464) (steliyan-g)NewCircleCl APP 2:15 PMNew commits deployed to Prophet Prod-EU:[Od2170f](https://github.com/jiminny/prophet/commit/0d2170fd4f25032fe37738e936a418512ca7b6e2) - [JY-20544](https://jiminny.atlassian.net/browse/JY-20544)eval changes (#459) (ilian-jiminny)New commits deployed to Prophet Prod-US:[0d2170f](https://github.com/jiminny/prophet/commit/0d2170fd4f25032fe37738e936a418512ca7b6el2) - [JY-20544](https://jiminny.atlassian.net/browse/JY-20544)eval changes (#459) (flian-jiminny)Message #releases+ Аа...
|
NULL
|
-7518130477457148794
|
NULL
|
visual_change
|
ocr
|
NULL
|
SlackFileEditViewGoHistoryWindowHelpec2-userGDOCKE SlackFileEditViewGoHistoryWindowHelpec2-userGDOCKER981DEV (docker)882APP (-zsh)[EMAIL]@73b64f5d54a3:/home/jiminny#[ec2-user@ip-10-30-93-249 ~]$ dockerexec -it $(dockny && bash"root@c78a087b1345:/home/Jiminny# php artisan automated-reports[2026-04-14 10:46:08] staging.INF0: [automated-reports] Started{"correlation_id":"5[2026-04-1410:46:08]staging.INFO: [automated-reports] Checking conditions {"isMondaid":"5c23e861-2ca9-4f92-9f67-773d6bc80ca0","trace_id" :"185df6f6-4327-4609-9cZe-2ab83a[2026-04-14 10:46:08]ab83a0f5432"}staging.INFO: [automated-reports] Processing daily reports{"c[2026-04-1410:46:08]9-9c2e-2ab83a0f5432"}staging.INFO: [automated-reports]Found 3 daily reports to proc[2026-04-1410:46:087daily"staging.INFO: [automated-reports]Dispatching Generate Report j,"type":"ask_jiminny"} {"correlation_id":"5c23e861-2ca9-4f92-9f67-773d6bc80ca®"[2026-04-14 10:46:08]staging.INFO: [automated-reports]Dispatching Generate Report jdaily", "type": "ask_jiminny"} {"correlation_id":"5c23e861-2ca9-4f92-9f67-773d6bc80cab"[2026-04-14 10:46:08]staging. INFO: [automated-reports]daily'", "type" "ask-fiminny"'} ("correlation-id' : 5c2se861-2ca -4792-9f87-773 e8oca[2026-04-14 10:46:08]staging.INFO: [automated-reports]Completed{"correlation_id":root@c78a087b1345:/home/jiminny# phpartisanautomated-reports --report-id 35[2026-04-14 10:48:42] staging.INFO: [automated-reports]Started{"correlation_id":"2[2026-04-14 10:48:42]staging.INFO: [automated-reports]Checking conditions {"isMondaid":"246alala-7076-458c-bd7d-49d2f5a2db88","trace_id":"1f894bf6-e50d-4e99-b635-2aa526[2026-04-14 10:48:42]staging.INFO: [automated-reports]Processing daily reports{"caa52627fc27"}[automated-reports] Automated report[2026-04-14 10:48:42]staging.INFO: [automated-reports] Found 1 daily reports to proc9-b635-2aa52627f c27"}[2026-04-14 10:48:42]staging.INF0: [automated-reports]Dispatching Generate Reportdaily","type": "ask_jiminny"} {"correlation_id":"246a1a1a-7076-458c-bd7d-49d2f5a2db88"[2026-04-14 10:48:42]staging.INFO: [automated-reports]Completed{"correlation_id":root@c78a087b1345:/home/jiminny# [ec2-user@ip-10-30-93-249 ~]$I+HomeDMsActivityFilesLater.*•MorelhlJiminny ...scnicre# infra-changes# jiminny-bg# platform-tickets# product_launches# random# relgases# sofia-office# support# thank-yous# the_people_of jimi...Direct messages€. Vasil VasilevAneliya Angelova, ...Steliyan GeorgievAdelina Petrova, Ili...0. Adelina Petrova. Galya Dimitrova *&s Nikolay Nikolov "2Galya Dimitrova, Ni...2Galya Dimitrova, Ni...P. Nikolay Yankov::: AppsJira CloudToastGoogle Cale...§ Support Daily - in 42 m100% CTue 14 Apr 14:18:12Search Jiminny Inc# releases8 226 0• Messages• Files@ Bookmarks+1f99de0e313cToday ~8b256855f58e5bf1f5) - [JY-20571](https://jiminny.atlassian.net/browse/JY-20571): Panorama offline reports (#465)(steliyan-g)(8cf63ce)(https://github.com/jiminny/prophet/commit/8cf63cec5153b6e1320e84c67b03977ce6fe4c0c) - [JY-19982](https://jiminny.atlassian.net/browse/JY-19982): Allow multiple LLM evals with onecommand run (#464) (steliyan-g)NewCircleCl APP 2:15 PMNew commits deployed to Prophet Prod-EU:[Od2170f](https://github.com/jiminny/prophet/commit/0d2170fd4f25032fe37738e936a418512ca7b6e2) - [JY-20544](https://jiminny.atlassian.net/browse/JY-20544)eval changes (#459) (ilian-jiminny)New commits deployed to Prophet Prod-US:[0d2170f](https://github.com/jiminny/prophet/commit/0d2170fd4f25032fe37738e936a418512ca7b6el2) - [JY-20544](https://jiminny.atlassian.net/browse/JY-20544)eval changes (#459) (flian-jiminny)Message #releases+ Аа...
|
NULL
|