Class: AssetScan

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
PgSearch
Defined in:
app/models/asset_scan.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.asset_scan_list(name, asset) ⇒ Object

for view scan list



47
48
49
# File 'app/models/asset_scan.rb', line 47

def self.asset_scan_list(name , asset)
  AssetScan.where("name = ? and asset_id =?",name , asset).last
end

.asset_warranties(oraginaztion_id, start_month, end_month) ⇒ Object

for asset warranties



62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'app/models/asset_scan.rb', line 62

def self.asset_warranties(oraginaztion_id , start_month ,end_month)
  scan_list ={}
  assets =  Asset.where("organization_id =? and created_at >= ? and created_at <= ? and  retire =?", oraginaztion_id, start_month , end_month, false)
 
  assets.each do |asset|
    asset_name = asset.name
    scan = self.where("name = ? and asset_id =? and start_date >= ? and expiry_date <= ?", "warranty", asset.id , start_month.to_date, end_month.to_date)
    if !scan.blank?
      scan_list.store(scan , asset_name)
    end
  end
  
  return scan_list
end

.find_repaired_history(repair_id) ⇒ Object

find history records



52
53
54
# File 'app/models/asset_scan.rb', line 52

def self.find_repaired_history(repair_id)
  @repair_record = AssetScan.find_by_repair_id(repair_id)
end

.find_scans(scan_id) ⇒ Object



56
57
58
# File 'app/models/asset_scan.rb', line 56

def self.find_scans(scan_id)
  @scan_id = AssetScan.find_by_id(scan_id)
end

.total_asset_warranty(asset_id) ⇒ Object

Find total scan for warranty



78
79
80
# File 'app/models/asset_scan.rb', line 78

def self.total_asset_warranty(asset_id)
  self.where("asset_id = ? and name = ?",asset_id, "warranty")
end

.total_service_contract(asset_id) ⇒ Object

Find Total scan for service contract



83
84
85
# File 'app/models/asset_scan.rb', line 83

def self.total_service_contract(asset_id)
  self.where("asset_id = ? and name = ?",asset_id, "service_contract")
end

Instance Method Details

#decode_scan(params, asset_scan) ⇒ Object

decode hash of anuglar base 64 image string



32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'app/models/asset_scan.rb', line 32

def decode_scan(params,asset_scan)
  #    Rails.logger.info 'decoding base64 file'
  decoded_data = Base64.decode64(params[:image_url][:base64])
  # create 'file' understandable by Paperclip
  data = StringIO.new(decoded_data)
  data.class_eval do
    attr_accessor :content_type, :original_filename
  end
  # set file properties
  data.content_type = params[:image_url][:filetype]
  data.original_filename = params[:image_url][:filename]
  asset_scan.update(:scans => data)
end

#is_image?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'app/models/asset_scan.rb', line 23

def is_image?
  scans.content_type =~ %r(image)
end

#is_pdf?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'app/models/asset_scan.rb', line 26

def is_pdf?
  scans.content_type =~ %r(application)
end