class DoorList attr_reader :show extend ::ArtfullyOseHelper def initialize(show) @show = show end def tickets @tickets ||= Ticket.where(:show_id => show.id).includes(:buyer, :ticket_type, :items => :order).select(&:committed?) end def items @items ||= tickets.map { |t| Item.new t, t.buyer }.sort end private class Item attr_accessor :ticket, :buyer, :special_instructions, :notes, :payment_method, :order_id, :addresses, :phones comma do order_id "Order Number" buyer("Email") { |buyer| buyer.email } buyer("Salutation") { |buyer| buyer.salutation } buyer("First Name") { |buyer| buyer.first_name } buyer("Middle Name") { |buyer| buyer.middle_name } buyer("Last Name") { |buyer| buyer.last_name } buyer("Suffix") { |buyer| buyer.suffix } buyer("Title") { |buyer| buyer.title } buyer("Type") { |buyer| buyer.type } buyer("Sub Type") { |buyer| buyer.subtype } buyer("Company Name") { |buyer| buyer.company_name } ('A'..'C').each_with_index do |letter, i| addresses("Address#{letter} Type") { |addresses| addresses[i] && addresses[i].kind } addresses("Address#{letter} Address 1") { |addresses| addresses[i] && addresses[i].address1 } addresses("Address#{letter} Address 2") { |addresses| addresses[i] && addresses[i].address2 } addresses("Address#{letter} City") { |addresses| addresses[i] && addresses[i].city } addresses("Address#{letter} State") { |addresses| addresses[i] && addresses[i].state } addresses("Address#{letter} Zip") { |addresses| addresses[i] && addresses[i].zip } addresses("Address#{letter} Country") { |addresses| addresses[i] && addresses[i].country } end (1..3).each do |i| phones("Phone#{i} type") { |phones| phones[i-1] && phones[i-1].kind } phones("Phone#{i} number") { |phones| phones[i-1] && phones[i-1].number } end buyer("Website") { |buyer| buyer.website } buyer("Twitter Handle") { |buyer| buyer.twitter_handle } buyer("Facebook URL") { |buyer| buyer.facebook_url } buyer("LinkedIn URL") { |buyer| buyer.linked_in_url } buyer("Tags") { |buyer| buyer.tags.join("|") } buyer("Do Not Email") { |buyer| buyer.do_not_email } buyer("Do Not Call") { |buyer| buyer.do_not_call } buyer("Birth Month") { |buyer| buyer.birth_month } buyer("Birth Day") { |buyer| buyer.birth_day } buyer("Birth Year") { |buyer| buyer.birth_year } ticket("Ticket Type") { |ticket| ticket.ticket_type.name } ticket("Price") { |ticket| DoorList.number_as_cents ticket.sold_price } ticket("Special Instructions") { |ticket| ticket.special_instructions } ticket("Notes") { |ticket| ticket.notes } ticket("Went") { |ticket| ticket.validated } end def initialize(ticket, buyer) sold_item = ticket.sold_item self.ticket = ticket self.buyer = buyer self.special_instructions = ticket.special_instructions self.notes = ticket.notes self.payment_method = sold_item.try(:order).try(:payment_method) self.order_id = sold_item.try(:order).try(:id) self.addresses = buyer.addresses self.phones = buyer.phones end def <=>(obj) (self.ticket.buyer.last_name.try(:downcase) || "") <=> (obj.ticket.buyer.last_name.try(:downcase) || "") end end end