Class: Edi990LoadTenderResponsesController

Inherits:
ApplicationController show all
Includes:
Edi204Helper
Defined in:
app/controllers/edi_990_load_tender_responses_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

#check_if_a_response_existsObject



34
35
36
37
38
39
40
41
42
43
# File 'app/controllers/edi_990_load_tender_responses_controller.rb', line 34

def check_if_a_response_exists
  shipment_no = params[:shipment_no]
  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: { exists: Edi990LoadTenderResponses.exists?(shipment_identification_no: shipment_no,
                                                           edi_204_b2_id: edi_204_b2_id) }
end

#indexObject



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

def index
  edi_204_b2_id = params[:edi_204_b2_id]
  shipment_identification_no = params[:sio]
  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 = Edi990LoadTenderResponses
            .select('edi_990_load_tender_responses.*, vw_edi_out_log.*')
            .joins('LEFT JOIN vw_edi_out_log ON vw_edi_out_log.document_ref_id = edi_990_load_tender_responses.edi_990_load_tender_response_id')
            .where(edi_204_b2_id: edi_204_b2_id)
            .where(vw_edi_out_log: { document_code: shipment_identification_no.to_s })

  results = results.map do |item|
    item = item.as_json(methods: [:status_description])

    item
  end

  render json: results
end

#load_reject_reasonsObject



71
72
73
74
# File 'app/controllers/edi_990_load_tender_responses_controller.rb', line 71

def load_reject_reasons
  rejection_codes = TypesMaster.where(element: 'EDI 990 Reject Reason')
  render json: rejection_codes
end

#load_tender_responseObject



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'app/controllers/edi_990_load_tender_responses_controller.rb', line 45

def load_tender_response
  edi_204_b2_id = params[:edi_204_b2_id]
  action_code = params[:action_code]
  booking_date = params[:booking_date]
  shipment_date = params[:shipment_date]
  pro_number = params[:pro_number]
  rejection_code = params[:rejection_code]
  rejection_description = params[:rejection_description]
  user = 'Admin'
  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

  Edi990LoadTenderResponses.load_edi_990_tender_response(
    edi_204_b2_id: edi_204_b2_id,
    action_code: action_code,
    booking_date: booking_date,
    shipment_date: shipment_date,
    pro_number: pro_number,
    rejection_code: rejection_code,
    rejection_description: rejection_description,
    user: user
  )
  render json: { message: 'Tender response loaded successfully' }, status: :ok
end