Class: InvoiceSerializer
- Inherits:
-
ActiveModel::Serializer
- Object
- ActiveModel::Serializer
- InvoiceSerializer
- Defined in:
- app/serializers/invoice_serializer.rb
Instance Method Summary collapse
- #discount_amount ⇒ Object
- #discounts ⇒ Object
- #expenses ⇒ Object
- #invoice_period ⇒ Object
- #subtotal ⇒ Object
- #total ⇒ Object
Instance Method Details
#discount_amount ⇒ Object
13 14 15 |
# File 'app/serializers/invoice_serializer.rb', line 13 def discount_amount object.discounts.pluck(:amount).sum end |
#discounts ⇒ Object
31 32 33 34 35 36 37 38 39 |
# File 'app/serializers/invoice_serializer.rb', line 31 def discounts object.discounts.map do |e| { id: e.id, amount: e&.amount, description: e&.description } end end |
#expenses ⇒ Object
21 22 23 24 25 26 27 28 29 |
# File 'app/serializers/invoice_serializer.rb', line 21 def expenses object.expenses.map do |e| { id: e.id, category: e&.category, amount: e&.amount } end end |
#invoice_period ⇒ Object
5 6 7 |
# File 'app/serializers/invoice_serializer.rb', line 5 def invoice_period "#{object.booking.check_in_date} - #{object.booking.check_out_date}" end |
#subtotal ⇒ Object
9 10 11 |
# File 'app/serializers/invoice_serializer.rb', line 9 def subtotal object.expenses.pluck(:amount).sum end |
#total ⇒ Object
17 18 19 |
# File 'app/serializers/invoice_serializer.rb', line 17 def total object.expenses.pluck(:amount).sum - object.discounts.pluck(:amount).sum end |