module Comee module Core class SalesOrderItemsController < ApplicationController include Common def index super do SalesOrderItem.includes( :sales_order, :customer_order_item, :source, :product, :unit ).where(sales_order_id: params[:id]) end end def filter data = SalesOrderItem.includes( :sales_order, :purchase_order_item, :customer_order_item, :source, :product, :unit ).ransack(params[:q]).result render_content(data) end def shipment_details details = SalesOrderItem.includes( shipment_items: [ {shipment_instruction_items: :pod}, :item_statuses ], sales_order: :fulfillment_center, purchase_order_item: [{purchase_order: :supplier}] ).find(params[:id]) render_content( details, { include: [ "shipment_items.shipment_instruction_items.pod", "shipment_items.item_statuses", "purchase_order_item.purchase_order.supplier", "sales_order.fulfillment_center" ], serializer: SalesOrderItemDetailSerializer } ) end def suggest_values service = CustomerOrderService.new result = service.suggest_values( params[:id], suggest_params[:from_id], suggest_params[:to_id], suggest_params[:quantity] ) render json: {success: true, data: result} end def cancel item = set_object item.update(canceled: true) render_content(item) end def cancel_quantity item = set_object to_cancel = cancel_quantity_params[:quantity] raise(StandardError, "Quantity to cancel is greater than available quantity.") if to_cancel > item.quantity_remaining item.quantity_canceled += to_cancel item.save! render_content(item) rescue StandardError => e render_error(e) end def activate item = set_object item.update(canceled: false) render_content(item) end def destroy Comee::Core::SalesOrderItem.destroy(params[:id]) render json: {success: true} end private def suggest_params params.permit(:from_id, :to_id, :quantity) end def model_params params.require(:payload) .permit(:sales_order_id, :customer_order_item_id, :product_id, :unit_id, :quantity, :quantity_delivered, :serial_no, :quantity_canceled, :customer_item_no, :customer_item_description, :price, :handover_date, :delivery_date, :eb_number, :lead_time, :comment, :action_note, :purchase_order_item_id, :pallet_no, :source_id, :processing_status) end def cancel_quantity_params params.require(:payload).permit(:quantity) end end end end