Class: Checkout
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Checkout
- Defined in:
- app/models/checkout.rb
Instance Attribute Summary collapse
-
#operator ⇒ Object
Returns the value of attribute operator.
Class Method Summary collapse
- .manifestations_count(start_date, end_date, manifestation) ⇒ Object
- .remove_all_history(user) ⇒ Object
- .send_due_date_notification ⇒ Object
- .send_overdue_notification ⇒ Object
Instance Method Summary collapse
- #get_new_due_date ⇒ Object
- #is_not_checked? ⇒ Boolean
- #is_today_due_date? ⇒ Boolean
- #over_checkout_renewal_limit? ⇒ Boolean
- #overdue? ⇒ Boolean
- #renewable? ⇒ Boolean
- #reserved? ⇒ Boolean
Instance Attribute Details
#operator ⇒ Object
Returns the value of attribute operator.
47 48 49 |
# File 'app/models/checkout.rb', line 47 def operator @operator end |
Class Method Details
.manifestations_count(start_date, end_date, manifestation) ⇒ Object
117 118 119 120 121 122 123 124 125 126 |
# File 'app/models/checkout.rb', line 117 def self.manifestations_count(start_date, end_date, manifestation) self.where( self.arel_table[:created_at].gteq start_date ).where( self.arel_table[:created_at].lt end_date ) .where( item_id: manifestation.items.pluck('items.id') ).count end |
.remove_all_history(user) ⇒ Object
155 156 157 |
# File 'app/models/checkout.rb', line 155 def self.remove_all_history(user) user.checkouts.returned.update_all(user_id: nil) end |
.send_due_date_notification ⇒ Object
128 129 130 131 132 133 134 135 136 137 138 139 |
# File 'app/models/checkout.rb', line 128 def self.send_due_date_notification template = 'recall_item' queues = [] User.find_each do |user| # 未来の日時を指定する checkouts = user.checkouts.due_date_on(user.profile.user_group.number_of_day_to_notify_due_date.days.from_now.beginning_of_day) unless checkouts.empty? queues << user.(template, manifestations: checkouts.collect(&:item).collect(&:manifestation)) end end queues.size end |
.send_overdue_notification ⇒ Object
141 142 143 144 145 146 147 148 149 150 151 152 153 |
# File 'app/models/checkout.rb', line 141 def self.send_overdue_notification template = 'recall_overdue_item' queues = [] User.find_each do |user| user.profile.user_group.number_of_time_to_notify_overdue.times do |i| checkouts = user.checkouts.due_date_on((user.profile.user_group.number_of_day_to_notify_overdue * (i + 1)).days.ago.beginning_of_day) unless checkouts.empty? queues << user.profile.user.(template, manifestations: checkouts.collect(&:item).collect(&:manifestation)) end end end queues.size end |
Instance Method Details
#get_new_due_date ⇒ Object
106 107 108 109 110 111 112 113 114 115 |
# File 'app/models/checkout.rb', line 106 def get_new_due_date return nil unless user if item if checkout_renewal_count <= item.checkout_status(user).checkout_renewal_limit new_due_date = Time.zone.now.advance(days: item.checkout_status(user).checkout_period).beginning_of_day else new_due_date = due_date end end end |
#is_not_checked? ⇒ Boolean
51 52 53 54 55 56 |
# File 'app/models/checkout.rb', line 51 def is_not_checked? checkout = Checkout.not_returned.where(item_id: item_id) unless checkout.empty? errors[:base] << I18n.t('activerecord.errors.messages.checkin.already_checked_out') end end |
#is_today_due_date? ⇒ Boolean
98 99 100 101 102 103 104 |
# File 'app/models/checkout.rb', line 98 def is_today_due_date? if Time.zone.now.beginning_of_day == due_date.beginning_of_day return true else return false end end |
#over_checkout_renewal_limit? ⇒ Boolean
85 86 87 88 |
# File 'app/models/checkout.rb', line 85 def over_checkout_renewal_limit? return nil unless item.checkout_status(user) return true if item.checkout_status(user).checkout_renewal_limit < checkout_renewal_count end |
#overdue? ⇒ Boolean
90 91 92 93 94 95 96 |
# File 'app/models/checkout.rb', line 90 def overdue? if Time.zone.now > due_date.tomorrow.beginning_of_day return true else return false end end |
#renewable? ⇒ Boolean
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'app/models/checkout.rb', line 58 def renewable? return nil if checkin = [] if !operator and overdue? << I18n.t('checkout.you_have_overdue_item') end if !operator and reserved? << I18n.t('checkout.this_item_is_reserved') end if !operator and over_checkout_renewal_limit? << I18n.t('checkout.excessed_renewal_limit') end if .empty? true else .each do || errors[:base] << end false end end |
#reserved? ⇒ Boolean
80 81 82 83 |
# File 'app/models/checkout.rb', line 80 def reserved? return true if item.try(:reserved?) false end |