Class: SalariesController

Inherits:
InvoicesController
  • Object
show all
Defined in:
app/controllers/salaries_controller.rb

Instance Method Summary collapse

Instance Method Details

#newObject



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'app/controllers/salaries_controller.rb', line 30

def new
  @salary = Salary.new(params[:salary])
  @salary.state = 'booked'

  unless @salary.employee
    # Trigger validation to flag bad values in select form
    @salary.valid?

    render :action => 'select_employee' and return
  end

  # Deduced defaults
  @salary.employer_id = current_tenant.company.id
  month_name          = t('date.month_names')[@salary.duration_from.month]
  @salary.title       = "Lohn #{month_name} #{@salary.duration_from.year} - #{@salary.employee.vcard.full_name}"
  @salary.duration_to = @salary.duration_from.end_of_month

  # Prebuild line items
  @salary.build_line_items

  # Prebuild an empty attachment instance
  @salary.attachments.build

  new!
end

#payslipObject



56
57
58
59
60
# File 'app/controllers/salaries_controller.rb', line 56

def payslip
  show! do |format|
    format.html { redirect_to :action => :show }
  end
end

#select_employeeObject



18
19
20
21
22
23
24
25
26
27
28
# File 'app/controllers/salaries_controller.rb', line 18

def select_employee
  # Allow pre-seeding some parameters
  salary_params = {
    :duration_from  => Date.today.beginning_of_month
  }

  # Set default parameters
  salary_params.merge!(params[:salary]) if params[:salary]

  @salary = Salary.new(salary_params)
end

#statisticsObject

Actions



14
15
16
# File 'app/controllers/salaries_controller.rb', line 14

def statistics
  index!
end