Class: InterLibraryLoan
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- InterLibraryLoan
- Extended by:
- ItemsHelper
- Defined in:
- app/models/inter_library_loan.rb
Instance Attribute Summary collapse
-
#item_identifier ⇒ Object
Returns the value of attribute item_identifier.
Class Method Summary collapse
- .get_loan_lists(loans, library_ids) ⇒ Object
- .get_loan_report(inter_library_loan) ⇒ Object
- .get_pickup_item_file(pickup_item, loan) ⇒ Object
- .loan_items ⇒ Object
- .reasons ⇒ Object
Instance Method Summary collapse
- #do_request ⇒ Object
- #receive ⇒ Object
- #request_for_checkin(item, from_library) ⇒ Object
- #request_for_reserve(item, to_library) ⇒ Object
- #return_receive ⇒ Object
- #return_ship ⇒ Object
- #ship ⇒ Object
Instance Attribute Details
#item_identifier ⇒ Object
Returns the value of attribute item_identifier.
21 22 23 |
# File 'app/models/inter_library_loan.rb', line 21 def item_identifier @item_identifier end |
Class Method Details
.get_loan_lists(loans, library_ids) ⇒ Object
162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 |
# File 'app/models/inter_library_loan.rb', line 162 def self.get_loan_lists(loans, library_ids) report = ThinReports::Report.new :layout => "#{Rails.root.to_s}/app/views/inter_library_loans/loan_list" report.events.on :page_create do |e| e.page.item(:page).value(e.page.no) end report.events.on :generate do |e| e.pages.each do |page| page.item(:total).value(e.report.page_count) end end library_ids.each do |library_id| library = Library.find(library_id) rescue nil to_libraries = InterLibraryLoan.where(:from_library_id => library_id).inject([]){|libraries, data| libraries << Library.find(data.to_library_id)} next if to_libraries.blank? to_libraries.uniq.each do |to_library| report.start_new_page report.page.item(:date).value(Time.now) report.page.item(:library).value(library.display_name.localize) report.page.item(:library_move_to).value(to_library.display_name.localize) loans.each do |loan| if loan.from_library_id == library.id && loan.to_library_id == to_library.id && loan.reason == 1 report.page.list(:list).add_row do |row| row.item(:reason).value(I18n.t('inter_library_loan.checkout')) row.item(:item_identifier).value(loan.item.item_identifier) row.item(:shelf).value(loan.item.shelf.display_name) if loan.item.shelf row.item(:call_number).value(call_numberformat(loan.item)) row.item(:title).value(loan.item.manifestation.original_title) if loan.item.manifestation end end end loans.each do |loan| if loan.from_library_id == library.id && loan.to_library_id == to_library.id && loan.reason == 2 report.page.list(:list).add_row do |row| row.item(:reason).value(I18n.t('inter_library_loan.checkin')) row.item(:item_identifier).value(loan.item.item_identifier) row.item(:shelf).value(loan.item.shelf.display_name) if loan.item.shelf row.item(:call_number).value(call_numberformat(loan.item)) row.item(:title).value(loan.item.manifestation.original_title) if loan.item.manifestation end end end end end logger.error report.page return report end |
.get_loan_report(inter_library_loan) ⇒ Object
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 |
# File 'app/models/inter_library_loan.rb', line 135 def self.get_loan_report(inter_library_loan) @loan = inter_library_loan begin report = ThinReports::Report.new :layout => "#{Rails.root.to_s}/app/views/inter_library_loans/move_item" report.start_new_page report.page.item(:export_date).value(Time.now) report.page.item(:title).value(@loan.item.manifestation.original_title) report.page.item(:call_number).value(call_numberformat(@loan.item)) report.page.item(:from_library).value(@loan.from_library.display_name.localize) report.page.item(:to_library).value(@loan.to_library.display_name.localize) report.page.item(:reason).value(I18n.t('inter_library_loan.checkout')) if @loan.reason == 1 report.page.item(:reason).value(I18n.t('inter_library_loan.checkin')) if @loan.reason == 2 reserve = Reserve.waiting.where(:item_id => @loan.item_id, :receipt_library_id => @loan.to_library_id, :state => 'in_process').first if reserve report.page.item(:user_title).show report.page.item(:reserve_user).value(reserve.user.username) if reserve.user report.page.item(:expire_date_title).show report.page.item(:reserve_expire_date).value(reserve.expired_at) end logger.error "created report: #{Time.now}" return report.generate rescue Exception => e logger.error "failed #{e}" return false end end |
.get_pickup_item_file(pickup_item, loan) ⇒ Object
211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 |
# File 'app/models/inter_library_loan.rb', line 211 def self.get_pickup_item_file(pickup_item, loan) report = ThinReports::Report.new :layout => "#{Rails.root.to_s}/app/views/inter_library_loans/move_item" report.start_new_page report.page.item(:export_date).value(Time.now) report.page.item(:title).value(pickup_item.manifestation.original_title) report.page.item(:call_number).value(call_numberformat(pickup_item)) report.page.item(:from_library).value(loan.from_library.display_name.localize) report.page.item(:to_library).value(loan.to_library.display_name.localize) report.page.item(:reason).value(I18n.t('inter_library_loan.checkout')) if loan.reason == 1 report.page.item(:reason).value(I18n.t('inter_library_loan.checkin')) if loan.reason == 2 reserve = Reserve.waiting.where(:item_id => loan.item_id, :receipt_library_id => loan.to_library_id, :state => 'in_process').first if reserve report.page.item(:user_title).show report.page.item(:reserve_user).value(reserve.user.username) if reserve.user report.page.item(:expire_date_title).show report.page.item(:reserve_expire_date).value(reserve.expired_at) end return report end |
.loan_items ⇒ Object
120 121 122 123 124 125 126 127 |
# File 'app/models/inter_library_loan.rb', line 120 def self.loan_items loans = [] item_ids = InterLibraryLoan.select(:item_id).where(:received_at => nil).inject([]){|ids, loan| ids << loan.item_id}.uniq item_ids.each do |id| loans << InterLibraryLoan.where(:item_id => id, :received_at => nil).order("reason DESC, created_at ASC").first end return loans end |
.reasons ⇒ Object
129 130 131 132 133 |
# File 'app/models/inter_library_loan.rb', line 129 def self.reasons reasons = [[I18n.t('inter_library_loan.checkout'), 1], [I18n.t('inter_library_loan.checkin'), 2]] return reasons end |
Instance Method Details
#do_request ⇒ Object
74 75 76 77 78 79 |
# File 'app/models/inter_library_loan.rb', line 74 def do_request InterLibraryLoan.transaction do self.item.update_attribute(:circulation_status, CirculationStatus.where(:name => 'Recalled').first) self.update_attribute(:requested_at, Time.zone.now) end end |
#receive ⇒ Object
88 89 90 91 92 93 |
# File 'app/models/inter_library_loan.rb', line 88 def receive InterLibraryLoan.transaction do # self.item.update_attributes({:circulation_status => CirculationStatus.where(:name => 'In Process').first}) self.update_attributes({:received_at => Time.zone.now}) end end |
#request_for_checkin(item, from_library) ⇒ Object
115 116 117 118 |
# File 'app/models/inter_library_loan.rb', line 115 def request_for_checkin(item, from_library) self.update_attributes(:item_id => item.id, :from_library_id => from_library.id, :to_library_id => item.shelf.library.id, :requested_at => Time.zone.now, :reason => 2) self.sm_request! end |
#request_for_reserve(item, to_library) ⇒ Object
110 111 112 113 |
# File 'app/models/inter_library_loan.rb', line 110 def request_for_reserve(item, to_library) self.update_attributes(:item_id => item.id, :to_library_id => to_library.id, :from_library_id => item.shelf.library.id, :requested_at => Time.zone.now, :reason => 1) self.sm_request! end |
#return_receive ⇒ Object
102 103 104 105 106 107 108 |
# File 'app/models/inter_library_loan.rb', line 102 def return_receive InterLibraryLoan.transaction do # TODO: 'Waiting To Be Reshelved' self.item.update_attributes({:circulation_status => CirculationStatus.where(:name => 'Available On Shelf').first}) self.update_attributes({:return_received_at => Time.zone.now}) end end |
#return_ship ⇒ Object
95 96 97 98 99 100 |
# File 'app/models/inter_library_loan.rb', line 95 def return_ship InterLibraryLoan.transaction do self.item.update_attributes({:circulation_status => CirculationStatus.where(:name => 'In Transit Between Library Locations').first}) self.update_attributes({:return_shipped_at => Time.zone.now}) end end |
#ship ⇒ Object
81 82 83 84 85 86 |
# File 'app/models/inter_library_loan.rb', line 81 def ship InterLibraryLoan.transaction do self.item.update_attributes({:circulation_status => CirculationStatus.where(:name => 'In Transit Between Library Locations').first}) self.update_attributes({:shipped_at => Time.zone.now}) end end |