<% 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 %>
> <%# Customer, email and the big amount, like the top of QuickBooks' estimate screen %>
<%= text_field_tag 'estimate[customer_name]', form.customer_name, id: 'qbo_estimate_customer_name', class: 'customer-name', autocomplete: 'off', placeholder: l(:label_choose_a_customer), data: { autocomplete_url: '/customers/autocomplete' } %> <%= hidden_field_tag 'estimate[customer_id]', form.customer_id, id: 'customer_id' %>
<%= text_field_tag 'estimate[email]', form.email, id: 'qbo_estimate_email', autocomplete: 'off', placeholder: l(:text_separate_emails_with_comma) %>
<%= l(:label_amount) %> <%= number_to_currency(form.total || form.subtotal) %> <% if invoice && form.balance && form.total && form.balance.to_d != form.total.to_d %> <%= l(:label_invoice_balance, balance: number_to_currency(form.balance)) %> <% end %>
<%= l(:label_billing_address) %>
<%= form.billing_address.to_s %>
<%= date_field_tag 'estimate[txn_date]', form.txn_date, id: 'qbo_estimate_txn_date' %>
<% if invoice %> <%# Left empty, QuickBooks works it out from the customer's terms %> <%= date_field_tag 'estimate[due_date]', form.due_date, id: 'qbo_estimate_due_date' %> <% else %> <%= date_field_tag 'estimate[expiration_date]', form.expiration_date, id: 'qbo_estimate_expiration_date' %> <% end %>
<%# Not editable: QuickBooks numbers estimates. Posted only so the page can show it again. %> <%= hidden_field_tag 'estimate[doc_number]', form.doc_number, id: nil %> <%= text_field_tag nil, form.doc_number.presence, id: 'qbo_estimate_doc_number', readonly: true, tabindex: -1, placeholder: l(:text_assigned_by_quickbooks) %>
<%= text_field_tag nil, form.sales_person, id: 'qbo_estimate_sales_person', readonly: true, tabindex: -1 %> <% if settings_read && !sales_field %> <%= l(:text_no_sales_person_field) %> <% end %>
<%= text_field_tag 'estimate[vin]', form.vin, id: 'qbo_estimate_vin', list: 'qbo-estimate-vins', maxlength: 31, autocomplete: 'off', spellcheck: false, disabled: vin_field.nil? %> <% vehicles.each do |vehicle| %> <% end %> <% if settings_read && !vin_field %> <%= l(:text_no_vin_field) %> <% end %>
<%# Mileage only shows when QuickBooks has a text field named like "Mileage" %> <% if mileage_field %>
<%= text_field_tag 'estimate[mileage]', form.mileage, id: 'qbo_estimate_mileage', maxlength: 31, inputmode: 'numeric', autocomplete: 'off' %>
<% end %> <% if settings_read && (sales_field.nil? || vin_field.nil?) && User.current.admin? %>
<%= link_to sprite_icon('reload', l(:button_refresh_quickbooks_fields)), refresh_company_qbo_estimates_path, method: :post, class: 'icon icon-reload' %> <%= l(:text_quickbooks_custom_fields_found, fields: company.custom_fields.map { |f| "#{f.name} (##{f.id})" }.join(', ').presence || l(:label_none)) %>
<% end %>
<%# Product/service lines %>
<% form.lines.each_with_index do |line, index| %> <%= render partial: (line.subtotal? ? 'qbo_estimates/subtotal_line' : 'qbo_estimates/line'), locals: { line: line, key: index, number: index + 1 } %> <% end %>
# <%= l(:label_product_service) %> <%= l(:field_description) %> <%= l(:label_qty) %> <%= l(:label_rate) %> <%= l(:label_amount) %> <%= l(:label_tax) %>

<% if invoice %> <% end %>

<% if invoice %> <%# Import: billable QuickBooks time (replacing the lines ticked) and open estimates. Filled by the script. %> <% end %>
<%= text_area_tag 'estimate[customer_memo]', form.customer_memo, id: 'qbo_estimate_customer_memo', rows: 4, maxlength: 1000 %>
<%= text_area_tag 'estimate[private_note]', form.private_note, id: 'qbo_estimate_private_note', rows: 4, maxlength: 4000, placeholder: l(:text_memo_is_private) %>
<% if form.discount.to_f != 0 %> <% end %>
<%= l(:label_subtotal) %> <%= number_to_currency(form.subtotal) %>
<%= l(:label_taxable_subtotal) %>
<%= l(:label_discount_from_quickbooks) %> -<%= number_to_currency(form.discount) %>
<%= l(:label_sales_tax) %> <%= form.total_tax ? number_to_currency(form.total_tax) : l(:text_tax_calculated_by_quickbooks) %>
<%= l(:label_estimate_total) %> <%= number_to_currency(form.total || form.subtotal) %>
<%# 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' %>