<% company = RedmineQboBilling::Company sales_field = company.sales_person_field # A box for every other text custom field QuickBooks has enabled (e.g. VIN, Mileage, Crew #) custom_fields = company.editable_custom_fields customer = Customer.find_by(id: form.customer_id) if form.customer_id.present? # Suggestions other plugins give for those boxes (e.g. redmine_qbo_vehicles: the customer's vehicles' VINs) field_options = RedmineQboBilling.field_options(customer) # 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? # The discount box, unless QuickBooks has discounts turned off or the document is read-only (shown anyway # for a document that has one) show_discount = form.discount? || (company.discounts_allowed? && !form.locked) # The draft being continued (QboDraft), if any; new documents can be saved as drafts draft = local_assigns[:draft] 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 'draft_id', draft.id, id: nil if draft %> <%= 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 %> <%# A paid invoice opened for editing (Unlock) stays unlocked if the page is shown again %> <% if form.unlocked %> <%= hidden_field_tag 'unlock', '1', id: nil %> <%= hidden_field_tag 'estimate[amount_paid]', form.amount_paid, id: nil %> <% end %> <%# 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 %>
<%# Plugins' editor scripts find a box by its field id or name (qboEditor.field / fieldNamed) %> <% custom_fields.each do |field| %>
<%= text_field_tag "estimate[custom_fields][#{field.id}]", form.custom_field(field), id: "qbo_custom_field_#{field.id}", list: "qbo-custom-field-options-#{field.id}", maxlength: 31, autocomplete: 'off', spellcheck: false, class: 'qbo-custom-field' %> <% Array(field_options[field.id.to_s]).each do |option| %> <% end %>
<% end %> <% if settings_read && (sales_field.nil? || custom_fields.empty?) && 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 show_discount %> <%# A percent of the subtotal or a dollar amount; QuickBooks' discount line %> <% end %>
<%= l(:label_subtotal) %> <%= number_to_currency(form.subtotal) %>
<%= l(:label_taxable_subtotal) %>
<%= text_field_tag 'estimate[discount_value]', form.discount_value, id: 'qbo_estimate_discount_value', size: 6, inputmode: 'decimal', autocomplete: 'off', placeholder: '0' %> <%= select_tag 'estimate[discount_type]', options_for_select([[l(:label_discount_percent), 'percent'], [l(:label_discount_amount), 'amount']], form.discount_type), id: 'qbo_estimate_discount_type', 'aria-label': l(:label_discount_type) %> <%= "-#{number_to_currency(form.discount_amount)}" if 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 %> <%# Shown while a save is on its way to QuickBooks (qbo_estimates/_script) %> <% unless form.persisted? %> <%# Kept in Redmine only, however incomplete (QboDraftHandling) %> <% if draft %> <%= link_to l(:button_qbo_delete_draft), qbo_draft_path(draft), method: :delete, data: { confirm: l(:text_are_you_sure) }, class: 'qbo-button qbo-button-dark', id: 'qbo-delete-draft' %> <% end %> <%= submit_tag l(:button_qbo_save_draft), name: 'save_draft', class: 'qbo-button qbo-button-dark', id: 'qbo-save-draft', formnovalidate: true, data: { saving_text: l(:text_qbo_saving_draft) } %> <% end %> <%= 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), saving_text: l(:text_qbo_saving_and_sending) } %> <% end %> <% end %>
<% end %> <%= render partial: 'qbo_estimates/styles' %> <%= render partial: 'qbo_estimates/script' %> <%# Plugins add their editor scripts here (see window.qboEditor and the qbo:* events in qbo_estimates/_script) %> <%= call_hook(:view_qbo_estimate_form_bottom, { form: form, document: form.document }) %>