Class: AgentChangeInfo

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/agent_change_info.rb

Constant Summary collapse

PENDING =
"pending"
APPROVED =
"approved"
CHANGE_COMPANY_NAME =
"change_company_name"
CHANGE_PROFILE =
"change_profile"
REJECT =
"reject"

Instance Method Summary collapse

Instance Method Details

#describe_idObject



15
16
17
# File 'app/models/agent_change_info.rb', line 15

def describe_id
"AgentChangeInfo ##{id}"
end

#update_edit_stateObject



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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'app/models/agent_change_info.rb', line 19

def update_edit_state
	if status_changed?
		agent = self.user.agent
		action = self.action
		status = self.status
		p action
		p status
		if action == CHANGE_PROFILE
			if status == REJECT
				begin
					agent.update!(first_name: self.first_name_old, last_name: last_name_old,edit_profile_state: REJECT)
					UserMailer.delay.send_email_notification(agent, CHANGE_PROFILE, REJECT)
					agent.push_notification_apply_change(REJECT,self);
				rescue Exception => e
				p e 					
				end
			elsif status == APPROVED
				begin
					agent.update!(edit_profile_state: APPROVED,:first_name => self.first_name_new,:last_name => self.last_name_new)
					UserMailer.delay.send_email_notification(agent, CHANGE_PROFILE, APPROVED)
					agent.push_notification_apply_change(APPROVED,self)
 			rescue Exception => e
 				p e
 			end
 		else
 			return
			end
		elsif action == CHANGE_COMPANY_NAME
			if status == REJECT
				begin
					agent.update!(company_name: self.company_name_old,edit_company_name_state: REJECT)
					UserMailer.delay.send_email_notification(agent, CHANGE_COMPANY_NAME, REJECT)
					agent.push_notification_apply_change_company(REJECT,self)
				rescue Exception => e
					p e
				end
			elsif status == APPROVED
				begin
					agent.update!(company_name: self.company_name_new,edit_company_name_state: APPROVED)
					UserMailer.delay.send_email_notification(agent, CHANGE_COMPANY_NAME, APPROVED)
					agent.push_notification_apply_change_company(APPROVED,self)
				rescue Exception => e
					p e
				end
			end
		end
	end
end