Skip to content

Commit

Permalink
Merge 5e84c9d into 1acfc8f
Browse files Browse the repository at this point in the history
  • Loading branch information
hellcp committed Feb 19, 2023
2 parents 1acfc8f + 5e84c9d commit ede52bb
Show file tree
Hide file tree
Showing 17 changed files with 148 additions and 144 deletions.
1 change: 0 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ gem 'date_validator'
gem 'devise'
gem 'devise_ichain_authenticatable', '>= 0.3.0'
gem 'git'
gem 'inherited_resources'
gem 'kaminari'
# Newer prawn lost the template support in Document
# Would be good to replace with something else
Expand Down
9 changes: 0 additions & 9 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -147,21 +147,13 @@ GEM
activesupport (>= 5.1)
haml (>= 4.0.6)
railties (>= 5.1)
has_scope (0.7.2)
actionpack (>= 4.1)
activesupport (>= 4.1)
hashery (2.1.2)
htmlentities (4.3.4)
i18n (1.12.0)
concurrent-ruby (~> 1.0)
image_processing (1.12.2)
mini_magick (>= 4.9.5, < 5)
ruby-vips (>= 2.0.17, < 3)
inherited_resources (1.11.0)
actionpack (>= 5.0, < 6.1)
has_scope (~> 0.6)
railties (>= 5.0, < 6.1)
responders (>= 2, < 4)
jaro_winkler (1.5.4)
jquery-rails (4.5.1)
rails-dom-testing (>= 1, < 3)
Expand Down Expand Up @@ -424,7 +416,6 @@ DEPENDENCIES
exception_notification
git
haml-rails
inherited_resources
jquery-rails
jquery-ui-rails
kaminari
Expand Down
19 changes: 6 additions & 13 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,12 @@ def authenticate_and_audit_user
# Can be overidden by individuals controllers. Some logic merged here, though,
# to avoid too much spreading
def set_breadcrumbs
# For user related controllers
if users_controller?
@breadcrumbs = [{ label: :breadcrumb_user }]
# For inherited_resources controllers (the respond_to alternative looks
# cleaner, but it's not working despite the method existing)
# elsif respond_to? :association_chain
elsif is_a? InheritedResources::Base
@breadcrumbs = [{ label: resource_class.model_name.human(count: 2),
url: collection_path }]
@breadcrumbs << { label: resource, url: resource_path } if %w[show edit update].include? action_name
else
@breadcrumbs = [{ label: '' }]
end
@breadcrumbs = if users_controller?
# For user related controllers
[{ label: :breadcrumb_user }]
else
[{ label: '' }]
end
end

def users_controller?
Expand Down
102 changes: 79 additions & 23 deletions app/controllers/reimbursements_controller.rb
Original file line number Diff line number Diff line change
@@ -1,25 +1,65 @@
# frozen_string_literal: true

class ReimbursementsController < InheritedResources::Base
respond_to :html, :js, :json, :pdf
load_and_authorize_resource :request, except: [:check_request]
load_and_authorize_resource :reimbursement, through: :request, singleton: true, except: %i[create check_request]
skip_load_and_authorize_resource only: :check_request
class ReimbursementsController < ApplicationController
authorize_resource :request, except: %i[index check_request]
authorize_resource :reimbursement, through: :request, singleton: true, except: %i[index create check_request]
skip_authorize_resource only: %i[index check_request]
skip_load_resource
helper_method :reimbursement_states_collection
prepend_before_action :set_reimbursement, only: %i[show edit update destroy]
prepend_before_action :set_request, except: %i[index check_request]

defaults singleton: true
belongs_to :request
def index
@q ||= Reimbursement.accessible_by(current_ability).includes(request: :expenses).ransack(params[:q])
@q.sorts = 'id asc' if @q.sorts.empty?
@all_reimbursements ||= @q.result(distinct: true)
@index ||= @all_reimbursements.page(params[:page]).per(20)
end

def show; end

def new
@reimbursement = Reimbursement.new
end

def create
if parent.reimbursement.nil? || parent.reimbursement.new_record?
@reimbursement = Reimbursement.new
@reimbursement.request = parent
create! { edit_resource_path }
else
redirect_to edit_resource_path
redirect_to edit_reimbursement_path(@request.reimbursement) unless @request.reimbursement.nil? || @request.reimbursement.new_record?
@reimbursement = Reimbursement.new
@reimbursement.request = @request

respond_to do |format|
if @reimbursement.save
format.html { redirect_to edit_request_reimbursement_url(@request), notice: t(:reimbursement_create) }
format.json { render :show, status: :created, location: @reimbursement }
else
format.html { render :new, status: :unprocessable_entity }
format.json { render json: @reimbursement.errors, status: :unprocessable_entity }
end
end
end

def show; end
def edit; end

def update
respond_to do |format|
if @reimbursement.update(reimbursement_params)
format.html { redirect_to request_reimbursement_url(@request), notice: t(:reimbursement_update) }
format.json { render :show, status: :updated, location: @reimbursement }
else
format.html { render :new, status: :unprocessable_entity }
format.json { render json: @reimbursement.errors, status: :unprocessable_entity }
end
end
end

def destroy
@reimbursement.destroy

respond_to do |format|
format.html { redirect_to request_url(@request), notice: t(:reimbursement_destroyed) }
format.json { head :no_content }
end
end

def check_request
@reimbursement = Reimbursement.where(request_id: params[:request_id]).includes(user: :profile).first
Expand All @@ -40,19 +80,35 @@ def check_request
end
end

protected
private

def reimbursement_states_collection
Reimbursement.state_machines[:state].states.map { |s| [s.human_name, s.value] }
end

def set_breadcrumbs
@breadcrumbs = [label: parent, url: parent]
@breadcrumbs << { label: Reimbursement.model_name.human, url: resource_path } unless resource.blank? || resource.new_record?
@breadcrumbs = action_name == 'index' ? [label: Reimbursement.model_name.human] : [label: @request, url: @request]
@breadcrumbs << { label: Reimbursement.model_name.human, url: request_reimbursement_path(@request) } unless @reimbursement.blank? || @reimbursement.new_record?
end

def set_request
@request = Request.find(params[:request_id])

redirect_back(fallback_location: requests_url) unless @request
end

def set_reimbursement
@reimbursement = @request.reimbursement

redirect_back(fallback_location: reimbursements_url) unless @reimbursement
end

def permitted_params
def reimbursement_params
bank_account_attributes = %i[holder bank_name iban bic national_bank_code format national_account_code country_code bank_postal_address]
params.permit(reimbursement: [:description,
{ request_attributes: [{ expenses_attributes: %i[id total_amount authorized_amount] }] },
{ attachments_attributes: %i[id title file file_cache _destroy] },
{ links_attributes: %i[id title url _destroy] },
{ bank_account_attributes: bank_account_attributes }])
params.require(:reimbursement).permit(:description,
request_attributes: [expenses_attributes: %i[id total_amount authorized_amount]],
attachments_attributes: %i[id title file file_cache _destroy],
links_attributes: %i[id title url _destroy],
bank_account_attributes: bank_account_attributes)
end
end
26 changes: 0 additions & 26 deletions app/controllers/reimbursements_lists_controller.rb

This file was deleted.

4 changes: 2 additions & 2 deletions app/helpers/reimbursements_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ def reimbursement_acceptance_file(reimbursement)
end

links = []
links << link_to(t(:pdf_format), request_reimbursement_path(reimbursement.request, format: :pdf)) if can_read_pdf_for?(resource) && resource.editable?
links << link_to(t(:send_reimbursement_acceptance), new_request_reimbursement_acceptance_path(resource.request), remote: true) if can? :submit, reimbursement
links << link_to(t(:pdf_format), request_reimbursement_path(reimbursement.request, format: :pdf)) if can_read_pdf_for?(reimbursement) && reimbursement.editable?
links << link_to(t(:send_reimbursement_acceptance), new_request_reimbursement_acceptance_path(reimbursement.request), remote: true) if can? :submit, reimbursement

info = if can? :submit, reimbursement
t(:reimbursement_acceptance_intro).html_safe
Expand Down
5 changes: 0 additions & 5 deletions app/views/application/edit.html.haml

This file was deleted.

5 changes: 0 additions & 5 deletions app/views/application/new.html.haml

This file was deleted.

26 changes: 13 additions & 13 deletions app/views/reimbursements/edit.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@

%strong.label.labe.label-defaultl-defaul.label-defaultt= Reimbursement.human_attribute_name(:event)
%br
= render resource.event
= render @reimbursement.event

%strong.label.label-default= Reimbursement.human_attribute_name(:request)
%br
= render parent
= render @request

= simple_form_for(resource, :url => request_reimbursement_path(parent),html: { class: 'form-horizontal form-inputs' }, wrapper: :horizontal_form, :method => :put) do |f|
= simple_form_for(@reimbursement, :url => request_reimbursement_path(@request),html: { class: 'form-horizontal form-inputs' }, wrapper: :horizontal_form, :method => :put) do |f|
%strong.label.label-default= t(:general_info)
%br
.col-md-6
Expand Down Expand Up @@ -38,8 +38,8 @@

.form-inline.col-md-10
%strong.label.label-default= TravelSponsorship.human_attribute_name(:links)
- unless resource.errors[:links].empty?
.alert.alert-inline.alert-danger= resource.links.map {|e| e.errors.full_messages}.uniq.join("; ")
- unless @reimbursement.errors[:links].empty?
.alert.alert-inline.alert-danger= @reimbursement.links.map {|e| e.errors.full_messages}.uniq.join("; ")
%table.table.table-condensed
%thead
%tr
Expand All @@ -54,8 +54,8 @@

.form-inline.col-md-10
%strong.label.label-default= TravelSponsorship.human_attribute_name(:attachments)
- unless resource.errors[:attachments].empty?
.alert.alert-inline.alert-error= resource.attachments.map {|e| e.errors.full_messages}.uniq.join("; ")
- unless @reimbursement.errors[:attachments].empty?
.alert.alert-inline.alert-error= @reimbursement.attachments.map {|e| e.errors.full_messages}.uniq.join("; ")
%table.table.table-condensed
%thead
%tr
Expand All @@ -72,10 +72,10 @@
%strong.label.label-default= Reimbursement.human_attribute_name(:expenses)
.alert.alert-inline.alert-info
= t(:reimbursement_expenses_help)
- if manual_authorized_amount_is_needed_for? resource
- if manual_authorized_amount_is_needed_for? @reimbursement
= t(:reimbursement_manual_expenses_help)
- if !resource.errors[:"request.expenses"].empty?
.alert.alert-inline.alert-error= resource.expenses.map {|e| e.errors.full_messages}.uniq.join("; ")
- if !@reimbursement.errors[:"request.expenses"].empty?
.alert.alert-inline.alert-error= @reimbursement.expenses.map {|e| e.errors.full_messages}.uniq.join("; ")
%table.table.table-condensed
%thead#expenses_head
%tr
Expand All @@ -84,7 +84,7 @@
%th= RequestExpense.human_attribute_name(:estimated_amount)
%th= RequestExpense.human_attribute_name(:approved_amount)
%th= RequestExpense.human_attribute_name(:total_amount)
- if manual_authorized_amount_is_needed_for? resource
- if manual_authorized_amount_is_needed_for? @reimbursement
%th= RequestExpense.human_attribute_name(:authorized_amount)

%tbody#expenses
Expand All @@ -97,12 +97,12 @@
%td.estimated= number_to_currency(expense.estimated_amount, :unit => expense.estimated_currency)
%td.approved= number_to_currency(expense.approved_amount, :unit => expense.approved_currency)
%td.total= number_to_currency(e.text_field(:total_amount, :class => 'input-mini'), :unit => expense.total_currency)
- if manual_authorized_amount_is_needed_for? resource
- if manual_authorized_amount_is_needed_for? @reimbursement
- if expense.authorized_can_be_calculated?
%td.authorized= number_to_currency("XX", :unit => expense.authorized_currency)
- else
%td.authorized= number_to_currency(e.text_field(:authorized_amount, :class => 'input-mini'), :unit => expense.authorized_currency)

.well.col-md-12
= f.button :submit, :class => 'btn btn-primary'
= link_to t('.cancel', :default => t("helpers.links.cancel")), request_reimbursement_path(resource.request), :class => 'btn btn-default'
= link_to t('.cancel', :default => t("helpers.links.cancel")), request_reimbursement_path(@reimbursement.request), :class => 'btn btn-default'
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

%nav.navbar.navbar-default.nav-tsp
.container-fluid
- collection
- @index
= search_form_for @q, :class => "navbar-form pull-right" do |f|
- s_opts = {'non-selected-text' => t(:events_any), 'number-displayed' => 2, 'n-selected-text' => t(:events_n) }
= f.collection_select :request_event_id_in, Event.all, :id, :name, {}, :multiple => true, :data => s_opts
Expand All @@ -24,7 +24,7 @@
%th= model_class.human_attribute_name(:authorized_sum)
%th= sort_link(@q, :state, [:state, "state_updated_at desc"])
%tbody
- collection.each do |reimb|
- @index.each do |reimb|
%tr{:id => "request-#{reimb.id}"}
%td.id= link_to "#{reimb.label}", request_reimbursement_path(reimb.request)
%td.user= reimb.user.try(:title)
Expand All @@ -34,7 +34,7 @@
%td.authorized= expenses_sum(reimb, :authorized)
%td.state= timestamped_state(reimb)
%tfoot
- if @all_reimbursements.size > @collection.size
- if @all_reimbursements.size > @index.size
%tr
%td
%td
Expand All @@ -47,9 +47,9 @@
%td
%td
%th.text-right= t(:full_total)
%td= expenses_sum(@collection, :approved)
%td= expenses_sum(@collection, :total)
%td= expenses_sum(@collection, :authorized)
%td= expenses_sum(@index, :approved)
%td= expenses_sum(@index, :total)
%td= expenses_sum(@index, :authorized)
%td

= paginate collection
= paginate @index

0 comments on commit ede52bb

Please sign in to comment.