Class: Pdf::Document::ElectricalPlan

Inherits:
BaseService
  • Object
show all
Includes:
Base
Defined in:
app/services/pdf/document/electrical_plan.rb

Constant Summary collapse

FONT_BOLD =
"#{FONT} bold".freeze
FALLBACK_FONT =
'DejaVuSans'.freeze

Constants included from Base

Base::FONT, Base::NIMBUS_SANS_PATH, Base::NIMBUS_SANS_PATH_BOLD, Base::WY_LOGO_PATH

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(suggested_skus, room_configuration) ⇒ ElectricalPlan

Returns a new instance of ElectricalPlan.



9
10
11
12
13
14
15
16
17
18
19
20
# File 'app/services/pdf/document/electrical_plan.rb', line 9

def initialize(suggested_skus, room_configuration)
  @rc = room_configuration
  @hep = Item::HeatingElementPlan.new_from_room_configuration(@rc)
  @controls = @hep.electrical_plan_controls.collect(&:item).uniq
  @num_integration_kits = @hep.integration_kits.sum(:quantity)
  @num_power_modules = @hep.power_modules.sum(:quantity)
  @control_name = @num_integration_kits.positive? ? 'integration kit' : 'thermostat'
  @suggested_skus = suggested_skus unless suggested_skus.empty?
  @suggested_skus = @rc.get_material_alerts.collect(&:items).flatten.collect(&:sku) if suggested_skus.empty?
  @with_pole_assignment = @rc.element_pole_assignments.present?
  @composer = initialize_composer
end

Instance Attribute Details

#composerObject (readonly)

Returns the value of attribute composer.



7
8
9
# File 'app/services/pdf/document/electrical_plan.rb', line 7

def composer
  @composer
end

Instance Method Details

#callObject



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
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
183
184
185
186
187
188
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
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
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
300
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
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
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
538
539
540
541
542
543
544
545
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
577
578
579
580
581
582
583
584
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
644
645
646
647
648
649
650
651
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
707
708
# File 'app/services/pdf/document/electrical_plan.rb', line 26

def call

  l = composer.document.layout

  # ------------------------------------------------------------
  # Header Section (the legacy template hides an H1, then shows the header)
  composer.container do |container|
    # Hidden header placeholder (for accessibility; actual header content is rendered below in the footer)
    container.text('', style: { font: FONT_BOLD, font_size: 1 })
    container.text('Exclusively designed for:', style: { fill_color: '777', font: FONT, font_size: 11 }, padding: [0, 0, 5, 0])
    container.text(@rc.customer.full_name, style: { font: FONT_BOLD, font_size: 15 }, padding: [0, 0, 5, 0])
  end

  # ------------------------------------------------------------
  # Row 1: Left Column (Customer Info & Installation Notes) / Right Column (Heating System Details)
  composer.container(width: 562, style: { position: :flow, padding: [0, 0, 10, 0] }) do |container|
    # Left Column
    container.container(width: 281, style: { position: :float, align: :left }) do |left_container|
      left_container.formatted_text([
                                      { text: 'Date: ', style: { font: FONT_BOLD, fill_color: '111', font_size: 12 } },
                                      { text: (@rc.plan_created_at || @rc.created_at || Time.current).to_fs(:crm_date_only), style: { font: FONT, fill_color: '444', font_size: 12 } }
                                    ], style: { padding: [0, 0, 3, 0] })
      left_container.formatted_text([
                                      { text: "#{@hep.room_label}: ", style: { font: FONT, fill_color: '111', font_size: 12 } },
                                      { text: truncate(@rc.name, length: 40).to_s, style: { font: FONT, fill_color: '444', font_size: 12 } }
                                    ], style: { padding: [0, 0, 3, 0] })

      left_container.formatted_text([
                                      { text: 'Plan Number: ', style: { font: FONT_BOLD, fill_color: '111', font_size: 12 } },
                                      { text: @rc.reference_number.to_s, style: { font: FONT, fill_color: '444', font_size: 12 } }
                                    ], style: { padding: [0, 0, 3, 0] })
      left_container.formatted_text([
                                      { text: 'Notes: ', style: { font: FONT_BOLD, fill_color: '111', font_size: 12 } }
                                    ], style: { padding: [0, 0, 5, 0] })

      installation_notes = @hep.instructions(true)
      left_container.container(width: 281, style: { position: :flow }) do |list_container|
        installation_notes.each_with_index do |rule, index|
          list_container.container(width: 281, style: { position: :flow }) do |row|
            row.container(width: 10, style: { position: :float, align: :left }) { |int| int.text("#{index + 1}. ", style: { line_height: 11, font: FONT, fill_color: 'FFFFFF', font_size: 8 }) }
            row.container(width: 271, style: { position: :float, align: :right }) { |txt| txt.text(rule, style: { line_height: 11, font: FONT, fill_color: 'FFFFFF', font_size: 8, padding: [0, 21, 0, 0] }) }
          end
        end
      end
    end

    container.container(width: 281, style: { position: :float, align: :right }) do |right_container|
      right_container.formatted_text([
                                       { text: 'Heating System: ', style: { font: FONT_BOLD, fill_color: '111', font_size: 12 } },
                                       { text: "#{@hep.heating_system_voltage ? "#{@hep.heating_system_voltage}V* " : ''}#{@hep.heating_system_name}", style: { font: FONT, fill_color: '444', font_size: 12 } }
                                     ], style: { padding: [0, 0, 4, 0] })

      unless @hep.is_countertop?
        right_container.formatted_text([
                                         { text: 'Wattage: ', style: { font: FONT_BOLD, fill_color: '111', font_size: 12 } },
                                         { text: @hep.watts_per_sqft.to_s, style: { font: FONT, fill_color: '444', font_size: 12 } }
                                       ], style: { padding: [0, 0, 2, 0] })
      end

      if @num_integration_kits.positive?
        right_container.formatted_text([{ text: 'Control: ', style: { font: FONT_BOLD, fill_color: '111', font_size: 12 } },
                                        { text: 'Third Party Thermostat', style: { font: FONT, fill_color: '444', font_size: 12, padding: [0, 0, 3, 0] } }])
      else
        right_container.formatted_text([
                                         { text: 'Control: ', style: { font: FONT_BOLD, fill_color: '111', font_size: 12 } },
                                         { text: "#{@hep.control_voltage}V* " + @controls.collect { |c| c.public_name }.join(', '), style: { font: FONT, fill_color: '444', font_size: 12, line_height: 15 } }
                                       ], style: { padding: [0, 0, 3, 0] })
      end

      right_container.text('* Verify that the heating system and control is supplied this voltage from the breaker panel.', style: { fill_color: '333', font: FONT_BOLD, font_size: 10, line_height: 13 })
    end
  end

  # header_row is an array of hashes (one row)
  header_row = @hep.heating_elements_table_column_headers(
    with_cold_lead: true,
    with_ohms: true,
    with_pole_assignment: @with_pole_assignment
  ).map do |attrib, col_header|
    { content: l.text(col_header.to_s,
                      style: { font: FONT, font_size: 8, fill_color: '555', background_color: (@hep.highlighted_columns.include?(attrib) ? 'yellow' : nil) },
                      padding: [0, 0, -3, 0]),
      col_span: 1 }
  end

  # table_data is an array of rows (each row is an array of cell hashes)
  table_data = @hep.heating_elements_table(
    with_cold_lead: true,
    with_ohms: true,
    with_pole_assignment: @with_pole_assignment
  ).map do |item|
    @hep.heating_elements_table_column_headers(
      with_cold_lead: true,
      with_ohms: true,
      with_pole_assignment: @with_pole_assignment
    ).keys.map do |attrib|
      { content: l.text(item[attrib].to_s.tr('', "'").tr('', '"'),
                        style: { font: FONT, font_size: 8, fill_color: '555' },
                        padding: [0, 0, -3, 0]),
        col_span: 1 }
    end
  end

  col_count = @hep.heating_elements_table_column_headers(with_cold_lead: true,
                                                         with_ohms: true,
                                                         with_pole_assignment: @with_pole_assignment).size

  data1 = []
  data1 << [
    { content: l.text("#{@hep.heating_system_name} Specifications", style: { font: FONT, font_size: 12, padding: [0, 0, -3, 5], fill_color: '333' }), col_span: col_count }
  ]
  data1 << header_row # Add the header row first.
  data1.concat(table_data)

  # Append the footers if any exist.
  if @hep.heating_elements_table_footers.any?
    footer_row = @hep.heating_elements_table_column_headers(with_cold_lead: true, with_ohms: true, with_pole_assignment: @with_pole_assignment).map do |attrib, _col_header|
      { content: l.text(@hep.heating_elements_table_footers[attrib].to_s, style: { font: FONT_BOLD, font_size: 8, fill_color: '333', padding: [0, 0, -3, 0] }), col_span: 1 }
    end
    data1 << footer_row
  end

  # Append alternative volts explanation rows.
  @hep.alternative_volts_explanation.each do |symbol, alt_volts|
    alt_row = [
      { content: l.text("#{symbol} Other compatible voltages: #{alt_volts}", style: { font: FONT_BOLD, font_size: 10, fill_color: '333', padding: [0, 0, -3, 0] }), col_span: 8 }
    ]
    data1 << alt_row
  end

  breaker_content = [
    { text: "BREAKER SIZE NEEDED:\n", style: { font: FONT_BOLD, font_size: 10, fill_color: '333', line_height: 12, padding: [0, 0, -3, 0] } },
    { text: @hep.breaker_rules.join("\n"), style: { font: FONT_BOLD, font_size: 10, fill_color: '333', line_height: 12, padding: [0, 0, -3, 0] } }
  ]

  breaker_content << { text: "\n" + @rc.service_panel_note, style: { font: FONT_BOLD, font_size: 10, fill_color: '333', line_height: 12, padding: [0, 0, -3, 0] } } if @rc.service_panel_note.present?

  if @rc&.room_type&.is_outdoor?
    breaker_content << {
      text: "\n" + '* The National Electric Code requires that outdoor heating cables and rolls must be supplied power by a GFEP (30mA) protected circuit. GFEP (ground fault equipment protection) is required for fixed outdoor electric deicing and snow melting equipment; and electric heat tracing. This protection is provided by GFEP breakers which are not supplied by WarmlyYours.', style: {
        font: FONT_BOLD, font_size: 6.5, fill_color: '434', line_height: 10, padding: [0, 0, -3, 0]
      }
    }
  end

  data2 = [
    [{ content: l.text('Service Panel', style: { font: FONT, font_size: 12, padding: [0, 0, -3, 5], fill_color: '333' }) }],
    [{ content: l.formatted_text(breaker_content) }]
  ]

  data3 = []
  unless /Snow|Roof & Gutter Deicing|pipe/i.match?(@hep.heating_system)
    @controls.each do |control|
      data3 << [
        { content: l.text('Control Specifications', style: { font: FONT, font_size: 12, padding: [0, 0, -3, 0], fill_color: '333' }), col_span: 2 }
      ]
      data3 << [
        { content: l.text('Model #', style: { font: FONT_BOLD, font_size: 9, fill_color: '444', padding: [0, 0, -3, 0] }), col_span: 1 },
        { content: l.text(control.sku.to_s, style: { font: FONT, font_size: 9, fill_color: '666', padding: [0, 0, -3, 0] }), col_span: 1 }
      ]
      data3 << [
        { content: l.text('Ground Fault Protection (GFCI)', style: { font: FONT_BOLD, font_size: 9, fill_color: '444', padding: [0, 0, -3, 0] }), col_span: 1 },
        { content: l.text(control.spec_value(:gfci).to_s, style: { font: FONT, font_size: 9, fill_color: '666', padding: [0, 0, -3, 0] }), col_span: 1 }
      ]

      next unless control.sku.in?(%w[UWG4-4999 UWG4-4999-B UDG4-4999 UDG4-4999-WY])

      data3 << [
        { content: l.text('Floor Load', style: { font: FONT_BOLD, font_size: 9, fill_color: '444', padding: [0, 0, -3, 0] }), col_span: 1 },
        { content: l.text(@hep.floor_load.to_s + ' kW*', style: { font: FONT, font_size: 9, fill_color: '666', padding: [0, 0, -3, 0] }), col_span: 1 }
      ]
      data3 << [
        { content: l.text('* used during thermostat setup', style: { font: FONT_BOLD, font_size: 7, fill_color: '444', padding: [0, 0, -3, 0] }), col_span: 2 }
      ]
    end
  end

  unless @hep.electrical_consumption.nil?
    data4 = [
      [
        { content: l.text('System Electrical Consumption', style: { font: FONT, font_size: 12, padding: [0, 0, -3, 5], fill_color: '333' }), col_span: 1 }
      ],
      [
        { content: l.formatted_text(
          [
            { text: "#{ActionController::Base.helpers.number_to_currency(@hep.electrical_consumption[:rate])}/hour*\n", style: { font: FONT, font_size: 9, fill_color: '666' } },
            { text: @hep.electrical_consumption[:disclaimer],
              style: { font: FONT_BOLD, fill_color: '444', font_size: 7, line_height: 10 } }
          ], style: { padding: [0, 0, -3, 0] }
        ) }
      ]
    ]
  end

  # A lambda for applying table cell styling.
  block = lambda do |total_rows|
    lambda do |cell|
      cell.style.background_color = cell.row == 0 ? 'EEEEEE' : 'FFFFFF'
      cell.style.text_valign = :center
      cell.style.border = {
        color: 'AAAAAA',
        width: if cell.row == 0
                 [0, 0, 0.5, 0]
               else
                 cell.row == total_rows - 1 ? 0 : [0, 0, 0.5, 0]
               end
      }
    end
  end

  block_options = lambda do |total_rows|
    lambda do |cell|
      cell.style.background_color = cell.row == 0 ? 'EEEEEE' : 'FFFFFF'
      cell.style.text_valign = :center
      cell.style.border = {
        color: 'AAAAAA',
        width: if cell.row == 0
                 [0, 0, 0.5, 0]
               else
                 cell.row == total_rows - 1 ? 0 : [0, 0, 0.0, 0]
               end
      }
    end
  end

  if /Snow/i.match?(@hep.heating_system)
    alt_text = ''
    alt_text = <<~ALT.chomp
      If you are exploring other options, your account manager can assist with alternatives such as reducing the coverage area (e.g., tire track coverage for driveways) or selecting a different controller, coverage, or zoning configuration.

      Alternative option examples:
    ALT

    data5 = [
      [
        { content: l.text('Alternative Options', style: { font: FONT, font_size: 12, padding: [0, 0, -3, 5], fill_color: '333' }), col_span: 26 }
      ],
      [
        { content: l.formatted_text(
          [{ text: alt_text, style: { font: FONT, font_size: 8, fill_color: '333', line_height: 10, padding: [0, 0, -3, 0] } }]
        ), col_span: 26 }
      ],
      [
        { content: l.text('', style: { font: FONT, font_size: 9, fill_color: '333', line_height: 10, padding: [0, 0, -3, 0], text_align: :right }), col_span: 3 },
        { content: l.text('Tire track coverage for driveways can decrease the amperage by up to 70%', style: { font: FONT, font_size: 8, fill_color: '555', line_height: 10, padding: [0, 0, -3, -5] }), col_span: 23 }
      ],
      [
        { content: l.text('', style: { font: FONT, font_size: 9, fill_color: '333', line_height: 10, padding: [0, 0, -3, 0], text_align: :right }), col_span: 3 },
        {
          content: l.text('ZoneBraker control can be used as a compromise solution to reduce power load by operating up to 4 zones with customizable time durations, prioritizing critical areas in projects with limited amperage.',
                          style: { font: FONT, font_size: 8, fill_color: '555', line_height: 10, padding: [0, 0, 0, -5] }), col_span: 23
        }
      ]
    ]
  end

  if /Snow/i.match?(@hep.heating_system) && ( @hep.has_item?('SCP-120') || @hep.has_item?('SCE-120') )
    note_text = <<~ALT.chomp
      To comply with the energy conservation requirements of your state, this control unit includes a slab temperature and an ambient/precipitation sensor. Please consult a local inspector or authority having jurisdiction (AHJ) to explore all available options from WarmlyYours, some of which may be lower-cost alternatives that do not include a slab temperature sensor.

    ALT
    data6 = [
      [
        { content: l.text('Notes', style: { font: FONT, font_size: 12, padding: [0, 0, -3, 5], fill_color: '333' }), col_span: 26 }
      ],
      [
        { content: l.formatted_text(
          [{ text: note_text, style: { font: FONT, font_size: 8, fill_color: '333', line_height: 10, padding: [0, 0, -3, 0] } }]
        ), col_span: 26 }
      ]
    ]
  end

  if @hep.electrical_rough_in_kits.any?
    data_rough_in = [

      [
        { content: l.text('Electrical Rough-in Kit', style: { font: FONT, font_size: 12, padding: [0, 0, -3, 5], fill_color: '333' }), col_span: 1 }
      ],

      [
        { content: l.formatted_text([{ text: 'Your order includes an electrical rough-in kit.', style: { font: FONT_BOLD, font_size: 8.5, fill_color: '222', text_align: :center, line_height: 12 } },
                                     {
                                       text: "\nThe Electrical Rough-in Kit with 2 Conduits carries all the essentials an electrician needs while installing and connecting a thermostat with an electric radiant heating system. This kit includes two conduits for the most demanding local codes that require a separate conduit for low voltage wires.", style: {
                                         font: FONT, font_size: 8, fill_color: '333', text_align: :left, line_height: 9
                                       }
                                     }],
                                    style: { padding: [0, 0, -5, 0] }), col_span: 1 }
      ]
    ]

  elsif @suggested_skus&.include?('FHE-ROUGH-IN-KIT-03')
    detailed = html_to_plain_text(Item.find_by(sku: 'FHE-ROUGH-IN-KIT-03').detailed_description_html)

    data_rough_in = [
      [
        { content: l.text('Electrical Rough-in Kit', style: { font: FONT, font_size: 12, fill_color: '333', padding: [0, 0, -3, 5] }), col_span: 1 }
      ],
      [
        { content: l.text(
          "Want to save a trip to the store searching for installation parts? Call us at (800) 875-5285 to order our electrical rough-in kit.\n" + detailed,
          style: { font: FONT, font_size: 9, fill_color: '666', line_height: 12, padding: [0, 0, -3, 0] }
        ), col_span: 1 }
      ]
    ]
  else
    data_rough_in = nil
  end

  strings = @hep.instructions(true)
  x = 25
  y = 414

  canvas = composer.canvas

  strings.each_with_index do |text, index|
    canvas.font(FONT, size: 8)
    frame = HexaPDF::Layout::Frame.new(x, y, 281, 200)

    combined_data = [
      [
        { content: l.text("#{index + 1}.", style: { line_height: 11, font: FONT, fill_color: '555', font_size: 8 }), align: :left },
        { content: l.text(text, style: { line_height: 11, font: FONT, fill_color: '555', font_size: 8, padding: [0, 20, 0, 0] }), align: :left }
      ]
    ]
    combined_box = l.table(combined_data, column_widths: [10, 270], cell_style: { border: { width: 0 }, margin: 0, padding: 0 }, style: { border: { width: 0 } })

    result = frame.fit(combined_box)
    frame.draw(composer.canvas, result)

    y -= result.box.height
  end

  table_boxes = []

  if data2.present?
    table_boxes << l.table_box(
      data2.compact,
      width: 191,
      cell_style: block.call(data2.size),
      style: { border: { width: 0.5, color: 'AAAAAA' } }
    )
  end

  unless @hep.electrical_consumption.nil?
    table_boxes << l.table_box(
      data4.compact,
      width: 191,
      cell_style: block.call(data4.size),
      style: { border: { width: 0.5, color: 'AAAAAA' } }
    )
  end

  if /Snow/i.match?(@hep.heating_system)
    table_boxes << l.table_box(
      data5.compact,
      width: 191,
      cell_style: block_options.call(data5.size),
      style: { border: { width: 0.5, color: 'AAAAAA' } }
    )
  end

  if /Snow/i.match?(@hep.heating_system) && ( @hep.has_item?('SCP-120') || @hep.has_item?('SCE-120') )
    table_boxes << l.table_box(
      data6.compact,
      width: 191,
      cell_style: block_options.call(data6.size),
      style: { border: { width: 0.5, color: 'AAAAAA' } }
    )
  end

  if data_rough_in
    table_boxes << HexaPDF::Layout::TableBox.new(
      cells: data_rough_in,
      width: 191,
      cell_style: block.call(data_rough_in.size),
      style: { border: { width: 0.5, color: 'AAAAAA' }, padding: [0, 0, 10, 0] }
    )
  end

  x2 = 400
  y -= 10

  table_boxes.each do |tb|
    frame = HexaPDF::Layout::Frame.new(x2, y, 191, @suggested_skus&.include?('FHE-ROUGH-IN-KIT-03') ? 360 : 200)

    result = frame.fit(tb)
    frame.draw(composer.canvas, result)
    height = result.box.height

    y -= height + 10
  end

  composer.table(data1, width: 361, cell_style: block.call(data1.size),
                        style: { border: { width: 0.5, color: 'AAAAAA' } }, margin: [0, 0, 10, 0])
  unless data3.empty?
    composer.table(data3, width: 361, cell_style: block.call(data3.size),
                          style: { border: { width: 0.5, color: 'AAAAAA' } }, margin: [0, 0, 10, 0])
  end

  if @hep.requires_breaker_size_vs_circuit_length_table?
    composer.new_page

    block = lambda do |cell|
      cell.style.background_color =
        ((cell.row & 1).zero? ? 'EEEEEE' : 'FFFFFF')
      cell.style.border = {
        color: 'AAAAAA',
        width: 0.5
      }
    end

    composer.container(width: 562, style: { border: { width: 0.5, color: 'AAAAAA' }, padding: -0.5 }) do |container|
      header_row1 = []
      header_row1 << {
        content: l.text('Minimum Start-up Temperature', style: { font: FONT_BOLD, font_size: 10, fill_color: 'black' }),
        row_span: 2
      }
      header_row1 << {
        content: l.text('Breaker Size', style: { font: FONT_BOLD, font_size: 10, fill_color: 'black' })
      }
      if @hep.has_item?(ItemConstants::PIPE_TRACING_CABLE_5_WATT_PER_FT_SPOOL_SKUS)
        header_row1 << {
          content: l.text('5 Watts per Foot', style: { font: FONT_BOLD, font_size: 10, fill_color: 'black' }),
          col_span: 4
        }
      end
      if @hep.has_item?(ItemConstants::PIPE_TRACING_CABLE_8_WATT_PER_FT_SPOOL_SKUS)
        header_row1 << {
          content: l.text('8 Watts per Foot', style: { font: FONT_BOLD, font_size: 10, fill_color: 'black' }),
          col_span: 4
        }
      end
      if @hep.has_item?(ItemConstants::PIPE_TRACING_CABLE_10_WATT_PER_FT_SPOOL_SKUS)
        header_row1 << {
          content: l.text('10 Watts per Foot', style: { font: FONT_BOLD, font_size: 10, fill_color: 'black' }),
          col_span: 4
        }
      end

      header_row2 = []
      header_row2 << {
        content: l.text('Amps', style: { font: FONT_BOLD, font_size: 10, fill_color: 'black' })
      }
      if @hep.has_item?(ItemConstants::PIPE_TRACING_CABLE_5_WATT_PER_FT_SPOOL_SKUS)
        header_row2.concat([
                             { content: l.text('120V', style: { font: FONT_BOLD, font_size: 10, fill_color: 'black' }) },
                             { content: l.text('208V', style: { font: FONT_BOLD, font_size: 10, fill_color: 'black' }) },
                             { content: l.text('240V', style: { font: FONT_BOLD, font_size: 10, fill_color: 'black' }) },
                             { content: l.text('277V', style: { font: FONT_BOLD, font_size: 10, fill_color: 'black' }) }
                           ])
      end
      if @hep.has_item?(ItemConstants::PIPE_TRACING_CABLE_8_WATT_PER_FT_SPOOL_SKUS)
        header_row2.concat([
                             { content: l.text('120V', style: { font: FONT_BOLD, font_size: 10, fill_color: 'black' }) },
                             { content: l.text('208V', style: { font: FONT_BOLD, font_size: 10, fill_color: 'black' }) },
                             { content: l.text('240V', style: { font: FONT_BOLD, font_size: 10, fill_color: 'black' }) },
                             { content: l.text('277V', style: { font: FONT_BOLD, font_size: 10, fill_color: 'black' }) }
                           ])
      end
      if @hep.has_item?(ItemConstants::PIPE_TRACING_CABLE_10_WATT_PER_FT_SPOOL_SKUS)
        header_row2.concat([
                             { content: l.text('120V', style: { font: FONT_BOLD, font_size: 10, fill_color: 'black' }) },
                             { content: l.text('208V', style: { font: FONT_BOLD, font_size: 10, fill_color: 'black' }) },
                             { content: l.text('240V', style: { font: FONT_BOLD, font_size: 10, fill_color: 'black' }) },
                             { content: l.text('277V', style: { font: FONT_BOLD, font_size: 10, fill_color: 'black' }) }
                           ])
      end

      data = []
      data << header_row1
      data << header_row2

      container.table(data, cell_style: block, padding: -0.5)

      lengths = [15]
      lengths += [140, 268, 285, 311] if @hep.has_item?(ItemConstants::PIPE_TRACING_CABLE_5_WATT_PER_FT_SPOOL_SKUS)
      lengths += [100, 184, 200, 222] if @hep.has_item?(ItemConstants::PIPE_TRACING_CABLE_8_WATT_PER_FT_SPOOL_SKUS)
      lengths += [80, 147, 160, 178] if @hep.has_item?(ItemConstants::PIPE_TRACING_CABLE_10_WATT_PER_FT_SPOOL_SKUS)

      data_0F = []

      lengths_1 = [15]
      lengths_1 += [140, 268, 285, 311] if @hep.has_item?(ItemConstants::PIPE_TRACING_CABLE_5_WATT_PER_FT_SPOOL_SKUS)
      lengths_1 += [100, 184, 200, 222] if @hep.has_item?(ItemConstants::PIPE_TRACING_CABLE_8_WATT_PER_FT_SPOOL_SKUS)
      lengths_1 += [80, 147, 160, 178]  if @hep.has_item?(ItemConstants::PIPE_TRACING_CABLE_10_WATT_PER_FT_SPOOL_SKUS)

      row_1 = []

      row_1 << { content: l.text("0°F\n(-18°C)", style: { font: FONT, font_size: 10, fill_color: 'black' }),
                 row_span: 4 }

      lengths_1.each do |val|
        row_1 << { content: l.text(val.to_s, style: { font: FONT, font_size: 10, fill_color: 'black', padding: [0, 3, 0, 3] }),
                   col_span: 1 }
      end
      data_0F << row_1

      # --- Row 2 ---
      lengths_2 = [20]
      lengths_2 += [190, 357, 380, 414] if @hep.has_item?(ItemConstants::PIPE_TRACING_CABLE_5_WATT_PER_FT_SPOOL_SKUS)
      lengths_2 += [130, 244, 265, 294] if @hep.has_item?(ItemConstants::PIPE_TRACING_CABLE_8_WATT_PER_FT_SPOOL_SKUS)
      lengths_2 += [110, 198, 215, 239] if @hep.has_item?(ItemConstants::PIPE_TRACING_CABLE_10_WATT_PER_FT_SPOOL_SKUS)

      row_2 = lengths_2.map do |val|
        { content: l.text(val.to_s, style: { font: FONT, font_size: 10, fill_color: 'black', padding: [0, 3, 0, 3] }),
          col_span: 1 }
      end
      data_0F << row_2

      lengths_3 = [30]
      lengths_3 += [270, 508, 540, 589] if @hep.has_item?(ItemConstants::PIPE_TRACING_CABLE_5_WATT_PER_FT_SPOOL_SKUS)
      lengths_3 += [200, 368, 400, 444] if @hep.has_item?(ItemConstants::PIPE_TRACING_CABLE_8_WATT_PER_FT_SPOOL_SKUS)
      lengths_3 += [160, 299, 325, 361] if @hep.has_item?(ItemConstants::PIPE_TRACING_CABLE_10_WATT_PER_FT_SPOOL_SKUS)

      row_3 = lengths_3.map do |val|
        { content: l.text(val.to_s, style: { font: FONT, font_size: 10, fill_color: 'black', padding: [0, 3, 0, 3] }),
          col_span: 1 }
      end
      data_0F << row_3

      lengths_4 = [40]
      lengths_4 += [270, 508, 540, 589] if @hep.has_item?(ItemConstants::PIPE_TRACING_CABLE_5_WATT_PER_FT_SPOOL_SKUS)
      lengths_4 += [210, 386, 420, 466] if @hep.has_item?(ItemConstants::PIPE_TRACING_CABLE_8_WATT_PER_FT_SPOOL_SKUS)
      lengths_4 += [180, 331, 360, 400] if @hep.has_item?(ItemConstants::PIPE_TRACING_CABLE_10_WATT_PER_FT_SPOOL_SKUS)

      row_4 = lengths_4.map do |val|
        { content: l.text(val.to_s, style: { font: FONT, font_size: 10, fill_color: 'black', padding: [0, 3, 0, 3] }),
          col_span: 1 }
      end
      data_0F << row_4

      container.table(data_0F, cell_style: block, padding: -0.5)

      data_minus20 = []

      lengths_1 = [15]
      lengths_1 += [125, 235, 250, 273] if @hep.has_item?(ItemConstants::PIPE_TRACING_CABLE_5_WATT_PER_FT_SPOOL_SKUS)
      lengths_1 += [85, 161, 175, 194]  if @hep.has_item?(ItemConstants::PIPE_TRACING_CABLE_8_WATT_PER_FT_SPOOL_SKUS)
      lengths_1 += [70, 133, 145, 161] if @hep.has_item?(ItemConstants::PIPE_TRACING_CABLE_10_WATT_PER_FT_SPOOL_SKUS)

      row_1 = []
      row_1 << {
        content: l.text("-20°F\n(-29°C)", style: { font: FONT, font_size: 10, fill_color: 'black' }),
        row_span: 4
      }
      lengths_1.each do |val|
        row_1 << {
          content: l.text(val.to_s, style: { font: FONT, font_size: 10, fill_color: 'black', padding: [0, 3, 0, 3] }),
          col_span: 1
        }
      end
      data_minus20 << row_1

      lengths_2 = [20]
      lengths_2 += [165, 310, 330, 360] if @hep.has_item?(ItemConstants::PIPE_TRACING_CABLE_5_WATT_PER_FT_SPOOL_SKUS)
      lengths_2 += [115, 216, 235, 261] if @hep.has_item?(ItemConstants::PIPE_TRACING_CABLE_8_WATT_PER_FT_SPOOL_SKUS)
      lengths_2 += [95, 175, 190, 211]  if @hep.has_item?(ItemConstants::PIPE_TRACING_CABLE_10_WATT_PER_FT_SPOOL_SKUS)

      row_2 = lengths_2.map do |val|
        {
          content: l.text(val.to_s, style: { font: FONT, font_size: 10, fill_color: 'black', padding: [0, 3, 0, 3] }),
          col_span: 1
        }
      end
      data_minus20 << row_2

      lengths_3 = [30]
      lengths_3 += [250, 470, 500, 545] if @hep.has_item?(ItemConstants::PIPE_TRACING_CABLE_5_WATT_PER_FT_SPOOL_SKUS)
      lengths_3 += [175, 322, 350, 389] if @hep.has_item?(ItemConstants::PIPE_TRACING_CABLE_8_WATT_PER_FT_SPOOL_SKUS)
      lengths_3 += [145, 262, 285, 316] if @hep.has_item?(ItemConstants::PIPE_TRACING_CABLE_10_WATT_PER_FT_SPOOL_SKUS)

      row_3 = lengths_3.map do |val|
        {
          content: l.text(val.to_s, style: { font: FONT, font_size: 10, fill_color: 'black', padding: [0, 3, 0, 3] }),
          col_span: 1
        }
      end
      data_minus20 << row_3

      lengths_4 = [40]
      lengths_4 += [270, 508, 540, 589] if @hep.has_item?(ItemConstants::PIPE_TRACING_CABLE_5_WATT_PER_FT_SPOOL_SKUS)
      lengths_4 += [210, 386, 420, 466] if @hep.has_item?(ItemConstants::PIPE_TRACING_CABLE_8_WATT_PER_FT_SPOOL_SKUS)
      lengths_4 += [180, 331, 360, 400] if @hep.has_item?(ItemConstants::PIPE_TRACING_CABLE_10_WATT_PER_FT_SPOOL_SKUS)

      row_4 = lengths_4.map do |val|
        {
          content: l.text(val.to_s, style: { font: FONT, font_size: 10, fill_color: 'black', padding: [0, 3, 0, 3] }),
          col_span: 1
        }
      end
      data_minus20 << row_4

      container.table(data_minus20, cell_style: block, padding: -0.5)

      data_minus40 = []

      lengths_1 = [15]
      lengths_1 += [110, 207, 220, 240] if @hep.has_item?(ItemConstants::PIPE_TRACING_CABLE_5_WATT_PER_FT_SPOOL_SKUS)
      lengths_1 += [80, 143, 155, 172]  if @hep.has_item?(ItemConstants::PIPE_TRACING_CABLE_8_WATT_PER_FT_SPOOL_SKUS)
      lengths_1 += [60, 115, 125, 139] if @hep.has_item?(ItemConstants::PIPE_TRACING_CABLE_10_WATT_PER_FT_SPOOL_SKUS)

      row_1 = []
      row_1 << {
        content: l.text("-40°F\n(-40°C)", style: { font: FONT, font_size: 10, fill_color: 'black' }),
        row_span: 4
      }
      lengths_1.each do |val|
        row_1 << {
          content: l.text(val.to_s, style: { font: FONT, font_size: 10, fill_color: 'black', padding: [0, 3, 0, 3] }),
          col_span: 1
        }
      end
      data_minus40 << row_1

      lengths_2 = [20]
      lengths_2 += [145, 277, 295, 322] if @hep.has_item?(ItemConstants::PIPE_TRACING_CABLE_5_WATT_PER_FT_SPOOL_SKUS)
      lengths_2 += [105, 193, 210, 233] if @hep.has_item?(ItemConstants::PIPE_TRACING_CABLE_8_WATT_PER_FT_SPOOL_SKUS)
      lengths_2 += [85, 156, 170, 189]  if @hep.has_item?(ItemConstants::PIPE_TRACING_CABLE_10_WATT_PER_FT_SPOOL_SKUS)

      row_2 = lengths_2.map do |val|
        { content: l.text(val.to_s, style: { font: FONT, font_size: 10, fill_color: 'black', padding: [0, 3, 0, 3] }),
          col_span: 1 }
      end
      data_minus40 << row_2

      lengths_3 = [30]
      lengths_3 += [220, 414, 440, 480] if @hep.has_item?(ItemConstants::PIPE_TRACING_CABLE_5_WATT_PER_FT_SPOOL_SKUS)
      lengths_3 += [155, 290, 315, 350] if @hep.has_item?(ItemConstants::PIPE_TRACING_CABLE_8_WATT_PER_FT_SPOOL_SKUS)
      lengths_3 += [125, 235, 255, 283] if @hep.has_item?(ItemConstants::PIPE_TRACING_CABLE_10_WATT_PER_FT_SPOOL_SKUS)

      row_3 = lengths_3.map do |val|
        { content: l.text(val.to_s, style: { font: FONT, font_size: 10, fill_color: 'black', padding: [0, 3, 0, 3] }),
          col_span: 1 }
      end
      data_minus40 << row_3

      lengths_4 = [40]
      lengths_4 += [270, 508, 540, 589] if @hep.has_item?(ItemConstants::PIPE_TRACING_CABLE_5_WATT_PER_FT_SPOOL_SKUS)
      lengths_4 += [210, 386, 420, 466] if @hep.has_item?(ItemConstants::PIPE_TRACING_CABLE_8_WATT_PER_FT_SPOOL_SKUS)
      lengths_4 += [180, 331, 360, 400] if @hep.has_item?(ItemConstants::PIPE_TRACING_CABLE_10_WATT_PER_FT_SPOOL_SKUS)

      row_4 = lengths_4.map do |val|
        { content: l.text(val.to_s, style: { font: FONT, font_size: 10, fill_color: 'black', padding: [0, 3, 0, 3] }),
          col_span: 1 }
      end
      data_minus40 << row_4

      container.table(data_minus40, cell_style: block, padding: -0.5)
    end
  end

  composer.document.pages.each do |page|
    canvas = page.canvas
    page_width  = page.box(:media).width
    page_height = page.box(:media).height

    logo_path = Rails.public_path.join('images', 'pdf', 'new-wylogo.png').to_s
    support_path = Rails.public_path.join('images', 'pdf', '247.png').to_s

    canvas.image(logo_path, at: [17.5, page_height - 65], width: 200)
    canvas.composer.formatted_text(
      [
        { text: "Electrical Plan & Information\n", style: { text_align: :left, font: FONT_BOLD, font_size: 13, line_height: 15 } },
        { text: 'Share this information with your Electrician', style: { text_align: :left, font: FONT_BOLD, font_size: 10, line_height: 15 } }
      ],
      align: :right,
      padding: [30, 20]
    )
    canvas.composer.formatted_text([
                                     { box: [:image, support_path], height: 12, valign: :text, padding: [0, 0, -3, 0] },
                                     { text: ' Technical Support', style: { font: FONT, font_size: 12 } },
                                     { text: '', style: { font_size: 12, fill_color: '973233' } },
                                     { text: '(800) 875-5285', style: { font: FONT, font_size: 12 } },
                                     { text: '', style: { font_size: 12, fill_color: '973233' } },
                                     { link: 'www.warmlyyours.com/support', style: { font: FONT, font_size: 12, fill_color: '973233' } }
                                   ], align: :center, valign: :bottom, style: { padding: [0, 0, 3, 0] })
  end

  buffer = StringIO.new
  composer.write(buffer, optimize: true)
  buffer.string
end

#initialize_composerObject



22
23
24
# File 'app/services/pdf/document/electrical_plan.rb', line 22

def initialize_composer
  build_composer(margin: [80, 25, 50, 25])
end