%
company = RedmineQboBilling::Company
sales_field = company.sales_person_field
vin_field = company.vin_field
mileage_field = company.mileage_field
customer = Customer.find_by(id: form.customer_id) if form.customer_id.present?
vehicles = customer.respond_to?(:vehicles) ? customer.vehicles.select { |v| v.vin.present? } : []
# When QuickBooks' settings couldn't be read at all, the page header says so instead of each field
settings_read = company.settings.present?
# The same editor writes estimates and invoices
invoice = form.invoice?
sender = invoice ? RedmineQboBilling.invoice_sender? : RedmineQboBilling.sender?
cancel_path = customer ? customer_path(customer) : home_path
form_url =
if invoice
form.persisted? ? qbo_invoice_path(form.id) : qbo_invoices_path
else
form.persisted? ? qbo_estimate_path(form.id) : qbo_estimates_path
end
%>
<%= form_tag(form_url,
method: form.persisted? ? :patch : :post,
id: 'qbo-estimate-form',
class: "qbo-estimate qbo-document-#{form.document}",
data: {
document: form.document,
import_url: (import_options_qbo_invoices_path if invoice),
labor_item_ids: (RedmineQboBilling::LaborItems.item_ids if invoice),
items_url: items_qbo_estimates_path,
customer_info_url: customer_info_qbo_estimates_path,
saved_subtotal: (form.persisted? ? form.subtotal.to_s('F') : ''),
saved_tax: form.total_tax.to_s,
discount: form.discount.to_s,
# New estimates: moving the estimate date moves the default expiration date with it
expiration_days: (form.persisted? || invoice ? 0 : RedmineQboBilling::EstimateWriter.expiration_days),
warn_unsaved: User.current.pref.warn_on_leaving_unsaved != '0'
}) do %>
<%= hidden_field_tag 'estimate[sync_token]', form.sync_token, id: nil %>
<%= hidden_field_tag 'estimate[total_tax]', form.total_tax, id: nil %>
<%= hidden_field_tag 'estimate[discount]', form.discount, id: nil %>
<%= hidden_field_tag 'estimate[email_status]', form.email_status, id: nil %>
<%= hidden_field_tag 'estimate[txn_status]', form.txn_status, id: nil %>
<%# Shown again if the page is redisplayed; the saved value is worked out when saving %>
<%= hidden_field_tag 'estimate[sales_person]', form.sales_person, id: nil if form.persisted? || form.invoice? %>
<% if invoice %>
<%= hidden_field_tag 'estimate[balance]', form.balance, id: nil %>
<%# Estimates whose lines are on this invoice; the Import panel adds more %>
<% form.linked_estimate_ids.each do |estimate_id| %>
<%= hidden_field_tag 'estimate[linked_estimate_ids][]', estimate_id, id: nil %>
<% end %>
<% end %>
<%# Action bar, like the bar along the bottom of QuickBooks' estimate screen %>
<%= link_to l(:button_cancel), cancel_path, class: 'qbo-button qbo-button-dark', id: 'qbo-estimate-cancel' %>
<% unless form.locked %>
<%= submit_tag l(:button_save), name: 'save', class: 'qbo-button qbo-button-dark' %>
<% if sender %>
<%= submit_tag l(:button_save_and_send), name: 'save_and_send', class: 'qbo-button qbo-button-primary',
id: 'qbo-estimate-save-and-send', data: { needs_email_text: l(:text_estimate_send_needs_email) } %>
<% end %>
<% end %>
<% end %>
<%= render partial: 'qbo_estimates/styles' %>
<%= render partial: 'qbo_estimates/script' %>