@@ -11,24 +11,24 @@ def get_updated_contact_data():
1111 Session = sessionmaker (engine )
1212
1313 qry = """ -- Collect latest foster/volunteer dates
14- select json_agg (upd) as "cd"
14+ select json_agg (upd) as "cd"
1515 from (
1616 select
1717 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
1919 case
2020 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
2323 then 'Active'
2424 else 'Inactive'
2525 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"
3232 from (
3333 select source_id, matching_id from pdp_contacts sf
3434 where sf.source_type = 'salesforcecontacts'
@@ -55,6 +55,7 @@ def get_updated_contact_data():
5555 group by volg_id
5656 ) vol on vol.volg_id::text = vc.source_id
5757 where sl.matching_id is not null or vc.matching_id is not null
58+ group by sf.source_id
5859 ) upd;
5960 """
6061
0 commit comments