Class: Checkin

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#item_identifierObject

Returns the value of attribute item_identifier.



14
15
16
# File 'app/models/checkin.rb', line 14

def item_identifier
  @item_identifier
end

Instance Method Details

#available_for_checkin?Boolean

Returns:

  • (Boolean)


18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'app/models/checkin.rb', line 18

def available_for_checkin?
  unless basket
    return nil
  end

  if item.blank?
    errors[:base] << I18n.t('checkin.item_not_found')
    return
  end

  if basket.items.where('item_id = ?', item.id).first
    errors[:base] << I18n.t('checkin.already_checked_in')
  end
end

#item_checkin(current_user) ⇒ Object



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
67
68
69
70
71
72
73
# File 'app/models/checkin.rb', line 33

def item_checkin(current_user)
  message = ''
  Checkin.transaction do
    item.checkin!
    Checkout.not_returned.where(item_id: item_id).each do |checkout|
      # TODO: ILL時の処理
      checkout.checkin = self
      checkout.operator = current_user
      unless checkout.user.profile.try(:save_checkout_history)
        checkout.user = nil
      end
      checkout.save(validate: false)
      unless checkout.item.shelf.library == current_user.profile.library
        message << I18n.t('checkin.other_library_item')
      end
    end

    if item.reserved?
      # TODO: もっと目立たせるために別画面を表示するべき?
      message << I18n.t('item.this_item_is_reserved')
      item.retain(current_user)
    end

    if item.include_supplements?
      message << I18n.t('item.this_item_include_supplement')
    end

    if item.circulation_status.name == 'Missing'
      message << I18n.t('checkout.missing_item_found')
    end

    # メールとメッセージの送信
    #ReservationNotifier.deliver_reserved(item.manifestation.reserves.first.user, item.manifestation)
    #Message.create(sender: current_user, receiver: item.manifestation.next_reservation.user, subject: message_template.title, body: message_template.body, recipient: item.manifestation.next_reservation.user)
  end
  if message.present?
    message
  else
    nil
  end
end

#set_itemObject



75
76
77
78
79
80
81
# File 'app/models/checkin.rb', line 75

def set_item
  identifier = item_identifier.to_s.strip
  if identifier.present?
    item = Item.where(item_identifier: identifier).first
    self.item = item
  end
end