Class: Edi204Controller

Inherits:
ApplicationController show all
Includes:
Edi204Helper
Defined in:
app/controllers/edi_204_controller.rb

Instance Method Summary collapse

Methods included from Edi204Helper

#check_record_exists_for_company, #edi_204_exist_for_company, #get_edi_204_counts_data, #get_shipment_status_codes, #get_stops, #get_time_zones

Methods included from AuthentificationHelper

#accessible_company_ids_from_tenant_and_user, #application_mode_from_hostname, #current_company_id_from_accessible_company_ids, #current_tenant_from_user, #current_user_and_locale_from_token

Instance Method Details

#countsObject



107
108
109
110
111
112
113
114
115
# File 'app/controllers/edi_204_controller.rb', line 107

def counts
  edi_204_b2_id = params[:edi_204_b2_id]
  if check_record_exists_for_company(edi_204_b2_id)
    return render json: { error: 'EDI 204 does not exist for this company' }, status: :not_found
  end

  data = get_edi_204_counts_data(edi_204_b2_id)
  render json: data
end

#edi_204_l11Object



43
44
45
46
47
48
49
50
51
# File 'app/controllers/edi_204_controller.rb', line 43

def edi_204_l11
  edi_204_b2_id = params[:edi_204_b2_id]
  if check_record_exists_for_company(edi_204_b2_id)
    return render json: { error: 'EDI 204 does not exist for this company' }, status: :not_found
  end

  results = Edi204L11.where(edi_204_b2_id: edi_204_b2_id)
  render json: results
end

#edi_204_n1_name_addressObject



63
64
65
66
67
68
69
70
71
# File 'app/controllers/edi_204_controller.rb', line 63

def edi_204_n1_name_address
  edi_204_b2_id = params[:edi_204_b2_id]
  if check_record_exists_for_company(edi_204_b2_id)
    return render json: { error: 'EDI 204 does not exist for this company' }, status: :not_found
  end

  results = Edi204N1NameAddress.where(edi_204_b2_id: edi_204_b2_id)
  render json: results
end

#edi_204_nteObject



53
54
55
56
57
58
59
60
61
# File 'app/controllers/edi_204_controller.rb', line 53

def edi_204_nte
  edi_204_b2_id = params[:edi_204_b2_id]
  if check_record_exists_for_company(edi_204_b2_id)
    return render json: { error: 'EDI 204 does not exist for this company' }, status: :not_found
  end

  results = Edi204Nte.where(edi_204_b2_id: edi_204_b2_id)
  render json: results
end

#edi_204_s5_oidObject



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'app/controllers/edi_204_controller.rb', line 73

def edi_204_s5_oid
  edi_204_b2_id = params[:edi_204_b2_id]
  stop_id = params[:stop_id]
  if check_record_exists_for_company(edi_204_b2_id)
    return render json: { error: 'EDI 204 does not exist for this company' }, status: :not_found
  end

  results1 = Edi204S5.where(edi_204_b2_id: edi_204_b2_id)
  if stop_id.present?
    results = Edi204Oid.where(stop_id: stop_id)
  end
  render json: {
    edi_204_s5: results1,
    edi_204_oid: results || []
  }
end

#indexObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'app/controllers/edi_204_controller.rb', line 12

def index
  display_length = params[:limit] || 10
  search_value = params[:query] || ''
  display_start_from_page_no = params[:offset] || 1
  order_by = params[:order_by] || 'edi_204_b2_id'
  order_direction = params[:order_direction] || 'DESC'
  grouping = "#{order_by} #{order_direction}"
  company_id = current_company_id
  edi_partner_id = params[:edi_partner_id]

  result = Edi204.edi_204_by_page(
    display_length: display_length,
    search_value: search_value,
    display_start_from_page_no: display_start_from_page_no,
    grouping: grouping,
    company_id: company_id,
    edi_partner_id: edi_partner_id
  )
  render json: {
    data: result[:data],
    metadata: result[:metadata]
  }
end

#main_formObject



36
37
38
39
40
41
# File 'app/controllers/edi_204_controller.rb', line 36

def main_form
  edi_204_b2_id = params[:edi_204_b2_id]
  company_id = current_company_id
  results = Edi204.find_by(edi_204_b2_id: edi_204_b2_id, company_id: company_id)
  render json: { results: results }
end

#shipment_status_codesObject



90
91
92
# File 'app/controllers/edi_204_controller.rb', line 90

def shipment_status_codes
  render json: { shipment_status_codes: get_shipment_status_codes }
end

#stopsObject



98
99
100
101
102
103
104
105
# File 'app/controllers/edi_204_controller.rb', line 98

def stops
  edi_204_b2_id = params[:edi_204_b2_id]
  if check_record_exists_for_company(edi_204_b2_id)
    return render json: { error: 'EDI 204 does not exist for this company' }, status: :not_found
  end

  render json: { stops: get_stops(edi_204_b2_id) }
end

#time_zonesObject



94
95
96
# File 'app/controllers/edi_204_controller.rb', line 94

def time_zones
  render json: { time_zones: get_time_zones }
end