Added running total calculated using subtask totals from the entire issue tree

This commit is contained in:
2026-04-17 21:13:33 -04:00
parent b939d834e9
commit c9d2a47a92
3 changed files with 36 additions and 1 deletions
@@ -32,8 +32,18 @@
<tfoot> <tfoot>
<tr> <tr>
<td colspan="3" style="text-align:right;"><strong><%= t :label_total %></strong></td> <td colspan="3" style="text-align:right;"><strong><%= t :label_total %></strong></td>
<td><strong><%= number_to_currency(total) %></strong></td> <td>
<strong><%= number_to_currency(total) %></strong>
</td>
</tr> </tr>
<% if @issue.children? %>
<tr>
<td colspan="3" style="text-align:right;"><strong><%= t :label_running_total %></strong></td>
<td>
<strong>(<%= number_to_currency(@issue.descendant_line_items_total + total) %>)</strong>
</td>
</tr>
<% end %>
</tfoot> </tfoot>
</table> </table>
</div> </div>
+1
View File
@@ -33,6 +33,7 @@ en:
label_no: "No" label_no: "No"
label_qty: "Quantity" label_qty: "Quantity"
label_remove: "Remove" label_remove: "Remove"
label_running_total: "Running Total"
label_sync_now_accounts: "Sync Accounts" label_sync_now_accounts: "Sync Accounts"
label_sync_now_items: "Sync Items" label_sync_now_items: "Sync Items"
label_type: "Type" label_type: "Type"
+24
View File
@@ -16,6 +16,30 @@ module LineItems
has_many :line_items, dependent: :destroy has_many :line_items, dependent: :destroy
accepts_nested_attributes_for :line_items, allow_destroy: true, reject_if: proc { |attrs| attrs['description'].blank? } accepts_nested_attributes_for :line_items, allow_destroy: true, reject_if: proc { |attrs| attrs['description'].blank? }
# Returns line items for immediate children
def children_line_items
LineItem.where(issue_id: self.children.pluck(:id))
end
# Calculates the total value of all child line items
def children_line_items_total
children_line_items.sum(:line_total)
end
# Returns line items for the entire tree below this issue
def descendant_line_items
LineItem.where(issue_id: self.descendants.pluck(:id))
end
# Calculates the total value of entire tree below this issue
def descendant_line_items_total
descendant_line_items.sum(:line_total)
end
def line_items_total
line_items.sum(:line_total)
end
def line_items_attributes=(attrs) def line_items_attributes=(attrs)
attrs = attrs.stringify_keys attrs = attrs.stringify_keys