Commit 5eaf3182 authored by Chrysanthi Lagodimou's avatar Chrysanthi Lagodimou
Browse files

Billing Expenses Basis

parent 21e3585a
class BillingExpensesController < ApplicationController
include MakeNotice
before_action :set_billing_expense, only: [:show, :edit, :update, :destroy]
before_action :set_volunteer
def index
billing_expense = BillingExpense.new(volunteer: @volunteer)
authorize billing_expense
@billing_expenses = BillingExpense.where(volunteer: @volunteer)
end
def show; end
def new
@billing_expense = BillingExpense.new(volunteer: @volunteer)
@assignments = Assignment.where(volunteer: params[:volunteer_id])
authorize @billing_expense
end
def edit; end
def create
@billing_expense = BillingExpense.new(billing_expense_params)
authorize @billing_expense
if @billing_expense.save!
redirect_to @volunteer, make_notice
else
render :new
end
end
def update
if @billing_expense.update!(billing_expense_params)
redirect_to @volunteer, make_notice
else
render :edit
end
end
def destroy
@billing_expense.destroy
redirect_to @volunteer, make_notice
end
private
def set_billing_expense
@billing_expense = BillingExpense.find(params[:id])
authorize @billing_expense
end
def set_volunteer
@volunteer = Volunteer.find(params[:volunteer_id]) if params[:volunteer_id]
end
def billing_expense_params
params.require(:billing_expense).permit(:amount, :assignment_id, :volunteer_id)
end
end
......@@ -10,6 +10,7 @@ class Assignment < ApplicationRecord
belongs_to :creator, class_name: 'User', foreign_key: 'creator_id'
has_many :hours
has_many :assignment_journals
has_many :billing_expenses
STATES = [:suggested, :active, :finished, :archived].freeze
......
class BillingExpense < ApplicationRecord
belongs_to :volunteer
belongs_to :assignment
default_scope { order(created_at: :desc) }
AMOUNT = [50, 100, 150].freeze
validates :amount, inclusion: { in: AMOUNT }
def self.amount_collection
AMOUNT.map(&:to_s)
end
end
......@@ -41,6 +41,7 @@ class Volunteer < ApplicationRecord
has_many :clients, through: :assignments
has_many :hours, through: :assignments
has_many :assignment_journals, through: :assignments
has_many :billing_expenses
has_attached_file :avatar, styles: { thumb: '100x100#' }
......
class BillingExpensePolicy < ApplicationPolicy
alias_method :index?, :superadmin_or_volunteer_related?
alias_method :show?, :superadmin_or_volunteer_related?
alias_method :new?, :superadmin_or_volunteer_related?
alias_method :edit?, :superadmin_or_volunteer_related?
alias_method :create?, :superadmin_or_volunteer_related?
alias_method :update?, :superadmin_or_volunteer_related?
alias_method :destroy?, :superadmin_or_volunteer_related?
end
= simple_form_for [@volunteer, @billing_expense] do |f|
= simple_error_notice f
.row
.col-xs-12
- if action_name == 'new'
= f.association :assignment, collection: @assignments, label_method: :client, value_method: :id
- else
= f.hidden_field :assignment_id, value: @billing_expense.assignment.id
.row
.col-xs-12
= f.hidden_field :volunteer_id, value: params[:volunteer_id]
.row
.col-xs-12
= f.input :amount, collection: BillingExpense.amount_collection
.row
.col-xs-12
= f.button :submit
.row
.col-xs-12
h1= t_title(:edit)
= render 'form'
.row
.col-xs-12
= button_link t('back'), @volunteer
h1= @volunteer.contact.full_name
h1= t_title(:index, BillingExpense)
.table-responsive
table.table
thead
tr
th= t_model(Volunteer)
th= t_model(Client)
th= t_attr(:amount, BillingExpense)
th= t_attr(:created_at)
th colspan=3
tbody
- @volunteer.billing_expenses.each do |record|
tr
td= @volunteer.contact.full_name
td= record.assignment.client.contact.full_name
td= record.amount
td= l(record.created_at.to_date)
td= link_to t_action(:show), volunteer_billing_expense_path(@volunteer, record)
td= link_to t_action(:edit), edit_volunteer_billing_expense_path(@volunteer, record)
td= link_to t_action(:destroy), volunteer_billing_expense_path(@volunteer, record), confirm_deleting(record)
.row
.col-xs-12
= form_navigation_btn :new
.row
.col-xs-12
= button_link t('back'), @volunteer
.row
.col-xs-12
h1= t_title(:new)
= render 'form'
.row
.col-xs-12
= button_link t('back'), @volunteer
.row
.col-xs-12
.table-responsive
table.table.table-no-border-top
tbody
tr
td= t_model(Volunteer)
td= @billing_expense.volunteer.contact.full_name
tr
td= t_attr(:amount)
td= @billing_expense.amount
tr
td= t_attr(:created_at)
td= l(@billing_expense.created_at.to_date)
.row
.col-xs-12
= button_link t_title(:edit, BillingExpense), params.to_unsafe_h.merge({action: 'edit'})
......@@ -8,13 +8,19 @@
= render 'journals/journal_block', journaled_for: @volunteer
.row
- if policy(Volunteer).seeking_clients? & @volunteer.seeking_clients?
.col-xs-12.col-md-4
.col-xs-12
= button_link t_title(:new, Assignment), new_assignment_path(volunteer_id: @volunteer)
.row
- if @volunteer.assignments.any?
.col-xs-12.col-md-4
.col-xs-12.col-md-3
= button_link t_title(:index, Hour), volunteer_hours_path(@volunteer)
.col-xs-12.col-md-4
.col-xs-12.col-md-3
= button_link t_title(:new, Hour), new_volunteer_hour_url(@volunteer)
.col-xs-12.col-md-3
= button_link t_title(:new, BillingExpense), new_volunteer_billing_expense_path(@volunteer)
.col-xs-12.col-md-3
= button_link t_title(:index, BillingExpense), volunteer_billing_expenses_path(@volunteer)
- if policy(Volunteer).checklist?
h3= t('checklist')
......
......@@ -61,6 +61,10 @@ de:
conversation: Ich wünsche ein Gespräch mit meiner/meinem Freiwilligenverantwortlichen.
future: Soll der Einsatz weiterlaufen und wenn ja, mit welchen Inhalten (Zielen)?
goals: Was waren die wichtigsten Inhalte (oder Ziele) Ihres Einsatzes in den letzten Monaten?
billing_expense:
<<: *id-generic_keys
amount: Betrag
assignment: Begleitung
client:
<<: *id-generic_keys
actual_activities: Aktuelle Tätigkeiten
......@@ -233,6 +237,7 @@ de:
models:
assignment: Begleitung
assignment_journal: Inhaltliches Journal
billing_expense: Spesenformular
client: Klient/in
contact: Kontakt
department: Standort
......@@ -339,6 +344,7 @@ de:
- :year
delete_assignment: Begleitung wirklich löschen?
delete_assignment_journal: Inhaltliches Journal wirklich löschen?
delete_billing_expense: Spesenformular wirklich löschen?
delete_hour: Stundeneintrag wirklich löschen?
delete_journal: Journaleintrag wirklich löschen?
department_confirm_destroy: Sind Sie sicher dass Sie den Standort löschen wollen?
......
......@@ -84,6 +84,7 @@ en:
models:
assignment: Assignment
assignment_journal: Assignment journal
billing_expense: Billing expense
client: Client
contact: Contact
department: Department
......@@ -193,6 +194,7 @@ en:
- :year
delete_assignment: Really delete assignment?
delete_assignment_journal: Really delete assignment journal?
delete_billing_expense: Really delete billing expense?
delete_hour: Really delete hour?
delete_journal: Really delete journal?
departments: Departments
......
......@@ -21,6 +21,7 @@ Rails.application.routes.draw do
get :find_client, on: :member, to: 'assignments#find_client'
resources :journals
resources :hours
resources :billing_expenses
end
resources :volunteer_emails
resources :profiles, except: [:destroy, :index]
......
class CreateBillingExpenses < ActiveRecord::Migration[5.1]
def change
create_table :billing_expenses do |t|
t.integer :amount
t.belongs_to :volunteer
t.belongs_to :assignment
t.datetime :deleted_at, index: true
t.timestamps
end
end
end
......@@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20170825144136) do
ActiveRecord::Schema.define(version: 20170831105352) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
......@@ -57,6 +57,18 @@ ActiveRecord::Schema.define(version: 20170825144136) do
t.index ["volunteer_id"], name: "index_assignments_on_volunteer_id"
end
create_table "billing_expenses", force: :cascade do |t|
t.integer "amount"
t.bigint "volunteer_id"
t.bigint "assignment_id"
t.datetime "deleted_at"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["assignment_id"], name: "index_billing_expenses_on_assignment_id"
t.index ["deleted_at"], name: "index_billing_expenses_on_deleted_at"
t.index ["volunteer_id"], name: "index_billing_expenses_on_volunteer_id"
end
create_table "clients", force: :cascade do |t|
t.date "birth_year"
t.string "nationality"
......
FactoryGirl.define do
factory :billing_expense do
amount 1
end
end
Markdown is supported
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