@@ -11,24 +11,24 @@ def get_updated_contact_data():
11
11
Session = sessionmaker (engine )
12
12
13
13
qry = """ -- Collect latest foster/volunteer dates
14
- select json_agg (upd) as "cd"
14
+ select json_agg (upd) as "cd"
15
15
from (
16
16
select
17
17
sf.source_id as "Id" , -- long salesforce string
18
- sle.person_id as "Person_Id__c", -- short PAWS-local shelterluv id
18
+ array_agg(sl.source_id) filter (where sl.source_id is not null) as "Person_Id__c", -- short PAWS-local shelterluv id
19
19
case
20
20
when
21
- (extract(epoch from now())::bigint - foster_out < 365*86400) -- foster out in last year
22
- or (extract(epoch from now())::bigint - foster_return < 365*86400) -- foster return
21
+ (extract(epoch from now())::bigint - max( foster_out) < 365*86400) -- foster out in last year
22
+ or (extract(epoch from now())::bigint - max( foster_return) < 365*86400) -- foster return
23
23
then 'Active'
24
24
else 'Inactive'
25
25
end as "Foster_Activity__c",
26
- foster_out as "Foster_Start_Date__c",
27
- foster_return as "Foster_End_Date__c",
28
- vol.first_date "First_volunteer_date__c",
29
- vol.last_date "Last_volunteer_date__c",
30
- vol.hours as "Total_volunteer_hours__c",
31
- vc.source_id::integer as "Volgistics_Id__c"
26
+ max( foster_out) as "Foster_Start_Date__c",
27
+ max( foster_return) as "Foster_End_Date__c",
28
+ min( vol.first_date) "First_volunteer_date__c",
29
+ max( vol.last_date) "Last_volunteer_date__c",
30
+ sum( vol.hours) as "Total_volunteer_hours__c",
31
+ array_agg( vc.source_id::integer) filter(where vc.source_id is not null) as "Volgistics_Id__c"
32
32
from (
33
33
select source_id, matching_id from pdp_contacts sf
34
34
where sf.source_type = 'salesforcecontacts'
@@ -55,6 +55,7 @@ def get_updated_contact_data():
55
55
group by volg_id
56
56
) vol on vol.volg_id::text = vc.source_id
57
57
where sl.matching_id is not null or vc.matching_id is not null
58
+ group by sf.source_id
58
59
) upd;
59
60
"""
60
61
0 commit comments