<commit_before>module Generators::Reports  
  class IrsYearlyPdfReport < PdfReport
    include ActionView::Helpers::NumberHelper

    attr_accessor :responsible_party_data, :settings, :calender_year

    def initialize(notice, options={})
      @settings = YAML.load(File.read("#{Rails.root}/config/irs_settings.yml")).with_indifferent_access
      initialize_variables(options)

      super({:template => get_template(options), :margin => [30, 55]})
      font_size 11

      @notice = notice
      @margin = [30, 70]
    end

    def get_template(options)
      notice_type = (['new', 'corrected'].include?(options[:notice_type]) ? 'new' : options[:notice_type])

      if options[:calender_year] == 2016 && options[:notice_type] != 'void'
        template_name = settings[:tax_document][options[:calender_year]][notice_type][:template][options[:qhp_type]]
      else
        template_name = settings[:tax_document][options[:calender_year]][notice_type][:template]
      end

      "#{Rails.root}/lib/pdf_templates/#{template_name}"
    end

    def initialize_variables(options)
      @calender_year = options[:calender_year]
      @multiple = options[:multiple]
      @corrected = options[:notice_type] == 'corrected'

      settings[:tax_document].keys.each do |year|
        instance_variable_set("@notice_#{year}", false)
        instance_variable_set("@void_#{year}", false)
      end

      if ['new', 'corrected'].include?(options[:notice_type])
        instance_variable_set("@notice_#{options[:calender_year]}", true)
      end

      if options[:notice_type] == 'void'
        instance_variable_set("@void_#{options[:calender_year]}", true)
      end

      @catastrophic = false
      @catastrophic_corrected = false
      @catastrophic_aptc = false
      @catastrophic_confirmation =  false
      @void = @void_2014
    end

    def process
      fill_envelope
      fill_coverletter
      return if @catastrophic_confirmation
      if @catastrophic_corrected
        go_to_page(3)
      elsif @notice_2016 || @void_2016
        go_to_page(9)
      else
        go_to_page(5)
      end
      fill_subscriber_details
      fill_household_details unless (@void || @void_2016)
      fill_preimum_details
    end

    def fill_envelope
      x_pos = mm2pt(21.83) - @margin[0]
      y_pos = 790.86 - mm2pt(57.15) - 65

      bounding_box([x_pos, y_pos], :width => 300) do
        fill_recipient_contact
      end
    end

    def fill_coverletter
      go_to_page(settings[:tax_document][calender_year][:coverage_page_no])

      padding = 31
      padding = 10

      padding = 26 if @void_2014 || @void_2016

      bounding_box([15, 553+padding], :width => 200) do
        text "#{Date.today.strftime('%m/%d/%Y')}"
      end

      bounding_box([15, 525+padding], :width => 300) do
        fill_recipient_contact
      end

      y_pos = if @catastrophic
        405
      elsif @catastrophic_corrected
        444
      else
        if @notice_2014 # 2014
          418
        else
          # 430 # 2014 void
          430 # 2015
        end
      end

      x_pos = 44

      x_pos = 42 if @catastrophic_corrected

      padding = 12 unless @void
      padding = 20 if @void_2016
      y_pos = 409 if @void_2016
      y_pos = 444 if @void_2015

      bounding_box([x_pos, y_pos+padding], :width => 200) do
        text "#{@notice.recipient.name}:"
      end

      padding = -20 if @void_2016


      if @void_2016
        bounding_box([93, 242+padding], :width => 200) do
          text @notice.canceled_policies.blank? ? 'None' : @notice.canceled_policies
        end

        bounding_box([100, 132+padding], :width => 200) do
          text @notice.active_policies.blank? ? 'None' : @notice.active_policies
        end
      end

      if @void_2015
        bounding_box([133, 237+padding], :width => 200) do
          text @notice.canceled_policies.blank? ? 'None' : @notice.canceled_policies
        end

        bounding_box([120, 141+padding], :width => 200) do
          text @notice.active_policies.blank? ? 'None' : @notice.active_policies
        end
      end

      if @void_2014
        bounding_box([133, 292+padding], :width => 200) do
          text @notice.canceled_policies.blank? ? 'None' : @notice.canceled_policies
        end

        bounding_box([120, 223+padding], :width => 200) do
          text @notice.active_policies.blank? ? 'None' : @notice.active_policies
        end
      end
    end

    def fill_recipient_contact
      text @notice.recipient.name
      text @notice.recipient_address.street_1
      text @notice.recipient_address.street_2 unless @notice.recipient_address.street_2.blank?
      text "#{@notice.recipient_address.city}, #{@notice.recipient_address.state} #{@notice.recipient_address.zip}"      
    end

    def fill_subscriber_details

      col1 = mm2pt(-2)
      col2 = mm2pt(51.50)
      col3 = mm2pt(102.50)
      col4 = mm2pt(145.50)
      y_pos = 790.86 - mm2pt(37.15) - 45

      x_pos_corrected = mm2pt(128.50)
      y_pos_corrected = 790.86 - mm2pt(31.80)
      y_pos_corrected = 790.86 - mm2pt(23.80) if @void_2015 || @void_2016

      if @corrected || @void || @void_2015 || @void_2016
        bounding_box([x_pos_corrected, y_pos_corrected], :width => 100) do
          font "/Library/Fonts/Arial Unicode.ttf"
          text "\u2714"
        end
      end

      font "Times-Roman"
<commit_msg>Refs #18659 changed checkmark to 'x'<commit_after>module Generators::Reports  
  class IrsYearlyPdfReport < PdfReport
    include ActionView::Helpers::NumberHelper

    attr_accessor :responsible_party_data, :settings, :calender_year

    def initialize(notice, options={})
      @settings = YAML.load(File.read("#{Rails.root}/config/irs_settings.yml")).with_indifferent_access
      initialize_variables(options)

      super({:template => get_template(options), :margin => [30, 55]})
      font_size 11

      @notice = notice
      @margin = [30, 70]
    end

    def get_template(options)
      notice_type = (['new', 'corrected'].include?(options[:notice_type]) ? 'new' : options[:notice_type])

      if options[:calender_year] == 2016 && options[:notice_type] != 'void'
        template_name = settings[:tax_document][options[:calender_year]][notice_type][:template][options[:qhp_type]]
      else
        template_name = settings[:tax_document][options[:calender_year]][notice_type][:template]
      end

      "#{Rails.root}/lib/pdf_templates/#{template_name}"
    end

    def initialize_variables(options)
      @calender_year = options[:calender_year]
      @multiple = options[:multiple]
      @corrected = options[:notice_type] == 'corrected'

      settings[:tax_document].keys.each do |year|
        instance_variable_set("@notice_#{year}", false)
        instance_variable_set("@void_#{year}", false)
      end

      if ['new', 'corrected'].include?(options[:notice_type])
        instance_variable_set("@notice_#{options[:calender_year]}", true)
      end

      if options[:notice_type] == 'void'
        instance_variable_set("@void_#{options[:calender_year]}", true)
      end

      @catastrophic = false
      @catastrophic_corrected = false
      @catastrophic_aptc = false
      @catastrophic_confirmation =  false
      @void = @void_2014
    end

    def process
      fill_envelope
      fill_coverletter
      return if @catastrophic_confirmation
      if @catastrophic_corrected
        go_to_page(3)
      elsif @notice_2016 || @void_2016
        go_to_page(9)
      else
        go_to_page(5)
      end
      fill_subscriber_details
      fill_household_details unless (@void || @void_2016)
      fill_preimum_details
    end

    def fill_envelope
      x_pos = mm2pt(21.83) - @margin[0]
      y_pos = 790.86 - mm2pt(57.15) - 65

      bounding_box([x_pos, y_pos], :width => 300) do
        fill_recipient_contact
      end
    end

    def fill_coverletter
      go_to_page(settings[:tax_document][calender_year][:coverage_page_no])

      padding = 31
      padding = 10

      padding = 26 if @void_2014 || @void_2016

      bounding_box([15, 553+padding], :width => 200) do
        text "#{Date.today.strftime('%m/%d/%Y')}"
      end

      bounding_box([15, 525+padding], :width => 300) do
        fill_recipient_contact
      end

      y_pos = if @catastrophic
        405
      elsif @catastrophic_corrected
        444
      else
        if @notice_2014 # 2014
          418
        else
          # 430 # 2014 void
          430 # 2015
        end
      end

      x_pos = 44

      x_pos = 42 if @catastrophic_corrected

      padding = 12 unless @void
      padding = 20 if @void_2016
      y_pos = 409 if @void_2016
      y_pos = 444 if @void_2015

      bounding_box([x_pos, y_pos+padding], :width => 200) do
        text "#{@notice.recipient.name}:"
      end

      padding = -20 if @void_2016


      if @void_2016
        bounding_box([93, 242+padding], :width => 200) do
          text @notice.canceled_policies.blank? ? 'None' : @notice.canceled_policies
        end

        bounding_box([100, 132+padding], :width => 200) do
          text @notice.active_policies.blank? ? 'None' : @notice.active_policies
        end
      end

      if @void_2015
        bounding_box([133, 237+padding], :width => 200) do
          text @notice.canceled_policies.blank? ? 'None' : @notice.canceled_policies
        end

        bounding_box([120, 141+padding], :width => 200) do
          text @notice.active_policies.blank? ? 'None' : @notice.active_policies
        end
      end

      if @void_2014
        bounding_box([133, 292+padding], :width => 200) do
          text @notice.canceled_policies.blank? ? 'None' : @notice.canceled_policies
        end

        bounding_box([120, 223+padding], :width => 200) do
          text @notice.active_policies.blank? ? 'None' : @notice.active_policies
        end
      end
    end

    def fill_recipient_contact
      text @notice.recipient.name
      text @notice.recipient_address.street_1
      text @notice.recipient_address.street_2 unless @notice.recipient_address.street_2.blank?
      text "#{@notice.recipient_address.city}, #{@notice.recipient_address.state} #{@notice.recipient_address.zip}"      
    end

    def fill_subscriber_details

      col1 = mm2pt(-2)
      col2 = mm2pt(51.50)
      col3 = mm2pt(102.50)
      col4 = mm2pt(145.50)
      y_pos = 790.86 - mm2pt(37.15) - 45

      x_pos_corrected = mm2pt(128.50)
      y_pos_corrected = 790.86 - mm2pt(31.80)
      y_pos_corrected = 790.86 - mm2pt(23.80) if @void_2015 || @void_2016

      if @corrected || @void || @void_2015 || @void_2016
        bounding_box([x_pos_corrected, y_pos_corrected], :width => 100) do
          text "x"
        end
      end

      font "Times-Roman"

{'fraction_non_alphanumeric': 0.11506900410294667, 'fraction_numerical': 0.05641551659828422, 'mean_word_length': 2.640529531568228, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 29, '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': '822841', 'n_tokens_mistral': 4048, 'n_tokens_neox': 3469, 'n_words': 684}