Class: UserNotificationSetting

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

Class Method Summary collapse

Class Method Details

.assigment(asset, organization, employee, sender_email, user, assignment) ⇒ Object



99
100
101
102
103
104
# File 'app/models/user_notification_setting.rb', line 99

def self.assigment(asset, organization, employee, sender_email, user , assignment)
  seen = true
  type = "asset assignment"
  UserMailer.asset_assgiment(asset,organization, employee, sender_email, user , assignment , user).deliver
  HistoryEmail.history_email(user.id ,type,seen,organization.id , assignment.id)
end

.collect_repair_alert(collection, organization, current_user) ⇒ Object

Checking the Main Notification for cost alert



152
153
154
155
156
157
158
159
160
161
162
163
164
165
# File 'app/models/user_notification_setting.rb', line 152

def self.collect_repair_alert(collection , organization , current_user)
  purchasecost = collection.asset.purchased_cost
  member = Member.where("organization_id = ? " , organization.id).first
  if member.has_role? 'owner'
    @onwer_user = User.where("id = ?",member.user_id).first
    repair_cost = self.repair_cost(@onwer_user)
    @estimate_cost = (purchasecost/100)*repair_cost.to_f
    if @estimate_cost.to_f < collection.vending_cost.to_f || collection.estimate_by_user.to_f >= collection.vending_cost.to_f
      if @onwer_user
        UserMailer.repair_cost_alert(collection ,  organization , current_user , @onwer_user , @estimate_cost).deliver
      end
    end
  end
end

.colletion_tickect(asset, organization, sender_email, user, collection) ⇒ Object

Ticket collect



123
124
125
126
127
128
# File 'app/models/user_notification_setting.rb', line 123

def self.colletion_tickect(asset , organization , sender_email, user , collection)
  seen = true
  type = "collect ticket"
  UserMailer.collect_ticket(asset ,  organization , sender_email, user , collection , user).deliver
  HistoryEmail.history_email(user.id ,type, seen,organization.id, collection.collected_by_id)
end

.create_asset_email(asset, organization, sender_email, user) ⇒ Object

Email for Assets



88
89
90
# File 'app/models/user_notification_setting.rb', line 88

def self.create_asset_email(asset, organization , sender_email, user)
  UserMailer.create_asset(asset, organization ,sender_email , user , user).deliver
end

.create_ticket(asset, organization, sender_email, user, ticket) ⇒ Object

For ticket



115
116
117
118
119
120
# File 'app/models/user_notification_setting.rb', line 115

def self.create_ticket(asset , organization , sender_email, user , ticket )
  seen = true
  type = "create ticket"
  UserMailer.create_ticket(asset , organization , sender_email, user , ticket ,user).deliver
  HistoryEmail.history_email(user.id ,type,seen,organization.id , ticket.id)
end

.create_vendor(vendor, sender_email, organization, user) ⇒ Object

End of Asset For Vendor Creation



107
108
109
110
111
112
# File 'app/models/user_notification_setting.rb', line 107

def self.create_vendor(vendor, sender_email, organization, user )
  seen = true
  type = "vendor create"
  UserMailer.ct_vendor(vendor,sender_email, organization, user , user ).deliver
  HistoryEmail.history_email(user.id ,type,seen,organization.id,vendor.id)
end

.email_setting(user) ⇒ Object

Email function for setting timer



7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'app/models/user_notification_setting.rb', line 7

def self.email_setting(user)
  get_data = notify_setting(user)
  if get_data.blank?
    email_delay = "immediately"
    #      notification_update(user)
  else
    if get_data.email_date =="immediately"
      email_delay = get_data.email_date
      #        notification_update(user)
    else
      email_delay = get_data.email_date
    end
  end
end

.repair_cost(user) ⇒ Object

Repair cost for x setting



33
34
35
36
37
38
39
40
# File 'app/models/user_notification_setting.rb', line 33

def self.repair_cost(user)
  get_data = notify_setting(user)
  if get_data.blank?
    repaire_cost = 5
  else
    repaire_cost = get_data.cost
  end
end

.repair_count(user) ⇒ Object

repair count for same asset



43
44
45
46
47
48
49
50
# File 'app/models/user_notification_setting.rb', line 43

def self.repair_count(user)
  get_data = notify_setting(user)
  if get_data.blank?
    repaire_count = 5
  else
    repaire_count = get_data.repair_count
  end
end

.repair_count_email(asset, vendor, organization, user, ticket) ⇒ Object

Count Checking of repair asset



139
140
141
142
143
144
145
146
147
148
149
# File 'app/models/user_notification_setting.rb', line 139

def self.repair_count_email(asset , vendor, organization, user , ticket)
  total_repair = AssetRepairRequest.get_total_repair(asset.id)
  member = Member.where("organization_id = ? " , organization.id).first
  if member.has_role? 'owner'
    onwer_user = User.where("id = ?",member.user_id).first
    repair_count = UserNotificationSetting.repair_count(onwer_user.id)
    if total_repair >= repair_count.to_i 
      UserMailer.repair_count_exceding(asset , vendor,  organization , user , onwer_user, total_repair,repair_count , ticket).deliver
    end
  end
end

.send_repair(asset, organization, sender_email, user, request) ⇒ Object

end



131
132
133
134
135
136
# File 'app/models/user_notification_setting.rb', line 131

def self.send_repair(asset , organization ,  sender_email, user , request)
  seen = true
  type="repair request"
  UserMailer.repair_request(asset ,  organization ,  sender_email, user , request , user).deliver
  HistoryEmail.history_email(user.id ,type , seen,organization.id , request.id)
end

.service_date(setting) ⇒ Object

Convert Time



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'app/models/user_notification_setting.rb', line 70

def self.service_date(setting)
  if setting.contract_date.blank?
    time = 1.day
  elsif  setting.contract_date =="day"
    time = 1.day
  elsif  setting.contract_date =="week"
    time = 1.week
  elsif  setting.contract_date =="month"
    time = 1.month
  elsif  setting.contract_date =="2_month"
    time = 2.months
  elsif  setting.contract_date =="3_month"
    time = 3.months
  end
  return time 
end

.setting_date(user) ⇒ Object

Setting Date Time



23
24
25
26
27
28
29
30
# File 'app/models/user_notification_setting.rb', line 23

def self.setting_date(user)
  get_data = notify_setting(user)
  if get_data.updated_at.blank?
    st_date =  DateTime.now.to_date
  else
    st_date = get_data.updated_at.to_date
  end
end

.update_asset_email(asset, organization, sender_email, user) ⇒ Object



92
93
94
95
96
97
# File 'app/models/user_notification_setting.rb', line 92

def self.update_asset_email(asset,organization, sender_email, user)
  seen = true
  type = "asset update"
  UserMailer.update_asset(asset,organization ,sender_email,user,user).deliver
  HistoryEmail.history_email(user.id ,type , seen , organization.id , asset.id)
end

.user_notification(user_id) ⇒ Object

User Setting for specific user



64
65
66
# File 'app/models/user_notification_setting.rb', line 64

def self.user_notification(user_id)
  self.find_by_user_id(user_id)
end

.waranty_date(user) ⇒ Object

Waranty Email Notification



53
54
55
56
57
58
59
60
# File 'app/models/user_notification_setting.rb', line 53

def self.waranty_date(user)
  get_data = notify_setting(user)
  if get_data.blank?
    warant_date = "warnty_day"
  else
    warant_date = get_data.waranty_date
  end
end