From d341062fc6b7758ed041994075aee99dab75cf40 Mon Sep 17 00:00:00 2001 From: Norris Mei Date: Sat, 17 Aug 2024 22:51:19 -0700 Subject: [PATCH] Show units column if using custom units --- app/pdfs/picklists_pdf.rb | 41 ++++++++++++++++++++++++++++++--------- 1 file changed, 32 insertions(+), 9 deletions(-) diff --git a/app/pdfs/picklists_pdf.rb b/app/pdfs/picklists_pdf.rb index b2ae5d7a4a..38e42826f9 100644 --- a/app/pdfs/picklists_pdf.rb +++ b/app/pdfs/picklists_pdf.rb @@ -82,14 +82,15 @@ def compute_and_render move_down 20 - data = request_data + items = build_items + data = custom_units ? data_with_units(items) : data_no_units(items) font_size 11 # Line item table table(data) do self.header = true - self.cell_style = { padding: [5, 20, 5, 20]} + self.cell_style = { padding: [5, 10, 5, 10]} self.row_colors = %w(dddddd ffffff) cells.borders = [] @@ -128,20 +129,42 @@ def compute_and_render render end - def request_data + def build_items + request = @requests.first + request_items = request.request_items.map do |request_item| + RequestItem.from_json(request_item, request) + end + end + + def custom_units + Flipper.enabled?(:enable_packs) && @request.item_requests.any? { |item| item.request_unit } + end + + def data_with_units(items) data = [["Items Requested", "Quantity", + "Unit (if applicable)", "[X]", "Differences / Comments"]] - request = @requests.first - request_items = request.request_items.map do |request_item| - RequestItem.from_json(request_item, request) + data + items.map do |i| + [i.item.name, + i.quantity, + i.unit&.capitalize&.pluralize(i.quantity), + "[ ]", + ""] end + end + + def data_no_units(items) + data = [["Items Requested", + "Quantity", + "[X]", + "Differences / Comments"]] - data + request_items.map do |request_item| - [request_item.item.name, - request_item.quantity, + data + items.map do |i| + [i.item.name, + i.quantity, "[ ]", ""] end