Skip to content

Commit

Permalink
TBE-28 Allow transitioning intakes to all possible states when not in…
Browse files Browse the repository at this point in the history
… production (#4636)

Easier Notifications!
  • Loading branch information
tofarr authored Jul 24, 2024
1 parent 8e17189 commit e2bf157
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 70 deletions.
25 changes: 25 additions & 0 deletions app/controllers/hub/state_file/efile_submissions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
109 changes: 50 additions & 59 deletions app/views/hub/state_file/efile_submissions/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -30,74 +30,65 @@
<span class="label-value"><%= @efile_submissions_same_intake.map{ |submission| link_to(submission.id, hub_state_file_efile_submission_path(id: submission.id))}.join(', ').html_safe %></span>
</div>
<% end %>

<div style="display: flex;">
<% 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" %>
<div style="margin-left: 10px;">
<%= 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" %>
</div>
<div style="margin-left: 10px;">
<%= link_to "Download PDF", hub_state_file_efile_submission_show_pdf_path(efile_submission_id: @efile_submission.id), class: "button button--small" %>
</div>

<% if @efile_submission.can_transition_to?(:failed) %>
<div style="margin-left: 10px">
<%= 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") %>
</div>
<% end %>
<% end %>
<% if @efile_submission.can_transition_to?(:resubmitted) %>
<div style="margin-left: 10px;">
<%= button_to("Resubmit",
resubmit_hub_efile_submission_path(id: @efile_submission.id),
<% unless acts_like_production? %>
<div class="spacing-below-15" style="display: flex; gap: 10px;">
<%= 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" %>
</div>
<div class="transition-to">
<h4 class="spacing-below-10">Transition to State</h4>
<div class="spacing-below-15" style="display: flex; gap: 10px;">
<% @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 %>
</div>
</div>
</div>
<% else %>
<div style="display:flex; gap:10px;">
<% 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) %>
<div style="margin-left: 10px;">
<%= 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")
%>
</div>
<%= 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) %>
<div style="margin-left: 10px">
<%= 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") %>
</div>
<%= 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? %>
<div style="margin-left: 10px">
<%= 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") %>
</div>
<% 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 %>
</div>
<div class="log-wrapper">
<h4 class="spacing-below-10">Status Logs</h4>
<ul role="list" class="logs">
<%= render("log", transitions: @efile_submission.efile_submission_transitions) %>
</ul>
</div>
<% end %>
<div class="log-wrapper padding-20">
<h4 class="spacing-below-10">Status Logs</h4>
<ul role="list" class="logs">
<%= render("log", transitions: @efile_submission.efile_submission_transitions) %>
</ul>
</div>
<% end %>
12 changes: 1 addition & 11 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit e2bf157

Please sign in to comment.