module IdCard class PrintController < ApplicationController # View Methods def index @employer_setups = IdCard::Setup.active.to_a @queue_counts = IdCardQueueService::GetQueuedCounts.new().call add_queued_count_to_card_setup @queued = @employer_setups.select { |setup| setup.queued_card_count > 0 }.sort_by { |setup| setup.pl_plan_key.to_i } @not_queued = @employer_setups.select { |setup| setup.queued_card_count == 0 }.sort_by { |setup| setup.pl_plan_key.to_i } render :index end # API Methods def print_all_queued @queue_members = IdCardQueueService::GetQueuedCards.new().call cards_pdf = IdCardPrinterService::QueuedCardsGenerator.new(@queue_members).call if cards_pdf.is_a?(CombinePDF::PDF) send_data cards_pdf.to_pdf, filename: "queued_cards_#{Date.today}.pdf", type: "application/pdf", disposition: 'attachment' else cards_pdf.rewind send_data cards_pdf.read, filename: "queued_cards_#{Date.today}.zip", type: 'application/zip', disposition: 'attachment' end end def print_queued_by_employer pl_plan_key = params[:id].to_s @employer = Employer.find_by(pl_plan_key: pl_plan_key) @queue_members = IdCardQueueService::GetQueuedCards.new(pl_plan_key).call cards_pdf = IdCardPrinterService::QueuedCardsGenerator.new(@queue_members).call send_data cards_pdf.to_pdf, filename: "#{@employer.name.parameterize(separator: "_")}_queued_cards_#{Date.today}.pdf", type: "application/pdf", disposition: 'attachment' end def generate_sample if Integer(params[:id], exception: false).is_a?(Integer) pl_plan_key = params[:id].to_s @employer = Employer.find_by(pl_plan_key: pl_plan_key) else slug = params[:id] @employer = Employer.find_by(slug: slug) end sample_cards_pdf = IdCardPrinterService::SampleCardsGenerator.new(@employer).call send_data sample_cards_pdf.to_pdf, filename: "#{@employer.name.parameterize(separator: "_")}_sample_cards_#{Date.today}.pdf", type: "application/pdf", disposition: 'attachment' end def generate_print if Integer(params[:id], exception: false).is_a?(Integer) pl_plan_key = params[:id].to_s @employer = Employer.find_by(pl_plan_key: pl_plan_key) else slug = params[:id] @employer = Employer.find_by(slug: slug) end cards_pdf = IdCardPrinterService::CardsGenerator.new(@employer.employer_member_keys, "PrintCard").call send_data cards_pdf.to_pdf, filename: "#{@employer.name.parameterize(separator: "_")}_print_cards_#{Date.today}.pdf", type: "application/pdf", disposition: 'attachment' end def generate_mobile_display if Integer(params[:id], exception: false).is_a?(Integer) pl_plan_key = params[:id].to_s @employer = Employer.find_by(pl_plan_key: pl_plan_key) else slug = params[:id] @employer = Employer.find_by(slug: slug) end cards_pdf = IdCardPrinterService::EmployerCardsGenerator.new(@employer, "MobileDisplayCard").call send_data cards_pdf.to_pdf, filename: "#{@employer.name.parameterize(separator: "_")}_mobile_display_cards_#{Date.today}.pdf", type: "application/pdf", disposition: 'attachment' end def generate_full_page if Integer(params[:id], exception: false).is_a?(Integer) pl_plan_key = params[:id].to_s @employer = Employer.find_by(pl_plan_key: pl_plan_key) else slug = params[:id] @employer = Employer.find_by(slug: slug) end cards_pdf = IdCardPrinterService::EmployerCardsGenerator.new(@employer, "FullPageCard", true).call cards_pdf.rewind send_data cards_pdf.sysread, filename: "#{@employer.name.parameterize(separator: "_")}_full_page_cards_#{Date.today}.zip", type: 'application/zip', disposition: 'attachment' end private def add_queued_count_to_card_setup @queue_counts.each do |qc| match = @employer_setups.find { |setup| setup.pl_plan_key == qc["PLPlanKey"] } if match.present? match.queued_card_count = qc["QueuedCardsCount"] end end end end end