Class: EdiPartner

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

Defined Under Namespace

Classes: View

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

.create_update_procedure(company_id:, edi_partner_id: 0, default_isa_id: nil, description: nil, duns_number: nil, head_office_id: nil, active: nil, schedule_asn_transmission: nil, auto_delete_duplicate_pos: nil, one_asn_per_order: nil, repetition_separator: nil, auto_generate_855: nil, entity_type: nil, network_code: nil, system_date: nil, system_user: nil) ⇒ Object



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'app/models/edi_partner.rb', line 70

def create_update_procedure(
  company_id:,
  edi_partner_id: 0,
  default_isa_id: nil,
  description: nil,
  duns_number: nil,
  head_office_id: nil,
  active: nil,
  schedule_asn_transmission: nil,
  auto_delete_duplicate_pos: nil,
  one_asn_per_order: nil,
  repetition_separator: nil,
  auto_generate_855: nil,
  entity_type: nil,
  network_code: nil,
  system_date: nil,
  system_user: nil
)
  result = ActiveRecord::Base.execute_procedure(
    'pr_insert_update_edi_partner',
    company_id,
    edi_partner_id,
    default_isa_id,
    description,
    duns_number,
    head_office_id,
    active,
    schedule_asn_transmission,
    auto_delete_duplicate_pos,
    one_asn_per_order,
    repetition_separator,
    auto_generate_855,
    entity_type,
    network_code,
    system_date,
    system_user
  )[0]

  EdiPartner.find(result['edi_partner_id'])
end

.from_procedure(company_id:, entity_type: nil, query: '', limit: 10, offset: 0, grouping: 'edi_partner_id desc') ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'app/models/edi_partner.rb', line 36

def from_procedure(
  company_id:,
  entity_type: nil,
  query: '',
  limit: 10,
  offset: 0,
  grouping: 'edi_partner_id desc'
)
  offset = offset.to_i
  limit = limit.to_i
  page_number = (offset / limit) + 1

  data = ActiveRecord::Base.execute_procedure(
    'pr_get_edi_partners_by_page',
    company_id,
    entity_type,
    limit,
    query,
    page_number,
    grouping
  )

   = {
    total: data.length.positive? ? data.first['TotalRecords'] : 0,
    limit: limit,
    offset: limit * page_number
  }

  {
    metadata: ,
    data: data
  }
end

Instance Method Details

#partnerObject

validates :default_isa_id, presence: true, uniqueness: true validates :description, presence: true, uniqueness: true



15
16
17
# File 'app/models/edi_partner.rb', line 15

def partner
  partner_class.find(head_office_id)
end

#partner_classObject



19
20
21
22
23
24
25
# File 'app/models/edi_partner.rb', line 19

def partner_class
  if entity_type == 'S'
    Supplier
  elsif entity_type == 'C'
    Customer
  end
end

#partners_countObject



27
28
29
30
31
32
33
# File 'app/models/edi_partner.rb', line 27

def partners_count
  if entity_type == 'S'
    1
  elsif entity_type == 'C'
    Customer.where(belongs_to_ho_id: head_office_id).count
  end
end