opf/openproject

View on GitHub
modules/costs/app/views/costlog/edit.html.erb

Summary

Maintainability
Test Coverage
<%#-- copyright
OpenProject is an open source project management software.
Copyright (C) 2012-2024 the OpenProject GmbH

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License version 3.

OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
Copyright (C) 2006-2013 Jean-Philippe Lang
Copyright (C) 2010-2013 the ChiliProject Team

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.

See COPYRIGHT and LICENSE files for more details.

++#%>

<% html_title t(:label_log_costs) %>
<h2><%= t(:label_log_costs) %></h2>

<% url = @cost_entry.new_record? ?
  { action: 'create', project_id: @project.id } :
  { action: 'update', id: @cost_entry } %>

<% method = @cost_entry.new_record? ?
  :post :
  :put %>

<remote-field-updater data-url="<%= url_for(controller: :budgets, action: :update_material_budget_item, project_id: @cost_entry.project) %>"
                      data-mode="json">
</remote-field-updater>
<%= labelled_tabular_form_for @cost_entry, url: url, html: { method: method } do |f| %>
  <%= error_messages_for 'cost_entry' %>
  <%= back_url_hidden_field_tag %>
  <%= f.hidden_field :element_id, value: 'cost_entry', class: 'remote-field--input', data: { :'remote-field-key' => 'element_id' } %>

  <div class="form--field -required">
    <%= f.text_field :work_package_id,
                     size: 6,
                     required: true,
                     autofocus: true,
                     container_class: '-xslim' %>

    <% if @cost_entry.work_package %>
      <div class="form--field-instructions">
        <%= h("#{@cost_entry.work_package.to_s}") %>
      </div>
    <% end %>
  </div>
  <div class="form--field -required">
    <%= f.date_picker :spent_on,
                      required: true,
                      data: { :'remote-field-key' => 'fixed_date' } %>
    <label for="cost_entry_spent_on" class="hidden-for-sighted"><%= t(:label_date) %> <%= t(:text_hint_date_format) %></label>
  </div>
  <% if User.current.allowed_in_project? :log_costs, @project %>
    <div class="form--field">
      <%# Without knowing why `prompt` is in this case responsible for no blank line in the selection options %>
      <%= f.select :user_id,
                   user_collection_for_select_options,
                   required: true,
                   prompt: true,
                   container_class: '-middle' %>
    </div>
  <% else %>
    <%= f.hidden_field :user_id, value: User.current.id %>
  <% end %>
  <div class="form--field -required">
    <%# see above %>
    <%= f.select :cost_type_id,
                 cost_types_collection_for_select_options,
                 { prompt: true,
                   container_class: '-middle' },
                 {
                   required: true,
                   class: 'remote-field--input',
                   data: { :'remote-field-key' => 'cost_type_id' }
                 } %></p>
  </div>
  <div class="form--field -required">
    <% if @cost_entry.cost_type.nil? %>
      <%= f.text_field :units,
                       value: unitless_currency_number(@cost_entry.units),
                       size: 6,
                       required: true,
                       container_class: '-slim' %>
    <% else %>
      <% suffix = @cost_entry.units == 1 ? @cost_entry.cost_type.unit : @cost_entry.cost_type.unit_plural %>
      <%= f.text_field :units,
                       size: 6,
                       value: unitless_currency_number(@cost_entry.units),
                       required: true,
                       suffix: h(suffix),
                       suffix_id: 'cost_entry_unit_name',
                       class: 'remote-field--input',
                       data: { :'remote-field-key' => 'units' },
                       container_class: '-slim' %>
    <% end %>
  </div>

  <div class="form--field">
    <label for="cost_entry_costs_edit" class="form--label"><%= CostEntry.human_attribute_name(:costs) %></label>
    <% if User.current.allowed_in_project?(:view_cost_rates, @cost_entry.project) %>
    <span class="form--field-container">
      <a href="#"
         id="cost_entry_costs"
         class="costs--edit-planned-costs-btn icon-context icon-edit"
         role="button"
         title="<%= t(:help_click_to_edit) %>">
            <%= number_to_currency(@cost_entry.real_costs) %>
        </a>
      <%= render partial: '/budgets/items/budget_override_cost_form',
                 locals: {
                   field_name: "cost_entry[overridden_costs]",
                   cost_value: unitless_currency_number(@cost_entry.real_costs),
                 }
      %>

      </span>
    <% else %>
    <span class="form--field-container">
          <%= f.text_field :overridden_costs,
                           value: @cost_entry.overridden_costs ? unitless_currency_number(@cost_entry.overridden_costs).strip : '',
                           placeholder: t(:label_example_placeholder, decimal: unitless_currency_number(1000.50)),
                           no_label: true,
                           suffix: Setting.plugin_costs['costs_currency'],
                           id: 'cost_entry_cost_value',
                           container_class: '-middle',
                           size: 7 %>
        </span>
      <div class="form--field-instructions">
        <p><%= t(:help_override_rate) %></p>
      </div>
    <% end %>
  </div>

  <div class="form--field">
    <%= f.text_field :comments, size: 100, container_class: '-wide' %>
  </div>

  <%= styled_button_tag t(:button_save), class: '-with-icon icon-checkmark' %>
<% end %>