Skip to content
Permalink
cac6cecbfb
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
@ij
Latest commit cac6cec Aug 20, 2020 History
1 contributor

Users who have contributed to this file

161 lines (134 sloc) 5.7 KB
class Sf::Account
include Sf::Base
FIELDS = ['Id', 'Name', 'Member_Type__c', 'Member_Category__c', 'MOU_Participant__c', 'Member_Join_Date__c', 'Status__c', 'Website', 'InCommon_Participant__c', 'InCommon_Participation__c', 'iMIS_ID__c', 'Membership_Status__c']
FIELDS_SELECT_STR = FIELDS.join(', ')
MEMBER_TYPES = ['R&E Network Member', 'University Member', 'Industry Member', 'Affiliate Member']
MEMBER_TYPES_STR = MEMBER_TYPES.map{|v| "\'#{v}\'"}.join(', ')
def initialize(account=nil)
@account = account
end
def update(args={})
params = {Id: self.Id}
args.map {|k,v| params[k] = v}
end
def contacts
Sf::Contact.where({AccountId: self.Id, Status__c: 'Active'})
end
def method_missing(method_name, *args, &block)
@account.send(method_name, *args, &block)
end
def respond_to_missing?(method_name, include_private = false)
@account.respond_to?(method_name, include_private) || super
end
def inc_execs
Sf::Contact.inc_execs_for(self.Id)
end
def inc_part_since_year
if self.InCommon_Participant__c
start_date = start_dates_by_subscription["InCommon Participation"]
start_date.split("-")[0] if start_date
end
end
# Class Methods
def self.find(id)
new Sf.client.find("Account", id)
end
def self.find_by(args = {})
where = args.map {|k,v| "#{k} = \'#{v}\'"}.join(" and ")
sobject = Sf.client.query("select #{FIELDS_SELECT_STR} from Account where #{where}").first
if sobject.present?
new sobject
end
end
def self.intl_partners
build_collection Sf.client.query("select #{FIELDS_SELECT_STR} from Account where MOU_Participant__c = true order by Name")
end
def self.members
build_collection Sf.client.query("select #{FIELDS_SELECT_STR} from Account where Membership_Status__c = true order by Name")
end
def self.all
build_collection Sf.client.query("select #{FIELDS_SELECT_STR} from Account order by Name")
end
def self.community_orgs
build_collection Sf.client.query(
"select #{FIELDS_SELECT_STR} from Account
where Name='Internet2' or InCommon_Participant__c = true
or Membership_Status__c = true
or MOU_Participant__c = true
order by Name"
)
end
def self.incommon_participants
build_collection Sf.client.query("select #{FIELDS_SELECT_STR} from Account where InCommon_Participant__c = true order by Name")
end
def self.internet2
i2 = find_by({Name: "Internet2", Status__c: "Active"})
find i2.Id
end
def self.member?(account_id)
members.map(&:Id).include?(account_id)
end
def self.inc_part?(account_id)
incommon_participants.map(&:Id).include?(account_id)
end
def self.intl_partner?(account_id)
intl_partners.map(&:Id).include?(account_id)
end
# Accounts with a closed won opportunity but not yet the "InCommon Control" check box is checked.
def self.inc_parts_to_be
acct_ids = Sf::Opportunity.inc_participations(Date.today.prev_month(2)).map(&:AccountId)
if acct_ids.empty?
[]
else
accts_str = acct_ids.map{|v| "\'#{v}\'"}.join(', ')
build_collection Sf.client.query("select #{FIELDS_SELECT_STR} from Account where InCommon_Participant__c != true and Id in (#{accts_str})")
end
end
def self.inc_certs_to_be
acct_ids = Sf::Opportunity.cert_subscribers(Date.today.prev_month(2)).map(&:AccountId)
if acct_ids.empty?
[]
else
accts_str = acct_ids.map{|v| "\'#{v}\'"}.join(', ')
build_collection Sf.client.query("select #{FIELDS_SELECT_STR} from Account where InCommon_Participant__c = true and Id in (#{accts_str})")
end
end
def self.active_inc_parts(service_name)
today = Date.today.strftime('%Y-%m-%d')
sobjects = Sf.client.query("select
Supporting_Institution__r.Id,
Supporting_Institution__r.Name,
Supporting_Institution__r.InCommon_Website_Name__c,
Supporting_Institution__r.InCommon_Participant_Type__c,
Supporting_Institution__r.InCommon_Weblink__c
from Service_Institution__c where Service__r.Name = \'#{service_name}\'
and (Service_End_Date__c = null or Service_End_Date__c > #{today})
and (Service_Start_Date__c = null or Service_Start_Date__c < #{today})
and Do_Not_Publish__c <> true")
build_collection sobjects.map(&:Supporting_Institution__r) unless sobjects.blank?
end
def self.cert_service_subscribers
sobjects = Sf.client.query("select
Supporting_Institution__r.Id,
Supporting_Institution__r.Name,
Supporting_Institution__r.InCommon_Website_Name__c,
Supporting_Institution__r.InCommon_Participant_Type__c,
Supporting_Institution__r.InCommon_Weblink__c
from Service_Institution__c where Service__r.Name = \'InCommon Certificate Service\'
and Service_End_Date__c = null
and (Type_of_Support__c = 'Subscriber' or Type_of_Support__c = 'subscriber_parent')
and Do_Not_Publish__c <> true")
build_collection sobjects.map(&:Supporting_Institution__r) unless sobjects.blank?
end
private
def subscriptions
# sorting by Service_Start_Date__c in case of multiple subscriptions of the same service
Sf.client.query("select Service__r.Id, Service__r.Name, Service_Start_Date__c, Service_End_Date__c from Service_Institution__c where Supporting_Institution__c = \'#{self.Id}\' ORDER BY Service_Start_Date__c")
end
# The latest subscription is included only in case of the multiple subscriptions of the same service.
def start_dates_by_subscription
start_dates = {}
subscriptions.each {|s| start_dates[s.Service__r.Name] = s.Service_Start_Date__c}
start_dates
end
end