Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

6.5 KB
Raw Blame
<%#-- copyright
OpenProject is an open source project management software.
Copyright (C) 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) %>

<%=
  render(Primer::OpenProject::PageHeader.new) do |header|
    header.with_title { I18n.t(:label_log_costs) }
    header.with_breadcrumbs(
      [({ href: project_overview_path(@project.id), text: @project.name }),
       ({ href: project_work_packages_path(@project), text: t(:label_work_package_plural) }),
       I18n.t(:label_log_costs)]
    )
  end
%>

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

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

<%= 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.hidden_field :entity_type, value: "WorkPackage" %>
    <%= f.text_field :entity_id,
                     size: 6,
                     required: true,
                     autofocus: true,
                     container_class: "-xslim" %>

    <% if @cost_entry.entity %>
      <div class="form--field-instructions">
        <%= h(@cost_entry.entity.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="sr-only"><%= 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.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" %>

  <opce-remote-field-updater data-url="<%= url_for(controller: :budgets, action: :update_material_budget_item, project_id: @cost_entry.project) %>">
  </opce-remote-field-updater>
<% end %>