module Logistics module Core class AirWeighBillsController < ApplicationController before_action :set_air_weigh_bill, only: [:update] # GET /air_weigh_bills # GET /air_weigh_bills.json def index @air_weigh_bill_rates = AirwayBillRate.all air_weigh_bill_rates_array =[] @air_weigh_bill_rates.each { |awb| air_weigh_bill_rates_array.push({:id => awb.id, :high => awb.high, :low => awb.low, :medium => awb.medium, :margin => awb.margin, :effective_date => awb.effective_date, :service_delivery_unit_name => awb.chargeable_service_unit_of_charge.service_delivery_unit.name, :service_delivery_unit_id => awb.chargeable_service_unit_of_charge.service_delivery_unit.id, :transaction_type_id => awb.transaction_type_id, :transaction_type_name => awb.transaction_type.name, :chargeable_service_id => awb.chargeable_service_unit_of_charge.chargeable_service_id, :chargeable_service_name => awb.chargeable_service_unit_of_charge.chargeable_service.name}) } @response = {:success => true, :message => '', :data => air_weigh_bill_rates_array} render json: @response end # POST /air_weigh_bills # POST /air_weigh_bills.json def create effective_date = params[:effective_date] AirwayBillRate.generate_rate_for_air_weigh_bill_services(effective_date) @response = {:success => true, :message => 'Rate table generated successfully', :data => []} render json: @response end # PATCH/PUT /air_weigh_bills/1 # PATCH/PUT /air_weigh_bills/1.json def update service_rates = params[:updated_service_rates] service_rates.each { |service_rate| old_service_rate = AirwayBillRate.find(service_rate['id']) old_service_rate.low = service_rate['low'] old_service_rate.medium = service_rate['medium'] old_service_rate.high = service_rate['high'] old_service_rate.margin = service_rate['margin'] old_service_rate.effective_date = service_rate['effective_date'] old_service_rate.save } @response = {:success => true, :message => 'Rate table updated successfully', :data => service_rates} render json: @response end private # Use callbacks to share common setup or constraints between actions. def set_air_weigh_bill @bill_of_loading_rate = AirwayBillRate.find(params[:id]) end def air_weigh_bill_params params.require(:air_weigh_bill).permit(:transaction_type_id, :chargeable_service_unit_of_charge_id, :low, :medium, :high, :effective_date) end end end end