Class: Readiness::Salesforce::Accounts
- Defined in:
- lib/support_readiness/salesforce/accounts.rb
Overview
Defines the class Accounts within the module Readiness::Salesforce.
Class Method Summary collapse
-
.account_arr(account) ⇒ Object
Returns an accounts ARR.
-
.account_expiration(account) ⇒ Object
Returns an accounts latest expiration.
-
.account_health_score(account) ⇒ Object
Returns an accounts health score.
-
.account_is_partner_customer?(account, type) ⇒ Boolean
Returns if an account is a partner customer or not.
-
.account_market_segment(account) ⇒ Object
Returns an accounts market segment.
-
.account_region(account) ⇒ Object
Returns an accounts region.
-
.account_seats(account) ⇒ Object
Returns an accounts seat count.
-
.account_sold_to(account) ⇒ Object
Returns an accounts sold to.
-
.account_subscriptions(account, type) ⇒ Object
Return an Array of subscriptions used for the account sync.
-
.account_type(account, expiration) ⇒ Object
Returns an accounts type.
-
.global_accounts(client) ⇒ Array
Return an Array of accounts from Salesforce for Global support.
-
.global_highest_support_level(subscriptions) ⇒ Object
Returns an accounts highest support level for the Global support sync.
-
.global_sync_object(account) ⇒ Object
Return a Hash used for the account sync for Global support.
-
.global_sync_query_string ⇒ String
Provides the String needed to make a specific type of SOQL query.
- .process_global_subs(account, charge_names) ⇒ Object
- .process_usgov_subs(account, charge_names) ⇒ Object
-
.update!(client, aid, **args) ⇒ Boolean
Updates an Account in Salesforce.
-
.us_gov_check_query_string(aid) ⇒ String
Provides the String needed to make a specific type of SOQL query.
-
.us_gov_enabled?(client, aid) ⇒ Boolean
Determines if a SFDC Account is US Government enabled.
-
.us_gov_only?(account, subs) ⇒ Boolean
Determines if a given account with its subscriptions is US Government only.
-
.usgov_accounts(client) ⇒ Array
Return an Array of accounts from Salesforce for US Government support.
-
.usgov_highest_support_level(subscriptions) ⇒ Object
Returns an accounts highest support level for the US Government support sync.
-
.usgov_sync_object(account) ⇒ Object
Return a Hash used for the account sync for US Government support.
-
.usgov_sync_query_string ⇒ String
Provides the String needed to make a specific type of SOQL query.
Methods inherited from Client
auth_error, bad_request_error, convert_actions, convert_conditions, convert_standard_names_to_ids, convert_ticket_form_agent_conditions, convert_ticket_form_brands, convert_ticket_form_end_user_conditions, convert_ticket_form_names_to_ids, convert_view_names_to_ids, convert_view_restrictions, covert_ticket_form_field_ids, create_package!, erb_renderer, handle_request_error, not_found_error, not_processible_error, put_into_archive, recursively_deflate_directory, timestamp_filename, to_clean_json, to_clean_json_with_key, to_hash, to_nearly_clean_json, to_nearly_clean_json_with_key, to_param_string, write_entries
Class Method Details
.account_arr(account) ⇒ Object
Returns an accounts ARR
360 361 362 363 364 365 366 367 368 369 370 |
# File 'lib/support_readiness/salesforce/accounts.rb', line 360 def self.account_arr(account) total = 0 return total if account.Zuora__R00N40000001lGjTEAU__r.nil? account.Zuora__R00N40000001lGjTEAU__r.each do |subscription| next if Date.parse(subscription.Zuora__EffectiveEndDate__c) < Date.today total += subscription.Zuora__TotalContractValue__c.to_i end total end |
.account_expiration(account) ⇒ Object
Returns an accounts latest expiration
335 336 337 338 339 |
# File 'lib/support_readiness/salesforce/accounts.rb', line 335 def self.account_expiration(account) return '1970-01-01' if account.Zuora__R00N40000001lGjTEAU__r.nil? account.Zuora__R00N40000001lGjTEAU__r.map(&:Zuora__EffectiveEndDate__c).max end |
.account_health_score(account) ⇒ Object
Returns an accounts health score
423 424 425 426 427 |
# File 'lib/support_readiness/salesforce/accounts.rb', line 423 def self.account_health_score(account) account.GS_Health_Score_Color__c.downcase rescue NoMethodError nil end |
.account_is_partner_customer?(account, type) ⇒ Boolean
Returns if an account is a partner customer or not
434 435 436 437 438 439 440 441 |
# File 'lib/support_readiness/salesforce/accounts.rb', line 434 def self.account_is_partner_customer?(account, type) return false if account.Latest_Sold_To_Contact__r.nil? return false if type != 'customer' return false if account.Account_ID_18__c == '0016100000g04oWAAQ' return true if account.Latest_Sold_To_Contact__r.Email == 'ecopo@us.ibm.com' false end |
.account_market_segment(account) ⇒ Object
Returns an accounts market segment
377 378 379 380 381 |
# File 'lib/support_readiness/salesforce/accounts.rb', line 377 def self.account_market_segment(account) account.Ultimate_Parent_Sales_Segment_Employees__c.downcase rescue NoMethodError 'unknown' end |
.account_region(account) ⇒ Object
Returns an accounts region
405 406 407 408 409 410 411 412 413 414 415 416 |
# File 'lib/support_readiness/salesforce/accounts.rb', line 405 def self.account_region(account) return 'org_region_amer' if account.Account_Demographics_Geo__c == 'AMER' return 'org_region_apac' if account.Account_Demographics_Geo__c == 'APJ' return 'org_region_emea' if account.Account_Demographics_Geo__c == 'EMEA' if account.Account_Demographics_Geo__c == 'SMB' return 'org_region_amer' if account.Account_Demographics_Region__c == 'AMER' return 'org_region_apac' if account.Account_Demographics_Region__c == 'APJ' return 'org_region_emea' if account.Account_Demographics_Region__c == 'EMEA' end nil end |
.account_seats(account) ⇒ Object
Returns an accounts seat count
388 389 390 391 392 393 394 395 396 397 398 |
# File 'lib/support_readiness/salesforce/accounts.rb', line 388 def self.account_seats(account) total = 0 return total if account.Zuora__R00N40000001lGjTEAU__r.nil? account.Zuora__R00N40000001lGjTEAU__r.each do |subscription| next if Date.parse(subscription.Zuora__EffectiveEndDate__c) < Date.today total += subscription.Zuora__Quantity__c.to_i end total end |
.account_sold_to(account) ⇒ Object
Returns an accounts sold to
494 495 496 497 498 499 500 501 502 503 |
# File 'lib/support_readiness/salesforce/accounts.rb', line 494 def self.account_sold_to(account) return nil if account.Zuora__R00N40000001kyLcEAI__r.nil? return nil if account.Zuora__R00N40000001kyLcEAI__r.first.Zuora__SoldToWorkEmail__c == 'ecopo@us.ibm.com' { "salesforce_id" => account.Account_ID_18__c, "email" => account.Zuora__R00N40000001kyLcEAI__r.first.Zuora__SoldToWorkEmail__c, "name" => account.Zuora__R00N40000001kyLcEAI__r.first.Name } end |
.account_subscriptions(account, type) ⇒ Object
Return an Array of subscriptions used for the account sync
243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 |
# File 'lib/support_readiness/salesforce/accounts.rb', line 243 def self.account_subscriptions(account, type) subs = [] return subs if account.Zuora__R00N40000001lGjTEAU__r.nil? grouped = account.Zuora__R00N40000001lGjTEAU__r.group_by { |z| z.Zuora__Subscription__c } grouped.each_value.each do |charges| valid_charges = charges.select { |c| c.Subscription_Status__c == 'Active' && Date.parse(c.Zuora__EffectiveEndDate__c) >= Date.today } next if valid_charges.count.zero? charge_names = valid_charges.map { |x| x.Name } sub_types = if type == 'global' process_global_subs(account, charge_names) else process_usgov_subs(account, charge_names) end subs += sub_types end subs.compact.uniq end |
.account_type(account, expiration) ⇒ Object
Returns an accounts type
346 347 348 349 350 351 352 353 |
# File 'lib/support_readiness/salesforce/accounts.rb', line 346 def self.account_type(account, expiration) return 'alliance_partner' if %w[0014M00001sDiGEQA0].include?(account.Account_ID_18__c) return 'open_partner' if account.Type == 'Partner' && account.Partner_Track__c == 'Open' return 'select_partner' if account.Type == 'Partner' && account.Partner_Track__c == 'Select' return 'former_customer' if Date.parse(expiration) < Date.today 'customer' end |
.global_accounts(client) ⇒ Array
Return an Array of accounts from Salesforce for Global support
90 91 92 93 94 |
# File 'lib/support_readiness/salesforce/accounts.rb', line 90 def self.global_accounts(client) query = Queries.new(global_sync_query_string) results = Queries.run!(client, query) results.map { |r| global_sync_object(r) }.compact end |
.global_highest_support_level(subscriptions) ⇒ Object
Returns an accounts highest support level for the Global support sync
448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 |
# File 'lib/support_readiness/salesforce/accounts.rb', line 448 def self.global_highest_support_level(subscriptions) return 'ultimate' if subscriptions.include? 'sub_sm_ultimate' return 'gold' if subscriptions.include? 'sub_dotcom_ultimate' return 'ultimate' if subscriptions.include? 'sub_gitlab_dedicated' return 'premium' if subscriptions.include? 'sub_sm_premium' return 'silver' if subscriptions.include? 'sub_dotcom_premium' return 'starter' if subscriptions.include? 'sub_sm_starter' return 'consumption_only' if subscriptions.include? 'sub_consumption_ai' return 'consumption_only' if subscriptions.include? 'sub_consumption_cicd_minutes' return 'consumption_only' if subscriptions.include? 'sub_consumption_eap' return 'consumption_only' if subscriptions.include? 'sub_consumption_storage' return 'custom' if subscriptions.include? 'sub_usgov_12x5' return 'custom' if subscriptions.include? 'sub_usgov_24x7' return 'custom' if subscriptions.include? 'sub_ss_ase' return 'custom' if subscriptions.include? 'sub_ss_growth' return 'custom' if subscriptions.include? 'sub_ss_enterprise' return 'community' if subscriptions.include? 'sub_edu' return 'community' if subscriptions.include? 'sub_oss' return 'community' if subscriptions.include? 'sub_community_other' return 'other' if subscriptions.include? 'sub_proserv' return 'sub_other' if subscriptions.include? 'sub_proserv' 'expired' end |
.global_sync_object(account) ⇒ Object
Return a Hash used for the account sync for Global support
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 |
# File 'lib/support_readiness/salesforce/accounts.rb', line 126 def self.global_sync_object(account) subscriptions = account_subscriptions(account, 'global') if subscriptions.count.zero? usgov_subs = account_subscriptions(account, 'usgov') # Return nil if it has no global subs but has us gov subs return nil if usgov_subs.count.nonzero? end expiration = account_expiration(account) type = account_type(account, expiration) partner = %w[alliance_partner open_partner select_partner].include?(type) { "name" => "#{Digest::SHA1.hexdigest(account.Account_ID_18__c)[0..7]} #{account.Name}", "salesforce_id" => account.Account_ID_18__c, "sfdc_short_id" => account.Account_ID_18__c[..-4], "support_level" => (partner ? 'ultimate' : global_highest_support_level(subscriptions)), "aar" => account_arr(account).to_f, "sales_segmentation" => account_market_segment(account), "account_owner" => account.Account_Owner_Calc__c, "type" => type, "technical_account_manager" => account.Technical_Account_Manager_Name__c, "solutions_architect" => account.Solutions_Architect_Lookup__r&.Name, "seats_decimal" => account_seats(account).to_f, "org_region" => account_region(account), "health_score" => account_health_score(account), "expiration_date" => expiration, "restricted_account" => (account.Restricted_Account__c == 'Restricted Party'), "greatly_expired" => (partner ? false : Date.parse(expiration) <= Date.today.years_ago(3)), "sub_consumption_ai" => subscriptions.include?('sub_consumption_ai'), "sub_consumption_cicd_minutes" => subscriptions.include?('sub_consumption_cicd_minutes'), "sub_consumption_duo_enterprise" => subscriptions.include?('sub_consumption_duo_enterprise'), "sub_consumption_duo_premium" => subscriptions.include?('sub_consumption_duo_premium'), "sub_consumption_duo_amazon_q" => subscriptions.include?('sub_consumption_duo_amazon_q'), "sub_consumption_eap" => subscriptions.include?('sub_consumption_eap'), "sub_consumption_storage" => subscriptions.include?('sub_consumption_storage'), "sub_proserv" => subscriptions.include?('sub_proserv'), "sub_dotcom_premium" => subscriptions.include?('sub_dotcom_premium'), "sub_dotcom_ultimate" => subscriptions.include?('sub_dotcom_ultimate'), "sub_sm_starter" => subscriptions.include?('sub_sm_starter'), "sub_sm_premium" => subscriptions.include?('sub_sm_premium'), "sub_sm_ultimate" => subscriptions.include?('sub_sm_ultimate'), "sub_usgov_12x5" => subscriptions.include?('sub_usgov_12x5'), "sub_usgov_24x7" => subscriptions.include?('sub_usgov_24x7'), "sub_gitlab_dedicated" => subscriptions.include?('sub_gitlab_dedicated'), "sub_edu" => subscriptions.include?('sub_edu'), "sub_oss" => subscriptions.include?('sub_oss'), "sub_community_other" => subscriptions.include?('sub_community_other'), "sub_ss_ase" => subscriptions.include?('sub_ss_ase'), 'sub_ss_growth' => subscriptions.include?('sub_ss_growth'), 'sub_ss_enterprise' => subscriptions.include?('sub_ss_enterprise'), "sub_other" => subscriptions.include?('sub_other'), "partner_customer" => account_is_partner_customer?(account, type), "not_in_sfdc" => false, "support_hold" => account.Support_Hold__c, "sold_to" => account_sold_to(account), "org_in_escalated_state" => (account.Account_Risk_Level__c == 'At Risk - Escalated') } end |
.global_sync_query_string ⇒ String
Provides the String needed to make a specific type of SOQL query
585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 |
# File 'lib/support_readiness/salesforce/accounts.rb', line 585 def self.global_sync_query_string <<~QUERY SELECT Account_ID_18__c, Name, Type, Ultimate_Parent_Sales_Segment_Employees__c, Account_Owner_Calc__c, Technical_Account_Manager_Name__c, GS_Health_Score_Color__c, Restricted_Account__c, Solutions_Architect_Lookup__r.Name, Account_Demographics_Geo__c, Account_Demographics_Region__c, Latest_Sold_To_Contact__r.Email, Latest_Sold_To_Contact__r.Name, Partner_Track__c, Partners_Partner_Type__c, Support_Hold__c, Account_Risk_Level__c, Support_Instance__c, ( SELECT Id, Name, Zuora__ProductName__c, Zuora__EffectiveEndDate__c, Zuora__Quantity__c, Zuora__TotalContractValue__c, Subscription_Status__c, Zuora__Subscription__c FROM Zuora__R00N40000001lGjTEAU__r WHERE Zuora__EffectiveEndDate__c != NULL ), ( SELECT Name, Zuora__SoldToWorkEmail__c FROM Zuora__R00N40000001kyLcEAI__r WHERE IsDeleted = false ORDER BY CreatedDate ASC LIMIT 1 ) FROM Account WHERE Type != 'Prospect' AND ( Type IN ('Customer', 'Former Customer') OR ( Type = 'Partner' AND Partners_Partner_Status__c IN ('Authorized', 'Former') AND Partners_Partner_Type__c IN ('Alliance', 'Channel') AND Partner_Track__c IN ('Open', 'Select', 'Technology') ) ) QUERY end |
.process_global_subs(account, charge_names) ⇒ Object
263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 |
# File 'lib/support_readiness/salesforce/accounts.rb', line 263 def self.process_global_subs(account, charge_names) sub_types = [] sub_types.push('sub_consumption_cicd_minutes') if charge_names.any? { |x| SubscriptionDefinitions.consumption_cicd_minutes.include?(x) } sub_types.push('sub_consumption_storage') if charge_names.any? { |x| SubscriptionDefinitions.consumption_storage.include?(x) } sub_types.push('sub_dotcom_premium') if charge_names.any? { |x| SubscriptionDefinitions.dotcom_premium.include?(x) } sub_types.push('sub_dotcom_ultimate') if charge_names.any? { |x| SubscriptionDefinitions.dotcom_ultimate.include?(x) } sub_types.push('sub_gitlab_dedicated') if charge_names.any? { |x| SubscriptionDefinitions.gitlab_dedicated.include?(x) } sub_types.push('sub_edu') if charge_names.any? { |x| SubscriptionDefinitions.edu.include?(x) } sub_types.push('sub_oss') if charge_names.any? { |x| SubscriptionDefinitions.oss.include?(x) } sub_types.push('sub_community_other') if charge_names.any? { |x| SubscriptionDefinitions.community_other.include?(x) } sub_types.push('sub_ss_growth') if charge_names.any? { |x| SubscriptionDefinitions.ss_success_advanced.include?(x) } sub_types.push('sub_ss_enterprise') if charge_names.any? { |x| SubscriptionDefinitions.ss_success_signature.include?(x) } sub_types.push('sub_ss_ase') if charge_names.any? { |x| SubscriptionDefinitions.ss_success_signature.include?(x) } sub_types.push('sub_ss_enterprise') if account.Account_ID_18__c == '00161000010fYlBAAU' && charge_names.select { |x| x =~ /Success\ Plan\ Services/ } sub_types.push('sub_ss_enterprise') if account.Account_ID_18__c == '001PL00000S7nT3YAJ' && charge_names.select { |x| x =~ /Success\ Plan\ Services/ } sub_types.push('sub_ss_enterprise') if account.Account_ID_18__c == '0016100000K8R8fAAF' && charge_names.select { |x| x =~ /Success\ Plan\ Services/ } sub_types.push('sub_ss_enterprise') if account.Account_ID_18__c == '0014M00001lcEpNQAU' && charge_names.select { |x| x =~ /Success\ Plan\ Services/ } if account.Account_ID_18__c == '0016100000SEhkLAAT' sub_types.push('sub_ss_enterprise') if (Date.parse('2025-04-29')..Date.parse('2026-04-28')).cover?(Date.today) sub_types.push('sub_ss_ase') if (Date.parse('2025-04-29')..Date.parse('2026-04-28')).cover?(Date.today) sub_types.push('sub_ss_growth') if (Date.parse('2026-04-29')..Date.parse('2027-04-28')).cover?(Date.today) end if account.Support_Instance__c != 'federal-support' has_12x5 = charge_names.any? { |x| SubscriptionDefinitions.usgov_12x5.include?(x) } has_24x7 = charge_names.any? { |x| SubscriptionDefinitions.usgov_24x7.include?(x) } unless has_12x5 || has_24x7 sub_types.push('sub_sm_premium') if charge_names.any? { |x| SubscriptionDefinitions.sm_premium.include?(x) } sub_types.push('sub_sm_ultimate') if charge_names.any? { |x| SubscriptionDefinitions.sm_ultimate.include?(x) } sub_types.push('sub_consumption_duo_premium') if charge_names.any? { |x| SubscriptionDefinitions.consumption_duo_premium.include?(x) } sub_types.push('sub_consumption_duo_enterprise') if charge_names.any? { |x| SubscriptionDefinitions.consumption_duo_enterprise.include?(x) } sub_types.push('sub_consumption_duo_amazon_q') if charge_names.any? { |x| SubscriptionDefinitions.consumption_duo_amazon_q.include?(x) } sub_types.push('sub_ss_ase') if charge_names.any? { |x| SubscriptionDefinitions.ss_ase.include?(x) } sub_types.push('sub_consumption_eap') if charge_names.any? { |x| SubscriptionDefinitions.consumption_eap.include?(x) } end end sub_types end |
.process_usgov_subs(account, charge_names) ⇒ Object
301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 |
# File 'lib/support_readiness/salesforce/accounts.rb', line 301 def self.process_usgov_subs(account, charge_names) sub_types = [] sub_types.push('sub_usgov_12x5') if charge_names.any? { |x| SubscriptionDefinitions.usgov_12x5.include?(x) } sub_types.push('sub_usgov_24x7') if charge_names.any? { |x| SubscriptionDefinitions.usgov_24x7.include?(x) } sub_types.push('sub_usgov_24x7') if charge_names.any? { |x| SubscriptionDefinitions.fedramp.include?(x) } sub_types.push('sub_gitlab_dedicated') if charge_names.any? { |x| SubscriptionDefinitions.fedramp.include?(x) } if account.Support_Instance__c == 'federal-support' sub_types.push('sub_sm_premium') if charge_names.any? { |x| SubscriptionDefinitions.sm_premium.include?(x) } sub_types.push('sub_sm_ultimate') if charge_names.any? { |x| SubscriptionDefinitions.sm_ultimate.include?(x) } sub_types.push('sub_consumption_duo_premium') if charge_names.any? { |x| SubscriptionDefinitions.consumption_duo_premium.include?(x) } sub_types.push('sub_consumption_duo_enterprise') if charge_names.any? { |x| SubscriptionDefinitions.consumption_duo_enterprise.include?(x) } sub_types.push('sub_consumption_duo_amazon_q') if charge_names.any? { |x| SubscriptionDefinitions.consumption_duo_amazon_q.include?(x) } sub_types.push('sub_ss_ase') if charge_names.any? { |x| SubscriptionDefinitions.ss_ase.include?(x) } sub_types.push('sub_consumption_eap') if charge_names.any? { |x| SubscriptionDefinitions.consumption_eap.include?(x) } end has_12x5 = charge_names.any? { |x| SubscriptionDefinitions.usgov_12x5.include?(x) } has_24x7 = charge_names.any? { |x| SubscriptionDefinitions.usgov_24x7.include?(x) } if has_12x5 || has_24x7 sub_types.push('sub_sm_premium') if charge_names.any? { |x| SubscriptionDefinitions.sm_premium.include?(x) } sub_types.push('sub_sm_ultimate') if charge_names.any? { |x| SubscriptionDefinitions.sm_ultimate.include?(x) } sub_types.push('sub_consumption_duo_premium') if charge_names.any? { |x| SubscriptionDefinitions.consumption_duo_premium.include?(x) } sub_types.push('sub_consumption_duo_enterprise') if charge_names.any? { |x| SubscriptionDefinitions.consumption_duo_enterprise.include?(x) } sub_types.push('sub_consumption_duo_amazon_q') if charge_names.any? { |x| SubscriptionDefinitions.consumption_duo_amazon_q.include?(x) } sub_types.push('sub_ss_ase') if charge_names.any? { |x| SubscriptionDefinitions.ss_ase.include?(x) } sub_types.push('sub_consumption_eap') if charge_names.any? { |x| SubscriptionDefinitions.consumption_eap.include?(x) } end sub_types end |
.update!(client, aid, **args) ⇒ Boolean
Updates an Account in Salesforce. This will exit on error
37 38 39 40 |
# File 'lib/support_readiness/salesforce/accounts.rb', line 37 def self.update!(client, aid, **args) client.connection.update!('Account', Id: aid, **args) true end |
.us_gov_check_query_string(aid) ⇒ String
Provides the String needed to make a specific type of SOQL query
546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 |
# File 'lib/support_readiness/salesforce/accounts.rb', line 546 def self.us_gov_check_query_string(aid) <<~STRING SELECT Zuora__Account__r.Account_ID_18__c, Zuora__Account__r.Support_Hold__c, Zuora__Account__r.Restricted_Account__c, Zuora__Subscription__c FROM Zuora__SubscriptionProductCharge__c WHERE Zuora__Account__r.Account_ID_18__c = '#{aid}' AND Subscription_Status__c = 'Active' AND Zuora__EffectiveEndDate__c >= #{(Date.today - 91.days).iso8601} AND ( Name IN ( '12x5 US Citizen Support - 1 Year', '12x5 US Citizen Support - 2 Year', '12x5 US Citizen Support - 3 Year', '12x5 US Citizen Support - Monthly', '24x7 US Citizen Support - 1 Year', '24x7 US Citizen Support - 2 Year', '24x7 US Citizen Support - 3 Year', '24x7 US Citizen Support - Monthly', 'GitLab Dedicated for US Public Sector - Ultimate - 1 Year', 'GitLab Dedicated for US Public Sector - Ultimate - 2 Year', 'GitLab Dedicated for US Public Sector - Ultimate - 3 Year', 'GitLab Dedicated for US Public Sector - Ultimate - Monthly' ) OR Zuora__Account__r.Support_Instance__c = 'federal-support' ) STRING end |
.us_gov_enabled?(client, aid) ⇒ Boolean
Determines if a SFDC Account is US Government enabled.
61 62 63 64 65 66 67 68 69 |
# File 'lib/support_readiness/salesforce/accounts.rb', line 61 def self.us_gov_enabled?(client, aid) query = Queries.new(us_gov_check_query_string(aid)) results = Queries.run!(client, query) return false if results.count.zero? return false if results.first.Zuora__Account__r.Support_Hold__c return false unless results.first.Zuora__Account__r.Restricted_Account__c.nil? true end |
.us_gov_only?(account, subs) ⇒ Boolean
Determines if a given account with its subscriptions is US Government only
510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 |
# File 'lib/support_readiness/salesforce/accounts.rb', line 510 def self.us_gov_only?(account, subs) return false if subs.count.zero? return false if subs.include? 'sub_consumption_cicd_minutes' return false if subs.include? 'sub_dotcom_premium' return false if subs.include? 'sub_dotcom_ultimate' return false if subs.include? 'sub_edu' return false if subs.include? 'sub_oss' return false if subs.include? 'sub_community_other' if subs.include?('sub_usgov_12x5') || subs.include?('sub_usgov_24x7') || account.Support_Instance__c == 'federal-support' global_subs_present = false grouped = account.Zuora__R00N40000001lGjTEAU__r.group_by { |z| z.Zuora__Subscription__c } grouped.each_value do |charges| valid_charges = charges.select { |c| c.Subscription_Status__c == 'Active' && Date.parse(c.Zuora__EffectiveEndDate__c) >= Date.today } next if valid_charges.count.zero? next if valid_charges.map { |a| a.Name }.any? { |x| SubscriptionDefinitions.usgov_12x5.include?(x) } next if valid_charges.map { |a| a.Name }.any? { |x| SubscriptionDefinitions.usgov_24x7.include?(x) } next if valid_charges.map { |a| a.Name }.any? { |x| SubscriptionDefinitions.fedramp.include?(x) } next if valid_charges.map { |a| a.Name }.any? { |x| SubscriptionDefinitions.sm_ultimate.include?(x) } && account.Support_Instance__c == 'federal-support' next if valid_charges.map { |a| a.Name }.any? { |x| SubscriptionDefinitions.sm_premium.include?(x) } && account.Support_Instance__c == 'federal-support' next if valid_charges.map { |a| a.Name }.any? { |x| SubscriptionDefinitions.sm_starter.include?(x) } && account.Support_Instance__c == 'federal-support' global_subs_present = true end return true unless global_subs_present end false end |
.usgov_accounts(client) ⇒ Array
Return an Array of accounts from Salesforce for US Government support
115 116 117 118 119 |
# File 'lib/support_readiness/salesforce/accounts.rb', line 115 def self.usgov_accounts(client) query = Queries.new(usgov_sync_query_string) results = Queries.run!(client, query) results.map { |r| usgov_sync_object(r) } end |
.usgov_highest_support_level(subscriptions) ⇒ Object
Returns an accounts highest support level for the US Government support sync
478 479 480 481 482 483 484 485 486 487 |
# File 'lib/support_readiness/salesforce/accounts.rb', line 478 def self.usgov_highest_support_level(subscriptions) return 'ultimate' if subscriptions.include? 'sub_sm_ultimate' return 'ultimate' if subscriptions.include? 'sub_gitlab_dedicated' return 'premium' if subscriptions.include? 'sub_sm_premium' return 'starter' if subscriptions.include? 'sub_sm_starter' return 'custom' if subscriptions.include? 'sub_usgov_12x5' return 'custom' if subscriptions.include? 'sub_usgov_24x7' 'expired' end |
.usgov_sync_object(account) ⇒ Object
Return a Hash used for the account sync for US Government support
189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 |
# File 'lib/support_readiness/salesforce/accounts.rb', line 189 def self.usgov_sync_object(account) subscriptions = account_subscriptions(account, 'usgov') expiration = account_expiration(account) type = account_type(account, expiration) partner = %w[alliance_partner open_partner select_partner].include?(type) { "name" => "#{Digest::SHA1.hexdigest(account.Account_ID_18__c)[0..7]} #{account.Name}", "salesforce_id" => account.Account_ID_18__c, "sfdc_short_id" => account.Account_ID_18__c[..-4], "support_level" => usgov_highest_support_level(subscriptions), "arr" => account_arr(account).to_f, "market_segment" => account_market_segment(account), "account_owner" => account.Account_Owner_Calc__c, "type" => type, "technical_account_manager" => account.Technical_Account_Manager_Name__c, "solutions_architect" => account.Solutions_Architect_Lookup__r&.Name, "number_of_seats" => account_seats(account).to_f, "health_score" => account_health_score(account), "expiration_date" => expiration, "restricted_account" => (account.Restricted_Account__c == 'Restricted Party'), "greatly_expired" => (partner ? false : Date.parse(expiration) <= Date.today.years_ago(3)), "emergency_support_24x7" => subscriptions.include?('sub_usgov_24x7'), "sub_consumption_ai" => subscriptions.include?('sub_consumption_ai'), "sub_consumption_cicd_minutes" => subscriptions.include?('sub_consumption_cicd_minutes'), "sub_consumption_duo_enterprise" => subscriptions.include?('sub_consumption_duo_enterprise'), "sub_consumption_duo_premium" => subscriptions.include?('sub_consumption_duo_premium'), "sub_consumption_duo_amazon_q" => subscriptions.include?('sub_consumption_duo_amazon_q'), "sub_consumption_eap" => subscriptions.include?('sub_consumption_eap'), "sub_consumption_storage" => subscriptions.include?('sub_consumption_storage'), "sub_proserv" => subscriptions.include?('sub_proserv'), "sub_dotcom_premium" => subscriptions.include?('sub_dotcom_premium'), "sub_dotcom_ultimate" => subscriptions.include?('sub_dotcom_ultimate'), "sub_sm_starter" => subscriptions.include?('sub_sm_starter'), "sub_sm_premium" => subscriptions.include?('sub_sm_premium'), "sub_sm_ultimate" => subscriptions.include?('sub_sm_ultimate'), "sub_usgov_12x5" => subscriptions.include?('sub_usgov_12x5'), "sub_usgov_24x7" => subscriptions.include?('sub_usgov_24x7'), "sub_gitlab_dedicated" => subscriptions.include?('sub_gitlab_dedicated'), "sub_edu" => subscriptions.include?('sub_edu'), "sub_oss" => subscriptions.include?('sub_oss'), "sub_community_other" => subscriptions.include?('sub_community_other'), "sub_ss_ase" => subscriptions.include?('sub_ss_ase'), "sub_other" => subscriptions.include?('sub_other'), "not_in_sfdc" => false, "support_hold" => account.Support_Hold__c, "date_marked_not_in_sfdc" => nil } end |
.usgov_sync_query_string ⇒ String
Provides the String needed to make a specific type of SOQL query
652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 |
# File 'lib/support_readiness/salesforce/accounts.rb', line 652 def self.usgov_sync_query_string <<~QUERY SELECT Account_ID_18__c, Name, Ultimate_Parent_Sales_Segment_Employees__c, Account_Owner_Calc__c, Technical_Account_Manager_Name__c, GS_Health_Score_Color__c, Restricted_Account__c, Solutions_Architect_Lookup__r.Name, Support_Hold__c, Support_Instance__c, ( SELECT Id, Name, Zuora__ProductName__c, Zuora__EffectiveEndDate__c, Zuora__Quantity__c, Zuora__TotalContractValue__c, Subscription_Status__c, Zuora__Subscription__c FROM Zuora__R00N40000001lGjTEAU__r ) FROM Account WHERE Id IN ( SELECT Zuora__Account__c FROM Zuora__SubscriptionProductCharge__c WHERE Subscription_Status__c = 'Active' AND Zuora__EffectiveEndDate__c >= #{(Date.today - 91.days).iso8601} AND ( Name IN ( '12x5 US Citizen Support - 1 Year', '12x5 US Citizen Support - 2 Year', '12x5 US Citizen Support - 3 Year', '12x5 US Citizen Support - Monthly', '24x7 US Citizen Support - 1 Year', '24x7 US Citizen Support - 2 Year', '24x7 US Citizen Support - 3 Year', '24x7 US Citizen Support - Monthly', 'GitLab Dedicated for US Public Sector - Ultimate - 1 Year', 'GitLab Dedicated for US Public Sector - Ultimate - 2 Year', 'GitLab Dedicated for US Public Sector - Ultimate - 3 Year', 'GitLab Dedicated for US Public Sector - Ultimate - Monthly' ) OR Zuora__Account__r.Support_Instance__c = 'federal-support' ) ) QUERY end |