diff --git a/app/views/line_items/_issue_line_items.html.erb b/app/views/line_items/_issue_line_items.html.erb
index c651298..f48d4ce 100644
--- a/app/views/line_items/_issue_line_items.html.erb
+++ b/app/views/line_items/_issue_line_items.html.erb
@@ -32,8 +32,18 @@
| <%= t :label_total %> |
- <%= number_to_currency(total) %> |
+
+ <%= number_to_currency(total) %>
+ |
+ <% if @issue.children? %>
+
+ | <%= t :label_running_total %> |
+
+ (<%= number_to_currency(@issue.descendant_line_items_total + total) %>)
+ |
+
+ <% end %>
diff --git a/config/locales/en.yml b/config/locales/en.yml
index 9b60516..4cda68c 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -33,6 +33,7 @@ en:
label_no: "No"
label_qty: "Quantity"
label_remove: "Remove"
+ label_running_total: "Running Total"
label_sync_now_accounts: "Sync Accounts"
label_sync_now_items: "Sync Items"
label_type: "Type"
diff --git a/lib/line_items/patches/issue_patch.rb b/lib/line_items/patches/issue_patch.rb
index ec140c0..55b79d2 100644
--- a/lib/line_items/patches/issue_patch.rb
+++ b/lib/line_items/patches/issue_patch.rb
@@ -16,6 +16,30 @@ module LineItems
has_many :line_items, dependent: :destroy
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)
attrs = attrs.stringify_keys