Commit 1229484f authored by Kaspar Vollenweider's avatar Kaspar Vollenweider 👻 Committed by Kaspar
Browse files

directly create billing expense from volunteer view

parent a4000dab
class BillingExpense < ApplicationRecord class BillingExpense < ApplicationRecord
include FullBankDetails include FullBankDetails
before_validation :compute_amount before_validation :auto_set_amount
belongs_to :volunteer belongs_to :volunteer
belongs_to :user, -> { with_deleted } belongs_to :user, -> { with_deleted }
has_many :hours has_many :hours
...@@ -25,6 +26,10 @@ class BillingExpense < ApplicationRecord ...@@ -25,6 +26,10 @@ class BillingExpense < ApplicationRecord
super(compute_amount) super(compute_amount)
end end
def auto_set_amount
self.amount = nil
end
def compute_amount def compute_amount
hour_count = id ? hours_sum : volunteer.billable_hours_sum hour_count = id ? hours_sum : volunteer.billable_hours_sum
if hour_count > 50 if hour_count > 50
......
...@@ -30,7 +30,9 @@ h1= t_title(:index, BillingExpense) ...@@ -30,7 +30,9 @@ h1= t_title(:index, BillingExpense)
td= link_to t_action(:destroy), volunteer_billing_expense_path(@volunteer, record), confirm_deleting(record) td= link_to t_action(:destroy), volunteer_billing_expense_path(@volunteer, record), confirm_deleting(record)
.row .row
.col-xs-12 .col-xs-12
= form_navigation_btn :new = simple_form_for [@volunteer, BillingExpense.new] do |f|
= f.hidden_field :volunteer_id, value: @volunteer.id
= f.button :submits
.row .row
.col-xs-12 .col-xs-12
= button_link t('back'), @volunteer = button_link t('back'), @volunteer
...@@ -10,8 +10,12 @@ nav.navbar.section-navigation ...@@ -10,8 +10,12 @@ nav.navbar.section-navigation
- if @volunteer.seeking_clients? - if @volunteer.seeking_clients?
li = button_link t_title(:new, Assignment), new_assignment_path(volunteer_id: @volunteer) li = button_link t_title(:new, Assignment), new_assignment_path(volunteer_id: @volunteer)
- if @volunteer.assignments.any? - if @volunteer.assignments.any?
li = button_link t_title(:new, BillingExpense), new_volunteer_billing_expense_path(@volunteer) li
li = button_link t_title(:index, BillingExpense), volunteer_billing_expenses_path(@volunteer) = simple_form_for [@volunteer, BillingExpense.new] do |f|
= f.hidden_field :volunteer_id, value: @volunteer.id
= f.button :submits
- if @volunteer.billing_expenses.any?
li = button_link t_title(:index, BillingExpense), volunteer_billing_expenses_path(@volunteer)
- if @volunteer.assignments? - if @volunteer.assignments?
li= button_link t('.new_certificate'), new_volunteer_certificate_path(@volunteer) li= button_link t('.new_certificate'), new_volunteer_certificate_path(@volunteer)
- if @volunteer.certificates.size == 1 - if @volunteer.certificates.size == 1
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment