Необходимо скорректировать скрипт с учетом требований + убрать закоммеченные строки + заменить константы дат для params на передаваемые параметры.
Сервис profiles: отображать тип пользователя как ЮЛ/ФЛ/ИП
with params as (
select '2026-03-31'::date at time zone 'gmt+03' as end_date
)
select u.id
--, u.type
, case u.type
when 'LEGAL' then 'ЮЛ'
when 'ENTREPRENEUR' then 'ИП'
when 'INDIVIDUAL' then 'ФЛ'
end as type
, case u.type
when 'LEGAL' then lp.title
when 'ENTREPRENEUR' then concat_ws(' ', pd.last_name, pd.first_name, pd.second_name)
when 'INDIVIDUAL' then concat_ws(' ', pd.last_name, pd.first_name, pd.second_name)
end as title
, case u.type
when 'LEGAL' then lp.inn
when 'ENTREPRENEUR' then pd.inn
when 'INDIVIDUAL' then pd.inn
end as inn
, case
when p.deleted_at is not null then 'Пользовательское соглашение расторгнуто'
when u.is_blocked then 'Заблокирован'
when not u.is_identified then 'Не идентифицирован'
when u.is_identified then 'Идентифицирован'
end as current_status
, u.registered_at
, u.deleted_at
from params, users u
inner join profile p on p.user_id = u.id and p.type = u.type
left join individual_profile ip on ip.id = p.id
left join entrepreneur_profile ep on ep.id = p.id
left join legal_profile lp on lp.id = p.id
left join personal_data pd on pd.id = coalesce(ip.personal_data_id, ep.personal_data_id)
where u.type in ('LEGAL', 'ENTREPRENEUR', 'INDIVIDUAL')
and p.status = 'APPROVED'
and p.created_at <= params.end_date
order
by 2, 3
;
Сервис money: убрана фильтрация по дате создания кошелька
/*with params as (
select '2026-03-31'::date + interval '1' day as end_date
)*/
select a.user_id
, a.number as account_number
from /params,/ account a
where a.account_type = 'DEPOSIT'
– and a.created_at < params.end_date
;