Class: Invoice
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- Invoice
- Includes:
- CustomFields, LocalizeInput
- Defined in:
- app/models/invoice.rb
Instance Attribute Summary collapse
-
#delete_attachment ⇒ Object
Returns the value of attribute delete_attachment.
Attributes included from CustomFields
Instance Method Summary collapse
- #expected_amount ⇒ Object
-
#net_amount ⇒ Object
Amount without deposit.
- #orders_sum ⇒ Object
- #orders_transport_sum ⇒ Object
- #user_can_edit?(user) ⇒ Boolean
-
#valid_attachments ⇒ Object
protected
validates that the attachments are jpeg, png or pdf.
Methods included from LocalizeInput
Instance Attribute Details
#delete_attachment ⇒ Object
Returns the value of attribute delete_attachment.
19 20 21 |
# File 'app/models/invoice.rb', line 19 def @delete_attachment end |
Instance Method Details
#expected_amount ⇒ Object
45 46 47 48 49 |
# File 'app/models/invoice.rb', line 45 def expected_amount return net_amount unless orders.any? orders_sum + orders_transport_sum end |
#net_amount ⇒ Object
Amount without deposit
29 30 31 |
# File 'app/models/invoice.rb', line 29 def net_amount amount - deposit + deposit_credit end |
#orders_sum ⇒ Object
33 34 35 36 37 38 39 |
# File 'app/models/invoice.rb', line 33 def orders_sum orders .joins(order_articles: [:article_price]) .sum('COALESCE(order_articles.units_received, order_articles.units_billed, order_articles.units_to_order)' \ + '* article_prices.unit_quantity' \ + '* ROUND((article_prices.price + article_prices.deposit) * (100 + article_prices.tax) / 100, 2)') end |
#orders_transport_sum ⇒ Object
41 42 43 |
# File 'app/models/invoice.rb', line 41 def orders_transport_sum orders.sum(:transport) end |
#user_can_edit?(user) ⇒ Boolean
24 25 26 |
# File 'app/models/invoice.rb', line 24 def user_can_edit?(user) user.role_finance? || (user.role_invoices? && !paid_on && created_by.try(:id) == user.id) end |
#valid_attachments ⇒ Object (protected)
validates that the attachments are jpeg, png or pdf
54 55 56 57 58 |
# File 'app/models/invoice.rb', line 54 def .each do || errors.add(:attachments, I18n.t('model.invoice.invalid_mime', mime: .content_type)) unless .content_type.in?(%w[image/jpeg image/png application/pdf]) end end |