Class: PerformanceReviewReportPdf
- Inherits:
-
Prawn::Document
- Object
- Prawn::Document
- PerformanceReviewReportPdf
- Includes:
- MoneyRails::ActionViewExtension
- Defined in:
- app/my_lib/performance_review_report_pdf.rb
Constant Summary collapse
- TABLE_COLUMN_WIDTHS =
[ 80, 80, 80, 80, 80, ]
Instance Attribute Summary collapse
-
#data ⇒ Object
Returns the value of attribute data.
-
#date ⇒ Object
Returns the value of attribute date.
-
#date_filter_type ⇒ Object
Returns the value of attribute date_filter_type.
-
#dates ⇒ Object
Returns the value of attribute dates.
-
#emails ⇒ Object
Returns the value of attribute emails.
-
#end_date ⇒ Object
Returns the value of attribute end_date.
-
#pdf_url ⇒ Object
Returns the value of attribute pdf_url.
-
#restaurant_id ⇒ Object
Returns the value of attribute restaurant_id.
-
#result ⇒ Object
Returns the value of attribute result.
-
#start_date ⇒ Object
Returns the value of attribute start_date.
-
#type ⇒ Object
Returns the value of attribute type.
Instance Method Summary collapse
- #download_link ⇒ Object
- #filepath ⇒ Object
- #generate_pdf(args = {}) ⇒ Object
- #generate_pdf_table ⇒ Object
-
#initialize(args = {}) ⇒ PerformanceReviewReportPdf
constructor
A new instance of PerformanceReviewReportPdf.
- #save_attachment ⇒ Object
- #store_to_attachment ⇒ Object
Constructor Details
#initialize(args = {}) ⇒ PerformanceReviewReportPdf
Returns a new instance of PerformanceReviewReportPdf.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'app/my_lib/performance_review_report_pdf.rb', line 20 def initialize(args = {}) if args.present? args.to_h.with_indifferent_access.each do |k, v| send("#{k}=".to_sym, v) end end @dates = if date_filter_type == 'single' @start_date = @end_date = date [date] else (start_date.to_date..end_date.to_date).to_a end super(top_margin: 10, page_size: 'A4', page_layout: :landscape) font_families.update('Mitr' => { normal: Rails.root.join('vendor/assets/fonts/mitr/Mitr-Regular.ttf'), bold: Rails.root.join('vendor/assets/fonts/mitr/Mitr-Bold.ttf'), }) font 'Mitr' @pdf_url = {} end |
Instance Attribute Details
#data ⇒ Object
Returns the value of attribute data.
16 17 18 |
# File 'app/my_lib/performance_review_report_pdf.rb', line 16 def data @data end |
#date ⇒ Object
Returns the value of attribute date.
16 17 18 |
# File 'app/my_lib/performance_review_report_pdf.rb', line 16 def date @date end |
#date_filter_type ⇒ Object
Returns the value of attribute date_filter_type.
16 17 18 |
# File 'app/my_lib/performance_review_report_pdf.rb', line 16 def date_filter_type @date_filter_type end |
#dates ⇒ Object
Returns the value of attribute dates.
16 17 18 |
# File 'app/my_lib/performance_review_report_pdf.rb', line 16 def dates @dates end |
#emails ⇒ Object
Returns the value of attribute emails.
16 17 18 |
# File 'app/my_lib/performance_review_report_pdf.rb', line 16 def emails @emails end |
#end_date ⇒ Object
Returns the value of attribute end_date.
16 17 18 |
# File 'app/my_lib/performance_review_report_pdf.rb', line 16 def end_date @end_date end |
#pdf_url ⇒ Object
Returns the value of attribute pdf_url.
16 17 18 |
# File 'app/my_lib/performance_review_report_pdf.rb', line 16 def pdf_url @pdf_url end |
#restaurant_id ⇒ Object
Returns the value of attribute restaurant_id.
16 17 18 |
# File 'app/my_lib/performance_review_report_pdf.rb', line 16 def restaurant_id @restaurant_id end |
#result ⇒ Object
Returns the value of attribute result.
16 17 18 |
# File 'app/my_lib/performance_review_report_pdf.rb', line 16 def result @result end |
#start_date ⇒ Object
Returns the value of attribute start_date.
16 17 18 |
# File 'app/my_lib/performance_review_report_pdf.rb', line 16 def start_date @start_date end |
#type ⇒ Object
Returns the value of attribute type.
16 17 18 |
# File 'app/my_lib/performance_review_report_pdf.rb', line 16 def type @type end |
Instance Method Details
#download_link ⇒ Object
105 106 107 108 109 110 111 112 113 |
# File 'app/my_lib/performance_review_report_pdf.rb', line 105 def download_link link = .pdf_url link = "#{Figaro.env.HH_HOST_URL!}#{link}" unless link.include? 'http' return link unless Figaro.bool_env! :ENABLE_CDN link.gsub(Figaro.env.CDN_URL, Figaro.env.HH_HOST_URL) link end |
#filepath ⇒ Object
101 102 103 |
# File 'app/my_lib/performance_review_report_pdf.rb', line 101 def filepath Rails.root.join('tmp', 'reports', file_name).to_s end |
#generate_pdf(args = {}) ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'app/my_lib/performance_review_report_pdf.rb', line 72 def generate_pdf(args = {}) [1, 2, 3, 4, 5, 6].each do |number| args[:file_number] = number args[:file_name] = name(number) file_pdf = self.class.new(args) file_pdf.generate_pdf_table file_pdf.render_file(file_pdf.filepath) path = Rails.root.join(file_pdf.filepath) loop do break if path.exist? sleep 1 end file_pdf. @pdf_url["file_#{number}".to_sym] = file_pdf.download_link end end |
#generate_pdf_table ⇒ Object
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 |
# File 'app/my_lib/performance_review_report_pdf.rb', line 44 def generate_pdf_table I18n.locale = :en @result = [] image_url = AdminSetting.report_pdf_image_url if image_url.present? = [[{ image: open(image_url), image_height: 110, image_width: 530, position: :center }]] end label = [] label += [['Restaurant Name', restaurant.name]] bounding_box([0, 510], width: 230) do table(label, cell_style: { border_width: 0 }) # transparent(0.5) { stroke_bounds } end if .present? bounding_box([370, 530], width: 250) do table(, cell_style: { border_width: 0 }) # transparent(0.5) { stroke_bounds } end end gen_content_file(file_number) table(result, column_widths: TABLE_COLUMN_WIDTHS, header: true) end |
#save_attachment ⇒ Object
91 92 93 |
# File 'app/my_lib/performance_review_report_pdf.rb', line 91 def self. = end |
#store_to_attachment ⇒ Object
95 96 97 98 99 |
# File 'app/my_lib/performance_review_report_pdf.rb', line 95 def = Attachment.new pdf: open(filepath) .save! end |