diff --git a/app/helpers/deliverables_helper.rb b/app/helpers/deliverables_helper.rb new file mode 100644 index 0000000..e19afd9 --- /dev/null +++ b/app/helpers/deliverables_helper.rb @@ -0,0 +1,12 @@ +module DeliverablesHelper + def field_with_budget_observer_and_totals(form, field) + content_tag(:p, + form.text_field(field, :size => 7) + + content_tag(:span, + 0, + :class => "budget-calculation", + :id => 'deliverable_' + field.to_s + '_subtotal' + ) + ) + observe_field('deliverable_' + field.to_s, :function => "updateSubtotal('deliverable_#{field.to_s}'); updateBudget('deliverable_budget');") + end +end diff --git a/app/views/deliverables/_form.html.erb b/app/views/deliverables/_form.html.erb index f4d9b1d..a0e233f 100644 --- a/app/views/deliverables/_form.html.erb +++ b/app/views/deliverables/_form.html.erb @@ -19,16 +19,19 @@
<%# TODO: Need to update subtotals with observers %>

TODO: Fixed cost

+

<%= f.text_field :cost_per_hour, :size => 7 %>

- <%= observe_field('deliverable_cost_per_hour', :function => "updateBudget('deliverable_budget');") %> -

<%= f.text_field :total_hours, :size => 7 %>

- <%= observe_field('deliverable_total_hours', :function => "updateBudget('deliverable_budget');") %> -

<%= f.text_field :overhead, :size => 7 %>

- <%= observe_field('deliverable_overhead', :function => "updateBudget('deliverable_budget');") %> -

<%= f.text_field :materials, :size => 7 %>

- <%= observe_field('deliverable_materials', :function => "updateBudget('deliverable_budget');") %> -

<%= f.text_field :profit, :size => 7 %>

- <%= observe_field('deliverable_profit', :function => "updateBudget('deliverable_budget');") %> + <%= observe_field('deliverable_cost_per_hour', :function => "updateBaseSubtotal(); updateBudget('deliverable_budget');") %> + +

+ <%= f.text_field :total_hours, :size => 7 %> + <%= content_tag(:span, 0, :class => "budget-calculation", :id => 'deliverable_base_subtotal') %> +

+ <%= observe_field('deliverable_total_hours', :function => "updateBaseSubtotal(); updateBudget('deliverable_budget');") %> + + <%= field_with_budget_observer_and_totals(f, :overhead) %> + <%= field_with_budget_observer_and_totals(f, :materials) %> + <%= field_with_budget_observer_and_totals(f, :profit) %>

<%= f.text_field :budget, :size => 7, :disabled => true %>

@@ -101,5 +104,35 @@ function updateBudget(field) { $(field).value = calcBudget(); } } + +function updateSubtotal(field) { + var perHour = toAmount($('deliverable_cost_per_hour').value); + var hours = toAmount($('deliverable_total_hours').value); + + var variableCost = perHour * hours; + + if ($(field).value.match('%')) { + var subtotal = (toAmount($(field).value) / 100) * variableCost; + } else { + var subtotal = toAmount($(field).value); + } + + if ($(field + '_subtotal')) { + $(field + '_subtotal').innerHTML = subtotal; + } + + calcBudget('deliverable_budget'); +} + +function updateBaseSubtotal() { + var perHour = toAmount($('deliverable_cost_per_hour').value); + var hours = toAmount($('deliverable_total_hours').value); + + var variableCost = perHour * hours; + + if ($('deliverable_base_subtotal')) { + $('deliverable_base_subtotal').innerHTML = variableCost; + } +} <% end %> diff --git a/assets/stylesheets/budget.css b/assets/stylesheets/budget.css index d2e8ce6..f3a6faf 100644 --- a/assets/stylesheets/budget.css +++ b/assets/stylesheets/budget.css @@ -8,4 +8,6 @@ tr.deliverable td.subject { text-align: left; } tr.deliverable td.done_ratio table.progress { margin-left:auto; margin-right: auto;} #deliverable-form .splitcontentleft { width: 62% } -#deliverable-form .splitcontentright { width: 37% } \ No newline at end of file +#deliverable-form .splitcontentright { width: 37% } + +span.budget-calculation { color:#999999; font-weight:bold;} \ No newline at end of file