<commit_before>class ReviewCapitalPlanModule < BaseCapitalPlanModule

  include TransamFormatHelper

  def complete
    plan = @capital_plan_module.capital_plan

    # soft delete all capital projects and ALIs
    projs = CapitalProject.where(organization_id: plan.organization_id, fy_year: plan.fy_year)
    alis = ActivityLineItem.where(capital_project_id: projs.ids)
    alis.update_all(active: false)
    projs.update_all(active: false)

    alis.each do |ali|
      # mark all assets as under replacement
      ali.assets.each do |asset|
        ReplacementStatusUpdateEvent.create(replacement_year: plan.fy_year, replacement_status_type_id: ReplacementStatusType.find_by(name: 'Underway').id, comments: "The #{format_as_fiscal_year(plan.fy_year)} capital plan includes the replacement of this asset.")
        asset.update_replacement_status
        asset.update_sogr
      end

      # update bucket budget amounts and committed amounts, soft delete if bucket used up
      ali.funding_requests.each do |request|
        fed_bucket = request.federal_funding_line_item
        fed_bucket.budget_amount = fed_bucket.budget_amount-request.federal_amount
        fed_bucket.budget_committed = fed_bucket.budget_committed-request.federal_amount
        if fed_bucket.budget_amount == 0
          fed_bucket.active = false
        end
        fed_bucket.save

        state_bucket = request.state_funding_line_item
        state_bucket.budget_amount = state_bucket.budget_amount-request.state_amount
        state_bucket.budget_committed = state_bucket.budget_committed-request.state_amount
        if state_bucket.budget_amount == 0
          state_bucket.active = false
        end
        state_bucket.save<commit_msg>set asset on replacement status asset event TTPLAT-1340<commit_after>class ReviewCapitalPlanModule < BaseCapitalPlanModule

  include TransamFormatHelper

  def complete
    plan = @capital_plan_module.capital_plan

    # soft delete all capital projects and ALIs
    projs = CapitalProject.where(organization_id: plan.organization_id, fy_year: plan.fy_year)
    alis = ActivityLineItem.where(capital_project_id: projs.ids)
    alis.update_all(active: false)
    projs.update_all(active: false)

    alis.each do |ali|
      # mark all assets as under replacement
      ali.assets.each do |asset|
        ReplacementStatusUpdateEvent.create(transam_asset: asset, replacement_year: plan.fy_year, replacement_status_type_id: ReplacementStatusType.find_by(name: 'Underway').id, comments: "The #{format_as_fiscal_year(plan.fy_year)} capital plan includes the replacement of this asset.")
        asset.update_replacement_status
        asset.update_sogr
      end

      # update bucket budget amounts and committed amounts, soft delete if bucket used up
      ali.funding_requests.each do |request|
        fed_bucket = request.federal_funding_line_item
        fed_bucket.budget_amount = fed_bucket.budget_amount-request.federal_amount
        fed_bucket.budget_committed = fed_bucket.budget_committed-request.federal_amount
        if fed_bucket.budget_amount == 0
          fed_bucket.active = false
        end
        fed_bucket.save

        state_bucket = request.state_funding_line_item
        state_bucket.budget_amount = state_bucket.budget_amount-request.state_amount
        state_bucket.budget_committed = state_bucket.budget_committed-request.state_amount
        if state_bucket.budget_amount == 0
          state_bucket.active = false
        end
        state_bucket.save
{'fraction_non_alphanumeric': 0.062428734321550744, 'fraction_numerical': 0.002280501710376283, 'mean_word_length': 3.6724367509986684, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4039300', 'n_tokens_mistral': 1042, 'n_tokens_neox': 998, 'n_words': 210}