|
|
@ -1,13 +1,12 @@ |
|
|
|
class OrganisationsController < ApplicationController |
|
|
|
class OrganisationsController < ApplicationController |
|
|
|
include Pagy::Backend |
|
|
|
include Pagy::Backend |
|
|
|
include Modules::LogsFilter |
|
|
|
|
|
|
|
include Modules::SearchFilter |
|
|
|
include Modules::SearchFilter |
|
|
|
|
|
|
|
|
|
|
|
before_action :authenticate_user! |
|
|
|
before_action :authenticate_user! |
|
|
|
before_action :find_resource, except: %i[index new create] |
|
|
|
before_action :find_resource, except: %i[index new create] |
|
|
|
before_action :authenticate_scope!, except: [:index] |
|
|
|
before_action :authenticate_scope!, except: [:index] |
|
|
|
before_action -> { session_filters(specific_org: true) }, if: -> { current_user.support? || current_user.organisation.has_managing_agents? }, only: %i[lettings_logs sales_logs email_lettings_csv download_lettings_csv email_sales_csv download_sales_csv] |
|
|
|
before_action :session_filters, if: -> { current_user.support? || current_user.organisation.has_managing_agents? }, only: %i[lettings_logs sales_logs email_lettings_csv download_lettings_csv email_sales_csv download_sales_csv] |
|
|
|
before_action :set_session_filters, if: -> { current_user.support? || current_user.organisation.has_managing_agents? }, only: %i[lettings_logs sales_logs email_lettings_csv download_lettings_csv email_sales_csv download_sales_csv] |
|
|
|
before_action -> { filter_manager.serialize_filters_to_session }, if: -> { current_user.support? || current_user.organisation.has_managing_agents? }, only: %i[lettings_logs sales_logs email_lettings_csv download_lettings_csv email_sales_csv download_sales_csv] |
|
|
|
|
|
|
|
|
|
|
|
def index |
|
|
|
def index |
|
|
|
redirect_to organisation_path(current_user.organisation) unless current_user.support? |
|
|
|
redirect_to organisation_path(current_user.organisation) unless current_user.support? |
|
|
@ -91,7 +90,7 @@ class OrganisationsController < ApplicationController |
|
|
|
|
|
|
|
|
|
|
|
def lettings_logs |
|
|
|
def lettings_logs |
|
|
|
organisation_logs = LettingsLog.visible.where(owning_organisation_id: @organisation.id) |
|
|
|
organisation_logs = LettingsLog.visible.where(owning_organisation_id: @organisation.id) |
|
|
|
unpaginated_filtered_logs = filtered_logs(organisation_logs, search_term, @session_filters) |
|
|
|
unpaginated_filtered_logs = filter_manager.filtered_logs(organisation_logs, search_term, session_filters) |
|
|
|
|
|
|
|
|
|
|
|
respond_to do |format| |
|
|
|
respond_to do |format| |
|
|
|
format.html do |
|
|
|
format.html do |
|
|
@ -100,6 +99,7 @@ class OrganisationsController < ApplicationController |
|
|
|
@searched = search_term.presence |
|
|
|
@searched = search_term.presence |
|
|
|
@total_count = organisation_logs.size |
|
|
|
@total_count = organisation_logs.size |
|
|
|
@log_type = :lettings |
|
|
|
@log_type = :lettings |
|
|
|
|
|
|
|
@filter_type = "lettings_logs" |
|
|
|
render "logs", layout: "application" |
|
|
|
render "logs", layout: "application" |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
@ -107,20 +107,20 @@ class OrganisationsController < ApplicationController |
|
|
|
|
|
|
|
|
|
|
|
def download_lettings_csv |
|
|
|
def download_lettings_csv |
|
|
|
organisation_logs = LettingsLog.visible.where(owning_organisation_id: @organisation.id) |
|
|
|
organisation_logs = LettingsLog.visible.where(owning_organisation_id: @organisation.id) |
|
|
|
unpaginated_filtered_logs = filtered_logs(organisation_logs, search_term, @session_filters) |
|
|
|
unpaginated_filtered_logs = filter_manager.filtered_logs(organisation_logs, search_term, session_filters) |
|
|
|
codes_only = params.require(:codes_only) == "true" |
|
|
|
codes_only = params.require(:codes_only) == "true" |
|
|
|
|
|
|
|
|
|
|
|
render "logs/download_csv", locals: { search_term:, count: unpaginated_filtered_logs.size, post_path: lettings_logs_email_csv_organisation_path, codes_only: } |
|
|
|
render "logs/download_csv", locals: { search_term:, count: unpaginated_filtered_logs.size, post_path: lettings_logs_email_csv_organisation_path, codes_only: } |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
def email_lettings_csv |
|
|
|
def email_lettings_csv |
|
|
|
EmailCsvJob.perform_later(current_user, search_term, @session_filters, false, @organisation, codes_only_export?) |
|
|
|
EmailCsvJob.perform_later(current_user, search_term, session_filters, false, @organisation, codes_only_export?) |
|
|
|
redirect_to lettings_logs_csv_confirmation_organisation_path |
|
|
|
redirect_to lettings_logs_csv_confirmation_organisation_path |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
def sales_logs |
|
|
|
def sales_logs |
|
|
|
organisation_logs = SalesLog.where(owning_organisation_id: @organisation.id) |
|
|
|
organisation_logs = SalesLog.where(owning_organisation_id: @organisation.id) |
|
|
|
unpaginated_filtered_logs = filtered_logs(organisation_logs, search_term, @session_filters) |
|
|
|
unpaginated_filtered_logs = filter_manager.filtered_logs(organisation_logs, search_term, session_filters) |
|
|
|
|
|
|
|
|
|
|
|
respond_to do |format| |
|
|
|
respond_to do |format| |
|
|
|
format.html do |
|
|
|
format.html do |
|
|
@ -129,6 +129,7 @@ class OrganisationsController < ApplicationController |
|
|
|
@searched = search_term.presence |
|
|
|
@searched = search_term.presence |
|
|
|
@total_count = organisation_logs.size |
|
|
|
@total_count = organisation_logs.size |
|
|
|
@log_type = :sales |
|
|
|
@log_type = :sales |
|
|
|
|
|
|
|
@filter_type = "sales_logs" |
|
|
|
render "logs", layout: "application" |
|
|
|
render "logs", layout: "application" |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
@ -140,14 +141,14 @@ class OrganisationsController < ApplicationController |
|
|
|
|
|
|
|
|
|
|
|
def download_sales_csv |
|
|
|
def download_sales_csv |
|
|
|
organisation_logs = SalesLog.visible.where(owning_organisation_id: @organisation.id) |
|
|
|
organisation_logs = SalesLog.visible.where(owning_organisation_id: @organisation.id) |
|
|
|
unpaginated_filtered_logs = filtered_logs(organisation_logs, search_term, @session_filters) |
|
|
|
unpaginated_filtered_logs = filter_manager.filtered_logs(organisation_logs, search_term, session_filters) |
|
|
|
codes_only = params.require(:codes_only) == "true" |
|
|
|
codes_only = params.require(:codes_only) == "true" |
|
|
|
|
|
|
|
|
|
|
|
render "logs/download_csv", locals: { search_term:, count: unpaginated_filtered_logs.size, post_path: sales_logs_email_csv_organisation_path, codes_only: } |
|
|
|
render "logs/download_csv", locals: { search_term:, count: unpaginated_filtered_logs.size, post_path: sales_logs_email_csv_organisation_path, codes_only: } |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
def email_sales_csv |
|
|
|
def email_sales_csv |
|
|
|
EmailCsvJob.perform_later(current_user, search_term, @session_filters, false, @organisation, codes_only_export?, "sales") |
|
|
|
EmailCsvJob.perform_later(current_user, search_term, session_filters, false, @organisation, codes_only_export?, "sales") |
|
|
|
redirect_to sales_logs_csv_confirmation_organisation_path |
|
|
|
redirect_to sales_logs_csv_confirmation_organisation_path |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
@ -189,6 +190,22 @@ class OrganisationsController < ApplicationController |
|
|
|
|
|
|
|
|
|
|
|
private |
|
|
|
private |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def filter_type |
|
|
|
|
|
|
|
if params[:action].include?("lettings") |
|
|
|
|
|
|
|
"lettings_logs" |
|
|
|
|
|
|
|
elsif params[:action].include?("sales") |
|
|
|
|
|
|
|
"sales_logs" |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def session_filters |
|
|
|
|
|
|
|
filter_manager.session_filters |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def filter_manager |
|
|
|
|
|
|
|
FilterManager.new(current_user:, session:, params:, filter_type:) |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
def org_params |
|
|
|
def org_params |
|
|
|
params.require(:organisation).permit(:name, :address_line1, :address_line2, :postcode, :phone, :holds_own_stock, :provider_type, :housing_registration_no) |
|
|
|
params.require(:organisation).permit(:name, :address_line1, :address_line2, :postcode, :phone, :holds_own_stock, :provider_type, :housing_registration_no) |
|
|
|
end |
|
|
|
end |
|
|
|