From e2bf157740b1f2dabea7f8b9a9c6e664e07fd162 Mon Sep 17 00:00:00 2001 From: tofarr Date: Wed, 24 Jul 2024 10:47:24 -0600 Subject: [PATCH] TBE-28 Allow transitioning intakes to all possible states when not in production (#4636) Easier Notifications! --- .../efile_submissions_controller.rb | 25 ++++ .../efile_submissions/show.html.erb | 109 ++++++++---------- config/routes.rb | 12 +- 3 files changed, 76 insertions(+), 70 deletions(-) diff --git a/app/controllers/hub/state_file/efile_submissions_controller.rb b/app/controllers/hub/state_file/efile_submissions_controller.rb index c4ab8f2ab6..c3df545dc5 100644 --- a/app/controllers/hub/state_file/efile_submissions_controller.rb +++ b/app/controllers/hub/state_file/efile_submissions_controller.rb @@ -29,6 +29,10 @@ def index def show @efile_submissions_same_intake = EfileSubmission.where(data_source: @efile_submission.data_source).where.not(id: @efile_submission.id) authorize! :read, @efile_submissions_same_intake + @valid_transitions = EfileSubmissionStateMachine.states.filter do |state| + next if %w[failed rejected].include?(state) && acts_like_production? + @efile_submission.can_transition_to?(state) + end end def show_xml @@ -59,6 +63,27 @@ def state_counts respond_to :js end + def transition_to + to_state = params[:to_state] + if %w[failed rejected].include?(to_state) && acts_like_production? + flash[:error] = "Transition to #{to_state} failed" + redirect_to hub_state_file_efile_submission_path(id: @efile_submission.id) + return + end + + authorize! :update, @efile_submission + metadata = { initiated_by_id: current_user.id } + if to_state == "rejected" + metadata[:error_code] = EfileError.where(service_type: :state_file).last.code + end + if @efile_submission.transition_to!(to_state, metadata) + flash[:notice] = "Transitioned to #{to_state}" + else + flash[:error] = "Transition to #{to_state} failed" + end + redirect_to hub_state_file_efile_submission_path(id: @efile_submission.id) + end + private def error_redirect diff --git a/app/views/hub/state_file/efile_submissions/show.html.erb b/app/views/hub/state_file/efile_submissions/show.html.erb index eb6ff4ddfa..7f9b43ce55 100644 --- a/app/views/hub/state_file/efile_submissions/show.html.erb +++ b/app/views/hub/state_file/efile_submissions/show.html.erb @@ -30,74 +30,65 @@ <%= @efile_submissions_same_intake.map{ |submission| link_to(submission.id, hub_state_file_efile_submission_path(id: submission.id))}.join(', ').html_safe %> <% end %> - -
- <% unless acts_like_production? %> - <%= link_to "Show XML", hub_state_file_efile_submission_show_xml_path(efile_submission_id: @efile_submission.id), class: "button button--small" %> -
- <%= link_to "Show direct-file XML", hub_state_file_efile_submission_show_df_xml_path(efile_submission_id: @efile_submission.id), class: "button button--small" %> -
-
- <%= link_to "Download PDF", hub_state_file_efile_submission_show_pdf_path(efile_submission_id: @efile_submission.id), class: "button button--small" %> -
- - <% if @efile_submission.can_transition_to?(:failed) %> -
- <%= link_to("Failed", - failed_hub_efile_submission_path(id: @efile_submission.id), - method: :patch, - data: { confirm: "Are you sure you want to mark this tax return submission as 'Failed'?" }, - class: "button button--danger button--small") %> -
- <% end %> - <% end %> - <% if @efile_submission.can_transition_to?(:resubmitted) %> -
- <%= button_to("Resubmit", - resubmit_hub_efile_submission_path(id: @efile_submission.id), + <% unless acts_like_production? %> +
+ <%= link_to "Show XML", hub_state_file_efile_submission_show_xml_path(efile_submission_id: @efile_submission.id), class: "button button--small", style: "margin:0" %> + <%= link_to "Show direct-file XML", hub_state_file_efile_submission_show_df_xml_path(efile_submission_id: @efile_submission.id), class: "button button--small", style: "margin:0" %> + <%= link_to "Download PDF", hub_state_file_efile_submission_show_pdf_path(efile_submission_id: @efile_submission.id), class: "button button--small", style: "margin:0" %> +
+
+

Transition to State

+
+ <% @valid_transitions.each do |state| %> + <%= link_to(state.titleize, + transition_to_hub_state_file_efile_submission_path(id: @efile_submission.id, to_state: state), method: :patch, - # disabled: @efile_submission.intake.refund_payment_method_direct_deposit? && !@efile_submission.intake.bank_account.present?, - data: { confirm: "Have you updated the necessary information?" }, - class: "button button--small button--teal button--no-margin") - %> + data: { confirm: "Are you sure you want to mark this tax return submission as '#{state.titleize}'?" }, + class: "button button--#{state.titleize} button--small", + style: "margin: 0") %> + <% end %>
+
+
+ <% else %> +
+ <% if @efile_submission.can_transition_to?(:resubmitted) %> + <%= button_to("Resubmit", + transition_to_hub_state_file_efile_submission_path(id: @efile_submission.id, to_state: :resubmitted), + method: :patch, + data: { confirm: "Have you updated the necessary information?" }, + class: "button button--small button--teal button--no-margin") + %> <% end %> <% if @efile_submission.in_state?(:rejected) || @efile_submission.in_state?(:waiting) %> -
- <%= button_to("Notify of Rejection", - notify_of_rejection_hub_efile_submission_path(id: @efile_submission.id), - method: :patch, - data: { confirm: "Are you sure you want to notify the filer?" }, - class: "button button--small button--teal button--no-margin") - %> -
+ <%= button_to("Notify of Rejection", + transition_to_hub_state_file_efile_submission_path(id: @efile_submission.id, to_state: :notified_of_rejection), + method: :patch, + data: { confirm: "Are you sure you want to notify the filer?" }, + class: "button button--small button--teal button--no-margin") + %> <% end %> - <% if @efile_submission.can_transition_to?(:cancelled) %> -
- <%= link_to("Do not file", - cancel_hub_efile_submission_path(id: @efile_submission.id), - method: :patch, - data: { confirm: "Are you sure you want to mark this tax return submission as 'Not filing'?" }, - class: "button button--danger button--small") %> -
+ <%= link_to("Do not file", + transition_to_hub_state_file_efile_submission_path(id: @efile_submission.id, to_state: :cancelled), + method: :patch, + data: { confirm: "Are you sure you want to mark this tax return submission as 'Not filing'?" }, + class: "button button--danger button--small") %> <% end %> - <% if @efile_submission.can_transition_to?(:rejected) && !Rails.env.production? %> -
- <%= link_to("Rejected", - reject_hub_efile_submission_path(id: @efile_submission.id), - method: :patch, - data: { confirm: "Are you sure you want to mark this tax return submission as 'Rejected'?" }, - class: "button button--danger button--small") %> -
+ <% if @efile_submission.can_transition_to?(:rejected) && !acts_like_production? %> + <%= link_to("Rejected", + transition_to_hub_state_file_efile_submission_path(id: @efile_submission.id, to_state: :rejected), + method: :patch, + data: { confirm: "Are you sure you want to mark this tax return submission as 'Rejected'?" }, + class: "button button--danger button--small") %> <% end %>
-
-

Status Logs

-
    - <%= render("log", transitions: @efile_submission.efile_submission_transitions) %> -
-
+ <% end %> +
+

Status Logs

+
    + <%= render("log", transitions: @efile_submission.efile_submission_transitions) %> +
<% end %> diff --git a/config/routes.rb b/config/routes.rb index 748988fbcb..254be41c58 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -211,17 +211,6 @@ def scoped_navigation_routes(context, navigation) end resources :intentional_log, only: [:index] resources :tax_returns, only: [:edit, :update, :show] - resources :efile_submissions, path: "efile", only: [:index, :show] do - patch '/resubmit', to: 'efile_submissions#resubmit', on: :member, as: :resubmit - patch '/failed', to: 'efile_submissions#failed', on: :member, as: :failed - patch '/reject', to: 'efile_submissions#reject', on: :member, as: :reject - patch '/cancel', to: 'efile_submissions#cancel', on: :member, as: :cancel - patch '/investigate', to: 'efile_submissions#investigate', on: :member, as: :investigate - patch '/notify_of_rejection', to: 'efile_submissions#notify_of_rejection', on: :member, as: :notify_of_rejection - patch '/wait', to: 'efile_submissions#wait', on: :member, as: :wait - get '/download', to: 'efile_submissions#download', on: :member, as: :download - get '/state-counts', to: 'efile_submissions#state_counts', on: :collection, as: :state_counts - end resources :fraud_indicators, path: "fraud-indicators" do collection do @@ -251,6 +240,7 @@ def scoped_navigation_routes(context, navigation) get "show_df_xml", to: "efile_submissions#show_df_xml" get "show_pdf", to: "efile_submissions#show_pdf" get "/state-counts", to: 'efile_submissions#state_counts', on: :collection, as: :state_counts + patch '/transition-to/:to_state', to: 'efile_submissions#transition_to', on: :member, as: :transition_to end resources :efile_errors, path: "errors", except: [:create, :new, :destroy] do