mirror of
https://github.com/rickbarrette/redmine_qbo.git
synced 2026-11-21 02:50:36 -05:00
An estimate attached to an issue was read-only, so changing it after a customer asked for tweaks meant taking it off the work order first. A new global permission, "Edit estimates linked to issues" (on top of Write estimates), shows an "Unlock to edit" button on a linked estimate. After a confirmation the estimate opens for editing, and the issues stay linked when it's saved. EstimateWriter.save still refuses a linked estimate unless it was unlocked by a user with the permission. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
110 lines
4.6 KiB
ERB
110 lines
4.6 KiB
ERB
<%# Title with the customer breadcrumb, errors, and warnings shared by the estimate and invoice pages %>
|
|
<%
|
|
customer = Customer.find_by(id: form.customer_id) if form.customer_id.present?
|
|
invoice = form.invoice?
|
|
%>
|
|
<h2>
|
|
<%= link_to l(:label_customers), customers_path %>
|
|
»
|
|
<% if customer %>
|
|
<%= link_to customer.name, customer_path(customer) %>
|
|
»
|
|
<% end %>
|
|
<% if form.persisted? %>
|
|
<%= l(invoice ? :label_invoice : :label_estimate) %> #<%= form.doc_number %>
|
|
<% if form.sent? %>
|
|
<span class="qbo-estimate-status qbo-estimate-status-sent"><%= l(:label_estimate_sent) %></span>
|
|
<% end %>
|
|
<% if invoice %>
|
|
<% status = RedmineQboBilling::InvoiceStatus.status(total: form.total, balance: form.balance,
|
|
due_date: RedmineQboBilling::EstimateForm.date(form.due_date),
|
|
today: User.current.today) %>
|
|
<% if status %>
|
|
<% paid_on = Invoice.where(id: form.id).pick(:paid_on) if status == :paid && form.id.present? %>
|
|
<span class="qbo-estimate-status qbo-invoice-status-<%= status %>"><%= RedmineQboBilling::InvoiceStatus.label(status, paid_on: paid_on) %></span>
|
|
<% end %>
|
|
<% elsif !invoice && form.txn_status.present? %>
|
|
<span class="qbo-estimate-status qbo-estimate-status-<%= form.txn_status.downcase %>"><%= form.txn_status %></span>
|
|
<% end %>
|
|
<% else %>
|
|
<%= l(invoice ? :label_new_invoice : :label_new_estimate) %>
|
|
<% end %>
|
|
</h2>
|
|
|
|
<%= error_messages_for form %>
|
|
|
|
<% if @conflict %>
|
|
<p class="warning">
|
|
<%= l(:text_estimate_reload) %>
|
|
<%= link_to l(:button_reload_estimate), invoice ? edit_qbo_invoice_path(form.id) : edit_qbo_estimate_path(form.id) %>
|
|
</p>
|
|
<% end %>
|
|
|
|
|
|
<% if form.duplicated_from.present? %>
|
|
<div class="flash notice"><%= l(:text_estimate_duplicated_from, number: form.duplicated_from) %></div>
|
|
<% end %>
|
|
<% if form.converted_from.present? %>
|
|
<div class="flash notice"><%= l(:text_invoice_from_estimate, number: form.converted_from) %></div>
|
|
<% end %>
|
|
|
|
<% if form.locked == :billed %>
|
|
<div class="warning qbo-estimate-notice">
|
|
<%= l(:error_estimate_billed) %>
|
|
<% if Array(form.invoiced_on).any? %>
|
|
<ul>
|
|
<% form.invoiced_on.each do |invoice_id, number| %>
|
|
<li><%= link_to "#{l(:label_invoice)} ##{number}", RedmineQboBilling.invoice_writer? ? edit_qbo_invoice_path(invoice_id) : invoice_path(invoice_id) %></li>
|
|
<% end %>
|
|
</ul>
|
|
<% end %>
|
|
</div>
|
|
<% elsif form.locked == :linked %>
|
|
<div class="warning qbo-estimate-notice">
|
|
<%= l(:error_estimate_linked_to_issues) %>
|
|
<ul>
|
|
<% Array(@linked_issues).each do |issue| %>
|
|
<li><%= link_to_issue(issue, truncate: 60) %></li>
|
|
<% end %>
|
|
</ul>
|
|
<%# Opened for editing anyway after a confirmation (e.g. the customer asks for changes after the diagnosis) %>
|
|
<% if RedmineQboBilling.linked_estimate_editor? %>
|
|
<%= link_to sprite_icon('unlock', l(:button_unlock_estimate)), edit_qbo_estimate_path(form.id, unlock: 1),
|
|
class: 'icon icon-unlock', id: 'qbo-unlock-estimate',
|
|
data: { confirm: l(:text_unlock_estimate_confirmation) } %>
|
|
<% end %>
|
|
</div>
|
|
<% elsif form.unlocked && !invoice %>
|
|
<div class="warning qbo-estimate-notice">
|
|
<%= l(:text_estimate_unlocked) %>
|
|
<ul>
|
|
<% Array(@linked_issues).each do |issue| %>
|
|
<li><%= link_to_issue(issue, truncate: 60) %></li>
|
|
<% end %>
|
|
</ul>
|
|
</div>
|
|
<% elsif form.locked == :paid %>
|
|
<p class="warning">
|
|
<%= l(:error_invoice_paid) %>
|
|
<%# Opened for editing anyway after a confirmation (e.g. a discount after a deposit) %>
|
|
<% if RedmineQboBilling.paid_invoice_editor?(form.fully_paid?) %>
|
|
<%= link_to sprite_icon('unlock', l(:button_unlock_invoice)), edit_qbo_invoice_path(form.id, unlock: 1),
|
|
class: 'icon icon-unlock', id: 'qbo-unlock-invoice',
|
|
data: { confirm: l(:text_unlock_invoice_confirmation) } %>
|
|
<% end %>
|
|
</p>
|
|
<% elsif form.unlocked && form.amount_paid.to_d > 0 %>
|
|
<p class="warning"><%= l(:text_invoice_unlocked, paid: number_to_currency(form.amount_paid)) %></p>
|
|
<% elsif form.locked == :bundles %>
|
|
<p class="warning"><%= l(invoice ? :error_invoice_has_bundles : :error_estimate_has_bundles) %></p>
|
|
<% end %>
|
|
|
|
<% if RedmineQboBilling::Company.settings.empty? %>
|
|
<p class="warning">
|
|
<%= l(:text_quickbooks_settings_unavailable) %>
|
|
<% if User.current.admin? %>
|
|
<%= link_to l(:button_refresh_quickbooks_fields), refresh_company_qbo_estimates_path, method: :post %>
|
|
<% end %>
|
|
</p>
|
|
<% end %>
|