Added Bank Information under Demographics for Participants, Workers and Vendors. Finished structing and laying out the Participant views. Still need to do the other models. Also Routing and Account numbers need verification set up.
This commit is contained in:
parent
54ac6a05a3
commit
47c981cd57
|
@ -0,0 +1,83 @@
|
|||
class BankAccountsController < ApplicationController
|
||||
before_action :set_owner
|
||||
before_action :set_bank_account, only: [:edit, :update, :destroy]
|
||||
|
||||
def new
|
||||
@bank_account = BankAccount.new
|
||||
end
|
||||
|
||||
def create
|
||||
@bank_account = @owner.bank_accounts.build(bank_account_params)
|
||||
if @bank_account.save
|
||||
redirect_to owner_path(@owner), notice: 'Bank account was successfully created.'
|
||||
else
|
||||
render :new
|
||||
end
|
||||
end
|
||||
|
||||
def index
|
||||
@bank_accounts = @owner.bank_accounts.order(start_date: :desc)
|
||||
end
|
||||
|
||||
def edit
|
||||
end
|
||||
|
||||
def update
|
||||
@bank_account = BankAccount.find(params[:id])
|
||||
if @bank_account.update(bank_account_params)
|
||||
redirect_to owner_path(@owner), notice: 'Bank account was successfully updated.'
|
||||
else
|
||||
render :edit
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
@bank_account.destroy
|
||||
redirect_to polymorphic_path([@owner]), notice: 'Bank account was successfully deleted.'
|
||||
end
|
||||
|
||||
|
||||
private
|
||||
|
||||
def set_owner
|
||||
@owner = if params[:participant_id]
|
||||
Participant.find(params[:participant_id])
|
||||
elsif params[:worker_id]
|
||||
Worker.find(params[:worker_id])
|
||||
elsif params[:vendor_id]
|
||||
Vendor.find(params[:vendor_id])
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def find_owner
|
||||
params.each do |name, value|
|
||||
if name =~ /(.+)_id$/
|
||||
return $1.classify.constantize.find(value)
|
||||
end
|
||||
end
|
||||
nil
|
||||
end
|
||||
|
||||
def set_bank_account
|
||||
@bank_account = BankAccount.find(params[:id])
|
||||
end
|
||||
|
||||
def bank_account_params
|
||||
params.require(:bank_account).permit(:institution_name, :account_type, :routing_number, :account_number, :start_date, :end_date)
|
||||
end
|
||||
|
||||
def owner_path(owner)
|
||||
case owner
|
||||
when Participant
|
||||
participant_path(owner)
|
||||
when Worker
|
||||
worker_path(owner)
|
||||
when Vendor
|
||||
vendor_path(owner)
|
||||
else
|
||||
root_path # Default path if owner type is unknown
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
module BankAccountsHelper
|
||||
def hide_account_number(account_number)
|
||||
# Example implementation that hides all but the last 4 digits
|
||||
"**** **** **** #{account_number.last(4)}"
|
||||
end
|
||||
end
|
||||
|
|
@ -3,4 +3,7 @@ import "@hotwired/turbo-rails"
|
|||
import "controllers"
|
||||
|
||||
import Rails from '@rails/ujs';
|
||||
Rails.start();
|
||||
Rails.start();
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
class BankAccount < ApplicationRecord
|
||||
belongs_to :owner, polymorphic: true
|
||||
end
|
|
@ -8,6 +8,7 @@ class Participant < ApplicationRecord
|
|||
has_many :employer_records
|
||||
has_many :employers, through: :employer_records
|
||||
has_and_belongs_to_many :programs
|
||||
has_many :bank_accounts, as: :owner
|
||||
|
||||
# Validations
|
||||
validates :first_name, :last_name, :ssn, presence: true
|
||||
|
|
|
@ -3,6 +3,7 @@ class Vendor < ApplicationRecord
|
|||
has_and_belongs_to_many :employers
|
||||
has_many :service_contracts
|
||||
has_many :participants, through: :service_contracts
|
||||
has_many :bank_accounts, as: :owner
|
||||
|
||||
# Validations
|
||||
validates :tin, uniqueness: true, allow_blank: true, presence: true
|
||||
|
|
|
@ -18,4 +18,7 @@ class Worker < ApplicationRecord
|
|||
def full_name
|
||||
"#{first_name} #{last_name}"
|
||||
end
|
||||
|
||||
has_many :bank_accounts, as: :owner
|
||||
|
||||
end
|
||||
|
|
|
@ -0,0 +1,59 @@
|
|||
<%= form_with(model: [@owner, @bank_account], local: true, html: { class: 'needs-validation', novalidate: true }) do |form| %>
|
||||
<% if @bank_account.errors.any? %>
|
||||
<div id="error_explanation" class="alert alert-danger">
|
||||
<h4><%= pluralize(@bank_account.errors.count, "error") %> prohibited this bank account from being saved:</h4>
|
||||
<ul>
|
||||
<% @bank_account.errors.full_messages.each do |message| %>
|
||||
<li><%= message %></li>
|
||||
<% end %>
|
||||
</ul>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<div class="mb-3">
|
||||
<%= form.label :institution_name, 'Institution Name', class: 'form-label' %>
|
||||
<%= form.text_field :institution_name, class: 'form-control', placeholder: 'Institution Name' %>
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<label class='form-label'>Account Type</label><br>
|
||||
<%= form.radio_button :account_type, 'Checking', class: 'form-check-input' %>
|
||||
<%= form.label :account_type_checking, 'Checking', class: 'form-check-label' %>
|
||||
<%= form.radio_button :account_type, 'Savings', class: 'form-check-input' %>
|
||||
<%= form.label :account_type_savings, 'Savings', class: 'form-check-label' %>
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<%= form.label :routing_number, 'Routing Number', class: 'form-label' %>
|
||||
<%= form.text_field :routing_number, class: 'form-control', placeholder: 'Routing Number' %>
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<%= form.label :routing_number_confirmation, 'Re-enter Routing Number', class: 'form-label' %>
|
||||
<%= form.text_field :routing_number_confirmation, class: 'form-control', placeholder: 'Re-enter Routing Number' %>
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<%= form.label :account_number, 'Account Number', class: 'form-label' %>
|
||||
<%= form.text_field :account_number, class: 'form-control', placeholder: 'Account Number' %>
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<%= form.label :account_number_confirmation, 'Re-enter Account Number', class: 'form-label' %>
|
||||
<%= form.text_field :account_number_confirmation, class: 'form-control', placeholder: 'Re-enter Account Number' %>
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<%= form.label :start_date, 'Start Date', class: 'form-label' %>
|
||||
<%= form.date_field :start_date, class: 'form-control' %>
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<%= form.label :end_date, 'End Date', class: 'form-label' %>
|
||||
<%= form.date_field :end_date, class: 'form-control' %>
|
||||
</div>
|
||||
|
||||
<div class="actions">
|
||||
<%= form.submit 'Submit', class: 'btn btn-dark' %>
|
||||
</div>
|
||||
<% end %>
|
|
@ -0,0 +1,2 @@
|
|||
<h1>BankAccounts#create</h1>
|
||||
<p>Find me in app/views/bank_accounts/create.html.erb</p>
|
|
@ -0,0 +1,13 @@
|
|||
<div class="container mt-5">
|
||||
<div class="row justify-content-center">
|
||||
<div class="col-md-6">
|
||||
<h1 class="mb-4 text-center">Edit Bank Account</h1>
|
||||
|
||||
<%= render 'form', owner: @owner, bank_account: @bank_account %>
|
||||
|
||||
<div class="mt-3 text-center">
|
||||
<%= link_to 'Back to Participant', polymorphic_path(@owner), class: "btn btn-secondary" %>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
|
@ -0,0 +1,44 @@
|
|||
<div class="container mt-5">
|
||||
<h1 class="mb-4 text-center">Bank Information</h1>
|
||||
<table class="table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Institution Name</th>
|
||||
<th>Type</th>
|
||||
<th>Routing Number</th>
|
||||
<th>Account Number</th>
|
||||
<th>Start Date</th>
|
||||
<th>End Date</th>
|
||||
<th>Actions</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<% @bank_accounts.each do |account| %>
|
||||
<tr>
|
||||
<td><%= account.institution_name %></td>
|
||||
<td><%= account.account_type.capitalize %></td>
|
||||
<td><%= account.routing_number %></td>
|
||||
<td><%= hide_account_number(account.account_number) %></td>
|
||||
<td><%= account.start_date.strftime('%B %d, %Y') if account.start_date %></td>
|
||||
<td><%= account.end_date.strftime('%B %d, %Y') if account.end_date %></td>
|
||||
<td>
|
||||
<%= link_to edit_polymorphic_path([@owner, account]), class: 'btn btn-info btn-sm' do %>
|
||||
<i class="bi bi-pencil-fill" style="color: white;"></i>
|
||||
<% end %>
|
||||
<%= link_to polymorphic_path([@owner, account]), method: :delete, data: { confirm: 'Are you sure?' }, class: 'btn btn-danger btn-sm' do %>
|
||||
<i class="bi bi-trash-fill"></i>
|
||||
<% end %>
|
||||
</td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<%= link_to 'Add New Bank Account', new_polymorphic_path([@owner, BankAccount.new]), class: 'btn btn-dark' %>
|
||||
</div>
|
||||
|
||||
<div class="text-center mt-3">
|
||||
<%= link_to 'Back', polymorphic_path(@owner), class: 'btn btn-secondary mt-3' %>
|
||||
</div>
|
||||
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
<div class="container mt-5">
|
||||
<div class="row justify-content-center">
|
||||
<div class="col-md-6">
|
||||
<h1 class="mb-4 text-center">New Bank Account</h1>
|
||||
|
||||
<%= render 'form', owner: @owner, bank_account: @bank_account %>
|
||||
|
||||
<div class="mt-3 text-center">
|
||||
<%= link_to 'Back to Participant', polymorphic_path(@owner), class: "btn btn-secondary" %>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
|
@ -0,0 +1,2 @@
|
|||
<h1>BankAccounts#update</h1>
|
||||
<p>Find me in app/views/bank_accounts/update.html.erb</p>
|
|
@ -1,3 +1,15 @@
|
|||
<div class="dropdown">
|
||||
<button class="btn btn-secondary dropdown-toggle" type="button" id="demographicsDropdown" data-bs-toggle="dropdown" aria-expanded="false">
|
||||
Demographics
|
||||
</button>
|
||||
<ul class="dropdown-menu" aria-labelledby="demographicsDropdown">
|
||||
<li><a class="dropdown-item" href="<%= participant_bank_accounts_path(@participant) %>">Bank Information</a></li>
|
||||
<!-- Add other demographic options here as needed -->
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
<div class="container mt-5">
|
||||
<div class="row">
|
||||
<div class="col-12">
|
||||
|
|
|
@ -10,10 +10,10 @@ Rails.application.routes.draw do
|
|||
end
|
||||
|
||||
resources :participants do
|
||||
resources :bank_accounts, only: [:index, :new, :create, :edit, :update, :destroy]
|
||||
collection do
|
||||
get 'search' # Define search on the collection, not on a member
|
||||
end
|
||||
|
||||
member do
|
||||
post 'link_worker' # Other member routes
|
||||
post 'link_vendor' #Add this line to link a vendor
|
||||
|
@ -22,6 +22,7 @@ Rails.application.routes.draw do
|
|||
|
||||
|
||||
resources :workers do
|
||||
resources :bank_accounts, only: [:index, :new, :create, :edit, :update, :destroy] # Added :index action
|
||||
member do
|
||||
post 'link_participant'
|
||||
post 'link_employer'
|
||||
|
@ -31,10 +32,12 @@ Rails.application.routes.draw do
|
|||
|
||||
|
||||
resources :vendors do
|
||||
resources :bank_accounts, only: [:index, :new, :create, :edit, :update, :destroy] # Added :index action
|
||||
collection do
|
||||
get 'search'
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
resources :employments, only: [:edit, :update, :destroy]
|
||||
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
class CreateBankAccounts < ActiveRecord::Migration[7.1]
|
||||
def change
|
||||
create_table :bank_accounts do |t|
|
||||
t.string :institution_name
|
||||
t.string :account_type
|
||||
t.string :routing_number
|
||||
t.string :account_number
|
||||
t.date :start_date
|
||||
t.date :end_date
|
||||
t.references :owner, polymorphic: true, null: false
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
end
|
||||
end
|
|
@ -10,7 +10,21 @@
|
|||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema[7.1].define(version: 2024_02_06_215805) do
|
||||
ActiveRecord::Schema[7.1].define(version: 2024_02_12_212110) do
|
||||
create_table "bank_accounts", force: :cascade do |t|
|
||||
t.string "institution_name"
|
||||
t.string "account_type"
|
||||
t.string "routing_number"
|
||||
t.string "account_number"
|
||||
t.date "start_date"
|
||||
t.date "end_date"
|
||||
t.string "owner_type", null: false
|
||||
t.integer "owner_id", null: false
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.index ["owner_type", "owner_id"], name: "index_bank_accounts_on_owner"
|
||||
end
|
||||
|
||||
create_table "employer_records", force: :cascade do |t|
|
||||
t.integer "participant_id", null: false
|
||||
t.integer "employer_id", null: false
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
require "test_helper"
|
||||
|
||||
class BankAccountsControllerTest < ActionDispatch::IntegrationTest
|
||||
test "should get new" do
|
||||
get bank_accounts_new_url
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
test "should get create" do
|
||||
get bank_accounts_create_url
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
test "should get edit" do
|
||||
get bank_accounts_edit_url
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
test "should get update" do
|
||||
get bank_accounts_update_url
|
||||
assert_response :success
|
||||
end
|
||||
end
|
|
@ -0,0 +1,21 @@
|
|||
# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
|
||||
|
||||
one:
|
||||
institution_name: MyString
|
||||
account_type: MyString
|
||||
routing_number: MyString
|
||||
account_number: MyString
|
||||
start_date: 2024-02-12
|
||||
end_date: 2024-02-12
|
||||
owner: one
|
||||
owner_type: Owner
|
||||
|
||||
two:
|
||||
institution_name: MyString
|
||||
account_type: MyString
|
||||
routing_number: MyString
|
||||
account_number: MyString
|
||||
start_date: 2024-02-12
|
||||
end_date: 2024-02-12
|
||||
owner: two
|
||||
owner_type: Owner
|
|
@ -0,0 +1,7 @@
|
|||
require "test_helper"
|
||||
|
||||
class BankAccountTest < ActiveSupport::TestCase
|
||||
# test "the truth" do
|
||||
# assert true
|
||||
# end
|
||||
end
|
Loading…
Reference in New Issue