Class: AssetRepairRequest
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- AssetRepairRequest
- Includes:
- PgSearch
- Defined in:
- app/models/asset_repair_request.rb
Class Method Summary collapse
-
.all_repair_request(organization_id, start_date, end_date) ⇒ Object
All.
- .complete_repair(organization_id, start_date, end_date) ⇒ Object
- .create_repair_request(params, status, current_user) ⇒ Object
- .create_ticket_user(params, current_user) ⇒ Object
- .delete_repair(organization_id, start_date, end_date) ⇒ Object
- .dispatch_repair(organization_id, start_date, end_date) ⇒ Object
-
.get_collect(collect_id) ⇒ Object
Get Collected Ticket.
-
.get_ticket(ticket_id) ⇒ Object
Get Ticket for Email.
-
.get_total_repair(asset_id) ⇒ Object
Get Total repair for an asset.
- .open_repair(organization_id, start_date, end_date) ⇒ Object
-
.preventative_detail(organization_id, start_date, end_date) ⇒ Object
for preventative details.
-
.rebuild_pg_search_documents ⇒ Object
Naive approach.
- .repair_cost_origional(asset) ⇒ Object
Instance Method Summary collapse
-
#arr_notifications ⇒ Object
All notifications of type “ARR” -> “Asset Repair Request”.
- #asset_name ⇒ Object
-
#respond(is_accepted, comments, responded_by) ⇒ Object
End.
-
#user_name ⇒ Object
User name for multiple search.
- #vendor_name ⇒ Object
Class Method Details
.all_repair_request(organization_id, start_date, end_date) ⇒ Object
All
78 79 80 81 82 83 84 85 86 |
# File 'app/models/asset_repair_request.rb', line 78 def self.all_repair_request(organization_id , start_date, end_date) asset = Asset.where("organization_id =? and created_at >= ? and created_at <= ? ", organization_id, start_date , end_date) total = 0 asset.each do |ass| total_count = self.where("asset_id =?", ass.id).count total = total+ total_count end return total end |
.complete_repair(organization_id, start_date, end_date) ⇒ Object
99 100 101 102 103 104 105 106 107 |
# File 'app/models/asset_repair_request.rb', line 99 def self.complete_repair(organization_id , start_date, end_date) asset = Asset.where("organization_id =? and created_at >= ? and created_at <= ? ", organization_id, start_date , end_date) total = 0 asset.each do |aset_detail| total_count = self.where("asset_id =? and status =?", aset_detail.id , 2).count total = total+ total_count end return total end |
.create_repair_request(params, status, current_user) ⇒ Object
144 145 146 147 148 149 150 151 152 153 154 155 |
# File 'app/models/asset_repair_request.rb', line 144 def self.create_repair_request(params , status ,current_user) self.create(:comments => params[:comments], :asset_id => params[:asset][:id], :requested_by_id => current_user.id, :vendor_id => params[:vendor][:id], :status => status, :estimate_by_user => params[:request][:estimate_by_user], :requested_date => Date.today(), :responded_date => Date.today(), :responder_comments => 'Approved', :responded_by_id => current_user.id) end |
.create_ticket_user(params, current_user) ⇒ Object
157 158 159 160 161 162 163 164 165 |
# File 'app/models/asset_repair_request.rb', line 157 def self.create_ticket_user(params,current_user) self.create(:comments => params[:comments], :asset_id => params[:asset][:id], :requested_by_id => current_user.id, :vendor_id => params[:vendor][:id], :status => '0', :estimate_by_user => params[:request][:estimate_by_user], :requested_date => Date.today()) end |
.delete_repair(organization_id, start_date, end_date) ⇒ Object
109 110 111 112 113 114 115 116 117 |
# File 'app/models/asset_repair_request.rb', line 109 def self.delete_repair(organization_id , start_date, end_date) asset = Asset.where("organization_id =? and created_at >= ? and created_at <= ? ", organization_id, start_date , end_date) total = 0 asset.each do |aset_detail| total_count = self.where("asset_id =? and status =?", aset_detail.id , 4).count total = total+ total_count end return total end |
.dispatch_repair(organization_id, start_date, end_date) ⇒ Object
119 120 121 122 123 124 125 126 127 |
# File 'app/models/asset_repair_request.rb', line 119 def self.dispatch_repair(organization_id , start_date, end_date) asset = Asset.where("organization_id =? and created_at >= ? and created_at <= ? ", organization_id, start_date , end_date) dispatch_total = 0 asset.each do |ass| total_dis = self.where("asset_id =? and status =? ", ass.id , 3).count dispatch_total= dispatch_total + total_dis end return dispatch_total end |
.get_collect(collect_id) ⇒ Object
Get Collected Ticket
135 136 137 |
# File 'app/models/asset_repair_request.rb', line 135 def self.get_collect(collect_id) self.find_by_collected_by_id(collect_id) end |
.get_ticket(ticket_id) ⇒ Object
Get Ticket for Email
130 131 132 |
# File 'app/models/asset_repair_request.rb', line 130 def self.get_ticket(ticket_id ) self.find_by_id(ticket_id) end |
.get_total_repair(asset_id) ⇒ Object
Get Total repair for an asset
140 141 142 |
# File 'app/models/asset_repair_request.rb', line 140 def self.get_total_repair(asset_id) self.where("asset_id = ?",asset_id).count end |
.open_repair(organization_id, start_date, end_date) ⇒ Object
89 90 91 92 93 94 95 96 97 |
# File 'app/models/asset_repair_request.rb', line 89 def self.open_repair(organization_id , start_date, end_date) asset = Asset.where("organization_id =? and created_at >= ? and created_at <= ? ", organization_id, start_date , end_date) total = 0 asset.each do |aset_detail| total_count = self.where("asset_id =? and status =?", aset_detail.id , 0).count total = total+ total_count end return total end |
.preventative_detail(organization_id, start_date, end_date) ⇒ Object
for preventative details
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'app/models/asset_repair_request.rb', line 58 def self.preventative_detail(organization_id , start_date, end_date) @asset = Asset.where("organization_id =? and created_at >= ? and created_at <= ? and retire =?", organization_id, start_date , end_date, false) arr =[] count = 0 @asset.each do |asset| asset_name = asset.name request = self.find_by_asset_id(asset.id) if request.blank? vendor = "" vendor_name = "" else vendor = Vendor.find_by_id(request.vendor_id) vendor_name = vendor.name arr<<asset_name << request << vendor_name end end return arr end |
.rebuild_pg_search_documents ⇒ Object
Naive approach
12 13 14 |
# File 'app/models/asset_repair_request.rb', line 12 def self.rebuild_pg_search_documents find_each { |record| record.update_pg_search_document } end |
.repair_cost_origional(asset) ⇒ Object
47 48 49 50 51 52 53 54 55 |
# File 'app/models/asset_repair_request.rb', line 47 def self.repair_cost_origional(asset) @vendor_cost= AssetRepairRequest.where(:asset_id =>asset) @total = 0 @vendor_cost.each do |f| @vend = f.vending_cost.to_f @total = @vend + @total end return @total end |
Instance Method Details
#arr_notifications ⇒ Object
All notifications of type “ARR” -> “Asset Repair Request”
41 42 43 44 45 |
# File 'app/models/asset_repair_request.rb', line 41 def arr_notifications self.notifications.where({ notification_type: "ARR" }) end |
#asset_name ⇒ Object
24 25 26 |
# File 'app/models/asset_repair_request.rb', line 24 def asset_name asset.name end |
#respond(is_accepted, comments, responded_by) ⇒ Object
End
32 33 34 35 36 37 38 |
# File 'app/models/asset_repair_request.rb', line 32 def respond(is_accepted, comments, responded_by) self.status = (is_accepted ? 1 : -1) self.responder_comments = comments self.responded_by = responded_by self.responded_date = Time.new self.save! end |
#user_name ⇒ Object
User name for multiple search
20 21 22 |
# File 'app/models/asset_repair_request.rb', line 20 def user_name requested_by.name end |
#vendor_name ⇒ Object
28 29 30 |
# File 'app/models/asset_repair_request.rb', line 28 def vendor_name vendor.name end |