Major features finished

This commit is contained in:
Jason Jordan
2026-04-15 08:12:47 -04:00
parent 9f306d3150
commit 247a075c9c
112 changed files with 3700 additions and 379 deletions
@@ -15,13 +15,30 @@ module IdCardPrinterService
IdCard::PrintData.where(pl_plan_key: pl_plan_keys, primary_mb_member_key: nil).destroy_all
pdf_array = []
batches = break_into_batches(pl_plan_keys)
batches.each do |card_template, batch_pl_plan_keys|
jasper_batch_id = "#{batch_pl_plan_keys.join('_')}-#{Time.current.utc.to_i}"
batch = IdCard::PrintData.where(pl_plan_key: batch_pl_plan_keys)
batch.update!(jasper_batch_id: jasper_batch_id)
batch_pdf = IdCardPrinterService::PdfBatchProcessor.new(card_template, jasper_batch_id, @layout).call
pdf_array << batch_pdf
template_groups = break_up_by_template(pl_plan_keys)
template_groups.each do |card_template, template_pl_plan_keys|
batch = IdCard::PrintData.where(pl_plan_key: template_pl_plan_keys)
# all_template_cards.in_batches(of: 75).each_with_index do |batch, index|
jasper_batch_id = "#{template_pl_plan_keys.join('_')}-#{Time.current.utc.to_i}"
# binding.pry
batch.update!(jasper_batch_id: jasper_batch_id)
if @layout == "PrintCard"
add_dependent_cards(batch)
end
batch_pdf = IdCardPrinterService::PdfBatchProcessor.new(card_template, jasper_batch_id, @layout).call
pdf_array << batch_pdf
# end
# jasper_batches = break_into_jasper_batches(group_pl_plan_keys)
# jasper_batches.each_with_index do |batch, index|
# jasper_batch_id = "#{group_pl_plan_keys.join('_')}-#{index + 1}-#{Time.current.utc.to_i}"
# binding.pry
# batch.update!(jasper_batch_id: jasper_batch_id)
# if @layout == "PrintCard"
# add_dependent_cards(batch)
# end
# batch_pdf = IdCardPrinterService::PdfBatchProcessor.new(card_template, jasper_batch_id, @layout).call
# pdf_array << batch_pdf
# end
end
# @employers_member_keys.each do |emk|
# employer_jasper_batches = IdCard::PrintData.where(pl_plan_key: emk[:pl_plan_key]).pluck(:network_logo_id).uniq
@@ -44,18 +61,47 @@ module IdCardPrinterService
private
def break_into_batches(pl_plan_keys)
def break_up_by_template(pl_plan_keys)
batches_by_card_template = IdCard::Setup.where(pl_plan_key: pl_plan_keys).group_by(&:card_template)
.transform_values { |setups| setups.map(&:pl_plan_key) }
.compact_blank
end
def break_into_jasper_batches(pl_plan_keys)
all_cards = IdCard::PrintData.where(pl_plan_key: pl_plan_keys)
binding.pry
jasper_batches = all_cards.each_slice(75).to_a
jasper_batches
end
def add_dependent_cards(batch)
batch.where.not(dependent_1: [nil, ""]).find_each do |member_card|
dependent_card = member_card.dup
dependent_card.update(
full_name_last_name_first: member_card.full_name_last_name_first.concat(" dependent")
)
dependent_card.save
end
end
def combine_pdfs(pdf_array)
if @zip
group_cards_pdf = Zip::OutputStream.write_buffer do |zio|
pdf_array.each do |file|
zio.put_next_entry(file[:name])
zio.write(file[:data])
pdf_file = pdf_array.first
puts "-- CombinePdfPages --"
puts pdf_file.pages.count
pdf_file.pages.reverse.each do |page|
page_pdf = CombinePDF.new
page_pdf << page
page_data = page_pdf.to_pdf
full_name_last_name_first = get_watermark_field(page_data)
if full_name_last_name_first.present?
page_filename = "#{full_name_last_name_first.gsub(", ", "_")}_digital_card_#{Date.today}.pdf"
puts "-- Filename --"
puts page_filename
zio.put_next_entry(page_filename)
zio.write(page_data)
end
end
end
else
@@ -64,5 +110,19 @@ module IdCardPrinterService
end
group_cards_pdf
end
def get_watermark_field(page_data)
watermark_field = ""
reader = PDF::Reader.new(StringIO.new(page_data))
puts "-- ReaderPages --"
puts reader.pages.count
page = reader.pages.first
if watermark_match = page.text.match(/:WATERMARK:([^:]*):/)
watermark_field = page.text.match(/:WATERMARK:([^:]*):/)[1].strip
else
puts "blank page"
end
watermark_field
end
end
end