#Este reporte permite sacar los stands con sus respectivas cuentas (Incluye contraseña).
#En el repote tambien se sacan todos los contactos que se hayan configurado para ese stand.
event = Event.find(2154)
contact_params = EventParam.get_by_event(event.id).where(param_name: 5)
contact_config = Hash[contact_params.map{|c| [c.id, c.param_value]}]
stands = event.stands.where(status: [2,3], archived: false)
CSV.open("/home/ubuntu/usuga_stand_account_report.csv", "wb") do |csv|
csv << ["identificador", "compañia", "username", "pass"] + contact_config.values
stands.each do |stand|
reservation = stand.current_reservation
next if reservation.blank? or reservation.event_account.blank?
contacts = {}
reservation.stand_reservation_contacts.each do |rcontact|
contact = rcontact.contact
next if contact.blank? or contact.contact_emails.blank?
contacts[rcontact.param_contact_id] = contact.contact_emails.first.email
end
account = reservation.event_account
company = reservation.company.blank? ? "" : reservation.company.name
plain_password = (account.decryptable_password.blank? ? nil : MiniEnigma.decrypt(account.decryptable_password))
contacts_info = contact_config.map{|k,v| contacts[k]}
csv << [stand.identifier, reservation.company.name, account.username, plain_password] + contacts_info
end
end