Class: Pdf::Label::RmaItem
- Inherits:
-
BaseService
- Object
- BaseService
- Pdf::Label::RmaItem
- Includes:
- Base
- Defined in:
- app/services/pdf/label/rma_item.rb
Overview
Service object: rma item.
Defined Under Namespace
Classes: Result
Constant Summary collapse
- PAGE_WIDTH =
Label dimensions: 2.3125 in × 4 in
(2.3125 * 72).round(2).freeze
- PAGE_HEIGHT =
Page height.
(4.0 * 72)
Constants included from Base
Base::FONT, Base::NIMBUS_SANS_PATH, Base::NIMBUS_SANS_PATH_BOLD, Base::WY_LOGO_PATH
Instance Method Summary collapse
-
#call(rma_items_array, _options = {}) ⇒ Object
rma_items_array is like "24160"=>"1" keys are "rma_item_id" or "rma_item_id|sub_item_id", values are quantities.
Instance Method Details
#call(rma_items_array, _options = {}) ⇒ Object
rma_items_array is like "24160"=>"1"
keys are "rma_item_id" or "rma_item_id|sub_item_id", values are quantities
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'app/services/pdf/label/rma_item.rb', line 18 def call(rma_items_array, = {}) pdf = PdfCombinator.new rma = nil rma_items_list = [] rma_items_array.each do |rma_item_param, quantity| rma_item_id, sub_item_id = rma_item_param.split('|') sub_item = sub_item_id ? Item.find_by(id: sub_item_id) : nil quantity = quantity.to_i next unless quantity > 0 rma_item = RmaItem.eager_load(:returned_item).find(rma_item_id) rma_items_list << rma_item rma ||= rma_item.rma applicable_item = sub_item || rma_item.returned_item serial_number = rma_item.serial_numbers.joins(:store_item) .where(store_items: { item_id: applicable_item.id }) .first&.number label_pdf = generate_label(rma_item, sub_item, serial_number) quantity.times { pdf << label_pdf } end md5 = Digest::MD5.hexdigest(rma_items_list.map(&:id).to_json) Result.new(pdf: pdf.to_pdf, rma: rma, rma_items: rma_items_list, file_name: "rma_items_labels_#{md5}.pdf") end |