Class: Checkout
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Checkout
- Defined in:
- app/models/checkout.rb
Class Method Summary collapse
- .manifestations_count(start_date, end_date, manifestation) ⇒ Object
- .per_page ⇒ Object
- .send_due_date_notification ⇒ Object
- .send_overdue_notification ⇒ Object
Instance Method Summary collapse
- #checkout_renewable? ⇒ Boolean
- #get_new_due_date ⇒ Object
- #is_not_checked? ⇒ Boolean
- #is_today_due_date? ⇒ Boolean
- #over_checkout_renewal_limit? ⇒ Boolean
- #overdue? ⇒ Boolean
- #reserved? ⇒ Boolean
Class Method Details
.manifestations_count(start_date, end_date, manifestation) ⇒ Object
80 81 82 |
# File 'app/models/checkout.rb', line 80 def self.manifestations_count(start_date, end_date, manifestation) self.completed(start_date, end_date).where(:item_id => manifestation.items.collect(&:id)).count end |
.per_page ⇒ Object
26 27 28 |
# File 'app/models/checkout.rb', line 26 def self.per_page 10 end |
.send_due_date_notification ⇒ Object
84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'app/models/checkout.rb', line 84 def self.send_due_date_notification template = 'recall_item' queues = [] User.find_each do |user| # 未来の日時を指定する checkouts = user.checkouts.due_date_on(user.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
97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'app/models/checkout.rb', line 97 def self.send_overdue_notification template = 'recall_overdue_item' queues = [] User.find_each do |user| user.user_group.number_of_time_to_notify_overdue.times do |i| checkouts = user.checkouts.due_date_on((user.user_group.number_of_day_to_notify_overdue * (i + 1)).days.ago.beginning_of_day) unless checkouts.empty? queues << user.(template, :manifestations => checkouts.collect(&:item).collect(&:manifestation)) end end end queues.size end |
Instance Method Details
#checkout_renewable? ⇒ Boolean
37 38 39 40 41 42 43 44 |
# File 'app/models/checkout.rb', line 37 def checkout_renewable? return false if self.overdue? if self.item return false if self.over_checkout_renewal_limit? return false if self.reserved? end true end |
#get_new_due_date ⇒ Object
70 71 72 73 74 75 76 77 78 |
# File 'app/models/checkout.rb', line 70 def get_new_due_date if self.item if self.checkout_renewal_count <= self.item.checkout_status(user).checkout_renewal_limit new_due_date = Time.zone.now.advance(:days => self.item.checkout_status(user).checkout_period).beginning_of_day else new_due_date = self.due_date end end end |
#is_not_checked? ⇒ Boolean
30 31 32 33 34 35 |
# File 'app/models/checkout.rb', line 30 def is_not_checked? checkout = Checkout.not_returned.find(self.item) rescue nil unless checkout.nil? errors[:base] << I18n.t('activerecord.errors.messages.checkin.already_checked_out') end end |
#is_today_due_date? ⇒ Boolean
62 63 64 65 66 67 68 |
# File 'app/models/checkout.rb', line 62 def is_today_due_date? if Time.zone.now.beginning_of_day == self.due_date.beginning_of_day return true else return false end end |
#over_checkout_renewal_limit? ⇒ Boolean
50 51 52 |
# File 'app/models/checkout.rb', line 50 def over_checkout_renewal_limit? return true if self.item.checkout_status(self.user).checkout_renewal_limit <= self.checkout_renewal_count end |
#overdue? ⇒ Boolean
54 55 56 57 58 59 60 |
# File 'app/models/checkout.rb', line 54 def overdue? if Time.zone.now > due_date.tomorrow.beginning_of_day return true else return false end end |
#reserved? ⇒ Boolean
46 47 48 |
# File 'app/models/checkout.rb', line 46 def reserved? return true if self.item.reserved? end |