Skip to content

Commit

Permalink
Merge 8393e52 into 995d89e
Browse files Browse the repository at this point in the history
  • Loading branch information
jgreben committed Mar 6, 2020
2 parents 995d89e + 8393e52 commit 3a56ca6
Show file tree
Hide file tree
Showing 18 changed files with 265 additions and 359 deletions.
53 changes: 5 additions & 48 deletions app/controllers/endowed_funds_reports_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,66 +24,23 @@ def create
@endowed_funds_report = EndowedFundsReport.new(batch_params)
if @endowed_funds_report.valid?
# write keys to file to Symphony mount [/symphony] on libsys-webforms-dev
keys = @endowed_funds_report.keys
if keys.present?
@endowed_funds_report.write_keys(keys)
out_file = File.new("#{Settings.symphony_dataload_endowrpt}/#{@endowed_funds_report.ckeys_file}", 'w')
out_file.puts(keys.join("\n"))
out_file.close
flash[:success] = 'Report requested!'
redirect_to root_path
else
flash[:error] = 'Could not find catalog keys for the date range selected'
render action: 'new'
end
else
flash[:warning] = 'Check that all form fields are entered!'
flash[:warning] = 'Check that all form fields are entered'
render action: 'new'
end
end

def keys
if !@endowed_funds_report.fund.nil?
@endowed_funds_report.fiscal_years.any? ? funds_fy : funds_keys
elsif !@endowed_funds_report.fund_begin.nil?
@endowed_funds_report.fiscal_years.any? ? funds_fy_begin : funds_keys_begin
end
end

def funds_keys
EndowedFundsReport.ol_cat_key_fund(@endowed_funds_report.fund, date_start, date_end)
end

def funds_fy
EndowedFundsReport.ol_cat_key_fy(@endowed_funds_report.fund, date_start, date_end)
end

def funds_keys_begin
EndowedFundsReport.ol_cat_key_fund_begin(@endowed_funds_report.fund, date_start, date_end)
end

def funds_fy_begin
EndowedFundsReport.ol_cat_key_fy_begin(@endowed_funds_report.fund, date_start, date_end)
end

def date_start
if @endowed_funds_report.fiscal_years.any?
start_date = @endowed_funds_report.fiscal_years[0]
elsif @endowed_funds_report.calendar_years.any?
start_date = Time.parse("#{@endowed_funds_report.calendar_years[0]}-01-01").in_time_zone.strftime('%Y-%m-%d')
elsif @endowed_funds_report.paid_years.any?
start_date = Time.parse(@endowed_funds_report.paid_years[0].to_s).in_time_zone.strftime('%Y-%m-%d')
end
start_date
end

def date_end
if @endowed_funds_report.fiscal_years.any?
end_date = @endowed_funds_report.fiscal_years[1]
elsif @endowed_funds_report.calendar_years.any?
end_date = Time.parse("#{@endowed_funds_report.calendar_years[1]}-12-31").in_time_zone.strftime('%Y-%m-%d')
elsif @endowed_funds_report.paid_years.any?
end_date = Time.parse(@endowed_funds_report.paid_years[1].to_s).in_time_zone.strftime('%Y-%m-%d')
end
end_date
end

def batch_params
params.require(:endowed_funds_report).permit!
end
Expand Down
33 changes: 19 additions & 14 deletions app/models/circulation_statistics_report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,29 @@ class CirculationStatisticsReport
:tag_field, :tag_field2, :tags_url, :link_type, :col_header1,
:col_header2, :col_header3, :col_header4, :col_header5,
:blank_col_array, :lib_loc_array, :user_id
validates :email, :lib_array, presence: true
validates :barcodes, presence: true, if: :barcode_range_type?
validates :lib_array, length: { minimum: 2, message: "can't be empty" }, if: :not_barcode_range_type?
validates :min_yr, length: { is: 4 }, numericality: { only_integer: true }, allow_blank: true
validates :max_yr, length: { is: 4 }, numericality: { only_integer: true }, allow_blank: true
validates :tag_field, length: { is: 3 }, numericality: { only_integer: true },
exclusion: { in: %w[008] }, allow_blank: true
validates :tag_field2, length: { is: 3 }, numericality: { only_integer: true },
exclusion: { in: %w[008] }, allow_blank: true

validates :lib_array, length: { minimum: 2, message: 'Select at least one library' }, unless: :barcode_range_type?
validates :barcodes, presence: { is: true, message: 'Upload a file of barcodes' }, if: :barcode_range_type?
validates :email, format: { with: Rails.configuration.email_pattern,
message: 'Email address is missing or not in a correct format' }
validates :min_yr, length: { is: 4, message: 'Year length must be four digits' },
numericality: { only_integer: true },
allow_blank: true
validates :max_yr, length: { is: 4, message: 'Year length must be four digits' },
numericality: { only_integer: true },
allow_blank: true
validates :tag_field, length: { is: 3, message: 'Bibfield number must be 3 digits' },
numericality: { only_integer: true, message: 'Bibfield must be a 3-digit number' },
exclusion: { in: %w[008], message: 'Bibfield cannot be 008' },
allow_blank: true
validates :tag_field2, length: { is: 3, message: 'Bibfield number must be 3 digits' },
numericality: { only_integer: true, message: 'Bibfield must be a 3-digit number' },
exclusion: { in: %w[008], message: 'Bibfield cannot be 008' },
allow_blank: true
validate :lc_call_lo, if: :lc_range_type?
validate :lc_call_hi, if: :lc_range_type?
validate :classic_call_lo_and_hi, if: :classic_range_type?
validate :classic_call_alpha, if: :classic_range_type?
validates :email, format: { with: Rails.configuration.email_pattern }, allow_blank: true

before_validation :upcase_call_alpha

Expand All @@ -49,10 +58,6 @@ def classic_range_type?
range_type == 'classic'
end

def not_barcode_range_type?
range_type != 'barcodes'
end

def call_regex
/^[A-Z]{1,2}$|^[A-Z]\#$/
end
Expand Down
24 changes: 12 additions & 12 deletions app/models/encumbrance_report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@ class EncumbranceReport < ApplicationRecord
attr_accessor :fund_select, :show_dates, :fund, :fund_begin, :email, :status,
:date_ran, :date_request, :output_file, :fund_acct

validates :email, :status, :date_request, :output_file, presence: true
validates :email, format: { with: Rails.configuration.email_pattern }, allow_blank: true
validates :fund, presence: true, if: :blank_fund_begin?
validates :fund_begin, presence: true, if: :blank_fund?
validate :email_format
validate :fund_selection_present

before_save :set_fund, :write_dates, :set_email, :set_status, :set_output_file

Expand All @@ -21,14 +19,6 @@ def kickoff

private

def blank_fund_begin?
fund_begin.blank?
end

def blank_fund?
fund.blank?
end

def set_fund
if fund.present?
self[:fund_acct] = fund.join(',')
Expand All @@ -52,4 +42,14 @@ def set_status
def set_output_file
self[:output_file] = output_file
end

def email_format
message = 'Email address is missing or not in a correct format'
errors.add(:base, message) unless email.match(Rails.configuration.email_pattern)
end

def fund_selection_present
message = 'Select a single Fund ID/PTA, a fund that begins with an ID/PTA number, or all SUL funds'
errors.add(:base, message) unless fund.present? || fund_begin.present?
end
end
80 changes: 53 additions & 27 deletions app/models/endowed_funds_report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,20 @@ class EndowedFundsReport
:date_ran, :date_type, :fy_start, :fy_end, :cal_start, :cal_end,
:pd_start, :pd_end, :email, :ckeys_file

validates :fund, presence: true, if: :blank_fund_begin?
validates :fund_begin, presence: true, if: :blank_fund?
validates :fy_start, presence: true, if: :only_fy?
validates :cal_start, presence: true, if: :only_cal?
validates :pd_start, presence: true, if: :only_pd?
validates :email, presence: true
validates :email, format: { with: Rails.configuration.email_pattern }, allow_blank: true
validate :email_format
validate :fund_selection_present
validate :start_date_present

def keys
if fund.present?
fiscal_years.any? ? ol_cat_key_fy : ol_cat_key_fund
elsif fund_begin.present?
fiscal_years.any? ? ol_cat_key_fy_begin : ol_cat_key_fund_begin
end
end

# get cat keys
def self.ol_cat_key_fund(fund, date_start, date_end)
def ol_cat_key_fund
fund_codes = []
fund.each do |fc|
Expenditures.where("ta_fund_code = ? AND ta_date_2encina between
Expand All @@ -31,7 +35,7 @@ def self.ol_cat_key_fund(fund, date_start, date_end)
fund_codes.uniq
end

def self.ol_cat_key_fy(fund, date_start, date_end)
def ol_cat_key_fy
fund_codes = []
fund.each do |fc|
Expenditures.where('ta_fund_code = ? AND (ti_fiscal_cycle >= ? AND ti_fiscal_cycle <= ?)',
Expand All @@ -43,24 +47,40 @@ def self.ol_cat_key_fy(fund, date_start, date_end)
fund_codes.uniq
end

def self.ol_cat_key_fund_begin(fund_begin, date_start, date_end)
def ol_cat_key_fund_begin
Expenditures.where("ta_fund_code LIKE ? AND ti_inv_lib = 'SUL' AND ta_date_2encina between
TO_DATE(?, 'yyyy-mm-dd') AND TO_DATE(?, 'yyyy-mm-dd')",
"%#{fund_begin}%", date_start, date_end).pluck(:ol_cat_key)
rescue ActiveRecord::StatementInvalid
end

def self.ol_cat_key_fy_begin(fund_begin, date_start, date_end)
def ol_cat_key_fy_begin
Expenditures.where("ta_fund_code LIKE ? AND ti_inv_lib = 'SUL' AND
(ti_fiscal_cycle >= ? AND ti_fiscal_cycle <= ?)",
"%#{fund_begin}%", date_start, date_end).pluck(:ol_cat_key)
rescue ActiveRecord::StatementInvalid
end

def write_keys(catalog_keys)
out_file = File.new("#{Settings.symphony_dataload_endowrpt}/#{ckeys_file}", 'w')
out_file.puts(catalog_keys.join("\n"))
out_file.close
def date_start
if fiscal_years.any?
start_date = fiscal_years[0]
elsif calendar_years.any?
start_date = Time.parse("#{calendar_years[0]}-01-01").in_time_zone.strftime('%Y-%m-%d')
elsif paid_years.any?
start_date = Time.parse(paid_years[0].to_s).in_time_zone.strftime('%Y-%m-%d')
end
start_date
end

def date_end
if fiscal_years.any?
end_date = fiscal_years[1]
elsif calendar_years.any?
end_date = Time.parse("#{calendar_years[1]}-12-31").in_time_zone.strftime('%Y-%m-%d')
elsif paid_years.any?
end_date = Time.parse(paid_years[1].to_s).in_time_zone.strftime('%Y-%m-%d')
end
end_date
end

def fiscal_years
Expand All @@ -86,23 +106,29 @@ def paid_years

private

def blank_fund_begin?
fund_begin.blank?
end

def blank_fund?
fund.blank?
def start_date_present
message = 'Choose a start date for fiscal, calendar, or paid date'
errors.add(:base, message) unless type_of_date_present?
end

def only_fy?
cal_start.blank? && pd_start.blank?
def type_of_date_present?
case date_type
when 'calendar'
cal_start.present?
when 'fiscal'
fy_start.present?
when 'paydate'
pd_start.present?
end
end

def only_cal?
fy_start.blank? && pd_start.blank?
def email_format
message = 'Email address is missing or not in a correct format'
errors.add(:base, message) unless email.match(Rails.configuration.email_pattern)
end

def only_pd?
fy_start.blank? && cal_start.blank?
def fund_selection_present
message = 'Select a single Fund ID/PTA, a fund that begins with an ID/PTA number, or all SUL funds'
errors.add(:base, message) unless fund.present? || fund_begin.present?
end
end
34 changes: 19 additions & 15 deletions app/models/expenditure_report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,9 @@ class ExpenditureReport < ApplicationRecord
attr_accessor :fund, :fund_begin, :fund_select, :date_type, :fy_start, :fy_end,
:cal_start, :cal_end, :pd_start, :pd_end, :output_file

validates :email, presence: true
validates :fund, presence: true, if: :blank_fund_begin?
validates :fund_begin, presence: true, if: :blank_fund?
validates :date_type, inclusion: %w[fiscal calendar paydate]
validates :start_date_present?, inclusion: { in: [true], message: 'Please choose a start date for the report.' }
validates :email, format: { with: Rails.configuration.email_pattern }, allow_blank: true
validate :email_format
validate :fund_selection_present
validate :start_date_present

before_save :set_fund, :set_output_file, :check_dates

Expand All @@ -24,19 +21,16 @@ def kickoff

private

def blank_fund_begin?
fund_begin.blank?
end

def blank_fund?
fund.blank?
end

def set_output_file
self[:output_file] = output_file
end

def start_date_present?
def start_date_present
message = 'Choose a start date for fiscal, calendar, or paid date'
errors.add(:base, message) unless type_of_date_present?
end

def type_of_date_present?
case date_type
when 'calendar'
cal_start.present?
Expand All @@ -46,4 +40,14 @@ def start_date_present?
pd_start.present?
end
end

def email_format
message = 'Email address is missing or not in a correct format'
errors.add(:base, message) unless email.match(Rails.configuration.email_pattern)
end

def fund_selection_present
message = 'Select a single Fund ID/PTA, a fund that begins with an ID/PTA number, or all SUL funds'
errors.add(:base, message) unless fund.present? || fund_begin.present?
end
end

0 comments on commit 3a56ca6

Please sign in to comment.