diff --git a/app/components/check_answers_summary_list_card_component.html.erb b/app/components/check_answers_summary_list_card_component.html.erb
index 73e9335c8..f299674b2 100644
--- a/app/components/check_answers_summary_list_card_component.html.erb
+++ b/app/components/check_answers_summary_list_card_component.html.erb
@@ -16,18 +16,18 @@
<% row.key { question.check_answer_label.to_s.presence || question.header.to_s } %>
<% row.value do %>
<%= get_answer_label(question) %>
- <% extra_value = question.get_extra_check_answer_value(lettings_log) %>
+ <% extra_value = question.get_extra_check_answer_value(log) %>
<% if extra_value %>
<%= extra_value %>
<% end %>
- <% question.get_inferred_answers(lettings_log).each do |inferred_answer| %>
+ <% question.get_inferred_answers(log).each do |inferred_answer| %>
<%= inferred_answer %>
<% end %>
<% end %>
<% row.action(
- text: question.action_text(lettings_log),
- href: question.action_href(lettings_log, question.page.id),
+ text: question.action_text(log),
+ href: question.action_href(log, question.page.id),
visually_hidden_text: question.check_answer_label.to_s.downcase,
) %>
<% end %>
diff --git a/app/components/check_answers_summary_list_card_component.rb b/app/components/check_answers_summary_list_card_component.rb
index bc7d8cdb9..de7fe9685 100644
--- a/app/components/check_answers_summary_list_card_component.rb
+++ b/app/components/check_answers_summary_list_card_component.rb
@@ -1,18 +1,18 @@
class CheckAnswersSummaryListCardComponent < ViewComponent::Base
- attr_reader :questions, :lettings_log, :user
+ attr_reader :questions, :log, :user
- def initialize(questions:, lettings_log:, user:)
+ def initialize(questions:, log:, user:)
@questions = questions
- @lettings_log = lettings_log
+ @log = log
@user = user
super
end
def applicable_questions
- questions.reject { |q| q.hidden_in_check_answers?(lettings_log, user) }
+ questions.reject { |q| q.hidden_in_check_answers?(log, user) }
end
def get_answer_label(question)
- question.answer_label(lettings_log).presence || "You didn’t answer this question".html_safe
+ question.answer_label(log).presence || "You didn’t answer this question".html_safe
end
end
diff --git a/app/controllers/lettings_logs_controller.rb b/app/controllers/lettings_logs_controller.rb
index 10b64d830..0fa90a9d6 100644
--- a/app/controllers/lettings_logs_controller.rb
+++ b/app/controllers/lettings_logs_controller.rb
@@ -12,6 +12,7 @@ class LettingsLogsController < LogsController
@pagy, @lettings_logs = pagy(unpaginated_filtered_logs)
@searched = search_term.presence
@total_count = all_logs.size
+ render "logs/index"
end
format.csv do
@@ -39,7 +40,7 @@ class LettingsLogsController < LogsController
def show
respond_to do |format|
# We don't have a dedicated non-editable show view
- format.html { edit }
+ format.html { render "logs/edit" }
format.json do
if @lettings_log
render json: @lettings_log, status: :ok
@@ -53,7 +54,7 @@ class LettingsLogsController < LogsController
def edit
@lettings_log = current_user.lettings_logs.find_by(id: params[:id])
if @lettings_log
- render :edit, locals: { current_user: }
+ render "logs/edit", locals: { current_user: }
else
render_not_found
end
diff --git a/app/controllers/logs_controller.rb b/app/controllers/logs_controller.rb
index ea140426f..3a6bc4af7 100644
--- a/app/controllers/logs_controller.rb
+++ b/app/controllers/logs_controller.rb
@@ -10,7 +10,7 @@ class LogsController < ApplicationController
def index
set_session_filters
- all_logs = current_user.lettings_logs + current_user.sales_logs
+ all_logs = AllLog.where(id: (current_user.lettings_logs + current_user.sales_logs).pluck(:id))
unpaginated_filtered_logs = filtered_logs(filtered_collection(all_logs, search_term))
respond_to do |format|
diff --git a/app/controllers/modules/logs_filter.rb b/app/controllers/modules/logs_filter.rb
index ef33ac372..83e0de9ea 100644
--- a/app/controllers/modules/logs_filter.rb
+++ b/app/controllers/modules/logs_filter.rb
@@ -9,7 +9,7 @@ module Modules::LogsFilter
logs = logs.public_send("filter_by_#{category}", values, current_user)
end
end
- logs = logs.sort_by(&:created_at)
+ logs = logs.order(created_at: :desc)
current_user.support? ? logs.all.includes(:owning_organisation, :managing_organisation) : logs
end
diff --git a/app/controllers/sales_logs_controller.rb b/app/controllers/sales_logs_controller.rb
index 3d13b3b4b..588602d7f 100644
--- a/app/controllers/sales_logs_controller.rb
+++ b/app/controllers/sales_logs_controller.rb
@@ -5,14 +5,14 @@ class SalesLogsController < LogsController
def show
respond_to do |format|
- format.html { edit }
+ format.html { "logs/edit" }
end
end
def edit
@sales_log = current_user.sales_logs.find_by(id: params[:id])
if @sales_log
- render :edit, locals: { current_user: }
+ render "logs/edit", locals: { current_user: }
else
render_not_found
end
diff --git a/app/models/all_log.rb b/app/models/all_log.rb
new file mode 100644
index 000000000..e3638b608
--- /dev/null
+++ b/app/models/all_log.rb
@@ -0,0 +1,30 @@
+class AllLog < ApplicationRecord
+ self.table_name = :logs
+
+ STATUS = { "not_started" => 0, "in_progress" => 1, "completed" => 2 }.freeze
+ enum status: STATUS
+
+ def read_only?
+ true
+ end
+
+ def tenancycode?
+ log_type == "lettings"
+ end
+
+ def needstype?
+ log_type == "lettings"
+ end
+
+ def startdate?
+ false
+ end
+
+ def is_general_needs?
+ log_type == "lettings"
+ end
+
+ def created_by
+ User.find(created_by_id)
+ end
+end
diff --git a/app/models/lettings_log.rb b/app/models/lettings_log.rb
index a1639a42e..1973ad015 100644
--- a/app/models/lettings_log.rb
+++ b/app/models/lettings_log.rb
@@ -67,11 +67,9 @@ class LettingsLog < Log
OPTIONAL_FIELDS = %w[first_time_property_let_as_social_housing tenancycode propcode].freeze
RENT_TYPE_MAPPING_LABELS = { 1 => "Social Rent", 2 => "Affordable Rent", 3 => "Intermediate Rent" }.freeze
HAS_BENEFITS_OPTIONS = [1, 6, 8, 7].freeze
- STATUS = { "not_started" => 0, "in_progress" => 1, "completed" => 2 }.freeze
NUM_OF_WEEKS_FROM_PERIOD = { 2 => 26, 3 => 13, 4 => 12, 5 => 50, 6 => 49, 7 => 48, 8 => 47, 9 => 46, 1 => 52 }.freeze
SUFFIX_FROM_PERIOD = { 2 => "every 2 weeks", 3 => "every 4 weeks", 4 => "every month" }.freeze
RETIREMENT_AGES = { "M" => 67, "F" => 60, "X" => 67 }.freeze
- enum status: STATUS
def form
FormHandler.instance.get_form(form_name) || FormHandler.instance.forms.first.second
diff --git a/app/models/log.rb b/app/models/log.rb
index 57d2935ad..de0b2a601 100644
--- a/app/models/log.rb
+++ b/app/models/log.rb
@@ -5,6 +5,9 @@ class Log < ApplicationRecord
belongs_to :managing_organisation, class_name: "Organisation", optional: true
belongs_to :created_by, class_name: "User", optional: true
+ STATUS = { "not_started" => 0, "in_progress" => 1, "completed" => 2 }.freeze
+ enum status: STATUS
+
scope :combined, -> { ActiveRecord::Base.connection.execute("SELECT * FROM logs") }
def collection_start_year
diff --git a/app/models/sales_log.rb b/app/models/sales_log.rb
index 5a616007e..edd2b4edd 100644
--- a/app/models/sales_log.rb
+++ b/app/models/sales_log.rb
@@ -10,9 +10,6 @@ class SalesLog < Log
scope :filter_by_organisation, ->(org, _user = nil) { where(owning_organisation: org).or(where(managing_organisation: org)) }
- STATUS = { "not_started" => 0, "in_progress" => 1, "completed" => 2 }.freeze
- enum status: STATUS
-
OPTIONAL_FIELDS = [].freeze
def startdate
diff --git a/app/views/lettings_logs/_log_filters.erb b/app/views/logs/_log_filters.erb
similarity index 100%
rename from app/views/lettings_logs/_log_filters.erb
rename to app/views/logs/_log_filters.erb
diff --git a/app/views/lettings_logs/_log_list.html.erb b/app/views/logs/_log_list.html.erb
similarity index 100%
rename from app/views/lettings_logs/_log_list.html.erb
rename to app/views/logs/_log_list.html.erb
diff --git a/app/views/lettings_logs/_tasklist.html.erb b/app/views/logs/_tasklist.html.erb
similarity index 100%
rename from app/views/lettings_logs/_tasklist.html.erb
rename to app/views/logs/_tasklist.html.erb
diff --git a/app/views/lettings_logs/bulk_upload.html.erb b/app/views/logs/bulk_upload.html.erb
similarity index 100%
rename from app/views/lettings_logs/bulk_upload.html.erb
rename to app/views/logs/bulk_upload.html.erb
diff --git a/app/views/lettings_logs/edit.html.erb b/app/views/logs/edit.html.erb
similarity index 100%
rename from app/views/lettings_logs/edit.html.erb
rename to app/views/logs/edit.html.erb
diff --git a/app/views/lettings_logs/index.html.erb b/app/views/logs/index.html.erb
similarity index 100%
rename from app/views/lettings_logs/index.html.erb
rename to app/views/logs/index.html.erb
diff --git a/app/views/sales_logs/_tasklist.html.erb b/app/views/sales_logs/_tasklist.html.erb
deleted file mode 100644
index e635d8241..000000000
--- a/app/views/sales_logs/_tasklist.html.erb
+++ /dev/null
@@ -1,25 +0,0 @@
-
<%= section.description.html_safe %>
- <% end %> -<%= get_subsections_count(@sales_log, :completed) %> of <%= get_subsections_count(@sales_log, :all) %> sections completed.
-- <% next_incomplete_section = get_next_incomplete_section(@sales_log) %> -
-- <% if next_incomplete_section.present? %> - - Skip to next incomplete section: <%= next_incomplete_section.label %> - - <% end %> -
- <% elsif @sales_log.status == "not_started" %> -This log has not been started.
- <% elsif @sales_log.status == "completed" %> -- <%= status_tag(@sales_log.status) %> -
-- You can <%= govuk_link_to "review and make changes to this log", "/logs/#{@sales_log.id}/review" %> until 2nd June <%= @sales_log.collection_start_year.present? ? @sales_log.collection_start_year + 1 : "" %>. -
- <% end %> - <%= render "tasklist" %> -