Class: Comee::Core::PurchaseOrder

Inherits:
ApplicationRecord show all
Defined in:
app/models/comee/core/purchase_order.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.ransackable_associations(_auth_object = nil) ⇒ Object



73
74
75
# File 'app/models/comee/core/purchase_order.rb', line 73

def self.ransackable_associations(_auth_object = nil)
  %w[supplier unit]
end

.ransackable_attributes(_auth_object = nil) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'app/models/comee/core/purchase_order.rb', line 55

def self.ransackable_attributes(_auth_object = nil)
  %w[
    id
    po_number
    supplier_id
    unit_id
    order_date
    status
    delivery_address
    delivery_date
    order_reference
  ]
end

Instance Method Details

#calculate_confirmed_totalObject



49
50
51
52
53
# File 'app/models/comee/core/purchase_order.rb', line 49

def calculate_confirmed_total
  items = PurchaseOrderItem.where(purchase_order_id: id)
  items.sum(&:confirmed_total_price).round(2)
  # confirmed_total = (confirmed_total * (1 - confirmed_discount / 100.0)).round(2) if confirmed_discount&.positive?
end

#calculate_confirmed_total_priceObject



27
28
29
# File 'app/models/comee/core/purchase_order.rb', line 27

def calculate_confirmed_total_price
  self.confirmed_total_price = calculate_confirmed_total
end

#calculate_confirmed_vatObject



37
38
39
40
41
# File 'app/models/comee/core/purchase_order.rb', line 37

def calculate_confirmed_vat
  return unless supplier.tax_code == "Inland"

  self.confirmed_vat = (calculate_confirmed_total * 0.19).round(2)
end

#calculate_totalObject



43
44
45
46
47
# File 'app/models/comee/core/purchase_order.rb', line 43

def calculate_total
  items = PurchaseOrderItem.where(purchase_order_id: id)
  items.sum(&:total_price).round(2)
  # total = (total * (1 - discount / 100.0)).round(2) if discount&.positive?
end

#calculate_total_priceObject



23
24
25
# File 'app/models/comee/core/purchase_order.rb', line 23

def calculate_total_price
  self.total_price = calculate_total
end

#calculate_vatObject



31
32
33
34
35
# File 'app/models/comee/core/purchase_order.rb', line 31

def calculate_vat
  return unless supplier.tax_code == "Inland"

  self.vat = (calculate_total * 0.19).round(2)
end

#generate_po_numberObject



69
70
71
# File 'app/models/comee/core/purchase_order.rb', line 69

def generate_po_number
  self.po_number = Util.generate_number("PurchaseOrder", "po_number", "PO")
end

#set_termsObject



77
78
79
80
81
# File 'app/models/comee/core/purchase_order.rb', line 77

def set_terms
  return if terms

  self.terms = supplier.payment_terms
end