Skip to content

Commit

Permalink
Update invoice.rb
Browse files Browse the repository at this point in the history
added type argument for order and delivery sum and for expected_amount for calculation without and with markup
  • Loading branch information
mjavurek authored Nov 13, 2024
1 parent 34e1c35 commit 46e54ca
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions app/models/invoice.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,30 @@ def net_amount
amount - deposit + deposit_credit
end

def orders_sum
orders.sum { |order| order.sum(:groups_without_markup) }
def orders_sum(type = :without_markup)
if type == :without_markup
orders.sum { |order| order.sum(:groups_without_markup) }
elsif type == :with_markup
orders.sum { |order| order.sum(:groups) }

Check failure on line 37 in app/models/invoice.rb

View workflow job for this annotation

GitHub Actions / test

Layout/TrailingWhitespace: Trailing whitespace detected.
end
end

def orders_transport_sum
orders.sum(:transport)
end

def deliveries_sum
deliveries.sum(&:sum)

def deliveries_sum(type = :without_markup)
if type == :without_markup
deliveries.sum(&:sum)

Check failure on line 47 in app/models/invoice.rb

View workflow job for this annotation

GitHub Actions / test

Layout/TrailingWhitespace: Trailing whitespace detected.
elsif type == :with_markup

Check failure on line 48 in app/models/invoice.rb

View workflow job for this annotation

GitHub Actions / test

Layout/TrailingWhitespace: Trailing whitespace detected.
deliveries.sum { |delivery| delivery.sum(:fc)}

Check failure on line 49 in app/models/invoice.rb

View workflow job for this annotation

GitHub Actions / test

Layout/ExtraSpacing: Unnecessary spacing detected.

Check failure on line 49 in app/models/invoice.rb

View workflow job for this annotation

GitHub Actions / test

Layout/SpaceInsideBlockBraces: Space missing inside }.
end
end
def expected_amount

def expected_amount(type = :without_markup)
return net_amount unless orders.any?

orders_sum + orders_transport_sum + deliveries_sum
orders_sum(type) + orders_transport_sum + deliveries_sum(type)

Check failure on line 56 in app/models/invoice.rb

View workflow job for this annotation

GitHub Actions / test

Layout/TrailingWhitespace: Trailing whitespace detected.
end

protected
Expand Down

0 comments on commit 46e54ca

Please sign in to comment.