module Logistics module Core class OfferRequestsController < ApplicationController protect_from_forgery with: :null_session before_action :set_offer_request, only: [:update] def index offer_request = OfferRequest.new result = offer_request.get_bill_of_loading_by_status_and_user(params[:status], session[:user_id]) data = ActiveModelSerializers::SerializableResource.new(result).as_json response = Mks::Common::MethodResponse.new(true, nil, data, nil, nil) render json: response end def get_request_by_status offer_request = OfferRequest.new result = offer_request.get_bill_of_loading_by_status(params[:status]) data = ActiveModelSerializers::SerializableResource.new(result).as_json response = Mks::Common::MethodResponse.new(true, nil, data, nil, nil) render json: response end def get_requests_with_additional_service offer_request = OfferRequest.new result = offer_request.get_request_with_additional_service data = ActiveModelSerializers::SerializableResource.new(result).as_json response = Mks::Common::MethodResponse.new(true, nil, data, nil, nil) render json: response end def get_request_by_security_status offer_request = OfferRequest.new result = offer_request.get_requests_by_security_status(params[:security_status]) data = ActiveModelSerializers::SerializableResource.new(result).as_json response = Mks::Common::MethodResponse.new(true, nil, data, nil, nil) render json: response end def new end def create offer_request = OfferRequest.new(offer_request_params) if offer_request.valid? offer_request.status = 'draft' offer_request.user_id = session[:user_id] offer_request.request_no = ReferenceNumber.ref_num offer_request.save response = Mks::Common::MethodResponse.new(true, 'Request capture successfully!', nil, nil, nil) else errors = Mks::Common::Util.error_messages offer_request, 'Offer Request' response = Mks::Common::MethodResponse.new(false, nil, nil, errors, nil) end render json: response end def update if @offer_request.update(offer_request_params) response = Mks::Common::MethodResponse.new(true, 'Request updated successfully !', nil, nil, nil) else errors = Mks::Common::Util.error_messages @offer_request, 'Offer Request' response = Mks::Common::MethodResponse.new(false, nil, nil, errors, nil) end render json: response end def change_status status = params[:status] offer_request = OfferRequest.find(params[:offer_request_id]) offer_request.status = status if offer_request.save response = Mks::Common::MethodResponse.new(true, "Status changed to #{status}!", nil, nil, nil) else response = Mks::Common::MethodResponse.new(false, "Status change failure!", nil, nil, nil) end render json: response end def change_sent_status offer_request = OfferRequest.find(params[:offer_request_id]) offer_request.is_sent = true offer_request.sent_date = Date.today offer_request.save response = Mks::Common::MethodResponse.new(true, 'Status changed to sent !',nil,nil,nil) render json: response end def set_security_status offer_request = OfferRequest.find(params[:offer_request_id]) offer_request.security_status = params[:security_status] offer_request.save response = Mks::Common::MethodResponse.new(true, "Security status changed to #{params[:security_status]} !",nil,nil,nil) render json: response end def update_storage_detail offer_request = OfferRequest.find(params[:offer_request_id]) offer_request.arrival_date = params[:arrival_date] offer_request.days_until_loaded = params[:days_until_loaded] offer_request.warehouse_id = params[:warehouse_id] offer_request.save @response = Mks::Common::MethodResponse.new(true, 'Storage data captured successfully !',nil, nil, nil) render json: @response end def update_demurage_detail offer_request = OfferRequest.find(params[:offer_request_id]) offer_request.carrier_id = params[:carrier_id] offer_request.agent_id = params[:agent_id] offer_request.arrival_date = params[:arrival_date] offer_request.days_before_returning_container = params[:days_before_returning_container] offer_request.save @response = Mks::Common::MethodResponse.new(true, 'Demurage data captured successfully !',nil, nil, nil) render json: @response end private def set_offer_request @offer_request = OfferRequest.find(params[:id]) end def offer_request_params params.require('offer_request').permit(:client_id, :transaction_type_id, :operation_type_id, :freight_forwarding, :customs_clearing, :transport, :security_status, :request_no, :communication_channel_id, :source_detail, :point_of_recipient, :date_of_recipient,:general_remark, :rate_level, :no_of_items, :no_of_convoy, :is_bulk,:contract_id,:remark) end end end end