Class: SaleOrderHeader

Inherits:
ApplicationRecord show all
Defined in:
app/models/sale_order_header.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ApplicationRecord

define_decrypted_attribute, define_decrypted_attributes, #errors_in_bullet_points, primary_connection, special_connection

Class Method Details

.find_from_procedure(sale_order_id) ⇒ Object

Raises:

  • (ActiveRecord::RecordNotFound)


14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'app/models/sale_order_header.rb', line 14

def find_from_procedure(sale_order_id)
  results = ActiveRecord::Base.execute_procedure(
    'pr_get_sales_order_header',
    sale_order_id
  )

  raise ActiveRecord::RecordNotFound if results.blank?

  header = results.first

  header[:store_province_code] =
    header[:store_province_id].presence && Province.find_by(province_id: header[:store_province_id])&.code

  header[:payment_term_option] = {
    payment_term_id: header[:payment_term_id],
    description: PaymentTerm.find_by(payment_term_id: header[:payment_term_id])&.description
  }

  header[:shipping_company_option] = {
    shipping_company_id: header[:ship_via_id],
    description_english: ShippingCompany.find_by(shipping_company_id: header[:ship_via_id])&.description_english
  }

  bill_to_customer = Customer.find_by(customer_id: header[:bill_to_key])
  header[:bill_to_customer_option] = {
    customer_id: header[:bill_to_key],
    name: bill_to_customer&.name,
    code: bill_to_customer&.code,
    address: bill_to_customer&.address,
    email: bill_to_customer&.email,
    phone: bill_to_customer&.phone_1
  }

  ship_to_customer = Customer.find_by(customer_id: header[:ship_to_key])
  header[:ship_to_customer_option] = {
    customer_id: header[:ship_to_key],
    name: ship_to_customer&.name,
    code: ship_to_customer&.code,
    address: ship_to_customer&.address
  }

  header[:total_hst_amount_ordered] = header[:total_hst_amount_ordered].to_f.round(2)
  header[:grand_total_amount_shipped] = header[:grand_total_amount_shipped].to_f.round(2)

  header
end

Instance Method Details

#cancellable?Boolean

Returns:

  • (Boolean)


5
6
7
# File 'app/models/sale_order_header.rb', line 5

def cancellable?
  %w[0 1].include?(order_stage)
end

#verifiable?Boolean

Returns:

  • (Boolean)


9
10
11
# File 'app/models/sale_order_header.rb', line 9

def verifiable?
  order_stage.to_s.strip == '0'
end