bookyt_salary 0.8.0 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -8,4 +8,19 @@ class SalaryTemplatesController < AuthorizedController
8
8
 
9
9
  render 'edit'
10
10
  end
11
+
12
+ # has_many :salary_items
13
+ def new_salary_item
14
+ if salary_template_id = params[:id]
15
+ @salary_template = resource_class.find(salary_template_id)
16
+ else
17
+ @salary_template = resource_class.new
18
+ end
19
+
20
+ @salary_item = @salary_template.salary_items.build(
21
+ :times => 1
22
+ )
23
+
24
+ respond_with @salary_item
25
+ end
11
26
  end
data/app/models/salary.rb CHANGED
@@ -89,9 +89,15 @@ class Salary < Invoice
89
89
 
90
90
  # Line Items
91
91
  def build_line_items
92
- salary_template.salary_booking_templates.each do |booking_template|
92
+ salary_template.salary_items.each do |salary_item|
93
93
  line_item = line_items.build(:date => self.value_date)
94
- line_item.set_booking_template(booking_template)
94
+
95
+ # Defaults from booking_template
96
+ line_item.set_booking_template(salary_item.salary_booking_template)
97
+
98
+ # Overrides from salary_item
99
+ line_item.times = salary_item.times if salary_item.times.present?
100
+ line_item.price = salary_item.price if salary_item.price.present?
95
101
  end
96
102
  end
97
103
 
@@ -0,0 +1,4 @@
1
+ class SalaryItem < ActiveRecord::Base
2
+ belongs_to :salary_template
3
+ belongs_to :salary_booking_template
4
+ end
@@ -1,4 +1,7 @@
1
1
  class SalaryTemplate < ActiveRecord::Base
2
2
  belongs_to :person
3
- has_and_belongs_to_many :salary_booking_templates
3
+
4
+ # Salary Items
5
+ has_many :salary_items
6
+ accepts_nested_attributes_for :salary_items, :allow_destroy => true
4
7
  end
@@ -0,0 +1,7 @@
1
+ %tr.salary_item.nested-form-item
2
+ %td= salary_item.select :salary_booking_template_id, SalaryBookingTemplate.all.map{|template| [template.title, template.id]}, :required => true, :style => 'width: 30em'
3
+ %td= salary_item.text_field :times, :required => true, :style => 'width: 3em', :autocomplete => "off"
4
+ %td= salary_item.text_field :price, :required => true, :style => 'width: 5em', :autocomplete => "off"
5
+ %td.action_links
6
+ = salary_item.hidden_field :_destroy
7
+ = link_to t_action(:delete), '#', :class => 'icon-delete-text delete-nested-form-item'
@@ -0,0 +1,6 @@
1
+ %tr[line_item]
2
+ %td= line_item.date
3
+ %td= line_item.title
4
+ %td.currency= line_item.times_to_s
5
+ %td.currency= currency_fmt(line_item.price)
6
+ %td.currency= currency_fmt(line_item.total_amount)
@@ -0,0 +1,7 @@
1
+ = f.inputs t_title(:list, SalaryItem) do
2
+ %table#salary_items
3
+ %thead
4
+ = render 'salary_items/list_header'
5
+ %tbody
6
+ = f.fields_for :salary_items do |salary_item|
7
+ = render 'salary_items/form', :salary_item => salary_item
@@ -0,0 +1,6 @@
1
+ %tr
2
+ %th{:style => 'padding: 2px'}= t_attr(:salary_booking_template, SalaryItem)
3
+ %th{:style => 'padding: 2px; width: 3em'}= t_attr(:times, SalaryItem)
4
+ %th{:style => 'padding: 2px; width: 3em'}= t_attr(:price, SalaryItem)
5
+ %th
6
+ %th.action_links= link_to t_action(:more), [:new_salary_item, resource.persisted? ? resource : resource.class.name.underscore.pluralize.to_sym], :remote => true, :class => 'icon-add-text'
@@ -3,11 +3,11 @@
3
3
  = f.inputs do
4
4
  .row
5
5
  .span8= f.input :title, :input_html => {"data-autofocus" => true}
6
- .span8= f.input :person
7
- .row
8
- .span16= f.input :salary_booking_templates, :input_html => {:class => 'span12'}
6
+ .span8= f.input :person, :collection => Employee.all
9
7
  .row
10
8
  .span16= f.input :remarks, :input_html => {:rows => 2, :class => 'span12'}
11
9
 
10
+ = render 'salary_items/list_form', :f => f
11
+
12
12
  = f.buttons do
13
13
  = f.commit_button
@@ -0,0 +1,3 @@
1
+ = fields_for @salary_template do |salary_template|
2
+ = salary_template.fields_for :salary_items, @salary_item, :child_index => -(DateTime.now.to_i) do |salary_item|
3
+ = render 'salary_items/form', :salary_item => salary_item
@@ -0,0 +1,2 @@
1
+ $('#salary_items tbody').append('<%=j render 'salary_item_form' %>');
2
+ initializeBehaviours();
@@ -27,6 +27,10 @@ de:
27
27
  salary_booking_templates: Lohnarten
28
28
  title: Titel
29
29
  remarks: Bemerkungen
30
+ salary_item:
31
+ salary_booking_template: Lohnart
32
+ times: Anzahl
33
+ price: Betrag
30
34
 
31
35
  salaries:
32
36
  select_employee:
@@ -37,3 +41,6 @@ de:
37
41
  salary_templates:
38
42
  index:
39
43
  title: Lohnvorlagen
44
+ salary_items:
45
+ list:
46
+ title: Lohnarten
data/config/routes.rb CHANGED
@@ -6,7 +6,11 @@ Rails.application.routes.draw do
6
6
  end
7
7
  end
8
8
 
9
- resources :salary_templates
9
+ resources :salary_templates do
10
+ member do
11
+ get :new_salary_item
12
+ end
13
+ end
10
14
 
11
15
  resources :salaries do
12
16
  collection do
@@ -0,0 +1,15 @@
1
+ class CreateSalaryItems < ActiveRecord::Migration
2
+ def change
3
+ create_table :salary_items do |t|
4
+ t.integer :salary_booking_template_id
5
+ t.integer :salary_template_id
6
+ t.decimal :times, :precision => 10, :scale => 2
7
+ t.decimal :price, :precision => 10, :scale => 2
8
+
9
+ t.timestamps
10
+ end
11
+
12
+ add_index :salary_items, :salary_booking_template_id
13
+ add_index :salary_items, :salary_template_id
14
+ end
15
+ end
@@ -1,3 +1,3 @@
1
1
  module BookytSalary
2
- VERSION = '0.8.0'
2
+ VERSION = '0.9.0'
3
3
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bookyt_salary
3
3
  version: !ruby/object:Gem::Version
4
- hash: 63
4
+ hash: 59
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 8
8
+ - 9
9
9
  - 0
10
- version: 0.8.0
10
+ version: 0.9.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - "Simon H\xC3\xBCrlimann (CyT)"
@@ -105,6 +105,7 @@ files:
105
105
  - app/helpers/salary_booking_template_helper.rb
106
106
  - app/models/salary.rb
107
107
  - app/models/salary_booking_template.rb
108
+ - app/models/salary_item.rb
108
109
  - app/models/salary_template.rb
109
110
  - app/views/salaries/_form.html.haml
110
111
  - app/views/salaries/_list.html.haml
@@ -119,9 +120,15 @@ files:
119
120
  - app/views/salary_booking_templates/_form.html.haml
120
121
  - app/views/salary_booking_templates/_list.html.haml
121
122
  - app/views/salary_booking_templates/_salary_booking_template.html.haml
123
+ - app/views/salary_items/_form.html.haml
124
+ - app/views/salary_items/_line_item.html.haml
125
+ - app/views/salary_items/_list_form.html.haml
126
+ - app/views/salary_items/_list_header.html.haml
122
127
  - app/views/salary_templates/_form.html.haml
123
128
  - app/views/salary_templates/_list.html.haml
129
+ - app/views/salary_templates/_salary_item_form.html.haml
124
130
  - app/views/salary_templates/_salary_template.html.haml
131
+ - app/views/salary_templates/new_salary_item.js.erb
125
132
  - config/application.rb
126
133
  - config/boot.rb
127
134
  - config/locales/bookyt_salary.de.yml
@@ -132,6 +139,7 @@ files:
132
139
  - db/migrate/20120117113315_create_salary_template_habtm_table.rb
133
140
  - db/migrate/20120117120044_rename_salary_booking_template_habtm_table.rb
134
141
  - db/migrate/20120117122025_add_title_and_remarks_to_salary_templates.rb
142
+ - db/migrate/20120118121223_create_salary_items.rb
135
143
  - db/seeds.rb
136
144
  - lib/bookyt_salary.rb
137
145
  - lib/bookyt_salary/navigation.rb