# frozen_string_literal: true puts "Seeding eminuxCRM..." Current.user = nil admin = User.find_or_initialize_by(email: "admin@simplecrm.local") admin.assign_attributes( first_name: "Admin", last_name: "eminuxCRM", role: "admin", password: "password123", password_confirmation: "password123", active: true ) admin.save! user1 = User.find_or_initialize_by(email: "marco@simplecrm.local") user1.assign_attributes( first_name: "Marco", last_name: "Bianchi", role: "user", password: "password123", password_confirmation: "password123", active: true ) user1.save! user2 = User.find_or_initialize_by(email: "lucia@simplecrm.local") user2.assign_attributes( first_name: "Lucia", last_name: "Verdi", role: "user", password: "password123", password_confirmation: "password123", active: true ) user2.save! Current.user = admin projects = [ ["MatchLiveTV", "matchlivetv", "Streaming e diritti sportivi", 0], ["RiskMeter", "riskmeter", "Risk management", 1], ["Cardoo", "cardoo", "Cardoo", 2] ].map do |name, code, description, position| project = Project.find_or_initialize_by(code: code) project.assign_attributes(name: name, description: description, position: position, active: true) project.save! project end matchlivetv, riskmeter, cardoo = projects # Utenti normali: Marco → MatchLiveTV + RiskMeter; Lucia → MatchLiveTV + Cardoo [user1, user2].each { |u| Project.find_each { |p| u.user_projects.find_or_create_by!(project: p) { |up| up.enabled = false } } } user1.enable_project!(matchlivetv) user1.enable_project!(riskmeter) user1.disable_project!(cardoo) user2.enable_project!(matchlivetv) user2.enable_project!(cardoo) user2.disable_project!(riskmeter) Current.project = matchlivetv %w[Light Full Partnership Evento Altro].each_with_index do |name, idx| Product.find_or_create_by!(code: name.parameterize) do |p| p.name = name p.position = idx p.active = true end end goal = SalesGoal.find_or_initialize_by(name: "Prime 10 società paganti", project: matchlivetv) goal.assign_attributes( metric: "customers_acquired", target_value: 10, start_date: Date.new(2026, 8, 16), end_date: Date.new(2026, 9, 30), active: true ) goal.save! SalesGoal.where(project_id: matchlivetv.id).where.not(id: goal.id).update_all(active: false) template = MailTemplate.find_or_initialize_by(project: matchlivetv, name: "Presentazione MatchLiveTV") template.assign_attributes( subject: "MatchLiveTV per {{societa}}", body_html: <<~HTML
Ciao {{contatto_nome}},
scriviamo a {{societa}} ({{regione}}) per presentarti MatchLiveTV.
Possiamo aiutarvi a trasmettere le giovanili in modo semplice, con un piano {{piano}}.
A presto,
Il team MatchLiveTV