<commit_before>class FormulaPdf < Prawn::Document

  def initialize(formula, view)
    super(page_size: [210.mm, 297.mm], margin: [0.mm, 0.mm, 0.mm, 0.mm], skip_page_creation: true)
    @view = view
    @formula = formula
    @premix = Premix.find formula.id
    reset_page_properties
    draw
  end

  def reset_page_properties
    @detail_height = 5.mm
    @py = 268.mm
  end

  def draw
    @total_pages = 0
    new_page
    draw_formula
    self
  end

  def draw_formula
    @py = @py - 10.mm
    formula_start_at = @py + 6.mm
    stroke_horizontal_line 10.mm, 200.mm, at: @py + 13.mm
    @py = @py + 8.mm

    draw_text "Optimize by - Least Cost Feed (leastcostfeed.com)", size: 14, style: :bold, at: [10.mm, 287.mm]
    draw_text "Produce by - #{User.current.name} at #{@premix.updated_at.in_time_zone(User.current.time_zone).to_s(:long)}", size: 12, at: [10.mm, 281.mm]

    draw_text "Formula:", size: 12, at: [10.mm, 275.mm], style: :bold
    draw_text "#{@premix.name}", size: 12, at: [30.mm, 275.mm], style: :italic

    draw_text "Cost:", size: 12, at: [90.mm, 275.mm], style: :bold
    draw_text @view.number_with_precision("#{@premix.cost*1000}/1000#{User.current.weight_unit}", precision: 2), size: 12, at: [105.mm, 275.mm], style: :italic

    draw_text "Batch Size:", size: 12, at: [140.mm, 275.mm], style: :bold
    draw_text "#{@premix.batch_size} #{User.current.weight_unit}", size: 12, at: [170.mm, 275.mm], style: :italic

    draw_text "Ingredient", size: 12, style: :bold_italic, at: [10.mm, @py]
    draw_text "Cost", size: 12, style: :bold_italic, at: [70.mm, @py]
    draw_text "%", size: 12, style: :bold_italic, at: [93.mm, @py]
    draw_text "#{User.current.weight_unit}", size: 12, style: :bold_italic, at: [113.mm, @py]
    draw_text "Amount", size: 12, style: :bold_italic, at: [124.mm, @py]
    draw_text "Amt/1000#{User.current.weight_unit}", size: 12, style: :bold_italic, at: [144.mm, @py]
    draw_text "Cost %", size: 12, style: :bold_italic, at: [173.mm, @py]

    @py = @py - 2.mm
    @formula.formula_ingredients.select { |t| t.actual > 0 }.each do |i|
      bounding_box [10.mm, @py], height: @detail_height, width: 53.mm do
        font("#{Rails.root}/vendor/assets/fonts/DroidSansFallbackFull.ttf") do
          text i.ingredient_name, size: 12, overflow: :shrink_to_fit, valign: :center
        end
      end
      bounding_box [60.mm, @py], height: @detail_height, width: 20.mm do
        text @view.number_with_precision(i.ingredient_cost, precision: 4), size: 12, overflow: :shrink_to_fit, valign: :center, align: :right
      end
      bounding_box [80.mm, @py], height: @detail_height, width: 20.mm do
        text @view.number_with_precision(i.actual_perc, precision: 4), size: 12, overflow: :shrink_to_fit, valign: :center, align: :right
      end
      bounding_box [100.mm, @py], height: @detail_height, width: 20.mm do
        text @view.number_with_precision(i.weight, precision: 2), size: 12, overflow: :shrink_to_fit, valign: :center, align: :right
      end
      bounding_box [120.mm, @py], height: @detail_height, width: 20.mm do
        text @view.number_with_precision(i.weight * i.ingredient_cost, precision: 2), size: 12, overflow: :shrink_to_fit, valign: :center, align: :right
      end<commit_msg>added bugfixed cost to print format<commit_after>class FormulaPdf < Prawn::Document

  def initialize(formula, view)
    super(page_size: [210.mm, 297.mm], margin: [0.mm, 0.mm, 0.mm, 0.mm], skip_page_creation: true)
    @view = view
    @formula = formula
    @premix = Premix.find formula.id
    reset_page_properties
    draw
  end

  def reset_page_properties
    @detail_height = 5.mm
    @py = 268.mm
  end

  def draw
    @total_pages = 0
    new_page
    draw_formula
    self
  end

  def draw_formula
    @py = @py - 10.mm
    formula_start_at = @py + 6.mm
    stroke_horizontal_line 10.mm, 200.mm, at: @py + 13.mm
    @py = @py + 8.mm

    draw_text "Optimize by - Least Cost Feed (leastcostfeed.com)", size: 14, style: :bold, at: [10.mm, 287.mm]
    draw_text "Produce by - #{User.current.name} at #{@premix.updated_at.in_time_zone(User.current.time_zone).to_s(:long)}", size: 12, at: [10.mm, 281.mm]

    draw_text "Formula:", size: 12, at: [10.mm, 275.mm], style: :bold
    draw_text "#{@premix.name}", size: 12, at: [30.mm, 275.mm], style: :italic

    draw_text "Cost:", size: 12, at: [90.mm, 275.mm], style: :bold
    draw_text "#{@premix.cost}/#{User.current.weight_unit}", size: 12, at: [105.mm, 275.mm], style: :italic

    draw_text "Batch Size:", size: 12, at: [140.mm, 275.mm], style: :bold
    draw_text "#{@premix.batch_size} #{User.current.weight_unit}", size: 12, at: [170.mm, 275.mm], style: :italic

    draw_text "Ingredient", size: 12, style: :bold_italic, at: [10.mm, @py]
    draw_text "Cost", size: 12, style: :bold_italic, at: [70.mm, @py]
    draw_text "%", size: 12, style: :bold_italic, at: [93.mm, @py]
    draw_text "#{User.current.weight_unit}", size: 12, style: :bold_italic, at: [113.mm, @py]
    draw_text "Amount", size: 12, style: :bold_italic, at: [124.mm, @py]
    draw_text "Amt/1000#{User.current.weight_unit}", size: 12, style: :bold_italic, at: [144.mm, @py]
    draw_text "Cost %", size: 12, style: :bold_italic, at: [173.mm, @py]

    @py = @py - 2.mm
    @formula.formula_ingredients.select { |t| t.actual > 0 }.each do |i|
      bounding_box [10.mm, @py], height: @detail_height, width: 53.mm do
        font("#{Rails.root}/vendor/assets/fonts/DroidSansFallbackFull.ttf") do
          text i.ingredient_name, size: 12, overflow: :shrink_to_fit, valign: :center
        end
      end
      bounding_box [60.mm, @py], height: @detail_height, width: 20.mm do
        text @view.number_with_precision(i.ingredient_cost, precision: 4), size: 12, overflow: :shrink_to_fit, valign: :center, align: :right
      end
      bounding_box [80.mm, @py], height: @detail_height, width: 20.mm do
        text @view.number_with_precision(i.actual_perc, precision: 4), size: 12, overflow: :shrink_to_fit, valign: :center, align: :right
      end
      bounding_box [100.mm, @py], height: @detail_height, width: 20.mm do
        text @view.number_with_precision(i.weight, precision: 2), size: 12, overflow: :shrink_to_fit, valign: :center, align: :right
      end
      bounding_box [120.mm, @py], height: @detail_height, width: 20.mm do
        text @view.number_with_precision(i.weight * i.ingredient_cost, precision: 2), size: 12, overflow: :shrink_to_fit, valign: :center, align: :right
      end
{'fraction_non_alphanumeric': 0.15759532595325954, 'fraction_numerical': 0.050276752767527674, 'mean_word_length': 3.571328179901616, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '798446', 'n_tokens_mistral': 2786, 'n_tokens_neox': 2431, 'n_words': 638}